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


Ignore:
Timestamp:
2017-10-15T13:44:39Z (8 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/rh.c

    r867b375 r20eaa82  
    3838#include <usb/debug.h>
    3939#include <usb/host/utils/malloc32.h>
     40#include <usb/host/bus.h>
    4041#include <usb/host/ddf_helpers.h>
    4142
     
    7374// TODO: This currently assumes the device is attached to rh directly.
    7475//       Also, we should consider moving a lot of functionailty to xhci bus
    75 int xhci_rh_address_device(xhci_rh_t *rh, usb_speed_t unused_speed, usb_tt_address_t tt, usb_address_t *address)
     76int xhci_rh_address_device(xhci_rh_t *rh, device_t *dev)
    7677{
    7778        int err;
     
    8182        xhci_cmd_init(&cmd);
    8283
    83         uint8_t port = tt.port;
    84 
    8584        /* XXX Certainly not generic solution. */
    8685        uint32_t route_str = 0;
    8786
    88         const xhci_port_speed_t *speed = xhci_rh_get_port_speed(rh, port);
     87        const xhci_port_speed_t *speed = xhci_rh_get_port_speed(rh, dev->port);
    8988
    9089        xhci_send_enable_slot_command(hc, &cmd);
     
    109108        /* Initialize slot_ctx according to section 4.3.3 point 3. */
    110109        /* Attaching to root hub port, root string equals to 0. */
    111         XHCI_SLOT_ROOT_HUB_PORT_SET(ictx->slot_ctx, port);
     110        XHCI_SLOT_ROOT_HUB_PORT_SET(ictx->slot_ctx, dev->port);
    112111        XHCI_SLOT_CTX_ENTRIES_SET(ictx->slot_ctx, 1);
    113112        XHCI_SLOT_ROUTE_STRING_SET(ictx->slot_ctx, route_str);
     
    158157        xhci_cmd_fini(&cmd);
    159158
    160         *address = XHCI_SLOT_DEVICE_ADDRESS(dctx->slot_ctx);
    161         usb_log_debug2("Obtained USB address: %d.\n", *address);
     159        dev->address = XHCI_SLOT_DEVICE_ADDRESS(dctx->slot_ctx);
     160        usb_log_debug2("Obtained USB address: %d.\n", dev->address);
    162161
    163162        // TODO: Ask libusbhost to create a control endpoint for EP0.
     
    183182}
    184183
     184/** Create a device node for device directly connected to RH.
     185 */
    185186static int rh_setup_device(xhci_rh_t *rh, uint8_t port_id)
    186187{
    187         /** This should ideally use the libusbhost in a clean and elegant way,
    188          * to create child function. The refactoring of libusbhost is not over
    189          * yet, so for now it is still quirky.
    190          */
    191 
    192         return hcd_roothub_new_device(rh->hcd_rh, port_id);
     188        int err;
     189        assert(rh);
     190
     191        xhci_bus_t *bus = &rh->hc->bus;
     192
     193        device_t *dev = hcd_ddf_device_create(rh->hc_device, bus->base.device_size);
     194        if (!dev) {
     195                usb_log_error("Failed to create USB device function.");
     196                return ENOMEM;
     197        }
     198
     199        dev->hub = &rh->device;
     200        dev->port = port_id;
     201
     202        if ((err = xhci_bus_enumerate_device(bus, rh->hc, dev))) {
     203                usb_log_error("Failed to enumerate USB device: %s", str_error(err));
     204                return err;
     205        }
     206
     207        if (!ddf_fun_get_name(dev->fun)) {
     208                device_set_default_name(dev);
     209        }
     210
     211        if ((err = ddf_fun_bind(dev->fun))) {
     212                usb_log_error("Device(%d): Failed to register: %s.", dev->address, str_error(err));
     213                goto err_usb_dev;
     214        }
     215
     216        fibril_mutex_lock(&rh->device.guard);
     217        list_append(&dev->link, &rh->device.devices);
     218        fibril_mutex_unlock(&rh->device.guard);
     219
     220        return EOK;
     221
     222err_usb_dev:
     223        hcd_ddf_device_destroy(dev);
     224        return err;
    193225}
    194226
Note: See TracChangeset for help on using the changeset viewer.