[e2b9a993] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Lenka Trochtova
|
---|
| 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 | /** @addtogroup devman
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
[08d9c4e6] | 32 |
|
---|
[e2b9a993] | 33 | #ifndef DEVMAN_H_
|
---|
| 34 | #define DEVMAN_H_
|
---|
| 35 |
|
---|
| 36 | #include <assert.h>
|
---|
| 37 | #include <bool.h>
|
---|
| 38 | #include <dirent.h>
|
---|
[c47e1a8] | 39 | #include <str.h>
|
---|
[e2b9a993] | 40 | #include <adt/list.h>
|
---|
[957cfa58] | 41 | #include <adt/hash_table.h>
|
---|
[e2b9a993] | 42 | #include <ipc/ipc.h>
|
---|
[bda60d9] | 43 | #include <ipc/devman.h>
|
---|
[d51ee2b] | 44 | #include <ipc/devmap.h>
|
---|
[e85920d] | 45 | #include <fibril_synch.h>
|
---|
[084ff99] | 46 | #include <atomic.h>
|
---|
[e2b9a993] | 47 |
|
---|
[08d9c4e6] | 48 | #include "util.h"
|
---|
[e2b9a993] | 49 |
|
---|
| 50 | #define NAME "devman"
|
---|
| 51 |
|
---|
| 52 | #define MATCH_EXT ".ma"
|
---|
[957cfa58] | 53 | #define DEVICE_BUCKETS 256
|
---|
[e2b9a993] | 54 |
|
---|
[ce89036b] | 55 | #define DEVMAP_CLASS_NAMESPACE "class"
|
---|
| 56 | #define DEVMAP_DEVICE_NAMESPACE "devices"
|
---|
[a32defa] | 57 | #define DEVMAP_SEPARATOR '\\'
|
---|
[ce89036b] | 58 |
|
---|
[e2b9a993] | 59 | struct node;
|
---|
| 60 | typedef struct node node_t;
|
---|
| 61 |
|
---|
[e85920d] | 62 | typedef enum {
|
---|
[38b3baf] | 63 | /** Driver has not been started. */
|
---|
[e85920d] | 64 | DRIVER_NOT_STARTED = 0,
|
---|
[38b3baf] | 65 |
|
---|
| 66 | /**
|
---|
| 67 | * Driver has been started, but has not registered as running and ready
|
---|
| 68 | * to receive requests.
|
---|
| 69 | */
|
---|
[e85920d] | 70 | DRIVER_STARTING,
|
---|
[38b3baf] | 71 |
|
---|
| 72 | /** Driver is running and prepared to serve incomming requests. */
|
---|
[e85920d] | 73 | DRIVER_RUNNING
|
---|
| 74 | } driver_state_t;
|
---|
| 75 |
|
---|
[38b3baf] | 76 | /** Representation of device driver. */
|
---|
[e2b9a993] | 77 | typedef struct driver {
|
---|
[38b3baf] | 78 | /** Pointers to previous and next drivers in a linked list. */
|
---|
[e2b9a993] | 79 | link_t drivers;
|
---|
[38b3baf] | 80 |
|
---|
| 81 | /**
|
---|
| 82 | * Specifies whether the driver has been started and wheter is running
|
---|
| 83 | * and prepared to receive requests.
|
---|
| 84 | */
|
---|
[e85920d] | 85 | int state;
|
---|
[38b3baf] | 86 |
|
---|
| 87 | /** Phone asociated with this driver. */
|
---|
[e2b9a993] | 88 | ipcarg_t phone;
|
---|
[38b3baf] | 89 | /** Name of the device driver. */
|
---|
[e2b9a993] | 90 | char *name;
|
---|
[38b3baf] | 91 | /** Path to the driver's binary. */
|
---|
[e2b9a993] | 92 | const char *binary_path;
|
---|
[38b3baf] | 93 | /** List of device ids for device-to-driver matching. */
|
---|
[e2b9a993] | 94 | match_id_list_t match_ids;
|
---|
[38b3baf] | 95 | /** Pointer to the linked list of devices controlled by this driver. */
|
---|
[e2b9a993] | 96 | link_t devices;
|
---|
[38b3baf] | 97 |
|
---|
| 98 | /**
|
---|
| 99 | * Fibril mutex for this driver - driver state, list of devices, phone.
|
---|
| 100 | */
|
---|
[e85920d] | 101 | fibril_mutex_t driver_mutex;
|
---|
[e2b9a993] | 102 | } driver_t;
|
---|
| 103 |
|
---|
[e85920d] | 104 | /** The list of drivers. */
|
---|
| 105 | typedef struct driver_list {
|
---|
| 106 | /** List of drivers */
|
---|
| 107 | link_t drivers;
|
---|
| 108 | /** Fibril mutex for list of drivers. */
|
---|
[38b3baf] | 109 | fibril_mutex_t drivers_mutex;
|
---|
[e85920d] | 110 | } driver_list_t;
|
---|
| 111 |
|
---|
[df747b9c] | 112 | /** The state of the device. */
|
---|
| 113 | typedef enum {
|
---|
| 114 | DEVICE_NOT_INITIALIZED = 0,
|
---|
| 115 | DEVICE_USABLE,
|
---|
| 116 | DEVICE_NOT_PRESENT,
|
---|
| 117 | DEVICE_INVALID
|
---|
| 118 | } device_state_t;
|
---|
| 119 |
|
---|
[38b3baf] | 120 | /** Representation of a node in the device tree. */
|
---|
[e2b9a993] | 121 | struct node {
|
---|
[38b3baf] | 122 | /** The global unique identifier of the device. */
|
---|
[bda60d9] | 123 | device_handle_t handle;
|
---|
| 124 | /** The name of the device specified by its parent. */
|
---|
| 125 | char *name;
|
---|
[38b3baf] | 126 |
|
---|
| 127 | /**
|
---|
| 128 | * Full path and name of the device in device hierarchi (i. e. in full
|
---|
| 129 | * path in device tree).
|
---|
| 130 | */
|
---|
| 131 | char *pathname;
|
---|
| 132 |
|
---|
[e2b9a993] | 133 | /** The node of the parent device. */
|
---|
| 134 | node_t *parent;
|
---|
[38b3baf] | 135 |
|
---|
| 136 | /**
|
---|
| 137 | * Pointers to previous and next child devices in the linked list of
|
---|
| 138 | * parent device's node.
|
---|
| 139 | */
|
---|
[08d9c4e6] | 140 | link_t sibling;
|
---|
[38b3baf] | 141 |
|
---|
[e2b9a993] | 142 | /** List of child device nodes. */
|
---|
| 143 | link_t children;
|
---|
[38b3baf] | 144 | /** List of device ids for device-to-driver matching. */
|
---|
[08d9c4e6] | 145 | match_id_list_t match_ids;
|
---|
[38b3baf] | 146 | /** Driver of this device. */
|
---|
[08d9c4e6] | 147 | driver_t *drv;
|
---|
[df747b9c] | 148 | /** The state of the device. */
|
---|
| 149 | device_state_t state;
|
---|
[38b3baf] | 150 | /**
|
---|
| 151 | * Pointer to the previous and next device in the list of devices
|
---|
| 152 | * owned by one driver.
|
---|
| 153 | */
|
---|
[08d9c4e6] | 154 | link_t driver_devices;
|
---|
[38b3baf] | 155 |
|
---|
| 156 | /** The list of device classes to which this device belongs. */
|
---|
[d51ee2b] | 157 | link_t classes;
|
---|
[957cfa58] | 158 | /** Devmap handle if the device is registered by devmapper. */
|
---|
| 159 | dev_handle_t devmap_handle;
|
---|
[38b3baf] | 160 |
|
---|
| 161 | /**
|
---|
| 162 | * Used by the hash table of devices indexed by devman device handles.
|
---|
| 163 | */
|
---|
[957cfa58] | 164 | link_t devman_link;
|
---|
[38b3baf] | 165 |
|
---|
| 166 | /**
|
---|
| 167 | * Used by the hash table of devices indexed by devmap device handles.
|
---|
| 168 | */
|
---|
[957cfa58] | 169 | link_t devmap_link;
|
---|
[e2b9a993] | 170 | };
|
---|
| 171 |
|
---|
[38b3baf] | 172 | /** Represents device tree. */
|
---|
[e2b9a993] | 173 | typedef struct dev_tree {
|
---|
| 174 | /** Root device node. */
|
---|
| 175 | node_t *root_node;
|
---|
[38b3baf] | 176 |
|
---|
| 177 | /**
|
---|
| 178 | * The next available handle - handles are assigned in a sequential
|
---|
| 179 | * manner.
|
---|
| 180 | */
|
---|
[957cfa58] | 181 | device_handle_t current_handle;
|
---|
[38b3baf] | 182 |
|
---|
| 183 | /** Synchronize access to the device tree. */
|
---|
[957cfa58] | 184 | fibril_rwlock_t rwlock;
|
---|
[38b3baf] | 185 |
|
---|
| 186 | /** Hash table of all devices indexed by devman handles. */
|
---|
[957cfa58] | 187 | hash_table_t devman_devices;
|
---|
[38b3baf] | 188 |
|
---|
| 189 | /**
|
---|
| 190 | * Hash table of devices registered by devmapper, indexed by devmap
|
---|
| 191 | * handles.
|
---|
| 192 | */
|
---|
[957cfa58] | 193 | hash_table_t devmap_devices;
|
---|
[e2b9a993] | 194 | } dev_tree_t;
|
---|
| 195 |
|
---|
[38b3baf] | 196 | typedef struct dev_class {
|
---|
| 197 | /** The name of the class. */
|
---|
[d51ee2b] | 198 | const char *name;
|
---|
[38b3baf] | 199 |
|
---|
| 200 | /**
|
---|
| 201 | * Pointer to the previous and next class in the list of registered
|
---|
| 202 | * classes.
|
---|
| 203 | */
|
---|
| 204 | link_t link;
|
---|
| 205 |
|
---|
| 206 | /**
|
---|
| 207 | * List of dev_class_info structures - one for each device registered by
|
---|
| 208 | * this class.
|
---|
| 209 | */
|
---|
[692c40cb] | 210 | link_t devices;
|
---|
[38b3baf] | 211 |
|
---|
| 212 | /**
|
---|
| 213 | * Default base name for the device within the class, might be overrided
|
---|
| 214 | * by the driver.
|
---|
| 215 | */
|
---|
[d51ee2b] | 216 | const char *base_dev_name;
|
---|
[38b3baf] | 217 |
|
---|
| 218 | /** Unique numerical identifier of the newly added device. */
|
---|
[d51ee2b] | 219 | size_t curr_dev_idx;
|
---|
| 220 | /** Synchronize access to the list of devices in this class. */
|
---|
| 221 | fibril_mutex_t mutex;
|
---|
| 222 | } dev_class_t;
|
---|
| 223 |
|
---|
[38b3baf] | 224 | /** Provides n-to-m mapping between device nodes and classes - each device may
|
---|
| 225 | * be register to the arbitrary number of classes and each class may contain
|
---|
| 226 | * the arbitrary number of devices.
|
---|
| 227 | */
|
---|
[d51ee2b] | 228 | typedef struct dev_class_info {
|
---|
[38b3baf] | 229 | /** The class. */
|
---|
[d51ee2b] | 230 | dev_class_t *dev_class;
|
---|
[38b3baf] | 231 | /** The device. */
|
---|
[d51ee2b] | 232 | node_t *dev;
|
---|
[38b3baf] | 233 |
|
---|
| 234 | /**
|
---|
| 235 | * Pointer to the previous and next class info in the list of devices
|
---|
| 236 | * registered by the class.
|
---|
| 237 | */
|
---|
[d51ee2b] | 238 | link_t link;
|
---|
[38b3baf] | 239 |
|
---|
| 240 | /**
|
---|
| 241 | * Pointer to the previous and next class info in the list of classes
|
---|
| 242 | * by which the device is registered.
|
---|
| 243 | */
|
---|
[d51ee2b] | 244 | link_t dev_classes;
|
---|
[38b3baf] | 245 |
|
---|
| 246 | /** The name of the device within the class. */
|
---|
| 247 | char *dev_name;
|
---|
| 248 | /** The handle of the device by device mapper in the class namespace. */
|
---|
[d51ee2b] | 249 | dev_handle_t devmap_handle;
|
---|
[38b3baf] | 250 |
|
---|
| 251 | /**
|
---|
| 252 | * Link in the hash table of devices registered by the devmapper using
|
---|
| 253 | * their class names.
|
---|
| 254 | */
|
---|
[ce89036b] | 255 | link_t devmap_link;
|
---|
[d51ee2b] | 256 | } dev_class_info_t;
|
---|
[e2b9a993] | 257 |
|
---|
[692c40cb] | 258 | /** The list of device classes. */
|
---|
| 259 | typedef struct class_list {
|
---|
[38b3baf] | 260 | /** List of classes. */
|
---|
[692c40cb] | 261 | link_t classes;
|
---|
[38b3baf] | 262 |
|
---|
| 263 | /**
|
---|
| 264 | * Hash table of devices registered by devmapper using their class name,
|
---|
| 265 | * indexed by devmap handles.
|
---|
| 266 | */
|
---|
[ce89036b] | 267 | hash_table_t devmap_devices;
|
---|
[38b3baf] | 268 |
|
---|
[692c40cb] | 269 | /** Fibril mutex for list of classes. */
|
---|
[38b3baf] | 270 | fibril_rwlock_t rwlock;
|
---|
[692c40cb] | 271 | } class_list_t;
|
---|
| 272 |
|
---|
[38b3baf] | 273 | /* Match ids and scores */
|
---|
[e2b9a993] | 274 |
|
---|
[38b3baf] | 275 | extern int get_match_score(driver_t *, node_t *);
|
---|
[e2b9a993] | 276 |
|
---|
[38b3baf] | 277 | extern bool parse_match_ids(char *, match_id_list_t *);
|
---|
| 278 | extern bool read_match_ids(const char *, match_id_list_t *);
|
---|
| 279 | extern char *read_match_id(char **);
|
---|
| 280 | extern char *read_id(const char **);
|
---|
[729fa2d6] | 281 |
|
---|
[38b3baf] | 282 | /* Drivers */
|
---|
[0c3666d] | 283 |
|
---|
[38b3baf] | 284 | /**
|
---|
[d347b53] | 285 | * Initialize the list of device driver's.
|
---|
[38b3baf] | 286 | *
|
---|
[d347b53] | 287 | * @param drv_list the list of device driver's.
|
---|
[38b3baf] | 288 | *
|
---|
[d347b53] | 289 | */
|
---|
[38b3baf] | 290 | static inline void init_driver_list(driver_list_t *drv_list)
|
---|
[0c3666d] | 291 | {
|
---|
| 292 | assert(NULL != drv_list);
|
---|
| 293 |
|
---|
| 294 | list_initialize(&drv_list->drivers);
|
---|
[38b3baf] | 295 | fibril_mutex_initialize(&drv_list->drivers_mutex);
|
---|
[0c3666d] | 296 | }
|
---|
| 297 |
|
---|
[38b3baf] | 298 | extern driver_t *create_driver(void);
|
---|
| 299 | extern bool get_driver_info(const char *, const char *, driver_t *);
|
---|
| 300 | extern int lookup_available_drivers(driver_list_t *, const char *);
|
---|
[e2b9a993] | 301 |
|
---|
[38b3baf] | 302 | extern driver_t *find_best_match_driver(driver_list_t *, node_t *);
|
---|
| 303 | extern bool assign_driver(node_t *, driver_list_t *, dev_tree_t *);
|
---|
[e2b9a993] | 304 |
|
---|
[38b3baf] | 305 | extern void add_driver(driver_list_t *, driver_t *);
|
---|
| 306 | extern void attach_driver(node_t *, driver_t *);
|
---|
| 307 | extern void add_device(int, driver_t *, node_t *, dev_tree_t *);
|
---|
| 308 | extern bool start_driver(driver_t *);
|
---|
[e2b9a993] | 309 |
|
---|
[38b3baf] | 310 | extern driver_t *find_driver(driver_list_t *, const char *);
|
---|
| 311 | extern void set_driver_phone(driver_t *, ipcarg_t);
|
---|
| 312 | void initialize_running_driver(driver_t *, dev_tree_t *);
|
---|
[729fa2d6] | 313 |
|
---|
[38b3baf] | 314 | /** Initialize device driver structure.
|
---|
| 315 | *
|
---|
| 316 | * @param drv The device driver structure.
|
---|
[d347b53] | 317 | */
|
---|
[08d9c4e6] | 318 | static inline void init_driver(driver_t *drv)
|
---|
[e2b9a993] | 319 | {
|
---|
[08d9c4e6] | 320 | assert(drv != NULL);
|
---|
| 321 |
|
---|
| 322 | memset(drv, 0, sizeof(driver_t));
|
---|
[e2b9a993] | 323 | list_initialize(&drv->match_ids.ids);
|
---|
| 324 | list_initialize(&drv->devices);
|
---|
[38b3baf] | 325 | fibril_mutex_initialize(&drv->driver_mutex);
|
---|
[e2b9a993] | 326 | }
|
---|
| 327 |
|
---|
[38b3baf] | 328 | /** Device driver structure clean-up.
|
---|
| 329 | *
|
---|
| 330 | * @param drv The device driver structure.
|
---|
[d347b53] | 331 | */
|
---|
[08d9c4e6] | 332 | static inline void clean_driver(driver_t *drv)
|
---|
[e2b9a993] | 333 | {
|
---|
| 334 | assert(drv != NULL);
|
---|
[08d9c4e6] | 335 |
|
---|
| 336 | free_not_null(drv->name);
|
---|
[38b3baf] | 337 | free_not_null(drv->binary_path);
|
---|
[08d9c4e6] | 338 |
|
---|
[e2b9a993] | 339 | clean_match_ids(&drv->match_ids);
|
---|
[08d9c4e6] | 340 |
|
---|
| 341 | init_driver(drv);
|
---|
[e2b9a993] | 342 | }
|
---|
| 343 |
|
---|
[38b3baf] | 344 | /** Delete device driver structure.
|
---|
| 345 | *
|
---|
| 346 | * @param drv The device driver structure.
|
---|
[d347b53] | 347 | */
|
---|
[08d9c4e6] | 348 | static inline void delete_driver(driver_t *drv)
|
---|
[e2b9a993] | 349 | {
|
---|
[08d9c4e6] | 350 | assert(NULL != drv);
|
---|
| 351 |
|
---|
[e2b9a993] | 352 | clean_driver(drv);
|
---|
| 353 | free(drv);
|
---|
| 354 | }
|
---|
| 355 |
|
---|
[38b3baf] | 356 |
|
---|
| 357 | /* Device nodes */
|
---|
| 358 |
|
---|
| 359 | /** Create a new device node.
|
---|
| 360 | *
|
---|
| 361 | * @return A device node structure.
|
---|
[d347b53] | 362 | */
|
---|
[38b3baf] | 363 | static inline node_t *create_dev_node(void)
|
---|
[e2b9a993] | 364 | {
|
---|
| 365 | node_t *res = malloc(sizeof(node_t));
|
---|
[692c40cb] | 366 |
|
---|
[e2b9a993] | 367 | if (res != NULL) {
|
---|
[08d9c4e6] | 368 | memset(res, 0, sizeof(node_t));
|
---|
[692c40cb] | 369 | list_initialize(&res->children);
|
---|
| 370 | list_initialize(&res->match_ids.ids);
|
---|
| 371 | list_initialize(&res->classes);
|
---|
[e2b9a993] | 372 | }
|
---|
[084ff99] | 373 |
|
---|
[e2b9a993] | 374 | return res;
|
---|
| 375 | }
|
---|
| 376 |
|
---|
[38b3baf] | 377 | /** Delete a device node.
|
---|
| 378 | *
|
---|
| 379 | * @param node The device node structure.
|
---|
[5cd136ab] | 380 | */
|
---|
[d347b53] | 381 | static inline void delete_dev_node(node_t *node)
|
---|
| 382 | {
|
---|
[38b3baf] | 383 | assert(list_empty(&node->children));
|
---|
| 384 | assert(NULL == node->parent);
|
---|
| 385 | assert(NULL == node->drv);
|
---|
[d347b53] | 386 |
|
---|
| 387 | clean_match_ids(&node->match_ids);
|
---|
| 388 | free_not_null(node->name);
|
---|
| 389 | free_not_null(node->pathname);
|
---|
[38b3baf] | 390 | free(node);
|
---|
[d347b53] | 391 | }
|
---|
| 392 |
|
---|
[38b3baf] | 393 | /** Find the device node structure of the device witch has the specified handle.
|
---|
| 394 | *
|
---|
[957cfa58] | 395 | * Device tree's rwlock should be held at least for reading.
|
---|
[38b3baf] | 396 | *
|
---|
| 397 | * @param tree The device tree where we look for the device node.
|
---|
| 398 | * @param handle The handle of the device.
|
---|
| 399 | * @return The device node.
|
---|
[d347b53] | 400 | */
|
---|
[38b3baf] | 401 | static inline node_t *
|
---|
| 402 | find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle)
|
---|
[e2b9a993] | 403 | {
|
---|
[957cfa58] | 404 | unsigned long key = handle;
|
---|
| 405 | link_t *link = hash_table_find(&tree->devman_devices, &key);
|
---|
| 406 | return hash_table_get_instance(link, node_t, devman_link);
|
---|
| 407 | }
|
---|
| 408 |
|
---|
[38b3baf] | 409 | /** Find the device node structure of the device witch has the specified handle.
|
---|
| 410 | *
|
---|
| 411 | * @param tree The device tree where we look for the device node.
|
---|
| 412 | * @param handle The handle of the device.
|
---|
| 413 | * @return The device node.
|
---|
[957cfa58] | 414 | */
|
---|
[38b3baf] | 415 | static inline node_t *
|
---|
| 416 | find_dev_node(dev_tree_t *tree, device_handle_t handle)
|
---|
[957cfa58] | 417 | {
|
---|
| 418 | node_t *node = NULL;
|
---|
| 419 |
|
---|
| 420 | fibril_rwlock_read_lock(&tree->rwlock);
|
---|
| 421 | node = find_dev_node_no_lock(tree, handle);
|
---|
| 422 | fibril_rwlock_read_unlock(&tree->rwlock);
|
---|
| 423 |
|
---|
| 424 | return node;
|
---|
[e2b9a993] | 425 | }
|
---|
| 426 |
|
---|
[38b3baf] | 427 | extern node_t *find_dev_node_by_path(dev_tree_t *, char *);
|
---|
| 428 | extern node_t *find_node_child(node_t *, const char *);
|
---|
| 429 |
|
---|
| 430 |
|
---|
| 431 | /* Device tree */
|
---|
[5cd136ab] | 432 |
|
---|
[38b3baf] | 433 | extern bool init_device_tree(dev_tree_t *, driver_list_t *);
|
---|
| 434 | extern bool create_root_node(dev_tree_t *);
|
---|
| 435 | extern bool insert_dev_node(dev_tree_t *, node_t *, char *, node_t *);
|
---|
[e2b9a993] | 436 |
|
---|
| 437 |
|
---|
[38b3baf] | 438 | /* Device classes */
|
---|
[d51ee2b] | 439 |
|
---|
[38b3baf] | 440 | /** Create device class.
|
---|
| 441 | *
|
---|
| 442 | * @return Device class.
|
---|
[d51ee2b] | 443 | */
|
---|
[38b3baf] | 444 | static inline dev_class_t *create_dev_class(void)
|
---|
[d51ee2b] | 445 | {
|
---|
[38b3baf] | 446 | dev_class_t *cl;
|
---|
| 447 |
|
---|
| 448 | cl = (dev_class_t *) malloc(sizeof(dev_class_t));
|
---|
[d51ee2b] | 449 | if (NULL != cl) {
|
---|
| 450 | memset(cl, 0, sizeof(dev_class_t));
|
---|
[692c40cb] | 451 | list_initialize(&cl->devices);
|
---|
[d51ee2b] | 452 | fibril_mutex_initialize(&cl->mutex);
|
---|
| 453 | }
|
---|
[38b3baf] | 454 |
|
---|
| 455 | return cl;
|
---|
[d51ee2b] | 456 | }
|
---|
| 457 |
|
---|
[38b3baf] | 458 | /** Create device class info.
|
---|
| 459 | *
|
---|
| 460 | * @return Device class info.
|
---|
[d51ee2b] | 461 | */
|
---|
[38b3baf] | 462 | static inline dev_class_info_t *create_dev_class_info(void)
|
---|
[d51ee2b] | 463 | {
|
---|
[38b3baf] | 464 | dev_class_info_t *info;
|
---|
| 465 |
|
---|
| 466 | info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
|
---|
| 467 | if (NULL != info)
|
---|
[d51ee2b] | 468 | memset(info, 0, sizeof(dev_class_info_t));
|
---|
[38b3baf] | 469 |
|
---|
| 470 | return info;
|
---|
[d51ee2b] | 471 | }
|
---|
| 472 |
|
---|
| 473 | static inline size_t get_new_class_dev_idx(dev_class_t *cl)
|
---|
| 474 | {
|
---|
| 475 | size_t dev_idx;
|
---|
[38b3baf] | 476 |
|
---|
[d51ee2b] | 477 | fibril_mutex_lock(&cl->mutex);
|
---|
| 478 | dev_idx = ++cl->curr_dev_idx;
|
---|
| 479 | fibril_mutex_unlock(&cl->mutex);
|
---|
[38b3baf] | 480 |
|
---|
[d51ee2b] | 481 | return dev_idx;
|
---|
| 482 | }
|
---|
| 483 |
|
---|
[38b3baf] | 484 | extern char *create_dev_name_for_class(dev_class_t *, const char *);
|
---|
| 485 | extern dev_class_info_t *add_device_to_class(node_t *, dev_class_t *,
|
---|
| 486 | const char *);
|
---|
[d51ee2b] | 487 |
|
---|
[38b3baf] | 488 | extern void init_class_list(class_list_t *);
|
---|
[692c40cb] | 489 |
|
---|
[38b3baf] | 490 | extern dev_class_t *get_dev_class(class_list_t *, char *);
|
---|
| 491 | extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
|
---|
[692c40cb] | 492 |
|
---|
[38b3baf] | 493 | static inline void
|
---|
| 494 | add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl)
|
---|
[692c40cb] | 495 | {
|
---|
| 496 | list_append(&cl->link, &class_list->classes);
|
---|
| 497 | }
|
---|
| 498 |
|
---|
[ce89036b] | 499 |
|
---|
[38b3baf] | 500 | /* Devmap devices */
|
---|
[ce89036b] | 501 |
|
---|
[38b3baf] | 502 | extern node_t *find_devmap_tree_device(dev_tree_t *, dev_handle_t);
|
---|
| 503 | extern node_t *find_devmap_class_device(class_list_t *, dev_handle_t);
|
---|
[a32defa] | 504 |
|
---|
[38b3baf] | 505 | static inline void
|
---|
| 506 | class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
|
---|
[a32defa] | 507 | {
|
---|
[38b3baf] | 508 | unsigned long key = (unsigned long) cli->devmap_handle;
|
---|
| 509 |
|
---|
[a32defa] | 510 | fibril_rwlock_write_lock(&class_list->rwlock);
|
---|
| 511 | hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
|
---|
| 512 | fibril_rwlock_write_unlock(&class_list->rwlock);
|
---|
| 513 | }
|
---|
| 514 |
|
---|
| 515 | static inline void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
|
---|
| 516 | {
|
---|
[38b3baf] | 517 | unsigned long key = (unsigned long) node->devmap_handle;
|
---|
[a32defa] | 518 | fibril_rwlock_write_lock(&tree->rwlock);
|
---|
| 519 | hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
|
---|
[38b3baf] | 520 | fibril_rwlock_write_unlock(&tree->rwlock);
|
---|
[a32defa] | 521 | }
|
---|
| 522 |
|
---|
[e2b9a993] | 523 | #endif
|
---|
[c16cf62] | 524 |
|
---|
| 525 | /** @}
|
---|
[38b3baf] | 526 | */
|
---|