Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 5e2b1ae6 in mainline


Ignore:
Timestamp:
2018-01-07T01:54:45Z (4 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master
Children:
3dc3f99
Parents:
63431db
Message:

usbhost: reserve default speed in library

Location:
uspace
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/hc.c

    r63431db r5e2b1ae6  
    388388int hc_init_mem_structures(hc_t *instance, hc_device_t *hcd)
    389389{
    390         int err;
    391390        assert(instance);
    392391
    393         if ((err = usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11)))
    394                 return err;
     392        usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11);
    395393
    396394        bus_t *bus = (bus_t *) &instance->bus;
  • uspace/drv/bus/usb/usbhub/port.c

    r63431db r5e2b1ae6  
    406406
    407407        /* Reserve default address */
    408         while ((ret = usbhc_reserve_default_address(exch, speed)) == ENOENT) {
     408        while ((ret = usbhc_reserve_default_address(exch, speed)) == EAGAIN) {
    409409                async_usleep(1000000);
    410410        }
  • uspace/drv/bus/usb/xhci/bus.c

    r63431db r5e2b1ae6  
    426426}
    427427
    428 static int reserve_default_address(bus_t *bus_base, usb_speed_t speed)
    429 {
    430         xhci_bus_t *xhci_bus = bus_to_xhci_bus(bus_base);
    431 
    432         if (xhci_bus->default_address_speed != USB_SPEED_MAX)
    433                 /* Already allocated */
    434                 return ENOENT;
    435 
    436         xhci_bus->default_address_speed = speed;
    437         return EOK;
    438 }
    439 
    440 static int release_default_address(bus_t *bus_base)
    441 {
    442         xhci_bus_t *xhci_bus = bus_to_xhci_bus(bus_base);
    443 
    444         xhci_bus->default_address_speed = USB_SPEED_MAX;
    445         return EOK;
    446 }
    447 
    448428static usb_transfer_batch_t *batch_create(endpoint_t *ep)
    449429{
     
    461441// TODO: Is it good idea to use this macro? It blurrs the fact that the callbacks and static functions are called the same.
    462442#define BIND_OP(op) .op = op,
    463         BIND_OP(reserve_default_address)
    464         BIND_OP(release_default_address)
    465 
    466443        BIND_OP(device_enumerate)
    467444        BIND_OP(device_remove)
     
    501478        bus->hc = hc;
    502479        bus->base.ops = &xhci_bus_ops;
    503         bus->default_address_speed = USB_SPEED_MAX;
    504480        return EOK;
    505481}
  • uspace/drv/bus/usb/xhci/bus.h

    r63431db r5e2b1ae6  
    5151
    5252        xhci_device_t **devices_by_slot;        /**< Devices by Slot ID */
    53 
    54         usb_speed_t default_address_speed;      /**< Used to get speed from usb hubs */
    5553} xhci_bus_t;
    5654
  • uspace/lib/usbhost/include/usb/host/bus.h

    r63431db r5e2b1ae6  
    100100        void (*interrupt)(bus_t *, uint32_t);
    101101        int (*status)(bus_t *, uint32_t *);
    102         int (*reserve_default_address)(bus_t *, usb_speed_t);
    103         int (*release_default_address)(bus_t *);
    104102
    105103        /* Operations on device */
     
    139137        const bus_ops_t *ops;
    140138
     139        /* Reserving default address - USB_SPEED_MAX when free. */
     140        usb_speed_t default_address_speed;
     141
    141142        /* This structure is meant to be extended by overriding. */
    142143} bus_t;
     
    166167
    167168int bus_reserve_default_address(bus_t *, usb_speed_t);
    168 int bus_release_default_address(bus_t *);
     169void bus_release_default_address(bus_t *);
    169170
    170171#endif
  • uspace/lib/usbhost/include/usb/host/usb2_bus.h

    r63431db r5e2b1ae6  
    5050        bus_t base;                     /**< Inheritance - keep this first */
    5151
    52         /** The speed which reserved default address. Invalid unless reserved. */
    53         usb_speed_t default_address_speed;
    54 
    5552        /** Map of occupied addresses */
    5653        bool address_occupied [USB_ADDRESS_COUNT];
     
    6461extern const bus_ops_t usb2_bus_ops;
    6562
    66 extern int usb2_bus_init(usb2_bus_t *, size_t);
     63extern void usb2_bus_init(usb2_bus_t *, size_t);
    6764
    6865#endif
  • uspace/lib/usbhost/src/bus.c

    r63431db r5e2b1ae6  
    5454        fibril_mutex_initialize(&bus->guard);
    5555        bus->device_size = device_size;
     56        bus->default_address_speed = USB_SPEED_MAX;
    5657}
    5758
     
    239240        assert(bus);
    240241
    241         const bus_ops_t *ops = BUS_OPS_LOOKUP(bus->ops, reserve_default_address);
    242         if (!ops)
    243                 return ENOTSUP;
    244 
    245242        fibril_mutex_lock(&bus->guard);
    246         const int r = ops->reserve_default_address(bus, speed);
    247         fibril_mutex_unlock(&bus->guard);
    248         return r;
    249 }
    250 
    251 int bus_release_default_address(bus_t *bus)
     243        if (bus->default_address_speed != USB_SPEED_MAX) {
     244                fibril_mutex_unlock(&bus->guard);
     245                return EAGAIN;
     246        } else {
     247                bus->default_address_speed = speed;
     248                fibril_mutex_unlock(&bus->guard);
     249                return EOK;
     250        }
     251}
     252
     253void bus_release_default_address(bus_t *bus)
    252254{
    253255        assert(bus);
    254 
    255         const bus_ops_t *ops = BUS_OPS_LOOKUP(bus->ops, release_default_address);
    256         if (!ops)
    257                 return ENOTSUP;
    258 
    259         fibril_mutex_lock(&bus->guard);
    260         const int r = ops->release_default_address(bus);
    261         fibril_mutex_unlock(&bus->guard);
    262         return r;
     256        bus->default_address_speed = USB_SPEED_MAX;
    263257}
    264258
  • uspace/lib/usbhost/src/ddf_helpers.c

    r63431db r5e2b1ae6  
    137137
    138138        usb_log_debug("Device %d released default address\n", dev->address);
    139         return bus_release_default_address(hcd->bus);
     139        bus_release_default_address(hcd->bus);
     140
     141        return EOK;
    140142}
    141143
  • uspace/lib/usbhost/src/usb2_bus.c

    r63431db r5e2b1ae6  
    100100 * @param bus usb_device_manager
    101101 * @param addr Pointer to requested address value, place to store new address
    102  * @parma strict Fail if the requested address is not available.
    103102 * @return Error code.
    104103 * @note Default address is only available in strict mode.
    105104 */
    106 static int request_address(usb2_bus_t *bus, usb_address_t *addr, bool strict)
     105static int request_address(usb2_bus_t *bus, usb_address_t *addr)
    107106{
    108107        int err;
     
    114113                return EINVAL;
    115114
    116         /* Only grant default address to strict requests */
    117         if ((*addr == USB_ADDRESS_DEFAULT) && !strict) {
    118                 if ((err = get_free_address(bus, addr)))
    119                         return err;
    120         }
    121         else if (bus->address_occupied[*addr]) {
    122                 if (strict) {
    123                         return ENOENT;
    124                 }
    125                 if ((err = get_free_address(bus, addr)))
    126                         return err;
    127         }
     115        if ((err = get_free_address(bus, addr)))
     116                return err;
    128117
    129118        assert(usb_address_is_valid(*addr));
    130119        assert(bus->address_occupied[*addr] == false);
    131         assert(*addr != USB_ADDRESS_DEFAULT || strict);
     120        assert(*addr != USB_ADDRESS_DEFAULT);
    132121
    133122        bus->address_occupied[*addr] = true;
     
    152141        /** Reserve address early, we want pretty log messages */
    153142        usb_address_t address = USB_ADDRESS_DEFAULT;
    154         if ((err = request_address(bus, &address, false))) {
     143        if ((err = request_address(bus, &address))) {
    155144                usb_log_error("Failed to reserve new address: %s.",
    156145                    str_error(err));
     
    231220         * default address.
    232221         */
    233         dev->speed = bus->default_address_speed;
     222        dev->speed = bus->base.default_address_speed;
    234223        usb_log_debug("Found new %s speed USB device.", usb_str_speed(dev->speed));
    235224
     
    301290}
    302291
    303 static int usb2_bus_register_default_address(bus_t *bus_base, usb_speed_t speed)
    304 {
    305         usb2_bus_t *bus = bus_to_usb2_bus(bus_base);
    306         usb_address_t addr = USB_ADDRESS_DEFAULT;
    307         const int err = request_address(bus, &addr, true);
    308         if (err)
    309                 return err;
    310         bus->default_address_speed = speed;
    311         return EOK;
    312 }
    313 
    314 static int usb2_bus_release_default_address(bus_t *bus_base)
    315 {
    316         usb2_bus_t *bus = bus_to_usb2_bus(bus_base);
    317         return release_address(bus, USB_ADDRESS_DEFAULT);
    318 }
    319 
    320292const bus_ops_t usb2_bus_ops = {
    321         .reserve_default_address = usb2_bus_register_default_address,
    322         .release_default_address = usb2_bus_release_default_address,
    323293        .device_enumerate = usb2_bus_device_enumerate,
    324294        .endpoint_create = usb2_bus_create_ep,
     
    334304 * @return Error code.
    335305 */
    336 int usb2_bus_init(usb2_bus_t *bus, size_t available_bandwidth)
     306void usb2_bus_init(usb2_bus_t *bus, size_t available_bandwidth)
    337307{
    338308        assert(bus);
     
    342312
    343313        bus->free_bw = available_bandwidth;
    344 
    345         return EOK;
    346314}
    347315/**
Note: See TracChangeset for help on using the changeset viewer.