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


Ignore:
Timestamp:
2018-01-19T21:04:32Z (7 years ago)
Author:
Jenda <jenda.jzqk73@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
726af29
Parents:
c6f82e5
Message:

Handling HCs with 32 or 64-bytes context size

File:
1 edited

Legend:

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

    rc6f82e5 r7ec7b7e  
    223223
    224224        hc->ac64 = XHCI_REG_RD(hc->cap_regs, XHCI_CAP_AC64);
     225        hc->csz = XHCI_REG_RD(hc->cap_regs, XHCI_CAP_CSZ);
    225226        hc->max_slots = XHCI_REG_RD(hc->cap_regs, XHCI_CAP_MAX_SLOTS);
    226227
     
    723724
    724725        /* Prepare memory for the context */
    725         if ((err = dma_buffer_alloc(&dev->dev_ctx, sizeof(xhci_device_ctx_t))))
     726        if ((err = dma_buffer_alloc(&dev->dev_ctx, XHCI_DEVICE_CTX_SIZE(hc))))
    726727                return err;
    727         memset(dev->dev_ctx.virt, 0, sizeof(xhci_device_ctx_t));
     728        memset(dev->dev_ctx.virt, 0, XHCI_DEVICE_CTX_SIZE(hc));
    728729
    729730        /* Get the slot number */
     
    807808static int create_configure_ep_input_ctx(xhci_device_t *dev, dma_buffer_t *dma_buf)
    808809{
    809         const int err = dma_buffer_alloc(dma_buf, sizeof(xhci_input_ctx_t));
     810        const xhci_hc_t * hc = bus_to_hc(dev->base.bus);
     811        const int err = dma_buffer_alloc(dma_buf, XHCI_INPUT_CTX_SIZE(hc));
    810812        if (err)
    811813                return err;
    812814
    813815        xhci_input_ctx_t *ictx = dma_buf->virt;
    814         memset(ictx, 0, sizeof(xhci_input_ctx_t));
     816        memset(ictx, 0, XHCI_INPUT_CTX_SIZE(hc));
    815817
    816818        // Quoting sec. 4.6.5 and 4.6.6: A1, D0, D1 are down (already zeroed), A0 is up.
    817         XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 0);
    818         xhci_setup_slot_context(dev, &ictx->slot_ctx);
     819        XHCI_INPUT_CTRL_CTX_ADD_SET(*XHCI_GET_CTRL_CTX(ictx, hc), 0);
     820        xhci_slot_ctx_t *slot_ctx = XHCI_GET_SLOT_CTX(XHCI_GET_DEVICE_CTX(ictx, hc), hc);
     821        xhci_setup_slot_context(dev, slot_ctx);
    819822
    820823        return EOK;
     
    846849
    847850        /* Copy endpoint 0 context and set A1 flag. */
    848         XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 1);
    849         xhci_setup_endpoint_context(ep0, &ictx->endpoint_ctx[0]);
    850 
     851        XHCI_INPUT_CTRL_CTX_ADD_SET(*XHCI_GET_CTRL_CTX(ictx, hc), 1);
     852        xhci_ep_ctx_t *ep_ctx = XHCI_GET_EP_CTX(XHCI_GET_DEVICE_CTX(ictx, hc), hc, 0);
     853        xhci_setup_endpoint_context(ep0, ep_ctx);
    851854        /* Address device needs Ctx entries set to 1 only */
    852         xhci_slot_ctx_t *slot_ctx = &ictx->slot_ctx;
     855        xhci_slot_ctx_t *slot_ctx = XHCI_GET_SLOT_CTX(XHCI_GET_DEVICE_CTX(ictx, hc), hc);
    853856        XHCI_SLOT_CTX_ENTRIES_SET(*slot_ctx, 1);
    854857
     
    857860                return err;
    858861
    859         xhci_device_ctx_t *dev_ctx = dev->dev_ctx.virt;
    860         dev->base.address = XHCI_SLOT_DEVICE_ADDRESS(dev_ctx->slot_ctx);
     862        xhci_device_ctx_t *device_ctx = dev->dev_ctx.virt;
     863        dev->base.address = XHCI_SLOT_DEVICE_ADDRESS(*XHCI_GET_SLOT_CTX(device_ctx, hc));
    861864        usb_log_debug2("Obtained USB address: %d.", dev->base.address);
    862865
     
    911914
    912915        xhci_input_ctx_t *ictx = ictx_dma_buf.virt;
    913         XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */
    914         memcpy(&ictx->endpoint_ctx[ep_idx], ep_ctx, sizeof(xhci_ep_ctx_t));
    915916
    916917        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     918        XHCI_INPUT_CTRL_CTX_ADD_SET(*XHCI_GET_CTRL_CTX(ictx, hc), ep_idx + 1); /* Preceded by slot ctx */
     919
     920        xhci_ep_ctx_t *_ep_ctx = XHCI_GET_EP_CTX(XHCI_GET_DEVICE_CTX(ictx, hc), hc, ep_idx);
     921        memcpy(_ep_ctx, ep_ctx, XHCI_ONE_CTX_SIZE(hc));
     922
    917923        return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf);
    918924}
     
    932938                return err;
    933939
     940        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
    934941        xhci_input_ctx_t *ictx = ictx_dma_buf.virt;
    935         XHCI_INPUT_CTRL_CTX_DROP_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */
    936 
    937         xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     942        XHCI_INPUT_CTRL_CTX_DROP_SET(*XHCI_GET_CTRL_CTX(ictx, hc), ep_idx + 1); /* Preceded by slot ctx */
     943
    938944        return xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf);
    939945}
     
    950956{
    951957        dma_buffer_t ictx_dma_buf;
    952         const int err = dma_buffer_alloc(&ictx_dma_buf, sizeof(xhci_input_ctx_t));
     958        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     959
     960        const int err = dma_buffer_alloc(&ictx_dma_buf, XHCI_INPUT_CTX_SIZE(hc));
    953961        if (err)
    954962                return err;
    955963
    956964        xhci_input_ctx_t *ictx = ictx_dma_buf.virt;
    957         memset(ictx, 0, sizeof(xhci_input_ctx_t));
    958 
    959         XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, ep_idx + 1);
    960         memcpy(&ictx->endpoint_ctx[ep_idx], ep_ctx, sizeof(xhci_ep_ctx_t));
    961 
    962         xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     965        memset(ictx, 0, XHCI_INPUT_CTX_SIZE(hc));
     966
     967        XHCI_INPUT_CTRL_CTX_ADD_SET(*XHCI_GET_CTRL_CTX(ictx, hc), ep_idx + 1);
     968        xhci_ep_ctx_t *_ep_ctx = XHCI_GET_EP_CTX(XHCI_GET_DEVICE_CTX(ictx, hc), hc, 0);
     969        memcpy(_ep_ctx, ep_ctx, sizeof(xhci_ep_ctx_t));
     970
    963971        return xhci_cmd_sync_inline(hc, EVALUATE_CONTEXT, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf);
    964972}
Note: See TracChangeset for help on using the changeset viewer.