Ignore:
File:
1 edited

Legend:

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

    r4e00f87 r77a69ea  
    6666/* hash table operations */
    6767
    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
     68static hash_index_t devices_hash(unsigned long key[])
     69{
     70        return key[0] % DEVICE_BUCKETS;
     71}
     72
     73static 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
     80static 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
     87static 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
     94static void devices_remove_callback(link_t *item)
     95{
     96}
     97
     98static hash_table_operations_t devman_devices_ops = {
     99        .hash = devices_hash,
     100        .compare = devman_devices_compare,
     101        .remove_callback = devices_remove_callback
    126102};
    127103
    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
     104static hash_table_operations_t devman_functions_ops = {
     105        .hash = devices_hash,
     106        .compare = devman_functions_compare,
     107        .remove_callback = devices_remove_callback
    134108};
    135109
    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
     110static hash_table_operations_t loc_devices_ops = {
     111        .hash = devices_hash,
     112        .compare = loc_functions_compare,
     113        .remove_callback = devices_remove_callback
    142114};
    143115
     
    179151        fibril_mutex_unlock(&drivers_list->drivers_mutex);
    180152
    181         log_msg(LOG_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 "
    182154            "drivers.", drv->name);
    183155}
     
    270242bool read_match_ids(const char *conf_path, match_id_list_t *ids)
    271243{
    272         log_msg(LOG_DEFAULT, LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);
     244        log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);
    273245       
    274246        bool suc = false;
     
    280252        fd = open(conf_path, O_RDONLY);
    281253        if (fd < 0) {
    282                 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to open `%s' for reading: %s.",
     254                log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.",
    283255                    conf_path, str_error(fd));
    284256                goto cleanup;
     
    289261        lseek(fd, 0, SEEK_SET);
    290262        if (len == 0) {
    291                 log_msg(LOG_DEFAULT, LVL_ERROR, "Configuration file '%s' is empty.",
     263                log_msg(LVL_ERROR, "Configuration file '%s' is empty.",
    292264                    conf_path);
    293265                goto cleanup;
     
    296268        buf = malloc(len + 1);
    297269        if (buf == NULL) {
    298                 log_msg(LOG_DEFAULT, LVL_ERROR, "Memory allocation failed when parsing file "
     270                log_msg(LVL_ERROR, "Memory allocation failed when parsing file "
    299271                    "'%s'.", conf_path);
    300272                goto cleanup;
     
    303275        ssize_t read_bytes = read_all(fd, buf, len);
    304276        if (read_bytes <= 0) {
    305                 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path,
     277                log_msg(LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path,
    306278                    read_bytes);
    307279                goto cleanup;
     
    342314bool get_driver_info(const char *base_path, const char *name, driver_t *drv)
    343315{
    344         log_msg(LOG_DEFAULT, LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")",
     316        log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")",
    345317            base_path, name);
    346318       
     
    374346        struct stat s;
    375347        if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */
    376                 log_msg(LOG_DEFAULT, LVL_ERROR, "Driver not found at path `%s'.",
     348                log_msg(LVL_ERROR, "Driver not found at path `%s'.",
    377349                    drv->binary_path);
    378350                goto cleanup;
     
    402374int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path)
    403375{
    404         log_msg(LOG_DEFAULT, LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path);
     376        log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path);
    405377       
    406378        int drv_cnt = 0;
     
    436408        dev_node_t *dev;
    437409       
    438         log_msg(LOG_DEFAULT, LVL_DEBUG, "create_root_nodes()");
     410        log_msg(LVL_DEBUG, "create_root_nodes()");
    439411       
    440412        fibril_rwlock_write_lock(&tree->rwlock);
     
    523495void attach_driver(dev_tree_t *tree, dev_node_t *dev, driver_t *drv)
    524496{
    525         log_msg(LOG_DEFAULT, LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")",
     497        log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")",
    526498            dev->pfun->pathname, drv->name);
    527499       
     
    548520        assert(drv != NULL);
    549521       
    550         log_msg(LOG_DEFAULT, LVL_DEBUG, "detach_driver(dev=\"%s\",drv=\"%s\")",
     522        log_msg(LVL_DEBUG, "detach_driver(dev=\"%s\",drv=\"%s\")",
    551523            dev->pfun->pathname, drv->name);
    552524       
     
    573545        assert(fibril_mutex_is_locked(&drv->driver_mutex));
    574546       
    575         log_msg(LOG_DEFAULT, LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);
     547        log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);
    576548       
    577549        rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL);
    578550        if (rc != EOK) {
    579                 log_msg(LOG_DEFAULT, LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",
     551                log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",
    580552                    drv->name, drv->binary_path, str_error(rc));
    581553                return false;
     
    622594        link_t *link;
    623595
    624         log_msg(LOG_DEFAULT, LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")",
     596        log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")",
    625597            driver->name);
    626598
     
    642614                }
    643615
    644                 log_msg(LOG_DEFAULT, LVL_DEBUG, "pass_devices_to_driver: dev->refcnt=%d\n",
     616                log_msg(LVL_DEBUG, "pass_devices_to_driver: dev->refcnt=%d\n",
    645617                    (int)atomic_get(&dev->refcnt));
    646618                dev_add_ref(dev);
     
    678650         * immediately and possibly started here as well.
    679651         */
    680         log_msg(LOG_DEFAULT, LVL_DEBUG, "Driver `%s' enters running state.", driver->name);
     652        log_msg(LVL_DEBUG, "Driver `%s' enters running state.", driver->name);
    681653        driver->state = DRIVER_RUNNING;
    682654
     
    695667void initialize_running_driver(driver_t *driver, dev_tree_t *tree)
    696668{
    697         log_msg(LOG_DEFAULT, LVL_DEBUG, "initialize_running_driver(driver=\"%s\")",
     669        log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")",
    698670            driver->name);
    699671       
     
    789761         * access any structures that would affect driver_t.
    790762         */
    791         log_msg(LOG_DEFAULT, LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")",
     763        log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")",
    792764            drv->name, dev->pfun->name);
    793765       
     
    855827        driver_t *drv = find_best_match_driver(drivers_list, dev);
    856828        if (drv == NULL) {
    857                 log_msg(LOG_DEFAULT, LVL_ERROR, "No driver found for device `%s'.",
     829                log_msg(LVL_ERROR, "No driver found for device `%s'.",
    858830                    dev->pfun->pathname);
    859831                return false;
     
    895867        assert(dev != NULL);
    896868       
    897         log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_dev_remove(%p)", dev);
     869        log_msg(LVL_DEBUG, "driver_dev_remove(%p)", dev);
    898870       
    899871        fibril_rwlock_read_lock(&tree->rwlock);
     
    918890        assert(dev != NULL);
    919891       
    920         log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_dev_gone(%p)", dev);
     892        log_msg(LVL_DEBUG, "driver_dev_gone(%p)", dev);
    921893       
    922894        fibril_rwlock_read_lock(&tree->rwlock);
     
    939911        devman_handle_t handle;
    940912       
    941         log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_fun_online(%p)", fun);
     913        log_msg(LVL_DEBUG, "driver_fun_online(%p)", fun);
    942914
    943915        fibril_rwlock_read_lock(&tree->rwlock);
     
    967939        devman_handle_t handle;
    968940       
    969         log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_fun_offline(%p)", fun);
     941        log_msg(LVL_DEBUG, "driver_fun_offline(%p)", fun);
    970942
    971943        fibril_rwlock_read_lock(&tree->rwlock);
     
    998970bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list)
    999971{
    1000         log_msg(LOG_DEFAULT, LVL_DEBUG, "init_device_tree()");
     972        log_msg(LVL_DEBUG, "init_device_tree()");
    1001973       
    1002974        tree->current_handle = 0;
    1003975       
    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);
    1007982       
    1008983        fibril_rwlock_initialize(&tree->rwlock);
     
    10381013        list_initialize(&dev->functions);
    10391014        link_initialize(&dev->driver_devices);
     1015        link_initialize(&dev->devman_dev);
    10401016       
    10411017        return dev;
     
    10761052}
    10771053
     1054
    10781055/** Find the device node structure of the device witch has the specified handle.
    10791056 *
     
    10841061dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
    10851062{
     1063        unsigned long key = handle;
     1064        link_t *link;
     1065       
    10861066        assert(fibril_rwlock_is_locked(&tree->rwlock));
    10871067       
    1088         ht_link_t *link = hash_table_find(&tree->devman_devices, &handle);
     1068        link = hash_table_find(&tree->devman_devices, &key);
    10891069        if (link == NULL)
    10901070                return NULL;
    10911071       
    1092         return hash_table_get_inst(link, dev_node_t, devman_dev);
     1072        return hash_table_get_instance(link, dev_node_t, devman_dev);
    10931073}
    10941074
     
    11621142        fun->state = FUN_INIT;
    11631143        atomic_set(&fun->refcnt, 0);
    1164         fibril_mutex_initialize(&fun->busy_lock);
    11651144        link_initialize(&fun->dev_functions);
    11661145        list_initialize(&fun->match_ids.ids);
     1146        link_initialize(&fun->devman_fun);
     1147        link_initialize(&fun->loc_fun);
    11671148       
    11681149        return fun;
     
    12051186}
    12061187
    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 
    12191188/** Find the function node with the specified handle.
    12201189 *
     
    12251194fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
    12261195{
     1196        unsigned long key = handle;
     1197        link_t *link;
    12271198        fun_node_t *fun;
    12281199       
    12291200        assert(fibril_rwlock_is_locked(&tree->rwlock));
    12301201       
    1231         ht_link_t *link = hash_table_find(&tree->devman_functions, &handle);
     1202        link = hash_table_find(&tree->devman_functions, &key);
    12321203        if (link == NULL)
    12331204                return NULL;
    12341205       
    1235         fun = hash_table_get_inst(link, fun_node_t, devman_fun);
     1206        fun = hash_table_get_instance(link, fun_node_t, devman_fun);
    12361207       
    12371208        return fun;
     
    12781249        fun->pathname = (char *) malloc(pathsize);
    12791250        if (fun->pathname == NULL) {
    1280                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to allocate device path.");
     1251                log_msg(LVL_ERROR, "Failed to allocate device path.");
    12811252                return false;
    12821253        }
     
    13061277        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    13071278       
    1308         log_msg(LOG_DEFAULT, LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])",
     1279        log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])",
    13091280            dev, pfun, pfun->pathname);
    13101281
    13111282        /* Add the node to the handle-to-node map. */
    13121283        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);
    13141286
    13151287        /* Add the node to the list of its parent's children. */
     
    13291301        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    13301302       
    1331         log_msg(LOG_DEFAULT, LVL_DEBUG, "remove_dev_node(dev=%p)", dev);
     1303        log_msg(LVL_DEBUG, "remove_dev_node(dev=%p)", dev);
    13321304       
    13331305        /* 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);
    13351308       
    13361309        /* Unlink from parent function. */
     
    13731346        /* Add the node to the handle-to-node map. */
    13741347        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);
    13761350
    13771351        /* Add the node to the list of its parent's children. */
     
    13931367       
    13941368        /* 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);
    13961371       
    13971372        /* Remove the node from the list of its parent's children. */
     
    15061481{
    15071482        fun_node_t *fun = NULL;
     1483        link_t *link;
     1484        unsigned long key = (unsigned long) service_id;
    15081485       
    15091486        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);
    15111488        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);
    15131490                fun_add_ref(fun);
    15141491        }
     
    15221499        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    15231500       
    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);
    15251503}
    15261504
Note: See TracChangeset for help on using the changeset viewer.