Changes in uspace/lib/usbdev/src/devdrv.c [b803845:882580a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/devdrv.c
rb803845 r882580a 64 64 * @return Task exit status. 65 65 */ 66 int usb_driver_main( usb_driver_t *drv)66 int usb_driver_main(const usb_driver_t *drv) 67 67 { 68 68 assert(drv != NULL); … … 140 140 assert(driver->ops->device_add); 141 141 142 int rc; 143 144 usb_device_t *dev = NULL; 142 usb_device_t *dev = ddf_dev_data_alloc(gen_dev, sizeof(usb_device_t)); 143 if (dev == NULL) { 144 usb_log_error("USB device `%s' structure allocation failed.\n", 145 gen_dev->name); 146 return ENOMEM; 147 } 145 148 const char *err_msg = NULL; 146 rc = usb_device_create(gen_dev, driver->endpoints, &dev, &err_msg);147 if (rc != EOK) { 148 usb_log_error("USB device `%s' creationfailed (%s): %s.\n",149 int rc = usb_device_init(dev, gen_dev, driver->endpoints, &err_msg); 150 if (rc != EOK) { 151 usb_log_error("USB device `%s' init failed (%s): %s.\n", 149 152 gen_dev->name, err_msg, str_error(rc)); 150 153 return rc; 151 154 } 152 gen_dev->driver_data = dev;153 155 154 156 rc = driver->ops->device_add(dev); … … 516 518 517 519 518 /** Create new instance of USB device. 519 * 520 /** Initialize new instance of USB device. 521 * 522 * @param[in] usb_dev Pointer to the new device. 520 523 * @param[in] ddf_dev Generic DDF device backing the USB one. 521 524 * @param[in] endpoints NULL terminated array of endpoints (NULL for none). 522 * @param[out] dev_ptr Where to store pointer to the new device.523 525 * @param[out] errstr_ptr Where to store description of context 524 526 * (in case error occurs). 525 527 * @return Error code. 526 528 */ 527 int usb_device_create(ddf_dev_t *ddf_dev, 528 const usb_endpoint_description_t **endpoints, 529 usb_device_t **dev_ptr, const char **errstr_ptr) 530 { 531 assert(dev_ptr != NULL); 529 int usb_device_init(usb_device_t *usb_dev, ddf_dev_t *ddf_dev, 530 const usb_endpoint_description_t **endpoints, const char **errstr_ptr) 531 { 532 assert(usb_dev != NULL); 532 533 assert(ddf_dev != NULL); 533 534 534 int rc; 535 536 usb_device_t *dev = malloc(sizeof(usb_device_t)); 537 if (dev == NULL) { 538 *errstr_ptr = "structure allocation"; 539 return ENOMEM; 540 } 541 542 // FIXME: proper deallocation in case of errors 543 544 dev->ddf_dev = ddf_dev; 545 dev->driver_data = NULL; 546 dev->descriptors.configuration = NULL; 547 dev->alternate_interfaces = NULL; 548 549 dev->pipes_count = 0; 550 dev->pipes = NULL; 535 usb_dev->ddf_dev = ddf_dev; 536 usb_dev->driver_data = NULL; 537 usb_dev->descriptors.configuration = NULL; 538 usb_dev->alternate_interfaces = NULL; 539 usb_dev->pipes_count = 0; 540 usb_dev->pipes = NULL; 551 541 552 542 /* Initialize backing wire and control pipe. */ 553 rc = init_wire_and_ctrl_pipe(dev, errstr_ptr);543 int rc = init_wire_and_ctrl_pipe(usb_dev, errstr_ptr); 554 544 if (rc != EOK) { 555 545 return rc; … … 557 547 558 548 /* Get our interface. */ 559 dev->interface_no = usb_device_get_assigned_interface(dev->ddf_dev);549 usb_dev->interface_no = usb_device_get_assigned_interface(ddf_dev); 560 550 561 551 /* Retrieve standard descriptors. */ 562 rc = usb_device_retrieve_descriptors(&dev->ctrl_pipe, 563 &dev->descriptors); 564 if (rc != EOK) { 552 rc = usb_device_retrieve_descriptors(&usb_dev->ctrl_pipe, 553 &usb_dev->descriptors); 554 if (rc != EOK) { 555 /* Nothing allocated, nothing to free. */ 565 556 *errstr_ptr = "descriptor retrieval"; 566 557 return rc; 567 558 } 568 559 569 /* Create alternate interfaces. */ 570 rc = usb_alternate_interfaces_create(dev->descriptors.configuration, 571 dev->descriptors.configuration_size, dev->interface_no, 572 &dev->alternate_interfaces); 573 if (rc != EOK) { 574 /* We will try to silently ignore this. */ 575 dev->alternate_interfaces = NULL; 576 } 577 578 rc = initialize_other_pipes(endpoints, dev, 0); 579 if (rc != EOK) { 560 /* Create alternate interfaces. We will silently ignore failure. */ 561 //TODO Why ignore? 562 usb_alternate_interfaces_create(usb_dev->descriptors.configuration, 563 usb_dev->descriptors.configuration_size, usb_dev->interface_no, 564 &usb_dev->alternate_interfaces); 565 566 rc = initialize_other_pipes(endpoints, usb_dev, 0); 567 if (rc != EOK) { 568 /* Full configuration descriptor is allocated. */ 569 free(usb_dev->descriptors.configuration); 570 /* Alternate interfaces may be allocated */ 571 usb_alternate_interfaces_destroy(usb_dev->alternate_interfaces); 580 572 *errstr_ptr = "pipes initialization"; 581 573 return rc; … … 583 575 584 576 *errstr_ptr = NULL; 585 *dev_ptr = dev;586 577 587 578 return EOK; 588 579 } 589 580 590 /** Destroyinstance of a USB device.581 /** Clean instance of a USB device. 591 582 * 592 583 * @param dev Device to be de-initialized. … … 596 587 void usb_device_deinit(usb_device_t *dev) 597 588 { 598 if (dev == NULL) { 599 return; 600 } 601 602 /* Ignore errors and hope for the best. */ 603 destroy_current_pipes(dev); 604 605 if (dev->alternate_interfaces != NULL) { 606 free(dev->alternate_interfaces->alternatives); 607 } 608 free(dev->alternate_interfaces); 609 free(dev->descriptors.configuration); 610 free(dev->driver_data); 589 if (dev) { 590 /* Ignore errors and hope for the best. */ 591 destroy_current_pipes(dev); 592 593 usb_alternate_interfaces_destroy(dev->alternate_interfaces); 594 free(dev->descriptors.configuration); 595 free(dev->driver_data); 596 } 611 597 } 612 598
Note:
See TracChangeset
for help on using the changeset viewer.