xref: /haiku/src/add-ons/kernel/bus_managers/acpi/ACPIPrivate.h (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
1 /*
2  * Copyright 2009, Clemens Zeidler. All rights reserved.
3  * Copyright 2006, Jérôme Duval. All rights reserved.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef _ACPI_PRIVATE_H
7 #define _ACPI_PRIVATE_H
8 
9 
10 #include <sys/cdefs.h>
11 
12 #include <device_manager.h>
13 #include <KernelExport.h>
14 #include <ACPI.h>
15 #include <PCI.h>
16 
17 // name of ACPI root module
18 #define ACPI_ROOT_MODULE_NAME 	"bus_managers/acpi/root/driver_v1"
19 
20 // name of ACPI device modules
21 #define ACPI_DEVICE_MODULE_NAME "bus_managers/acpi/driver_v1"
22 
23 // name of the ACPI namespace device
24 #define ACPI_NS_DUMP_DEVICE_MODULE_NAME "bus_managers/acpi/namespace/device_v1"
25 
26 
27 __BEGIN_DECLS
28 
29 extern device_manager_info* gDeviceManager;
30 extern pci_module_info* gPCIManager;
31 
32 // information about one ACPI device
33 typedef struct acpi_device_cookie {
34 	char*			path;			// path
35 	acpi_handle		handle;
36 	uint32			type;			// type
37 	device_node*	node;
38 	char			name[32];		// name (for fast log)
39 } acpi_device_cookie;
40 
41 
42 typedef struct acpi_resource acpi_resource;
43 typedef acpi_status (*acpi_walk_resources_callback)(acpi_resource* resource,
44 	void* context);
45 
46 
47 // ACPI root.
48 typedef struct acpi_root_info {
49 	driver_module_info info;
50 
51 	status_t	(*get_handle)(acpi_handle parent, const char *pathname,
52 					acpi_handle *retHandle);
53 	status_t 	(*get_name)(acpi_handle handle, uint32 nameType,
54 					char* returnedName, size_t bufferLength);
55 
56 	/* Global Lock */
57 
58 	status_t	(*acquire_global_lock)(uint16 timeout, uint32 *handle);
59 	status_t	(*release_global_lock)(uint32 handle);
60 
61 	/* Notify Handler */
62 
63     status_t	(*install_notify_handler)(acpi_handle device,
64     				uint32 handlerType, acpi_notify_handler handler,
65     				void *context);
66 	status_t	(*remove_notify_handler)(acpi_handle device,
67     				uint32 handlerType, acpi_notify_handler handler);
68 
69 	/* GPE Handler */
70 	status_t	(*update_all_gpes)();
71 	status_t	(*enable_gpe)(acpi_handle handle, uint32 gpeNumber);
72 	status_t	(*disable_gpe)(acpi_handle handle, uint32 gpeNumber);
73 	status_t	(*clear_gpe)(acpi_handle handle, uint32 gpeNumber);
74 	status_t	(*set_gpe)(acpi_handle handle, uint32 gpeNumber,
75 					uint8 action);
76 	status_t	(*finish_gpe)(acpi_handle handle, uint32 gpeNumber);
77 	status_t	(*install_gpe_handler)(acpi_handle handle, uint32 gpeNumber,
78 					uint32 type, acpi_gpe_handler handler, void *data);
79 	status_t	(*remove_gpe_handler)(acpi_handle handle, uint32 gpeNumber,
80 					acpi_gpe_handler address);
81 
82 	/* Address Space Handler */
83 
84 	status_t	(*install_address_space_handler)(acpi_handle handle,
85 					uint32 spaceId,
86 					acpi_adr_space_handler handler,
87 					acpi_adr_space_setup setup,	void *data);
88 	status_t	(*remove_address_space_handler)(acpi_handle handle,
89 					uint32 spaceId,
90 					acpi_adr_space_handler handler);
91 
92 	/* Fixed Event Management */
93 
94 	void		(*enable_fixed_event)(uint32 event);
95 	void		(*disable_fixed_event)(uint32 event);
96 
97 	uint32		(*fixed_event_status) (uint32 event);
98 					/* Returns 1 if event set, 0 otherwise */
99 	void		(*reset_fixed_event) (uint32 event);
100 
101 	status_t	(*install_fixed_event_handler)(uint32 event,
102 					acpi_event_handler handler, void *data);
103 	status_t	(*remove_fixed_event_handler)(uint32 event,
104 					acpi_event_handler handler);
105 
106 	/* Namespace Access */
107 
108 	status_t	(*get_next_entry)(uint32 objectType, const char *base,
109 					char *result, size_t length, void **_counter);
110 	status_t	(*get_next_object)(uint32 objectType, acpi_handle parent,
111 					acpi_handle* currentChild);
112 	status_t	(*get_device)(const char *hid, uint32 index, char *result,
113 					size_t resultLength);
114 
115 	status_t	(*get_device_hid)(const char *path, char *hid,
116 					size_t hidLength);
117 	uint32		(*get_object_type)(const char *path);
118 	status_t	(*get_object)(const char *path,
119 					acpi_object_type **_returnValue);
120 	status_t	(*get_object_typed)(const char *path,
121 					acpi_object_type **_returnValue, uint32 objectType);
122 	status_t	(*ns_handle_to_pathname)(acpi_handle targetHandle,
123 					acpi_data *buffer);
124 
125 	/* Control method execution and data acquisition */
126 
127 	status_t	(*evaluate_object)(acpi_handle handle, const char* object,
128 					acpi_objects *args, acpi_object_type *returnValue,
129 					size_t bufferLength);
130 	status_t	(*evaluate_method)(acpi_handle handle, const char *method,
131 					acpi_objects *args, acpi_data *returnValue);
132 
133 	/* Resource info */
134 
135 	status_t	(*get_irq_routing_table)(acpi_handle busDeviceHandle,
136 					acpi_data *retBuffer);
137 	status_t	(*get_current_resources)(acpi_handle busDeviceHandle,
138 					acpi_data *retBuffer);
139 	status_t	(*get_possible_resources)(acpi_handle busDeviceHandle,
140 					acpi_data *retBuffer);
141 	status_t	(*set_current_resources)(acpi_handle busDeviceHandle,
142 					acpi_data *buffer);
143 	status_t	(*walk_resources)(acpi_handle busDeviceHandle,
144 					char *method, acpi_walk_resources_callback callback,
145 					void* context);
146 
147 	/* Power state setting */
148 
149 	status_t	(*prepare_sleep_state)(uint8 state, void (*wakeFunc)(void),
150 					size_t size);
151 	status_t	(*enter_sleep_state)(uint8 state);
152 	status_t	(*reboot)(void);
153 
154 	/* Table Access */
155 	status_t	(*get_table)(const char *signature, uint32 instance,
156 					void **tableHeader);
157 } acpi_root_info;
158 
159 
160 extern struct acpi_module_info gACPIModule;
161 
162 extern struct device_module_info acpi_ns_dump_module;
163 
164 extern struct driver_module_info embedded_controller_driver_module;
165 extern struct device_module_info embedded_controller_device_module;
166 
167 extern acpi_device_module_info gACPIDeviceModule;
168 
169 
170 status_t get_handle(acpi_handle parent, const char* pathname,
171 	acpi_handle* retHandle);
172 status_t get_name(acpi_handle handle, uint32 nameType,
173 	char* returnedName, size_t bufferLength);
174 
175 status_t acquire_global_lock(uint16 timeout, uint32* handle);
176 status_t release_global_lock(uint32 handle);
177 
178 status_t install_notify_handler(acpi_handle device,	uint32 handlerType,
179 	acpi_notify_handler handler, void* context);
180 status_t remove_notify_handler(acpi_handle device, uint32 handlerType,
181 	acpi_notify_handler handler);
182 
183 status_t update_all_gpes();
184 status_t enable_gpe(acpi_handle handle, uint32 gpeNumber);
185 status_t disable_gpe(acpi_handle handle, uint32 gpeNumber);
186 status_t clear_gpe(acpi_handle handle, uint32 gpeNumber);
187 status_t set_gpe(acpi_handle handle, uint32 gpeNumber, uint8 action);
188 status_t finish_gpe(acpi_handle handle, uint32 gpeNumber);
189 status_t install_gpe_handler(acpi_handle handle, uint32 gpeNumber, uint32 type,
190 	acpi_gpe_handler handler, void* data);
191 status_t remove_gpe_handler(acpi_handle handle, uint32 gpeNumber,
192 	acpi_gpe_handler address);
193 
194 status_t install_address_space_handler(acpi_handle handle, uint32 spaceID,
195 	acpi_adr_space_handler handler, acpi_adr_space_setup setup, void* data);
196 status_t remove_address_space_handler(acpi_handle handle, uint32 spaceID,
197 	acpi_adr_space_handler handler);
198 
199 void enable_fixed_event(uint32 event);
200 void disable_fixed_event(uint32 event);
201 
202 uint32 fixed_event_status(uint32 event);
203 void reset_fixed_event(uint32 event);
204 
205 status_t install_fixed_event_handler(uint32 event, acpi_event_handler handler,
206 	void* data);
207 status_t remove_fixed_event_handler(uint32 event, acpi_event_handler handler);
208 
209 status_t get_next_entry(uint32 object_type, const char* base, char* result,
210 	size_t length, void** _counter);
211 status_t get_next_object(uint32 object_type, acpi_handle parent,
212 	acpi_handle* currentChild);
213 status_t get_device(const char* hid, uint32 index, char* result,
214 	size_t resultLength);
215 
216 status_t get_device_hid(const char* path, char* hid, size_t hidLength);
217 uint32 get_object_type(const char* path);
218 status_t get_object(const char* path, acpi_object_type** _returnValue);
219 status_t get_object_typed(const char* path, acpi_object_type** _returnValue,
220 	uint32 object_type);
221 status_t ns_handle_to_pathname(acpi_handle targetHandle, acpi_data* buffer);
222 
223 status_t evaluate_object(acpi_handle handle, const char* object,
224 	acpi_objects* args, acpi_object_type* returnValue, size_t bufferLength);
225 status_t evaluate_method(acpi_handle handle, const char* method,
226 	acpi_objects* args, acpi_data* returnValue);
227 
228 status_t get_irq_routing_table(acpi_handle busDeviceHandle,
229 	acpi_data* returnValue);
230 status_t get_current_resources(acpi_handle busDeviceHandle,
231 	acpi_data* returnValue);
232 status_t get_possible_resources(acpi_handle busDeviceHandle,
233 	acpi_data* returnValue);
234 status_t set_current_resources(acpi_handle busDeviceHandle,
235 	acpi_data* buffer);
236 status_t walk_resources(acpi_handle busDeviceHandle, char* method,
237 	acpi_walk_resources_callback callback, void* context);
238 
239 status_t prepare_sleep_state(uint8 state, void (*wakeFunc)(void), size_t size);
240 status_t enter_sleep_state(uint8 state);
241 
242 status_t reboot(void);
243 
244 status_t get_table(const char* signature, uint32 instance, void** tableHeader);
245 
246 __END_DECLS
247 
248 
249 #endif	/* _ACPI_PRIVATE_H */
250