Ignore:
File:
1 edited

Legend:

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

    r50b581d ref40434  
    8484 */
    8585typedef enum {
    86         /** Asks for address assignment by host controller.
    87          * Answer:
    88          * - ELIMIT - host controller run out of address
    89          * - EOK - address assigned
    90          * Answer arguments:
    91          * - assigned address
    92          *
    93          * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS.
    94          */
    95         IPC_M_USBHC_REQUEST_ADDRESS,
    96 
    97         /** Bind USB address with devman handle.
    98          * Parameters:
    99          * - USB address
    100          * - devman handle
    101          * Answer:
    102          * - EOK - address binded
    103          * - ENOENT - address is not in use
    104          */
    105         IPC_M_USBHC_BIND_ADDRESS,
    106 
    10786        /** Get handle binded with given USB address.
    10887         * Parameters
     
    11392         */
    11493        IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,
    115 
    116         /** Release address in use.
    117          * Arguments:
    118          * - address to be released
    119          * Answer:
    120          * - ENOENT - address not in use
    121          * - EPERM - trying to release default USB address
    122          */
    123         IPC_M_USBHC_RELEASE_ADDRESS,
    12494
    12595        /** Register endpoint attributes at host controller.
     
    161131} usbhc_iface_funcs_t;
    162132
    163 int usbhc_request_address(async_exch_t *exch, usb_address_t *address,
    164     bool strict, usb_speed_t speed)
    165 {
    166         if (!exch || !address)
    167                 return EINVAL;
    168         sysarg_t new_address;
    169         const int ret = async_req_4_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    170             IPC_M_USBHC_REQUEST_ADDRESS, *address, strict, speed, &new_address);
    171         if (ret == EOK)
    172                 *address = (usb_address_t)new_address;
    173         return ret;
    174 }
    175 /*----------------------------------------------------------------------------*/
    176 int usbhc_bind_address(async_exch_t *exch, usb_address_t address,
    177     devman_handle_t handle)
    178 {
    179         if (!exch)
    180                 return EINVAL;
    181         return async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    182             IPC_M_USBHC_BIND_ADDRESS, address, handle);
    183 }
    184 /*----------------------------------------------------------------------------*/
     133
     134
    185135int usbhc_get_handle(async_exch_t *exch, usb_address_t address,
    186136    devman_handle_t *handle)
    187137{
    188138        if (!exch)
    189                 return EINVAL;
     139                return EBADMEM;
    190140        sysarg_t h;
    191141        const int ret = async_req_2_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     
    195145        return ret;
    196146}
    197 /*----------------------------------------------------------------------------*/
    198 int usbhc_release_address(async_exch_t *exch, usb_address_t address)
    199 {
    200         if (!exch)
    201                 return EINVAL;
    202         return async_req_2_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    203             IPC_M_USBHC_RELEASE_ADDRESS, address);
    204 }
    205 /*----------------------------------------------------------------------------*/
     147
    206148int usbhc_register_endpoint(async_exch_t *exch, usb_address_t address,
    207149    usb_endpoint_t endpoint, usb_transfer_type_t type,
     
    209151{
    210152        if (!exch)
    211                 return EINVAL;
     153                return EBADMEM;
    212154        const usb_target_t target =
    213155            {{ .address = address, .endpoint = endpoint }};
     
    220162#undef _PACK2
    221163}
    222 /*----------------------------------------------------------------------------*/
     164
    223165int usbhc_unregister_endpoint(async_exch_t *exch, usb_address_t address,
    224166    usb_endpoint_t endpoint, usb_direction_t direction)
    225167{
    226168        if (!exch)
    227                 return EINVAL;
     169                return EBADMEM;
    228170        return async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    229171            IPC_M_USBHC_UNREGISTER_ENDPOINT, address, endpoint, direction);
    230172}
    231 /*----------------------------------------------------------------------------*/
     173
    232174int usbhc_read(async_exch_t *exch, usb_address_t address,
    233175    usb_endpoint_t endpoint, uint64_t setup, void *data, size_t size,
    234176    size_t *rec_size)
    235177{
     178        if (!exch)
     179                return EBADMEM;
     180
    236181        if (size == 0 && setup == 0)
    237182                return EOK;
    238183
    239         if (!exch)
    240                 return EINVAL;
    241184        const usb_target_t target =
    242185            {{ .address = address, .endpoint = endpoint }};
     
    284227        return EOK;
    285228}
    286 /*----------------------------------------------------------------------------*/
     229
    287230int usbhc_write(async_exch_t *exch, usb_address_t address,
    288231    usb_endpoint_t endpoint, uint64_t setup, const void *data, size_t size)
    289232{
     233        if (!exch)
     234                return EBADMEM;
     235
    290236        if (size == 0 && setup == 0)
    291237                return EOK;
    292238
    293         if (!exch)
    294                 return EINVAL;
    295239        const usb_target_t target =
    296240            {{ .address = address, .endpoint = endpoint }};
     
    319263        return (int) opening_request_rc;
    320264}
    321 /*----------------------------------------------------------------------------*/
    322 
    323 static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    324 static void remote_usbhc_bind_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     265
     266
    325267static void remote_usbhc_get_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    326 static void remote_usbhc_release_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    327268static void remote_usbhc_register_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    328269static void remote_usbhc_unregister_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     
    333274/** Remote USB host controller interface operations. */
    334275static remote_iface_func_ptr_t remote_usbhc_iface_ops[] = {
    335         [IPC_M_USBHC_REQUEST_ADDRESS] = remote_usbhc_request_address,
    336         [IPC_M_USBHC_RELEASE_ADDRESS] = remote_usbhc_release_address,
    337         [IPC_M_USBHC_BIND_ADDRESS] = remote_usbhc_bind_address,
    338276        [IPC_M_USBHC_GET_HANDLE_BY_ADDRESS] = remote_usbhc_get_handle,
    339277
     
    384322        return trans;
    385323}
    386 /*----------------------------------------------------------------------------*/
    387 void remote_usbhc_request_address(ddf_fun_t *fun, void *iface,
    388     ipc_callid_t callid, ipc_call_t *call)
    389 {
    390         const usbhc_iface_t *usb_iface = iface;
    391 
    392         if (!usb_iface->request_address) {
    393                 async_answer_0(callid, ENOTSUP);
    394                 return;
    395         }
    396 
    397         usb_address_t address = DEV_IPC_GET_ARG1(*call);
    398         const bool strict = DEV_IPC_GET_ARG2(*call);
    399         const usb_speed_t speed = DEV_IPC_GET_ARG3(*call);
    400 
    401         const int rc = usb_iface->request_address(fun, &address, strict, speed);
    402         if (rc != EOK) {
    403                 async_answer_0(callid, rc);
    404         } else {
    405                 async_answer_1(callid, EOK, (sysarg_t) address);
    406         }
    407 }
    408 /*----------------------------------------------------------------------------*/
    409 void remote_usbhc_bind_address(ddf_fun_t *fun, void *iface,
    410     ipc_callid_t callid, ipc_call_t *call)
    411 {
    412         const usbhc_iface_t *usb_iface = iface;
    413 
    414         if (!usb_iface->bind_address) {
    415                 async_answer_0(callid, ENOTSUP);
    416                 return;
    417         }
    418 
    419         const usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
    420         const devman_handle_t handle = (devman_handle_t) DEV_IPC_GET_ARG2(*call);
    421 
    422         const int ret = usb_iface->bind_address(fun, address, handle);
    423         async_answer_0(callid, ret);
    424 }
    425 /*----------------------------------------------------------------------------*/
     324
     325
    426326void remote_usbhc_get_handle(ddf_fun_t *fun, void *iface,
    427327    ipc_callid_t callid, ipc_call_t *call)
     
    444344        }
    445345}
    446 /*----------------------------------------------------------------------------*/
    447 void remote_usbhc_release_address(ddf_fun_t *fun, void *iface,
    448     ipc_callid_t callid, ipc_call_t *call)
    449 {
    450         const usbhc_iface_t *usb_iface = iface;
    451 
    452         if (!usb_iface->release_address) {
    453                 async_answer_0(callid, ENOTSUP);
    454                 return;
    455         }
    456 
    457         const usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
    458 
    459         const int ret = usb_iface->release_address(fun, address);
    460         async_answer_0(callid, ret);
    461 }
    462 /*----------------------------------------------------------------------------*/
    463 static void callback_out(ddf_fun_t *fun,
    464     int outcome, void *arg)
     346
     347
     348static void callback_out(int outcome, void *arg)
    465349{
    466350        async_transaction_t *trans = arg;
     
    470354        async_transaction_destroy(trans);
    471355}
    472 /*----------------------------------------------------------------------------*/
    473 static void callback_in(ddf_fun_t *fun,
    474     int outcome, size_t actual_size, void *arg)
     356
     357static void callback_in(int outcome, size_t actual_size, void *arg)
    475358{
    476359        async_transaction_t *trans = (async_transaction_t *)arg;
     
    494377        async_transaction_destroy(trans);
    495378}
    496 /*----------------------------------------------------------------------------*/
     379
    497380void remote_usbhc_register_endpoint(ddf_fun_t *fun, void *iface,
    498381    ipc_callid_t callid, ipc_call_t *call)
     
    594477        }
    595478}
    596 /*----------------------------------------------------------------------------*/
     479
    597480void remote_usbhc_write(
    598481    ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
Note: See TracChangeset for help on using the changeset viewer.