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


Ignore:
Timestamp:
2011-11-10T11:29:10Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
54464f6a, c2245a3, c6f189f7
Parents:
2e1b9dc (diff), 2d1ba51 (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 USB changes.

Interface changes:

  • GET_ADDRESS has been renamed to GET_MY_ADDRESS and the handle parameter was dropped. Tis call no longer cascades up to the root hub, but it is answered in the first place the information is available (nearest hub)
  • Reintroduced address reservation for USB_DEFAULT_ADDRESS. The interface now enables device drivers to request specific address on initialization and either insists on that address or accept any other if the address is not available. Note that it is not possible to get the default address if the driver does not insist.
  • Any endpoint registered is removed when address is released and a warning is produced if there were any such endpoints.
  • It is no longer necessary or possible to pass device speed information when registering endpoints.

Driver fixes: memory leaks and crashes (not only) in error paths.
Fixes or removes flaky device_remove implementation in device drivers.

File:
1 edited

Legend:

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

    r2e1b9dc r747ef72  
    5757{
    5858        list_foreach(*list, l) {
    59                 usbmid_interface_t *iface
    60                     = list_get_instance(l, usbmid_interface_t, link);
     59                usbmid_interface_t *iface = usbmid_interface_from_link(l);
    6160                if (iface->interface_no == interface_no) {
    6261                        return true;
     
    8281        };
    8382
    84         usb_dp_parser_t parser = {
     83        static const usb_dp_parser_t parser = {
    8584                .nesting = usb_dp_standard_descriptor_nesting
    8685        };
    8786
    8887        const uint8_t *interface_ptr =
    89             usb_dp_get_nested_descriptor(&parser, &data, data.data);
    90         if (interface_ptr == NULL) {
    91                 return;
    92         }
    93 
    94         do {
    95                 if (interface_ptr[1] != USB_DESCTYPE_INTERFACE) {
    96                         goto next_descriptor;
    97                 }
    98 
    99                 usb_standard_interface_descriptor_t *interface
     88            usb_dp_get_nested_descriptor(&parser, &data, config_descriptor);
     89
     90        /* Walk all descriptors nested in the current configuration decriptor;
     91         * i.e. all interface descriptors. */
     92        for (;interface_ptr != NULL;
     93            interface_ptr = usb_dp_get_sibling_descriptor(
     94                &parser, &data, config_descriptor, interface_ptr))
     95        {
     96                /* The second byte is DESCTYPE byte in all desriptors. */
     97                if (interface_ptr[1] != USB_DESCTYPE_INTERFACE)
     98                        continue;
     99
     100                const usb_standard_interface_descriptor_t *interface
    100101                    = (usb_standard_interface_descriptor_t *) interface_ptr;
    101102
    102103                /* Skip alternate interfaces. */
    103                 if (!interface_in_list(list, interface->interface_number)) {
    104                         usbmid_interface_t *iface
    105                             = malloc(sizeof(usbmid_interface_t));
    106                         if (iface == NULL) {
    107                                 break;
    108                         }
    109                         link_initialize(&iface->link);
    110                         iface->fun = NULL;
    111                         iface->interface_no = interface->interface_number;
    112                         iface->interface = interface;
    113 
    114                         list_append(&iface->link, list);
    115                 }
    116 
    117                 /* TODO: add the alternatives and create match ids from them
    118                  * as well.
    119                  */
    120 
    121 next_descriptor:
    122                 interface_ptr = usb_dp_get_sibling_descriptor(&parser, &data,
    123                     data.data, interface_ptr);
    124 
    125         } while (interface_ptr != NULL);
    126 
     104                if (interface_in_list(list, interface->interface_number)) {
     105                        /* TODO: add the alternatives and create match ids
     106                         * for them. */
     107                        continue;
     108                }
     109                usbmid_interface_t *iface = malloc(sizeof(usbmid_interface_t));
     110                if (iface == NULL) {
     111                        //TODO: Do something about that failure.
     112                        break;
     113                }
     114
     115                link_initialize(&iface->link);
     116                iface->fun = NULL;
     117                iface->interface_no = interface->interface_number;
     118                iface->interface = interface;
     119
     120                list_append(&iface->link, list);
     121        }
    127122}
    128123
     
    139134        int rc;
    140135
    141         int dev_class = dev->descriptors.device.device_class;
     136        unsigned dev_class = dev->descriptors.device.device_class;
    142137        if (dev_class != USB_CLASS_USE_INTERFACE) {
    143138                usb_log_warning(
    144                     "Device class: %d (%s), but expected class 0.\n",
    145                     dev_class, usb_str_class(dev_class));
     139                    "Device class: %u (%s), but expected class %u.\n",
     140                    dev_class, usb_str_class(dev_class),
     141                    USB_CLASS_USE_INTERFACE);
    146142                usb_log_error("Not multi interface device, refusing.\n");
    147143                return false;
    148144        }
    149145
    150         /* Short cuts to save on typing ;-). */
     146        /* Shortcuts to save on typing ;-). */
    151147        const void *config_descriptor_raw = dev->descriptors.configuration;
    152148        size_t config_descriptor_size = dev->descriptors.configuration_size;
     
    163159        }
    164160
     161        /* Create driver soft-state. */
    165162        usb_mid_t *usb_mid = usb_device_data_alloc(dev, sizeof(usb_mid_t));
    166163        if (!usb_mid) {
     
    169166        }
    170167
    171         /* Create control function */
     168        /* Create control function. */
    172169        usb_mid->ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl");
    173170        if (usb_mid->ctl_fun == NULL) {
     
    175172                return false;
    176173        }
    177 
    178174        usb_mid->ctl_fun->ops = &mid_device_ops;
    179175
     176        /* Bind control function. */
    180177        rc = ddf_fun_bind(usb_mid->ctl_fun);
    181178        if (rc != EOK) {
     
    192189            &usb_mid->interface_list);
    193190
     191        /* Start child function for every interface. */
    194192        list_foreach(usb_mid->interface_list, link) {
    195                 usbmid_interface_t *iface = list_get_instance(link,
    196                     usbmid_interface_t, link);
     193                usbmid_interface_t *iface = usbmid_interface_from_link(link);
    197194
    198195                usb_log_info("Creating child for interface %d (%s).\n",
    199                     (int) iface->interface_no,
     196                    iface->interface_no,
    200197                    usb_str_class(iface->interface->interface_class));
    201198
Note: See TracChangeset for help on using the changeset viewer.