Changeset 501e5df in mainline for uspace/lib/usb/src/pipesio.c


Ignore:
Timestamp:
2011-04-09T20:56:50Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ba038f4
Parents:
8790650 (diff), 709e868 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Development changes

File:
1 edited

Legend:

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

    r8790650 r501e5df  
    4949#include <assert.h>
    5050#include <usbhc_iface.h>
     51#include "pipepriv.h"
    5152
    5253/** Request an in transfer, no checking of input parameters.
     
    7879        }
    7980
     81        /* Ensure serialization over the phone. */
     82        pipe_start_transaction(pipe);
     83
    8084        /*
    8185         * Make call identifying target USB device and type of transfer.
    8286         */
    83         aid_t opening_request = async_send_4(pipe->hc_phone,
     87        aid_t opening_request = async_send_3(pipe->hc_phone,
    8488            DEV_IFACE_ID(USBHC_DEV_IFACE), ipc_method,
    8589            pipe->wire->address, pipe->endpoint_no,
    86             pipe->max_packet_size,
    8790            NULL);
    8891        if (opening_request == 0) {
     92                pipe_end_transaction(pipe);
    8993                return ENOMEM;
    9094        }
     
    96100        aid_t data_request = async_data_read(pipe->hc_phone, buffer, size,
    97101            &data_request_call);
     102
     103        /*
     104         * Since now on, someone else might access the backing phone
     105         * without breaking the transfer IPC protocol.
     106         */
     107        pipe_end_transaction(pipe);
    98108
    99109        if (data_request == 0) {
     
    146156
    147157        if (buffer == NULL) {
    148                         return EINVAL;
     158                return EINVAL;
    149159        }
    150160
    151161        if (size == 0) {
    152162                return EINVAL;
    153         }
    154 
    155         if (!usb_pipe_is_session_started(pipe)) {
    156                 return EBADF;
    157163        }
    158164
     
    165171        }
    166172
     173        int rc;
     174        rc = pipe_add_ref(pipe);
     175        if (rc != EOK) {
     176                return rc;
     177        }
     178
     179
    167180        size_t act_size = 0;
    168         int rc;
    169181
    170182        rc = usb_pipe_read_no_checks(pipe, buffer, size, &act_size);
     183
     184        pipe_drop_ref(pipe);
     185
    171186        if (rc != EOK) {
    172187                return rc;
     
    210225        }
    211226
     227        /* Ensure serialization over the phone. */
     228        pipe_start_transaction(pipe);
     229
    212230        /*
    213231         * Make call identifying target USB device and type of transfer.
    214232         */
    215         aid_t opening_request = async_send_4(pipe->hc_phone,
     233        aid_t opening_request = async_send_3(pipe->hc_phone,
    216234            DEV_IFACE_ID(USBHC_DEV_IFACE), ipc_method,
    217235            pipe->wire->address, pipe->endpoint_no,
    218             pipe->max_packet_size,
    219236            NULL);
    220237        if (opening_request == 0) {
     238                pipe_end_transaction(pipe);
    221239                return ENOMEM;
    222240        }
     
    226244         */
    227245        int rc = async_data_write_start(pipe->hc_phone, buffer, size);
     246
     247        /*
     248         * Since now on, someone else might access the backing phone
     249         * without breaking the transfer IPC protocol.
     250         */
     251        pipe_end_transaction(pipe);
     252
    228253        if (rc != EOK) {
    229254                async_wait_for(opening_request, NULL);
     
    260285        }
    261286
    262         if (!usb_pipe_is_session_started(pipe)) {
    263                 return EBADF;
    264         }
    265 
    266287        if (pipe->direction != USB_DIRECTION_OUT) {
    267288                return EBADF;
     
    272293        }
    273294
    274         int rc = usb_pipe_write_no_check(pipe, buffer, size);
     295        int rc;
     296
     297        rc = pipe_add_ref(pipe);
     298        if (rc != EOK) {
     299                return rc;
     300        }
     301
     302        rc = usb_pipe_write_no_check(pipe, buffer, size);
     303
     304        pipe_drop_ref(pipe);
    275305
    276306        return rc;
     
    293323    void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
    294324{
     325        /* Ensure serialization over the phone. */
     326        pipe_start_transaction(pipe);
     327
    295328        /*
    296329         * Make call identifying target USB device and control transfer type.
    297330         */
    298         aid_t opening_request = async_send_4(pipe->hc_phone,
     331        aid_t opening_request = async_send_3(pipe->hc_phone,
    299332            DEV_IFACE_ID(USBHC_DEV_IFACE), IPC_M_USBHC_CONTROL_READ,
    300333            pipe->wire->address, pipe->endpoint_no,
    301             pipe->max_packet_size,
    302334            NULL);
    303335        if (opening_request == 0) {
     
    311343            setup_buffer, setup_buffer_size);
    312344        if (rc != EOK) {
     345                pipe_end_transaction(pipe);
    313346                async_wait_for(opening_request, NULL);
    314347                return rc;
     
    322355            data_buffer, data_buffer_size,
    323356            &data_request_call);
     357
     358        /*
     359         * Since now on, someone else might access the backing phone
     360         * without breaking the transfer IPC protocol.
     361         */
     362        pipe_end_transaction(pipe);
     363
     364
    324365        if (data_request == 0) {
    325366                async_wait_for(opening_request, NULL);
     
    379420        }
    380421
    381         if (!usb_pipe_is_session_started(pipe)) {
    382                 return EBADF;
    383         }
    384 
    385422        if ((pipe->direction != USB_DIRECTION_BOTH)
    386423            || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
     
    388425        }
    389426
     427        int rc;
     428
     429        rc = pipe_add_ref(pipe);
     430        if (rc != EOK) {
     431                return rc;
     432        }
     433
    390434        size_t act_size = 0;
    391         int rc = usb_pipe_control_read_no_check(pipe,
     435        rc = usb_pipe_control_read_no_check(pipe,
    392436            setup_buffer, setup_buffer_size,
    393437            data_buffer, data_buffer_size, &act_size);
     438
     439        pipe_drop_ref(pipe);
    394440
    395441        if (rc != EOK) {
     
    418464    void *data_buffer, size_t data_buffer_size)
    419465{
     466        /* Ensure serialization over the phone. */
     467        pipe_start_transaction(pipe);
     468
    420469        /*
    421470         * Make call identifying target USB device and control transfer type.
    422471         */
    423         aid_t opening_request = async_send_5(pipe->hc_phone,
     472        aid_t opening_request = async_send_4(pipe->hc_phone,
    424473            DEV_IFACE_ID(USBHC_DEV_IFACE), IPC_M_USBHC_CONTROL_WRITE,
    425474            pipe->wire->address, pipe->endpoint_no,
    426475            data_buffer_size,
    427             pipe->max_packet_size,
    428476            NULL);
    429477        if (opening_request == 0) {
     478                pipe_end_transaction(pipe);
    430479                return ENOMEM;
    431480        }
     
    437486            setup_buffer, setup_buffer_size);
    438487        if (rc != EOK) {
     488                pipe_end_transaction(pipe);
    439489                async_wait_for(opening_request, NULL);
    440490                return rc;
     
    447497                rc = async_data_write_start(pipe->hc_phone,
    448498                    data_buffer, data_buffer_size);
     499
     500                /* All data sent, pipe can be released. */
     501                pipe_end_transaction(pipe);
     502
    449503                if (rc != EOK) {
    450504                        async_wait_for(opening_request, NULL);
    451505                        return rc;
    452506                }
     507        } else {
     508                /* No data to send, we can release the pipe for others. */
     509                pipe_end_transaction(pipe);
    453510        }
    454511
     
    491548        }
    492549
    493         if (!usb_pipe_is_session_started(pipe)) {
    494                 return EBADF;
    495         }
    496 
    497550        if ((pipe->direction != USB_DIRECTION_BOTH)
    498551            || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
     
    500553        }
    501554
    502         int rc = usb_pipe_control_write_no_check(pipe,
     555        int rc;
     556
     557        rc = pipe_add_ref(pipe);
     558        if (rc != EOK) {
     559                return rc;
     560        }
     561
     562        rc = usb_pipe_control_write_no_check(pipe,
    503563            setup_buffer, setup_buffer_size, data_buffer, data_buffer_size);
     564
     565        pipe_drop_ref(pipe);
    504566
    505567        return rc;
Note: See TracChangeset for help on using the changeset viewer.