Ignore:
Timestamp:
2017-10-15T13:44:39Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2770b66
Parents:
867b375
Message:

usbhost refactoring: introduced bus→enumerate_device

File:
1 edited

Legend:

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

    r867b375 r20eaa82  
    4545#include <usb/usb.h>
    4646
     47#include <assert.h>
    4748#include <fibril_synch.h>
    4849#include <stdbool.h>
     
    5152typedef struct endpoint endpoint_t;
    5253typedef struct bus bus_t;
     54typedef struct ddf_fun ddf_fun_t;
     55
     56typedef struct device {
     57        /* Device tree keeping */
     58        link_t link;
     59        list_t devices;
     60        fibril_mutex_t guard;
     61
     62        /* Associated DDF function, if any */
     63        ddf_fun_t *fun;
     64
     65        /* Invalid for the roothub device */
     66        unsigned port;
     67        struct device *hub;
     68
     69        /* Transaction translator */
     70        usb_tt_address_t tt;
     71
     72        /* The following are not set by the library */
     73        usb_speed_t speed;
     74        usb_address_t address;
     75
     76        /* This structure is meant to be extended by overriding. */
     77} device_t;
    5378
    5479typedef struct {
     80        int (*enumerate_device)(bus_t *, hcd_t *, device_t *);
     81        int (*remove_device)(bus_t *, hcd_t *, device_t *);
     82
    5583        endpoint_t *(*create_endpoint)(bus_t *);
    5684        int (*register_endpoint)(bus_t *, endpoint_t *);
     
    5987
    6088        int (*request_address)(bus_t *, usb_address_t*, bool, usb_speed_t);
    61         int (*get_speed)(bus_t *, usb_address_t, usb_speed_t *);
    6289        int (*release_address)(bus_t *, usb_address_t);
    6390
     
    77104        fibril_mutex_t guard;
    78105
     106        size_t device_size;
     107
    79108        /* Do not call directly, ops are synchronized. */
    80109        bus_ops_t ops;
     
    83112} bus_t;
    84113
    85 void bus_init(bus_t *);
     114void bus_init(bus_t *, size_t);
     115int device_init(device_t *);
     116
     117extern int bus_add_ep(bus_t *bus, device_t *device, usb_endpoint_t endpoint,
     118    usb_direction_t dir, usb_transfer_type_t type, size_t max_packet_size,
     119    unsigned packets, size_t size);
     120extern int bus_remove_ep(bus_t *bus, usb_target_t target, usb_direction_t dir);
     121
     122int device_set_default_name(device_t *);
     123
     124int bus_enumerate_device(bus_t *, hcd_t *, device_t *);
     125int bus_remove_device(bus_t *, hcd_t *, device_t *);
    86126
    87127endpoint_t *bus_create_endpoint(bus_t *);
     
    93133
    94134int bus_request_address(bus_t *, usb_address_t *, bool, usb_speed_t);
    95 int bus_get_speed(bus_t *, usb_address_t, usb_speed_t *);
    96135int bus_release_address(bus_t *, usb_address_t);
     136
     137static inline int bus_reserve_default_address(bus_t *bus, usb_speed_t speed) {
     138        usb_address_t addr = USB_ADDRESS_DEFAULT;
     139
     140        const int r = bus_request_address(bus, &addr, true, speed);
     141        assert(addr == USB_ADDRESS_DEFAULT);
     142        return r;
     143}
     144
     145static inline int bus_release_default_address(bus_t *bus) {
     146        return bus_release_address(bus, USB_ADDRESS_DEFAULT);
     147}
    97148
    98149int bus_reset_toggle(bus_t *, usb_target_t, bool);
Note: See TracChangeset for help on using the changeset viewer.