Changeset 1d1f894 in mainline for uspace/srv/hw/bus/usb/hcd/virtual/connhost.c
- Timestamp:
- 2010-11-03T15:05:41Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d70a463
- Parents:
- af894a21
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/bus/usb/hcd/virtual/connhost.c
raf894a21 r1d1f894 41 41 #include "hc.h" 42 42 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 49 43 typedef 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 49 static 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); 64 59 65 60 free(trans); … … 67 62 free(buffer); 68 63 } 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 67 static void async_to_device(ipc_callid_t iid, ipc_call_t icall, bool setup_transaction) 114 68 { 115 69 size_t expected_len = IPC_GET_ARG3(icall); … … 119 73 }; 120 74 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); 131 77 132 78 size_t len = 0; … … 143 89 } 144 90 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; 148 95 149 96 hc_add_transaction_to_device(setup_transaction, target, 150 97 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 103 static 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 127 static void async_from_device(ipc_callid_t iid, ipc_call_t icall) 160 128 { 161 129 usb_target_t target = { … … 165 133 size_t len = IPC_GET_ARG3(icall); 166 134 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 handle176 = 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 outcome211 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 outcome276 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 288 135 dprintf(1, "async_from_device: dev=%d:%d, size=%d, iid=%x", 289 136 target.address, target.endpoint, len, iid); … … 345 192 * 346 193 * @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 */ 195 void connection_handler_host(ipcarg_t phone_hash) 196 { 353 197 dprintf(0, "host connected through phone %#x", phone_hash); 354 198 … … 368 212 369 213 switch (IPC_GET_METHOD(call)) { 214 215 /* standard IPC methods */ 216 370 217 case IPC_M_PHONE_HUNGUP: 371 ipc_hangup(host_phone);372 218 ipc_answer_0(callid, EOK); 373 219 dprintf(0, "phone%#x: host hung-up", … … 379 225 break; 380 226 227 228 /* USB methods */ 229 381 230 case IPC_M_USB_HCD_TRANSACTION_SIZE: 382 231 ipc_answer_1(callid, EOK, USB_MAX_PAYLOAD_SIZE); 383 232 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 */416 233 417 234 case IPC_M_USB_HCD_GET_BUFFER_ASYNC: … … 436 253 break; 437 254 255 438 256 /* end of known methods */ 439 257
Note:
See TracChangeset
for help on using the changeset viewer.