Ignore:
File:
1 edited

Legend:

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

    reff1f033 rebcb05a  
    22 * Copyright (c) 2010 Lenka Trochtova
    33 * Copyright (c) 2010 Vojtech Horky
     4 * Copyright (c) 2011 Jiri Svoboda
    45 * All rights reserved.
    56 *
     
    4445#include <stdlib.h>
    4546#include <str.h>
     47#include <str_error.h>
    4648#include <ctype.h>
    4749#include <macros.h>
     
    4951#include <sysinfo.h>
    5052
    51 #include <driver.h>
     53#include <ddf/driver.h>
     54#include <ddf/log.h>
    5255#include <devman.h>
    5356#include <ipc/devman.h>
     
    5558#define NAME "root"
    5659
    57 #define PLATFORM_DEVICE_NAME "hw"
    58 #define PLATFORM_DEVICE_MATCH_ID_FMT "platform/%s"
    59 #define PLATFORM_DEVICE_MATCH_SCORE 100
    60 
    61 #define VIRTUAL_DEVICE_NAME "virt"
    62 #define VIRTUAL_DEVICE_MATCH_ID "rootvirt"
    63 #define VIRTUAL_DEVICE_MATCH_SCORE 100
    64 
    65 static int root_add_device(device_t *dev);
     60#define PLATFORM_FUN_NAME "hw"
     61#define PLATFORM_FUN_MATCH_ID_FMT "platform/%s"
     62#define PLATFORM_FUN_MATCH_SCORE 100
     63
     64#define VIRTUAL_FUN_NAME "virt"
     65#define VIRTUAL_FUN_MATCH_ID "rootvirt"
     66#define VIRTUAL_FUN_MATCH_SCORE 100
     67
     68static int root_add_device(ddf_dev_t *dev);
    6669
    6770/** The root device driver's standard operations. */
     
    7679};
    7780
    78 /** Create the device which represents the root of virtual device tree.
    79  *
    80  * @param parent Parent of the newly created device.
    81  * @return Error code.
    82  */
    83 static int add_virtual_root_child(device_t *parent)
    84 {
    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);
    88 
    89         int res = child_device_register_wrapper(parent, VIRTUAL_DEVICE_NAME,
    90             VIRTUAL_DEVICE_MATCH_ID, VIRTUAL_DEVICE_MATCH_SCORE);
    91 
    92         return res;
    93 }
    94 
    95 /** Create the device which represents the root of HW device tree.
    96  *
    97  * @param parent        Parent of the newly created device.
    98  * @return 0 on success, negative error number otherwise.
    99  */
    100 static int add_platform_child(device_t *parent)
     81/** Create the function which represents the root of virtual device tree.
     82 *
     83 * @param dev   Device
     84 * @return      EOK on success or negative error code
     85 */
     86static int add_virtual_root_fun(ddf_dev_t *dev)
     87{
     88        const char *name = VIRTUAL_FUN_NAME;
     89        ddf_fun_t *fun;
     90        int rc;
     91
     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);
     95
     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;
     120}
     121
     122/** Create the function which represents the root of HW device tree.
     123 *
     124 * @param dev   Device
     125 * @return      EOK on success or negative error code
     126 */
     127static int add_platform_fun(ddf_dev_t *dev)
    101128{
    102129        char *match_id;
    103130        char *platform;
    104131        size_t platform_size;
    105         int res;
     132
     133        const char *name = PLATFORM_FUN_NAME;
     134        ddf_fun_t *fun;
     135        int rc;
    106136
    107137        /* Get platform name from sysinfo. */
    108 
    109138        platform = sysinfo_get_data("platform", &platform_size);
    110139        if (platform == NULL) {
    111                 printf(NAME ": Failed to obtain platform name.\n");
     140                ddf_msg(LVL_ERROR, "Failed to obtain platform name.");
    112141                return ENOENT;
    113142        }
     
    116145        platform = realloc(platform, platform_size + 1);
    117146        if (platform == NULL) {
    118                 printf(NAME ": Memory allocation failed.\n");
     147                ddf_msg(LVL_ERROR, "Memory allocation failed.");
    119148                return ENOMEM;
    120149        }
     
    123152
    124153        /* Construct match ID. */
    125 
    126         if (asprintf(&match_id, PLATFORM_DEVICE_MATCH_ID_FMT, platform) == -1) {
    127                 printf(NAME ": Memory allocation failed.\n");
    128                 return ENOMEM;
    129         }
    130 
    131         /* Add child. */
    132 
    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);
    136 
    137         res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME,
    138             match_id, PLATFORM_DEVICE_MATCH_SCORE);
    139 
    140         return res;
     154        if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) {
     155                ddf_msg(LVL_ERROR, "Memory allocation failed.");
     156                return ENOMEM;
     157        }
     158
     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);
     163
     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        }
     169
     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        }
     177
     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;
    141187}
    142188
     
    146192 *                      of HW and pseudo devices).
    147193 */
    148 static int root_add_device(device_t *dev)
    149 {
    150         printf(NAME ": root_add_device, device handle=%" PRIun "\n",
     194static int root_add_device(ddf_dev_t *dev)
     195{
     196        ddf_msg(LVL_DEBUG, "root_add_device, device handle=%" PRIun,
    151197            dev->handle);
    152        
     198
    153199        /*
    154200         * Register virtual devices root.
     
    156202         * vital for the system.
    157203         */
    158         add_virtual_root_child(dev);
     204        add_virtual_root_fun(dev);
    159205
    160206        /* Register root device's children. */
    161         int res = add_platform_child(dev);
     207        int res = add_platform_fun(dev);
    162208        if (EOK != res)
    163                 printf(NAME ": failed to add child device for platform.\n");
    164        
     209                ddf_msg(LVL_ERROR, "Failed adding child device for platform.");
     210
    165211        return res;
    166212}
     
    169215{
    170216        printf(NAME ": HelenOS root device driver\n");
    171         return driver_main(&root_driver);
     217
     218        ddf_log_init(NAME, LVL_ERROR);
     219        return ddf_driver_main(&root_driver);
    172220}
    173221
Note: See TracChangeset for help on using the changeset viewer.