Changeset 8b8c164 in mainline for uspace/drv/bus/usb/xhci/endpoint.c


Ignore:
Timestamp:
2017-10-27T15:22:06Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade
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/drv/bus/usb/xhci/endpoint.c

    r7010861 r8b8c164  
    189189{
    190190
    191         usb_log_debug2("Allocating main transfer ring for endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
     191        usb_log_debug2("Allocating main transfer ring for endpoint %u", xhci_ep->base.endpoint);
    192192
    193193        xhci_ep->primary_stream_ctx_array = NULL;
     
    323323}
    324324
    325 int xhci_device_add_endpoint(xhci_hc_t *hc, xhci_device_t *dev, xhci_endpoint_t *ep)
     325int xhci_device_add_endpoint(xhci_device_t *dev, xhci_endpoint_t *ep)
    326326{
    327327        assert(dev);
     
    329329
    330330        /* Offline devices don't create new endpoints other than EP0. */
    331         if (!dev->online) {
     331        if (!dev->online && ep->base.endpoint > 0) {
    332332                return EAGAIN;
    333333        }
     
    335335        const usb_endpoint_t ep_num = ep->base.endpoint;
    336336
    337         assert(&dev->base == ep->base.device);
    338 
    339         // TODO Do not fail hard on runtime conditions
    340         assert(!dev->endpoints[ep_num]);
     337        if (dev->endpoints[ep_num])
     338                return EEXIST;
     339
     340        /* Device reference */
     341        endpoint_add_ref(&ep->base);
     342        ep->base.device = &dev->base;
    341343
    342344        dev->endpoints[ep_num] = ep;
    343345        ++dev->active_endpoint_count;
    344346
    345         if (ep_num == 0) {
    346                 /* EP 0 is initialized while setting up the device,
    347                  * so we must not issue the command now. */
    348                 return EOK;
    349         }
    350 
    351         /* Add endpoint. */
    352         xhci_ep_ctx_t ep_ctx;
    353         xhci_setup_endpoint_context(ep, &ep_ctx);
    354 
    355         return hc_add_endpoint(hc, dev->slot_id, xhci_endpoint_index(ep), &ep_ctx);
    356 }
    357 
    358 int xhci_device_remove_endpoint(xhci_hc_t *hc, xhci_device_t *dev, xhci_endpoint_t *ep)
    359 {
    360         assert(&dev->base == ep->base.device);
     347        return EOK;
     348}
     349
     350void xhci_device_remove_endpoint(xhci_endpoint_t *ep)
     351{
     352        assert(ep);
     353        xhci_device_t *dev = xhci_device_get(ep->base.device);
     354
    361355        assert(dev->endpoints[ep->base.endpoint]);
    362 
    363         int err = ENOMEM;
    364         const usb_endpoint_t ep_num = ep->base.endpoint;
    365356
    366357        dev->endpoints[ep->base.endpoint] = NULL;
    367358        --dev->active_endpoint_count;
    368 
    369         if (ep_num == 0) {
    370                 /* EP 0 is finalized while releasing the device,
    371                  * so we must not issue the command now. */
    372                 return EOK;
    373         }
    374 
    375         /* Drop the endpoint. */
    376         if ((err = hc_drop_endpoint(hc, dev->slot_id, xhci_endpoint_index(ep)))) {
    377                 goto err;
    378         }
    379 
    380         /* Tear down TRB ring / PSA. */
    381         /* FIXME: For some reason, this causes crash at xhci_trb_ring_fini.
    382         if ((err = xhci_endpoint_free_transfer_ds(ep))) {
    383                 goto err_cmd;
    384         }
    385         */
    386 
    387         return EOK;
    388 
    389 err:
    390         dev->endpoints[ep_num] = ep;
    391         ++dev->active_endpoint_count;
    392         return err;
     359        ep->base.device = NULL;
     360
     361        endpoint_del_ref(&ep->base);
    393362}
    394363
Note: See TracChangeset for help on using the changeset viewer.