Changeset 0a6fa9f in mainline for uspace/lib/usb/src/usbdrv.c


Ignore:
Timestamp:
2011-02-10T22:14:38Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1e64b250
Parents:
8bf1eeb
Message:

Get buffer replaced with asynchronous data read

The GET_BUFFER request from the USB HC interface (of DDF) was replaced
by using asynchronous version of IPC_M_DATA_READ.

Still needs to be done:

  • check error handling of protocol problems
  • remove the get_buffer callback from remote part of the interface completely
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/usbdrv.c

    r8bf1eeb r0a6fa9f  
    4949        /** Storage for actual number of bytes transferred. */
    5050        size_t *size_transferred;
    51         /** Initial call replay data. */
     51        /** Initial call reply data. */
    5252        ipc_call_t reply;
    5353        /** Initial call identifier. */
    5454        aid_t request;
     55        /** Reply data for data read call. */
     56        ipc_call_t read_reply;
     57        /** Data read call identifier. */
     58        aid_t read_request;
    5559} transfer_info_t;
    5660
     
    140144
    141145        if (rc != EOK) {
    142                 printf("usb_drv_get_my_address over %d failed: %s\n", phone, str_error(rc));
    143146                return rc;
    144147        }
     
    250253        }
    251254
     255        transfer->read_request = 0;
    252256        transfer->size_transferred = NULL;
    253257        transfer->buffer = NULL;
     
    315319        }
    316320
     321        transfer->read_request = 0;
    317322        transfer->size_transferred = actual_size;
    318323        transfer->buffer = buffer;
     
    327332            &transfer->reply);
    328333
     334        if (buffer != NULL) {
     335                transfer->read_request = async_data_read(phone, buffer, size,
     336                    &transfer->read_reply);
     337        }
     338
    329339        *handle = (usb_handle_t) transfer;
    330340
     
    332342}
    333343
    334 /** Read buffer from HCD.
    335  *
    336  * @param phone Opened phone to HCD.
    337  * @param hash Buffer hash (obtained after completing IN transaction).
    338  * @param buffer Buffer where to store data data.
    339  * @param size Buffer size.
    340  * @param actual_size Storage where actual number of bytes transferred will
    341  *      be stored.
    342  * @return Error status.
    343  */
    344 static int read_buffer_in(int phone, sysarg_t hash,
    345     void *buffer, size_t size, size_t *actual_size)
    346 {
    347         ipc_call_t answer_data;
    348         sysarg_t answer_rc;
    349         aid_t req;
    350         int rc;
    351 
    352         req = async_send_2(phone,
    353             DEV_IFACE_ID(USBHC_DEV_IFACE),
    354             IPC_M_USBHC_GET_BUFFER,
    355             hash,
    356             &answer_data);
    357 
    358         rc = async_data_read_start(phone, buffer, size);
    359         if (rc != EOK) {
    360                 async_wait_for(req, NULL);
    361                 return EINVAL;
    362         }
    363 
    364         async_wait_for(req, &answer_rc);
    365         rc = (int)answer_rc;
    366 
    367         if (rc != EOK) {
    368                 return rc;
    369         }
    370 
    371         *actual_size = IPC_GET_ARG1(answer_data);
    372 
    373         return EOK;
    374 }
    375344
    376345/** Blocks caller until given USB transaction is finished.
     
    395364
    396365        sysarg_t answer_rc;
    397         async_wait_for(transfer->request, &answer_rc);
    398 
    399         if (answer_rc != EOK) {
    400                 rc = (int) answer_rc;
    401                 goto leave;
    402         }
    403366
    404367        /*
     
    406369         */
    407370        if ((transfer->buffer != NULL) && (transfer->size > 0)) {
    408                 /*
    409                  * The buffer hash identifies the data on the server
    410                  * side.
    411                  * We will use it when actually reading-in the data.
    412                  */
    413                 sysarg_t buffer_hash = IPC_GET_ARG1(transfer->reply);
    414                 if (buffer_hash == 0) {
    415                         rc = ENOENT;
     371                async_wait_for(transfer->read_request, &answer_rc);
     372
     373                if (answer_rc != EOK) {
     374                        rc = (int) answer_rc;
    416375                        goto leave;
    417376                }
    418377
    419                 size_t actual_size;
    420                 rc = read_buffer_in(transfer->phone, buffer_hash,
    421                     transfer->buffer, transfer->size, &actual_size);
    422 
    423                 if (rc != EOK) {
    424                         goto leave;
     378                if (transfer->size_transferred != NULL) {
     379                        *(transfer->size_transferred)
     380                            = IPC_GET_ARG2(transfer->read_reply);
    425381                }
    426 
    427                 if (transfer->size_transferred) {
    428                         *(transfer->size_transferred) = actual_size;
    429                 }
     382        }
     383
     384        async_wait_for(transfer->request, &answer_rc);
     385
     386        if (answer_rc != EOK) {
     387                rc = (int) answer_rc;
     388                goto leave;
    430389        }
    431390
     
    515474        }
    516475
     476        transfer->read_request = 0;
    517477        transfer->size_transferred = NULL;
    518478        transfer->buffer = NULL;
     
    620580        }
    621581
     582        transfer->read_request = async_data_read(phone, buffer, buffer_size,
     583            &transfer->read_reply);
     584
    622585        *handle = (usb_handle_t) transfer;
    623586
Note: See TracChangeset for help on using the changeset viewer.