Ignore:
File:
1 edited

Legend:

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

    r6427cf67 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);
    163                 return;
    164         }
    165        
    166         bool full_speed = DEV_IPC_GET_ARG1(*call);
    167        
    168         int rc = usb_iface->reserve_default_address(device, full_speed);
    169 
    170         async_answer_0(callid, rc);
     197                ipc_answer_0(callid, ENOTSUP);
     198                return;
     199        }
     200
     201        int rc = usb_iface->reserve_default_address(device);
     202
     203        ipc_answer_0(callid, rc);
    171204}
    172205
     
    177210
    178211        if (!usb_iface->release_default_address) {
    179                 async_answer_0(callid, ENOTSUP);
     212                ipc_answer_0(callid, ENOTSUP);
    180213                return;
    181214        }
     
    183216        int rc = usb_iface->release_default_address(device);
    184217
    185         async_answer_0(callid, rc);
     218        ipc_answer_0(callid, rc);
    186219}
    187220
     
    192225
    193226        if (!usb_iface->request_address) {
    194                 async_answer_0(callid, ENOTSUP);
    195                 return;
    196         }
    197        
    198         bool full_speed = DEV_IPC_GET_ARG1(*call);
     227                ipc_answer_0(callid, ENOTSUP);
     228                return;
     229        }
    199230
    200231        usb_address_t address;
    201         int rc = usb_iface->request_address(device, full_speed, &address);
    202         if (rc != EOK) {
    203                 async_answer_0(callid, rc);
     232        int rc = usb_iface->request_address(device, &address);
     233        if (rc != EOK) {
     234                ipc_answer_0(callid, rc);
    204235        } else {
    205                 async_answer_1(callid, EOK, (sysarg_t) address);
     236                ipc_answer_1(callid, EOK, (sysarg_t) address);
    206237        }
    207238}
     
    213244
    214245        if (!usb_iface->bind_address) {
    215                 async_answer_0(callid, ENOTSUP);
     246                ipc_answer_0(callid, ENOTSUP);
    216247                return;
    217248        }
     
    222253        int rc = usb_iface->bind_address(device, address, handle);
    223254
    224         async_answer_0(callid, rc);
     255        ipc_answer_0(callid, rc);
    225256}
    226257
     
    231262
    232263        if (!usb_iface->release_address) {
    233                 async_answer_0(callid, ENOTSUP);
     264                ipc_answer_0(callid, ENOTSUP);
    234265                return;
    235266        }
     
    239270        int rc = usb_iface->release_address(device, address);
    240271
    241         async_answer_0(callid, rc);
     272        ipc_answer_0(callid, rc);
    242273}
    243274
    244275
    245276static void callback_out(device_t *device,
    246     int outcome, void *arg)
     277    usb_transaction_outcome_t outcome, void *arg)
    247278{
    248279        async_transaction_t *trans = (async_transaction_t *)arg;
    249280
    250         async_answer_0(trans->caller, outcome);
     281        ipc_answer_0(trans->caller, outcome);
    251282
    252283        async_transaction_destroy(trans);
     
    254285
    255286static void callback_in(device_t *device,
    256     int outcome, size_t actual_size, void *arg)
     287    usb_transaction_outcome_t outcome, size_t actual_size, void *arg)
    257288{
    258289        async_transaction_t *trans = (async_transaction_t *)arg;
    259290
    260         if (outcome != EOK) {
    261                 async_answer_0(trans->caller, outcome);
    262                 if (trans->data_caller) {
    263                         async_answer_0(trans->data_caller, EINTR);
    264                 }
     291        if (outcome != USB_OUTCOME_OK) {
     292                ipc_answer_0(trans->caller, outcome);
    265293                async_transaction_destroy(trans);
    266294                return;
     
    268296
    269297        trans->size = actual_size;
    270 
    271         if (trans->data_caller) {
    272                 async_data_read_finalize(trans->data_caller,
    273                     trans->buffer, actual_size);
    274         }
    275 
    276         async_answer_0(trans->caller, EOK);
    277 
    278         async_transaction_destroy(trans);
     298        ipc_answer_1(trans->caller, USB_OUTCOME_OK, (sysarg_t)trans);
    279299}
    280300
     
    291311{
    292312        if (!transfer_func) {
    293                 async_answer_0(callid, ENOTSUP);
     313                ipc_answer_0(callid, ENOTSUP);
    294314                return;
    295315        }
     
    309329
    310330                if (rc != EOK) {
    311                         async_answer_0(callid, rc);
     331                        ipc_answer_0(callid, rc);
    312332                        return;
    313333                }
     
    319339                        free(buffer);
    320340                }
    321                 async_answer_0(callid, ENOMEM);
     341                ipc_answer_0(callid, ENOMEM);
    322342                return;
    323343        }
     
    330350
    331351        if (rc != EOK) {
    332                 async_answer_0(callid, rc);
     352                ipc_answer_0(callid, rc);
    333353                async_transaction_destroy(trans);
    334354        }
     
    347367{
    348368        if (!transfer_func) {
    349                 async_answer_0(callid, ENOTSUP);
     369                ipc_answer_0(callid, ENOTSUP);
    350370                return;
    351371        }
     
    357377        };
    358378
    359         ipc_callid_t data_callid;
    360         if (!async_data_read_receive(&data_callid, &len)) {
    361                 async_answer_0(callid, EPARTY);
    362                 return;
    363         }
    364 
    365379        async_transaction_t *trans = async_transaction_create(callid);
    366380        if (trans == NULL) {
    367                 async_answer_0(callid, ENOMEM);
    368                 return;
    369         }
    370         trans->data_caller = data_callid;
     381                ipc_answer_0(callid, ENOMEM);
     382                return;
     383        }
    371384        trans->buffer = malloc(len);
    372385        trans->size = len;
     
    376389
    377390        if (rc != EOK) {
    378                 async_answer_0(callid, rc);
     391                ipc_answer_0(callid, rc);
    379392                async_transaction_destroy(trans);
    380393        }
     
    401414                case USB_DIRECTION_IN:
    402415                        if (!transfer_in_func) {
    403                                 async_answer_0(callid, ENOTSUP);
     416                                ipc_answer_0(callid, ENOTSUP);
    404417                                return;
    405418                        }
     
    407420                case USB_DIRECTION_OUT:
    408421                        if (!transfer_out_func) {
    409                                 async_answer_0(callid, ENOTSUP);
     422                                ipc_answer_0(callid, ENOTSUP);
    410423                                return;
    411424                        }
     
    423436        async_transaction_t *trans = async_transaction_create(callid);
    424437        if (trans == NULL) {
    425                 async_answer_0(callid, ENOMEM);
     438                ipc_answer_0(callid, ENOMEM);
    426439                return;
    427440        }
     
    443456
    444457        if (rc != EOK) {
    445                 async_answer_0(callid, rc);
     458                ipc_answer_0(callid, rc);
    446459                async_transaction_destroy(trans);
    447460        }
     
    536549
    537550        if (!usb_iface->control_write) {
    538                 async_answer_0(callid, ENOTSUP);
     551                ipc_answer_0(callid, ENOTSUP);
    539552                return;
    540553        }
     
    544557                .endpoint = DEV_IPC_GET_ARG2(*call)
    545558        };
    546         size_t data_buffer_len = DEV_IPC_GET_ARG3(*call);
    547559
    548560        int rc;
     
    551563        void *data_buffer = NULL;
    552564        size_t setup_packet_len = 0;
     565        size_t data_buffer_len = 0;
    553566
    554567        rc = async_data_write_accept(&setup_packet, false,
    555568            1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
    556569        if (rc != EOK) {
    557                 async_answer_0(callid, rc);
    558                 return;
    559         }
    560 
    561         if (data_buffer_len > 0) {
    562                 rc = async_data_write_accept(&data_buffer, false,
    563                     1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len);
    564                 if (rc != EOK) {
    565                         async_answer_0(callid, rc);
    566                         free(setup_packet);
    567                         return;
    568                 }
     570                ipc_answer_0(callid, rc);
     571                return;
     572        }
     573        rc = async_data_write_accept(&data_buffer, false,
     574            1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len);
     575        if (rc != EOK) {
     576                ipc_answer_0(callid, rc);
     577                free(setup_packet);
     578                return;
    569579        }
    570580
    571581        async_transaction_t *trans = async_transaction_create(callid);
    572582        if (trans == NULL) {
    573                 async_answer_0(callid, ENOMEM);
     583                ipc_answer_0(callid, ENOMEM);
    574584                free(setup_packet);
    575585                free(data_buffer);
     
    586596
    587597        if (rc != EOK) {
    588                 async_answer_0(callid, rc);
     598                ipc_answer_0(callid, rc);
    589599                async_transaction_destroy(trans);
    590600        }
     
    599609
    600610        if (!usb_iface->control_read) {
    601                 async_answer_0(callid, ENOTSUP);
    602                 return;
    603         }
    604 
     611                ipc_answer_0(callid, ENOTSUP);
     612                return;
     613        }
     614
     615        size_t data_len = DEV_IPC_GET_ARG3(*call);
    605616        usb_target_t target = {
    606617                .address = DEV_IPC_GET_ARG1(*call),
     
    612623        void *setup_packet = NULL;
    613624        size_t setup_packet_len = 0;
    614         size_t data_len = 0;
    615625
    616626        rc = async_data_write_accept(&setup_packet, false,
    617627            1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
    618628        if (rc != EOK) {
    619                 async_answer_0(callid, rc);
    620                 return;
    621         }
    622 
    623         ipc_callid_t data_callid;
    624         if (!async_data_read_receive(&data_callid, &data_len)) {
    625                 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);
    626636                free(setup_packet);
    627637                return;
    628638        }
    629 
    630         async_transaction_t *trans = async_transaction_create(callid);
    631         if (trans == NULL) {
    632                 async_answer_0(callid, ENOMEM);
    633                 free(setup_packet);
    634                 return;
    635         }
    636         trans->data_caller = data_callid;
    637639        trans->setup_packet = setup_packet;
    638640        trans->size = data_len;
    639641        trans->buffer = malloc(data_len);
    640642        if (trans->buffer == NULL) {
    641                 async_answer_0(callid, ENOMEM);
     643                ipc_answer_0(callid, ENOMEM);
    642644                async_transaction_destroy(trans);
    643645                return;
     
    650652
    651653        if (rc != EOK) {
    652                 async_answer_0(callid, rc);
     654                ipc_answer_0(callid, rc);
    653655                async_transaction_destroy(trans);
    654656        }
Note: See TracChangeset for help on using the changeset viewer.