Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/devman.c

    r77a69ea r4e00f87  
    6666/* hash table operations */
    6767
    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
     68static inline size_t handle_key_hash(void *key)
     69{
     70        devman_handle_t handle = *(devman_handle_t*)key;
     71        return handle;
     72}
     73
     74static 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
     80static 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
     86static 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
     93static 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
     100static 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
     106static 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
     112static 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
     120static 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
    102126};
    103127
    104 static hash_table_operations_t devman_functions_ops = {
    105         .hash = devices_hash,
    106         .compare = devman_functions_compare,
    107         .remove_callback = devices_remove_callback
     128static 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
    108134};
    109135
    110 static hash_table_operations_t loc_devices_ops = {
    111         .hash = devices_hash,
    112         .compare = loc_functions_compare,
    113         .remove_callback = devices_remove_callback
     136static 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
    114142};
    115143
     
    151179        fibril_mutex_unlock(&drivers_list->drivers_mutex);
    152180
    153         log_msg(LVL_NOTE, "Driver `%s' was added to the list of available "
     181        log_msg(LOG_DEFAULT, LVL_NOTE, "Driver `%s' was added to the list of available "
    154182            "drivers.", drv->name);
    155183}
     
    242270bool read_match_ids(const char *conf_path, match_id_list_t *ids)
    243271{
    244         log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);
     272        log_msg(LOG_DEFAULT, LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);
    245273       
    246274        bool suc = false;
     
    252280        fd = open(conf_path, O_RDONLY);
    253281        if (fd < 0) {
    254                 log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.",
     282                log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to open `%s' for reading: %s.",
    255283                    conf_path, str_error(fd));
    256284                goto cleanup;
     
    261289        lseek(fd, 0, SEEK_SET);
    262290        if (len == 0) {
    263                 log_msg(LVL_ERROR, "Configuration file '%s' is empty.",
     291                log_msg(LOG_DEFAULT, LVL_ERROR, "Configuration file '%s' is empty.",
    264292                    conf_path);
    265293                goto cleanup;
     
    268296        buf = malloc(len + 1);
    269297        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 "
    271299                    "'%s'.", conf_path);
    272300                goto cleanup;
     
    275303        ssize_t read_bytes = read_all(fd, buf, len);
    276304        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,
    278306                    read_bytes);
    279307                goto cleanup;
     
    314342bool get_driver_info(const char *base_path, const char *name, driver_t *drv)
    315343{
    316         log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")",
     344        log_msg(LOG_DEFAULT, LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")",
    317345            base_path, name);
    318346       
     
    346374        struct stat s;
    347375        if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */
    348                 log_msg(LVL_ERROR, "Driver not found at path `%s'.",
     376                log_msg(LOG_DEFAULT, LVL_ERROR, "Driver not found at path `%s'.",
    349377                    drv->binary_path);
    350378                goto cleanup;
     
    374402int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path)
    375403{
    376         log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path);
     404        log_msg(LOG_DEFAULT, LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path);
    377405       
    378406        int drv_cnt = 0;
     
    408436        dev_node_t *dev;
    409437       
    410         log_msg(LVL_DEBUG, "create_root_nodes()");
     438        log_msg(LOG_DEFAULT, LVL_DEBUG, "create_root_nodes()");
    411439       
    412440        fibril_rwlock_write_lock(&tree->rwlock);
     
    495523void attach_driver(dev_tree_t *tree, dev_node_t *dev, driver_t *drv)
    496524{
    497         log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")",
     525        log_msg(LOG_DEFAULT, LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")",
    498526            dev->pfun->pathname, drv->name);
    499527       
     
    520548        assert(drv != NULL);
    521549       
    522         log_msg(LVL_DEBUG, "detach_driver(dev=\"%s\",drv=\"%s\")",
     550        log_msg(LOG_DEFAULT, LVL_DEBUG, "detach_driver(dev=\"%s\",drv=\"%s\")",
    523551            dev->pfun->pathname, drv->name);
    524552       
     
    545573        assert(fibril_mutex_is_locked(&drv->driver_mutex));
    546574       
    547         log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);
     575        log_msg(LOG_DEFAULT, LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);
    548576       
    549577        rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL);
    550578        if (rc != EOK) {
    551                 log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",
     579                log_msg(LOG_DEFAULT, LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",
    552580                    drv->name, drv->binary_path, str_error(rc));
    553581                return false;
     
    594622        link_t *link;
    595623
    596         log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")",
     624        log_msg(LOG_DEFAULT, LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")",
    597625            driver->name);
    598626
     
    614642                }
    615643
    616                 log_msg(LVL_DEBUG, "pass_devices_to_driver: dev->refcnt=%d\n",
     644                log_msg(LOG_DEFAULT, LVL_DEBUG, "pass_devices_to_driver: dev->refcnt=%d\n",
    617645                    (int)atomic_get(&dev->refcnt));
    618646                dev_add_ref(dev);
     
    650678         * immediately and possibly started here as well.
    651679         */
    652         log_msg(LVL_DEBUG, "Driver `%s' enters running state.", driver->name);
     680        log_msg(LOG_DEFAULT, LVL_DEBUG, "Driver `%s' enters running state.", driver->name);
    653681        driver->state = DRIVER_RUNNING;
    654682
     
    667695void initialize_running_driver(driver_t *driver, dev_tree_t *tree)
    668696{
    669         log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")",
     697        log_msg(LOG_DEFAULT, LVL_DEBUG, "initialize_running_driver(driver=\"%s\")",
    670698            driver->name);
    671699       
     
    761789         * access any structures that would affect driver_t.
    762790         */
    763         log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")",
     791        log_msg(LOG_DEFAULT, LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")",
    764792            drv->name, dev->pfun->name);
    765793       
     
    827855        driver_t *drv = find_best_match_driver(drivers_list, dev);
    828856        if (drv == NULL) {
    829                 log_msg(LVL_ERROR, "No driver found for device `%s'.",
     857                log_msg(LOG_DEFAULT, LVL_ERROR, "No driver found for device `%s'.",
    830858                    dev->pfun->pathname);
    831859                return false;
     
    867895        assert(dev != NULL);
    868896       
    869         log_msg(LVL_DEBUG, "driver_dev_remove(%p)", dev);
     897        log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_dev_remove(%p)", dev);
    870898       
    871899        fibril_rwlock_read_lock(&tree->rwlock);
     
    890918        assert(dev != NULL);
    891919       
    892         log_msg(LVL_DEBUG, "driver_dev_gone(%p)", dev);
     920        log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_dev_gone(%p)", dev);
    893921       
    894922        fibril_rwlock_read_lock(&tree->rwlock);
     
    911939        devman_handle_t handle;
    912940       
    913         log_msg(LVL_DEBUG, "driver_fun_online(%p)", fun);
     941        log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_fun_online(%p)", fun);
    914942
    915943        fibril_rwlock_read_lock(&tree->rwlock);
     
    939967        devman_handle_t handle;
    940968       
    941         log_msg(LVL_DEBUG, "driver_fun_offline(%p)", fun);
     969        log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_fun_offline(%p)", fun);
    942970
    943971        fibril_rwlock_read_lock(&tree->rwlock);
     
    970998bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list)
    971999{
    972         log_msg(LVL_DEBUG, "init_device_tree()");
     1000        log_msg(LOG_DEFAULT, LVL_DEBUG, "init_device_tree()");
    9731001       
    9741002        tree->current_handle = 0;
    9751003       
    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);
     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);
    9821007       
    9831008        fibril_rwlock_initialize(&tree->rwlock);
     
    10131038        list_initialize(&dev->functions);
    10141039        link_initialize(&dev->driver_devices);
    1015         link_initialize(&dev->devman_dev);
    10161040       
    10171041        return dev;
     
    10521076}
    10531077
    1054 
    10551078/** Find the device node structure of the device witch has the specified handle.
    10561079 *
     
    10611084dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
    10621085{
    1063         unsigned long key = handle;
    1064         link_t *link;
    1065        
    10661086        assert(fibril_rwlock_is_locked(&tree->rwlock));
    10671087       
    1068         link = hash_table_find(&tree->devman_devices, &key);
     1088        ht_link_t *link = hash_table_find(&tree->devman_devices, &handle);
    10691089        if (link == NULL)
    10701090                return NULL;
    10711091       
    1072         return hash_table_get_instance(link, dev_node_t, devman_dev);
     1092        return hash_table_get_inst(link, dev_node_t, devman_dev);
    10731093}
    10741094
     
    11421162        fun->state = FUN_INIT;
    11431163        atomic_set(&fun->refcnt, 0);
     1164        fibril_mutex_initialize(&fun->busy_lock);
    11441165        link_initialize(&fun->dev_functions);
    11451166        list_initialize(&fun->match_ids.ids);
    1146         link_initialize(&fun->devman_fun);
    1147         link_initialize(&fun->loc_fun);
    11481167       
    11491168        return fun;
     
    11861205}
    11871206
     1207/** Make function busy for reconfiguration operations. */
     1208void fun_busy_lock(fun_node_t *fun)
     1209{
     1210        fibril_mutex_lock(&fun->busy_lock);
     1211}
     1212
     1213/** Mark end of reconfiguration operation. */
     1214void fun_busy_unlock(fun_node_t *fun)
     1215{
     1216        fibril_mutex_unlock(&fun->busy_lock);
     1217}
     1218
    11881219/** Find the function node with the specified handle.
    11891220 *
     
    11941225fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
    11951226{
    1196         unsigned long key = handle;
    1197         link_t *link;
    11981227        fun_node_t *fun;
    11991228       
    12001229        assert(fibril_rwlock_is_locked(&tree->rwlock));
    12011230       
    1202         link = hash_table_find(&tree->devman_functions, &key);
     1231        ht_link_t *link = hash_table_find(&tree->devman_functions, &handle);
    12031232        if (link == NULL)
    12041233                return NULL;
    12051234       
    1206         fun = hash_table_get_instance(link, fun_node_t, devman_fun);
     1235        fun = hash_table_get_inst(link, fun_node_t, devman_fun);
    12071236       
    12081237        return fun;
     
    12491278        fun->pathname = (char *) malloc(pathsize);
    12501279        if (fun->pathname == NULL) {
    1251                 log_msg(LVL_ERROR, "Failed to allocate device path.");
     1280                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to allocate device path.");
    12521281                return false;
    12531282        }
     
    12771306        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    12781307       
    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\"])",
    12801309            dev, pfun, pfun->pathname);
    12811310
    12821311        /* Add the node to the handle-to-node map. */
    12831312        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);
    12861314
    12871315        /* Add the node to the list of its parent's children. */
     
    13011329        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    13021330       
    1303         log_msg(LVL_DEBUG, "remove_dev_node(dev=%p)", dev);
     1331        log_msg(LOG_DEFAULT, LVL_DEBUG, "remove_dev_node(dev=%p)", dev);
    13041332       
    13051333        /* Remove node from the handle-to-node map. */
    1306         unsigned long key = dev->handle;
    1307         hash_table_remove(&tree->devman_devices, &key, 1);
     1334        hash_table_remove(&tree->devman_devices, &dev->handle);
    13081335       
    13091336        /* Unlink from parent function. */
     
    13461373        /* Add the node to the handle-to-node map. */
    13471374        fun->handle = ++tree->current_handle;
    1348         unsigned long key = fun->handle;
    1349         hash_table_insert(&tree->devman_functions, &key, &fun->devman_fun);
     1375        hash_table_insert(&tree->devman_functions, &fun->devman_fun);
    13501376
    13511377        /* Add the node to the list of its parent's children. */
     
    13671393       
    13681394        /* Remove the node from the handle-to-node map. */
    1369         unsigned long key = fun->handle;
    1370         hash_table_remove(&tree->devman_functions, &key, 1);
     1395        hash_table_remove(&tree->devman_functions, &fun->handle);
    13711396       
    13721397        /* Remove the node from the list of its parent's children. */
     
    14811506{
    14821507        fun_node_t *fun = NULL;
    1483         link_t *link;
    1484         unsigned long key = (unsigned long) service_id;
    14851508       
    14861509        fibril_rwlock_read_lock(&tree->rwlock);
    1487         link = hash_table_find(&tree->loc_functions, &key);
     1510        ht_link_t *link = hash_table_find(&tree->loc_functions, &service_id);
    14881511        if (link != NULL) {
    1489                 fun = hash_table_get_instance(link, fun_node_t, loc_fun);
     1512                fun = hash_table_get_inst(link, fun_node_t, loc_fun);
    14901513                fun_add_ref(fun);
    14911514        }
     
    14991522        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    15001523       
    1501         unsigned long key = (unsigned long) fun->service_id;
    1502         hash_table_insert(&tree->loc_functions, &key, &fun->loc_fun);
     1524        hash_table_insert(&tree->loc_functions, &fun->loc_fun);
    15031525}
    15041526
Note: See TracChangeset for help on using the changeset viewer.