source: mainline/uspace/drv/rootvirt/rootvirt.c@ 8b1e15ac

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

Finish splitting device node: devman client in C library, drv library. Update device drivers accordingly.

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2010 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * @defgroup rootvirt Root device driver for virtual devices.
31 * @{
32 */
33
34/** @file
35 */
36
37#include <assert.h>
38#include <stdio.h>
39#include <errno.h>
40#include <str_error.h>
41#include <driver.h>
42
43#define NAME "rootvirt"
44
45/** Virtual function entry */
46typedef struct {
47 /** Function name */
48 const char *name;
49 /** Function match ID */
50 const char *match_id;
51} virtual_function_t;
52
53/** List of existing virtual functions */
54virtual_function_t virtual_functions[] = {
55#include "devices.def"
56 /* Terminating item */
57 {
58 .name = NULL,
59 .match_id = NULL
60 }
61};
62
63static int add_device(device_t *dev);
64
65static driver_ops_t rootvirt_ops = {
66 .add_device = &add_device
67};
68
69static driver_t rootvirt_driver = {
70 .name = NAME,
71 .driver_ops = &rootvirt_ops
72};
73
74/** Add function to the virtual device.
75 *
76 * @param vdev The virtual device
77 * @param vfun Virtual function description
78 * @return EOK on success or negative error code.
79 */
80static int add_child(device_t *vdev, virtual_function_t *vfun)
81{
82 printf(NAME ": registering function `%s' (match \"%s\")\n",
83 vfun->name, vfun->match_id);
84
85 int rc = register_function_wrapper(vdev, vfun->name,
86 vfun->match_id, 10);
87
88 if (rc == EOK) {
89 printf(NAME ": registered child device `%s'\n",
90 vfun->name);
91 } else {
92 printf(NAME ": failed to register child device `%s': %s\n",
93 vfun->name, str_error(rc));
94 }
95
96 return rc;
97}
98
99static int add_device(device_t *dev)
100{
101 static int instances = 0;
102
103 /*
104 * Allow only single instance of root virtual device.
105 */
106 instances++;
107 if (instances > 1) {
108 return ELIMIT;
109 }
110
111 printf(NAME ": add_device(handle=%d)\n", (int)dev->handle);
112
113 /*
114 * Go through all virtual functions and try to add them.
115 * We silently ignore failures.
116 */
117 virtual_function_t *vfun = virtual_functions;
118 while (vfun->name != NULL) {
119 (void) add_child(dev, vfun);
120 vfun++;
121 }
122
123 return EOK;
124}
125
126int main(int argc, char *argv[])
127{
128 printf(NAME ": HelenOS virtual devices root driver\n");
129 return driver_main(&rootvirt_driver);
130}
131
132/**
133 * @}
134 */
135
Note: See TracBrowser for help on using the repository browser.