Changeset 02fc5c4 in mainline for uspace/lib/usbdev/src


Ignore:
Timestamp:
2011-11-25T17:41:23Z (14 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'

Location:
uspace/lib/usbdev/src
Files:
3 edited

Legend:

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

    r56bdd9a4 r02fc5c4  
    7676{
    7777        CHECK_CONNECTION(connection);
    78        
     78
    7979        async_exch_t *exch = async_exchange_begin(connection->hc_sess);
    80        
    81         sysarg_t address;
    82         int rc = async_req_4_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    83             IPC_M_USBHC_REQUEST_ADDRESS, preferred, strict, speed, &address);
    84        
     80        if (!exch)
     81                return (usb_address_t)ENOMEM;
     82
     83        usb_address_t address = preferred;
     84        const int ret = usbhc_request_address(exch, &address, strict, speed);
     85
    8586        async_exchange_end(exch);
    86        
    87         if (rc != EOK)
    88                 return (usb_address_t) rc;
    89        
    90         return (usb_address_t) address;
     87        return ret == EOK ? address : ret;
    9188}
    9289
     
    9794 * @return Error code.
    9895 */
    99 int usb_hc_register_device(usb_hc_connection_t * connection,
     96int usb_hc_register_device(usb_hc_connection_t *connection,
    10097    const usb_hub_attached_device_t *attached_device)
    10198{
    10299        CHECK_CONNECTION(connection);
    103        
    104         if (attached_device == NULL)
    105                 return EBADMEM;
    106        
     100        if (attached_device == NULL || attached_device->fun == NULL)
     101                return EINVAL;
     102
    107103        async_exch_t *exch = async_exchange_begin(connection->hc_sess);
    108         int rc = async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    109             IPC_M_USBHC_BIND_ADDRESS,
     104        if (!exch)
     105                return ENOMEM;
     106        const int ret = usbhc_bind_address(exch,
    110107            attached_device->address, attached_device->fun->handle);
    111108        async_exchange_end(exch);
    112        
    113         return rc;
     109
     110        return ret;
    114111}
    115112
     
    124121{
    125122        CHECK_CONNECTION(connection);
    126        
     123
    127124        async_exch_t *exch = async_exchange_begin(connection->hc_sess);
    128         int rc = async_req_2_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    129             IPC_M_USBHC_RELEASE_ADDRESS, address);
     125        if (!exch)
     126                return ENOMEM;
     127        const int ret = usbhc_release_address(exch, address);
    130128        async_exchange_end(exch);
    131        
    132         return rc;
     129
     130        return ret;
    133131}
    134132
  • uspace/lib/usbdev/src/pipesinit.c

    r56bdd9a4 r02fc5c4  
    405405        }
    406406
    407 #define TRY_LOOP(attempt_var) \
    408         for (attempt_var = 0; attempt_var < 3; attempt_var++)
    409 
    410         size_t failed_attempts;
    411         int rc;
    412407
    413408        usb_pipe_start_long_transfer(pipe);
     
    415410        uint8_t dev_descr_start[CTRL_PIPE_MIN_PACKET_SIZE];
    416411        size_t transferred_size;
    417         TRY_LOOP(failed_attempts) {
     412        int rc;
     413        for (size_t attempt_var = 0; attempt_var < 3; ++attempt_var) {
    418414                rc = usb_request_get_descriptor(pipe, USB_REQUEST_TYPE_STANDARD,
    419415                    USB_REQUEST_RECIPIENT_DEVICE, USB_DESCTYPE_DEVICE,
     
    450446{
    451447        assert(pipe);
     448        assert(pipe->wire);
    452449        assert(hc_connection);
    453450
    454451        if (!usb_hc_connection_is_opened(hc_connection))
    455452                return EBADF;
    456 
    457         const usb_target_t target =
    458             {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};
    459 #define _PACK2(high, low) (((high & 0xffff) << 16) | (low & 0xffff))
    460 
    461453        async_exch_t *exch = async_exchange_begin(hc_connection->hc_sess);
    462         int rc = async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    463             IPC_M_USBHC_REGISTER_ENDPOINT, target.packed,
    464             _PACK2(pipe->transfer_type, pipe->direction),
    465             _PACK2(pipe->max_packet_size, interval));
     454        if (!exch)
     455                return ENOMEM;
     456        const int ret = usbhc_register_endpoint(exch,
     457            pipe->wire->address, pipe->endpoint_no, pipe->transfer_type,
     458            pipe->direction, pipe->max_packet_size, interval);
     459
    466460        async_exchange_end(exch);
    467 
    468 #undef _PACK2
    469         return rc;
     461        return ret;
    470462}
    471463
     
    482474        assert(pipe->wire);
    483475        assert(hc_connection);
    484        
     476
    485477        if (!usb_hc_connection_is_opened(hc_connection))
    486478                return EBADF;
    487        
     479
    488480        async_exch_t *exch = async_exchange_begin(hc_connection->hc_sess);
    489         int rc = async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    490             IPC_M_USBHC_UNREGISTER_ENDPOINT,
     481        if (!exch)
     482                return ENOMEM;
     483        const int ret = usbhc_unregister_endpoint(exch,
    491484            pipe->wire->address, pipe->endpoint_no, pipe->direction);
    492485        async_exchange_end(exch);
    493        
    494         return rc;
     486
     487        return ret;
    495488}
    496489
  • 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.