Changeset 25696fea in mainline for uspace/lib


Ignore:
Timestamp:
2011-10-15T20:05:00Z (14 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
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.
Message:

Merge with mainline

Location:
uspace/lib
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/async.c

    r1ccc32f5 r25696fea  
    18461846       
    18471847        fibril_mutex_lock(&async_sess_mutex);
     1848
     1849        int rc = async_hangup_internal(sess->phone);
    18481850       
    18491851        while (!list_empty(&sess->exch_list)) {
     
    18581860        }
    18591861
    1860         int rc = async_hangup_internal(sess->phone);
    18611862        free(sess);
    18621863       
  • uspace/lib/usb/include/usb/hc.h

    r1ccc32f5 r25696fea  
    5353
    5454int usb_hc_connection_initialize_from_device(usb_hc_connection_t *,
    55     ddf_dev_t *);
     55    const ddf_dev_t *);
    5656int usb_hc_connection_initialize(usb_hc_connection_t *, devman_handle_t);
    5757
  • uspace/lib/usb/src/hc.c

    r1ccc32f5 r25696fea  
    5050 */
    5151int usb_hc_connection_initialize_from_device(usb_hc_connection_t *connection,
    52     ddf_dev_t *device)
     52    const ddf_dev_t *device)
    5353{
    5454        assert(connection);
  • uspace/lib/usbdev/include/usb/dev/dp.h

    r1ccc32f5 r25696fea  
    5959typedef struct {
    6060        /** Used descriptor nesting. */
    61         usb_dp_descriptor_nesting_t *nesting;
     61        const usb_dp_descriptor_nesting_t *nesting;
    6262} usb_dp_parser_t;
    6363
     
    6565typedef struct {
    6666        /** Data to be parsed. */
    67         uint8_t *data;
     67        const uint8_t *data;
    6868        /** Size of input data in bytes. */
    6969        size_t size;
     
    7272} usb_dp_parser_data_t;
    7373
    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 *);
     74typedef void (*walk_callback_t)(const uint8_t *, size_t, void *);
    7875
    79 void usb_dp_walk_simple(uint8_t *, size_t, usb_dp_descriptor_nesting_t *,
    80     void (*)(uint8_t *, size_t, void *), void *);
     76const uint8_t *usb_dp_get_nested_descriptor(const usb_dp_parser_t *,
     77    const usb_dp_parser_data_t *, const uint8_t *);
     78const 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
     81void usb_dp_walk_simple(uint8_t *, size_t, const usb_dp_descriptor_nesting_t *,
     82    walk_callback_t, void *);
    8183
    8284#endif
  • uspace/lib/usbdev/include/usb/dev/driver.h

    r1ccc32f5 r25696fea  
    4343        usb_standard_device_descriptor_t device;
    4444        /** Full configuration descriptor of current configuration. */
    45         uint8_t *configuration;
     45        const uint8_t *configuration;
    4646        size_t configuration_size;
    4747} usb_device_descriptors_t;
     
    5353typedef struct {
    5454        /** Interface descriptor. */
    55         usb_standard_interface_descriptor_t *interface;
     55        const usb_standard_interface_descriptor_t *interface;
    5656        /** Pointer to start of descriptor tree bound with this interface. */
    57         uint8_t *nested_descriptors;
     57        const uint8_t *nested_descriptors;
    5858        /** Size of data pointed by nested_descriptors in bytes. */
    5959        size_t nested_descriptors_size;
     
    9696        usb_device_descriptors_t descriptors;
    9797
    98         /** Generic DDF device backing this one. */
     98        /** Generic DDF device backing this one. RO: DO NOT TOUCH!*/
    9999        ddf_dev_t *ddf_dev;
    100100        /** Custom driver data.
     
    112112/** USB driver ops. */
    113113typedef 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 *);
    116120} usb_driver_ops_t;
    117121
     
    154158        usb_endpoint_description_t **endpoints;
    155159        /** Driver ops. */
    156         usb_driver_ops_t *ops;
     160        const usb_driver_ops_t *ops;
    157161} usb_driver_t;
    158162
     
    163167
    164168int 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,
     169int usb_device_create_pipes(const ddf_dev_t *, usb_device_connection_t *,
     170    usb_endpoint_description_t **, const uint8_t *, size_t, int, int,
    167171    usb_endpoint_mapping_t **, size_t *);
    168 int usb_device_destroy_pipes(ddf_dev_t *, usb_endpoint_mapping_t *, size_t);
     172int usb_device_destroy_pipes(const ddf_dev_t *, usb_endpoint_mapping_t *, size_t);
    169173int usb_device_create(ddf_dev_t *, usb_endpoint_description_t **, usb_device_t **, const char **);
    170174void usb_device_destroy(usb_device_t *);
     175void * usb_device_data_alloc(usb_device_t *, size_t);
    171176
    172 size_t usb_interface_count_alternates(uint8_t *, size_t, uint8_t);
    173 int usb_alternate_interfaces_create(uint8_t *, size_t, int,
     177size_t usb_interface_count_alternates(const uint8_t *, size_t, uint8_t);
     178int usb_alternate_interfaces_create(const uint8_t *, size_t, int,
    174179    usb_alternate_interfaces_t **);
    175180
  • uspace/lib/usbdev/include/usb/dev/hub.h

    r1ccc32f5 r25696fea  
    3838#define LIBUSBDEV_HUB_H_
    3939
     40#include <ddf/driver.h>
    4041#include <sys/types.h>
    4142#include <usb/hc.h>
    4243
    4344int 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 **);
    4747
    4848/** Info about device attached to host controller.
     
    5555        /** Device address. */
    5656        usb_address_t address;
    57         /** Devman handle of the device. */
    58         devman_handle_t handle;
    59 } usb_hc_attached_device_t;
     57        /** DDF function (external) of the device. */
     58        ddf_fun_t *fun;
     59} usb_hub_attached_device_t;
    6060
    6161usb_address_t usb_hc_request_address(usb_hc_connection_t *, usb_speed_t);
    6262int usb_hc_register_device(usb_hc_connection_t *,
    63     const usb_hc_attached_device_t *);
     63    const usb_hub_attached_device_t *);
    6464int usb_hc_unregister_device(usb_hc_connection_t *, usb_address_t);
    6565
  • uspace/lib/usbdev/include/usb/dev/pipes.h

    r1ccc32f5 r25696fea  
    159159    usb_device_connection_t *, usb_hc_connection_t *);
    160160int usb_device_connection_initialize_from_device(usb_device_connection_t *,
    161     ddf_dev_t *);
     161    const ddf_dev_t *);
    162162int usb_device_connection_initialize(usb_device_connection_t *,
    163163    devman_handle_t, usb_address_t);
    164164
    165 int usb_device_get_assigned_interface(ddf_dev_t *);
     165int usb_device_get_assigned_interface(const ddf_dev_t *);
    166166
    167167int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *,
     
    171171int usb_pipe_probe_default_control(usb_pipe_t *);
    172172int 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 *);
    174174int usb_pipe_register_with_speed(usb_pipe_t *, usb_speed_t,
    175175    unsigned int, usb_hc_connection_t *);
     
    185185int usb_pipe_control_read(usb_pipe_t *, const void *, size_t,
    186186    void *, size_t, size_t *);
    187 int usb_pipe_control_write(usb_pipe_t *, void *, size_t,
    188     void *, size_t);
     187int usb_pipe_control_write(usb_pipe_t *, const void *, size_t,
     188    const void *, size_t);
    189189
    190190#endif
  • uspace/lib/usbdev/include/usb/dev/recognise.h

    r1ccc32f5 r25696fea  
    5151
    5252int usb_device_register_child_in_devman(usb_address_t, devman_handle_t,
    53     ddf_dev_t *, devman_handle_t *, ddf_dev_ops_t *, void *, ddf_fun_t **);
     53    ddf_dev_t *, ddf_dev_ops_t *, void *, ddf_fun_t **);
    5454
    5555#endif
  • uspace/lib/usbdev/src/altiface.c

    r1ccc32f5 r25696fea  
    4848 * @return Number of alternate interfaces for @p interface_no interface.
    4949 */
    50 size_t usb_interface_count_alternates(uint8_t *config_descr,
     50size_t usb_interface_count_alternates(const uint8_t *config_descr,
    5151    size_t config_descr_size, uint8_t interface_no)
    5252{
     
    5454        assert(config_descr_size > 0);
    5555
    56         usb_dp_parser_t dp_parser = {
     56        const usb_dp_parser_t dp_parser = {
    5757                .nesting = usb_dp_standard_descriptor_nesting
    5858        };
    59         usb_dp_parser_data_t dp_data = {
     59        const usb_dp_parser_data_t dp_data = {
    6060                .data = config_descr,
    6161                .size = config_descr_size,
     
    6565        size_t alternate_count = 0;
    6666
    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,
    6868            &dp_data, config_descr);
    6969        while (iface_ptr != NULL) {
     
    9090 * @return Error code.
    9191 */
    92 int usb_alternate_interfaces_create(uint8_t *config_descr,
     92int usb_alternate_interfaces_create(const uint8_t *config_descr,
    9393    size_t config_descr_size, int interface_number,
    9494    usb_alternate_interfaces_t **alternates_ptr)
     
    140140            = &alternates->alternatives[0];
    141141
    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,
    143143            &dp_data, dp_data.data);
    144144        while (iface_ptr != NULL) {
     
    160160                    dp_data.data, iface_ptr);
    161161                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;
    163163                        cur_alt_iface->nested_descriptors_size
    164164                            = next - cur_alt_iface->nested_descriptors;
  • uspace/lib/usbdev/src/devdrv.c

    r1ccc32f5 r25696fea  
    4141#include <assert.h>
    4242
    43 static int generic_add_device(ddf_dev_t *);
     43static int generic_device_add(ddf_dev_t *);
     44static int generic_device_remove(ddf_dev_t *);
     45static int generic_device_gone(ddf_dev_t *);
    4446
    4547static 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,
    4751};
    4852static driver_t generic_driver = {
     
    5054};
    5155
    52 static usb_driver_t *driver = NULL;
     56static const usb_driver_t *driver = NULL;
    5357
    5458
     
    111115        int rc = usb_device_create_pipes(dev->ddf_dev, &dev->wire, endpoints,
    112116            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);
    115118
    116119        if (rc != EOK) {
     
    123126        return EOK;
    124127}
    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.
    129132 *
    130133 * @param gen_dev Device structure as prepared by DDF.
    131134 * @return Error code.
    132135 */
    133 int generic_add_device(ddf_dev_t *gen_dev)
     136int generic_device_add(ddf_dev_t *gen_dev)
    134137{
    135138        assert(driver);
    136139        assert(driver->ops);
    137         assert(driver->ops->add_device);
     140        assert(driver->ops->device_add);
    138141
    139142        int rc;
     
    147150                return rc;
    148151        }
    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 */
     167int 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 */
     184int 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/*----------------------------------------------------------------------------*/
    153198/** Destroy existing pipes of a USB device.
    154199 *
     
    275320 * @return Error code.
    276321 */
    277 int usb_device_create_pipes(ddf_dev_t *dev, usb_device_connection_t *wire,
     322int usb_device_create_pipes(const ddf_dev_t *dev, usb_device_connection_t *wire,
    278323    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,
    280325    int interface_no, int interface_setting,
    281326    usb_endpoint_mapping_t **pipes_ptr, size_t *pipes_count_ptr)
     
    291336        int rc;
    292337
    293         size_t pipe_count = count_other_pipes(endpoints);
     338        const size_t pipe_count = count_other_pipes(endpoints);
    294339        if (pipe_count == 0) {
     340                *pipes_count_ptr = pipe_count;
    295341                *pipes_ptr = NULL;
    296342                return EOK;
     
    349395        }
    350396
    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");
    352400
    353401        *pipes_ptr = pipes;
     
    371419        }
    372420
    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");
    374424
    375425        /*
     
    395445 * @param[in] pipes_count Number of endpoints.
    396446 */
    397 int usb_device_destroy_pipes(ddf_dev_t *dev,
     447int usb_device_destroy_pipes(const ddf_dev_t *dev,
    398448    usb_endpoint_mapping_t *pipes, size_t pipes_count)
    399449{
    400450        assert(dev != NULL);
    401         assert(((pipes != NULL) && (pipes_count > 0))
    402             || ((pipes == NULL) && (pipes_count == 0)));
    403451
    404452        if (pipes_count == 0) {
     453                assert(pipes == NULL);
    405454                return EOK;
    406455        }
     456        assert(pipes != NULL);
    407457
    408458        int rc;
     
    422472        size_t i;
    423473        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);
    425478                free(pipes[i].pipe);
    426479        }
    427480
    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");
    429484
    430485        free(pipes);
     
    544599
    545600        /* 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);
    550602
    551603        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
     611void * 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
    559617}
    560618
  • uspace/lib/usbdev/src/dp.c

    r1ccc32f5 r25696fea  
    7575 * @return Whether @p ptr points inside <code>data->data</code> field.
    7676 */
    77 static bool is_valid_descriptor_pointer(usb_dp_parser_data_t *data,
    78     uint8_t *ptr)
     77static bool is_valid_descriptor_pointer(const usb_dp_parser_data_t *data,
     78    const uint8_t *ptr)
    7979{
    8080        if (ptr == NULL) {
     
    100100 * @retval NULL Invalid input or no next descriptor.
    101101 */
    102 static uint8_t *get_next_descriptor(usb_dp_parser_data_t *data,
    103     uint8_t *current)
     102static const uint8_t *get_next_descriptor(const usb_dp_parser_data_t *data,
     103    const uint8_t *current)
    104104{
    105105        assert(is_valid_descriptor_pointer(data, current));
    106106
    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;
    109109
    110110        if (!is_valid_descriptor_pointer(data, next)) {
     
    124124 * @retval -1 Invalid input.
    125125 */
    126 static int get_descriptor_type(usb_dp_parser_data_t *data, uint8_t *start)
     126static int get_descriptor_type(const usb_dp_parser_data_t *data, const uint8_t *start)
    127127{
    128128        if (start == NULL) {
     
    145145 * @return Whether @p child could be child of @p parent.
    146146 */
    147 static bool is_nested_descriptor_type(usb_dp_parser_t *parser,
     147static bool is_nested_descriptor_type(const usb_dp_parser_t *parser,
    148148    int child, int parent)
    149149{
    150         usb_dp_descriptor_nesting_t *nesting = parser->nesting;
     150        const usb_dp_descriptor_nesting_t *nesting = parser->nesting;
    151151        while ((nesting->child > 0) && (nesting->parent > 0)) {
    152152                if ((nesting->child == child) && (nesting->parent == parent)) {
     
    166166 * @return Whether @p child could be child of @p parent.
    167167 */
    168 static bool is_nested_descriptor(usb_dp_parser_t *parser,
    169     usb_dp_parser_data_t *data, uint8_t *child, uint8_t *parent)
     168static 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)
    170170{
    171171        return is_nested_descriptor_type(parser,
     
    183183 * @retval NULL Invalid input.
    184184 */
    185 uint8_t *usb_dp_get_nested_descriptor(usb_dp_parser_t *parser,
    186     usb_dp_parser_data_t *data, uint8_t *parent)
     185const 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)
    187187{
    188188        if (!is_valid_descriptor_pointer(data, parent)) {
     
    190190        }
    191191
    192         uint8_t *next = get_next_descriptor(data, parent);
     192        const uint8_t *next = get_next_descriptor(data, parent);
    193193        if (next == NULL) {
    194194                return NULL;
     
    211211 * @retval NULL Invalid input.
    212212 */
    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);
     213static 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);
    217218        if (child == NULL) {
    218219                return get_next_descriptor(data, parent);
    219220        }
    220         uint8_t *next_child = skip_nested_descriptors(parser, data, child);
     221        const uint8_t *next_child =
     222            skip_nested_descriptors(parser, data, child);
    221223        while (is_nested_descriptor(parser, data, next_child, parent)) {
    222224                next_child = skip_nested_descriptors(parser, data, next_child);
     
    236238 * @retval NULL Invalid input.
    237239 */
    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)
     240const 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)
    240243{
    241244        if (!is_valid_descriptor_pointer(data, parent)
     
    244247        }
    245248
    246         uint8_t *possible_sibling = skip_nested_descriptors(parser, data, sibling);
     249        const uint8_t *possible_sibling =
     250            skip_nested_descriptors(parser, data, sibling);
    247251        if (possible_sibling == NULL) {
    248252                return NULL;
     
    269273 * @param arg Custom (user) argument.
    270274 */
    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)
     275static 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)
    274278{
    275279        if (root == NULL) {
     
    277281        }
    278282        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);
    280284        do {
    281285                usb_dp_browse_simple_internal(parser, data, child, depth + 1,
     
    301305 */
    302306void 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)
    305309{
    306310        if ((descriptors == NULL) || (descriptors_size == 0)
     
    309313        }
    310314
    311         usb_dp_parser_data_t data = {
     315        const usb_dp_parser_data_t data = {
    312316                .data = descriptors,
    313317                .size = descriptors_size,
     
    315319        };
    316320
    317         usb_dp_parser_t parser = {
     321        const usb_dp_parser_t parser = {
    318322                .nesting = descriptor_nesting
    319323        };
  • uspace/lib/usbdev/src/hub.c

    r1ccc32f5 r25696fea  
    3737#include <usb/dev/request.h>
    3838#include <usb/dev/recognise.h>
     39#include <usb/debug.h>
    3940#include <usbhc_iface.h>
    4041#include <errno.h>
     
    5758                assert((conn)); \
    5859                if (!usb_hc_connection_is_opened((conn))) { \
    59                         return ENOENT; \
     60                        usb_log_error("Connection not open.\n"); \
     61                        return ENOTCONN; \
    6062                } \
    6163        } while (false)
     
    9597 */
    9698int usb_hc_register_device(usb_hc_connection_t * connection,
    97     const usb_hc_attached_device_t *attached_device)
     99    const usb_hub_attached_device_t *attached_device)
    98100{
    99101        CHECK_CONNECTION(connection);
     
    105107        int rc = async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    106108            IPC_M_USBHC_BIND_ADDRESS,
    107             attached_device->address, attached_device->handle);
     109            attached_device->address, attached_device->fun->handle);
    108110        async_exchange_end(exch);
    109111       
     
    155157 * The @p enable_port function is expected to enable signaling on given
    156158 * 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).
    161161 *
    162162 * If the @p enable_port fails (i.e. does not return EOK), the device
     
    175175 * @param[in] enable_port Function for enabling signaling through the port the
    176176 *      device is attached to.
    177  * @param[in] port_no Port number (passed through to @p enable_port).
    178177 * @param[in] arg Any data argument to @p enable_port.
    179178 * @param[out] assigned_address USB address of the device.
    180  * @param[out] assigned_handle Devman handle of the new device.
    181179 * @param[in] dev_ops Child device ops.
    182180 * @param[in] new_dev_data Arbitrary pointer to be stored in the child
     
    194192int usb_hc_new_device_wrapper(ddf_dev_t *parent, usb_hc_connection_t *connection,
    195193    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,
    198195    ddf_dev_ops_t *dev_ops, void *new_dev_data, ddf_fun_t **new_fun)
    199196{
     
    224221        usb_address_t dev_addr = usb_hc_request_address(&hc_conn, dev_speed);
    225222        if (dev_addr < 0) {
    226                 usb_hc_connection_close(&hc_conn);
    227                 return EADDRNOTAVAIL;
     223                rc = EADDRNOTAVAIL;
     224                goto close_connection;
    228225        }
    229226
     
    279276         * device address.
    280277         */
    281         rc = enable_port(port_no, arg);
     278        rc = enable_port(arg);
    282279        if (rc != EOK) {
    283280                goto leave_release_default_address;
     
    320317         */
    321318        /* FIXME: create device_register that will get opened ctrl pipe. */
    322         devman_handle_t child_handle;
     319        ddf_fun_t *child_fun;
    323320        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);
    326322        if (rc != EOK) {
    327323                rc = ESTALL;
     
    332328         * And now inform the host controller about the handle.
    333329         */
    334         usb_hc_attached_device_t new_device = {
     330        usb_hub_attached_device_t new_device = {
    335331                .address = dev_addr,
    336                 .handle = child_handle
     332                .fun = child_fun,
    337333        };
    338334        rc = usb_hc_register_device(&hc_conn, &new_device);
     
    341337                goto leave_release_free_address;
    342338        }
    343        
    344         usb_hc_connection_close(&hc_conn);
     339
    345340
    346341        /*
     
    350345                *assigned_address = dev_addr;
    351346        }
    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;
    359353
    360354        /*
     
    368362        usb_hc_unregister_device(&hc_conn, dev_addr);
    369363
    370         usb_hc_connection_close(&hc_conn);
     364close_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");
    371368
    372369        return rc;
  • uspace/lib/usbdev/src/pipes.c

    r1ccc32f5 r25696fea  
    5252 * @return USB address or error code.
    5353 */
    54 static usb_address_t get_my_address(async_sess_t *sess, ddf_dev_t *dev)
     54static usb_address_t get_my_address(async_sess_t *sess, const ddf_dev_t *dev)
    5555{
    5656        async_exch_t *exch = async_exchange_begin(sess);
     
    7878 * @return Interface number (negative code means any).
    7979 */
    80 int usb_device_get_assigned_interface(ddf_dev_t *device)
     80int usb_device_get_assigned_interface(const ddf_dev_t *device)
    8181{
    8282        async_sess_t *parent_sess =
     
    108108 */
    109109int 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)
    111111{
    112112        assert(connection);
  • uspace/lib/usbdev/src/pipesinit.c

    r1ccc32f5 r25696fea  
    6868 * @return Whether the given descriptor is endpoint descriptor.
    6969 */
    70 static inline bool is_endpoint_descriptor(uint8_t *descriptor)
     70static inline bool is_endpoint_descriptor(const uint8_t *descriptor)
    7171{
    7272        return descriptor[1] == USB_DESCTYPE_ENDPOINT;
     
    8080 */
    8181static bool endpoint_fits_description(const usb_endpoint_description_t *wanted,
    82     usb_endpoint_description_t *found)
     82    const usb_endpoint_description_t *found)
    8383{
    8484#define _SAME(fieldname) ((wanted->fieldname) == (found->fieldname))
     
    120120static usb_endpoint_mapping_t *find_endpoint_mapping(
    121121    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    122     usb_endpoint_description_t *found_endpoint,
     122    const usb_endpoint_description_t *found_endpoint,
    123123    int interface_number, int interface_setting)
    124124{
     
    160160    usb_device_connection_t *wire)
    161161{
    162         usb_endpoint_description_t description;
    163162
    164163        /*
     
    167166
    168167        /* 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        };
    183183
    184184        /*
     
    224224static int process_interface(
    225225    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,
    230230            parser_data, interface_descriptor);
    231231
     
    284284int usb_pipe_initialize_from_configuration(
    285285    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,
    287287    usb_device_connection_t *connection)
    288288{
    289289        assert(connection);
    290290
    291         if (configuration_descriptor == NULL) {
     291        if (config_descriptor == NULL) {
    292292                return EBADMEM;
    293293        }
    294         if (configuration_descriptor_size
     294        if (config_descriptor_size
    295295            < sizeof(usb_standard_configuration_descriptor_t)) {
    296296                return ERANGE;
     
    310310         * Prepare the descriptor parser.
    311311         */
    312         usb_dp_parser_t dp_parser = {
     312        const usb_dp_parser_t dp_parser = {
    313313                .nesting = descriptor_nesting
    314314        };
    315         usb_dp_parser_data_t dp_data = {
    316                 .data = configuration_descriptor,
    317                 .size = configuration_descriptor_size,
     315        const usb_dp_parser_data_t dp_data = {
     316                .data = config_descriptor,
     317                .size = config_descriptor_size,
    318318                .arg = connection
    319319        };
     
    322322         * Iterate through all interfaces.
    323323         */
    324         uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,
    325             &dp_data, configuration_descriptor);
     324        const uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,
     325            &dp_data, config_descriptor);
    326326        if (interface == NULL) {
    327327                return ENOENT;
     
    329329        do {
    330330                (void) process_interface(mapping, mapping_count,
    331                     &dp_parser, &dp_data,
    332                     interface);
     331                    &dp_parser, &dp_data, interface);
    333332                interface = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
    334                     configuration_descriptor, interface);
     333                    config_descriptor, interface);
    335334        } while (interface != NULL);
    336335
     
    514513{
    515514        assert(pipe);
     515        assert(pipe->wire);
    516516        assert(hc_connection);
    517517       
  • uspace/lib/usbdev/src/pipesio.c

    r1ccc32f5 r25696fea  
    469469 */
    470470static 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)
    473473{
    474474        /* Ensure serialization over the phone. */
     
    536536 */
    537537int 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)
    540540{
    541541        assert(pipe);
  • uspace/lib/usbdev/src/recognise.c

    r1ccc32f5 r25696fea  
    339339 * @param[in] hc_handle Handle of the host controller.
    340340 * @param[in] parent Parent device.
    341  * @param[out] child_handle Handle of the child device.
    342341 * @param[in] dev_ops Child device ops.
    343342 * @param[in] dev_data Arbitrary pointer to be stored in the child
     
    348347 */
    349348int 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,
    352350    ddf_dev_ops_t *dev_ops, void *dev_data, ddf_fun_t **child_fun)
    353351{
     
    414412        }
    415413
    416         if (child_handle != NULL) {
    417                 *child_handle = child->handle;
    418         }
    419 
    420414        if (child_fun != NULL) {
    421415                *child_fun = child;
  • uspace/lib/usbdev/src/request.c

    r1ccc32f5 r25696fea  
    425425
    426426        /* Everything is okay, copy the descriptor. */
    427         memcpy(descriptor, &descriptor_tmp,
    428             sizeof(descriptor_tmp));
     427        memcpy(descriptor, &descriptor_tmp, sizeof(descriptor_tmp));
    429428
    430429        return EOK;
     
    470469
    471470        /* Everything is okay, copy the descriptor. */
    472         memcpy(descriptor, &descriptor_tmp,
    473             sizeof(descriptor_tmp));
     471        memcpy(descriptor, &descriptor_tmp, sizeof(descriptor_tmp));
    474472
    475473        return EOK;
  • uspace/lib/usbhid/src/hidreport.c

    r1ccc32f5 r25696fea  
    6969         * First nested descriptor of the configuration descriptor.
    7070         */
    71         uint8_t *d =
     71        const uint8_t *d =
    7272            usb_dp_get_nested_descriptor(&parser, &parser_data,
    7373            dev->descriptors.configuration);
     
    9292         * First nested descriptor of the interface descriptor.
    9393         */
    94         uint8_t *iface_desc = d;
     94        const uint8_t *iface_desc = d;
    9595        d = usb_dp_get_nested_descriptor(&parser, &parser_data, iface_desc);
    9696       
Note: See TracChangeset for help on using the changeset viewer.