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


Ignore:
Timestamp:
2018-01-08T00:07:00Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1102eca
Parents:
ecbad17
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-08 00:05:39)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-08 00:07:00)
Message:

xhci: documentation & cleanup

Also, a simple refactoring to remove functions that only wraps another
functions unused anywhere else.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/rh.c

    recbad17 reb928c4  
    6161        XHCI_REG_MASK(XHCI_PORT_CEC);
    6262
     63/**
     64 * Initialize the roothub subsystem.
     65 */
    6366int xhci_rh_init(xhci_rh_t *rh, xhci_hc_t *hc)
    6467{
     
    8184}
    8285
    83 /** Create a device node for device directly connected to RH.
     86/**
     87 * Finalize the RH subsystem.
     88 */
     89int xhci_rh_fini(xhci_rh_t *rh)
     90{
     91        assert(rh);
     92        free(rh->devices_by_port);
     93        return EOK;
     94}
     95
     96/**
     97 * Create and setup a device directly connected to RH. As the xHCI is not using
     98 * a virtual usbhub device for RH, this routine is called for devices directly.
    8499 */
    85100static int rh_setup_device(xhci_rh_t *rh, uint8_t port_id)
     
    89104
    90105        assert(rh->devices_by_port[port_id - 1] == NULL);
    91 
    92         xhci_bus_t *bus = &rh->hc->bus;
    93106
    94107        device_t *dev = hcd_ddf_fun_create(&rh->hc->base);
     
    107120        dev->speed = port_speed->usb_speed;
    108121
    109         if ((err = xhci_bus_enumerate_device(bus, dev))) {
     122        if ((err = bus_device_enumerate(dev))) {
    110123                usb_log_error("Failed to enumerate USB device: %s", str_error(err));
    111124                return err;
     
    134147}
    135148
     149/**
     150 * Handle a device connection. USB 3+ devices are set up directly, USB 2 and
     151 * below first need to have their port reset.
     152 */
    136153static int handle_connected_device(xhci_rh_t *rh, uint8_t port_id)
    137154{
     
    161178                usb_log_debug("USB 2 device attached, issuing reset.");
    162179                xhci_rh_reset_port(rh, port_id);
    163                 /*
    164                         FIXME: we need to wait for the event triggered by the reset
    165                         and then alloc_dev()... can't it be done directly instead of
    166                         going around?
    167                 */
    168180                return EOK;
    169181        }
    170182}
    171183
    172 /** Deal with a detached device.
     184/**
     185 * Deal with a detached device.
    173186 */
    174187static int handle_disconnected_device(xhci_rh_t *rh, uint8_t port_id)
     
    194207
    195208        /* Remove device from XHCI bus. */
    196         if ((err = xhci_bus_remove_device(&rh->hc->bus, &dev->base))) {
     209        if ((err = bus_device_remove(&dev->base))) {
    197210                usb_log_warning("Failed to remove device " XHCI_DEV_FMT " from XHCI bus: %s",
    198211                    XHCI_DEV_ARGS(*dev), str_error(err));
     
    202215}
    203216
    204 /** Handle an incoming Port Change Detected Event.
     217/**
     218 * Handle an incoming Port Change Detected Event.
    205219 */
    206220int xhci_rh_handle_port_status_change_event(xhci_hc_t *hc, xhci_trb_t *trb)
     
    219233}
    220234
     235/**
     236 * Handle all changes on all ports.
     237 */
    221238void xhci_rh_handle_port_change(xhci_rh_t *rh)
    222239{
     
    303320}
    304321
    305 static inline int get_hub_available_bandwidth(xhci_hc_t *hc, xhci_device_t* dev, uint8_t speed, xhci_port_bandwidth_ctx_t *ctx)
    306 {
    307         int err = EOK;
    308 
    309         // TODO: find a correct place for this function + API
    310         // We need speed, because a root hub device has both USB 2 and USB 3 speeds
    311         // and the command can query only one of them
    312         // ctx is an out parameter as of now
    313         assert(dev);
    314         assert(ctx);
    315 
    316         xhci_cmd_t cmd;
    317         xhci_cmd_init(&cmd, XHCI_CMD_GET_PORT_BANDWIDTH);
    318 
    319         if ((err = dma_buffer_alloc(&cmd.bandwidth_ctx, sizeof(xhci_port_bandwidth_ctx_t))))
    320                 goto end;
    321 
    322         cmd.device_speed = speed;
    323 
    324         if ((err = xhci_cmd_sync(hc, &cmd)))
    325                 goto end;
    326 
    327         memcpy(ctx, cmd.bandwidth_ctx.virt, sizeof(xhci_port_bandwidth_ctx_t));
    328 
    329 end:
    330         xhci_cmd_fini(&cmd);
    331         return err;
    332 }
    333 
     322/**
     323 * Get a port speed for a given port id.
     324 */
    334325const xhci_port_speed_t *xhci_rh_get_port_speed(xhci_rh_t *rh, uint8_t port)
    335326{
     
    340331}
    341332
     333/**
     334 * Issue a port reset for a given port.
     335 */
    342336int xhci_rh_reset_port(xhci_rh_t* rh, uint8_t port)
    343337{
     
    349343}
    350344
    351 int xhci_rh_fini(xhci_rh_t *rh)
    352 {
    353         assert(rh);
    354         free(rh->devices_by_port);
    355         return EOK;
    356 }
    357 
    358345/**
    359346 * @}
Note: See TracChangeset for help on using the changeset viewer.