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


Ignore:
Timestamp:
2011-03-30T13:10:24Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4ae90f9
Parents:
6e50466 (diff), d6b81941 (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

    r6e50466 rad7a6c9  
    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};
     
    251266        }
    252267       
    253         if (read(fd, buf, len) <= 0) {
     268        ssize_t read_bytes = safe_read(fd, buf, len);
     269        if (read_bytes <= 0) {
    254270                printf(NAME ": unable to read file '%s'.\n", conf_path);
    255271                goto cleanup;
    256272        }
    257         buf[len] = 0;
     273        buf[read_bytes] = 0;
    258274       
    259275        suc = parse_match_ids(buf, ids);
     
    373389}
    374390
    375 /** Create root device node in the device tree.
     391/** Create root device and function node in the device tree.
    376392 *
    377393 * @param tree  The device tree.
    378394 * @return      True on success, false otherwise.
    379395 */
    380 bool create_root_node(dev_tree_t *tree)
    381 {
    382         node_t *node;
    383 
    384         printf(NAME ": create_root_node\n");
    385 
    386         node = create_dev_node();
    387         if (node != NULL) {
    388                 insert_dev_node(tree, node, clone_string(""), NULL);
    389                 match_id_t *id = create_match_id();
    390                 id->id = clone_string("root");
    391                 id->score = 100;
    392                 add_match_id(&node->match_ids, id);
    393                 tree->root_node = node;
    394         }
    395 
    396         return node != NULL;
     396bool create_root_nodes(dev_tree_t *tree)
     397{
     398        fun_node_t *fun;
     399        dev_node_t *dev;
     400       
     401        printf(NAME ": create_root_nodes\n");
     402       
     403        fibril_rwlock_write_lock(&tree->rwlock);
     404       
     405        /*
     406         * Create root function. This is a pseudo function to which
     407         * the root device node is attached. It allows us to match
     408         * the root device driver in a standard manner, i.e. against
     409         * the parent function.
     410         */
     411       
     412        fun = create_fun_node();
     413        if (fun == NULL) {
     414                fibril_rwlock_write_unlock(&tree->rwlock);
     415                return false;
     416        }
     417       
     418        insert_fun_node(tree, fun, clone_string(""), NULL);
     419        match_id_t *id = create_match_id();
     420        id->id = clone_string("root");
     421        id->score = 100;
     422        add_match_id(&fun->match_ids, id);
     423        tree->root_node = fun;
     424       
     425        /*
     426         * Create root device node.
     427         */
     428        dev = create_dev_node();
     429        if (dev == NULL) {
     430                fibril_rwlock_write_unlock(&tree->rwlock);
     431                return false;
     432        }
     433       
     434        insert_dev_node(tree, dev, fun);
     435       
     436        fibril_rwlock_write_unlock(&tree->rwlock);
     437       
     438        return dev != NULL;
    397439}
    398440
     
    412454 *                      is found.
    413455 */
    414 driver_t *find_best_match_driver(driver_list_t *drivers_list, node_t *node)
     456driver_t *find_best_match_driver(driver_list_t *drivers_list, dev_node_t *node)
    415457{
    416458        driver_t *best_drv = NULL, *drv = NULL;
     
    440482 * @param drv           The driver.
    441483 */
    442 void attach_driver(node_t *node, driver_t *drv)
     484void attach_driver(dev_node_t *dev, driver_t *drv)
    443485{
    444486        printf(NAME ": attach_driver %s to device %s\n",
    445             drv->name, node->pathname);
     487            drv->name, dev->pfun->pathname);
    446488       
    447489        fibril_mutex_lock(&drv->driver_mutex);
    448490       
    449         node->drv = drv;
    450         list_append(&node->driver_devices, &drv->devices);
     491        dev->drv = drv;
     492        list_append(&dev->driver_devices, &drv->devices);
    451493       
    452494        fibril_mutex_unlock(&drv->driver_mutex);
     
    454496
    455497/** Start a driver
    456  *
    457  * The driver's mutex is assumed to be locked.
    458498 *
    459499 * @param drv           The driver's structure.
     
    465505        int rc;
    466506
     507        assert(fibril_mutex_is_locked(&drv->driver_mutex));
     508       
    467509        printf(NAME ": start_driver '%s'\n", drv->name);
    468510       
     
    528570static void pass_devices_to_driver(driver_t *driver, dev_tree_t *tree)
    529571{
    530         node_t *dev;
     572        dev_node_t *dev;
    531573        link_t *link;
    532574        int phone;
     
    549591        link = driver->devices.next;
    550592        while (link != &driver->devices) {
    551                 dev = list_get_instance(link, node_t, driver_devices);
     593                dev = list_get_instance(link, dev_node_t, driver_devices);
    552594                if (dev->passed_to_driver) {
    553595                        link = link->next;
     
    588630        }
    589631
    590         ipc_hangup(phone);
     632        async_hangup(phone);
    591633
    592634        /*
     
    667709}
    668710
    669 /** Create devmap path and name for the device. */
    670 static void devmap_register_tree_device(node_t *node, dev_tree_t *tree)
     711/** Create devmap path and name for the function. */
     712void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)
    671713{
    672714        char *devmap_pathname = NULL;
    673715        char *devmap_name = NULL;
    674716       
    675         asprintf(&devmap_name, "%s", node->pathname);
     717        asprintf(&devmap_name, "%s", fun->pathname);
    676718        if (devmap_name == NULL)
    677719                return;
     
    687729       
    688730        devmap_device_register_with_iface(devmap_pathname,
    689             &node->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
    690        
    691         tree_add_devmap_device(tree, node);
     731            &fun->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
     732       
     733        tree_add_devmap_function(tree, fun);
    692734       
    693735        free(devmap_name);
     
    700742 * @param node          The device's node in the device tree.
    701743 */
    702 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree)
     744void add_device(int phone, driver_t *drv, dev_node_t *dev, dev_tree_t *tree)
    703745{
    704746        /*
     
    707749         */
    708750        printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
    709             node->name);
     751            dev->pfun->name);
    710752       
    711753        sysarg_t rc;
     
    714756        /* Send the device to the driver. */
    715757        devman_handle_t parent_handle;
    716         if (node->parent) {
    717                 parent_handle = node->parent->handle;
     758        if (dev->pfun) {
     759                parent_handle = dev->pfun->handle;
    718760        } else {
    719761                parent_handle = 0;
    720762        }
    721763
    722         aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle,
     764        aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, dev->handle,
    723765            parent_handle, &answer);
    724766       
    725767        /* Send the device's name to the driver. */
    726         rc = async_data_write_start(phone, node->name,
    727             str_size(node->name) + 1);
     768        rc = async_data_write_start(phone, dev->pfun->name,
     769            str_size(dev->pfun->name) + 1);
    728770        if (rc != EOK) {
    729771                /* TODO handle error */
     
    735777        switch(rc) {
    736778        case EOK:
    737                 node->state = DEVICE_USABLE;
    738                 devmap_register_tree_device(node, tree);
     779                dev->state = DEVICE_USABLE;
    739780                break;
    740781        case ENOENT:
    741                 node->state = DEVICE_NOT_PRESENT;
     782                dev->state = DEVICE_NOT_PRESENT;
    742783                break;
    743784        default:
    744                 node->state = DEVICE_INVALID;
    745         }
    746        
    747         node->passed_to_driver = true;
     785                dev->state = DEVICE_INVALID;
     786        }
     787       
     788        dev->passed_to_driver = true;
    748789
    749790        return;
     
    757798 *                      successfully assigned to the device, false otherwise.
    758799 */
    759 bool assign_driver(node_t *node, driver_list_t *drivers_list, dev_tree_t *tree)
    760 {
     800bool assign_driver(dev_node_t *dev, driver_list_t *drivers_list,
     801    dev_tree_t *tree)
     802{
     803        assert(dev != NULL);
     804        assert(drivers_list != NULL);
     805        assert(tree != NULL);
     806       
    761807        /*
    762808         * Find the driver which is the most suitable for handling this device.
    763809         */
    764         driver_t *drv = find_best_match_driver(drivers_list, node);
     810        driver_t *drv = find_best_match_driver(drivers_list, dev);
    765811        if (drv == NULL) {
    766812                printf(NAME ": no driver found for device '%s'.\n",
    767                     node->pathname);
     813                    dev->pfun->pathname);
    768814                return false;
    769815        }
    770816       
    771817        /* Attach the driver to the device. */
    772         attach_driver(node, drv);
     818        attach_driver(dev, drv);
    773819       
    774820        fibril_mutex_lock(&drv->driver_mutex);
     
    783829                /* Notify the driver about the new device. */
    784830                int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
    785                 if (phone > 0) {
    786                         add_device(phone, drv, node, tree);
    787                         ipc_hangup(phone);
     831                if (phone >= 0) {
     832                        add_device(phone, drv, dev, tree);
     833                        async_hangup(phone);
    788834                }
    789835        }
     
    808854        hash_table_create(&tree->devman_devices, DEVICE_BUCKETS, 1,
    809855            &devman_devices_ops);
    810         hash_table_create(&tree->devmap_devices, DEVICE_BUCKETS, 1,
     856        hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1,
     857            &devman_functions_ops);
     858        hash_table_create(&tree->devmap_functions, DEVICE_BUCKETS, 1,
    811859            &devmap_devices_ops);
    812860       
    813861        fibril_rwlock_initialize(&tree->rwlock);
    814862       
    815         /* Create root node and add it to the device tree. */
    816         if (!create_root_node(tree))
     863        /* Create root function and root device and add them to the device tree. */
     864        if (!create_root_nodes(tree))
    817865                return false;
    818866
    819867        /* Find suitable driver and start it. */
    820         return assign_driver(tree->root_node, drivers_list, tree);
     868        return assign_driver(tree->root_node->child, drivers_list, tree);
    821869}
    822870
     
    827875 * @return              A device node structure.
    828876 */
    829 node_t *create_dev_node(void)
    830 {
    831         node_t *res = malloc(sizeof(node_t));
     877dev_node_t *create_dev_node(void)
     878{
     879        dev_node_t *res = malloc(sizeof(dev_node_t));
    832880       
    833881        if (res != NULL) {
    834                 memset(res, 0, sizeof(node_t));
    835                 list_initialize(&res->children);
    836                 list_initialize(&res->match_ids.ids);
    837                 list_initialize(&res->classes);
     882                memset(res, 0, sizeof(dev_node_t));
     883                list_initialize(&res->functions);
     884                link_initialize(&res->driver_devices);
     885                link_initialize(&res->devman_dev);
    838886        }
    839887       
     
    845893 * @param node          The device node structure.
    846894 */
    847 void delete_dev_node(node_t *node)
    848 {
    849         assert(list_empty(&node->children));
    850         assert(node->parent == NULL);
    851         assert(node->drv == NULL);
    852        
    853         clean_match_ids(&node->match_ids);
    854         free_not_null(node->name);
    855         free_not_null(node->pathname);
    856         free(node);
     895void delete_dev_node(dev_node_t *dev)
     896{
     897        assert(list_empty(&dev->functions));
     898        assert(dev->pfun == NULL);
     899        assert(dev->drv == NULL);
     900       
     901        free(dev);
    857902}
    858903
    859904/** Find the device node structure of the device witch has the specified handle.
    860  *
    861  * Device tree's rwlock should be held at least for reading.
    862905 *
    863906 * @param tree          The device tree where we look for the device node.
     
    865908 * @return              The device node.
    866909 */
    867 node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
     910dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
    868911{
    869912        unsigned long key = handle;
    870         link_t *link = hash_table_find(&tree->devman_devices, &key);
    871         return hash_table_get_instance(link, node_t, devman_link);
     913        link_t *link;
     914       
     915        assert(fibril_rwlock_is_locked(&tree->rwlock));
     916       
     917        link = hash_table_find(&tree->devman_devices, &key);
     918        return hash_table_get_instance(link, dev_node_t, devman_dev);
    872919}
    873920
     
    878925 * @return              The device node.
    879926 */
    880 node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle)
    881 {
    882         node_t *node = NULL;
     927dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle)
     928{
     929        dev_node_t *dev = NULL;
    883930       
    884931        fibril_rwlock_read_lock(&tree->rwlock);
    885         node = find_dev_node_no_lock(tree, handle);
     932        dev = find_dev_node_no_lock(tree, handle);
    886933        fibril_rwlock_read_unlock(&tree->rwlock);
    887934       
    888         return node;
    889 }
    890 
     935        return dev;
     936}
     937
     938/* Function nodes */
     939
     940/** Create a new function node.
     941 *
     942 * @return              A function node structure.
     943 */
     944fun_node_t *create_fun_node(void)
     945{
     946        fun_node_t *res = malloc(sizeof(fun_node_t));
     947       
     948        if (res != NULL) {
     949                memset(res, 0, sizeof(fun_node_t));
     950                link_initialize(&res->dev_functions);
     951                list_initialize(&res->match_ids.ids);
     952                list_initialize(&res->classes);
     953                link_initialize(&res->devman_fun);
     954                link_initialize(&res->devmap_fun);
     955        }
     956       
     957        return res;
     958}
     959
     960/** Delete a function node.
     961 *
     962 * @param fun           The device node structure.
     963 */
     964void delete_fun_node(fun_node_t *fun)
     965{
     966        assert(fun->dev == NULL);
     967        assert(fun->child == NULL);
     968       
     969        clean_match_ids(&fun->match_ids);
     970        free_not_null(fun->name);
     971        free_not_null(fun->pathname);
     972        free(fun);
     973}
     974
     975/** Find the function node with the specified handle.
     976 *
     977 * @param tree          The device tree where we look for the device node.
     978 * @param handle        The handle of the function.
     979 * @return              The function node.
     980 */
     981fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
     982{
     983        unsigned long key = handle;
     984        link_t *link;
     985       
     986        assert(fibril_rwlock_is_locked(&tree->rwlock));
     987       
     988        link = hash_table_find(&tree->devman_functions, &key);
     989        if (link == NULL)
     990                return NULL;
     991       
     992        return hash_table_get_instance(link, fun_node_t, devman_fun);
     993}
     994
     995/** Find the function node with the specified handle.
     996 *
     997 * @param tree          The device tree where we look for the device node.
     998 * @param handle        The handle of the function.
     999 * @return              The function node.
     1000 */
     1001fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle)
     1002{
     1003        fun_node_t *fun = NULL;
     1004       
     1005        fibril_rwlock_read_lock(&tree->rwlock);
     1006        fun = find_fun_node_no_lock(tree, handle);
     1007        fibril_rwlock_read_unlock(&tree->rwlock);
     1008       
     1009        return fun;
     1010}
    8911011
    8921012/** Create and set device's full path in device tree.
     
    8971017 *                      resources etc.).
    8981018 */
    899 static bool set_dev_path(node_t *node, node_t *parent)
    900 {
    901         assert(node->name != NULL);
    902        
    903         size_t pathsize = (str_size(node->name) + 1);
     1019static bool set_fun_path(fun_node_t *fun, fun_node_t *parent)
     1020{
     1021        assert(fun->name != NULL);
     1022       
     1023        size_t pathsize = (str_size(fun->name) + 1);
    9041024        if (parent != NULL)
    9051025                pathsize += str_size(parent->pathname) + 1;
    9061026       
    907         node->pathname = (char *) malloc(pathsize);
    908         if (node->pathname == NULL) {
     1027        fun->pathname = (char *) malloc(pathsize);
     1028        if (fun->pathname == NULL) {
    9091029                printf(NAME ": failed to allocate device path.\n");
    9101030                return false;
     
    9121032       
    9131033        if (parent != NULL) {
    914                 str_cpy(node->pathname, pathsize, parent->pathname);
    915                 str_append(node->pathname, pathsize, "/");
    916                 str_append(node->pathname, pathsize, node->name);
     1034                str_cpy(fun->pathname, pathsize, parent->pathname);
     1035                str_append(fun->pathname, pathsize, "/");
     1036                str_append(fun->pathname, pathsize, fun->name);
    9171037        } else {
    918                 str_cpy(node->pathname, pathsize, node->name);
     1038                str_cpy(fun->pathname, pathsize, fun->name);
    9191039        }
    9201040       
     
    9231043
    9241044/** Insert new device into device tree.
    925  *
    926  * The device tree's rwlock should be already held exclusively when calling this
    927  * function.
    9281045 *
    9291046 * @param tree          The device tree.
     
    9351052 *                      etc.).
    9361053 */
    937 bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name,
    938     node_t *parent)
    939 {
    940         assert(node != NULL);
     1054bool insert_dev_node(dev_tree_t *tree, dev_node_t *dev, fun_node_t *pfun)
     1055{
     1056        assert(dev != NULL);
    9411057        assert(tree != NULL);
    942         assert(dev_name != NULL);
    943        
    944         node->name = dev_name;
    945         if (!set_dev_path(node, parent)) {
     1058        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
     1059       
     1060        /* Add the node to the handle-to-node map. */
     1061        dev->handle = ++tree->current_handle;
     1062        unsigned long key = dev->handle;
     1063        hash_table_insert(&tree->devman_devices, &key, &dev->devman_dev);
     1064
     1065        /* Add the node to the list of its parent's children. */
     1066        printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);
     1067        dev->pfun = pfun;
     1068        pfun->child = dev;
     1069       
     1070        return true;
     1071}
     1072
     1073/** Insert new function into device tree.
     1074 *
     1075 * @param tree          The device tree.
     1076 * @param node          The newly added function node.
     1077 * @param dev_name      The name of the newly added function.
     1078 * @param parent        Owning device node.
     1079 *
     1080 * @return              True on success, false otherwise (insufficient resources
     1081 *                      etc.).
     1082 */
     1083bool insert_fun_node(dev_tree_t *tree, fun_node_t *fun, char *fun_name,
     1084    dev_node_t *dev)
     1085{
     1086        fun_node_t *pfun;
     1087       
     1088        assert(fun != NULL);
     1089        assert(tree != NULL);
     1090        assert(fun_name != NULL);
     1091        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
     1092       
     1093        /*
     1094         * The root function is a special case, it does not belong to any
     1095         * device so for the root function dev == NULL.
     1096         */
     1097        pfun = (dev != NULL) ? dev->pfun : NULL;
     1098       
     1099        fun->name = fun_name;
     1100        if (!set_fun_path(fun, pfun)) {
    9461101                return false;
    9471102        }
    9481103       
    9491104        /* Add the node to the handle-to-node map. */
    950         node->handle = ++tree->current_handle;
    951         unsigned long key = node->handle;
    952         hash_table_insert(&tree->devman_devices, &key, &node->devman_link);
     1105        fun->handle = ++tree->current_handle;
     1106        unsigned long key = fun->handle;
     1107        hash_table_insert(&tree->devman_functions, &key, &fun->devman_fun);
    9531108
    9541109        /* Add the node to the list of its parent's children. */
    955         node->parent = parent;
    956         if (parent != NULL)
    957                 list_append(&node->sibling, &parent->children);
     1110        fun->dev = dev;
     1111        if (dev != NULL)
     1112                list_append(&fun->dev_functions, &dev->functions);
    9581113       
    9591114        return true;
    9601115}
    9611116
    962 /** Find device node with a specified path in the device tree.
     1117/** Find function node with a specified path in the device tree.
    9631118 *
    964  * @param path          The path of the device node in the device tree.
     1119 * @param path          The path of the function node in the device tree.
    9651120 * @param tree          The device tree.
    966  * @return              The device node if it is present in the tree, NULL
     1121 * @return              The function node if it is present in the tree, NULL
    9671122 *                      otherwise.
    9681123 */
    969 node_t *find_dev_node_by_path(dev_tree_t *tree, char *path)
    970 {
     1124fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path)
     1125{
     1126        assert(path != NULL);
     1127
     1128        bool is_absolute = path[0] == '/';
     1129        if (!is_absolute) {
     1130                return NULL;
     1131        }
     1132
    9711133        fibril_rwlock_read_lock(&tree->rwlock);
    9721134       
    973         node_t *dev = tree->root_node;
     1135        fun_node_t *fun = tree->root_node;
    9741136        /*
    975          * 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
    9761138         * beginning)
    9771139         */
    9781140        char *rel_path = path;
    9791141        char *next_path_elem = NULL;
    980         bool cont = (rel_path[0] == '/');
    981        
    982         while (cont && dev != NULL) {
     1142        bool cont = true;
     1143       
     1144        while (cont && fun != NULL) {
    9831145                next_path_elem  = get_path_elem_end(rel_path + 1);
    9841146                if (next_path_elem[0] == '/') {
     
    9891151                }
    9901152               
    991                 dev = find_node_child(dev, rel_path + 1);
     1153                fun = find_node_child(fun, rel_path + 1);
    9921154               
    9931155                if (cont) {
     
    10001162        fibril_rwlock_read_unlock(&tree->rwlock);
    10011163       
    1002         return dev;
    1003 }
    1004 
    1005 /** Find child device node with a specified name.
     1164        return fun;
     1165}
     1166
     1167/** Find child function node with a specified name.
    10061168 *
    10071169 * Device tree rwlock should be held at least for reading.
    10081170 *
    1009  * @param parent        The parent device node.
    1010  * @param name          The name of the child device node.
    1011  * @return              The child device node.
    1012  */
    1013 node_t *find_node_child(node_t *parent, const char *name)
    1014 {
    1015         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;
    10161178        link_t *link;
    10171179       
    1018         link = parent->children.next;
    1019        
    1020         while (link != &parent->children) {
    1021                 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);
    10221184               
    1023                 if (str_cmp(name, dev->name) == 0)
    1024                         return dev;
     1185                if (str_cmp(name, fun->name) == 0)
     1186                        return fun;
    10251187               
    10261188                link = link->next;
     
    10611223        if (info != NULL) {
    10621224                memset(info, 0, sizeof(dev_class_info_t));
    1063                 list_initialize(&info->dev_classes);
    1064                 list_initialize(&info->devmap_link);
    1065                 list_initialize(&info->link);
     1225                link_initialize(&info->dev_classes);
     1226                link_initialize(&info->devmap_link);
     1227                link_initialize(&info->link);
    10661228        }
    10671229       
     
    11051267}
    11061268
    1107 /** Add the device to the class.
     1269/** Add the device function to the class.
    11081270 *
    11091271 * The device may be added to multiple classes and a class may contain multiple
     
    11181280 *                      with the class.
    11191281 */
    1120 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,
    11211283    const char *base_dev_name)
    11221284{
    1123         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
    11241292       
    11251293        if (info != NULL) {
    11261294                info->dev_class = cl;
    1127                 info->dev = dev;
     1295                info->fun = fun;
    11281296               
    11291297                /* Add the device to the class. */
     
    11331301               
    11341302                /* Add the class to the device. */
    1135                 list_append(&info->dev_classes, &dev->classes);
     1303                list_append(&info->dev_classes, &fun->classes);
    11361304               
    11371305                /* Create unique name for the device within the class. */
     
    11871355        list_initialize(&class_list->classes);
    11881356        fibril_rwlock_initialize(&class_list->rwlock);
    1189         hash_table_create(&class_list->devmap_devices, DEVICE_BUCKETS, 1,
     1357        hash_table_create(&class_list->devmap_functions, DEVICE_BUCKETS, 1,
    11901358            &devmap_devices_class_ops);
    11911359}
     
    11941362/* Devmap devices */
    11951363
    1196 node_t *find_devmap_tree_device(dev_tree_t *tree, devmap_handle_t devmap_handle)
    1197 {
    1198         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;
    11991367        link_t *link;
    12001368        unsigned long key = (unsigned long) devmap_handle;
    12011369       
    12021370        fibril_rwlock_read_lock(&tree->rwlock);
    1203         link = hash_table_find(&tree->devmap_devices, &key);
     1371        link = hash_table_find(&tree->devmap_functions, &key);
    12041372        if (link != NULL)
    1205                 dev = hash_table_get_instance(link, node_t, devmap_link);
     1373                fun = hash_table_get_instance(link, fun_node_t, devmap_fun);
    12061374        fibril_rwlock_read_unlock(&tree->rwlock);
    12071375       
    1208         return dev;
    1209 }
    1210 
    1211 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,
    12121380    devmap_handle_t devmap_handle)
    12131381{
    1214         node_t *dev = NULL;
     1382        fun_node_t *fun = NULL;
    12151383        dev_class_info_t *cli;
    12161384        link_t *link;
     
    12181386       
    12191387        fibril_rwlock_read_lock(&classes->rwlock);
    1220         link = hash_table_find(&classes->devmap_devices, &key);
     1388        link = hash_table_find(&classes->devmap_functions, &key);
    12211389        if (link != NULL) {
    12221390                cli = hash_table_get_instance(link, dev_class_info_t,
    12231391                    devmap_link);
    1224                 dev = cli->dev;
     1392                fun = cli->fun;
    12251393        }
    12261394        fibril_rwlock_read_unlock(&classes->rwlock);
    12271395       
    1228         return dev;
    1229 }
    1230 
    1231 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)
    12321400{
    12331401        unsigned long key = (unsigned long) cli->devmap_handle;
    12341402       
    12351403        fibril_rwlock_write_lock(&class_list->rwlock);
    1236         hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
     1404        hash_table_insert(&class_list->devmap_functions, &key, &cli->devmap_link);
    12371405        fibril_rwlock_write_unlock(&class_list->rwlock);
    12381406
    1239         assert(find_devmap_class_device(class_list, cli->devmap_handle) != NULL);
    1240 }
    1241 
    1242 void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
    1243 {
    1244         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;
    12451413        fibril_rwlock_write_lock(&tree->rwlock);
    1246         hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
     1414        hash_table_insert(&tree->devmap_functions, &key, &fun->devmap_fun);
    12471415        fibril_rwlock_write_unlock(&tree->rwlock);
    12481416}
Note: See TracChangeset for help on using the changeset viewer.