- Timestamp:
- 2011-08-21T12:04:27Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8a6ba94
- Parents:
- 1877128 (diff), a6480d5 (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
- Files:
-
- 2 added
- 30 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/Makefile
r1877128 rd1e196f7 37 37 app/blkdump \ 38 38 app/bnchmark \ 39 app/devctl \ 39 40 app/edit \ 40 41 app/ext2info \ -
uspace/app/lsusb/main.c
r1877128 rd1e196f7 81 81 } 82 82 char path[MAX_PATH_LENGTH]; 83 rc = devman_ get_device_path(dev_handle, path, MAX_PATH_LENGTH);83 rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH); 84 84 if (rc != EOK) { 85 85 continue; … … 120 120 } 121 121 char path[MAX_PATH_LENGTH]; 122 rc = devman_ get_device_path(hc_handle, path, MAX_PATH_LENGTH);122 rc = devman_fun_get_path(hc_handle, path, MAX_PATH_LENGTH); 123 123 if (rc != EOK) { 124 124 printf(NAME ": Error resolving path of HC with SID %" -
uspace/app/mkbd/main.c
r1877128 rd1e196f7 240 240 241 241 char path[MAX_PATH_LENGTH]; 242 rc = devman_ get_device_path(dev_handle, path, MAX_PATH_LENGTH);242 rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH); 243 243 if (rc != EOK) { 244 244 return ENOMEM; -
uspace/app/tester/hw/serial/serial1.c
r1877128 rd1e196f7 72 72 73 73 devman_handle_t handle; 74 int res = devman_ device_get_handle("/hw/pci0/00:01.0/com1/a", &handle,74 int res = devman_fun_get_handle("/hw/pci0/00:01.0/com1/a", &handle, 75 75 IPC_FLAG_BLOCKING); 76 76 if (res != EOK) -
uspace/lib/c/arch/ia32/Makefile.common
r1877128 rd1e196f7 28 28 29 29 CLANG_ARCH = i386 30 GCC_CFLAGS += -march=pentium -fno-omit-frame-pointer 30 31 ifeq ($(PROCESSOR),i486) 32 GCC_CFLAGS += -march=i486 -fno-omit-frame-pointer 33 else 34 GCC_CFLAGS += -march=pentium -fno-omit-frame-pointer 35 endif 31 36 32 37 ENDIANESS = LE -
uspace/lib/c/arch/ia32/Makefile.inc
r1877128 rd1e196f7 28 28 29 29 ARCH_SOURCES = \ 30 arch/$(UARCH)/src/entry. s\30 arch/$(UARCH)/src/entry.S \ 31 31 arch/$(UARCH)/src/entryjmp.s \ 32 32 arch/$(UARCH)/src/thread_entry.s \ -
uspace/lib/c/arch/ia32/include/ddi.h
r1877128 rd1e196f7 41 41 static inline uint8_t pio_read_8(ioport8_t *port) 42 42 { 43 uint8_t val; 44 45 asm volatile ( 46 "inb %w[port], %b[val]\n" 47 : [val] "=a" (val) 48 : [port] "d" (port) 49 ); 50 51 return val; 43 if (port < (ioport8_t *) IO_SPACE_BOUNDARY) { 44 uint8_t val; 45 46 asm volatile ( 47 "inb %w[port], %b[val]\n" 48 : [val] "=a" (val) 49 : [port] "d" (port) 50 ); 51 52 return val; 53 } else 54 return (uint8_t) *port; 52 55 } 53 56 54 57 static inline uint16_t pio_read_16(ioport16_t *port) 55 58 { 56 uint16_t val; 57 58 asm volatile ( 59 "inw %w[port], %w[val]\n" 60 : [val] "=a" (val) 61 : [port] "d" (port) 62 ); 63 64 return val; 59 if (port < (ioport16_t *) IO_SPACE_BOUNDARY) { 60 uint16_t val; 61 62 asm volatile ( 63 "inw %w[port], %w[val]\n" 64 : [val] "=a" (val) 65 : [port] "d" (port) 66 ); 67 68 return val; 69 } else 70 return (uint16_t) *port; 65 71 } 66 72 67 73 static inline uint32_t pio_read_32(ioport32_t *port) 68 74 { 69 uint32_t val; 70 71 asm volatile ( 72 "inl %w[port], %[val]\n" 73 : [val] "=a" (val) 74 : [port] "d" (port) 75 ); 76 77 return val; 75 if (port < (ioport32_t *) IO_SPACE_BOUNDARY) { 76 uint32_t val; 77 78 asm volatile ( 79 "inl %w[port], %[val]\n" 80 : [val] "=a" (val) 81 : [port] "d" (port) 82 ); 83 84 return val; 85 } else 86 return (uint32_t) *port; 78 87 } 79 88 80 89 static inline void pio_write_8(ioport8_t *port, uint8_t val) 81 90 { 82 asm volatile ( 83 "outb %b[val], %w[port]\n" 84 :: [val] "a" (val), [port] "d" (port) 85 ); 91 if (port < (ioport8_t *) IO_SPACE_BOUNDARY) { 92 asm volatile ( 93 "outb %b[val], %w[port]\n" 94 :: [val] "a" (val), [port] "d" (port) 95 ); 96 } else 97 *port = val; 86 98 } 87 99 88 100 static inline void pio_write_16(ioport16_t *port, uint16_t val) 89 101 { 90 asm volatile ( 91 "outw %w[val], %w[port]\n" 92 :: [val] "a" (val), [port] "d" (port) 93 ); 102 if (port < (ioport16_t *) IO_SPACE_BOUNDARY) { 103 asm volatile ( 104 "outw %w[val], %w[port]\n" 105 :: [val] "a" (val), [port] "d" (port) 106 ); 107 } else 108 *port = val; 94 109 } 95 110 96 111 static inline void pio_write_32(ioport32_t *port, uint32_t val) 97 112 { 98 asm volatile ( 99 "outl %[val], %w[port]\n" 100 :: [val] "a" (val), [port] "d" (port) 101 ); 113 if (port < (ioport32_t *) IO_SPACE_BOUNDARY) { 114 asm volatile ( 115 "outl %[val], %w[port]\n" 116 :: [val] "a" (val), [port] "d" (port) 117 ); 118 } else 119 *port = val; 102 120 } 103 121 -
uspace/lib/c/arch/ia32/src/entry.S
r1877128 rd1e196f7 47 47 # Do not set %gs, it contains descriptor that can see TLS 48 48 49 #ifndef PROCESSOR_i486 49 50 # Detect the mechanism used for making syscalls 50 51 movl $(INTEL_CPUID_STANDARD), %eax … … 52 53 bt $(INTEL_SEP), %edx 53 54 jnc 0f 54 leal __syscall_fast_func, %eax 55 movl $__syscall_fast, (%eax) 56 0: 55 leal __syscall_fast_func, %eax 56 movl $__syscall_fast, (%eax) 57 0: 58 #endif 59 57 60 # 58 61 # Create the first stack frame. -
uspace/lib/c/generic/async.c
r1877128 rd1e196f7 98 98 #include <ipc/ipc.h> 99 99 #include <async.h> 100 #include "private/async.h" 100 101 #undef LIBC_ASYNC_C_ 101 102 … … 112 113 #include <mem.h> 113 114 #include <stdlib.h> 114 #include "private/async.h"115 #include <macros.h> 115 116 116 117 #define CLIENT_HASH_TABLE_BUCKETS 32 … … 138 139 link_t link; 139 140 140 sysarg_t in_task_hash;141 task_id_t in_task_id; 141 142 atomic_t refcnt; 142 143 void *data; … … 150 151 link_t link; 151 152 152 /** Incoming client task hash. */153 sysarg_t in_task_hash;153 /** Incoming client task ID. */ 154 task_id_t in_task_id; 154 155 155 156 /** Incoming phone hash. */ … … 283 284 { 284 285 assert(key); 286 assert(keys == 2); 285 287 assert(item); 286 288 287 289 client_t *client = hash_table_get_instance(item, client_t, link); 288 return (key[0] == client->in_task_hash); 290 return (key[0] == LOWER32(client->in_task_id) && 291 (key[1] == UPPER32(client->in_task_id))); 289 292 } 290 293 … … 574 577 } 575 578 576 static client_t *async_client_get(sysarg_t client_hash, bool create) 577 { 578 unsigned long key = client_hash; 579 static client_t *async_client_get(task_id_t client_id, bool create) 580 { 581 unsigned long key[2] = { 582 LOWER32(client_id), 583 UPPER32(client_id), 584 }; 579 585 client_t *client = NULL; 580 586 581 587 futex_down(&async_futex); 582 link_t *lnk = hash_table_find(&client_hash_table, &key);588 link_t *lnk = hash_table_find(&client_hash_table, key); 583 589 if (lnk) { 584 590 client = hash_table_get_instance(lnk, client_t, link); … … 587 593 client = malloc(sizeof(client_t)); 588 594 if (client) { 589 client->in_task_ hash = client_hash;595 client->in_task_id = client_id; 590 596 client->data = async_client_data_create(); 591 597 592 598 atomic_set(&client->refcnt, 1); 593 hash_table_insert(&client_hash_table, &key, &client->link);599 hash_table_insert(&client_hash_table, key, &client->link); 594 600 } 595 601 } … … 602 608 { 603 609 bool destroy; 604 unsigned long key = client->in_task_hash; 610 unsigned long key[2] = { 611 LOWER32(client->in_task_id), 612 UPPER32(client->in_task_id) 613 }; 605 614 606 615 futex_down(&async_futex); 607 616 608 617 if (atomic_predec(&client->refcnt) == 0) { 609 hash_table_remove(&client_hash_table, &key, 1);618 hash_table_remove(&client_hash_table, key, 2); 610 619 destroy = true; 611 620 } else … … 628 637 } 629 638 630 void *async_get_client_data_by_ hash(sysarg_t client_hash)631 { 632 client_t *client = async_client_get(client_ hash, false);639 void *async_get_client_data_by_id(task_id_t client_id) 640 { 641 client_t *client = async_client_get(client_id, false); 633 642 if (!client) 634 643 return NULL; … … 641 650 } 642 651 643 void async_put_client_data_by_ hash(sysarg_t client_hash)644 { 645 client_t *client = async_client_get(client_ hash, false);652 void async_put_client_data_by_id(task_id_t client_id) 653 { 654 client_t *client = async_client_get(client_id, false); 646 655 647 656 assert(client); … … 680 689 */ 681 690 682 client_t *client = async_client_get(fibril_connection->in_task_ hash, true);691 client_t *client = async_client_get(fibril_connection->in_task_id, true); 683 692 if (!client) { 684 693 ipc_answer_0(fibril_connection->callid, ENOMEM); … … 737 746 * particular fibrils. 738 747 * 739 * @param in_task_ hashIdentification of the incoming connection.748 * @param in_task_id Identification of the incoming connection. 740 749 * @param in_phone_hash Identification of the incoming connection. 741 750 * @param callid Hash of the opening IPC_M_CONNECT_ME_TO call. … … 751 760 * 752 761 */ 753 fid_t async_new_connection( sysarg_t in_task_hash, sysarg_t in_phone_hash,762 fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash, 754 763 ipc_callid_t callid, ipc_call_t *call, 755 764 async_client_conn_t cfibril, void *carg) … … 763 772 } 764 773 765 conn->in_task_ hash = in_task_hash;774 conn->in_task_id = in_task_id; 766 775 conn->in_phone_hash = in_phone_hash; 767 776 list_initialize(&conn->msg_queue); … … 822 831 case IPC_M_CONNECT_ME_TO: 823 832 /* Open new connection with fibril, etc. */ 824 async_new_connection(call->in_task_ hash, IPC_GET_ARG5(*call),833 async_new_connection(call->in_task_id, IPC_GET_ARG5(*call), 825 834 callid, call, client_connection, NULL); 826 835 return; … … 970 979 { 971 980 if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 972 1, &client_hash_table_ops))981 2, &client_hash_table_ops)) 973 982 abort(); 974 983 … … 986 995 session_ns->arg2 = 0; 987 996 session_ns->arg3 = 0; 997 998 fibril_mutex_initialize(&session_ns->remote_state_mtx); 999 session_ns->remote_state_data = NULL; 988 1000 989 1001 list_initialize(&session_ns->exch_list); … … 1463 1475 return ENOENT; 1464 1476 1465 sysarg_t task_hash;1466 1477 sysarg_t phone_hash; 1467 int rc = async_req_3_5(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, 1468 NULL, NULL, NULL, &task_hash, &phone_hash); 1478 sysarg_t rc; 1479 1480 aid_t req; 1481 ipc_call_t answer; 1482 req = async_send_3(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, 1483 &answer); 1484 async_wait_for(req, &rc); 1469 1485 if (rc != EOK) 1470 return rc; 1471 1486 return (int) rc; 1487 1488 phone_hash = IPC_GET_ARG5(answer); 1489 1472 1490 if (client_receiver != NULL) 1473 async_new_connection( task_hash, phone_hash, 0, NULL,1491 async_new_connection(answer.in_task_id, phone_hash, 0, NULL, 1474 1492 client_receiver, carg); 1475 1493 … … 1546 1564 sess->arg3 = 0; 1547 1565 1566 fibril_mutex_initialize(&sess->remote_state_mtx); 1567 sess->remote_state_data = NULL; 1568 1548 1569 list_initialize(&sess->exch_list); 1549 1570 fibril_mutex_initialize(&sess->mutex); … … 1627 1648 sess->arg3 = arg3; 1628 1649 1650 fibril_mutex_initialize(&sess->remote_state_mtx); 1651 sess->remote_state_data = NULL; 1652 1629 1653 list_initialize(&sess->exch_list); 1630 1654 fibril_mutex_initialize(&sess->mutex); … … 1632 1656 1633 1657 return sess; 1658 } 1659 1660 /** Set arguments for new connections. 1661 * 1662 * FIXME This is an ugly hack to work around the problem that parallel 1663 * exchanges are implemented using parallel connections. When we create 1664 * a callback session, the framework does not know arguments for the new 1665 * connections. 1666 * 1667 * The proper solution seems to be to implement parallel exchanges using 1668 * tagging. 1669 */ 1670 void async_sess_args_set(async_sess_t *sess, sysarg_t arg1, sysarg_t arg2, 1671 sysarg_t arg3) 1672 { 1673 sess->arg1 = arg1; 1674 sess->arg2 = arg2; 1675 sess->arg3 = arg3; 1634 1676 } 1635 1677 … … 1677 1719 sess->arg3 = arg3; 1678 1720 1721 fibril_mutex_initialize(&sess->remote_state_mtx); 1722 sess->remote_state_data = NULL; 1723 1679 1724 list_initialize(&sess->exch_list); 1680 1725 fibril_mutex_initialize(&sess->mutex); … … 1707 1752 sess->arg2 = 0; 1708 1753 sess->arg3 = 0; 1754 1755 fibril_mutex_initialize(&sess->remote_state_mtx); 1756 sess->remote_state_data = NULL; 1709 1757 1710 1758 list_initialize(&sess->exch_list); … … 2371 2419 sess->arg3 = 0; 2372 2420 2421 fibril_mutex_initialize(&sess->remote_state_mtx); 2422 sess->remote_state_data = NULL; 2423 2373 2424 list_initialize(&sess->exch_list); 2374 2425 fibril_mutex_initialize(&sess->mutex); … … 2417 2468 sess->arg3 = 0; 2418 2469 2470 fibril_mutex_initialize(&sess->remote_state_mtx); 2471 sess->remote_state_data = NULL; 2472 2419 2473 list_initialize(&sess->exch_list); 2420 2474 fibril_mutex_initialize(&sess->mutex); … … 2458 2512 sess->arg2 = 0; 2459 2513 sess->arg3 = 0; 2514 2515 fibril_mutex_initialize(&sess->remote_state_mtx); 2516 sess->remote_state_data = NULL; 2460 2517 2461 2518 list_initialize(&sess->exch_list); … … 2499 2556 } 2500 2557 2558 /** Lock and get session remote state 2559 * 2560 * Lock and get the local replica of the remote state 2561 * in stateful sessions. The call should be paired 2562 * with async_remote_state_release*(). 2563 * 2564 * @param[in] sess Stateful session. 2565 * 2566 * @return Local replica of the remote state. 2567 * 2568 */ 2569 void *async_remote_state_acquire(async_sess_t *sess) 2570 { 2571 fibril_mutex_lock(&sess->remote_state_mtx); 2572 return sess->remote_state_data; 2573 } 2574 2575 /** Update the session remote state 2576 * 2577 * Update the local replica of the remote state 2578 * in stateful sessions. The remote state must 2579 * be already locked. 2580 * 2581 * @param[in] sess Stateful session. 2582 * @param[in] state New local replica of the remote state. 2583 * 2584 */ 2585 void async_remote_state_update(async_sess_t *sess, void *state) 2586 { 2587 assert(fibril_mutex_is_locked(&sess->remote_state_mtx)); 2588 sess->remote_state_data = state; 2589 } 2590 2591 /** Release the session remote state 2592 * 2593 * Unlock the local replica of the remote state 2594 * in stateful sessions. 2595 * 2596 * @param[in] sess Stateful session. 2597 * 2598 */ 2599 void async_remote_state_release(async_sess_t *sess) 2600 { 2601 assert(fibril_mutex_is_locked(&sess->remote_state_mtx)); 2602 2603 fibril_mutex_unlock(&sess->remote_state_mtx); 2604 } 2605 2606 /** Release the session remote state and end an exchange 2607 * 2608 * Unlock the local replica of the remote state 2609 * in stateful sessions. This is convenience function 2610 * which gets the session pointer from the exchange 2611 * and also ends the exchange. 2612 * 2613 * @param[in] exch Stateful session's exchange. 2614 * 2615 */ 2616 void async_remote_state_release_exchange(async_exch_t *exch) 2617 { 2618 if (exch == NULL) 2619 return; 2620 2621 async_sess_t *sess = exch->sess; 2622 assert(fibril_mutex_is_locked(&sess->remote_state_mtx)); 2623 2624 async_exchange_end(exch); 2625 fibril_mutex_unlock(&sess->remote_state_mtx); 2626 } 2627 2501 2628 /** @} 2502 2629 */ -
uspace/lib/c/generic/async_obsolete.c
r1877128 rd1e196f7 38 38 #include <async.h> 39 39 #include <async_obsolete.h> 40 #include "private/async.h" 40 41 #undef LIBC_ASYNC_C_ 41 42 #undef LIBC_ASYNC_OBSOLETE_C_ … … 44 45 #include <malloc.h> 45 46 #include <errno.h> 46 #include "private/async.h"47 47 48 48 /** Send message and return id of the sent message. -
uspace/lib/c/generic/devman.c
r1877128 rd1e196f7 1 1 /* 2 2 * Copyright (c) 2007 Josef Cejka 3 * Copyright (c) 20 09Jiri Svoboda3 * Copyright (c) 2011 Jiri Svoboda 4 4 * Copyright (c) 2010 Lenka Trochtova 5 5 * All rights reserved. … … 89 89 if (devman_driver_block_sess == NULL) 90 90 devman_driver_block_sess = 91 service_connect_blocking(EXCHANGE_ SERIALIZE,91 service_connect_blocking(EXCHANGE_PARALLEL, 92 92 SERVICE_DEVMAN, DEVMAN_DRIVER, 0); 93 93 } … … 138 138 if (devman_driver_sess == NULL) 139 139 devman_driver_sess = 140 service_connect(EXCHANGE_ SERIALIZE, SERVICE_DEVMAN,140 service_connect(EXCHANGE_PARALLEL, SERVICE_DEVMAN, 141 141 DEVMAN_DRIVER, 0); 142 142 … … 195 195 196 196 exch = devman_exchange_begin(DEVMAN_DRIVER); 197 async_connect_to_me(exch, 0, 0, 0, NULL, NULL);197 async_connect_to_me(exch, 0, 0, 0, conn, NULL); 198 198 devman_exchange_end(exch); 199 199 … … 342 342 } 343 343 344 int devman_ device_get_handle(const char *pathname, devman_handle_t *handle,344 int devman_fun_get_handle(const char *pathname, devman_handle_t *handle, 345 345 unsigned int flags) 346 346 { … … 383 383 } 384 384 385 int devman_get_device_path(devman_handle_t handle, char *path, size_t path_size) 385 static int devman_get_str_internal(sysarg_t method, sysarg_t arg1, char *buf, 386 size_t buf_size) 387 { 388 async_exch_t *exch; 389 ipc_call_t dreply; 390 size_t act_size; 391 sysarg_t dretval; 392 393 exch = devman_exchange_begin_blocking(LOC_PORT_CONSUMER); 394 395 ipc_call_t answer; 396 aid_t req = async_send_1(exch, method, arg1, &answer); 397 aid_t dreq = async_data_read(exch, buf, buf_size - 1, &dreply); 398 async_wait_for(dreq, &dretval); 399 400 devman_exchange_end(exch); 401 402 if (dretval != EOK) { 403 async_wait_for(req, NULL); 404 return dretval; 405 } 406 407 sysarg_t retval; 408 async_wait_for(req, &retval); 409 410 if (retval != EOK) 411 return retval; 412 413 act_size = IPC_GET_ARG2(dreply); 414 assert(act_size <= buf_size - 1); 415 buf[act_size] = '\0'; 416 417 return EOK; 418 } 419 420 int devman_fun_get_path(devman_handle_t handle, char *buf, size_t buf_size) 421 { 422 return devman_get_str_internal(DEVMAN_FUN_GET_PATH, handle, buf, 423 buf_size); 424 } 425 426 int devman_fun_get_name(devman_handle_t handle, char *buf, size_t buf_size) 427 { 428 return devman_get_str_internal(DEVMAN_FUN_GET_NAME, handle, buf, 429 buf_size); 430 } 431 432 static int devman_get_handles_once(sysarg_t method, sysarg_t arg1, 433 devman_handle_t *handle_buf, size_t buf_size, size_t *act_size) 434 { 435 async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_CLIENT); 436 437 ipc_call_t answer; 438 aid_t req = async_send_1(exch, method, arg1, &answer); 439 int rc = async_data_read_start(exch, handle_buf, buf_size); 440 441 devman_exchange_end(exch); 442 443 if (rc != EOK) { 444 async_wait_for(req, NULL); 445 return rc; 446 } 447 448 sysarg_t retval; 449 async_wait_for(req, &retval); 450 451 if (retval != EOK) { 452 return retval; 453 } 454 455 *act_size = IPC_GET_ARG1(answer); 456 return EOK; 457 } 458 459 /** Get list of handles. 460 * 461 * Returns an allocated array of handles. 462 * 463 * @param method IPC method 464 * @param arg1 IPC argument 1 465 * @param data Place to store pointer to array of handles 466 * @param count Place to store number of handles 467 * @return EOK on success or negative error code 468 */ 469 static int devman_get_handles_internal(sysarg_t method, sysarg_t arg1, 470 devman_handle_t **data, size_t *count) 471 { 472 devman_handle_t *handles; 473 size_t act_size; 474 size_t alloc_size; 475 int rc; 476 477 *data = NULL; 478 act_size = 0; /* silence warning */ 479 480 rc = devman_get_handles_once(method, arg1, NULL, 0, 481 &act_size); 482 if (rc != EOK) 483 return rc; 484 485 alloc_size = act_size; 486 handles = malloc(alloc_size); 487 if (handles == NULL) 488 return ENOMEM; 489 490 while (true) { 491 rc = devman_get_handles_once(method, arg1, handles, alloc_size, 492 &act_size); 493 if (rc != EOK) 494 return rc; 495 496 if (act_size <= alloc_size) 497 break; 498 499 alloc_size *= 2; 500 free(handles); 501 502 handles = malloc(alloc_size); 503 if (handles == NULL) 504 return ENOMEM; 505 } 506 507 *count = act_size / sizeof(devman_handle_t); 508 *data = handles; 509 return EOK; 510 } 511 512 int devman_fun_get_child(devman_handle_t funh, devman_handle_t *devh) 386 513 { 387 514 async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT); … … 389 516 return ENOMEM; 390 517 391 ipc_call_t answer; 392 aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_DEVICE_PATH, 393 handle, &answer); 394 395 ipc_call_t data_request_call; 396 aid_t data_request = async_data_read(exch, path, path_size, 397 &data_request_call); 398 399 devman_exchange_end(exch); 400 401 if (data_request == 0) { 402 async_wait_for(req, NULL); 403 return ENOMEM; 404 } 405 406 sysarg_t data_request_rc; 407 async_wait_for(data_request, &data_request_rc); 408 409 sysarg_t opening_request_rc; 410 async_wait_for(req, &opening_request_rc); 411 412 if (data_request_rc != EOK) { 413 /* Prefer the return code of the opening request. */ 414 if (opening_request_rc != EOK) 415 return (int) opening_request_rc; 416 else 417 return (int) data_request_rc; 418 } 419 420 if (opening_request_rc != EOK) 421 return (int) opening_request_rc; 422 423 /* To be on the safe-side. */ 424 path[path_size - 1] = 0; 425 size_t transferred_size = IPC_GET_ARG2(data_request_call); 426 if (transferred_size >= path_size) 427 return ELIMIT; 428 429 /* Terminate the string (trailing 0 not send over IPC). */ 430 path[transferred_size] = 0; 431 return EOK; 518 sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_GET_CHILD, 519 funh, devh); 520 521 devman_exchange_end(exch); 522 return (int) retval; 523 } 524 525 int devman_dev_get_functions(devman_handle_t devh, devman_handle_t **funcs, 526 size_t *count) 527 { 528 return devman_get_handles_internal(DEVMAN_DEV_GET_FUNCTIONS, 529 devh, funcs, count); 432 530 } 433 531 -
uspace/lib/c/generic/io/printf_core.c
r1877128 rd1e196f7 206 206 } 207 207 208 return (int) (counter + 1);208 return (int) (counter); 209 209 } 210 210 … … 244 244 } 245 245 246 return (int) (counter + 1);246 return (int) (counter); 247 247 } 248 248 -
uspace/lib/c/generic/ipc.c
r1877128 rd1e196f7 47 47 #include <futex.h> 48 48 #include <fibril.h> 49 #include <macros.h> 49 50 50 51 /** … … 611 612 /** Request callback connection. 612 613 * 613 * The @a task hashand @a phonehash identifiers returned614 * The @a task_id and @a phonehash identifiers returned 614 615 * by the kernel can be used for connection tracking. 615 616 * … … 618 619 * @param arg2 User defined argument. 619 620 * @param arg3 User defined argument. 620 * @param task hash Opaque identifier of the client task.621 * @param task_id Identifier of the client task. 621 622 * @param phonehash Opaque identifier of the phone that will 622 623 * be used for incoming calls. … … 626 627 */ 627 628 int ipc_connect_to_me(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, 628 sysarg_t *taskhash, sysarg_t *phonehash) 629 { 630 return ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_TO_ME, arg1, arg2, 631 arg3, NULL, NULL, NULL, taskhash, phonehash); 629 task_id_t *task_id, sysarg_t *phonehash) 630 { 631 ipc_call_t data; 632 int rc = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, 633 IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, (sysarg_t) &data); 634 if (rc == EOK) { 635 *task_id = data.in_task_id; 636 *phonehash = IPC_GET_ARG5(data); 637 } 638 return rc; 632 639 } 633 640 -
uspace/lib/c/generic/loader.c
r1877128 rd1e196f7 263 263 264 264 int i; 265 for (i = 0; files[i]; i++) 266 ; 265 for (i = 0; files[i]; i++); 267 266 268 267 ipc_call_t answer; -
uspace/lib/c/generic/loc.c
r1877128 rd1e196f7 315 315 /** Register new service. 316 316 * 317 * @param fqsn 318 * @param sid 317 * @param fqsn Fully qualified service name 318 * @param sid Output: ID of new service 319 319 * 320 320 */ -
uspace/lib/c/generic/ns.c
r1877128 rd1e196f7 56 56 async_exchange_end(exch); 57 57 58 /* 59 * FIXME Ugly hack to work around limitation of implementing 60 * parallel exchanges using multiple connections. Shift out 61 * first argument for non-initial connections. 62 */ 63 async_sess_args_set(sess, arg2, arg3, 0); 64 58 65 return sess; 59 66 } … … 66 73 async_connect_me_to_blocking(mgmt, exch, service, arg2, arg3); 67 74 async_exchange_end(exch); 75 76 /* 77 * FIXME Ugly hack to work around limitation of implementing 78 * parallel exchanges using multiple connections. Shift out 79 * first argument for non-initial connections. 80 */ 81 async_sess_args_set(sess, arg2, arg3, 0); 68 82 69 83 return sess; -
uspace/lib/c/generic/private/async.h
r1877128 rd1e196f7 36 36 #define LIBC_PRIVATE_ASYNC_H_ 37 37 38 #include < ipc/common.h>38 #include <async.h> 39 39 #include <adt/list.h> 40 40 #include <fibril.h> 41 #include <fibril_synch.h> 41 42 #include <sys/time.h> 42 43 #include <bool.h> 44 45 /** Session data */ 46 struct _async_sess { 47 /** List of inactive exchanges */ 48 list_t exch_list; 49 50 /** Exchange management style */ 51 exch_mgmt_t mgmt; 52 53 /** Session identification */ 54 int phone; 55 56 /** First clone connection argument */ 57 sysarg_t arg1; 58 59 /** Second clone connection argument */ 60 sysarg_t arg2; 61 62 /** Third clone connection argument */ 63 sysarg_t arg3; 64 65 /** Exchange mutex */ 66 fibril_mutex_t mutex; 67 68 /** Number of opened exchanges */ 69 atomic_t refcnt; 70 71 /** Mutex for stateful connections */ 72 fibril_mutex_t remote_state_mtx; 73 74 /** Data for stateful connections */ 75 void *remote_state_data; 76 }; 77 78 /** Exchange data */ 79 struct _async_exch { 80 /** Link into list of inactive exchanges */ 81 link_t sess_link; 82 83 /** Link into global list of inactive exchanges */ 84 link_t global_link; 85 86 /** Session pointer */ 87 async_sess_t *sess; 88 89 /** Exchange identification */ 90 int phone; 91 }; 43 92 44 93 /** Structures of this type are used to track the timeout events. */ -
uspace/lib/c/include/async.h
r1877128 rd1e196f7 42 42 #include <ipc/common.h> 43 43 #include <fibril.h> 44 #include <fibril_synch.h>45 44 #include <sys/time.h> 46 45 #include <atomic.h> … … 96 95 } exch_mgmt_t; 97 96 98 /** Session data */ 99 typedef struct { 100 /** List of inactive exchanges */ 101 list_t exch_list; 102 103 /** Exchange management style */ 104 exch_mgmt_t mgmt; 105 106 /** Session identification */ 107 int phone; 108 109 /** First clone connection argument */ 110 sysarg_t arg1; 111 112 /** Second clone connection argument */ 113 sysarg_t arg2; 114 115 /** Third clone connection argument */ 116 sysarg_t arg3; 117 118 /** Exchange mutex */ 119 fibril_mutex_t mutex; 120 121 /** Number of opened exchanges */ 122 atomic_t refcnt; 123 } async_sess_t; 124 125 /** Exchange data */ 126 typedef struct { 127 /** Link into list of inactive exchanges */ 128 link_t sess_link; 129 130 /** Link into global list of inactive exchanges */ 131 link_t global_link; 132 133 /** Session pointer */ 134 async_sess_t *sess; 135 136 /** Exchange identification */ 137 int phone; 138 } async_exch_t; 97 /** Forward declarations */ 98 struct _async_exch; 99 struct _async_sess; 100 101 typedef struct _async_sess async_sess_t; 102 typedef struct _async_exch async_exch_t; 139 103 140 104 extern atomic_t threads_in_ipc_wait; … … 176 140 extern int async_wait_timeout(aid_t, sysarg_t *, suseconds_t); 177 141 178 extern fid_t async_new_connection( sysarg_t, sysarg_t, ipc_callid_t,142 extern fid_t async_new_connection(task_id_t, sysarg_t, ipc_callid_t, 179 143 ipc_call_t *, async_client_conn_t, void *); 180 144 … … 186 150 extern void async_set_client_data_destructor(async_client_data_dtor_t); 187 151 extern void *async_get_client_data(void); 188 extern void *async_get_client_data_by_ hash(sysarg_t);189 extern void async_put_client_data_by_ hash(sysarg_t);152 extern void *async_get_client_data_by_id(task_id_t); 153 extern void async_put_client_data_by_id(task_id_t); 190 154 191 155 extern void async_set_client_connection(async_client_conn_t); … … 373 337 374 338 /* 339 * FIXME These functions just work around problems with parallel exchange 340 * management. Proper solution needs to be implemented. 341 */ 342 void async_sess_args_set(async_sess_t *sess, sysarg_t, sysarg_t, sysarg_t); 343 344 /* 375 345 * User-friendly wrappers for async_share_in_start(). 376 346 */ … … 485 455 extern int async_state_change_finalize(ipc_callid_t, async_exch_t *); 486 456 457 extern void *async_remote_state_acquire(async_sess_t *); 458 extern void async_remote_state_update(async_sess_t *, void *); 459 extern void async_remote_state_release(async_sess_t *); 460 extern void async_remote_state_release_exchange(async_exch_t *); 461 487 462 #endif 488 463 -
uspace/lib/c/include/devman.h
r1877128 rd1e196f7 56 56 unsigned int); 57 57 58 extern int devman_ device_get_handle(const char *, devman_handle_t *,58 extern int devman_fun_get_handle(const char *, devman_handle_t *, 59 59 unsigned int); 60 extern int devman_get_device_path(devman_handle_t, char *, size_t); 60 extern int devman_fun_get_child(devman_handle_t, devman_handle_t *); 61 extern int devman_dev_get_functions(devman_handle_t, devman_handle_t **, 62 size_t *); 63 extern int devman_fun_get_name(devman_handle_t, char *, size_t); 64 extern int devman_fun_get_path(devman_handle_t, char *, size_t); 61 65 62 66 extern int devman_add_device_to_category(devman_handle_t, const char *); -
uspace/lib/c/include/ipc/common.h
r1877128 rd1e196f7 39 39 #include <abi/ipc/ipc.h> 40 40 #include <atomic.h> 41 #include <task.h> 41 42 42 43 #define IPC_FLAG_BLOCKING 0x01 … … 44 45 typedef struct { 45 46 sysarg_t args[IPC_CALL_LEN]; 46 sysarg_t in_task_hash;47 task_id_t in_task_id; 47 48 sysarg_t in_phone_hash; 48 49 } ipc_call_t; -
uspace/lib/c/include/ipc/devman.h
r1877128 rd1e196f7 149 149 typedef enum { 150 150 DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD, 151 DEVMAN_DEVICE_GET_DEVICE_PATH, 151 DEVMAN_DEV_GET_FUNCTIONS, 152 DEVMAN_FUN_GET_CHILD, 153 DEVMAN_FUN_GET_NAME, 154 DEVMAN_FUN_GET_PATH, 152 155 DEVMAN_FUN_SID_TO_HANDLE 153 156 } client_to_devman_t; -
uspace/lib/c/include/ipc/ipc.h
r1877128 rd1e196f7 254 254 sysarg_t, sysarg_t, void *, ipc_async_callback_t, bool); 255 255 256 extern int ipc_connect_to_me(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t *,256 extern int ipc_connect_to_me(int, sysarg_t, sysarg_t, sysarg_t, task_id_t *, 257 257 sysarg_t *); 258 258 extern int ipc_connect_me(int); -
uspace/lib/drv/generic/driver.c
r1877128 rd1e196f7 428 428 static void driver_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 429 429 { 430 sysarg_t conn_type; 431 432 if (iid == 0) { 433 /* Callback connection from devman */ 434 /* XXX Use separate handler for this type of connection */ 435 conn_type = DRIVER_DEVMAN; 436 } else { 437 conn_type = IPC_GET_ARG1(*icall); 438 } 439 430 440 /* Select interface */ 431 switch ( (sysarg_t) (IPC_GET_ARG1(*icall))) {441 switch (conn_type) { 432 442 case DRIVER_DEVMAN: 433 443 /* Handle request from device manager */ -
uspace/lib/usb/src/resolve.c
r1877128 rd1e196f7 152 152 if (str_length(func_start) > 0) { 153 153 char tmp_path[MAX_DEVICE_PATH ]; 154 rc = devman_ get_device_path(dev_handle,154 rc = devman_fun_get_path(dev_handle, 155 155 tmp_path, MAX_DEVICE_PATH); 156 156 if (rc != EOK) { … … 173 173 174 174 /* First try to get the device handle. */ 175 rc = devman_ device_get_handle(path, &dev_handle, 0);175 rc = devman_fun_get_handle(path, &dev_handle, 0); 176 176 if (rc != EOK) { 177 177 free(path); … … 184 184 /* Get device handle first. */ 185 185 devman_handle_t tmp_handle; 186 rc = devman_ device_get_handle(path, &tmp_handle, 0);186 rc = devman_fun_get_handle(path, &tmp_handle, 0); 187 187 if (rc != EOK) { 188 188 free(path); -
uspace/lib/usbvirt/src/device.c
r1877128 rd1e196f7 87 87 88 88 devman_handle_t handle; 89 int rc = devman_ device_get_handle(vhc_path, &handle, 0);89 int rc = devman_fun_get_handle(vhc_path, &handle, 0); 90 90 if (rc != EOK) 91 91 return rc; -
uspace/srv/devman/devman.c
r1877128 rd1e196f7 548 548 549 549 fibril_mutex_lock(&driver->driver_mutex); 550 551 async_exch_t *exch = async_exchange_begin(driver->sess);552 async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch,553 DRIVER_DEVMAN, 0, 0);554 async_exchange_end(exch);555 556 if (!sess) {557 fibril_mutex_unlock(&driver->driver_mutex);558 return;559 }560 550 561 551 /* … … 583 573 fibril_mutex_unlock(&driver->driver_mutex); 584 574 585 add_device( sess,driver, dev, tree);575 add_device(driver, dev, tree); 586 576 587 577 /* … … 603 593 link = driver->devices.head.next; 604 594 } 605 606 async_hangup(sess);607 595 608 596 /* … … 718 706 * @param node The device's node in the device tree. 719 707 */ 720 void add_device(async_sess_t *sess, driver_t *drv, dev_node_t *dev, 721 dev_tree_t *tree) 708 void add_device(driver_t *drv, dev_node_t *dev, dev_tree_t *tree) 722 709 { 723 710 /* … … 736 723 } 737 724 738 async_exch_t *exch = async_exchange_begin( sess);725 async_exch_t *exch = async_exchange_begin(drv->sess); 739 726 740 727 ipc_call_t answer; … … 806 793 fibril_mutex_unlock(&drv->driver_mutex); 807 794 808 if (is_running) { 809 /* Notify the driver about the new device. */ 810 async_exch_t *exch = async_exchange_begin(drv->sess); 811 async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch, 812 DRIVER_DEVMAN, 0, 0); 813 async_exchange_end(exch); 814 815 if (sess) { 816 add_device(sess, drv, dev, tree); 817 async_hangup(sess); 818 } 819 } 795 /* Notify the driver about the new device. */ 796 if (is_running) 797 add_device(drv, dev, tree); 820 798 821 799 return true; … … 919 897 return dev; 920 898 } 899 900 /** Get list of device functions. */ 901 int dev_get_functions(dev_tree_t *tree, dev_node_t *dev, 902 devman_handle_t *hdl_buf, size_t buf_size, size_t *act_size) 903 { 904 size_t act_cnt; 905 size_t buf_cnt; 906 907 assert(fibril_rwlock_is_locked(&tree->rwlock)); 908 909 buf_cnt = buf_size / sizeof(devman_handle_t); 910 911 act_cnt = list_count(&dev->functions); 912 *act_size = act_cnt * sizeof(devman_handle_t); 913 914 if (buf_size % sizeof(devman_handle_t) != 0) 915 return EINVAL; 916 917 size_t pos = 0; 918 list_foreach(dev->functions, item) { 919 fun_node_t *fun = 920 list_get_instance(item, fun_node_t, dev_functions); 921 922 if (pos < buf_cnt) 923 hdl_buf[pos] = fun->handle; 924 pos++; 925 } 926 927 return EOK; 928 } 929 921 930 922 931 /* Function nodes */ … … 1145 1154 char *rel_path = path; 1146 1155 char *next_path_elem = NULL; 1147 bool cont = true;1156 bool cont = (rel_path[1] != '\0'); 1148 1157 1149 1158 while (cont && fun != NULL) { -
uspace/srv/devman/devman.h
r1877128 rd1e196f7 63 63 typedef struct fun_node fun_node_t; 64 64 65 typedef struct { 66 fibril_mutex_t mutex; 67 struct driver *driver; 68 } client_t; 69 65 70 typedef enum { 66 71 /** Driver has not been started. */ … … 235 240 extern void add_driver(driver_list_t *, driver_t *); 236 241 extern void attach_driver(dev_node_t *, driver_t *); 237 extern void add_device( async_sess_t *,driver_t *, dev_node_t *, dev_tree_t *);242 extern void add_device(driver_t *, dev_node_t *, dev_tree_t *); 238 243 extern bool start_driver(driver_t *); 239 244 … … 253 258 extern dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle); 254 259 extern dev_node_t *find_dev_function(dev_node_t *, const char *); 260 extern int dev_get_functions(dev_tree_t *tree, dev_node_t *, devman_handle_t *, 261 size_t, size_t *); 255 262 256 263 extern fun_node_t *create_fun_node(void); -
uspace/srv/devman/main.c
r1877128 rd1e196f7 65 65 static dev_tree_t device_tree; 66 66 67 static int init_running_drv(void *drv); 68 67 69 /** Register running driver. */ 68 static driver_t *devman_driver_register(void) 69 { 70 ipc_call_t icall; 71 ipc_callid_t iid; 70 static driver_t *devman_driver_register(ipc_callid_t callid, ipc_call_t *call) 71 { 72 72 driver_t *driver = NULL; 73 char *drv_name = NULL; 73 74 74 75 log_msg(LVL_DEBUG, "devman_driver_register"); 75 76 iid = async_get_call(&icall);77 if (IPC_GET_IMETHOD(icall) != DEVMAN_DRIVER_REGISTER) {78 async_answer_0(iid, EREFUSED);79 return NULL;80 }81 82 char *drv_name = NULL;83 76 84 77 /* Get driver name. */ 85 78 int rc = async_data_write_accept((void **) &drv_name, true, 0, 0, 0, 0); 86 79 if (rc != EOK) { 87 async_answer_0( iid, rc);80 async_answer_0(callid, rc); 88 81 return NULL; 89 82 } … … 98 91 free(drv_name); 99 92 drv_name = NULL; 100 async_answer_0( iid, ENOENT);93 async_answer_0(callid, ENOENT); 101 94 return NULL; 102 95 } … … 112 105 driver->name); 113 106 fibril_mutex_unlock(&driver->driver_mutex); 114 async_answer_0( iid, EEXISTS);107 async_answer_0(callid, EEXISTS); 115 108 return NULL; 116 109 } … … 134 127 log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.", 135 128 driver->name); 136 driver->sess = async_callback_receive(EXCHANGE_ SERIALIZE);129 driver->sess = async_callback_receive(EXCHANGE_PARALLEL); 137 130 if (!driver->sess) { 138 131 fibril_mutex_unlock(&driver->driver_mutex); 139 async_answer_0( iid, ENOTSUP);132 async_answer_0(callid, ENOTSUP); 140 133 return NULL; 141 134 } 142 143 fibril_mutex_unlock(&driver->driver_mutex);135 /* FIXME: Work around problem with callback sessions */ 136 async_sess_args_set(driver->sess, DRIVER_DEVMAN, 0, 0); 144 137 145 138 log_msg(LVL_NOTE, … … 147 140 driver->name); 148 141 149 async_answer_0(iid, EOK); 150 142 /* 143 * Initialize the driver as running (e.g. pass assigned devices to it) 144 * in a separate fibril; the separate fibril is used to enable the 145 * driver to use devman service during the driver's initialization. 146 */ 147 fid_t fid = fibril_create(init_running_drv, driver); 148 if (fid == 0) { 149 log_msg(LVL_ERROR, "Failed to create initialization fibril " \ 150 "for driver `%s'.", driver->name); 151 fibril_mutex_unlock(&driver->driver_mutex); 152 async_answer_0(callid, ENOMEM); 153 return NULL; 154 } 155 156 fibril_add_ready(fid); 157 fibril_mutex_unlock(&driver->driver_mutex); 158 159 async_answer_0(callid, EOK); 151 160 return driver; 152 161 } … … 429 438 static void devman_connection_driver(ipc_callid_t iid, ipc_call_t *icall) 430 439 { 440 client_t *client; 441 driver_t *driver; 442 431 443 /* Accept the connection. */ 432 444 async_answer_0(iid, EOK); 433 445 434 driver_t *driver = devman_driver_register(); 435 if (driver == NULL) 436 return; 437 438 /* 439 * Initialize the driver as running (e.g. pass assigned devices to it) 440 * in a separate fibril; the separate fibril is used to enable the 441 * driver to use devman service during the driver's initialization. 442 */ 443 fid_t fid = fibril_create(init_running_drv, driver); 444 if (fid == 0) { 445 log_msg(LVL_ERROR, "Failed to create initialization fibril " \ 446 "for driver `%s'.", driver->name); 447 return; 448 } 449 fibril_add_ready(fid); 446 client = async_get_client_data(); 447 if (client == NULL) { 448 log_msg(LVL_ERROR, "Failed to allocate client data."); 449 return; 450 } 450 451 451 452 while (true) { … … 456 457 break; 457 458 459 if (IPC_GET_IMETHOD(call) != DEVMAN_DRIVER_REGISTER) { 460 fibril_mutex_lock(&client->mutex); 461 driver = client->driver; 462 fibril_mutex_unlock(&client->mutex); 463 if (driver == NULL) { 464 /* First call must be to DEVMAN_DRIVER_REGISTER */ 465 async_answer_0(callid, ENOTSUP); 466 continue; 467 } 468 } 469 458 470 switch (IPC_GET_IMETHOD(call)) { 471 case DEVMAN_DRIVER_REGISTER: 472 fibril_mutex_lock(&client->mutex); 473 if (client->driver != NULL) { 474 fibril_mutex_unlock(&client->mutex); 475 async_answer_0(callid, EINVAL); 476 continue; 477 } 478 client->driver = devman_driver_register(callid, &call); 479 fibril_mutex_unlock(&client->mutex); 480 break; 459 481 case DEVMAN_ADD_FUNCTION: 460 482 devman_add_function(callid, &call); … … 497 519 } 498 520 499 /** Find device path by its handle. */ 500 static void devman_get_device_path_by_handle(ipc_callid_t iid, 501 ipc_call_t *icall) 521 /** Get device name. */ 522 static void devman_fun_get_name(ipc_callid_t iid, ipc_call_t *icall) 502 523 { 503 524 devman_handle_t handle = IPC_GET_ARG1(*icall); … … 523 544 } 524 545 546 size_t sent_length = str_size(fun->name); 547 if (sent_length > data_len) { 548 sent_length = data_len; 549 } 550 551 async_data_read_finalize(data_callid, fun->name, sent_length); 552 async_answer_0(iid, EOK); 553 554 free(buffer); 555 } 556 557 558 /** Get device path. */ 559 static void devman_fun_get_path(ipc_callid_t iid, ipc_call_t *icall) 560 { 561 devman_handle_t handle = IPC_GET_ARG1(*icall); 562 563 fun_node_t *fun = find_fun_node(&device_tree, handle); 564 if (fun == NULL) { 565 async_answer_0(iid, ENOMEM); 566 return; 567 } 568 569 ipc_callid_t data_callid; 570 size_t data_len; 571 if (!async_data_read_receive(&data_callid, &data_len)) { 572 async_answer_0(iid, EINVAL); 573 return; 574 } 575 576 void *buffer = malloc(data_len); 577 if (buffer == NULL) { 578 async_answer_0(data_callid, ENOMEM); 579 async_answer_0(iid, ENOMEM); 580 return; 581 } 582 525 583 size_t sent_length = str_size(fun->pathname); 526 584 if (sent_length > data_len) { … … 532 590 533 591 free(buffer); 592 } 593 594 static void devman_dev_get_functions(ipc_callid_t iid, ipc_call_t *icall) 595 { 596 ipc_callid_t callid; 597 size_t size; 598 size_t act_size; 599 int rc; 600 601 if (!async_data_read_receive(&callid, &size)) { 602 async_answer_0(callid, EREFUSED); 603 async_answer_0(iid, EREFUSED); 604 return; 605 } 606 607 fibril_rwlock_read_lock(&device_tree.rwlock); 608 609 dev_node_t *dev = find_dev_node_no_lock(&device_tree, 610 IPC_GET_ARG1(*icall)); 611 if (dev == NULL) { 612 fibril_rwlock_read_unlock(&device_tree.rwlock); 613 async_answer_0(callid, ENOENT); 614 async_answer_0(iid, ENOENT); 615 return; 616 } 617 618 devman_handle_t *hdl_buf = (devman_handle_t *) malloc(size); 619 if (hdl_buf == NULL) { 620 fibril_rwlock_read_unlock(&device_tree.rwlock); 621 async_answer_0(callid, ENOMEM); 622 async_answer_0(iid, ENOMEM); 623 return; 624 } 625 626 rc = dev_get_functions(&device_tree, dev, hdl_buf, size, &act_size); 627 if (rc != EOK) { 628 fibril_rwlock_read_unlock(&device_tree.rwlock); 629 async_answer_0(callid, rc); 630 async_answer_0(iid, rc); 631 return; 632 } 633 634 fibril_rwlock_read_unlock(&device_tree.rwlock); 635 636 sysarg_t retval = async_data_read_finalize(callid, hdl_buf, size); 637 free(hdl_buf); 638 639 async_answer_1(iid, retval, act_size); 640 } 641 642 643 /** Get handle for child device of a function. */ 644 static void devman_fun_get_child(ipc_callid_t iid, ipc_call_t *icall) 645 { 646 fun_node_t *fun; 647 648 fibril_rwlock_read_lock(&device_tree.rwlock); 649 650 fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall)); 651 if (fun == NULL) { 652 fibril_rwlock_read_unlock(&device_tree.rwlock); 653 async_answer_0(iid, ENOENT); 654 return; 655 } 656 657 if (fun->child == NULL) { 658 fibril_rwlock_read_unlock(&device_tree.rwlock); 659 async_answer_0(iid, ENOENT); 660 return; 661 } 662 663 async_answer_1(iid, EOK, fun->child->handle); 664 665 fibril_rwlock_read_unlock(&device_tree.rwlock); 534 666 } 535 667 … … 566 698 devman_function_get_handle(callid, &call); 567 699 break; 568 case DEVMAN_DEVICE_GET_DEVICE_PATH: 569 devman_get_device_path_by_handle(callid, &call); 700 case DEVMAN_DEV_GET_FUNCTIONS: 701 devman_dev_get_functions(callid, &call); 702 break; 703 case DEVMAN_FUN_GET_CHILD: 704 devman_fun_get_child(callid, &call); 705 break; 706 case DEVMAN_FUN_GET_NAME: 707 devman_fun_get_name(callid, &call); 708 break; 709 case DEVMAN_FUN_GET_PATH: 710 devman_fun_get_path(callid, &call); 570 711 break; 571 712 case DEVMAN_FUN_SID_TO_HANDLE: … … 695 836 static void devman_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 696 837 { 697 /* Select interface. */838 /* Select port. */ 698 839 switch ((sysarg_t) (IPC_GET_ARG1(*icall))) { 699 840 case DEVMAN_DRIVER: … … 721 862 } 722 863 864 static void *devman_client_data_create(void) 865 { 866 client_t *client; 867 868 client = calloc(1, sizeof(client_t)); 869 if (client == NULL) 870 return NULL; 871 872 fibril_mutex_initialize(&client->mutex); 873 return client; 874 } 875 876 static void devman_client_data_destroy(void *data) 877 { 878 free(data); 879 } 880 723 881 /** Initialize device manager internal structures. */ 724 882 static bool devman_init(void) … … 767 925 } 768 926 769 /* Set a handler of incomming connections. */ 927 /* Set handlers for incoming connections. */ 928 async_set_client_data_constructor(devman_client_data_create); 929 async_set_client_data_destructor(devman_client_data_destroy); 770 930 async_set_client_connection(devman_connection); 771 931 -
uspace/srv/vfs/vfs.c
r1877128 rd1e196f7 36 36 */ 37 37 38 #include <vfs/vfs.h> 38 39 #include <ipc/services.h> 39 40 #include <abi/ipc/event.h> … … 47 48 #include <as.h> 48 49 #include <atomic.h> 49 #include < vfs/vfs.h>50 #include <macros.h> 50 51 #include "vfs.h" 51 52 52 53 #define NAME "vfs" 54 55 enum { 56 VFS_TASK_STATE_CHANGE 57 }; 53 58 54 59 static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) … … 134 139 } 135 140 136 enum {137 VFS_TASK_STATE_CHANGE138 };139 140 141 static void notification_received(ipc_callid_t callid, ipc_call_t *call) 141 142 { … … 143 144 case VFS_TASK_STATE_CHANGE: 144 145 if (IPC_GET_ARG1(*call) == VFS_PASS_HANDLE) 145 vfs_pass_handle(IPC_GET_ARG4(*call), 146 IPC_GET_ARG5(*call), (int) IPC_GET_ARG2(*call)); 146 vfs_pass_handle( 147 (task_id_t) MERGE_LOUP32(IPC_GET_ARG4(*call), 148 IPC_GET_ARG5(*call)), call->in_task_id, 149 (int) IPC_GET_ARG2(*call)); 147 150 break; 148 151 default: -
uspace/srv/vfs/vfs.h
r1877128 rd1e196f7 41 41 #include <bool.h> 42 42 #include <ipc/vfs.h> 43 #include <task.h> 43 44 44 45 #ifndef dprintf … … 188 189 extern void vfs_client_data_destroy(void *); 189 190 190 extern void vfs_pass_handle( sysarg_t, sysarg_t, int);191 extern void vfs_pass_handle(task_id_t, task_id_t, int); 191 192 extern int vfs_wait_handle_internal(void); 192 193 -
uspace/srv/vfs/vfs_file.c
r1877128 rd1e196f7 44 44 #include <fibril_synch.h> 45 45 #include <adt/list.h> 46 #include <task.h> 46 47 #include "vfs.h" 47 48 … … 346 347 } 347 348 348 void vfs_pass_handle( sysarg_t donor_hash, sysarg_t acceptor_hash, int donor_fd)349 void vfs_pass_handle(task_id_t donor_id, task_id_t acceptor_id, int donor_fd) 349 350 { 350 351 vfs_client_data_t *donor_data = NULL; … … 355 356 int acceptor_fd; 356 357 357 acceptor_data = async_get_client_data_by_ hash(acceptor_hash);358 acceptor_data = async_get_client_data_by_id(acceptor_id); 358 359 if (!acceptor_data) 359 360 return; … … 365 366 bh->handle = -1; 366 367 367 donor_data = async_get_client_data_by_ hash(donor_hash);368 donor_data = async_get_client_data_by_id(donor_id); 368 369 if (!donor_data) 369 370 goto out; … … 402 403 403 404 if (donor_data) 404 async_put_client_data_by_ hash(donor_hash);405 async_put_client_data_by_id(donor_id); 405 406 if (acceptor_data) 406 async_put_client_data_by_ hash(acceptor_hash);407 async_put_client_data_by_id(acceptor_id); 407 408 if (donor_file) 408 409 _vfs_file_put(donor_data, donor_file);
Note:
See TracChangeset
for help on using the changeset viewer.