Changeset a4e7e6e1 in mainline


Ignore:
Timestamp:
2018-01-19T15:25:20Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
861b5d6
Parents:
c7d5189
Message:

xhci: setup also slot context where needed

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

Legend:

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

    rc7d5189 ra4e7e6e1  
    8787
    8888        /* Address device */
    89         if ((err = hc_address_device(bus->hc, dev, ep0)))
     89        if ((err = hc_address_device(dev, ep0)))
    9090                goto err_added;
    9191
     
    128128        xhci_setup_endpoint_context(ep0, &ep_ctx);
    129129
    130         if ((err = hc_update_endpoint(hc, dev->slot_id, 0, &ep_ctx)))
     130        if ((err = hc_update_endpoint(dev, 0, &ep_ctx)))
    131131                return err;
    132132
     
    238238
    239239        /* Transition the device from the Addressed to the Configured state. */
    240         if ((err = hc_configure_device(bus->hc, dev->slot_id))) {
     240        if ((err = hc_configure_device(dev))) {
    241241                usb_log_warning("Failed to configure device " XHCI_DEV_FMT ".", XHCI_DEV_ARGS(*dev));
    242242                return err;
     
    263263
    264264        /* Issue one HC command to simultaneously drop all endpoints except zero. */
    265         if ((err = hc_deconfigure_device(bus->hc, dev->slot_id))) {
     265        if ((err = hc_deconfigure_device(dev))) {
    266266                usb_log_warning("Failed to deconfigure device " XHCI_DEV_FMT ".",
    267267                    XHCI_DEV_ARGS(*dev));
     
    312312{
    313313        int err;
    314         xhci_bus_t *bus = bus_to_xhci_bus(endpoint_get_bus(ep_base));
    315314        xhci_endpoint_t *ep = xhci_endpoint_get(ep_base);
    316315        xhci_device_t *dev = xhci_device_get(ep_base->device);
     
    319318        xhci_setup_endpoint_context(ep, &ep_ctx);
    320319
    321         if ((err = hc_add_endpoint(bus->hc, dev->slot_id, xhci_endpoint_index(ep), &ep_ctx)))
     320        if ((err = hc_add_endpoint(dev, xhci_endpoint_index(ep), &ep_ctx)))
    322321                return err;
    323322
     
    330329static int endpoint_abort(endpoint_t *ep)
    331330{
    332         xhci_bus_t *bus = bus_to_xhci_bus(endpoint_get_bus(ep));
    333331        xhci_device_t *dev = xhci_device_get(ep->device);
    334332
     
    337335        if (ep->active_batch) {
    338336                if (dev->slot_id) {
    339                         const int err = hc_stop_endpoint(bus->hc, dev->slot_id, xhci_endpoint_dci(xhci_endpoint_get(ep)));
     337                        const int err = hc_stop_endpoint(dev, xhci_endpoint_dci(xhci_endpoint_get(ep)));
    340338                        if (err) {
    341339                                usb_log_warning("Failed to stop endpoint %u of device " XHCI_DEV_FMT ": %s",
     
    370368{
    371369        int err;
    372         xhci_bus_t *bus = bus_to_xhci_bus(endpoint_get_bus(ep_base));
    373370        xhci_endpoint_t *ep = xhci_endpoint_get(ep_base);
    374371        xhci_device_t *dev = xhci_device_get(ep_base->device);
     
    379376        if (dev->slot_id) {
    380377
    381                 if ((err = hc_drop_endpoint(bus->hc, dev->slot_id, xhci_endpoint_index(ep)))) {
     378                if ((err = hc_drop_endpoint(dev, xhci_endpoint_index(ep)))) {
    382379                        usb_log_error("Failed to drop endpoint " XHCI_EP_FMT ": %s", XHCI_EP_ARGS(*ep), str_error(err));
    383380                }
  • uspace/drv/bus/usb/xhci/endpoint.c

    rc7d5189 ra4e7e6e1  
    346346        const unsigned dci = xhci_endpoint_dci(ep);
    347347
    348         if ((err = hc_reset_endpoint(hc, slot_id, dci)))
     348        if ((err = hc_reset_endpoint(dev, dci)))
    349349                return err;
    350350
  • uspace/drv/bus/usb/xhci/hc.c

    rc7d5189 ra4e7e6e1  
    764764
    765765/**
     766 * Fill a slot context that is part of an Input Context with appropriate
     767 * values.
     768 *
     769 * @param ctx Slot context, zeroed out.
     770 */
     771static void xhci_setup_slot_context(xhci_device_t *dev, xhci_slot_ctx_t *ctx)
     772{
     773        /* Initialize slot_ctx according to section 4.3.3 point 3. */
     774        XHCI_SLOT_ROOT_HUB_PORT_SET(*ctx, dev->rh_port);
     775        XHCI_SLOT_CTX_ENTRIES_SET(*ctx, 1);
     776        XHCI_SLOT_ROUTE_STRING_SET(*ctx, dev->route_str);
     777        XHCI_SLOT_SPEED_SET(*ctx, usb_speed_to_psiv[dev->base.speed]);
     778
     779        /* Setup Transaction Translation. TODO: Test this with HS hub. */
     780        if (dev->base.tt.dev != NULL) {
     781                xhci_device_t *hub = xhci_device_get(dev->base.tt.dev);
     782                XHCI_SLOT_TT_HUB_SLOT_ID_SET(*ctx, hub->slot_id);
     783                XHCI_SLOT_TT_HUB_PORT_SET(*ctx, dev->base.tt.port);
     784        }
     785
     786        // As we always allocate space for whole input context, we can set this to maximum
     787        XHCI_SLOT_CTX_ENTRIES_SET(*ctx, 31);
     788}
     789
     790/**
    766791 * Prepare an empty Endpoint Input Context inside a dma buffer.
    767792 */
    768 static int create_configure_ep_input_ctx(dma_buffer_t *dma_buf)
     793static int create_configure_ep_input_ctx(xhci_device_t *dev, dma_buffer_t *dma_buf)
    769794{
    770795        const int err = dma_buffer_alloc(dma_buf, sizeof(xhci_input_ctx_t));
     
    777802        // Quoting sec. 4.6.5 and 4.6.6: A1, D0, D1 are down (already zeroed), A0 is up.
    778803        XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 0);
    779 
    780         // As we always allocate space for whole input context, we can set this to maximum
    781         XHCI_SLOT_CTX_ENTRIES_SET(ictx->slot_ctx, 31);
     804        xhci_setup_slot_context(dev, &ictx->slot_ctx);
    782805
    783806        return EOK;
     
    790813 * @param ep0 EP0 of device TODO remove, can be fetched from dev
    791814 */
    792 int hc_address_device(xhci_hc_t *hc, xhci_device_t *dev, xhci_endpoint_t *ep0)
     815int hc_address_device(xhci_device_t *dev, xhci_endpoint_t *ep0)
    793816{
    794817        int err = ENOMEM;
     818        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
    795819
    796820        /* Although we have the precise PSIV value on devices of tier 1,
     
    810834        /* Issue configure endpoint command (sec 4.3.5). */
    811835        dma_buffer_t ictx_dma_buf;
    812         if ((err = create_configure_ep_input_ctx(&ictx_dma_buf))) {
     836        if ((err = create_configure_ep_input_ctx(dev, &ictx_dma_buf))) {
    813837                goto err_dev_ctx;
    814838        }
    815839        xhci_input_ctx_t *ictx = ictx_dma_buf.virt;
    816 
    817         /* Initialize slot_ctx according to section 4.3.3 point 3. */
    818         XHCI_SLOT_ROOT_HUB_PORT_SET(ictx->slot_ctx, dev->rh_port);
    819         XHCI_SLOT_CTX_ENTRIES_SET(ictx->slot_ctx, 1);
    820         XHCI_SLOT_ROUTE_STRING_SET(ictx->slot_ctx, dev->route_str);
    821         XHCI_SLOT_SPEED_SET(ictx->slot_ctx, usb_speed_to_psiv[dev->base.speed]);
    822 
    823         /* Setup Transaction Translation. TODO: Test this with HS hub. */
    824         if (dev->base.tt.dev != NULL) {
    825                 xhci_device_t *hub = xhci_device_get(dev->base.tt.dev);
    826                 XHCI_SLOT_TT_HUB_SLOT_ID_SET(ictx->slot_ctx, hub->slot_id);
    827                 XHCI_SLOT_TT_HUB_PORT_SET(ictx->slot_ctx, dev->base.tt.port);
    828                 XHCI_SLOT_MTT_SET(ictx->slot_ctx, 0); // MTT not supported yet
    829         }
    830840
    831841        /* Copy endpoint 0 context and set A1 flag. */
     
    856866 * @param slot_id Slot ID assigned to the device.
    857867 */
    858 int hc_configure_device(xhci_hc_t *hc, uint32_t slot_id)
    859 {
     868int hc_configure_device(xhci_device_t *dev)
     869{
     870        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     871
    860872        /* Issue configure endpoint command (sec 4.3.5). */
    861873        dma_buffer_t ictx_dma_buf;
    862         const int err = create_configure_ep_input_ctx(&ictx_dma_buf);
     874        const int err = create_configure_ep_input_ctx(dev, &ictx_dma_buf);
    863875        if (err)
    864876                return err;
    865877
    866         // TODO: Set slot context and other flags. (probably forgot a lot of 'em)
    867 
    868         return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = slot_id, .input_ctx = ictx_dma_buf);
     878        return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf);
    869879}
    870880
     
    872882 * Issue a Deconfigure Device command for a device in slot.
    873883 *
    874  * @param slot_id Slot ID assigned to the device.
    875  */
    876 int hc_deconfigure_device(xhci_hc_t *hc, uint32_t slot_id)
    877 {
     884 * @param dev The owner of the device
     885 */
     886int hc_deconfigure_device(xhci_device_t *dev)
     887{
     888        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     889
    878890        /* Issue configure endpoint command (sec 4.3.5) with the DC flag. */
    879         return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = slot_id, .deconfigure = true);
     891        return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .deconfigure = true);
    880892}
    881893
     
    883895 * Instruct xHC to add an endpoint with supplied endpoint context.
    884896 *
    885  * @param slot_id Slot ID assigned to the device.
    886  * @param ep_idx Endpoint index (number + direction) in question
     897 * @param dev The owner of the device
     898 * @param ep_idx Endpoint DCI in question
    887899 * @param ep_ctx Endpoint context of the endpoint
    888900 */
    889 int hc_add_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx, xhci_ep_ctx_t *ep_ctx)
     901int hc_add_endpoint(xhci_device_t *dev, uint8_t ep_idx, xhci_ep_ctx_t *ep_ctx)
    890902{
    891903        /* Issue configure endpoint command (sec 4.3.5). */
    892904        dma_buffer_t ictx_dma_buf;
    893         const int err = create_configure_ep_input_ctx(&ictx_dma_buf);
     905        const int err = create_configure_ep_input_ctx(dev, &ictx_dma_buf);
    894906        if (err)
    895907                return err;
     
    899911        memcpy(&ictx->endpoint_ctx[ep_idx], ep_ctx, sizeof(xhci_ep_ctx_t));
    900912
    901         // TODO: Set slot context and other flags. (probably forgot a lot of 'em)
    902 
    903         return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = slot_id, .input_ctx = ictx_dma_buf);
     913        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     914        return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf);
    904915}
    905916
     
    907918 * Instruct xHC to drop an endpoint.
    908919 *
    909  * @param slot_id Slot ID assigned to the device.
    910  * @param ep_idx Endpoint index (number + direction) in question
    911  */
    912 int hc_drop_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx)
     920 * @param dev The owner of the endpoint
     921 * @param ep_idx Endpoint DCI in question
     922 */
     923int hc_drop_endpoint(xhci_device_t *dev, uint8_t ep_idx)
    913924{
    914925        /* Issue configure endpoint command (sec 4.3.5). */
    915926        dma_buffer_t ictx_dma_buf;
    916         const int err = create_configure_ep_input_ctx(&ictx_dma_buf);
     927        const int err = create_configure_ep_input_ctx(dev, &ictx_dma_buf);
    917928        if (err)
    918929                return err;
     
    920931        xhci_input_ctx_t *ictx = ictx_dma_buf.virt;
    921932        XHCI_INPUT_CTRL_CTX_DROP_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */
    922         // TODO: Set slot context and other flags. (probably forgot a lot of 'em)
    923 
    924         return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = slot_id, .input_ctx = ictx_dma_buf);
     933
     934        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     935        return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf);
    925936}
    926937
     
    929940 * endpoint context.
    930941 *
    931  * @param slot_id Slot ID assigned to the device.
    932  * @param ep_idx Endpoint index (number + direction) in question
     942 * @param dev The owner of the endpoint
     943 * @param ep_idx Endpoint DCI in question
    933944 * @param ep_ctx Endpoint context of the endpoint
    934945 */
    935 int hc_update_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx, xhci_ep_ctx_t *ep_ctx)
     946int hc_update_endpoint(xhci_device_t *dev, uint8_t ep_idx, xhci_ep_ctx_t *ep_ctx)
    936947{
    937948        dma_buffer_t ictx_dma_buf;
     
    946957        memcpy(&ictx->endpoint_ctx[ep_idx], ep_ctx, sizeof(xhci_ep_ctx_t));
    947958
    948         return xhci_cmd_sync_inline(hc, EVALUATE_CONTEXT, .slot_id = slot_id, .input_ctx = ictx_dma_buf);
     959        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     960        return xhci_cmd_sync_inline(hc, EVALUATE_CONTEXT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf);
    949961}
    950962
     
    952964 * Instruct xHC to stop running a transfer ring on an endpoint.
    953965 *
    954  * @param slot_id Slot ID assigned to the device.
    955  * @param ep_idx Endpoint index (number + direction) in question
    956  */
    957 int hc_stop_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx)
    958 {
    959         return xhci_cmd_sync_inline(hc, STOP_ENDPOINT, .slot_id = slot_id, .endpoint_id = ep_idx);
     966 * @param dev The owner of the endpoint
     967 * @param ep_idx Endpoint DCI in question
     968 */
     969int hc_stop_endpoint(xhci_device_t *dev, uint8_t ep_idx)
     970{
     971        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     972        return xhci_cmd_sync_inline(hc, STOP_ENDPOINT, .slot_id = dev->slot_id, .endpoint_id = ep_idx);
    960973}
    961974
     
    963976 * Instruct xHC to reset halted endpoint.
    964977 *
    965  * @param slot_id Slot ID assigned to the device.
    966  * @param ep_idx Endpoint index (number + direction) in question
    967  */
    968 int hc_reset_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx)
    969 {
    970         return xhci_cmd_sync_inline(hc, RESET_ENDPOINT, .slot_id = slot_id, .endpoint_id = ep_idx);
     978 * @param dev The owner of the endpoint
     979 * @param ep_idx Endpoint DCI in question
     980 */
     981int hc_reset_endpoint(xhci_device_t *dev, uint8_t ep_idx)
     982{
     983        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     984        return xhci_cmd_sync_inline(hc, RESET_ENDPOINT, .slot_id = dev->slot_id, .endpoint_id = ep_idx);
    971985}
    972986
  • uspace/drv/bus/usb/xhci/hc.h

    rc7d5189 ra4e7e6e1  
    120120void hc_fini(xhci_hc_t *);
    121121void hc_ring_doorbell(xhci_hc_t *, unsigned, unsigned);
     122
    122123int hc_enable_slot(xhci_hc_t *, uint32_t *);
    123124int hc_disable_slot(xhci_hc_t *, xhci_device_t *);
    124 int hc_address_device(xhci_hc_t *, xhci_device_t *, xhci_endpoint_t *);
    125 int hc_configure_device(xhci_hc_t *, uint32_t);
    126 int hc_deconfigure_device(xhci_hc_t *, uint32_t);
    127 int hc_add_endpoint(xhci_hc_t *, uint32_t, uint8_t, xhci_ep_ctx_t *);
    128 int hc_drop_endpoint(xhci_hc_t *, uint32_t, uint8_t);
    129 int hc_update_endpoint(xhci_hc_t *, uint32_t, uint8_t, xhci_ep_ctx_t *);
    130 int hc_stop_endpoint(xhci_hc_t *, uint32_t , uint8_t);
    131 int hc_reset_endpoint(xhci_hc_t *, uint32_t , uint8_t);
     125int hc_address_device(xhci_device_t *, xhci_endpoint_t *);
     126int hc_configure_device(xhci_device_t *);
     127int hc_deconfigure_device(xhci_device_t *);
     128int hc_add_endpoint(xhci_device_t *, uint8_t, xhci_ep_ctx_t *);
     129int hc_drop_endpoint(xhci_device_t *, uint8_t);
     130int hc_update_endpoint(xhci_device_t *, uint8_t, xhci_ep_ctx_t *);
     131int hc_stop_endpoint(xhci_device_t *, uint8_t);
     132int hc_reset_endpoint(xhci_device_t *, uint8_t);
    132133
    133134int hc_status(bus_t *, uint32_t *);
  • uspace/drv/bus/usb/xhci/streams.c

    rc7d5189 ra4e7e6e1  
    327327        }
    328328
    329         hc_stop_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep));
     329        hc_stop_endpoint(dev, xhci_endpoint_index(xhci_ep));
    330330        xhci_endpoint_free_transfer_ds(xhci_ep);
    331331
     
    340340        memset(&ep_ctx, 0, sizeof(ep_ctx));
    341341        xhci_setup_endpoint_context(xhci_ep, &ep_ctx);
    342         return hc_update_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep), &ep_ctx);
     342        return hc_update_endpoint(dev, xhci_endpoint_index(xhci_ep), &ep_ctx);
    343343}
    344344
     
    361361         * Stop the endpoint, destroy the ring, and transition to streams.
    362362         */
    363         hc_stop_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep));
     363        hc_stop_endpoint(dev, xhci_endpoint_index(xhci_ep));
    364364        xhci_endpoint_free_transfer_ds(xhci_ep);
    365365
     
    381381        setup_stream_context(xhci_ep, &ep_ctx, pstreams, 1);
    382382
    383         return hc_update_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep), &ep_ctx);
     383        return hc_update_endpoint(dev, xhci_endpoint_index(xhci_ep), &ep_ctx);
    384384}
    385385
     
    434434         * Stop the endpoint, destroy the ring, and transition to streams.
    435435         */
    436         hc_stop_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep));
     436        hc_stop_endpoint(dev, xhci_endpoint_index(xhci_ep));
    437437        xhci_endpoint_free_transfer_ds(xhci_ep);
    438438
     
    455455        setup_stream_context(xhci_ep, &ep_ctx, pstreams, 0);
    456456
    457         return hc_update_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep), &ep_ctx);
     457        return hc_update_endpoint(dev, xhci_endpoint_index(xhci_ep), &ep_ctx);
    458458
    459459err_init:
  • uspace/drv/bus/usb/xhci/transfers.c

    rc7d5189 ra4e7e6e1  
    197197        // Issue a Configure Endpoint command, if needed.
    198198        if (configure_endpoint_needed(setup)) {
    199                 const int err = hc_configure_device(hc, xhci_ep_to_dev(xhci_ep)->slot_id);
     199                const int err = hc_configure_device(xhci_ep_to_dev(xhci_ep));
    200200                if (err)
    201201                        return err;
Note: See TracChangeset for help on using the changeset viewer.