1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44#define EXPORT_ACPI_INTERFACES
45
46#include <acpi/acpi.h>
47#include "accommon.h"
48#include "actables.h"
49
50#define _COMPONENT ACPI_EVENTS
51ACPI_MODULE_NAME("evxfevnt")
52
53#if (!ACPI_REDUCED_HARDWARE)
54
55
56
57
58
59
60
61
62
63
64
65acpi_status acpi_enable(void)
66{
67 acpi_status status;
68 int retry;
69
70 ACPI_FUNCTION_TRACE(acpi_enable);
71
72
73
74 if (acpi_gbl_fadt_index == ACPI_INVALID_TABLE_INDEX) {
75 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
76 }
77
78
79
80 if (acpi_gbl_reduced_hardware) {
81 return_ACPI_STATUS(AE_OK);
82 }
83
84
85
86 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
87 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
88 "System is already in ACPI mode\n"));
89 return_ACPI_STATUS(AE_OK);
90 }
91
92
93
94 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
95 if (ACPI_FAILURE(status)) {
96 ACPI_ERROR((AE_INFO,
97 "Could not transition to ACPI mode"));
98 return_ACPI_STATUS(status);
99 }
100
101
102
103 for (retry = 0; retry < 30000; ++retry) {
104 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
105 if (retry != 0)
106 ACPI_WARNING((AE_INFO,
107 "Platform took > %d00 usec to enter ACPI mode", retry));
108 return_ACPI_STATUS(AE_OK);
109 }
110 acpi_os_stall(100);
111 }
112
113 ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
114 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
115}
116
117ACPI_EXPORT_SYMBOL(acpi_enable)
118
119
120
121
122
123
124
125
126
127
128
129
130acpi_status acpi_disable(void)
131{
132 acpi_status status = AE_OK;
133
134 ACPI_FUNCTION_TRACE(acpi_disable);
135
136
137
138 if (acpi_gbl_reduced_hardware) {
139 return_ACPI_STATUS(AE_OK);
140 }
141
142 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
143 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
144 "System is already in legacy (non-ACPI) mode\n"));
145 } else {
146
147
148 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
149
150 if (ACPI_FAILURE(status)) {
151 ACPI_ERROR((AE_INFO,
152 "Could not exit ACPI mode to legacy mode"));
153 return_ACPI_STATUS(status);
154 }
155
156 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
157 }
158
159 return_ACPI_STATUS(status);
160}
161
162ACPI_EXPORT_SYMBOL(acpi_disable)
163
164
165
166
167
168
169
170
171
172
173
174
175
176acpi_status acpi_enable_event(u32 event, u32 flags)
177{
178 acpi_status status = AE_OK;
179 u32 value;
180
181 ACPI_FUNCTION_TRACE(acpi_enable_event);
182
183
184
185 if (acpi_gbl_reduced_hardware) {
186 return_ACPI_STATUS(AE_OK);
187 }
188
189
190
191 if (event > ACPI_EVENT_MAX) {
192 return_ACPI_STATUS(AE_BAD_PARAMETER);
193 }
194
195
196
197
198
199 status =
200 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
201 enable_register_id, ACPI_ENABLE_EVENT);
202 if (ACPI_FAILURE(status)) {
203 return_ACPI_STATUS(status);
204 }
205
206
207
208 status =
209 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
210 enable_register_id, &value);
211 if (ACPI_FAILURE(status)) {
212 return_ACPI_STATUS(status);
213 }
214
215 if (value != 1) {
216 ACPI_ERROR((AE_INFO,
217 "Could not enable %s event",
218 acpi_ut_get_event_name(event)));
219 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
220 }
221
222 return_ACPI_STATUS(status);
223}
224
225ACPI_EXPORT_SYMBOL(acpi_enable_event)
226
227
228
229
230
231
232
233
234
235
236
237
238
239acpi_status acpi_disable_event(u32 event, u32 flags)
240{
241 acpi_status status = AE_OK;
242 u32 value;
243
244 ACPI_FUNCTION_TRACE(acpi_disable_event);
245
246
247
248 if (acpi_gbl_reduced_hardware) {
249 return_ACPI_STATUS(AE_OK);
250 }
251
252
253
254 if (event > ACPI_EVENT_MAX) {
255 return_ACPI_STATUS(AE_BAD_PARAMETER);
256 }
257
258
259
260
261
262 status =
263 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
264 enable_register_id, ACPI_DISABLE_EVENT);
265 if (ACPI_FAILURE(status)) {
266 return_ACPI_STATUS(status);
267 }
268
269 status =
270 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
271 enable_register_id, &value);
272 if (ACPI_FAILURE(status)) {
273 return_ACPI_STATUS(status);
274 }
275
276 if (value != 0) {
277 ACPI_ERROR((AE_INFO,
278 "Could not disable %s events",
279 acpi_ut_get_event_name(event)));
280 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
281 }
282
283 return_ACPI_STATUS(status);
284}
285
286ACPI_EXPORT_SYMBOL(acpi_disable_event)
287
288
289
290
291
292
293
294
295
296
297
298
299acpi_status acpi_clear_event(u32 event)
300{
301 acpi_status status = AE_OK;
302
303 ACPI_FUNCTION_TRACE(acpi_clear_event);
304
305
306
307 if (acpi_gbl_reduced_hardware) {
308 return_ACPI_STATUS(AE_OK);
309 }
310
311
312
313 if (event > ACPI_EVENT_MAX) {
314 return_ACPI_STATUS(AE_BAD_PARAMETER);
315 }
316
317
318
319
320
321 status =
322 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
323 status_register_id, ACPI_CLEAR_STATUS);
324
325 return_ACPI_STATUS(status);
326}
327
328ACPI_EXPORT_SYMBOL(acpi_clear_event)
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
344{
345 acpi_status status;
346 acpi_event_status local_event_status = 0;
347 u32 in_byte;
348
349 ACPI_FUNCTION_TRACE(acpi_get_event_status);
350
351 if (!event_status) {
352 return_ACPI_STATUS(AE_BAD_PARAMETER);
353 }
354
355
356
357 if (event > ACPI_EVENT_MAX) {
358 return_ACPI_STATUS(AE_BAD_PARAMETER);
359 }
360
361
362
363 if (acpi_gbl_fixed_event_handlers[event].handler) {
364 local_event_status |= ACPI_EVENT_FLAG_HAS_HANDLER;
365 }
366
367
368
369 status =
370 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
371 enable_register_id, &in_byte);
372 if (ACPI_FAILURE(status)) {
373 return_ACPI_STATUS(status);
374 }
375
376 if (in_byte) {
377 local_event_status |=
378 (ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET);
379 }
380
381
382
383 status =
384 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
385 status_register_id, &in_byte);
386 if (ACPI_FAILURE(status)) {
387 return_ACPI_STATUS(status);
388 }
389
390 if (in_byte) {
391 local_event_status |= ACPI_EVENT_FLAG_STATUS_SET;
392 }
393
394 (*event_status) = local_event_status;
395 return_ACPI_STATUS(AE_OK);
396}
397
398ACPI_EXPORT_SYMBOL(acpi_get_event_status)
399#endif
400