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