Changeset d93f5afb in mainline
- Timestamp:
- 2013-08-02T15:59:51Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- dcbda00
- Parents:
- 3969a42
- Location:
- uspace
- Files:
-
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhub/usbhub.c
r3969a42 rd93f5afb 111 111 fibril_condvar_initialize(&hub_dev->pending_ops_cv); 112 112 113 usb_pipe_t *control_pipe = usb_device_get_default_pipe(usb_dev);114 115 int opResult = usb_pipe_start_long_transfer(control_pipe);116 if (opResult != EOK) {117 usb_log_error("Failed to start long ctrl pipe transfer: %s\n",118 str_error(opResult));119 return opResult;120 }121 122 113 /* Set hub's first configuration. (There should be only one) */ 123 opResult = usb_set_first_configuration(usb_dev); 124 if (opResult != EOK) { 125 usb_pipe_end_long_transfer(control_pipe); 114 int opResult = usb_set_first_configuration(usb_dev); 115 if (opResult != EOK) { 126 116 usb_log_error("Could not set hub configuration: %s\n", 127 117 str_error(opResult)); … … 132 122 opResult = usb_hub_process_hub_specific_info(hub_dev); 133 123 if (opResult != EOK) { 134 usb_pipe_end_long_transfer(control_pipe);135 124 usb_log_error("Could process hub specific info, %s\n", 136 125 str_error(opResult)); … … 143 132 fun_exposed, HUB_FNC_NAME); 144 133 if (hub_dev->hub_fun == NULL) { 145 usb_pipe_end_long_transfer(control_pipe);146 134 usb_log_error("Failed to create hub function.\n"); 147 135 return ENOMEM; … … 151 139 opResult = ddf_fun_bind(hub_dev->hub_fun); 152 140 if (opResult != EOK) { 153 usb_pipe_end_long_transfer(control_pipe);154 141 usb_log_error("Failed to bind hub function: %s.\n", 155 142 str_error(opResult)); … … 164 151 -1, usb_hub_polling_terminated_callback, hub_dev); 165 152 if (opResult != EOK) { 166 usb_pipe_end_long_transfer(control_pipe);167 153 /* Function is already bound */ 168 154 ddf_fun_unbind(hub_dev->hub_fun); … … 176 162 usb_device_get_name(hub_dev->usb_device), hub_dev->port_count); 177 163 178 usb_pipe_end_long_transfer(control_pipe);179 164 return EOK; 180 165 } -
uspace/lib/usbdev/include/usb/dev/device.h
r3969a42 rd93f5afb 95 95 void * usb_device_data_get(usb_device_t *); 96 96 97 /* Legacy support */98 usb_address_t usb_device_address(usb_device_t *);99 devman_handle_t usb_device_hc_handle(usb_device_t*);100 101 97 #endif 102 98 /** -
uspace/lib/usbdev/include/usb/dev/pipes.h
r3969a42 rd93f5afb 41 41 #include <usb/usb.h> 42 42 #include <usb/descriptor.h> 43 #include <usb/dev/usb_device_connection.h>44 43 #include <usb_iface.h> 45 44 … … 51 50 */ 52 51 typedef struct { 53 /** The connection used for sending the data. */54 usb_device_connection_t *wire;55 56 52 /** Endpoint number. */ 57 53 usb_endpoint_t endpoint_no; … … 71 67 bool auto_reset_halt; 72 68 69 /** The connection used for sending the data. */ 73 70 usb_dev_session_t *bus_session; 74 71 } usb_pipe_t; … … 108 105 } usb_endpoint_mapping_t; 109 106 110 int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *, 111 usb_endpoint_t, usb_transfer_type_t, size_t, usb_direction_t, 112 usb_dev_session_t *); 113 int usb_pipe_initialize_default_control(usb_pipe_t *, 114 usb_device_connection_t *, usb_dev_session_t *); 107 int usb_pipe_initialize(usb_pipe_t *, usb_endpoint_t, usb_transfer_type_t, 108 size_t, usb_direction_t, usb_dev_session_t *); 109 int usb_pipe_initialize_default_control(usb_pipe_t *, usb_dev_session_t *); 115 110 116 111 int usb_pipe_probe_default_control(usb_pipe_t *); 117 112 int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *, 118 size_t, const uint8_t *, size_t, usb_device_connection_t *, 119 usb_dev_session_t *); 113 size_t, const uint8_t *, size_t, usb_dev_session_t *); 120 114 121 115 int usb_pipe_register(usb_pipe_t *, unsigned); 122 116 int usb_pipe_unregister(usb_pipe_t *); 123 124 int usb_pipe_start_long_transfer(usb_pipe_t *);125 int usb_pipe_end_long_transfer(usb_pipe_t *);126 117 127 118 int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *); -
uspace/lib/usbdev/src/devdrv.c
r3969a42 rd93f5afb 45 45 /** USB device structure. */ 46 46 typedef struct usb_device { 47 /** Connection to USB hc, used by wire and arbitrary requests. */ 48 usb_hc_connection_t hc_conn; 49 /** Connection backing the pipes. 50 * Typically, you will not need to use this attribute at all. 51 */ 52 usb_device_connection_t wire; 47 /** Connection to device on USB bus */ 48 usb_dev_session_t *bus_session; 49 /** devman handle */ 50 devman_handle_t handle; 53 51 /** The default control pipe. */ 54 52 usb_pipe_t ctrl_pipe; … … 78 76 void *driver_data; 79 77 80 /** Connection to device on USB bus */81 usb_dev_session_t *bus_session;82 /** devman handle */83 devman_handle_t handle;84 78 } usb_device_t; 85 79 … … 157 151 assert(usb_dev->descriptors.full_config == NULL); 158 152 159 /* It is worth to start a long transfer. */160 usb_pipe_start_long_transfer(&usb_dev->ctrl_pipe);161 162 153 /* Get the device descriptor. */ 163 154 int rc = usb_request_get_device_descriptor(&usb_dev->ctrl_pipe, 164 155 &usb_dev->descriptors.device); 165 156 if (rc != EOK) { 166 goto leave;157 return rc; 167 158 } 168 159 … … 173 164 &usb_dev->descriptors.full_config_size); 174 165 175 leave:176 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);177 166 178 167 return rc; … … 198 187 * - registers endpoints with the host controller 199 188 * 200 * @param[in] wire Initialized backing connection to the host controller.201 189 * @param[in] endpoints Endpoints description, NULL terminated. 202 190 * @param[in] config_descr Configuration descriptor of active configuration. … … 240 228 int rc = usb_pipe_initialize_from_configuration(pipes, pipe_count, 241 229 usb_dev->descriptors.full_config, 242 usb_dev->descriptors.full_config_size, &usb_dev->wire,230 usb_dev->descriptors.full_config_size, 243 231 usb_dev->bus_session); 244 232 if (rc != EOK) { … … 353 341 } 354 342 355 static int usb_dev_get_info(usb_device_t *usb_dev, devman_handle_t *handle,356 usb_address_t *address, int *iface_no)357 {358 assert(usb_dev);359 360 int ret = EOK;361 async_exch_t *exch = async_exchange_begin(usb_dev->bus_session);362 if (!exch)363 ret = ENOMEM;364 365 if (ret == EOK && address)366 ret = usb_get_my_address(exch, address);367 368 if (ret == EOK && handle)369 ret = usb_get_hc_handle(exch, handle);370 371 if (ret == EOK && iface_no) {372 ret = usb_get_my_interface(exch, iface_no);373 if (ret == ENOTSUP) {374 ret = EOK;375 *iface_no = -1;376 }377 }378 379 async_exchange_end(exch);380 return ret;381 }382 383 343 /** Clean instance of a USB device. 384 344 * … … 393 353 usb_device_destroy_pipes(usb_dev); 394 354 /* Ignore errors and hope for the best. */ 395 usb_hc_connection_deinitialize(&usb_dev->hc_conn);396 355 usb_alternate_interfaces_deinit(&usb_dev->alternate_interfaces); 397 356 usb_device_release_descriptors(usb_dev); … … 437 396 } 438 397 439 /* Get assigned params */440 devman_handle_t hc_handle;441 usb_address_t address;442 443 int rc = usb_dev_get_info(usb_dev, &hc_handle, &address, NULL);444 if (rc != EOK) {445 usb_dev_disconnect(usb_dev->bus_session);446 *errstr_ptr = "device parameters retrieval";447 return rc;448 }449 450 /* Initialize hc connection. */451 usb_hc_connection_initialize(&usb_dev->hc_conn, hc_handle);452 453 /* Initialize backing wire and control pipe. */454 rc = usb_device_connection_initialize(455 &usb_dev->wire, &usb_dev->hc_conn, address);456 if (rc != EOK) {457 usb_dev_disconnect(usb_dev->bus_session);458 *errstr_ptr = "device connection initialization";459 return rc;460 }461 462 398 /* This pipe was registered by the hub driver, 463 399 * during device initialization. */ 464 rc = usb_pipe_initialize_default_control(465 &usb_dev->ctrl_pipe, &usb_dev->wire,usb_dev->bus_session);400 int rc = usb_pipe_initialize_default_control( 401 &usb_dev->ctrl_pipe, usb_dev->bus_session); 466 402 if (rc != EOK) { 467 403 usb_dev_disconnect(usb_dev->bus_session); … … 470 406 } 471 407 472 /* Open hc connection for pipe registration. */473 rc = usb_hc_connection_open(&usb_dev->hc_conn);474 if (rc != EOK) {475 usb_dev_disconnect(usb_dev->bus_session);476 *errstr_ptr = "hc connection open";477 return rc;478 }479 480 408 /* Retrieve standard descriptors. */ 481 409 rc = usb_device_retrieve_descriptors(usb_dev); 482 410 if (rc != EOK) { 483 411 *errstr_ptr = "descriptor retrieval"; 484 usb_hc_connection_close(&usb_dev->hc_conn);485 412 usb_dev_disconnect(usb_dev->bus_session); 486 413 return rc; … … 499 426 rc = usb_device_create_pipes(usb_dev, endpoints); 500 427 if (rc != EOK) { 501 usb_hc_connection_close(&usb_dev->hc_conn);502 428 usb_device_fini(usb_dev); 503 429 *errstr_ptr = "pipes initialization"; … … 506 432 } 507 433 508 usb_hc_connection_close(&usb_dev->hc_conn);509 434 return EOK; 510 435 } … … 645 570 } 646 571 647 usb_address_t usb_device_address(usb_device_t *usb_dev)648 {649 assert(usb_dev);650 return usb_dev->wire.address;651 }652 653 devman_handle_t usb_device_hc_handle(usb_device_t *usb_dev)654 {655 assert(usb_dev);656 return usb_dev->hc_conn.hc_handle;657 }658 572 /** 659 573 * @} -
uspace/lib/usbdev/src/devpoll.c
r3969a42 rd93f5afb 87 87 } 88 88 89 usb_pipe_start_long_transfer(pipe);90 89 size_t failed_attempts = 0; 91 90 while (failed_attempts <= params->max_failures) { … … 148 147 } 149 148 150 usb_pipe_end_long_transfer(pipe);151 152 149 const bool failed = failed_attempts > 0; 153 150 -
uspace/lib/usbdev/src/pipes.c
r3969a42 rd93f5afb 38 38 #include <assert.h> 39 39 40 /** Prepare pipe for a long transfer.41 *42 * Long transfer is transfer consisting of several requests to the HC.43 * Calling this function is optional and it has positive effect of44 * improved performance because IPC session is initiated only once.45 *46 * @param pipe Pipe over which the transfer will happen.47 * @return Error code.48 */49 int usb_pipe_start_long_transfer(usb_pipe_t *pipe)50 {51 assert(pipe);52 assert(pipe->wire);53 assert(pipe->wire->hc_connection);54 return usb_hc_connection_open(pipe->wire->hc_connection);55 }56 57 /** Terminate a long transfer on a pipe.58 * @param pipe Pipe where to end the long transfer.59 * @return Error code.60 * @see usb_pipe_start_long_transfer61 */62 int usb_pipe_end_long_transfer(usb_pipe_t *pipe)63 {64 assert(pipe);65 assert(pipe->wire);66 assert(pipe->wire->hc_connection);67 return usb_hc_connection_close(pipe->wire->hc_connection);68 }69 70 40 /** Try to clear endpoint halt of default control pipe. 71 41 * … … 271 241 * 272 242 * @param pipe Endpoint pipe to be initialized. 273 * @param connection Connection to the USB device backing this pipe (the wire).274 243 * @param endpoint_no Endpoint number (in USB 1.1 in range 0 to 15). 275 244 * @param transfer_type Transfer type (e.g. interrupt or bulk). … … 278 247 * @return Error code. 279 248 */ 280 int usb_pipe_initialize(usb_pipe_t *pipe, 281 usb_device_connection_t *connection, usb_endpoint_t endpoint_no, 249 int usb_pipe_initialize(usb_pipe_t *pipe, usb_endpoint_t endpoint_no, 282 250 usb_transfer_type_t transfer_type, size_t max_packet_size, 283 251 usb_direction_t direction, usb_dev_session_t *bus_session) 284 252 { 285 253 assert(pipe); 286 assert(connection); 287 288 pipe->wire = connection; 254 289 255 pipe->endpoint_no = endpoint_no; 290 256 pipe->transfer_type = transfer_type; … … 300 266 * 301 267 * @param pipe Endpoint pipe to be initialized. 302 * @param connection Connection to the USB device backing this pipe (the wire).303 268 * @return Error code. 304 269 */ 305 270 int usb_pipe_initialize_default_control(usb_pipe_t *pipe, 306 usb_device_connection_t *connection, usb_dev_session_t *bus_session) 307 { 308 assert(pipe); 309 assert(connection); 310 311 int rc = usb_pipe_initialize(pipe, connection, 0, USB_TRANSFER_CONTROL, 271 usb_dev_session_t *bus_session) 272 { 273 assert(pipe); 274 275 const int rc = usb_pipe_initialize(pipe, 0, USB_TRANSFER_CONTROL, 312 276 CTRL_PIPE_MIN_PACKET_SIZE, USB_DIRECTION_BOTH, bus_session); 313 277 -
uspace/lib/usbdev/src/pipesinit.c
r3969a42 rd93f5afb 148 148 * @param interface Interface descriptor under which belongs the @p endpoint. 149 149 * @param endpoint Endpoint descriptor. 150 * @param wire Connection backing the endpoint pipes.151 150 * @return Error code. 152 151 */ … … 155 154 usb_standard_interface_descriptor_t *interface, 156 155 usb_standard_endpoint_descriptor_t *endpoint_desc, 157 usb_dev ice_connection_t *wire, usb_dev_session_t *bus_session)156 usb_dev_session_t *bus_session) 158 157 { 159 158 … … 193 192 } 194 193 195 int rc = usb_pipe_initialize(&ep_mapping->pipe, wire,194 int rc = usb_pipe_initialize(&ep_mapping->pipe, 196 195 ep_no, description.transfer_type, 197 196 uint16_usb2host(endpoint_desc->max_packet_size), … … 236 235 (usb_standard_endpoint_descriptor_t *) 237 236 descriptor, 238 (usb_device_connection_t *) parser_data->arg,239 237 bus_session); 240 238 } … … 281 279 usb_endpoint_mapping_t *mapping, size_t mapping_count, 282 280 const uint8_t *config_descriptor, size_t config_descriptor_size, 283 usb_device_connection_t *connection, usb_dev_session_t *bus_session) 284 { 285 assert(connection); 281 usb_dev_session_t *bus_session) 282 { 286 283 287 284 if (config_descriptor == NULL) { … … 307 304 .data = config_descriptor, 308 305 .size = config_descriptor_size, 309 .arg = connection310 306 }; 311 307 … … 348 344 return EINVAL; 349 345 } 350 351 352 usb_pipe_start_long_transfer(pipe);353 346 354 347 uint8_t dev_descr_start[CTRL_PIPE_MIN_PACKET_SIZE]; … … 368 361 } 369 362 } 370 usb_pipe_end_long_transfer(pipe);371 363 if (rc != EOK) { 372 364 return rc; -
uspace/lib/usbvirt/include/usbvirt/device.h
r3969a42 rd93f5afb 40 40 #include <usb/dev/request.h> 41 41 #include <async.h> 42 #include <errno.h> 42 43 43 44
Note:
See TracChangeset
for help on using the changeset viewer.