Changes in uspace/lib/usbdev/src/devdrv.c [b7fd2a0:5a6cc679] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/devdrv.c
rb7fd2a0 r5a6cc679 48 48 #include <devman.h> 49 49 #include <errno.h> 50 #include <str_error.h> 50 51 #include <stdlib.h> 51 52 … … 56 57 /** Connection to device on USB bus */ 57 58 usb_dev_session_t *bus_session; 58 59 59 60 /** devman handle */ 60 61 devman_handle_t handle; 61 62 62 63 /** The default control pipe. */ 63 64 usb_pipe_t ctrl_pipe; 64 65 65 66 /** Other endpoint pipes. 66 67 * … … 69 70 */ 70 71 usb_endpoint_mapping_t *pipes; 71 72 72 73 /** Number of other endpoint pipes. */ 73 74 size_t pipes_count; 74 75 76 /** USB address of this device */ 77 usb_address_t address; 78 79 /** Depth in the USB hub hiearchy */ 80 unsigned depth; 81 82 /** USB speed of this device */ 83 usb_speed_t speed; 84 75 85 /** Current interface. 76 86 * … … 79 89 */ 80 90 int interface_no; 81 91 82 92 /** Alternative interfaces. */ 83 93 usb_alternate_interfaces_t alternate_interfaces; 84 94 85 95 /** Some useful descriptors for USB device. */ 86 96 usb_device_descriptors_t descriptors; 87 97 88 98 /** Generic DDF device backing this one. DO NOT TOUCH! */ 89 99 ddf_dev_t *ddf_dev; 90 100 91 101 /** Custom driver data. 92 102 * … … 146 156 return rc; 147 157 } 148 158 149 159 /* Change current alternative */ 150 160 usb_dev->alternate_interfaces.current = alternate_setting; … … 255 265 256 266 /* Register created pipes. */ 267 unsigned pipes_registered = 0; 257 268 for (size_t i = 0; i < pipe_count; i++) { 258 269 if (pipes[i].present) { 259 rc = usb_pipe_register(&pipes[i].pipe, 260 pipes[i].descriptor->poll_interval); 270 rc = usb_pipe_register(&pipes[i].pipe, pipes[i].descriptor, pipes[i].companion_descriptor); 261 271 if (rc != EOK) { 262 272 goto rollback_unregister_endpoints; 263 273 } 264 274 } 275 pipes_registered++; 265 276 } 266 277 … … 277 288 */ 278 289 rollback_unregister_endpoints: 279 for (size_t i = 0; i < pipe _count; i++) {290 for (size_t i = 0; i < pipes_registered; i++) { 280 291 if (pipes[i].present) { 281 292 usb_pipe_unregister(&pipes[i].pipe); … … 296 307 assert(usb_dev); 297 308 assert(usb_dev->pipes || usb_dev->pipes_count == 0); 298 309 299 310 /* Destroy the pipes. */ 311 int rc; 300 312 for (size_t i = 0; i < usb_dev->pipes_count; ++i) { 301 usb_log_debug2("Unregistering pipe %zu: %spresent. \n",313 usb_log_debug2("Unregistering pipe %zu: %spresent.", 302 314 i, usb_dev->pipes[i].present ? "" : "not "); 303 if (usb_dev->pipes[i].present) 304 usb_pipe_unregister(&usb_dev->pipes[i].pipe); 305 } 306 315 316 rc = usb_device_unmap_ep(usb_dev->pipes + i); 317 if (rc != EOK && rc != ENOENT) 318 usb_log_warning("Unregistering pipe %zu failed: %s", i, str_error(rc)); 319 } 320 307 321 free(usb_dev->pipes); 308 322 usb_dev->pipes = NULL; … … 327 341 } 328 342 329 usb_endpoint_mapping_t * usb_device_get_mapped_ep( 330 usb_device_t *usb_dev, usb_endpoint_t ep) 331 { 332 assert(usb_dev); 333 for (unsigned i = 0; i < usb_dev->pipes_count; ++i) { 334 if (usb_dev->pipes[i].pipe.endpoint_no == ep) 335 return &usb_dev->pipes[i]; 336 } 337 return NULL; 338 } 339 340 int usb_device_get_iface_number(usb_device_t *usb_dev) 343 int usb_device_unmap_ep(usb_endpoint_mapping_t *epm) 344 { 345 assert(epm); 346 347 if (!epm->present) 348 return ENOENT; 349 350 const int rc = usb_pipe_unregister(&epm->pipe); 351 if (rc != EOK) 352 return rc; 353 354 epm->present = false; 355 return EOK; 356 } 357 358 usb_address_t usb_device_get_address(const usb_device_t *usb_dev) 359 { 360 assert(usb_dev); 361 return usb_dev->depth; 362 } 363 364 unsigned usb_device_get_depth(const usb_device_t *usb_dev) 365 { 366 assert(usb_dev); 367 return usb_dev->depth; 368 } 369 370 usb_speed_t usb_device_get_speed(const usb_device_t *usb_dev) 371 { 372 assert(usb_dev); 373 return usb_dev->speed; 374 } 375 376 int usb_device_get_iface_number(const usb_device_t *usb_dev) 341 377 { 342 378 assert(usb_dev); … … 344 380 } 345 381 346 devman_handle_t usb_device_get_devman_handle( usb_device_t *usb_dev)382 devman_handle_t usb_device_get_devman_handle(const usb_device_t *usb_dev) 347 383 { 348 384 assert(usb_dev); … … 394 430 */ 395 431 static errno_t usb_device_init(usb_device_t *usb_dev, ddf_dev_t *ddf_dev, 396 const usb_endpoint_description_t **endpoints, const char **errstr_ptr, 397 devman_handle_t handle, int interface_no) 432 const usb_endpoint_description_t **endpoints, const char **errstr_ptr) 398 433 { 399 434 assert(usb_dev != NULL); … … 403 438 404 439 usb_dev->ddf_dev = ddf_dev; 405 usb_dev->handle = handle;406 usb_dev->interface_no = interface_no;407 440 usb_dev->driver_data = NULL; 408 441 usb_dev->descriptors.full_config = NULL; … … 411 444 usb_dev->pipes = NULL; 412 445 413 usb_dev->bus_session = usb_dev_connect( handle);446 usb_dev->bus_session = usb_dev_connect(usb_dev->handle); 414 447 415 448 if (!usb_dev->bus_session) { … … 420 453 /* This pipe was registered by the hub driver, 421 454 * during device initialization. */ 422 errno_t rc = usb_pipe_initialize_default_control( 423 &usb_dev->ctrl_pipe, usb_dev->bus_session); 455 errno_t rc = usb_pipe_initialize_default_control(&usb_dev->ctrl_pipe, usb_dev->bus_session); 424 456 if (rc != EOK) { 425 457 usb_dev_disconnect(usb_dev->bus_session); … … 440 472 * it makes no sense to speak about alternate interfaces when 441 473 * controlling a device. */ 442 rc =usb_alternate_interfaces_init(&usb_dev->alternate_interfaces,474 usb_alternate_interfaces_init(&usb_dev->alternate_interfaces, 443 475 usb_dev->descriptors.full_config, 444 476 usb_dev->descriptors.full_config_size, usb_dev->interface_no); … … 457 489 } 458 490 459 static errno_t usb_device_get_info(async_sess_t *sess, devman_handle_t *handle, 460 int *iface_no) 461 { 462 assert(handle); 463 assert(iface_no); 464 491 static errno_t usb_device_get_info(async_sess_t *sess, usb_device_t *dev) 492 { 493 assert(dev); 494 465 495 async_exch_t *exch = async_exchange_begin(sess); 466 496 if (!exch) 467 497 return EPARTY; 468 469 errno_t ret = usb_get_my_device_handle(exch, handle); 498 499 usb_device_desc_t dev_desc; 500 const errno_t ret = usb_get_my_description(exch, &dev_desc); 501 470 502 if (ret == EOK) { 471 ret = usb_get_my_interface(exch, iface_no);472 if (ret == ENOTSUP) {473 *iface_no = -1;474 ret = EOK;475 }476 } 477 503 dev->address = dev_desc.address; 504 dev->depth = dev_desc.depth; 505 dev->speed = dev_desc.speed; 506 dev->handle = dev_desc.handle; 507 dev->interface_no = dev_desc.iface; 508 } 509 478 510 async_exchange_end(exch); 479 511 return ret; … … 485 517 assert(ddf_dev); 486 518 assert(err); 487 488 devman_handle_t h = 0;489 int iface_no = -1;490 519 491 520 async_sess_t *sess = ddf_dev_parent_sess_get(ddf_dev); 492 521 if (sess == NULL) 493 522 return ENOMEM; 494 const errno_t ret = usb_device_get_info(sess, &h, &iface_no);495 if (ret != EOK)496 return ret;497 523 498 524 usb_device_t *usb_dev = … … 502 528 return ENOMEM; 503 529 } 504 505 return usb_device_init(usb_dev, ddf_dev, desc, err, h, iface_no); 530 531 const errno_t ret = usb_device_get_info(sess, usb_dev); 532 if (ret != EOK) 533 return ret; 534 535 return usb_device_init(usb_dev, ddf_dev, desc, err); 506 536 } 507 537 … … 517 547 usb_device_t * usb_device_create(devman_handle_t handle) 518 548 { 519 devman_handle_t h = 0;520 int iface_no = -1;521 522 async_sess_t *sess = devman_device_connect(handle, IPC_FLAG_BLOCKING);523 errno_t ret = usb_device_get_info(sess, &h, &iface_no);524 if (sess)525 async_hangup(sess);526 if (ret != EOK)527 return NULL;528 529 549 usb_device_t *usb_dev = malloc(sizeof(usb_device_t)); 530 550 if (!usb_dev) 531 551 return NULL; 532 552 553 async_sess_t *sess = devman_device_connect(handle, IPC_FLAG_BLOCKING); 554 errno_t ret = usb_device_get_info(sess, usb_dev); 555 if (sess) 556 async_hangup(sess); 557 if (ret != EOK) { 558 free(usb_dev); 559 return NULL; 560 } 561 533 562 const char* dummy = NULL; 534 ret = usb_device_init(usb_dev, NULL, NULL, &dummy , handle, iface_no);563 ret = usb_device_init(usb_dev, NULL, NULL, &dummy); 535 564 if (ret != EOK) { 536 565 free(usb_dev);
Note:
See TracChangeset
for help on using the changeset viewer.