Changes in uspace/srv/devman/devman.c [8b1e15ac:fa581b3] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r8b1e15ac rfa581b3 41 41 #include "devman.h" 42 42 43 fun_node_t *find_node_child(fun_node_t *parent, const char *name);44 45 43 /* hash table operations */ 46 44 … … 53 51 link_t *item) 54 52 { 55 dev_node_t *dev = hash_table_get_instance(item, dev_node_t, devman_dev);53 node_t *dev = hash_table_get_instance(item, node_t, devman_link); 56 54 return (dev->handle == (devman_handle_t) key[0]); 57 55 } 58 56 59 static int devma n_functions_compare(unsigned long key[], hash_count_t keys,57 static int devmap_devices_compare(unsigned long key[], hash_count_t keys, 60 58 link_t *item) 61 59 { 62 fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devman_fun); 63 return (fun->handle == (devman_handle_t) key[0]); 64 } 65 66 static int devmap_functions_compare(unsigned long key[], hash_count_t keys, 67 link_t *item) 68 { 69 fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devmap_fun); 70 return (fun->devmap_handle == (devmap_handle_t) key[0]); 60 node_t *dev = hash_table_get_instance(item, node_t, devmap_link); 61 return (dev->devmap_handle == (devmap_handle_t) key[0]); 71 62 } 72 63 … … 91 82 }; 92 83 93 static hash_table_operations_t devman_functions_ops = {94 .hash = devices_hash,95 .compare = devman_functions_compare,96 .remove_callback = devices_remove_callback97 };98 99 84 static hash_table_operations_t devmap_devices_ops = { 100 85 .hash = devices_hash, 101 .compare = devmap_ functions_compare,86 .compare = devmap_devices_compare, 102 87 .remove_callback = devices_remove_callback 103 88 }; … … 388 373 } 389 374 390 /** Create root device and functionnode in the device tree.375 /** Create root device node in the device tree. 391 376 * 392 377 * @param tree The device tree. 393 378 * @return True on success, false otherwise. 394 379 */ 395 bool create_root_nodes(dev_tree_t *tree) 396 { 397 fun_node_t *fun; 398 dev_node_t *dev; 399 400 printf(NAME ": create_root_nodes\n"); 401 380 bool create_root_node(dev_tree_t *tree) 381 { 382 node_t *node; 383 384 printf(NAME ": create_root_node\n"); 385 402 386 fibril_rwlock_write_lock(&tree->rwlock); 403 404 /* 405 * Create root function. This is a pseudo function to which 406 * the root device node is attached. It allows us to match 407 * the root device driver in a standard manner, i.e. against 408 * the parent function. 409 */ 410 411 fun = create_fun_node(); 412 if (fun == NULL) { 413 fibril_rwlock_write_unlock(&tree->rwlock); 414 return false; 415 } 416 417 insert_fun_node(tree, fun, clone_string(""), NULL); 418 match_id_t *id = create_match_id(); 419 id->id = clone_string("root"); 420 id->score = 100; 421 add_match_id(&fun->match_ids, id); 422 tree->root_node = fun; 423 424 /* 425 * Create root device node. 426 */ 427 dev = create_dev_node(); 428 if (dev == NULL) { 429 fibril_rwlock_write_unlock(&tree->rwlock); 430 return false; 431 } 432 433 insert_dev_node(tree, dev, fun); 434 387 node = create_dev_node(); 388 if (node != NULL) { 389 insert_dev_node(tree, node, clone_string(""), NULL); 390 match_id_t *id = create_match_id(); 391 id->id = clone_string("root"); 392 id->score = 100; 393 add_match_id(&node->match_ids, id); 394 tree->root_node = node; 395 } 435 396 fibril_rwlock_write_unlock(&tree->rwlock); 436 437 return dev!= NULL;397 398 return node != NULL; 438 399 } 439 400 … … 453 414 * is found. 454 415 */ 455 driver_t *find_best_match_driver(driver_list_t *drivers_list, dev_node_t *node)416 driver_t *find_best_match_driver(driver_list_t *drivers_list, node_t *node) 456 417 { 457 418 driver_t *best_drv = NULL, *drv = NULL; … … 481 442 * @param drv The driver. 482 443 */ 483 void attach_driver( dev_node_t *dev, driver_t *drv)444 void attach_driver(node_t *node, driver_t *drv) 484 445 { 485 446 printf(NAME ": attach_driver %s to device %s\n", 486 drv->name, dev->pfun->pathname);447 drv->name, node->pathname); 487 448 488 449 fibril_mutex_lock(&drv->driver_mutex); 489 450 490 dev->drv = drv;491 list_append(& dev->driver_devices, &drv->devices);451 node->drv = drv; 452 list_append(&node->driver_devices, &drv->devices); 492 453 493 454 fibril_mutex_unlock(&drv->driver_mutex); … … 569 530 static void pass_devices_to_driver(driver_t *driver, dev_tree_t *tree) 570 531 { 571 dev_node_t *dev;532 node_t *dev; 572 533 link_t *link; 573 534 int phone; … … 590 551 link = driver->devices.next; 591 552 while (link != &driver->devices) { 592 dev = list_get_instance(link, dev_node_t, driver_devices);553 dev = list_get_instance(link, node_t, driver_devices); 593 554 if (dev->passed_to_driver) { 594 555 link = link->next; … … 629 590 } 630 591 631 async_hangup(phone);592 ipc_hangup(phone); 632 593 633 594 /* … … 708 669 } 709 670 710 /** Create devmap path and name for the function. */711 void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)671 /** Create devmap path and name for the device. */ 672 static void devmap_register_tree_device(node_t *node, dev_tree_t *tree) 712 673 { 713 674 char *devmap_pathname = NULL; 714 675 char *devmap_name = NULL; 715 676 716 asprintf(&devmap_name, "%s", fun->pathname);677 asprintf(&devmap_name, "%s", node->pathname); 717 678 if (devmap_name == NULL) 718 679 return; … … 728 689 729 690 devmap_device_register_with_iface(devmap_pathname, 730 & fun->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);731 732 tree_add_devmap_ function(tree, fun);691 &node->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP); 692 693 tree_add_devmap_device(tree, node); 733 694 734 695 free(devmap_name); … … 741 702 * @param node The device's node in the device tree. 742 703 */ 743 void add_device(int phone, driver_t *drv, dev_node_t *dev, dev_tree_t *tree)704 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree) 744 705 { 745 706 /* … … 748 709 */ 749 710 printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name, 750 dev->pfun->name);711 node->name); 751 712 752 713 sysarg_t rc; … … 755 716 /* Send the device to the driver. */ 756 717 devman_handle_t parent_handle; 757 if ( dev->pfun) {758 parent_handle = dev->pfun->handle;718 if (node->parent) { 719 parent_handle = node->parent->handle; 759 720 } else { 760 721 parent_handle = 0; 761 722 } 762 723 763 aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, dev->handle,724 aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle, 764 725 parent_handle, &answer); 765 726 766 727 /* Send the device's name to the driver. */ 767 rc = async_data_write_start(phone, dev->pfun->name,768 str_size( dev->pfun->name) + 1);728 rc = async_data_write_start(phone, node->name, 729 str_size(node->name) + 1); 769 730 if (rc != EOK) { 770 731 /* TODO handle error */ … … 776 737 switch(rc) { 777 738 case EOK: 778 dev->state = DEVICE_USABLE; 739 node->state = DEVICE_USABLE; 740 devmap_register_tree_device(node, tree); 779 741 break; 780 742 case ENOENT: 781 dev->state = DEVICE_NOT_PRESENT;743 node->state = DEVICE_NOT_PRESENT; 782 744 break; 783 745 default: 784 dev->state = DEVICE_INVALID;785 } 786 787 dev->passed_to_driver = true;746 node->state = DEVICE_INVALID; 747 } 748 749 node->passed_to_driver = true; 788 750 789 751 return; … … 797 759 * successfully assigned to the device, false otherwise. 798 760 */ 799 bool assign_driver(dev_node_t *dev, driver_list_t *drivers_list, 800 dev_tree_t *tree) 801 { 802 assert(dev != NULL); 803 assert(drivers_list != NULL); 804 assert(tree != NULL); 805 761 bool assign_driver(node_t *node, driver_list_t *drivers_list, dev_tree_t *tree) 762 { 806 763 /* 807 764 * Find the driver which is the most suitable for handling this device. 808 765 */ 809 driver_t *drv = find_best_match_driver(drivers_list, dev);766 driver_t *drv = find_best_match_driver(drivers_list, node); 810 767 if (drv == NULL) { 811 768 printf(NAME ": no driver found for device '%s'.\n", 812 dev->pfun->pathname);769 node->pathname); 813 770 return false; 814 771 } 815 772 816 773 /* Attach the driver to the device. */ 817 attach_driver( dev, drv);774 attach_driver(node, drv); 818 775 819 776 fibril_mutex_lock(&drv->driver_mutex); … … 829 786 int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0); 830 787 if (phone >= 0) { 831 add_device(phone, drv, dev, tree);832 async_hangup(phone);788 add_device(phone, drv, node, tree); 789 ipc_hangup(phone); 833 790 } 834 791 } … … 853 810 hash_table_create(&tree->devman_devices, DEVICE_BUCKETS, 1, 854 811 &devman_devices_ops); 855 hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1, 856 &devman_functions_ops); 857 hash_table_create(&tree->devmap_functions, DEVICE_BUCKETS, 1, 812 hash_table_create(&tree->devmap_devices, DEVICE_BUCKETS, 1, 858 813 &devmap_devices_ops); 859 814 860 815 fibril_rwlock_initialize(&tree->rwlock); 861 816 862 /* Create root function and root device and add themto the device tree. */863 if (!create_root_node s(tree))817 /* Create root node and add it to the device tree. */ 818 if (!create_root_node(tree)) 864 819 return false; 865 820 866 821 /* Find suitable driver and start it. */ 867 return assign_driver(tree->root_node ->child, drivers_list, tree);822 return assign_driver(tree->root_node, drivers_list, tree); 868 823 } 869 824 … … 874 829 * @return A device node structure. 875 830 */ 876 dev_node_t *create_dev_node(void)877 { 878 dev_node_t *res = malloc(sizeof(dev_node_t));831 node_t *create_dev_node(void) 832 { 833 node_t *res = malloc(sizeof(node_t)); 879 834 880 835 if (res != NULL) { 881 memset(res, 0, sizeof( dev_node_t));882 list_initialize(&res-> functions);883 li nk_initialize(&res->driver_devices);884 li nk_initialize(&res->devman_dev);836 memset(res, 0, sizeof(node_t)); 837 list_initialize(&res->children); 838 list_initialize(&res->match_ids.ids); 839 list_initialize(&res->classes); 885 840 } 886 841 … … 892 847 * @param node The device node structure. 893 848 */ 894 void delete_dev_node(dev_node_t *dev) 895 { 896 assert(list_empty(&dev->functions)); 897 assert(dev->pfun == NULL); 898 assert(dev->drv == NULL); 899 900 free(dev); 849 void delete_dev_node(node_t *node) 850 { 851 assert(list_empty(&node->children)); 852 assert(node->parent == NULL); 853 assert(node->drv == NULL); 854 855 clean_match_ids(&node->match_ids); 856 free_not_null(node->name); 857 free_not_null(node->pathname); 858 free(node); 901 859 } 902 860 … … 907 865 * @return The device node. 908 866 */ 909 dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)867 node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle) 910 868 { 911 869 unsigned long key = handle; … … 915 873 916 874 link = hash_table_find(&tree->devman_devices, &key); 917 return hash_table_get_instance(link, dev_node_t, devman_dev);875 return hash_table_get_instance(link, node_t, devman_link); 918 876 } 919 877 … … 924 882 * @return The device node. 925 883 */ 926 dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle)927 { 928 dev_node_t *dev= NULL;884 node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle) 885 { 886 node_t *node = NULL; 929 887 930 888 fibril_rwlock_read_lock(&tree->rwlock); 931 dev= find_dev_node_no_lock(tree, handle);889 node = find_dev_node_no_lock(tree, handle); 932 890 fibril_rwlock_read_unlock(&tree->rwlock); 933 891 934 return dev; 935 } 936 937 /* Function nodes */ 938 939 /** Create a new function node. 940 * 941 * @return A function node structure. 942 */ 943 fun_node_t *create_fun_node(void) 944 { 945 fun_node_t *res = malloc(sizeof(fun_node_t)); 946 947 if (res != NULL) { 948 memset(res, 0, sizeof(fun_node_t)); 949 link_initialize(&res->dev_functions); 950 list_initialize(&res->match_ids.ids); 951 list_initialize(&res->classes); 952 link_initialize(&res->devman_fun); 953 link_initialize(&res->devmap_fun); 954 } 955 956 return res; 957 } 958 959 /** Delete a function node. 960 * 961 * @param fun The device node structure. 962 */ 963 void delete_fun_node(fun_node_t *fun) 964 { 965 assert(fun->dev == NULL); 966 assert(fun->child == NULL); 967 968 clean_match_ids(&fun->match_ids); 969 free_not_null(fun->name); 970 free_not_null(fun->pathname); 971 free(fun); 972 } 973 974 /** Find the function node with the specified handle. 975 * 976 * @param tree The device tree where we look for the device node. 977 * @param handle The handle of the function. 978 * @return The function node. 979 */ 980 fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle) 981 { 982 unsigned long key = handle; 983 link_t *link; 984 985 assert(fibril_rwlock_is_locked(&tree->rwlock)); 986 987 link = hash_table_find(&tree->devman_functions, &key); 988 if (link == NULL) 989 return NULL; 990 991 return hash_table_get_instance(link, fun_node_t, devman_fun); 992 } 993 994 /** Find the function node with the specified handle. 995 * 996 * @param tree The device tree where we look for the device node. 997 * @param handle The handle of the function. 998 * @return The function node. 999 */ 1000 fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle) 1001 { 1002 fun_node_t *fun = NULL; 1003 1004 fibril_rwlock_read_lock(&tree->rwlock); 1005 fun = find_fun_node_no_lock(tree, handle); 1006 fibril_rwlock_read_unlock(&tree->rwlock); 1007 1008 return fun; 1009 } 892 return node; 893 } 894 1010 895 1011 896 /** Create and set device's full path in device tree. … … 1016 901 * resources etc.). 1017 902 */ 1018 static bool set_ fun_path(fun_node_t *fun, fun_node_t *parent)1019 { 1020 assert( fun->name != NULL);1021 1022 size_t pathsize = (str_size( fun->name) + 1);903 static bool set_dev_path(node_t *node, node_t *parent) 904 { 905 assert(node->name != NULL); 906 907 size_t pathsize = (str_size(node->name) + 1); 1023 908 if (parent != NULL) 1024 909 pathsize += str_size(parent->pathname) + 1; 1025 910 1026 fun->pathname = (char *) malloc(pathsize);1027 if ( fun->pathname == NULL) {911 node->pathname = (char *) malloc(pathsize); 912 if (node->pathname == NULL) { 1028 913 printf(NAME ": failed to allocate device path.\n"); 1029 914 return false; … … 1031 916 1032 917 if (parent != NULL) { 1033 str_cpy( fun->pathname, pathsize, parent->pathname);1034 str_append( fun->pathname, pathsize, "/");1035 str_append( fun->pathname, pathsize, fun->name);918 str_cpy(node->pathname, pathsize, parent->pathname); 919 str_append(node->pathname, pathsize, "/"); 920 str_append(node->pathname, pathsize, node->name); 1036 921 } else { 1037 str_cpy( fun->pathname, pathsize, fun->name);922 str_cpy(node->pathname, pathsize, node->name); 1038 923 } 1039 924 … … 1051 936 * etc.). 1052 937 */ 1053 bool insert_dev_node(dev_tree_t *tree, dev_node_t *dev, fun_node_t *pfun) 1054 { 1055 assert(dev != NULL); 938 bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, 939 node_t *parent) 940 { 941 assert(node != NULL); 1056 942 assert(tree != NULL); 943 assert(dev_name != NULL); 1057 944 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 1058 945 946 node->name = dev_name; 947 if (!set_dev_path(node, parent)) { 948 return false; 949 } 950 1059 951 /* Add the node to the handle-to-node map. */ 1060 dev->handle = ++tree->current_handle;1061 unsigned long key = dev->handle;1062 hash_table_insert(&tree->devman_devices, &key, & dev->devman_dev);952 node->handle = ++tree->current_handle; 953 unsigned long key = node->handle; 954 hash_table_insert(&tree->devman_devices, &key, &node->devman_link); 1063 955 1064 956 /* Add the node to the list of its parent's children. */ 1065 printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);1066 dev->pfun = pfun;1067 pfun->child = dev;957 node->parent = parent; 958 if (parent != NULL) 959 list_append(&node->sibling, &parent->children); 1068 960 1069 961 return true; 1070 962 } 1071 963 1072 /** Insert new function into device tree. 1073 * 964 /** Find device node with a specified path in the device tree. 965 * 966 * @param path The path of the device node in the device tree. 1074 967 * @param tree The device tree. 1075 * @param node The newly added function node. 1076 * @param dev_name The name of the newly added function. 1077 * @param parent Owning device node. 1078 * 1079 * @return True on success, false otherwise (insufficient resources 1080 * etc.). 1081 */ 1082 bool insert_fun_node(dev_tree_t *tree, fun_node_t *fun, char *fun_name, 1083 dev_node_t *dev) 1084 { 1085 fun_node_t *pfun; 1086 1087 assert(fun != NULL); 1088 assert(tree != NULL); 1089 assert(fun_name != NULL); 1090 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 1091 968 * @return The device node if it is present in the tree, NULL 969 * otherwise. 970 */ 971 node_t *find_dev_node_by_path(dev_tree_t *tree, char *path) 972 { 973 fibril_rwlock_read_lock(&tree->rwlock); 974 975 node_t *dev = tree->root_node; 1092 976 /* 1093 * The root function is a special case, it does not belong to any 1094 * device so for the root function dev == NULL. 1095 */ 1096 pfun = (dev != NULL) ? dev->pfun : NULL; 1097 1098 fun->name = fun_name; 1099 if (!set_fun_path(fun, pfun)) { 1100 return false; 1101 } 1102 1103 /* Add the node to the handle-to-node map. */ 1104 fun->handle = ++tree->current_handle; 1105 unsigned long key = fun->handle; 1106 hash_table_insert(&tree->devman_functions, &key, &fun->devman_fun); 1107 1108 /* Add the node to the list of its parent's children. */ 1109 fun->dev = dev; 1110 if (dev != NULL) 1111 list_append(&fun->dev_functions, &dev->functions); 1112 1113 return true; 1114 } 1115 1116 /** Find function node with a specified path in the device tree. 1117 * 1118 * @param path The path of the function node in the device tree. 1119 * @param tree The device tree. 1120 * @return The function node if it is present in the tree, NULL 1121 * otherwise. 1122 */ 1123 fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path) 1124 { 1125 fibril_rwlock_read_lock(&tree->rwlock); 1126 1127 fun_node_t *fun = tree->root_node; 1128 /* 1129 * Relative path to the function from its parent (but with '/' at the 977 * Relative path to the device from its parent (but with '/' at the 1130 978 * beginning) 1131 979 */ … … 1134 982 bool cont = (rel_path[0] == '/'); 1135 983 1136 while (cont && fun!= NULL) {984 while (cont && dev != NULL) { 1137 985 next_path_elem = get_path_elem_end(rel_path + 1); 1138 986 if (next_path_elem[0] == '/') { … … 1143 991 } 1144 992 1145 fun = find_node_child(fun, rel_path + 1);993 dev = find_node_child(dev, rel_path + 1); 1146 994 1147 995 if (cont) { … … 1154 1002 fibril_rwlock_read_unlock(&tree->rwlock); 1155 1003 1156 return fun;1157 } 1158 1159 /** Find child functionnode with a specified name.1004 return dev; 1005 } 1006 1007 /** Find child device node with a specified name. 1160 1008 * 1161 1009 * Device tree rwlock should be held at least for reading. 1162 1010 * 1163 * @param parent The parent functionnode.1164 * @param name The name of the child function.1165 * @return The child functionnode.1166 */ 1167 fun_node_t *find_node_child(fun_node_t *pfun, const char *name)1168 { 1169 fun_node_t *fun;1011 * @param parent The parent device node. 1012 * @param name The name of the child device node. 1013 * @return The child device node. 1014 */ 1015 node_t *find_node_child(node_t *parent, const char *name) 1016 { 1017 node_t *dev; 1170 1018 link_t *link; 1171 1019 1172 link = p fun->child->functions.next;1173 1174 while (link != &p fun->child->functions) {1175 fun = list_get_instance(link, fun_node_t, dev_functions);1020 link = parent->children.next; 1021 1022 while (link != &parent->children) { 1023 dev = list_get_instance(link, node_t, sibling); 1176 1024 1177 if (str_cmp(name, fun->name) == 0)1178 return fun;1025 if (str_cmp(name, dev->name) == 0) 1026 return dev; 1179 1027 1180 1028 link = link->next; … … 1259 1107 } 1260 1108 1261 /** Add the device functionto the class.1109 /** Add the device to the class. 1262 1110 * 1263 1111 * The device may be added to multiple classes and a class may contain multiple … … 1272 1120 * with the class. 1273 1121 */ 1274 dev_class_info_t *add_ function_to_class(fun_node_t *fun, dev_class_t *cl,1122 dev_class_info_t *add_device_to_class(node_t *dev, dev_class_t *cl, 1275 1123 const char *base_dev_name) 1276 1124 { 1277 dev_class_info_t *info; 1278 1279 assert(fun != NULL); 1280 assert(cl != NULL); 1281 1282 info = create_dev_class_info(); 1283 1125 dev_class_info_t *info = create_dev_class_info(); 1284 1126 1285 1127 if (info != NULL) { 1286 1128 info->dev_class = cl; 1287 info-> fun = fun;1129 info->dev = dev; 1288 1130 1289 1131 /* Add the device to the class. */ … … 1293 1135 1294 1136 /* Add the class to the device. */ 1295 list_append(&info->dev_classes, & fun->classes);1137 list_append(&info->dev_classes, &dev->classes); 1296 1138 1297 1139 /* Create unique name for the device within the class. */ … … 1347 1189 list_initialize(&class_list->classes); 1348 1190 fibril_rwlock_initialize(&class_list->rwlock); 1349 hash_table_create(&class_list->devmap_ functions, DEVICE_BUCKETS, 1,1191 hash_table_create(&class_list->devmap_devices, DEVICE_BUCKETS, 1, 1350 1192 &devmap_devices_class_ops); 1351 1193 } … … 1354 1196 /* Devmap devices */ 1355 1197 1356 fun_node_t *find_devmap_tree_function(dev_tree_t *tree, devmap_handle_t devmap_handle)1357 { 1358 fun_node_t *fun= NULL;1198 node_t *find_devmap_tree_device(dev_tree_t *tree, devmap_handle_t devmap_handle) 1199 { 1200 node_t *dev = NULL; 1359 1201 link_t *link; 1360 1202 unsigned long key = (unsigned long) devmap_handle; 1361 1203 1362 1204 fibril_rwlock_read_lock(&tree->rwlock); 1363 link = hash_table_find(&tree->devmap_ functions, &key);1205 link = hash_table_find(&tree->devmap_devices, &key); 1364 1206 if (link != NULL) 1365 fun = hash_table_get_instance(link, fun_node_t, devmap_fun);1207 dev = hash_table_get_instance(link, node_t, devmap_link); 1366 1208 fibril_rwlock_read_unlock(&tree->rwlock); 1367 1209 1368 return fun;1369 } 1370 1371 fun_node_t *find_devmap_class_function(class_list_t *classes,1210 return dev; 1211 } 1212 1213 node_t *find_devmap_class_device(class_list_t *classes, 1372 1214 devmap_handle_t devmap_handle) 1373 1215 { 1374 fun_node_t *fun= NULL;1216 node_t *dev = NULL; 1375 1217 dev_class_info_t *cli; 1376 1218 link_t *link; … … 1378 1220 1379 1221 fibril_rwlock_read_lock(&classes->rwlock); 1380 link = hash_table_find(&classes->devmap_ functions, &key);1222 link = hash_table_find(&classes->devmap_devices, &key); 1381 1223 if (link != NULL) { 1382 1224 cli = hash_table_get_instance(link, dev_class_info_t, 1383 1225 devmap_link); 1384 fun = cli->fun;1226 dev = cli->dev; 1385 1227 } 1386 1228 fibril_rwlock_read_unlock(&classes->rwlock); 1387 1229 1388 return fun;1389 } 1390 1391 void class_add_devmap_ function(class_list_t *class_list, dev_class_info_t *cli)1230 return dev; 1231 } 1232 1233 void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli) 1392 1234 { 1393 1235 unsigned long key = (unsigned long) cli->devmap_handle; 1394 1236 1395 1237 fibril_rwlock_write_lock(&class_list->rwlock); 1396 hash_table_insert(&class_list->devmap_ functions, &key, &cli->devmap_link);1238 hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link); 1397 1239 fibril_rwlock_write_unlock(&class_list->rwlock); 1398 1240 1399 assert(find_devmap_class_ function(class_list, cli->devmap_handle) != NULL);1400 } 1401 1402 void tree_add_devmap_ function(dev_tree_t *tree, fun_node_t *fun)1403 { 1404 unsigned long key = (unsigned long) fun->devmap_handle;1241 assert(find_devmap_class_device(class_list, cli->devmap_handle) != NULL); 1242 } 1243 1244 void tree_add_devmap_device(dev_tree_t *tree, node_t *node) 1245 { 1246 unsigned long key = (unsigned long) node->devmap_handle; 1405 1247 fibril_rwlock_write_lock(&tree->rwlock); 1406 hash_table_insert(&tree->devmap_ functions, &key, &fun->devmap_fun);1248 hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link); 1407 1249 fibril_rwlock_write_unlock(&tree->rwlock); 1408 1250 }
Note:
See TracChangeset
for help on using the changeset viewer.