Ignore:
File:
1 edited

Legend:

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

    r8b1e15ac r45059d6b  
    3434#include <fcntl.h>
    3535#include <sys/stat.h>
     36#include <io/log.h>
    3637#include <ipc/driver.h>
    3738#include <ipc/devman.h>
    38 #include <devmap.h>
     39#include <loc.h>
    3940#include <str_error.h>
     41#include <stdio.h>
    4042
    4143#include "devman.h"
     
    6466}
    6567
    66 static int devmap_functions_compare(unsigned long key[], hash_count_t keys,
     68static int loc_functions_compare(unsigned long key[], hash_count_t keys,
    6769    link_t *item)
    6870{
    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]);
    71 }
    72 
    73 static int devmap_devices_class_compare(unsigned long key[], hash_count_t keys,
    74     link_t *item)
    75 {
    76         dev_class_info_t *class_info
    77             = hash_table_get_instance(item, dev_class_info_t, devmap_link);
    78         assert(class_info != NULL);
    79 
    80         return (class_info->devmap_handle == (devmap_handle_t) key[0]);
     71        fun_node_t *fun = hash_table_get_instance(item, fun_node_t, loc_fun);
     72        return (fun->service_id == (service_id_t) key[0]);
    8173}
    8274
     
    9789};
    9890
    99 static hash_table_operations_t devmap_devices_ops = {
     91static hash_table_operations_t loc_devices_ops = {
    10092        .hash = devices_hash,
    101         .compare = devmap_functions_compare,
    102         .remove_callback = devices_remove_callback
    103 };
    104 
    105 static hash_table_operations_t devmap_devices_class_ops = {
    106         .hash = devices_hash,
    107         .compare = devmap_devices_class_compare,
     93        .compare = loc_functions_compare,
    10894        .remove_callback = devices_remove_callback
    10995};
     
    146132        fibril_mutex_unlock(&drivers_list->drivers_mutex);
    147133
    148         printf(NAME": the '%s' driver was added to the list of available "
    149             "drivers.\n", drv->name);
     134        log_msg(LVL_NOTE, "Driver `%s' was added to the list of available "
     135            "drivers.", drv->name);
    150136}
    151137
     
    237223bool read_match_ids(const char *conf_path, match_id_list_t *ids)
    238224{
    239         printf(NAME ": read_match_ids conf_path = %s.\n", conf_path);
     225        log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);
    240226       
    241227        bool suc = false;
     
    247233        fd = open(conf_path, O_RDONLY);
    248234        if (fd < 0) {
    249                 printf(NAME ": unable to open %s\n", conf_path);
     235                log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.",
     236                    conf_path, str_error(fd));
    250237                goto cleanup;
    251238        }
     
    255242        lseek(fd, 0, SEEK_SET);
    256243        if (len == 0) {
    257                 printf(NAME ": configuration file '%s' is empty.\n", conf_path);
     244                log_msg(LVL_ERROR, "Configuration file '%s' is empty.",
     245                    conf_path);
    258246                goto cleanup;
    259247        }
     
    261249        buf = malloc(len + 1);
    262250        if (buf == NULL) {
    263                 printf(NAME ": memory allocation failed when parsing file "
    264                     "'%s'.\n", conf_path);
     251                log_msg(LVL_ERROR, "Memory allocation failed when parsing file "
     252                    "'%s'.", conf_path);
    265253                goto cleanup;
    266254        }
    267255       
    268         if (read(fd, buf, len) <= 0) {
    269                 printf(NAME ": unable to read file '%s'.\n", conf_path);
     256        ssize_t read_bytes = read_all(fd, buf, len);
     257        if (read_bytes <= 0) {
     258                log_msg(LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path,
     259                    read_bytes);
    270260                goto cleanup;
    271261        }
    272         buf[len] = 0;
     262        buf[read_bytes] = 0;
    273263       
    274264        suc = parse_match_ids(buf, ids);
     
    305295bool get_driver_info(const char *base_path, const char *name, driver_t *drv)
    306296{
    307         printf(NAME ": get_driver_info base_path = %s, name = %s.\n",
     297        log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")",
    308298            base_path, name);
    309299       
     
    337327        struct stat s;
    338328        if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */
    339                 printf(NAME ": driver not found at path %s.", drv->binary_path);
     329                log_msg(LVL_ERROR, "Driver not found at path `%s'.",
     330                    drv->binary_path);
    340331                goto cleanup;
    341332        }
     
    364355int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path)
    365356{
    366         printf(NAME ": lookup_available_drivers, dir = %s \n", dir_path);
     357        log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path);
    367358       
    368359        int drv_cnt = 0;
     
    398389        dev_node_t *dev;
    399390       
    400         printf(NAME ": create_root_nodes\n");
     391        log_msg(LVL_DEBUG, "create_root_nodes()");
    401392       
    402393        fibril_rwlock_write_lock(&tree->rwlock);
     
    415406        }
    416407       
    417         insert_fun_node(tree, fun, clone_string(""), NULL);
     408        insert_fun_node(tree, fun, str_dup(""), NULL);
    418409        match_id_t *id = create_match_id();
    419         id->id = clone_string("root");
     410        id->id = str_dup("root");
    420411        id->score = 100;
    421412        add_match_id(&fun->match_ids, id);
     
    460451        fibril_mutex_lock(&drivers_list->drivers_mutex);
    461452       
    462         link_t *link = drivers_list->drivers.next;
    463         while (link != &drivers_list->drivers) {
     453        list_foreach(drivers_list->drivers, link) {
    464454                drv = list_get_instance(link, driver_t, drivers);
    465455                score = get_match_score(drv, node);
     
    468458                        best_drv = drv;
    469459                }
    470                 link = link->next;
    471460        }
    472461       
     
    483472void attach_driver(dev_node_t *dev, driver_t *drv)
    484473{
    485         printf(NAME ": attach_driver %s to device %s\n",
    486             drv->name, dev->pfun->pathname);
     474        log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")",
     475            dev->pfun->pathname, drv->name);
    487476       
    488477        fibril_mutex_lock(&drv->driver_mutex);
     
    506495        assert(fibril_mutex_is_locked(&drv->driver_mutex));
    507496       
    508         printf(NAME ": start_driver '%s'\n", drv->name);
     497        log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);
    509498       
    510499        rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL);
    511500        if (rc != EOK) {
    512                 printf(NAME ": error spawning %s (%s)\n",
    513                     drv->name, str_error(rc));
     501                log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",
     502                    drv->name, drv->binary_path, str_error(rc));
    514503                return false;
    515504        }
     
    530519        driver_t *res = NULL;
    531520        driver_t *drv = NULL;
    532         link_t *link;
    533521       
    534522        fibril_mutex_lock(&drv_list->drivers_mutex);
    535523       
    536         link = drv_list->drivers.next;
    537         while (link != &drv_list->drivers) {
     524        list_foreach(drv_list->drivers, link) {
    538525                drv = list_get_instance(link, driver_t, drivers);
    539526                if (str_cmp(drv->name, drv_name) == 0) {
     
    541528                        break;
    542529                }
    543 
    544                 link = link->next;
    545530        }
    546531       
     
    548533       
    549534        return res;
    550 }
    551 
    552 /** Remember the driver's phone.
    553  *
    554  * @param driver        The driver.
    555  * @param phone         The phone to the driver.
    556  */
    557 void set_driver_phone(driver_t *driver, sysarg_t phone)
    558 {
    559         fibril_mutex_lock(&driver->driver_mutex);
    560         assert(driver->state == DRIVER_STARTING);
    561         driver->phone = phone;
    562         fibril_mutex_unlock(&driver->driver_mutex);
    563535}
    564536
     
    571543        dev_node_t *dev;
    572544        link_t *link;
    573         int phone;
    574 
    575         printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name);
     545
     546        log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")",
     547            driver->name);
    576548
    577549        fibril_mutex_lock(&driver->driver_mutex);
    578 
    579         phone = async_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0);
    580 
    581         if (phone < 0) {
    582                 fibril_mutex_unlock(&driver->driver_mutex);
    583                 return;
    584         }
    585550
    586551        /*
     
    588553         * that has not been passed to the driver.
    589554         */
    590         link = driver->devices.next;
    591         while (link != &driver->devices) {
     555        link = driver->devices.head.next;
     556        while (link != &driver->devices.head) {
    592557                dev = list_get_instance(link, dev_node_t, driver_devices);
    593558                if (dev->passed_to_driver) {
     
    608573                fibril_mutex_unlock(&driver->driver_mutex);
    609574
    610                 add_device(phone, driver, dev, tree);
     575                add_device(driver, dev, tree);
    611576
    612577                /*
     
    626591                 * Restart the cycle to go through all devices again.
    627592                 */
    628                 link = driver->devices.next;
    629         }
    630 
    631         async_hangup(phone);
     593                link = driver->devices.head.next;
     594        }
    632595
    633596        /*
     
    640603         * immediately and possibly started here as well.
    641604         */
    642         printf(NAME ": driver %s goes into running state.\n", driver->name);
     605        log_msg(LVL_DEBUG, "Driver `%s' enters running state.", driver->name);
    643606        driver->state = DRIVER_RUNNING;
    644607
     
    657620void initialize_running_driver(driver_t *driver, dev_tree_t *tree)
    658621{
    659         printf(NAME ": initialize_running_driver (`%s')\n", driver->name);
     622        log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")",
     623            driver->name);
    660624       
    661625        /*
     
    678642        list_initialize(&drv->devices);
    679643        fibril_mutex_initialize(&drv->driver_mutex);
     644        drv->sess = NULL;
    680645}
    681646
     
    708673}
    709674
    710 /** Create devmap path and name for the function. */
    711 void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)
    712 {
    713         char *devmap_pathname = NULL;
    714         char *devmap_name = NULL;
    715        
    716         asprintf(&devmap_name, "%s", fun->pathname);
    717         if (devmap_name == NULL)
     675/** Create loc path and name for the function. */
     676void loc_register_tree_function(fun_node_t *fun, dev_tree_t *tree)
     677{
     678        char *loc_pathname = NULL;
     679        char *loc_name = NULL;
     680       
     681        asprintf(&loc_name, "%s", fun->pathname);
     682        if (loc_name == NULL)
    718683                return;
    719684       
    720         replace_char(devmap_name, '/', DEVMAP_SEPARATOR);
    721        
    722         asprintf(&devmap_pathname, "%s/%s", DEVMAP_DEVICE_NAMESPACE,
    723             devmap_name);
    724         if (devmap_pathname == NULL) {
    725                 free(devmap_name);
     685        replace_char(loc_name, '/', LOC_SEPARATOR);
     686       
     687        asprintf(&loc_pathname, "%s/%s", LOC_DEVICE_NAMESPACE,
     688            loc_name);
     689        if (loc_pathname == NULL) {
     690                free(loc_name);
    726691                return;
    727692        }
    728693       
    729         devmap_device_register_with_iface(devmap_pathname,
    730             &fun->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
    731        
    732         tree_add_devmap_function(tree, fun);
    733        
    734         free(devmap_name);
    735         free(devmap_pathname);
     694        loc_service_register_with_iface(loc_pathname,
     695            &fun->service_id, DEVMAN_CONNECT_FROM_LOC);
     696       
     697        tree_add_loc_function(tree, fun);
     698       
     699        free(loc_name);
     700        free(loc_pathname);
    736701}
    737702
     
    741706 * @param node          The device's node in the device tree.
    742707 */
    743 void add_device(int phone, driver_t *drv, dev_node_t *dev, dev_tree_t *tree)
     708void add_device(driver_t *drv, dev_node_t *dev, dev_tree_t *tree)
    744709{
    745710        /*
     
    747712         * access any structures that would affect driver_t.
    748713         */
    749         printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
    750             dev->pfun->name);
    751        
    752         sysarg_t rc;
    753         ipc_call_t answer;
     714        log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")",
     715            drv->name, dev->pfun->name);
    754716       
    755717        /* Send the device to the driver. */
     
    760722                parent_handle = 0;
    761723        }
    762 
    763         aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, dev->handle,
     724       
     725        async_exch_t *exch = async_exchange_begin(drv->sess);
     726       
     727        ipc_call_t answer;
     728        aid_t req = async_send_2(exch, DRIVER_ADD_DEVICE, dev->handle,
    764729            parent_handle, &answer);
    765730       
    766         /* Send the device's name to the driver. */
    767         rc = async_data_write_start(phone, dev->pfun->name,
     731        /* Send the device name to the driver. */
     732        sysarg_t rc = async_data_write_start(exch, dev->pfun->name,
    768733            str_size(dev->pfun->name) + 1);
     734       
     735        async_exchange_end(exch);
     736       
    769737        if (rc != EOK) {
    770738                /* TODO handle error */
     
    809777        driver_t *drv = find_best_match_driver(drivers_list, dev);
    810778        if (drv == NULL) {
    811                 printf(NAME ": no driver found for device '%s'.\n",
     779                log_msg(LVL_ERROR, "No driver found for device `%s'.",
    812780                    dev->pfun->pathname);
    813781                return false;
     
    825793        fibril_mutex_unlock(&drv->driver_mutex);
    826794
    827         if (is_running) {
    828                 /* Notify the driver about the new device. */
    829                 int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
    830                 if (phone >= 0) {
    831                         add_device(phone, drv, dev, tree);
    832                         async_hangup(phone);
    833                 }
    834         }
     795        /* Notify the driver about the new device. */
     796        if (is_running)
     797                add_device(drv, dev, tree);
    835798       
    836799        return true;
     
    847810bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list)
    848811{
    849         printf(NAME ": init_device_tree.\n");
     812        log_msg(LVL_DEBUG, "init_device_tree()");
    850813       
    851814        tree->current_handle = 0;
     
    855818        hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1,
    856819            &devman_functions_ops);
    857         hash_table_create(&tree->devmap_functions, DEVICE_BUCKETS, 1,
    858             &devmap_devices_ops);
     820        hash_table_create(&tree->loc_functions, DEVICE_BUCKETS, 1,
     821            &loc_devices_ops);
    859822       
    860823        fibril_rwlock_initialize(&tree->rwlock);
     
    935898}
    936899
     900/** Get list of device functions. */
     901int dev_get_functions(dev_tree_t *tree, dev_node_t *dev,
     902    devman_handle_t *hdl_buf, size_t buf_size, size_t *act_size)
     903{
     904        size_t act_cnt;
     905        size_t buf_cnt;
     906
     907        assert(fibril_rwlock_is_locked(&tree->rwlock));
     908
     909        buf_cnt = buf_size / sizeof(devman_handle_t);
     910
     911        act_cnt = list_count(&dev->functions);
     912        *act_size = act_cnt * sizeof(devman_handle_t);
     913
     914        if (buf_size % sizeof(devman_handle_t) != 0)
     915                return EINVAL;
     916
     917        size_t pos = 0;
     918        list_foreach(dev->functions, item) {
     919                fun_node_t *fun =
     920                    list_get_instance(item, fun_node_t, dev_functions);
     921
     922                if (pos < buf_cnt)
     923                        hdl_buf[pos] = fun->handle;
     924                pos++;
     925        }
     926
     927        return EOK;
     928}
     929
     930
    937931/* Function nodes */
    938932
     
    949943                link_initialize(&res->dev_functions);
    950944                list_initialize(&res->match_ids.ids);
    951                 list_initialize(&res->classes);
    952945                link_initialize(&res->devman_fun);
    953                 link_initialize(&res->devmap_fun);
     946                link_initialize(&res->loc_fun);
    954947        }
    955948       
     
    10261019        fun->pathname = (char *) malloc(pathsize);
    10271020        if (fun->pathname == NULL) {
    1028                 printf(NAME ": failed to allocate device path.\n");
     1021                log_msg(LVL_ERROR, "Failed to allocate device path.");
    10291022                return false;
    10301023        }
     
    10571050        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    10581051       
     1052        log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])",
     1053            dev, pfun, pfun->pathname);
     1054
    10591055        /* Add the node to the handle-to-node map. */
    10601056        dev->handle = ++tree->current_handle;
     
    10631059
    10641060        /* Add the node to the list of its parent's children. */
    1065         printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);
    10661061        dev->pfun = pfun;
    10671062        pfun->child = dev;
     
    11121107       
    11131108        return true;
     1109}
     1110
     1111/** Remove function from device tree.
     1112 *
     1113 * @param tree          Device tree
     1114 * @param node          Function node to remove
     1115 */
     1116void remove_fun_node(dev_tree_t *tree, fun_node_t *fun)
     1117{
     1118        assert(tree != NULL);
     1119        assert(fun != NULL);
     1120        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
     1121       
     1122        /* Remove the node from the handle-to-node map. */
     1123        unsigned long key = fun->handle;
     1124        hash_table_remove(&tree->devman_functions, &key, 1);
     1125       
     1126        /* Remove the node from the list of its parent's children. */
     1127        if (fun->dev != NULL)
     1128                list_remove(&fun->dev_functions);
    11141129}
    11151130
     
    11231138fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path)
    11241139{
     1140        assert(path != NULL);
     1141
     1142        bool is_absolute = path[0] == '/';
     1143        if (!is_absolute) {
     1144                return NULL;
     1145        }
     1146
    11251147        fibril_rwlock_read_lock(&tree->rwlock);
    11261148       
     
    11321154        char *rel_path = path;
    11331155        char *next_path_elem = NULL;
    1134         bool cont = (rel_path[0] == '/');
     1156        bool cont = (rel_path[1] != '\0');
    11351157       
    11361158        while (cont && fun != NULL) {
     
    11571179}
    11581180
     1181/** Find function with a specified name belonging to given device.
     1182 *
     1183 * Device tree rwlock should be held at least for reading.
     1184 *
     1185 * @param dev Device the function belongs to.
     1186 * @param name Function name (not path).
     1187 * @return Function node.
     1188 * @retval NULL No function with given name.
     1189 */
     1190fun_node_t *find_fun_node_in_device(dev_node_t *dev, const char *name)
     1191{
     1192        assert(dev != NULL);
     1193        assert(name != NULL);
     1194
     1195        fun_node_t *fun;
     1196
     1197        list_foreach(dev->functions, link) {
     1198                fun = list_get_instance(link, fun_node_t, dev_functions);
     1199
     1200                if (str_cmp(name, fun->name) == 0)
     1201                        return fun;
     1202        }
     1203
     1204        return NULL;
     1205}
     1206
    11591207/** Find child function node with a specified name.
    11601208 *
     
    11671215fun_node_t *find_node_child(fun_node_t *pfun, const char *name)
    11681216{
    1169         fun_node_t *fun;
    1170         link_t *link;
    1171        
    1172         link = pfun->child->functions.next;
    1173        
    1174         while (link != &pfun->child->functions) {
    1175                 fun = list_get_instance(link, fun_node_t, dev_functions);
    1176                
    1177                 if (str_cmp(name, fun->name) == 0)
    1178                         return fun;
    1179                
    1180                 link = link->next;
    1181         }
    1182        
    1183         return NULL;
    1184 }
    1185 
    1186 /* Device classes */
    1187 
    1188 /** Create device class.
    1189  *
    1190  * @return      Device class.
    1191  */
    1192 dev_class_t *create_dev_class(void)
    1193 {
    1194         dev_class_t *cl;
    1195        
    1196         cl = (dev_class_t *) malloc(sizeof(dev_class_t));
    1197         if (cl != NULL) {
    1198                 memset(cl, 0, sizeof(dev_class_t));
    1199                 list_initialize(&cl->devices);
    1200                 fibril_mutex_initialize(&cl->mutex);
    1201         }
    1202        
    1203         return cl;
    1204 }
    1205 
    1206 /** Create device class info.
    1207  *
    1208  * @return              Device class info.
    1209  */
    1210 dev_class_info_t *create_dev_class_info(void)
    1211 {
    1212         dev_class_info_t *info;
    1213        
    1214         info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
    1215         if (info != NULL) {
    1216                 memset(info, 0, sizeof(dev_class_info_t));
    1217                 list_initialize(&info->dev_classes);
    1218                 list_initialize(&info->devmap_link);
    1219                 list_initialize(&info->link);
    1220         }
    1221        
    1222         return info;
    1223 }
    1224 
    1225 size_t get_new_class_dev_idx(dev_class_t *cl)
    1226 {
    1227         size_t dev_idx;
    1228        
    1229         fibril_mutex_lock(&cl->mutex);
    1230         dev_idx = ++cl->curr_dev_idx;
    1231         fibril_mutex_unlock(&cl->mutex);
    1232        
    1233         return dev_idx;
    1234 }
    1235 
    1236 
    1237 /** Create unique device name within the class.
    1238  *
    1239  * @param cl            The class.
    1240  * @param base_dev_name Contains the base name for the device if it was
    1241  *                      specified by the driver when it registered the device by
    1242  *                      the class; NULL if driver specified no base name.
    1243  * @return              The unique name for the device within the class.
    1244  */
    1245 char *create_dev_name_for_class(dev_class_t *cl, const char *base_dev_name)
    1246 {
    1247         char *dev_name;
    1248         const char *base_name;
    1249        
    1250         if (base_dev_name != NULL)
    1251                 base_name = base_dev_name;
    1252         else
    1253                 base_name = cl->base_dev_name;
    1254        
    1255         size_t idx = get_new_class_dev_idx(cl);
    1256         asprintf(&dev_name, "%s%zu", base_name, idx);
    1257        
    1258         return dev_name;
    1259 }
    1260 
    1261 /** Add the device function to the class.
    1262  *
    1263  * The device may be added to multiple classes and a class may contain multiple
    1264  * devices. The class and the device are associated with each other by the
    1265  * dev_class_info_t structure.
    1266  *
    1267  * @param dev           The device.
    1268  * @param class         The class.
    1269  * @param base_dev_name The base name of the device within the class if
    1270  *                      specified by the driver, NULL otherwise.
    1271  * @return              dev_class_info_t structure which associates the device
    1272  *                      with the class.
    1273  */
    1274 dev_class_info_t *add_function_to_class(fun_node_t *fun, dev_class_t *cl,
    1275     const char *base_dev_name)
    1276 {
    1277         dev_class_info_t *info;
    1278 
    1279         assert(fun != NULL);
    1280         assert(cl != NULL);
    1281 
    1282         info = create_dev_class_info();
    1283 
    1284        
    1285         if (info != NULL) {
    1286                 info->dev_class = cl;
    1287                 info->fun = fun;
    1288                
    1289                 /* Add the device to the class. */
    1290                 fibril_mutex_lock(&cl->mutex);
    1291                 list_append(&info->link, &cl->devices);
    1292                 fibril_mutex_unlock(&cl->mutex);
    1293                
    1294                 /* Add the class to the device. */
    1295                 list_append(&info->dev_classes, &fun->classes);
    1296                
    1297                 /* Create unique name for the device within the class. */
    1298                 info->dev_name = create_dev_name_for_class(cl, base_dev_name);
    1299         }
    1300        
    1301         return info;
    1302 }
    1303 
    1304 dev_class_t *get_dev_class(class_list_t *class_list, char *class_name)
    1305 {
    1306         dev_class_t *cl;
    1307        
    1308         fibril_rwlock_write_lock(&class_list->rwlock);
    1309         cl = find_dev_class_no_lock(class_list, class_name);
    1310         if (cl == NULL) {
    1311                 cl = create_dev_class();
    1312                 if (cl != NULL) {
    1313                         cl->name = class_name;
    1314                         cl->base_dev_name = "";
    1315                         add_dev_class_no_lock(class_list, cl);
    1316                 }
    1317         }
    1318 
    1319         fibril_rwlock_write_unlock(&class_list->rwlock);
    1320         return cl;
    1321 }
    1322 
    1323 dev_class_t *find_dev_class_no_lock(class_list_t *class_list,
    1324     const char *class_name)
    1325 {
    1326         dev_class_t *cl;
    1327         link_t *link = class_list->classes.next;
    1328        
    1329         while (link != &class_list->classes) {
    1330                 cl = list_get_instance(link, dev_class_t, link);
    1331                 if (str_cmp(cl->name, class_name) == 0) {
    1332                         return cl;
    1333                 }
    1334                 link = link->next;
    1335         }
    1336        
    1337         return NULL;
    1338 }
    1339 
    1340 void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl)
    1341 {
    1342         list_append(&cl->link, &class_list->classes);
    1343 }
    1344 
    1345 void init_class_list(class_list_t *class_list)
    1346 {
    1347         list_initialize(&class_list->classes);
    1348         fibril_rwlock_initialize(&class_list->rwlock);
    1349         hash_table_create(&class_list->devmap_functions, DEVICE_BUCKETS, 1,
    1350             &devmap_devices_class_ops);
    1351 }
    1352 
    1353 
    1354 /* Devmap devices */
    1355 
    1356 fun_node_t *find_devmap_tree_function(dev_tree_t *tree, devmap_handle_t devmap_handle)
     1217        return find_fun_node_in_device(pfun->child, name);
     1218}
     1219
     1220/* loc devices */
     1221
     1222fun_node_t *find_loc_tree_function(dev_tree_t *tree, service_id_t service_id)
    13571223{
    13581224        fun_node_t *fun = NULL;
    13591225        link_t *link;
    1360         unsigned long key = (unsigned long) devmap_handle;
     1226        unsigned long key = (unsigned long) service_id;
    13611227       
    13621228        fibril_rwlock_read_lock(&tree->rwlock);
    1363         link = hash_table_find(&tree->devmap_functions, &key);
     1229        link = hash_table_find(&tree->loc_functions, &key);
    13641230        if (link != NULL)
    1365                 fun = hash_table_get_instance(link, fun_node_t, devmap_fun);
     1231                fun = hash_table_get_instance(link, fun_node_t, loc_fun);
    13661232        fibril_rwlock_read_unlock(&tree->rwlock);
    13671233       
     
    13691235}
    13701236
    1371 fun_node_t *find_devmap_class_function(class_list_t *classes,
    1372     devmap_handle_t devmap_handle)
    1373 {
    1374         fun_node_t *fun = NULL;
    1375         dev_class_info_t *cli;
    1376         link_t *link;
    1377         unsigned long key = (unsigned long)devmap_handle;
    1378        
    1379         fibril_rwlock_read_lock(&classes->rwlock);
    1380         link = hash_table_find(&classes->devmap_functions, &key);
    1381         if (link != NULL) {
    1382                 cli = hash_table_get_instance(link, dev_class_info_t,
    1383                     devmap_link);
    1384                 fun = cli->fun;
    1385         }
    1386         fibril_rwlock_read_unlock(&classes->rwlock);
    1387        
    1388         return fun;
    1389 }
    1390 
    1391 void class_add_devmap_function(class_list_t *class_list, dev_class_info_t *cli)
    1392 {
    1393         unsigned long key = (unsigned long) cli->devmap_handle;
    1394        
    1395         fibril_rwlock_write_lock(&class_list->rwlock);
    1396         hash_table_insert(&class_list->devmap_functions, &key, &cli->devmap_link);
    1397         fibril_rwlock_write_unlock(&class_list->rwlock);
    1398 
    1399         assert(find_devmap_class_function(class_list, cli->devmap_handle) != NULL);
    1400 }
    1401 
    1402 void tree_add_devmap_function(dev_tree_t *tree, fun_node_t *fun)
    1403 {
    1404         unsigned long key = (unsigned long) fun->devmap_handle;
     1237void tree_add_loc_function(dev_tree_t *tree, fun_node_t *fun)
     1238{
     1239        unsigned long key = (unsigned long) fun->service_id;
    14051240        fibril_rwlock_write_lock(&tree->rwlock);
    1406         hash_table_insert(&tree->devmap_functions, &key, &fun->devmap_fun);
     1241        hash_table_insert(&tree->loc_functions, &key, &fun->loc_fun);
    14071242        fibril_rwlock_write_unlock(&tree->rwlock);
    14081243}
Note: See TracChangeset for help on using the changeset viewer.