Changeset 2757247 in mainline for uspace/lib/usbhost/src/ddf_helpers.c


Ignore:
Timestamp:
2013-08-07T13:55:15Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0918382f
Parents:
e991937
Message:

libusbhost: Keep devices tree in internal representation.

This is necessary for USB 2.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/ddf_helpers.c

    re991937 r2757247  
    7070typedef struct usb_dev {
    7171        link_t link;
     72        list_t devices;
    7273        ddf_fun_t *fun;
    7374        usb_address_t address;
    7475        usb_speed_t speed;
     76        unsigned port;
    7577} usb_dev_t;
     78
     79static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port,
     80    usb_address_t *id);
     81static int hcd_ddf_remove_device(ddf_dev_t *device, usb_dev_t *hub,
     82    usb_address_t id);
     83
     84
     85/* DDF INTERFACE */
    7686
    7787/** Register endpoint interface function.
     
    162172        assert(dev);
    163173        usb_address_t address = 0;
     174        unsigned port = 0; //TODO provide real value here
    164175        usb_log_debug("Device %d reported a new USB device\n", dev->address);
    165         const int ret = hcd_ddf_new_device(ddf_dev, &address);
     176        const int ret = hcd_ddf_new_device(ddf_dev, dev, port, &address);
    166177        if (ret == EOK && handle)
    167178                *handle = address;
     
    176187        assert(ddf_dev);
    177188        assert(dev);
    178         usb_log_debug("Device %d reported removal of device %d\n",
    179             dev->address, (int)handle);
    180         return hcd_ddf_remove_device(ddf_dev, (usb_address_t)handle);
     189        usb_log_debug("Hub `%s' reported removal of device %d\n",
     190            ddf_fun_get_name(fun), (int)handle);
     191        return hcd_ddf_remove_device(ddf_dev, dev, (usb_address_t)handle);
    181192}
    182193
     
    247258}
    248259
    249 /** Root hub USB interface */
     260/** USB device interface */
    250261static usb_iface_t usb_iface = {
    251262        .get_my_device_handle = get_my_device_handle,
     
    264275};
    265276
    266 /** Standard USB RH options (device interface) */
     277/** Standard USB device interface) */
    267278static ddf_dev_ops_t usb_ops = {
    268279        .interfaces[USB_DEV_IFACE] = &usb_iface,
    269280};
     281
     282
     283/* DDF HELPERS */
    270284
    271285#define GET_DEVICE_DESC(size) \
     
    291305};
    292306
    293 int hcd_ddf_add_usb_device(ddf_dev_t *parent,
    294     usb_address_t address, usb_speed_t speed, const char *name,
     307static int hcd_ddf_add_device(ddf_dev_t *parent, usb_dev_t *hub_dev,
     308    unsigned port, usb_address_t address, usb_speed_t speed, const char *name,
    295309    const match_id_list_t *mids)
    296310{
    297311        assert(parent);
    298         hc_dev_t *hc_dev = dev_to_hc_dev(parent);
    299312
    300313        char default_name[10] = { 0 }; /* usbxyz-ss */
     
    317330        info->speed = speed;
    318331        info->fun = fun;
     332        info->port = port;
    319333        link_initialize(&info->link);
     334        list_initialize(&info->devices);
    320335
    321336        ddf_fun_set_ops(fun, &usb_ops);
     
    331346        }
    332347
    333         list_append(&info->link, &hc_dev->devices);
     348        if (hub_dev) {
     349                list_append(&info->link, &hub_dev->devices);
     350        } else {
     351                hc_dev_t *hc_dev = dev_to_hc_dev(parent);
     352                list_append(&info->link, &hc_dev->devices);
     353        }
    334354        return EOK;
    335355}
     
    354374} while (0)
    355375
    356 
    357376/* This is a copy of lib/usbdev/src/recognise.c */
    358377static int create_match_ids(match_id_list_t *l,
     
    385404}
    386405
    387 int hcd_ddf_remove_device(ddf_dev_t *device, usb_address_t id)
     406static int hcd_ddf_remove_device(ddf_dev_t *device, usb_dev_t *hub,
     407    usb_address_t id)
    388408{
    389409        assert(device);
     
    399419        usb_dev_t *victim = NULL;
    400420
    401         list_foreach(hc_dev->devices, it) {
     421        list_foreach(hub->devices, it) {
    402422                victim = list_get_instance(it, usb_dev_t, link);
    403423                if (victim->address == id)
     
    410430                if (ret == EOK) {
    411431                        ddf_fun_destroy(victim->fun);
    412                         hcd_release_address(hcd, id);
     432                        hcd_release_address(hcd, victim->address);
    413433                } else {
    414434                        usb_log_warning("Failed to unbind device %d: %s\n",
     
    420440}
    421441
    422 int hcd_ddf_new_device(ddf_dev_t *device, usb_address_t *id)
     442static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port,
     443    usb_address_t *id)
    423444{
    424445        assert(device);
     
    526547
    527548        /* Register device */
    528         ret = hcd_ddf_add_usb_device(device, address, speed, NULL, &mids);
     549        ret = hcd_ddf_add_device(device, hub, port, address, speed, NULL, &mids);
    529550        clean_match_ids(&mids);
    530551        if (ret != EOK) {
     
    553574
    554575        hcd_reserve_default_address(hcd, speed);
    555         const int ret = hcd_ddf_new_device(device, NULL);
     576        const int ret = hcd_ddf_new_device(device, NULL, 0, NULL);
    556577        hcd_release_default_address(hcd);
    557578        return ret;
Note: See TracChangeset for help on using the changeset viewer.