Changeset 8e4219ab in mainline for uspace/lib/usbdev/src/devdrv.c


Ignore:
Timestamp:
2013-08-02T14:04:51Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6fe7683
Parents:
9d15d1b
Message:

Implement and use usb_get_device_handle.

Enables object instantiation on usb interface functions.
avoids forwarding in usbmid driver.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/src/devdrv.c

    r9d15d1b r8e4219ab  
    7878        void *driver_data;
    7979
     80        /** Connection to device on USB bus */
    8081        usb_dev_session_t *bus_session;
     82        /** devman handle */
     83        devman_handle_t handle;
    8184} usb_device_t;
    8285
     
    331334}
    332335
     336devman_handle_t usb_device_get_devman_handle(usb_device_t *usb_dev)
     337{
     338        assert(usb_dev);
     339        return usb_dev->handle;
     340}
     341
    333342const usb_device_descriptors_t *usb_device_descriptors(usb_device_t *usb_dev)
    334343{
     
    405414static int usb_device_init(usb_device_t *usb_dev, ddf_dev_t *ddf_dev,
    406415    const usb_endpoint_description_t **endpoints, const char **errstr_ptr,
    407     devman_handle_t handle)
     416    devman_handle_t handle, int interface_no)
    408417{
    409418        assert(usb_dev != NULL);
     
    413422
    414423        usb_dev->ddf_dev = ddf_dev;
     424        usb_dev->handle = handle;
     425        usb_dev->interface_no = interface_no;
    415426        usb_dev->driver_data = NULL;
    416427        usb_dev->descriptors.full_config = NULL;
     
    419430        usb_dev->pipes = NULL;
    420431
    421         if (ddf_dev)
    422                 usb_dev->bus_session = usb_dev_connect_to_self(ddf_dev);
    423         else
    424                 usb_dev->bus_session = usb_dev_connect(handle);
     432        usb_dev->bus_session = usb_dev_connect(handle);
    425433
    426434        if (!usb_dev->bus_session) {
     
    433441        usb_address_t address;
    434442
    435         int rc = usb_dev_get_info(usb_dev,
    436             &hc_handle, &address, &usb_dev->interface_no);
     443        int rc = usb_dev_get_info(usb_dev, &hc_handle, &address, NULL);
    437444        if (rc != EOK) {
    438445                usb_dev_disconnect(usb_dev->bus_session);
     
    503510}
    504511
     512static int usb_device_get_info(async_sess_t *sess, devman_handle_t *handle,
     513        int *iface_no)
     514{
     515        assert(handle);
     516        assert(iface_no);
     517        async_exch_t *exch = async_exchange_begin(sess);
     518        if (!exch)
     519                return EPARTY;
     520        int ret = usb_get_device_handle(exch, handle);
     521        if (ret == EOK) {
     522                ret = usb_get_my_interface(exch, iface_no);
     523                if (ret == ENOTSUP) {
     524                        *iface_no = -1;
     525                        ret = EOK;
     526                }
     527        }
     528        async_exchange_end(exch);
     529        return ret;
     530}
     531
    505532int usb_device_create_ddf(ddf_dev_t *ddf_dev,
    506533    const usb_endpoint_description_t **desc, const char **err)
     
    508535        assert(ddf_dev);
    509536        assert(err);
     537
     538        devman_handle_t h = 0;
     539        int iface_no = -1;
     540
     541        async_sess_t *sess = devman_parent_device_connect(EXCHANGE_ATOMIC,
     542            ddf_dev_get_handle(ddf_dev), IPC_FLAG_BLOCKING);
     543        const int ret = usb_device_get_info(sess, &h, &iface_no);
     544        async_hangup(sess);
     545        if (ret != EOK)
     546                return ret;
     547
    510548        usb_device_t *usb_dev =
    511549            ddf_dev_data_alloc(ddf_dev, sizeof(usb_device_t));
     
    514552                return ENOMEM;
    515553        }
    516         return usb_device_init(usb_dev, ddf_dev, desc, err, 0);
     554       
     555        return usb_device_init(usb_dev, ddf_dev, desc, err, h, iface_no);
    517556}
    518557
     
    528567usb_device_t * usb_device_create(devman_handle_t handle)
    529568{
     569        devman_handle_t h = 0;
     570        int iface_no = -1;
     571
     572        async_sess_t *sess = devman_device_connect(
     573            EXCHANGE_ATOMIC, handle, IPC_FLAG_BLOCKING);
     574        int ret = usb_device_get_info(sess, &h, &iface_no);
     575        async_hangup(sess);
     576        if (ret != EOK)
     577                return NULL;
     578
    530579        usb_device_t *usb_dev = malloc(sizeof(usb_device_t));
    531580        if (!usb_dev)
    532581                return NULL;
     582
    533583        const char* dummy = NULL;
    534         const int ret = usb_device_init(usb_dev, NULL, NULL, &dummy, handle);
     584        ret = usb_device_init(usb_dev, NULL, NULL, &dummy, handle, iface_no);
    535585        if (ret != EOK) {
    536586                free(usb_dev);
Note: See TracChangeset for help on using the changeset viewer.