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