Changeset 89cefe78 in mainline


Ignore:
Timestamp:
2017-10-22T21:47:55Z (6 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
82fe063
Parents:
ee794529
Message:

Refactored transfer DS allocation in preparation for streams. Also, converted EP context setup to table.

Location:
uspace/drv/bus/usb/xhci
Files:
3 edited

Legend:

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

    ree794529 r89cefe78  
    5454        endpoint_init(ep, bus);
    5555
    56         return xhci_trb_ring_init(&xhci_ep->ring);
     56        return EOK;
    5757}
    5858
     
    6161        assert(xhci_ep);
    6262
    63         /* FIXME: Tear down TR's? */
    64         xhci_trb_ring_fini(&xhci_ep->ring);
     63        // TODO: Something missed?
     64}
     65
     66int xhci_endpoint_alloc_transfer_ds(xhci_endpoint_t *xhci_ep)
     67{
     68        int err;
     69
     70        if (xhci_ep->max_streams > 0) {
     71                // Set up primary stream context array if needed.
     72                xhci_ep->primary_stream_ctx_array = malloc32(xhci_ep->max_streams * sizeof(xhci_stream_ctx_t));
     73                if (!xhci_ep->primary_stream_ctx_array) {
     74                        return ENOMEM;
     75                }
     76                memset(xhci_ep->primary_stream_ctx_array, 0, xhci_ep->max_streams * sizeof(xhci_stream_ctx_t));
     77        } else {
     78                xhci_ep->primary_stream_ctx_array = NULL;
     79                if ((err = xhci_trb_ring_init(&xhci_ep->ring))) {
     80                        return err;
     81                }
     82        }
     83
     84        return EOK;
     85}
     86
     87int xhci_endpoint_free_transfer_ds(xhci_endpoint_t *xhci_ep)
     88{
     89        int err;
     90
     91        if (xhci_ep->max_streams > 0) {
     92                // TODO: What about secondaries?
     93                free32(xhci_ep->primary_stream_ctx_array);
     94        } else {
     95                if ((err = xhci_trb_ring_fini(&xhci_ep->ring))) {
     96                        return err;
     97                }
     98        }
     99
     100        return EOK;
    65101}
    66102
     
    113149}
    114150
    115 static void setup_control_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx,
    116         xhci_trb_ring_t *ring)
     151static void setup_control_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx)
    117152{
    118153        // EP0 is configured elsewhere.
     
    122157        XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size);
    123158        XHCI_EP_ERROR_COUNT_SET(*ctx, 3);
    124         XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue);
     159        XHCI_EP_TR_DPTR_SET(*ctx, ep->ring.dequeue);
    125160        XHCI_EP_DCS_SET(*ctx, 1);
    126161}
    127162
    128 static void setup_bulk_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx,
    129         xhci_trb_ring_t *ring, usb_superspeed_endpoint_companion_descriptor_t *ss_desc)
     163static void setup_bulk_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx)
    130164{
    131165        XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(ep));
    132166        XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size);
    133167        XHCI_EP_MAX_BURST_SIZE_SET(*ctx,
    134             xhci_device_get(ep->base.device)->usb3 ? ss_desc->max_burst : 0);
     168            xhci_device_get(ep->base.device)->usb3 ? ep->max_burst : 0);
    135169        XHCI_EP_ERROR_COUNT_SET(*ctx, 3);
    136170
    137         // FIXME: Get maxStreams and other things from ss_desc
    138         const uint8_t maxStreams = 0;
    139         if (maxStreams > 0) {
    140                 // TODO: allocate and clear primary stream array
    141                 // TODO: XHCI_EP_MAX_P_STREAMS_SET(ctx, psa_size);
    142                 // TODO: XHCI_EP_TR_DPTR_SET(ctx, psa_start_phys_addr);
     171        if (ep->max_streams > 0) {
     172                XHCI_EP_MAX_P_STREAMS_SET(*ctx, ep->max_streams);
     173                XHCI_EP_TR_DPTR_SET(*ctx, addr_to_phys(ep->primary_stream_ctx_array));
    143174                // TODO: set HID
    144175                // TODO: set LSA
    145176        } else {
    146177                XHCI_EP_MAX_P_STREAMS_SET(*ctx, 0);
    147                 XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue);
     178                XHCI_EP_TR_DPTR_SET(*ctx, ep->ring.dequeue);
    148179                XHCI_EP_DCS_SET(*ctx, 1);
    149180        }
    150181}
    151182
    152 static void setup_isoch_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx,
    153         xhci_trb_ring_t *ring, usb_superspeed_endpoint_companion_descriptor_t *ss_desc)
     183static void setup_isoch_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx)
    154184{
    155185        XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(ep));
    156186        XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size & 0x07FF);
    157         XHCI_EP_MAX_BURST_SIZE_SET(*ctx, ss_desc->max_burst);
    158         // FIXME: get Mult field from SS companion descriptor somehow
    159         XHCI_EP_MULT_SET(*ctx, 0);
     187        XHCI_EP_MAX_BURST_SIZE_SET(*ctx, ep->max_burst);
     188        XHCI_EP_MULT_SET(*ctx, ep->mult);
    160189        XHCI_EP_ERROR_COUNT_SET(*ctx, 0);
    161         XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue);
     190        XHCI_EP_TR_DPTR_SET(*ctx, ep->ring.dequeue);
    162191        XHCI_EP_DCS_SET(*ctx, 1);
    163192        // TODO: max ESIT payload
    164193}
    165194
    166 static void setup_interrupt_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx,
    167         xhci_trb_ring_t *ring, usb_superspeed_endpoint_companion_descriptor_t *ss_desc)
     195static void setup_interrupt_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx)
    168196{
    169197        XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(ep));
    170198        XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size & 0x07FF);
    171         XHCI_EP_MAX_BURST_SIZE_SET(*ctx, ss_desc->max_burst);
     199        XHCI_EP_MAX_BURST_SIZE_SET(*ctx, ep->max_burst);
    172200        XHCI_EP_MULT_SET(*ctx, 0);
    173201        XHCI_EP_ERROR_COUNT_SET(*ctx, 3);
    174         XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue);
     202        XHCI_EP_TR_DPTR_SET(*ctx, ep->ring.dequeue);
    175203        XHCI_EP_DCS_SET(*ctx, 1);
    176204        // TODO: max ESIT payload
    177205}
     206
     207typedef void (*setup_ep_ctx_helper)(xhci_endpoint_t *, xhci_ep_ctx_t *);
     208
     209static const setup_ep_ctx_helper setup_ep_ctx_helpers[] = {
     210        [USB_TRANSFER_CONTROL] = setup_control_ep_ctx,
     211        [USB_TRANSFER_ISOCHRONOUS] = setup_isoch_ep_ctx,
     212        [USB_TRANSFER_BULK] = setup_bulk_ep_ctx,
     213        [USB_TRANSFER_INTERRUPT] = setup_interrupt_ep_ctx,
     214};
    178215
    179216int xhci_device_add_endpoint(xhci_device_t *dev, xhci_endpoint_t *ep)
     
    202239                return EOK;
    203240
    204         // FIXME: Retrieve this from somewhere, if applicable.
    205         usb_superspeed_endpoint_companion_descriptor_t ss_desc;
    206         memset(&ss_desc, 0, sizeof(ss_desc));
     241        // FIXME: Set these from usb_superspeed_endpoint_companion_descriptor_t:
     242        ep->max_streams = 0;
     243        ep->max_burst = 0;
     244        ep->mult = 0;
     245
     246        xhci_endpoint_alloc_transfer_ds(ep);
    207247
    208248        // Prepare input context.
     
    222262        XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */
    223263
    224         xhci_trb_ring_t *ep_ring = &ep->ring;
    225264        xhci_ep_ctx_t *ep_ctx = &ictx->endpoint_ctx[ep_idx];
    226 
    227         // TODO: Convert to table
    228         switch (ep->base.transfer_type) {
    229         case USB_TRANSFER_CONTROL:
    230                 setup_control_ep_ctx(ep, ep_ctx, ep_ring);
    231                 break;
    232 
    233         case USB_TRANSFER_BULK:
    234                 setup_bulk_ep_ctx(ep, ep_ctx, ep_ring, &ss_desc);
    235                 break;
    236 
    237         case USB_TRANSFER_ISOCHRONOUS:
    238                 setup_isoch_ep_ctx(ep, ep_ctx, ep_ring, &ss_desc);
    239                 break;
    240 
    241         case USB_TRANSFER_INTERRUPT:
    242                 setup_interrupt_ep_ctx(ep, ep_ctx, ep_ring, &ss_desc);
    243                 break;
    244         }
     265        setup_ep_ctx_helpers[ep->base.transfer_type](ep, ep_ctx);
    245266
    246267        // Issue configure endpoint command (sec 4.3.5).
     
    274295        // TODO: Issue configure endpoint command to drop this endpoint.
    275296
     297        // FIXME: Ignoring return code.
     298        xhci_endpoint_free_transfer_ds(ep);
     299
    276300        dev->endpoints[ep->base.target.endpoint] = NULL;
    277301        --dev->active_endpoint_count;
  • uspace/drv/bus/usb/xhci/endpoint.h

    ree794529 r89cefe78  
    6565        endpoint_t base;        /**< Inheritance. Keep this first. */
    6666
    67         /** Main TRB ring */
     67        /** Main TRB ring (or NULL if endpoint uses streams) */
    6868        xhci_trb_ring_t ring;
    6969
     
    7272         * endpoint_t */
    7373        xhci_transfer_t active_transfer;
     74
     75        /** Primary stream context array (or NULL if endpoint doesn't use streams) */
     76        xhci_stream_ctx_t *primary_stream_ctx_array;
     77
     78        /** Maximum number of streams, also a valid range of PSCA above */
     79        uint16_t max_streams;
     80
     81        /* FIXME: Figure out type for these two fields. */
     82        uint8_t max_burst;
     83        uint8_t mult;
    7484} xhci_endpoint_t;
    7585
     
    101111int xhci_endpoint_init(xhci_endpoint_t *, xhci_bus_t *);
    102112void xhci_endpoint_fini(xhci_endpoint_t *);
     113int xhci_endpoint_alloc_transfer_ds(xhci_endpoint_t *);
     114int xhci_endpoint_free_transfer_ds(xhci_endpoint_t *);
    103115
    104116uint8_t xhci_endpoint_dci(xhci_endpoint_t *);
  • uspace/drv/bus/usb/xhci/rh.c

    ree794529 r89cefe78  
    129129                goto err_ictx;
    130130        xhci_endpoint_t *ep0 = xhci_endpoint_get(ep0_base);
     131
     132        /* Control endpoints don't use streams. */
     133        /* FIXME: Sync this with xhci_device_add_endpoint. */
     134        ep0->max_streams = 0;
     135        ep0->max_burst = 0;
     136        ep0->mult = 0;
     137        if ((err = xhci_endpoint_alloc_transfer_ds(ep0)))
     138                goto err_ictx;
     139
    131140        setup_control_ep0_ctx(&ictx->endpoint_ctx[0], &ep0->ring, speed);
    132141
Note: See TracChangeset for help on using the changeset viewer.