Changes in uspace/srv/devman/devman.c [7e752b2:01b87dc5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r7e752b2 r01b87dc5 62 62 } 63 63 64 static int devmap_devices_class_compare(unsigned long key[], hash_count_t keys, 65 link_t *item) 66 { 67 dev_class_info_t *class_info 68 = hash_table_get_instance(item, dev_class_info_t, devmap_link); 69 assert(class_info != NULL); 70 71 return (class_info->devmap_handle == (devmap_handle_t) key[0]); 72 } 73 64 74 static void devices_remove_callback(link_t *item) 65 75 { … … 75 85 .hash = devices_hash, 76 86 .compare = devmap_devices_compare, 87 .remove_callback = devices_remove_callback 88 }; 89 90 static hash_table_operations_t devmap_devices_class_ops = { 91 .hash = devices_hash, 92 .compare = devmap_devices_class_compare, 77 93 .remove_callback = devices_remove_callback 78 94 }; … … 368 384 printf(NAME ": create_root_node\n"); 369 385 386 fibril_rwlock_write_lock(&tree->rwlock); 370 387 node = create_dev_node(); 371 388 if (node != NULL) { … … 377 394 tree->root_node = node; 378 395 } 396 fibril_rwlock_write_unlock(&tree->rwlock); 379 397 380 398 return node != NULL; … … 439 457 /** Start a driver 440 458 * 441 * The driver's mutex is assumed to be locked.442 *443 459 * @param drv The driver's structure. 444 460 * @return True if the driver's task is successfully spawned, false … … 449 465 int rc; 450 466 467 assert(fibril_mutex_is_locked(&drv->driver_mutex)); 468 451 469 printf(NAME ": start_driver '%s'\n", drv->name); 452 470 … … 498 516 * @param phone The phone to the driver. 499 517 */ 500 void set_driver_phone(driver_t *driver, ipcarg_t phone)518 void set_driver_phone(driver_t *driver, sysarg_t phone) 501 519 { 502 520 fibril_mutex_lock(&driver->driver_mutex); … … 508 526 /** Notify driver about the devices to which it was assigned. 509 527 * 510 * The driver's mutex must be locked.511 *512 528 * @param driver The driver to which the devices are passed. 513 529 */ … … 518 534 int phone; 519 535 520 printf(NAME ": pass_devices_to_driver\n"); 521 522 phone = ipc_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0); 523 if (phone > 0) { 524 536 printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name); 537 538 fibril_mutex_lock(&driver->driver_mutex); 539 540 phone = async_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0); 541 542 if (phone < 0) { 543 fibril_mutex_unlock(&driver->driver_mutex); 544 return; 545 } 546 547 /* 548 * Go through devices list as long as there is some device 549 * that has not been passed to the driver. 550 */ 551 link = driver->devices.next; 552 while (link != &driver->devices) { 553 dev = list_get_instance(link, node_t, driver_devices); 554 if (dev->passed_to_driver) { 555 link = link->next; 556 continue; 557 } 558 559 /* 560 * We remove the device from the list to allow safe adding 561 * of new devices (no one will touch our item this way). 562 */ 563 list_remove(link); 564 565 /* 566 * Unlock to avoid deadlock when adding device 567 * handled by itself. 568 */ 569 fibril_mutex_unlock(&driver->driver_mutex); 570 571 add_device(phone, driver, dev, tree); 572 573 /* 574 * Lock again as we will work with driver's 575 * structure. 576 */ 577 fibril_mutex_lock(&driver->driver_mutex); 578 579 /* 580 * Insert the device back. 581 * The order is not relevant here so no harm is done 582 * (actually, the order would be preserved in most cases). 583 */ 584 list_append(link, &driver->devices); 585 586 /* 587 * Restart the cycle to go through all devices again. 588 */ 525 589 link = driver->devices.next; 526 while (link != &driver->devices) { 527 dev = list_get_instance(link, node_t, driver_devices); 528 add_device(phone, driver, dev, tree); 529 link = link->next; 530 } 531 532 ipc_hangup(phone); 533 } 590 } 591 592 ipc_hangup(phone); 593 594 /* 595 * Once we passed all devices to the driver, we need to mark the 596 * driver as running. 597 * It is vital to do it here and inside critical section. 598 * 599 * If we would change the state earlier, other devices added to 600 * the driver would be added to the device list and started 601 * immediately and possibly started here as well. 602 */ 603 printf(NAME ": driver %s goes into running state.\n", driver->name); 604 driver->state = DRIVER_RUNNING; 605 606 fibril_mutex_unlock(&driver->driver_mutex); 534 607 } 535 608 … … 545 618 void initialize_running_driver(driver_t *driver, dev_tree_t *tree) 546 619 { 547 printf(NAME ": initialize_running_driver\n"); 548 fibril_mutex_lock(&driver->driver_mutex); 620 printf(NAME ": initialize_running_driver (`%s')\n", driver->name); 549 621 550 622 /* … … 553 625 */ 554 626 pass_devices_to_driver(driver, tree); 555 556 /* Change driver's state to running. */557 driver->state = DRIVER_RUNNING;558 559 fibril_mutex_unlock(&driver->driver_mutex);560 627 } 561 628 … … 621 688 } 622 689 623 devmap_device_register(devmap_pathname, &node->devmap_handle); 690 devmap_device_register_with_iface(devmap_pathname, 691 &node->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP); 624 692 625 693 tree_add_devmap_device(tree, node); … … 629 697 } 630 698 631 632 699 /** Pass a device to running driver. 633 700 * … … 637 704 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree) 638 705 { 639 printf(NAME ": add_device\n"); 640 641 ipcarg_t rc; 706 /* 707 * We do not expect to have driver's mutex locked as we do not 708 * access any structures that would affect driver_t. 709 */ 710 printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name, 711 node->name); 712 713 sysarg_t rc; 642 714 ipc_call_t answer; 643 715 644 716 /* Send the device to the driver. */ 645 aid_t req = async_send_1(phone, DRIVER_ADD_DEVICE, node->handle, 646 &answer); 717 devman_handle_t parent_handle; 718 if (node->parent) { 719 parent_handle = node->parent->handle; 720 } else { 721 parent_handle = 0; 722 } 723 724 aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle, 725 parent_handle, &answer); 647 726 648 727 /* Send the device's name to the driver. */ … … 652 731 /* TODO handle error */ 653 732 } 654 733 655 734 /* Wait for answer from the driver. */ 656 735 async_wait_for(req, &rc); 736 657 737 switch(rc) { 658 738 case EOK: … … 667 747 } 668 748 749 node->passed_to_driver = true; 750 669 751 return; 670 752 } … … 692 774 attach_driver(node, drv); 693 775 776 fibril_mutex_lock(&drv->driver_mutex); 694 777 if (drv->state == DRIVER_NOT_STARTED) { 695 778 /* Start the driver. */ 696 779 start_driver(drv); 697 780 } 698 699 if (drv->state == DRIVER_RUNNING) { 781 bool is_running = drv->state == DRIVER_RUNNING; 782 fibril_mutex_unlock(&drv->driver_mutex); 783 784 if (is_running) { 700 785 /* Notify the driver about the new device. */ 701 int phone = ipc_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);786 int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0); 702 787 if (phone > 0) { 703 788 add_device(phone, drv, node, tree); … … 776 861 /** Find the device node structure of the device witch has the specified handle. 777 862 * 778 * Device tree's rwlock should be held at least for reading.779 *780 863 * @param tree The device tree where we look for the device node. 781 864 * @param handle The handle of the device. … … 785 868 { 786 869 unsigned long key = handle; 787 link_t *link = hash_table_find(&tree->devman_devices, &key); 870 link_t *link; 871 872 assert(fibril_rwlock_is_locked(&tree->rwlock)); 873 874 link = hash_table_find(&tree->devman_devices, &key); 788 875 return hash_table_get_instance(link, node_t, devman_link); 789 876 } … … 841 928 /** Insert new device into device tree. 842 929 * 843 * The device tree's rwlock should be already held exclusively when calling this844 * function.845 *846 930 * @param tree The device tree. 847 931 * @param node The newly added device node. … … 858 942 assert(tree != NULL); 859 943 assert(dev_name != NULL); 944 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 860 945 861 946 node->name = dev_name; 862 947 if (!set_dev_path(node, parent)) { 863 fibril_rwlock_write_unlock(&tree->rwlock);864 948 return false; 865 949 } … … 977 1061 978 1062 info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t)); 979 if (info != NULL) 1063 if (info != NULL) { 980 1064 memset(info, 0, sizeof(dev_class_info_t)); 1065 list_initialize(&info->dev_classes); 1066 list_initialize(&info->devmap_link); 1067 list_initialize(&info->link); 1068 } 981 1069 982 1070 return info; … … 1083 1171 while (link != &class_list->classes) { 1084 1172 cl = list_get_instance(link, dev_class_t, link); 1085 if (str_cmp(cl->name, class_name) == 0) 1173 if (str_cmp(cl->name, class_name) == 0) { 1086 1174 return cl; 1175 } 1176 link = link->next; 1087 1177 } 1088 1178 … … 1100 1190 fibril_rwlock_initialize(&class_list->rwlock); 1101 1191 hash_table_create(&class_list->devmap_devices, DEVICE_BUCKETS, 1, 1102 &devmap_devices_ ops);1192 &devmap_devices_class_ops); 1103 1193 } 1104 1194 … … 1148 1238 hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link); 1149 1239 fibril_rwlock_write_unlock(&class_list->rwlock); 1240 1241 assert(find_devmap_class_device(class_list, cli->devmap_handle) != NULL); 1150 1242 } 1151 1243
Note:
See TracChangeset
for help on using the changeset viewer.