Ignore:
File:
1 edited

Legend:

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

    rdf147c7 r3ca3430  
    4141#include "devman.h"
    4242
    43 fun_node_t *find_node_child(fun_node_t *parent, const char *name);
    44 
    4543/* hash table operations */
    4644
     
    5351    link_t *item)
    5452{
    55         dev_node_t *dev = hash_table_get_instance(item, dev_node_t, devman_dev);
     53        node_t *dev = hash_table_get_instance(item, node_t, devman_link);
    5654        return (dev->handle == (devman_handle_t) key[0]);
    5755}
    5856
    59 static int devman_functions_compare(unsigned long key[], hash_count_t keys,
     57static int devmap_devices_compare(unsigned long key[], hash_count_t keys,
    6058    link_t *item)
    6159{
    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 
    66 static 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]);
     60        node_t *dev = hash_table_get_instance(item, node_t, devmap_link);
     61        return (dev->devmap_handle == (devmap_handle_t) key[0]);
    7162}
    7263
     
    9182};
    9283
    93 static hash_table_operations_t devman_functions_ops = {
    94         .hash = devices_hash,
    95         .compare = devman_functions_compare,
    96         .remove_callback = devices_remove_callback
    97 };
    98 
    9984static hash_table_operations_t devmap_devices_ops = {
    10085        .hash = devices_hash,
    101         .compare = devmap_functions_compare,
     86        .compare = devmap_devices_compare,
    10287        .remove_callback = devices_remove_callback
    10388};
     
    266251        }
    267252       
    268         ssize_t read_bytes = safe_read(fd, buf, len);
    269         if (read_bytes <= 0) {
     253        if (read(fd, buf, len) <= 0) {
    270254                printf(NAME ": unable to read file '%s'.\n", conf_path);
    271255                goto cleanup;
    272256        }
    273         buf[read_bytes] = 0;
     257        buf[len] = 0;
    274258       
    275259        suc = parse_match_ids(buf, ids);
     
    389373}
    390374
    391 /** Create root device and function node in the device tree.
     375/** Create root device node in the device tree.
    392376 *
    393377 * @param tree  The device tree.
    394378 * @return      True on success, false otherwise.
    395379 */
    396 bool 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;
     380bool 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;
    439397}
    440398
     
    454412 *                      is found.
    455413 */
    456 driver_t *find_best_match_driver(driver_list_t *drivers_list, dev_node_t *node)
     414driver_t *find_best_match_driver(driver_list_t *drivers_list, node_t *node)
    457415{
    458416        driver_t *best_drv = NULL, *drv = NULL;
     
    482440 * @param drv           The driver.
    483441 */
    484 void attach_driver(dev_node_t *dev, driver_t *drv)
     442void attach_driver(node_t *node, driver_t *drv)
    485443{
    486444        printf(NAME ": attach_driver %s to device %s\n",
    487             drv->name, dev->pfun->pathname);
     445            drv->name, node->pathname);
    488446       
    489447        fibril_mutex_lock(&drv->driver_mutex);
    490448       
    491         dev->drv = drv;
    492         list_append(&dev->driver_devices, &drv->devices);
     449        node->drv = drv;
     450        list_append(&node->driver_devices, &drv->devices);
    493451       
    494452        fibril_mutex_unlock(&drv->driver_mutex);
     
    496454
    497455/** Start a driver
     456 *
     457 * The driver's mutex is assumed to be locked.
    498458 *
    499459 * @param drv           The driver's structure.
     
    505465        int rc;
    506466
    507         assert(fibril_mutex_is_locked(&drv->driver_mutex));
    508        
    509467        printf(NAME ": start_driver '%s'\n", drv->name);
    510468       
     
    570528static void pass_devices_to_driver(driver_t *driver, dev_tree_t *tree)
    571529{
    572         dev_node_t *dev;
     530        node_t *dev;
    573531        link_t *link;
    574532        int phone;
     
    591549        link = driver->devices.next;
    592550        while (link != &driver->devices) {
    593                 dev = list_get_instance(link, dev_node_t, driver_devices);
     551                dev = list_get_instance(link, node_t, driver_devices);
    594552                if (dev->passed_to_driver) {
    595553                        link = link->next;
     
    630588        }
    631589
    632         async_hangup(phone);
     590        ipc_hangup(phone);
    633591
    634592        /*
     
    709667}
    710668
    711 /** Create devmap path and name for the function. */
    712 void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)
     669/** Create devmap path and name for the device. */
     670static void devmap_register_tree_device(node_t *node, dev_tree_t *tree)
    713671{
    714672        char *devmap_pathname = NULL;
    715673        char *devmap_name = NULL;
    716674       
    717         asprintf(&devmap_name, "%s", fun->pathname);
     675        asprintf(&devmap_name, "%s", node->pathname);
    718676        if (devmap_name == NULL)
    719677                return;
     
    729687       
    730688        devmap_device_register_with_iface(devmap_pathname,
    731             &fun->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
    732        
    733         tree_add_devmap_function(tree, fun);
     689            &node->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
     690       
     691        tree_add_devmap_device(tree, node);
    734692       
    735693        free(devmap_name);
     
    742700 * @param node          The device's node in the device tree.
    743701 */
    744 void add_device(int phone, driver_t *drv, dev_node_t *dev, dev_tree_t *tree)
     702void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree)
    745703{
    746704        /*
     
    749707         */
    750708        printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
    751             dev->pfun->name);
     709            node->name);
    752710       
    753711        sysarg_t rc;
     
    756714        /* Send the device to the driver. */
    757715        devman_handle_t parent_handle;
    758         if (dev->pfun) {
    759                 parent_handle = dev->pfun->handle;
     716        if (node->parent) {
     717                parent_handle = node->parent->handle;
    760718        } else {
    761719                parent_handle = 0;
    762720        }
    763721
    764         aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, dev->handle,
     722        aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle,
    765723            parent_handle, &answer);
    766724       
    767725        /* Send the device's name to the driver. */
    768         rc = async_data_write_start(phone, dev->pfun->name,
    769             str_size(dev->pfun->name) + 1);
     726        rc = async_data_write_start(phone, node->name,
     727            str_size(node->name) + 1);
    770728        if (rc != EOK) {
    771729                /* TODO handle error */
     
    777735        switch(rc) {
    778736        case EOK:
    779                 dev->state = DEVICE_USABLE;
     737                node->state = DEVICE_USABLE;
     738                devmap_register_tree_device(node, tree);
    780739                break;
    781740        case ENOENT:
    782                 dev->state = DEVICE_NOT_PRESENT;
     741                node->state = DEVICE_NOT_PRESENT;
    783742                break;
    784743        default:
    785                 dev->state = DEVICE_INVALID;
    786         }
    787        
    788         dev->passed_to_driver = true;
     744                node->state = DEVICE_INVALID;
     745        }
     746       
     747        node->passed_to_driver = true;
    789748
    790749        return;
     
    798757 *                      successfully assigned to the device, false otherwise.
    799758 */
    800 bool 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        
     759bool assign_driver(node_t *node, driver_list_t *drivers_list, dev_tree_t *tree)
     760{
    807761        /*
    808762         * Find the driver which is the most suitable for handling this device.
    809763         */
    810         driver_t *drv = find_best_match_driver(drivers_list, dev);
     764        driver_t *drv = find_best_match_driver(drivers_list, node);
    811765        if (drv == NULL) {
    812766                printf(NAME ": no driver found for device '%s'.\n",
    813                     dev->pfun->pathname);
     767                    node->pathname);
    814768                return false;
    815769        }
    816770       
    817771        /* Attach the driver to the device. */
    818         attach_driver(dev, drv);
     772        attach_driver(node, drv);
    819773       
    820774        fibril_mutex_lock(&drv->driver_mutex);
     
    829783                /* Notify the driver about the new device. */
    830784                int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
    831                 if (phone >= 0) {
    832                         add_device(phone, drv, dev, tree);
    833                         async_hangup(phone);
     785                if (phone > 0) {
     786                        add_device(phone, drv, node, tree);
     787                        ipc_hangup(phone);
    834788                }
    835789        }
     
    854808        hash_table_create(&tree->devman_devices, DEVICE_BUCKETS, 1,
    855809            &devman_devices_ops);
    856         hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1,
    857             &devman_functions_ops);
    858         hash_table_create(&tree->devmap_functions, DEVICE_BUCKETS, 1,
     810        hash_table_create(&tree->devmap_devices, DEVICE_BUCKETS, 1,
    859811            &devmap_devices_ops);
    860812       
    861813        fibril_rwlock_initialize(&tree->rwlock);
    862814       
    863         /* Create root function and root device and add them to the device tree. */
    864         if (!create_root_nodes(tree))
     815        /* Create root node and add it to the device tree. */
     816        if (!create_root_node(tree))
    865817                return false;
    866818
    867819        /* Find suitable driver and start it. */
    868         return assign_driver(tree->root_node->child, drivers_list, tree);
     820        return assign_driver(tree->root_node, drivers_list, tree);
    869821}
    870822
     
    875827 * @return              A device node structure.
    876828 */
    877 dev_node_t *create_dev_node(void)
    878 {
    879         dev_node_t *res = malloc(sizeof(dev_node_t));
     829node_t *create_dev_node(void)
     830{
     831        node_t *res = malloc(sizeof(node_t));
    880832       
    881833        if (res != NULL) {
    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);
     834                memset(res, 0, sizeof(node_t));
     835                list_initialize(&res->children);
     836                list_initialize(&res->match_ids.ids);
     837                list_initialize(&res->classes);
    886838        }
    887839       
     
    893845 * @param node          The device node structure.
    894846 */
    895 void 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);
     847void 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);
    902857}
    903858
    904859/** 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.
    905862 *
    906863 * @param tree          The device tree where we look for the device node.
     
    908865 * @return              The device node.
    909866 */
    910 dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
     867node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
    911868{
    912869        unsigned long key = handle;
    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);
     870        link_t *link = hash_table_find(&tree->devman_devices, &key);
     871        return hash_table_get_instance(link, node_t, devman_link);
    919872}
    920873
     
    925878 * @return              The device node.
    926879 */
    927 dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle)
    928 {
    929         dev_node_t *dev = NULL;
     880node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle)
     881{
     882        node_t *node = NULL;
    930883       
    931884        fibril_rwlock_read_lock(&tree->rwlock);
    932         dev = find_dev_node_no_lock(tree, handle);
     885        node = find_dev_node_no_lock(tree, handle);
    933886        fibril_rwlock_read_unlock(&tree->rwlock);
    934887       
    935         return dev;
    936 }
    937 
    938 /* Function nodes */
    939 
    940 /** Create a new function node.
    941  *
    942  * @return              A function node structure.
    943  */
    944 fun_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  */
    964 void 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  */
    981 fun_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  */
    1001 fun_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 }
     888        return node;
     889}
     890
    1011891
    1012892/** Create and set device's full path in device tree.
     
    1017897 *                      resources etc.).
    1018898 */
    1019 static 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);
     899static 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);
    1024904        if (parent != NULL)
    1025905                pathsize += str_size(parent->pathname) + 1;
    1026906       
    1027         fun->pathname = (char *) malloc(pathsize);
    1028         if (fun->pathname == NULL) {
     907        node->pathname = (char *) malloc(pathsize);
     908        if (node->pathname == NULL) {
    1029909                printf(NAME ": failed to allocate device path.\n");
    1030910                return false;
     
    1032912       
    1033913        if (parent != NULL) {
    1034                 str_cpy(fun->pathname, pathsize, parent->pathname);
    1035                 str_append(fun->pathname, pathsize, "/");
    1036                 str_append(fun->pathname, pathsize, fun->name);
     914                str_cpy(node->pathname, pathsize, parent->pathname);
     915                str_append(node->pathname, pathsize, "/");
     916                str_append(node->pathname, pathsize, node->name);
    1037917        } else {
    1038                 str_cpy(fun->pathname, pathsize, fun->name);
     918                str_cpy(node->pathname, pathsize, node->name);
    1039919        }
    1040920       
     
    1043923
    1044924/** Insert new device into device tree.
     925 *
     926 * The device tree's rwlock should be already held exclusively when calling this
     927 * function.
    1045928 *
    1046929 * @param tree          The device tree.
     
    1052935 *                      etc.).
    1053936 */
    1054 bool insert_dev_node(dev_tree_t *tree, dev_node_t *dev, fun_node_t *pfun)
    1055 {
    1056         assert(dev != NULL);
     937bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name,
     938    node_t *parent)
     939{
     940        assert(node != NULL);
    1057941        assert(tree != NULL);
    1058         assert(fibril_rwlock_is_write_locked(&tree->rwlock));
     942        assert(dev_name != NULL);
     943       
     944        node->name = dev_name;
     945        if (!set_dev_path(node, parent)) {
     946                return false;
     947        }
    1059948       
    1060949        /* 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);
     950        node->handle = ++tree->current_handle;
     951        unsigned long key = node->handle;
     952        hash_table_insert(&tree->devman_devices, &key, &node->devman_link);
    1064953
    1065954        /* 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;
     955        node->parent = parent;
     956        if (parent != NULL)
     957                list_append(&node->sibling, &parent->children);
    1069958       
    1070959        return true;
    1071960}
    1072961
    1073 /** Insert new function into device tree.
    1074  *
     962/** Find device node with a specified path in the device tree.
     963 *
     964 * @param path          The path of the device node in the device tree.
    1075965 * @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  */
    1083 bool 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        
     966 * @return              The device node if it is present in the tree, NULL
     967 *                      otherwise.
     968 */
     969node_t *find_dev_node_by_path(dev_tree_t *tree, char *path)
     970{
     971        fibril_rwlock_read_lock(&tree->rwlock);
     972       
     973        node_t *dev = tree->root_node;
    1093974        /*
    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)) {
    1101                 return false;
    1102         }
    1103        
    1104         /* Add the node to the handle-to-node map. */
    1105         fun->handle = ++tree->current_handle;
    1106         unsigned long key = fun->handle;
    1107         hash_table_insert(&tree->devman_functions, &key, &fun->devman_fun);
    1108 
    1109         /* Add the node to the list of its parent's children. */
    1110         fun->dev = dev;
    1111         if (dev != NULL)
    1112                 list_append(&fun->dev_functions, &dev->functions);
    1113        
    1114         return true;
    1115 }
    1116 
    1117 /** Find function node with a specified path in the device tree.
    1118  *
    1119  * @param path          The path of the function node in the device tree.
    1120  * @param tree          The device tree.
    1121  * @return              The function node if it is present in the tree, NULL
    1122  *                      otherwise.
    1123  */
    1124 fun_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 
    1133         fibril_rwlock_read_lock(&tree->rwlock);
    1134        
    1135         fun_node_t *fun = tree->root_node;
    1136         /*
    1137          * Relative path to the function from its parent (but with '/' at the
     975         * Relative path to the device from its parent (but with '/' at the
    1138976         * beginning)
    1139977         */
    1140978        char *rel_path = path;
    1141979        char *next_path_elem = NULL;
    1142         bool cont = true;
    1143        
    1144         while (cont && fun != NULL) {
     980        bool cont = (rel_path[0] == '/');
     981       
     982        while (cont && dev != NULL) {
    1145983                next_path_elem  = get_path_elem_end(rel_path + 1);
    1146984                if (next_path_elem[0] == '/') {
     
    1151989                }
    1152990               
    1153                 fun = find_node_child(fun, rel_path + 1);
     991                dev = find_node_child(dev, rel_path + 1);
    1154992               
    1155993                if (cont) {
     
    11621000        fibril_rwlock_read_unlock(&tree->rwlock);
    11631001       
    1164         return fun;
    1165 }
    1166 
    1167 /** Find child function node with a specified name.
     1002        return dev;
     1003}
     1004
     1005/** Find child device node with a specified name.
    11681006 *
    11691007 * Device tree rwlock should be held at least for reading.
    11701008 *
    1171  * @param parent        The parent function node.
    1172  * @param name          The name of the child function.
    1173  * @return              The child function node.
    1174  */
    1175 fun_node_t *find_node_child(fun_node_t *pfun, const char *name)
    1176 {
    1177         fun_node_t *fun;
     1009 * @param parent        The parent device node.
     1010 * @param name          The name of the child device node.
     1011 * @return              The child device node.
     1012 */
     1013node_t *find_node_child(node_t *parent, const char *name)
     1014{
     1015        node_t *dev;
    11781016        link_t *link;
    11791017       
    1180         link = pfun->child->functions.next;
    1181        
    1182         while (link != &pfun->child->functions) {
    1183                 fun = list_get_instance(link, fun_node_t, dev_functions);
     1018        link = parent->children.next;
     1019       
     1020        while (link != &parent->children) {
     1021                dev = list_get_instance(link, node_t, sibling);
    11841022               
    1185                 if (str_cmp(name, fun->name) == 0)
    1186                         return fun;
     1023                if (str_cmp(name, dev->name) == 0)
     1024                        return dev;
    11871025               
    11881026                link = link->next;
     
    12231061        if (info != NULL) {
    12241062                memset(info, 0, sizeof(dev_class_info_t));
    1225                 link_initialize(&info->dev_classes);
    1226                 link_initialize(&info->devmap_link);
    1227                 link_initialize(&info->link);
     1063                list_initialize(&info->dev_classes);
     1064                list_initialize(&info->devmap_link);
     1065                list_initialize(&info->link);
    12281066        }
    12291067       
     
    12671105}
    12681106
    1269 /** Add the device function to the class.
     1107/** Add the device to the class.
    12701108 *
    12711109 * The device may be added to multiple classes and a class may contain multiple
     
    12801118 *                      with the class.
    12811119 */
    1282 dev_class_info_t *add_function_to_class(fun_node_t *fun, dev_class_t *cl,
     1120dev_class_info_t *add_device_to_class(node_t *dev, dev_class_t *cl,
    12831121    const char *base_dev_name)
    12841122{
    1285         dev_class_info_t *info;
    1286 
    1287         assert(fun != NULL);
    1288         assert(cl != NULL);
    1289 
    1290         info = create_dev_class_info();
    1291 
     1123        dev_class_info_t *info = create_dev_class_info();
    12921124       
    12931125        if (info != NULL) {
    12941126                info->dev_class = cl;
    1295                 info->fun = fun;
     1127                info->dev = dev;
    12961128               
    12971129                /* Add the device to the class. */
     
    13011133               
    13021134                /* Add the class to the device. */
    1303                 list_append(&info->dev_classes, &fun->classes);
     1135                list_append(&info->dev_classes, &dev->classes);
    13041136               
    13051137                /* Create unique name for the device within the class. */
     
    13551187        list_initialize(&class_list->classes);
    13561188        fibril_rwlock_initialize(&class_list->rwlock);
    1357         hash_table_create(&class_list->devmap_functions, DEVICE_BUCKETS, 1,
     1189        hash_table_create(&class_list->devmap_devices, DEVICE_BUCKETS, 1,
    13581190            &devmap_devices_class_ops);
    13591191}
     
    13621194/* Devmap devices */
    13631195
    1364 fun_node_t *find_devmap_tree_function(dev_tree_t *tree, devmap_handle_t devmap_handle)
    1365 {
    1366         fun_node_t *fun = NULL;
     1196node_t *find_devmap_tree_device(dev_tree_t *tree, devmap_handle_t devmap_handle)
     1197{
     1198        node_t *dev = NULL;
    13671199        link_t *link;
    13681200        unsigned long key = (unsigned long) devmap_handle;
    13691201       
    13701202        fibril_rwlock_read_lock(&tree->rwlock);
    1371         link = hash_table_find(&tree->devmap_functions, &key);
     1203        link = hash_table_find(&tree->devmap_devices, &key);
    13721204        if (link != NULL)
    1373                 fun = hash_table_get_instance(link, fun_node_t, devmap_fun);
     1205                dev = hash_table_get_instance(link, node_t, devmap_link);
    13741206        fibril_rwlock_read_unlock(&tree->rwlock);
    13751207       
    1376         return fun;
    1377 }
    1378 
    1379 fun_node_t *find_devmap_class_function(class_list_t *classes,
     1208        return dev;
     1209}
     1210
     1211node_t *find_devmap_class_device(class_list_t *classes,
    13801212    devmap_handle_t devmap_handle)
    13811213{
    1382         fun_node_t *fun = NULL;
     1214        node_t *dev = NULL;
    13831215        dev_class_info_t *cli;
    13841216        link_t *link;
     
    13861218       
    13871219        fibril_rwlock_read_lock(&classes->rwlock);
    1388         link = hash_table_find(&classes->devmap_functions, &key);
     1220        link = hash_table_find(&classes->devmap_devices, &key);
    13891221        if (link != NULL) {
    13901222                cli = hash_table_get_instance(link, dev_class_info_t,
    13911223                    devmap_link);
    1392                 fun = cli->fun;
     1224                dev = cli->dev;
    13931225        }
    13941226        fibril_rwlock_read_unlock(&classes->rwlock);
    13951227       
    1396         return fun;
    1397 }
    1398 
    1399 void class_add_devmap_function(class_list_t *class_list, dev_class_info_t *cli)
     1228        return dev;
     1229}
     1230
     1231void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
    14001232{
    14011233        unsigned long key = (unsigned long) cli->devmap_handle;
    14021234       
    14031235        fibril_rwlock_write_lock(&class_list->rwlock);
    1404         hash_table_insert(&class_list->devmap_functions, &key, &cli->devmap_link);
     1236        hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
    14051237        fibril_rwlock_write_unlock(&class_list->rwlock);
    14061238
    1407         assert(find_devmap_class_function(class_list, cli->devmap_handle) != NULL);
    1408 }
    1409 
    1410 void tree_add_devmap_function(dev_tree_t *tree, fun_node_t *fun)
    1411 {
    1412         unsigned long key = (unsigned long) fun->devmap_handle;
     1239        assert(find_devmap_class_device(class_list, cli->devmap_handle) != NULL);
     1240}
     1241
     1242void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
     1243{
     1244        unsigned long key = (unsigned long) node->devmap_handle;
    14131245        fibril_rwlock_write_lock(&tree->rwlock);
    1414         hash_table_insert(&tree->devmap_functions, &key, &fun->devmap_fun);
     1246        hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
    14151247        fibril_rwlock_write_unlock(&tree->rwlock);
    14161248}
Note: See TracChangeset for help on using the changeset viewer.