source: mainline/uspace/drv/root/root.c@ bab6388

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since bab6388 was bab6388, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Small additional cleanup.

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[924c75e1]1/*
2 * Copyright (c) 2010 Lenka Trochtova
[0ca16307]3 * Copyright (c) 2010 Vojtech Horky
[68414f4a]4 * Copyright (c) 2011 Jiri Svoboda
[924c75e1]5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
[c16cf62]32 * @defgroup root Root device driver.
[924c75e1]33 * @brief HelenOS root device driver.
34 * @{
35 */
36
37/** @file
38 */
39
40#include <assert.h>
41#include <stdio.h>
42#include <errno.h>
43#include <bool.h>
44#include <fibril_synch.h>
45#include <stdlib.h>
[c47e1a8]46#include <str.h>
[924c75e1]47#include <ctype.h>
[bda60d9]48#include <macros.h>
[7e752b2]49#include <inttypes.h>
[eff1f033]50#include <sysinfo.h>
[924c75e1]51
[c16cf62]52#include <driver.h>
[729fa2d6]53#include <devman.h>
[924c75e1]54#include <ipc/devman.h>
55
56#define NAME "root"
57
[68414f4a]58#define PLATFORM_FUN_NAME "hw"
59#define PLATFORM_FUN_MATCH_ID_FMT "platform/%s"
60#define PLATFORM_FUN_MATCH_SCORE 100
[0ca16307]61
[68414f4a]62#define VIRTUAL_FUN_NAME "virt"
63#define VIRTUAL_FUN_MATCH_ID "rootvirt"
64#define VIRTUAL_FUN_MATCH_SCORE 100
[6f9e7fea]65
[df747b9c]66static int root_add_device(device_t *dev);
[924c75e1]67
[5291411]68/** The root device driver's standard operations. */
[729fa2d6]69static driver_ops_t root_ops = {
70 .add_device = &root_add_device
71};
72
[5291411]73/** The root device driver structure. */
[729fa2d6]74static driver_t root_driver = {
75 .name = NAME,
76 .driver_ops = &root_ops
77};
78
[68414f4a]79/** Create the function which represents the root of virtual device tree.
[6f9e7fea]80 *
[68414f4a]81 * @param dev Device
82 * @return EOK on success or negative error code
[6f9e7fea]83 */
[68414f4a]84static int add_virtual_root_fun(device_t *dev)
[6f9e7fea]85{
[68414f4a]86 printf(NAME ": adding new function for virtual devices.\n");
87 printf(NAME ": function node is `%s' (%d %s)\n", VIRTUAL_FUN_NAME,
88 VIRTUAL_FUN_MATCH_SCORE, VIRTUAL_FUN_MATCH_ID);
[6f9e7fea]89
[68414f4a]90 int res = register_function_wrapper(dev, VIRTUAL_FUN_NAME,
91 VIRTUAL_FUN_MATCH_ID, VIRTUAL_FUN_MATCH_SCORE);
[6f9e7fea]92
93 return res;
94}
95
[68414f4a]96/** Create the function which represents the root of HW device tree.
[5291411]97 *
[68414f4a]98 * @param dev Device
99 * @return EOK on success or negative error code
[66babbd]100 */
[68414f4a]101static int add_platform_fun(device_t *dev)
[5291411]102{
[eff1f033]103 char *match_id;
104 char *platform;
105 size_t platform_size;
106 int res;
107
108 /* Get platform name from sysinfo. */
109 platform = sysinfo_get_data("platform", &platform_size);
110 if (platform == NULL) {
111 printf(NAME ": Failed to obtain platform name.\n");
112 return ENOENT;
113 }
114
115 /* Null-terminate string. */
116 platform = realloc(platform, platform_size + 1);
117 if (platform == NULL) {
118 printf(NAME ": Memory allocation failed.\n");
119 return ENOMEM;
120 }
121
122 platform[platform_size] = '\0';
123
124 /* Construct match ID. */
[68414f4a]125 if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) {
[eff1f033]126 printf(NAME ": Memory allocation failed.\n");
127 return ENOMEM;
128 }
129
[68414f4a]130 /* Add function. */
131 printf(NAME ": adding platform function\n");
132 printf(NAME ": function node is `%s' (%d %s)\n", PLATFORM_FUN_NAME,
133 PLATFORM_FUN_MATCH_SCORE, match_id);
[eff1f033]134
[68414f4a]135 res = register_function_wrapper(dev, PLATFORM_FUN_NAME,
136 match_id, PLATFORM_FUN_MATCH_SCORE);
[0ca16307]137
[5291411]138 return res;
[bda60d9]139}
140
[66babbd]141/** Get the root device.
[5291411]142 *
143 * @param dev The device which is root of the whole device tree (both
144 * of HW and pseudo devices).
[66babbd]145 */
[5291411]146static int root_add_device(device_t *dev)
[c16cf62]147{
[7e752b2]148 printf(NAME ": root_add_device, device handle=%" PRIun "\n",
149 dev->handle);
[bab6388]150
[6f9e7fea]151 /*
152 * Register virtual devices root.
153 * We ignore error occurrence because virtual devices shall not be
154 * vital for the system.
155 */
[68414f4a]156 add_virtual_root_fun(dev);
[6f9e7fea]157
[5291411]158 /* Register root device's children. */
[68414f4a]159 int res = add_platform_fun(dev);
[5291411]160 if (EOK != res)
[d347b53]161 printf(NAME ": failed to add child device for platform.\n");
[bab6388]162
[df747b9c]163 return res;
[c16cf62]164}
165
[924c75e1]166int main(int argc, char *argv[])
167{
[5291411]168 printf(NAME ": HelenOS root device driver\n");
[924c75e1]169 return driver_main(&root_driver);
170}
[c16cf62]171
172/**
173 * @}
[bda60d9]174 */
[5291411]175
Note: See TracBrowser for help on using the repository browser.