Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 70a422b in mainline


Ignore:
Timestamp:
2013-01-27T19:12:05Z (9 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
d2cfe72
Parents:
8582076
Message:

libdrv: Add endpoint management to usb iface.

Location:
uspace/lib/drv
Files:
2 edited

Legend:

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

    r8582076 r70a422b  
    7474        IPC_M_USB_DEVICE_ENUMERATE,
    7575        IPC_M_USB_DEVICE_REMOVE,
     76        IPC_M_USB_REGISTER_ENDPOINT,
     77        IPC_M_USB_UNREGISTER_ENDPOINT,
    7678} usb_iface_funcs_t;
    7779
     
    186188}
    187189
     190int usb_register_endpoint(async_exch_t *exch, usb_endpoint_t endpoint,
     191    usb_transfer_type_t type, usb_direction_t direction,
     192    size_t mps, unsigned interval)
     193{
     194        if (!exch)
     195                return EBADMEM;
     196#define _PACK2(high, low) (((high & 0xffff) << 16) | (low & 0xffff))
     197
     198        return async_req_4_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     199            IPC_M_USB_REGISTER_ENDPOINT, endpoint,
     200            _PACK2(type, direction), _PACK2(mps, interval));
     201
     202#undef _PACK2
     203}
     204
     205int usb_unregister_endpoint(async_exch_t *exch, usb_endpoint_t endpoint,
     206    usb_direction_t direction)
     207{
     208        if (!exch)
     209                return EBADMEM;
     210        return async_req_3_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     211            IPC_M_USB_UNREGISTER_ENDPOINT, endpoint, direction);
     212}
     213
    188214static void remote_usb_get_my_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    189215static void remote_usb_get_my_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     
    194220static void remote_usb_device_enumerate(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    195221static void remote_usb_device_remove(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     222static void remote_usb_register_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     223static void remote_usb_unregister_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    196224
    197225/** Remote USB interface operations. */
     
    204232        [IPC_M_USB_DEVICE_ENUMERATE] = remote_usb_device_enumerate,
    205233        [IPC_M_USB_DEVICE_REMOVE] = remote_usb_device_remove,
     234        [IPC_M_USB_REGISTER_ENDPOINT] = remote_usb_register_endpoint,
     235        [IPC_M_USB_UNREGISTER_ENDPOINT] = remote_usb_unregister_endpoint,
    206236};
    207237
     
    333363        async_answer_0(callid, ret);
    334364}
     365
     366static void remote_usb_register_endpoint(ddf_fun_t *fun, void *iface,
     367    ipc_callid_t callid, ipc_call_t *call)
     368{
     369        usb_iface_t *usb_iface = (usb_iface_t *) iface;
     370
     371        if (!usb_iface->register_endpoint) {
     372                async_answer_0(callid, ENOTSUP);
     373                return;
     374        }
     375
     376#define _INIT_FROM_HIGH_DATA2(type, var, arg_no) \
     377        type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) >> 16)
     378#define _INIT_FROM_LOW_DATA2(type, var, arg_no) \
     379        type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) & 0xffff)
     380
     381        const usb_endpoint_t endpoint = DEV_IPC_GET_ARG1(*call);
     382
     383        _INIT_FROM_HIGH_DATA2(usb_transfer_type_t, transfer_type, 2);
     384        _INIT_FROM_LOW_DATA2(usb_direction_t, direction, 2);
     385
     386        _INIT_FROM_HIGH_DATA2(size_t, max_packet_size, 3);
     387        _INIT_FROM_LOW_DATA2(unsigned int, interval, 3);
     388
     389#undef _INIT_FROM_HIGH_DATA2
     390#undef _INIT_FROM_LOW_DATA2
     391
     392        const int ret = usb_iface->register_endpoint(fun, endpoint,
     393            transfer_type, direction, max_packet_size, interval);
     394
     395        async_answer_0(callid, ret);
     396}
     397
     398static void remote_usb_unregister_endpoint(ddf_fun_t *fun, void *iface,
     399    ipc_callid_t callid, ipc_call_t *call)
     400{
     401        usb_iface_t *usb_iface = (usb_iface_t *) iface;
     402
     403        if (!usb_iface->unregister_endpoint) {
     404                async_answer_0(callid, ENOTSUP);
     405                return;
     406        }
     407
     408        usb_endpoint_t endpoint = (usb_endpoint_t) DEV_IPC_GET_ARG1(*call);
     409        usb_direction_t direction = (usb_direction_t) DEV_IPC_GET_ARG2(*call);
     410
     411        int rc = usb_iface->unregister_endpoint(fun, endpoint, direction);
     412
     413        async_answer_0(callid, rc);
     414}
    335415/**
    336416 * @}
  • uspace/lib/drv/include/usb_iface.h

    r8582076 r70a422b  
    6262int usb_device_remove(async_exch_t *, usb_device_handle_t);
    6363
     64int usb_register_endpoint(async_exch_t *, usb_endpoint_t, usb_transfer_type_t,
     65    usb_direction_t, size_t, unsigned);
     66int usb_unregister_endpoint(async_exch_t *, usb_endpoint_t, usb_direction_t);
     67
    6468/** USB device communication interface. */
    6569typedef struct {
     
    7276        int (*device_enumerate)(ddf_fun_t *, usb_device_handle_t *);
    7377        int (*device_remove)(ddf_fun_t *, usb_device_handle_t);
     78        int (*register_endpoint)(ddf_fun_t *, usb_endpoint_t,
     79            usb_transfer_type_t, usb_direction_t, size_t, unsigned);
     80        int (*unregister_endpoint)(ddf_fun_t *, usb_endpoint_t,
     81            usb_direction_t);
    7482} usb_iface_t;
    7583
Note: See TracChangeset for help on using the changeset viewer.