Changeset 0f4bff8 in mainline
- Timestamp:
- 2013-01-24T21:19:56Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ffa254f1
- Parents:
- ef40434
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhub/port.c
ref40434 r0f4bff8 258 258 assert(port); 259 259 assert(hub); 260 async_exch_t *exch = async_exchange_begin(hub->usb_device->bus_session);260 async_exch_t *exch = usb_device_bus_exchange_begin(hub->usb_device); 261 261 if (!exch) 262 262 return ENOMEM; 263 263 const int rc = usb_device_remove(exch, port->attached_handle); 264 async_exchange_end(exch);264 usb_device_bus_exchange_end(exch); 265 265 if (rc == EOK) 266 266 port->attached_handle = -1; 267 267 return rc; 268 268 269 #if 0270 if (port->attached_device.address < 0) {271 usb_log_warning(272 "Device on port %zu removed before being registered.\n",273 port->port_number);274 275 /*276 * Device was removed before port reset completed.277 * We will announce a failed port reset to unblock the278 * port reset callback from new device wrapper.279 */280 usb_hub_port_reset_fail(port);281 return EOK;282 }283 284 fibril_mutex_lock(&port->mutex);285 assert(port->attached_device.fun);286 usb_log_debug("Removing device on port %zu.\n", port->port_number);287 int ret = ddf_fun_unbind(port->attached_device.fun);288 if (ret != EOK) {289 usb_log_error("Failed to unbind child function on port"290 " %zu: %s.\n", port->port_number, str_error(ret));291 fibril_mutex_unlock(&port->mutex);292 return ret;293 }294 295 ddf_fun_destroy(port->attached_device.fun);296 port->attached_device.fun = NULL;297 298 ret = usb_hub_unregister_device(&hub->usb_device->hc_conn,299 &port->attached_device);300 if (ret != EOK) {301 usb_log_warning("Failed to unregister address of the "302 "removed device: %s.\n", str_error(ret));303 }304 305 port->attached_device.address = -1;306 fibril_mutex_unlock(&port->mutex);307 usb_log_info("Removed device on port %zu.\n", port->port_number);308 return EOK;309 #endif310 269 } 311 270 … … 410 369 } 411 370 412 /** Callback for enabling a specific port.413 *414 * We wait on a CV until port is reseted.415 * That is announced via change on interrupt pipe.416 *417 * @param port_no Port number (starting at 1).418 * @param arg Custom argument, points to @c usb_hub_dev_t.419 * @return Error code.420 */421 #if 0422 static int enable_port_callback(void *arg)423 {424 usb_hub_port_t *port = arg;425 assert(port);426 const int rc =427 usb_hub_port_set_feature(port, USB_HUB_FEATURE_PORT_RESET);428 if (rc != EOK) {429 usb_log_warning("Port reset failed: %s.\n", str_error(rc));430 return rc;431 }432 433 /*434 * Wait until reset completes.435 */436 fibril_mutex_lock(&port->mutex);437 while (!port->reset_completed) {438 fibril_condvar_wait(&port->reset_cv, &port->mutex);439 }440 fibril_mutex_unlock(&port->mutex);441 442 return port->reset_okay ? EOK : ESTALL;443 }444 #endif445 446 371 /** Fibril for adding a new device. 447 372 * … … 463 388 free(arg); 464 389 465 usb_log_fatal("Creating Exchange on session %p\n", 466 hub->usb_device->bus_session); 467 async_exch_t *exch = async_exchange_begin(hub->usb_device->bus_session); 390 async_exch_t *exch = usb_device_bus_exchange_begin(hub->usb_device); 468 391 if (!exch) { 469 392 usb_log_error("Failed to begin bus exchange\n"); … … 508 431 } 509 432 out: 510 async_exchange_end(exch);433 usb_device_bus_exchange_end(exch); 511 434 512 435 fibril_mutex_lock(&hub->pending_ops_mutex); … … 517 440 518 441 return ret; 519 #if 0520 struct add_device_phase1 *data = arg;521 assert(data);522 523 usb_address_t new_address;524 ddf_fun_t *child_fun;525 526 const int rc = usb_hc_new_device_wrapper(data->hub->usb_device->ddf_dev,527 &data->hub->usb_device->hc_conn, data->speed, enable_port_callback,528 data->port, &new_address, &child_fun);529 530 if (rc == EOK) {531 fibril_mutex_lock(&data->port->mutex);532 data->port->attached_device.fun = child_fun;533 data->port->attached_device.address = new_address;534 fibril_mutex_unlock(&data->port->mutex);535 536 usb_log_info("Detected new device on `%s' (port %zu), "537 "address %d (handle %" PRIun ").\n",538 ddf_dev_get_name(data->hub->usb_device->ddf_dev),539 data->port->port_number, new_address,540 ddf_fun_get_handle(child_fun));541 } else {542 usb_log_error("Failed registering device on port %zu: %s.\n",543 data->port->port_number, str_error(rc));544 }545 546 547 fibril_mutex_lock(&data->hub->pending_ops_mutex);548 assert(data->hub->pending_ops_count > 0);549 --data->hub->pending_ops_count;550 fibril_condvar_signal(&data->hub->pending_ops_cv);551 fibril_mutex_unlock(&data->hub->pending_ops_mutex);552 553 free(arg);554 555 return rc;556 #endif557 442 } 558 443 -
uspace/drv/bus/usb/usbhub/usbhub.c
ref40434 r0f4bff8 99 99 fibril_condvar_initialize(&hub_dev->pending_ops_cv); 100 100 101 102 int opResult = usb_pipe_start_long_transfer(&usb_dev->ctrl_pipe); 101 usb_pipe_t *control_pipe = usb_device_get_default_pipe(usb_dev); 102 103 int opResult = usb_pipe_start_long_transfer(control_pipe); 103 104 if (opResult != EOK) { 104 105 usb_log_error("Failed to start long ctrl pipe transfer: %s\n", … … 110 111 opResult = usb_set_first_configuration(usb_dev); 111 112 if (opResult != EOK) { 112 usb_pipe_end_long_transfer( &usb_dev->ctrl_pipe);113 usb_pipe_end_long_transfer(control_pipe); 113 114 usb_log_error("Could not set hub configuration: %s\n", 114 115 str_error(opResult)); … … 119 120 opResult = usb_hub_process_hub_specific_info(hub_dev); 120 121 if (opResult != EOK) { 121 usb_pipe_end_long_transfer( &usb_dev->ctrl_pipe);122 usb_pipe_end_long_transfer(control_pipe); 122 123 usb_log_error("Could process hub specific info, %s\n", 123 124 str_error(opResult)); … … 130 131 fun_exposed, HUB_FNC_NAME); 131 132 if (hub_dev->hub_fun == NULL) { 132 usb_pipe_end_long_transfer( &usb_dev->ctrl_pipe);133 usb_pipe_end_long_transfer(control_pipe); 133 134 usb_log_error("Failed to create hub function.\n"); 134 135 return ENOMEM; … … 138 139 opResult = ddf_fun_bind(hub_dev->hub_fun); 139 140 if (opResult != EOK) { 140 usb_pipe_end_long_transfer( &usb_dev->ctrl_pipe);141 usb_pipe_end_long_transfer(control_pipe); 141 142 usb_log_error("Failed to bind hub function: %s.\n", 142 143 str_error(opResult)); … … 151 152 usb_hub_polling_terminated_callback, hub_dev); 152 153 if (opResult != EOK) { 153 usb_pipe_end_long_transfer( &usb_dev->ctrl_pipe);154 usb_pipe_end_long_transfer(control_pipe); 154 155 /* Function is already bound */ 155 156 ddf_fun_unbind(hub_dev->hub_fun); … … 163 164 ddf_dev_get_name(hub_dev->usb_device->ddf_dev), hub_dev->port_count); 164 165 165 usb_pipe_end_long_transfer( &usb_dev->ctrl_pipe);166 usb_pipe_end_long_transfer(control_pipe); 166 167 return EOK; 167 168 } … … 186 187 { 187 188 assert(usb_dev); 188 usb_hub_dev_t *hub = usb_dev ->driver_data;189 usb_hub_dev_t *hub = usb_device_data_get(usb_dev); 189 190 assert(hub); 190 191 unsigned tries = 10; … … 271 272 /* Get hub descriptor. */ 272 273 usb_log_debug("Retrieving descriptor\n"); 273 usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe; 274 usb_pipe_t *control_pipe = 275 usb_device_get_default_pipe(hub_dev->usb_device); 274 276 275 277 usb_hub_descriptor_header_t descriptor; … … 360 362 361 363 // TODO: Make sure that the cast is correct 362 usb_standard_configuration_descriptor_t *config_descriptor364 const usb_standard_configuration_descriptor_t *config_descriptor 363 365 = (usb_standard_configuration_descriptor_t *) 364 366 usb_device->descriptors.configuration; … … 367 369 * usb_device->descriptors.configuration i.e. The first one. */ 368 370 const int opResult = usb_request_set_configuration( 369 &usb_device->ctrl_pipe, config_descriptor->configuration_number); 371 usb_device_get_default_pipe(usb_device), 372 config_descriptor->configuration_number); 370 373 if (opResult != EOK) { 371 374 usb_log_error("Failed to set hub configuration: %s.\n", … … 427 430 assert(hub_dev->usb_device); 428 431 usb_log_debug("Global interrupt on a hub\n"); 429 usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe; 432 usb_pipe_t *control_pipe = 433 usb_device_get_default_pipe(hub_dev->usb_device); 430 434 431 435 usb_hub_status_t status; … … 451 455 /* Ack change in hub OC flag */ 452 456 const int ret = usb_request_clear_feature( 453 &hub_dev->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS,457 control_pipe, USB_REQUEST_TYPE_CLASS, 454 458 USB_REQUEST_RECIPIENT_DEVICE, 455 459 USB_HUB_FEATURE_C_HUB_OVER_CURRENT, 0); -
uspace/lib/usbdev/include/usb/dev/driver.h
ref40434 r0f4bff8 110 110 */ 111 111 void *driver_data; 112 112 113 usb_dev_session_t *bus_session; 113 114 } usb_device_t; … … 170 171 void usb_device_deinit(usb_device_t *); 171 172 173 async_exch_t * usb_device_bus_exchange_begin(usb_device_t *); 174 void usb_device_bus_exchange_end(async_exch_t *); 175 172 176 int usb_device_select_interface(usb_device_t *, uint8_t, 173 177 const usb_endpoint_description_t **); … … 180 184 usb_endpoint_mapping_t **, size_t *); 181 185 void usb_device_destroy_pipes(usb_endpoint_mapping_t *, size_t); 186 usb_pipe_t *usb_device_get_default_pipe(usb_device_t *); 187 usb_pipe_t *usb_device_get_pipe(usb_device_t *, usb_endpoint_t, usb_direction_t); 182 188 183 189 void * usb_device_data_alloc(usb_device_t *, size_t); 190 void * usb_device_data_get(usb_device_t *); 184 191 185 192 size_t usb_interface_count_alternates(const uint8_t *, size_t, uint8_t); -
uspace/lib/usbdev/src/devdrv.c
ref40434 r0f4bff8 388 388 } 389 389 390 usb_pipe_t *usb_device_get_default_pipe(usb_device_t *usb_dev) 391 { 392 assert(usb_dev); 393 return &usb_dev->ctrl_pipe; 394 } 395 390 396 /** Initialize new instance of USB device. 391 397 * … … 515 521 } 516 522 523 async_exch_t * usb_device_bus_exchange_begin(usb_device_t *usb_dev) 524 { 525 assert(usb_dev); 526 return async_exchange_begin(usb_dev->bus_session); 527 } 528 529 void usb_device_bus_exchange_end(async_exch_t *exch) 530 { 531 async_exchange_end(exch); 532 } 533 517 534 /** Allocate driver specific data. 518 535 * @param usb_dev usb_device structure. … … 528 545 } 529 546 547 void * usb_device_data_get(usb_device_t *usb_dev) 548 { 549 assert(usb_dev); 550 return usb_dev->driver_data; 551 } 530 552 /** 531 553 * @}
Note:
See TracChangeset
for help on using the changeset viewer.