Ignore:
Timestamp:
2010-11-03T15:05:41Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d70a463
Parents:
af894a21
Message:

Old code removal

Completely removed old methods for communicating with HCD (the ones
that used callback phones). Now only methods using the async framework
are available.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hw/bus/usb/hcd/virtual/connhost.c

    raf894a21 r1d1f894  
    4141#include "hc.h"
    4242
    43 static usb_transaction_handle_t g_handle_seed = 1;
    44 static usb_transaction_handle_t create_transaction_handle(int phone)
    45 {
    46         return g_handle_seed++;
    47 }
    48 
    4943typedef struct {
    50         int phone;
    51         usb_transaction_handle_t handle;
    52 } transaction_details_t;
    53 
    54 
    55 /** Callback for outgoing transaction.
    56  */
    57 static void out_callback(void * buffer, size_t len, usb_transaction_outcome_t outcome, void * arg)
    58 {
    59         dprintf(2, "out_callback(buffer, %u, %d, %p)", len, outcome, arg);
    60        
    61         transaction_details_t * trans = (transaction_details_t *)arg;
    62        
    63         async_msg_2(trans->phone, IPC_M_USB_HCD_DATA_SENT, trans->handle, outcome);
     44        ipc_callid_t caller;
     45        void *buffer;
     46        size_t size;
     47} async_transaction_t;
     48
     49static void async_out_callback(void * buffer, size_t len,
     50    usb_transaction_outcome_t outcome, void * arg)
     51{
     52        async_transaction_t * trans = (async_transaction_t *)arg;
     53       
     54        dprintf(2, "async_out_callback(buffer, %u, %d, %p) -> %x",
     55            len, outcome, arg, trans->caller);
     56       
     57        // FIXME - answer according to outcome
     58        ipc_answer_1(trans->caller, EOK, 0);
    6459       
    6560        free(trans);
     
    6762                free(buffer);
    6863        }
    69 }
    70 
    71 /** Callback for incoming transaction.
    72  */
    73 static void in_callback(void * buffer, size_t len, usb_transaction_outcome_t outcome, void * arg)
    74 {
    75         dprintf(2, "in_callback(buffer, %u, %d, %p)", len, outcome, arg);
    76         transaction_details_t * trans = (transaction_details_t *)arg;
    77        
    78         ipc_call_t answer_data;
    79         ipcarg_t answer_rc;
    80         aid_t req;
    81         int rc;
    82        
    83         req = async_send_3(trans->phone,
    84             IPC_M_USB_HCD_DATA_RECEIVED,
    85             trans->handle, outcome,
    86             len,
    87             &answer_data);
    88        
    89         if (len > 0) {
    90                 rc = async_data_write_start(trans->phone, buffer, len);
    91                 if (rc != EOK) {
    92                         async_wait_for(req, NULL);
    93                         goto leave;
    94                 }
    95         }
    96        
    97         async_wait_for(req, &answer_rc);
    98         rc = (int)answer_rc;
    99         if (rc != EOK) {
    100                 goto leave;
    101         }
    102        
    103 leave:
    104         free(trans);
    105         if (buffer != NULL) {
    106                 free(buffer);
    107         }
    108 }
    109 
    110 /** Handle data from host to function.
    111  */
    112 static void handle_data_to_function(ipc_callid_t iid, ipc_call_t icall,
    113     bool setup_transaction, int callback_phone)
     64        dprintf(4, "async_out_callback answered");
     65}
     66
     67static void async_to_device(ipc_callid_t iid, ipc_call_t icall, bool setup_transaction)
    11468{
    11569        size_t expected_len = IPC_GET_ARG3(icall);
     
    11973        };
    12074       
    121         dprintf(1, "pretending transfer to function (dev=%d:%d)",
    122             target.address, target.endpoint);
    123        
    124         if (callback_phone == -1) {
    125                 ipc_answer_0(iid, ENOENT);
    126                 return;
    127         }
    128        
    129         usb_transaction_handle_t handle
    130             = create_transaction_handle(callback_phone);
     75        dprintf(1, "async_to_device: dev=%d:%d, size=%d, iid=%x",
     76            target.address, target.endpoint, expected_len, iid);
    13177       
    13278        size_t len = 0;
     
    14389        }
    14490       
    145         transaction_details_t * trans = malloc(sizeof(transaction_details_t));
    146         trans->phone = callback_phone;
    147         trans->handle = handle;
     91        async_transaction_t * trans = malloc(sizeof(async_transaction_t));
     92        trans->caller = iid;
     93        trans->buffer = NULL;
     94        trans->size = 0;
    14895       
    14996        hc_add_transaction_to_device(setup_transaction, target,
    15097            buffer, len,
    151             out_callback, trans);
    152        
    153         ipc_answer_1(iid, EOK, handle);
    154         dprintf(2, "transfer to function scheduled (handle %d)", handle);
    155 }
    156 
    157 /** Handle data from function to host.
    158  */
    159 static void handle_data_from_function(ipc_callid_t iid, ipc_call_t icall, int callback_phone)
     98            async_out_callback, trans);
     99       
     100        dprintf(2, "async transaction to device scheduled (%p)", trans);
     101}
     102
     103static void async_in_callback(void * buffer, size_t len,
     104    usb_transaction_outcome_t outcome, void * arg)
     105{       
     106        async_transaction_t * trans = (async_transaction_t *)arg;
     107       
     108        dprintf(2, "async_in_callback(buffer, %u, %d, %p) -> %x",
     109            len, outcome, arg, trans->caller);
     110       
     111        trans->buffer = buffer;
     112        trans->size = len;
     113       
     114        ipc_callid_t caller = trans->caller;
     115       
     116        if (buffer == NULL) {
     117                free(trans);
     118                trans = NULL;
     119        }
     120       
     121       
     122        // FIXME - answer according to outcome
     123        ipc_answer_1(caller, EOK, (ipcarg_t)trans);
     124        dprintf(4, "async_in_callback answered (%#x)", (ipcarg_t)trans);
     125}
     126
     127static void async_from_device(ipc_callid_t iid, ipc_call_t icall)
    160128{
    161129        usb_target_t target = {
     
    165133        size_t len = IPC_GET_ARG3(icall);
    166134       
    167         dprintf(1, "pretending transfer from function (dev=%d:%d)",
    168             target.address, target.endpoint);
    169        
    170         if (callback_phone == -1) {
    171                 ipc_answer_0(iid, ENOENT);
    172                 return;
    173         }
    174        
    175         usb_transaction_handle_t handle
    176             = create_transaction_handle(callback_phone);
    177        
    178         void * buffer = NULL;
    179         if (len > 0) {
    180                 buffer = malloc(len);
    181         }
    182        
    183         transaction_details_t * trans = malloc(sizeof(transaction_details_t));
    184         trans->phone = callback_phone;
    185         trans->handle = handle;
    186        
    187         hc_add_transaction_from_device(target,
    188             buffer, len,
    189             in_callback, trans);
    190        
    191         ipc_answer_1(iid, EOK, handle);
    192         dprintf(2, "transfer from function scheduled (handle %d)", handle);
    193 }
    194 
    195 
    196 typedef struct {
    197         ipc_callid_t caller;
    198         void *buffer;
    199         size_t size;
    200 } async_transaction_t;
    201 
    202 static void async_out_callback(void * buffer, size_t len,
    203     usb_transaction_outcome_t outcome, void * arg)
    204 {
    205         async_transaction_t * trans = (async_transaction_t *)arg;
    206        
    207         dprintf(2, "async_out_callback(buffer, %u, %d, %p) -> %x",
    208             len, outcome, arg, trans->caller);
    209        
    210         // FIXME - answer according to outcome
    211         ipc_answer_1(trans->caller, EOK, 0);
    212        
    213         free(trans);
    214         if (buffer) {
    215                 free(buffer);
    216         }
    217         dprintf(4, "async_out_callback answered");
    218 }
    219 
    220 static void async_to_device(ipc_callid_t iid, ipc_call_t icall, bool setup_transaction)
    221 {
    222         size_t expected_len = IPC_GET_ARG3(icall);
    223         usb_target_t target = {
    224                 .address = IPC_GET_ARG1(icall),
    225                 .endpoint = IPC_GET_ARG2(icall)
    226         };
    227        
    228         dprintf(1, "async_to_device: dev=%d:%d, size=%d, iid=%x",
    229             target.address, target.endpoint, expected_len, iid);
    230        
    231         size_t len = 0;
    232         void * buffer = NULL;
    233         if (expected_len > 0) {
    234                 int rc = async_data_write_accept(&buffer, false,
    235                     1, USB_MAX_PAYLOAD_SIZE,
    236                     0, &len);
    237                
    238                 if (rc != EOK) {
    239                         ipc_answer_0(iid, rc);
    240                         return;
    241                 }
    242         }
    243        
    244         async_transaction_t * trans = malloc(sizeof(async_transaction_t));
    245         trans->caller = iid;
    246         trans->buffer = NULL;
    247         trans->size = 0;
    248        
    249         hc_add_transaction_to_device(setup_transaction, target,
    250             buffer, len,
    251             async_out_callback, trans);
    252        
    253         dprintf(2, "async transaction to device scheduled (%p)", trans);
    254 }
    255 
    256 static void async_in_callback(void * buffer, size_t len,
    257     usb_transaction_outcome_t outcome, void * arg)
    258 {       
    259         async_transaction_t * trans = (async_transaction_t *)arg;
    260        
    261         dprintf(2, "async_in_callback(buffer, %u, %d, %p) -> %x",
    262             len, outcome, arg, trans->caller);
    263        
    264         trans->buffer = buffer;
    265         trans->size = len;
    266        
    267         ipc_callid_t caller = trans->caller;
    268        
    269         if (buffer == NULL) {
    270                 free(trans);
    271                 trans = NULL;
    272         }
    273        
    274        
    275         // FIXME - answer according to outcome
    276         ipc_answer_1(caller, EOK, (ipcarg_t)trans);
    277         dprintf(4, "async_in_callback answered (%#x)", (ipcarg_t)trans);
    278 }
    279 
    280 static void async_from_device(ipc_callid_t iid, ipc_call_t icall)
    281 {
    282         usb_target_t target = {
    283                 .address = IPC_GET_ARG1(icall),
    284                 .endpoint = IPC_GET_ARG2(icall)
    285         };
    286         size_t len = IPC_GET_ARG3(icall);
    287        
    288135        dprintf(1, "async_from_device: dev=%d:%d, size=%d, iid=%x",
    289136            target.address, target.endpoint, len, iid);
     
    345192 *
    346193 * @param phone_hash Incoming phone hash.
    347  * @param host_phone Callback phone to host.
    348  */
    349 void connection_handler_host(ipcarg_t phone_hash, int host_phone)
    350 {
    351         assert(host_phone > 0);
    352        
     194 */
     195void connection_handler_host(ipcarg_t phone_hash)
     196{
    353197        dprintf(0, "host connected through phone %#x", phone_hash);
    354198       
     
    368212               
    369213                switch (IPC_GET_METHOD(call)) {
     214
     215                        /* standard IPC methods */
     216
    370217                        case IPC_M_PHONE_HUNGUP:
    371                                 ipc_hangup(host_phone);
    372218                                ipc_answer_0(callid, EOK);
    373219                                dprintf(0, "phone%#x: host hung-up",
     
    379225                                break;
    380226                       
     227
     228                        /* USB methods */
     229
    381230                        case IPC_M_USB_HCD_TRANSACTION_SIZE:
    382231                                ipc_answer_1(callid, EOK, USB_MAX_PAYLOAD_SIZE);
    383232                                break;
    384                        
    385                         /* callback-result methods */
    386                        
    387                         case IPC_M_USB_HCD_INTERRUPT_OUT:
    388                                 handle_data_to_function(callid, call,
    389                                     false, host_phone);
    390                                 break;
    391                                
    392                         case IPC_M_USB_HCD_INTERRUPT_IN:
    393                                 handle_data_from_function(callid, call, host_phone);
    394                                 break;
    395                        
    396                         case IPC_M_USB_HCD_CONTROL_WRITE_SETUP:
    397                                 handle_data_to_function(callid, call,
    398                                     true, host_phone);
    399                                 break;
    400                                
    401                         case IPC_M_USB_HCD_CONTROL_WRITE_DATA:
    402                                 handle_data_to_function(callid, call,
    403                                     false, host_phone);
    404                                 break;
    405                                
    406                         case IPC_M_USB_HCD_CONTROL_WRITE_STATUS:
    407                                 handle_data_from_function(callid, call, host_phone);
    408                                 break;
    409                        
    410                         case IPC_M_USB_HCD_CONTROL_READ_SETUP:
    411                                 handle_data_to_function(callid, call,
    412                                     true, host_phone);
    413                                 break;
    414                        
    415                         /* async methods */
    416233                       
    417234                        case IPC_M_USB_HCD_GET_BUFFER_ASYNC:
     
    436253                                break;
    437254                       
     255
    438256                        /* end of known methods */
    439257                       
Note: See TracChangeset for help on using the changeset viewer.