source: mainline/uspace/drv/rootvirt/rootvirt.c@ 83a2f43

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

Rename bunch of stuff so that it starts with 'ddf_'.

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[6f9e7fea]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
[8b1e15ac]45/** Virtual function entry */
[6f9e7fea]46typedef struct {
[8b1e15ac]47 /** Function name */
[6f9e7fea]48 const char *name;
[8b1e15ac]49 /** Function match ID */
[6f9e7fea]50 const char *match_id;
[8b1e15ac]51} virtual_function_t;
[6f9e7fea]52
[8b1e15ac]53/** List of existing virtual functions */
54virtual_function_t virtual_functions[] = {
[6f9e7fea]55#include "devices.def"
[8b1e15ac]56 /* Terminating item */
[6f9e7fea]57 {
58 .name = NULL,
59 .match_id = NULL
60 }
61};
62
[83a2f43]63static int rootvirt_add_device(ddf_dev_t *dev);
[6f9e7fea]64
65static driver_ops_t rootvirt_ops = {
[68414f4a]66 .add_device = &rootvirt_add_device
[6f9e7fea]67};
68
69static driver_t rootvirt_driver = {
70 .name = NAME,
71 .driver_ops = &rootvirt_ops
72};
73
[8b1e15ac]74/** Add function to the virtual device.
[6f9e7fea]75 *
[8b1e15ac]76 * @param vdev The virtual device
77 * @param vfun Virtual function description
78 * @return EOK on success or negative error code.
[6f9e7fea]79 */
[83a2f43]80static int rootvirt_add_fun(ddf_dev_t *vdev, virtual_function_t *vfun)
[6f9e7fea]81{
[83a2f43]82 ddf_fun_t *fun;
[cd0684d]83 int rc;
84
[8b1e15ac]85 printf(NAME ": registering function `%s' (match \"%s\")\n",
86 vfun->name, vfun->match_id);
[6f9e7fea]87
[cd0684d]88 fun = ddf_fun_create(vdev, fun_inner, vfun->name);
89 if (fun == NULL) {
90 printf(NAME ": error creating function %s\n", vfun->name);
91 return ENOMEM;
92 }
[6f9e7fea]93
[cd0684d]94 rc = ddf_fun_add_match_id(fun, vfun->match_id, 10);
95 if (rc != EOK) {
96 printf(NAME ": error adding match IDs to function %s\n",
[8b1e15ac]97 vfun->name);
[cd0684d]98 ddf_fun_destroy(fun);
99 return rc;
[6f9e7fea]100 }
101
[cd0684d]102 rc = ddf_fun_bind(fun);
103 if (rc != EOK) {
104 printf(NAME ": error binding function %s: %s\n", vfun->name,
105 str_error(rc));
106 ddf_fun_destroy(fun);
107 return rc;
108 }
109
110 printf(NAME ": registered child device `%s'\n", vfun->name);
111 return EOK;
[6f9e7fea]112}
113
[83a2f43]114static int rootvirt_add_device(ddf_dev_t *dev)
[6f9e7fea]115{
116 static int instances = 0;
117
118 /*
119 * Allow only single instance of root virtual device.
120 */
121 instances++;
122 if (instances > 1) {
123 return ELIMIT;
124 }
125
[8b1e15ac]126 printf(NAME ": add_device(handle=%d)\n", (int)dev->handle);
[bab6388]127
[6f9e7fea]128 /*
[8b1e15ac]129 * Go through all virtual functions and try to add them.
[6f9e7fea]130 * We silently ignore failures.
131 */
[8b1e15ac]132 virtual_function_t *vfun = virtual_functions;
133 while (vfun->name != NULL) {
[68414f4a]134 (void) rootvirt_add_fun(dev, vfun);
[8b1e15ac]135 vfun++;
[6f9e7fea]136 }
137
138 return EOK;
139}
140
141int main(int argc, char *argv[])
142{
143 printf(NAME ": HelenOS virtual devices root driver\n");
[83a2f43]144 return ddf_driver_main(&rootvirt_driver);
[6f9e7fea]145}
146
147/**
148 * @}
149 */
150
Note: See TracBrowser for help on using the repository browser.