Changeset 6a44ee4 in mainline for uspace/srv/devman
- Timestamp:
- 2011-07-20T15:26:21Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- efcebe1
- Parents:
- 25bef0ff (diff), a701812 (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/srv/devman
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r25bef0ff r6a44ee4 466 466 fibril_mutex_lock(&drivers_list->drivers_mutex); 467 467 468 link_t *link = drivers_list->drivers.next; 469 while (link != &drivers_list->drivers) { 468 list_foreach(drivers_list->drivers, link) { 470 469 drv = list_get_instance(link, driver_t, drivers); 471 470 score = get_match_score(drv, node); … … 474 473 best_drv = drv; 475 474 } 476 link = link->next;477 475 } 478 476 … … 536 534 driver_t *res = NULL; 537 535 driver_t *drv = NULL; 538 link_t *link;539 536 540 537 fibril_mutex_lock(&drv_list->drivers_mutex); 541 538 542 link = drv_list->drivers.next; 543 while (link != &drv_list->drivers) { 539 list_foreach(drv_list->drivers, link) { 544 540 drv = list_get_instance(link, driver_t, drivers); 545 541 if (str_cmp(drv->name, drv_name) == 0) { … … 547 543 break; 548 544 } 549 550 link = link->next;551 545 } 552 546 … … 564 558 dev_node_t *dev; 565 559 link_t *link; 566 int phone;567 560 568 561 log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")", … … 570 563 571 564 fibril_mutex_lock(&driver->driver_mutex); 572 573 phone = async_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0); 574 575 if (phone < 0) { 565 566 async_exch_t *exch = async_exchange_begin(driver->sess); 567 async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch, 568 DRIVER_DEVMAN, 0, 0); 569 async_exchange_end(exch); 570 571 if (!sess) { 576 572 fibril_mutex_unlock(&driver->driver_mutex); 577 573 return; … … 582 578 * that has not been passed to the driver. 583 579 */ 584 link = driver->devices. next;585 while (link != &driver->devices ) {580 link = driver->devices.head.next; 581 while (link != &driver->devices.head) { 586 582 dev = list_get_instance(link, dev_node_t, driver_devices); 587 583 if (dev->passed_to_driver) { … … 602 598 fibril_mutex_unlock(&driver->driver_mutex); 603 599 604 add_device( phone, driver, dev, tree);600 add_device(sess, driver, dev, tree); 605 601 606 602 /* … … 620 616 * Restart the cycle to go through all devices again. 621 617 */ 622 link = driver->devices. next;623 } 624 625 async_hangup( phone);618 link = driver->devices.head.next; 619 } 620 621 async_hangup(sess); 626 622 627 623 /* … … 673 669 list_initialize(&drv->devices); 674 670 fibril_mutex_initialize(&drv->driver_mutex); 675 drv-> phone = -1;671 drv->sess = NULL; 676 672 } 677 673 … … 737 733 * @param node The device's node in the device tree. 738 734 */ 739 void add_device(int phone, driver_t *drv, dev_node_t *dev, dev_tree_t *tree) 735 void add_device(async_sess_t *sess, driver_t *drv, dev_node_t *dev, 736 dev_tree_t *tree) 740 737 { 741 738 /* … … 746 743 drv->name, dev->pfun->name); 747 744 748 sysarg_t rc;749 ipc_call_t answer;750 751 745 /* Send the device to the driver. */ 752 746 devman_handle_t parent_handle; … … 756 750 parent_handle = 0; 757 751 } 758 759 aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, dev->handle, 752 753 async_exch_t *exch = async_exchange_begin(sess); 754 755 ipc_call_t answer; 756 aid_t req = async_send_2(exch, DRIVER_ADD_DEVICE, dev->handle, 760 757 parent_handle, &answer); 761 758 762 /* Send the device 'sname to the driver. */763 rc = async_data_write_start(phone, dev->pfun->name,759 /* Send the device name to the driver. */ 760 sysarg_t rc = async_data_write_start(exch, dev->pfun->name, 764 761 str_size(dev->pfun->name) + 1); 762 763 async_exchange_end(exch); 764 765 765 if (rc != EOK) { 766 766 /* TODO handle error */ … … 823 823 if (is_running) { 824 824 /* 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); 825 async_exch_t *exch = async_exchange_begin(drv->sess); 826 async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch, 827 DRIVER_DEVMAN, 0, 0); 828 async_exchange_end(exch); 829 830 if (sess) { 831 add_device(sess, drv, dev, tree); 832 async_hangup(sess); 829 833 } 830 834 } … … 1177 1181 1178 1182 fun_node_t *fun; 1179 link_t *link; 1180 1181 for (link = dev->functions.next; 1182 link != &dev->functions; 1183 link = link->next) { 1183 1184 list_foreach(dev->functions, link) { 1184 1185 fun = list_get_instance(link, fun_node_t, dev_functions); 1185 1186 … … 1375 1376 { 1376 1377 dev_class_t *cl; 1377 link_t *link = class_list->classes.next; 1378 1379 while (link != &class_list->classes) { 1378 1379 list_foreach(class_list->classes, link) { 1380 1380 cl = list_get_instance(link, dev_class_t, link); 1381 1381 if (str_cmp(cl->name, class_name) == 0) { 1382 1382 return cl; 1383 1383 } 1384 link = link->next;1385 1384 } 1386 1385 … … 1398 1397 assert(dev_name != NULL); 1399 1398 1400 link_t *link; 1401 for (link = dev_class->devices.next; 1402 link != &dev_class->devices; 1403 link = link->next) { 1399 list_foreach(dev_class->devices, link) { 1404 1400 dev_class_info_t *dev = list_get_instance(link, 1405 1401 dev_class_info_t, link); -
uspace/srv/devman/devman.h
r25bef0ff r6a44ee4 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; … … 95 96 /** List of device ids for device-to-driver matching. */ 96 97 match_id_list_t match_ids; 97 /** Pointer to the linked list of devices controlled by this driver. */98 li nk_t devices;99 100 /** 101 * Fibril mutex for this driver - driver state, list of devices, phone.98 /** List of devices controlled by this driver. */ 99 list_t devices; 100 101 /** 102 * Fibril mutex for this driver - driver state, list of devices, session. 102 103 */ 103 104 fibril_mutex_t driver_mutex; … … 107 108 typedef struct driver_list { 108 109 /** List of drivers */ 109 li nk_t drivers;110 list_t drivers; 110 111 /** Fibril mutex for list of drivers. */ 111 112 fibril_mutex_t drivers_mutex; … … 129 130 130 131 /** List of device functions. */ 131 li nk_t functions;132 list_t functions; 132 133 /** Driver of this device. */ 133 134 driver_t *drv; … … 169 170 match_id_list_t match_ids; 170 171 171 /** The list of device classes to which this device function belongs. */172 li nk_t classes;172 /** List of device classes to which this device function belongs. */ 173 list_t classes; 173 174 /** Devmap handle if the device function is registered by devmap. */ 174 175 devmap_handle_t devmap_handle; … … 227 228 * this class. 228 229 */ 229 li nk_t devices;230 list_t devices; 230 231 231 232 /** … … 279 280 typedef struct class_list { 280 281 /** List of classes. */ 281 li nk_t classes;282 list_t classes; 282 283 283 284 /** … … 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
r25bef0ff r6a44ee4 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); … … 515 507 } 516 508 509 /** Find device path by its handle. */ 510 static void devman_get_device_path_by_handle(ipc_callid_t iid, 511 ipc_call_t *icall) 512 { 513 devman_handle_t handle = IPC_GET_ARG1(*icall); 514 515 fun_node_t *fun = find_fun_node(&device_tree, handle); 516 if (fun == NULL) { 517 async_answer_0(iid, ENOMEM); 518 return; 519 } 520 521 ipc_callid_t data_callid; 522 size_t data_len; 523 if (!async_data_read_receive(&data_callid, &data_len)) { 524 async_answer_0(iid, EINVAL); 525 return; 526 } 527 528 void *buffer = malloc(data_len); 529 if (buffer == NULL) { 530 async_answer_0(data_callid, ENOMEM); 531 async_answer_0(iid, ENOMEM); 532 return; 533 } 534 535 size_t sent_length = str_size(fun->pathname); 536 if (sent_length > data_len) { 537 sent_length = data_len; 538 } 539 540 async_data_read_finalize(data_callid, fun->pathname, sent_length); 541 async_answer_0(iid, EOK); 542 543 free(buffer); 544 } 545 517 546 518 547 /** Function for handling connections from a client to the device manager. */ … … 522 551 async_answer_0(iid, EOK); 523 552 524 bool cont = true; 525 while (cont) { 553 while (true) { 526 554 ipc_call_t call; 527 555 ipc_callid_t callid = async_get_call(&call); 528 556 557 if (!IPC_GET_IMETHOD(call)) 558 break; 559 529 560 switch (IPC_GET_IMETHOD(call)) { 530 case IPC_M_PHONE_HUNGUP:531 cont = false;532 continue;533 561 case DEVMAN_DEVICE_GET_HANDLE: 534 562 devman_function_get_handle(callid, &call); … … 536 564 case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS: 537 565 devman_function_get_handle_by_class(callid, &call); 566 break; 567 case DEVMAN_DEVICE_GET_DEVICE_PATH: 568 devman_get_device_path_by_handle(callid, &call); 538 569 break; 539 570 default: … … 606 637 method = DRIVER_CLIENT; 607 638 608 if (driver->phone < 0) { 609 log_msg(LVL_ERROR, 610 "Could not forward to driver `%s' (phone is %d).", 611 driver->name, (int) driver->phone); 639 if (!driver->sess) { 640 log_msg(LVL_ERROR, 641 "Could not forward to driver `%s'.", driver->name); 612 642 async_answer_0(iid, EINVAL); 613 643 return; … … 623 653 dev->pfun->pathname, driver->name); 624 654 } 625 626 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); 627 659 } 628 660 … … 646 678 dev = fun->dev; 647 679 648 if ( dev->state != DEVICE_USABLE || dev->drv->phone < 0) {680 if ((dev->state != DEVICE_USABLE) || (!dev->drv->sess)) { 649 681 async_answer_0(iid, EINVAL); 650 682 return; 651 683 } 652 684 653 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, 654 687 IPC_FF_NONE); 655 log_msg(LVL_DEBUG, 688 async_exchange_end(exch); 689 690 log_msg(LVL_DEBUG, 656 691 "Forwarding devmapper request for `%s' function to driver `%s'.", 657 692 fun->pathname, dev->drv->name); … … 659 694 660 695 /** Function for handling connections to device manager. */ 661 static void devman_connection(ipc_callid_t iid, ipc_call_t *icall )696 static void devman_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 662 697 { 663 698 /* Select interface. */ … … 745 780 746 781 printf(NAME ": Accepting connections.\n"); 782 task_retval(0); 747 783 async_manager(); 748 784 -
uspace/srv/devman/match.c
r25bef0ff r6a44ee4 59 59 int get_match_score(driver_t *drv, dev_node_t *dev) 60 60 { 61 link_t *drv_head = &drv->match_ids.ids ;62 link_t *dev_head = &dev->pfun->match_ids.ids ;61 link_t *drv_head = &drv->match_ids.ids.head; 62 link_t *dev_head = &dev->pfun->match_ids.ids.head; 63 63 64 if (list_empty(drv_head) || list_empty(dev_head)) 64 if (list_empty(&drv->match_ids.ids) || 65 list_empty(&dev->pfun->match_ids.ids)) { 65 66 return 0; 67 } 66 68 67 69 /* … … 70 72 int highest_score = 0; 71 73 72 link_t *drv_link = drv->match_ids.ids. next;74 link_t *drv_link = drv->match_ids.ids.head.next; 73 75 while (drv_link != drv_head) { 74 76 link_t *dev_link = dev_head->next;
Note:
See TracChangeset
for help on using the changeset viewer.
