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

Last change on this file since d89b259 was e55741e, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

sysman: Instrumented devman with autostart

  • created unit files for drivers, their processing in Makefile
  • just naïvely replaced task_spawn with sysman_unit_start in devman

Conflicts:

boot/Makefile.common
uspace/srv/devman/devman.h
uspace/srv/devman/driver.c

  • Property mode set to 100644
File size: 5.7 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>
[498ced1]43#include <refcount.h>
[79ae36dd]44#include <async.h>
[e2b9a993]45
[08d9c4e6]46#include "util.h"
[e2b9a993]47
48#define NAME "devman"
49
[15f3c3f]50#define LOC_SEPARATOR '\\'
[ce89036b]51
[ba38f72c]52struct dev_node;
53typedef struct dev_node dev_node_t;
54
55struct fun_node;
56typedef struct fun_node fun_node_t;
[e2b9a993]57
[422722e]58typedef struct {
59 fibril_mutex_t mutex;
60 struct driver *driver;
61} client_t;
62
[38b3baf]63/** Representation of device driver. */
[e2b9a993]64typedef struct driver {
[38b3baf]65 /** Pointers to previous and next drivers in a linked list. */
[e2b9a993]66 link_t drivers;
[0511549]67 /** Handle */
68 devman_handle_t handle;
[a35b458]69
[38b3baf]70 /**
71 * Specifies whether the driver has been started and wheter is running
72 * and prepared to receive requests.
73 */
[e5556e4a]74 driver_state_t state;
[a35b458]75
[79ae36dd]76 /** Session asociated with this driver. */
77 async_sess_t *sess;
[38b3baf]78 /** Name of the device driver. */
[e2b9a993]79 char *name;
[38b3baf]80 /** List of device ids for device-to-driver matching. */
[e2b9a993]81 match_id_list_t match_ids;
[b72efe8]82 /** List of devices controlled by this driver. */
83 list_t devices;
[a35b458]84
[38b3baf]85 /**
[79ae36dd]86 * Fibril mutex for this driver - driver state, list of devices, session.
[38b3baf]87 */
[e85920d]88 fibril_mutex_t driver_mutex;
[e2b9a993]89} driver_t;
90
[e85920d]91/** The list of drivers. */
92typedef struct driver_list {
93 /** List of drivers */
[b72efe8]94 list_t drivers;
[e85920d]95 /** Fibril mutex for list of drivers. */
[38b3baf]96 fibril_mutex_t drivers_mutex;
[0511549]97 /** Next free handle */
98 devman_handle_t next_handle;
[e85920d]99} driver_list_t;
100
[c1a0488]101/** Device state */
[df747b9c]102typedef enum {
103 DEVICE_NOT_INITIALIZED = 0,
104 DEVICE_USABLE,
105 DEVICE_NOT_PRESENT,
[c1a0488]106 DEVICE_INVALID,
107 /** Device node has been removed from the tree */
108 DEVICE_REMOVED
[df747b9c]109} device_state_t;
110
[ba38f72c]111/** Device node in the device tree. */
112struct dev_node {
[58cbb0c8]113 /** Reference count */
[498ced1]114 atomic_refcount_t refcnt;
[a35b458]115
[38b3baf]116 /** The global unique identifier of the device. */
[0b5a4131]117 devman_handle_t handle;
[a35b458]118
[ba38f72c]119 /** (Parent) function the device is attached to. */
120 fun_node_t *pfun;
[a35b458]121
[ba38f72c]122 /** List of device functions. */
[b72efe8]123 list_t functions;
[ba38f72c]124 /** Driver of this device. */
125 driver_t *drv;
126 /** The state of the device. */
127 device_state_t state;
128 /** Link to list of devices owned by driver (driver_t.devices) */
129 link_t driver_devices;
[a35b458]130
[38b3baf]131 /**
[ba38f72c]132 * Used by the hash table of devices indexed by devman device handles.
[38b3baf]133 */
[062d900]134 ht_link_t devman_dev;
[a35b458]135
[38b3baf]136 /**
[ba38f72c]137 * Whether this device was already passed to the driver.
[38b3baf]138 */
[ba38f72c]139 bool passed_to_driver;
140};
141
[c1a0488]142/** Function state */
143typedef enum {
144 FUN_INIT = 0,
145 FUN_OFF_LINE,
146 FUN_ON_LINE,
147 /** Function node has been removed from the tree */
148 FUN_REMOVED
149} fun_state_t;
150
[ba38f72c]151/** Function node in the device tree. */
152struct fun_node {
[58cbb0c8]153 /** Reference count */
[498ced1]154 atomic_refcount_t refcnt;
[c1a0488]155 /** State */
156 fun_state_t state;
[4820360]157 /** Locked while performing reconfiguration operations */
158 fibril_mutex_t busy_lock;
[a35b458]159
[ba38f72c]160 /** The global unique identifier of the function */
161 devman_handle_t handle;
162 /** Name of the function, assigned by the device driver */
163 char *name;
[d0dd7b5]164 /** Function type */
165 fun_type_t ftype;
[a35b458]166
[ba38f72c]167 /** Full path and name of the device in device hierarchy */
168 char *pathname;
[a35b458]169
[ba38f72c]170 /** Device which this function belongs to */
171 dev_node_t *dev;
[a35b458]172
[83a2f43]173 /** Link to list of functions in the device (ddf_dev_t.functions) */
[ba38f72c]174 link_t dev_functions;
[a35b458]175
[ba38f72c]176 /** Child device node (if any attached). */
177 dev_node_t *child;
[38b3baf]178 /** List of device ids for device-to-driver matching. */
[08d9c4e6]179 match_id_list_t match_ids;
[a35b458]180
[15f3c3f]181 /** Service ID if the device function is registered with loc. */
182 service_id_t service_id;
[a35b458]183
[38b3baf]184 /**
[ba38f72c]185 * Used by the hash table of functions indexed by devman device handles.
[38b3baf]186 */
[062d900]187 ht_link_t devman_fun;
[a35b458]188
[38b3baf]189 /**
[15f3c3f]190 * Used by the hash table of functions indexed by service IDs.
[5bee897]191 */
[062d900]192 ht_link_t loc_fun;
[e2b9a993]193};
194
[38b3baf]195/** Represents device tree. */
[e2b9a993]196typedef struct dev_tree {
197 /** Root device node. */
[ba38f72c]198 fun_node_t *root_node;
[a35b458]199
[38b3baf]200 /**
201 * The next available handle - handles are assigned in a sequential
202 * manner.
203 */
[0b5a4131]204 devman_handle_t current_handle;
[a35b458]205
[38b3baf]206 /** Synchronize access to the device tree. */
[957cfa58]207 fibril_rwlock_t rwlock;
[a35b458]208
[38b3baf]209 /** Hash table of all devices indexed by devman handles. */
[957cfa58]210 hash_table_t devman_devices;
[a35b458]211
[ba38f72c]212 /** Hash table of all devices indexed by devman handles. */
213 hash_table_t devman_functions;
[a35b458]214
[38b3baf]215 /**
[15f3c3f]216 * Hash table of services registered with location service, indexed by
217 * service IDs.
[38b3baf]218 */
[15f3c3f]219 hash_table_t loc_functions;
[e2b9a993]220} dev_tree_t;
221
222#endif
[c16cf62]223
224/** @}
[38b3baf]225 */
Note: See TracBrowser for help on using the repository browser.