Ignore:
Timestamp:
2017-12-14T23:01:57Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
837d53d
Parents:
bd05140
git-author:
Ondřej Hlavatý <aearsis@…> (2017-12-14 23:01:54)
git-committer:
Ondřej Hlavatý <aearsis@…> (2017-12-14 23:01:57)
Message:

usbhost bus: refactor the bus ops

This way, method names better represent the entity it is working with.
Their semantics was shifted a bit.

Regarding the tree of structures:

bus ← device ← endpoint ← batch

Previously, devices were kept in DDF function nodes, and endpoints had
pointer to the bus and device. Now, devices have pointer to bus,
endpoints don't.

Pointer to hcd_t in bus is WIP, and will be removed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/bus.h

    rbd05140 r6832245  
    7777        usb_address_t address;
    7878
     79        /* Managing bus */
     80        bus_t *bus;
     81
    7982        /* This structure is meant to be extended by overriding. */
    8083} device_t;
    8184
    82 typedef struct {
    83         int (*enumerate_device)(bus_t *, hcd_t *, device_t *);
    84         int (*remove_device)(bus_t *, hcd_t *, device_t *);
     85typedef struct bus_ops bus_ops_t;
    8586
    86         int (*online_device)(bus_t *, hcd_t *, device_t *);                     /**< Optional */
    87         int (*offline_device)(bus_t *, hcd_t *, device_t *);                    /**< Optional */
     87/**
     88 * Operations structure serving as an interface of hc driver for the library
     89 * (and the rest of the system).
     90 */
     91struct bus_ops {
     92        /* Undefined operations will be delegated to parent ops */
     93        const bus_ops_t *parent;
    8894
    89         /* The following operations are protected by a bus guard. */
    90         endpoint_t *(*create_endpoint)(bus_t *);
    91         int (*register_endpoint)(bus_t *, device_t *, endpoint_t *, const usb_endpoint_desc_t *);
    92         int (*unregister_endpoint)(bus_t *, endpoint_t *);
    93         endpoint_t *(*find_endpoint)(bus_t *, device_t*, usb_target_t, usb_direction_t);
    94         void (*destroy_endpoint)(endpoint_t *);                 /**< Optional */
     95        /* Global operations on the bus */
     96        int (*reserve_default_address)(bus_t *, usb_speed_t);
     97        int (*release_default_address)(bus_t *);
     98        int (*reset_toggle)(bus_t *, usb_target_t, toggle_reset_mode_t);
     99
     100        /* Operations on device */
     101        int (*device_enumerate)(device_t *);
     102        int (*device_remove)(device_t *);
     103        int (*device_online)(device_t *);                       /**< Optional */
     104        int (*device_offline)(device_t *);                      /**< Optional */
     105        endpoint_t *(*device_find_endpoint)(device_t*, usb_target_t, usb_direction_t);
     106        endpoint_t *(*endpoint_create)(device_t *, const usb_endpoint_desc_t *);
     107
     108        /* Operations on endpoint */
     109        int (*endpoint_register)(endpoint_t *);
     110        int (*endpoint_unregister)(endpoint_t *);
     111        void (*endpoint_destroy)(endpoint_t *);                 /**< Optional */
    95112        bool (*endpoint_get_toggle)(endpoint_t *);              /**< Optional */
    96113        void (*endpoint_set_toggle)(endpoint_t *, bool);        /**< Optional */
     114        ssize_t (*endpoint_count_bw) (endpoint_t *, size_t);
     115        usb_transfer_batch_t *(*batch_create)(endpoint_t *);    /**< Optional */
    97116
    98         int (*reserve_default_address)(bus_t *, usb_speed_t);
    99         int (*release_default_address)(bus_t *);
     117        /* Operations on batch */
     118        void (*batch_destroy)(usb_transfer_batch_t *);  /**< Optional */
     119};
    100120
    101         int (*reset_toggle)(bus_t *, usb_target_t, toggle_reset_mode_t);
    102 
    103         size_t (*count_bw) (endpoint_t *, size_t);
    104 
    105         usb_transfer_batch_t *(*create_batch)(bus_t *, endpoint_t *); /**< Optional */
    106         void (*destroy_batch)(usb_transfer_batch_t *);  /**< Optional */
    107 } bus_ops_t;
     121/**
     122 * Use this macro to lookup virtual function.
     123 */
     124#define BUS_OPS_LOOKUP(start, fn) ({ bus_ops_t const * ops = (start); while (ops && ops->fn == NULL) ops = ops->parent; ops; })
    108125
    109126/** Endpoint management structure */
     
    112129        fibril_mutex_t guard;
    113130
     131        /* TODO: get rid of this one. */
     132        hcd_t *hcd;
     133
    114134        size_t device_size;
    115135
    116136        /* Do not call directly, ops are synchronized. */
    117         bus_ops_t ops;
     137        const bus_ops_t *ops;
    118138
    119139        /* This structure is meant to be extended by overriding. */
    120140} bus_t;
    121141
    122 void bus_init(bus_t *, size_t);
    123 int device_init(device_t *);
     142void bus_init(bus_t *, hcd_t *, size_t);
     143int bus_device_init(device_t *, bus_t *);
    124144
    125 int device_set_default_name(device_t *);
     145int bus_device_set_default_name(device_t *);
    126146
    127 int bus_enumerate_device(bus_t *, hcd_t *, device_t *);
    128 int bus_remove_device(bus_t *, hcd_t *, device_t *);
     147int bus_device_enumerate(device_t *);
     148int bus_device_remove(device_t *);
    129149
    130 int bus_online_device(bus_t *, hcd_t *, device_t *);
    131 int bus_offline_device(bus_t *, hcd_t *, device_t *);
     150int bus_device_online(device_t *);
     151int bus_device_offline(device_t *);
    132152
    133 int bus_add_endpoint(bus_t *, device_t *, const usb_endpoint_desc_t *, endpoint_t **);
    134 endpoint_t *bus_find_endpoint(bus_t *, device_t *, usb_target_t, usb_direction_t);
    135 int bus_remove_endpoint(bus_t *, endpoint_t *);
    136 
    137 size_t bus_count_bw(endpoint_t *, size_t);
     153int bus_endpoint_add(device_t *, const usb_endpoint_desc_t *, endpoint_t **);
     154endpoint_t *bus_find_endpoint(device_t *, usb_target_t, usb_direction_t);
     155int bus_endpoint_remove(endpoint_t *);
    138156
    139157int bus_reserve_default_address(bus_t *, usb_speed_t);
Note: See TracChangeset for help on using the changeset viewer.