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 LT |
44 | #include <acpi/acpi.h> |
45 | #include <acpi/acevents.h> | |
46 | #include <acpi/acnamesp.h> | |
1a666f8b | 47 | #include <acpi/actables.h> |
1da177e4 LT |
48 | |
49 | #define _COMPONENT ACPI_EVENTS | |
4be44fcd | 50 | ACPI_MODULE_NAME("evxfevnt") |
1da177e4 LT |
51 | |
52 | /******************************************************************************* | |
53 | * | |
54 | * FUNCTION: acpi_enable | |
55 | * | |
56 | * PARAMETERS: None | |
57 | * | |
58 | * RETURN: Status | |
59 | * | |
60 | * DESCRIPTION: Transfers the system into ACPI mode. | |
61 | * | |
62 | ******************************************************************************/ | |
4be44fcd | 63 | acpi_status acpi_enable(void) |
1da177e4 | 64 | { |
4be44fcd | 65 | acpi_status status = AE_OK; |
1da177e4 | 66 | |
b229cf92 | 67 | ACPI_FUNCTION_TRACE(acpi_enable); |
1da177e4 | 68 | |
c857303a BM |
69 | /* ACPI tables must be present */ |
70 | ||
71 | if (!acpi_tb_tables_loaded()) { | |
72 | return_ACPI_STATUS(AE_NO_ACPI_TABLES); | |
73 | } | |
74 | ||
75 | /* Check current mode */ | |
76 | ||
1da177e4 | 77 | if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) { |
4be44fcd LB |
78 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
79 | "System is already in ACPI mode\n")); | |
80 | } else { | |
1da177e4 LT |
81 | /* Transition to ACPI mode */ |
82 | ||
4be44fcd LB |
83 | status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI); |
84 | if (ACPI_FAILURE(status)) { | |
b8e4d893 BM |
85 | ACPI_ERROR((AE_INFO, |
86 | "Could not transition to ACPI mode")); | |
4be44fcd | 87 | return_ACPI_STATUS(status); |
1da177e4 LT |
88 | } |
89 | ||
4be44fcd LB |
90 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
91 | "Transition to ACPI mode successful\n")); | |
1da177e4 LT |
92 | } |
93 | ||
4be44fcd | 94 | return_ACPI_STATUS(status); |
1da177e4 LT |
95 | } |
96 | ||
8313524a BM |
97 | ACPI_EXPORT_SYMBOL(acpi_enable) |
98 | ||
1da177e4 LT |
99 | /******************************************************************************* |
100 | * | |
101 | * FUNCTION: acpi_disable | |
102 | * | |
103 | * PARAMETERS: None | |
104 | * | |
105 | * RETURN: Status | |
106 | * | |
44f6c012 | 107 | * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode. |
1da177e4 LT |
108 | * |
109 | ******************************************************************************/ | |
4be44fcd | 110 | acpi_status acpi_disable(void) |
1da177e4 | 111 | { |
4be44fcd | 112 | acpi_status status = AE_OK; |
1da177e4 | 113 | |
b229cf92 | 114 | ACPI_FUNCTION_TRACE(acpi_disable); |
1da177e4 | 115 | |
1da177e4 | 116 | if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) { |
4be44fcd LB |
117 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, |
118 | "System is already in legacy (non-ACPI) mode\n")); | |
119 | } else { | |
1da177e4 LT |
120 | /* Transition to LEGACY mode */ |
121 | ||
4be44fcd | 122 | status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY); |
1da177e4 | 123 | |
4be44fcd | 124 | if (ACPI_FAILURE(status)) { |
b8e4d893 BM |
125 | ACPI_ERROR((AE_INFO, |
126 | "Could not exit ACPI mode to legacy mode")); | |
4be44fcd | 127 | return_ACPI_STATUS(status); |
1da177e4 LT |
128 | } |
129 | ||
4be44fcd | 130 | ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n")); |
1da177e4 LT |
131 | } |
132 | ||
4be44fcd | 133 | return_ACPI_STATUS(status); |
1da177e4 LT |
134 | } |
135 | ||
8313524a BM |
136 | ACPI_EXPORT_SYMBOL(acpi_disable) |
137 | ||
1da177e4 LT |
138 | /******************************************************************************* |
139 | * | |
140 | * FUNCTION: acpi_enable_event | |
141 | * | |
142 | * PARAMETERS: Event - The fixed eventto be enabled | |
143 | * Flags - Reserved | |
144 | * | |
145 | * RETURN: Status | |
146 | * | |
147 | * DESCRIPTION: Enable an ACPI event (fixed) | |
148 | * | |
149 | ******************************************************************************/ | |
4be44fcd | 150 | acpi_status acpi_enable_event(u32 event, u32 flags) |
1da177e4 | 151 | { |
4be44fcd LB |
152 | acpi_status status = AE_OK; |
153 | u32 value; | |
1da177e4 | 154 | |
b229cf92 | 155 | ACPI_FUNCTION_TRACE(acpi_enable_event); |
1da177e4 LT |
156 | |
157 | /* Decode the Fixed Event */ | |
158 | ||
159 | if (event > ACPI_EVENT_MAX) { | |
4be44fcd | 160 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
161 | } |
162 | ||
163 | /* | |
9f15fc66 BM |
164 | * Enable the requested fixed event (by writing a one to the enable |
165 | * register bit) | |
1da177e4 | 166 | */ |
4be44fcd LB |
167 | status = |
168 | acpi_set_register(acpi_gbl_fixed_event_info[event]. | |
d8c71b6d | 169 | enable_register_id, 1); |
4be44fcd LB |
170 | if (ACPI_FAILURE(status)) { |
171 | return_ACPI_STATUS(status); | |
1da177e4 LT |
172 | } |
173 | ||
174 | /* Make sure that the hardware responded */ | |
175 | ||
4be44fcd LB |
176 | status = |
177 | acpi_get_register(acpi_gbl_fixed_event_info[event]. | |
d8c71b6d | 178 | enable_register_id, &value); |
4be44fcd LB |
179 | if (ACPI_FAILURE(status)) { |
180 | return_ACPI_STATUS(status); | |
1da177e4 LT |
181 | } |
182 | ||
183 | if (value != 1) { | |
b8e4d893 BM |
184 | ACPI_ERROR((AE_INFO, |
185 | "Could not enable %s event", | |
186 | acpi_ut_get_event_name(event))); | |
4be44fcd | 187 | return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE); |
1da177e4 LT |
188 | } |
189 | ||
4be44fcd | 190 | return_ACPI_STATUS(status); |
1da177e4 | 191 | } |
1da177e4 | 192 | |
8313524a | 193 | ACPI_EXPORT_SYMBOL(acpi_enable_event) |
1da177e4 LT |
194 | |
195 | /******************************************************************************* | |
196 | * | |
197 | * FUNCTION: acpi_set_gpe_type | |
198 | * | |
199 | * PARAMETERS: gpe_device - Parent GPE Device | |
200 | * gpe_number - GPE level within the GPE block | |
201 | * Type - New GPE type | |
202 | * | |
203 | * RETURN: Status | |
204 | * | |
44f6c012 | 205 | * DESCRIPTION: Set the type of an individual GPE |
1da177e4 LT |
206 | * |
207 | ******************************************************************************/ | |
4be44fcd | 208 | acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type) |
1da177e4 | 209 | { |
4be44fcd LB |
210 | acpi_status status = AE_OK; |
211 | struct acpi_gpe_event_info *gpe_event_info; | |
1da177e4 | 212 | |
b229cf92 | 213 | ACPI_FUNCTION_TRACE(acpi_set_gpe_type); |
1da177e4 LT |
214 | |
215 | /* Ensure that we have a valid GPE number */ | |
216 | ||
4be44fcd | 217 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
218 | if (!gpe_event_info) { |
219 | status = AE_BAD_PARAMETER; | |
220 | goto unlock_and_exit; | |
221 | } | |
222 | ||
223 | if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) { | |
4be44fcd | 224 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
225 | } |
226 | ||
227 | /* Set the new type (will disable GPE if currently enabled) */ | |
228 | ||
4be44fcd | 229 | status = acpi_ev_set_gpe_type(gpe_event_info, type); |
1da177e4 | 230 | |
4be44fcd LB |
231 | unlock_and_exit: |
232 | return_ACPI_STATUS(status); | |
1da177e4 | 233 | } |
1da177e4 | 234 | |
8313524a | 235 | ACPI_EXPORT_SYMBOL(acpi_set_gpe_type) |
1da177e4 LT |
236 | |
237 | /******************************************************************************* | |
238 | * | |
239 | * FUNCTION: acpi_enable_gpe | |
240 | * | |
241 | * PARAMETERS: gpe_device - Parent GPE Device | |
242 | * gpe_number - GPE level within the GPE block | |
243 | * Flags - Just enable, or also wake enable? | |
244 | * Called from ISR or not | |
245 | * | |
246 | * RETURN: Status | |
247 | * | |
248 | * DESCRIPTION: Enable an ACPI event (general purpose) | |
249 | * | |
250 | ******************************************************************************/ | |
0b7084ac | 251 | acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number) |
1da177e4 | 252 | { |
4be44fcd | 253 | acpi_status status = AE_OK; |
0b7084ac | 254 | acpi_cpu_flags flags; |
4be44fcd | 255 | struct acpi_gpe_event_info *gpe_event_info; |
1da177e4 | 256 | |
b229cf92 | 257 | ACPI_FUNCTION_TRACE(acpi_enable_gpe); |
1da177e4 | 258 | |
0b7084ac | 259 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
1da177e4 LT |
260 | |
261 | /* Ensure that we have a valid GPE number */ | |
262 | ||
4be44fcd | 263 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
264 | if (!gpe_event_info) { |
265 | status = AE_BAD_PARAMETER; | |
266 | goto unlock_and_exit; | |
267 | } | |
268 | ||
269 | /* Perform the enable */ | |
270 | ||
4be44fcd | 271 | status = acpi_ev_enable_gpe(gpe_event_info, TRUE); |
1da177e4 | 272 | |
4be44fcd | 273 | unlock_and_exit: |
0b7084ac | 274 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
4be44fcd | 275 | return_ACPI_STATUS(status); |
1da177e4 | 276 | } |
1da177e4 | 277 | |
8313524a | 278 | ACPI_EXPORT_SYMBOL(acpi_enable_gpe) |
1da177e4 LT |
279 | |
280 | /******************************************************************************* | |
281 | * | |
282 | * FUNCTION: acpi_disable_gpe | |
283 | * | |
284 | * PARAMETERS: gpe_device - Parent GPE Device | |
285 | * gpe_number - GPE level within the GPE block | |
286 | * Flags - Just disable, or also wake disable? | |
287 | * Called from ISR or not | |
288 | * | |
289 | * RETURN: Status | |
290 | * | |
291 | * DESCRIPTION: Disable an ACPI event (general purpose) | |
292 | * | |
293 | ******************************************************************************/ | |
0b7084ac | 294 | acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number) |
1da177e4 | 295 | { |
4be44fcd | 296 | acpi_status status = AE_OK; |
0b7084ac | 297 | acpi_cpu_flags flags; |
4be44fcd | 298 | struct acpi_gpe_event_info *gpe_event_info; |
1da177e4 | 299 | |
b229cf92 | 300 | ACPI_FUNCTION_TRACE(acpi_disable_gpe); |
1da177e4 | 301 | |
0b7084ac | 302 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
1da177e4 LT |
303 | /* Ensure that we have a valid GPE number */ |
304 | ||
4be44fcd | 305 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
306 | if (!gpe_event_info) { |
307 | status = AE_BAD_PARAMETER; | |
308 | goto unlock_and_exit; | |
309 | } | |
310 | ||
4be44fcd | 311 | status = acpi_ev_disable_gpe(gpe_event_info); |
1da177e4 | 312 | |
0b7084ac AS |
313 | unlock_and_exit: |
314 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); | |
4be44fcd | 315 | return_ACPI_STATUS(status); |
1da177e4 LT |
316 | } |
317 | ||
8313524a BM |
318 | ACPI_EXPORT_SYMBOL(acpi_disable_gpe) |
319 | ||
1da177e4 LT |
320 | /******************************************************************************* |
321 | * | |
322 | * FUNCTION: acpi_disable_event | |
323 | * | |
324 | * PARAMETERS: Event - The fixed eventto be enabled | |
325 | * Flags - Reserved | |
326 | * | |
327 | * RETURN: Status | |
328 | * | |
329 | * DESCRIPTION: Disable an ACPI event (fixed) | |
330 | * | |
331 | ******************************************************************************/ | |
4be44fcd | 332 | acpi_status acpi_disable_event(u32 event, u32 flags) |
1da177e4 | 333 | { |
4be44fcd LB |
334 | acpi_status status = AE_OK; |
335 | u32 value; | |
1da177e4 | 336 | |
b229cf92 | 337 | ACPI_FUNCTION_TRACE(acpi_disable_event); |
1da177e4 LT |
338 | |
339 | /* Decode the Fixed Event */ | |
340 | ||
341 | if (event > ACPI_EVENT_MAX) { | |
4be44fcd | 342 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
343 | } |
344 | ||
345 | /* | |
9f15fc66 BM |
346 | * Disable the requested fixed event (by writing a zero to the enable |
347 | * register bit) | |
1da177e4 | 348 | */ |
4be44fcd LB |
349 | status = |
350 | acpi_set_register(acpi_gbl_fixed_event_info[event]. | |
d8c71b6d | 351 | enable_register_id, 0); |
4be44fcd LB |
352 | if (ACPI_FAILURE(status)) { |
353 | return_ACPI_STATUS(status); | |
1da177e4 LT |
354 | } |
355 | ||
4be44fcd LB |
356 | status = |
357 | acpi_get_register(acpi_gbl_fixed_event_info[event]. | |
d8c71b6d | 358 | enable_register_id, &value); |
4be44fcd LB |
359 | if (ACPI_FAILURE(status)) { |
360 | return_ACPI_STATUS(status); | |
1da177e4 LT |
361 | } |
362 | ||
363 | if (value != 0) { | |
b8e4d893 BM |
364 | ACPI_ERROR((AE_INFO, |
365 | "Could not disable %s events", | |
366 | acpi_ut_get_event_name(event))); | |
4be44fcd | 367 | return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE); |
1da177e4 LT |
368 | } |
369 | ||
4be44fcd | 370 | return_ACPI_STATUS(status); |
1da177e4 | 371 | } |
1da177e4 | 372 | |
8313524a | 373 | ACPI_EXPORT_SYMBOL(acpi_disable_event) |
1da177e4 LT |
374 | |
375 | /******************************************************************************* | |
376 | * | |
377 | * FUNCTION: acpi_clear_event | |
378 | * | |
379 | * PARAMETERS: Event - The fixed event to be cleared | |
380 | * | |
381 | * RETURN: Status | |
382 | * | |
383 | * DESCRIPTION: Clear an ACPI event (fixed) | |
384 | * | |
385 | ******************************************************************************/ | |
4be44fcd | 386 | acpi_status acpi_clear_event(u32 event) |
1da177e4 | 387 | { |
4be44fcd | 388 | acpi_status status = AE_OK; |
1da177e4 | 389 | |
b229cf92 | 390 | ACPI_FUNCTION_TRACE(acpi_clear_event); |
1da177e4 LT |
391 | |
392 | /* Decode the Fixed Event */ | |
393 | ||
394 | if (event > ACPI_EVENT_MAX) { | |
4be44fcd | 395 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
396 | } |
397 | ||
398 | /* | |
9f15fc66 BM |
399 | * Clear the requested fixed event (By writing a one to the status |
400 | * register bit) | |
1da177e4 | 401 | */ |
4be44fcd LB |
402 | status = |
403 | acpi_set_register(acpi_gbl_fixed_event_info[event]. | |
d8c71b6d | 404 | status_register_id, 1); |
1da177e4 | 405 | |
4be44fcd | 406 | return_ACPI_STATUS(status); |
1da177e4 | 407 | } |
1da177e4 | 408 | |
8313524a | 409 | ACPI_EXPORT_SYMBOL(acpi_clear_event) |
1da177e4 LT |
410 | |
411 | /******************************************************************************* | |
412 | * | |
413 | * FUNCTION: acpi_clear_gpe | |
414 | * | |
415 | * PARAMETERS: gpe_device - Parent GPE Device | |
416 | * gpe_number - GPE level within the GPE block | |
417 | * Flags - Called from an ISR or not | |
418 | * | |
419 | * RETURN: Status | |
420 | * | |
421 | * DESCRIPTION: Clear an ACPI event (general purpose) | |
422 | * | |
423 | ******************************************************************************/ | |
4be44fcd | 424 | acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags) |
1da177e4 | 425 | { |
4be44fcd LB |
426 | acpi_status status = AE_OK; |
427 | struct acpi_gpe_event_info *gpe_event_info; | |
1da177e4 | 428 | |
b229cf92 | 429 | ACPI_FUNCTION_TRACE(acpi_clear_gpe); |
1da177e4 LT |
430 | |
431 | /* Use semaphore lock if not executing at interrupt level */ | |
432 | ||
433 | if (flags & ACPI_NOT_ISR) { | |
4be44fcd LB |
434 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
435 | if (ACPI_FAILURE(status)) { | |
436 | return_ACPI_STATUS(status); | |
1da177e4 LT |
437 | } |
438 | } | |
439 | ||
440 | /* Ensure that we have a valid GPE number */ | |
441 | ||
4be44fcd | 442 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
443 | if (!gpe_event_info) { |
444 | status = AE_BAD_PARAMETER; | |
445 | goto unlock_and_exit; | |
446 | } | |
447 | ||
4be44fcd | 448 | status = acpi_hw_clear_gpe(gpe_event_info); |
1da177e4 | 449 | |
4be44fcd | 450 | unlock_and_exit: |
1da177e4 | 451 | if (flags & ACPI_NOT_ISR) { |
4be44fcd | 452 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
1da177e4 | 453 | } |
4be44fcd | 454 | return_ACPI_STATUS(status); |
1da177e4 LT |
455 | } |
456 | ||
8313524a | 457 | ACPI_EXPORT_SYMBOL(acpi_clear_gpe) |
1da177e4 LT |
458 | /******************************************************************************* |
459 | * | |
460 | * FUNCTION: acpi_get_event_status | |
461 | * | |
462 | * PARAMETERS: Event - The fixed event | |
44f6c012 | 463 | * event_status - Where the current status of the event will |
1da177e4 LT |
464 | * be returned |
465 | * | |
466 | * RETURN: Status | |
467 | * | |
468 | * DESCRIPTION: Obtains and returns the current status of the event | |
469 | * | |
470 | ******************************************************************************/ | |
4be44fcd | 471 | acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status) |
1da177e4 | 472 | { |
4be44fcd | 473 | acpi_status status = AE_OK; |
71b58cbb | 474 | u32 value; |
1da177e4 | 475 | |
b229cf92 | 476 | ACPI_FUNCTION_TRACE(acpi_get_event_status); |
1da177e4 LT |
477 | |
478 | if (!event_status) { | |
4be44fcd | 479 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
480 | } |
481 | ||
482 | /* Decode the Fixed Event */ | |
483 | ||
484 | if (event > ACPI_EVENT_MAX) { | |
4be44fcd | 485 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
486 | } |
487 | ||
488 | /* Get the status of the requested fixed event */ | |
489 | ||
4be44fcd LB |
490 | status = |
491 | acpi_get_register(acpi_gbl_fixed_event_info[event]. | |
71b58cbb ZR |
492 | enable_register_id, &value); |
493 | if (ACPI_FAILURE(status)) | |
494 | return_ACPI_STATUS(status); | |
495 | ||
496 | *event_status = value; | |
497 | ||
498 | status = | |
499 | acpi_get_register(acpi_gbl_fixed_event_info[event]. | |
500 | status_register_id, &value); | |
501 | if (ACPI_FAILURE(status)) | |
502 | return_ACPI_STATUS(status); | |
503 | ||
504 | if (value) | |
505 | *event_status |= ACPI_EVENT_FLAG_SET; | |
1da177e4 | 506 | |
ed206fac ZR |
507 | if (acpi_gbl_fixed_event_handlers[event].handler) |
508 | *event_status |= ACPI_EVENT_FLAG_HANDLE; | |
509 | ||
4be44fcd | 510 | return_ACPI_STATUS(status); |
1da177e4 LT |
511 | } |
512 | ||
8313524a BM |
513 | ACPI_EXPORT_SYMBOL(acpi_get_event_status) |
514 | ||
1da177e4 LT |
515 | /******************************************************************************* |
516 | * | |
517 | * FUNCTION: acpi_get_gpe_status | |
518 | * | |
519 | * PARAMETERS: gpe_device - Parent GPE Device | |
520 | * gpe_number - GPE level within the GPE block | |
521 | * Flags - Called from an ISR or not | |
44f6c012 | 522 | * event_status - Where the current status of the event will |
1da177e4 LT |
523 | * be returned |
524 | * | |
525 | * RETURN: Status | |
526 | * | |
527 | * DESCRIPTION: Get status of an event (general purpose) | |
528 | * | |
529 | ******************************************************************************/ | |
1da177e4 | 530 | acpi_status |
4be44fcd LB |
531 | acpi_get_gpe_status(acpi_handle gpe_device, |
532 | u32 gpe_number, u32 flags, acpi_event_status * event_status) | |
1da177e4 | 533 | { |
4be44fcd LB |
534 | acpi_status status = AE_OK; |
535 | struct acpi_gpe_event_info *gpe_event_info; | |
1da177e4 | 536 | |
b229cf92 | 537 | ACPI_FUNCTION_TRACE(acpi_get_gpe_status); |
1da177e4 LT |
538 | |
539 | /* Use semaphore lock if not executing at interrupt level */ | |
540 | ||
541 | if (flags & ACPI_NOT_ISR) { | |
4be44fcd LB |
542 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
543 | if (ACPI_FAILURE(status)) { | |
544 | return_ACPI_STATUS(status); | |
1da177e4 LT |
545 | } |
546 | } | |
547 | ||
548 | /* Ensure that we have a valid GPE number */ | |
549 | ||
4be44fcd | 550 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
1da177e4 LT |
551 | if (!gpe_event_info) { |
552 | status = AE_BAD_PARAMETER; | |
553 | goto unlock_and_exit; | |
554 | } | |
555 | ||
556 | /* Obtain status on the requested GPE number */ | |
557 | ||
4be44fcd | 558 | status = acpi_hw_get_gpe_status(gpe_event_info, event_status); |
1da177e4 | 559 | |
ed206fac ZR |
560 | if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) |
561 | *event_status |= ACPI_EVENT_FLAG_HANDLE; | |
562 | ||
4be44fcd | 563 | unlock_and_exit: |
1da177e4 | 564 | if (flags & ACPI_NOT_ISR) { |
4be44fcd | 565 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
1da177e4 | 566 | } |
4be44fcd | 567 | return_ACPI_STATUS(status); |
1da177e4 | 568 | } |
8313524a BM |
569 | |
570 | ACPI_EXPORT_SYMBOL(acpi_get_gpe_status) | |
1da177e4 LT |
571 | /******************************************************************************* |
572 | * | |
573 | * FUNCTION: acpi_install_gpe_block | |
574 | * | |
575 | * PARAMETERS: gpe_device - Handle to the parent GPE Block Device | |
576 | * gpe_block_address - Address and space_iD | |
577 | * register_count - Number of GPE register pairs in the block | |
6f42ccf2 | 578 | * interrupt_number - H/W interrupt for the block |
1da177e4 LT |
579 | * |
580 | * RETURN: Status | |
581 | * | |
582 | * DESCRIPTION: Create and Install a block of GPE registers | |
583 | * | |
584 | ******************************************************************************/ | |
1da177e4 | 585 | acpi_status |
4be44fcd LB |
586 | acpi_install_gpe_block(acpi_handle gpe_device, |
587 | struct acpi_generic_address *gpe_block_address, | |
588 | u32 register_count, u32 interrupt_number) | |
1da177e4 | 589 | { |
4be44fcd LB |
590 | acpi_status status; |
591 | union acpi_operand_object *obj_desc; | |
592 | struct acpi_namespace_node *node; | |
593 | struct acpi_gpe_block_info *gpe_block; | |
1da177e4 | 594 | |
b229cf92 | 595 | ACPI_FUNCTION_TRACE(acpi_install_gpe_block); |
1da177e4 | 596 | |
4be44fcd LB |
597 | if ((!gpe_device) || (!gpe_block_address) || (!register_count)) { |
598 | return_ACPI_STATUS(AE_BAD_PARAMETER); | |
1da177e4 LT |
599 | } |
600 | ||
4be44fcd LB |
601 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
602 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
603 | return (status); |
604 | } | |
605 | ||
4be44fcd | 606 | node = acpi_ns_map_handle_to_node(gpe_device); |
1da177e4 LT |
607 | if (!node) { |
608 | status = AE_BAD_PARAMETER; | |
609 | goto unlock_and_exit; | |
610 | } | |
611 | ||
612 | /* | |
613 | * For user-installed GPE Block Devices, the gpe_block_base_number | |
614 | * is always zero | |
615 | */ | |
4be44fcd LB |
616 | status = |
617 | acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0, | |
618 | interrupt_number, &gpe_block); | |
619 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
620 | goto unlock_and_exit; |
621 | } | |
622 | ||
96db255c BM |
623 | /* Run the _PRW methods and enable the GPEs */ |
624 | ||
625 | status = acpi_ev_initialize_gpe_block(node, gpe_block); | |
626 | if (ACPI_FAILURE(status)) { | |
627 | goto unlock_and_exit; | |
628 | } | |
629 | ||
1da177e4 LT |
630 | /* Get the device_object attached to the node */ |
631 | ||
4be44fcd | 632 | obj_desc = acpi_ns_get_attached_object(node); |
1da177e4 | 633 | if (!obj_desc) { |
52fc0b02 | 634 | |
1da177e4 LT |
635 | /* No object, create a new one */ |
636 | ||
4be44fcd | 637 | obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE); |
1da177e4 LT |
638 | if (!obj_desc) { |
639 | status = AE_NO_MEMORY; | |
640 | goto unlock_and_exit; | |
641 | } | |
642 | ||
4be44fcd LB |
643 | status = |
644 | acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE); | |
1da177e4 LT |
645 | |
646 | /* Remove local reference to the object */ | |
647 | ||
4be44fcd | 648 | acpi_ut_remove_reference(obj_desc); |
1da177e4 | 649 | |
4be44fcd | 650 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
651 | goto unlock_and_exit; |
652 | } | |
653 | } | |
654 | ||
655 | /* Install the GPE block in the device_object */ | |
656 | ||
657 | obj_desc->device.gpe_block = gpe_block; | |
658 | ||
4be44fcd LB |
659 | unlock_and_exit: |
660 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | |
661 | return_ACPI_STATUS(status); | |
1da177e4 | 662 | } |
1da177e4 | 663 | |
8313524a | 664 | ACPI_EXPORT_SYMBOL(acpi_install_gpe_block) |
1da177e4 LT |
665 | |
666 | /******************************************************************************* | |
667 | * | |
668 | * FUNCTION: acpi_remove_gpe_block | |
669 | * | |
670 | * PARAMETERS: gpe_device - Handle to the parent GPE Block Device | |
671 | * | |
672 | * RETURN: Status | |
673 | * | |
674 | * DESCRIPTION: Remove a previously installed block of GPE registers | |
675 | * | |
676 | ******************************************************************************/ | |
4be44fcd | 677 | acpi_status acpi_remove_gpe_block(acpi_handle gpe_device) |
1da177e4 | 678 | { |
4be44fcd LB |
679 | union acpi_operand_object *obj_desc; |
680 | acpi_status status; | |
681 | struct acpi_namespace_node *node; | |
1da177e4 | 682 | |
b229cf92 | 683 | ACPI_FUNCTION_TRACE(acpi_remove_gpe_block); |
1da177e4 LT |
684 | |
685 | if (!gpe_device) { | |
4be44fcd | 686 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
687 | } |
688 | ||
4be44fcd LB |
689 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
690 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
691 | return (status); |
692 | } | |
693 | ||
4be44fcd | 694 | node = acpi_ns_map_handle_to_node(gpe_device); |
1da177e4 LT |
695 | if (!node) { |
696 | status = AE_BAD_PARAMETER; | |
697 | goto unlock_and_exit; | |
698 | } | |
699 | ||
700 | /* Get the device_object attached to the node */ | |
701 | ||
4be44fcd LB |
702 | obj_desc = acpi_ns_get_attached_object(node); |
703 | if (!obj_desc || !obj_desc->device.gpe_block) { | |
704 | return_ACPI_STATUS(AE_NULL_OBJECT); | |
1da177e4 LT |
705 | } |
706 | ||
707 | /* Delete the GPE block (but not the device_object) */ | |
708 | ||
4be44fcd LB |
709 | status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block); |
710 | if (ACPI_SUCCESS(status)) { | |
1da177e4 LT |
711 | obj_desc->device.gpe_block = NULL; |
712 | } | |
713 | ||
4be44fcd LB |
714 | unlock_and_exit: |
715 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | |
716 | return_ACPI_STATUS(status); | |
1da177e4 | 717 | } |
44f6c012 | 718 | |
8313524a | 719 | ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block) |