Changeset b724494 in mainline for uspace/drv/bus/usb/xhci/rh.c
- Timestamp:
- 2017-10-23T21:26:22Z (6 years ago)
- Branches:
- lfn, master, serial
- Children:
- ec700c7
- Parents:
- 327f147
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/rh.c
r327f147 rb724494 95 95 { 96 96 int err; 97 98 const xhci_port_speed_t *speed = xhci_rh_get_port_speed(rh, dev->port); 97 99 xhci_device_t *xhci_dev = xhci_device_get(dev); 98 99 /* FIXME: Certainly not generic solution. */100 const uint32_t route_str = 0;101 102 100 xhci_dev->hc = rh->hc; 103 104 const xhci_port_speed_t *speed = xhci_rh_get_port_speed(rh, dev->port);105 101 xhci_dev->usb3 = speed->major == 3; 106 102 107 /* Enable new slot */103 /* Enable new slot. */ 108 104 if ((err = hc_enable_slot(rh->hc, &xhci_dev->slot_id)) != EOK) 109 105 return err; 110 106 usb_log_debug2("Obtained slot ID: %u.\n", xhci_dev->slot_id); 111 107 112 /* Setup input context */ 113 xhci_input_ctx_t *ictx = malloc32(sizeof(xhci_input_ctx_t)); 114 if (!ictx) 115 return ENOMEM; 116 memset(ictx, 0, sizeof(xhci_input_ctx_t)); 117 118 XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 0); 119 XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, 1); 120 121 /* Initialize slot_ctx according to section 4.3.3 point 3. */ 122 /* Attaching to root hub port, root string equals to 0. */ 123 XHCI_SLOT_ROOT_HUB_PORT_SET(ictx->slot_ctx, dev->port); 124 XHCI_SLOT_CTX_ENTRIES_SET(ictx->slot_ctx, 1); 125 XHCI_SLOT_ROUTE_STRING_SET(ictx->slot_ctx, route_str); 126 108 /* Create and configure control endpoint. */ 127 109 endpoint_t *ep0_base = bus_create_endpoint(&rh->hc->bus.base); 128 110 if (!ep0_base) 129 goto err_ictx; 111 return ENOMEM; 112 130 113 xhci_endpoint_t *ep0 = xhci_endpoint_get(ep0_base); 131 132 /* Control endpoints don't use streams. */133 114 /* FIXME: Sync this with xhci_device_add_endpoint. */ 134 115 ep0->max_streams = 0; 135 116 ep0->max_burst = 0; 136 117 ep0->mult = 0; 118 137 119 if ((err = xhci_endpoint_alloc_transfer_ds(ep0))) 138 goto err_ictx; 139 140 setup_control_ep0_ctx(&ictx->endpoint_ctx[0], &ep0->ring, speed); 120 goto err_ep; 121 122 xhci_ep_ctx_t ep_ctx; 123 memset(&ep_ctx, 0, sizeof(xhci_ep_ctx_t)); 124 setup_control_ep0_ctx(&ep_ctx, &ep0->ring, speed); 141 125 142 126 /* Setup and register device context */ 143 xhci_dev ice_ctx_t *dctx = malloc32(sizeof(xhci_device_ctx_t));144 if (! dctx) {127 xhci_dev->dev_ctx = malloc32(sizeof(xhci_device_ctx_t)); 128 if (!xhci_dev->dev_ctx) { 145 129 err = ENOMEM; 146 goto err_ep; 147 } 148 xhci_dev->dev_ctx = dctx; 149 rh->hc->dcbaa[xhci_dev->slot_id] = addr_to_phys(dctx); 150 memset(dctx, 0, sizeof(xhci_device_ctx_t)); 130 goto err_ds; 131 } 132 rh->hc->dcbaa[xhci_dev->slot_id] = addr_to_phys(xhci_dev->dev_ctx); 133 memset(xhci_dev->dev_ctx, 0, sizeof(xhci_device_ctx_t)); 151 134 152 135 /* Address device */ 153 if ((err = hc_address_ device(rh->hc, xhci_dev->slot_id, ictx)) != EOK)136 if ((err = hc_address_rh_device(rh->hc, xhci_dev->slot_id, dev->port, &ep_ctx))) 154 137 goto err_dctx; 155 dev->address = XHCI_SLOT_DEVICE_ADDRESS( dctx->slot_ctx);138 dev->address = XHCI_SLOT_DEVICE_ADDRESS(xhci_dev->dev_ctx->slot_ctx); 156 139 usb_log_debug2("Obtained USB address: %d.\n", dev->address); 157 140 … … 178 161 } 179 162 180 free32(ictx);181 163 return EOK; 182 164 183 165 err_dctx: 184 free32( dctx);166 free32(xhci_dev->dev_ctx); 185 167 rh->hc->dcbaa[xhci_dev->slot_id] = 0; 168 err_ds: 169 xhci_endpoint_free_transfer_ds(ep0); 186 170 err_ep: 187 171 xhci_endpoint_fini(ep0); 188 172 free(ep0); 189 err_ictx:190 free32(ictx);191 173 return err; 192 174 } … … 316 298 317 299 /* TODO: Figure out how to handle errors here. So far, they are reported and skipped. */ 300 /* TODO: Move parts of the code below to xhci_bus_remove_device() */ 318 301 319 302 /* Make DDF (and all drivers) forget about the device. */ … … 323 306 } 324 307 325 // TODO: Remove EP0. 326 // TODO: Deconfigure device. 308 /* Unregister EP0. */ 309 if ((err = bus_unregister_endpoint(&rh->hc->bus.base, &dev->endpoints[0]->base))) { 310 usb_log_warning("Failed to unregister configuration endpoint of device '%s' from XHCI bus: %s", 311 ddf_fun_get_name(dev->base.fun), str_error(err)); 312 } 313 314 /* Deconfigure device. */ 315 if ((err = hc_deconfigure_device(rh->hc, dev->slot_id))) { 316 usb_log_warning("Failed to deconfigure detached device '%s': %s", 317 ddf_fun_get_name(dev->base.fun), str_error(err)); 318 } 319 320 /* TODO: Free EP0 structures. */ 321 /* TODO: Destroy EP0 by removing its last reference. */ 327 322 328 323 /* Remove device from XHCI bus. */
Note: See TracChangeset
for help on using the changeset viewer.