Changes in uspace/lib/usbdev/src/devdrv.c [70452dd4:065064e6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/devdrv.c
r70452dd4 r065064e6 41 41 #include <assert.h> 42 42 43 static int generic_add_device(ddf_dev_t *); 43 static int generic_device_add(ddf_dev_t *); 44 static int generic_device_remove(ddf_dev_t *); 45 static int generic_device_gone(ddf_dev_t *); 44 46 45 47 static driver_ops_t generic_driver_ops = { 46 .add_device = generic_add_device 48 .add_device = generic_device_add, 49 .dev_remove = generic_device_remove, 50 .dev_gone = generic_device_gone, 47 51 }; 48 52 static driver_t generic_driver = { … … 50 54 }; 51 55 52 static usb_driver_t *driver = NULL;56 static const usb_driver_t *driver = NULL; 53 57 54 58 … … 111 115 int rc = usb_device_create_pipes(dev->ddf_dev, &dev->wire, endpoints, 112 116 dev->descriptors.configuration, dev->descriptors.configuration_size, 113 dev->interface_no, alternate_setting, 114 &pipes, &pipes_count); 117 dev->interface_no, alternate_setting, &pipes, &pipes_count); 115 118 116 119 if (rc != EOK) { … … 123 126 return EOK; 124 127 } 125 126 /** Callback when new device is supposed to be controlled by this driver.127 * 128 * This callback is a wrapper for USB specific version of @c add_device.128 /*----------------------------------------------------------------------------*/ 129 /** Callback when a new device is supposed to be controlled by this driver. 130 * 131 * This callback is a wrapper for USB specific version of @c device_add. 129 132 * 130 133 * @param gen_dev Device structure as prepared by DDF. 131 134 * @return Error code. 132 135 */ 133 int generic_ add_device(ddf_dev_t *gen_dev)136 int generic_device_add(ddf_dev_t *gen_dev) 134 137 { 135 138 assert(driver); 136 139 assert(driver->ops); 137 assert(driver->ops-> add_device);140 assert(driver->ops->device_add); 138 141 139 142 int rc; … … 147 150 return rc; 148 151 } 149 150 return driver->ops->add_device(dev); 151 } 152 152 gen_dev->driver_data = dev; 153 154 rc = driver->ops->device_add(dev); 155 if (rc != EOK) 156 usb_device_destroy(dev); 157 return rc; 158 } 159 /*----------------------------------------------------------------------------*/ 160 /** Callback when a device is supposed to be removed from the system. 161 * 162 * This callback is a wrapper for USB specific version of @c device_remove. 163 * 164 * @param gen_dev Device structure as prepared by DDF. 165 * @return Error code. 166 */ 167 int generic_device_remove(ddf_dev_t *gen_dev) 168 { 169 assert(driver); 170 assert(driver->ops); 171 if (driver->ops->device_rem == NULL) 172 return ENOTSUP; 173 /* Just tell the driver to stop whatever it is doing, keep structures */ 174 return driver->ops->device_rem(gen_dev->driver_data); 175 } 176 /*----------------------------------------------------------------------------*/ 177 /** Callback when a device was removed from the system. 178 * 179 * This callback is a wrapper for USB specific version of @c device_gone. 180 * 181 * @param gen_dev Device structure as prepared by DDF. 182 * @return Error code. 183 */ 184 int generic_device_gone(ddf_dev_t *gen_dev) 185 { 186 assert(driver); 187 assert(driver->ops); 188 if (driver->ops->device_gone == NULL) 189 return ENOTSUP; 190 usb_device_t *usb_dev = gen_dev->driver_data; 191 const int ret = driver->ops->device_gone(usb_dev); 192 if (ret == EOK) 193 usb_device_destroy(usb_dev); 194 195 return ret; 196 } 197 /*----------------------------------------------------------------------------*/ 153 198 /** Destroy existing pipes of a USB device. 154 199 * … … 275 320 * @return Error code. 276 321 */ 277 int usb_device_create_pipes( ddf_dev_t *dev, usb_device_connection_t *wire,322 int usb_device_create_pipes(const ddf_dev_t *dev, usb_device_connection_t *wire, 278 323 usb_endpoint_description_t **endpoints, 279 uint8_t *config_descr, size_t config_descr_size,324 const uint8_t *config_descr, size_t config_descr_size, 280 325 int interface_no, int interface_setting, 281 326 usb_endpoint_mapping_t **pipes_ptr, size_t *pipes_count_ptr) … … 291 336 int rc; 292 337 293 size_t pipe_count = count_other_pipes(endpoints);338 const size_t pipe_count = count_other_pipes(endpoints); 294 339 if (pipe_count == 0) { 340 *pipes_count_ptr = pipe_count; 295 341 *pipes_ptr = NULL; 296 342 return EOK; … … 349 395 } 350 396 351 usb_hc_connection_close(&hc_conn); 397 if (usb_hc_connection_close(&hc_conn) != EOK) 398 usb_log_warning("usb_device_create_pipes(): " 399 "Failed to close connection.\n"); 352 400 353 401 *pipes_ptr = pipes; … … 371 419 } 372 420 373 usb_hc_connection_close(&hc_conn); 421 if (usb_hc_connection_close(&hc_conn) != EOK) 422 usb_log_warning("usb_device_create_pipes(): " 423 "Failed to close connection.\n"); 374 424 375 425 /* … … 395 445 * @param[in] pipes_count Number of endpoints. 396 446 */ 397 int usb_device_destroy_pipes( ddf_dev_t *dev,447 int usb_device_destroy_pipes(const ddf_dev_t *dev, 398 448 usb_endpoint_mapping_t *pipes, size_t pipes_count) 399 449 { 400 450 assert(dev != NULL); 401 assert(((pipes != NULL) && (pipes_count > 0))402 || ((pipes == NULL) && (pipes_count == 0)));403 451 404 452 if (pipes_count == 0) { 453 assert(pipes == NULL); 405 454 return EOK; 406 455 } 456 assert(pipes != NULL); 407 457 408 458 int rc; … … 422 472 size_t i; 423 473 for (i = 0; i < pipes_count; i++) { 424 usb_pipe_unregister(pipes[i].pipe, &hc_conn); 474 usb_log_debug2("Unregistering pipe %zu (%spresent).\n", 475 i, pipes[i].present ? "" : "not "); 476 if (pipes[i].present) 477 usb_pipe_unregister(pipes[i].pipe, &hc_conn); 425 478 free(pipes[i].pipe); 426 479 } 427 480 428 usb_hc_connection_close(&hc_conn); 481 if (usb_hc_connection_close(&hc_conn) != EOK) 482 usb_log_warning("usb_device_destroy_pipes(): " 483 "Failed to close connection.\n"); 429 484 430 485 free(pipes); … … 544 599 545 600 /* Ignore errors and hope for the best. */ 546 usb_device_destroy_pipes(dev->ddf_dev, dev->pipes, dev->pipes_count); 547 if (dev->descriptors.configuration != NULL) { 548 free(dev->descriptors.configuration); 549 } 601 destroy_current_pipes(dev); 550 602 551 603 if (dev->alternate_interfaces != NULL) { 552 if (dev->alternate_interfaces->alternatives != NULL) { 553 free(dev->alternate_interfaces->alternatives); 554 } 555 free(dev->alternate_interfaces); 556 } 557 558 free(dev); 604 free(dev->alternate_interfaces->alternatives); 605 } 606 free(dev->alternate_interfaces); 607 free(dev->descriptors.configuration); 608 free(dev->driver_data); 609 } 610 611 void * usb_device_data_alloc(usb_device_t *usb_dev, size_t size) 612 { 613 assert(usb_dev); 614 assert(usb_dev->driver_data == NULL); 615 return usb_dev->driver_data = calloc(1, size); 616 559 617 } 560 618
Note:
See TracChangeset
for help on using the changeset viewer.