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