Changes in / [b6c7da6:867e6735] in mainline
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-rhd/root_hub.c
rb6c7da6 r867e6735 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 r867e6735 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/lib/usb/src/pipes.c
rb6c7da6 r867e6735 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/usbdrv.c
rb6c7da6 r867e6735 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.