Changeset 02fc5c4 in mainline for uspace/lib/usbdev/src
- Timestamp:
- 2011-11-25T17:41:23Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 095bddfc
- Parents:
- 56bdd9a4
- Location:
- uspace/lib/usbdev/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/hub.c
r56bdd9a4 r02fc5c4 76 76 { 77 77 CHECK_CONNECTION(connection); 78 78 79 79 async_exch_t *exch = async_exchange_begin(connection->hc_sess); 80 81 sysarg_t address; 82 int rc = async_req_4_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 83 IPC_M_USBHC_REQUEST_ADDRESS, preferred, strict, speed, &address); 84 80 if (!exch) 81 return (usb_address_t)ENOMEM; 82 83 usb_address_t address = preferred; 84 const int ret = usbhc_request_address(exch, &address, strict, speed); 85 85 86 async_exchange_end(exch); 86 87 if (rc != EOK) 88 return (usb_address_t) rc; 89 90 return (usb_address_t) address; 87 return ret == EOK ? address : ret; 91 88 } 92 89 … … 97 94 * @return Error code. 98 95 */ 99 int usb_hc_register_device(usb_hc_connection_t * 96 int usb_hc_register_device(usb_hc_connection_t *connection, 100 97 const usb_hub_attached_device_t *attached_device) 101 98 { 102 99 CHECK_CONNECTION(connection); 103 104 if (attached_device == NULL) 105 return EBADMEM; 106 100 if (attached_device == NULL || attached_device->fun == NULL) 101 return EINVAL; 102 107 103 async_exch_t *exch = async_exchange_begin(connection->hc_sess); 108 int rc = async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 109 IPC_M_USBHC_BIND_ADDRESS, 104 if (!exch) 105 return ENOMEM; 106 const int ret = usbhc_bind_address(exch, 110 107 attached_device->address, attached_device->fun->handle); 111 108 async_exchange_end(exch); 112 113 return r c;109 110 return ret; 114 111 } 115 112 … … 124 121 { 125 122 CHECK_CONNECTION(connection); 126 123 127 124 async_exch_t *exch = async_exchange_begin(connection->hc_sess); 128 int rc = async_req_2_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 129 IPC_M_USBHC_RELEASE_ADDRESS, address); 125 if (!exch) 126 return ENOMEM; 127 const int ret = usbhc_release_address(exch, address); 130 128 async_exchange_end(exch); 131 132 return r c;129 130 return ret; 133 131 } 134 132 -
uspace/lib/usbdev/src/pipesinit.c
r56bdd9a4 r02fc5c4 405 405 } 406 406 407 #define TRY_LOOP(attempt_var) \408 for (attempt_var = 0; attempt_var < 3; attempt_var++)409 410 size_t failed_attempts;411 int rc;412 407 413 408 usb_pipe_start_long_transfer(pipe); … … 415 410 uint8_t dev_descr_start[CTRL_PIPE_MIN_PACKET_SIZE]; 416 411 size_t transferred_size; 417 TRY_LOOP(failed_attempts) { 412 int rc; 413 for (size_t attempt_var = 0; attempt_var < 3; ++attempt_var) { 418 414 rc = usb_request_get_descriptor(pipe, USB_REQUEST_TYPE_STANDARD, 419 415 USB_REQUEST_RECIPIENT_DEVICE, USB_DESCTYPE_DEVICE, … … 450 446 { 451 447 assert(pipe); 448 assert(pipe->wire); 452 449 assert(hc_connection); 453 450 454 451 if (!usb_hc_connection_is_opened(hc_connection)) 455 452 return EBADF; 456 457 const usb_target_t target =458 {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};459 #define _PACK2(high, low) (((high & 0xffff) << 16) | (low & 0xffff))460 461 453 async_exch_t *exch = async_exchange_begin(hc_connection->hc_sess); 462 int rc = async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 463 IPC_M_USBHC_REGISTER_ENDPOINT, target.packed, 464 _PACK2(pipe->transfer_type, pipe->direction), 465 _PACK2(pipe->max_packet_size, interval)); 454 if (!exch) 455 return ENOMEM; 456 const int ret = usbhc_register_endpoint(exch, 457 pipe->wire->address, pipe->endpoint_no, pipe->transfer_type, 458 pipe->direction, pipe->max_packet_size, interval); 459 466 460 async_exchange_end(exch); 467 468 #undef _PACK2 469 return rc; 461 return ret; 470 462 } 471 463 … … 482 474 assert(pipe->wire); 483 475 assert(hc_connection); 484 476 485 477 if (!usb_hc_connection_is_opened(hc_connection)) 486 478 return EBADF; 487 479 488 480 async_exch_t *exch = async_exchange_begin(hc_connection->hc_sess); 489 int rc = async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 490 IPC_M_USBHC_UNREGISTER_ENDPOINT, 481 if (!exch) 482 return ENOMEM; 483 const int ret = usbhc_unregister_endpoint(exch, 491 484 pipe->wire->address, pipe->endpoint_no, pipe->direction); 492 485 async_exchange_end(exch); 493 494 return r c;486 487 return ret; 495 488 } 496 489 -
uspace/lib/usbdev/src/pipesio.c
r56bdd9a4 r02fc5c4 70 70 return ENOTSUP; 71 71 72 const usb_target_t target =73 {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};74 75 72 /* Ensure serialization over the phone. */ 76 73 pipe_start_transaction(pipe); 77 74 async_exch_t *exch = async_exchange_begin(pipe->hc_sess); 78 79 /* 80 * Make call identifying target USB device and type of transfer. 81 */ 82 aid_t opening_request = async_send_2(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 83 IPC_M_USBHC_READ, target.packed, NULL); 84 85 if (opening_request == 0) { 86 async_exchange_end(exch); 75 if (!exch) { 87 76 pipe_end_transaction(pipe); 88 77 return ENOMEM; 89 78 } 90 91 /* 92 * Retrieve the data. 93 */ 94 ipc_call_t data_request_call; 95 aid_t data_request = async_data_read(exch, buffer, size, 96 &data_request_call); 97 98 /* 99 * Since now on, someone else might access the backing phone 100 * without breaking the transfer IPC protocol. 101 */ 79 80 const int ret = usbhc_read(exch, pipe->wire->address, pipe->endpoint_no, 81 0, buffer, size, size_transfered); 102 82 async_exchange_end(exch); 103 83 pipe_end_transaction(pipe); 104 105 if (data_request == 0) { 106 /* 107 * FIXME: 108 * How to let the other side know that we want to abort? 109 */ 110 async_wait_for(opening_request, NULL); 111 return ENOMEM; 112 } 113 114 /* 115 * Wait for the answer. 116 */ 117 sysarg_t data_request_rc; 118 sysarg_t opening_request_rc; 119 async_wait_for(data_request, &data_request_rc); 120 async_wait_for(opening_request, &opening_request_rc); 121 122 if (data_request_rc != EOK) { 123 /* Prefer the return code of the opening request. */ 124 if (opening_request_rc != EOK) { 125 return (int) opening_request_rc; 126 } else { 127 return (int) data_request_rc; 128 } 129 } 130 if (opening_request_rc != EOK) { 131 return (int) opening_request_rc; 132 } 133 134 *size_transfered = IPC_GET_ARG2(data_request_call); 135 136 return EOK; 84 return ret; 137 85 } 138 86 … … 209 157 return ENOTSUP; 210 158 211 const usb_target_t target =212 {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};213 214 159 /* Ensure serialization over the phone. */ 215 160 pipe_start_transaction(pipe); 216 161 async_exch_t *exch = async_exchange_begin(pipe->hc_sess); 217 218 /* 219 * Make call identifying target USB device and type of transfer. 220 */ 221 aid_t opening_request = async_send_3(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 222 IPC_M_USBHC_WRITE, target.packed, size, NULL); 223 224 if (opening_request == 0) { 225 async_exchange_end(exch); 162 if (!exch) { 226 163 pipe_end_transaction(pipe); 227 164 return ENOMEM; 228 165 } 229 230 /* 231 * Send the data. 232 */ 233 int rc = async_data_write_start(exch, buffer, size); 234 235 /* 236 * Since now on, someone else might access the backing phone 237 * without breaking the transfer IPC protocol. 238 */ 166 const int ret = 167 usbhc_write(exch, pipe->wire->address, pipe->endpoint_no, 168 0, buffer, size); 239 169 async_exchange_end(exch); 240 170 pipe_end_transaction(pipe); 241 242 if (rc != EOK) { 243 async_wait_for(opening_request, NULL); 244 return rc; 245 } 246 247 /* 248 * Wait for the answer. 249 */ 250 sysarg_t opening_request_rc; 251 async_wait_for(opening_request, &opening_request_rc); 252 253 return (int) opening_request_rc; 171 return ret; 254 172 } 255 173 … … 334 252 pipe_start_transaction(pipe); 335 253 336 const usb_target_t target =337 {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};338 339 254 assert(setup_buffer_size == 8); 340 255 uint64_t setup_packet; 341 256 memcpy(&setup_packet, setup_buffer, 8); 342 /* 343 * Make call identifying target USB device and control transfer type. 344 */ 257 345 258 async_exch_t *exch = async_exchange_begin(pipe->hc_sess); 346 aid_t opening_request = async_send_4(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 347 IPC_M_USBHC_READ, target.packed, 348 (setup_packet & UINT32_MAX), (setup_packet >> 32), NULL); 349 350 if (opening_request == 0) { 351 async_exchange_end(exch); 259 if (!exch) { 260 pipe_end_transaction(pipe); 352 261 return ENOMEM; 353 262 } 354 263 355 /* 356 * Retrieve the data. 357 */ 358 ipc_call_t data_request_call; 359 aid_t data_request = async_data_read(exch, data_buffer, 360 data_buffer_size, &data_request_call); 361 362 /* 363 * Since now on, someone else might access the backing phone 364 * without breaking the transfer IPC protocol. 365 */ 264 const int ret = usbhc_read(exch, pipe->wire->address, pipe->endpoint_no, 265 setup_packet, data_buffer, data_buffer_size, data_transfered_size); 366 266 async_exchange_end(exch); 367 267 pipe_end_transaction(pipe); 368 369 if (data_request == 0) { 370 async_wait_for(opening_request, NULL); 371 return ENOMEM; 372 } 373 374 /* 375 * Wait for the answer. 376 */ 377 sysarg_t data_request_rc; 378 sysarg_t opening_request_rc; 379 async_wait_for(data_request, &data_request_rc); 380 async_wait_for(opening_request, &opening_request_rc); 381 382 if (data_request_rc != EOK) { 383 /* Prefer the return code of the opening request. */ 384 if (opening_request_rc != EOK) { 385 return (int) opening_request_rc; 386 } else { 387 return (int) data_request_rc; 388 } 389 } 390 if (opening_request_rc != EOK) { 391 return (int) opening_request_rc; 392 } 393 394 *data_transfered_size = IPC_GET_ARG2(data_request_call); 395 396 return EOK; 268 return ret; 397 269 } 398 270 … … 475 347 pipe_start_transaction(pipe); 476 348 477 const usb_target_t target =478 {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};479 349 assert(setup_buffer_size == 8); 480 350 uint64_t setup_packet; 481 351 memcpy(&setup_packet, setup_buffer, 8); 482 352 483 /* 484 * Make call identifying target USB device and control transfer type. 485 */ 353 /* Make call identifying target USB device and control transfer type. */ 486 354 async_exch_t *exch = async_exchange_begin(pipe->hc_sess); 487 aid_t opening_request = async_send_5(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 488 IPC_M_USBHC_WRITE, target.packed, data_buffer_size, 489 (setup_packet & UINT32_MAX), (setup_packet >> 32), NULL); 490 491 if (opening_request == 0) { 492 async_exchange_end(exch); 355 if (!exch) { 493 356 pipe_end_transaction(pipe); 494 357 return ENOMEM; 495 358 } 496 497 /* 498 * Send the data (if any). 499 */ 500 if (data_buffer_size > 0) { 501 int rc = async_data_write_start(exch, data_buffer, data_buffer_size); 502 503 /* All data sent, pipe can be released. */ 504 async_exchange_end(exch); 505 pipe_end_transaction(pipe); 506 507 if (rc != EOK) { 508 async_wait_for(opening_request, NULL); 509 return rc; 510 } 511 } else { 512 /* No data to send, we can release the pipe for others. */ 513 async_exchange_end(exch); 514 pipe_end_transaction(pipe); 515 } 516 517 /* 518 * Wait for the answer. 519 */ 520 sysarg_t opening_request_rc; 521 async_wait_for(opening_request, &opening_request_rc); 522 523 return (int) opening_request_rc; 359 const int ret = 360 usbhc_write(exch, pipe->wire->address, pipe->endpoint_no, 361 setup_packet, data_buffer, data_buffer_size); 362 async_exchange_end(exch); 363 pipe_end_transaction(pipe); 364 return ret; 524 365 } 525 366
Note:
See TracChangeset
for help on using the changeset viewer.