xref: /haiku/headers/os/drivers/ACPI.h (revision fc75f2df0c666dcc61be83c4facdd3132340c2fb)
1 /*
2  * Copyright 2005-2008, Haiku Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License
4  */
5 #ifndef _ACPI_H
6 #define _ACPI_H
7 
8 
9 #include <device_manager.h>
10 #include <KernelExport.h>
11 
12 
13 typedef struct acpi_module_info acpi_module_info;
14 typedef struct acpi_object_type acpi_object_type;
15 
16 #define B_ACPI_MODULE_NAME "bus_managers/acpi/v1"
17 
18 typedef addr_t acpi_physical_address;
19 typedef addr_t acpi_io_address;
20 typedef size_t acpi_size;
21 
22 /* Actually a ptr to a NS Node */
23 typedef void *				acpi_handle;
24 
25 #ifndef __ACTYPES_H__
26 
27 /* Notify types */
28 
29 #define ACPI_SYSTEM_NOTIFY				0x1
30 #define ACPI_DEVICE_NOTIFY				0x2
31 #define ACPI_ALL_NOTIFY					(ACPI_SYSTEM_NOTIFY | ACPI_DEVICE_NOTIFY)
32 #define ACPI_MAX_NOTIFY_HANDLER_TYPE	0x3
33 
34 #define ACPI_MAX_SYS_NOTIFY				0x7f
35 
36 /* Address Space (Operation Region) Types */
37 
38 enum {
39 	ACPI_ADR_SPACE_SYSTEM_MEMORY	= 0,
40 	ACPI_ADR_SPACE_SYSTEM_IO		= 1,
41 	ACPI_ADR_SPACE_PCI_CONFIG		= 2,
42 	ACPI_ADR_SPACE_EC				= 3,
43 	ACPI_ADR_SPACE_SMBUS			= 4,
44 	ACPI_ADR_SPACE_CMOS 			= 5,
45 	ACPI_ADR_SPACE_PCI_BAR_TARGET	= 6,
46 	ACPI_ADR_SPACE_IPMI				= 7,
47 	ACPI_ADR_SPACE_DATA_TABLE		= 8,
48 	ACPI_ADR_SPACE_FIXED_HARDWARE	= 127
49 };
50 
51 /* ACPI fixed event types */
52 
53 enum {
54 	ACPI_EVENT_PMTIMER = 0,
55 	ACPI_EVENT_GLOBAL,
56 	ACPI_EVENT_POWER_BUTTON,
57 	ACPI_EVENT_SLEEP_BUTTON,
58 	ACPI_EVENT_RTC
59 };
60 
61 /* ACPI Object Types */
62 
63 enum {
64 	ACPI_TYPE_ANY = 0,
65 	ACPI_TYPE_INTEGER,
66 	ACPI_TYPE_STRING,
67 	ACPI_TYPE_BUFFER,
68 	ACPI_TYPE_PACKAGE,
69 	ACPI_TYPE_FIELD_UNIT,
70 	ACPI_TYPE_DEVICE,
71 	ACPI_TYPE_EVENT,
72 	ACPI_TYPE_METHOD,
73 	ACPI_TYPE_MUTEX,
74 	ACPI_TYPE_REGION,
75 	ACPI_TYPE_POWER,
76 	ACPI_TYPE_PROCESSOR,
77 	ACPI_TYPE_THERMAL,
78 	ACPI_TYPE_BUFFER_FIELD,
79 	ACPI_TYPE_DDB_HANDLE,
80 	ACPI_TYPE_DEBUG_OBJECT,
81 	ACPI_TYPE_LOCAL_REFERENCE = 0x14
82 };
83 
84 /* ACPI control method arg type */
85 
86 struct acpi_object_type {
87 	uint32 object_type;
88 	union {
89 		uint64 integer;
90 		struct {
91 			uint32 len;
92 			char *string; /* You have to allocate string space yourself */
93 		} string;
94 		struct {
95 			size_t length;
96 			void *buffer;
97 		} buffer;
98 		struct {
99 			uint32 count;
100 			acpi_object_type *objects;
101 		} package;
102 		struct {
103 			uint32 actual_type;
104 			acpi_handle handle;
105 		} reference;
106 		struct {
107 			uint32 cpu_id;
108 			int pblk_address;
109 			size_t pblk_length;
110 		} processor;
111 		struct {
112 			uint32 min_power_state;
113 			uint32 resource_order;
114 		} power_resource;
115 	} data;
116 };
117 
118 
119 /*
120  * List of objects, used as a parameter list for control method evaluation
121  */
122 typedef struct acpi_objects {
123 	uint32				count;
124 	acpi_object_type	*pointer;
125 } acpi_objects;
126 
127 
128 typedef struct acpi_data {
129 	acpi_size			length;		/* Length in bytes of the buffer */
130 	void				*pointer;	/* pointer to buffer */
131 } acpi_data;
132 
133 
134 enum {
135 	ACPI_ALLOCATE_BUFFER = -1,
136 };
137 
138 
139 /*
140  * acpi_status should return ACPI specific error codes, not BeOS ones.
141  */
142 typedef uint32 acpi_status;
143 
144 #endif	// __ACTYPES_H__
145 
146 
147 typedef uint32 (*acpi_event_handler)(void *Context);
148 typedef uint32 (*acpi_gpe_handler) (acpi_handle GpeDevice, uint32 GpeNumber,
149 	void *Context);
150 
151 typedef acpi_status (*acpi_adr_space_handler)(uint32 function,
152 	acpi_physical_address address, uint32 bitWidth, int *value,
153 	void *handlerContext, void *regionContext);
154 
155 typedef acpi_status (*acpi_adr_space_setup)(acpi_handle regionHandle,
156 	uint32 function, void *handlerContext, void **regionContext);
157 
158 typedef void (*acpi_notify_handler)(acpi_handle device, uint32 value,
159 	void *context);
160 
161 
162 struct acpi_module_info {
163 	module_info info;
164 
165 	status_t	(*get_handle)(acpi_handle parent, const char *pathname,
166 					acpi_handle *retHandle);
167 
168 	/* Global Lock */
169 
170 	status_t	(*acquire_global_lock)(uint16 timeout, uint32 *handle);
171 	status_t	(*release_global_lock)(uint32 handle);
172 
173 	/* Notify Handler */
174 
175 	status_t	(*install_notify_handler)(acpi_handle device,
176 					uint32 handlerType, acpi_notify_handler handler,
177 					void *context);
178 	status_t	(*remove_notify_handler)(acpi_handle device,
179 					uint32 handlerType, acpi_notify_handler handler);
180 
181 	/* GPE 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,
188 					uint8 action);
189 	status_t	(*finish_gpe)(acpi_handle handle, uint32 gpeNumber);
190 	status_t	(*install_gpe_handler)(acpi_handle handle, uint32 gpeNumber,
191 					uint32 type, acpi_gpe_handler handler, void *data);
192 	status_t	(*remove_gpe_handler)(acpi_handle handle, uint32 gpeNumber,
193 					acpi_gpe_handler address);
194 
195 	/* Address Space Handler */
196 
197 	status_t	(*install_address_space_handler)(acpi_handle handle,
198 					uint32 spaceId,
199 					acpi_adr_space_handler handler,
200 					acpi_adr_space_setup setup,	void *data);
201 	status_t	(*remove_address_space_handler)(acpi_handle handle,
202 					uint32 spaceId,
203 					acpi_adr_space_handler handler);
204 
205 	/* Fixed Event Management */
206 
207 	void		(*enable_fixed_event)(uint32 event);
208 	void		(*disable_fixed_event)(uint32 event);
209 
210 	uint32		(*fixed_event_status) (uint32 event);
211 					/* Returns 1 if event set, 0 otherwise */
212 	void		(*reset_fixed_event) (uint32 event);
213 
214 	status_t	(*install_fixed_event_handler)(uint32 event,
215 					interrupt_handler *handler, void *data);
216 	status_t	(*remove_fixed_event_handler)(uint32 event,
217 					interrupt_handler *handler);
218 
219 	/* Namespace Access */
220 
221 	status_t	(*get_next_entry)(uint32 objectType, const char *base,
222 					char *result, size_t length, void **_counter);
223 	status_t	(*get_device)(const char *hid, uint32 index, char *result,
224 					size_t resultLength);
225 
226 	status_t	(*get_device_hid)(const char *path, char *hid,
227 					size_t hidLength);
228 	uint32		(*get_object_type)(const char *path);
229 	status_t	(*get_object)(const char *path,
230 					acpi_object_type **_returnValue);
231 	status_t	(*get_object_typed)(const char *path,
232 					acpi_object_type **_returnValue, uint32 objectType);
233 	status_t	(*ns_handle_to_pathname)(acpi_handle targetHandle,
234 					acpi_data *buffer);
235 
236 	/* Control method execution and data acquisition */
237 
238 	status_t	(*evaluate_object)(const char* object,
239 					acpi_object_type *returnValue, size_t bufferLength);
240 	status_t	(*evaluate_method)(acpi_handle handle, const char *method,
241 					acpi_objects *args, acpi_data *returnValue);
242 
243 	/* Resource Management */
244 
245 	status_t	(*get_irq_routing_table)(acpi_handle busDeviceHandle,
246 					acpi_data *retBuffer);
247 	status_t	(*get_current_resources)(acpi_handle busDeviceHandle,
248 					acpi_data *retBuffer);
249 	status_t	(*get_possible_resources)(acpi_handle busDeviceHandle,
250 					acpi_data *retBuffer);
251 	status_t	(*set_current_resources)(acpi_handle busDeviceHandle,
252 					acpi_data *buffer);
253 
254 	/* Power state setting */
255 
256 	status_t	(*prepare_sleep_state)(uint8 state, void (*wakeFunc)(void),
257 					size_t size);
258 	status_t	(*enter_sleep_state)(uint8 state);
259 	status_t	(*reboot)(void);
260 
261 	/* Table Access */
262 	status_t	(*get_table)(const char *signature, uint32 instance,
263 					void **tableHeader);
264 };
265 
266 
267 /* Sleep states */
268 
269 enum {
270 	ACPI_POWER_STATE_ON = 0,
271 	ACPI_POWER_STATE_SLEEP_S1,
272 	ACPI_POWER_STATE_SLEEP_S2,
273 	ACPI_POWER_STATE_SLEEP_S3,
274 	ACPI_POWER_STATE_HIBERNATE,
275 	ACPI_POWER_STATE_OFF
276 };
277 
278 
279 #define ACPI_DEVICE_HID_ITEM	"acpi/hid"
280 #define ACPI_DEVICE_PATH_ITEM	"acpi/path"
281 #define ACPI_DEVICE_TYPE_ITEM	"acpi/type"
282 
283 
284 typedef struct acpi_device_cookie *acpi_device;
285 
286 //	Interface to one ACPI device.
287 typedef struct acpi_device_module_info {
288 	driver_module_info info;
289 
290 	/* Notify Handler */
291 
292 	status_t	(*install_notify_handler)(acpi_device device,
293 					uint32 handlerType, acpi_notify_handler handler,
294 					void *context);
295 	status_t	(*remove_notify_handler)(acpi_device device,
296 					uint32 handlerType, acpi_notify_handler handler);
297 
298 	/* Address Space Handler */
299 	status_t	(*install_address_space_handler)(acpi_device device,
300 					uint32 spaceId,
301 					acpi_adr_space_handler handler,
302 					acpi_adr_space_setup setup,	void *data);
303 	status_t	(*remove_address_space_handler)(acpi_device device,
304 					uint32 spaceId,
305 					acpi_adr_space_handler handler);
306 
307 	/* Namespace Access */
308 	uint32		(*get_object_type)(acpi_device device);
309 	status_t	(*get_object)(acpi_device device, const char *path,
310 					acpi_object_type **_returnValue);
311 
312 	/* Control method execution and data acquisition */
313 	status_t	(*evaluate_method)(acpi_device device, const char *method,
314 					acpi_objects *args, acpi_data *returnValue);
315 } acpi_device_module_info;
316 
317 
318 #endif	/* _ACPI_H */
319