Changeset 8b8c164 in mainline for uspace/lib/usbhost/src/usb2_bus.c


Ignore:
Timestamp:
2017-10-27T15:22:06Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
58ac3ec
Parents:
7010861
Message:

libusbhost bus: endpoint→device is now managed by bus implementation

That allows xhci to better isolate responsibilities.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/usb2_bus.c

    r7010861 r8b8c164  
    110110
    111111        /** Reserve address early, we want pretty log messages */
    112         const usb_address_t address = bus_reserve_default_address(bus, dev->speed);
    113         if (address < 0) {
     112        usb_address_t address;
     113        if ((err = bus_request_address(bus, &address, false, dev->speed))) {
    114114                usb_log_error("Failed to reserve new address: %s.",
    115                     str_error(address));
    116                 return address;
     115                    str_error(err));
     116                return err;
    117117        }
    118118        usb_log_debug("Device(%d): Reserved new address.", address);
     
    159159        }
    160160
     161        /* We need to remove ep before we change the address */
     162        if ((err = bus_remove_endpoint(bus, default_ep))) {
     163                usb_log_error("Device(%d): Failed to unregister default target: %s", address, str_error(err));
     164                goto err_address;
     165        }
     166        endpoint_del_ref(default_ep);
     167
    161168        dev->address = address;
    162169
     
    175182                usb_log_error("Device(%d): Failed to register EP0: %s",
    176183                    address, str_error(err));
    177                 goto err_default_control_ep;
    178         }
    179 
    180         err = bus_remove_endpoint(bus, default_ep);
    181         assert(err == EOK);
    182         endpoint_del_ref(default_ep);
    183 
    184         err = bus_release_address(bus, address);
    185         assert(err == EOK);
     184                goto err_address;
     185        }
    186186
    187187        return EOK;
     
    210210        usb_log_debug("Found new %s speed USB device.", usb_str_speed(dev->speed));
    211211
    212         /* Manage TT */
    213         if (dev->hub->speed == USB_SPEED_HIGH && usb_speed_is_11(dev->speed)) {
    214                 /* For LS devices under HS hub */
    215                 /* TODO: How about SS hubs? */
    216                 dev->tt.address = dev->hub->address;
    217                 dev->tt.port = dev->port;
     212        if (dev->hub) {
     213                /* Manage TT */
     214                if (dev->hub->speed == USB_SPEED_HIGH && usb_speed_is_11(dev->speed)) {
     215                        /* For LS devices under HS hub */
     216                        /* TODO: How about SS hubs? */
     217                        dev->tt.address = dev->hub->address;
     218                        dev->tt.port = dev->port;
     219                }
     220                else {
     221                        /* Inherit hub's TT */
     222                        dev->tt = dev->hub->tt;
     223                }
    218224        }
    219225        else {
    220                 /* Inherit hub's TT */
    221                 dev->tt = dev->hub->tt;
     226                dev->tt = (usb_tt_address_t) {
     227                        .address = -1,
     228                        .port = 0,
     229                };
    222230        }
    223231
     
    310318 * @param endpoint USB endpoint number.
    311319 */
    312 static int usb2_bus_register_ep(bus_t *bus_base, endpoint_t *ep, const usb_endpoint_desc_t *desc)
     320static int usb2_bus_register_ep(bus_t *bus_base, device_t *device, endpoint_t *ep, const usb_endpoint_desc_t *desc)
    313321{
    314322        usb2_bus_t *bus = bus_to_usb2_bus(bus_base);
    315323        assert(ep);
    316324
    317         assert(ep->device);
     325        ep->device = device;
    318326
    319327        /* Extract USB2-related information from endpoint_desc */
     
    347355        usb2_bus_t *bus = bus_to_usb2_bus(bus_base);
    348356        assert(ep);
     357
     358        list_remove(&ep->link);
     359        ep->device = NULL;
    349360
    350361        bus->free_bw += ep->bandwidth;
Note: See TracChangeset for help on using the changeset viewer.