Changeset 92574f4 in mainline for uspace/srv/devman/devman.c


Ignore:
Timestamp:
2011-02-24T12:03:27Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e7b7ebd5
Parents:
4837092 (diff), a80849c (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:

Merged development (changes in DDF, etc.).

Conflicts in uspace/drv/usbkbd/main.c

File:
1 edited

Legend:

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

    r4837092 r92574f4  
    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};
     
    381396}
    382397
    383 /** Create root device node in the device tree.
     398/** Create root device and function node in the device tree.
    384399 *
    385400 * @param tree  The device tree.
    386401 * @return      True on success, false otherwise.
    387402 */
    388 bool create_root_node(dev_tree_t *tree)
    389 {
    390         node_t *node;
    391 
    392         printf(NAME ": create_root_node\n");
    393 
     403bool create_root_nodes(dev_tree_t *tree)
     404{
     405        fun_node_t *fun;
     406        dev_node_t *dev;
     407       
     408        printf(NAME ": create_root_nodes\n");
     409       
    394410        fibril_rwlock_write_lock(&tree->rwlock);
    395         node = create_dev_node();
    396         if (node != NULL) {
    397                 insert_dev_node(tree, node, clone_string(""), NULL);
    398                 match_id_t *id = create_match_id();
    399                 id->id = clone_string("root");
    400                 id->score = 100;
    401                 add_match_id(&node->match_ids, id);
    402                 tree->root_node = node;
    403         }
     411       
     412        /*
     413         * Create root function. This is a pseudo function to which
     414         * the root device node is attached. It allows us to match
     415         * the root device driver in a standard manner, i.e. against
     416         * the parent function.
     417         */
     418       
     419        fun = create_fun_node();
     420        if (fun == NULL) {
     421                fibril_rwlock_write_unlock(&tree->rwlock);
     422                return false;
     423        }
     424       
     425        insert_fun_node(tree, fun, clone_string(""), NULL);
     426        match_id_t *id = create_match_id();
     427        id->id = clone_string("root");
     428        id->score = 100;
     429        add_match_id(&fun->match_ids, id);
     430        tree->root_node = fun;
     431       
     432        /*
     433         * Create root device node.
     434         */
     435        dev = create_dev_node();
     436        if (dev == NULL) {
     437                fibril_rwlock_write_unlock(&tree->rwlock);
     438                return false;
     439        }
     440       
     441        insert_dev_node(tree, dev, fun);
     442       
    404443        fibril_rwlock_write_unlock(&tree->rwlock);
    405 
    406         return node != NULL;
     444       
     445        return dev != NULL;
    407446}
    408447
     
    422461 *                      is found.
    423462 */
    424 driver_t *find_best_match_driver(driver_list_t *drivers_list, node_t *node)
     463driver_t *find_best_match_driver(driver_list_t *drivers_list, dev_node_t *node)
    425464{
    426465        driver_t *best_drv = NULL, *drv = NULL;
     
    450489 * @param drv           The driver.
    451490 */
    452 void attach_driver(node_t *node, driver_t *drv)
     491void attach_driver(dev_node_t *dev, driver_t *drv)
    453492{
    454493        printf(NAME ": attach_driver %s to device %s\n",
    455             drv->name, node->pathname);
     494            drv->name, dev->pfun->pathname);
    456495       
    457496        fibril_mutex_lock(&drv->driver_mutex);
    458497       
    459         node->drv = drv;
    460         list_append(&node->driver_devices, &drv->devices);
     498        dev->drv = drv;
     499        list_append(&dev->driver_devices, &drv->devices);
    461500       
    462501        fibril_mutex_unlock(&drv->driver_mutex);
     
    538577static void pass_devices_to_driver(driver_t *driver, dev_tree_t *tree)
    539578{
    540         node_t *dev;
     579        dev_node_t *dev;
    541580        link_t *link;
    542581        int phone;
     
    559598        link = driver->devices.next;
    560599        while (link != &driver->devices) {
    561                 dev = list_get_instance(link, node_t, driver_devices);
     600                dev = list_get_instance(link, dev_node_t, driver_devices);
    562601                if (dev->passed_to_driver) {
    563602                        link = link->next;
     
    598637        }
    599638
    600         ipc_hangup(phone);
     639        async_hangup(phone);
    601640
    602641        /*
     
    677716}
    678717
    679 /** Create devmap path and name for the device. */
    680 static void devmap_register_tree_device(node_t *node, dev_tree_t *tree)
     718/** Create devmap path and name for the function. */
     719void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)
    681720{
    682721        char *devmap_pathname = NULL;
    683722        char *devmap_name = NULL;
    684723       
    685         asprintf(&devmap_name, "%s", node->pathname);
     724        asprintf(&devmap_name, "%s", fun->pathname);
    686725        if (devmap_name == NULL)
    687726                return;
     
    697736       
    698737        devmap_device_register_with_iface(devmap_pathname,
    699             &node->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
    700        
    701         tree_add_devmap_device(tree, node);
     738            &fun->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
     739       
     740        tree_add_devmap_function(tree, fun);
    702741       
    703742        free(devmap_name);
     
    710749 * @param node          The device's node in the device tree.
    711750 */
    712 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree)
     751void add_device(int phone, driver_t *drv, dev_node_t *dev, dev_tree_t *tree)
    713752{
    714753        /*
     
    717756         */
    718757        printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
    719             node->name);
     758            dev->pfun->name);
    720759       
    721760        sysarg_t rc;
     
    724763        /* Send the device to the driver. */
    725764        devman_handle_t parent_handle;
    726         if (node->parent) {
    727                 parent_handle = node->parent->handle;
     765        if (dev->pfun) {
     766                parent_handle = dev->pfun->handle;
    728767        } else {
    729768                parent_handle = 0;
    730769        }
    731770
    732         aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle,
     771        aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, dev->handle,
    733772            parent_handle, &answer);
    734773       
    735774        /* Send the device's name to the driver. */
    736         rc = async_data_write_start(phone, node->name,
    737             str_size(node->name) + 1);
     775        rc = async_data_write_start(phone, dev->pfun->name,
     776            str_size(dev->pfun->name) + 1);
    738777        if (rc != EOK) {
    739778                /* TODO handle error */
     
    745784        switch(rc) {
    746785        case EOK:
    747                 node->state = DEVICE_USABLE;
    748                 devmap_register_tree_device(node, tree);
     786                dev->state = DEVICE_USABLE;
    749787                break;
    750788        case ENOENT:
    751                 node->state = DEVICE_NOT_PRESENT;
     789                dev->state = DEVICE_NOT_PRESENT;
    752790                break;
    753791        default:
    754                 node->state = DEVICE_INVALID;
    755         }
    756        
    757         node->passed_to_driver = true;
     792                dev->state = DEVICE_INVALID;
     793        }
     794       
     795        dev->passed_to_driver = true;
    758796
    759797        return;
     
    767805 *                      successfully assigned to the device, false otherwise.
    768806 */
    769 bool assign_driver(node_t *node, driver_list_t *drivers_list, dev_tree_t *tree)
    770 {
     807bool assign_driver(dev_node_t *dev, driver_list_t *drivers_list,
     808    dev_tree_t *tree)
     809{
     810        assert(dev != NULL);
     811        assert(drivers_list != NULL);
     812        assert(tree != NULL);
     813       
    771814        /*
    772815         * Find the driver which is the most suitable for handling this device.
    773816         */
    774         driver_t *drv = find_best_match_driver(drivers_list, node);
     817        driver_t *drv = find_best_match_driver(drivers_list, dev);
    775818        if (drv == NULL) {
    776819                printf(NAME ": no driver found for device '%s'.\n",
    777                     node->pathname);
     820                    dev->pfun->pathname);
    778821                return false;
    779822        }
    780823       
    781824        /* Attach the driver to the device. */
    782         attach_driver(node, drv);
     825        attach_driver(dev, drv);
    783826       
    784827        fibril_mutex_lock(&drv->driver_mutex);
     
    794837                int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
    795838                if (phone >= 0) {
    796                         add_device(phone, drv, node, tree);
    797                         ipc_hangup(phone);
     839                        add_device(phone, drv, dev, tree);
     840                        async_hangup(phone);
    798841                }
    799842        }
     
    818861        hash_table_create(&tree->devman_devices, DEVICE_BUCKETS, 1,
    819862            &devman_devices_ops);
    820         hash_table_create(&tree->devmap_devices, DEVICE_BUCKETS, 1,
     863        hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1,
     864            &devman_functions_ops);
     865        hash_table_create(&tree->devmap_functions, DEVICE_BUCKETS, 1,
    821866            &devmap_devices_ops);
    822867       
    823868        fibril_rwlock_initialize(&tree->rwlock);
    824869       
    825         /* Create root node and add it to the device tree. */
    826         if (!create_root_node(tree))
     870        /* Create root function and root device and add them to the device tree. */
     871        if (!create_root_nodes(tree))
    827872                return false;
    828873
    829874        /* Find suitable driver and start it. */
    830         return assign_driver(tree->root_node, drivers_list, tree);
     875        return assign_driver(tree->root_node->child, drivers_list, tree);
    831876}
    832877
     
    837882 * @return              A device node structure.
    838883 */
    839 node_t *create_dev_node(void)
    840 {
    841         node_t *res = malloc(sizeof(node_t));
     884dev_node_t *create_dev_node(void)
     885{
     886        dev_node_t *res = malloc(sizeof(dev_node_t));
    842887       
    843888        if (res != NULL) {
    844                 memset(res, 0, sizeof(node_t));
    845                 list_initialize(&res->children);
    846                 list_initialize(&res->match_ids.ids);
    847                 list_initialize(&res->classes);
     889                memset(res, 0, sizeof(dev_node_t));
     890                list_initialize(&res->functions);
     891                link_initialize(&res->driver_devices);
     892                link_initialize(&res->devman_dev);
    848893        }
    849894       
     
    855900 * @param node          The device node structure.
    856901 */
    857 void delete_dev_node(node_t *node)
    858 {
    859         assert(list_empty(&node->children));
    860         assert(node->parent == NULL);
    861         assert(node->drv == NULL);
    862        
    863         clean_match_ids(&node->match_ids);
    864         free_not_null(node->name);
    865         free_not_null(node->pathname);
    866         free(node);
     902void delete_dev_node(dev_node_t *dev)
     903{
     904        assert(list_empty(&dev->functions));
     905        assert(dev->pfun == NULL);
     906        assert(dev->drv == NULL);
     907       
     908        free(dev);
    867909}
    868910
     
    873915 * @return              The device node.
    874916 */
    875 node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
     917dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
    876918{
    877919        unsigned long key = handle;
     
    881923       
    882924        link = hash_table_find(&tree->devman_devices, &key);
    883         return hash_table_get_instance(link, node_t, devman_link);
     925        return hash_table_get_instance(link, dev_node_t, devman_dev);
    884926}
    885927
     
    890932 * @return              The device node.
    891933 */
    892 node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle)
    893 {
    894         node_t *node = NULL;
     934dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle)
     935{
     936        dev_node_t *dev = NULL;
    895937       
    896938        fibril_rwlock_read_lock(&tree->rwlock);
    897         node = find_dev_node_no_lock(tree, handle);
     939        dev = find_dev_node_no_lock(tree, handle);
    898940        fibril_rwlock_read_unlock(&tree->rwlock);
    899941       
    900         return node;
    901 }
    902 
     942        return dev;
     943}
     944
     945/* Function nodes */
     946
     947/** Create a new function node.
     948 *
     949 * @return              A function node structure.
     950 */
     951fun_node_t *create_fun_node(void)
     952{
     953        fun_node_t *res = malloc(sizeof(fun_node_t));
     954       
     955        if (res != NULL) {
     956                memset(res, 0, sizeof(fun_node_t));
     957                link_initialize(&res->dev_functions);
     958                list_initialize(&res->match_ids.ids);
     959                list_initialize(&res->classes);
     960                link_initialize(&res->devman_fun);
     961                link_initialize(&res->devmap_fun);
     962        }
     963       
     964        return res;
     965}
     966
     967/** Delete a function node.
     968 *
     969 * @param fun           The device node structure.
     970 */
     971void delete_fun_node(fun_node_t *fun)
     972{
     973        assert(fun->dev == NULL);
     974        assert(fun->child == NULL);
     975       
     976        clean_match_ids(&fun->match_ids);
     977        free_not_null(fun->name);
     978        free_not_null(fun->pathname);
     979        free(fun);
     980}
     981
     982/** Find the function node with the specified handle.
     983 *
     984 * @param tree          The device tree where we look for the device node.
     985 * @param handle        The handle of the function.
     986 * @return              The function node.
     987 */
     988fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
     989{
     990        unsigned long key = handle;
     991        link_t *link;
     992       
     993        assert(fibril_rwlock_is_locked(&tree->rwlock));
     994       
     995        link = hash_table_find(&tree->devman_functions, &key);
     996        if (link == NULL)
     997                return NULL;
     998       
     999        return hash_table_get_instance(link, fun_node_t, devman_fun);
     1000}
     1001
     1002/** Find the function node with the specified handle.
     1003 *
     1004 * @param tree          The device tree where we look for the device node.
     1005 * @param handle        The handle of the function.
     1006 * @return              The function node.
     1007 */
     1008fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle)
     1009{
     1010        fun_node_t *fun = NULL;
     1011       
     1012        fibril_rwlock_read_lock(&tree->rwlock);
     1013        fun = find_fun_node_no_lock(tree, handle);
     1014        fibril_rwlock_read_unlock(&tree->rwlock);
     1015       
     1016        return fun;
     1017}
    9031018
    9041019/** Create and set device's full path in device tree.
     
    9091024 *                      resources etc.).
    9101025 */
    911 static bool set_dev_path(node_t *node, node_t *parent)
    912 {
    913         assert(node->name != NULL);
    914        
    915         size_t pathsize = (str_size(node->name) + 1);
     1026static bool set_fun_path(fun_node_t *fun, fun_node_t *parent)
     1027{
     1028        assert(fun->name != NULL);
     1029       
     1030        size_t pathsize = (str_size(fun->name) + 1);
    9161031        if (parent != NULL)
    9171032                pathsize += str_size(parent->pathname) + 1;
    9181033       
    919         node->pathname = (char *) malloc(pathsize);
    920         if (node->pathname == NULL) {
     1034        fun->pathname = (char *) malloc(pathsize);
     1035        if (fun->pathname == NULL) {
    9211036                printf(NAME ": failed to allocate device path.\n");
    9221037                return false;
     
    9241039       
    9251040        if (parent != NULL) {
    926                 str_cpy(node->pathname, pathsize, parent->pathname);
    927                 str_append(node->pathname, pathsize, "/");
    928                 str_append(node->pathname, pathsize, node->name);
     1041                str_cpy(fun->pathname, pathsize, parent->pathname);
     1042                str_append(fun->pathname, pathsize, "/");
     1043                str_append(fun->pathname, pathsize, fun->name);
    9291044        } else {
    930                 str_cpy(node->pathname, pathsize, node->name);
     1045                str_cpy(fun->pathname, pathsize, fun->name);
    9311046        }
    9321047       
     
    9441059 *                      etc.).
    9451060 */
    946 bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name,
    947     node_t *parent)
    948 {
    949         assert(node != NULL);
     1061bool insert_dev_node(dev_tree_t *tree, dev_node_t *dev, fun_node_t *pfun)
     1062{
     1063        assert(dev != NULL);
    9501064        assert(tree != NULL);
    951         assert(dev_name != NULL);
    9521065        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    9531066       
    954         node->name = dev_name;
    955         if (!set_dev_path(node, parent)) {
     1067        /* Add the node to the handle-to-node map. */
     1068        dev->handle = ++tree->current_handle;
     1069        unsigned long key = dev->handle;
     1070        hash_table_insert(&tree->devman_devices, &key, &dev->devman_dev);
     1071
     1072        /* Add the node to the list of its parent's children. */
     1073        printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);
     1074        dev->pfun = pfun;
     1075        pfun->child = dev;
     1076       
     1077        return true;
     1078}
     1079
     1080/** Insert new function into device tree.
     1081 *
     1082 * @param tree          The device tree.
     1083 * @param node          The newly added function node.
     1084 * @param dev_name      The name of the newly added function.
     1085 * @param parent        Owning device node.
     1086 *
     1087 * @return              True on success, false otherwise (insufficient resources
     1088 *                      etc.).
     1089 */
     1090bool insert_fun_node(dev_tree_t *tree, fun_node_t *fun, char *fun_name,
     1091    dev_node_t *dev)
     1092{
     1093        fun_node_t *pfun;
     1094       
     1095        assert(fun != NULL);
     1096        assert(tree != NULL);
     1097        assert(fun_name != NULL);
     1098        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
     1099       
     1100        /*
     1101         * The root function is a special case, it does not belong to any
     1102         * device so for the root function dev == NULL.
     1103         */
     1104        pfun = (dev != NULL) ? dev->pfun : NULL;
     1105       
     1106        fun->name = fun_name;
     1107        if (!set_fun_path(fun, pfun)) {
    9561108                return false;
    9571109        }
    9581110       
    9591111        /* Add the node to the handle-to-node map. */
    960         node->handle = ++tree->current_handle;
    961         unsigned long key = node->handle;
    962         hash_table_insert(&tree->devman_devices, &key, &node->devman_link);
     1112        fun->handle = ++tree->current_handle;
     1113        unsigned long key = fun->handle;
     1114        hash_table_insert(&tree->devman_functions, &key, &fun->devman_fun);
    9631115
    9641116        /* Add the node to the list of its parent's children. */
    965         node->parent = parent;
    966         if (parent != NULL)
    967                 list_append(&node->sibling, &parent->children);
     1117        fun->dev = dev;
     1118        if (dev != NULL)
     1119                list_append(&fun->dev_functions, &dev->functions);
    9681120       
    9691121        return true;
    9701122}
    9711123
    972 /** Find device node with a specified path in the device tree.
     1124/** Find function node with a specified path in the device tree.
    9731125 *
    974  * @param path          The path of the device node in the device tree.
     1126 * @param path          The path of the function node in the device tree.
    9751127 * @param tree          The device tree.
    976  * @return              The device node if it is present in the tree, NULL
     1128 * @return              The function node if it is present in the tree, NULL
    9771129 *                      otherwise.
    9781130 */
    979 node_t *find_dev_node_by_path(dev_tree_t *tree, char *path)
     1131fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path)
    9801132{
    9811133        fibril_rwlock_read_lock(&tree->rwlock);
    9821134       
    983         node_t *dev = tree->root_node;
     1135        fun_node_t *fun = tree->root_node;
    9841136        /*
    985          * Relative path to the device from its parent (but with '/' at the
     1137         * Relative path to the function from its parent (but with '/' at the
    9861138         * beginning)
    9871139         */
     
    9901142        bool cont = (rel_path[0] == '/');
    9911143       
    992         while (cont && dev != NULL) {
     1144        while (cont && fun != NULL) {
    9931145                next_path_elem  = get_path_elem_end(rel_path + 1);
    9941146                if (next_path_elem[0] == '/') {
     
    9991151                }
    10001152               
    1001                 dev = find_node_child(dev, rel_path + 1);
     1153                fun = find_node_child(fun, rel_path + 1);
    10021154               
    10031155                if (cont) {
     
    10101162        fibril_rwlock_read_unlock(&tree->rwlock);
    10111163       
    1012         return dev;
    1013 }
    1014 
    1015 /** Find child device node with a specified name.
     1164        return fun;
     1165}
     1166
     1167/** Find child function node with a specified name.
    10161168 *
    10171169 * Device tree rwlock should be held at least for reading.
    10181170 *
    1019  * @param parent        The parent device node.
    1020  * @param name          The name of the child device node.
    1021  * @return              The child device node.
    1022  */
    1023 node_t *find_node_child(node_t *parent, const char *name)
    1024 {
    1025         node_t *dev;
     1171 * @param parent        The parent function node.
     1172 * @param name          The name of the child function.
     1173 * @return              The child function node.
     1174 */
     1175fun_node_t *find_node_child(fun_node_t *pfun, const char *name)
     1176{
     1177        fun_node_t *fun;
    10261178        link_t *link;
    10271179       
    1028         link = parent->children.next;
    1029        
    1030         while (link != &parent->children) {
    1031                 dev = list_get_instance(link, node_t, sibling);
     1180        link = pfun->child->functions.next;
     1181       
     1182        while (link != &pfun->child->functions) {
     1183                fun = list_get_instance(link, fun_node_t, dev_functions);
    10321184               
    1033                 if (str_cmp(name, dev->name) == 0)
    1034                         return dev;
     1185                if (str_cmp(name, fun->name) == 0)
     1186                        return fun;
    10351187               
    10361188                link = link->next;
     
    10711223        if (info != NULL) {
    10721224                memset(info, 0, sizeof(dev_class_info_t));
    1073                 list_initialize(&info->dev_classes);
    1074                 list_initialize(&info->devmap_link);
    1075                 list_initialize(&info->link);
     1225                link_initialize(&info->dev_classes);
     1226                link_initialize(&info->devmap_link);
     1227                link_initialize(&info->link);
    10761228        }
    10771229       
     
    11151267}
    11161268
    1117 /** Add the device to the class.
     1269/** Add the device function to the class.
    11181270 *
    11191271 * The device may be added to multiple classes and a class may contain multiple
     
    11281280 *                      with the class.
    11291281 */
    1130 dev_class_info_t *add_device_to_class(node_t *dev, dev_class_t *cl,
     1282dev_class_info_t *add_function_to_class(fun_node_t *fun, dev_class_t *cl,
    11311283    const char *base_dev_name)
    11321284{
    1133         dev_class_info_t *info = create_dev_class_info();
     1285        dev_class_info_t *info;
     1286
     1287        assert(fun != NULL);
     1288        assert(cl != NULL);
     1289
     1290        info = create_dev_class_info();
     1291
    11341292       
    11351293        if (info != NULL) {
    11361294                info->dev_class = cl;
    1137                 info->dev = dev;
     1295                info->fun = fun;
    11381296               
    11391297                /* Add the device to the class. */
     
    11431301               
    11441302                /* Add the class to the device. */
    1145                 list_append(&info->dev_classes, &dev->classes);
     1303                list_append(&info->dev_classes, &fun->classes);
    11461304               
    11471305                /* Create unique name for the device within the class. */
     
    11971355        list_initialize(&class_list->classes);
    11981356        fibril_rwlock_initialize(&class_list->rwlock);
    1199         hash_table_create(&class_list->devmap_devices, DEVICE_BUCKETS, 1,
     1357        hash_table_create(&class_list->devmap_functions, DEVICE_BUCKETS, 1,
    12001358            &devmap_devices_class_ops);
    12011359}
     
    12041362/* Devmap devices */
    12051363
    1206 node_t *find_devmap_tree_device(dev_tree_t *tree, devmap_handle_t devmap_handle)
    1207 {
    1208         node_t *dev = NULL;
     1364fun_node_t *find_devmap_tree_function(dev_tree_t *tree, devmap_handle_t devmap_handle)
     1365{
     1366        fun_node_t *fun = NULL;
    12091367        link_t *link;
    12101368        unsigned long key = (unsigned long) devmap_handle;
    12111369       
    12121370        fibril_rwlock_read_lock(&tree->rwlock);
    1213         link = hash_table_find(&tree->devmap_devices, &key);
     1371        link = hash_table_find(&tree->devmap_functions, &key);
    12141372        if (link != NULL)
    1215                 dev = hash_table_get_instance(link, node_t, devmap_link);
     1373                fun = hash_table_get_instance(link, fun_node_t, devmap_fun);
    12161374        fibril_rwlock_read_unlock(&tree->rwlock);
    12171375       
    1218         return dev;
    1219 }
    1220 
    1221 node_t *find_devmap_class_device(class_list_t *classes,
     1376        return fun;
     1377}
     1378
     1379fun_node_t *find_devmap_class_function(class_list_t *classes,
    12221380    devmap_handle_t devmap_handle)
    12231381{
    1224         node_t *dev = NULL;
     1382        fun_node_t *fun = NULL;
    12251383        dev_class_info_t *cli;
    12261384        link_t *link;
     
    12281386       
    12291387        fibril_rwlock_read_lock(&classes->rwlock);
    1230         link = hash_table_find(&classes->devmap_devices, &key);
     1388        link = hash_table_find(&classes->devmap_functions, &key);
    12311389        if (link != NULL) {
    12321390                cli = hash_table_get_instance(link, dev_class_info_t,
    12331391                    devmap_link);
    1234                 dev = cli->dev;
     1392                fun = cli->fun;
    12351393        }
    12361394        fibril_rwlock_read_unlock(&classes->rwlock);
    12371395       
    1238         return dev;
    1239 }
    1240 
    1241 void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
     1396        return fun;
     1397}
     1398
     1399void class_add_devmap_function(class_list_t *class_list, dev_class_info_t *cli)
    12421400{
    12431401        unsigned long key = (unsigned long) cli->devmap_handle;
    12441402       
    12451403        fibril_rwlock_write_lock(&class_list->rwlock);
    1246         hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
     1404        hash_table_insert(&class_list->devmap_functions, &key, &cli->devmap_link);
    12471405        fibril_rwlock_write_unlock(&class_list->rwlock);
    12481406
    1249         assert(find_devmap_class_device(class_list, cli->devmap_handle) != NULL);
    1250 }
    1251 
    1252 void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
    1253 {
    1254         unsigned long key = (unsigned long) node->devmap_handle;
     1407        assert(find_devmap_class_function(class_list, cli->devmap_handle) != NULL);
     1408}
     1409
     1410void tree_add_devmap_function(dev_tree_t *tree, fun_node_t *fun)
     1411{
     1412        unsigned long key = (unsigned long) fun->devmap_handle;
    12551413        fibril_rwlock_write_lock(&tree->rwlock);
    1256         hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
     1414        hash_table_insert(&tree->devmap_functions, &key, &fun->devmap_fun);
    12571415        fibril_rwlock_write_unlock(&tree->rwlock);
    12581416}
Note: See TracChangeset for help on using the changeset viewer.