Ignore:
File:
1 edited

Legend:

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

    rc7bbf029 r8b1e15ac  
    3434#include <fcntl.h>
    3535#include <sys/stat.h>
    36 #include <io/log.h>
    3736#include <ipc/driver.h>
    3837#include <ipc/devman.h>
    3938#include <devmap.h>
    4039#include <str_error.h>
    41 #include <stdio.h>
    4240
    4341#include "devman.h"
     
    148146        fibril_mutex_unlock(&drivers_list->drivers_mutex);
    149147
    150         log_msg(LVL_NOTE, "Driver `%s' was added to the list of available "
    151             "drivers.", drv->name);
     148        printf(NAME": the '%s' driver was added to the list of available "
     149            "drivers.\n", drv->name);
    152150}
    153151
     
    239237bool read_match_ids(const char *conf_path, match_id_list_t *ids)
    240238{
    241         log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);
     239        printf(NAME ": read_match_ids conf_path = %s.\n", conf_path);
    242240       
    243241        bool suc = false;
     
    249247        fd = open(conf_path, O_RDONLY);
    250248        if (fd < 0) {
    251                 log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.",
    252                     conf_path, str_error(fd));
     249                printf(NAME ": unable to open %s\n", conf_path);
    253250                goto cleanup;
    254251        }
     
    258255        lseek(fd, 0, SEEK_SET);
    259256        if (len == 0) {
    260                 log_msg(LVL_ERROR, "Configuration file '%s' is empty.",
    261                     conf_path);
     257                printf(NAME ": configuration file '%s' is empty.\n", conf_path);
    262258                goto cleanup;
    263259        }
     
    265261        buf = malloc(len + 1);
    266262        if (buf == NULL) {
    267                 log_msg(LVL_ERROR, "Memory allocation failed when parsing file "
    268                     "'%s'.", conf_path);
     263                printf(NAME ": memory allocation failed when parsing file "
     264                    "'%s'.\n", conf_path);
    269265                goto cleanup;
    270266        }
    271267       
    272         ssize_t read_bytes = safe_read(fd, buf, len);
    273         if (read_bytes <= 0) {
    274                 log_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
     268        if (read(fd, buf, len) <= 0) {
     269                printf(NAME ": unable to read file '%s'.\n", conf_path);
    275270                goto cleanup;
    276271        }
    277         buf[read_bytes] = 0;
     272        buf[len] = 0;
    278273       
    279274        suc = parse_match_ids(buf, ids);
     
    310305bool get_driver_info(const char *base_path, const char *name, driver_t *drv)
    311306{
    312         log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")",
     307        printf(NAME ": get_driver_info base_path = %s, name = %s.\n",
    313308            base_path, name);
    314309       
     
    342337        struct stat s;
    343338        if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */
    344                 log_msg(LVL_ERROR, "Driver not found at path `%s'.",
    345                     drv->binary_path);
     339                printf(NAME ": driver not found at path %s.", drv->binary_path);
    346340                goto cleanup;
    347341        }
     
    370364int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path)
    371365{
    372         log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path);
     366        printf(NAME ": lookup_available_drivers, dir = %s \n", dir_path);
    373367       
    374368        int drv_cnt = 0;
     
    404398        dev_node_t *dev;
    405399       
    406         log_msg(LVL_DEBUG, "create_root_nodes()");
     400        printf(NAME ": create_root_nodes\n");
    407401       
    408402        fibril_rwlock_write_lock(&tree->rwlock);
     
    489483void attach_driver(dev_node_t *dev, driver_t *drv)
    490484{
    491         log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")",
    492             dev->pfun->pathname, drv->name);
     485        printf(NAME ": attach_driver %s to device %s\n",
     486            drv->name, dev->pfun->pathname);
    493487       
    494488        fibril_mutex_lock(&drv->driver_mutex);
     
    512506        assert(fibril_mutex_is_locked(&drv->driver_mutex));
    513507       
    514         log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);
     508        printf(NAME ": start_driver '%s'\n", drv->name);
    515509       
    516510        rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL);
    517511        if (rc != EOK) {
    518                 log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",
    519                     drv->name, drv->binary_path, str_error(rc));
     512                printf(NAME ": error spawning %s (%s)\n",
     513                    drv->name, str_error(rc));
    520514                return false;
    521515        }
     
    556550}
    557551
     552/** Remember the driver's phone.
     553 *
     554 * @param driver        The driver.
     555 * @param phone         The phone to the driver.
     556 */
     557void 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);
     563}
     564
    558565/** Notify driver about the devices to which it was assigned.
    559566 *
     
    566573        int phone;
    567574
    568         log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")",
    569             driver->name);
     575        printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name);
    570576
    571577        fibril_mutex_lock(&driver->driver_mutex);
     
    634640         * immediately and possibly started here as well.
    635641         */
    636         log_msg(LVL_DEBUG, "Driver `%s' enters running state.", driver->name);
     642        printf(NAME ": driver %s goes into running state.\n", driver->name);
    637643        driver->state = DRIVER_RUNNING;
    638644
     
    651657void initialize_running_driver(driver_t *driver, dev_tree_t *tree)
    652658{
    653         log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")",
    654             driver->name);
     659        printf(NAME ": initialize_running_driver (`%s')\n", driver->name);
    655660       
    656661        /*
     
    673678        list_initialize(&drv->devices);
    674679        fibril_mutex_initialize(&drv->driver_mutex);
    675         drv->phone = -1;
    676680}
    677681
     
    743747         * access any structures that would affect driver_t.
    744748         */
    745         log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")",
    746             drv->name, dev->pfun->name);
     749        printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
     750            dev->pfun->name);
    747751       
    748752        sysarg_t rc;
     
    805809        driver_t *drv = find_best_match_driver(drivers_list, dev);
    806810        if (drv == NULL) {
    807                 log_msg(LVL_ERROR, "No driver found for device `%s'.",
     811                printf(NAME ": no driver found for device '%s'.\n",
    808812                    dev->pfun->pathname);
    809813                return false;
     
    843847bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list)
    844848{
    845         log_msg(LVL_DEBUG, "init_device_tree()");
     849        printf(NAME ": init_device_tree.\n");
    846850       
    847851        tree->current_handle = 0;
     
    10221026        fun->pathname = (char *) malloc(pathsize);
    10231027        if (fun->pathname == NULL) {
    1024                 log_msg(LVL_ERROR, "Failed to allocate device path.");
     1028                printf(NAME ": failed to allocate device path.\n");
    10251029                return false;
    10261030        }
     
    10531057        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    10541058       
    1055         log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])",
    1056             dev, pfun, pfun->pathname);
    1057 
    10581059        /* Add the node to the handle-to-node map. */
    10591060        dev->handle = ++tree->current_handle;
     
    10621063
    10631064        /* Add the node to the list of its parent's children. */
     1065        printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);
    10641066        dev->pfun = pfun;
    10651067        pfun->child = dev;
     
    11211123fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path)
    11221124{
    1123         assert(path != NULL);
    1124 
    1125         bool is_absolute = path[0] == '/';
    1126         if (!is_absolute) {
    1127                 return NULL;
    1128         }
    1129 
    11301125        fibril_rwlock_read_lock(&tree->rwlock);
    11311126       
     
    11371132        char *rel_path = path;
    11381133        char *next_path_elem = NULL;
    1139         bool cont = true;
     1134        bool cont = (rel_path[0] == '/');
    11401135       
    11411136        while (cont && fun != NULL) {
     
    11621157}
    11631158
    1164 /** Find function with a specified name belonging to given device.
    1165  *
    1166  * Device tree rwlock should be held at least for reading.
    1167  *
    1168  * @param dev Device the function belongs to.
    1169  * @param name Function name (not path).
    1170  * @return Function node.
    1171  * @retval NULL No function with given name.
    1172  */
    1173 fun_node_t *find_fun_node_in_device(dev_node_t *dev, const char *name)
    1174 {
    1175         assert(dev != NULL);
    1176         assert(name != NULL);
    1177 
    1178         fun_node_t *fun;
    1179         link_t *link;
    1180 
    1181         for (link = dev->functions.next;
    1182             link != &dev->functions;
    1183             link = link->next) {
    1184                 fun = list_get_instance(link, fun_node_t, dev_functions);
    1185 
    1186                 if (str_cmp(name, fun->name) == 0)
    1187                         return fun;
    1188         }
    1189 
    1190         return NULL;
    1191 }
    1192 
    1193 /** Find function node by its class name and index. */
    1194 fun_node_t *find_fun_node_by_class(class_list_t *class_list,
    1195     const char *class_name, const char *dev_name)
    1196 {
    1197         assert(class_list != NULL);
    1198         assert(class_name != NULL);
    1199         assert(dev_name != NULL);
    1200 
    1201         fibril_rwlock_read_lock(&class_list->rwlock);
    1202 
    1203         dev_class_t *cl = find_dev_class_no_lock(class_list, class_name);
    1204         if (cl == NULL) {
    1205                 fibril_rwlock_read_unlock(&class_list->rwlock);
    1206                 return NULL;
    1207         }
    1208 
    1209         dev_class_info_t *dev = find_dev_in_class(cl, dev_name);
    1210         if (dev == NULL) {
    1211                 fibril_rwlock_read_unlock(&class_list->rwlock);
    1212                 return NULL;
    1213         }
    1214 
    1215         fun_node_t *fun = dev->fun;
    1216 
    1217         fibril_rwlock_read_unlock(&class_list->rwlock);
    1218 
    1219         return fun;
    1220 }
    1221 
    1222 
    12231159/** Find child function node with a specified name.
    12241160 *
     
    12311167fun_node_t *find_node_child(fun_node_t *pfun, const char *name)
    12321168{
    1233         return find_fun_node_in_device(pfun->child, name);
     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;
    12341184}
    12351185
     
    12651215        if (info != NULL) {
    12661216                memset(info, 0, sizeof(dev_class_info_t));
    1267                 link_initialize(&info->dev_classes);
    1268                 link_initialize(&info->devmap_link);
    1269                 link_initialize(&info->link);
     1217                list_initialize(&info->dev_classes);
     1218                list_initialize(&info->devmap_link);
     1219                list_initialize(&info->link);
    12701220        }
    12711221       
     
    13931343}
    13941344
    1395 dev_class_info_t *find_dev_in_class(dev_class_t *dev_class, const char *dev_name)
    1396 {
    1397         assert(dev_class != NULL);
    1398         assert(dev_name != NULL);
    1399 
    1400         link_t *link;
    1401         for (link = dev_class->devices.next;
    1402             link != &dev_class->devices;
    1403             link = link->next) {
    1404                 dev_class_info_t *dev = list_get_instance(link,
    1405                     dev_class_info_t, link);
    1406 
    1407                 if (str_cmp(dev->dev_name, dev_name) == 0) {
    1408                         return dev;
    1409                 }
    1410         }
    1411 
    1412         return NULL;
    1413 }
    1414 
    14151345void init_class_list(class_list_t *class_list)
    14161346{
Note: See TracChangeset for help on using the changeset viewer.