Changeset b724494 in mainline for uspace/drv/bus/usb/xhci/hc.c


Ignore:
Timestamp:
2017-10-23T21:26:22Z (7 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ec700c7
Parents:
327f147
Message:

Moved some code from RH to HC. Simplified device address process. Issuing deconfigure device command.

File:
1 edited

Legend:

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

    r327f147 rb724494  
    652652}
    653653
     654static int create_valid_input_ctx(xhci_input_ctx_t **out_ictx)
     655{
     656        xhci_input_ctx_t *ictx = malloc32(sizeof(xhci_input_ctx_t));
     657        if (!ictx) {
     658                return ENOMEM;
     659        }
     660
     661        memset(ictx, 0, sizeof(xhci_input_ctx_t));
     662
     663        // Quoting sec. 4.6.6: A1, D0, D1 are down, A0 is up.
     664        XHCI_INPUT_CTRL_CTX_ADD_CLEAR(ictx->ctrl_ctx, 1);
     665        XHCI_INPUT_CTRL_CTX_DROP_CLEAR(ictx->ctrl_ctx, 0);
     666        XHCI_INPUT_CTRL_CTX_DROP_CLEAR(ictx->ctrl_ctx, 1);
     667        XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 0);
     668
     669        if (out_ictx) {
     670                *out_ictx = ictx;
     671        }
     672
     673        return EOK;
     674}
     675
     676int hc_address_rh_device(xhci_hc_t *hc, uint32_t slot_id, uint8_t port, xhci_ep_ctx_t *ep_ctx)
     677{
     678        int err;
     679
     680        /* Issue configure endpoint command (sec 4.3.5). */
     681        xhci_input_ctx_t *ictx;
     682        if ((err = create_valid_input_ctx(&ictx))) {
     683                goto err;
     684        }
     685
     686        /* Initialize slot_ctx according to section 4.3.3 point 3. */
     687        XHCI_SLOT_ROOT_HUB_PORT_SET(ictx->slot_ctx, port);
     688        XHCI_SLOT_CTX_ENTRIES_SET(ictx->slot_ctx, 1);
     689
     690        /* Attaching to root hub port, root string equals to 0. */
     691        XHCI_SLOT_ROUTE_STRING_SET(ictx->slot_ctx, 0);
     692
     693        /* Copy endpoint 0 context and set A1 flag. */
     694        memcpy(&ictx->endpoint_ctx[0], ep_ctx, sizeof(xhci_ep_ctx_t));
     695        XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 1);
     696
     697        if ((err = hc_address_device(hc, slot_id, ictx))) {
     698                goto err_cmd;
     699        }
     700
     701        free32(ictx);
     702        return EOK;
     703
     704err_cmd:
     705        free32(ictx);
     706err:
     707        return err;
     708}
     709
     710int hc_configure_device(xhci_hc_t *hc, uint32_t slot_id)
     711{
     712        int err;
     713
     714        /* Issue configure endpoint command (sec 4.3.5). */
     715        xhci_input_ctx_t *ictx;
     716        if ((err = create_valid_input_ctx(&ictx))) {
     717                goto err;
     718        }
     719
     720        // TODO: Set slot context and other flags. (probably forgot a lot of 'em)
     721
     722        xhci_cmd_t cmd;
     723        xhci_cmd_init(&cmd);
     724
     725        cmd.slot_id = slot_id;
     726
     727        if ((err = xhci_send_configure_endpoint_command(hc, &cmd, ictx))) {
     728                goto err_cmd;
     729        }
     730
     731        if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) {
     732                goto err_cmd;
     733        }
     734
     735        xhci_cmd_fini(&cmd);
     736
     737        free32(ictx);
     738        return EOK;
     739
     740err_cmd:
     741        free32(ictx);
     742err:
     743        return err;
     744}
     745
     746int hc_deconfigure_device(xhci_hc_t *hc, uint32_t slot_id)
     747{
     748        int err;
     749
     750        /* Issue configure endpoint command (sec 4.3.5) with the DC flag. */
     751        xhci_cmd_t cmd;
     752        xhci_cmd_init(&cmd);
     753
     754        cmd.slot_id = slot_id;
     755        cmd.deconfigure = true;
     756
     757        if ((err = xhci_send_configure_endpoint_command(hc, &cmd, NULL))) {
     758                return err;
     759        }
     760
     761        if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) {
     762                return err;
     763        }
     764
     765        xhci_cmd_fini(&cmd);
     766
     767        return EOK;
     768}
     769
     770int hc_add_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx, xhci_ep_ctx_t *ep_ctx)
     771{
     772        int err;
     773
     774        /* Issue configure endpoint command (sec 4.3.5). */
     775        xhci_input_ctx_t *ictx;
     776        if ((err = create_valid_input_ctx(&ictx))) {
     777                goto err;
     778        }
     779
     780        XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */
     781        memcpy(&ictx->endpoint_ctx[ep_idx], ep_ctx, sizeof(xhci_ep_ctx_t));
     782
     783        // TODO: Set slot context and other flags. (probably forgot a lot of 'em)
     784
     785        xhci_cmd_t cmd;
     786        xhci_cmd_init(&cmd);
     787
     788        cmd.slot_id = slot_id;
     789
     790        if ((err = xhci_send_configure_endpoint_command(hc, &cmd, ictx))) {
     791                goto err_cmd;
     792        }
     793
     794        if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) {
     795                goto err_cmd;
     796        }
     797
     798        xhci_cmd_fini(&cmd);
     799
     800        free32(ictx);
     801        return EOK;
     802
     803err_cmd:
     804        free32(ictx);
     805err:
     806        return err;
     807}
     808
     809int hc_drop_endpoint(xhci_hc_t *hc, uint32_t slot_id, uint8_t ep_idx)
     810{
     811        int err;
     812
     813        /* Issue configure endpoint command (sec 4.3.5). */
     814        xhci_input_ctx_t *ictx;
     815        if ((err = create_valid_input_ctx(&ictx))) {
     816                goto err;
     817        }
     818
     819        XHCI_INPUT_CTRL_CTX_DROP_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */
     820
     821        // TODO: Set slot context and other flags. (probably forgot a lot of 'em)
     822
     823        xhci_cmd_t cmd;
     824        xhci_cmd_init(&cmd);
     825
     826        cmd.slot_id = slot_id;
     827
     828        if ((err = xhci_send_configure_endpoint_command(hc, &cmd, ictx))) {
     829                goto err_cmd;
     830        }
     831
     832        if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) {
     833                goto err_cmd;
     834        }
     835
     836        xhci_cmd_fini(&cmd);
     837
     838        free32(ictx);
     839        return EOK;
     840
     841err_cmd:
     842        free32(ictx);
     843err:
     844        return err;
     845}
     846
    654847/**
    655848 * @}
Note: See TracChangeset for help on using the changeset viewer.