Changeset c24c157d in mainline


Ignore:
Timestamp:
2011-12-12T11:59:35Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1a38701
Parents:
899f1a9
Message:

libusb, libusbdev: Provide generic usb_get_info_by_handle function.

Add separate wrappers for host controller handle, address and interface number.

Location:
uspace/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/dev.h

    r899f1a9 rc24c157d  
    6666}
    6767
    68 usb_address_t usb_get_address_by_handle(devman_handle_t);
     68int usb_get_info_by_handle(devman_handle_t,
     69    devman_handle_t *, usb_address_t *, int *);
    6970
    70 int usb_get_hc_by_handle(devman_handle_t, devman_handle_t *);
     71static inline int usb_get_hc_by_handle(devman_handle_t dev, devman_handle_t *hc)
     72{
     73        return usb_get_info_by_handle(dev, hc, NULL, NULL);
     74}
     75
     76static inline int usb_get_address_by_handle(
     77    devman_handle_t dev, usb_address_t *address)
     78{
     79        return usb_get_info_by_handle(dev, NULL, address, NULL);
     80}
     81
     82static inline int usb_get_iface_by_handle(devman_handle_t dev, int *iface)
     83{
     84        return usb_get_info_by_handle(dev, NULL, NULL, iface);
     85}
    7186
    7287int usb_resolve_device_handle(const char *, devman_handle_t *, usb_address_t *,
  • uspace/lib/usb/src/dev.c

    r899f1a9 rc24c157d  
    3131#include <usb_iface.h>
    3232
    33 /** Tell USB address assigned to device with given handle.
     33/** Find host controller handle, address and iface number for the device.
    3434 *
    35  * @param dev_handle Devman handle of the USB device in question.
    36  * @return USB address or negative error code.
     35 * @param[in] device_handle Device devman handle.
     36 * @param[out] hc_handle Where to store handle of host controller
     37 *      controlling device with @p device_handle handle.
     38 * @param[out] address Place to store the device's address
     39 * @param[out] iface Place to stoer the assigned USB interface number.
     40 * @return Error code.
    3741 */
    38 usb_address_t usb_get_address_by_handle(devman_handle_t dev_handle)
     42int usb_get_info_by_handle(devman_handle_t device_handle,
     43    devman_handle_t *hc_handle, usb_address_t *address, int *iface)
    3944{
    4045        async_sess_t *parent_sess =
    41             devman_parent_device_connect(EXCHANGE_ATOMIC, dev_handle,
    42             IPC_FLAG_BLOCKING);
     46            devman_parent_device_connect(EXCHANGE_ATOMIC, device_handle,
     47                IPC_FLAG_BLOCKING);
    4348        if (!parent_sess)
    4449                return ENOMEM;
     
    4954                return ENOMEM;
    5055        }
    51         usb_address_t address;
    52         const int ret = usb_get_my_address(exch, &address);
     56
     57        usb_address_t tmp_address;
     58        devman_handle_t tmp_handle;
     59        int tmp_iface;
     60
     61        if (address) {
     62                const int ret = usb_get_my_address(exch, &tmp_address);
     63                if (ret != EOK) {
     64                        async_exchange_end(exch);
     65                        async_hangup(parent_sess);
     66                        return ret;
     67                }
     68        }
     69
     70        if (hc_handle) {
     71                const int ret = usb_get_hc_handle(exch, &tmp_handle);
     72                if (ret != EOK) {
     73                        async_exchange_end(exch);
     74                        async_hangup(parent_sess);
     75                        return ret;
     76                }
     77        }
     78
     79        if (iface) {
     80                const int ret = usb_get_my_interface(exch, &tmp_iface);
     81                switch (ret) {
     82                case ENOTSUP:
     83                        /* Implementing GET_MY_INTERFACE is voluntary. */
     84                        tmp_iface = -1;
     85                case EOK:
     86                        break;
     87                default:
     88                        async_exchange_end(exch);
     89                        async_hangup(parent_sess);
     90                        return ret;
     91                }
     92        }
     93
     94        if (hc_handle)
     95                *hc_handle = tmp_handle;
     96
     97        if (address)
     98                *address = tmp_address;
     99
     100        if (iface)
     101                *iface = tmp_iface;
    53102
    54103        async_exchange_end(exch);
    55104        async_hangup(parent_sess);
    56105
    57         if (ret != EOK)
    58                 return ret;
    59 
    60         return address;
    61 }
    62 /*----------------------------------------------------------------------------*/
    63 /** Find host controller handle for the device.
    64  *
    65  * @param[in] device_handle Device devman handle.
    66  * @param[out] hc_handle Where to store handle of host controller
    67  *      controlling device with @p device_handle handle.
    68  * @return Error code.
    69  */
    70 int usb_get_hc_by_handle(devman_handle_t device_handle,
    71     devman_handle_t *hc_handle)
    72 {
    73         async_sess_t *parent_sess =
    74             devman_parent_device_connect(EXCHANGE_ATOMIC, device_handle,
    75             IPC_FLAG_BLOCKING);
    76         if (!parent_sess)
    77                 return ENOMEM;
    78 
    79         async_exch_t *exch = async_exchange_begin(parent_sess);
    80         if (!exch) {
    81                 async_hangup(parent_sess);
    82                 return ENOMEM;
    83         }
    84         const int ret = usb_get_hc_handle(exch, hc_handle);
    85 
    86         async_exchange_end(exch);
    87         async_hangup(parent_sess);
    88 
    89         return ret;
     106        return EOK;
    90107}
    91108/*----------------------------------------------------------------------------*/
  • uspace/lib/usb/src/resolve.c

    r899f1a9 rc24c157d  
    193193                /* Try to get its address. */
    194194                if (!found_addr) {
    195                         dev_addr = usb_get_address_by_handle(tmp_handle);
    196                         if (dev_addr >= 0) {
     195                        rc = usb_get_address_by_handle(tmp_handle, &dev_addr);
     196                        if (rc == 0) {
    197197                                found_addr = true;
    198198                        }
  • uspace/lib/usbdev/src/devdrv.c

    r899f1a9 rc24c157d  
    484484        usb_dev->pipes = NULL;
    485485
     486        /* Get assigned params */
     487        devman_handle_t hc_handle;
     488        usb_address_t address;
     489
     490        int rc = usb_get_info_by_handle(ddf_dev->handle,
     491            &hc_handle, &address, &usb_dev->interface_no);
     492        if (rc != EOK) {
     493                *errstr_ptr = "device parameters retrieval";
     494                return rc;
     495        }
     496
    486497        /* Initialize hc connection. */
    487         usb_hc_connection_initialize_from_device(&usb_dev->hc_conn, ddf_dev);
    488         const usb_address_t address =
    489             usb_get_address_by_handle(ddf_dev->handle);
     498        usb_hc_connection_initialize(&usb_dev->hc_conn, hc_handle);
    490499
    491500        /* Initialize backing wire and control pipe. */
    492         int rc = usb_device_connection_initialize(
     501        rc = usb_device_connection_initialize(
    493502            &usb_dev->wire, &usb_dev->hc_conn, address);
    494503        if (rc != EOK) {
     
    512521        }
    513522
    514         /* Get our interface. */
    515         usb_dev->interface_no = usb_device_get_assigned_interface(ddf_dev);
    516523        /* Retrieve standard descriptors. */
    517524        rc = usb_device_retrieve_descriptors(
Note: See TracChangeset for help on using the changeset viewer.