Changeset eeca8a6 in mainline
- Timestamp:
- 2018-01-16T19:22:58Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4603b35
- Parents:
- 47e9494
- Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhub/port.c
r47e9494 reeca8a6 246 246 * TODO: Make the request synchronous. 247 247 */ 248 while ((err = usbhc_reserve_default_address(exch , port->speed)) == EAGAIN) {248 while ((err = usbhc_reserve_default_address(exch)) == EAGAIN) { 249 249 fibril_condvar_wait_timeout(&port->state_cv, &port->guard, 500000); 250 250 if (port->state != PORT_CONNECTED) { … … 271 271 port_log(debug, port, "Port reset, enumerating device."); 272 272 273 if ((err = usbhc_device_enumerate(exch, port->port_number ))) {273 if ((err = usbhc_device_enumerate(exch, port->port_number, port->speed))) { 274 274 port_log(error, port, "Failed to enumerate device: %s", str_error(err)); 275 275 port_change_state(port, PORT_DISABLED); -
uspace/drv/bus/usb/xhci/rh.c
r47e9494 reeca8a6 169 169 } 170 170 171 device_t *dev = hcd_ddf_fun_create(&rh->hc->base); 171 const xhci_port_speed_t *port_speed = xhci_rh_get_port_speed(rh, port_id); 172 173 device_t *dev = hcd_ddf_fun_create(&rh->hc->base, port_speed->usb_speed); 172 174 if (!dev) { 173 175 usb_log_error("Failed to create USB device function."); … … 175 177 } 176 178 177 const xhci_port_speed_t *port_speed = xhci_rh_get_port_speed(rh, port_id); 179 dev->hub = &rh->device.base; 180 dev->port = port_id; 181 178 182 xhci_device_t *xhci_dev = xhci_device_get(dev); 179 183 xhci_dev->usb3 = port_speed->major == 3; 180 184 xhci_dev->rh_port = port_id; 181 182 dev->hub = &rh->device.base;183 dev->port = port_id;184 dev->speed = port_speed->usb_speed;185 185 186 186 if ((err = bus_device_enumerate(dev))) { -
uspace/lib/drv/generic/remote_usbhc.c
r47e9494 reeca8a6 57 57 /** Reserve default USB address. 58 58 * @param[in] exch IPC communication exchange 59 * @return Error code. 60 */ 61 int usbhc_reserve_default_address(async_exch_t *exch) 62 { 63 if (!exch) 64 return EBADMEM; 65 return async_req_1_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), IPC_M_USB_RESERVE_DEFAULT_ADDRESS); 66 } 67 68 /** Release default USB address. 69 * 70 * @param[in] exch IPC communication exchange 71 * 72 * @return Error code. 73 */ 74 int usbhc_release_default_address(async_exch_t *exch) 75 { 76 if (!exch) 77 return EBADMEM; 78 return async_req_1_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), IPC_M_USB_RELEASE_DEFAULT_ADDRESS); 79 } 80 81 /** 82 * Trigger USB device enumeration 83 * 84 * @param[in] exch IPC communication exchange 85 * @param[in] port Port number at which the device is attached 59 86 * @param[in] speed Communication speed of the newly attached device 87 * 60 88 * @return Error code. 61 89 */ 62 int usbhc_reserve_default_address(async_exch_t *exch, usb_speed_t speed) 63 { 64 if (!exch) 65 return EBADMEM; 66 return async_req_2_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 67 IPC_M_USB_RESERVE_DEFAULT_ADDRESS, speed); 68 } 69 70 /** Release default USB address. 71 * 72 * @param[in] exch IPC communication exchange 73 * 74 * @return Error code. 75 * 76 */ 77 int usbhc_release_default_address(async_exch_t *exch) 78 { 79 if (!exch) 80 return EBADMEM; 81 return async_req_1_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 82 IPC_M_USB_RELEASE_DEFAULT_ADDRESS); 83 } 84 85 /** Trigger USB device enumeration 86 * 87 * @param[in] exch IPC communication exchange 88 * @param[out] handle Identifier of the newly added device (if successful) 89 * 90 * @return Error code. 91 * 92 */ 93 int usbhc_device_enumerate(async_exch_t *exch, unsigned port) 94 { 95 if (!exch) 96 return EBADMEM; 97 const int ret = async_req_2_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 98 IPC_M_USB_DEVICE_ENUMERATE, port); 90 int usbhc_device_enumerate(async_exch_t *exch, unsigned port, usb_speed_t speed) 91 { 92 if (!exch) 93 return EBADMEM; 94 const int ret = async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 95 IPC_M_USB_DEVICE_ENUMERATE, port, speed); 99 96 return ret; 100 97 } … … 310 307 } 311 308 312 usb_speed_t speed = DEV_IPC_GET_ARG1(*call); 313 const int ret = usbhc_iface->reserve_default_address(fun, speed); 309 const int ret = usbhc_iface->reserve_default_address(fun); 314 310 async_answer_0(callid, ret); 315 311 } … … 340 336 341 337 const unsigned port = DEV_IPC_GET_ARG1(*call); 342 const int ret = usbhc_iface->device_enumerate(fun, port); 338 usb_speed_t speed = DEV_IPC_GET_ARG2(*call); 339 const int ret = usbhc_iface->device_enumerate(fun, port, speed); 343 340 async_answer_0(callid, ret); 344 341 } -
uspace/lib/drv/include/usbhc_iface.h
r47e9494 reeca8a6 80 80 } usb_endpoint_descriptors_t; 81 81 82 extern int usbhc_reserve_default_address(async_exch_t * , usb_speed_t);82 extern int usbhc_reserve_default_address(async_exch_t *); 83 83 extern int usbhc_release_default_address(async_exch_t *); 84 84 85 extern int usbhc_device_enumerate(async_exch_t *, unsigned port);86 extern int usbhc_device_remove(async_exch_t *, unsigned port);85 extern int usbhc_device_enumerate(async_exch_t *, unsigned, usb_speed_t); 86 extern int usbhc_device_remove(async_exch_t *, unsigned); 87 87 88 88 extern int usbhc_register_endpoint(async_exch_t *, usb_pipe_desc_t *, const usb_endpoint_descriptors_t *); … … 99 99 /** USB device communication interface. */ 100 100 typedef struct { 101 int (*reserve_default_address)(ddf_fun_t * , usb_speed_t);101 int (*reserve_default_address)(ddf_fun_t *); 102 102 int (*release_default_address)(ddf_fun_t *); 103 103 104 int (*device_enumerate)(ddf_fun_t *, unsigned );104 int (*device_enumerate)(ddf_fun_t *, unsigned, usb_speed_t); 105 105 int (*device_remove)(ddf_fun_t *, unsigned); 106 106 -
uspace/lib/usbhost/include/usb/host/bus.h
r47e9494 reeca8a6 140 140 const bus_ops_t *ops; 141 141 142 /* Reserving default address - USB_SPEED_MAX when free. */ 143 usb_speed_t default_address_speed; 142 /* Reserving default address */ 143 device_t *default_address_owner; 144 fibril_condvar_t default_address_cv; 144 145 145 146 /* This structure is meant to be extended by overriding. */ … … 169 170 int bus_endpoint_remove(endpoint_t *); 170 171 171 int bus_reserve_default_address(bus_t *, usb_speed_t);172 void bus_release_default_address(bus_t * );172 int bus_reserve_default_address(bus_t *, device_t *); 173 void bus_release_default_address(bus_t *, device_t *); 173 174 174 175 #endif -
uspace/lib/usbhost/include/usb/host/ddf_helpers.h
r47e9494 reeca8a6 48 48 int hcd_setup_virtual_root_hub(hc_device_t *); 49 49 50 device_t *hcd_ddf_fun_create(hc_device_t * );50 device_t *hcd_ddf_fun_create(hc_device_t *, usb_speed_t); 51 51 void hcd_ddf_fun_destroy(device_t *); 52 52 -
uspace/lib/usbhost/src/bus.c
r47e9494 reeca8a6 60 60 fibril_mutex_initialize(&bus->guard); 61 61 bus->device_size = device_size; 62 bus->default_address_speed = USB_SPEED_MAX;63 62 } 64 63 … … 495 494 * The speed is then used for devices enumerated while the address is reserved. 496 495 */ 497 int bus_reserve_default_address(bus_t *bus, usb_speed_t speed)496 int bus_reserve_default_address(bus_t *bus, device_t *dev) 498 497 { 499 498 assert(bus); 500 499 500 int err; 501 501 fibril_mutex_lock(&bus->guard); 502 if (bus->default_address_speed != USB_SPEED_MAX) { 503 fibril_mutex_unlock(&bus->guard); 504 return EAGAIN; 502 if (bus->default_address_owner != NULL) { 503 err = (bus->default_address_owner == dev) ? EINVAL : EAGAIN; 505 504 } else { 506 bus->default_address_speed = speed; 507 fibril_mutex_unlock(&bus->guard); 508 return EOK; 509 } 505 bus->default_address_owner = dev; 506 err = EOK; 507 } 508 fibril_mutex_unlock(&bus->guard); 509 return err; 510 510 } 511 511 … … 513 513 * Release the default address. 514 514 */ 515 void bus_release_default_address(bus_t *bus )515 void bus_release_default_address(bus_t *bus, device_t *dev) 516 516 { 517 517 assert(bus); 518 bus->default_address_speed = USB_SPEED_MAX; 518 519 fibril_mutex_lock(&bus->guard); 520 if (bus->default_address_owner != dev) { 521 usb_log_error("Device %d tried to release address, which is not reserved for it.", dev->address); 522 } else { 523 bus->default_address_owner = NULL; 524 } 525 fibril_mutex_unlock(&bus->guard); 519 526 } 520 527 -
uspace/lib/usbhost/src/ddf_helpers.c
r47e9494 reeca8a6 117 117 * 118 118 * @param fun DDF function of the device (hub) requesting the address. 119 * @param speed An USB speed of the device for which the address is reserved. 120 */ 121 static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed) 119 */ 120 static int reserve_default_address(ddf_fun_t *fun) 122 121 { 123 122 assert(fun); … … 128 127 assert(dev); 129 128 130 usb_log_debug("Device %d requested default address at %s speed", 131 dev->address, usb_str_speed(speed)); 132 return bus_reserve_default_address(hcd->bus, speed); 129 usb_log_debug("Device %d requested default address", dev->address); 130 return bus_reserve_default_address(hcd->bus, dev); 133 131 } 134 132 … … 148 146 149 147 usb_log_debug("Device %d released default address", dev->address); 150 bus_release_default_address(hcd->bus );148 bus_release_default_address(hcd->bus, dev); 151 149 152 150 return EOK; … … 157 155 * 158 156 * @param fun DDF function of the device (hub) requesting the address. 159 */ 160 static int device_enumerate(ddf_fun_t *fun, unsigned port) 157 * @param speed USB speed of the new device 158 */ 159 static int device_enumerate(ddf_fun_t *fun, unsigned port, usb_speed_t speed) 161 160 { 162 161 assert(fun); … … 170 169 int err; 171 170 172 usb_log_debug("Hub %d reported a new USBdevice on port: %u",173 hub->address, port);174 175 device_t *dev = hcd_ddf_fun_create(hcd );171 usb_log_debug("Hub %d reported a new %s device on port: %u", 172 hub->address, usb_str_speed(speed), port); 173 174 device_t *dev = hcd_ddf_fun_create(hcd, speed); 176 175 if (!dev) { 177 176 usb_log_error("Failed to create USB device function."); … … 181 180 dev->hub = hub; 182 181 dev->port = port; 182 dev->speed = speed; 183 183 184 184 if ((err = bus_device_enumerate(dev))) { … … 380 380 } 381 381 382 device_t *hcd_ddf_fun_create(hc_device_t *hc )382 device_t *hcd_ddf_fun_create(hc_device_t *hc, usb_speed_t speed) 383 383 { 384 384 /* Create DDF function for the new device */ … … 398 398 bus_device_init(dev, hc->bus); 399 399 dev->fun = fun; 400 dev->speed = speed; 400 401 return dev; 401 402 } … … 464 465 assert(hcd); 465 466 466 if ((err = bus_reserve_default_address(hcd->bus, USB_SPEED_MAX))) { 467 usb_log_error("Failed to reserve default address for roothub setup: %s", str_error(err)); 468 return err; 469 } 470 471 device_t *dev = hcd_ddf_fun_create(hcd); 467 device_t *dev = hcd_ddf_fun_create(hcd, USB_SPEED_MAX); 472 468 if (!dev) { 473 469 usb_log_error("Failed to create function for the root hub."); 474 goto err_default_address;470 return ENOMEM; 475 471 } 476 472 … … 488 484 } 489 485 490 bus_release_default_address(hcd->bus);491 486 return EOK; 492 487 … … 495 490 err_usb_dev: 496 491 hcd_ddf_fun_destroy(dev); 497 err_default_address:498 bus_release_default_address(hcd->bus);499 492 return err; 500 493 } -
uspace/lib/usbhost/src/usb2_bus.c
r47e9494 reeca8a6 190 190 usb2_bus_t *bus = bus_to_usb2_bus(dev->bus); 191 191 192 /* The speed of the new device was reported by the hub when reserving193 * default address.194 */195 dev->speed = bus->base.default_address_speed;196 192 usb_log_debug("Found new %s speed USB device.", usb_str_speed(dev->speed)); 197 193
Note:
See TracChangeset
for help on using the changeset viewer.