Changeset 25696fea in mainline for uspace/lib
- Timestamp:
- 2011-10-15T20:05:00Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 22ceff3a
- Parents:
- 1ccc32f5 (diff), 721d4b6e (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
- Files:
-
- 18 edited
-
c/generic/async.c (modified) (2 diffs)
-
usb/include/usb/hc.h (modified) (1 diff)
-
usb/src/hc.c (modified) (1 diff)
-
usbdev/include/usb/dev/dp.h (modified) (3 diffs)
-
usbdev/include/usb/dev/driver.h (modified) (6 diffs)
-
usbdev/include/usb/dev/hub.h (modified) (2 diffs)
-
usbdev/include/usb/dev/pipes.h (modified) (3 diffs)
-
usbdev/include/usb/dev/recognise.h (modified) (1 diff)
-
usbdev/src/altiface.c (modified) (6 diffs)
-
usbdev/src/devdrv.c (modified) (12 diffs)
-
usbdev/src/dp.c (modified) (15 diffs)
-
usbdev/src/hub.c (modified) (14 diffs)
-
usbdev/src/pipes.c (modified) (3 diffs)
-
usbdev/src/pipesinit.c (modified) (11 diffs)
-
usbdev/src/pipesio.c (modified) (2 diffs)
-
usbdev/src/recognise.c (modified) (3 diffs)
-
usbdev/src/request.c (modified) (2 diffs)
-
usbhid/src/hidreport.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
r1ccc32f5 r25696fea 1846 1846 1847 1847 fibril_mutex_lock(&async_sess_mutex); 1848 1849 int rc = async_hangup_internal(sess->phone); 1848 1850 1849 1851 while (!list_empty(&sess->exch_list)) { … … 1858 1860 } 1859 1861 1860 int rc = async_hangup_internal(sess->phone);1861 1862 free(sess); 1862 1863 -
uspace/lib/usb/include/usb/hc.h
r1ccc32f5 r25696fea 53 53 54 54 int usb_hc_connection_initialize_from_device(usb_hc_connection_t *, 55 ddf_dev_t *);55 const ddf_dev_t *); 56 56 int usb_hc_connection_initialize(usb_hc_connection_t *, devman_handle_t); 57 57 -
uspace/lib/usb/src/hc.c
r1ccc32f5 r25696fea 50 50 */ 51 51 int usb_hc_connection_initialize_from_device(usb_hc_connection_t *connection, 52 ddf_dev_t *device)52 const ddf_dev_t *device) 53 53 { 54 54 assert(connection); -
uspace/lib/usbdev/include/usb/dev/dp.h
r1ccc32f5 r25696fea 59 59 typedef struct { 60 60 /** Used descriptor nesting. */ 61 usb_dp_descriptor_nesting_t *nesting;61 const usb_dp_descriptor_nesting_t *nesting; 62 62 } usb_dp_parser_t; 63 63 … … 65 65 typedef struct { 66 66 /** Data to be parsed. */ 67 uint8_t *data;67 const uint8_t *data; 68 68 /** Size of input data in bytes. */ 69 69 size_t size; … … 72 72 } usb_dp_parser_data_t; 73 73 74 uint8_t *usb_dp_get_nested_descriptor(usb_dp_parser_t *, 75 usb_dp_parser_data_t *, uint8_t *); 76 uint8_t *usb_dp_get_sibling_descriptor(usb_dp_parser_t *, 77 usb_dp_parser_data_t *, uint8_t *, uint8_t *); 74 typedef void (*walk_callback_t)(const uint8_t *, size_t, void *); 78 75 79 void usb_dp_walk_simple(uint8_t *, size_t, usb_dp_descriptor_nesting_t *, 80 void (*)(uint8_t *, size_t, void *), void *); 76 const uint8_t *usb_dp_get_nested_descriptor(const usb_dp_parser_t *, 77 const usb_dp_parser_data_t *, const uint8_t *); 78 const uint8_t *usb_dp_get_sibling_descriptor(const usb_dp_parser_t *, 79 const usb_dp_parser_data_t *, const uint8_t *, const uint8_t *); 80 81 void usb_dp_walk_simple(uint8_t *, size_t, const usb_dp_descriptor_nesting_t *, 82 walk_callback_t, void *); 81 83 82 84 #endif -
uspace/lib/usbdev/include/usb/dev/driver.h
r1ccc32f5 r25696fea 43 43 usb_standard_device_descriptor_t device; 44 44 /** Full configuration descriptor of current configuration. */ 45 uint8_t *configuration;45 const uint8_t *configuration; 46 46 size_t configuration_size; 47 47 } usb_device_descriptors_t; … … 53 53 typedef struct { 54 54 /** Interface descriptor. */ 55 usb_standard_interface_descriptor_t *interface;55 const usb_standard_interface_descriptor_t *interface; 56 56 /** Pointer to start of descriptor tree bound with this interface. */ 57 uint8_t *nested_descriptors;57 const uint8_t *nested_descriptors; 58 58 /** Size of data pointed by nested_descriptors in bytes. */ 59 59 size_t nested_descriptors_size; … … 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 … … 154 158 usb_endpoint_description_t **endpoints; 155 159 /** Driver ops. */ 156 usb_driver_ops_t *ops;160 const usb_driver_ops_t *ops; 157 161 } usb_driver_t; 158 162 … … 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 *,166 usb_endpoint_description_t **, uint8_t *, size_t, int, int,169 int usb_device_create_pipes(const ddf_dev_t *, usb_device_connection_t *, 170 usb_endpoint_description_t **, const 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 *); 175 void * usb_device_data_alloc(usb_device_t *, size_t); 171 176 172 size_t usb_interface_count_alternates( uint8_t *, size_t, uint8_t);173 int usb_alternate_interfaces_create( uint8_t *, size_t, int,177 size_t usb_interface_count_alternates(const uint8_t *, size_t, uint8_t); 178 int usb_alternate_interfaces_create(const uint8_t *, size_t, int, 174 179 usb_alternate_interfaces_t **); 175 180 -
uspace/lib/usbdev/include/usb/dev/hub.h
r1ccc32f5 r25696fea 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
r1ccc32f5 r25696fea 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 *, … … 171 171 int usb_pipe_probe_default_control(usb_pipe_t *); 172 172 int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *, 173 size_t, uint8_t *, size_t, usb_device_connection_t *);173 size_t, const uint8_t *, size_t, usb_device_connection_t *); 174 174 int usb_pipe_register_with_speed(usb_pipe_t *, usb_speed_t, 175 175 unsigned int, usb_hc_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
r1ccc32f5 r25696fea 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/altiface.c
r1ccc32f5 r25696fea 48 48 * @return Number of alternate interfaces for @p interface_no interface. 49 49 */ 50 size_t usb_interface_count_alternates( uint8_t *config_descr,50 size_t usb_interface_count_alternates(const uint8_t *config_descr, 51 51 size_t config_descr_size, uint8_t interface_no) 52 52 { … … 54 54 assert(config_descr_size > 0); 55 55 56 usb_dp_parser_t dp_parser = {56 const usb_dp_parser_t dp_parser = { 57 57 .nesting = usb_dp_standard_descriptor_nesting 58 58 }; 59 usb_dp_parser_data_t dp_data = {59 const usb_dp_parser_data_t dp_data = { 60 60 .data = config_descr, 61 61 .size = config_descr_size, … … 65 65 size_t alternate_count = 0; 66 66 67 uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,67 const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser, 68 68 &dp_data, config_descr); 69 69 while (iface_ptr != NULL) { … … 90 90 * @return Error code. 91 91 */ 92 int usb_alternate_interfaces_create( uint8_t *config_descr,92 int usb_alternate_interfaces_create(const uint8_t *config_descr, 93 93 size_t config_descr_size, int interface_number, 94 94 usb_alternate_interfaces_t **alternates_ptr) … … 140 140 = &alternates->alternatives[0]; 141 141 142 uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,142 const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser, 143 143 &dp_data, dp_data.data); 144 144 while (iface_ptr != NULL) { … … 160 160 dp_data.data, iface_ptr); 161 161 if (iface_ptr == NULL) { 162 uint8_t *next = dp_data.data + dp_data.size;162 const uint8_t *next = dp_data.data + dp_data.size; 163 163 cur_alt_iface->nested_descriptors_size 164 164 = next - cur_alt_iface->nested_descriptors; -
uspace/lib/usbdev/src/devdrv.c
r1ccc32f5 r25696fea 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 -
uspace/lib/usbdev/src/dp.c
r1ccc32f5 r25696fea 75 75 * @return Whether @p ptr points inside <code>data->data</code> field. 76 76 */ 77 static bool is_valid_descriptor_pointer( usb_dp_parser_data_t *data,78 uint8_t *ptr)77 static bool is_valid_descriptor_pointer(const usb_dp_parser_data_t *data, 78 const uint8_t *ptr) 79 79 { 80 80 if (ptr == NULL) { … … 100 100 * @retval NULL Invalid input or no next descriptor. 101 101 */ 102 static uint8_t *get_next_descriptor(usb_dp_parser_data_t *data,103 uint8_t *current)102 static const uint8_t *get_next_descriptor(const usb_dp_parser_data_t *data, 103 const uint8_t *current) 104 104 { 105 105 assert(is_valid_descriptor_pointer(data, current)); 106 106 107 uint8_t current_length = *current;108 uint8_t *next = current + current_length;107 const uint8_t current_length = *current; 108 const uint8_t *next = current + current_length; 109 109 110 110 if (!is_valid_descriptor_pointer(data, next)) { … … 124 124 * @retval -1 Invalid input. 125 125 */ 126 static int get_descriptor_type( usb_dp_parser_data_t *data,uint8_t *start)126 static int get_descriptor_type(const usb_dp_parser_data_t *data, const uint8_t *start) 127 127 { 128 128 if (start == NULL) { … … 145 145 * @return Whether @p child could be child of @p parent. 146 146 */ 147 static bool is_nested_descriptor_type( usb_dp_parser_t *parser,147 static bool is_nested_descriptor_type(const usb_dp_parser_t *parser, 148 148 int child, int parent) 149 149 { 150 usb_dp_descriptor_nesting_t *nesting = parser->nesting;150 const usb_dp_descriptor_nesting_t *nesting = parser->nesting; 151 151 while ((nesting->child > 0) && (nesting->parent > 0)) { 152 152 if ((nesting->child == child) && (nesting->parent == parent)) { … … 166 166 * @return Whether @p child could be child of @p parent. 167 167 */ 168 static bool is_nested_descriptor( usb_dp_parser_t *parser,169 usb_dp_parser_data_t *data, uint8_t *child,uint8_t *parent)168 static bool is_nested_descriptor(const usb_dp_parser_t *parser, 169 const usb_dp_parser_data_t *data, const uint8_t *child, const uint8_t *parent) 170 170 { 171 171 return is_nested_descriptor_type(parser, … … 183 183 * @retval NULL Invalid input. 184 184 */ 185 uint8_t *usb_dp_get_nested_descriptor(usb_dp_parser_t *parser,186 usb_dp_parser_data_t *data,uint8_t *parent)185 const uint8_t *usb_dp_get_nested_descriptor(const usb_dp_parser_t *parser, 186 const usb_dp_parser_data_t *data, const uint8_t *parent) 187 187 { 188 188 if (!is_valid_descriptor_pointer(data, parent)) { … … 190 190 } 191 191 192 uint8_t *next = get_next_descriptor(data, parent);192 const uint8_t *next = get_next_descriptor(data, parent); 193 193 if (next == NULL) { 194 194 return NULL; … … 211 211 * @retval NULL Invalid input. 212 212 */ 213 static uint8_t *skip_nested_descriptors(usb_dp_parser_t *parser, 214 usb_dp_parser_data_t *data, uint8_t *parent) 215 { 216 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, parent); 213 static const uint8_t *skip_nested_descriptors(const usb_dp_parser_t *parser, 214 const usb_dp_parser_data_t *data, const uint8_t *parent) 215 { 216 const uint8_t *child = 217 usb_dp_get_nested_descriptor(parser, data, parent); 217 218 if (child == NULL) { 218 219 return get_next_descriptor(data, parent); 219 220 } 220 uint8_t *next_child = skip_nested_descriptors(parser, data, child); 221 const uint8_t *next_child = 222 skip_nested_descriptors(parser, data, child); 221 223 while (is_nested_descriptor(parser, data, next_child, parent)) { 222 224 next_child = skip_nested_descriptors(parser, data, next_child); … … 236 238 * @retval NULL Invalid input. 237 239 */ 238 uint8_t *usb_dp_get_sibling_descriptor(usb_dp_parser_t *parser, 239 usb_dp_parser_data_t *data, uint8_t *parent, uint8_t *sibling) 240 const uint8_t *usb_dp_get_sibling_descriptor( 241 const usb_dp_parser_t *parser, const usb_dp_parser_data_t *data, 242 const uint8_t *parent, const uint8_t *sibling) 240 243 { 241 244 if (!is_valid_descriptor_pointer(data, parent) … … 244 247 } 245 248 246 uint8_t *possible_sibling = skip_nested_descriptors(parser, data, sibling); 249 const uint8_t *possible_sibling = 250 skip_nested_descriptors(parser, data, sibling); 247 251 if (possible_sibling == NULL) { 248 252 return NULL; … … 269 273 * @param arg Custom (user) argument. 270 274 */ 271 static void usb_dp_browse_simple_internal( usb_dp_parser_t *parser,272 usb_dp_parser_data_t *data,uint8_t *root, size_t depth,273 void (*callback)( uint8_t *, size_t, void *), void *arg)275 static void usb_dp_browse_simple_internal(const usb_dp_parser_t *parser, 276 const usb_dp_parser_data_t *data, const uint8_t *root, size_t depth, 277 void (*callback)(const uint8_t *, size_t, void *), void *arg) 274 278 { 275 279 if (root == NULL) { … … 277 281 } 278 282 callback(root, depth, arg); 279 uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);283 const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root); 280 284 do { 281 285 usb_dp_browse_simple_internal(parser, data, child, depth + 1, … … 301 305 */ 302 306 void usb_dp_walk_simple(uint8_t *descriptors, size_t descriptors_size, 303 usb_dp_descriptor_nesting_t *descriptor_nesting,304 void (*callback)(uint8_t *, size_t, void *), void *arg)307 const usb_dp_descriptor_nesting_t *descriptor_nesting, 308 walk_callback_t callback, void *arg) 305 309 { 306 310 if ((descriptors == NULL) || (descriptors_size == 0) … … 309 313 } 310 314 311 usb_dp_parser_data_t data = {315 const usb_dp_parser_data_t data = { 312 316 .data = descriptors, 313 317 .size = descriptors_size, … … 315 319 }; 316 320 317 usb_dp_parser_t parser = {321 const usb_dp_parser_t parser = { 318 322 .nesting = descriptor_nesting 319 323 }; -
uspace/lib/usbdev/src/hub.c
r1ccc32f5 r25696fea 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
r1ccc32f5 r25696fea 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/pipesinit.c
r1ccc32f5 r25696fea 68 68 * @return Whether the given descriptor is endpoint descriptor. 69 69 */ 70 static inline bool is_endpoint_descriptor( uint8_t *descriptor)70 static inline bool is_endpoint_descriptor(const uint8_t *descriptor) 71 71 { 72 72 return descriptor[1] == USB_DESCTYPE_ENDPOINT; … … 80 80 */ 81 81 static bool endpoint_fits_description(const usb_endpoint_description_t *wanted, 82 usb_endpoint_description_t *found)82 const usb_endpoint_description_t *found) 83 83 { 84 84 #define _SAME(fieldname) ((wanted->fieldname) == (found->fieldname)) … … 120 120 static usb_endpoint_mapping_t *find_endpoint_mapping( 121 121 usb_endpoint_mapping_t *mapping, size_t mapping_count, 122 usb_endpoint_description_t *found_endpoint,122 const usb_endpoint_description_t *found_endpoint, 123 123 int interface_number, int interface_setting) 124 124 { … … 160 160 usb_device_connection_t *wire) 161 161 { 162 usb_endpoint_description_t description;163 162 164 163 /* … … 167 166 168 167 /* Actual endpoint number is in bits 0..3 */ 169 usb_endpoint_t ep_no = endpoint->endpoint_address & 0x0F; 170 171 /* Endpoint direction is set by bit 7 */ 172 description.direction = (endpoint->endpoint_address & 128) 173 ? USB_DIRECTION_IN : USB_DIRECTION_OUT; 174 /* Transfer type is in bits 0..2 and the enum values corresponds 1:1 */ 175 description.transfer_type = endpoint->attributes & 3; 176 177 /* 178 * Get interface characteristics. 179 */ 180 description.interface_class = interface->interface_class; 181 description.interface_subclass = interface->interface_subclass; 182 description.interface_protocol = interface->interface_protocol; 168 const usb_endpoint_t ep_no = endpoint->endpoint_address & 0x0F; 169 170 const usb_endpoint_description_t description = { 171 /* Endpoint direction is set by bit 7 */ 172 .direction = (endpoint->endpoint_address & 128) 173 ? USB_DIRECTION_IN : USB_DIRECTION_OUT, 174 /* Transfer type is in bits 0..2 and 175 * the enum values corresponds 1:1 */ 176 .transfer_type = endpoint->attributes & 3, 177 178 /* Get interface characteristics. */ 179 .interface_class = interface->interface_class, 180 .interface_subclass = interface->interface_subclass, 181 .interface_protocol = interface->interface_protocol, 182 }; 183 183 184 184 /* … … 224 224 static int process_interface( 225 225 usb_endpoint_mapping_t *mapping, size_t mapping_count, 226 usb_dp_parser_t *parser,usb_dp_parser_data_t *parser_data,227 uint8_t *interface_descriptor)228 { 229 uint8_t *descriptor = usb_dp_get_nested_descriptor(parser,226 const usb_dp_parser_t *parser, const usb_dp_parser_data_t *parser_data, 227 const uint8_t *interface_descriptor) 228 { 229 const uint8_t *descriptor = usb_dp_get_nested_descriptor(parser, 230 230 parser_data, interface_descriptor); 231 231 … … 284 284 int usb_pipe_initialize_from_configuration( 285 285 usb_endpoint_mapping_t *mapping, size_t mapping_count, 286 uint8_t *configuration_descriptor, size_t configuration_descriptor_size,286 const uint8_t *config_descriptor, size_t config_descriptor_size, 287 287 usb_device_connection_t *connection) 288 288 { 289 289 assert(connection); 290 290 291 if (config uration_descriptor == NULL) {291 if (config_descriptor == NULL) { 292 292 return EBADMEM; 293 293 } 294 if (config uration_descriptor_size294 if (config_descriptor_size 295 295 < sizeof(usb_standard_configuration_descriptor_t)) { 296 296 return ERANGE; … … 310 310 * Prepare the descriptor parser. 311 311 */ 312 usb_dp_parser_t dp_parser = {312 const usb_dp_parser_t dp_parser = { 313 313 .nesting = descriptor_nesting 314 314 }; 315 usb_dp_parser_data_t dp_data = {316 .data = config uration_descriptor,317 .size = config uration_descriptor_size,315 const usb_dp_parser_data_t dp_data = { 316 .data = config_descriptor, 317 .size = config_descriptor_size, 318 318 .arg = connection 319 319 }; … … 322 322 * Iterate through all interfaces. 323 323 */ 324 uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,325 &dp_data, config uration_descriptor);324 const uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser, 325 &dp_data, config_descriptor); 326 326 if (interface == NULL) { 327 327 return ENOENT; … … 329 329 do { 330 330 (void) process_interface(mapping, mapping_count, 331 &dp_parser, &dp_data, 332 interface); 331 &dp_parser, &dp_data, interface); 333 332 interface = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data, 334 config uration_descriptor, interface);333 config_descriptor, interface); 335 334 } while (interface != NULL); 336 335 … … 514 513 { 515 514 assert(pipe); 515 assert(pipe->wire); 516 516 assert(hc_connection); 517 517 -
uspace/lib/usbdev/src/pipesio.c
r1ccc32f5 r25696fea 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
r1ccc32f5 r25696fea 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; -
uspace/lib/usbdev/src/request.c
r1ccc32f5 r25696fea 425 425 426 426 /* Everything is okay, copy the descriptor. */ 427 memcpy(descriptor, &descriptor_tmp, 428 sizeof(descriptor_tmp)); 427 memcpy(descriptor, &descriptor_tmp, sizeof(descriptor_tmp)); 429 428 430 429 return EOK; … … 470 469 471 470 /* Everything is okay, copy the descriptor. */ 472 memcpy(descriptor, &descriptor_tmp, 473 sizeof(descriptor_tmp)); 471 memcpy(descriptor, &descriptor_tmp, sizeof(descriptor_tmp)); 474 472 475 473 return EOK; -
uspace/lib/usbhid/src/hidreport.c
r1ccc32f5 r25696fea 69 69 * First nested descriptor of the configuration descriptor. 70 70 */ 71 uint8_t *d =71 const uint8_t *d = 72 72 usb_dp_get_nested_descriptor(&parser, &parser_data, 73 73 dev->descriptors.configuration); … … 92 92 * First nested descriptor of the interface descriptor. 93 93 */ 94 uint8_t *iface_desc = d;94 const uint8_t *iface_desc = d; 95 95 d = usb_dp_get_nested_descriptor(&parser, &parser_data, iface_desc); 96 96
Note:
See TracChangeset
for help on using the changeset viewer.
