Changeset 8ea7459 in mainline for uspace/drv/bus/usb/xhci/rh.c


Ignore:
Timestamp:
2017-10-21T12:17:09Z (6 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f270ecb
Parents:
d1d7a92
Message:

Refactored some parts of RH to HC. Also moved some bus ops around.

File:
1 edited

Legend:

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

    rd1d7a92 r8ea7459  
    7373}
    7474
     75static void setup_control_ep0_ctx(xhci_ep_ctx_t *ctx, xhci_trb_ring_t *ring,
     76                const xhci_port_speed_t *speed)
     77{
     78        XHCI_EP_TYPE_SET(*ctx, EP_TYPE_CONTROL);
     79        // TODO: must be changed with a command after USB descriptor is read
     80        // See 4.6.5 in XHCI specification, first note
     81        XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, speed->major == 3 ? 512 : 8);
     82        XHCI_EP_MAX_BURST_SIZE_SET(*ctx, 0);
     83        XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue);
     84        XHCI_EP_DCS_SET(*ctx, 1);
     85        XHCI_EP_INTERVAL_SET(*ctx, 0);
     86        XHCI_EP_MAX_P_STREAMS_SET(*ctx, 0);
     87        XHCI_EP_MULT_SET(*ctx, 0);
     88        XHCI_EP_ERROR_COUNT_SET(*ctx, 3);
     89}
     90
    7591// TODO: Check device deallocation, we free device_ctx in hc.c, not
    7692//       sure about the other structs.
     
    7995int xhci_rh_address_device(xhci_rh_t *rh, device_t *dev, xhci_bus_t *bus)
    8096{
     97        /* FIXME: Certainly not generic solution. */
     98        const uint32_t route_str = 0;
     99
    81100        int err;
    82101        xhci_hc_t *hc = rh->hc;
    83 
    84         xhci_cmd_t cmd;
    85         xhci_cmd_init(&cmd);
    86 
    87         /* XXX Certainly not generic solution. */
    88         uint32_t route_str = 0;
    89 
    90102        const xhci_port_speed_t *speed = xhci_rh_get_port_speed(rh, dev->port);
    91103
    92         xhci_send_enable_slot_command(hc, &cmd);
    93         if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT)) != EOK)
     104        /* Enable new slot */
     105        uint32_t slot_id;
     106        if ((err = hc_enable_slot(hc, &slot_id)) != EOK)
    94107                return err;
    95 
    96         uint32_t slot_id = cmd.slot_id;
    97 
    98108        usb_log_debug2("Obtained slot ID: %u.\n", slot_id);
    99         xhci_cmd_fini(&cmd);
    100 
     109
     110        /* Setup input context */
    101111        xhci_input_ctx_t *ictx = malloc(sizeof(xhci_input_ctx_t));
    102         if (!ictx) {
     112        if (!ictx)
    103113                return ENOMEM;
    104         }
    105 
    106114        memset(ictx, 0, sizeof(xhci_input_ctx_t));
    107115
     
    124132        if (err)
    125133                goto err_ring;
    126 
    127         XHCI_EP_TYPE_SET(ictx->endpoint_ctx[0], EP_TYPE_CONTROL);
    128         // TODO: must be changed with a command after USB descriptor is read
    129         // See 4.6.5 in XHCI specification, first note
    130         XHCI_EP_MAX_PACKET_SIZE_SET(ictx->endpoint_ctx[0],
    131             speed->major == 3 ? 512 : 8);
    132         XHCI_EP_MAX_BURST_SIZE_SET(ictx->endpoint_ctx[0], 0);
    133         /* FIXME physical pointer? */
    134         XHCI_EP_TR_DPTR_SET(ictx->endpoint_ctx[0], ep_ring->dequeue);
    135         XHCI_EP_DCS_SET(ictx->endpoint_ctx[0], 1);
    136         XHCI_EP_INTERVAL_SET(ictx->endpoint_ctx[0], 0);
    137         XHCI_EP_MAX_P_STREAMS_SET(ictx->endpoint_ctx[0], 0);
    138         XHCI_EP_MULT_SET(ictx->endpoint_ctx[0], 0);
    139         XHCI_EP_ERROR_COUNT_SET(ictx->endpoint_ctx[0], 3);
    140 
     134        setup_control_ep0_ctx(&ictx->endpoint_ctx[0], ep_ring, speed);
     135
     136        /* Setup and register device context */
    141137        xhci_device_ctx_t *dctx = malloc32(sizeof(xhci_device_ctx_t));
    142138        if (!dctx) {
     
    145141        }
    146142        memset(dctx, 0, sizeof(xhci_device_ctx_t));
    147 
    148143        hc->dcbaa[slot_id] = addr_to_phys(dctx);
    149144
     
    152147        hc->dcbaa_virt[slot_id].trs[0] = ep_ring;
    153148
    154         xhci_cmd_init(&cmd);
    155         cmd.slot_id = slot_id;
    156         xhci_send_address_device_command(hc, &cmd, ictx);
    157         if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT)) != EOK)
     149        /* Address device */
     150        if ((err = hc_address_device(hc, slot_id, ictx)) != EOK)
    158151                goto err_dctx;
    159 
    160         xhci_cmd_fini(&cmd);
    161 
    162152        dev->address = XHCI_SLOT_DEVICE_ADDRESS(dctx->slot_ctx);
    163153        usb_log_debug2("Obtained USB address: %d.\n", dev->address);
Note: See TracChangeset for help on using the changeset viewer.