Changeset 51c1d500 in mainline for uspace/drv/bus/usb/xhci/endpoint.c


Ignore:
Timestamp:
2018-01-20T17:16:33Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6271a34
Parents:
abb5d08
Message:

xhci: move HC semantics from endpoint/device to hc module

File:
1 edited

Legend:

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

    rabb5d08 r51c1d500  
    172172        int err;
    173173        xhci_endpoint_t *ep = xhci_endpoint_get(ep_base);
    174         xhci_device_t *dev = xhci_device_get(ep_base->device);
    175 
    176         xhci_ep_ctx_t ep_ctx;
    177         xhci_setup_endpoint_context(ep, &ep_ctx);
    178 
    179         if ((err = hc_add_endpoint(dev, xhci_endpoint_index(ep), &ep_ctx)))
     174
     175        if ((err = hc_add_endpoint(ep)))
    180176                return err;
    181177
     
    189185{
    190186        xhci_device_t *dev = xhci_device_get(ep->device);
     187        xhci_endpoint_t *xhci_ep = xhci_endpoint_get(ep);
    191188
    192189        usb_transfer_batch_t *batch = NULL;
     
    194191        if (ep->active_batch) {
    195192                if (dev->slot_id) {
    196                         const int err = hc_stop_endpoint(dev, xhci_endpoint_dci(xhci_endpoint_get(ep)));
     193                        const int err = hc_stop_endpoint(xhci_ep);
    197194                        if (err) {
    198195                                usb_log_warning("Failed to stop endpoint %u of device " XHCI_DEV_FMT ": %s",
     
    235232        if (dev->slot_id) {
    236233
    237                 if ((err = hc_drop_endpoint(dev, xhci_endpoint_index(ep)))) {
     234                if ((err = hc_drop_endpoint(ep))) {
    238235                        usb_log_error("Failed to drop endpoint " XHCI_EP_FMT ": %s", XHCI_EP_ARGS(*ep), str_error(err));
    239236                }
     
    318315}
    319316
    320 /** See section 4.5.1 of the xHCI spec.
    321  */
    322 uint8_t xhci_endpoint_dci(xhci_endpoint_t *ep)
    323 {
    324         return (2 * ep->base.endpoint) +
    325                 (ep->base.transfer_type == USB_TRANSFER_CONTROL
    326                  || ep->base.direction == USB_DIRECTION_IN);
    327 }
    328 
    329 /** Return an index to the endpoint array. The indices are assigned as follows:
    330  * 0    EP0 BOTH
    331  * 1    EP1 OUT
    332  * 2    EP1 IN
    333  *
    334  * For control endpoints >0, the IN endpoint index is used.
    335  *
    336  * The index returned must be usually offset by a number of contexts preceding
    337  * the endpoint contexts themselves.
    338  */
    339 uint8_t xhci_endpoint_index(xhci_endpoint_t *ep)
    340 {
    341         return xhci_endpoint_dci(ep) - 1;
     317xhci_trb_ring_t *xhci_endpoint_get_ring(xhci_endpoint_t *ep, uint32_t stream_id)
     318{
     319        if (ep->primary_stream_data_size == 0)
     320                return stream_id == 0 ? &ep->ring : NULL;
     321
     322        xhci_stream_data_t *stream_data = xhci_get_stream_ctx_data(ep, stream_id);
     323        if (stream_data == NULL) {
     324                usb_log_warning("No transfer ring was found for stream %u.", stream_id);
     325                return NULL;
     326        }
     327
     328        return &stream_data->ring;
    342329}
    343330
     
    435422}
    436423
    437 uint8_t xhci_endpoint_get_state(xhci_endpoint_t *ep)
    438 {
    439         assert(ep);
    440 
    441         xhci_device_t *dev = xhci_device_get(ep->base.device);
    442         if (!dev->slot_id)
    443                 return EP_STATE_DISABLED;
    444 
    445         unsigned idx = xhci_endpoint_index(ep);
    446         xhci_device_ctx_t *ctx = dev->dev_ctx.virt;
    447         const xhci_hc_t * hc = bus_to_hc(dev->base.bus);
    448         xhci_ep_ctx_t *ep_ctx = XHCI_GET_EP_CTX(ctx, hc, idx);
    449 
    450         return XHCI_EP_STATE(*ep_ctx);
    451 }
    452 
    453424/**
    454425 * Clear endpoint halt condition by resetting the endpoint and skipping the
    455426 * offending transfer.
    456427 */
    457 int xhci_endpoint_clear_halt(xhci_endpoint_t *ep, unsigned stream_id)
     428int xhci_endpoint_clear_halt(xhci_endpoint_t *ep, uint32_t stream_id)
    458429{
    459430        int err;
    460431
    461         xhci_device_t * const dev = xhci_device_get(ep->base.device);
    462         xhci_bus_t * const bus = bus_to_xhci_bus(dev->base.bus);
    463         xhci_hc_t * const hc = bus->hc;
    464 
    465         const unsigned slot_id = dev->slot_id;
    466         const unsigned dci = xhci_endpoint_dci(ep);
    467 
    468         if ((err = hc_reset_endpoint(dev, dci)))
     432        if ((err = hc_reset_endpoint(ep)))
    469433                return err;
    470434
    471         uintptr_t addr;
    472 
    473         xhci_trb_ring_reset_dequeue_state(&ep->ring, &addr);
    474 
    475         if ((err = xhci_cmd_sync_inline(hc, SET_TR_DEQUEUE_POINTER,
    476                             .slot_id = slot_id,
    477                             .endpoint_id = dci,
    478                             .stream_id = stream_id,
    479                             .dequeue_ptr = addr,
    480                         )))
     435        if ((err = hc_reset_ring(ep, stream_id)))
    481436                return err;
    482437
Note: See TracChangeset for help on using the changeset viewer.