Changeset 6832245 in mainline for uspace/lib/usbhost/include


Ignore:
Timestamp:
2017-12-14T23:01:57Z (8 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.

Location:
uspace/lib/usbhost/include/usb/host
Files:
5 edited

Legend:

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

    rbd05140 r6832245  
    5151typedef struct endpoint endpoint_t;
    5252
    53 extern size_t bandwidth_count_usb11(endpoint_t *, size_t);
     53extern ssize_t bandwidth_count_usb11(endpoint_t *, size_t);
    5454
    55 extern size_t bandwidth_count_usb20(endpoint_t *, size_t);
     55extern ssize_t bandwidth_count_usb20(endpoint_t *, size_t);
    5656
    5757#endif
  • 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);
  • uspace/lib/usbhost/include/usb/host/ddf_helpers.h

    rbd05140 r6832245  
    8181int hcd_setup_virtual_root_hub(hcd_t *, ddf_dev_t *);
    8282
    83 device_t *hcd_ddf_device_create(ddf_dev_t *, size_t);
     83device_t *hcd_ddf_device_create(ddf_dev_t *, bus_t *);
    8484void hcd_ddf_device_destroy(device_t *);
    85 int hcd_ddf_device_explore(hcd_t *, device_t *);
     85int hcd_ddf_device_explore(device_t *);
    8686int hcd_ddf_device_online(ddf_fun_t *);
    8787int hcd_ddf_device_offline(ddf_fun_t *);
  • uspace/lib/usbhost/include/usb/host/endpoint.h

    rbd05140 r6832245  
    4545#include <stdbool.h>
    4646#include <usb/usb.h>
     47#include <usb/host/bus.h>
    4748
    4849typedef struct bus bus_t;
     
    5455        /** Part of linked list. */
    5556        link_t link;
    56         /** Managing bus */
    57         bus_t *bus;
     57        /** USB device */
     58        device_t *device;
    5859        /** Reference count. */
    5960        atomic_t refcnt;
    60         /** USB device */
    61         device_t *device;
    6261        /** Enpoint number */
    6362        usb_endpoint_t endpoint;
     
    8483} endpoint_t;
    8584
    86 extern void endpoint_init(endpoint_t *, bus_t *);
     85extern void endpoint_init(endpoint_t *, device_t *, const usb_endpoint_desc_t *);
    8786
    8887extern void endpoint_add_ref(endpoint_t *);
     
    103102void endpoint_abort(endpoint_t *);
    104103
     104/* Manage the toggle bit */
    105105extern int endpoint_toggle_get(endpoint_t *);
    106106extern void endpoint_toggle_set(endpoint_t *, bool);
     107
     108/* Calculate bandwidth */
     109ssize_t endpoint_count_bw(endpoint_t *, size_t);
     110
     111static inline bus_t *endpoint_get_bus(endpoint_t *ep)
     112{
     113        return ep->device->bus;
     114}
    107115
    108116/** list_get_instance wrapper.
  • uspace/lib/usbhost/include/usb/host/usb2_bus.h

    rbd05140 r6832245  
    4646typedef struct endpoint endpoint_t;
    4747
    48 typedef size_t (*count_bw_func_t)(endpoint_t *, size_t);
    49 
    5048/** Endpoint management structure */
    5149typedef struct usb2_bus {
     
    6664} usb2_bus_t;
    6765
    68 extern int usb2_bus_init(usb2_bus_t *, size_t, count_bw_func_t);
     66extern const bus_ops_t usb2_bus_ops;
     67
     68extern int usb2_bus_init(usb2_bus_t *, hcd_t *, size_t);
    6969
    7070#endif
Note: See TracChangeset for help on using the changeset viewer.