Changeset b4b534ac in mainline for uspace/drv/bus/usb/usbmid/explore.c


Ignore:
Timestamp:
2016-07-22T08:24:47Z (9 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f76d2c2
Parents:
5b18137 (diff), 8351f9a4 (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 from lp:~jan.vesely/helenos/usb

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbmid/explore.c

    r5b18137 rb4b534ac  
    3434 * Exploration of available interfaces in the USB device.
    3535 */
    36 #include <ddf/driver.h>
    3736#include <errno.h>
    3837#include <str_error.h>
     
    4140#include <usb/dev/request.h>
    4241#include <usb/dev/dp.h>
    43 #include <usb/ddfiface.h>
    4442#include "usbmid.h"
    45 
    46 /** Operations of the device itself. */
    47 static ddf_dev_ops_t mid_device_ops = {
    48         .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl
    49 };
    5043
    5144/** Tell whether given interface is already in the list.
     
    5750static bool interface_in_list(const list_t *list, int interface_no)
    5851{
    59         list_foreach(*list, link, usbmid_interface_t, iface) {
     52        list_foreach(*list, link, const usbmid_interface_t, iface) {
    6053                if (iface->interface_no == interface_no) {
    6154                        return true;
     
    7164 * @param config_descriptor_size Size of configuration descriptor in bytes.
    7265 * @param list List where to add the interfaces.
    73  * @return EOK on success, ENOMEM if out of memory.
    7466 */
    75 static int create_interfaces(usb_mid_t *mid, const uint8_t *config_descriptor,
    76     size_t config_descriptor_size)
     67static int create_interfaces(const uint8_t *config_descriptor,
     68    size_t config_descriptor_size, list_t *list, usb_device_t *usb_dev)
    7769{
     70        assert(config_descriptor);
     71        assert(usb_dev);
     72
    7873        const usb_dp_parser_data_t data = {
    7974                .data = config_descriptor,
     
    9186        /* Walk all descriptors nested in the current configuration decriptor;
    9287         * i.e. all interface descriptors. */
    93         for (;interface_ptr != NULL;
     88        for (; interface_ptr != NULL;
    9489            interface_ptr = usb_dp_get_sibling_descriptor(
    9590                &parser, &data, config_descriptor, interface_ptr))
     
    10398
    10499                /* Skip alternate interfaces. */
    105                 if (interface_in_list(&mid->interface_list,
    106                     interface->interface_number)) {
     100                if (interface_in_list(list, interface->interface_number)) {
    107101                        /* TODO: add the alternatives and create match ids
    108102                         * for them. */
     
    110104                }
    111105
    112                 /* Create the function */
    113                 ddf_fun_t *fun = ddf_fun_create(mid->dev, fun_inner, NULL);
    114                 if (fun == NULL)
    115                         goto error;
    116106
    117                 usbmid_interface_t *iface = ddf_fun_data_alloc(fun,
    118                     sizeof(usbmid_interface_t));
    119                 if (iface == NULL)
    120                         goto error;
     107                usb_log_info("Creating child for interface %d (%s).\n",
     108                    interface->interface_number,
     109                    usb_str_class(interface->interface_class));
    121110
    122                 link_initialize(&iface->link);
    123                 iface->fun = fun;
    124                 iface->interface_no = interface->interface_number;
    125                 iface->interface = interface;
    126 
    127                 list_append(&iface->link, &mid->interface_list);
     111                usbmid_interface_t *iface = NULL;
     112                const int rc = usbmid_spawn_interface_child(usb_dev, &iface,
     113                        &usb_device_descriptors(usb_dev)->device, interface);
     114                if (rc != EOK) {
     115                        //TODO: Do something about that failure.
     116                        usb_log_error("Failed to create interface child for "
     117                            "%d (%s): %s.\n", interface->interface_number,
     118                            usb_str_class(interface->interface_class),
     119                            str_error(rc));
     120                } else {
     121                        list_append(&iface->link, list);
     122                }
    128123        }
    129 
    130124        return EOK;
    131 error:
    132         while (!list_empty(&mid->interface_list)) {
    133                 link_t *link = list_first(&mid->interface_list);
    134                 usbmid_interface_t *iface = list_get_instance(link,
    135                     usbmid_interface_t, link);
    136 
    137                 ddf_fun_destroy(iface->fun);
    138         }
    139 
    140         return ENOMEM;
    141125}
    142126
     
    149133 * @return Whether to accept this device from devman.
    150134 */
    151 bool usbmid_explore_device(usb_device_t *dev)
     135int usbmid_explore_device(usb_device_t *dev)
    152136{
    153         int rc;
    154 
    155         unsigned dev_class = dev->descriptors.device.device_class;
     137        assert(dev);
     138        const unsigned dev_class =
     139            usb_device_descriptors(dev)->device.device_class;
    156140        if (dev_class != USB_CLASS_USE_INTERFACE) {
    157141                usb_log_warning(
     
    159143                    dev_class, usb_str_class(dev_class),
    160144                    USB_CLASS_USE_INTERFACE);
    161                 usb_log_error("Not multi interface device, refusing.\n");
    162                 return false;
     145                usb_log_error("Not a multi-interface device, refusing.\n");
     146                return ENOTSUP;
    163147        }
    164148
    165         /* Shortcuts to save on typing ;-). */
    166         const void *config_descriptor_raw = dev->descriptors.configuration;
    167         size_t config_descriptor_size = dev->descriptors.configuration_size;
     149        /* Get coonfiguration descriptor. */
     150        const size_t config_descriptor_size =
     151            usb_device_descriptors(dev)->full_config_size;
     152        const void *config_descriptor_raw =
     153            usb_device_descriptors(dev)->full_config;
    168154        const usb_standard_configuration_descriptor_t *config_descriptor =
    169155            config_descriptor_raw;
    170156
    171157        /* Select the first configuration */
    172         rc = usb_request_set_configuration(&dev->ctrl_pipe,
     158        int rc = usb_request_set_configuration(usb_device_get_default_pipe(dev),
    173159            config_descriptor->configuration_number);
    174160        if (rc != EOK) {
    175161                usb_log_error("Failed to set device configuration: %s.\n",
    176162                    str_error(rc));
    177                 return false;
     163                return rc;
    178164        }
    179 
     165       
    180166        /* Create driver soft-state. */
    181167        usb_mid_t *usb_mid = usb_device_data_alloc(dev, sizeof(usb_mid_t));
    182168        if (!usb_mid) {
    183169                usb_log_error("Failed to create USB MID structure.\n");
    184                 return false;
     170                return ENOMEM;
    185171        }
    186172
    187         usb_mid->dev = dev->ddf_dev;
    188 
    189173        /* Create control function. */
    190         usb_mid->ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl");
     174        usb_mid->ctl_fun = usb_device_ddf_fun_create(dev, fun_exposed, "ctl");
    191175        if (usb_mid->ctl_fun == NULL) {
    192176                usb_log_error("Failed to create control function.\n");
    193                 return false;
     177                return ENOMEM;
    194178        }
    195         ddf_fun_set_ops(usb_mid->ctl_fun, &mid_device_ops);
    196179
    197180        /* Bind control function. */
     
    201184                    str_error(rc));
    202185                ddf_fun_destroy(usb_mid->ctl_fun);
    203                 return false;
     186                return rc;
    204187        }
    205188
    206189        /* Create interface children. */
    207190        list_initialize(&usb_mid->interface_list);
    208         create_interfaces(usb_mid, config_descriptor_raw, config_descriptor_size);
     191        create_interfaces(config_descriptor_raw, config_descriptor_size,
     192            &usb_mid->interface_list, dev);
    209193
    210         /* Start child function for every interface. */
    211         list_foreach(usb_mid->interface_list, link, usbmid_interface_t, iface) {
    212                 usb_log_info("Creating child for interface %d (%s).\n",
    213                     iface->interface_no,
    214                     usb_str_class(iface->interface->interface_class));
    215 
    216                 rc = usbmid_spawn_interface_child(dev, iface,
    217                     &dev->descriptors.device, iface->interface);
    218                 if (rc != EOK) {
    219                         usb_log_error("Failed to create interface child: %s.\n",
    220                             str_error(rc));
    221                 }
    222         }
    223 
    224         return true;
     194        return EOK;
    225195}
    226196
Note: See TracChangeset for help on using the changeset viewer.