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

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

Move dev-node related devman functionality to a separate module.

  • Property mode set to 100644
File size: 7.5 KB
RevLine 
[e2b9a993]1/*
2 * Copyright (c) 2010 Lenka Trochtova
[d0dd7b5]3 * Copyright (c) 2011 Jiri Svoboda
[e2b9a993]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 */
[08d9c4e6]33
[e2b9a993]34#ifndef DEVMAN_H_
35#define DEVMAN_H_
36
[3e6a98c5]37#include <stdbool.h>
[e2b9a993]38#include <adt/list.h>
[957cfa58]39#include <adt/hash_table.h>
[bda60d9]40#include <ipc/devman.h>
[15f3c3f]41#include <ipc/loc.h>
[e85920d]42#include <fibril_synch.h>
[084ff99]43#include <atomic.h>
[79ae36dd]44#include <async.h>
[e2b9a993]45
[08d9c4e6]46#include "util.h"
[e2b9a993]47
48#define NAME "devman"
49
50#define MATCH_EXT ".ma"
51
[15f3c3f]52#define LOC_DEVICE_NAMESPACE "devices"
53#define LOC_SEPARATOR '\\'
[ce89036b]54
[ba38f72c]55struct dev_node;
56typedef struct dev_node dev_node_t;
57
58struct fun_node;
59typedef struct fun_node fun_node_t;
[e2b9a993]60
[422722e]61typedef struct {
62 fibril_mutex_t mutex;
63 struct driver *driver;
64} client_t;
65
[e85920d]66typedef enum {
[38b3baf]67 /** Driver has not been started. */
[e85920d]68 DRIVER_NOT_STARTED = 0,
[38b3baf]69
70 /**
71 * Driver has been started, but has not registered as running and ready
72 * to receive requests.
73 */
[e85920d]74 DRIVER_STARTING,
[38b3baf]75
76 /** Driver is running and prepared to serve incomming requests. */
[e85920d]77 DRIVER_RUNNING
78} driver_state_t;
79
[38b3baf]80/** Representation of device driver. */
[e2b9a993]81typedef struct driver {
[38b3baf]82 /** Pointers to previous and next drivers in a linked list. */
[e2b9a993]83 link_t drivers;
[38b3baf]84
85 /**
86 * Specifies whether the driver has been started and wheter is running
87 * and prepared to receive requests.
88 */
[e85920d]89 int state;
[38b3baf]90
[79ae36dd]91 /** Session asociated with this driver. */
92 async_sess_t *sess;
[38b3baf]93 /** Name of the device driver. */
[e2b9a993]94 char *name;
[38b3baf]95 /** Path to the driver's binary. */
[e2b9a993]96 const char *binary_path;
[38b3baf]97 /** List of device ids for device-to-driver matching. */
[e2b9a993]98 match_id_list_t match_ids;
[b72efe8]99 /** List of devices controlled by this driver. */
100 list_t devices;
[38b3baf]101
102 /**
[79ae36dd]103 * Fibril mutex for this driver - driver state, list of devices, session.
[38b3baf]104 */
[e85920d]105 fibril_mutex_t driver_mutex;
[e2b9a993]106} driver_t;
107
[e85920d]108/** The list of drivers. */
109typedef struct driver_list {
110 /** List of drivers */
[b72efe8]111 list_t drivers;
[e85920d]112 /** Fibril mutex for list of drivers. */
[38b3baf]113 fibril_mutex_t drivers_mutex;
[e85920d]114} driver_list_t;
115
[c1a0488]116/** Device state */
[df747b9c]117typedef enum {
118 DEVICE_NOT_INITIALIZED = 0,
119 DEVICE_USABLE,
120 DEVICE_NOT_PRESENT,
[c1a0488]121 DEVICE_INVALID,
122 /** Device node has been removed from the tree */
123 DEVICE_REMOVED
[df747b9c]124} device_state_t;
125
[ba38f72c]126/** Device node in the device tree. */
127struct dev_node {
[58cbb0c8]128 /** Reference count */
129 atomic_t refcnt;
130
[38b3baf]131 /** The global unique identifier of the device. */
[0b5a4131]132 devman_handle_t handle;
[ba38f72c]133
134 /** (Parent) function the device is attached to. */
135 fun_node_t *pfun;
136
137 /** List of device functions. */
[b72efe8]138 list_t functions;
[ba38f72c]139 /** Driver of this device. */
140 driver_t *drv;
141 /** The state of the device. */
142 device_state_t state;
143 /** Link to list of devices owned by driver (driver_t.devices) */
144 link_t driver_devices;
[38b3baf]145
146 /**
[ba38f72c]147 * Used by the hash table of devices indexed by devman device handles.
[38b3baf]148 */
[062d900]149 ht_link_t devman_dev;
[38b3baf]150
151 /**
[ba38f72c]152 * Whether this device was already passed to the driver.
[38b3baf]153 */
[ba38f72c]154 bool passed_to_driver;
155};
156
[c1a0488]157/** Function state */
158typedef enum {
159 FUN_INIT = 0,
160 FUN_OFF_LINE,
161 FUN_ON_LINE,
162 /** Function node has been removed from the tree */
163 FUN_REMOVED
164} fun_state_t;
165
[ba38f72c]166/** Function node in the device tree. */
167struct fun_node {
[58cbb0c8]168 /** Reference count */
169 atomic_t refcnt;
[c1a0488]170 /** State */
171 fun_state_t state;
[4820360]172 /** Locked while performing reconfiguration operations */
173 fibril_mutex_t busy_lock;
[58cbb0c8]174
[ba38f72c]175 /** The global unique identifier of the function */
176 devman_handle_t handle;
177 /** Name of the function, assigned by the device driver */
178 char *name;
[d0dd7b5]179 /** Function type */
180 fun_type_t ftype;
[ba38f72c]181
182 /** Full path and name of the device in device hierarchy */
183 char *pathname;
184
185 /** Device which this function belongs to */
186 dev_node_t *dev;
[38b3baf]187
[83a2f43]188 /** Link to list of functions in the device (ddf_dev_t.functions) */
[ba38f72c]189 link_t dev_functions;
190
191 /** Child device node (if any attached). */
192 dev_node_t *child;
[38b3baf]193 /** List of device ids for device-to-driver matching. */
[08d9c4e6]194 match_id_list_t match_ids;
[38b3baf]195
[15f3c3f]196 /** Service ID if the device function is registered with loc. */
197 service_id_t service_id;
[38b3baf]198
199 /**
[ba38f72c]200 * Used by the hash table of functions indexed by devman device handles.
[38b3baf]201 */
[062d900]202 ht_link_t devman_fun;
[38b3baf]203
204 /**
[15f3c3f]205 * Used by the hash table of functions indexed by service IDs.
[5bee897]206 */
[062d900]207 ht_link_t loc_fun;
[e2b9a993]208};
209
[38b3baf]210/** Represents device tree. */
[e2b9a993]211typedef struct dev_tree {
212 /** Root device node. */
[ba38f72c]213 fun_node_t *root_node;
[38b3baf]214
215 /**
216 * The next available handle - handles are assigned in a sequential
217 * manner.
218 */
[0b5a4131]219 devman_handle_t current_handle;
[38b3baf]220
221 /** Synchronize access to the device tree. */
[957cfa58]222 fibril_rwlock_t rwlock;
[38b3baf]223
224 /** Hash table of all devices indexed by devman handles. */
[957cfa58]225 hash_table_t devman_devices;
[38b3baf]226
[ba38f72c]227 /** Hash table of all devices indexed by devman handles. */
228 hash_table_t devman_functions;
229
[38b3baf]230 /**
[15f3c3f]231 * Hash table of services registered with location service, indexed by
232 * service IDs.
[38b3baf]233 */
[15f3c3f]234 hash_table_t loc_functions;
[e2b9a993]235} dev_tree_t;
236
[38b3baf]237/* Match ids and scores */
[e2b9a993]238
[ba38f72c]239extern int get_match_score(driver_t *, dev_node_t *);
[e2b9a993]240
[38b3baf]241extern bool parse_match_ids(char *, match_id_list_t *);
242extern bool read_match_ids(const char *, match_id_list_t *);
243extern char *read_match_id(char **);
244extern char *read_id(const char **);
[729fa2d6]245
[d1bafbf]246/* Function nodes */
[ba38f72c]247
248extern fun_node_t *create_fun_node(void);
249extern void delete_fun_node(fun_node_t *);
[58cbb0c8]250extern void fun_add_ref(fun_node_t *);
251extern void fun_del_ref(fun_node_t *);
[4820360]252extern void fun_busy_lock(fun_node_t *);
253extern void fun_busy_unlock(fun_node_t *);
[ba38f72c]254extern fun_node_t *find_fun_node_no_lock(dev_tree_t *tree,
[0b5a4131]255 devman_handle_t handle);
[ba38f72c]256extern fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle);
257extern fun_node_t *find_fun_node_by_path(dev_tree_t *, char *);
[58cbb0c8]258extern fun_node_t *find_fun_node_in_device(dev_tree_t *tree, dev_node_t *,
259 const char *);
[38b3baf]260
261/* Device tree */
[5cd136ab]262
[38b3baf]263extern bool init_device_tree(dev_tree_t *, driver_list_t *);
[ba38f72c]264extern bool create_root_nodes(dev_tree_t *);
265extern bool insert_dev_node(dev_tree_t *, dev_node_t *, fun_node_t *);
[1a5b252]266extern void remove_dev_node(dev_tree_t *, dev_node_t *);
[ba38f72c]267extern bool insert_fun_node(dev_tree_t *, fun_node_t *, char *, dev_node_t *);
[d0dd7b5]268extern void remove_fun_node(dev_tree_t *, fun_node_t *);
[e2b9a993]269
[15f3c3f]270/* Loc services */
[ce89036b]271
[15f3c3f]272extern void loc_register_tree_function(fun_node_t *, dev_tree_t *);
[8b1e15ac]273
[15f3c3f]274extern fun_node_t *find_loc_tree_function(dev_tree_t *, service_id_t);
[a32defa]275
[15f3c3f]276extern void tree_add_loc_function(dev_tree_t *, fun_node_t *);
[a32defa]277
[e2b9a993]278#endif
[c16cf62]279
280/** @}
[38b3baf]281 */
Note: See TracBrowser for help on using the repository browser.