]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
75a44ce0 | 8 | * Copyright (C) 2000 - 2008, Intel Corp. |
1da177e4 LT |
9 | * All rights reserved. |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions, and the following disclaimer, | |
16 | * without modification. | |
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
18 | * substantially similar to the "NO WARRANTY" disclaimer below | |
19 | * ("Disclaimer") and any redistribution must be conditioned upon | |
20 | * including a substantially similar Disclaimer requirement for further | |
21 | * binary redistribution. | |
22 | * 3. Neither the names of the above-listed copyright holders nor the names | |
23 | * of any contributors may be used to endorse or promote products derived | |
24 | * from this software without specific prior written permission. | |
25 | * | |
26 | * Alternatively, this software may be distributed under the terms of the | |
27 | * GNU General Public License ("GPL") version 2 as published by the Free | |
28 | * Software Foundation. | |
29 | * | |
30 | * NO WARRANTY | |
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
41 | * POSSIBILITY OF SUCH DAMAGES. | |
42 | */ | |
43 | ||
1da177e4 | 44 | #include <acpi/acpi.h> |
e2f7a777 LB |
45 | #include "accommon.h" |
46 | #include "acevents.h" | |
47 | #include "acnamesp.h" | |
48 | #include "actables.h" | |
1da177e4 LT |
49 | |
50 | #define _COMPONENT ACPI_EVENTS | |
4be44fcd | 51 | ACPI_MODULE_NAME("evxfevnt") |
1da177e4 | 52 | |
e97d6bf1 | 53 | /* Local prototypes */ |
e4c1ebfc | 54 | static acpi_status |
e97d6bf1 BM |
55 | acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info, |
56 | struct acpi_gpe_block_info *gpe_block, void *context); | |
57 | ||
1da177e4 LT |
58 | /******************************************************************************* |
59 | * | |
60 | * FUNCTION: acpi_enable | |
61 | * | |
62 | * PARAMETERS: None | |
63 | * | |
64 | * RETURN: Status | |
65 | * | |
66 | * DESCRIPTION: Transfers the system into ACPI mode. | |
67 | * | |
68 | ******************************************************************************/ | |
e97d6bf1 | 69 | |
4be44fcd | 70 | acpi_status acpi_enable(void) |
1da177e4 | 71 | { |
4be44fcd | 72 | acpi_status status = AE_OK; |
1da177e4 | 73 | |
b229cf92 | 74 | ACPI_FUNCTION_TRACE(acpi_enable); |
1da177e4 | 75 | |
c857303a BM |
76 | /* ACPI tables must be present */ |
77 | ||
78 | if (!acpi_tb_tables_loaded()) { | |
79 | return_ACPI_STATUS(AE_NO_ACPI_TABLES); | |
80 | } | |
81 | ||
82 | /* Check current mode */ | |
83 | ||
1da177e4 | 84 | if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) { |
4be44fcd LB |
85 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
86 | "System is already in ACPI mode\n")); | |
87 | } else { | |
1da177e4 LT |
88 | /* Transition to ACPI mode */ |
89 | ||
4be44fcd LB |
90 | status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI); |
91 | if (ACPI_FAILURE(status)) { | |
b8e4d893 BM |
92 | ACPI_ERROR((AE_INFO, |
93 | "Could not transition to ACPI mode")); | |
4be44fcd | 94 | return_ACPI_STATUS(status); |
1da177e4 LT |
95 | } |
96 | ||
4be44fcd LB |
97 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
98 | "Transition to ACPI mode successful\n")); | |
1da177e4 LT |
99 | } |
100 | ||
4be44fcd | 101 | return_ACPI_STATUS(status); |
1da177e4 LT |
102 | } |
103 | ||
8313524a BM |
104 | ACPI_EXPORT_SYMBOL(acpi_enable) |
105 | ||
1da177e4 LT |
106 | /******************************************************************************* |
107 | * | |
108 | * FUNCTION: acpi_disable | |
109 | * | |
110 | * PARAMETERS: None | |
111 | * | |
112 | * RETURN: Status | |
113 | * | |
44f6c012 | 114 | * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode. |
1da177e4 LT |
115 | * |
116 | ******************************************************************************/ | |
4be44fcd | 117 | acpi_status acpi_disable(void) |
1da177e4 | 118 | { |
4be44fcd | 119 | acpi_status status = AE_OK; |
1da177e4 | 120 | |
b229cf92 | 121 | ACPI_FUNCTION_TRACE(acpi_disable); |
1da177e4 | 122 | |
1da177e4 | 123 | if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) { |
4be44fcd LB |
124 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
125 | "System is already in legacy (non-ACPI) mode\n")); | |
126 | } else { | |
1da177e4 LT |
127 | /* Transition to LEGACY mode */ |
128 | ||
4be44fcd | 129 | status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY); |
1da177e4 | 130 | |
4be44fcd | 131 | if (ACPI_FAILURE(status)) { |
b8e4d893 BM |
132 | ACPI_ERROR((AE_INFO, |
133 | "Could not exit ACPI mode to legacy mode")); | |
4be44fcd | 134 | return_ACPI_STATUS(status); |
1da177e4 LT |
135 | } |
136 | ||
4be44fcd | 137 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n")); |
1da177e4 LT |
138 | } |
139 | ||
4be44fcd | 140 | return_ACPI_STATUS(status); |
1da177e4 LT |
141 | } |
142 | ||
8313524a BM |
143 | ACPI_EXPORT_SYMBOL(acpi_disable) |
144 | ||
1da177e4 LT |
145 | /******************************************************************************* |
146 | * | |
147 | * FUNCTION: acpi_enable_event | |
148 | * | |
149 | * PARAMETERS: Event - The fixed eventto be enabled | |
150 | * Flags - Reserved | |
151 | * | |
152 | * RETURN: Status | |
153 | * | |
154 | * DESCRIPTION: Enable an ACPI event (fixed) | |
155 | * | |
156 | ******************************************************************************/ | |
4be44fcd | 157 | acpi_status acpi_enable_event(u32 event, u32 flags) |
1da177e4 | 158 | { |
4be44fcd LB |
159 | acpi_status status = AE_OK; |
160 | u32 value; | |
1da177e4 | 161 | |
b229cf92 | 162 | ACPI_FUNCTION_TRACE(acpi_enable_event); |
1da177e4 LT |
163 | |
164 | /* Decode the Fixed Event */ | |
165 | ||
166 | if (event > ACPI_EVENT_MAX) { | |
4be44fcd | 167 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
168 | } |
169 | ||
170 | /* | |
9f15fc66 BM |
171 | * Enable the requested fixed event (by writing a one to the enable |
172 | * register bit) | |
1da177e4 | 173 | */ |
4be44fcd | 174 | status = |
50ffba1b | 175 | acpi_write_bit_register(acpi_gbl_fixed_event_info[event]. |
768aaaf1 | 176 | enable_register_id, ACPI_ENABLE_EVENT); |
4be44fcd LB |
177 | if (ACPI_FAILURE(status)) { |
178 | return_ACPI_STATUS(status); | |
1da177e4 LT |
179 | } |
180 | ||
181 | /* Make sure that the hardware responded */ | |
182 | ||
4be44fcd | 183 | status = |
50ffba1b BM |
184 | acpi_read_bit_register(acpi_gbl_fixed_event_info[event]. |
185 | enable_register_id, &value); | |
4be44fcd LB |
186 | if (ACPI_FAILURE(status)) { |
187 | return_ACPI_STATUS(status); | |
1da177e4 LT |
188 | } |
189 | ||
190 | if (value != 1) { | |
b8e4d893 BM |
191 | ACPI_ERROR((AE_INFO, |
192 | "Could not enable %s event", | |
193 | acpi_ut_get_event_name(event))); | |
4be44fcd | 194 | return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE); |
1da177e4 LT |
195 | } |
196 | ||
4be44fcd | 197 | return_ACPI_STATUS(status); |
1da177e4 | 198 | } |
1da177e4 | 199 | |
8313524a | 200 | ACPI_EXPORT_SYMBOL(acpi_enable_event) |
1da177e4 LT |
201 | |
202 | /******************************************************************************* | |
203 | * | |
9630bdd9 | 204 | * FUNCTION: acpi_set_gpe |
1da177e4 LT |
205 | * |
206 | * PARAMETERS: gpe_device - Parent GPE Device | |
207 | * gpe_number - GPE level within the GPE block | |
9630bdd9 RW |
208 | * action - Enable or disable |
209 | * Called from ISR or not | |
1da177e4 LT |
210 | * |
211 | * RETURN: Status | |
212 | * | |
9630bdd9 | 213 | * DESCRIPTION: Enable or disable an ACPI event (general purpose) |
1da177e4 LT |
214 | * |
215 | ******************************************************************************/ | |
9630bdd9 | 216 | acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action) |
1da177e4 | 217 | { |
4be44fcd | 218 | acpi_status status = AE_OK; |
9630bdd9 | 219 | acpi_cpu_flags flags; |
4be44fcd | 220 | struct acpi_gpe_event_info *gpe_event_info; |
1da177e4 | 221 | |
9630bdd9 RW |
222 | ACPI_FUNCTION_TRACE(acpi_set_gpe); |
223 | ||
224 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); | |
1da177e4 LT |
225 | |
226 | /* Ensure that we have a valid GPE number */ | |
227 | ||
4be44fcd | 228 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
229 | if (!gpe_event_info) { |
230 | status = AE_BAD_PARAMETER; | |
231 | goto unlock_and_exit; | |
232 | } | |
233 | ||
9630bdd9 RW |
234 | /* Perform the action */ |
235 | ||
236 | switch (action) { | |
237 | case ACPI_GPE_ENABLE: | |
238 | status = acpi_ev_enable_gpe(gpe_event_info, TRUE); | |
239 | break; | |
1da177e4 | 240 | |
9630bdd9 RW |
241 | case ACPI_GPE_DISABLE: |
242 | status = acpi_ev_disable_gpe(gpe_event_info); | |
243 | break; | |
1da177e4 | 244 | |
9630bdd9 RW |
245 | default: |
246 | ACPI_ERROR((AE_INFO, "Invalid action\n")); | |
247 | status = AE_BAD_PARAMETER; | |
248 | break; | |
249 | } | |
1da177e4 | 250 | |
4be44fcd | 251 | unlock_and_exit: |
9630bdd9 | 252 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
4be44fcd | 253 | return_ACPI_STATUS(status); |
1da177e4 | 254 | } |
1da177e4 | 255 | |
9630bdd9 | 256 | ACPI_EXPORT_SYMBOL(acpi_set_gpe) |
1da177e4 LT |
257 | |
258 | /******************************************************************************* | |
259 | * | |
260 | * FUNCTION: acpi_enable_gpe | |
261 | * | |
262 | * PARAMETERS: gpe_device - Parent GPE Device | |
263 | * gpe_number - GPE level within the GPE block | |
9630bdd9 | 264 | * type - Purpose the GPE will be used for |
1da177e4 LT |
265 | * |
266 | * RETURN: Status | |
267 | * | |
9630bdd9 | 268 | * DESCRIPTION: Take a reference to a GPE and enable it if necessary |
1da177e4 LT |
269 | * |
270 | ******************************************************************************/ | |
9630bdd9 | 271 | acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type) |
1da177e4 | 272 | { |
4be44fcd | 273 | acpi_status status = AE_OK; |
0b7084ac | 274 | acpi_cpu_flags flags; |
4be44fcd | 275 | struct acpi_gpe_event_info *gpe_event_info; |
1da177e4 | 276 | |
b229cf92 | 277 | ACPI_FUNCTION_TRACE(acpi_enable_gpe); |
1da177e4 | 278 | |
0b7084ac | 279 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
1da177e4 LT |
280 | |
281 | /* Ensure that we have a valid GPE number */ | |
282 | ||
4be44fcd | 283 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
284 | if (!gpe_event_info) { |
285 | status = AE_BAD_PARAMETER; | |
286 | goto unlock_and_exit; | |
287 | } | |
288 | ||
9630bdd9 RW |
289 | if (type & ACPI_GPE_TYPE_RUNTIME) { |
290 | if (++gpe_event_info->runtime_count == 1) | |
291 | status = acpi_ev_enable_gpe(gpe_event_info, TRUE); | |
1da177e4 | 292 | |
9630bdd9 RW |
293 | if (ACPI_FAILURE(status)) |
294 | gpe_event_info->runtime_count--; | |
295 | } | |
1da177e4 | 296 | |
9630bdd9 RW |
297 | if (type & ACPI_GPE_TYPE_WAKE) { |
298 | if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) { | |
299 | status = AE_BAD_PARAMETER; | |
300 | goto unlock_and_exit; | |
301 | } | |
302 | ||
303 | /* | |
304 | * Wake-up GPEs are only enabled right prior to putting the | |
305 | * system into a sleep state. | |
306 | */ | |
307 | if (++gpe_event_info->wakeup_count == 1) | |
308 | acpi_ev_update_gpe_enable_masks(gpe_event_info); | |
309 | } | |
310 | ||
311 | unlock_and_exit: | |
0b7084ac | 312 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
4be44fcd | 313 | return_ACPI_STATUS(status); |
1da177e4 | 314 | } |
8313524a | 315 | ACPI_EXPORT_SYMBOL(acpi_enable_gpe) |
1da177e4 LT |
316 | |
317 | /******************************************************************************* | |
318 | * | |
319 | * FUNCTION: acpi_disable_gpe | |
320 | * | |
321 | * PARAMETERS: gpe_device - Parent GPE Device | |
322 | * gpe_number - GPE level within the GPE block | |
9630bdd9 | 323 | * type - Purpose the GPE won't be used for any more |
1da177e4 LT |
324 | * |
325 | * RETURN: Status | |
326 | * | |
9630bdd9 | 327 | * DESCRIPTION: Release a reference to a GPE and disable it if necessary |
1da177e4 LT |
328 | * |
329 | ******************************************************************************/ | |
9630bdd9 | 330 | acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type) |
1da177e4 | 331 | { |
4be44fcd | 332 | acpi_status status = AE_OK; |
0b7084ac | 333 | acpi_cpu_flags flags; |
4be44fcd | 334 | struct acpi_gpe_event_info *gpe_event_info; |
1da177e4 | 335 | |
b229cf92 | 336 | ACPI_FUNCTION_TRACE(acpi_disable_gpe); |
1da177e4 | 337 | |
0b7084ac | 338 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
1da177e4 LT |
339 | /* Ensure that we have a valid GPE number */ |
340 | ||
4be44fcd | 341 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
342 | if (!gpe_event_info) { |
343 | status = AE_BAD_PARAMETER; | |
344 | goto unlock_and_exit; | |
345 | } | |
346 | ||
9630bdd9 RW |
347 | if ((type & ACPI_GPE_TYPE_WAKE) && gpe_event_info->runtime_count) { |
348 | if (--gpe_event_info->runtime_count == 0) | |
349 | acpi_ev_disable_gpe(gpe_event_info); | |
350 | } | |
351 | ||
352 | if ((type & ACPI_GPE_TYPE_RUNTIME) && gpe_event_info->wakeup_count) { | |
353 | /* | |
354 | * Wake-up GPEs are not enabled after leaving system sleep | |
355 | * states, so we don't need to disable them here. | |
356 | */ | |
357 | if (--gpe_event_info->wakeup_count == 0) | |
358 | acpi_ev_update_gpe_enable_masks(gpe_event_info); | |
359 | } | |
1da177e4 | 360 | |
0b7084ac AS |
361 | unlock_and_exit: |
362 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); | |
4be44fcd | 363 | return_ACPI_STATUS(status); |
1da177e4 | 364 | } |
8313524a BM |
365 | ACPI_EXPORT_SYMBOL(acpi_disable_gpe) |
366 | ||
1da177e4 LT |
367 | /******************************************************************************* |
368 | * | |
369 | * FUNCTION: acpi_disable_event | |
370 | * | |
371 | * PARAMETERS: Event - The fixed eventto be enabled | |
372 | * Flags - Reserved | |
373 | * | |
374 | * RETURN: Status | |
375 | * | |
376 | * DESCRIPTION: Disable an ACPI event (fixed) | |
377 | * | |
378 | ******************************************************************************/ | |
4be44fcd | 379 | acpi_status acpi_disable_event(u32 event, u32 flags) |
1da177e4 | 380 | { |
4be44fcd LB |
381 | acpi_status status = AE_OK; |
382 | u32 value; | |
1da177e4 | 383 | |
b229cf92 | 384 | ACPI_FUNCTION_TRACE(acpi_disable_event); |
1da177e4 LT |
385 | |
386 | /* Decode the Fixed Event */ | |
387 | ||
388 | if (event > ACPI_EVENT_MAX) { | |
4be44fcd | 389 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
390 | } |
391 | ||
392 | /* | |
9f15fc66 BM |
393 | * Disable the requested fixed event (by writing a zero to the enable |
394 | * register bit) | |
1da177e4 | 395 | */ |
4be44fcd | 396 | status = |
50ffba1b | 397 | acpi_write_bit_register(acpi_gbl_fixed_event_info[event]. |
768aaaf1 | 398 | enable_register_id, ACPI_DISABLE_EVENT); |
4be44fcd LB |
399 | if (ACPI_FAILURE(status)) { |
400 | return_ACPI_STATUS(status); | |
1da177e4 LT |
401 | } |
402 | ||
4be44fcd | 403 | status = |
50ffba1b BM |
404 | acpi_read_bit_register(acpi_gbl_fixed_event_info[event]. |
405 | enable_register_id, &value); | |
4be44fcd LB |
406 | if (ACPI_FAILURE(status)) { |
407 | return_ACPI_STATUS(status); | |
1da177e4 LT |
408 | } |
409 | ||
410 | if (value != 0) { | |
b8e4d893 BM |
411 | ACPI_ERROR((AE_INFO, |
412 | "Could not disable %s events", | |
413 | acpi_ut_get_event_name(event))); | |
4be44fcd | 414 | return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE); |
1da177e4 LT |
415 | } |
416 | ||
4be44fcd | 417 | return_ACPI_STATUS(status); |
1da177e4 | 418 | } |
1da177e4 | 419 | |
8313524a | 420 | ACPI_EXPORT_SYMBOL(acpi_disable_event) |
1da177e4 LT |
421 | |
422 | /******************************************************************************* | |
423 | * | |
424 | * FUNCTION: acpi_clear_event | |
425 | * | |
426 | * PARAMETERS: Event - The fixed event to be cleared | |
427 | * | |
428 | * RETURN: Status | |
429 | * | |
430 | * DESCRIPTION: Clear an ACPI event (fixed) | |
431 | * | |
432 | ******************************************************************************/ | |
4be44fcd | 433 | acpi_status acpi_clear_event(u32 event) |
1da177e4 | 434 | { |
4be44fcd | 435 | acpi_status status = AE_OK; |
1da177e4 | 436 | |
b229cf92 | 437 | ACPI_FUNCTION_TRACE(acpi_clear_event); |
1da177e4 LT |
438 | |
439 | /* Decode the Fixed Event */ | |
440 | ||
441 | if (event > ACPI_EVENT_MAX) { | |
4be44fcd | 442 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
443 | } |
444 | ||
445 | /* | |
9f15fc66 BM |
446 | * Clear the requested fixed event (By writing a one to the status |
447 | * register bit) | |
1da177e4 | 448 | */ |
4be44fcd | 449 | status = |
50ffba1b | 450 | acpi_write_bit_register(acpi_gbl_fixed_event_info[event]. |
768aaaf1 | 451 | status_register_id, ACPI_CLEAR_STATUS); |
1da177e4 | 452 | |
4be44fcd | 453 | return_ACPI_STATUS(status); |
1da177e4 | 454 | } |
1da177e4 | 455 | |
8313524a | 456 | ACPI_EXPORT_SYMBOL(acpi_clear_event) |
1da177e4 LT |
457 | |
458 | /******************************************************************************* | |
459 | * | |
460 | * FUNCTION: acpi_clear_gpe | |
461 | * | |
462 | * PARAMETERS: gpe_device - Parent GPE Device | |
463 | * gpe_number - GPE level within the GPE block | |
464 | * Flags - Called from an ISR or not | |
465 | * | |
466 | * RETURN: Status | |
467 | * | |
468 | * DESCRIPTION: Clear an ACPI event (general purpose) | |
469 | * | |
470 | ******************************************************************************/ | |
4be44fcd | 471 | acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags) |
1da177e4 | 472 | { |
4be44fcd LB |
473 | acpi_status status = AE_OK; |
474 | struct acpi_gpe_event_info *gpe_event_info; | |
1da177e4 | 475 | |
b229cf92 | 476 | ACPI_FUNCTION_TRACE(acpi_clear_gpe); |
1da177e4 LT |
477 | |
478 | /* Use semaphore lock if not executing at interrupt level */ | |
479 | ||
480 | if (flags & ACPI_NOT_ISR) { | |
4be44fcd LB |
481 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
482 | if (ACPI_FAILURE(status)) { | |
483 | return_ACPI_STATUS(status); | |
1da177e4 LT |
484 | } |
485 | } | |
486 | ||
487 | /* Ensure that we have a valid GPE number */ | |
488 | ||
4be44fcd | 489 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
490 | if (!gpe_event_info) { |
491 | status = AE_BAD_PARAMETER; | |
492 | goto unlock_and_exit; | |
493 | } | |
494 | ||
4be44fcd | 495 | status = acpi_hw_clear_gpe(gpe_event_info); |
1da177e4 | 496 | |
4be44fcd | 497 | unlock_and_exit: |
1da177e4 | 498 | if (flags & ACPI_NOT_ISR) { |
4be44fcd | 499 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
1da177e4 | 500 | } |
4be44fcd | 501 | return_ACPI_STATUS(status); |
1da177e4 LT |
502 | } |
503 | ||
8313524a | 504 | ACPI_EXPORT_SYMBOL(acpi_clear_gpe) |
1da177e4 LT |
505 | /******************************************************************************* |
506 | * | |
507 | * FUNCTION: acpi_get_event_status | |
508 | * | |
509 | * PARAMETERS: Event - The fixed event | |
44f6c012 | 510 | * event_status - Where the current status of the event will |
1da177e4 LT |
511 | * be returned |
512 | * | |
513 | * RETURN: Status | |
514 | * | |
515 | * DESCRIPTION: Obtains and returns the current status of the event | |
516 | * | |
517 | ******************************************************************************/ | |
4be44fcd | 518 | acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status) |
1da177e4 | 519 | { |
4be44fcd | 520 | acpi_status status = AE_OK; |
71b58cbb | 521 | u32 value; |
1da177e4 | 522 | |
b229cf92 | 523 | ACPI_FUNCTION_TRACE(acpi_get_event_status); |
1da177e4 LT |
524 | |
525 | if (!event_status) { | |
4be44fcd | 526 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
527 | } |
528 | ||
529 | /* Decode the Fixed Event */ | |
530 | ||
531 | if (event > ACPI_EVENT_MAX) { | |
4be44fcd | 532 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
533 | } |
534 | ||
535 | /* Get the status of the requested fixed event */ | |
536 | ||
4be44fcd | 537 | status = |
50ffba1b | 538 | acpi_read_bit_register(acpi_gbl_fixed_event_info[event]. |
71b58cbb ZR |
539 | enable_register_id, &value); |
540 | if (ACPI_FAILURE(status)) | |
541 | return_ACPI_STATUS(status); | |
542 | ||
543 | *event_status = value; | |
544 | ||
545 | status = | |
50ffba1b | 546 | acpi_read_bit_register(acpi_gbl_fixed_event_info[event]. |
71b58cbb ZR |
547 | status_register_id, &value); |
548 | if (ACPI_FAILURE(status)) | |
549 | return_ACPI_STATUS(status); | |
550 | ||
551 | if (value) | |
552 | *event_status |= ACPI_EVENT_FLAG_SET; | |
1da177e4 | 553 | |
ed206fac ZR |
554 | if (acpi_gbl_fixed_event_handlers[event].handler) |
555 | *event_status |= ACPI_EVENT_FLAG_HANDLE; | |
556 | ||
4be44fcd | 557 | return_ACPI_STATUS(status); |
1da177e4 LT |
558 | } |
559 | ||
8313524a BM |
560 | ACPI_EXPORT_SYMBOL(acpi_get_event_status) |
561 | ||
1da177e4 LT |
562 | /******************************************************************************* |
563 | * | |
564 | * FUNCTION: acpi_get_gpe_status | |
565 | * | |
566 | * PARAMETERS: gpe_device - Parent GPE Device | |
567 | * gpe_number - GPE level within the GPE block | |
568 | * Flags - Called from an ISR or not | |
44f6c012 | 569 | * event_status - Where the current status of the event will |
1da177e4 LT |
570 | * be returned |
571 | * | |
572 | * RETURN: Status | |
573 | * | |
574 | * DESCRIPTION: Get status of an event (general purpose) | |
575 | * | |
576 | ******************************************************************************/ | |
1da177e4 | 577 | acpi_status |
4be44fcd LB |
578 | acpi_get_gpe_status(acpi_handle gpe_device, |
579 | u32 gpe_number, u32 flags, acpi_event_status * event_status) | |
1da177e4 | 580 | { |
4be44fcd LB |
581 | acpi_status status = AE_OK; |
582 | struct acpi_gpe_event_info *gpe_event_info; | |
1da177e4 | 583 | |
b229cf92 | 584 | ACPI_FUNCTION_TRACE(acpi_get_gpe_status); |
1da177e4 LT |
585 | |
586 | /* Use semaphore lock if not executing at interrupt level */ | |
587 | ||
588 | if (flags & ACPI_NOT_ISR) { | |
4be44fcd LB |
589 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
590 | if (ACPI_FAILURE(status)) { | |
591 | return_ACPI_STATUS(status); | |
1da177e4 LT |
592 | } |
593 | } | |
594 | ||
595 | /* Ensure that we have a valid GPE number */ | |
596 | ||
4be44fcd | 597 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
598 | if (!gpe_event_info) { |
599 | status = AE_BAD_PARAMETER; | |
600 | goto unlock_and_exit; | |
601 | } | |
602 | ||
603 | /* Obtain status on the requested GPE number */ | |
604 | ||
4be44fcd | 605 | status = acpi_hw_get_gpe_status(gpe_event_info, event_status); |
1da177e4 | 606 | |
ed206fac ZR |
607 | if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) |
608 | *event_status |= ACPI_EVENT_FLAG_HANDLE; | |
609 | ||
4be44fcd | 610 | unlock_and_exit: |
1da177e4 | 611 | if (flags & ACPI_NOT_ISR) { |
4be44fcd | 612 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
1da177e4 | 613 | } |
4be44fcd | 614 | return_ACPI_STATUS(status); |
1da177e4 | 615 | } |
8313524a BM |
616 | |
617 | ACPI_EXPORT_SYMBOL(acpi_get_gpe_status) | |
1da177e4 LT |
618 | /******************************************************************************* |
619 | * | |
620 | * FUNCTION: acpi_install_gpe_block | |
621 | * | |
622 | * PARAMETERS: gpe_device - Handle to the parent GPE Block Device | |
623 | * gpe_block_address - Address and space_iD | |
624 | * register_count - Number of GPE register pairs in the block | |
6f42ccf2 | 625 | * interrupt_number - H/W interrupt for the block |
1da177e4 LT |
626 | * |
627 | * RETURN: Status | |
628 | * | |
629 | * DESCRIPTION: Create and Install a block of GPE registers | |
630 | * | |
631 | ******************************************************************************/ | |
1da177e4 | 632 | acpi_status |
4be44fcd LB |
633 | acpi_install_gpe_block(acpi_handle gpe_device, |
634 | struct acpi_generic_address *gpe_block_address, | |
635 | u32 register_count, u32 interrupt_number) | |
1da177e4 | 636 | { |
4be44fcd LB |
637 | acpi_status status; |
638 | union acpi_operand_object *obj_desc; | |
639 | struct acpi_namespace_node *node; | |
640 | struct acpi_gpe_block_info *gpe_block; | |
1da177e4 | 641 | |
b229cf92 | 642 | ACPI_FUNCTION_TRACE(acpi_install_gpe_block); |
1da177e4 | 643 | |
4be44fcd LB |
644 | if ((!gpe_device) || (!gpe_block_address) || (!register_count)) { |
645 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
1da177e4 LT |
646 | } |
647 | ||
4be44fcd LB |
648 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
649 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
650 | return (status); |
651 | } | |
652 | ||
f24b664d | 653 | node = acpi_ns_validate_handle(gpe_device); |
1da177e4 LT |
654 | if (!node) { |
655 | status = AE_BAD_PARAMETER; | |
656 | goto unlock_and_exit; | |
657 | } | |
658 | ||
659 | /* | |
660 | * For user-installed GPE Block Devices, the gpe_block_base_number | |
661 | * is always zero | |
662 | */ | |
4be44fcd LB |
663 | status = |
664 | acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0, | |
665 | interrupt_number, &gpe_block); | |
666 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
667 | goto unlock_and_exit; |
668 | } | |
669 | ||
96db255c BM |
670 | /* Run the _PRW methods and enable the GPEs */ |
671 | ||
672 | status = acpi_ev_initialize_gpe_block(node, gpe_block); | |
673 | if (ACPI_FAILURE(status)) { | |
674 | goto unlock_and_exit; | |
675 | } | |
676 | ||
1da177e4 LT |
677 | /* Get the device_object attached to the node */ |
678 | ||
4be44fcd | 679 | obj_desc = acpi_ns_get_attached_object(node); |
1da177e4 | 680 | if (!obj_desc) { |
52fc0b02 | 681 | |
1da177e4 LT |
682 | /* No object, create a new one */ |
683 | ||
4be44fcd | 684 | obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE); |
1da177e4 LT |
685 | if (!obj_desc) { |
686 | status = AE_NO_MEMORY; | |
687 | goto unlock_and_exit; | |
688 | } | |
689 | ||
4be44fcd LB |
690 | status = |
691 | acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE); | |
1da177e4 LT |
692 | |
693 | /* Remove local reference to the object */ | |
694 | ||
4be44fcd | 695 | acpi_ut_remove_reference(obj_desc); |
1da177e4 | 696 | |
4be44fcd | 697 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
698 | goto unlock_and_exit; |
699 | } | |
700 | } | |
701 | ||
702 | /* Install the GPE block in the device_object */ | |
703 | ||
704 | obj_desc->device.gpe_block = gpe_block; | |
705 | ||
4be44fcd LB |
706 | unlock_and_exit: |
707 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | |
708 | return_ACPI_STATUS(status); | |
1da177e4 | 709 | } |
1da177e4 | 710 | |
8313524a | 711 | ACPI_EXPORT_SYMBOL(acpi_install_gpe_block) |
1da177e4 LT |
712 | |
713 | /******************************************************************************* | |
714 | * | |
715 | * FUNCTION: acpi_remove_gpe_block | |
716 | * | |
717 | * PARAMETERS: gpe_device - Handle to the parent GPE Block Device | |
718 | * | |
719 | * RETURN: Status | |
720 | * | |
721 | * DESCRIPTION: Remove a previously installed block of GPE registers | |
722 | * | |
723 | ******************************************************************************/ | |
4be44fcd | 724 | acpi_status acpi_remove_gpe_block(acpi_handle gpe_device) |
1da177e4 | 725 | { |
4be44fcd LB |
726 | union acpi_operand_object *obj_desc; |
727 | acpi_status status; | |
728 | struct acpi_namespace_node *node; | |
1da177e4 | 729 | |
b229cf92 | 730 | ACPI_FUNCTION_TRACE(acpi_remove_gpe_block); |
1da177e4 LT |
731 | |
732 | if (!gpe_device) { | |
4be44fcd | 733 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
734 | } |
735 | ||
4be44fcd LB |
736 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
737 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
738 | return (status); |
739 | } | |
740 | ||
f24b664d | 741 | node = acpi_ns_validate_handle(gpe_device); |
1da177e4 LT |
742 | if (!node) { |
743 | status = AE_BAD_PARAMETER; | |
744 | goto unlock_and_exit; | |
745 | } | |
746 | ||
747 | /* Get the device_object attached to the node */ | |
748 | ||
4be44fcd LB |
749 | obj_desc = acpi_ns_get_attached_object(node); |
750 | if (!obj_desc || !obj_desc->device.gpe_block) { | |
751 | return_ACPI_STATUS(AE_NULL_OBJECT); | |
1da177e4 LT |
752 | } |
753 | ||
754 | /* Delete the GPE block (but not the device_object) */ | |
755 | ||
4be44fcd LB |
756 | status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block); |
757 | if (ACPI_SUCCESS(status)) { | |
1da177e4 LT |
758 | obj_desc->device.gpe_block = NULL; |
759 | } | |
760 | ||
4be44fcd LB |
761 | unlock_and_exit: |
762 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | |
763 | return_ACPI_STATUS(status); | |
1da177e4 | 764 | } |
44f6c012 | 765 | |
8313524a | 766 | ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block) |
e97d6bf1 BM |
767 | |
768 | /******************************************************************************* | |
769 | * | |
770 | * FUNCTION: acpi_get_gpe_device | |
771 | * | |
772 | * PARAMETERS: Index - System GPE index (0-current_gpe_count) | |
773 | * gpe_device - Where the parent GPE Device is returned | |
774 | * | |
775 | * RETURN: Status | |
776 | * | |
777 | * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL | |
778 | * gpe device indicates that the gpe number is contained in one of | |
779 | * the FADT-defined gpe blocks. Otherwise, the GPE block device. | |
780 | * | |
781 | ******************************************************************************/ | |
782 | acpi_status | |
783 | acpi_get_gpe_device(u32 index, acpi_handle *gpe_device) | |
784 | { | |
785 | struct acpi_gpe_device_info info; | |
786 | acpi_status status; | |
787 | ||
788 | ACPI_FUNCTION_TRACE(acpi_get_gpe_device); | |
789 | ||
790 | if (!gpe_device) { | |
791 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
792 | } | |
793 | ||
794 | if (index >= acpi_current_gpe_count) { | |
795 | return_ACPI_STATUS(AE_NOT_EXIST); | |
796 | } | |
797 | ||
798 | /* Setup and walk the GPE list */ | |
799 | ||
800 | info.index = index; | |
801 | info.status = AE_NOT_EXIST; | |
802 | info.gpe_device = NULL; | |
803 | info.next_block_base_index = 0; | |
804 | ||
805 | status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info); | |
806 | if (ACPI_FAILURE(status)) { | |
807 | return_ACPI_STATUS(status); | |
808 | } | |
809 | ||
810 | *gpe_device = info.gpe_device; | |
811 | return_ACPI_STATUS(info.status); | |
812 | } | |
813 | ||
814 | ACPI_EXPORT_SYMBOL(acpi_get_gpe_device) | |
815 | ||
816 | /******************************************************************************* | |
817 | * | |
818 | * FUNCTION: acpi_ev_get_gpe_device | |
819 | * | |
820 | * PARAMETERS: GPE_WALK_CALLBACK | |
821 | * | |
822 | * RETURN: Status | |
823 | * | |
824 | * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE | |
825 | * block device. NULL if the GPE is one of the FADT-defined GPEs. | |
826 | * | |
827 | ******************************************************************************/ | |
e4c1ebfc | 828 | static acpi_status |
e97d6bf1 BM |
829 | acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info, |
830 | struct acpi_gpe_block_info *gpe_block, void *context) | |
831 | { | |
832 | struct acpi_gpe_device_info *info = context; | |
833 | ||
834 | /* Increment Index by the number of GPEs in this block */ | |
835 | ||
836 | info->next_block_base_index += | |
837 | (gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH); | |
838 | ||
839 | if (info->index < info->next_block_base_index) { | |
840 | /* | |
841 | * The GPE index is within this block, get the node. Leave the node | |
842 | * NULL for the FADT-defined GPEs | |
843 | */ | |
844 | if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) { | |
845 | info->gpe_device = gpe_block->node; | |
846 | } | |
847 | ||
848 | info->status = AE_OK; | |
849 | return (AE_CTRL_END); | |
850 | } | |
851 | ||
852 | return (AE_OK); | |
853 | } | |
08ac07b8 BM |
854 | |
855 | /****************************************************************************** | |
856 | * | |
857 | * FUNCTION: acpi_disable_all_gpes | |
858 | * | |
859 | * PARAMETERS: None | |
860 | * | |
861 | * RETURN: Status | |
862 | * | |
863 | * DESCRIPTION: Disable and clear all GPEs in all GPE blocks | |
864 | * | |
865 | ******************************************************************************/ | |
866 | ||
867 | acpi_status acpi_disable_all_gpes(void) | |
868 | { | |
869 | acpi_status status; | |
870 | ||
871 | ACPI_FUNCTION_TRACE(acpi_disable_all_gpes); | |
872 | ||
873 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | |
874 | if (ACPI_FAILURE(status)) { | |
875 | return_ACPI_STATUS(status); | |
876 | } | |
877 | ||
878 | status = acpi_hw_disable_all_gpes(); | |
879 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | |
880 | ||
881 | return_ACPI_STATUS(status); | |
882 | } | |
883 | ||
884 | /****************************************************************************** | |
885 | * | |
886 | * FUNCTION: acpi_enable_all_runtime_gpes | |
887 | * | |
888 | * PARAMETERS: None | |
889 | * | |
890 | * RETURN: Status | |
891 | * | |
892 | * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks | |
893 | * | |
894 | ******************************************************************************/ | |
895 | ||
896 | acpi_status acpi_enable_all_runtime_gpes(void) | |
897 | { | |
898 | acpi_status status; | |
899 | ||
900 | ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes); | |
901 | ||
902 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | |
903 | if (ACPI_FAILURE(status)) { | |
904 | return_ACPI_STATUS(status); | |
905 | } | |
906 | ||
907 | status = acpi_hw_enable_all_runtime_gpes(); | |
908 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | |
909 | ||
910 | return_ACPI_STATUS(status); | |
911 | } |