Changeset e25a849 in mainline for uspace/lib/usbvirt/src/ipc_dev.c


Ignore:
Timestamp:
2011-05-06T15:50:03Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
42e2172
Parents:
dc06caa
Message:

libusbvirt: split IPC wrappers into more files

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbvirt/src/ipc_dev.c

    rdc06caa re25a849  
    3131 */
    3232/** @file
    33  *
     33 * IPC wrappers, device side.
    3434 */
    3535#include <errno.h>
     
    4141#include <usbvirt/device.h>
    4242#include <usbvirt/ipc.h>
    43 
    4443#include <usb/debug.h>
    45 
    46 static usbvirt_device_t *DEV = NULL;
    4744
    4845static void ipc_get_name(usbvirt_device_t *dev,
     
    248245}
    249246
    250 static void callback_connection(ipc_callid_t iid, ipc_call_t *icall)
    251 {
    252         assert(DEV != NULL);
    253 
    254         async_answer_0(iid, EOK);
    255 
    256         while (true) {
    257                 ipc_callid_t callid;
    258                 ipc_call_t call;
    259 
    260                 callid = async_get_call(&call);
    261                 bool processed = usbvirt_ipc_handle_call(DEV, callid, &call);
    262                 if (!processed) {
    263                         switch (IPC_GET_IMETHOD(call)) {
    264                                 case IPC_M_PHONE_HUNGUP:
    265                                         async_answer_0(callid, EOK);
    266                                         return;
    267                                 default:
    268                                         async_answer_0(callid, EINVAL);
    269                                         break;
    270                         }
    271                 }
    272         }
    273 }
    274 
    275 /** Connect the device to the virtual host controller.
    276  *
    277  * @param dev The virtual device to be (virtually) plugged in.
    278  * @param vhc_path Devman path to the virtual host controller.
    279  * @return Error code.
    280  */
    281 int usbvirt_device_plug(usbvirt_device_t *dev, const char *vhc_path)
    282 {
    283         int rc;
    284         devman_handle_t handle;
    285 
    286         rc = devman_device_get_handle(vhc_path, &handle, 0);
    287         if (rc != EOK) {
    288                 return rc;
    289         }
    290 
    291         int hcd_phone = devman_device_connect(handle, 0);
    292 
    293         if (hcd_phone < 0) {
    294                 return hcd_phone;
    295         }
    296 
    297         DEV = dev;
    298 
    299         rc = async_connect_to_me(hcd_phone, 0, 0, 0, callback_connection);
    300         if (rc != EOK) {
    301                 DEV = NULL;
    302                 return rc;
    303         }
    304 
    305 
    306 
    307         return EOK;
    308 }
    309 
    310 
    311 
    312 int usbvirt_ipc_send_control_read(int phone, usb_endpoint_t ep,
    313     void *setup_buffer, size_t setup_buffer_size,
    314     void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
    315 {
    316         aid_t opening_request = async_send_1(phone,
    317             IPC_M_USBVIRT_CONTROL_READ, ep, NULL);
    318         if (opening_request == 0) {
    319                 return ENOMEM;
    320         }
    321 
    322         int rc = async_data_write_start(phone,
    323             setup_buffer, setup_buffer_size);
    324         if (rc != EOK) {
    325                 async_wait_for(opening_request, NULL);
    326                 return rc;
    327         }
    328 
    329         ipc_call_t data_request_call;
    330         aid_t data_request = async_data_read(phone,
    331             data_buffer, data_buffer_size,
    332             &data_request_call);
    333 
    334         if (data_request == 0) {
    335                 async_wait_for(opening_request, NULL);
    336                 return ENOMEM;
    337         }
    338 
    339         sysarg_t data_request_rc;
    340         sysarg_t opening_request_rc;
    341         async_wait_for(data_request, &data_request_rc);
    342         async_wait_for(opening_request, &opening_request_rc);
    343 
    344         if (data_request_rc != EOK) {
    345                 /* Prefer the return code of the opening request. */
    346                 if (opening_request_rc != EOK) {
    347                         return (int) opening_request_rc;
    348                 } else {
    349                         return (int) data_request_rc;
    350                 }
    351         }
    352         if (opening_request_rc != EOK) {
    353                 return (int) opening_request_rc;
    354         }
    355 
    356         *data_transfered_size = IPC_GET_ARG2(data_request_call);
    357 
    358         return EOK;
    359 }
    360 
    361 int usbvirt_ipc_send_control_write(int phone, usb_endpoint_t ep,
    362     void *setup_buffer, size_t setup_buffer_size,
    363     void *data_buffer, size_t data_buffer_size)
    364 {
    365         aid_t opening_request = async_send_2(phone,
    366             IPC_M_USBVIRT_CONTROL_WRITE, ep, data_buffer_size,  NULL);
    367         if (opening_request == 0) {
    368                 return ENOMEM;
    369         }
    370 
    371         int rc = async_data_write_start(phone,
    372             setup_buffer, setup_buffer_size);
    373         if (rc != EOK) {
    374                 async_wait_for(opening_request, NULL);
    375                 return rc;
    376         }
    377 
    378         if (data_buffer_size > 0) {
    379                 rc = async_data_write_start(phone,
    380                     data_buffer, data_buffer_size);
    381 
    382                 if (rc != EOK) {
    383                         async_wait_for(opening_request, NULL);
    384                         return rc;
    385                 }
    386         }
    387 
    388         sysarg_t opening_request_rc;
    389         async_wait_for(opening_request, &opening_request_rc);
    390 
    391         return (int) opening_request_rc;
    392 }
    393 
    394 int usbvirt_ipc_send_data_in(int phone, usb_endpoint_t ep,
    395     usb_transfer_type_t tr_type, void *data, size_t data_size, size_t *act_size)
    396 {
    397         aid_t opening_request = async_send_2(phone,
    398             IPC_M_USBVIRT_INTERRUPT_IN, ep, tr_type, NULL);
    399         if (opening_request == 0) {
    400                 return ENOMEM;
    401         }
    402 
    403         ipc_call_t data_request_call;
    404         aid_t data_request = async_data_read(phone,
    405             data, data_size,  &data_request_call);
    406 
    407         if (data_request == 0) {
    408                 async_wait_for(opening_request, NULL);
    409                 return ENOMEM;
    410         }
    411 
    412         sysarg_t data_request_rc;
    413         sysarg_t opening_request_rc;
    414         async_wait_for(data_request, &data_request_rc);
    415         async_wait_for(opening_request, &opening_request_rc);
    416 
    417         if (data_request_rc != EOK) {
    418                 /* Prefer the return code of the opening request. */
    419                 if (opening_request_rc != EOK) {
    420                         return (int) opening_request_rc;
    421                 } else {
    422                         return (int) data_request_rc;
    423                 }
    424         }
    425         if (opening_request_rc != EOK) {
    426                 return (int) opening_request_rc;
    427         }
    428 
    429         if (act_size != NULL) {
    430                 *act_size = IPC_GET_ARG2(data_request_call);
    431         }
    432 
    433         return EOK;
    434 }
    435 
    436 int usbvirt_ipc_send_data_out(int phone, usb_endpoint_t ep,
    437     usb_transfer_type_t tr_type, void *data, size_t data_size)
    438 {
    439         aid_t opening_request = async_send_2(phone,
    440             IPC_M_USBVIRT_INTERRUPT_OUT, ep, tr_type, NULL);
    441         if (opening_request == 0) {
    442                 return ENOMEM;
    443         }
    444 
    445         int rc = async_data_write_start(phone,
    446             data, data_size);
    447         if (rc != EOK) {
    448                 async_wait_for(opening_request, NULL);
    449                 return rc;
    450         }
    451 
    452         sysarg_t opening_request_rc;
    453         async_wait_for(opening_request, &opening_request_rc);
    454 
    455         return (int) opening_request_rc;
    456 }
    457 
    458 
    459247/**
    460248 * @}
Note: See TracChangeset for help on using the changeset viewer.