xref: /haiku/headers/os/drivers/ACPI.h (revision 03187b607b2b5eec7ee059f1ead09bdba14991fb)
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 /* This must be uint64 for 64 bit! */
19 typedef uint32 acpi_physical_address;
20 typedef uint32 acpi_io_address;
21 typedef uint32 acpi_size;
22 
23 /* Actually a ptr to a NS Node */
24 typedef void *				acpi_handle;
25 
26 #ifndef __ACTYPES_H__
27 
28 /* Address Space (Operation Region) Types */
29 
30 enum {
31 	ACPI_ADR_SPACE_SYSTEM_MEMORY	= 0,
32 	ACPI_ADR_SPACE_SYSTEM_IO		= 1,
33 	ACPI_ADR_SPACE_PCI_CONFIG		= 2,
34 	ACPI_ADR_SPACE_EC				= 3,
35 	ACPI_ADR_SPACE_SMBUS			= 4,
36 	ACPI_ADR_SPACE_CMOS 			= 5,
37 	ACPI_ADR_SPACE_PCI_BAR_TARGET	= 6,
38 	ACPI_ADR_SPACE_DATA_TABLE		= 7,
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_LOCAL_REFERENCE = 0x14
71 };
72 
73 /* ACPI control method arg type */
74 
75 struct acpi_object_type {
76 	uint32 object_type;
77 	union {
78 		uint32 integer;
79 		struct {
80 			uint32 len;
81 			char *string; /* You have to allocate string space yourself */
82 		} string;
83 		struct {
84 			size_t length;
85 			void *buffer;
86 		} buffer;
87 		struct {
88 			uint32 count;
89 			acpi_object_type *objects;
90 		} package;
91 		struct
92 	    {
93 	        uint32 type;
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 #endif	// __ACTYPES_H__
131 
132 
133 typedef uint32 (*acpi_event_handler)(void *Context);
134 
135 typedef status_t (*acpi_adr_space_handler)(uint32 function,
136 	acpi_physical_address address, uint32 bitWidth, int *value,
137 	void *handlerContext, void *regionContext);
138 
139 typedef status_t (*acpi_adr_space_setup)(acpi_handle regionHandle,
140 	uint32 function, void *handlerContext, void **regionContext);
141 
142 typedef void (*acpi_notify_handler)(acpi_handle device, uint32 value,
143 	void *context);
144 
145 
146 struct acpi_module_info {
147 	module_info info;
148 
149 	status_t	(*get_handle)(acpi_handle parent, char *pathname,
150 					acpi_handle *retHandle);
151 
152 	/* Global Lock */
153 
154 	status_t	(*acquire_global_lock)(uint16 timeout, uint32 *handle);
155 	status_t	(*release_global_lock)(uint32 handle);
156 
157 	/* Notify Handler */
158 
159     status_t	(*install_notify_handler)(acpi_handle device,
160     				uint32 handlerType, acpi_notify_handler handler,
161     				void *context);
162 	status_t	(*remove_notify_handler)(acpi_handle device,
163     				uint32 handlerType, acpi_notify_handler handler);
164 
165 	/* GPE Handler */
166 
167 	status_t	(*enable_gpe)(acpi_handle handle, uint32 gpeNumber,
168 					uint32 flags);
169 	status_t	(*set_gpe_type)(acpi_handle handle, uint32 gpeNumber,
170 					uint8 type);
171 	status_t	(*install_gpe_handler)(acpi_handle handle, uint32 gpeNumber,
172 					uint32 type, acpi_event_handler handler, void *data);
173 	status_t	(*remove_gpe_handler)(acpi_handle handle, uint32 gpeNumber,
174 					acpi_event_handler address);
175 
176 	/* Address Space Handler */
177 
178 	status_t	(*install_address_space_handler)(acpi_handle handle,
179 					uint32 spaceId,
180 					acpi_adr_space_handler handler,
181 					acpi_adr_space_setup setup,	void *data);
182 	status_t	(*remove_address_space_handler)(acpi_handle handle,
183 					uint32 spaceId,
184 					acpi_adr_space_handler handler);
185 
186 	/* Fixed Event Management */
187 
188 	void		(*enable_fixed_event)(uint32 event);
189 	void		(*disable_fixed_event)(uint32 event);
190 
191 	uint32		(*fixed_event_status) (uint32 event);
192 					/* Returns 1 if event set, 0 otherwise */
193 	void		(*reset_fixed_event) (uint32 event);
194 
195 	status_t	(*install_fixed_event_handler)(uint32 event,
196 					interrupt_handler *handler, void *data);
197 	status_t	(*remove_fixed_event_handler)(uint32 event,
198 					interrupt_handler *handler);
199 
200 	/* Namespace Access */
201 
202 	status_t	(*get_next_entry)(uint32 objectType, const char *base,
203 					char *result, size_t length, void **_counter);
204 	status_t	(*get_device)(const char *hid, uint32 index, char *result,
205 					size_t resultLength);
206 
207 	status_t	(*get_device_hid)(const char *path, char *hid,
208 					size_t hidLength);
209 	uint32		(*get_object_type)(const char *path);
210 	status_t	(*get_object)(const char *path,
211 					acpi_object_type **_returnValue);
212 	status_t	(*get_object_typed)(const char *path,
213 					acpi_object_type **_returnValue, uint32 objectType);
214 
215 	/* Control method execution and data acquisition */
216 
217 	status_t	(*evaluate_object)(const char* object,
218 					acpi_object_type *returnValue, size_t bufferLength);
219 	status_t	(*evaluate_method)(acpi_handle handle, const char *method,
220 					acpi_objects *args, acpi_data *returnValue);
221 
222 	/* Power state setting */
223 
224 	status_t	(*prepare_sleep_state)(uint8 state, void (*wakeFunc)(void),
225 					size_t size);
226 	status_t	(*enter_sleep_state)(uint8 state);
227 	status_t	(*reboot)(void);
228 };
229 
230 
231 /* Sleep states */
232 
233 enum {
234 	ACPI_POWER_STATE_ON = 0,
235 	ACPI_POWER_STATE_SLEEP_S1,
236 	ACPI_POWER_STATE_SLEEP_S2,
237 	ACPI_POWER_STATE_SLEEP_S3,
238 	ACPI_POWER_STATE_HIBERNATE,
239 	ACPI_POWER_STATE_OFF
240 };
241 
242 
243 #define ACPI_DEVICE_HID_ITEM	"acpi/hid"
244 #define ACPI_DEVICE_PATH_ITEM	"acpi/path"
245 #define ACPI_DEVICE_TYPE_ITEM	"acpi/type"
246 
247 
248 typedef struct acpi_device_cookie *acpi_device;
249 
250 //	Interface to one ACPI device.
251 typedef struct acpi_device_module_info {
252 	driver_module_info info;
253 
254 	/* Notify Handler */
255 
256 	status_t	(*install_notify_handler)(acpi_device device,
257     				uint32 handlerType, acpi_notify_handler handler,
258     				void *context);
259 	status_t	(*remove_notify_handler)(acpi_device device,
260     				uint32 handlerType, acpi_notify_handler handler);
261 
262 	/* Address Space Handler */
263 	status_t	(*install_address_space_handler)(acpi_device device,
264 					uint32 spaceId,
265 					acpi_adr_space_handler handler,
266 					acpi_adr_space_setup setup,	void *data);
267 	status_t	(*remove_address_space_handler)(acpi_device device,
268 					uint32 spaceId,
269 					acpi_adr_space_handler handler);
270 
271 	/* Namespace Access */
272 	uint32		(*get_object_type)(acpi_device device);
273 	status_t	(*get_object)(acpi_device device, const char *path,
274 					acpi_object_type **_returnValue);
275 
276 	/* Control method execution and data acquisition */
277 	status_t	(*evaluate_method)(acpi_device device, const char *method,
278 					acpi_objects *args, acpi_data *returnValue);
279 } acpi_device_module_info;
280 
281 
282 #endif	/* _ACPI_H */
283