Changeset 96e01fbc in mainline for uspace/lib/usbdev


Ignore:
Timestamp:
2012-08-31T17:30:29Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2be2506a
Parents:
e0d5bc5 (diff), 0d57c3e (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 mainline changes.

Location:
uspace/lib/usbdev
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/include/usb/dev/usb_device_connection.h

    re0d5bc5 r96e01fbc  
    7272        return EOK;
    7373}
    74 /*----------------------------------------------------------------------------*/
     74
    7575/** Register endpoint on the device.
    7676 * @param instance device connection structure to use.
     
    9191            instance->address, ep, type, direction, packet_size, interval);
    9292}
    93 /*----------------------------------------------------------------------------*/
     93
    9494/** Unregister endpoint on the device.
    9595 * @param instance device connection structure
     
    105105            instance->address, ep, dir);
    106106}
    107 /*----------------------------------------------------------------------------*/
     107
    108108/** Get data from the device.
    109109 * @param[in] instance device connection structure to use.
     
    122122            instance->address, ep, setup, data, size, rsize);
    123123}
    124 /*----------------------------------------------------------------------------*/
     124
    125125/** Send data to the device.
    126126 * @param instance device connection structure to use.
     
    138138            instance->address, ep, setup, data, size);
    139139}
    140 /*----------------------------------------------------------------------------*/
     140
    141141/** Wrapper for read calls with no setup stage.
    142142 * @param[in] instance device connection structure.
     
    153153        return usb_device_control_read(instance, ep, 0, data, size, real_size);
    154154}
    155 /*----------------------------------------------------------------------------*/
     155
    156156/** Wrapper for write calls with no setup stage.
    157157 * @param instance device connection structure.
  • uspace/lib/usbdev/src/devdrv.c

    re0d5bc5 r96e01fbc  
    7474        return ddf_driver_main(&generic_driver);
    7575}
    76 /*----------------------------------------------------------------------------*/
     76
    7777/** Count number of pipes the driver expects.
    7878 *
     
    8787        return count;
    8888}
    89 /*----------------------------------------------------------------------------*/
     89
    9090/** Callback when a new device is supposed to be controlled by this driver.
    9191 *
     
    105105        if (dev == NULL) {
    106106                usb_log_error("USB device `%s' structure allocation failed.\n",
    107                     gen_dev->name);
     107                    ddf_dev_get_name(gen_dev));
    108108                return ENOMEM;
    109109        }
     
    114114        if (rc != EOK) {
    115115                usb_log_error("USB device `%s' init failed (%s): %s.\n",
    116                     gen_dev->name, err_msg, str_error(rc));
     116                    ddf_dev_get_name(gen_dev), err_msg, str_error(rc));
    117117                return rc;
    118118        }
     
    124124        return rc;
    125125}
    126 /*----------------------------------------------------------------------------*/
     126
    127127/** Callback when a device is supposed to be removed from the system.
    128128 *
     
    139139                return ENOTSUP;
    140140        /* Just tell the driver to stop whatever it is doing */
    141         usb_device_t *usb_dev = gen_dev->driver_data;
     141        usb_device_t *usb_dev = ddf_dev_data_get(gen_dev);
    142142        const int ret = driver->ops->device_rem(usb_dev);
    143143        if (ret != EOK)
     
    146146        return EOK;
    147147}
    148 /*----------------------------------------------------------------------------*/
     148
    149149/** Callback when a device was removed from the system.
    150150 *
     
    160160        if (driver->ops->device_gone == NULL)
    161161                return ENOTSUP;
    162         usb_device_t *usb_dev = gen_dev->driver_data;
     162        usb_device_t *usb_dev = ddf_dev_data_get(gen_dev);
    163163        const int ret = driver->ops->device_gone(usb_dev);
    164164        if (ret == EOK)
     
    167167        return ret;
    168168}
    169 /*----------------------------------------------------------------------------*/
     169
    170170/** Destroy existing pipes of a USB device.
    171171 *
     
    178178        dev->pipes_count = 0;
    179179}
    180 /*----------------------------------------------------------------------------*/
     180
    181181/** Change interface setting of a device.
    182182 * This function selects new alternate setting of an interface by issuing
     
    415415        usb_address_t address;
    416416
    417         int rc = usb_get_info_by_handle(ddf_dev->handle,
     417        int rc = usb_get_info_by_handle(ddf_dev_get_handle(ddf_dev),
    418418            &hc_handle, &address, &usb_dev->interface_no);
    419419        if (rc != EOK) {
  • uspace/lib/usbdev/src/devpoll.c

    re0d5bc5 r96e01fbc  
    8080                usb_log_debug("Poll%p: started polling of `%s' - " \
    8181                    "interface %d (%s,%d,%d), %zuB/%zu.\n",
    82                     data, data->dev->ddf_dev->name,
     82                    data, ddf_dev_get_name(data->dev->ddf_dev),
    8383                    (int) mapping->interface->interface_number,
    8484                    usb_str_class(mapping->interface->interface_class),
     
    159159                if (failed) {
    160160                        usb_log_error("Polling of device `%s' terminated: "
    161                             "recurring failures.\n", data->dev->ddf_dev->name);
     161                            "recurring failures.\n", ddf_dev_get_name(
     162                            data->dev->ddf_dev));
    162163                } else {
    163164                        usb_log_debug("Polling of device `%s' terminated: "
    164                             "driver request.\n", data->dev->ddf_dev->name);
     165                            "driver request.\n", ddf_dev_get_name(
     166                            data->dev->ddf_dev));
    165167                }
    166168        }
  • uspace/lib/usbdev/src/hub.c

    re0d5bc5 r96e01fbc  
    6363                return EBADMEM;
    6464        return usb_hc_bind_address(connection,
    65             attached_device->address, attached_device->fun->handle);
     65            attached_device->address, ddf_fun_get_handle(attached_device->fun));
    6666}
    6767
     
    287287        rc = usb_hub_register_device(hc_conn, &new_device);
    288288        if (rc != EOK) {
    289                 /* We know nothing about that data. */
    290                 if (new_dev_data)
    291                         child_fun->driver_data = NULL;
    292289                /* The child function is already created. */
    293290                ddf_fun_destroy(child_fun);
  • uspace/lib/usbdev/src/pipes.c

    re0d5bc5 r96e01fbc  
    5454        return usb_hc_connection_open(pipe->wire->hc_connection);
    5555}
    56 /*----------------------------------------------------------------------------*/
     56
    5757/** Terminate a long transfer on a pipe.
    5858 * @param pipe Pipe where to end the long transfer.
     
    6767        return usb_hc_connection_close(pipe->wire->hc_connection);
    6868}
    69 /*----------------------------------------------------------------------------*/
     69
    7070/** Try to clear endpoint halt of default control pipe.
    7171 *
     
    8585        pipe->auto_reset_halt = true;
    8686}
    87 /*----------------------------------------------------------------------------*/
     87
    8888/** Request a control read transfer on an endpoint pipe.
    8989 *
     
    135135        return rc;
    136136}
    137 /*----------------------------------------------------------------------------*/
     137
    138138/** Request a control write transfer on an endpoint pipe.
    139139 *
     
    182182        return rc;
    183183}
    184 /*----------------------------------------------------------------------------*/
     184
    185185/** Request a read (in) transfer on an endpoint pipe.
    186186 *
     
    227227        return rc;
    228228}
    229 /*----------------------------------------------------------------------------*/
     229
    230230/** Request a write (out) transfer on an endpoint pipe.
    231231 *
     
    259259            pipe->endpoint_no, buffer, size);
    260260}
    261 /*----------------------------------------------------------------------------*/
     261
    262262/** Initialize USB endpoint pipe.
    263263 *
     
    287287        return EOK;
    288288}
    289 /*----------------------------------------------------------------------------*/
     289
    290290/** Initialize USB endpoint pipe as the default zero control pipe.
    291291 *
     
    307307        return rc;
    308308}
    309 /*----------------------------------------------------------------------------*/
     309
    310310/** Register endpoint with the host controller.
    311311 *
     
    323323           pipe->direction, pipe->max_packet_size, interval);
    324324}
    325 /*----------------------------------------------------------------------------*/
     325
    326326/** Revert endpoint registration with the host controller.
    327327 *
  • uspace/lib/usbdev/src/pipesinit.c

    re0d5bc5 r96e01fbc  
    154154    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    155155    usb_standard_interface_descriptor_t *interface,
    156     usb_standard_endpoint_descriptor_t *endpoint,
     156    usb_standard_endpoint_descriptor_t *endpoint_desc,
    157157    usb_device_connection_t *wire)
    158158{
     
    163163
    164164        /* Actual endpoint number is in bits 0..3 */
    165         const usb_endpoint_t ep_no = endpoint->endpoint_address & 0x0F;
     165        const usb_endpoint_t ep_no = endpoint_desc->endpoint_address & 0x0F;
    166166
    167167        const usb_endpoint_description_t description = {
    168168                /* Endpoint direction is set by bit 7 */
    169                 .direction = (endpoint->endpoint_address & 128)
     169                .direction = (endpoint_desc->endpoint_address & 128)
    170170                    ? USB_DIRECTION_IN : USB_DIRECTION_OUT,
    171171                /* Transfer type is in bits 0..2 and
    172172                 * the enum values corresponds 1:1 */
    173                 .transfer_type = endpoint->attributes & 3,
     173                .transfer_type = endpoint_desc->attributes & 3,
    174174
    175175                /* Get interface characteristics. */
     
    194194
    195195        int rc = usb_pipe_initialize(&ep_mapping->pipe, wire,
    196             ep_no, description.transfer_type, endpoint->max_packet_size,
     196            ep_no, description.transfer_type,
     197            uint16_usb2host(endpoint_desc->max_packet_size),
    197198            description.direction);
    198199        if (rc != EOK) {
     
    201202
    202203        ep_mapping->present = true;
    203         ep_mapping->descriptor = endpoint;
     204        ep_mapping->descriptor = endpoint_desc;
    204205        ep_mapping->interface = interface;
    205206
  • uspace/lib/usbdev/src/recognise.c

    re0d5bc5 r96e01fbc  
    3333 * Functions for recognition of attached devices.
    3434 */
     35
     36/** XXX Fix this */
     37#define _DDF_DATA_IMPLANT
    3538
    3639#include <sys/types.h>
     
    352355       
    353356        if (dev_ops != NULL)
    354                 child->ops = dev_ops;
     357                ddf_fun_set_ops(child, dev_ops);
    355358        else
    356                 child->ops = &child_ops;
    357        
    358         child->driver_data = dev_data;
     359                ddf_fun_set_ops(child, &child_ops);
     360       
     361        ddf_fun_data_implant(child, dev_data);
     362       
    359363        /*
    360364         * Store the attached device in fun
     
    373377        }
    374378       
    375         rc = usb_device_create_match_ids(ctrl_pipe, &child->match_ids);
     379        match_id_list_t match_ids;
     380        init_match_ids(&match_ids);
     381        rc = usb_device_create_match_ids(ctrl_pipe, &match_ids);
    376382        if (rc != EOK)
    377383                goto failure;
     384       
     385        list_foreach(match_ids.ids, id_link) {
     386                match_id_t *match_id = list_get_instance(id_link, match_id_t, link);
     387                rc = ddf_fun_add_match_id(child, match_id->id, match_id->score);
     388                if (rc != EOK) {
     389                        clean_match_ids(&match_ids);
     390                        goto failure;
     391                }
     392        }
     393       
     394        clean_match_ids(&match_ids);
    378395       
    379396        rc = ddf_fun_bind(child);
     
    386403failure:
    387404        if (child != NULL) {
    388                 /* We know nothing about the data if it came from outside. */
    389                 if (dev_data)
    390                         child->driver_data = NULL;
    391                
    392405                /* This takes care of match_id deallocation as well. */
    393406                ddf_fun_destroy(child);
  • uspace/lib/usbdev/src/request.c

    re0d5bc5 r96e01fbc  
    114114  *     (in native endianness).
    115115  * @param actual_data_size Actual size of transfered data
    116   *     (in native endianness).
     116  *        (in native endianness).
    117117  * @return Error code.
    118118  * @retval EBADMEM @p pipe is NULL.
     
    147147                    | (request_type << 5) | recipient,
    148148                .request = request,
    149                 .value = value,
    150                 .index = index,
    151                 .length = (uint16_t) data_size,
     149                .value = uint16_host2usb(value),
     150                .index = uint16_host2usb(index),
     151                .length = uint16_host2usb(data_size),
    152152        };
    153153
     
    375375        usb_standard_device_descriptor_t descriptor_tmp;
    376376        int rc = usb_request_get_descriptor(pipe,
    377             USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE, 
     377            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
    378378            USB_DESCTYPE_DEVICE, 0, 0,
    379379            &descriptor_tmp, sizeof(descriptor_tmp),
     
    435435        /* Everything is okay, copy the descriptor. */
    436436        memcpy(descriptor, &descriptor_tmp, sizeof(descriptor_tmp));
    437 
    438437        return EOK;
    439438}
     
    495494                return ENOENT;
    496495        }
    497         if (bare_config.total_length < sizeof(bare_config)) {
     496
     497        const size_t total_length = uint16_usb2host(bare_config.total_length);
     498        if (total_length < sizeof(bare_config)) {
    498499                return ELIMIT;
    499500        }
    500501
    501         void *buffer = malloc(bare_config.total_length);
     502        void *buffer = malloc(total_length);
    502503        if (buffer == NULL) {
    503504                return ENOMEM;
     
    506507        size_t transferred = 0;
    507508        rc = usb_request_get_full_configuration_descriptor(pipe, index,
    508             buffer, bare_config.total_length, &transferred);
     509            buffer, total_length, &transferred);
    509510        if (rc != EOK) {
    510511                free(buffer);
     
    512513        }
    513514
    514         if (transferred != bare_config.total_length) {
     515        if (transferred != total_length) {
    515516                free(buffer);
    516517                return ELIMIT;
     
    522523
    523524        if (descriptor_size != NULL) {
    524                 *descriptor_size = bare_config.total_length;
     525                *descriptor_size = total_length;
    525526        }
    526527
Note: See TracChangeset for help on using the changeset viewer.