xref: /haiku/src/system/kernel/device_manager/device_manager_private.h (revision 9d6d3fcf5fe8308cd020cecf89dede440346f8c4)
1 /*
2  * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Copyright 2002-04, Thomas Kurschel. All rights reserved.
4  *
5  * Distributed under the terms of the MIT License.
6  */
7 #ifndef DEVICE_MANAGER_PRIVATE
8 #define DEVICE_MANAGER_PRIVATE
9 
10 /*
11 	Part of Device Manager
12 	Internal header.
13 */
14 
15 #include <kdevice_manager.h>
16 #include <util/list.h>
17 
18 #include <lock.h>
19 
20 #define GENERATOR_MAX_ID 64
21 #define UNIVERSAL_SUBDIR "/universal"
22 #define GENERIC_SUBDIR "/generic"
23 
24 // driver registration directories
25 #define PNP_DIR
26 #define SYSTEM_DRIVER_REGISTRATION "/boot/beos/system/add-ons/kernel/"PNP_DIR"registration/"
27 #define COMMON_DRIVER_REGISTRATION "/boot/home/config/add-ons/kernel/"PNP_DIR"registration/"
28 
29 // module directories
30 #define SYSTEM_MODULES_DIR "/boot/beos/add-ons/kernel/"
31 #define COMMON_MODULES_DIR "/boot/home/config/add-ons/kernel/"
32 
33 
34 // info about ID generator
35 typedef struct id_generator {
36 	struct list_link link;
37 	struct id_generator *prev, *next;
38 	int32		ref_count;
39 	char		*name;
40 	uint32		num_ids;
41 	uint8		alloc_map[(GENERATOR_MAX_ID + 7) / 8];
42 } id_generator;
43 
44 
45 // info about a node attribute
46 typedef struct device_attr_info {
47 	struct device_attr_info *prev, *next;
48 	int32		ref_count;				// reference count
49 	device_attr	attr;
50 } device_attr_info;
51 
52 
53 // I/O resource
54 typedef struct io_resource_info {
55 	struct io_resource_info *prev, *next;
56 	device_node_info	*owner;			// associated node; NULL for temporary allocation
57 	io_resource			resource;		// info about actual resource
58 } io_resource_info;
59 
60 
61 // a structure to put nodes into lists
62 struct node_entry {
63 	struct list_link	link;
64 	device_node_info	*node;
65 };
66 
67 
68 // global lock
69 // whenever you do something in terms of nodes, grab it
70 extern benaphore gNodeLock;
71 // root node
72 extern device_node_info *gRootNode;
73 
74 // true, if user addons are disabled via safemode
75 extern bool disable_useraddons;
76 
77 
78 // # of allocate_io_resource() calls waiting for a retry
79 extern int pnp_resource_wait_count;
80 // semaphore for allocate_io_resource() call retry
81 extern sem_id pnp_resource_wait_sem;
82 
83 // list of driver registration directories
84 extern const char *pnp_registration_dirs[];
85 
86 
87 // list of I/O memory, I/O ports and ISA DMA channels
88 extern io_resource_info *io_mem_list, *io_port_list, *isa_dma_list;
89 
90 
91 // nesting of pnp_load_boot_links calls
92 int pnp_fs_emulation_nesting;
93 
94 
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
98 
99 // attributes.c
100 
101 device_attr_info *pnp_find_attr_nolock(device_node_handle node, const char *name,
102 	bool recursive, type_code type);
103 status_t pnp_get_attr_uint8(device_node_handle node, const char *name,
104 	uint8 *value, bool recursive);
105 status_t pnp_get_attr_uint8_nolock(device_node_handle node, const char *name,
106 	uint8 *value, bool recursive);
107 status_t pnp_get_attr_uint16(device_node_handle node, const char *name,
108 	uint16 *value, bool recursive);
109 status_t pnp_get_attr_uint16_nolock(device_node_handle node, const char *name,
110 	uint16 *value, bool recursive);
111 status_t pnp_get_attr_uint32(device_node_handle node, const char *name,
112 	uint32 *value, bool recursive);
113 status_t pnp_get_attr_uint32_nolock(device_node_handle node, const char *name,
114 	uint32 *value, bool recursive);
115 status_t pnp_get_attr_uint64(device_node_handle node, const char *name,
116 	uint64 *value, bool recursive);
117 status_t pnp_get_attr_uint64_nolock(device_node_handle node, const char *name,
118 	uint64 *value, bool recursive);
119 status_t pnp_get_attr_string(device_node_handle node, const char *name,
120 	char **value, bool recursive);
121 status_t pnp_get_attr_string_nolock(device_node_handle node, const char *name,
122 	const char **value, bool recursive);
123 status_t pnp_get_attr_raw(device_node_handle node, const char *name,
124 	void **data, size_t *len, bool recursive);
125 status_t pnp_get_attr_raw_nolock(device_node_handle node, const char *name,
126 	const void **data, size_t *len, bool recursive);
127 void pnp_free_node_attr(device_attr_info *attr);
128 status_t pnp_get_next_node_with_attrs(device_node_info **_node, const device_attr *attrs);
129 int pnp_compare_attrs(const device_attr *attrA, const device_attr *attrB);
130 status_t pnp_duplicate_node_attr(const device_attr *src, device_attr_info **dest_out);
131 status_t pnp_get_next_attr(device_node_handle node, device_attr_handle *attr);
132 status_t pnp_release_attr(device_node_handle node, device_attr_handle attr);
133 status_t pnp_retrieve_attr(device_attr_handle attr, const device_attr **attr_content);
134 status_t pnp_write_attr(device_node_handle node, const device_attr *attr);
135 void pnp_remove_attr_int(device_node_handle node, device_attr_info *attr);
136 status_t pnp_remove_attr(device_node_handle node, const char *name);
137 
138 
139 // driver_loader.c
140 
141 status_t pnp_load_driver(device_node_handle node, void *user_cookie,
142 			driver_module_info **interface, void **cookie);
143 status_t pnp_unload_driver(device_node_handle node);
144 void pnp_unblock_load(device_node_info *node);
145 
146 
147 // id_generator.c
148 
149 int32 dm_create_id(const char *name);
150 status_t dm_free_id(const char *name, uint32 id);
151 extern status_t dm_init_id_generator(void);
152 
153 
154 // io_resources.c
155 
156 status_t dm_acquire_io_resources(io_resource *resources, io_resource_handle *handles);
157 status_t dm_release_io_resources(const io_resource_handle *handles);
158 void dm_assign_io_resources(device_node_info *node, const io_resource_handle *handles);
159 void dm_release_node_resources(device_node_info *node);
160 
161 
162 // nodes.c
163 
164 status_t dm_allocate_node(const device_attr *attrs, const io_resource_handle *resources,
165 	device_node_info **new_node);
166 void dm_add_child_node(device_node_info *node, device_node_info *parent);
167 void dm_get_node_nolock(device_node_info *node);
168 void dm_get_node(device_node_info *node);
169 void dm_put_node_nolock(device_node_info *node);
170 void dm_dump_node(device_node_info *node, int32 level);
171 status_t dm_init_nodes(void);
172 
173 void dm_put_node(device_node_info *node);
174 status_t dm_get_next_child_node(device_node_info *parent,
175 	device_node_info **_node, const device_attr *attrs);
176 device_node_info *dm_get_root(void);
177 device_node_info *dm_get_parent(device_node_info *node);
178 
179 status_t device_manager_control(const char *subsystem, uint32 function, void *buffer, size_t bufferSize);
180 
181 
182 // notifications.c
183 
184 status_t dm_notify_unregistration(device_node_info *node);
185 void pnp_start_hook_call(device_node_info *node);
186 void pnp_start_hook_call_nolock(device_node_info *node);
187 void pnp_finish_hook_call(device_node_info *node);
188 void pnp_finish_hook_call_nolock(device_node_info *node);
189 
190 
191 // patterns.c
192 
193 status_t pnp_expand_pattern(device_node_info *node, const char *pattern,
194 	char *dest, char *buffer, size_t *term_array, int *num_parts);
195 status_t pnp_expand_pattern_attr(device_node_info *node, const char *attr_name,
196 	char **expanded);
197 
198 
199 // probe.cpp
200 status_t dm_register_child_device(device_node_info *node, const char *childName, bool checkSupport);
201 status_t dm_register_fixed_child_devices(device_node_info *node);
202 status_t dm_register_dynamic_child_devices(device_node_info *node);
203 
204 
205 // registration.c
206 
207 status_t dm_register_node(device_node_handle parent, const device_attr *attrs,
208 	const io_resource_handle *resources, device_node_handle *_newNode);
209 status_t dm_unregister_node(device_node_handle node);
210 
211 void pnp_unref_unregistered_nodes(device_node_info *node_list);
212 
213 
214 // root_node.c
215 
216 void dm_init_root_node(void);
217 
218 
219 // scan.c
220 
221 status_t dm_rescan(device_node_handle node);
222 status_t dm_register_child_devices(device_node_info *node);
223 
224 #ifdef __cplusplus
225 }
226 #endif
227 
228 #endif	/* DEVICE_MANAGER_PRIVATE_H */
229