Ignore:
File:
1 edited

Legend:

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

    r3afcf68 r58563585  
    175175} pack8_t;
    176176
    177 int usb_register_endpoint(async_exch_t *exch,
    178         usb_endpoint_desc_t *endpoint_desc)
    179 {
    180         if (!exch)
    181                 return EBADMEM;
    182 
    183         aid_t opening_request = async_send_1(exch,
    184             DEV_IFACE_ID(USB_DEV_IFACE), IPC_M_USB_REGISTER_ENDPOINT, NULL);
    185 
    186         if (opening_request == 0) {
    187                 return ENOMEM;
    188         }
    189 
    190         const int ret = async_data_write_start(exch, (void *) endpoint_desc,
    191                 sizeof(usb_endpoint_desc_t));
    192 
    193         if (ret != EOK) {
    194                 async_forget(opening_request);
    195                 return ret;
    196         }
    197 
    198         /* Wait for the answer. */
    199         sysarg_t opening_request_rc;
    200         async_wait_for(opening_request, &opening_request_rc);
    201 
    202         return (int) opening_request_rc;
    203 }
    204 
    205 int usb_unregister_endpoint(async_exch_t *exch,
    206         usb_endpoint_desc_t *endpoint_desc)
    207 {
    208         if (!exch)
    209                 return EBADMEM;
    210 
    211         aid_t opening_request = async_send_1(exch,
    212                 DEV_IFACE_ID(USB_DEV_IFACE), IPC_M_USB_UNREGISTER_ENDPOINT, NULL);
    213 
    214         if (opening_request == 0) {
    215                 return ENOMEM;
    216         }
    217 
    218         const int ret = async_data_write_start(exch, endpoint_desc,
    219                 sizeof(usb_endpoint_desc_t));
    220         if (ret != EOK) {
    221                 async_forget(opening_request);
    222                 return ret;
    223         }
    224 
    225         /* Wait for the answer. */
    226         sysarg_t opening_request_rc;
    227         async_wait_for(opening_request, &opening_request_rc);
    228 
    229         return (int) opening_request_rc;
     177int usb_register_endpoint(async_exch_t *exch, usb_endpoint_t endpoint,
     178    usb_transfer_type_t type, usb_direction_t direction,
     179    size_t mps, unsigned packets, unsigned interval)
     180{
     181        if (!exch)
     182                return EBADMEM;
     183        pack8_t pack;
     184        pack.arr[0] = type;
     185        pack.arr[1] = direction;
     186        pack.arr[2] = interval;
     187        pack.arr[3] = packets;
     188
     189        return async_req_4_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     190            IPC_M_USB_REGISTER_ENDPOINT, endpoint, pack.arg, mps);
     191
     192}
     193
     194int usb_unregister_endpoint(async_exch_t *exch, usb_endpoint_t endpoint,
     195    usb_direction_t direction)
     196{
     197        if (!exch)
     198                return EBADMEM;
     199        return async_req_3_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
     200            IPC_M_USB_UNREGISTER_ENDPOINT, endpoint, direction);
    230201}
    231202
     
    346317};
    347318
    348 typedef struct {
    349         ipc_callid_t caller;
    350         ipc_callid_t data_caller;
    351         void *buffer;
    352 } async_transaction_t;
    353 
    354319void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface,
    355320    ipc_callid_t callid, ipc_call_t *call)
     
    452417    ipc_callid_t callid, ipc_call_t *call)
    453418{
    454         assert(fun);
    455         assert(iface);
    456         assert(call);
    457 
    458         const usb_iface_t *usb_iface = iface;
     419        usb_iface_t *usb_iface = (usb_iface_t *) iface;
    459420
    460421        if (!usb_iface->register_endpoint) {
     
    463424        }
    464425
    465         void *buffer = NULL;
    466         size_t size = 0;
    467         int rc = async_data_write_accept(&buffer, false,
    468                 sizeof(usb_endpoint_desc_t), sizeof(usb_endpoint_desc_t), 0, &size);
    469 
    470         if (rc != EOK) {
    471                 free(buffer);
    472                 async_answer_0(callid, rc);
    473                 return;
    474         }
    475 
    476         usb_endpoint_desc_t *endpoint_desc = (usb_endpoint_desc_t *) buffer;
    477         rc = usb_iface->register_endpoint(fun, endpoint_desc);
    478 
    479         free(buffer);
     426        const usb_endpoint_t endpoint = DEV_IPC_GET_ARG1(*call);
     427        const pack8_t pack = { .arg = DEV_IPC_GET_ARG2(*call)};
     428        const size_t max_packet_size = DEV_IPC_GET_ARG3(*call);
     429
     430        const usb_transfer_type_t transfer_type = pack.arr[0];
     431        const usb_direction_t direction = pack.arr[1];
     432        unsigned packets = pack.arr[2];
     433        unsigned interval = pack.arr[3];
     434
     435        const int ret = usb_iface->register_endpoint(fun, endpoint,
     436            transfer_type, direction, max_packet_size, packets, interval);
     437
     438        async_answer_0(callid, ret);
     439}
     440
     441static void remote_usb_unregister_endpoint(ddf_fun_t *fun, void *iface,
     442    ipc_callid_t callid, ipc_call_t *call)
     443{
     444        usb_iface_t *usb_iface = (usb_iface_t *) iface;
     445
     446        if (!usb_iface->unregister_endpoint) {
     447                async_answer_0(callid, ENOTSUP);
     448                return;
     449        }
     450
     451        usb_endpoint_t endpoint = (usb_endpoint_t) DEV_IPC_GET_ARG1(*call);
     452        usb_direction_t direction = (usb_direction_t) DEV_IPC_GET_ARG2(*call);
     453
     454        int rc = usb_iface->unregister_endpoint(fun, endpoint, direction);
     455
    480456        async_answer_0(callid, rc);
    481457}
    482458
    483 static void remote_usb_unregister_endpoint(ddf_fun_t *fun, void *iface,
    484     ipc_callid_t callid, ipc_call_t *call)
    485 {
    486         assert(fun);
    487         assert(iface);
    488         assert(call);
    489 
    490         const usb_iface_t *usb_iface = iface;
    491 
    492         if (!usb_iface->unregister_endpoint) {
    493                 async_answer_0(callid, ENOTSUP);
    494                 return;
    495         }
    496 
    497         void *buffer = NULL;
    498         size_t size = 0;
    499         int rc = async_data_write_accept(&buffer, false,
    500                 sizeof(usb_endpoint_desc_t), sizeof(usb_endpoint_desc_t), 0, &size);
    501 
    502         if (rc != EOK) {
    503                 free(buffer);
    504                 async_answer_0(callid, rc);
    505                 return;
    506         }
    507 
    508         usb_endpoint_desc_t *endpoint_desc = (usb_endpoint_desc_t *) buffer;
    509         usb_iface->unregister_endpoint(fun, endpoint_desc);
    510 
    511         free(buffer);
    512         if (rc != EOK) {
    513                 async_answer_0(callid, rc);
    514         }
    515 }
     459typedef struct {
     460        ipc_callid_t caller;
     461        ipc_callid_t data_caller;
     462        void *buffer;
     463} async_transaction_t;
    516464
    517465static void async_transaction_destroy(async_transaction_t *trans)
Note: See TracChangeset for help on using the changeset viewer.