source: mainline/uspace/srv/devman/devman.h@ a60e90b

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

Move rest of functionality from devman.c to other modules.

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 * Copyright (c) 2010 Lenka Trochtova
3 * Copyright (c) 2011 Jiri Svoboda
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/** @addtogroup devman
31 * @{
32 */
33
34#ifndef DEVMAN_H_
35#define DEVMAN_H_
36
37#include <stdbool.h>
38#include <adt/list.h>
39#include <adt/hash_table.h>
40#include <ipc/devman.h>
41#include <ipc/loc.h>
42#include <fibril_synch.h>
43#include <atomic.h>
44#include <async.h>
45
46#include "util.h"
47
48#define NAME "devman"
49
50#define LOC_DEVICE_NAMESPACE "devices"
51#define LOC_SEPARATOR '\\'
52
53struct dev_node;
54typedef struct dev_node dev_node_t;
55
56struct fun_node;
57typedef struct fun_node fun_node_t;
58
59typedef struct {
60 fibril_mutex_t mutex;
61 struct driver *driver;
62} client_t;
63
64typedef enum {
65 /** Driver has not been started. */
66 DRIVER_NOT_STARTED = 0,
67
68 /**
69 * Driver has been started, but has not registered as running and ready
70 * to receive requests.
71 */
72 DRIVER_STARTING,
73
74 /** Driver is running and prepared to serve incomming requests. */
75 DRIVER_RUNNING
76} driver_state_t;
77
78/** Representation of device driver. */
79typedef struct driver {
80 /** Pointers to previous and next drivers in a linked list. */
81 link_t drivers;
82
83 /**
84 * Specifies whether the driver has been started and wheter is running
85 * and prepared to receive requests.
86 */
87 int state;
88
89 /** Session asociated with this driver. */
90 async_sess_t *sess;
91 /** Name of the device driver. */
92 char *name;
93 /** Path to the driver's binary. */
94 const char *binary_path;
95 /** List of device ids for device-to-driver matching. */
96 match_id_list_t match_ids;
97 /** List of devices controlled by this driver. */
98 list_t devices;
99
100 /**
101 * Fibril mutex for this driver - driver state, list of devices, session.
102 */
103 fibril_mutex_t driver_mutex;
104} driver_t;
105
106/** The list of drivers. */
107typedef struct driver_list {
108 /** List of drivers */
109 list_t drivers;
110 /** Fibril mutex for list of drivers. */
111 fibril_mutex_t drivers_mutex;
112} driver_list_t;
113
114/** Device state */
115typedef enum {
116 DEVICE_NOT_INITIALIZED = 0,
117 DEVICE_USABLE,
118 DEVICE_NOT_PRESENT,
119 DEVICE_INVALID,
120 /** Device node has been removed from the tree */
121 DEVICE_REMOVED
122} device_state_t;
123
124/** Device node in the device tree. */
125struct dev_node {
126 /** Reference count */
127 atomic_t refcnt;
128
129 /** The global unique identifier of the device. */
130 devman_handle_t handle;
131
132 /** (Parent) function the device is attached to. */
133 fun_node_t *pfun;
134
135 /** List of device functions. */
136 list_t functions;
137 /** Driver of this device. */
138 driver_t *drv;
139 /** The state of the device. */
140 device_state_t state;
141 /** Link to list of devices owned by driver (driver_t.devices) */
142 link_t driver_devices;
143
144 /**
145 * Used by the hash table of devices indexed by devman device handles.
146 */
147 ht_link_t devman_dev;
148
149 /**
150 * Whether this device was already passed to the driver.
151 */
152 bool passed_to_driver;
153};
154
155/** Function state */
156typedef enum {
157 FUN_INIT = 0,
158 FUN_OFF_LINE,
159 FUN_ON_LINE,
160 /** Function node has been removed from the tree */
161 FUN_REMOVED
162} fun_state_t;
163
164/** Function node in the device tree. */
165struct fun_node {
166 /** Reference count */
167 atomic_t refcnt;
168 /** State */
169 fun_state_t state;
170 /** Locked while performing reconfiguration operations */
171 fibril_mutex_t busy_lock;
172
173 /** The global unique identifier of the function */
174 devman_handle_t handle;
175 /** Name of the function, assigned by the device driver */
176 char *name;
177 /** Function type */
178 fun_type_t ftype;
179
180 /** Full path and name of the device in device hierarchy */
181 char *pathname;
182
183 /** Device which this function belongs to */
184 dev_node_t *dev;
185
186 /** Link to list of functions in the device (ddf_dev_t.functions) */
187 link_t dev_functions;
188
189 /** Child device node (if any attached). */
190 dev_node_t *child;
191 /** List of device ids for device-to-driver matching. */
192 match_id_list_t match_ids;
193
194 /** Service ID if the device function is registered with loc. */
195 service_id_t service_id;
196
197 /**
198 * Used by the hash table of functions indexed by devman device handles.
199 */
200 ht_link_t devman_fun;
201
202 /**
203 * Used by the hash table of functions indexed by service IDs.
204 */
205 ht_link_t loc_fun;
206};
207
208/** Represents device tree. */
209typedef struct dev_tree {
210 /** Root device node. */
211 fun_node_t *root_node;
212
213 /**
214 * The next available handle - handles are assigned in a sequential
215 * manner.
216 */
217 devman_handle_t current_handle;
218
219 /** Synchronize access to the device tree. */
220 fibril_rwlock_t rwlock;
221
222 /** Hash table of all devices indexed by devman handles. */
223 hash_table_t devman_devices;
224
225 /** Hash table of all devices indexed by devman handles. */
226 hash_table_t devman_functions;
227
228 /**
229 * Hash table of services registered with location service, indexed by
230 * service IDs.
231 */
232 hash_table_t loc_functions;
233} dev_tree_t;
234
235#endif
236
237/** @}
238 */
Note: See TracBrowser for help on using the repository browser.