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


Ignore:
Timestamp:
2017-10-15T16:55:48Z (7 years ago)
Author:
Michal Staruch <salmelu@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9b2f69e
Parents:
2770b66
Message:

Remote USB (async) sending structures

remote_usb_register_endpoint is now sending a whole new structure, instead of 5 numeric arguments pulled out of structure.
This allows future extensibility for the structure as well as a working code to be used for other remote async calls.

File:
1 edited

Legend:

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

    r2770b66 r816f5f4  
    175175} pack8_t;
    176176
    177 int 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 
    194 int 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);
     177int 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
     205int 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;
    201230}
    202231
     
    317346};
    318347
     348typedef struct {
     349        ipc_callid_t caller;
     350        ipc_callid_t data_caller;
     351        void *buffer;
     352} async_transaction_t;
     353
    319354void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface,
    320355    ipc_callid_t callid, ipc_call_t *call)
     
    417452    ipc_callid_t callid, ipc_call_t *call)
    418453{
    419         usb_iface_t *usb_iface = (usb_iface_t *) iface;
     454        assert(fun);
     455        assert(iface);
     456        assert(call);
     457
     458        const usb_iface_t *usb_iface = iface;
    420459
    421460        if (!usb_iface->register_endpoint) {
     
    424463        }
    425464
    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);
     465        void *buffer = malloc(sizeof(usb_endpoint_desc_t));
     466        if (!buffer) {
     467                async_answer_0(callid, ENOMEM);
     468                return;
     469        }
     470
     471        size_t size = 0;
     472        int rc = async_data_write_accept(&buffer, false,
     473                1, sizeof(usb_endpoint_desc_t), 0, &size);
     474
     475        if (rc != EOK) {
     476                free(buffer);
     477                async_answer_0(callid, rc);
     478                return;
     479        }
     480
     481        usb_endpoint_desc_t *endpoint_desc = (usb_endpoint_desc_t *) buffer;
     482        rc = usb_iface->register_endpoint(fun, endpoint_desc);
     483
     484        free(buffer);
     485        async_answer_0(callid, rc);
    439486}
    440487
     
    442489    ipc_callid_t callid, ipc_call_t *call)
    443490{
    444         usb_iface_t *usb_iface = (usb_iface_t *) iface;
     491        assert(fun);
     492        assert(iface);
     493        assert(call);
     494
     495        const usb_iface_t *usb_iface = iface;
    445496
    446497        if (!usb_iface->unregister_endpoint) {
     
    449500        }
    450501
    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 
    456         async_answer_0(callid, rc);
    457 }
    458 
    459 typedef struct {
    460         ipc_callid_t caller;
    461         ipc_callid_t data_caller;
    462         void *buffer;
    463 } async_transaction_t;
     502        void *buffer = malloc(sizeof(usb_endpoint_desc_t));
     503        if (!buffer) {
     504                async_answer_0(callid, ENOMEM);
     505                return;
     506        }
     507
     508        size_t size = 0;
     509        int rc = async_data_write_accept(&buffer, false,
     510                1, sizeof(usb_endpoint_desc_t), 0, &size);
     511
     512        if (rc != EOK) {
     513                free(buffer);
     514                async_answer_0(callid, rc);
     515                return;
     516        }
     517
     518        usb_endpoint_desc_t *endpoint_desc = (usb_endpoint_desc_t *) buffer;
     519        usb_iface->unregister_endpoint(fun, endpoint_desc);
     520
     521        free(buffer);
     522        if (rc != EOK) {
     523                async_answer_0(callid, rc);
     524        }
     525}
    464526
    465527static void async_transaction_destroy(async_transaction_t *trans)
Note: See TracChangeset for help on using the changeset viewer.