Changeset c280d7e in mainline for uspace/lib/drv/generic/remote_usb.c


Ignore:
Timestamp:
2018-01-20T03:02:36Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
60d3f35
Parents:
3cdaa7f
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-20 03:02:32)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-20 03:02:36)
Message:

libdrv: usb iface callbacks joined

In addition to handle and current interface, it is good for the device
to know its address and speed. Also, it is expected to add some other
fields (stats, info tied to devices of specific speed and so on) in the
future. Instead of adding yet another call, join those two and let HC
fill a description structure.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/remote_usb.c

    r3cdaa7f rc280d7e  
    6161
    6262typedef enum {
    63         IPC_M_USB_GET_MY_INTERFACE,
    64         IPC_M_USB_GET_MY_DEVICE_HANDLE,
     63        IPC_M_USB_GET_MY_DESCRIPTION,
    6564} usb_iface_funcs_t;
    6665
     
    7170 * @return Error code.
    7271 */
    73 int usb_get_my_interface(async_exch_t *exch, int *usb_iface)
     72int usb_get_my_description(async_exch_t *exch, usb_device_desc_t *desc)
    7473{
    7574        if (!exch)
    7675                return EBADMEM;
    77         sysarg_t iface_no;
    78         const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
    79             IPC_M_USB_GET_MY_INTERFACE, &iface_no);
    80         if (ret == EOK && usb_iface)
    81                 *usb_iface = (int)iface_no;
     76
     77        usb_device_desc_t tmp_desc;
     78
     79        const int ret = async_req_1_4(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     80            IPC_M_USB_GET_MY_DESCRIPTION,
     81            (sysarg_t *) &tmp_desc.address,
     82            (sysarg_t *) &tmp_desc.speed,
     83            &tmp_desc.handle,
     84            (sysarg_t *) &tmp_desc.iface);
     85        if (ret == EOK && desc)
     86                *desc = tmp_desc;
    8287        return ret;
    8388}
    8489
    85 /** Tell devman handle of the usb device function.
    86  *
    87  * @param[in]  exch   IPC communication exchange
    88  * @param[out] handle devman handle of the HC used by the target device.
    89  *
    90  * @return Error code.
    91  *
    92  */
    93 int usb_get_my_device_handle(async_exch_t *exch, devman_handle_t *handle)
    94 {
    95         devman_handle_t h = 0;
    96         const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
    97             IPC_M_USB_GET_MY_DEVICE_HANDLE, &h);
    98         if (ret == EOK && handle)
    99                 *handle = (devman_handle_t)h;
    100         return ret;
    101 }
    102 
    103 static void remote_usb_get_my_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    104 static void remote_usb_get_my_device_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     90static void remote_usb_get_my_description(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    10591
    10692/** Remote USB interface operations. */
    10793static const remote_iface_func_ptr_t remote_usb_iface_ops [] = {
    108         [IPC_M_USB_GET_MY_INTERFACE] = remote_usb_get_my_interface,
    109         [IPC_M_USB_GET_MY_DEVICE_HANDLE] = remote_usb_get_my_device_handle,
     94        [IPC_M_USB_GET_MY_DESCRIPTION] = remote_usb_get_my_description,
    11095};
    11196
     
    117102};
    118103
    119 void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface,
     104void remote_usb_get_my_description(ddf_fun_t *fun, void *iface,
    120105    ipc_callid_t callid, ipc_call_t *call)
    121106{
    122107        const usb_iface_t *usb_iface = (usb_iface_t *) iface;
    123108
    124         if (usb_iface->get_my_interface == NULL) {
     109        if (usb_iface->get_my_description == NULL) {
    125110                async_answer_0(callid, ENOTSUP);
    126111                return;
    127112        }
    128113
    129         int iface_no;
    130         const int ret = usb_iface->get_my_interface(fun, &iface_no);
     114        usb_device_desc_t desc;
     115        const int ret = usb_iface->get_my_description(fun, &desc);
    131116        if (ret != EOK) {
    132117                async_answer_0(callid, ret);
    133118        } else {
    134                 async_answer_1(callid, EOK, iface_no);
     119                async_answer_4(callid, EOK,
     120                    (sysarg_t) desc.address,
     121                    (sysarg_t) desc.speed,
     122                    desc.handle,
     123                    desc.iface);
    135124        }
    136 }
    137 
    138 void remote_usb_get_my_device_handle(ddf_fun_t *fun, void *iface,
    139     ipc_callid_t callid, ipc_call_t *call)
    140 {
    141         const usb_iface_t *usb_iface = (usb_iface_t *) iface;
    142 
    143         if (usb_iface->get_my_device_handle == NULL) {
    144                 async_answer_0(callid, ENOTSUP);
    145                 return;
    146         }
    147 
    148         devman_handle_t handle;
    149         const int ret = usb_iface->get_my_device_handle(fun, &handle);
    150         if (ret != EOK) {
    151                 async_answer_0(callid, ret);
    152         }
    153 
    154         async_answer_1(callid, EOK, (sysarg_t) handle);
    155125}
    156126
Note: See TracChangeset for help on using the changeset viewer.