Changeset 14dd4c9 in mainline


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

libusbhost: consolidate device lists and locking.

Root hub is added only once, there's no need for lock or list. Make the list
guard per device. Protect list append as well as removal.

File:
1 edited

Legend:

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

    r0918382f r14dd4c9  
    4646#define CTRL_PIPE_MIN_PACKET_SIZE 8
    4747
    48 typedef struct hc_dev {
    49         ddf_fun_t *ctl_fun;
    50         list_t devices;
    51         fibril_mutex_t guard;
    52         hcd_t hcd;
    53 } hc_dev_t;
    54 
    55 static hc_dev_t *dev_to_hc_dev(ddf_dev_t *dev)
    56 {
    57         return ddf_dev_data_get(dev);
    58 }
    59 
    60 hcd_t *dev_to_hcd(ddf_dev_t *dev)
    61 {
    62         hc_dev_t *hc_dev = dev_to_hc_dev(dev);
    63         if (!hc_dev) {
    64                 usb_log_error("Invalid HCD device.\n");
    65                 return NULL;
    66         }
    67         return &hc_dev->hcd;
    68 }
    69 
    7048typedef struct usb_dev {
    7149        link_t link;
    7250        list_t devices;
     51        fibril_mutex_t guard;
    7352        ddf_fun_t *fun;
    7453        usb_address_t address;
     
    7655        unsigned port;
    7756} usb_dev_t;
     57
     58typedef struct hc_dev {
     59        ddf_fun_t *ctl_fun;
     60        hcd_t hcd;
     61        usb_dev_t *root_hub;
     62} hc_dev_t;
     63
     64static hc_dev_t *dev_to_hc_dev(ddf_dev_t *dev)
     65{
     66        return ddf_dev_data_get(dev);
     67}
     68
     69hcd_t *dev_to_hcd(ddf_dev_t *dev)
     70{
     71        hc_dev_t *hc_dev = dev_to_hc_dev(dev);
     72        if (!hc_dev) {
     73                usb_log_error("Invalid HCD device.\n");
     74                return NULL;
     75        }
     76        return &hc_dev->hcd;
     77}
     78
    7879
    7980static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port);
     
    312313        }
    313314
    314         //TODO more checks
    315315        ddf_fun_t *fun = ddf_fun_create(parent, fun_inner, name);
    316316        if (!fun)
     
    327327        link_initialize(&info->link);
    328328        list_initialize(&info->devices);
     329        fibril_mutex_initialize(&info->guard);
    329330
    330331        ddf_fun_set_ops(fun, &usb_ops);
     
    341342
    342343        if (hub_dev) {
     344                fibril_mutex_lock(&hub_dev->guard);
    343345                list_append(&info->link, &hub_dev->devices);
     346                fibril_mutex_unlock(&hub_dev->guard);
    344347        } else {
    345348                hc_dev_t *hc_dev = dev_to_hc_dev(parent);
    346                 list_append(&info->link, &hc_dev->devices);
     349                assert(hc_dev->root_hub == NULL);
     350                hc_dev->root_hub = info;
    347351        }
    348352        return EOK;
     
    409413        assert(hc_dev);
    410414
    411         fibril_mutex_lock(&hc_dev->guard);
     415        fibril_mutex_lock(&hub->guard);
    412416
    413417        usb_dev_t *victim = NULL;
     
    420424        if (victim && victim->port == port) {
    421425                list_remove(&victim->link);
    422                 fibril_mutex_unlock(&hc_dev->guard);
     426                fibril_mutex_unlock(&hub->guard);
    423427                const int ret = ddf_fun_unbind(victim->fun);
    424428                if (ret == EOK) {
     
    585589                return ENOMEM;
    586590        }
    587         list_initialize(&instance->devices);
    588         fibril_mutex_initialize(&instance->guard);
     591        instance->root_hub = NULL;
    589592        hcd_init(&instance->hcd, max_speed, bw, bw_count);
    590593
Note: See TracChangeset for help on using the changeset viewer.