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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 178673c was 6f9e7fea, checked in by Vojtech Horky <vojtechhorky@…>, 15 years ago

Add root virtual device driver

The driver is meant as a simple way to add virtual devices to the
system (it only passes list of virtual devices to devman which then
decides what drivers to launch).

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Copyright (c) 2010 Lenka Trochtova
3 * Copyright (c) 2010 Vojtech Horky
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/**
31 * @defgroup root Root device driver.
32 * @brief HelenOS root device driver.
33 * @{
34 */
35
36/** @file
37 */
38
39#include <assert.h>
40#include <stdio.h>
41#include <errno.h>
42#include <bool.h>
43#include <fibril_synch.h>
44#include <stdlib.h>
45#include <str.h>
46#include <ctype.h>
47#include <macros.h>
48
49#include <driver.h>
50#include <devman.h>
51#include <ipc/devman.h>
52
53#define NAME "root"
54
55#define PLATFORM_DEVICE_NAME "hw"
56#define PLATFORM_DEVICE_MATCH_ID STRING(UARCH)
57#define PLATFORM_DEVICE_MATCH_SCORE 100
58
59#define VIRTUAL_DEVICE_NAME "virt"
60#define VIRTUAL_DEVICE_MATCH_ID "rootvirt"
61#define VIRTUAL_DEVICE_MATCH_SCORE 100
62
63static int root_add_device(device_t *dev);
64
65/** The root device driver's standard operations. */
66static driver_ops_t root_ops = {
67 .add_device = &root_add_device
68};
69
70/** The root device driver structure. */
71static driver_t root_driver = {
72 .name = NAME,
73 .driver_ops = &root_ops
74};
75
76/** Create the device which represents the root of virtual device tree.
77 *
78 * @param parent Parent of the newly created device.
79 * @return Error code.
80 */
81static int add_virtual_root_child(device_t *parent)
82{
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);
86
87 int res = child_device_register_wrapper(parent, VIRTUAL_DEVICE_NAME,
88 VIRTUAL_DEVICE_MATCH_ID, VIRTUAL_DEVICE_MATCH_SCORE);
89
90 return res;
91}
92
93/** Create the device which represents the root of HW device tree.
94 *
95 * @param parent Parent of the newly created device.
96 * @return 0 on success, negative error number otherwise.
97 */
98static int add_platform_child(device_t *parent)
99{
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);
106
107 return res;
108}
109
110/** Get the root device.
111 *
112 * @param dev The device which is root of the whole device tree (both
113 * of HW and pseudo devices).
114 */
115static int root_add_device(device_t *dev)
116{
117 printf(NAME ": root_add_device, device handle = %d\n", dev->handle);
118
119 /*
120 * Register virtual devices root.
121 * We ignore error occurrence because virtual devices shall not be
122 * vital for the system.
123 */
124 add_virtual_root_child(dev);
125
126 /* Register root device's children. */
127 int res = add_platform_child(dev);
128 if (EOK != res)
129 printf(NAME ": failed to add child device for platform.\n");
130
131 return res;
132}
133
134int main(int argc, char *argv[])
135{
136 printf(NAME ": HelenOS root device driver\n");
137 return driver_main(&root_driver);
138}
139
140/**
141 * @}
142 */
143
Note: See TracBrowser for help on using the repository browser.