Changeset 20eaa82 in mainline for uspace/drv/bus/usb/xhci/bus.c


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/drv/bus/usb/xhci/bus.c

    r867b375 r20eaa82  
    3535#include <adt/hash_table.h>
    3636#include <adt/hash.h>
     37#include <usb/host/ddf_helpers.h>
    3738#include <usb/host/endpoint.h>
     39#include <usb/host/hcd.h>
    3840#include <usb/debug.h>
    3941
    4042#include <assert.h>
    4143#include <errno.h>
     44#include <str_error.h>
    4245#include <macros.h>
    4346#include <stdbool.h>
     
    5356        xhci_device_t *device;
    5457} hashed_device_t;
     58
     59/** TODO: Still some copy-pasta left...
     60 */
     61int xhci_bus_enumerate_device(xhci_bus_t *bus, xhci_hc_t *hc, device_t *dev)
     62{
     63        int err;
     64
     65        /* TODO: get speed from the default address reservation */
     66        dev->speed = USB_SPEED_FULL;
     67
     68        /* Manage TT */
     69        if (dev->hub->speed == USB_SPEED_HIGH && usb_speed_is_11(dev->speed)) {
     70                /* For LS devices under HS hub */
     71                /* TODO: How about SS hubs? */
     72                dev->tt.address = dev->hub->address;
     73                dev->tt.port = dev->port;
     74        }
     75        else {
     76                /* Inherit hub's TT */
     77                dev->tt = dev->hub->tt;
     78        }
     79
     80        /* Assign an address to the device */
     81        if ((err = xhci_rh_address_device(&hc->rh, dev))) {
     82                usb_log_error("Failed to setup address of the new device: %s", str_error(err));
     83                return err;
     84        }
     85
     86        /* Read the device descriptor, derive the match ids */
     87        if ((err = hcd_ddf_device_explore(hc->hcd, dev))) {
     88                usb_log_error("Device(%d): Failed to explore device: %s", dev->address, str_error(err));
     89                bus_release_address(&bus->base, dev->address);
     90                return err;
     91        }
     92
     93        return EOK;
     94}
     95
     96static int enumerate_device(bus_t *bus, hcd_t *hcd, device_t *dev)
     97{
     98        xhci_hc_t *hc = hcd_get_driver_data(hcd);
     99        assert(hc);
     100
     101        return xhci_bus_enumerate_device((xhci_bus_t *) bus, hc, dev);
     102}
     103
     104static int remove_device(bus_t *bus, hcd_t *hcd, device_t *dev)
     105{
     106        // TODO: Implement me!
     107
     108        return ENOTSUP;
     109}
    55110
    56111/** Ops receive generic bus_t pointer. */
     
    214269}
    215270
    216 static int get_speed(bus_t *bus_base, usb_address_t address, usb_speed_t *speed)
    217 {
    218         xhci_bus_t *bus = bus_to_xhci_bus(bus_base);
    219         assert(bus);
    220 
    221         // TODO: Use `xhci_get_port_speed` once we find the port corresponding to `address`.
    222         *speed = USB_SPEED_SUPER;
    223         return EOK;
    224 }
    225 
    226271static int release_address(bus_t *bus_base, usb_address_t address)
    227272{
     
    255300
    256301static const bus_ops_t xhci_bus_ops = {
     302        .enumerate_device = enumerate_device,
     303        .remove_device = remove_device,
     304
    257305        .create_endpoint = create_endpoint,
    258306        .destroy_endpoint = destroy_endpoint,
     
    263311
    264312        .request_address = request_address,
    265         .get_speed = get_speed,
    266313        .release_address = release_address,
    267314        .reset_toggle = reset_toggle,
     
    303350        assert(bus);
    304351
    305         bus_init(&bus->base);
     352        bus_init(&bus->base, sizeof(device_t));
    306353
    307354        if (!hash_table_create(&bus->devices, 0, 0, &device_ht_ops)) {
     
    320367        hash_table_destroy(&bus->devices);
    321368}
     369
    322370/**
    323371 * @}
Note: See TracChangeset for help on using the changeset viewer.