Changeset aec2ad4 in mainline for uspace/lib
- Timestamp:
- 2011-02-04T11:48:33Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 103a3626
- Parents:
- ba5ab09 (diff), 3597dab (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. - Location:
- uspace/lib
- Files:
-
- 4 added
- 23 edited
-
c/generic/async.c (modified) (12 diffs)
-
c/generic/devman.c (modified) (1 diff)
-
c/generic/devmap.c (modified) (1 diff)
-
c/generic/ipc.c (modified) (2 diffs)
-
c/generic/net/modules.c (modified) (1 diff)
-
c/generic/vfs/vfs.c (modified) (37 diffs)
-
c/include/async.h (modified) (4 diffs)
-
c/include/ipc/ipc.h (modified) (2 diffs)
-
drv/generic/remote_usbhc.c (modified) (15 diffs)
-
drv/include/usbhc_iface.h (modified) (2 diffs)
-
fs/libfs.c (modified) (2 diffs)
-
net/il/il_skel.c (modified) (1 diff)
-
net/nil/nil_skel.c (modified) (1 diff)
-
net/tl/tl_skel.c (modified) (1 diff)
-
usb/Makefile (modified) (1 diff)
-
usb/include/usb/classes/hid.h (modified) (2 diffs)
-
usb/include/usb/debug.h (modified) (3 diffs)
-
usb/include/usb/pipes.h (added)
-
usb/include/usb/request.h (added)
-
usb/include/usb/usb.h (modified) (2 diffs)
-
usb/include/usb/usbdrv.h (modified) (3 diffs)
-
usb/src/debug.c (modified) (3 diffs)
-
usb/src/hidparser.c (modified) (2 diffs)
-
usb/src/pipes.c (added)
-
usb/src/request.c (added)
-
usb/src/usbdrv.c (modified) (2 diffs)
-
usbvirt/src/main.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
rba5ab09 raec2ad4 134 134 135 135 typedef struct { 136 sysarg_t in_task_hash; 137 link_t link; 138 int refcnt; 139 void *data; 140 } client_t; 141 142 typedef struct { 136 143 awaiter_t wdata; 137 144 … … 139 146 link_t link; 140 147 148 /** Incoming client task hash. */ 149 sysarg_t in_task_hash; 141 150 /** Incoming phone hash. */ 142 151 sysarg_t in_phone_hash; 143 152 153 /** Link to the client tracking structure. */ 154 client_t *client; 155 144 156 /** Messages that should be delivered to this fibril. */ 145 157 link_t msg_queue; … … 160 172 fibril_local connection_t *FIBRIL_connection; 161 173 174 static void *default_client_data_constructor(void) 175 { 176 return NULL; 177 } 178 179 static void default_client_data_destructor(void *data) 180 { 181 } 182 183 static async_client_data_ctor_t async_client_data_create = 184 default_client_data_constructor; 185 static async_client_data_dtor_t async_client_data_destroy = 186 default_client_data_destructor; 187 188 void async_set_client_data_constructor(async_client_data_ctor_t ctor) 189 { 190 async_client_data_create = ctor; 191 } 192 193 void async_set_client_data_destructor(async_client_data_dtor_t dtor) 194 { 195 async_client_data_destroy = dtor; 196 } 197 198 void *async_client_data_get(void) 199 { 200 assert(FIBRIL_connection); 201 202 return FIBRIL_connection->client->data; 203 } 204 162 205 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call); 163 206 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call); … … 174 217 static async_client_conn_t interrupt_received = default_interrupt_received; 175 218 219 static hash_table_t client_hash_table; 176 220 static hash_table_t conn_hash_table; 177 221 static LIST_INITIALIZE(timeout_list); 178 222 179 #define CONN_HASH_TABLE_CHAINS 32 223 #define CLIENT_HASH_TABLE_BUCKETS 32 224 #define CONN_HASH_TABLE_BUCKETS 32 225 226 static hash_index_t client_hash(unsigned long *key) 227 { 228 assert(key); 229 return (((*key) >> 4) % CLIENT_HASH_TABLE_BUCKETS); 230 } 231 232 static int client_compare(unsigned long key[], hash_count_t keys, link_t *item) 233 { 234 client_t *cl = hash_table_get_instance(item, client_t, link); 235 return (key[0] == cl->in_task_hash); 236 } 237 238 static void client_remove(link_t *item) 239 { 240 } 241 242 /** Operations for the client hash table. */ 243 static hash_table_operations_t client_hash_table_ops = { 244 .hash = client_hash, 245 .compare = client_compare, 246 .remove_callback = client_remove 247 }; 180 248 181 249 /** Compute hash into the connection hash table based on the source phone hash. … … 189 257 { 190 258 assert(key); 191 return (((*key) >> 4) % CONN_HASH_TABLE_ CHAINS);259 return (((*key) >> 4) % CONN_HASH_TABLE_BUCKETS); 192 260 } 193 261 … … 480 548 static int connection_fibril(void *arg) 481 549 { 550 unsigned long key; 551 client_t *cl; 552 link_t *lnk; 553 bool destroy = false; 554 482 555 /* 483 * Setup fibril-local connection pointer and call client_connection(). 484 * 556 * Setup fibril-local connection pointer. 485 557 */ 486 558 FIBRIL_connection = (connection_t *) arg; 559 560 /* 561 * Add our reference for the current connection in the client task 562 * tracking structure. If this is the first reference, create and 563 * hash in a new tracking structure. 564 */ 565 futex_down(&async_futex); 566 key = FIBRIL_connection->in_task_hash; 567 lnk = hash_table_find(&client_hash_table, &key); 568 if (lnk) { 569 cl = hash_table_get_instance(lnk, client_t, link); 570 cl->refcnt++; 571 } else { 572 cl = malloc(sizeof(client_t)); 573 if (!cl) { 574 ipc_answer_0(FIBRIL_connection->callid, ENOMEM); 575 futex_up(&async_futex); 576 return 0; 577 } 578 cl->in_task_hash = FIBRIL_connection->in_task_hash; 579 async_serialize_start(); 580 cl->data = async_client_data_create(); 581 async_serialize_end(); 582 cl->refcnt = 1; 583 hash_table_insert(&client_hash_table, &key, &cl->link); 584 } 585 futex_up(&async_futex); 586 587 FIBRIL_connection->client = cl; 588 589 /* 590 * Call the connection handler function. 591 */ 487 592 FIBRIL_connection->cfibril(FIBRIL_connection->callid, 488 593 &FIBRIL_connection->call); 489 594 490 /* Remove myself from the connection hash table */ 595 /* 596 * Remove the reference for this client task connection. 597 */ 491 598 futex_down(&async_futex); 492 unsigned long key = FIBRIL_connection->in_phone_hash; 599 if (--cl->refcnt == 0) { 600 hash_table_remove(&client_hash_table, &key, 1); 601 destroy = true; 602 } 603 futex_up(&async_futex); 604 605 if (destroy) { 606 if (cl->data) 607 async_client_data_destroy(cl->data); 608 free(cl); 609 } 610 611 /* 612 * Remove myself from the connection hash table. 613 */ 614 futex_down(&async_futex); 615 key = FIBRIL_connection->in_phone_hash; 493 616 hash_table_remove(&conn_hash_table, &key, 1); 494 617 futex_up(&async_futex); 495 618 496 /* Answer all remaining messages with EHANGUP */ 619 /* 620 * Answer all remaining messages with EHANGUP. 621 */ 497 622 while (!list_empty(&FIBRIL_connection->msg_queue)) { 498 623 msg_t *msg; … … 505 630 } 506 631 632 /* 633 * If the connection was hung-up, answer the last call, 634 * i.e. IPC_M_PHONE_HUNGUP. 635 */ 507 636 if (FIBRIL_connection->close_callid) 508 637 ipc_answer_0(FIBRIL_connection->close_callid, EOK); … … 517 646 * particular fibrils. 518 647 * 648 * @param in_task_hash Identification of the incoming connection. 519 649 * @param in_phone_hash Identification of the incoming connection. 520 650 * @param callid Hash of the opening IPC_M_CONNECT_ME_TO call. … … 529 659 * 530 660 */ 531 fid_t async_new_connection(sysarg_t in_phone_hash, ipc_callid_t callid, 532 ipc_call_t *call, void (*cfibril)(ipc_callid_t, ipc_call_t *)) 661 fid_t async_new_connection(sysarg_t in_task_hash, sysarg_t in_phone_hash, 662 ipc_callid_t callid, ipc_call_t *call, 663 void (*cfibril)(ipc_callid_t, ipc_call_t *)) 533 664 { 534 665 connection_t *conn = malloc(sizeof(*conn)); … … 539 670 } 540 671 672 conn->in_task_hash = in_task_hash; 541 673 conn->in_phone_hash = in_phone_hash; 542 674 list_initialize(&conn->msg_queue); … … 592 724 case IPC_M_CONNECT_ME_TO: 593 725 /* Open new connection with fibril etc. */ 594 async_new_connection( IPC_GET_ARG5(*call), callid, call,595 c lient_connection);726 async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call), 727 callid, call, client_connection); 596 728 goto out; 597 729 } … … 744 876 int __async_init(void) 745 877 { 746 if (!hash_table_create(&c onn_hash_table, CONN_HASH_TABLE_CHAINS, 1,747 &c onn_hash_table_ops)) {748 printf("%s: Cannot create async hash table\n", "libc");878 if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 1, 879 &client_hash_table_ops) || !hash_table_create(&conn_hash_table, 880 CONN_HASH_TABLE_BUCKETS, 1, &conn_hash_table_ops)) { 749 881 return ENOMEM; 750 882 } -
uspace/lib/c/generic/devman.c
rba5ab09 raec2ad4 116 116 async_set_client_connection(conn); 117 117 118 sysarg_t callback_phonehash; 119 ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash); 118 ipc_connect_to_me(phone, 0, 0, 0, NULL, NULL); 120 119 async_wait_for(req, &retval); 121 120 -
uspace/lib/c/generic/devmap.c
rba5ab09 raec2ad4 116 116 async_set_client_connection(conn); 117 117 118 sysarg_t callback_phonehash; 119 ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash); 118 ipc_connect_to_me(phone, 0, 0, 0, NULL, NULL); 120 119 async_wait_for(req, &retval); 121 120 -
uspace/lib/c/generic/ipc.c
rba5ab09 raec2ad4 578 578 * @param arg2 Service-defined argument. 579 579 * @param arg3 Service-defined argument. 580 * @param phonehash Storage where the library will store an opaque 580 * @param taskhash Storage where the kernel will store an opaque 581 * identifier of the client task. 582 * @param phonehash Storage where the kernel will store an opaque 581 583 * identifier of the phone that will be used for incoming 582 584 * calls. This identifier can be used for connection … … 586 588 */ 587 589 int ipc_connect_to_me(int phoneid, int arg1, int arg2, int arg3, 588 sysarg_t * phonehash)590 sysarg_t *taskhash, sysarg_t *phonehash) 589 591 { 590 592 return ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_TO_ME, arg1, arg2, 591 arg3, NULL, NULL, NULL, NULL, phonehash);593 arg3, NULL, NULL, NULL, taskhash, phonehash); 592 594 } 593 595 -
uspace/lib/c/generic/net/modules.c
rba5ab09 raec2ad4 143 143 if (phone >= 0) { 144 144 /* Request the bidirectional connection */ 145 sysarg_t taskhash; 145 146 sysarg_t phonehash; 146 147 147 rc = ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash); 148 rc = ipc_connect_to_me(phone, arg1, arg2, arg3, &taskhash, 149 &phonehash); 148 150 if (rc != EOK) { 149 151 ipc_hangup(phone); 150 152 return rc; 151 153 } 152 async_new_connection(phonehash, 0, NULL, client_receiver); 154 async_new_connection(taskhash, phonehash, 0, NULL, 155 client_receiver); 153 156 } 154 157 -
uspace/lib/c/generic/vfs/vfs.c
rba5ab09 raec2ad4 46 46 #include <ipc/services.h> 47 47 #include <async.h> 48 #include <atomic.h> 49 #include <futex.h> 48 #include <fibril_synch.h> 50 49 #include <errno.h> 50 #include <assert.h> 51 51 #include <str.h> 52 52 #include <devmap.h> … … 54 54 #include <ipc/devmap.h> 55 55 56 static async_sess_t vfs_session; 57 58 static FIBRIL_MUTEX_INITIALIZE(vfs_phone_mutex); 56 59 static int vfs_phone = -1; 57 static futex_t vfs_phone_futex = FUTEX_INITIALIZER; 58 static futex_t cwd_futex = FUTEX_INITIALIZER;60 61 static FIBRIL_MUTEX_INITIALIZE(cwd_mutex); 59 62 60 63 static int cwd_fd = -1; … … 67 70 char *ncwd_path_nc; 68 71 69 f utex_down(&cwd_futex);72 fibril_mutex_lock(&cwd_mutex); 70 73 size_t size = str_size(path); 71 74 if (*path != '/') { 72 75 if (!cwd_path) { 73 f utex_up(&cwd_futex);76 fibril_mutex_unlock(&cwd_mutex); 74 77 return NULL; 75 78 } 76 79 ncwd_path_nc = malloc(cwd_size + 1 + size + 1); 77 80 if (!ncwd_path_nc) { 78 f utex_up(&cwd_futex);81 fibril_mutex_unlock(&cwd_mutex); 79 82 return NULL; 80 83 } … … 85 88 ncwd_path_nc = malloc(size + 1); 86 89 if (!ncwd_path_nc) { 87 f utex_up(&cwd_futex);90 fibril_mutex_unlock(&cwd_mutex); 88 91 return NULL; 89 92 } … … 93 96 ncwd_path = canonify(ncwd_path_nc, retlen); 94 97 if (!ncwd_path) { 95 f utex_up(&cwd_futex);98 fibril_mutex_unlock(&cwd_mutex); 96 99 free(ncwd_path_nc); 97 100 return NULL; … … 105 108 free(ncwd_path_nc); 106 109 if (!ncwd_path) { 107 f utex_up(&cwd_futex);110 fibril_mutex_unlock(&cwd_mutex); 108 111 return NULL; 109 112 } 110 f utex_up(&cwd_futex);113 fibril_mutex_unlock(&cwd_mutex); 111 114 return ncwd_path; 112 115 } 113 116 117 /** Connect to VFS service and create session. */ 114 118 static void vfs_connect(void) 115 119 { 116 while (vfs_phone < 0) 117 vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0); 120 while (vfs_phone < 0) { 121 vfs_phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 122 0, 0); 123 } 124 125 async_session_create(&vfs_session, vfs_phone, 0); 126 } 127 128 /** Start an async exchange on the VFS session. 129 * 130 * @return New phone to be used during the exchange. 131 */ 132 static int vfs_exchange_begin(void) 133 { 134 fibril_mutex_lock(&vfs_phone_mutex); 135 if (vfs_phone < 0) 136 vfs_connect(); 137 fibril_mutex_unlock(&vfs_phone_mutex); 138 139 return async_exchange_begin(&vfs_session); 140 } 141 142 /** End an async exchange on the VFS session. 143 * 144 * @param phone Phone used during the exchange. 145 */ 146 static void vfs_exchange_end(int phone) 147 { 148 async_exchange_end(&vfs_session, phone); 118 149 } 119 150 … … 154 185 } 155 186 156 futex_down(&vfs_phone_futex); 157 async_serialize_start(); 158 vfs_connect(); 159 187 int vfs_phone = vfs_exchange_begin(); 188 160 189 sysarg_t rc_orig; 161 190 aid_t req = async_send_2(vfs_phone, VFS_IN_MOUNT, devmap_handle, flags, NULL); 162 191 sysarg_t rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size); 163 192 if (rc != EOK) { 164 async_wait_for(req, &rc_orig); 165 async_serialize_end(); 166 futex_up(&vfs_phone_futex); 193 vfs_exchange_end(vfs_phone); 167 194 free(mpa); 195 async_wait_for(req, &rc_orig); 168 196 169 197 if (null_id != -1) … … 178 206 rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts)); 179 207 if (rc != EOK) { 180 async_wait_for(req, &rc_orig); 181 async_serialize_end(); 182 futex_up(&vfs_phone_futex); 208 vfs_exchange_end(vfs_phone); 183 209 free(mpa); 210 async_wait_for(req, &rc_orig); 184 211 185 212 if (null_id != -1) … … 194 221 rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name)); 195 222 if (rc != EOK) { 196 async_wait_for(req, &rc_orig); 197 async_serialize_end(); 198 futex_up(&vfs_phone_futex); 223 vfs_exchange_end(vfs_phone); 199 224 free(mpa); 225 async_wait_for(req, &rc_orig); 200 226 201 227 if (null_id != -1) … … 211 237 rc = async_req_0_0(vfs_phone, IPC_M_PING); 212 238 if (rc != EOK) { 213 async_wait_for(req, &rc_orig); 214 async_serialize_end(); 215 futex_up(&vfs_phone_futex); 239 vfs_exchange_end(vfs_phone); 216 240 free(mpa); 241 async_wait_for(req, &rc_orig); 217 242 218 243 if (null_id != -1) … … 225 250 } 226 251 227 async_wait_for(req, &rc); 228 async_serialize_end(); 229 futex_up(&vfs_phone_futex); 252 vfs_exchange_end(vfs_phone); 230 253 free(mpa); 254 async_wait_for(req, &rc); 231 255 232 256 if ((rc != EOK) && (null_id != -1)) … … 248 272 return ENOMEM; 249 273 250 futex_down(&vfs_phone_futex); 251 async_serialize_start(); 252 vfs_connect(); 274 int vfs_phone = vfs_exchange_begin(); 253 275 254 276 req = async_send_0(vfs_phone, VFS_IN_UNMOUNT, NULL); 255 277 rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size); 256 278 if (rc != EOK) { 257 async_wait_for(req, &rc_orig); 258 async_serialize_end(); 259 futex_up(&vfs_phone_futex); 279 vfs_exchange_end(vfs_phone); 260 280 free(mpa); 261 if (rc_orig == EOK) 262 return (int) rc; 263 else 264 return (int) rc_orig; 265 } 266 267 268 async_wait_for(req, &rc); 269 async_serialize_end(); 270 futex_up(&vfs_phone_futex); 281 async_wait_for(req, &rc_orig); 282 if (rc_orig == EOK) 283 return (int) rc; 284 else 285 return (int) rc_orig; 286 } 287 288 289 vfs_exchange_end(vfs_phone); 271 290 free(mpa); 291 async_wait_for(req, &rc); 272 292 273 293 return (int) rc; … … 276 296 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag) 277 297 { 278 futex_down(&vfs_phone_futex); 279 async_serialize_start(); 280 vfs_connect(); 298 int vfs_phone = vfs_exchange_begin(); 281 299 282 300 ipc_call_t answer; … … 285 303 286 304 if (rc != EOK) { 305 vfs_exchange_end(vfs_phone); 306 287 307 sysarg_t rc_orig; 288 308 async_wait_for(req, &rc_orig); 289 309 290 async_serialize_end(); 291 futex_up(&vfs_phone_futex); 292 293 if (rc_orig == EOK) 294 return (int) rc; 295 else 296 return (int) rc_orig; 297 } 298 299 async_wait_for(req, &rc); 300 async_serialize_end(); 301 futex_up(&vfs_phone_futex); 310 if (rc_orig == EOK) 311 return (int) rc; 312 else 313 return (int) rc_orig; 314 } 315 316 vfs_exchange_end(vfs_phone); 317 async_wait_for(req, &rc); 302 318 303 319 if (rc != EOK) … … 322 338 int open_node(fdi_node_t *node, int oflag) 323 339 { 324 futex_down(&vfs_phone_futex); 325 async_serialize_start(); 326 vfs_connect(); 340 int vfs_phone = vfs_exchange_begin(); 327 341 328 342 ipc_call_t answer; … … 330 344 node->devmap_handle, node->index, oflag, &answer); 331 345 332 sysarg_t rc;333 async_wait_for(req, &rc); 334 async_serialize_end();335 futex_up(&vfs_phone_futex);346 vfs_exchange_end(vfs_phone); 347 348 sysarg_t rc; 349 async_wait_for(req, &rc); 336 350 337 351 if (rc != EOK) … … 345 359 sysarg_t rc; 346 360 347 futex_down(&vfs_phone_futex); 348 async_serialize_start(); 349 vfs_connect(); 361 int vfs_phone = vfs_exchange_begin(); 350 362 351 363 rc = async_req_1_0(vfs_phone, VFS_IN_CLOSE, fildes); 352 364 353 async_serialize_end(); 354 futex_up(&vfs_phone_futex); 365 vfs_exchange_end(vfs_phone); 355 366 356 367 return (int)rc; … … 363 374 aid_t req; 364 375 365 futex_down(&vfs_phone_futex); 366 async_serialize_start(); 367 vfs_connect(); 376 int vfs_phone = vfs_exchange_begin(); 368 377 369 378 req = async_send_1(vfs_phone, VFS_IN_READ, fildes, &answer); 370 379 rc = async_data_read_start(vfs_phone, (void *)buf, nbyte); 371 380 if (rc != EOK) { 381 vfs_exchange_end(vfs_phone); 382 372 383 sysarg_t rc_orig; 373 374 async_wait_for(req, &rc_orig); 375 async_serialize_end(); 376 futex_up(&vfs_phone_futex); 384 async_wait_for(req, &rc_orig); 385 377 386 if (rc_orig == EOK) 378 387 return (ssize_t) rc; … … 380 389 return (ssize_t) rc_orig; 381 390 } 382 async_wait_for(req, &rc); 383 async_serialize_end(); 384 futex_up(&vfs_phone_futex); 391 vfs_exchange_end(vfs_phone); 392 async_wait_for(req, &rc); 385 393 if (rc == EOK) 386 394 return (ssize_t) IPC_GET_ARG1(answer); … … 395 403 aid_t req; 396 404 397 futex_down(&vfs_phone_futex); 398 async_serialize_start(); 399 vfs_connect(); 405 int vfs_phone = vfs_exchange_begin(); 400 406 401 407 req = async_send_1(vfs_phone, VFS_IN_WRITE, fildes, &answer); 402 408 rc = async_data_write_start(vfs_phone, (void *)buf, nbyte); 403 409 if (rc != EOK) { 410 vfs_exchange_end(vfs_phone); 411 404 412 sysarg_t rc_orig; 405 406 async_wait_for(req, &rc_orig); 407 async_serialize_end(); 408 futex_up(&vfs_phone_futex); 413 async_wait_for(req, &rc_orig); 414 409 415 if (rc_orig == EOK) 410 416 return (ssize_t) rc; … … 412 418 return (ssize_t) rc_orig; 413 419 } 414 async_wait_for(req, &rc); 415 async_serialize_end(); 416 futex_up(&vfs_phone_futex); 420 vfs_exchange_end(vfs_phone); 421 async_wait_for(req, &rc); 417 422 if (rc == EOK) 418 423 return (ssize_t) IPC_GET_ARG1(answer); … … 423 428 int fsync(int fildes) 424 429 { 425 futex_down(&vfs_phone_futex); 426 async_serialize_start(); 427 vfs_connect(); 430 int vfs_phone = vfs_exchange_begin(); 428 431 429 432 sysarg_t rc = async_req_1_0(vfs_phone, VFS_IN_SYNC, fildes); 430 433 431 async_serialize_end(); 432 futex_up(&vfs_phone_futex); 434 vfs_exchange_end(vfs_phone); 433 435 434 436 return (int) rc; … … 437 439 off64_t lseek(int fildes, off64_t offset, int whence) 438 440 { 439 futex_down(&vfs_phone_futex); 440 async_serialize_start(); 441 vfs_connect(); 441 int vfs_phone = vfs_exchange_begin(); 442 442 443 443 sysarg_t newoff_lo; … … 447 447 &newoff_lo, &newoff_hi); 448 448 449 async_serialize_end(); 450 futex_up(&vfs_phone_futex); 449 vfs_exchange_end(vfs_phone); 451 450 452 451 if (rc != EOK) … … 460 459 sysarg_t rc; 461 460 462 futex_down(&vfs_phone_futex); 463 async_serialize_start(); 464 vfs_connect(); 461 int vfs_phone = vfs_exchange_begin(); 465 462 466 463 rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes, 467 464 LOWER32(length), UPPER32(length)); 468 async_serialize_end(); 469 futex_up(&vfs_phone_futex); 465 vfs_exchange_end(vfs_phone); 470 466 471 467 return (int) rc; … … 477 473 aid_t req; 478 474 479 futex_down(&vfs_phone_futex); 480 async_serialize_start(); 481 vfs_connect(); 475 int vfs_phone = vfs_exchange_begin(); 482 476 483 477 req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL); 484 478 rc = async_data_read_start(vfs_phone, (void *) stat, sizeof(struct stat)); 485 479 if (rc != EOK) { 480 vfs_exchange_end(vfs_phone); 481 486 482 sysarg_t rc_orig; 487 488 async_wait_for(req, &rc_orig); 489 async_serialize_end(); 490 futex_up(&vfs_phone_futex); 483 async_wait_for(req, &rc_orig); 484 491 485 if (rc_orig == EOK) 492 486 return (ssize_t) rc; … … 494 488 return (ssize_t) rc_orig; 495 489 } 496 async_wait_for(req, &rc); 497 async_serialize_end(); 498 futex_up(&vfs_phone_futex); 490 vfs_exchange_end(vfs_phone); 491 async_wait_for(req, &rc); 499 492 500 493 return rc; … … 512 505 return ENOMEM; 513 506 514 futex_down(&vfs_phone_futex); 515 async_serialize_start(); 516 vfs_connect(); 507 int vfs_phone = vfs_exchange_begin(); 517 508 518 509 req = async_send_0(vfs_phone, VFS_IN_STAT, NULL); 519 510 rc = async_data_write_start(vfs_phone, pa, pa_size); 520 511 if (rc != EOK) { 521 async_wait_for(req, &rc_orig); 522 async_serialize_end(); 523 futex_up(&vfs_phone_futex); 512 vfs_exchange_end(vfs_phone); 524 513 free(pa); 514 async_wait_for(req, &rc_orig); 525 515 if (rc_orig == EOK) 526 516 return (int) rc; … … 530 520 rc = async_data_read_start(vfs_phone, stat, sizeof(struct stat)); 531 521 if (rc != EOK) { 532 async_wait_for(req, &rc_orig); 533 async_serialize_end(); 534 futex_up(&vfs_phone_futex); 522 vfs_exchange_end(vfs_phone); 535 523 free(pa); 536 if (rc_orig == EOK) 537 return (int) rc; 538 else 539 return (int) rc_orig; 540 } 541 async_wait_for(req, &rc); 542 async_serialize_end(); 543 futex_up(&vfs_phone_futex); 524 async_wait_for(req, &rc_orig); 525 if (rc_orig == EOK) 526 return (int) rc; 527 else 528 return (int) rc_orig; 529 } 530 vfs_exchange_end(vfs_phone); 544 531 free(pa); 532 async_wait_for(req, &rc); 545 533 return rc; 546 534 } … … 601 589 return ENOMEM; 602 590 603 futex_down(&vfs_phone_futex); 604 async_serialize_start(); 605 vfs_connect(); 591 int vfs_phone = vfs_exchange_begin(); 606 592 607 593 req = async_send_1(vfs_phone, VFS_IN_MKDIR, mode, NULL); 608 594 rc = async_data_write_start(vfs_phone, pa, pa_size); 609 595 if (rc != EOK) { 596 vfs_exchange_end(vfs_phone); 597 free(pa); 598 610 599 sysarg_t rc_orig; 611 612 async_wait_for(req, &rc_orig); 613 async_serialize_end(); 614 futex_up(&vfs_phone_futex); 615 free(pa); 616 if (rc_orig == EOK) 617 return (int) rc; 618 else 619 return (int) rc_orig; 620 } 621 async_wait_for(req, &rc); 622 async_serialize_end(); 623 futex_up(&vfs_phone_futex); 600 async_wait_for(req, &rc_orig); 601 602 if (rc_orig == EOK) 603 return (int) rc; 604 else 605 return (int) rc_orig; 606 } 607 vfs_exchange_end(vfs_phone); 624 608 free(pa); 609 async_wait_for(req, &rc); 625 610 return rc; 626 611 } … … 636 621 return ENOMEM; 637 622 638 futex_down(&vfs_phone_futex); 639 async_serialize_start(); 640 vfs_connect(); 623 int vfs_phone = vfs_exchange_begin(); 641 624 642 625 req = async_send_0(vfs_phone, VFS_IN_UNLINK, NULL); 643 626 rc = async_data_write_start(vfs_phone, pa, pa_size); 644 627 if (rc != EOK) { 628 vfs_exchange_end(vfs_phone); 629 free(pa); 630 645 631 sysarg_t rc_orig; 646 647 async_wait_for(req, &rc_orig); 648 async_serialize_end(); 649 futex_up(&vfs_phone_futex); 650 free(pa); 651 if (rc_orig == EOK) 652 return (int) rc; 653 else 654 return (int) rc_orig; 655 } 656 async_wait_for(req, &rc); 657 async_serialize_end(); 658 futex_up(&vfs_phone_futex); 632 async_wait_for(req, &rc_orig); 633 634 if (rc_orig == EOK) 635 return (int) rc; 636 else 637 return (int) rc_orig; 638 } 639 vfs_exchange_end(vfs_phone); 659 640 free(pa); 641 async_wait_for(req, &rc); 660 642 return rc; 661 643 } … … 689 671 } 690 672 691 futex_down(&vfs_phone_futex); 692 async_serialize_start(); 693 vfs_connect(); 673 int vfs_phone = vfs_exchange_begin(); 694 674 695 675 req = async_send_0(vfs_phone, VFS_IN_RENAME, NULL); 696 676 rc = async_data_write_start(vfs_phone, olda, olda_size); 697 677 if (rc != EOK) { 698 async_wait_for(req, &rc_orig); 699 async_serialize_end(); 700 futex_up(&vfs_phone_futex); 678 vfs_exchange_end(vfs_phone); 701 679 free(olda); 702 680 free(newa); 681 async_wait_for(req, &rc_orig); 703 682 if (rc_orig == EOK) 704 683 return (int) rc; … … 708 687 rc = async_data_write_start(vfs_phone, newa, newa_size); 709 688 if (rc != EOK) { 710 async_wait_for(req, &rc_orig); 711 async_serialize_end(); 712 futex_up(&vfs_phone_futex); 689 vfs_exchange_end(vfs_phone); 713 690 free(olda); 714 691 free(newa); 715 if (rc_orig == EOK) 716 return (int) rc; 717 else 718 return (int) rc_orig; 719 } 720 async_wait_for(req, &rc); 721 async_serialize_end(); 722 futex_up(&vfs_phone_futex); 692 async_wait_for(req, &rc_orig); 693 if (rc_orig == EOK) 694 return (int) rc; 695 else 696 return (int) rc_orig; 697 } 698 vfs_exchange_end(vfs_phone); 723 699 free(olda); 724 700 free(newa); 701 async_wait_for(req, &rc); 725 702 return rc; 726 703 } … … 740 717 } 741 718 742 f utex_down(&cwd_futex);719 fibril_mutex_lock(&cwd_mutex); 743 720 744 721 if (cwd_fd >= 0) … … 753 730 cwd_size = abs_size; 754 731 755 f utex_up(&cwd_futex);732 fibril_mutex_unlock(&cwd_mutex); 756 733 return EOK; 757 734 } … … 762 739 return NULL; 763 740 764 f utex_down(&cwd_futex);741 fibril_mutex_lock(&cwd_mutex); 765 742 766 743 if ((cwd_size == 0) || (size < cwd_size + 1)) { 767 f utex_up(&cwd_futex);744 fibril_mutex_unlock(&cwd_mutex); 768 745 return NULL; 769 746 } 770 747 771 748 str_cpy(buf, size, cwd_path); 772 f utex_up(&cwd_futex);749 fibril_mutex_unlock(&cwd_mutex); 773 750 774 751 return buf; … … 806 783 int dup2(int oldfd, int newfd) 807 784 { 808 futex_down(&vfs_phone_futex); 809 async_serialize_start(); 810 vfs_connect(); 785 int vfs_phone = vfs_exchange_begin(); 811 786 812 787 sysarg_t ret; 813 788 sysarg_t rc = async_req_2_1(vfs_phone, VFS_IN_DUP, oldfd, newfd, &ret); 814 789 815 async_serialize_end(); 816 futex_up(&vfs_phone_futex); 790 vfs_exchange_end(vfs_phone); 817 791 818 792 if (rc == EOK) -
uspace/lib/c/include/async.h
rba5ab09 raec2ad4 44 44 45 45 typedef ipc_callid_t aid_t; 46 typedef void (*async_client_conn_t)(ipc_callid_t callid, ipc_call_t *call); 46 47 typedef void *(*async_client_data_ctor_t)(void); 48 typedef void (*async_client_data_dtor_t)(void *); 49 50 typedef void (*async_client_conn_t)(ipc_callid_t, ipc_call_t *); 47 51 48 52 extern atomic_t async_futex; … … 51 55 52 56 extern int __async_init(void); 53 extern ipc_callid_t async_get_call_timeout(ipc_call_t * call, suseconds_t usecs);57 extern ipc_callid_t async_get_call_timeout(ipc_call_t *, suseconds_t); 54 58 55 59 static inline ipc_callid_t async_get_call(ipc_call_t *data) … … 85 89 (arg5), (dataptr)) 86 90 87 extern aid_t async_send_fast(int phoneid, sysarg_t method, sysarg_t arg1, 88 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr); 89 extern aid_t async_send_slow(int phoneid, sysarg_t method, sysarg_t arg1, 90 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, 91 ipc_call_t *dataptr); 92 extern void async_wait_for(aid_t amsgid, sysarg_t *result); 93 extern int async_wait_timeout(aid_t amsgid, sysarg_t *retval, 94 suseconds_t timeout); 95 96 extern fid_t async_new_connection(sysarg_t in_phone_hash, ipc_callid_t callid, 97 ipc_call_t *call, void (*cthread)(ipc_callid_t, ipc_call_t *)); 98 extern void async_usleep(suseconds_t timeout); 91 extern aid_t async_send_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 92 sysarg_t, ipc_call_t *); 93 extern aid_t async_send_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 94 sysarg_t, sysarg_t, ipc_call_t *); 95 extern void async_wait_for(aid_t, sysarg_t *); 96 extern int async_wait_timeout(aid_t, sysarg_t *, suseconds_t); 97 98 extern fid_t async_new_connection(sysarg_t, sysarg_t, ipc_callid_t, 99 ipc_call_t *, void (*)(ipc_callid_t, ipc_call_t *)); 100 extern void async_usleep(suseconds_t); 99 101 extern void async_create_manager(void); 100 102 extern void async_destroy_manager(void); 101 103 102 extern void async_set_client_connection(async_client_conn_t conn); 103 extern void async_set_interrupt_received(async_client_conn_t conn); 104 extern void async_set_client_data_constructor(async_client_data_ctor_t); 105 extern void async_set_client_data_destructor(async_client_data_dtor_t); 106 107 extern void *async_client_data_get(void); 108 109 extern void async_set_client_connection(async_client_conn_t); 110 extern void async_set_interrupt_received(async_client_conn_t); 104 111 105 112 /* Wrappers for simple communication */ … … 243 250 (arg5), (rc1), (rc2), (rc3), (rc4), (rc5)) 244 251 245 extern sysarg_t async_req_fast(int phoneid, sysarg_t method, sysarg_t arg1, 246 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t *r1, sysarg_t *r2, 247 sysarg_t *r3, sysarg_t *r4, sysarg_t *r5); 248 extern sysarg_t async_req_slow(int phoneid, sysarg_t method, sysarg_t arg1, 249 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *r1, 250 sysarg_t *r2, sysarg_t *r3, sysarg_t *r4, sysarg_t *r5); 252 extern sysarg_t async_req_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 253 sysarg_t, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *); 254 extern sysarg_t async_req_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 255 sysarg_t, sysarg_t, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *, 256 sysarg_t *); 251 257 252 258 static inline void async_serialize_start(void) -
uspace/lib/c/include/ipc/ipc.h
rba5ab09 raec2ad4 46 46 typedef struct { 47 47 sysarg_t args[IPC_CALL_LEN]; 48 sysarg_t in_task_hash; 48 49 sysarg_t in_phone_hash; 49 50 } ipc_call_t; … … 258 259 sysarg_t, sysarg_t, void *, ipc_async_callback_t, int); 259 260 260 extern int ipc_connect_to_me(int, int, int, int, sysarg_t * );261 extern int ipc_connect_to_me(int, int, int, int, sysarg_t *, sysarg_t *); 261 262 extern int ipc_connect_me_to(int, int, int, int); 262 263 extern int ipc_connect_me_to_blocking(int, int, int, int); -
uspace/lib/drv/generic/remote_usbhc.c
rba5ab09 raec2ad4 1 1 /* 2 * Copyright (c) 2010 Vojtech Horky2 * Copyright (c) 2010-2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 52 52 static void remote_usbhc_control_read_data(device_t *, void *, ipc_callid_t, ipc_call_t *); 53 53 static void remote_usbhc_control_read_status(device_t *, void *, ipc_callid_t, ipc_call_t *); 54 static void remote_usbhc_control_write(device_t *, void *, ipc_callid_t, ipc_call_t *); 55 static void remote_usbhc_control_read(device_t *, void *, ipc_callid_t, ipc_call_t *); 54 56 static void remote_usbhc_reserve_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *); 55 57 static void remote_usbhc_release_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *); … … 81 83 remote_usbhc_control_read_setup, 82 84 remote_usbhc_control_read_data, 83 remote_usbhc_control_read_status 85 remote_usbhc_control_read_status, 86 87 remote_usbhc_control_write, 88 remote_usbhc_control_read 84 89 }; 85 90 … … 95 100 ipc_callid_t caller; 96 101 void *buffer; 102 void *setup_packet; 97 103 size_t size; 98 104 } async_transaction_t; 99 105 106 static void async_transaction_destroy(async_transaction_t *trans) 107 { 108 if (trans == NULL) { 109 return; 110 } 111 112 if (trans->setup_packet != NULL) { 113 free(trans->setup_packet); 114 } 115 if (trans->buffer != NULL) { 116 free(trans->buffer); 117 } 118 119 free(trans); 120 } 121 122 static async_transaction_t *async_transaction_create(ipc_callid_t caller) 123 { 124 async_transaction_t *trans = malloc(sizeof(async_transaction_t)); 125 if (trans == NULL) { 126 return NULL; 127 } 128 129 trans->caller = caller; 130 trans->buffer = NULL; 131 trans->setup_packet = NULL; 132 trans->size = 0; 133 134 return trans; 135 } 136 100 137 void remote_usbhc_get_address(device_t *device, void *iface, 101 138 ipc_callid_t callid, ipc_call_t *call) … … 130 167 if (trans->buffer == NULL) { 131 168 ipc_answer_0(callid, EINVAL); 132 free(trans);169 async_transaction_destroy(trans); 133 170 return; 134 171 } … … 138 175 if (!async_data_read_receive(&cid, &accepted_size)) { 139 176 ipc_answer_0(callid, EINVAL); 177 async_transaction_destroy(trans); 140 178 return; 141 179 } … … 148 186 ipc_answer_1(callid, EOK, accepted_size); 149 187 150 free(trans->buffer); 151 free(trans); 188 async_transaction_destroy(trans); 152 189 } 153 190 … … 242 279 async_transaction_t *trans = (async_transaction_t *)arg; 243 280 244 // FIXME - answer according to outcome245 281 ipc_answer_0(trans->caller, outcome); 246 282 247 free(trans);283 async_transaction_destroy(trans); 248 284 } 249 285 … … 253 289 async_transaction_t *trans = (async_transaction_t *)arg; 254 290 255 // FIXME - answer according to outcome 256 ipc_answer_1(trans->caller, outcome, (sysarg_t)trans); 291 if (outcome != USB_OUTCOME_OK) { 292 ipc_answer_0(trans->caller, outcome); 293 async_transaction_destroy(trans); 294 return; 295 } 257 296 258 297 trans->size = actual_size; 298 ipc_answer_1(trans->caller, USB_OUTCOME_OK, (sysarg_t)trans); 259 299 } 260 300 … … 294 334 } 295 335 296 async_transaction_t *trans = malloc(sizeof(async_transaction_t)); 297 trans->caller = callid; 298 trans->buffer = buffer; 299 trans->size = len; 300 301 int rc = transfer_func(device, target, buffer, len, 302 callback_out, trans); 303 304 if (rc != EOK) { 305 ipc_answer_0(callid, rc); 336 async_transaction_t *trans = async_transaction_create(callid); 337 if (trans == NULL) { 306 338 if (buffer != NULL) { 307 339 free(buffer); 308 340 } 309 free(trans); 341 ipc_answer_0(callid, ENOMEM); 342 return; 343 } 344 345 trans->buffer = buffer; 346 trans->size = len; 347 348 int rc = transfer_func(device, target, buffer, len, 349 callback_out, trans); 350 351 if (rc != EOK) { 352 ipc_answer_0(callid, rc); 353 async_transaction_destroy(trans); 310 354 } 311 355 } … … 333 377 }; 334 378 335 async_transaction_t *trans = malloc(sizeof(async_transaction_t)); 336 trans->caller = callid; 379 async_transaction_t *trans = async_transaction_create(callid); 380 if (trans == NULL) { 381 ipc_answer_0(callid, ENOMEM); 382 return; 383 } 337 384 trans->buffer = malloc(len); 338 385 trans->size = len; … … 343 390 if (rc != EOK) { 344 391 ipc_answer_0(callid, rc); 345 free(trans->buffer); 346 free(trans); 392 async_transaction_destroy(trans); 347 393 } 348 394 } … … 388 434 }; 389 435 390 async_transaction_t *trans = malloc(sizeof(async_transaction_t)); 391 trans->caller = callid; 392 trans->buffer = NULL; 393 trans->size = 0; 436 async_transaction_t *trans = async_transaction_create(callid); 437 if (trans == NULL) { 438 ipc_answer_0(callid, ENOMEM); 439 return; 440 } 394 441 395 442 int rc; … … 410 457 if (rc != EOK) { 411 458 ipc_answer_0(callid, rc); 412 free(trans); 413 } 414 return; 459 async_transaction_destroy(trans); 460 } 415 461 } 416 462 … … 496 542 } 497 543 544 void remote_usbhc_control_write(device_t *device, void *iface, 545 ipc_callid_t callid, ipc_call_t *call) 546 { 547 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 548 assert(usb_iface != NULL); 549 550 if (!usb_iface->control_write) { 551 ipc_answer_0(callid, ENOTSUP); 552 return; 553 } 554 555 usb_target_t target = { 556 .address = DEV_IPC_GET_ARG1(*call), 557 .endpoint = DEV_IPC_GET_ARG2(*call) 558 }; 559 560 int rc; 561 562 void *setup_packet = NULL; 563 void *data_buffer = NULL; 564 size_t setup_packet_len = 0; 565 size_t data_buffer_len = 0; 566 567 rc = async_data_write_accept(&setup_packet, false, 568 1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len); 569 if (rc != EOK) { 570 ipc_answer_0(callid, rc); 571 return; 572 } 573 rc = async_data_write_accept(&data_buffer, false, 574 1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len); 575 if (rc != EOK) { 576 ipc_answer_0(callid, rc); 577 free(setup_packet); 578 return; 579 } 580 581 async_transaction_t *trans = async_transaction_create(callid); 582 if (trans == NULL) { 583 ipc_answer_0(callid, ENOMEM); 584 free(setup_packet); 585 free(data_buffer); 586 return; 587 } 588 trans->setup_packet = setup_packet; 589 trans->buffer = data_buffer; 590 trans->size = data_buffer_len; 591 592 rc = usb_iface->control_write(device, target, 593 setup_packet, setup_packet_len, 594 data_buffer, data_buffer_len, 595 callback_out, trans); 596 597 if (rc != EOK) { 598 ipc_answer_0(callid, rc); 599 async_transaction_destroy(trans); 600 } 601 } 602 603 604 void remote_usbhc_control_read(device_t *device, void *iface, 605 ipc_callid_t callid, ipc_call_t *call) 606 { 607 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface; 608 assert(usb_iface != NULL); 609 610 if (!usb_iface->control_read) { 611 ipc_answer_0(callid, ENOTSUP); 612 return; 613 } 614 615 size_t data_len = DEV_IPC_GET_ARG3(*call); 616 usb_target_t target = { 617 .address = DEV_IPC_GET_ARG1(*call), 618 .endpoint = DEV_IPC_GET_ARG2(*call) 619 }; 620 621 int rc; 622 623 void *setup_packet = NULL; 624 size_t setup_packet_len = 0; 625 626 rc = async_data_write_accept(&setup_packet, false, 627 1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len); 628 if (rc != EOK) { 629 ipc_answer_0(callid, rc); 630 return; 631 } 632 633 async_transaction_t *trans = async_transaction_create(callid); 634 if (trans == NULL) { 635 ipc_answer_0(callid, ENOMEM); 636 free(setup_packet); 637 return; 638 } 639 trans->setup_packet = setup_packet; 640 trans->size = data_len; 641 trans->buffer = malloc(data_len); 642 if (trans->buffer == NULL) { 643 ipc_answer_0(callid, ENOMEM); 644 async_transaction_destroy(trans); 645 return; 646 } 647 648 rc = usb_iface->control_read(device, target, 649 setup_packet, setup_packet_len, 650 trans->buffer, trans->size, 651 callback_in, trans); 652 653 if (rc != EOK) { 654 ipc_answer_0(callid, rc); 655 async_transaction_destroy(trans); 656 } 657 } 658 498 659 499 660 -
uspace/lib/drv/include/usbhc_iface.h
rba5ab09 raec2ad4 201 201 IPC_M_USBHC_CONTROL_READ_STATUS, 202 202 203 /** Issue control WRITE transfer. 204 * See explanation at usb_iface_funcs_t (OUT transaction) for 205 * call parameters. 206 * This call is immediately followed by two IPC data writes 207 * from the caller (setup packet and actual data). 208 */ 209 IPC_M_USBHC_CONTROL_WRITE, 210 211 /** Issue control WRITE transfer. 212 * See explanation at usb_iface_funcs_t (IN transaction) for 213 * call parameters. 214 * This call is immediately followed by IPC data read from the caller 215 * (setup packet). 216 * Actual data are retrieved through IPC_M_USBHC_GET_BUFFER. 217 */ 218 IPC_M_USBHC_CONTROL_READ, 203 219 204 220 /* IPC_M_USB_ */ … … 249 265 int (*control_read_status)(device_t *, usb_target_t, 250 266 usbhc_iface_transfer_out_callback_t, void *); 267 268 int (*control_write)(device_t *, usb_target_t, 269 void *, size_t, void *, size_t, 270 usbhc_iface_transfer_out_callback_t, void *); 271 272 int (*control_read)(device_t *, usb_target_t, 273 void *, size_t, void *, size_t, 274 usbhc_iface_transfer_in_callback_t, void *); 251 275 } usbhc_iface_t; 252 276 -
uspace/lib/fs/libfs.c
rba5ab09 raec2ad4 102 102 * Ask VFS for callback connection. 103 103 */ 104 ipc_connect_to_me(vfs_phone, 0, 0, 0, ®->vfs_phonehash); 104 sysarg_t taskhash; 105 ipc_connect_to_me(vfs_phone, 0, 0, 0, &taskhash, ®->vfs_phonehash); 105 106 106 107 /* … … 131 132 * Create a connection fibril to handle the callback connection. 132 133 */ 133 async_new_connection( reg->vfs_phonehash, 0, NULL, conn);134 async_new_connection(taskhash, reg->vfs_phonehash, 0, NULL, conn); 134 135 135 136 /* -
uspace/lib/net/il/il_skel.c
rba5ab09 raec2ad4 115 115 goto out; 116 116 117 sysarg_t phonehash; 118 rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, &phonehash); 117 rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, NULL, NULL); 119 118 if (rc != EOK) 120 119 goto out; -
uspace/lib/net/nil/nil_skel.c
rba5ab09 raec2ad4 115 115 goto out; 116 116 117 sysarg_t phonehash; 118 rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, &phonehash); 117 rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, NULL, NULL); 119 118 if (rc != EOK) 120 119 goto out; -
uspace/lib/net/tl/tl_skel.c
rba5ab09 raec2ad4 117 117 goto out; 118 118 119 sysarg_t phonehash; 120 rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, &phonehash); 119 rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, NULL, NULL); 121 120 if (rc != EOK) 122 121 goto out; -
uspace/lib/usb/Makefile
rba5ab09 raec2ad4 43 43 src/hidparser.c \ 44 44 src/localdrv.c \ 45 src/pipes.c \ 45 46 src/recognise.c \ 46 47 src/remotedrv.c \ 48 src/request.c \ 47 49 src/usb.c \ 48 50 src/usbdrvreq.c \ -
uspace/lib/usb/include/usb/classes/hid.h
rba5ab09 raec2ad4 37 37 38 38 #include <usb/usb.h> 39 #include <driver.h>40 39 #include <usb/classes/hidparser.h> 41 40 #include <usb/descriptor.h> … … 101 100 } __attribute__ ((packed)) usb_standard_hid_descriptor_t; 102 101 103 /**104 *105 */106 typedef struct {107 usb_standard_interface_descriptor_t iface_desc;108 usb_standard_endpoint_descriptor_t *endpoints;109 usb_standard_hid_descriptor_t hid_desc;110 uint8_t *report_desc;111 //usb_standard_hid_class_descriptor_info_t *class_desc_info;112 //uint8_t **class_descs;113 } usb_hid_iface_t;114 115 /**116 *117 */118 typedef struct {119 usb_standard_configuration_descriptor_t config_descriptor;120 usb_hid_iface_t *interfaces;121 } usb_hid_configuration_t;122 123 /**124 * @brief USB/HID keyboard device type.125 *126 * Quite dummy right now.127 */128 typedef struct {129 device_t *device;130 usb_hid_configuration_t *conf;131 usb_address_t address;132 usb_endpoint_t poll_endpoint;133 usb_hid_report_parser_t *parser;134 } usb_hid_dev_kbd_t;135 136 // TODO: more configurations!137 102 138 103 #endif -
uspace/lib/usb/include/usb/debug.h
rba5ab09 raec2ad4 1 1 /* 2 * Copyright (c) 2010 Vojtech Horky2 * Copyright (c) 2010-2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 37 37 #include <stdio.h> 38 38 #include <usb/usb.h> 39 #include <assert.h> 39 40 40 41 void usb_dprintf(const char *tag, int level, const char *format, ...); … … 44 45 const uint8_t *, size_t); 45 46 47 /** Logging level. */ 48 typedef enum { 49 USB_LOG_LEVEL_FATAL, 50 USB_LOG_LEVEL_ERROR, 51 USB_LOG_LEVEL_WARNING, 52 USB_LOG_LEVEL_INFO, 53 USB_LOG_LEVEL_DEBUG, 54 USB_LOG_LEVEL_DEBUG2, 55 USB_LOG_LEVEL_MAX 56 } usb_log_level_t; 57 58 59 void usb_log_enable(usb_log_level_t, const char *); 60 61 void usb_log_printf(usb_log_level_t, const char *, ...); 62 63 #define usb_log_fatal(format, ...) \ 64 usb_log_printf(USB_LOG_LEVEL_FATAL, format, ##__VA_ARGS__) 65 66 #define usb_log_error(format, ...) \ 67 usb_log_printf(USB_LOG_LEVEL_ERROR, format, ##__VA_ARGS__) 68 69 #define usb_log_warning(format, ...) \ 70 usb_log_printf(USB_LOG_LEVEL_WARNING, format, ##__VA_ARGS__) 71 72 #define usb_log_info(format, ...) \ 73 usb_log_printf(USB_LOG_LEVEL_INFO, format, ##__VA_ARGS__) 74 75 #define usb_log_debug(format, ...) \ 76 usb_log_printf(USB_LOG_LEVEL_DEBUG, format, ##__VA_ARGS__) 77 78 #define usb_log_debug2(format, ...) \ 79 usb_log_printf(USB_LOG_LEVEL_DEBUG2, format, ##__VA_ARGS__) 80 81 82 46 83 #endif 47 84 /** -
uspace/lib/usb/include/usb/usb.h
rba5ab09 raec2ad4 37 37 38 38 #include <sys/types.h> 39 #include <byteorder.h> 39 40 #include <ipc/ipc.h> 41 42 /** Convert 16bit value from native (host) endianness to USB endianness. */ 43 #define uint16_host2usb(n) host2uint16_t_le((n)) 44 45 /** Convert 32bit value from native (host) endianness to USB endianness. */ 46 #define uint32_host2usb(n) host2uint32_t_le((n)) 47 48 /** Convert 16bit value from USB endianness into native (host) one. */ 49 #define uint16_usb2host(n) uint16_t_le2host((n)) 50 51 /** Convert 32bit value from USB endianness into native (host) one. */ 52 #define uint32_usb2host(n) uint32_t_le2host((n)) 53 40 54 41 55 /** USB transfer type. */ … … 52 66 typedef enum { 53 67 USB_DIRECTION_IN, 54 USB_DIRECTION_OUT 68 USB_DIRECTION_OUT, 69 USB_DIRECTION_BOTH 55 70 } usb_direction_t; 56 71 -
uspace/lib/usb/include/usb/usbdrv.h
rba5ab09 raec2ad4 70 70 usb_handle_t *); 71 71 72 int usb_drv_async_control_write(int, usb_target_t, 73 void *, size_t, void *, size_t, usb_handle_t *); 74 72 75 int usb_drv_psync_control_write_setup(int, usb_target_t, void *, size_t); 73 76 int usb_drv_psync_control_write_data(int, usb_target_t, void *, size_t); … … 77 80 void *, size_t, void *, size_t); 78 81 79 80 82 int usb_drv_async_control_read_setup(int, usb_target_t, 81 83 void *, size_t, usb_handle_t *); … … 84 86 int usb_drv_async_control_read_status(int, usb_target_t, 85 87 usb_handle_t *); 88 89 int usb_drv_async_control_read(int, usb_target_t, 90 void *, size_t, void *, size_t, size_t *, usb_handle_t *); 86 91 87 92 int usb_drv_psync_control_read_setup(int, usb_target_t, void *, size_t); -
uspace/lib/usb/src/debug.c
rba5ab09 raec2ad4 1 1 /* 2 * Copyright (c) 2010 Vojtech Horky2 * Copyright (c) 2010-2011 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 61 61 static FIBRIL_MUTEX_INITIALIZE(tag_list_guard); 62 62 63 /** Level of logging messages. */ 64 static usb_log_level_t log_level = USB_LOG_LEVEL_WARNING; 65 /** Prefix for logging messages. */ 66 static const char *log_prefix = "usb"; 67 /** Serialization mutex for logging functions. */ 68 static FIBRIL_MUTEX_INITIALIZE(log_serializer); 69 63 70 /** Find or create new tag with given name. 64 71 * … … 155 162 } 156 163 164 /** Enable logging. 165 * 166 * @param level Maximal enabled level (including this one). 167 * @param message_prefix Prefix for each printed message. 168 */ 169 void usb_log_enable(usb_log_level_t level, const char *message_prefix) 170 { 171 log_prefix = message_prefix; 172 log_level = level; 173 } 174 175 176 static const char *log_level_name(usb_log_level_t level) 177 { 178 switch (level) { 179 case USB_LOG_LEVEL_FATAL: 180 return " FATAL"; 181 case USB_LOG_LEVEL_ERROR: 182 return " ERROR"; 183 case USB_LOG_LEVEL_WARNING: 184 return " WARN"; 185 case USB_LOG_LEVEL_INFO: 186 return " info"; 187 default: 188 return ""; 189 } 190 } 191 192 /** Print logging message. 193 * 194 * @param level Verbosity level of the message. 195 * @param format Formatting directive. 196 */ 197 void usb_log_printf(usb_log_level_t level, const char *format, ...) 198 { 199 if (level > log_level) { 200 return; 201 } 202 203 FILE *stream = NULL; 204 switch (level) { 205 case USB_LOG_LEVEL_FATAL: 206 case USB_LOG_LEVEL_ERROR: 207 stream = stderr; 208 break; 209 default: 210 stream = stdout; 211 break; 212 } 213 assert(stream != NULL); 214 215 va_list args; 216 va_start(args, format); 217 218 fibril_mutex_lock(&log_serializer); 219 fprintf(stream, "[%s]%s: ", log_prefix, log_level_name(level)); 220 vfprintf(stream, format, args); 221 fibril_mutex_unlock(&log_serializer); 222 223 va_end(args); 224 } 157 225 158 226 /** -
uspace/lib/usb/src/hidparser.c
rba5ab09 raec2ad4 35 35 #include <usb/classes/hidparser.h> 36 36 #include <errno.h> 37 #include <stdio.h> 37 38 38 39 /** Parse HID report descriptor. … … 120 121 item.logical_max = 255; 121 122 122 if (size != 8){123 return -1;123 if (size != 8) { 124 return ERANGE; 124 125 } 125 126 126 127 uint8_t keys[6]; 127 for (i=item.offset; i<item.count; i++) {128 keys[i -2] = data[i];128 for (i = 0; i < item.count; i++) { 129 keys[i] = data[i + item.offset]; 129 130 } 130 131 -
uspace/lib/usb/src/usbdrv.c
rba5ab09 raec2ad4 495 495 } 496 496 497 /** Issue whole control write transfer. */ 498 int usb_drv_async_control_write(int phone, usb_target_t target, 499 void *setup_packet, size_t setup_packet_size, 500 void *buffer, size_t buffer_size, 501 usb_handle_t *handle) 502 { 503 // FIXME - check input parameters instead of asserting them 504 assert(phone > 0); 505 assert(setup_packet != NULL); 506 assert(setup_packet_size > 0); 507 assert(buffer != NULL); 508 assert(buffer_size > 0); 509 assert(handle != NULL); 510 511 transfer_info_t *transfer 512 = (transfer_info_t *) malloc(sizeof(transfer_info_t)); 513 if (transfer == NULL) { 514 return ENOMEM; 515 } 516 517 transfer->size_transferred = NULL; 518 transfer->buffer = NULL; 519 transfer->size = 0; 520 transfer->phone = phone; 521 522 int rc; 523 524 transfer->request = async_send_3(phone, 525 DEV_IFACE_ID(USBHC_DEV_IFACE), 526 IPC_M_USBHC_CONTROL_WRITE, 527 target.address, target.endpoint, 528 &transfer->reply); 529 530 rc = async_data_write_start(phone, setup_packet, setup_packet_size); 531 if (rc != EOK) { 532 async_wait_for(transfer->request, NULL); 533 return rc; 534 } 535 536 rc = async_data_write_start(phone, buffer, buffer_size); 537 if (rc != EOK) { 538 async_wait_for(transfer->request, NULL); 539 return rc; 540 } 541 542 *handle = (usb_handle_t) transfer; 543 544 return EOK; 545 } 546 497 547 /** Start control read transfer. */ 498 548 int usb_drv_async_control_read_setup(int phone, usb_target_t target, … … 530 580 } 531 581 582 /** Issue whole control read transfer. */ 583 int usb_drv_async_control_read(int phone, usb_target_t target, 584 void *setup_packet, size_t setup_packet_size, 585 void *buffer, size_t buffer_size, size_t *actual_size, 586 usb_handle_t *handle) 587 { 588 // FIXME - check input parameters instead of asserting them 589 assert(phone > 0); 590 assert(setup_packet != NULL); 591 assert(setup_packet_size > 0); 592 assert(buffer != NULL); 593 assert(buffer_size > 0); 594 assert(handle != NULL); 595 596 transfer_info_t *transfer 597 = (transfer_info_t *) malloc(sizeof(transfer_info_t)); 598 if (transfer == NULL) { 599 return ENOMEM; 600 } 601 602 transfer->size_transferred = actual_size; 603 transfer->buffer = buffer; 604 transfer->size = buffer_size; 605 transfer->phone = phone; 606 607 int rc; 608 609 transfer->request = async_send_4(phone, 610 DEV_IFACE_ID(USBHC_DEV_IFACE), 611 IPC_M_USBHC_CONTROL_READ, 612 target.address, target.endpoint, 613 buffer_size, 614 &transfer->reply); 615 616 rc = async_data_write_start(phone, setup_packet, setup_packet_size); 617 if (rc != EOK) { 618 async_wait_for(transfer->request, NULL); 619 return rc; 620 } 621 622 *handle = (usb_handle_t) transfer; 623 624 return EOK; 625 } 626 532 627 /** 533 628 * @} -
uspace/lib/usbvirt/src/main.c
rba5ab09 raec2ad4 221 221 222 222 sysarg_t phonehash; 223 rc = ipc_connect_to_me(hcd_phone, 0, 0, 0, &phonehash); 223 sysarg_t taskhash; 224 rc = ipc_connect_to_me(hcd_phone, 0, 0, 0, &taskhash, &phonehash); 224 225 if (rc != EOK) { 225 226 printf("ipc_connect_to_me() failed\n"); … … 233 234 virtual_device->id = 0; 234 235 235 async_new_connection( phonehash, 0, NULL, callback_connection);236 async_new_connection(taskhash, phonehash, 0, NULL, callback_connection); 236 237 237 238 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.
