Changeset 8ea7459 in mainline
- Timestamp:
- 2017-10-21T12:17:09Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f270ecb
- Parents:
- d1d7a92
- Location:
- uspace/drv/bus/usb/xhci
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/bus.c
rd1d7a92 r8ea7459 94 94 } 95 95 96 static int enumerate_device(bus_t *bus, hcd_t *hcd, device_t *dev) 96 int 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. */ 103 static 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 109 static int enumerate_device(bus_t *bus_base, hcd_t *hcd, device_t *dev) 97 110 { 98 111 xhci_hc_t *hc = hcd_get_driver_data(hcd); 99 112 assert(hc); 100 113 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 120 static 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); 116 129 } 117 130 … … 246 259 return res; 247 260 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; 249 264 250 265 if (hashed_dev->device->active_endpoint_count == 0) { -
uspace/drv/bus/usb/xhci/bus.h
rd1d7a92 r8ea7459 61 61 62 62 int xhci_bus_enumerate_device(xhci_bus_t *, xhci_hc_t *, device_t *); 63 int xhci_bus_remove_device(xhci_bus_t *, xhci_hc_t *, device_t *); 63 64 64 65 #endif -
uspace/drv/bus/usb/xhci/endpoint.c
rd1d7a92 r8ea7459 137 137 xhci_trb_ring_t *ring, usb_superspeed_endpoint_companion_descriptor_t *ss_desc) 138 138 { 139 140 139 XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(ep)); 141 140 XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size); … … 153 152 } else { 154 153 XHCI_EP_MAX_P_STREAMS_SET(*ctx, 0); 155 /* FIXME physical pointer? */156 154 XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue); 157 155 XHCI_EP_DCS_SET(*ctx, 1); … … 168 166 XHCI_EP_MULT_SET(*ctx, 0); 169 167 XHCI_EP_ERROR_COUNT_SET(*ctx, 0); 170 /* FIXME physical pointer? */171 168 XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue); 172 169 XHCI_EP_DCS_SET(*ctx, 1); … … 182 179 XHCI_EP_MULT_SET(*ctx, 0); 183 180 XHCI_EP_ERROR_COUNT_SET(*ctx, 3); 184 /* FIXME physical pointer? */185 181 XHCI_EP_TR_DPTR_SET(*ctx, ring->dequeue); 186 182 XHCI_EP_DCS_SET(*ctx, 1); -
uspace/drv/bus/usb/xhci/hc.c
rd1d7a92 r8ea7459 636 636 } 637 637 638 int 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 659 int 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 638 679 /** 639 680 * @} -
uspace/drv/bus/usb/xhci/hc.h
rd1d7a92 r8ea7459 98 98 void hc_fini(xhci_hc_t *); 99 99 int hc_ring_doorbell(xhci_hc_t *, unsigned, unsigned); 100 int hc_enable_slot(xhci_hc_t *, uint32_t *); 101 int hc_address_device(xhci_hc_t *, uint32_t, xhci_input_ctx_t *); 100 102 101 103 #endif -
uspace/drv/bus/usb/xhci/rh.c
rd1d7a92 r8ea7459 73 73 } 74 74 75 static 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 75 91 // TODO: Check device deallocation, we free device_ctx in hc.c, not 76 92 // sure about the other structs. … … 79 95 int xhci_rh_address_device(xhci_rh_t *rh, device_t *dev, xhci_bus_t *bus) 80 96 { 97 /* FIXME: Certainly not generic solution. */ 98 const uint32_t route_str = 0; 99 81 100 int err; 82 101 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 90 102 const xhci_port_speed_t *speed = xhci_rh_get_port_speed(rh, dev->port); 91 103 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) 94 107 return err; 95 96 uint32_t slot_id = cmd.slot_id;97 98 108 usb_log_debug2("Obtained slot ID: %u.\n", slot_id); 99 xhci_cmd_fini(&cmd); 100 109 110 /* Setup input context */ 101 111 xhci_input_ctx_t *ictx = malloc(sizeof(xhci_input_ctx_t)); 102 if (!ictx) {112 if (!ictx) 103 113 return ENOMEM; 104 }105 106 114 memset(ictx, 0, sizeof(xhci_input_ctx_t)); 107 115 … … 124 132 if (err) 125 133 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 */ 141 137 xhci_device_ctx_t *dctx = malloc32(sizeof(xhci_device_ctx_t)); 142 138 if (!dctx) { … … 145 141 } 146 142 memset(dctx, 0, sizeof(xhci_device_ctx_t)); 147 148 143 hc->dcbaa[slot_id] = addr_to_phys(dctx); 149 144 … … 152 147 hc->dcbaa_virt[slot_id].trs[0] = ep_ring; 153 148 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) 158 151 goto err_dctx; 159 160 xhci_cmd_fini(&cmd);161 162 152 dev->address = XHCI_SLOT_DEVICE_ADDRESS(dctx->slot_ctx); 163 153 usb_log_debug2("Obtained USB address: %d.\n", dev->address);
Note:
See TracChangeset
for help on using the changeset viewer.