Changeset 79ae36dd in mainline for uspace/lib/usbdev/src/pipesio.c


Ignore:
Timestamp:
2011-06-08T19:01:55Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eff68e
Parents:
764d71e
Message:

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
File:
1 edited

Legend:

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

    r764d71e r79ae36dd  
    4444 * obviously).
    4545 */
     46
    4647#include <usb/usb.h>
    4748#include <usb/dev/pipes.h>
     
    5051#include <usbhc_iface.h>
    5152#include <usb/dev/request.h>
     53#include <async.h>
    5254#include "pipepriv.h"
    5355
     
    7981                        return ENOTSUP;
    8082        }
    81 
     83       
    8284        /* Ensure serialization over the phone. */
    8385        pipe_start_transaction(pipe);
    84 
     86        async_exch_t *exch = async_exchange_begin(pipe->hc_sess);
     87       
    8588        /*
    8689         * Make call identifying target USB device and type of transfer.
    8790         */
    88         aid_t opening_request = async_send_3(pipe->hc_phone,
    89             DEV_IFACE_ID(USBHC_DEV_IFACE), ipc_method,
    90             pipe->wire->address, pipe->endpoint_no,
    91             NULL);
     91        aid_t opening_request = async_send_3(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     92            ipc_method, pipe->wire->address, pipe->endpoint_no, NULL);
     93       
    9294        if (opening_request == 0) {
     95                async_exchange_end(exch);
    9396                pipe_end_transaction(pipe);
    9497                return ENOMEM;
    9598        }
    96 
     99       
    97100        /*
    98101         * Retrieve the data.
    99102         */
    100103        ipc_call_t data_request_call;
    101         aid_t data_request = async_data_read(pipe->hc_phone, buffer, size,
     104        aid_t data_request = async_data_read(exch, buffer, size,
    102105            &data_request_call);
    103 
     106       
    104107        /*
    105108         * Since now on, someone else might access the backing phone
    106109         * without breaking the transfer IPC protocol.
    107110         */
     111        async_exchange_end(exch);
    108112        pipe_end_transaction(pipe);
    109 
     113       
    110114        if (data_request == 0) {
    111115                /*
     
    116120                return ENOMEM;
    117121        }
    118 
     122       
    119123        /*
    120124         * Wait for the answer.
     
    124128        async_wait_for(data_request, &data_request_rc);
    125129        async_wait_for(opening_request, &opening_request_rc);
    126 
     130       
    127131        if (data_request_rc != EOK) {
    128132                /* Prefer the return code of the opening request. */
     
    136140                return (int) opening_request_rc;
    137141        }
    138 
     142       
    139143        *size_transfered = IPC_GET_ARG2(data_request_call);
    140 
     144       
    141145        return EOK;
    142146}
     
    228232        /* Ensure serialization over the phone. */
    229233        pipe_start_transaction(pipe);
    230 
     234        async_exch_t *exch = async_exchange_begin(pipe->hc_sess);
     235       
    231236        /*
    232237         * Make call identifying target USB device and type of transfer.
    233238         */
    234         aid_t opening_request = async_send_3(pipe->hc_phone,
    235             DEV_IFACE_ID(USBHC_DEV_IFACE), ipc_method,
    236             pipe->wire->address, pipe->endpoint_no,
    237             NULL);
     239        aid_t opening_request = async_send_3(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     240            ipc_method, pipe->wire->address, pipe->endpoint_no, NULL);
     241       
    238242        if (opening_request == 0) {
     243                async_exchange_end(exch);
    239244                pipe_end_transaction(pipe);
    240245                return ENOMEM;
    241246        }
    242 
     247       
    243248        /*
    244249         * Send the data.
    245250         */
    246         int rc = async_data_write_start(pipe->hc_phone, buffer, size);
    247 
     251        int rc = async_data_write_start(exch, buffer, size);
     252       
    248253        /*
    249254         * Since now on, someone else might access the backing phone
    250255         * without breaking the transfer IPC protocol.
    251256         */
     257        async_exchange_end(exch);
    252258        pipe_end_transaction(pipe);
    253 
     259       
    254260        if (rc != EOK) {
    255261                async_wait_for(opening_request, NULL);
    256262                return rc;
    257263        }
    258 
     264       
    259265        /*
    260266         * Wait for the answer.
     
    262268        sysarg_t opening_request_rc;
    263269        async_wait_for(opening_request, &opening_request_rc);
    264 
     270       
    265271        return (int) opening_request_rc;
    266272}
     
    349355         * Make call identifying target USB device and control transfer type.
    350356         */
    351         aid_t opening_request = async_send_3(pipe->hc_phone,
    352             DEV_IFACE_ID(USBHC_DEV_IFACE), IPC_M_USBHC_CONTROL_READ,
    353             pipe->wire->address, pipe->endpoint_no,
     357        async_exch_t *exch = async_exchange_begin(pipe->hc_sess);
     358        aid_t opening_request = async_send_3(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     359            IPC_M_USBHC_CONTROL_READ, pipe->wire->address, pipe->endpoint_no,
    354360            NULL);
     361       
    355362        if (opening_request == 0) {
     363                async_exchange_end(exch);
    356364                return ENOMEM;
    357365        }
    358 
     366       
    359367        /*
    360368         * Send the setup packet.
    361369         */
    362         int rc = async_data_write_start(pipe->hc_phone,
    363             setup_buffer, setup_buffer_size);
    364         if (rc != EOK) {
     370        int rc = async_data_write_start(exch, setup_buffer, setup_buffer_size);
     371        if (rc != EOK) {
     372                async_exchange_end(exch);
    365373                pipe_end_transaction(pipe);
    366374                async_wait_for(opening_request, NULL);
    367375                return rc;
    368376        }
    369 
     377       
    370378        /*
    371379         * Retrieve the data.
    372380         */
    373381        ipc_call_t data_request_call;
    374         aid_t data_request = async_data_read(pipe->hc_phone,
    375             data_buffer, data_buffer_size,
    376             &data_request_call);
    377 
     382        aid_t data_request = async_data_read(exch, data_buffer,
     383            data_buffer_size, &data_request_call);
     384       
    378385        /*
    379386         * Since now on, someone else might access the backing phone
    380387         * without breaking the transfer IPC protocol.
    381388         */
     389        async_exchange_end(exch);
    382390        pipe_end_transaction(pipe);
    383 
    384 
     391       
    385392        if (data_request == 0) {
    386393                async_wait_for(opening_request, NULL);
     
    494501         * Make call identifying target USB device and control transfer type.
    495502         */
    496         aid_t opening_request = async_send_4(pipe->hc_phone,
    497             DEV_IFACE_ID(USBHC_DEV_IFACE), IPC_M_USBHC_CONTROL_WRITE,
    498             pipe->wire->address, pipe->endpoint_no,
    499             data_buffer_size,
    500             NULL);
     503        async_exch_t *exch = async_exchange_begin(pipe->hc_sess);
     504        aid_t opening_request = async_send_4(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     505            IPC_M_USBHC_CONTROL_WRITE, pipe->wire->address, pipe->endpoint_no,
     506            data_buffer_size, NULL);
     507       
    501508        if (opening_request == 0) {
     509                async_exchange_end(exch);
    502510                pipe_end_transaction(pipe);
    503511                return ENOMEM;
    504512        }
    505 
     513       
    506514        /*
    507515         * Send the setup packet.
    508516         */
    509         int rc = async_data_write_start(pipe->hc_phone,
    510             setup_buffer, setup_buffer_size);
    511         if (rc != EOK) {
     517        int rc = async_data_write_start(exch, setup_buffer, setup_buffer_size);
     518        if (rc != EOK) {
     519                async_exchange_end(exch);
    512520                pipe_end_transaction(pipe);
    513521                async_wait_for(opening_request, NULL);
    514522                return rc;
    515523        }
    516 
     524       
    517525        /*
    518526         * Send the data (if any).
    519527         */
    520528        if (data_buffer_size > 0) {
    521                 rc = async_data_write_start(pipe->hc_phone,
    522                     data_buffer, data_buffer_size);
    523 
     529                rc = async_data_write_start(exch, data_buffer, data_buffer_size);
     530               
    524531                /* All data sent, pipe can be released. */
     532                async_exchange_end(exch);
    525533                pipe_end_transaction(pipe);
    526 
     534       
    527535                if (rc != EOK) {
    528536                        async_wait_for(opening_request, NULL);
     
    531539        } else {
    532540                /* No data to send, we can release the pipe for others. */
     541                async_exchange_end(exch);
    533542                pipe_end_transaction(pipe);
    534543        }
    535 
     544       
    536545        /*
    537546         * Wait for the answer.
Note: See TracChangeset for help on using the changeset viewer.