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


Ignore:
Timestamp:
2011-02-07T22:15:37Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b367b4
Parents:
8b5690f
Message:

Split device tree node into dev_node_t (device node) and fun_node_t (function node).

File:
1 edited

Legend:

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

    r8b5690f rba38f72c  
    4141#include "devman.h"
    4242
     43fun_node_t *find_node_child(fun_node_t *parent, const char *name);
     44
    4345/* hash table operations */
    4446
     
    5153    link_t *item)
    5254{
    53         node_t *dev = hash_table_get_instance(item, node_t, devman_link);
     55        dev_node_t *dev = hash_table_get_instance(item, dev_node_t, devman_dev);
    5456        return (dev->handle == (devman_handle_t) key[0]);
    5557}
    5658
    57 static int devmap_devices_compare(unsigned long key[], hash_count_t keys,
     59static int devman_functions_compare(unsigned long key[], hash_count_t keys,
    5860    link_t *item)
    5961{
    60         node_t *dev = hash_table_get_instance(item, node_t, devmap_link);
    61         return (dev->devmap_handle == (devmap_handle_t) key[0]);
     62        fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devman_fun);
     63        return (fun->handle == (devman_handle_t) key[0]);
     64}
     65
     66static int devmap_functions_compare(unsigned long key[], hash_count_t keys,
     67    link_t *item)
     68{
     69        fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devmap_fun);
     70        return (fun->devmap_handle == (devmap_handle_t) key[0]);
    6271}
    6372
     
    8291};
    8392
     93static hash_table_operations_t devman_functions_ops = {
     94        .hash = devices_hash,
     95        .compare = devman_functions_compare,
     96        .remove_callback = devices_remove_callback
     97};
     98
    8499static hash_table_operations_t devmap_devices_ops = {
    85100        .hash = devices_hash,
    86         .compare = devmap_devices_compare,
     101        .compare = devmap_functions_compare,
    87102        .remove_callback = devices_remove_callback
    88103};
     
    373388}
    374389
    375 /** Create root device node in the device tree.
     390/** Create root device and function node in the device tree.
    376391 *
    377392 * @param tree  The device tree.
    378393 * @return      True on success, false otherwise.
    379394 */
    380 bool create_root_node(dev_tree_t *tree)
    381 {
    382         node_t *node;
    383 
    384         printf(NAME ": create_root_node\n");
    385 
     395bool create_root_nodes(dev_tree_t *tree)
     396{
     397        fun_node_t *fun;
     398        dev_node_t *dev;
     399       
     400        printf(NAME ": create_root_nodes\n");
     401       
    386402        fibril_rwlock_write_lock(&tree->rwlock);
    387         node = create_dev_node();
    388         if (node != NULL) {
    389                 insert_dev_node(tree, node, clone_string(""), NULL);
    390                 match_id_t *id = create_match_id();
    391                 id->id = clone_string("root");
    392                 id->score = 100;
    393                 add_match_id(&node->match_ids, id);
    394                 tree->root_node = node;
    395         }
     403       
     404        /*
     405         * Create root function. This is a pseudo function to which
     406         * the root device node is attached. It allows us to match
     407         * the root device driver in a standard manner, i.e. against
     408         * the parent function.
     409         */
     410       
     411        fun = create_fun_node();
     412        if (fun == NULL) {
     413                fibril_rwlock_write_unlock(&tree->rwlock);
     414                return false;
     415        }
     416       
     417        insert_fun_node(tree, fun, clone_string(""), NULL);
     418        match_id_t *id = create_match_id();
     419        id->id = clone_string("root");
     420        id->score = 100;
     421        add_match_id(&fun->match_ids, id);
     422        tree->root_node = fun;
     423       
     424        /*
     425         * Create root device node.
     426         */
     427        dev = create_dev_node();
     428        if (dev == NULL) {
     429                fibril_rwlock_write_unlock(&tree->rwlock);
     430                return false;
     431        }
     432       
     433        insert_dev_node(tree, dev, fun);
     434       
    396435        fibril_rwlock_write_unlock(&tree->rwlock);
    397 
    398         return node != NULL;
     436       
     437        return dev != NULL;
    399438}
    400439
     
    414453 *                      is found.
    415454 */
    416 driver_t *find_best_match_driver(driver_list_t *drivers_list, node_t *node)
     455driver_t *find_best_match_driver(driver_list_t *drivers_list, dev_node_t *node)
    417456{
    418457        driver_t *best_drv = NULL, *drv = NULL;
     
    442481 * @param drv           The driver.
    443482 */
    444 void attach_driver(node_t *node, driver_t *drv)
     483void attach_driver(dev_node_t *dev, driver_t *drv)
    445484{
    446485        printf(NAME ": attach_driver %s to device %s\n",
    447             drv->name, node->pathname);
     486            drv->name, dev->pfun->pathname);
    448487       
    449488        fibril_mutex_lock(&drv->driver_mutex);
    450489       
    451         node->drv = drv;
    452         list_append(&node->driver_devices, &drv->devices);
     490        dev->drv = drv;
     491        list_append(&dev->driver_devices, &drv->devices);
    453492       
    454493        fibril_mutex_unlock(&drv->driver_mutex);
     
    530569static void pass_devices_to_driver(driver_t *driver, dev_tree_t *tree)
    531570{
    532         node_t *dev;
     571        dev_node_t *dev;
    533572        link_t *link;
    534573        int phone;
     
    551590        link = driver->devices.next;
    552591        while (link != &driver->devices) {
    553                 dev = list_get_instance(link, node_t, driver_devices);
     592                dev = list_get_instance(link, dev_node_t, driver_devices);
    554593                if (dev->passed_to_driver) {
    555594                        link = link->next;
     
    669708}
    670709
    671 /** Create devmap path and name for the device. */
    672 static void devmap_register_tree_device(node_t *node, dev_tree_t *tree)
     710/** Create devmap path and name for the function. */
     711static void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)
    673712{
    674713        char *devmap_pathname = NULL;
    675714        char *devmap_name = NULL;
    676715       
    677         asprintf(&devmap_name, "%s", node->pathname);
     716        asprintf(&devmap_name, "%s", fun->pathname);
    678717        if (devmap_name == NULL)
    679718                return;
     
    689728       
    690729        devmap_device_register_with_iface(devmap_pathname,
    691             &node->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
    692        
    693         tree_add_devmap_device(tree, node);
     730            &fun->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
     731       
     732        tree_add_devmap_function(tree, fun);
    694733       
    695734        free(devmap_name);
     
    702741 * @param node          The device's node in the device tree.
    703742 */
    704 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree)
     743void add_device(int phone, driver_t *drv, dev_node_t *dev, dev_tree_t *tree)
    705744{
    706745        /*
     
    709748         */
    710749        printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
    711             node->name);
     750            dev->pfun->name);
    712751       
    713752        sysarg_t rc;
     
    716755        /* Send the device to the driver. */
    717756        devman_handle_t parent_handle;
    718         if (node->parent) {
    719                 parent_handle = node->parent->handle;
     757        if (dev->pfun) {
     758                parent_handle = dev->pfun->handle;
    720759        } else {
    721760                parent_handle = 0;
    722761        }
    723762
    724         aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle,
     763        aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, dev->handle,
    725764            parent_handle, &answer);
    726765       
    727766        /* Send the device's name to the driver. */
    728         rc = async_data_write_start(phone, node->name,
    729             str_size(node->name) + 1);
     767        rc = async_data_write_start(phone, dev->pfun->name,
     768            str_size(dev->pfun->name) + 1);
    730769        if (rc != EOK) {
    731770                /* TODO handle error */
     
    737776        switch(rc) {
    738777        case EOK:
    739                 node->state = DEVICE_USABLE;
    740                 devmap_register_tree_device(node, tree);
     778                dev->state = DEVICE_USABLE;
     779                // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     780                if (0) devmap_register_tree_function(NULL, tree);
     781                // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    741782                break;
    742783        case ENOENT:
    743                 node->state = DEVICE_NOT_PRESENT;
     784                dev->state = DEVICE_NOT_PRESENT;
    744785                break;
    745786        default:
    746                 node->state = DEVICE_INVALID;
    747         }
    748        
    749         node->passed_to_driver = true;
     787                dev->state = DEVICE_INVALID;
     788        }
     789       
     790        dev->passed_to_driver = true;
    750791
    751792        return;
     
    759800 *                      successfully assigned to the device, false otherwise.
    760801 */
    761 bool assign_driver(node_t *node, driver_list_t *drivers_list, dev_tree_t *tree)
    762 {
     802bool assign_driver(dev_node_t *dev, driver_list_t *drivers_list,
     803    dev_tree_t *tree)
     804{
     805        assert(dev != NULL);
     806        assert(drivers_list != NULL);
     807        assert(tree != NULL);
     808       
    763809        /*
    764810         * Find the driver which is the most suitable for handling this device.
    765811         */
    766         driver_t *drv = find_best_match_driver(drivers_list, node);
     812        driver_t *drv = find_best_match_driver(drivers_list, dev);
    767813        if (drv == NULL) {
    768814                printf(NAME ": no driver found for device '%s'.\n",
    769                     node->pathname);
     815                    dev->pfun->pathname);
    770816                return false;
    771817        }
    772818       
    773819        /* Attach the driver to the device. */
    774         attach_driver(node, drv);
     820        attach_driver(dev, drv);
    775821       
    776822        fibril_mutex_lock(&drv->driver_mutex);
     
    786832                int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
    787833                if (phone >= 0) {
    788                         add_device(phone, drv, node, tree);
     834                        add_device(phone, drv, dev, tree);
    789835                        async_hangup(phone);
    790836                }
     
    810856        hash_table_create(&tree->devman_devices, DEVICE_BUCKETS, 1,
    811857            &devman_devices_ops);
    812         hash_table_create(&tree->devmap_devices, DEVICE_BUCKETS, 1,
     858        hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1,
     859            &devman_functions_ops);
     860        hash_table_create(&tree->devmap_functions, DEVICE_BUCKETS, 1,
    813861            &devmap_devices_ops);
    814862       
    815863        fibril_rwlock_initialize(&tree->rwlock);
    816864       
    817         /* Create root node and add it to the device tree. */
    818         if (!create_root_node(tree))
     865        /* Create root function and root device and add them to the device tree. */
     866        if (!create_root_nodes(tree))
    819867                return false;
    820868
    821869        /* Find suitable driver and start it. */
    822         return assign_driver(tree->root_node, drivers_list, tree);
     870        return assign_driver(tree->root_node->child, drivers_list, tree);
    823871}
    824872
     
    829877 * @return              A device node structure.
    830878 */
    831 node_t *create_dev_node(void)
    832 {
    833         node_t *res = malloc(sizeof(node_t));
     879dev_node_t *create_dev_node(void)
     880{
     881        dev_node_t *res = malloc(sizeof(dev_node_t));
    834882       
    835883        if (res != NULL) {
    836                 memset(res, 0, sizeof(node_t));
    837                 list_initialize(&res->children);
    838                 list_initialize(&res->match_ids.ids);
    839                 list_initialize(&res->classes);
     884                memset(res, 0, sizeof(dev_node_t));
     885                list_initialize(&res->functions);
     886                link_initialize(&res->driver_devices);
     887                link_initialize(&res->devman_dev);
    840888        }
    841889       
     
    847895 * @param node          The device node structure.
    848896 */
    849 void delete_dev_node(node_t *node)
    850 {
    851         assert(list_empty(&node->children));
    852         assert(node->parent == NULL);
    853         assert(node->drv == NULL);
    854        
    855         clean_match_ids(&node->match_ids);
    856         free_not_null(node->name);
    857         free_not_null(node->pathname);
    858         free(node);
     897void delete_dev_node(dev_node_t *dev)
     898{
     899        assert(list_empty(&dev->functions));
     900        assert(dev->pfun == NULL);
     901        assert(dev->drv == NULL);
     902       
     903        free(dev);
    859904}
    860905
     
    865910 * @return              The device node.
    866911 */
    867 node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
     912dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
    868913{
    869914        unsigned long key = handle;
     
    873918       
    874919        link = hash_table_find(&tree->devman_devices, &key);
    875         return hash_table_get_instance(link, node_t, devman_link);
     920        return hash_table_get_instance(link, dev_node_t, devman_dev);
    876921}
    877922
     
    882927 * @return              The device node.
    883928 */
    884 node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle)
    885 {
    886         node_t *node = NULL;
     929dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle)
     930{
     931        dev_node_t *dev = NULL;
    887932       
    888933        fibril_rwlock_read_lock(&tree->rwlock);
    889         node = find_dev_node_no_lock(tree, handle);
     934        dev = find_dev_node_no_lock(tree, handle);
    890935        fibril_rwlock_read_unlock(&tree->rwlock);
    891936       
    892         return node;
    893 }
    894 
     937        return dev;
     938}
     939
     940/* Function nodes */
     941
     942/** Create a new function node.
     943 *
     944 * @return              A function node structure.
     945 */
     946fun_node_t *create_fun_node(void)
     947{
     948        fun_node_t *res = malloc(sizeof(fun_node_t));
     949       
     950        if (res != NULL) {
     951                memset(res, 0, sizeof(fun_node_t));
     952                link_initialize(&res->dev_functions);
     953                list_initialize(&res->match_ids.ids);
     954                list_initialize(&res->classes);
     955                link_initialize(&res->devman_fun);
     956                link_initialize(&res->devmap_fun);
     957        }
     958       
     959        return res;
     960}
     961
     962/** Delete a function node.
     963 *
     964 * @param fun           The device node structure.
     965 */
     966void delete_fun_node(fun_node_t *fun)
     967{
     968        assert(fun->dev == NULL);
     969        assert(fun->child == NULL);
     970       
     971        clean_match_ids(&fun->match_ids);
     972        free_not_null(fun->name);
     973        free_not_null(fun->pathname);
     974        free(fun);
     975}
     976
     977/** Find the function node with the specified handle.
     978 *
     979 * @param tree          The device tree where we look for the device node.
     980 * @param handle        The handle of the function.
     981 * @return              The function node.
     982 */
     983fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
     984{
     985        unsigned long key = handle;
     986        link_t *link;
     987       
     988        assert(fibril_rwlock_is_locked(&tree->rwlock));
     989       
     990        link = hash_table_find(&tree->devman_functions, &key);
     991        if (link == NULL)
     992                return NULL;
     993       
     994        return hash_table_get_instance(link, fun_node_t, devman_fun);
     995}
     996
     997/** Find the function node with the specified handle.
     998 *
     999 * @param tree          The device tree where we look for the device node.
     1000 * @param handle        The handle of the function.
     1001 * @return              The function node.
     1002 */
     1003fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle)
     1004{
     1005        fun_node_t *fun = NULL;
     1006       
     1007        fibril_rwlock_read_lock(&tree->rwlock);
     1008        fun = find_fun_node_no_lock(tree, handle);
     1009        fibril_rwlock_read_unlock(&tree->rwlock);
     1010       
     1011        return fun;
     1012}
    8951013
    8961014/** Create and set device's full path in device tree.
     
    9011019 *                      resources etc.).
    9021020 */
    903 static bool set_dev_path(node_t *node, node_t *parent)
    904 {
    905         assert(node->name != NULL);
    906        
    907         size_t pathsize = (str_size(node->name) + 1);
     1021static bool set_fun_path(fun_node_t *fun, fun_node_t *parent)
     1022{
     1023        assert(fun->name != NULL);
     1024       
     1025        size_t pathsize = (str_size(fun->name) + 1);
    9081026        if (parent != NULL)
    9091027                pathsize += str_size(parent->pathname) + 1;
    9101028       
    911         node->pathname = (char *) malloc(pathsize);
    912         if (node->pathname == NULL) {
     1029        fun->pathname = (char *) malloc(pathsize);
     1030        if (fun->pathname == NULL) {
    9131031                printf(NAME ": failed to allocate device path.\n");
    9141032                return false;
     
    9161034       
    9171035        if (parent != NULL) {
    918                 str_cpy(node->pathname, pathsize, parent->pathname);
    919                 str_append(node->pathname, pathsize, "/");
    920                 str_append(node->pathname, pathsize, node->name);
     1036                str_cpy(fun->pathname, pathsize, parent->pathname);
     1037                str_append(fun->pathname, pathsize, "/");
     1038                str_append(fun->pathname, pathsize, fun->name);
    9211039        } else {
    922                 str_cpy(node->pathname, pathsize, node->name);
     1040                str_cpy(fun->pathname, pathsize, fun->name);
    9231041        }
    9241042       
     
    9361054 *                      etc.).
    9371055 */
    938 bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name,
    939     node_t *parent)
    940 {
    941         assert(node != NULL);
     1056bool insert_dev_node(dev_tree_t *tree, dev_node_t *dev, fun_node_t *pfun)
     1057{
     1058        assert(dev != NULL);
    9421059        assert(tree != NULL);
    943         assert(dev_name != NULL);
    9441060        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    9451061       
    946         node->name = dev_name;
    947         if (!set_dev_path(node, parent)) {
     1062        /* Add the node to the handle-to-node map. */
     1063        dev->handle = ++tree->current_handle;
     1064        unsigned long key = dev->handle;
     1065        hash_table_insert(&tree->devman_devices, &key, &dev->devman_dev);
     1066
     1067        /* Add the node to the list of its parent's children. */
     1068        printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);
     1069        dev->pfun = pfun;
     1070        pfun->child = dev;
     1071       
     1072        return true;
     1073}
     1074
     1075/** Insert new function into device tree.
     1076 *
     1077 * @param tree          The device tree.
     1078 * @param node          The newly added function node.
     1079 * @param dev_name      The name of the newly added function.
     1080 * @param parent        Owning device node.
     1081 *
     1082 * @return              True on success, false otherwise (insufficient resources
     1083 *                      etc.).
     1084 */
     1085bool insert_fun_node(dev_tree_t *tree, fun_node_t *fun, char *fun_name,
     1086    dev_node_t *dev)
     1087{
     1088        fun_node_t *pfun;
     1089       
     1090        assert(fun != NULL);
     1091        assert(tree != NULL);
     1092        assert(fun_name != NULL);
     1093        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
     1094       
     1095        /*
     1096         * The root function is a special case, it does not belong to any
     1097         * device so for the root function dev == NULL.
     1098         */
     1099        pfun = (dev != NULL) ? dev->pfun : NULL;
     1100       
     1101        fun->name = fun_name;
     1102        if (!set_fun_path(fun, pfun)) {
    9481103                return false;
    9491104        }
    9501105       
    9511106        /* Add the node to the handle-to-node map. */
    952         node->handle = ++tree->current_handle;
    953         unsigned long key = node->handle;
    954         hash_table_insert(&tree->devman_devices, &key, &node->devman_link);
     1107        fun->handle = ++tree->current_handle;
     1108        unsigned long key = fun->handle;
     1109        hash_table_insert(&tree->devman_functions, &key, &fun->devman_fun);
    9551110
    9561111        /* Add the node to the list of its parent's children. */
    957         node->parent = parent;
    958         if (parent != NULL)
    959                 list_append(&node->sibling, &parent->children);
     1112        fun->dev = dev;
     1113        if (dev != NULL)
     1114                list_append(&fun->dev_functions, &dev->functions);
    9601115       
    9611116        return true;
    9621117}
    9631118
    964 /** Find device node with a specified path in the device tree.
     1119/** Find function node with a specified path in the device tree.
    9651120 *
    966  * @param path          The path of the device node in the device tree.
     1121 * @param path          The path of the function node in the device tree.
    9671122 * @param tree          The device tree.
    968  * @return              The device node if it is present in the tree, NULL
     1123 * @return              The function node if it is present in the tree, NULL
    9691124 *                      otherwise.
    9701125 */
    971 node_t *find_dev_node_by_path(dev_tree_t *tree, char *path)
     1126fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path)
    9721127{
    9731128        fibril_rwlock_read_lock(&tree->rwlock);
    9741129       
    975         node_t *dev = tree->root_node;
     1130        fun_node_t *fun = tree->root_node;
    9761131        /*
    977          * Relative path to the device from its parent (but with '/' at the
     1132         * Relative path to the function from its parent (but with '/' at the
    9781133         * beginning)
    9791134         */
     
    9821137        bool cont = (rel_path[0] == '/');
    9831138       
    984         while (cont && dev != NULL) {
     1139        while (cont && fun != NULL) {
    9851140                next_path_elem  = get_path_elem_end(rel_path + 1);
    9861141                if (next_path_elem[0] == '/') {
     
    9911146                }
    9921147               
    993                 dev = find_node_child(dev, rel_path + 1);
     1148                fun = find_node_child(fun, rel_path + 1);
    9941149               
    9951150                if (cont) {
     
    10021157        fibril_rwlock_read_unlock(&tree->rwlock);
    10031158       
    1004         return dev;
    1005 }
    1006 
    1007 /** Find child device node with a specified name.
     1159        return fun;
     1160}
     1161
     1162/** Find child function node with a specified name.
    10081163 *
    10091164 * Device tree rwlock should be held at least for reading.
    10101165 *
    1011  * @param parent        The parent device node.
    1012  * @param name          The name of the child device node.
    1013  * @return              The child device node.
    1014  */
    1015 node_t *find_node_child(node_t *parent, const char *name)
    1016 {
    1017         node_t *dev;
     1166 * @param parent        The parent function node.
     1167 * @param name          The name of the child function.
     1168 * @return              The child function node.
     1169 */
     1170fun_node_t *find_node_child(fun_node_t *pfun, const char *name)
     1171{
     1172        fun_node_t *fun;
    10181173        link_t *link;
    10191174       
    1020         link = parent->children.next;
    1021        
    1022         while (link != &parent->children) {
    1023                 dev = list_get_instance(link, node_t, sibling);
     1175        link = pfun->child->functions.next;
     1176       
     1177        while (link != &pfun->child->functions) {
     1178                fun = list_get_instance(link, fun_node_t, dev_functions);
    10241179               
    1025                 if (str_cmp(name, dev->name) == 0)
    1026                         return dev;
     1180                if (str_cmp(name, fun->name) == 0)
     1181                        return fun;
    10271182               
    10281183                link = link->next;
     
    11071262}
    11081263
    1109 /** Add the device to the class.
     1264/** Add the device function to the class.
    11101265 *
    11111266 * The device may be added to multiple classes and a class may contain multiple
     
    11201275 *                      with the class.
    11211276 */
    1122 dev_class_info_t *add_device_to_class(node_t *dev, dev_class_t *cl,
     1277dev_class_info_t *add_function_to_class(fun_node_t *fun, dev_class_t *cl,
    11231278    const char *base_dev_name)
    11241279{
    1125         dev_class_info_t *info = create_dev_class_info();
     1280        dev_class_info_t *info;
     1281
     1282        assert(fun != NULL);
     1283        assert(cl != NULL);
     1284
     1285        info = create_dev_class_info();
     1286
    11261287       
    11271288        if (info != NULL) {
    11281289                info->dev_class = cl;
    1129                 info->dev = dev;
     1290                info->fun = fun;
    11301291               
    11311292                /* Add the device to the class. */
     
    11351296               
    11361297                /* Add the class to the device. */
    1137                 list_append(&info->dev_classes, &dev->classes);
     1298                list_append(&info->dev_classes, &fun->classes);
    11381299               
    11391300                /* Create unique name for the device within the class. */
     
    11891350        list_initialize(&class_list->classes);
    11901351        fibril_rwlock_initialize(&class_list->rwlock);
    1191         hash_table_create(&class_list->devmap_devices, DEVICE_BUCKETS, 1,
     1352        hash_table_create(&class_list->devmap_functions, DEVICE_BUCKETS, 1,
    11921353            &devmap_devices_class_ops);
    11931354}
     
    11961357/* Devmap devices */
    11971358
    1198 node_t *find_devmap_tree_device(dev_tree_t *tree, devmap_handle_t devmap_handle)
    1199 {
    1200         node_t *dev = NULL;
     1359fun_node_t *find_devmap_tree_function(dev_tree_t *tree, devmap_handle_t devmap_handle)
     1360{
     1361        fun_node_t *fun = NULL;
    12011362        link_t *link;
    12021363        unsigned long key = (unsigned long) devmap_handle;
    12031364       
    12041365        fibril_rwlock_read_lock(&tree->rwlock);
    1205         link = hash_table_find(&tree->devmap_devices, &key);
     1366        link = hash_table_find(&tree->devmap_functions, &key);
    12061367        if (link != NULL)
    1207                 dev = hash_table_get_instance(link, node_t, devmap_link);
     1368                fun = hash_table_get_instance(link, fun_node_t, devmap_fun);
    12081369        fibril_rwlock_read_unlock(&tree->rwlock);
    12091370       
    1210         return dev;
    1211 }
    1212 
    1213 node_t *find_devmap_class_device(class_list_t *classes,
     1371        return fun;
     1372}
     1373
     1374fun_node_t *find_devmap_class_function(class_list_t *classes,
    12141375    devmap_handle_t devmap_handle)
    12151376{
    1216         node_t *dev = NULL;
     1377        fun_node_t *fun = NULL;
    12171378        dev_class_info_t *cli;
    12181379        link_t *link;
     
    12201381       
    12211382        fibril_rwlock_read_lock(&classes->rwlock);
    1222         link = hash_table_find(&classes->devmap_devices, &key);
     1383        link = hash_table_find(&classes->devmap_functions, &key);
    12231384        if (link != NULL) {
    12241385                cli = hash_table_get_instance(link, dev_class_info_t,
    12251386                    devmap_link);
    1226                 dev = cli->dev;
     1387                fun = cli->fun;
    12271388        }
    12281389        fibril_rwlock_read_unlock(&classes->rwlock);
    12291390       
    1230         return dev;
    1231 }
    1232 
    1233 void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
     1391        return fun;
     1392}
     1393
     1394void class_add_devmap_function(class_list_t *class_list, dev_class_info_t *cli)
    12341395{
    12351396        unsigned long key = (unsigned long) cli->devmap_handle;
    12361397       
    12371398        fibril_rwlock_write_lock(&class_list->rwlock);
    1238         hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
     1399        hash_table_insert(&class_list->devmap_functions, &key, &cli->devmap_link);
    12391400        fibril_rwlock_write_unlock(&class_list->rwlock);
    12401401
    1241         assert(find_devmap_class_device(class_list, cli->devmap_handle) != NULL);
    1242 }
    1243 
    1244 void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
    1245 {
    1246         unsigned long key = (unsigned long) node->devmap_handle;
     1402        assert(find_devmap_class_function(class_list, cli->devmap_handle) != NULL);
     1403}
     1404
     1405void tree_add_devmap_function(dev_tree_t *tree, fun_node_t *fun)
     1406{
     1407        unsigned long key = (unsigned long) fun->devmap_handle;
    12471408        fibril_rwlock_write_lock(&tree->rwlock);
    1248         hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
     1409        hash_table_insert(&tree->devmap_functions, &key, &fun->devmap_fun);
    12491410        fibril_rwlock_write_unlock(&tree->rwlock);
    12501411}
Note: See TracChangeset for help on using the changeset viewer.