source: mainline/uspace/srv/devman/devman.h@ 903bac0a

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

Work on device removal:

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