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


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

    r7010861 r8b8c164  
    9696        endpoint_add_ref(ep0_base);
    9797
    98         ep0_base->device = &dev->base;
    9998        xhci_endpoint_t *ep0 = xhci_endpoint_get(ep0_base);
    10099
     
    102101                goto err_ep;
    103102
     103        /* Register EP0 */
     104        if ((err = xhci_device_add_endpoint(dev, ep0)))
     105                goto err_prepared;
     106
    104107        /* Address device */
    105108        if ((err = hc_address_device(hc, dev, ep0)))
    106                 goto err_prepared_ep;
    107 
    108         /* Register EP0, passing Temporary reference */
    109         dev->endpoints[0] = ep0;
    110 
    111         return EOK;
    112 
    113 err_prepared_ep:
     109                goto err_added;
     110
     111        /* Temporary reference */
     112        endpoint_del_ref(ep0_base);
     113        return EOK;
     114
     115err_added:
     116        xhci_device_remove_endpoint(ep0);
     117err_prepared:
    114118        xhci_endpoint_free_transfer_ds(ep0);
    115119err_ep:
     120        /* Temporary reference */
    116121        endpoint_del_ref(ep0_base);
    117122err_slot:
     
    251256}
    252257
    253 static int register_endpoint(bus_t *bus_base, endpoint_t *ep, const usb_endpoint_desc_t *desc)
     258static int register_endpoint(bus_t *bus_base, device_t *device, endpoint_t *ep_base, const usb_endpoint_desc_t *desc)
    254259{
    255260        int err;
    256261        xhci_bus_t *bus = bus_to_xhci_bus(bus_base);
    257         assert(bus);
    258 
    259         assert(ep->device);
    260 
    261         xhci_device_t *xhci_dev = xhci_device_get(ep->device);
    262         xhci_endpoint_t *xhci_ep = xhci_endpoint_get(ep);
    263 
    264         if ((err = prepare_endpoint(xhci_ep, desc)))
     262        xhci_endpoint_t *ep = xhci_endpoint_get(ep_base);
     263
     264        xhci_device_t *dev = xhci_device_get(device);
     265
     266        if ((err = prepare_endpoint(ep, desc)))
    265267                return err;
    266268
    267         usb_log_info("Endpoint(%d:%d) registered to XHCI bus.", ep->device->address, ep->endpoint);
    268         return xhci_device_add_endpoint(bus->hc, xhci_dev, xhci_ep);
    269 }
    270 
    271 static int unregister_endpoint(bus_t *bus_base, endpoint_t *ep)
    272 {
     269        if ((err = xhci_device_add_endpoint(dev, ep)))
     270                goto err_prepared;
     271
     272        usb_log_info("Endpoint(%d:%d) registered to XHCI bus.", dev->base.address, ep->base.endpoint);
     273
     274        xhci_ep_ctx_t ep_ctx;
     275        xhci_setup_endpoint_context(ep, &ep_ctx);
     276
     277        if ((err = hc_add_endpoint(bus->hc, dev->slot_id, xhci_endpoint_index(ep), &ep_ctx)))
     278                goto err_added;
     279
     280        return EOK;
     281
     282err_added:
     283        xhci_device_remove_endpoint(ep);
     284err_prepared:
     285        xhci_endpoint_free_transfer_ds(ep);
     286        return err;
     287}
     288
     289static int unregister_endpoint(bus_t *bus_base, endpoint_t *ep_base)
     290{
     291        int err;
    273292        xhci_bus_t *bus = bus_to_xhci_bus(bus_base);
    274         assert(bus);
    275 
    276         usb_log_info("Endpoint(%d:%d) unregistered from XHCI bus.", ep->device->address, ep->endpoint);
    277 
    278         xhci_device_t *xhci_dev = xhci_device_get(ep->device);
    279         xhci_endpoint_t *xhci_ep = xhci_endpoint_get(ep);
    280         const int res = xhci_device_remove_endpoint(bus->hc, xhci_dev, xhci_ep);
    281         if (res != EOK)
    282                 return res;
     293        xhci_endpoint_t *ep = xhci_endpoint_get(ep_base);
     294        xhci_device_t *dev = xhci_device_get(ep_base->device);
     295
     296        usb_log_info("Endpoint(%d:%d) unregistered from XHCI bus.", dev->base.address, ep->base.endpoint);
     297
     298        xhci_device_remove_endpoint(ep);
     299
     300        /* Drop the endpoint. */
     301        if ((err = hc_drop_endpoint(bus->hc, dev->slot_id, xhci_endpoint_index(ep)))) {
     302                usb_log_error("Failed to drop endpoint: %s", str_error(err));
     303        }
     304
     305        /* Tear down TRB ring / PSA. */
     306        /* TODO: Make this method "noexcept" */
     307        if ((err = xhci_endpoint_free_transfer_ds(ep))) {
     308                usb_log_error("Failed to free resources of an endpoint.");
     309        }
    283310
    284311        return EOK;
Note: See TracChangeset for help on using the changeset viewer.