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