Ignore:
File:
1 edited

Legend:

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

    r5842493 r93f8da1  
    3333 */
    3434
     35#include <ipc/ipc.h>
    3536#include <async.h>
    3637#include <errno.h>
     
    4243
    4344static void remote_usbhc_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
     45static void remote_usbhc_get_buffer(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4446static void remote_usbhc_interrupt_out(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4547static void remote_usbhc_interrupt_in(device_t *, void *, ipc_callid_t, ipc_call_t *);
     
    6365        remote_usbhc_get_address,
    6466
     67        remote_usbhc_get_buffer,
     68
    6569        remote_usbhc_reserve_default_address,
    6670        remote_usbhc_release_default_address,
     
    9599typedef struct {
    96100        ipc_callid_t caller;
    97         ipc_callid_t data_caller;
    98101        void *buffer;
    99102        void *setup_packet;
     
    125128
    126129        trans->caller = caller;
    127         trans->data_caller = 0;
    128130        trans->buffer = NULL;
    129131        trans->setup_packet = NULL;
     
    139141
    140142        if (!usb_iface->tell_address) {
    141                 async_answer_0(callid, ENOTSUP);
     143                ipc_answer_0(callid, ENOTSUP);
    142144                return;
    143145        }
     
    148150        int rc = usb_iface->tell_address(device, handle, &address);
    149151        if (rc != EOK) {
    150                 async_answer_0(callid, rc);
     152                ipc_answer_0(callid, rc);
    151153        } else {
    152                 async_answer_1(callid, EOK, address);
    153         }
     154                ipc_answer_1(callid, EOK, address);
     155        }
     156}
     157
     158void remote_usbhc_get_buffer(device_t *device, void *iface,
     159    ipc_callid_t callid, ipc_call_t *call)
     160{
     161        sysarg_t buffer_hash = DEV_IPC_GET_ARG1(*call);
     162        async_transaction_t * trans = (async_transaction_t *)buffer_hash;
     163        if (trans == NULL) {
     164                ipc_answer_0(callid, ENOENT);
     165                return;
     166        }
     167        if (trans->buffer == NULL) {
     168                ipc_answer_0(callid, EINVAL);
     169                async_transaction_destroy(trans);
     170                return;
     171        }
     172
     173        ipc_callid_t cid;
     174        size_t accepted_size;
     175        if (!async_data_read_receive(&cid, &accepted_size)) {
     176                ipc_answer_0(callid, EINVAL);
     177                async_transaction_destroy(trans);
     178                return;
     179        }
     180
     181        if (accepted_size > trans->size) {
     182                accepted_size = trans->size;
     183        }
     184        async_data_read_finalize(cid, trans->buffer, accepted_size);
     185
     186        ipc_answer_1(callid, EOK, accepted_size);
     187
     188        async_transaction_destroy(trans);
    154189}
    155190
     
    160195
    161196        if (!usb_iface->reserve_default_address) {
    162                 async_answer_0(callid, ENOTSUP);
     197                ipc_answer_0(callid, ENOTSUP);
    163198                return;
    164199        }
     
    166201        int rc = usb_iface->reserve_default_address(device);
    167202
    168         async_answer_0(callid, rc);
     203        ipc_answer_0(callid, rc);
    169204}
    170205
     
    175210
    176211        if (!usb_iface->release_default_address) {
    177                 async_answer_0(callid, ENOTSUP);
     212                ipc_answer_0(callid, ENOTSUP);
    178213                return;
    179214        }
     
    181216        int rc = usb_iface->release_default_address(device);
    182217
    183         async_answer_0(callid, rc);
     218        ipc_answer_0(callid, rc);
    184219}
    185220
     
    190225
    191226        if (!usb_iface->request_address) {
    192                 async_answer_0(callid, ENOTSUP);
     227                ipc_answer_0(callid, ENOTSUP);
    193228                return;
    194229        }
     
    197232        int rc = usb_iface->request_address(device, &address);
    198233        if (rc != EOK) {
    199                 async_answer_0(callid, rc);
     234                ipc_answer_0(callid, rc);
    200235        } else {
    201                 async_answer_1(callid, EOK, (sysarg_t) address);
     236                ipc_answer_1(callid, EOK, (sysarg_t) address);
    202237        }
    203238}
     
    209244
    210245        if (!usb_iface->bind_address) {
    211                 async_answer_0(callid, ENOTSUP);
     246                ipc_answer_0(callid, ENOTSUP);
    212247                return;
    213248        }
     
    218253        int rc = usb_iface->bind_address(device, address, handle);
    219254
    220         async_answer_0(callid, rc);
     255        ipc_answer_0(callid, rc);
    221256}
    222257
     
    227262
    228263        if (!usb_iface->release_address) {
    229                 async_answer_0(callid, ENOTSUP);
     264                ipc_answer_0(callid, ENOTSUP);
    230265                return;
    231266        }
     
    235270        int rc = usb_iface->release_address(device, address);
    236271
    237         async_answer_0(callid, rc);
     272        ipc_answer_0(callid, rc);
    238273}
    239274
     
    244279        async_transaction_t *trans = (async_transaction_t *)arg;
    245280
    246         async_answer_0(trans->caller, outcome);
     281        ipc_answer_0(trans->caller, outcome);
    247282
    248283        async_transaction_destroy(trans);
     
    255290
    256291        if (outcome != USB_OUTCOME_OK) {
    257                 async_answer_0(trans->caller, outcome);
    258                 if (trans->data_caller) {
    259                         async_answer_0(trans->data_caller, EINTR);
    260                 }
     292                ipc_answer_0(trans->caller, outcome);
    261293                async_transaction_destroy(trans);
    262294                return;
     
    264296
    265297        trans->size = actual_size;
    266 
    267         if (trans->data_caller) {
    268                 async_data_read_finalize(trans->data_caller,
    269                     trans->buffer, actual_size);
    270         }
    271 
    272         async_answer_0(trans->caller, USB_OUTCOME_OK);
    273 
    274         async_transaction_destroy(trans);
     298        ipc_answer_1(trans->caller, USB_OUTCOME_OK, (sysarg_t)trans);
    275299}
    276300
     
    287311{
    288312        if (!transfer_func) {
    289                 async_answer_0(callid, ENOTSUP);
     313                ipc_answer_0(callid, ENOTSUP);
    290314                return;
    291315        }
     
    305329
    306330                if (rc != EOK) {
    307                         async_answer_0(callid, rc);
     331                        ipc_answer_0(callid, rc);
    308332                        return;
    309333                }
     
    315339                        free(buffer);
    316340                }
    317                 async_answer_0(callid, ENOMEM);
     341                ipc_answer_0(callid, ENOMEM);
    318342                return;
    319343        }
     
    326350
    327351        if (rc != EOK) {
    328                 async_answer_0(callid, rc);
     352                ipc_answer_0(callid, rc);
    329353                async_transaction_destroy(trans);
    330354        }
     
    343367{
    344368        if (!transfer_func) {
    345                 async_answer_0(callid, ENOTSUP);
     369                ipc_answer_0(callid, ENOTSUP);
    346370                return;
    347371        }
     
    353377        };
    354378
    355         ipc_callid_t data_callid;
    356         if (!async_data_read_receive(&data_callid, &len)) {
    357                 async_answer_0(callid, EPARTY);
    358                 return;
    359         }
    360 
    361379        async_transaction_t *trans = async_transaction_create(callid);
    362380        if (trans == NULL) {
    363                 async_answer_0(callid, ENOMEM);
    364                 return;
    365         }
    366         trans->data_caller = data_callid;
     381                ipc_answer_0(callid, ENOMEM);
     382                return;
     383        }
    367384        trans->buffer = malloc(len);
    368385        trans->size = len;
     
    372389
    373390        if (rc != EOK) {
    374                 async_answer_0(callid, rc);
     391                ipc_answer_0(callid, rc);
    375392                async_transaction_destroy(trans);
    376393        }
     
    397414                case USB_DIRECTION_IN:
    398415                        if (!transfer_in_func) {
    399                                 async_answer_0(callid, ENOTSUP);
     416                                ipc_answer_0(callid, ENOTSUP);
    400417                                return;
    401418                        }
     
    403420                case USB_DIRECTION_OUT:
    404421                        if (!transfer_out_func) {
    405                                 async_answer_0(callid, ENOTSUP);
     422                                ipc_answer_0(callid, ENOTSUP);
    406423                                return;
    407424                        }
     
    419436        async_transaction_t *trans = async_transaction_create(callid);
    420437        if (trans == NULL) {
    421                 async_answer_0(callid, ENOMEM);
     438                ipc_answer_0(callid, ENOMEM);
    422439                return;
    423440        }
     
    439456
    440457        if (rc != EOK) {
    441                 async_answer_0(callid, rc);
     458                ipc_answer_0(callid, rc);
    442459                async_transaction_destroy(trans);
    443460        }
     
    532549
    533550        if (!usb_iface->control_write) {
    534                 async_answer_0(callid, ENOTSUP);
     551                ipc_answer_0(callid, ENOTSUP);
    535552                return;
    536553        }
     
    551568            1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
    552569        if (rc != EOK) {
    553                 async_answer_0(callid, rc);
     570                ipc_answer_0(callid, rc);
    554571                return;
    555572        }
     
    557574            1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len);
    558575        if (rc != EOK) {
    559                 async_answer_0(callid, rc);
     576                ipc_answer_0(callid, rc);
    560577                free(setup_packet);
    561578                return;
     
    564581        async_transaction_t *trans = async_transaction_create(callid);
    565582        if (trans == NULL) {
    566                 async_answer_0(callid, ENOMEM);
     583                ipc_answer_0(callid, ENOMEM);
    567584                free(setup_packet);
    568585                free(data_buffer);
     
    579596
    580597        if (rc != EOK) {
    581                 async_answer_0(callid, rc);
     598                ipc_answer_0(callid, rc);
    582599                async_transaction_destroy(trans);
    583600        }
     
    592609
    593610        if (!usb_iface->control_read) {
    594                 async_answer_0(callid, ENOTSUP);
     611                ipc_answer_0(callid, ENOTSUP);
    595612                return;
    596613        }
     
    610627            1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
    611628        if (rc != EOK) {
    612                 async_answer_0(callid, rc);
    613                 return;
    614         }
    615 
    616         ipc_callid_t data_callid;
    617         if (!async_data_read_receive(&data_callid, &data_len)) {
    618                 async_answer_0(callid, EPARTY);
     629                ipc_answer_0(callid, rc);
     630                return;
     631        }
     632
     633        async_transaction_t *trans = async_transaction_create(callid);
     634        if (trans == NULL) {
     635                ipc_answer_0(callid, ENOMEM);
    619636                free(setup_packet);
    620637                return;
    621638        }
    622 
    623         async_transaction_t *trans = async_transaction_create(callid);
    624         if (trans == NULL) {
    625                 async_answer_0(callid, ENOMEM);
    626                 free(setup_packet);
    627                 return;
    628         }
    629         trans->data_caller = data_callid;
    630639        trans->setup_packet = setup_packet;
    631640        trans->size = data_len;
    632641        trans->buffer = malloc(data_len);
    633642        if (trans->buffer == NULL) {
    634                 async_answer_0(callid, ENOMEM);
     643                ipc_answer_0(callid, ENOMEM);
    635644                async_transaction_destroy(trans);
    636645                return;
     
    643652
    644653        if (rc != EOK) {
    645                 async_answer_0(callid, rc);
     654                ipc_answer_0(callid, rc);
    646655                async_transaction_destroy(trans);
    647656        }
Note: See TracChangeset for help on using the changeset viewer.