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


Ignore:
Timestamp:
2017-10-17T10:09:40Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
95c675b
Parents:
bb784ae
Message:

xhci: cleanup

And by the way… the USB mouse is now working :)

File:
1 edited

Legend:

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

    rbb784ae rdbf32b1  
    8181}
    8282
    83 uint8_t xhci_endpoint_ctx_offset(xhci_endpoint_t *ep)
    84 {
    85         /* 0 is slot ctx, 1 is EP0, then it's EP1 out, in, EP2 out, in, etc. */
    86 
    87         uint8_t off = 2 * (ep->base.target.endpoint);
    88         if (ep->base.direction == USB_DIRECTION_IN || ep->base.target.endpoint == 0)
    89                 ++off;
    90 
    91         return off;
     83/** Return an index to the endpoint array. The indices are assigned as follows:
     84 * 0    EP0 BOTH
     85 * 1    EP1 OUT
     86 * 2    EP1 IN
     87 *
     88 * For control endpoints >0, the IN endpoint index is used.
     89 *
     90 * The index returned must be usually offset by a number of contexts preceding
     91 * the endpoint contexts themselves.
     92 */
     93uint8_t xhci_endpoint_index(xhci_endpoint_t *ep)
     94{
     95        return  (2 * ep->base.target.endpoint)
     96            - (ep->base.direction == USB_DIRECTION_OUT);
    9297}
    9398
     
    211216                XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 0);
    212217
    213                 const uint8_t ep_offset = xhci_endpoint_ctx_offset(ep);
    214                 XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, ep_offset);
     218                const uint8_t ep_idx = xhci_endpoint_index(ep);
     219                XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */
    215220
    216221                ep_ring = malloc(sizeof(xhci_trb_ring_t));
     
    227232                switch (ep->base.transfer_type) {
    228233                case USB_TRANSFER_CONTROL:
    229                         setup_control_ep_ctx(ep, &ictx->endpoint_ctx[ep_offset - 1], ep_ring);
     234                        setup_control_ep_ctx(ep, &ictx->endpoint_ctx[ep_idx], ep_ring);
    230235                        break;
    231236
    232237                case USB_TRANSFER_BULK:
    233                         setup_bulk_ep_ctx(ep, &ictx->endpoint_ctx[ep_offset - 1], ep_ring, &ss_desc);
     238                        setup_bulk_ep_ctx(ep, &ictx->endpoint_ctx[ep_idx], ep_ring, &ss_desc);
    234239                        break;
    235240
    236241                case USB_TRANSFER_ISOCHRONOUS:
    237                         setup_isoch_ep_ctx(ep, &ictx->endpoint_ctx[ep_offset - 1], ep_ring, &ss_desc);
     242                        setup_isoch_ep_ctx(ep, &ictx->endpoint_ctx[ep_idx], ep_ring, &ss_desc);
    238243                        break;
    239244
    240245                case USB_TRANSFER_INTERRUPT:
    241                         setup_interrupt_ep_ctx(ep, &ictx->endpoint_ctx[ep_offset - 1], ep_ring, &ss_desc);
     246                        setup_interrupt_ep_ctx(ep, &ictx->endpoint_ctx[ep_idx], ep_ring, &ss_desc);
    242247                        break;
    243248
Note: See TracChangeset for help on using the changeset viewer.