Ignore:
File:
1 edited

Legend:

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

    r93f8da1 r5842493  
    3333 */
    3434
    35 #include <ipc/ipc.h>
    3635#include <async.h>
    3736#include <errno.h>
     
    4342
    4443static void remote_usbhc_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    45 static void remote_usbhc_get_buffer(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4644static void remote_usbhc_interrupt_out(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4745static void remote_usbhc_interrupt_in(device_t *, void *, ipc_callid_t, ipc_call_t *);
     
    6563        remote_usbhc_get_address,
    6664
    67         remote_usbhc_get_buffer,
    68 
    6965        remote_usbhc_reserve_default_address,
    7066        remote_usbhc_release_default_address,
     
    9995typedef struct {
    10096        ipc_callid_t caller;
     97        ipc_callid_t data_caller;
    10198        void *buffer;
    10299        void *setup_packet;
     
    128125
    129126        trans->caller = caller;
     127        trans->data_caller = 0;
    130128        trans->buffer = NULL;
    131129        trans->setup_packet = NULL;
     
    141139
    142140        if (!usb_iface->tell_address) {
    143                 ipc_answer_0(callid, ENOTSUP);
     141                async_answer_0(callid, ENOTSUP);
    144142                return;
    145143        }
     
    150148        int rc = usb_iface->tell_address(device, handle, &address);
    151149        if (rc != EOK) {
    152                 ipc_answer_0(callid, rc);
     150                async_answer_0(callid, rc);
    153151        } else {
    154                 ipc_answer_1(callid, EOK, address);
    155         }
    156 }
    157 
    158 void 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);
     152                async_answer_1(callid, EOK, address);
     153        }
    189154}
    190155
     
    195160
    196161        if (!usb_iface->reserve_default_address) {
    197                 ipc_answer_0(callid, ENOTSUP);
     162                async_answer_0(callid, ENOTSUP);
    198163                return;
    199164        }
     
    201166        int rc = usb_iface->reserve_default_address(device);
    202167
    203         ipc_answer_0(callid, rc);
     168        async_answer_0(callid, rc);
    204169}
    205170
     
    210175
    211176        if (!usb_iface->release_default_address) {
    212                 ipc_answer_0(callid, ENOTSUP);
     177                async_answer_0(callid, ENOTSUP);
    213178                return;
    214179        }
     
    216181        int rc = usb_iface->release_default_address(device);
    217182
    218         ipc_answer_0(callid, rc);
     183        async_answer_0(callid, rc);
    219184}
    220185
     
    225190
    226191        if (!usb_iface->request_address) {
    227                 ipc_answer_0(callid, ENOTSUP);
     192                async_answer_0(callid, ENOTSUP);
    228193                return;
    229194        }
     
    232197        int rc = usb_iface->request_address(device, &address);
    233198        if (rc != EOK) {
    234                 ipc_answer_0(callid, rc);
     199                async_answer_0(callid, rc);
    235200        } else {
    236                 ipc_answer_1(callid, EOK, (sysarg_t) address);
     201                async_answer_1(callid, EOK, (sysarg_t) address);
    237202        }
    238203}
     
    244209
    245210        if (!usb_iface->bind_address) {
    246                 ipc_answer_0(callid, ENOTSUP);
     211                async_answer_0(callid, ENOTSUP);
    247212                return;
    248213        }
     
    253218        int rc = usb_iface->bind_address(device, address, handle);
    254219
    255         ipc_answer_0(callid, rc);
     220        async_answer_0(callid, rc);
    256221}
    257222
     
    262227
    263228        if (!usb_iface->release_address) {
    264                 ipc_answer_0(callid, ENOTSUP);
     229                async_answer_0(callid, ENOTSUP);
    265230                return;
    266231        }
     
    270235        int rc = usb_iface->release_address(device, address);
    271236
    272         ipc_answer_0(callid, rc);
     237        async_answer_0(callid, rc);
    273238}
    274239
     
    279244        async_transaction_t *trans = (async_transaction_t *)arg;
    280245
    281         ipc_answer_0(trans->caller, outcome);
     246        async_answer_0(trans->caller, outcome);
    282247
    283248        async_transaction_destroy(trans);
     
    290255
    291256        if (outcome != USB_OUTCOME_OK) {
    292                 ipc_answer_0(trans->caller, outcome);
     257                async_answer_0(trans->caller, outcome);
     258                if (trans->data_caller) {
     259                        async_answer_0(trans->data_caller, EINTR);
     260                }
    293261                async_transaction_destroy(trans);
    294262                return;
     
    296264
    297265        trans->size = actual_size;
    298         ipc_answer_1(trans->caller, USB_OUTCOME_OK, (sysarg_t)trans);
     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);
    299275}
    300276
     
    311287{
    312288        if (!transfer_func) {
    313                 ipc_answer_0(callid, ENOTSUP);
     289                async_answer_0(callid, ENOTSUP);
    314290                return;
    315291        }
     
    329305
    330306                if (rc != EOK) {
    331                         ipc_answer_0(callid, rc);
     307                        async_answer_0(callid, rc);
    332308                        return;
    333309                }
     
    339315                        free(buffer);
    340316                }
    341                 ipc_answer_0(callid, ENOMEM);
     317                async_answer_0(callid, ENOMEM);
    342318                return;
    343319        }
     
    350326
    351327        if (rc != EOK) {
    352                 ipc_answer_0(callid, rc);
     328                async_answer_0(callid, rc);
    353329                async_transaction_destroy(trans);
    354330        }
     
    367343{
    368344        if (!transfer_func) {
    369                 ipc_answer_0(callid, ENOTSUP);
     345                async_answer_0(callid, ENOTSUP);
    370346                return;
    371347        }
     
    377353        };
    378354
     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
    379361        async_transaction_t *trans = async_transaction_create(callid);
    380362        if (trans == NULL) {
    381                 ipc_answer_0(callid, ENOMEM);
    382                 return;
    383         }
     363                async_answer_0(callid, ENOMEM);
     364                return;
     365        }
     366        trans->data_caller = data_callid;
    384367        trans->buffer = malloc(len);
    385368        trans->size = len;
     
    389372
    390373        if (rc != EOK) {
    391                 ipc_answer_0(callid, rc);
     374                async_answer_0(callid, rc);
    392375                async_transaction_destroy(trans);
    393376        }
     
    414397                case USB_DIRECTION_IN:
    415398                        if (!transfer_in_func) {
    416                                 ipc_answer_0(callid, ENOTSUP);
     399                                async_answer_0(callid, ENOTSUP);
    417400                                return;
    418401                        }
     
    420403                case USB_DIRECTION_OUT:
    421404                        if (!transfer_out_func) {
    422                                 ipc_answer_0(callid, ENOTSUP);
     405                                async_answer_0(callid, ENOTSUP);
    423406                                return;
    424407                        }
     
    436419        async_transaction_t *trans = async_transaction_create(callid);
    437420        if (trans == NULL) {
    438                 ipc_answer_0(callid, ENOMEM);
     421                async_answer_0(callid, ENOMEM);
    439422                return;
    440423        }
     
    456439
    457440        if (rc != EOK) {
    458                 ipc_answer_0(callid, rc);
     441                async_answer_0(callid, rc);
    459442                async_transaction_destroy(trans);
    460443        }
     
    549532
    550533        if (!usb_iface->control_write) {
    551                 ipc_answer_0(callid, ENOTSUP);
     534                async_answer_0(callid, ENOTSUP);
    552535                return;
    553536        }
     
    568551            1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
    569552        if (rc != EOK) {
    570                 ipc_answer_0(callid, rc);
     553                async_answer_0(callid, rc);
    571554                return;
    572555        }
     
    574557            1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len);
    575558        if (rc != EOK) {
    576                 ipc_answer_0(callid, rc);
     559                async_answer_0(callid, rc);
    577560                free(setup_packet);
    578561                return;
     
    581564        async_transaction_t *trans = async_transaction_create(callid);
    582565        if (trans == NULL) {
    583                 ipc_answer_0(callid, ENOMEM);
     566                async_answer_0(callid, ENOMEM);
    584567                free(setup_packet);
    585568                free(data_buffer);
     
    596579
    597580        if (rc != EOK) {
    598                 ipc_answer_0(callid, rc);
     581                async_answer_0(callid, rc);
    599582                async_transaction_destroy(trans);
    600583        }
     
    609592
    610593        if (!usb_iface->control_read) {
    611                 ipc_answer_0(callid, ENOTSUP);
     594                async_answer_0(callid, ENOTSUP);
    612595                return;
    613596        }
     
    627610            1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
    628611        if (rc != EOK) {
    629                 ipc_answer_0(callid, rc);
     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);
     619                free(setup_packet);
    630620                return;
    631621        }
     
    633623        async_transaction_t *trans = async_transaction_create(callid);
    634624        if (trans == NULL) {
    635                 ipc_answer_0(callid, ENOMEM);
     625                async_answer_0(callid, ENOMEM);
    636626                free(setup_packet);
    637627                return;
    638628        }
     629        trans->data_caller = data_callid;
    639630        trans->setup_packet = setup_packet;
    640631        trans->size = data_len;
    641632        trans->buffer = malloc(data_len);
    642633        if (trans->buffer == NULL) {
    643                 ipc_answer_0(callid, ENOMEM);
     634                async_answer_0(callid, ENOMEM);
    644635                async_transaction_destroy(trans);
    645636                return;
     
    652643
    653644        if (rc != EOK) {
    654                 ipc_answer_0(callid, rc);
     645                async_answer_0(callid, rc);
    655646                async_transaction_destroy(trans);
    656647        }
Note: See TracChangeset for help on using the changeset viewer.