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


Ignore:
Timestamp:
2017-10-23T21:26:22Z (7 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ec700c7
Parents:
327f147
Message:

Moved some code from RH to HC. Simplified device address process. Issuing deconfigure device command.

File:
1 edited

Legend:

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

    r327f147 rb724494  
    9595{
    9696        int err;
     97
     98        const xhci_port_speed_t *speed = xhci_rh_get_port_speed(rh, dev->port);
    9799        xhci_device_t *xhci_dev = xhci_device_get(dev);
    98 
    99         /* FIXME: Certainly not generic solution. */
    100         const uint32_t route_str = 0;
    101 
    102100        xhci_dev->hc = rh->hc;
    103 
    104         const xhci_port_speed_t *speed = xhci_rh_get_port_speed(rh, dev->port);
    105101        xhci_dev->usb3 = speed->major == 3;
    106102
    107         /* Enable new slot */
     103        /* Enable new slot. */
    108104        if ((err = hc_enable_slot(rh->hc, &xhci_dev->slot_id)) != EOK)
    109105                return err;
    110106        usb_log_debug2("Obtained slot ID: %u.\n", xhci_dev->slot_id);
    111107
    112         /* Setup input context */
    113         xhci_input_ctx_t *ictx = malloc32(sizeof(xhci_input_ctx_t));
    114         if (!ictx)
    115                 return ENOMEM;
    116         memset(ictx, 0, sizeof(xhci_input_ctx_t));
    117 
    118         XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 0);
    119         XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 1);
    120 
    121         /* Initialize slot_ctx according to section 4.3.3 point 3. */
    122         /* Attaching to root hub port, root string equals to 0. */
    123         XHCI_SLOT_ROOT_HUB_PORT_SET(ictx->slot_ctx, dev->port);
    124         XHCI_SLOT_CTX_ENTRIES_SET(ictx->slot_ctx, 1);
    125         XHCI_SLOT_ROUTE_STRING_SET(ictx->slot_ctx, route_str);
    126 
     108        /* Create and configure control endpoint. */
    127109        endpoint_t *ep0_base = bus_create_endpoint(&rh->hc->bus.base);
    128110        if (!ep0_base)
    129                 goto err_ictx;
     111                return ENOMEM;
     112
    130113        xhci_endpoint_t *ep0 = xhci_endpoint_get(ep0_base);
    131 
    132         /* Control endpoints don't use streams. */
    133114        /* FIXME: Sync this with xhci_device_add_endpoint. */
    134115        ep0->max_streams = 0;
    135116        ep0->max_burst = 0;
    136117        ep0->mult = 0;
     118
    137119        if ((err = xhci_endpoint_alloc_transfer_ds(ep0)))
    138                 goto err_ictx;
    139 
    140         setup_control_ep0_ctx(&ictx->endpoint_ctx[0], &ep0->ring, speed);
     120                goto err_ep;
     121
     122        xhci_ep_ctx_t ep_ctx;
     123        memset(&ep_ctx, 0, sizeof(xhci_ep_ctx_t));
     124        setup_control_ep0_ctx(&ep_ctx, &ep0->ring, speed);
    141125
    142126        /* Setup and register device context */
    143         xhci_device_ctx_t *dctx = malloc32(sizeof(xhci_device_ctx_t));
    144         if (!dctx) {
     127        xhci_dev->dev_ctx = malloc32(sizeof(xhci_device_ctx_t));
     128        if (!xhci_dev->dev_ctx) {
    145129                err = ENOMEM;
    146                 goto err_ep;
    147         }
    148         xhci_dev->dev_ctx = dctx;
    149         rh->hc->dcbaa[xhci_dev->slot_id] = addr_to_phys(dctx);
    150         memset(dctx, 0, sizeof(xhci_device_ctx_t));
     130                goto err_ds;
     131        }
     132        rh->hc->dcbaa[xhci_dev->slot_id] = addr_to_phys(xhci_dev->dev_ctx);
     133        memset(xhci_dev->dev_ctx, 0, sizeof(xhci_device_ctx_t));
    151134
    152135        /* Address device */
    153         if ((err = hc_address_device(rh->hc, xhci_dev->slot_id, ictx)) != EOK)
     136        if ((err = hc_address_rh_device(rh->hc, xhci_dev->slot_id, dev->port, &ep_ctx)))
    154137                goto err_dctx;
    155         dev->address = XHCI_SLOT_DEVICE_ADDRESS(dctx->slot_ctx);
     138        dev->address = XHCI_SLOT_DEVICE_ADDRESS(xhci_dev->dev_ctx->slot_ctx);
    156139        usb_log_debug2("Obtained USB address: %d.\n", dev->address);
    157140
     
    178161        }
    179162
    180         free32(ictx);
    181163        return EOK;
    182164
    183165err_dctx:
    184         free32(dctx);
     166        free32(xhci_dev->dev_ctx);
    185167        rh->hc->dcbaa[xhci_dev->slot_id] = 0;
     168err_ds:
     169        xhci_endpoint_free_transfer_ds(ep0);
    186170err_ep:
    187171        xhci_endpoint_fini(ep0);
    188172        free(ep0);
    189 err_ictx:
    190         free32(ictx);
    191173        return err;
    192174}
     
    316298
    317299        /* TODO: Figure out how to handle errors here. So far, they are reported and skipped. */
     300        /* TODO: Move parts of the code below to xhci_bus_remove_device() */
    318301
    319302        /* Make DDF (and all drivers) forget about the device. */
     
    323306        }
    324307
    325         // TODO: Remove EP0.
    326         // TODO: Deconfigure device.
     308        /* Unregister EP0. */
     309        if ((err = bus_unregister_endpoint(&rh->hc->bus.base, &dev->endpoints[0]->base))) {
     310                usb_log_warning("Failed to unregister configuration endpoint of device '%s' from XHCI bus: %s",
     311                    ddf_fun_get_name(dev->base.fun), str_error(err));
     312        }
     313
     314        /* Deconfigure device. */
     315        if ((err = hc_deconfigure_device(rh->hc, dev->slot_id))) {
     316                usb_log_warning("Failed to deconfigure detached device '%s': %s",
     317                    ddf_fun_get_name(dev->base.fun), str_error(err));
     318        }
     319
     320        /* TODO: Free EP0 structures. */
     321        /* TODO: Destroy EP0 by removing its last reference. */
    327322
    328323        /* Remove device from XHCI bus. */
Note: See TracChangeset for help on using the changeset viewer.