Changeset 374552ef in mainline
- Timestamp:
- 2011-02-18T20:22:08Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 423e8c81, 6edc69a, fbf0589
- Parents:
- b6c7da6 (diff), b36e5de2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/iface.c
rb6c7da6 r374552ef 164 164 return EOK; 165 165 } 166 /*----------------------------------------------------------------------------*/167 static int control_write_setup(device_t *dev, usb_target_t target,168 size_t max_packet_size,169 void *data, size_t size,170 usbhc_iface_transfer_out_callback_t callback, void *arg)171 {172 dev_speed_t speed = FULL_SPEED;173 166 174 usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);175 batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,176 max_packet_size, speed, NULL, 0, data, size, NULL, callback, arg);177 if (!batch)178 return ENOMEM;179 batch_control_setup_old(batch);180 return EOK;181 }182 /*----------------------------------------------------------------------------*/183 static int control_write_data(device_t *dev, usb_target_t target,184 size_t max_packet_size,185 void *data, size_t size,186 usbhc_iface_transfer_out_callback_t callback, void *arg)187 {188 dev_speed_t speed = FULL_SPEED;189 167 190 usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);191 batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,192 max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);193 if (!batch)194 return ENOMEM;195 batch_control_write_data_old(batch);196 return EOK;197 }198 /*----------------------------------------------------------------------------*/199 static int control_write_status(device_t *dev, usb_target_t target,200 usbhc_iface_transfer_in_callback_t callback, void *arg)201 {202 size_t max_packet_size = 8;203 dev_speed_t speed = FULL_SPEED;204 205 usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);206 batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,207 max_packet_size, speed, NULL, 0, NULL, 0, callback, NULL, arg);208 if (!batch)209 return ENOMEM;210 batch_control_write_status_old(batch);211 return EOK;212 }213 /*----------------------------------------------------------------------------*/214 static int control_read_setup(device_t *dev, usb_target_t target,215 size_t max_packet_size,216 void *data, size_t size,217 usbhc_iface_transfer_out_callback_t callback, void *arg)218 {219 dev_speed_t speed = FULL_SPEED;220 221 usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);222 batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,223 max_packet_size, speed, NULL, 0, data, size, NULL, callback, arg);224 if (!batch)225 return ENOMEM;226 batch_control_setup_old(batch);227 return EOK;228 }229 /*----------------------------------------------------------------------------*/230 static int control_read_data(device_t *dev, usb_target_t target,231 size_t max_packet_size,232 void *data, size_t size,233 usbhc_iface_transfer_in_callback_t callback, void *arg)234 {235 dev_speed_t speed = FULL_SPEED;236 237 usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);238 batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,239 max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);240 if (!batch)241 return ENOMEM;242 batch_control_read_data_old(batch);243 return EOK;244 }245 /*----------------------------------------------------------------------------*/246 static int control_read_status(device_t *dev, usb_target_t target,247 usbhc_iface_transfer_out_callback_t callback, void *arg)248 {249 size_t max_packet_size = 8;250 dev_speed_t speed = FULL_SPEED;251 252 usb_log_warning("Using deprecated API %s.\n", __FUNCTION__);253 batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,254 max_packet_size, speed, NULL, 0, NULL, 0, NULL, callback, arg);255 if (!batch)256 return ENOMEM;257 batch_control_read_status_old(batch);258 return EOK;259 }260 168 /*----------------------------------------------------------------------------*/ 261 169 usbhc_iface_t uhci_iface = { … … 273 181 .control_read = control_read, 274 182 .control_write = control_write, 275 276 .control_write_setup = control_write_setup,277 .control_write_data = control_write_data,278 .control_write_status = control_write_status,279 280 .control_read_setup = control_read_setup,281 .control_read_data = control_read_data,282 .control_read_status = control_read_status283 183 }; 284 184 /** -
uspace/drv/uhci-rhd/root_hub.c
rb6c7da6 r374552ef 47 47 assert(rh); 48 48 int ret; 49 ret = usb_ drv_find_hc(rh, &instance->hc_handle);49 ret = usb_hc_find(rh->handle, &instance->hc_handle); 50 50 usb_log_info("rh found(%d) hc handle: %d.\n", ret, instance->hc_handle); 51 51 if (ret != EOK) { -
uspace/drv/usbhub/usbhub.c
rb6c7da6 r374552ef 50 50 #include "usb/usb.h" 51 51 52 static int iface_get_hc_handle(device_t *device, devman_handle_t *handle) 53 { 54 return usb_hc_find(device->handle, handle); 55 } 56 52 57 static usb_iface_t hub_usb_iface = { 53 .get_hc_handle = usb_drv_find_hc58 .get_hc_handle = iface_get_hc_handle 54 59 }; 55 60 -
uspace/drv/vhc/connhost.c
rb6c7da6 r374552ef 234 234 } 235 235 236 static int enqueue_transfer_setup(device_t *dev,237 usb_target_t target, usb_transfer_type_t transfer_type,238 void *buffer, size_t size,239 usbhc_iface_transfer_out_callback_t callback, void *arg)240 {241 usb_log_debug2("Transfer SETUP [%d.%d (%s); %zu].\n",242 target.address, target.endpoint,243 usb_str_transfer_type(transfer_type),244 size);245 246 transfer_info_t *transfer247 = create_transfer_info(dev, USB_DIRECTION_OUT, arg);248 transfer->out_callback = callback;249 250 hc_add_transaction_to_device(true, target, transfer_type, buffer, size,251 universal_callback, transfer);252 253 return EOK;254 }255 256 236 static int enqueue_transfer_in(device_t *dev, 257 237 usb_target_t target, usb_transfer_type_t transfer_type, … … 292 272 return enqueue_transfer_in(dev, target, USB_TRANSFER_INTERRUPT, 293 273 data, size, 294 callback, arg);295 }296 297 static int control_write_setup(device_t *dev, usb_target_t target,298 size_t max_packet_size,299 void *data, size_t size,300 usbhc_iface_transfer_out_callback_t callback, void *arg)301 {302 return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL,303 data, size,304 callback, arg);305 }306 307 static int control_write_data(device_t *dev, usb_target_t target,308 size_t max_packet_size,309 void *data, size_t size,310 usbhc_iface_transfer_out_callback_t callback, void *arg)311 {312 return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL,313 data, size,314 callback, arg);315 }316 317 static int control_write_status(device_t *dev, usb_target_t target,318 usbhc_iface_transfer_in_callback_t callback, void *arg)319 {320 return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL,321 NULL, 0,322 274 callback, arg); 323 275 } … … 341 293 } 342 294 343 static int control_read_setup(device_t *dev, usb_target_t target,344 size_t max_packet_size,345 void *data, size_t size,346 usbhc_iface_transfer_out_callback_t callback, void *arg)347 {348 return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL,349 data, size,350 callback, arg);351 }352 353 static int control_read_data(device_t *dev, usb_target_t target,354 size_t max_packet_size,355 void *data, size_t size,356 usbhc_iface_transfer_in_callback_t callback, void *arg)357 {358 return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL,359 data, size,360 callback, arg);361 }362 363 static int control_read_status(device_t *dev, usb_target_t target,364 usbhc_iface_transfer_out_callback_t callback, void *arg)365 {366 return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL,367 NULL, 0,368 callback, arg);369 }370 371 295 static int control_read(device_t *dev, usb_target_t target, 372 296 size_t max_packet_size, … … 455 379 .interrupt_in = interrupt_in, 456 380 457 .control_write_setup = control_write_setup,458 .control_write_data = control_write_data,459 .control_write_status = control_write_status,460 461 381 .control_write = control_write, 462 463 .control_read_setup = control_read_setup,464 .control_read_data = control_read_data,465 .control_read_status = control_read_status,466 467 382 .control_read = control_read 468 383 }; -
uspace/lib/drv/generic/remote_usbhc.c
rb6c7da6 r374552ef 46 46 static void remote_usbhc_interrupt_out(device_t *, void *, ipc_callid_t, ipc_call_t *); 47 47 static void remote_usbhc_interrupt_in(device_t *, void *, ipc_callid_t, ipc_call_t *); 48 static void remote_usbhc_control_write_setup(device_t *, void *, ipc_callid_t, ipc_call_t *);49 static void remote_usbhc_control_write_data(device_t *, void *, ipc_callid_t, ipc_call_t *);50 static void remote_usbhc_control_write_status(device_t *, void *, ipc_callid_t, ipc_call_t *);51 static void remote_usbhc_control_read_setup(device_t *, void *, ipc_callid_t, ipc_call_t *);52 static void remote_usbhc_control_read_data(device_t *, void *, ipc_callid_t, ipc_call_t *);53 static void remote_usbhc_control_read_status(device_t *, void *, ipc_callid_t, ipc_call_t *);54 48 static void remote_usbhc_control_write(device_t *, void *, ipc_callid_t, ipc_call_t *); 55 49 static void remote_usbhc_control_read(device_t *, void *, ipc_callid_t, ipc_call_t *); … … 75 69 remote_usbhc_interrupt_in, 76 70 77 remote_usbhc_control_write_setup,78 remote_usbhc_control_write_data,79 remote_usbhc_control_write_status,80 81 remote_usbhc_control_read_setup,82 remote_usbhc_control_read_data,83 remote_usbhc_control_read_status,84 85 71 remote_usbhc_control_write, 86 72 remote_usbhc_control_read … … 297 283 } 298 284 299 size_t expected_len= DEV_IPC_GET_ARG3(*call);285 size_t max_packet_size = DEV_IPC_GET_ARG3(*call); 300 286 usb_target_t target = { 301 287 .address = DEV_IPC_GET_ARG1(*call), … … 305 291 size_t len = 0; 306 292 void *buffer = NULL; 307 if (expected_len > 0) { 308 int rc = async_data_write_accept(&buffer, false, 309 1, USB_MAX_PAYLOAD_SIZE, 310 0, &len); 311 312 if (rc != EOK) { 313 async_answer_0(callid, rc); 314 return; 315 } 293 294 int rc = async_data_write_accept(&buffer, false, 295 1, USB_MAX_PAYLOAD_SIZE, 296 0, &len); 297 298 if (rc != EOK) { 299 async_answer_0(callid, rc); 300 return; 316 301 } 317 302 … … 328 313 trans->size = len; 329 314 330 int rc = transfer_func(device, target, HACK_MAX_PACKET_SIZE,315 rc = transfer_func(device, target, max_packet_size, 331 316 buffer, len, 332 317 callback_out, trans); … … 354 339 } 355 340 356 size_t len= DEV_IPC_GET_ARG3(*call);341 size_t max_packet_size = DEV_IPC_GET_ARG3(*call); 357 342 usb_target_t target = { 358 343 .address = DEV_IPC_GET_ARG1(*call), … … 360 345 }; 361 346 347 size_t len; 362 348 ipc_callid_t data_callid; 363 349 if (!async_data_read_receive(&data_callid, &len)) { … … 375 361 trans->size = len; 376 362 377 int rc = transfer_func(device, target, HACK_MAX_PACKET_SIZE_INTERRUPT_IN,363 int rc = transfer_func(device, target, max_packet_size, 378 364 trans->buffer, len, 379 365 callback_in, trans); … … 385 371 } 386 372 387 /** Process status part of control transfer.388 *389 * @param device Target device.390 * @param callid Initiating caller.391 * @param call Initiating call.392 * @param direction Transfer direction (read ~ in, write ~ out).393 * @param transfer_in_func Transfer function for control read (might be NULL).394 * @param transfer_out_func Transfer function for control write (might be NULL).395 */396 static void remote_usbhc_status_transfer(device_t *device,397 ipc_callid_t callid, ipc_call_t *call,398 usb_direction_t direction,399 int (*transfer_in_func)(device_t *, usb_target_t,400 usbhc_iface_transfer_in_callback_t, void *),401 int (*transfer_out_func)(device_t *, usb_target_t,402 usbhc_iface_transfer_out_callback_t, void *))403 {404 switch (direction) {405 case USB_DIRECTION_IN:406 if (!transfer_in_func) {407 async_answer_0(callid, ENOTSUP);408 return;409 }410 break;411 case USB_DIRECTION_OUT:412 if (!transfer_out_func) {413 async_answer_0(callid, ENOTSUP);414 return;415 }416 break;417 default:418 assert(false && "unreachable code");419 break;420 }421 422 usb_target_t target = {423 .address = DEV_IPC_GET_ARG1(*call),424 .endpoint = DEV_IPC_GET_ARG2(*call)425 };426 427 async_transaction_t *trans = async_transaction_create(callid);428 if (trans == NULL) {429 async_answer_0(callid, ENOMEM);430 return;431 }432 433 int rc;434 switch (direction) {435 case USB_DIRECTION_IN:436 rc = transfer_in_func(device, target,437 callback_in, trans);438 break;439 case USB_DIRECTION_OUT:440 rc = transfer_out_func(device, target,441 callback_out, trans);442 break;443 default:444 assert(false && "unreachable code");445 break;446 }447 448 if (rc != EOK) {449 async_answer_0(callid, rc);450 async_transaction_destroy(trans);451 }452 }453 454 455 373 void remote_usbhc_interrupt_out(device_t *device, void *iface, 456 374 ipc_callid_t callid, ipc_call_t *call) … … 471 389 return remote_usbhc_in_transfer(device, callid, call, 472 390 usb_iface->interrupt_in); 473 }474 475 void remote_usbhc_control_write_setup(device_t *device, void *iface,476 ipc_callid_t callid, ipc_call_t *call)477 {478 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;479 assert(usb_iface != NULL);480 481 return remote_usbhc_out_transfer(device, callid, call,482 usb_iface->control_write_setup);483 }484 485 void remote_usbhc_control_write_data(device_t *device, void *iface,486 ipc_callid_t callid, ipc_call_t *call)487 {488 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;489 assert(usb_iface != NULL);490 491 return remote_usbhc_out_transfer(device, callid, call,492 usb_iface->control_write_data);493 }494 495 void remote_usbhc_control_write_status(device_t *device, void *iface,496 ipc_callid_t callid, ipc_call_t *call)497 {498 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;499 assert(usb_iface != NULL);500 501 return remote_usbhc_status_transfer(device, callid, call,502 USB_DIRECTION_IN, usb_iface->control_write_status, NULL);503 }504 505 void remote_usbhc_control_read_setup(device_t *device, void *iface,506 ipc_callid_t callid, ipc_call_t *call)507 {508 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;509 assert(usb_iface != NULL);510 511 return remote_usbhc_out_transfer(device, callid, call,512 usb_iface->control_read_setup);513 }514 515 void remote_usbhc_control_read_data(device_t *device, void *iface,516 ipc_callid_t callid, ipc_call_t *call)517 {518 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;519 assert(usb_iface != NULL);520 521 return remote_usbhc_in_transfer(device, callid, call,522 usb_iface->control_read_data);523 }524 525 void remote_usbhc_control_read_status(device_t *device, void *iface,526 ipc_callid_t callid, ipc_call_t *call)527 {528 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;529 assert(usb_iface != NULL);530 531 return remote_usbhc_status_transfer(device, callid, call,532 USB_DIRECTION_OUT, NULL, usb_iface->control_read_status);533 391 } 534 392 … … 549 407 }; 550 408 size_t data_buffer_len = DEV_IPC_GET_ARG3(*call); 409 size_t max_packet_size = DEV_IPC_GET_ARG4(*call); 551 410 552 411 int rc; … … 584 443 trans->size = data_buffer_len; 585 444 586 rc = usb_iface->control_write(device, target, HACK_MAX_PACKET_SIZE,445 rc = usb_iface->control_write(device, target, max_packet_size, 587 446 setup_packet, setup_packet_len, 588 447 data_buffer, data_buffer_len, … … 611 470 .endpoint = DEV_IPC_GET_ARG2(*call) 612 471 }; 472 size_t max_packet_size = DEV_IPC_GET_ARG3(*call); 613 473 614 474 int rc; … … 648 508 } 649 509 650 rc = usb_iface->control_read(device, target, HACK_MAX_PACKET_SIZE,510 rc = usb_iface->control_read(device, target, max_packet_size, 651 511 setup_packet, setup_packet_len, 652 512 trans->buffer, trans->size, -
uspace/lib/drv/include/usbhc_iface.h
rb6c7da6 r374552ef 53 53 * - argument #1 is target address 54 54 * - argument #2 is target endpoint 55 * - argument #3 is buffer size55 * - argument #3 is max packet size of the endpoint 56 56 * - this call is immediately followed by IPC data write (from caller) 57 57 * - the initial call (and the whole transaction) is answer after the … … 66 66 * - argument #1 is target address 67 67 * - argument #2 is target endpoint 68 * - argument #3 is buffer size68 * - argument #3 is max packet size of the endpoint 69 69 * - this call is immediately followed by IPC data read (async version) 70 70 * - the call is not answered until the device returns some data (or until … … 153 153 IPC_M_USBHC_INTERRUPT_IN, 154 154 155 156 /** Start WRITE control transfer.157 * See explanation at usb_iface_funcs_t (OUT transaction).158 */159 IPC_M_USBHC_CONTROL_WRITE_SETUP,160 161 /** Send control-transfer data to device.162 * See explanation at usb_iface_funcs_t (OUT transaction).163 */164 IPC_M_USBHC_CONTROL_WRITE_DATA,165 166 /** Terminate WRITE control transfer.167 * See explanation at usb_iface_funcs_t (NO-DATA transaction).168 */169 IPC_M_USBHC_CONTROL_WRITE_STATUS,170 171 172 173 /** Start READ control transfer.174 * See explanation at usb_iface_funcs_t (OUT transaction).175 */176 IPC_M_USBHC_CONTROL_READ_SETUP,177 178 /** Get control-transfer data from device.179 * See explanation at usb_iface_funcs_t (IN transaction).180 */181 IPC_M_USBHC_CONTROL_READ_DATA,182 183 /** Terminate READ control transfer.184 * See explanation at usb_iface_funcs_t (NO-DATA transaction).185 */186 IPC_M_USBHC_CONTROL_READ_STATUS,187 188 155 /** Issue control WRITE transfer. 189 156 * See explanation at usb_iface_funcs_t (OUT transaction) for … … 194 161 IPC_M_USBHC_CONTROL_WRITE, 195 162 196 /** Issue control WRITEtransfer.163 /** Issue control READ transfer. 197 164 * See explanation at usb_iface_funcs_t (IN transaction) for 198 165 * call parameters. 199 * This call is immediately followed by IPC data read from the caller 200 * (setup packet). 201 * Actual data are retrieved through IPC_M_USBHC_GET_BUFFER. 166 * This call is immediately followed by IPC data write from the caller 167 * (setup packet) and IPC data read (buffer that was read). 202 168 */ 203 169 IPC_M_USBHC_CONTROL_READ, … … 241 207 usbhc_iface_transfer_in_t interrupt_in; 242 208 243 usbhc_iface_transfer_setup_t control_write_setup;244 usbhc_iface_transfer_out_t control_write_data;245 int (*control_write_status)(device_t *, usb_target_t,246 usbhc_iface_transfer_in_callback_t, void *);247 248 usbhc_iface_transfer_setup_t control_read_setup;249 usbhc_iface_transfer_in_t control_read_data;250 int (*control_read_status)(device_t *, usb_target_t,251 usbhc_iface_transfer_out_callback_t, void *);252 253 209 int (*control_write)(device_t *, usb_target_t, 254 210 size_t, -
uspace/lib/usb/src/pipes.c
rb6c7da6 r374552ef 35 35 #include <usb/usb.h> 36 36 #include <usb/pipes.h> 37 #include <usbhc_iface.h> 37 38 #include <errno.h> 38 39 #include <assert.h> 39 #include <usb/usbdrv.h> 40 41 /** Tell USB address assigned to given device. 42 * 43 * @param phone Phone to my HC. 44 * @param dev Device in question. 45 * @return USB address or error code. 46 */ 47 static usb_address_t get_my_address(int phone, device_t *dev) 48 { 49 sysarg_t address; 50 int rc = async_req_2_1(phone, DEV_IFACE_ID(USBHC_DEV_IFACE), 51 IPC_M_USBHC_GET_ADDRESS, 52 dev->handle, &address); 53 54 if (rc != EOK) { 55 return rc; 56 } 57 58 return (usb_address_t) address; 59 } 40 60 41 61 /** Initialize connection to USB device. … … 55 75 usb_address_t my_address; 56 76 57 rc = usb_ drv_find_hc(device, &hc_handle);77 rc = usb_hc_find(device->handle, &hc_handle); 58 78 if (rc != EOK) { 59 79 return rc; … … 65 85 } 66 86 67 my_address = usb_drv_get_my_address(hc_phone, device);87 my_address = get_my_address(hc_phone, device); 68 88 if (my_address < 0) { 69 89 rc = my_address; -
uspace/lib/usb/src/pipesio.c
rb6c7da6 r374552ef 78 78 * Make call identifying target USB device and type of transfer. 79 79 */ 80 aid_t opening_request = async_send_ 3(pipe->hc_phone,80 aid_t opening_request = async_send_4(pipe->hc_phone, 81 81 DEV_IFACE_ID(USBHC_DEV_IFACE), ipc_method, 82 82 pipe->wire->address, pipe->endpoint_no, 83 pipe->max_packet_size, 83 84 NULL); 84 85 if (opening_request == 0) { … … 201 202 * Make call identifying target USB device and type of transfer. 202 203 */ 203 aid_t opening_request = async_send_ 3(pipe->hc_phone,204 aid_t opening_request = async_send_4(pipe->hc_phone, 204 205 DEV_IFACE_ID(USBHC_DEV_IFACE), ipc_method, 205 206 pipe->wire->address, pipe->endpoint_no, 207 pipe->max_packet_size, 206 208 NULL); 207 209 if (opening_request == 0) { … … 283 285 * Make call identifying target USB device and control transfer type. 284 286 */ 285 aid_t opening_request = async_send_ 3(pipe->hc_phone,287 aid_t opening_request = async_send_4(pipe->hc_phone, 286 288 DEV_IFACE_ID(USBHC_DEV_IFACE), IPC_M_USBHC_CONTROL_READ, 287 289 pipe->wire->address, pipe->endpoint_no, 290 pipe->max_packet_size, 288 291 NULL); 289 292 if (opening_request == 0) { … … 402 405 * Make call identifying target USB device and control transfer type. 403 406 */ 404 aid_t opening_request = async_send_ 4(pipe->hc_phone,407 aid_t opening_request = async_send_5(pipe->hc_phone, 405 408 DEV_IFACE_ID(USBHC_DEV_IFACE), IPC_M_USBHC_CONTROL_WRITE, 406 409 pipe->wire->address, pipe->endpoint_no, 407 410 data_buffer_size, 411 pipe->max_packet_size, 408 412 NULL); 409 413 if (opening_request == 0) { -
uspace/lib/usb/src/usbdrv.c
rb6c7da6 r374552ef 34 34 */ 35 35 #include <usb/usbdrv.h> 36 #include <usbhc_iface.h>37 #include <usb_iface.h>38 36 #include <errno.h> 39 #include <str_error.h> 40 41 /** Information about pending transaction on HC. */ 42 typedef struct { 43 /** Phone to host controller driver. */ 44 int phone; 45 /** Data buffer. */ 46 void *buffer; 47 /** Buffer size. */ 48 size_t size; 49 /** Storage for actual number of bytes transferred. */ 50 size_t *size_transferred; 51 /** Initial call reply data. */ 52 ipc_call_t reply; 53 /** Initial call identifier. */ 54 aid_t request; 55 /** Reply data for data read call. */ 56 ipc_call_t read_reply; 57 /** Data read call identifier. */ 58 aid_t read_request; 59 } transfer_info_t; 37 60 38 61 39 /** Find handle of host controller the device is physically attached to. … … 67 45 int usb_drv_find_hc(device_t *dev, devman_handle_t *handle) 68 46 { 69 if (dev == NULL) { 70 return EBADMEM; 71 } 72 if (handle == NULL) { 73 return EBADMEM; 74 } 75 76 int parent_phone = devman_parent_device_connect(dev->handle, 77 IPC_FLAG_BLOCKING); 78 if (parent_phone < 0) { 79 return parent_phone; 80 } 81 82 devman_handle_t h; 83 int rc = async_req_1_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE), 84 IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h); 85 86 async_hangup(parent_phone); 87 88 if (rc != EOK) { 89 return rc; 90 } 91 92 *handle = h; 93 94 return EOK; 47 return ENOTSUP; 95 48 } 96 49 … … 105 58 unsigned int flags) 106 59 { 107 return devman_device_connect(hc_handle, flags);60 return ENOTSUP; 108 61 } 109 62 … … 116 69 int usb_drv_hc_connect_auto(device_t *dev, unsigned int flags) 117 70 { 118 int rc; 119 devman_handle_t hc_handle; 120 121 /* 122 * Call parent hub to obtain device handle of respective HC. 123 */ 124 rc = usb_drv_find_hc(dev, &hc_handle); 125 if (rc != EOK) { 126 return rc; 127 } 128 129 return usb_drv_hc_connect(dev, hc_handle, flags); 71 return ENOTSUP; 130 72 } 131 73 … … 138 80 usb_address_t usb_drv_get_my_address(int phone, device_t *dev) 139 81 { 140 sysarg_t address; 141 int rc = async_req_2_1(phone, DEV_IFACE_ID(USBHC_DEV_IFACE), 142 IPC_M_USBHC_GET_ADDRESS, 143 dev->handle, &address); 144 145 if (rc != EOK) { 146 return rc; 147 } 148 149 return (usb_address_t) address; 82 return ENOTSUP; 150 83 } 151 84 … … 157 90 int usb_drv_reserve_default_address(int phone) 158 91 { 159 return async_req_1_0(phone, DEV_IFACE_ID(USBHC_DEV_IFACE), 160 IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS); 92 return ENOTSUP; 161 93 } 162 94 … … 168 100 int usb_drv_release_default_address(int phone) 169 101 { 170 return async_req_1_0(phone, DEV_IFACE_ID(USBHC_DEV_IFACE), 171 IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS); 102 return ENOTSUP; 172 103 } 173 104 … … 179 110 usb_address_t usb_drv_request_address(int phone) 180 111 { 181 sysarg_t address; 182 int rc = async_req_1_1(phone, DEV_IFACE_ID(USBHC_DEV_IFACE), 183 IPC_M_USBHC_REQUEST_ADDRESS, &address); 184 if (rc != EOK) { 185 return rc; 186 } else { 187 return (usb_address_t) address; 188 } 112 return ENOTSUP; 189 113 } 190 114 … … 199 123 devman_handle_t handle) 200 124 { 201 int rc = async_req_3_0(phone, DEV_IFACE_ID(USBHC_DEV_IFACE), 202 IPC_M_USBHC_BIND_ADDRESS, 203 address, handle); 204 205 return rc; 125 return ENOTSUP; 206 126 } 207 127 … … 214 134 int usb_drv_release_address(int phone, usb_address_t address) 215 135 { 216 return async_req_2_0(phone, DEV_IFACE_ID(USBHC_DEV_IFACE), 217 IPC_M_USBHC_RELEASE_ADDRESS, address); 218 } 219 220 /** Send data to HCD. 221 * 222 * @param phone Phone to HC. 223 * @param method Method used for calling. 224 * @param target Targeted device. 225 * @param buffer Data buffer (NULL to skip data transfer phase). 226 * @param size Buffer size (must be zero when @p buffer is NULL). 227 * @param handle Storage for transaction handle (cannot be NULL). 228 * @return Error status. 229 * @retval EINVAL Invalid parameter. 230 * @retval ENOMEM Not enough memory to complete the operation. 231 */ 232 static int async_send_buffer(int phone, int method, 233 usb_target_t target, 234 void *buffer, size_t size, 235 usb_handle_t *handle) 236 { 237 if (phone < 0) { 238 return EINVAL; 239 } 240 241 if ((buffer == NULL) && (size > 0)) { 242 return EINVAL; 243 } 244 245 if (handle == NULL) { 246 return EINVAL; 247 } 248 249 transfer_info_t *transfer 250 = (transfer_info_t *) malloc(sizeof(transfer_info_t)); 251 if (transfer == NULL) { 252 return ENOMEM; 253 } 254 255 transfer->read_request = 0; 256 transfer->size_transferred = NULL; 257 transfer->buffer = NULL; 258 transfer->size = 0; 259 transfer->phone = phone; 260 261 int rc; 262 263 transfer->request = async_send_4(phone, 264 DEV_IFACE_ID(USBHC_DEV_IFACE), 265 method, 266 target.address, target.endpoint, 267 size, 268 &transfer->reply); 269 270 if (size > 0) { 271 rc = async_data_write_start(phone, buffer, size); 272 if (rc != EOK) { 273 async_wait_for(transfer->request, NULL); 274 return rc; 275 } 276 } 277 278 *handle = (usb_handle_t) transfer; 279 280 return EOK; 281 } 282 283 /** Prepare data retrieval. 284 * 285 * @param phone Opened phone to HCD. 286 * @param method Method used for calling. 287 * @param target Targeted device. 288 * @param buffer Buffer where to store retrieved data 289 * (NULL to skip data transfer phase). 290 * @param size Buffer size (must be zero when @p buffer is NULL). 291 * @param actual_size Storage where actual number of bytes transferred will 292 * be stored. 293 * @param handle Storage for transaction handle (cannot be NULL). 294 * @return Error status. 295 * @retval EINVAL Invalid parameter. 296 * @retval ENOMEM Not enough memory to complete the operation. 297 */ 298 static int async_recv_buffer(int phone, int method, 299 usb_target_t target, 300 void *buffer, size_t size, size_t *actual_size, 301 usb_handle_t *handle) 302 { 303 if (phone < 0) { 304 return EINVAL; 305 } 306 307 if ((buffer == NULL) && (size > 0)) { 308 return EINVAL; 309 } 310 311 if (handle == NULL) { 312 return EINVAL; 313 } 314 315 transfer_info_t *transfer 316 = (transfer_info_t *) malloc(sizeof(transfer_info_t)); 317 if (transfer == NULL) { 318 return ENOMEM; 319 } 320 321 transfer->read_request = 0; 322 transfer->size_transferred = actual_size; 323 transfer->buffer = buffer; 324 transfer->size = size; 325 transfer->phone = phone; 326 327 transfer->request = async_send_4(phone, 328 DEV_IFACE_ID(USBHC_DEV_IFACE), 329 method, 330 target.address, target.endpoint, 331 size, 332 &transfer->reply); 333 334 if (buffer != NULL) { 335 transfer->read_request = async_data_read(phone, buffer, size, 336 &transfer->read_reply); 337 } 338 339 *handle = (usb_handle_t) transfer; 340 341 return EOK; 342 } 343 136 return ENOTSUP; 137 } 344 138 345 139 /** Blocks caller until given USB transaction is finished. … … 355 149 int usb_drv_async_wait_for(usb_handle_t handle) 356 150 { 357 if (handle == 0) { 358 return EBADMEM; 359 } 360 361 int rc = EOK; 362 363 transfer_info_t *transfer = (transfer_info_t *) handle; 364 365 sysarg_t answer_rc; 366 367 /* 368 * If the buffer is not NULL, we must accept some data. 369 */ 370 if ((transfer->buffer != NULL) && (transfer->size > 0)) { 371 async_wait_for(transfer->read_request, &answer_rc); 372 373 if (answer_rc != EOK) { 374 rc = (int) answer_rc; 375 goto leave; 376 } 377 378 if (transfer->size_transferred != NULL) { 379 *(transfer->size_transferred) 380 = IPC_GET_ARG2(transfer->read_reply); 381 } 382 } 383 384 async_wait_for(transfer->request, &answer_rc); 385 386 if (answer_rc != EOK) { 387 rc = (int) answer_rc; 388 goto leave; 389 } 390 391 leave: 392 free(transfer); 393 394 return rc; 151 return ENOTSUP; 395 152 } 396 153 … … 400 157 usb_handle_t *handle) 401 158 { 402 return async_send_buffer(phone, 403 IPC_M_USBHC_INTERRUPT_OUT, 404 target, 405 buffer, size, 406 handle); 159 return ENOTSUP; 407 160 } 408 161 … … 412 165 usb_handle_t *handle) 413 166 { 414 return async_recv_buffer(phone, 415 IPC_M_USBHC_INTERRUPT_IN, 416 target, 417 buffer, size, actual_size, 418 handle); 167 return ENOTSUP; 419 168 } 420 169 … … 424 173 usb_handle_t *handle) 425 174 { 426 return async_send_buffer(phone, 427 IPC_M_USBHC_CONTROL_WRITE_SETUP, 428 target, 429 buffer, size, 430 handle); 175 return ENOTSUP; 431 176 } 432 177 … … 436 181 usb_handle_t *handle) 437 182 { 438 return async_send_buffer(phone, 439 IPC_M_USBHC_CONTROL_WRITE_DATA, 440 target, 441 buffer, size, 442 handle); 183 return ENOTSUP; 443 184 } 444 185 … … 447 188 usb_handle_t *handle) 448 189 { 449 return async_recv_buffer(phone, 450 IPC_M_USBHC_CONTROL_WRITE_STATUS, 451 target, 452 NULL, 0, NULL, 453 handle); 190 return ENOTSUP; 454 191 } 455 192 … … 460 197 usb_handle_t *handle) 461 198 { 462 // FIXME - check input parameters instead of asserting them 463 assert(phone > 0); 464 assert(setup_packet != NULL); 465 assert(setup_packet_size > 0); 466 assert(((buffer != NULL) && (buffer_size > 0)) 467 || ((buffer == NULL) && (buffer_size == 0))); 468 assert(handle != NULL); 469 470 transfer_info_t *transfer 471 = (transfer_info_t *) malloc(sizeof(transfer_info_t)); 472 if (transfer == NULL) { 473 return ENOMEM; 474 } 475 476 transfer->read_request = 0; 477 transfer->size_transferred = NULL; 478 transfer->buffer = NULL; 479 transfer->size = 0; 480 transfer->phone = phone; 481 482 int rc; 483 484 transfer->request = async_send_3(phone, 485 DEV_IFACE_ID(USBHC_DEV_IFACE), 486 IPC_M_USBHC_CONTROL_WRITE, 487 target.address, target.endpoint, 488 &transfer->reply); 489 490 rc = async_data_write_start(phone, setup_packet, setup_packet_size); 491 if (rc != EOK) { 492 async_wait_for(transfer->request, NULL); 493 return rc; 494 } 495 496 if (buffer_size > 0) { 497 rc = async_data_write_start(phone, buffer, buffer_size); 498 if (rc != EOK) { 499 async_wait_for(transfer->request, NULL); 500 return rc; 501 } 502 } 503 504 *handle = (usb_handle_t) transfer; 505 506 return EOK; 199 return ENOTSUP; 507 200 } 508 201 … … 512 205 usb_handle_t *handle) 513 206 { 514 return async_send_buffer(phone, 515 IPC_M_USBHC_CONTROL_READ_SETUP, 516 target, 517 buffer, size, 518 handle); 207 return ENOTSUP; 519 208 } 520 209 … … 524 213 usb_handle_t *handle) 525 214 { 526 return async_recv_buffer(phone, 527 IPC_M_USBHC_CONTROL_READ_DATA, 528 target, 529 buffer, size, actual_size, 530 handle); 215 return ENOTSUP; 531 216 } 532 217 … … 535 220 usb_handle_t *handle) 536 221 { 537 return async_send_buffer(phone, 538 IPC_M_USBHC_CONTROL_READ_STATUS, 539 target, 540 NULL, 0, 541 handle); 222 return ENOTSUP; 542 223 } 543 224 … … 548 229 usb_handle_t *handle) 549 230 { 550 // FIXME - check input parameters instead of asserting them 551 assert(phone > 0); 552 assert(setup_packet != NULL); 553 assert(setup_packet_size > 0); 554 assert(buffer != NULL); 555 assert(buffer_size > 0); 556 assert(handle != NULL); 557 558 transfer_info_t *transfer 559 = (transfer_info_t *) malloc(sizeof(transfer_info_t)); 560 if (transfer == NULL) { 561 return ENOMEM; 562 } 563 564 transfer->size_transferred = actual_size; 565 transfer->buffer = buffer; 566 transfer->size = buffer_size; 567 transfer->phone = phone; 568 569 int rc; 570 571 transfer->request = async_send_4(phone, 572 DEV_IFACE_ID(USBHC_DEV_IFACE), 573 IPC_M_USBHC_CONTROL_READ, 574 target.address, target.endpoint, 575 buffer_size, 576 &transfer->reply); 577 578 rc = async_data_write_start(phone, setup_packet, setup_packet_size); 579 if (rc != EOK) { 580 async_wait_for(transfer->request, NULL); 581 return rc; 582 } 583 584 transfer->read_request = async_data_read(phone, buffer, buffer_size, 585 &transfer->read_reply); 586 587 *handle = (usb_handle_t) transfer; 588 589 return EOK; 231 return ENOTSUP; 590 232 } 591 233
Note:
See TracChangeset
for help on using the changeset viewer.