Changes in uspace/srv/devman/devman.c [8b1e15ac:45059d6b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r8b1e15ac r45059d6b 34 34 #include <fcntl.h> 35 35 #include <sys/stat.h> 36 #include <io/log.h> 36 37 #include <ipc/driver.h> 37 38 #include <ipc/devman.h> 38 #include < devmap.h>39 #include <loc.h> 39 40 #include <str_error.h> 41 #include <stdio.h> 40 42 41 43 #include "devman.h" … … 64 66 } 65 67 66 static int devmap_functions_compare(unsigned long key[], hash_count_t keys,68 static int loc_functions_compare(unsigned long key[], hash_count_t keys, 67 69 link_t *item) 68 70 { 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]); 71 } 72 73 static int devmap_devices_class_compare(unsigned long key[], hash_count_t keys, 74 link_t *item) 75 { 76 dev_class_info_t *class_info 77 = hash_table_get_instance(item, dev_class_info_t, devmap_link); 78 assert(class_info != NULL); 79 80 return (class_info->devmap_handle == (devmap_handle_t) key[0]); 71 fun_node_t *fun = hash_table_get_instance(item, fun_node_t, loc_fun); 72 return (fun->service_id == (service_id_t) key[0]); 81 73 } 82 74 … … 97 89 }; 98 90 99 static hash_table_operations_t devmap_devices_ops = {91 static hash_table_operations_t loc_devices_ops = { 100 92 .hash = devices_hash, 101 .compare = devmap_functions_compare, 102 .remove_callback = devices_remove_callback 103 }; 104 105 static hash_table_operations_t devmap_devices_class_ops = { 106 .hash = devices_hash, 107 .compare = devmap_devices_class_compare, 93 .compare = loc_functions_compare, 108 94 .remove_callback = devices_remove_callback 109 95 }; … … 146 132 fibril_mutex_unlock(&drivers_list->drivers_mutex); 147 133 148 printf(NAME": the '%s' driverwas added to the list of available "149 "drivers. \n", drv->name);134 log_msg(LVL_NOTE, "Driver `%s' was added to the list of available " 135 "drivers.", drv->name); 150 136 } 151 137 … … 237 223 bool read_match_ids(const char *conf_path, match_id_list_t *ids) 238 224 { 239 printf(NAME ": read_match_ids conf_path = %s.\n", conf_path);225 log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path); 240 226 241 227 bool suc = false; … … 247 233 fd = open(conf_path, O_RDONLY); 248 234 if (fd < 0) { 249 printf(NAME ": unable to open %s\n", conf_path); 235 log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.", 236 conf_path, str_error(fd)); 250 237 goto cleanup; 251 238 } … … 255 242 lseek(fd, 0, SEEK_SET); 256 243 if (len == 0) { 257 printf(NAME ": configuration file '%s' is empty.\n", conf_path); 244 log_msg(LVL_ERROR, "Configuration file '%s' is empty.", 245 conf_path); 258 246 goto cleanup; 259 247 } … … 261 249 buf = malloc(len + 1); 262 250 if (buf == NULL) { 263 printf(NAME ": memory allocation failed when parsing file "264 "'%s'. \n", conf_path);251 log_msg(LVL_ERROR, "Memory allocation failed when parsing file " 252 "'%s'.", conf_path); 265 253 goto cleanup; 266 254 } 267 255 268 if (read(fd, buf, len) <= 0) { 269 printf(NAME ": unable to read file '%s'.\n", conf_path); 256 ssize_t read_bytes = read_all(fd, buf, len); 257 if (read_bytes <= 0) { 258 log_msg(LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path, 259 read_bytes); 270 260 goto cleanup; 271 261 } 272 buf[ len] = 0;262 buf[read_bytes] = 0; 273 263 274 264 suc = parse_match_ids(buf, ids); … … 305 295 bool get_driver_info(const char *base_path, const char *name, driver_t *drv) 306 296 { 307 printf(NAME ": get_driver_info base_path = %s, name = %s.\n",297 log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")", 308 298 base_path, name); 309 299 … … 337 327 struct stat s; 338 328 if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */ 339 printf(NAME ": driver not found at path %s.", drv->binary_path); 329 log_msg(LVL_ERROR, "Driver not found at path `%s'.", 330 drv->binary_path); 340 331 goto cleanup; 341 332 } … … 364 355 int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path) 365 356 { 366 printf(NAME ": lookup_available_drivers, dir = %s \n", dir_path);357 log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path); 367 358 368 359 int drv_cnt = 0; … … 398 389 dev_node_t *dev; 399 390 400 printf(NAME ": create_root_nodes\n");391 log_msg(LVL_DEBUG, "create_root_nodes()"); 401 392 402 393 fibril_rwlock_write_lock(&tree->rwlock); … … 415 406 } 416 407 417 insert_fun_node(tree, fun, clone_string(""), NULL);408 insert_fun_node(tree, fun, str_dup(""), NULL); 418 409 match_id_t *id = create_match_id(); 419 id->id = clone_string("root");410 id->id = str_dup("root"); 420 411 id->score = 100; 421 412 add_match_id(&fun->match_ids, id); … … 460 451 fibril_mutex_lock(&drivers_list->drivers_mutex); 461 452 462 link_t *link = drivers_list->drivers.next; 463 while (link != &drivers_list->drivers) { 453 list_foreach(drivers_list->drivers, link) { 464 454 drv = list_get_instance(link, driver_t, drivers); 465 455 score = get_match_score(drv, node); … … 468 458 best_drv = drv; 469 459 } 470 link = link->next;471 460 } 472 461 … … 483 472 void attach_driver(dev_node_t *dev, driver_t *drv) 484 473 { 485 printf(NAME ": attach_driver %s to device %s\n",486 d rv->name, dev->pfun->pathname);474 log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")", 475 dev->pfun->pathname, drv->name); 487 476 488 477 fibril_mutex_lock(&drv->driver_mutex); … … 506 495 assert(fibril_mutex_is_locked(&drv->driver_mutex)); 507 496 508 printf(NAME ": start_driver '%s'\n", drv->name);497 log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name); 509 498 510 499 rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL); 511 500 if (rc != EOK) { 512 printf(NAME ": error spawning %s (%s)\n",513 drv->name, str_error(rc));501 log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.", 502 drv->name, drv->binary_path, str_error(rc)); 514 503 return false; 515 504 } … … 530 519 driver_t *res = NULL; 531 520 driver_t *drv = NULL; 532 link_t *link;533 521 534 522 fibril_mutex_lock(&drv_list->drivers_mutex); 535 523 536 link = drv_list->drivers.next; 537 while (link != &drv_list->drivers) { 524 list_foreach(drv_list->drivers, link) { 538 525 drv = list_get_instance(link, driver_t, drivers); 539 526 if (str_cmp(drv->name, drv_name) == 0) { … … 541 528 break; 542 529 } 543 544 link = link->next;545 530 } 546 531 … … 548 533 549 534 return res; 550 }551 552 /** Remember the driver's phone.553 *554 * @param driver The driver.555 * @param phone The phone to the driver.556 */557 void set_driver_phone(driver_t *driver, sysarg_t phone)558 {559 fibril_mutex_lock(&driver->driver_mutex);560 assert(driver->state == DRIVER_STARTING);561 driver->phone = phone;562 fibril_mutex_unlock(&driver->driver_mutex);563 535 } 564 536 … … 571 543 dev_node_t *dev; 572 544 link_t *link; 573 int phone; 574 575 printf(NAME ": pass_devices_to_driver(`%s')\n",driver->name);545 546 log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")", 547 driver->name); 576 548 577 549 fibril_mutex_lock(&driver->driver_mutex); 578 579 phone = async_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0);580 581 if (phone < 0) {582 fibril_mutex_unlock(&driver->driver_mutex);583 return;584 }585 550 586 551 /* … … 588 553 * that has not been passed to the driver. 589 554 */ 590 link = driver->devices. next;591 while (link != &driver->devices ) {555 link = driver->devices.head.next; 556 while (link != &driver->devices.head) { 592 557 dev = list_get_instance(link, dev_node_t, driver_devices); 593 558 if (dev->passed_to_driver) { … … 608 573 fibril_mutex_unlock(&driver->driver_mutex); 609 574 610 add_device( phone,driver, dev, tree);575 add_device(driver, dev, tree); 611 576 612 577 /* … … 626 591 * Restart the cycle to go through all devices again. 627 592 */ 628 link = driver->devices.next; 629 } 630 631 async_hangup(phone); 593 link = driver->devices.head.next; 594 } 632 595 633 596 /* … … 640 603 * immediately and possibly started here as well. 641 604 */ 642 printf(NAME ": driver %s goes into running state.\n", driver->name);605 log_msg(LVL_DEBUG, "Driver `%s' enters running state.", driver->name); 643 606 driver->state = DRIVER_RUNNING; 644 607 … … 657 620 void initialize_running_driver(driver_t *driver, dev_tree_t *tree) 658 621 { 659 printf(NAME ": initialize_running_driver (`%s')\n", driver->name); 622 log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")", 623 driver->name); 660 624 661 625 /* … … 678 642 list_initialize(&drv->devices); 679 643 fibril_mutex_initialize(&drv->driver_mutex); 644 drv->sess = NULL; 680 645 } 681 646 … … 708 673 } 709 674 710 /** Create devmappath and name for the function. */711 void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)712 { 713 char * devmap_pathname = NULL;714 char * devmap_name = NULL;715 716 asprintf(& devmap_name, "%s", fun->pathname);717 if ( devmap_name == NULL)675 /** Create loc path and name for the function. */ 676 void loc_register_tree_function(fun_node_t *fun, dev_tree_t *tree) 677 { 678 char *loc_pathname = NULL; 679 char *loc_name = NULL; 680 681 asprintf(&loc_name, "%s", fun->pathname); 682 if (loc_name == NULL) 718 683 return; 719 684 720 replace_char( devmap_name, '/', DEVMAP_SEPARATOR);721 722 asprintf(& devmap_pathname, "%s/%s", DEVMAP_DEVICE_NAMESPACE,723 devmap_name);724 if ( devmap_pathname == NULL) {725 free( devmap_name);685 replace_char(loc_name, '/', LOC_SEPARATOR); 686 687 asprintf(&loc_pathname, "%s/%s", LOC_DEVICE_NAMESPACE, 688 loc_name); 689 if (loc_pathname == NULL) { 690 free(loc_name); 726 691 return; 727 692 } 728 693 729 devmap_device_register_with_iface(devmap_pathname,730 &fun-> devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);731 732 tree_add_ devmap_function(tree, fun);733 734 free( devmap_name);735 free( devmap_pathname);694 loc_service_register_with_iface(loc_pathname, 695 &fun->service_id, DEVMAN_CONNECT_FROM_LOC); 696 697 tree_add_loc_function(tree, fun); 698 699 free(loc_name); 700 free(loc_pathname); 736 701 } 737 702 … … 741 706 * @param node The device's node in the device tree. 742 707 */ 743 void add_device( int phone,driver_t *drv, dev_node_t *dev, dev_tree_t *tree)708 void add_device(driver_t *drv, dev_node_t *dev, dev_tree_t *tree) 744 709 { 745 710 /* … … 747 712 * access any structures that would affect driver_t. 748 713 */ 749 printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name, 750 dev->pfun->name); 751 752 sysarg_t rc; 753 ipc_call_t answer; 714 log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")", 715 drv->name, dev->pfun->name); 754 716 755 717 /* Send the device to the driver. */ … … 760 722 parent_handle = 0; 761 723 } 762 763 aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, dev->handle, 724 725 async_exch_t *exch = async_exchange_begin(drv->sess); 726 727 ipc_call_t answer; 728 aid_t req = async_send_2(exch, DRIVER_ADD_DEVICE, dev->handle, 764 729 parent_handle, &answer); 765 730 766 /* Send the device 'sname to the driver. */767 rc = async_data_write_start(phone, dev->pfun->name,731 /* Send the device name to the driver. */ 732 sysarg_t rc = async_data_write_start(exch, dev->pfun->name, 768 733 str_size(dev->pfun->name) + 1); 734 735 async_exchange_end(exch); 736 769 737 if (rc != EOK) { 770 738 /* TODO handle error */ … … 809 777 driver_t *drv = find_best_match_driver(drivers_list, dev); 810 778 if (drv == NULL) { 811 printf(NAME ": no driver found for device '%s'.\n",779 log_msg(LVL_ERROR, "No driver found for device `%s'.", 812 780 dev->pfun->pathname); 813 781 return false; … … 825 793 fibril_mutex_unlock(&drv->driver_mutex); 826 794 827 if (is_running) { 828 /* Notify the driver about the new device. */ 829 int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0); 830 if (phone >= 0) { 831 add_device(phone, drv, dev, tree); 832 async_hangup(phone); 833 } 834 } 795 /* Notify the driver about the new device. */ 796 if (is_running) 797 add_device(drv, dev, tree); 835 798 836 799 return true; … … 847 810 bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list) 848 811 { 849 printf(NAME ": init_device_tree.\n");812 log_msg(LVL_DEBUG, "init_device_tree()"); 850 813 851 814 tree->current_handle = 0; … … 855 818 hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1, 856 819 &devman_functions_ops); 857 hash_table_create(&tree-> devmap_functions, DEVICE_BUCKETS, 1,858 & devmap_devices_ops);820 hash_table_create(&tree->loc_functions, DEVICE_BUCKETS, 1, 821 &loc_devices_ops); 859 822 860 823 fibril_rwlock_initialize(&tree->rwlock); … … 935 898 } 936 899 900 /** Get list of device functions. */ 901 int dev_get_functions(dev_tree_t *tree, dev_node_t *dev, 902 devman_handle_t *hdl_buf, size_t buf_size, size_t *act_size) 903 { 904 size_t act_cnt; 905 size_t buf_cnt; 906 907 assert(fibril_rwlock_is_locked(&tree->rwlock)); 908 909 buf_cnt = buf_size / sizeof(devman_handle_t); 910 911 act_cnt = list_count(&dev->functions); 912 *act_size = act_cnt * sizeof(devman_handle_t); 913 914 if (buf_size % sizeof(devman_handle_t) != 0) 915 return EINVAL; 916 917 size_t pos = 0; 918 list_foreach(dev->functions, item) { 919 fun_node_t *fun = 920 list_get_instance(item, fun_node_t, dev_functions); 921 922 if (pos < buf_cnt) 923 hdl_buf[pos] = fun->handle; 924 pos++; 925 } 926 927 return EOK; 928 } 929 930 937 931 /* Function nodes */ 938 932 … … 949 943 link_initialize(&res->dev_functions); 950 944 list_initialize(&res->match_ids.ids); 951 list_initialize(&res->classes);952 945 link_initialize(&res->devman_fun); 953 link_initialize(&res-> devmap_fun);946 link_initialize(&res->loc_fun); 954 947 } 955 948 … … 1026 1019 fun->pathname = (char *) malloc(pathsize); 1027 1020 if (fun->pathname == NULL) { 1028 printf(NAME ": failed to allocate device path.\n");1021 log_msg(LVL_ERROR, "Failed to allocate device path."); 1029 1022 return false; 1030 1023 } … … 1057 1050 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 1058 1051 1052 log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])", 1053 dev, pfun, pfun->pathname); 1054 1059 1055 /* Add the node to the handle-to-node map. */ 1060 1056 dev->handle = ++tree->current_handle; … … 1063 1059 1064 1060 /* 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 1061 dev->pfun = pfun; 1067 1062 pfun->child = dev; … … 1112 1107 1113 1108 return true; 1109 } 1110 1111 /** Remove function from device tree. 1112 * 1113 * @param tree Device tree 1114 * @param node Function node to remove 1115 */ 1116 void remove_fun_node(dev_tree_t *tree, fun_node_t *fun) 1117 { 1118 assert(tree != NULL); 1119 assert(fun != NULL); 1120 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 1121 1122 /* Remove the node from the handle-to-node map. */ 1123 unsigned long key = fun->handle; 1124 hash_table_remove(&tree->devman_functions, &key, 1); 1125 1126 /* Remove the node from the list of its parent's children. */ 1127 if (fun->dev != NULL) 1128 list_remove(&fun->dev_functions); 1114 1129 } 1115 1130 … … 1123 1138 fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path) 1124 1139 { 1140 assert(path != NULL); 1141 1142 bool is_absolute = path[0] == '/'; 1143 if (!is_absolute) { 1144 return NULL; 1145 } 1146 1125 1147 fibril_rwlock_read_lock(&tree->rwlock); 1126 1148 … … 1132 1154 char *rel_path = path; 1133 1155 char *next_path_elem = NULL; 1134 bool cont = (rel_path[ 0] == '/');1156 bool cont = (rel_path[1] != '\0'); 1135 1157 1136 1158 while (cont && fun != NULL) { … … 1157 1179 } 1158 1180 1181 /** Find function with a specified name belonging to given device. 1182 * 1183 * Device tree rwlock should be held at least for reading. 1184 * 1185 * @param dev Device the function belongs to. 1186 * @param name Function name (not path). 1187 * @return Function node. 1188 * @retval NULL No function with given name. 1189 */ 1190 fun_node_t *find_fun_node_in_device(dev_node_t *dev, const char *name) 1191 { 1192 assert(dev != NULL); 1193 assert(name != NULL); 1194 1195 fun_node_t *fun; 1196 1197 list_foreach(dev->functions, link) { 1198 fun = list_get_instance(link, fun_node_t, dev_functions); 1199 1200 if (str_cmp(name, fun->name) == 0) 1201 return fun; 1202 } 1203 1204 return NULL; 1205 } 1206 1159 1207 /** Find child function node with a specified name. 1160 1208 * … … 1167 1215 fun_node_t *find_node_child(fun_node_t *pfun, const char *name) 1168 1216 { 1169 fun_node_t *fun; 1170 link_t *link; 1171 1172 link = pfun->child->functions.next; 1173 1174 while (link != &pfun->child->functions) { 1175 fun = list_get_instance(link, fun_node_t, dev_functions); 1176 1177 if (str_cmp(name, fun->name) == 0) 1178 return fun; 1179 1180 link = link->next; 1181 } 1182 1183 return NULL; 1184 } 1185 1186 /* Device classes */ 1187 1188 /** Create device class. 1189 * 1190 * @return Device class. 1191 */ 1192 dev_class_t *create_dev_class(void) 1193 { 1194 dev_class_t *cl; 1195 1196 cl = (dev_class_t *) malloc(sizeof(dev_class_t)); 1197 if (cl != NULL) { 1198 memset(cl, 0, sizeof(dev_class_t)); 1199 list_initialize(&cl->devices); 1200 fibril_mutex_initialize(&cl->mutex); 1201 } 1202 1203 return cl; 1204 } 1205 1206 /** Create device class info. 1207 * 1208 * @return Device class info. 1209 */ 1210 dev_class_info_t *create_dev_class_info(void) 1211 { 1212 dev_class_info_t *info; 1213 1214 info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t)); 1215 if (info != NULL) { 1216 memset(info, 0, sizeof(dev_class_info_t)); 1217 list_initialize(&info->dev_classes); 1218 list_initialize(&info->devmap_link); 1219 list_initialize(&info->link); 1220 } 1221 1222 return info; 1223 } 1224 1225 size_t get_new_class_dev_idx(dev_class_t *cl) 1226 { 1227 size_t dev_idx; 1228 1229 fibril_mutex_lock(&cl->mutex); 1230 dev_idx = ++cl->curr_dev_idx; 1231 fibril_mutex_unlock(&cl->mutex); 1232 1233 return dev_idx; 1234 } 1235 1236 1237 /** Create unique device name within the class. 1238 * 1239 * @param cl The class. 1240 * @param base_dev_name Contains the base name for the device if it was 1241 * specified by the driver when it registered the device by 1242 * the class; NULL if driver specified no base name. 1243 * @return The unique name for the device within the class. 1244 */ 1245 char *create_dev_name_for_class(dev_class_t *cl, const char *base_dev_name) 1246 { 1247 char *dev_name; 1248 const char *base_name; 1249 1250 if (base_dev_name != NULL) 1251 base_name = base_dev_name; 1252 else 1253 base_name = cl->base_dev_name; 1254 1255 size_t idx = get_new_class_dev_idx(cl); 1256 asprintf(&dev_name, "%s%zu", base_name, idx); 1257 1258 return dev_name; 1259 } 1260 1261 /** Add the device function to the class. 1262 * 1263 * The device may be added to multiple classes and a class may contain multiple 1264 * devices. The class and the device are associated with each other by the 1265 * dev_class_info_t structure. 1266 * 1267 * @param dev The device. 1268 * @param class The class. 1269 * @param base_dev_name The base name of the device within the class if 1270 * specified by the driver, NULL otherwise. 1271 * @return dev_class_info_t structure which associates the device 1272 * with the class. 1273 */ 1274 dev_class_info_t *add_function_to_class(fun_node_t *fun, dev_class_t *cl, 1275 const char *base_dev_name) 1276 { 1277 dev_class_info_t *info; 1278 1279 assert(fun != NULL); 1280 assert(cl != NULL); 1281 1282 info = create_dev_class_info(); 1283 1284 1285 if (info != NULL) { 1286 info->dev_class = cl; 1287 info->fun = fun; 1288 1289 /* Add the device to the class. */ 1290 fibril_mutex_lock(&cl->mutex); 1291 list_append(&info->link, &cl->devices); 1292 fibril_mutex_unlock(&cl->mutex); 1293 1294 /* Add the class to the device. */ 1295 list_append(&info->dev_classes, &fun->classes); 1296 1297 /* Create unique name for the device within the class. */ 1298 info->dev_name = create_dev_name_for_class(cl, base_dev_name); 1299 } 1300 1301 return info; 1302 } 1303 1304 dev_class_t *get_dev_class(class_list_t *class_list, char *class_name) 1305 { 1306 dev_class_t *cl; 1307 1308 fibril_rwlock_write_lock(&class_list->rwlock); 1309 cl = find_dev_class_no_lock(class_list, class_name); 1310 if (cl == NULL) { 1311 cl = create_dev_class(); 1312 if (cl != NULL) { 1313 cl->name = class_name; 1314 cl->base_dev_name = ""; 1315 add_dev_class_no_lock(class_list, cl); 1316 } 1317 } 1318 1319 fibril_rwlock_write_unlock(&class_list->rwlock); 1320 return cl; 1321 } 1322 1323 dev_class_t *find_dev_class_no_lock(class_list_t *class_list, 1324 const char *class_name) 1325 { 1326 dev_class_t *cl; 1327 link_t *link = class_list->classes.next; 1328 1329 while (link != &class_list->classes) { 1330 cl = list_get_instance(link, dev_class_t, link); 1331 if (str_cmp(cl->name, class_name) == 0) { 1332 return cl; 1333 } 1334 link = link->next; 1335 } 1336 1337 return NULL; 1338 } 1339 1340 void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl) 1341 { 1342 list_append(&cl->link, &class_list->classes); 1343 } 1344 1345 void init_class_list(class_list_t *class_list) 1346 { 1347 list_initialize(&class_list->classes); 1348 fibril_rwlock_initialize(&class_list->rwlock); 1349 hash_table_create(&class_list->devmap_functions, DEVICE_BUCKETS, 1, 1350 &devmap_devices_class_ops); 1351 } 1352 1353 1354 /* Devmap devices */ 1355 1356 fun_node_t *find_devmap_tree_function(dev_tree_t *tree, devmap_handle_t devmap_handle) 1217 return find_fun_node_in_device(pfun->child, name); 1218 } 1219 1220 /* loc devices */ 1221 1222 fun_node_t *find_loc_tree_function(dev_tree_t *tree, service_id_t service_id) 1357 1223 { 1358 1224 fun_node_t *fun = NULL; 1359 1225 link_t *link; 1360 unsigned long key = (unsigned long) devmap_handle;1226 unsigned long key = (unsigned long) service_id; 1361 1227 1362 1228 fibril_rwlock_read_lock(&tree->rwlock); 1363 link = hash_table_find(&tree-> devmap_functions, &key);1229 link = hash_table_find(&tree->loc_functions, &key); 1364 1230 if (link != NULL) 1365 fun = hash_table_get_instance(link, fun_node_t, devmap_fun);1231 fun = hash_table_get_instance(link, fun_node_t, loc_fun); 1366 1232 fibril_rwlock_read_unlock(&tree->rwlock); 1367 1233 … … 1369 1235 } 1370 1236 1371 fun_node_t *find_devmap_class_function(class_list_t *classes, 1372 devmap_handle_t devmap_handle) 1373 { 1374 fun_node_t *fun = NULL; 1375 dev_class_info_t *cli; 1376 link_t *link; 1377 unsigned long key = (unsigned long)devmap_handle; 1378 1379 fibril_rwlock_read_lock(&classes->rwlock); 1380 link = hash_table_find(&classes->devmap_functions, &key); 1381 if (link != NULL) { 1382 cli = hash_table_get_instance(link, dev_class_info_t, 1383 devmap_link); 1384 fun = cli->fun; 1385 } 1386 fibril_rwlock_read_unlock(&classes->rwlock); 1387 1388 return fun; 1389 } 1390 1391 void class_add_devmap_function(class_list_t *class_list, dev_class_info_t *cli) 1392 { 1393 unsigned long key = (unsigned long) cli->devmap_handle; 1394 1395 fibril_rwlock_write_lock(&class_list->rwlock); 1396 hash_table_insert(&class_list->devmap_functions, &key, &cli->devmap_link); 1397 fibril_rwlock_write_unlock(&class_list->rwlock); 1398 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; 1237 void tree_add_loc_function(dev_tree_t *tree, fun_node_t *fun) 1238 { 1239 unsigned long key = (unsigned long) fun->service_id; 1405 1240 fibril_rwlock_write_lock(&tree->rwlock); 1406 hash_table_insert(&tree-> devmap_functions, &key, &fun->devmap_fun);1241 hash_table_insert(&tree->loc_functions, &key, &fun->loc_fun); 1407 1242 fibril_rwlock_write_unlock(&tree->rwlock); 1408 1243 }
Note:
See TracChangeset
for help on using the changeset viewer.