Changeset b995183 in mainline


Ignore:
Timestamp:
2013-01-06T16:19:33Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e938fa6
Parents:
be554d9
Message:

libusbhost: Add support for device removal. Use address as id.

Location:
uspace/lib/usbhost
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/ddf_helpers.h

    rbe554d9 rb995183  
    4646    usb_speed_t max_speed, size_t bw, bw_count_func_t bw_count);
    4747int hcd_ddf_setup_root_hub(ddf_dev_t *dev, usb_speed_t speed);
    48 int hcd_ddf_new_device(ddf_dev_t *device);
     48int hcd_ddf_new_device(ddf_dev_t *device, usb_address_t *address);
     49int hcd_ddf_remove_device(ddf_dev_t *device, usb_address_t address);
    4950
    5051hcd_t *dev_to_hcd(ddf_dev_t *dev);
  • uspace/lib/usbhost/src/ddf_helpers.c

    rbe554d9 rb995183  
    5151        ddf_fun_t *hc_fun;
    5252        list_t devices;
     53        fibril_mutex_t guard;
    5354} hc_dev_t;
    5455
     
    7374        usb_address_t address;
    7475        usb_speed_t speed;
    75         devman_handle_t handle;
     76        devman_handle_t hc_handle;
    7677} usb_dev_t;
    7778
     
    8283 * @return Error code.
    8384 */
    84 static int rh_get_my_address(ddf_fun_t *fun, usb_address_t *address)
     85static int get_my_address(ddf_fun_t *fun, usb_address_t *address)
    8586{
    8687        assert(fun);
     
    9899 * @return Error code.
    99100 */
    100 static int rh_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
     101static int get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
    101102{
    102103        assert(fun);
     
    104105        if (handle != NULL) {
    105106                usb_dev_t *usb_dev = ddf_fun_data_get(fun);
    106                 *handle = usb_dev->handle;
     107                *handle = usb_dev->hc_handle;
    107108        }
    108109        return EOK;
     
    111112/** Root hub USB interface */
    112113static usb_iface_t usb_iface = {
    113         .get_hc_handle = rh_get_hc_handle,
    114         .get_my_address = rh_get_my_address,
     114        .get_hc_handle = get_hc_handle,
     115        .get_my_address = get_my_address,
    115116};
    116117/** Standard USB RH options (RH interface) */
     
    146147};
    147148
    148 static const usb_device_request_setup_packet_t set_address = {
    149         .request_type = SETUP_REQUEST_TYPE_DEVICE_TO_HOST
    150             | (USB_REQUEST_TYPE_STANDARD << 5)
    151             | USB_REQUEST_RECIPIENT_DEVICE,
    152         .request = USB_DEVREQ_GET_DESCRIPTOR,
    153         .value = uint16_host2usb(USB_DESCTYPE_DEVICE << 8),
    154         .index = uint16_host2usb(0),
    155         .length = uint16_host2usb(CTRL_PIPE_MIN_PACKET_SIZE),
    156 };
    157 
    158149int hcd_ddf_add_usb_device(ddf_dev_t *parent,
    159150    usb_address_t address, usb_speed_t speed, const char *name,
     
    182173        info->address = address;
    183174        info->speed = speed;
    184         info->handle = hc_handle;
     175        info->hc_handle = hc_handle;
    185176        info->fun = fun;
    186177        link_initialize(&info->link);
     
    207198        return EOK;
    208199}
    209 
    210200
    211201#define ADD_MATCHID_OR_RETURN(list, sc, str, ...) \
     
    227217        add_match_id(list, mid); \
    228218} while (0)
    229                
     219
    230220
    231221/* This is a copy of lib/usbdev/src/recognise.c */
     
    259249}
    260250
    261 int hcd_ddf_new_device(ddf_dev_t *device)
     251int hcd_ddf_remove_device(ddf_dev_t *device, usb_address_t id)
    262252{
    263253        assert(device);
     
    265255        hcd_t *hcd = dev_to_hcd(device);
    266256        assert(hcd);
    267        
     257
     258        hc_dev_t *hc_dev = dev_to_hc_dev(device);
     259        assert(hc_dev);
     260
     261        fibril_mutex_lock(&hc_dev->guard);
     262
     263        usb_dev_t *victim = NULL;
     264
     265        list_foreach(hc_dev->devices, it) {
     266                victim = list_get_instance(it, usb_dev_t, link);
     267                if (victim->address == id)
     268                        break;
     269        }
     270        if (victim && victim->address == id) {
     271                list_remove(&victim->link);
     272                fibril_mutex_unlock(&hc_dev->guard);
     273                ddf_fun_unbind(victim->fun);
     274                ddf_fun_destroy(victim->fun);
     275                return EOK;
     276        }
     277        return ENOENT;
     278}
     279
     280int hcd_ddf_new_device(ddf_dev_t *device, usb_address_t *id)
     281{
     282        assert(device);
     283
     284        hcd_t *hcd = dev_to_hcd(device);
     285        assert(hcd);
     286
    268287        usb_speed_t speed = USB_SPEED_MAX;
    269288
     
    329348            SET_ADDRESS(target.address);
    330349
    331         // TODO CALLBACKS
    332350        got = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_OUT,
    333351            NULL, 0, *(uint64_t *)&set_address, "set address");
     
    345363            GET_DEVICE_DESC(sizeof(desc));
    346364
    347         // TODO CALLBACKS
    348365        got = hcd_send_batch_sync(hcd, target, USB_DIRECTION_IN,
    349366            &desc, sizeof(desc), *(uint64_t *)&get_device_desc,
     
    354371                return got < 0 ? got : EOVERFLOW;
    355372        }
    356        
     373
    357374        /* Create match ids from the device descriptor */
    358375        match_id_list_t mids;
     
    365382                return ret;
    366383        }
    367        
    368                
    369 
    370         /* Register device */   
     384
     385        /* Register device */
    371386        ret = hcd_ddf_add_usb_device(device, address, speed, NULL, &mids);
    372387        clean_match_ids(&mids);
     
    376391                return ret;
    377392        }
     393        if (ret == EOK && id)
     394                *id = target.address;
    378395
    379396        return ret;
     
    393410
    394411        hcd_reserve_default_address(hcd, speed);
    395         const int ret = hcd_ddf_new_device(device);
     412        const int ret = hcd_ddf_new_device(device, NULL);
    396413        hcd_release_default_address(hcd);
    397414        return ret;
     
    416433        }
    417434        list_initialize(&instance->devices);
     435        fibril_mutex_initialize(&instance->guard);
    418436
    419437#define CHECK_RET_DEST_FREE_RETURN(ret, message...) \
Note: See TracChangeset for help on using the changeset viewer.