66
66
/* hash table operations */
68
static hash_index_t devices_hash(unsigned long key[])
70
return key[0] % DEVICE_BUCKETS;
73
static int devman_devices_compare(unsigned long key[], hash_count_t keys,
76
dev_node_t *dev = hash_table_get_instance(item, dev_node_t, devman_dev);
77
return (dev->handle == (devman_handle_t) key[0]);
80
static int devman_functions_compare(unsigned long key[], hash_count_t keys,
83
fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devman_fun);
84
return (fun->handle == (devman_handle_t) key[0]);
87
static int loc_functions_compare(unsigned long key[], hash_count_t keys,
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]);
94
static void devices_remove_callback(link_t *item)
98
static hash_table_operations_t devman_devices_ops = {
100
.compare = devman_devices_compare,
101
.remove_callback = devices_remove_callback
104
static hash_table_operations_t devman_functions_ops = {
105
.hash = devices_hash,
106
.compare = devman_functions_compare,
107
.remove_callback = devices_remove_callback
110
static hash_table_operations_t loc_devices_ops = {
111
.hash = devices_hash,
112
.compare = loc_functions_compare,
113
.remove_callback = devices_remove_callback
68
static inline size_t handle_key_hash(void *key)
70
devman_handle_t handle = *(devman_handle_t*)key;
74
static size_t devman_devices_hash(const ht_link_t *item)
76
dev_node_t *dev = hash_table_get_inst(item, dev_node_t, devman_dev);
77
return handle_key_hash(&dev->handle);
80
static size_t devman_functions_hash(const ht_link_t *item)
82
fun_node_t *fun = hash_table_get_inst(item, fun_node_t, devman_fun);
83
return handle_key_hash(&fun->handle);
86
static bool devman_devices_key_equal(void *key, const ht_link_t *item)
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;
93
static bool devman_functions_key_equal(void *key, const ht_link_t *item)
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;
100
static inline size_t service_id_key_hash(void *key)
102
service_id_t service_id = *(service_id_t*)key;
106
static size_t loc_functions_hash(const ht_link_t *item)
108
fun_node_t *fun = hash_table_get_inst(item, fun_node_t, loc_fun);
109
return service_id_key_hash(&fun->service_id);
112
static bool loc_functions_key_equal(void *key, const ht_link_t *item)
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;
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,
125
.remove_callback = NULL
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,
133
.remove_callback = NULL
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,
141
.remove_callback = NULL
260
288
len = lseek(fd, 0, SEEK_END);
261
289
lseek(fd, 0, SEEK_SET);
263
log_msg(LVL_ERROR, "Configuration file '%s' is empty.",
291
log_msg(LOG_DEFAULT, LVL_ERROR, "Configuration file '%s' is empty.",
268
296
buf = malloc(len + 1);
269
297
if (buf == NULL) {
270
log_msg(LVL_ERROR, "Memory allocation failed when parsing file "
298
log_msg(LOG_DEFAULT, LVL_ERROR, "Memory allocation failed when parsing file "
271
299
"'%s'.", conf_path);
275
303
ssize_t read_bytes = read_all(fd, buf, len);
276
304
if (read_bytes <= 0) {
277
log_msg(LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path,
305
log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path,
545
573
assert(fibril_mutex_is_locked(&drv->driver_mutex));
547
log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);
575
log_msg(LOG_DEFAULT, LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);
549
577
rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL);
551
log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",
579
log_msg(LOG_DEFAULT, LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",
552
580
drv->name, drv->binary_path, str_error(rc));
970
998
bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list)
972
log_msg(LVL_DEBUG, "init_device_tree()");
1000
log_msg(LOG_DEFAULT, LVL_DEBUG, "init_device_tree()");
974
1002
tree->current_handle = 0;
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,
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);
983
1008
fibril_rwlock_initialize(&tree->rwlock);
1277
1306
assert(fibril_rwlock_is_write_locked(&tree->rwlock));
1279
log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])",
1308
log_msg(LOG_DEFAULT, LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])",
1280
1309
dev, pfun, pfun->pathname);
1282
1311
/* Add the node to the handle-to-node map. */
1283
1312
dev->handle = ++tree->current_handle;
1284
unsigned long key = dev->handle;
1285
hash_table_insert(&tree->devman_devices, &key, &dev->devman_dev);
1313
hash_table_insert(&tree->devman_devices, &dev->devman_dev);
1287
1315
/* Add the node to the list of its parent's children. */
1288
1316
dev->pfun = pfun;