Ignore:
File:
1 edited

Legend:

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

    raf6b5157 r6f9e7fea  
    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>
    50 #include <inttypes.h>
    51 #include <sysinfo.h>
    5248
    53 #include <ddf/driver.h>
     49#include <driver.h>
    5450#include <devman.h>
    5551#include <ipc/devman.h>
     
    5753#define NAME "root"
    5854
    59 #define PLATFORM_FUN_NAME "hw"
    60 #define PLATFORM_FUN_MATCH_ID_FMT "platform/%s"
    61 #define PLATFORM_FUN_MATCH_SCORE 100
     55#define PLATFORM_DEVICE_NAME "hw"
     56#define PLATFORM_DEVICE_MATCH_ID STRING(UARCH)
     57#define PLATFORM_DEVICE_MATCH_SCORE 100
    6258
    63 #define VIRTUAL_FUN_NAME "virt"
    64 #define VIRTUAL_FUN_MATCH_ID "rootvirt"
    65 #define VIRTUAL_FUN_MATCH_SCORE 100
     59#define VIRTUAL_DEVICE_NAME "virt"
     60#define VIRTUAL_DEVICE_MATCH_ID "rootvirt"
     61#define VIRTUAL_DEVICE_MATCH_SCORE 100
    6662
    67 static int root_add_device(ddf_dev_t *dev);
     63static int root_add_device(device_t *dev);
    6864
    6965/** The root device driver's standard operations. */
     
    7874};
    7975
    80 /** Create the function which represents the root of virtual device tree.
     76/** Create the device which represents the root of virtual device tree.
    8177 *
    82  * @param dev   Device
    83  * @return      EOK on success or negative error code
     78 * @param parent Parent of the newly created device.
     79 * @return Error code.
    8480 */
    85 static int add_virtual_root_fun(ddf_dev_t *dev)
     81static int add_virtual_root_child(device_t *parent)
    8682{
    87         const char *name = VIRTUAL_FUN_NAME;
    88         ddf_fun_t *fun;
    89         int rc;
     83        printf(NAME ": adding new child for virtual devices.\n");
     84        printf(NAME ":   device node is `%s' (%d %s)\n", VIRTUAL_DEVICE_NAME,
     85            VIRTUAL_DEVICE_MATCH_SCORE, VIRTUAL_DEVICE_MATCH_ID);
    9086
    91         printf(NAME ": adding new function for virtual devices.\n");
    92         printf(NAME ":   function node is `%s' (%d %s)\n", name,
    93             VIRTUAL_FUN_MATCH_SCORE, VIRTUAL_FUN_MATCH_ID);
     87        int res = child_device_register_wrapper(parent, VIRTUAL_DEVICE_NAME,
     88            VIRTUAL_DEVICE_MATCH_ID, VIRTUAL_DEVICE_MATCH_SCORE);
    9489
    95         fun = ddf_fun_create(dev, fun_inner, name);
    96         if (fun == NULL) {
    97                 printf(NAME ": error creating function %s\n", name);
    98                 return ENOMEM;
    99         }
    100 
    101         rc = ddf_fun_add_match_id(fun, VIRTUAL_FUN_MATCH_ID,
    102             VIRTUAL_FUN_MATCH_SCORE);
    103         if (rc != EOK) {
    104                 printf(NAME ": error adding match IDs to function %s\n", name);
    105                 ddf_fun_destroy(fun);
    106                 return rc;
    107         }
    108 
    109         rc = ddf_fun_bind(fun);
    110         if (rc != EOK) {
    111                 printf(NAME ": error binding function %s: %s\n", name,
    112                     str_error(rc));
    113                 ddf_fun_destroy(fun);
    114                 return rc;
    115         }
    116 
    117         return EOK;
     90        return res;
    11891}
    11992
    120 /** Create the function which represents the root of HW device tree.
     93/** Create the device which represents the root of HW device tree.
    12194 *
    122  * @param dev   Device
    123  * @return      EOK on success or negative error code
     95 * @param parent        Parent of the newly created device.
     96 * @return 0 on success, negative error number otherwise.
    12497 */
    125 static int add_platform_fun(ddf_dev_t *dev)
     98static int add_platform_child(device_t *parent)
    12699{
    127         char *match_id;
    128         char *platform;
    129         size_t platform_size;
     100        printf(NAME ": adding new child for platform device.\n");
     101        printf(NAME ":   device node is `%s' (%d %s)\n", PLATFORM_DEVICE_NAME,
     102            PLATFORM_DEVICE_MATCH_SCORE, PLATFORM_DEVICE_MATCH_ID);
     103       
     104        int res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME,
     105            PLATFORM_DEVICE_MATCH_ID, PLATFORM_DEVICE_MATCH_SCORE);
    130106
    131         const char *name = PLATFORM_FUN_NAME;
    132         ddf_fun_t *fun;
    133         int rc;
    134 
    135         /* Get platform name from sysinfo. */
    136         platform = sysinfo_get_data("platform", &platform_size);
    137         if (platform == NULL) {
    138                 printf(NAME ": Failed to obtain platform name.\n");
    139                 return ENOENT;
    140         }
    141 
    142         /* Null-terminate string. */
    143         platform = realloc(platform, platform_size + 1);
    144         if (platform == NULL) {
    145                 printf(NAME ": Memory allocation failed.\n");
    146                 return ENOMEM;
    147         }
    148 
    149         platform[platform_size] = '\0';
    150 
    151         /* Construct match ID. */
    152         if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) {
    153                 printf(NAME ": Memory allocation failed.\n");
    154                 return ENOMEM;
    155         }
    156 
    157         /* Add function. */
    158         printf(NAME ": adding platform function\n");
    159         printf(NAME ":   function node is `%s' (%d %s)\n", PLATFORM_FUN_NAME,
    160             PLATFORM_FUN_MATCH_SCORE, match_id);
    161 
    162         fun = ddf_fun_create(dev, fun_inner, name);
    163         if (fun == NULL) {
    164                 printf(NAME ": error creating function %s\n", name);
    165                 return ENOMEM;
    166         }
    167 
    168         rc = ddf_fun_add_match_id(fun, match_id, PLATFORM_FUN_MATCH_SCORE);
    169         if (rc != EOK) {
    170                 printf(NAME ": error adding match IDs to function %s\n", name);
    171                 ddf_fun_destroy(fun);
    172                 return rc;
    173         }
    174 
    175         rc = ddf_fun_bind(fun);
    176         if (rc != EOK) {
    177                 printf(NAME ": error binding function %s: %s\n", name,
    178                     str_error(rc));
    179                 ddf_fun_destroy(fun);
    180                 return rc;
    181         }
    182 
    183         return EOK;
     107        return res;
    184108}
    185109
     
    189113 *                      of HW and pseudo devices).
    190114 */
    191 static int root_add_device(ddf_dev_t *dev)
     115static int root_add_device(device_t *dev)
    192116{
    193         printf(NAME ": root_add_device, device handle=%" PRIun "\n",
    194             dev->handle);
    195 
     117        printf(NAME ": root_add_device, device handle = %d\n", dev->handle);
     118       
    196119        /*
    197120         * Register virtual devices root.
     
    199122         * vital for the system.
    200123         */
    201         add_virtual_root_fun(dev);
     124        add_virtual_root_child(dev);
    202125
    203126        /* Register root device's children. */
    204         int res = add_platform_fun(dev);
     127        int res = add_platform_child(dev);
    205128        if (EOK != res)
    206129                printf(NAME ": failed to add child device for platform.\n");
    207 
     130       
    208131        return res;
    209132}
     
    212135{
    213136        printf(NAME ": HelenOS root device driver\n");
    214         return ddf_driver_main(&root_driver);
     137        return driver_main(&root_driver);
    215138}
    216139
Note: See TracChangeset for help on using the changeset viewer.