Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/root/root.c

    rebcb05a reff1f033  
    22 * Copyright (c) 2010 Lenka Trochtova
    33 * Copyright (c) 2010 Vojtech Horky
    4  * Copyright (c) 2011 Jiri Svoboda
    54 * All rights reserved.
    65 *
     
    4544#include <stdlib.h>
    4645#include <str.h>
    47 #include <str_error.h>
    4846#include <ctype.h>
    4947#include <macros.h>
     
    5149#include <sysinfo.h>
    5250
    53 #include <ddf/driver.h>
    54 #include <ddf/log.h>
     51#include <driver.h>
    5552#include <devman.h>
    5653#include <ipc/devman.h>
     
    5855#define NAME "root"
    5956
    60 #define PLATFORM_FUN_NAME "hw"
    61 #define PLATFORM_FUN_MATCH_ID_FMT "platform/%s"
    62 #define PLATFORM_FUN_MATCH_SCORE 100
     57#define PLATFORM_DEVICE_NAME "hw"
     58#define PLATFORM_DEVICE_MATCH_ID_FMT "platform/%s"
     59#define PLATFORM_DEVICE_MATCH_SCORE 100
    6360
    64 #define VIRTUAL_FUN_NAME "virt"
    65 #define VIRTUAL_FUN_MATCH_ID "rootvirt"
    66 #define VIRTUAL_FUN_MATCH_SCORE 100
     61#define VIRTUAL_DEVICE_NAME "virt"
     62#define VIRTUAL_DEVICE_MATCH_ID "rootvirt"
     63#define VIRTUAL_DEVICE_MATCH_SCORE 100
    6764
    68 static int root_add_device(ddf_dev_t *dev);
     65static int root_add_device(device_t *dev);
    6966
    7067/** The root device driver's standard operations. */
     
    7976};
    8077
    81 /** Create the function which represents the root of virtual device tree.
     78/** Create the device which represents the root of virtual device tree.
    8279 *
    83  * @param dev   Device
    84  * @return      EOK on success or negative error code
     80 * @param parent Parent of the newly created device.
     81 * @return Error code.
    8582 */
    86 static int add_virtual_root_fun(ddf_dev_t *dev)
     83static int add_virtual_root_child(device_t *parent)
    8784{
    88         const char *name = VIRTUAL_FUN_NAME;
    89         ddf_fun_t *fun;
    90         int rc;
     85        printf(NAME ": adding new child for virtual devices.\n");
     86        printf(NAME ":   device node is `%s' (%d %s)\n", VIRTUAL_DEVICE_NAME,
     87            VIRTUAL_DEVICE_MATCH_SCORE, VIRTUAL_DEVICE_MATCH_ID);
    9188
    92         ddf_msg(LVL_DEBUG, "Adding new function for virtual devices. "
    93             "Function node is `%s' (%d %s)", name,
    94             VIRTUAL_FUN_MATCH_SCORE, VIRTUAL_FUN_MATCH_ID);
     89        int res = child_device_register_wrapper(parent, VIRTUAL_DEVICE_NAME,
     90            VIRTUAL_DEVICE_MATCH_ID, VIRTUAL_DEVICE_MATCH_SCORE);
    9591
    96         fun = ddf_fun_create(dev, fun_inner, name);
    97         if (fun == NULL) {
    98                 ddf_msg(LVL_ERROR, "Failed creating function %s", name);
    99                 return ENOMEM;
    100         }
    101 
    102         rc = ddf_fun_add_match_id(fun, VIRTUAL_FUN_MATCH_ID,
    103             VIRTUAL_FUN_MATCH_SCORE);
    104         if (rc != EOK) {
    105                 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
    106                     name);
    107                 ddf_fun_destroy(fun);
    108                 return rc;
    109         }
    110 
    111         rc = ddf_fun_bind(fun);
    112         if (rc != EOK) {
    113                 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    114                     str_error(rc));
    115                 ddf_fun_destroy(fun);
    116                 return rc;
    117         }
    118 
    119         return EOK;
     92        return res;
    12093}
    12194
    122 /** Create the function which represents the root of HW device tree.
     95/** Create the device which represents the root of HW device tree.
    12396 *
    124  * @param dev   Device
    125  * @return      EOK on success or negative error code
     97 * @param parent        Parent of the newly created device.
     98 * @return 0 on success, negative error number otherwise.
    12699 */
    127 static int add_platform_fun(ddf_dev_t *dev)
     100static int add_platform_child(device_t *parent)
    128101{
    129102        char *match_id;
    130103        char *platform;
    131104        size_t platform_size;
    132 
    133         const char *name = PLATFORM_FUN_NAME;
    134         ddf_fun_t *fun;
    135         int rc;
     105        int res;
    136106
    137107        /* Get platform name from sysinfo. */
     108
    138109        platform = sysinfo_get_data("platform", &platform_size);
    139110        if (platform == NULL) {
    140                 ddf_msg(LVL_ERROR, "Failed to obtain platform name.");
     111                printf(NAME ": Failed to obtain platform name.\n");
    141112                return ENOENT;
    142113        }
     
    145116        platform = realloc(platform, platform_size + 1);
    146117        if (platform == NULL) {
    147                 ddf_msg(LVL_ERROR, "Memory allocation failed.");
     118                printf(NAME ": Memory allocation failed.\n");
    148119                return ENOMEM;
    149120        }
     
    152123
    153124        /* Construct match ID. */
    154         if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) {
    155                 ddf_msg(LVL_ERROR, "Memory allocation failed.");
     125
     126        if (asprintf(&match_id, PLATFORM_DEVICE_MATCH_ID_FMT, platform) == -1) {
     127                printf(NAME ": Memory allocation failed.\n");
    156128                return ENOMEM;
    157129        }
    158130
    159         /* Add function. */
    160         ddf_msg(LVL_DEBUG, "Adding platform function. Function node is `%s' "
    161             " (%d %s)", PLATFORM_FUN_NAME, PLATFORM_FUN_MATCH_SCORE,
    162             match_id);
     131        /* Add child. */
    163132
    164         fun = ddf_fun_create(dev, fun_inner, name);
    165         if (fun == NULL) {
    166                 ddf_msg(LVL_ERROR, "Error creating function %s", name);
    167                 return ENOMEM;
    168         }
     133        printf(NAME ": adding new child for platform device.\n");
     134        printf(NAME ":   device node is `%s' (%d %s)\n", PLATFORM_DEVICE_NAME,
     135            PLATFORM_DEVICE_MATCH_SCORE, match_id);
    169136
    170         rc = ddf_fun_add_match_id(fun, match_id, PLATFORM_FUN_MATCH_SCORE);
    171         if (rc != EOK) {
    172                 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
    173                     name);
    174                 ddf_fun_destroy(fun);
    175                 return rc;
    176         }
     137        res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME,
     138            match_id, PLATFORM_DEVICE_MATCH_SCORE);
    177139
    178         rc = ddf_fun_bind(fun);
    179         if (rc != EOK) {
    180                 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    181                     str_error(rc));
    182                 ddf_fun_destroy(fun);
    183                 return rc;
    184         }
    185 
    186         return EOK;
     140        return res;
    187141}
    188142
     
    192146 *                      of HW and pseudo devices).
    193147 */
    194 static int root_add_device(ddf_dev_t *dev)
     148static int root_add_device(device_t *dev)
    195149{
    196         ddf_msg(LVL_DEBUG, "root_add_device, device handle=%" PRIun,
     150        printf(NAME ": root_add_device, device handle=%" PRIun "\n",
    197151            dev->handle);
    198 
     152       
    199153        /*
    200154         * Register virtual devices root.
     
    202156         * vital for the system.
    203157         */
    204         add_virtual_root_fun(dev);
     158        add_virtual_root_child(dev);
    205159
    206160        /* Register root device's children. */
    207         int res = add_platform_fun(dev);
     161        int res = add_platform_child(dev);
    208162        if (EOK != res)
    209                 ddf_msg(LVL_ERROR, "Failed adding child device for platform.");
    210 
     163                printf(NAME ": failed to add child device for platform.\n");
     164       
    211165        return res;
    212166}
     
    215169{
    216170        printf(NAME ": HelenOS root device driver\n");
    217 
    218         ddf_log_init(NAME, LVL_ERROR);
    219         return ddf_driver_main(&root_driver);
     171        return driver_main(&root_driver);
    220172}
    221173
Note: See TracChangeset for help on using the changeset viewer.