Changeset b800b0e in mainline for uspace/srv/devman/devman.c


Ignore:
Timestamp:
2012-10-23T13:16:49Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6ecf5b8
Parents:
32b3a12 (diff), b2ac3998 (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.
Message:

Merge mainline changes

File:
1 edited

Legend:

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

    r32b3a12 rb800b0e  
    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;
     
    10601084dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
    10611085{
    1062         unsigned long key = handle;
    1063         link_t *link;
    1064        
    10651086        assert(fibril_rwlock_is_locked(&tree->rwlock));
    10661087       
    1067         link = hash_table_find(&tree->devman_devices, &key);
     1088        ht_link_t *link = hash_table_find(&tree->devman_devices, &handle);
    10681089        if (link == NULL)
    10691090                return NULL;
    10701091       
    1071         return hash_table_get_instance(link, dev_node_t, devman_dev);
     1092        return hash_table_get_inst(link, dev_node_t, devman_dev);
    10721093}
    10731094
     
    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;
     
    12061225fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
    12071226{
    1208         unsigned long key = handle;
    1209         link_t *link;
    12101227        fun_node_t *fun;
    12111228       
    12121229        assert(fibril_rwlock_is_locked(&tree->rwlock));
    12131230       
    1214         link = hash_table_find(&tree->devman_functions, &key);
     1231        ht_link_t *link = hash_table_find(&tree->devman_functions, &handle);
    12151232        if (link == NULL)
    12161233                return NULL;
    12171234       
    1218         fun = hash_table_get_instance(link, fun_node_t, devman_fun);
     1235        fun = hash_table_get_inst(link, fun_node_t, devman_fun);
    12191236       
    12201237        return fun;
     
    12611278        fun->pathname = (char *) malloc(pathsize);
    12621279        if (fun->pathname == NULL) {
    1263                 log_msg(LVL_ERROR, "Failed to allocate device path.");
     1280                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to allocate device path.");
    12641281                return false;
    12651282        }
     
    12891306        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    12901307       
    1291         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\"])",
    12921309            dev, pfun, pfun->pathname);
    12931310
    12941311        /* Add the node to the handle-to-node map. */
    12951312        dev->handle = ++tree->current_handle;
    1296         unsigned long key = dev->handle;
    1297         hash_table_insert(&tree->devman_devices, &key, &dev->devman_dev);
     1313        hash_table_insert(&tree->devman_devices, &dev->devman_dev);
    12981314
    12991315        /* Add the node to the list of its parent's children. */
     
    13131329        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    13141330       
    1315         log_msg(LVL_DEBUG, "remove_dev_node(dev=%p)", dev);
     1331        log_msg(LOG_DEFAULT, LVL_DEBUG, "remove_dev_node(dev=%p)", dev);
    13161332       
    13171333        /* Remove node from the handle-to-node map. */
    1318         unsigned long key = dev->handle;
    1319         hash_table_remove(&tree->devman_devices, &key, 1);
     1334        hash_table_remove(&tree->devman_devices, &dev->handle);
    13201335       
    13211336        /* Unlink from parent function. */
     
    13581373        /* Add the node to the handle-to-node map. */
    13591374        fun->handle = ++tree->current_handle;
    1360         unsigned long key = fun->handle;
    1361         hash_table_insert(&tree->devman_functions, &key, &fun->devman_fun);
     1375        hash_table_insert(&tree->devman_functions, &fun->devman_fun);
    13621376
    13631377        /* Add the node to the list of its parent's children. */
     
    13791393       
    13801394        /* Remove the node from the handle-to-node map. */
    1381         unsigned long key = fun->handle;
    1382         hash_table_remove(&tree->devman_functions, &key, 1);
     1395        hash_table_remove(&tree->devman_functions, &fun->handle);
    13831396       
    13841397        /* Remove the node from the list of its parent's children. */
     
    14931506{
    14941507        fun_node_t *fun = NULL;
    1495         link_t *link;
    1496         unsigned long key = (unsigned long) service_id;
    14971508       
    14981509        fibril_rwlock_read_lock(&tree->rwlock);
    1499         link = hash_table_find(&tree->loc_functions, &key);
     1510        ht_link_t *link = hash_table_find(&tree->loc_functions, &service_id);
    15001511        if (link != NULL) {
    1501                 fun = hash_table_get_instance(link, fun_node_t, loc_fun);
     1512                fun = hash_table_get_inst(link, fun_node_t, loc_fun);
    15021513                fun_add_ref(fun);
    15031514        }
     
    15111522        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    15121523       
    1513         unsigned long key = (unsigned long) fun->service_id;
    1514         hash_table_insert(&tree->loc_functions, &key, &fun->loc_fun);
     1524        hash_table_insert(&tree->loc_functions, &fun->loc_fun);
    15151525}
    15161526
Note: See TracChangeset for help on using the changeset viewer.