Changeset d083126 in mainline for uspace/lib/usbdev
- Timestamp:
- 2011-10-13T13:20:26Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3a5506a
- Parents:
- cff3fb6 (diff), 22a2b763 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib/usbdev
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/include/usb/dev/driver.h
rcff3fb6 rd083126 96 96 usb_device_descriptors_t descriptors; 97 97 98 /** Generic DDF device backing this one. */98 /** Generic DDF device backing this one. RO: DO NOT TOUCH!*/ 99 99 ddf_dev_t *ddf_dev; 100 100 /** Custom driver data. … … 112 112 /** USB driver ops. */ 113 113 typedef struct { 114 /** Callback when new device is about to be controlled by the driver. */ 115 int (*add_device)(usb_device_t *); 114 /** Callback when a new device was added to the system. */ 115 int (*device_add)(usb_device_t *); 116 /** Callback when a device is about to be removed from the system. */ 117 int (*device_rem)(usb_device_t *); 118 /** Callback when a device was removed from the system. */ 119 int (*device_gone)(usb_device_t *); 116 120 } usb_driver_ops_t; 117 121 … … 163 167 164 168 int usb_device_retrieve_descriptors(usb_pipe_t *, usb_device_descriptors_t *); 165 int usb_device_create_pipes( ddf_dev_t *, usb_device_connection_t *,169 int usb_device_create_pipes(const ddf_dev_t *, usb_device_connection_t *, 166 170 usb_endpoint_description_t **, uint8_t *, size_t, int, int, 167 171 usb_endpoint_mapping_t **, size_t *); 168 int usb_device_destroy_pipes( ddf_dev_t *, usb_endpoint_mapping_t *, size_t);172 int usb_device_destroy_pipes(const ddf_dev_t *, usb_endpoint_mapping_t *, size_t); 169 173 int usb_device_create(ddf_dev_t *, usb_endpoint_description_t **, usb_device_t **, const char **); 170 174 void usb_device_destroy(usb_device_t *); -
uspace/lib/usbdev/include/usb/dev/hub.h
rcff3fb6 rd083126 38 38 #define LIBUSBDEV_HUB_H_ 39 39 40 #include <ddf/driver.h> 40 41 #include <sys/types.h> 41 42 #include <usb/hc.h> 42 43 43 44 int usb_hc_new_device_wrapper(ddf_dev_t *, usb_hc_connection_t *, usb_speed_t, 44 int (*)(int, void *), int, void *, 45 usb_address_t *, devman_handle_t *, 46 ddf_dev_ops_t *, void *, ddf_fun_t **); 45 int (*)(void *), void *, usb_address_t *, ddf_dev_ops_t *, void *, 46 ddf_fun_t **); 47 47 48 48 /** Info about device attached to host controller. … … 55 55 /** Device address. */ 56 56 usb_address_t address; 57 /** D evman handleof the device. */58 d evman_handle_t handle;59 } usb_h c_attached_device_t;57 /** DDF function (external) of the device. */ 58 ddf_fun_t *fun; 59 } usb_hub_attached_device_t; 60 60 61 61 usb_address_t usb_hc_request_address(usb_hc_connection_t *, usb_speed_t); 62 62 int usb_hc_register_device(usb_hc_connection_t *, 63 const usb_h c_attached_device_t *);63 const usb_hub_attached_device_t *); 64 64 int usb_hc_unregister_device(usb_hc_connection_t *, usb_address_t); 65 65 -
uspace/lib/usbdev/include/usb/dev/pipes.h
rcff3fb6 rd083126 159 159 usb_device_connection_t *, usb_hc_connection_t *); 160 160 int usb_device_connection_initialize_from_device(usb_device_connection_t *, 161 ddf_dev_t *);161 const ddf_dev_t *); 162 162 int usb_device_connection_initialize(usb_device_connection_t *, 163 163 devman_handle_t, usb_address_t); 164 164 165 int usb_device_get_assigned_interface( ddf_dev_t *);165 int usb_device_get_assigned_interface(const ddf_dev_t *); 166 166 167 167 int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *, … … 185 185 int usb_pipe_control_read(usb_pipe_t *, const void *, size_t, 186 186 void *, size_t, size_t *); 187 int usb_pipe_control_write(usb_pipe_t *, void *, size_t,188 void *, size_t);187 int usb_pipe_control_write(usb_pipe_t *, const void *, size_t, 188 const void *, size_t); 189 189 190 190 #endif -
uspace/lib/usbdev/include/usb/dev/recognise.h
rcff3fb6 rd083126 51 51 52 52 int usb_device_register_child_in_devman(usb_address_t, devman_handle_t, 53 ddf_dev_t *, d evman_handle_t *, ddf_dev_ops_t *, void *, ddf_fun_t **);53 ddf_dev_t *, ddf_dev_ops_t *, void *, ddf_fun_t **); 54 54 55 55 #endif -
uspace/lib/usbdev/src/devdrv.c
rcff3fb6 rd083126 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 = { … … 123 127 return EOK; 124 128 } 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.129 /*----------------------------------------------------------------------------*/ 130 /** Callback when a new device is supposed to be controlled by this driver. 131 * 132 * This callback is a wrapper for USB specific version of @c device_add. 129 133 * 130 134 * @param gen_dev Device structure as prepared by DDF. 131 135 * @return Error code. 132 136 */ 133 int generic_ add_device(ddf_dev_t *gen_dev)137 int generic_device_add(ddf_dev_t *gen_dev) 134 138 { 135 139 assert(driver); 136 140 assert(driver->ops); 137 assert(driver->ops-> add_device);141 assert(driver->ops->device_add); 138 142 139 143 int rc; … … 147 151 return rc; 148 152 } 149 150 return driver->ops->add_device(dev); 151 } 152 153 gen_dev->driver_data = dev; 154 155 return driver->ops->device_add(dev); 156 } 157 /*----------------------------------------------------------------------------*/ 158 /** Callback when a device is supposed to be removed from the system. 159 * 160 * This callback is a wrapper for USB specific version of @c device_remove. 161 * 162 * @param gen_dev Device structure as prepared by DDF. 163 * @return Error code. 164 */ 165 int generic_device_remove(ddf_dev_t *gen_dev) 166 { 167 assert(driver); 168 assert(driver->ops); 169 if (driver->ops->device_rem == NULL) 170 return ENOTSUP; 171 /* Just tell the driver to stop whatever it is doing, keep structures */ 172 return driver->ops->device_rem(gen_dev->driver_data); 173 } 174 /*----------------------------------------------------------------------------*/ 175 /** Callback when a device was removed from the system. 176 * 177 * This callback is a wrapper for USB specific version of @c device_gone. 178 * 179 * @param gen_dev Device structure as prepared by DDF. 180 * @return Error code. 181 */ 182 int generic_device_gone(ddf_dev_t *gen_dev) 183 { 184 assert(driver); 185 assert(driver->ops); 186 if (driver->ops->device_gone == NULL) 187 return ENOTSUP; 188 const int ret = driver->ops->device_gone(gen_dev->driver_data); 189 if (ret == EOK) 190 usb_device_destroy(gen_dev->driver_data); 191 192 return ret; 193 } 194 /*----------------------------------------------------------------------------*/ 153 195 /** Destroy existing pipes of a USB device. 154 196 * … … 275 317 * @return Error code. 276 318 */ 277 int usb_device_create_pipes( ddf_dev_t *dev, usb_device_connection_t *wire,319 int usb_device_create_pipes(const ddf_dev_t *dev, usb_device_connection_t *wire, 278 320 usb_endpoint_description_t **endpoints, 279 321 uint8_t *config_descr, size_t config_descr_size, … … 349 391 } 350 392 351 usb_hc_connection_close(&hc_conn); 393 if (usb_hc_connection_close(&hc_conn) != EOK) 394 usb_log_warning("usb_device_create_pipes(): " 395 "Failed to close connection.\n"); 352 396 353 397 *pipes_ptr = pipes; … … 371 415 } 372 416 373 usb_hc_connection_close(&hc_conn); 417 if (usb_hc_connection_close(&hc_conn) != EOK) 418 usb_log_warning("usb_device_create_pipes(): " 419 "Failed to close connection.\n"); 374 420 375 421 /* … … 395 441 * @param[in] pipes_count Number of endpoints. 396 442 */ 397 int usb_device_destroy_pipes( ddf_dev_t *dev,443 int usb_device_destroy_pipes(const ddf_dev_t *dev, 398 444 usb_endpoint_mapping_t *pipes, size_t pipes_count) 399 445 { … … 426 472 } 427 473 428 usb_hc_connection_close(&hc_conn); 474 if (usb_hc_connection_close(&hc_conn) != EOK) 475 usb_log_warning("usb_device_destroy_pipes(): " 476 "Failed to close connection.\n"); 429 477 430 478 free(pipes); … … 545 593 /* Ignore errors and hope for the best. */ 546 594 usb_device_destroy_pipes(dev->ddf_dev, dev->pipes, dev->pipes_count); 547 if (dev->descriptors.configuration != NULL) { 548 free(dev->descriptors.configuration); 549 } 595 free(dev->descriptors.configuration); 550 596 551 597 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 } 598 free(dev->alternate_interfaces->alternatives); 599 } 600 free(dev->alternate_interfaces); 557 601 558 602 free(dev); -
uspace/lib/usbdev/src/hub.c
rcff3fb6 rd083126 37 37 #include <usb/dev/request.h> 38 38 #include <usb/dev/recognise.h> 39 #include <usb/debug.h> 39 40 #include <usbhc_iface.h> 40 41 #include <errno.h> … … 57 58 assert((conn)); \ 58 59 if (!usb_hc_connection_is_opened((conn))) { \ 59 return ENOENT; \ 60 usb_log_error("Connection not open.\n"); \ 61 return ENOTCONN; \ 60 62 } \ 61 63 } while (false) … … 95 97 */ 96 98 int usb_hc_register_device(usb_hc_connection_t * connection, 97 const usb_h c_attached_device_t *attached_device)99 const usb_hub_attached_device_t *attached_device) 98 100 { 99 101 CHECK_CONNECTION(connection); … … 105 107 int rc = async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE), 106 108 IPC_M_USBHC_BIND_ADDRESS, 107 attached_device->address, attached_device-> handle);109 attached_device->address, attached_device->fun->handle); 108 110 async_exchange_end(exch); 109 111 … … 155 157 * The @p enable_port function is expected to enable signaling on given 156 158 * port. 157 * The two arguments to it can have arbitrary meaning 158 * (the @p port_no is only a suggestion) 159 * and are not touched at all by this function 160 * (they are passed as is to the @p enable_port function). 159 * The argument can have arbitrary meaning and it is not touched at all 160 * by this function (it is passed as is to the @p enable_port function). 161 161 * 162 162 * If the @p enable_port fails (i.e. does not return EOK), the device … … 175 175 * @param[in] enable_port Function for enabling signaling through the port the 176 176 * device is attached to. 177 * @param[in] port_no Port number (passed through to @p enable_port).178 177 * @param[in] arg Any data argument to @p enable_port. 179 178 * @param[out] assigned_address USB address of the device. 180 * @param[out] assigned_handle Devman handle of the new device.181 179 * @param[in] dev_ops Child device ops. 182 180 * @param[in] new_dev_data Arbitrary pointer to be stored in the child … … 194 192 int usb_hc_new_device_wrapper(ddf_dev_t *parent, usb_hc_connection_t *connection, 195 193 usb_speed_t dev_speed, 196 int (*enable_port)(int port_no, void *arg), int port_no, void *arg, 197 usb_address_t *assigned_address, devman_handle_t *assigned_handle, 194 int (*enable_port)(void *arg), void *arg, usb_address_t *assigned_address, 198 195 ddf_dev_ops_t *dev_ops, void *new_dev_data, ddf_fun_t **new_fun) 199 196 { … … 224 221 usb_address_t dev_addr = usb_hc_request_address(&hc_conn, dev_speed); 225 222 if (dev_addr < 0) { 226 usb_hc_connection_close(&hc_conn);227 return EADDRNOTAVAIL;223 rc = EADDRNOTAVAIL; 224 goto close_connection; 228 225 } 229 226 … … 279 276 * device address. 280 277 */ 281 rc = enable_port( port_no,arg);278 rc = enable_port(arg); 282 279 if (rc != EOK) { 283 280 goto leave_release_default_address; … … 320 317 */ 321 318 /* FIXME: create device_register that will get opened ctrl pipe. */ 322 d evman_handle_t child_handle;319 ddf_fun_t *child_fun; 323 320 rc = usb_device_register_child_in_devman(dev_addr, dev_conn.hc_handle, 324 parent, &child_handle, 325 dev_ops, new_dev_data, new_fun); 321 parent, dev_ops, new_dev_data, &child_fun); 326 322 if (rc != EOK) { 327 323 rc = ESTALL; … … 332 328 * And now inform the host controller about the handle. 333 329 */ 334 usb_h c_attached_device_t new_device = {330 usb_hub_attached_device_t new_device = { 335 331 .address = dev_addr, 336 . handle = child_handle332 .fun = child_fun, 337 333 }; 338 334 rc = usb_hc_register_device(&hc_conn, &new_device); … … 341 337 goto leave_release_free_address; 342 338 } 343 344 usb_hc_connection_close(&hc_conn); 339 345 340 346 341 /* … … 350 345 *assigned_address = dev_addr; 351 346 } 352 if (assigned_handle != NULL) { 353 *assigned_handle = child_handle; 354 } 355 356 return EOK; 357 358 347 if (new_fun != NULL) { 348 *new_fun = child_fun; 349 } 350 351 rc = EOK; 352 goto close_connection; 359 353 360 354 /* … … 368 362 usb_hc_unregister_device(&hc_conn, dev_addr); 369 363 370 usb_hc_connection_close(&hc_conn); 364 close_connection: 365 if (usb_hc_connection_close(&hc_conn) != EOK) 366 usb_log_warning("usb_hc_new_device_wrapper(): Failed to close " 367 "connection.\n"); 371 368 372 369 return rc; -
uspace/lib/usbdev/src/pipes.c
rcff3fb6 rd083126 52 52 * @return USB address or error code. 53 53 */ 54 static usb_address_t get_my_address(async_sess_t *sess, ddf_dev_t *dev)54 static usb_address_t get_my_address(async_sess_t *sess, const ddf_dev_t *dev) 55 55 { 56 56 async_exch_t *exch = async_exchange_begin(sess); … … 78 78 * @return Interface number (negative code means any). 79 79 */ 80 int usb_device_get_assigned_interface( ddf_dev_t *device)80 int usb_device_get_assigned_interface(const ddf_dev_t *device) 81 81 { 82 82 async_sess_t *parent_sess = … … 108 108 */ 109 109 int usb_device_connection_initialize_from_device( 110 usb_device_connection_t *connection, ddf_dev_t *dev)110 usb_device_connection_t *connection, const ddf_dev_t *dev) 111 111 { 112 112 assert(connection); -
uspace/lib/usbdev/src/pipesio.c
rcff3fb6 rd083126 469 469 */ 470 470 static int usb_pipe_control_write_no_check(usb_pipe_t *pipe, 471 void *setup_buffer, size_t setup_buffer_size,472 void *data_buffer, size_t data_buffer_size)471 const void *setup_buffer, size_t setup_buffer_size, 472 const void *data_buffer, size_t data_buffer_size) 473 473 { 474 474 /* Ensure serialization over the phone. */ … … 536 536 */ 537 537 int usb_pipe_control_write(usb_pipe_t *pipe, 538 void *setup_buffer, size_t setup_buffer_size,539 void *data_buffer, size_t data_buffer_size)538 const void *setup_buffer, size_t setup_buffer_size, 539 const void *data_buffer, size_t data_buffer_size) 540 540 { 541 541 assert(pipe); -
uspace/lib/usbdev/src/recognise.c
rcff3fb6 rd083126 339 339 * @param[in] hc_handle Handle of the host controller. 340 340 * @param[in] parent Parent device. 341 * @param[out] child_handle Handle of the child device.342 341 * @param[in] dev_ops Child device ops. 343 342 * @param[in] dev_data Arbitrary pointer to be stored in the child … … 348 347 */ 349 348 int usb_device_register_child_in_devman(usb_address_t address, 350 devman_handle_t hc_handle, 351 ddf_dev_t *parent, devman_handle_t *child_handle, 349 devman_handle_t hc_handle, ddf_dev_t *parent, 352 350 ddf_dev_ops_t *dev_ops, void *dev_data, ddf_fun_t **child_fun) 353 351 { … … 414 412 } 415 413 416 if (child_handle != NULL) {417 *child_handle = child->handle;418 }419 420 414 if (child_fun != NULL) { 421 415 *child_fun = child;
Note:
See TracChangeset
for help on using the changeset viewer.