Ignore:
File:
1 edited

Legend:

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

    r50b581d r99172baf  
    3737#include <errno.h>
    3838#include <assert.h>
     39#include <macros.h>
    3940
    4041#include "usbhc_iface.h"
     
    165166{
    166167        if (!exch || !address)
    167                 return EINVAL;
     168                return EBADMEM;
    168169        sysarg_t new_address;
    169170        const int ret = async_req_4_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     
    173174        return ret;
    174175}
    175 /*----------------------------------------------------------------------------*/
     176
    176177int usbhc_bind_address(async_exch_t *exch, usb_address_t address,
    177178    devman_handle_t handle)
    178179{
    179180        if (!exch)
    180                 return EINVAL;
     181                return EBADMEM;
    181182        return async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    182183            IPC_M_USBHC_BIND_ADDRESS, address, handle);
    183184}
    184 /*----------------------------------------------------------------------------*/
     185
    185186int usbhc_get_handle(async_exch_t *exch, usb_address_t address,
    186187    devman_handle_t *handle)
    187188{
    188189        if (!exch)
    189                 return EINVAL;
     190                return EBADMEM;
    190191        sysarg_t h;
    191192        const int ret = async_req_2_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     
    195196        return ret;
    196197}
    197 /*----------------------------------------------------------------------------*/
     198
    198199int usbhc_release_address(async_exch_t *exch, usb_address_t address)
    199200{
    200201        if (!exch)
    201                 return EINVAL;
     202                return EBADMEM;
    202203        return async_req_2_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    203204            IPC_M_USBHC_RELEASE_ADDRESS, address);
    204205}
    205 /*----------------------------------------------------------------------------*/
     206
    206207int usbhc_register_endpoint(async_exch_t *exch, usb_address_t address,
    207208    usb_endpoint_t endpoint, usb_transfer_type_t type,
     
    209210{
    210211        if (!exch)
    211                 return EINVAL;
     212                return EBADMEM;
    212213        const usb_target_t target =
    213214            {{ .address = address, .endpoint = endpoint }};
     
    220221#undef _PACK2
    221222}
    222 /*----------------------------------------------------------------------------*/
     223
    223224int usbhc_unregister_endpoint(async_exch_t *exch, usb_address_t address,
    224225    usb_endpoint_t endpoint, usb_direction_t direction)
    225226{
    226227        if (!exch)
    227                 return EINVAL;
     228                return EBADMEM;
    228229        return async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    229230            IPC_M_USBHC_UNREGISTER_ENDPOINT, address, endpoint, direction);
    230231}
    231 /*----------------------------------------------------------------------------*/
     232
    232233int usbhc_read(async_exch_t *exch, usb_address_t address,
    233234    usb_endpoint_t endpoint, uint64_t setup, void *data, size_t size,
    234235    size_t *rec_size)
    235236{
     237        if (!exch)
     238                return EBADMEM;
     239
    236240        if (size == 0 && setup == 0)
    237241                return EOK;
    238242
    239         if (!exch)
    240                 return EINVAL;
    241243        const usb_target_t target =
    242244            {{ .address = address, .endpoint = endpoint }};
     
    284286        return EOK;
    285287}
    286 /*----------------------------------------------------------------------------*/
     288
    287289int usbhc_write(async_exch_t *exch, usb_address_t address,
    288290    usb_endpoint_t endpoint, uint64_t setup, const void *data, size_t size)
    289291{
     292        if (!exch)
     293                return EBADMEM;
     294
    290295        if (size == 0 && setup == 0)
    291296                return EOK;
    292297
    293         if (!exch)
    294                 return EINVAL;
    295298        const usb_target_t target =
    296299            {{ .address = address, .endpoint = endpoint }};
     
    319322        return (int) opening_request_rc;
    320323}
    321 /*----------------------------------------------------------------------------*/
     324
    322325
    323326static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     
    332335
    333336/** Remote USB host controller interface operations. */
    334 static remote_iface_func_ptr_t remote_usbhc_iface_ops[] = {
     337static const remote_iface_func_ptr_t remote_usbhc_iface_ops[] = {
    335338        [IPC_M_USBHC_REQUEST_ADDRESS] = remote_usbhc_request_address,
    336339        [IPC_M_USBHC_RELEASE_ADDRESS] = remote_usbhc_release_address,
     
    347350/** Remote USB host controller interface structure.
    348351 */
    349 remote_iface_t remote_usbhc_iface = {
    350         .method_count = sizeof(remote_usbhc_iface_ops) /
    351             sizeof(remote_usbhc_iface_ops[0]),
     352const remote_iface_t remote_usbhc_iface = {
     353        .method_count = ARRAY_SIZE(remote_usbhc_iface_ops),
    352354        .methods = remote_usbhc_iface_ops
    353355};
     
    361363static void async_transaction_destroy(async_transaction_t *trans)
    362364{
    363         if (trans == NULL) {
    364                 return;
    365         }
    366         if (trans->buffer != NULL) {
     365        if (trans == NULL)
     366                return;
     367       
     368        if (trans->buffer != NULL)
    367369                free(trans->buffer);
    368         }
    369 
     370       
    370371        free(trans);
    371372}
     
    384385        return trans;
    385386}
    386 /*----------------------------------------------------------------------------*/
     387
    387388void remote_usbhc_request_address(ddf_fun_t *fun, void *iface,
    388389    ipc_callid_t callid, ipc_call_t *call)
     
    406407        }
    407408}
    408 /*----------------------------------------------------------------------------*/
     409
    409410void remote_usbhc_bind_address(ddf_fun_t *fun, void *iface,
    410411    ipc_callid_t callid, ipc_call_t *call)
     
    423424        async_answer_0(callid, ret);
    424425}
    425 /*----------------------------------------------------------------------------*/
     426
    426427void remote_usbhc_get_handle(ddf_fun_t *fun, void *iface,
    427428    ipc_callid_t callid, ipc_call_t *call)
     
    444445        }
    445446}
    446 /*----------------------------------------------------------------------------*/
     447
    447448void remote_usbhc_release_address(ddf_fun_t *fun, void *iface,
    448449    ipc_callid_t callid, ipc_call_t *call)
     
    460461        async_answer_0(callid, ret);
    461462}
    462 /*----------------------------------------------------------------------------*/
     463
    463464static void callback_out(ddf_fun_t *fun,
    464465    int outcome, void *arg)
     
    470471        async_transaction_destroy(trans);
    471472}
    472 /*----------------------------------------------------------------------------*/
     473
    473474static void callback_in(ddf_fun_t *fun,
    474475    int outcome, size_t actual_size, void *arg)
     
    494495        async_transaction_destroy(trans);
    495496}
    496 /*----------------------------------------------------------------------------*/
     497
    497498void remote_usbhc_register_endpoint(ddf_fun_t *fun, void *iface,
    498499    ipc_callid_t callid, ipc_call_t *call)
     
    583584                async_answer_0(callid, ENOMEM);
    584585                async_transaction_destroy(trans);
     586                return;
    585587        }
    586588
     
    594596        }
    595597}
    596 /*----------------------------------------------------------------------------*/
     598
    597599void remote_usbhc_write(
    598600    ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
Note: See TracChangeset for help on using the changeset viewer.