xref: /haiku/headers/os/drivers/ACPI.h (revision d374a27286b8a52974a97dba0d5966ea026a665d)
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 	status_t	(*set_gpe)(acpi_handle handle, uint32 gpeNumber,
173 					uint8 action);
174 	status_t	(*install_gpe_handler)(acpi_handle handle, uint32 gpeNumber,
175 					uint32 type, acpi_event_handler handler, void *data);
176 	status_t	(*remove_gpe_handler)(acpi_handle handle, uint32 gpeNumber,
177 					acpi_event_handler address);
178 
179 	/* Address Space Handler */
180 
181 	status_t	(*install_address_space_handler)(acpi_handle handle,
182 					uint32 spaceId,
183 					acpi_adr_space_handler handler,
184 					acpi_adr_space_setup setup,	void *data);
185 	status_t	(*remove_address_space_handler)(acpi_handle handle,
186 					uint32 spaceId,
187 					acpi_adr_space_handler handler);
188 
189 	/* Fixed Event Management */
190 
191 	void		(*enable_fixed_event)(uint32 event);
192 	void		(*disable_fixed_event)(uint32 event);
193 
194 	uint32		(*fixed_event_status) (uint32 event);
195 					/* Returns 1 if event set, 0 otherwise */
196 	void		(*reset_fixed_event) (uint32 event);
197 
198 	status_t	(*install_fixed_event_handler)(uint32 event,
199 					interrupt_handler *handler, void *data);
200 	status_t	(*remove_fixed_event_handler)(uint32 event,
201 					interrupt_handler *handler);
202 
203 	/* Namespace Access */
204 
205 	status_t	(*get_next_entry)(uint32 objectType, const char *base,
206 					char *result, size_t length, void **_counter);
207 	status_t	(*get_device)(const char *hid, uint32 index, char *result,
208 					size_t resultLength);
209 
210 	status_t	(*get_device_hid)(const char *path, char *hid,
211 					size_t hidLength);
212 	uint32		(*get_object_type)(const char *path);
213 	status_t	(*get_object)(const char *path,
214 					acpi_object_type **_returnValue);
215 	status_t	(*get_object_typed)(const char *path,
216 					acpi_object_type **_returnValue, uint32 objectType);
217 	status_t	(*ns_handle_to_pathname)(acpi_handle targetHandle,
218 					acpi_data *buffer);
219 
220 	/* Control method execution and data acquisition */
221 
222 	status_t	(*evaluate_object)(const char* object,
223 					acpi_object_type *returnValue, size_t bufferLength);
224 	status_t	(*evaluate_method)(acpi_handle handle, const char *method,
225 					acpi_objects *args, acpi_data *returnValue);
226 
227 	/* Resource info */
228 
229 	status_t	(*get_irq_routing_table)(acpi_handle busDeviceHandle,
230 					acpi_data *retBuffer);
231 	status_t	(*get_current_resources)(acpi_handle busDeviceHandle,
232 					acpi_data *retBuffer);
233 
234 	/* Power state setting */
235 
236 	status_t	(*prepare_sleep_state)(uint8 state, void (*wakeFunc)(void),
237 					size_t size);
238 	status_t	(*enter_sleep_state)(uint8 state);
239 	status_t	(*reboot)(void);
240 };
241 
242 
243 /* Sleep states */
244 
245 enum {
246 	ACPI_POWER_STATE_ON = 0,
247 	ACPI_POWER_STATE_SLEEP_S1,
248 	ACPI_POWER_STATE_SLEEP_S2,
249 	ACPI_POWER_STATE_SLEEP_S3,
250 	ACPI_POWER_STATE_HIBERNATE,
251 	ACPI_POWER_STATE_OFF
252 };
253 
254 
255 #define ACPI_DEVICE_HID_ITEM	"acpi/hid"
256 #define ACPI_DEVICE_PATH_ITEM	"acpi/path"
257 #define ACPI_DEVICE_TYPE_ITEM	"acpi/type"
258 
259 
260 typedef struct acpi_device_cookie *acpi_device;
261 
262 //	Interface to one ACPI device.
263 typedef struct acpi_device_module_info {
264 	driver_module_info info;
265 
266 	/* Notify Handler */
267 
268 	status_t	(*install_notify_handler)(acpi_device device,
269     				uint32 handlerType, acpi_notify_handler handler,
270     				void *context);
271 	status_t	(*remove_notify_handler)(acpi_device device,
272     				uint32 handlerType, acpi_notify_handler handler);
273 
274 	/* Address Space Handler */
275 	status_t	(*install_address_space_handler)(acpi_device device,
276 					uint32 spaceId,
277 					acpi_adr_space_handler handler,
278 					acpi_adr_space_setup setup,	void *data);
279 	status_t	(*remove_address_space_handler)(acpi_device device,
280 					uint32 spaceId,
281 					acpi_adr_space_handler handler);
282 
283 	/* Namespace Access */
284 	uint32		(*get_object_type)(acpi_device device);
285 	status_t	(*get_object)(acpi_device device, const char *path,
286 					acpi_object_type **_returnValue);
287 
288 	/* Control method execution and data acquisition */
289 	status_t	(*evaluate_method)(acpi_device device, const char *method,
290 					acpi_objects *args, acpi_data *returnValue);
291 } acpi_device_module_info;
292 
293 
294 #endif	/* _ACPI_H */
295