Changes in uspace/srv/devman/devman.c [df147c7:3ca3430] in mainline
- File:
-
- 1 edited
-
uspace/srv/devman/devman.c (modified) (38 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
rdf147c7 r3ca3430 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 }; … … 266 251 } 267 252 268 ssize_t read_bytes = safe_read(fd, buf, len); 269 if (read_bytes <= 0) { 253 if (read(fd, buf, len) <= 0) { 270 254 printf(NAME ": unable to read file '%s'.\n", conf_path); 271 255 goto cleanup; 272 256 } 273 buf[ read_bytes] = 0;257 buf[len] = 0; 274 258 275 259 suc = parse_match_ids(buf, ids); … … 389 373 } 390 374 391 /** Create root device and functionnode in the device tree.375 /** Create root device node in the device tree. 392 376 * 393 377 * @param tree The device tree. 394 378 * @return True on success, false otherwise. 395 379 */ 396 bool create_root_nodes(dev_tree_t *tree) 397 { 398 fun_node_t *fun; 399 dev_node_t *dev; 400 401 printf(NAME ": create_root_nodes\n"); 402 403 fibril_rwlock_write_lock(&tree->rwlock); 404 405 /* 406 * Create root function. This is a pseudo function to which 407 * the root device node is attached. It allows us to match 408 * the root device driver in a standard manner, i.e. against 409 * the parent function. 410 */ 411 412 fun = create_fun_node(); 413 if (fun == NULL) { 414 fibril_rwlock_write_unlock(&tree->rwlock); 415 return false; 416 } 417 418 insert_fun_node(tree, fun, clone_string(""), NULL); 419 match_id_t *id = create_match_id(); 420 id->id = clone_string("root"); 421 id->score = 100; 422 add_match_id(&fun->match_ids, id); 423 tree->root_node = fun; 424 425 /* 426 * Create root device node. 427 */ 428 dev = create_dev_node(); 429 if (dev == NULL) { 430 fibril_rwlock_write_unlock(&tree->rwlock); 431 return false; 432 } 433 434 insert_dev_node(tree, dev, fun); 435 436 fibril_rwlock_write_unlock(&tree->rwlock); 437 438 return dev != NULL; 380 bool create_root_node(dev_tree_t *tree) 381 { 382 node_t *node; 383 384 printf(NAME ": create_root_node\n"); 385 386 node = create_dev_node(); 387 if (node != NULL) { 388 insert_dev_node(tree, node, clone_string(""), NULL); 389 match_id_t *id = create_match_id(); 390 id->id = clone_string("root"); 391 id->score = 100; 392 add_match_id(&node->match_ids, id); 393 tree->root_node = node; 394 } 395 396 return node != NULL; 439 397 } 440 398 … … 454 412 * is found. 455 413 */ 456 driver_t *find_best_match_driver(driver_list_t *drivers_list, dev_node_t *node)414 driver_t *find_best_match_driver(driver_list_t *drivers_list, node_t *node) 457 415 { 458 416 driver_t *best_drv = NULL, *drv = NULL; … … 482 440 * @param drv The driver. 483 441 */ 484 void attach_driver( dev_node_t *dev, driver_t *drv)442 void attach_driver(node_t *node, driver_t *drv) 485 443 { 486 444 printf(NAME ": attach_driver %s to device %s\n", 487 drv->name, dev->pfun->pathname);445 drv->name, node->pathname); 488 446 489 447 fibril_mutex_lock(&drv->driver_mutex); 490 448 491 dev->drv = drv;492 list_append(& dev->driver_devices, &drv->devices);449 node->drv = drv; 450 list_append(&node->driver_devices, &drv->devices); 493 451 494 452 fibril_mutex_unlock(&drv->driver_mutex); … … 496 454 497 455 /** Start a driver 456 * 457 * The driver's mutex is assumed to be locked. 498 458 * 499 459 * @param drv The driver's structure. … … 505 465 int rc; 506 466 507 assert(fibril_mutex_is_locked(&drv->driver_mutex));508 509 467 printf(NAME ": start_driver '%s'\n", drv->name); 510 468 … … 570 528 static void pass_devices_to_driver(driver_t *driver, dev_tree_t *tree) 571 529 { 572 dev_node_t *dev;530 node_t *dev; 573 531 link_t *link; 574 532 int phone; … … 591 549 link = driver->devices.next; 592 550 while (link != &driver->devices) { 593 dev = list_get_instance(link, dev_node_t, driver_devices);551 dev = list_get_instance(link, node_t, driver_devices); 594 552 if (dev->passed_to_driver) { 595 553 link = link->next; … … 630 588 } 631 589 632 async_hangup(phone);590 ipc_hangup(phone); 633 591 634 592 /* … … 709 667 } 710 668 711 /** Create devmap path and name for the function. */712 void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)669 /** Create devmap path and name for the device. */ 670 static void devmap_register_tree_device(node_t *node, dev_tree_t *tree) 713 671 { 714 672 char *devmap_pathname = NULL; 715 673 char *devmap_name = NULL; 716 674 717 asprintf(&devmap_name, "%s", fun->pathname);675 asprintf(&devmap_name, "%s", node->pathname); 718 676 if (devmap_name == NULL) 719 677 return; … … 729 687 730 688 devmap_device_register_with_iface(devmap_pathname, 731 & fun->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);732 733 tree_add_devmap_ function(tree, fun);689 &node->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP); 690 691 tree_add_devmap_device(tree, node); 734 692 735 693 free(devmap_name); … … 742 700 * @param node The device's node in the device tree. 743 701 */ 744 void add_device(int phone, driver_t *drv, dev_node_t *dev, dev_tree_t *tree)702 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree) 745 703 { 746 704 /* … … 749 707 */ 750 708 printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name, 751 dev->pfun->name);709 node->name); 752 710 753 711 sysarg_t rc; … … 756 714 /* Send the device to the driver. */ 757 715 devman_handle_t parent_handle; 758 if ( dev->pfun) {759 parent_handle = dev->pfun->handle;716 if (node->parent) { 717 parent_handle = node->parent->handle; 760 718 } else { 761 719 parent_handle = 0; 762 720 } 763 721 764 aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, dev->handle,722 aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle, 765 723 parent_handle, &answer); 766 724 767 725 /* Send the device's name to the driver. */ 768 rc = async_data_write_start(phone, dev->pfun->name,769 str_size( dev->pfun->name) + 1);726 rc = async_data_write_start(phone, node->name, 727 str_size(node->name) + 1); 770 728 if (rc != EOK) { 771 729 /* TODO handle error */ … … 777 735 switch(rc) { 778 736 case EOK: 779 dev->state = DEVICE_USABLE; 737 node->state = DEVICE_USABLE; 738 devmap_register_tree_device(node, tree); 780 739 break; 781 740 case ENOENT: 782 dev->state = DEVICE_NOT_PRESENT;741 node->state = DEVICE_NOT_PRESENT; 783 742 break; 784 743 default: 785 dev->state = DEVICE_INVALID;786 } 787 788 dev->passed_to_driver = true;744 node->state = DEVICE_INVALID; 745 } 746 747 node->passed_to_driver = true; 789 748 790 749 return; … … 798 757 * successfully assigned to the device, false otherwise. 799 758 */ 800 bool assign_driver(dev_node_t *dev, driver_list_t *drivers_list, 801 dev_tree_t *tree) 802 { 803 assert(dev != NULL); 804 assert(drivers_list != NULL); 805 assert(tree != NULL); 806 759 bool assign_driver(node_t *node, driver_list_t *drivers_list, dev_tree_t *tree) 760 { 807 761 /* 808 762 * Find the driver which is the most suitable for handling this device. 809 763 */ 810 driver_t *drv = find_best_match_driver(drivers_list, dev);764 driver_t *drv = find_best_match_driver(drivers_list, node); 811 765 if (drv == NULL) { 812 766 printf(NAME ": no driver found for device '%s'.\n", 813 dev->pfun->pathname);767 node->pathname); 814 768 return false; 815 769 } 816 770 817 771 /* Attach the driver to the device. */ 818 attach_driver( dev, drv);772 attach_driver(node, drv); 819 773 820 774 fibril_mutex_lock(&drv->driver_mutex); … … 829 783 /* Notify the driver about the new device. */ 830 784 int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0); 831 if (phone > =0) {832 add_device(phone, drv, dev, tree);833 async_hangup(phone);785 if (phone > 0) { 786 add_device(phone, drv, node, tree); 787 ipc_hangup(phone); 834 788 } 835 789 } … … 854 808 hash_table_create(&tree->devman_devices, DEVICE_BUCKETS, 1, 855 809 &devman_devices_ops); 856 hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1, 857 &devman_functions_ops); 858 hash_table_create(&tree->devmap_functions, DEVICE_BUCKETS, 1, 810 hash_table_create(&tree->devmap_devices, DEVICE_BUCKETS, 1, 859 811 &devmap_devices_ops); 860 812 861 813 fibril_rwlock_initialize(&tree->rwlock); 862 814 863 /* Create root function and root device and add themto the device tree. */864 if (!create_root_node s(tree))815 /* Create root node and add it to the device tree. */ 816 if (!create_root_node(tree)) 865 817 return false; 866 818 867 819 /* Find suitable driver and start it. */ 868 return assign_driver(tree->root_node ->child, drivers_list, tree);820 return assign_driver(tree->root_node, drivers_list, tree); 869 821 } 870 822 … … 875 827 * @return A device node structure. 876 828 */ 877 dev_node_t *create_dev_node(void)878 { 879 dev_node_t *res = malloc(sizeof(dev_node_t));829 node_t *create_dev_node(void) 830 { 831 node_t *res = malloc(sizeof(node_t)); 880 832 881 833 if (res != NULL) { 882 memset(res, 0, sizeof( dev_node_t));883 list_initialize(&res-> functions);884 li nk_initialize(&res->driver_devices);885 li nk_initialize(&res->devman_dev);834 memset(res, 0, sizeof(node_t)); 835 list_initialize(&res->children); 836 list_initialize(&res->match_ids.ids); 837 list_initialize(&res->classes); 886 838 } 887 839 … … 893 845 * @param node The device node structure. 894 846 */ 895 void delete_dev_node(dev_node_t *dev) 896 { 897 assert(list_empty(&dev->functions)); 898 assert(dev->pfun == NULL); 899 assert(dev->drv == NULL); 900 901 free(dev); 847 void delete_dev_node(node_t *node) 848 { 849 assert(list_empty(&node->children)); 850 assert(node->parent == NULL); 851 assert(node->drv == NULL); 852 853 clean_match_ids(&node->match_ids); 854 free_not_null(node->name); 855 free_not_null(node->pathname); 856 free(node); 902 857 } 903 858 904 859 /** Find the device node structure of the device witch has the specified handle. 860 * 861 * Device tree's rwlock should be held at least for reading. 905 862 * 906 863 * @param tree The device tree where we look for the device node. … … 908 865 * @return The device node. 909 866 */ 910 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) 911 868 { 912 869 unsigned long key = handle; 913 link_t *link; 914 915 assert(fibril_rwlock_is_locked(&tree->rwlock)); 916 917 link = hash_table_find(&tree->devman_devices, &key); 918 return hash_table_get_instance(link, dev_node_t, devman_dev); 870 link_t *link = hash_table_find(&tree->devman_devices, &key); 871 return hash_table_get_instance(link, node_t, devman_link); 919 872 } 920 873 … … 925 878 * @return The device node. 926 879 */ 927 dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle)928 { 929 dev_node_t *dev= NULL;880 node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle) 881 { 882 node_t *node = NULL; 930 883 931 884 fibril_rwlock_read_lock(&tree->rwlock); 932 dev= find_dev_node_no_lock(tree, handle);885 node = find_dev_node_no_lock(tree, handle); 933 886 fibril_rwlock_read_unlock(&tree->rwlock); 934 887 935 return dev; 936 } 937 938 /* Function nodes */ 939 940 /** Create a new function node. 941 * 942 * @return A function node structure. 943 */ 944 fun_node_t *create_fun_node(void) 945 { 946 fun_node_t *res = malloc(sizeof(fun_node_t)); 947 948 if (res != NULL) { 949 memset(res, 0, sizeof(fun_node_t)); 950 link_initialize(&res->dev_functions); 951 list_initialize(&res->match_ids.ids); 952 list_initialize(&res->classes); 953 link_initialize(&res->devman_fun); 954 link_initialize(&res->devmap_fun); 955 } 956 957 return res; 958 } 959 960 /** Delete a function node. 961 * 962 * @param fun The device node structure. 963 */ 964 void delete_fun_node(fun_node_t *fun) 965 { 966 assert(fun->dev == NULL); 967 assert(fun->child == NULL); 968 969 clean_match_ids(&fun->match_ids); 970 free_not_null(fun->name); 971 free_not_null(fun->pathname); 972 free(fun); 973 } 974 975 /** Find the function node with the specified handle. 976 * 977 * @param tree The device tree where we look for the device node. 978 * @param handle The handle of the function. 979 * @return The function node. 980 */ 981 fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle) 982 { 983 unsigned long key = handle; 984 link_t *link; 985 986 assert(fibril_rwlock_is_locked(&tree->rwlock)); 987 988 link = hash_table_find(&tree->devman_functions, &key); 989 if (link == NULL) 990 return NULL; 991 992 return hash_table_get_instance(link, fun_node_t, devman_fun); 993 } 994 995 /** Find the function node with the specified handle. 996 * 997 * @param tree The device tree where we look for the device node. 998 * @param handle The handle of the function. 999 * @return The function node. 1000 */ 1001 fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle) 1002 { 1003 fun_node_t *fun = NULL; 1004 1005 fibril_rwlock_read_lock(&tree->rwlock); 1006 fun = find_fun_node_no_lock(tree, handle); 1007 fibril_rwlock_read_unlock(&tree->rwlock); 1008 1009 return fun; 1010 } 888 return node; 889 } 890 1011 891 1012 892 /** Create and set device's full path in device tree. … … 1017 897 * resources etc.). 1018 898 */ 1019 static bool set_ fun_path(fun_node_t *fun, fun_node_t *parent)1020 { 1021 assert( fun->name != NULL);1022 1023 size_t pathsize = (str_size( fun->name) + 1);899 static bool set_dev_path(node_t *node, node_t *parent) 900 { 901 assert(node->name != NULL); 902 903 size_t pathsize = (str_size(node->name) + 1); 1024 904 if (parent != NULL) 1025 905 pathsize += str_size(parent->pathname) + 1; 1026 906 1027 fun->pathname = (char *) malloc(pathsize);1028 if ( fun->pathname == NULL) {907 node->pathname = (char *) malloc(pathsize); 908 if (node->pathname == NULL) { 1029 909 printf(NAME ": failed to allocate device path.\n"); 1030 910 return false; … … 1032 912 1033 913 if (parent != NULL) { 1034 str_cpy( fun->pathname, pathsize, parent->pathname);1035 str_append( fun->pathname, pathsize, "/");1036 str_append( fun->pathname, pathsize, fun->name);914 str_cpy(node->pathname, pathsize, parent->pathname); 915 str_append(node->pathname, pathsize, "/"); 916 str_append(node->pathname, pathsize, node->name); 1037 917 } else { 1038 str_cpy( fun->pathname, pathsize, fun->name);918 str_cpy(node->pathname, pathsize, node->name); 1039 919 } 1040 920 … … 1043 923 1044 924 /** Insert new device into device tree. 925 * 926 * The device tree's rwlock should be already held exclusively when calling this 927 * function. 1045 928 * 1046 929 * @param tree The device tree. … … 1052 935 * etc.). 1053 936 */ 1054 bool insert_dev_node(dev_tree_t *tree, dev_node_t *dev, fun_node_t *pfun) 1055 { 1056 assert(dev != NULL); 937 bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, 938 node_t *parent) 939 { 940 assert(node != NULL); 1057 941 assert(tree != NULL); 1058 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 942 assert(dev_name != NULL); 943 944 node->name = dev_name; 945 if (!set_dev_path(node, parent)) { 946 return false; 947 } 1059 948 1060 949 /* Add the node to the handle-to-node map. */ 1061 dev->handle = ++tree->current_handle;1062 unsigned long key = dev->handle;1063 hash_table_insert(&tree->devman_devices, &key, & dev->devman_dev);950 node->handle = ++tree->current_handle; 951 unsigned long key = node->handle; 952 hash_table_insert(&tree->devman_devices, &key, &node->devman_link); 1064 953 1065 954 /* Add the node to the list of its parent's children. */ 1066 printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);1067 dev->pfun = pfun;1068 pfun->child = dev;955 node->parent = parent; 956 if (parent != NULL) 957 list_append(&node->sibling, &parent->children); 1069 958 1070 959 return true; 1071 960 } 1072 961 1073 /** Insert new function into device tree. 1074 * 962 /** Find device node with a specified path in the device tree. 963 * 964 * @param path The path of the device node in the device tree. 1075 965 * @param tree The device tree. 1076 * @param node The newly added function node. 1077 * @param dev_name The name of the newly added function. 1078 * @param parent Owning device node. 1079 * 1080 * @return True on success, false otherwise (insufficient resources 1081 * etc.). 1082 */ 1083 bool insert_fun_node(dev_tree_t *tree, fun_node_t *fun, char *fun_name, 1084 dev_node_t *dev) 1085 { 1086 fun_node_t *pfun; 1087 1088 assert(fun != NULL); 1089 assert(tree != NULL); 1090 assert(fun_name != NULL); 1091 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 1092 966 * @return The device node if it is present in the tree, NULL 967 * otherwise. 968 */ 969 node_t *find_dev_node_by_path(dev_tree_t *tree, char *path) 970 { 971 fibril_rwlock_read_lock(&tree->rwlock); 972 973 node_t *dev = tree->root_node; 1093 974 /* 1094 * The root function is a special case, it does not belong to any 1095 * device so for the root function dev == NULL. 1096 */ 1097 pfun = (dev != NULL) ? dev->pfun : NULL; 1098 1099 fun->name = fun_name; 1100 if (!set_fun_path(fun, pfun)) { 1101 return false; 1102 } 1103 1104 /* Add the node to the handle-to-node map. */ 1105 fun->handle = ++tree->current_handle; 1106 unsigned long key = fun->handle; 1107 hash_table_insert(&tree->devman_functions, &key, &fun->devman_fun); 1108 1109 /* Add the node to the list of its parent's children. */ 1110 fun->dev = dev; 1111 if (dev != NULL) 1112 list_append(&fun->dev_functions, &dev->functions); 1113 1114 return true; 1115 } 1116 1117 /** Find function node with a specified path in the device tree. 1118 * 1119 * @param path The path of the function node in the device tree. 1120 * @param tree The device tree. 1121 * @return The function node if it is present in the tree, NULL 1122 * otherwise. 1123 */ 1124 fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path) 1125 { 1126 assert(path != NULL); 1127 1128 bool is_absolute = path[0] == '/'; 1129 if (!is_absolute) { 1130 return NULL; 1131 } 1132 1133 fibril_rwlock_read_lock(&tree->rwlock); 1134 1135 fun_node_t *fun = tree->root_node; 1136 /* 1137 * Relative path to the function from its parent (but with '/' at the 975 * Relative path to the device from its parent (but with '/' at the 1138 976 * beginning) 1139 977 */ 1140 978 char *rel_path = path; 1141 979 char *next_path_elem = NULL; 1142 bool cont = true;1143 1144 while (cont && fun!= NULL) {980 bool cont = (rel_path[0] == '/'); 981 982 while (cont && dev != NULL) { 1145 983 next_path_elem = get_path_elem_end(rel_path + 1); 1146 984 if (next_path_elem[0] == '/') { … … 1151 989 } 1152 990 1153 fun = find_node_child(fun, rel_path + 1);991 dev = find_node_child(dev, rel_path + 1); 1154 992 1155 993 if (cont) { … … 1162 1000 fibril_rwlock_read_unlock(&tree->rwlock); 1163 1001 1164 return fun;1165 } 1166 1167 /** Find child functionnode with a specified name.1002 return dev; 1003 } 1004 1005 /** Find child device node with a specified name. 1168 1006 * 1169 1007 * Device tree rwlock should be held at least for reading. 1170 1008 * 1171 * @param parent The parent functionnode.1172 * @param name The name of the child function.1173 * @return The child functionnode.1174 */ 1175 fun_node_t *find_node_child(fun_node_t *pfun, const char *name)1176 { 1177 fun_node_t *fun;1009 * @param parent The parent device node. 1010 * @param name The name of the child device node. 1011 * @return The child device node. 1012 */ 1013 node_t *find_node_child(node_t *parent, const char *name) 1014 { 1015 node_t *dev; 1178 1016 link_t *link; 1179 1017 1180 link = p fun->child->functions.next;1181 1182 while (link != &p fun->child->functions) {1183 fun = list_get_instance(link, fun_node_t, dev_functions);1018 link = parent->children.next; 1019 1020 while (link != &parent->children) { 1021 dev = list_get_instance(link, node_t, sibling); 1184 1022 1185 if (str_cmp(name, fun->name) == 0)1186 return fun;1023 if (str_cmp(name, dev->name) == 0) 1024 return dev; 1187 1025 1188 1026 link = link->next; … … 1223 1061 if (info != NULL) { 1224 1062 memset(info, 0, sizeof(dev_class_info_t)); 1225 li nk_initialize(&info->dev_classes);1226 li nk_initialize(&info->devmap_link);1227 li nk_initialize(&info->link);1063 list_initialize(&info->dev_classes); 1064 list_initialize(&info->devmap_link); 1065 list_initialize(&info->link); 1228 1066 } 1229 1067 … … 1267 1105 } 1268 1106 1269 /** Add the device functionto the class.1107 /** Add the device to the class. 1270 1108 * 1271 1109 * The device may be added to multiple classes and a class may contain multiple … … 1280 1118 * with the class. 1281 1119 */ 1282 dev_class_info_t *add_ function_to_class(fun_node_t *fun, dev_class_t *cl,1120 dev_class_info_t *add_device_to_class(node_t *dev, dev_class_t *cl, 1283 1121 const char *base_dev_name) 1284 1122 { 1285 dev_class_info_t *info; 1286 1287 assert(fun != NULL); 1288 assert(cl != NULL); 1289 1290 info = create_dev_class_info(); 1291 1123 dev_class_info_t *info = create_dev_class_info(); 1292 1124 1293 1125 if (info != NULL) { 1294 1126 info->dev_class = cl; 1295 info-> fun = fun;1127 info->dev = dev; 1296 1128 1297 1129 /* Add the device to the class. */ … … 1301 1133 1302 1134 /* Add the class to the device. */ 1303 list_append(&info->dev_classes, & fun->classes);1135 list_append(&info->dev_classes, &dev->classes); 1304 1136 1305 1137 /* Create unique name for the device within the class. */ … … 1355 1187 list_initialize(&class_list->classes); 1356 1188 fibril_rwlock_initialize(&class_list->rwlock); 1357 hash_table_create(&class_list->devmap_ functions, DEVICE_BUCKETS, 1,1189 hash_table_create(&class_list->devmap_devices, DEVICE_BUCKETS, 1, 1358 1190 &devmap_devices_class_ops); 1359 1191 } … … 1362 1194 /* Devmap devices */ 1363 1195 1364 fun_node_t *find_devmap_tree_function(dev_tree_t *tree, devmap_handle_t devmap_handle)1365 { 1366 fun_node_t *fun= NULL;1196 node_t *find_devmap_tree_device(dev_tree_t *tree, devmap_handle_t devmap_handle) 1197 { 1198 node_t *dev = NULL; 1367 1199 link_t *link; 1368 1200 unsigned long key = (unsigned long) devmap_handle; 1369 1201 1370 1202 fibril_rwlock_read_lock(&tree->rwlock); 1371 link = hash_table_find(&tree->devmap_ functions, &key);1203 link = hash_table_find(&tree->devmap_devices, &key); 1372 1204 if (link != NULL) 1373 fun = hash_table_get_instance(link, fun_node_t, devmap_fun);1205 dev = hash_table_get_instance(link, node_t, devmap_link); 1374 1206 fibril_rwlock_read_unlock(&tree->rwlock); 1375 1207 1376 return fun;1377 } 1378 1379 fun_node_t *find_devmap_class_function(class_list_t *classes,1208 return dev; 1209 } 1210 1211 node_t *find_devmap_class_device(class_list_t *classes, 1380 1212 devmap_handle_t devmap_handle) 1381 1213 { 1382 fun_node_t *fun= NULL;1214 node_t *dev = NULL; 1383 1215 dev_class_info_t *cli; 1384 1216 link_t *link; … … 1386 1218 1387 1219 fibril_rwlock_read_lock(&classes->rwlock); 1388 link = hash_table_find(&classes->devmap_ functions, &key);1220 link = hash_table_find(&classes->devmap_devices, &key); 1389 1221 if (link != NULL) { 1390 1222 cli = hash_table_get_instance(link, dev_class_info_t, 1391 1223 devmap_link); 1392 fun = cli->fun;1224 dev = cli->dev; 1393 1225 } 1394 1226 fibril_rwlock_read_unlock(&classes->rwlock); 1395 1227 1396 return fun;1397 } 1398 1399 void class_add_devmap_ function(class_list_t *class_list, dev_class_info_t *cli)1228 return dev; 1229 } 1230 1231 void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli) 1400 1232 { 1401 1233 unsigned long key = (unsigned long) cli->devmap_handle; 1402 1234 1403 1235 fibril_rwlock_write_lock(&class_list->rwlock); 1404 hash_table_insert(&class_list->devmap_ functions, &key, &cli->devmap_link);1236 hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link); 1405 1237 fibril_rwlock_write_unlock(&class_list->rwlock); 1406 1238 1407 assert(find_devmap_class_ function(class_list, cli->devmap_handle) != NULL);1408 } 1409 1410 void tree_add_devmap_ function(dev_tree_t *tree, fun_node_t *fun)1411 { 1412 unsigned long key = (unsigned long) fun->devmap_handle;1239 assert(find_devmap_class_device(class_list, cli->devmap_handle) != NULL); 1240 } 1241 1242 void tree_add_devmap_device(dev_tree_t *tree, node_t *node) 1243 { 1244 unsigned long key = (unsigned long) node->devmap_handle; 1413 1245 fibril_rwlock_write_lock(&tree->rwlock); 1414 hash_table_insert(&tree->devmap_ functions, &key, &fun->devmap_fun);1246 hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link); 1415 1247 fibril_rwlock_write_unlock(&tree->rwlock); 1416 1248 }
Note:
See TracChangeset
for help on using the changeset viewer.
