Changeset 79ae36dd in mainline for uspace/srv/devman
- Timestamp:
- 2011-06-08T19:01:55Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0eff68e
- Parents:
- 764d71e
- Location:
- uspace/srv/devman
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r764d71e r79ae36dd 564 564 dev_node_t *dev; 565 565 link_t *link; 566 int phone;567 566 568 567 log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")", … … 570 569 571 570 fibril_mutex_lock(&driver->driver_mutex); 572 573 phone = async_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0); 574 575 if (phone < 0) { 571 572 async_exch_t *exch = async_exchange_begin(driver->sess); 573 async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch, 574 DRIVER_DEVMAN, 0, 0); 575 async_exchange_end(exch); 576 577 if (!sess) { 576 578 fibril_mutex_unlock(&driver->driver_mutex); 577 579 return; … … 602 604 fibril_mutex_unlock(&driver->driver_mutex); 603 605 604 add_device( phone, driver, dev, tree);606 add_device(sess, driver, dev, tree); 605 607 606 608 /* … … 623 625 } 624 626 625 async_hangup( phone);627 async_hangup(sess); 626 628 627 629 /* … … 673 675 list_initialize(&drv->devices); 674 676 fibril_mutex_initialize(&drv->driver_mutex); 675 drv-> phone = -1;677 drv->sess = NULL; 676 678 } 677 679 … … 737 739 * @param node The device's node in the device tree. 738 740 */ 739 void add_device(int phone, driver_t *drv, dev_node_t *dev, dev_tree_t *tree) 741 void add_device(async_sess_t *sess, driver_t *drv, dev_node_t *dev, 742 dev_tree_t *tree) 740 743 { 741 744 /* … … 746 749 drv->name, dev->pfun->name); 747 750 748 sysarg_t rc;749 ipc_call_t answer;750 751 751 /* Send the device to the driver. */ 752 752 devman_handle_t parent_handle; … … 756 756 parent_handle = 0; 757 757 } 758 759 aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, dev->handle, 758 759 async_exch_t *exch = async_exchange_begin(sess); 760 761 ipc_call_t answer; 762 aid_t req = async_send_2(exch, DRIVER_ADD_DEVICE, dev->handle, 760 763 parent_handle, &answer); 761 764 762 /* Send the device 'sname to the driver. */763 rc = async_data_write_start(phone, dev->pfun->name,765 /* Send the device name to the driver. */ 766 sysarg_t rc = async_data_write_start(exch, dev->pfun->name, 764 767 str_size(dev->pfun->name) + 1); 768 769 async_exchange_end(exch); 770 765 771 if (rc != EOK) { 766 772 /* TODO handle error */ … … 823 829 if (is_running) { 824 830 /* Notify the driver about the new device. */ 825 int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0); 826 if (phone >= 0) { 827 add_device(phone, drv, dev, tree); 828 async_hangup(phone); 831 async_exch_t *exch = async_exchange_begin(drv->sess); 832 async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch, 833 DRIVER_DEVMAN, 0, 0); 834 async_exchange_end(exch); 835 836 if (sess) { 837 add_device(sess, drv, dev, tree); 838 async_hangup(sess); 829 839 } 830 840 } -
uspace/srv/devman/devman.h
r764d71e r79ae36dd 44 44 #include <fibril_synch.h> 45 45 #include <atomic.h> 46 #include <async.h> 46 47 47 48 #include "util.h" … … 87 88 int state; 88 89 89 /** Phoneasociated with this driver. */90 int phone;90 /** Session asociated with this driver. */ 91 async_sess_t *sess; 91 92 /** Name of the device driver. */ 92 93 char *name; … … 99 100 100 101 /** 101 * Fibril mutex for this driver - driver state, list of devices, phone.102 * Fibril mutex for this driver - driver state, list of devices, session. 102 103 */ 103 104 fibril_mutex_t driver_mutex; … … 312 313 extern void add_driver(driver_list_t *, driver_t *); 313 314 extern void attach_driver(dev_node_t *, driver_t *); 314 extern void add_device( int, driver_t *, dev_node_t *, dev_tree_t *);315 extern void add_device(async_sess_t *, driver_t *, dev_node_t *, dev_tree_t *); 315 316 extern bool start_driver(driver_t *); 316 317 -
uspace/srv/devman/main.c
r764d71e r79ae36dd 39 39 #include <assert.h> 40 40 #include <ipc/services.h> 41 #include < ipc/ns.h>41 #include <ns.h> 42 42 #include <async.h> 43 43 #include <stdio.h> … … 108 108 fibril_mutex_lock(&driver->driver_mutex); 109 109 110 if (driver-> phone >= 0) {110 if (driver->sess) { 111 111 /* We already have a connection to the driver. */ 112 112 log_msg(LVL_ERROR, "Driver '%s' already started.\n", … … 128 128 break; 129 129 case DRIVER_RUNNING: 130 /* Should not happen since we do not have a connected phone*/130 /* Should not happen since we do not have a connected session */ 131 131 assert(false); 132 132 } … … 135 135 log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.", 136 136 driver->name); 137 ipc_call_t call; 138 ipc_callid_t callid = async_get_call(&call); 139 if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) { 137 driver->sess = async_callback_receive(EXCHANGE_SERIALIZE); 138 if (!driver->sess) { 140 139 fibril_mutex_unlock(&driver->driver_mutex); 141 async_answer_0(callid, ENOTSUP);142 140 async_answer_0(iid, ENOTSUP); 143 141 return NULL; 144 142 } 145 143 146 /* Remember driver's phone. */147 driver->phone = IPC_GET_ARG5(call);148 149 144 fibril_mutex_unlock(&driver->driver_mutex); 150 145 151 log_msg(LVL_NOTE, 146 log_msg(LVL_NOTE, 152 147 "The `%s' driver was successfully registered as running.", 153 148 driver->name); 154 149 155 async_answer_0(callid, EOK);156 150 async_answer_0(iid, EOK); 157 151 … … 434 428 fibril_add_ready(fid); 435 429 436 ipc_callid_t callid; 437 ipc_call_t call; 438 bool cont = true; 439 while (cont) { 440 callid = async_get_call(&call); 430 while (true) { 431 ipc_call_t call; 432 ipc_callid_t callid = async_get_call(&call); 433 434 if (!IPC_GET_IMETHOD(call)) 435 break; 441 436 442 437 switch (IPC_GET_IMETHOD(call)) { 443 case IPC_M_PHONE_HUNGUP:444 cont = false;445 continue;446 438 case DEVMAN_ADD_FUNCTION: 447 439 devman_add_function(callid, &call); … … 559 551 async_answer_0(iid, EOK); 560 552 561 bool cont = true; 562 while (cont) { 553 while (true) { 563 554 ipc_call_t call; 564 555 ipc_callid_t callid = async_get_call(&call); 565 556 557 if (!IPC_GET_IMETHOD(call)) 558 break; 559 566 560 switch (IPC_GET_IMETHOD(call)) { 567 case IPC_M_PHONE_HUNGUP:568 cont = false;569 continue;570 561 case DEVMAN_DEVICE_GET_HANDLE: 571 562 devman_function_get_handle(callid, &call); … … 635 626 if (driver == NULL) { 636 627 log_msg(LVL_ERROR, "IPC forwarding refused - " \ 637 "the device %" PRIun "(%s) is not in usable state.", 638 handle, dev->pfun->pathname); 628 "the device %" PRIun " is not in usable state.", handle); 639 629 async_answer_0(iid, ENOENT); 640 630 return; … … 647 637 method = DRIVER_CLIENT; 648 638 649 if (driver->phone < 0) { 650 log_msg(LVL_ERROR, 651 "Could not forward to driver `%s' (phone is %d).", 652 driver->name, (int) driver->phone); 639 if (!driver->sess) { 640 log_msg(LVL_ERROR, 641 "Could not forward to driver `%s'.", driver->name); 653 642 async_answer_0(iid, EINVAL); 654 643 return; … … 664 653 dev->pfun->pathname, driver->name); 665 654 } 666 667 async_forward_fast(iid, driver->phone, method, fwd_h, 0, IPC_FF_NONE); 655 656 async_exch_t *exch = async_exchange_begin(driver->sess); 657 async_forward_fast(iid, exch, method, fwd_h, 0, IPC_FF_NONE); 658 async_exchange_end(exch); 668 659 } 669 660 … … 687 678 dev = fun->dev; 688 679 689 if ( dev->state != DEVICE_USABLE || dev->drv->phone < 0) {680 if ((dev->state != DEVICE_USABLE) || (!dev->drv->sess)) { 690 681 async_answer_0(iid, EINVAL); 691 682 return; 692 683 } 693 684 694 async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0, 685 async_exch_t *exch = async_exchange_begin(dev->drv->sess); 686 async_forward_fast(iid, exch, DRIVER_CLIENT, fun->handle, 0, 695 687 IPC_FF_NONE); 696 log_msg(LVL_DEBUG, 688 async_exchange_end(exch); 689 690 log_msg(LVL_DEBUG, 697 691 "Forwarding devmapper request for `%s' function to driver `%s'.", 698 692 fun->pathname, dev->drv->name); … … 786 780 787 781 printf(NAME ": Accepting connections.\n"); 782 task_retval(0); 788 783 async_manager(); 789 784
Note:
See TracChangeset
for help on using the changeset viewer.