Changes in uspace/srv/devman/devman.c [4e00f87:77a69ea] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r4e00f87 r77a69ea 66 66 /* hash table operations */ 67 67 68 static inline size_t handle_key_hash(void *key) 69 { 70 devman_handle_t handle = *(devman_handle_t*)key; 71 return handle; 72 } 73 74 static size_t devman_devices_hash(const ht_link_t *item) 75 { 76 dev_node_t *dev = hash_table_get_inst(item, dev_node_t, devman_dev); 77 return handle_key_hash(&dev->handle); 78 } 79 80 static size_t devman_functions_hash(const ht_link_t *item) 81 { 82 fun_node_t *fun = hash_table_get_inst(item, fun_node_t, devman_fun); 83 return handle_key_hash(&fun->handle); 84 } 85 86 static bool devman_devices_key_equal(void *key, const ht_link_t *item) 87 { 88 devman_handle_t handle = *(devman_handle_t*)key; 89 dev_node_t *dev = hash_table_get_inst(item, dev_node_t, devman_dev); 90 return dev->handle == handle; 91 } 92 93 static bool devman_functions_key_equal(void *key, const ht_link_t *item) 94 { 95 devman_handle_t handle = *(devman_handle_t*)key; 96 fun_node_t *fun = hash_table_get_inst(item, fun_node_t, devman_fun); 97 return fun->handle == handle; 98 } 99 100 static inline size_t service_id_key_hash(void *key) 101 { 102 service_id_t service_id = *(service_id_t*)key; 103 return service_id; 104 } 105 106 static size_t loc_functions_hash(const ht_link_t *item) 107 { 108 fun_node_t *fun = hash_table_get_inst(item, fun_node_t, loc_fun); 109 return service_id_key_hash(&fun->service_id); 110 } 111 112 static bool loc_functions_key_equal(void *key, const ht_link_t *item) 113 { 114 service_id_t service_id = *(service_id_t*)key; 115 fun_node_t *fun = hash_table_get_inst(item, fun_node_t, loc_fun); 116 return fun->service_id == service_id; 117 } 118 119 120 static hash_table_ops_t devman_devices_ops = { 121 .hash = devman_devices_hash, 122 .key_hash = handle_key_hash, 123 .key_equal = devman_devices_key_equal, 124 .equal = NULL, 125 .remove_callback = NULL 68 static hash_index_t devices_hash(unsigned long key[]) 69 { 70 return key[0] % DEVICE_BUCKETS; 71 } 72 73 static int devman_devices_compare(unsigned long key[], hash_count_t keys, 74 link_t *item) 75 { 76 dev_node_t *dev = hash_table_get_instance(item, dev_node_t, devman_dev); 77 return (dev->handle == (devman_handle_t) key[0]); 78 } 79 80 static int devman_functions_compare(unsigned long key[], hash_count_t keys, 81 link_t *item) 82 { 83 fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devman_fun); 84 return (fun->handle == (devman_handle_t) key[0]); 85 } 86 87 static int loc_functions_compare(unsigned long key[], hash_count_t keys, 88 link_t *item) 89 { 90 fun_node_t *fun = hash_table_get_instance(item, fun_node_t, loc_fun); 91 return (fun->service_id == (service_id_t) key[0]); 92 } 93 94 static void devices_remove_callback(link_t *item) 95 { 96 } 97 98 static hash_table_operations_t devman_devices_ops = { 99 .hash = devices_hash, 100 .compare = devman_devices_compare, 101 .remove_callback = devices_remove_callback 126 102 }; 127 103 128 static hash_table_ops_t devman_functions_ops = { 129 .hash = devman_functions_hash, 130 .key_hash = handle_key_hash, 131 .key_equal = devman_functions_key_equal, 132 .equal = NULL, 133 .remove_callback = NULL 104 static hash_table_operations_t devman_functions_ops = { 105 .hash = devices_hash, 106 .compare = devman_functions_compare, 107 .remove_callback = devices_remove_callback 134 108 }; 135 109 136 static hash_table_ops_t loc_devices_ops = { 137 .hash = loc_functions_hash, 138 .key_hash = service_id_key_hash, 139 .key_equal = loc_functions_key_equal, 140 .equal = NULL, 141 .remove_callback = NULL 110 static hash_table_operations_t loc_devices_ops = { 111 .hash = devices_hash, 112 .compare = loc_functions_compare, 113 .remove_callback = devices_remove_callback 142 114 }; 143 115 … … 179 151 fibril_mutex_unlock(&drivers_list->drivers_mutex); 180 152 181 log_msg(L OG_DEFAULT, LVL_NOTE, "Driver `%s' was added to the list of available "153 log_msg(LVL_NOTE, "Driver `%s' was added to the list of available " 182 154 "drivers.", drv->name); 183 155 } … … 270 242 bool read_match_ids(const char *conf_path, match_id_list_t *ids) 271 243 { 272 log_msg(L OG_DEFAULT, LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);244 log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path); 273 245 274 246 bool suc = false; … … 280 252 fd = open(conf_path, O_RDONLY); 281 253 if (fd < 0) { 282 log_msg(L OG_DEFAULT, LVL_ERROR, "Unable to open `%s' for reading: %s.",254 log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.", 283 255 conf_path, str_error(fd)); 284 256 goto cleanup; … … 289 261 lseek(fd, 0, SEEK_SET); 290 262 if (len == 0) { 291 log_msg(L OG_DEFAULT, LVL_ERROR, "Configuration file '%s' is empty.",263 log_msg(LVL_ERROR, "Configuration file '%s' is empty.", 292 264 conf_path); 293 265 goto cleanup; … … 296 268 buf = malloc(len + 1); 297 269 if (buf == NULL) { 298 log_msg(L OG_DEFAULT, LVL_ERROR, "Memory allocation failed when parsing file "270 log_msg(LVL_ERROR, "Memory allocation failed when parsing file " 299 271 "'%s'.", conf_path); 300 272 goto cleanup; … … 303 275 ssize_t read_bytes = read_all(fd, buf, len); 304 276 if (read_bytes <= 0) { 305 log_msg(L OG_DEFAULT, LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path,277 log_msg(LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path, 306 278 read_bytes); 307 279 goto cleanup; … … 342 314 bool get_driver_info(const char *base_path, const char *name, driver_t *drv) 343 315 { 344 log_msg(L OG_DEFAULT, LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")",316 log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")", 345 317 base_path, name); 346 318 … … 374 346 struct stat s; 375 347 if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */ 376 log_msg(L OG_DEFAULT, LVL_ERROR, "Driver not found at path `%s'.",348 log_msg(LVL_ERROR, "Driver not found at path `%s'.", 377 349 drv->binary_path); 378 350 goto cleanup; … … 402 374 int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path) 403 375 { 404 log_msg(L OG_DEFAULT, LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path);376 log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path); 405 377 406 378 int drv_cnt = 0; … … 436 408 dev_node_t *dev; 437 409 438 log_msg(L OG_DEFAULT, LVL_DEBUG, "create_root_nodes()");410 log_msg(LVL_DEBUG, "create_root_nodes()"); 439 411 440 412 fibril_rwlock_write_lock(&tree->rwlock); … … 523 495 void attach_driver(dev_tree_t *tree, dev_node_t *dev, driver_t *drv) 524 496 { 525 log_msg(L OG_DEFAULT, LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")",497 log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")", 526 498 dev->pfun->pathname, drv->name); 527 499 … … 548 520 assert(drv != NULL); 549 521 550 log_msg(L OG_DEFAULT, LVL_DEBUG, "detach_driver(dev=\"%s\",drv=\"%s\")",522 log_msg(LVL_DEBUG, "detach_driver(dev=\"%s\",drv=\"%s\")", 551 523 dev->pfun->pathname, drv->name); 552 524 … … 573 545 assert(fibril_mutex_is_locked(&drv->driver_mutex)); 574 546 575 log_msg(L OG_DEFAULT, LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);547 log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name); 576 548 577 549 rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL); 578 550 if (rc != EOK) { 579 log_msg(L OG_DEFAULT, LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",551 log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.", 580 552 drv->name, drv->binary_path, str_error(rc)); 581 553 return false; … … 622 594 link_t *link; 623 595 624 log_msg(L OG_DEFAULT, LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")",596 log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")", 625 597 driver->name); 626 598 … … 642 614 } 643 615 644 log_msg(L OG_DEFAULT, LVL_DEBUG, "pass_devices_to_driver: dev->refcnt=%d\n",616 log_msg(LVL_DEBUG, "pass_devices_to_driver: dev->refcnt=%d\n", 645 617 (int)atomic_get(&dev->refcnt)); 646 618 dev_add_ref(dev); … … 678 650 * immediately and possibly started here as well. 679 651 */ 680 log_msg(L OG_DEFAULT, LVL_DEBUG, "Driver `%s' enters running state.", driver->name);652 log_msg(LVL_DEBUG, "Driver `%s' enters running state.", driver->name); 681 653 driver->state = DRIVER_RUNNING; 682 654 … … 695 667 void initialize_running_driver(driver_t *driver, dev_tree_t *tree) 696 668 { 697 log_msg(L OG_DEFAULT, LVL_DEBUG, "initialize_running_driver(driver=\"%s\")",669 log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")", 698 670 driver->name); 699 671 … … 789 761 * access any structures that would affect driver_t. 790 762 */ 791 log_msg(L OG_DEFAULT, LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")",763 log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")", 792 764 drv->name, dev->pfun->name); 793 765 … … 855 827 driver_t *drv = find_best_match_driver(drivers_list, dev); 856 828 if (drv == NULL) { 857 log_msg(L OG_DEFAULT, LVL_ERROR, "No driver found for device `%s'.",829 log_msg(LVL_ERROR, "No driver found for device `%s'.", 858 830 dev->pfun->pathname); 859 831 return false; … … 895 867 assert(dev != NULL); 896 868 897 log_msg(L OG_DEFAULT, LVL_DEBUG, "driver_dev_remove(%p)", dev);869 log_msg(LVL_DEBUG, "driver_dev_remove(%p)", dev); 898 870 899 871 fibril_rwlock_read_lock(&tree->rwlock); … … 918 890 assert(dev != NULL); 919 891 920 log_msg(L OG_DEFAULT, LVL_DEBUG, "driver_dev_gone(%p)", dev);892 log_msg(LVL_DEBUG, "driver_dev_gone(%p)", dev); 921 893 922 894 fibril_rwlock_read_lock(&tree->rwlock); … … 939 911 devman_handle_t handle; 940 912 941 log_msg(L OG_DEFAULT, LVL_DEBUG, "driver_fun_online(%p)", fun);913 log_msg(LVL_DEBUG, "driver_fun_online(%p)", fun); 942 914 943 915 fibril_rwlock_read_lock(&tree->rwlock); … … 967 939 devman_handle_t handle; 968 940 969 log_msg(L OG_DEFAULT, LVL_DEBUG, "driver_fun_offline(%p)", fun);941 log_msg(LVL_DEBUG, "driver_fun_offline(%p)", fun); 970 942 971 943 fibril_rwlock_read_lock(&tree->rwlock); … … 998 970 bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list) 999 971 { 1000 log_msg(L OG_DEFAULT, LVL_DEBUG, "init_device_tree()");972 log_msg(LVL_DEBUG, "init_device_tree()"); 1001 973 1002 974 tree->current_handle = 0; 1003 975 1004 hash_table_create(&tree->devman_devices, 0, 0, &devman_devices_ops); 1005 hash_table_create(&tree->devman_functions, 0, 0, &devman_functions_ops); 1006 hash_table_create(&tree->loc_functions, 0, 0, &loc_devices_ops); 976 hash_table_create(&tree->devman_devices, DEVICE_BUCKETS, 1, 977 &devman_devices_ops); 978 hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1, 979 &devman_functions_ops); 980 hash_table_create(&tree->loc_functions, DEVICE_BUCKETS, 1, 981 &loc_devices_ops); 1007 982 1008 983 fibril_rwlock_initialize(&tree->rwlock); … … 1038 1013 list_initialize(&dev->functions); 1039 1014 link_initialize(&dev->driver_devices); 1015 link_initialize(&dev->devman_dev); 1040 1016 1041 1017 return dev; … … 1076 1052 } 1077 1053 1054 1078 1055 /** Find the device node structure of the device witch has the specified handle. 1079 1056 * … … 1084 1061 dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle) 1085 1062 { 1063 unsigned long key = handle; 1064 link_t *link; 1065 1086 1066 assert(fibril_rwlock_is_locked(&tree->rwlock)); 1087 1067 1088 ht_link_t *link = hash_table_find(&tree->devman_devices, &handle);1068 link = hash_table_find(&tree->devman_devices, &key); 1089 1069 if (link == NULL) 1090 1070 return NULL; 1091 1071 1092 return hash_table_get_inst (link, dev_node_t, devman_dev);1072 return hash_table_get_instance(link, dev_node_t, devman_dev); 1093 1073 } 1094 1074 … … 1162 1142 fun->state = FUN_INIT; 1163 1143 atomic_set(&fun->refcnt, 0); 1164 fibril_mutex_initialize(&fun->busy_lock);1165 1144 link_initialize(&fun->dev_functions); 1166 1145 list_initialize(&fun->match_ids.ids); 1146 link_initialize(&fun->devman_fun); 1147 link_initialize(&fun->loc_fun); 1167 1148 1168 1149 return fun; … … 1205 1186 } 1206 1187 1207 /** Make function busy for reconfiguration operations. */1208 void fun_busy_lock(fun_node_t *fun)1209 {1210 fibril_mutex_lock(&fun->busy_lock);1211 }1212 1213 /** Mark end of reconfiguration operation. */1214 void fun_busy_unlock(fun_node_t *fun)1215 {1216 fibril_mutex_unlock(&fun->busy_lock);1217 }1218 1219 1188 /** Find the function node with the specified handle. 1220 1189 * … … 1225 1194 fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle) 1226 1195 { 1196 unsigned long key = handle; 1197 link_t *link; 1227 1198 fun_node_t *fun; 1228 1199 1229 1200 assert(fibril_rwlock_is_locked(&tree->rwlock)); 1230 1201 1231 ht_link_t *link = hash_table_find(&tree->devman_functions, &handle);1202 link = hash_table_find(&tree->devman_functions, &key); 1232 1203 if (link == NULL) 1233 1204 return NULL; 1234 1205 1235 fun = hash_table_get_inst (link, fun_node_t, devman_fun);1206 fun = hash_table_get_instance(link, fun_node_t, devman_fun); 1236 1207 1237 1208 return fun; … … 1278 1249 fun->pathname = (char *) malloc(pathsize); 1279 1250 if (fun->pathname == NULL) { 1280 log_msg(L OG_DEFAULT, LVL_ERROR, "Failed to allocate device path.");1251 log_msg(LVL_ERROR, "Failed to allocate device path."); 1281 1252 return false; 1282 1253 } … … 1306 1277 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 1307 1278 1308 log_msg(L OG_DEFAULT, LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])",1279 log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])", 1309 1280 dev, pfun, pfun->pathname); 1310 1281 1311 1282 /* Add the node to the handle-to-node map. */ 1312 1283 dev->handle = ++tree->current_handle; 1313 hash_table_insert(&tree->devman_devices, &dev->devman_dev); 1284 unsigned long key = dev->handle; 1285 hash_table_insert(&tree->devman_devices, &key, &dev->devman_dev); 1314 1286 1315 1287 /* Add the node to the list of its parent's children. */ … … 1329 1301 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 1330 1302 1331 log_msg(L OG_DEFAULT, LVL_DEBUG, "remove_dev_node(dev=%p)", dev);1303 log_msg(LVL_DEBUG, "remove_dev_node(dev=%p)", dev); 1332 1304 1333 1305 /* Remove node from the handle-to-node map. */ 1334 hash_table_remove(&tree->devman_devices, &dev->handle); 1306 unsigned long key = dev->handle; 1307 hash_table_remove(&tree->devman_devices, &key, 1); 1335 1308 1336 1309 /* Unlink from parent function. */ … … 1373 1346 /* Add the node to the handle-to-node map. */ 1374 1347 fun->handle = ++tree->current_handle; 1375 hash_table_insert(&tree->devman_functions, &fun->devman_fun); 1348 unsigned long key = fun->handle; 1349 hash_table_insert(&tree->devman_functions, &key, &fun->devman_fun); 1376 1350 1377 1351 /* Add the node to the list of its parent's children. */ … … 1393 1367 1394 1368 /* Remove the node from the handle-to-node map. */ 1395 hash_table_remove(&tree->devman_functions, &fun->handle); 1369 unsigned long key = fun->handle; 1370 hash_table_remove(&tree->devman_functions, &key, 1); 1396 1371 1397 1372 /* Remove the node from the list of its parent's children. */ … … 1506 1481 { 1507 1482 fun_node_t *fun = NULL; 1483 link_t *link; 1484 unsigned long key = (unsigned long) service_id; 1508 1485 1509 1486 fibril_rwlock_read_lock(&tree->rwlock); 1510 ht_link_t *link = hash_table_find(&tree->loc_functions, &service_id);1487 link = hash_table_find(&tree->loc_functions, &key); 1511 1488 if (link != NULL) { 1512 fun = hash_table_get_inst (link, fun_node_t, loc_fun);1489 fun = hash_table_get_instance(link, fun_node_t, loc_fun); 1513 1490 fun_add_ref(fun); 1514 1491 } … … 1522 1499 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 1523 1500 1524 hash_table_insert(&tree->loc_functions, &fun->loc_fun); 1501 unsigned long key = (unsigned long) fun->service_id; 1502 hash_table_insert(&tree->loc_functions, &key, &fun->loc_fun); 1525 1503 } 1526 1504
Note:
See TracChangeset
for help on using the changeset viewer.