Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 8ea7459 in mainline


Ignore:
Timestamp:
2017-10-21T12:17:09Z (3 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
master
Children:
f270ecb
Parents:
d1d7a92
Message:

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

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

Legend:

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

    rd1d7a92 r8ea7459  
    9494}
    9595
    96 static int enumerate_device(bus_t *bus, hcd_t *hcd, device_t *dev)
     96int xhci_bus_remove_device(xhci_bus_t *bus, xhci_hc_t *hc, device_t *dev)
     97{
     98        // TODO: Implement me!
     99        return ENOTSUP;
     100}
     101
     102/** Ops receive generic bus_t pointer. */
     103static inline xhci_bus_t *bus_to_xhci_bus(bus_t *bus_base)
     104{
     105        assert(bus_base);
     106        return (xhci_bus_t *) bus_base;
     107}
     108
     109static int enumerate_device(bus_t *bus_base, hcd_t *hcd, device_t *dev)
    97110{
    98111        xhci_hc_t *hc = hcd_get_driver_data(hcd);
    99112        assert(hc);
    100113
    101         return xhci_bus_enumerate_device((xhci_bus_t *) bus, hc, dev);
    102 }
    103 
    104 static int remove_device(bus_t *bus, hcd_t *hcd, device_t *dev)
    105 {
    106         // TODO: Implement me!
    107 
    108         return ENOTSUP;
    109 }
    110 
    111 /** Ops receive generic bus_t pointer. */
    112 static inline xhci_bus_t *bus_to_xhci_bus(bus_t *bus_base)
    113 {
    114         assert(bus_base);
    115         return (xhci_bus_t *) bus_base;
     114        xhci_bus_t *bus = bus_to_xhci_bus(bus_base);
     115        assert(bus);
     116
     117        return xhci_bus_enumerate_device(bus, hc, dev);
     118}
     119
     120static int remove_device(bus_t *bus_base, hcd_t *hcd, device_t *dev)
     121{
     122        xhci_hc_t *hc = hcd_get_driver_data(hcd);
     123        assert(hc);
     124
     125        xhci_bus_t *bus = bus_to_xhci_bus(bus_base);
     126        assert(bus);
     127
     128        return xhci_bus_remove_device(bus, hc, dev);
    116129}
    117130
     
    246259                return res;
    247260
    248         xhci_device_remove_endpoint(hashed_dev->device, xhci_endpoint_get(ep));
     261        res = xhci_device_remove_endpoint(hashed_dev->device, xhci_endpoint_get(ep));
     262        if (res != EOK)
     263                return res;
    249264
    250265        if (hashed_dev->device->active_endpoint_count == 0) {
  • uspace/drv/bus/usb/xhci/bus.h

    rd1d7a92 r8ea7459  
    6161
    6262int xhci_bus_enumerate_device(xhci_bus_t *, xhci_hc_t *, device_t *);
     63int xhci_bus_remove_device(xhci_bus_t *, xhci_hc_t *, device_t *);
    6364
    6465#endif
  • uspace/drv/bus/usb/xhci/endpoint.c

    rd1d7a92 r8ea7459  
    137137        xhci_trb_ring_t *ring, usb_superspeed_endpoint_companion_descriptor_t *ss_desc)
    138138{
    139 
    140139        XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(ep));
    141140        XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size);
     
    153152        } else {
    154153                XHCI_EP_MAX_P_STREAMS_SET(*ctx, 0);
    155                 /* FIXME physical pointer? */
    156154                XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue);
    157155                XHCI_EP_DCS_SET(*ctx, 1);
     
    168166        XHCI_EP_MULT_SET(*ctx, 0);
    169167        XHCI_EP_ERROR_COUNT_SET(*ctx, 0);
    170         /* FIXME physical pointer? */
    171168        XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue);
    172169        XHCI_EP_DCS_SET(*ctx, 1);
     
    182179        XHCI_EP_MULT_SET(*ctx, 0);
    183180        XHCI_EP_ERROR_COUNT_SET(*ctx, 3);
    184         /* FIXME physical pointer? */
    185181        XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue);
    186182        XHCI_EP_DCS_SET(*ctx, 1);
  • uspace/drv/bus/usb/xhci/hc.c

    rd1d7a92 r8ea7459  
    636636}
    637637
     638int hc_enable_slot(xhci_hc_t *hc, uint32_t *slot_id)
     639{
     640        assert(hc);
     641
     642        int err;
     643        xhci_cmd_t cmd;
     644        xhci_cmd_init(&cmd);
     645
     646        if ((err = xhci_send_enable_slot_command(hc, &cmd)) != EOK)
     647                return err;
     648
     649        if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT)) != EOK)
     650                return err;
     651
     652        if (slot_id)
     653                *slot_id = cmd.slot_id;
     654
     655        xhci_cmd_fini(&cmd);
     656        return EOK;
     657}
     658
     659int hc_address_device(xhci_hc_t *hc, uint32_t slot_id, xhci_input_ctx_t *ictx)
     660{
     661        assert(hc);
     662       
     663        int err;
     664        xhci_cmd_t cmd;
     665        xhci_cmd_init(&cmd);
     666
     667        cmd.slot_id = slot_id;
     668
     669        if ((err = xhci_send_address_device_command(hc, &cmd, ictx)) != EOK)
     670                return err;
     671
     672        if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT)) != EOK)
     673                return err;
     674
     675        xhci_cmd_fini(&cmd);
     676        return EOK;
     677}
     678
    638679/**
    639680 * @}
  • uspace/drv/bus/usb/xhci/hc.h

    rd1d7a92 r8ea7459  
    9898void hc_fini(xhci_hc_t *);
    9999int hc_ring_doorbell(xhci_hc_t *, unsigned, unsigned);
     100int hc_enable_slot(xhci_hc_t *, uint32_t *);
     101int hc_address_device(xhci_hc_t *, uint32_t, xhci_input_ctx_t *);
    100102
    101103#endif
  • 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.