Changeset 02fc5c4 in mainline for uspace/lib/usbdev/src/pipesio.c


Ignore:
Timestamp:
2011-11-25T17:41:23Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
095bddfc
Parents:
56bdd9a4
Message:

usbhc: Export IPC wrapper instead of IPC call numbers.

Hide IPC protocol in one file, instead of multiple client implementations.
Rename 'find_by_address' ⇒ 'get_handle'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/src/pipesio.c

    r56bdd9a4 r02fc5c4  
    7070            return ENOTSUP;
    7171
    72         const usb_target_t target =
    73             {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};
    74        
    7572        /* Ensure serialization over the phone. */
    7673        pipe_start_transaction(pipe);
    7774        async_exch_t *exch = async_exchange_begin(pipe->hc_sess);
    78        
    79         /*
    80          * Make call identifying target USB device and type of transfer.
    81          */
    82         aid_t opening_request = async_send_2(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    83             IPC_M_USBHC_READ, target.packed, NULL);
    84        
    85         if (opening_request == 0) {
    86                 async_exchange_end(exch);
     75        if (!exch) {
    8776                pipe_end_transaction(pipe);
    8877                return ENOMEM;
    8978        }
    90        
    91         /*
    92          * Retrieve the data.
    93          */
    94         ipc_call_t data_request_call;
    95         aid_t data_request = async_data_read(exch, buffer, size,
    96             &data_request_call);
    97        
    98         /*
    99          * Since now on, someone else might access the backing phone
    100          * without breaking the transfer IPC protocol.
    101          */
     79
     80        const int ret = usbhc_read(exch, pipe->wire->address, pipe->endpoint_no,
     81            0, buffer, size, size_transfered);
    10282        async_exchange_end(exch);
    10383        pipe_end_transaction(pipe);
    104        
    105         if (data_request == 0) {
    106                 /*
    107                  * FIXME:
    108                  * How to let the other side know that we want to abort?
    109                  */
    110                 async_wait_for(opening_request, NULL);
    111                 return ENOMEM;
    112         }
    113        
    114         /*
    115          * Wait for the answer.
    116          */
    117         sysarg_t data_request_rc;
    118         sysarg_t opening_request_rc;
    119         async_wait_for(data_request, &data_request_rc);
    120         async_wait_for(opening_request, &opening_request_rc);
    121        
    122         if (data_request_rc != EOK) {
    123                 /* Prefer the return code of the opening request. */
    124                 if (opening_request_rc != EOK) {
    125                         return (int) opening_request_rc;
    126                 } else {
    127                         return (int) data_request_rc;
    128                 }
    129         }
    130         if (opening_request_rc != EOK) {
    131                 return (int) opening_request_rc;
    132         }
    133        
    134         *size_transfered = IPC_GET_ARG2(data_request_call);
    135        
    136         return EOK;
     84        return ret;
    13785}
    13886
     
    209157            return ENOTSUP;
    210158
    211         const usb_target_t target =
    212             {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};
    213 
    214159        /* Ensure serialization over the phone. */
    215160        pipe_start_transaction(pipe);
    216161        async_exch_t *exch = async_exchange_begin(pipe->hc_sess);
    217        
    218         /*
    219          * Make call identifying target USB device and type of transfer.
    220          */
    221         aid_t opening_request = async_send_3(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    222             IPC_M_USBHC_WRITE, target.packed, size, NULL);
    223        
    224         if (opening_request == 0) {
    225                 async_exchange_end(exch);
     162        if (!exch) {
    226163                pipe_end_transaction(pipe);
    227164                return ENOMEM;
    228165        }
    229        
    230         /*
    231          * Send the data.
    232          */
    233         int rc = async_data_write_start(exch, buffer, size);
    234        
    235         /*
    236          * Since now on, someone else might access the backing phone
    237          * without breaking the transfer IPC protocol.
    238          */
     166        const int ret =
     167            usbhc_write(exch, pipe->wire->address, pipe->endpoint_no,
     168            0, buffer, size);
    239169        async_exchange_end(exch);
    240170        pipe_end_transaction(pipe);
    241        
    242         if (rc != EOK) {
    243                 async_wait_for(opening_request, NULL);
    244                 return rc;
    245         }
    246        
    247         /*
    248          * Wait for the answer.
    249          */
    250         sysarg_t opening_request_rc;
    251         async_wait_for(opening_request, &opening_request_rc);
    252        
    253         return (int) opening_request_rc;
     171        return ret;
    254172}
    255173
     
    334252        pipe_start_transaction(pipe);
    335253
    336         const usb_target_t target =
    337             {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};
    338 
    339254        assert(setup_buffer_size == 8);
    340255        uint64_t setup_packet;
    341256        memcpy(&setup_packet, setup_buffer, 8);
    342         /*
    343          * Make call identifying target USB device and control transfer type.
    344          */
     257
    345258        async_exch_t *exch = async_exchange_begin(pipe->hc_sess);
    346         aid_t opening_request = async_send_4(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    347             IPC_M_USBHC_READ, target.packed,
    348             (setup_packet & UINT32_MAX), (setup_packet >> 32), NULL);
    349 
    350         if (opening_request == 0) {
    351                 async_exchange_end(exch);
     259        if (!exch) {
     260                pipe_end_transaction(pipe);
    352261                return ENOMEM;
    353262        }
    354263
    355         /*
    356          * Retrieve the data.
    357          */
    358         ipc_call_t data_request_call;
    359         aid_t data_request = async_data_read(exch, data_buffer,
    360             data_buffer_size, &data_request_call);
    361        
    362         /*
    363          * Since now on, someone else might access the backing phone
    364          * without breaking the transfer IPC protocol.
    365          */
     264        const int ret = usbhc_read(exch, pipe->wire->address, pipe->endpoint_no,
     265            setup_packet, data_buffer, data_buffer_size, data_transfered_size);
    366266        async_exchange_end(exch);
    367267        pipe_end_transaction(pipe);
    368        
    369         if (data_request == 0) {
    370                 async_wait_for(opening_request, NULL);
    371                 return ENOMEM;
    372         }
    373 
    374         /*
    375          * Wait for the answer.
    376          */
    377         sysarg_t data_request_rc;
    378         sysarg_t opening_request_rc;
    379         async_wait_for(data_request, &data_request_rc);
    380         async_wait_for(opening_request, &opening_request_rc);
    381 
    382         if (data_request_rc != EOK) {
    383                 /* Prefer the return code of the opening request. */
    384                 if (opening_request_rc != EOK) {
    385                         return (int) opening_request_rc;
    386                 } else {
    387                         return (int) data_request_rc;
    388                 }
    389         }
    390         if (opening_request_rc != EOK) {
    391                 return (int) opening_request_rc;
    392         }
    393 
    394         *data_transfered_size = IPC_GET_ARG2(data_request_call);
    395 
    396         return EOK;
     268        return ret;
    397269}
    398270
     
    475347        pipe_start_transaction(pipe);
    476348
    477         const usb_target_t target =
    478             {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};
    479349        assert(setup_buffer_size == 8);
    480350        uint64_t setup_packet;
    481351        memcpy(&setup_packet, setup_buffer, 8);
    482352
    483         /*
    484          * Make call identifying target USB device and control transfer type.
    485          */
     353        /* Make call identifying target USB device and control transfer type. */
    486354        async_exch_t *exch = async_exchange_begin(pipe->hc_sess);
    487         aid_t opening_request = async_send_5(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    488             IPC_M_USBHC_WRITE, target.packed, data_buffer_size,
    489             (setup_packet & UINT32_MAX), (setup_packet >> 32), NULL);
    490        
    491         if (opening_request == 0) {
    492                 async_exchange_end(exch);
     355        if (!exch) {
    493356                pipe_end_transaction(pipe);
    494357                return ENOMEM;
    495358        }
    496 
    497         /*
    498          * Send the data (if any).
    499          */
    500         if (data_buffer_size > 0) {
    501                 int rc = async_data_write_start(exch, data_buffer, data_buffer_size);
    502                
    503                 /* All data sent, pipe can be released. */
    504                 async_exchange_end(exch);
    505                 pipe_end_transaction(pipe);
    506        
    507                 if (rc != EOK) {
    508                         async_wait_for(opening_request, NULL);
    509                         return rc;
    510                 }
    511         } else {
    512                 /* No data to send, we can release the pipe for others. */
    513                 async_exchange_end(exch);
    514                 pipe_end_transaction(pipe);
    515         }
    516        
    517         /*
    518          * Wait for the answer.
    519          */
    520         sysarg_t opening_request_rc;
    521         async_wait_for(opening_request, &opening_request_rc);
    522 
    523         return (int) opening_request_rc;
     359        const int ret =
     360            usbhc_write(exch, pipe->wire->address, pipe->endpoint_no,
     361            setup_packet, data_buffer, data_buffer_size);
     362        async_exchange_end(exch);
     363        pipe_end_transaction(pipe);
     364        return ret;
    524365}
    525366
Note: See TracChangeset for help on using the changeset viewer.