source: mainline/uspace/drv/infrastructure/rootvirt/rootvirt.c@ 1a5b252

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

DDF support for function offlining and onlining. This allows
(anticipated) hot removal — support needs to be added in individual
drivers, currently there is support in test1 and partially in rootvirt.
Surprise removal is not supported. TODO synchronization.

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