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


Ignore:
Timestamp:
2011-04-07T15:53:46Z (13 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c156c2d
Parents:
64dbc83 (diff), a82889e (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:

development merge

File:
1 edited

Legend:

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

    r64dbc83 rb04967a  
    3434#include <fcntl.h>
    3535#include <sys/stat.h>
     36#include <io/log.h>
    3637#include <ipc/driver.h>
    3738#include <ipc/devman.h>
     
    146147        fibril_mutex_unlock(&drivers_list->drivers_mutex);
    147148
    148         printf(NAME": the '%s' driver was added to the list of available "
    149             "drivers.\n", drv->name);
    150 
    151         printf(NAME ": match ids:");
    152         link_t *cur;
    153         for (cur = drv->match_ids.ids.next; cur != &drv->match_ids.ids; cur = cur->next) {
    154                 match_id_t *match_id = list_get_instance(cur, match_id_t, link);
    155                 printf(" %d:%s", match_id->score, match_id->id);
    156         }
    157         printf("\n");
     149        log_msg(LVL_NOTE, "Driver `%s' was added to the list of available "
     150            "drivers.", drv->name);
    158151}
    159152
     
    245238bool read_match_ids(const char *conf_path, match_id_list_t *ids)
    246239{
    247         printf(NAME ": read_match_ids conf_path = %s.\n", conf_path);
     240        log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);
    248241       
    249242        bool suc = false;
     
    255248        fd = open(conf_path, O_RDONLY);
    256249        if (fd < 0) {
    257                 printf(NAME ": unable to open %s\n", conf_path);
     250                log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.",
     251                    conf_path, str_error(fd));
    258252                goto cleanup;
    259253        }
     
    263257        lseek(fd, 0, SEEK_SET);
    264258        if (len == 0) {
    265                 printf(NAME ": configuration file '%s' is empty.\n", conf_path);
     259                log_msg(LVL_ERROR, "Configuration file '%s' is empty.",
     260                    conf_path);
    266261                goto cleanup;
    267262        }
     
    269264        buf = malloc(len + 1);
    270265        if (buf == NULL) {
    271                 printf(NAME ": memory allocation failed when parsing file "
    272                     "'%s'.\n", conf_path);
     266                log_msg(LVL_ERROR, "Memory allocation failed when parsing file "
     267                    "'%s'.", conf_path);
    273268                goto cleanup;
    274269        }
    275270       
    276         if (read(fd, buf, len) <= 0) {
    277                 printf(NAME ": unable to read file '%s'.\n", conf_path);
     271        ssize_t read_bytes = safe_read(fd, buf, len);
     272        if (read_bytes <= 0) {
     273                log_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
    278274                goto cleanup;
    279275        }
    280         buf[len] = 0;
     276        buf[read_bytes] = 0;
    281277       
    282278        suc = parse_match_ids(buf, ids);
     
    313309bool get_driver_info(const char *base_path, const char *name, driver_t *drv)
    314310{
    315         printf(NAME ": get_driver_info base_path = %s, name = %s.\n",
     311        log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")",
    316312            base_path, name);
    317313       
     
    345341        struct stat s;
    346342        if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */
    347                 printf(NAME ": driver not found at path %s.", drv->binary_path);
     343                log_msg(LVL_ERROR, "Driver not found at path `%s'.",
     344                    drv->binary_path);
    348345                goto cleanup;
    349346        }
     
    372369int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path)
    373370{
    374         printf(NAME ": lookup_available_drivers, dir = %s \n", dir_path);
     371        log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path);
    375372       
    376373        int drv_cnt = 0;
     
    406403        dev_node_t *dev;
    407404       
    408         printf(NAME ": create_root_nodes\n");
     405        log_msg(LVL_DEBUG, "create_root_nodes()");
    409406       
    410407        fibril_rwlock_write_lock(&tree->rwlock);
     
    491488void attach_driver(dev_node_t *dev, driver_t *drv)
    492489{
    493         printf(NAME ": attach_driver %s to device %s\n",
    494             drv->name, dev->pfun->pathname);
     490        log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")",
     491            dev->pfun->pathname, drv->name);
    495492       
    496493        fibril_mutex_lock(&drv->driver_mutex);
     
    514511        assert(fibril_mutex_is_locked(&drv->driver_mutex));
    515512       
    516         printf(NAME ": start_driver '%s'\n", drv->name);
     513        log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);
    517514       
    518515        rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL);
    519516        if (rc != EOK) {
    520                 printf(NAME ": error spawning %s (%s)\n",
    521                     drv->name, str_error(rc));
     517                log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.",
     518                    drv->name, drv->binary_path, str_error(rc));
    522519                return false;
    523520        }
     
    581578        int phone;
    582579
    583         printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name);
     580        log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")",
     581            driver->name);
    584582
    585583        fibril_mutex_lock(&driver->driver_mutex);
     
    648646         * immediately and possibly started here as well.
    649647         */
    650         printf(NAME ": driver %s goes into running state.\n", driver->name);
     648        log_msg(LVL_DEBUG, "Driver `%s' enters running state.", driver->name);
    651649        driver->state = DRIVER_RUNNING;
    652650
     
    665663void initialize_running_driver(driver_t *driver, dev_tree_t *tree)
    666664{
    667         printf(NAME ": initialize_running_driver (`%s')\n", driver->name);
     665        log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")",
     666            driver->name);
    668667       
    669668        /*
     
    755754         * access any structures that would affect driver_t.
    756755         */
    757         printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
    758             dev->pfun->name);
     756        log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")",
     757            drv->name, dev->pfun->name);
    759758       
    760759        sysarg_t rc;
     
    817816        driver_t *drv = find_best_match_driver(drivers_list, dev);
    818817        if (drv == NULL) {
    819                 printf(NAME ": no driver found for device '%s'.\n",
     818                log_msg(LVL_ERROR, "No driver found for device `%s'.",
    820819                    dev->pfun->pathname);
    821820                return false;
     
    855854bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list)
    856855{
    857         printf(NAME ": init_device_tree.\n");
     856        log_msg(LVL_DEBUG, "init_device_tree()");
    858857       
    859858        tree->current_handle = 0;
     
    10341033        fun->pathname = (char *) malloc(pathsize);
    10351034        if (fun->pathname == NULL) {
    1036                 printf(NAME ": failed to allocate device path.\n");
     1035                log_msg(LVL_ERROR, "Failed to allocate device path.");
    10371036                return false;
    10381037        }
     
    10651064        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    10661065       
     1066        log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])",
     1067            dev, pfun, pfun->pathname);
     1068
    10671069        /* Add the node to the handle-to-node map. */
    10681070        dev->handle = ++tree->current_handle;
     
    10711073
    10721074        /* Add the node to the list of its parent's children. */
    1073         printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);
    10741075        dev->pfun = pfun;
    10751076        pfun->child = dev;
     
    11311132fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path)
    11321133{
     1134        assert(path != NULL);
     1135
     1136        bool is_absolute = path[0] == '/';
     1137        if (!is_absolute) {
     1138                return NULL;
     1139        }
     1140
    11331141        fibril_rwlock_read_lock(&tree->rwlock);
    11341142       
     
    11401148        char *rel_path = path;
    11411149        char *next_path_elem = NULL;
    1142         bool cont = (rel_path[0] == '/');
     1150        bool cont = true;
    11431151       
    11441152        while (cont && fun != NULL) {
     
    11651173}
    11661174
     1175/** Find function with a specified name belonging to given device.
     1176 *
     1177 * Device tree rwlock should be held at least for reading.
     1178 *
     1179 * @param dev Device the function belongs to.
     1180 * @param name Function name (not path).
     1181 * @return Function node.
     1182 * @retval NULL No function with given name.
     1183 */
     1184fun_node_t *find_fun_node_in_device(dev_node_t *dev, const char *name)
     1185{
     1186        assert(dev != NULL);
     1187        assert(name != NULL);
     1188
     1189        fun_node_t *fun;
     1190        link_t *link;
     1191
     1192        for (link = dev->functions.next;
     1193            link != &dev->functions;
     1194            link = link->next) {
     1195                fun = list_get_instance(link, fun_node_t, dev_functions);
     1196
     1197                if (str_cmp(name, fun->name) == 0)
     1198                        return fun;
     1199        }
     1200
     1201        return NULL;
     1202}
     1203
     1204/** Find function node by its class name and index. */
     1205fun_node_t *find_fun_node_by_class(class_list_t *class_list,
     1206    const char *class_name, const char *dev_name)
     1207{
     1208        assert(class_list != NULL);
     1209        assert(class_name != NULL);
     1210        assert(dev_name != NULL);
     1211
     1212        fibril_rwlock_read_lock(&class_list->rwlock);
     1213
     1214        dev_class_t *cl = find_dev_class_no_lock(class_list, class_name);
     1215        if (cl == NULL) {
     1216                fibril_rwlock_read_unlock(&class_list->rwlock);
     1217                return NULL;
     1218        }
     1219
     1220        dev_class_info_t *dev = find_dev_in_class(cl, dev_name);
     1221        if (dev == NULL) {
     1222                fibril_rwlock_read_unlock(&class_list->rwlock);
     1223                return NULL;
     1224        }
     1225
     1226        fun_node_t *fun = dev->fun;
     1227
     1228        fibril_rwlock_read_unlock(&class_list->rwlock);
     1229
     1230        return fun;
     1231}
     1232
     1233
    11671234/** Find child function node with a specified name.
    11681235 *
     
    11751242fun_node_t *find_node_child(fun_node_t *pfun, const char *name)
    11761243{
    1177         fun_node_t *fun;
    1178         link_t *link;
    1179        
    1180         link = pfun->child->functions.next;
    1181        
    1182         while (link != &pfun->child->functions) {
    1183                 fun = list_get_instance(link, fun_node_t, dev_functions);
    1184                
    1185                 if (str_cmp(name, fun->name) == 0)
    1186                         return fun;
    1187                
    1188                 link = link->next;
    1189         }
    1190        
    1191         return NULL;
     1244        return find_fun_node_in_device(pfun->child, name);
    11921245}
    11931246
     
    13511404}
    13521405
     1406dev_class_info_t *find_dev_in_class(dev_class_t *dev_class, const char *dev_name)
     1407{
     1408        assert(dev_class != NULL);
     1409        assert(dev_name != NULL);
     1410
     1411        link_t *link;
     1412        for (link = dev_class->devices.next;
     1413            link != &dev_class->devices;
     1414            link = link->next) {
     1415                dev_class_info_t *dev = list_get_instance(link,
     1416                    dev_class_info_t, link);
     1417
     1418                if (str_cmp(dev->dev_name, dev_name) == 0) {
     1419                        return dev;
     1420                }
     1421        }
     1422
     1423        return NULL;
     1424}
     1425
    13531426void init_class_list(class_list_t *class_list)
    13541427{
Note: See TracChangeset for help on using the changeset viewer.