Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: evgpe - General Purpose Event handling and dispatch | |
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 | ||
44 | #include <acpi/acpi.h> | |
e2f7a777 LB |
45 | #include "accommon.h" |
46 | #include "acevents.h" | |
47 | #include "acnamesp.h" | |
1da177e4 LT |
48 | |
49 | #define _COMPONENT ACPI_EVENTS | |
4be44fcd | 50 | ACPI_MODULE_NAME("evgpe") |
1da177e4 | 51 | |
44f6c012 | 52 | /* Local prototypes */ |
4be44fcd | 53 | static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context); |
1da177e4 | 54 | |
1da177e4 LT |
55 | /******************************************************************************* |
56 | * | |
57 | * FUNCTION: acpi_ev_update_gpe_enable_masks | |
58 | * | |
59 | * PARAMETERS: gpe_event_info - GPE to update | |
1da177e4 LT |
60 | * |
61 | * RETURN: Status | |
62 | * | |
63 | * DESCRIPTION: Updates GPE register enable masks based on the GPE type | |
64 | * | |
65 | ******************************************************************************/ | |
66 | ||
67 | acpi_status | |
9630bdd9 | 68 | acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info) |
1da177e4 | 69 | { |
4be44fcd LB |
70 | struct acpi_gpe_register_info *gpe_register_info; |
71 | u8 register_bit; | |
1da177e4 | 72 | |
b229cf92 | 73 | ACPI_FUNCTION_TRACE(ev_update_gpe_enable_masks); |
1da177e4 LT |
74 | |
75 | gpe_register_info = gpe_event_info->register_info; | |
76 | if (!gpe_register_info) { | |
4be44fcd | 77 | return_ACPI_STATUS(AE_NOT_EXIST); |
1da177e4 | 78 | } |
d4913dc6 | 79 | |
69874165 AS |
80 | register_bit = (u8) |
81 | (1 << | |
82 | (gpe_event_info->gpe_number - gpe_register_info->base_gpe_number)); | |
1da177e4 | 83 | |
9630bdd9 RW |
84 | ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake, register_bit); |
85 | ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit); | |
1da177e4 | 86 | |
9630bdd9 | 87 | if (gpe_event_info->runtime_count) |
4be44fcd | 88 | ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit); |
1da177e4 | 89 | |
9630bdd9 | 90 | if (gpe_event_info->wakeup_count) |
4be44fcd | 91 | ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit); |
1da177e4 | 92 | |
4be44fcd | 93 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
94 | } |
95 | ||
1da177e4 LT |
96 | /******************************************************************************* |
97 | * | |
98 | * FUNCTION: acpi_ev_enable_gpe | |
99 | * | |
100 | * PARAMETERS: gpe_event_info - GPE to enable | |
101 | * write_to_hardware - Enable now, or just mark data structs | |
102 | * (WAKE GPEs should be deferred) | |
103 | * | |
104 | * RETURN: Status | |
105 | * | |
106 | * DESCRIPTION: Enable a GPE based on the GPE type | |
107 | * | |
108 | ******************************************************************************/ | |
109 | ||
110 | acpi_status | |
4be44fcd LB |
111 | acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info, |
112 | u8 write_to_hardware) | |
1da177e4 | 113 | { |
4be44fcd | 114 | acpi_status status; |
1da177e4 | 115 | |
b229cf92 | 116 | ACPI_FUNCTION_TRACE(ev_enable_gpe); |
1da177e4 LT |
117 | |
118 | /* Make sure HW enable masks are updated */ | |
119 | ||
9630bdd9 RW |
120 | status = acpi_ev_update_gpe_enable_masks(gpe_event_info); |
121 | if (ACPI_FAILURE(status)) | |
4be44fcd | 122 | return_ACPI_STATUS(status); |
1da177e4 LT |
123 | |
124 | /* Mark wake-enabled or HW enable, or both */ | |
125 | ||
9630bdd9 RW |
126 | if (gpe_event_info->runtime_count && write_to_hardware) { |
127 | /* Clear the GPE (of stale events), then enable it */ | |
128 | status = acpi_hw_clear_gpe(gpe_event_info); | |
129 | if (ACPI_FAILURE(status)) | |
130 | return_ACPI_STATUS(status); | |
1da177e4 | 131 | |
9630bdd9 RW |
132 | /* Enable the requested runtime GPE */ |
133 | status = acpi_hw_write_gpe_enable_reg(gpe_event_info); | |
1da177e4 LT |
134 | } |
135 | ||
4be44fcd | 136 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
137 | } |
138 | ||
1da177e4 LT |
139 | /******************************************************************************* |
140 | * | |
141 | * FUNCTION: acpi_ev_disable_gpe | |
142 | * | |
143 | * PARAMETERS: gpe_event_info - GPE to disable | |
144 | * | |
145 | * RETURN: Status | |
146 | * | |
147 | * DESCRIPTION: Disable a GPE based on the GPE type | |
148 | * | |
149 | ******************************************************************************/ | |
150 | ||
4be44fcd | 151 | acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info) |
1da177e4 | 152 | { |
4be44fcd | 153 | acpi_status status; |
1da177e4 | 154 | |
b229cf92 | 155 | ACPI_FUNCTION_TRACE(ev_disable_gpe); |
1da177e4 | 156 | |
1da177e4 LT |
157 | /* Make sure HW enable masks are updated */ |
158 | ||
9630bdd9 RW |
159 | status = acpi_ev_update_gpe_enable_masks(gpe_event_info); |
160 | if (ACPI_FAILURE(status)) | |
4be44fcd | 161 | return_ACPI_STATUS(status); |
1da177e4 | 162 | |
e38e8a07 BM |
163 | /* |
164 | * Even if we don't know the GPE type, make sure that we always | |
165 | * disable it. low_disable_gpe will just clear the enable bit for this | |
166 | * GPE and write it. It will not write out the current GPE enable mask, | |
167 | * since this may inadvertently enable GPEs too early, if a rogue GPE has | |
168 | * come in during ACPICA initialization - possibly as a result of AML or | |
169 | * other code that has enabled the GPE. | |
170 | */ | |
171 | status = acpi_hw_low_disable_gpe(gpe_event_info); | |
172 | return_ACPI_STATUS(status); | |
1da177e4 LT |
173 | } |
174 | ||
1da177e4 LT |
175 | /******************************************************************************* |
176 | * | |
177 | * FUNCTION: acpi_ev_get_gpe_event_info | |
178 | * | |
9f15fc66 | 179 | * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1 |
1da177e4 LT |
180 | * gpe_number - Raw GPE number |
181 | * | |
182 | * RETURN: A GPE event_info struct. NULL if not a valid GPE | |
183 | * | |
184 | * DESCRIPTION: Returns the event_info struct associated with this GPE. | |
185 | * Validates the gpe_block and the gpe_number | |
186 | * | |
187 | * Should be called only when the GPE lists are semaphore locked | |
188 | * and not subject to change. | |
189 | * | |
190 | ******************************************************************************/ | |
191 | ||
4be44fcd LB |
192 | struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device, |
193 | u32 gpe_number) | |
1da177e4 | 194 | { |
4be44fcd LB |
195 | union acpi_operand_object *obj_desc; |
196 | struct acpi_gpe_block_info *gpe_block; | |
67a119f9 | 197 | u32 i; |
1da177e4 | 198 | |
4be44fcd | 199 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
200 | |
201 | /* A NULL gpe_block means use the FADT-defined GPE block(s) */ | |
202 | ||
203 | if (!gpe_device) { | |
52fc0b02 | 204 | |
1da177e4 LT |
205 | /* Examine GPE Block 0 and 1 (These blocks are permanent) */ |
206 | ||
207 | for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) { | |
208 | gpe_block = acpi_gbl_gpe_fadt_blocks[i]; | |
209 | if (gpe_block) { | |
4be44fcd LB |
210 | if ((gpe_number >= gpe_block->block_base_number) |
211 | && (gpe_number < | |
212 | gpe_block->block_base_number + | |
213 | (gpe_block->register_count * 8))) { | |
214 | return (&gpe_block-> | |
215 | event_info[gpe_number - | |
216 | gpe_block-> | |
217 | block_base_number]); | |
1da177e4 LT |
218 | } |
219 | } | |
220 | } | |
221 | ||
222 | /* The gpe_number was not in the range of either FADT GPE block */ | |
223 | ||
224 | return (NULL); | |
225 | } | |
226 | ||
227 | /* A Non-NULL gpe_device means this is a GPE Block Device */ | |
228 | ||
fd350943 LB |
229 | obj_desc = acpi_ns_get_attached_object((struct acpi_namespace_node *) |
230 | gpe_device); | |
4be44fcd | 231 | if (!obj_desc || !obj_desc->device.gpe_block) { |
1da177e4 LT |
232 | return (NULL); |
233 | } | |
234 | ||
235 | gpe_block = obj_desc->device.gpe_block; | |
236 | ||
237 | if ((gpe_number >= gpe_block->block_base_number) && | |
4be44fcd LB |
238 | (gpe_number < |
239 | gpe_block->block_base_number + (gpe_block->register_count * 8))) { | |
240 | return (&gpe_block-> | |
241 | event_info[gpe_number - gpe_block->block_base_number]); | |
1da177e4 LT |
242 | } |
243 | ||
244 | return (NULL); | |
245 | } | |
246 | ||
1da177e4 LT |
247 | /******************************************************************************* |
248 | * | |
249 | * FUNCTION: acpi_ev_gpe_detect | |
250 | * | |
251 | * PARAMETERS: gpe_xrupt_list - Interrupt block for this interrupt. | |
252 | * Can have multiple GPE blocks attached. | |
253 | * | |
254 | * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED | |
255 | * | |
9f15fc66 | 256 | * DESCRIPTION: Detect if any GP events have occurred. This function is |
1da177e4 LT |
257 | * executed at interrupt level. |
258 | * | |
259 | ******************************************************************************/ | |
260 | ||
4be44fcd | 261 | u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list) |
1da177e4 | 262 | { |
0897831b BM |
263 | acpi_status status; |
264 | struct acpi_gpe_block_info *gpe_block; | |
265 | struct acpi_gpe_register_info *gpe_register_info; | |
4be44fcd LB |
266 | u32 int_status = ACPI_INTERRUPT_NOT_HANDLED; |
267 | u8 enabled_status_byte; | |
4be44fcd LB |
268 | u32 status_reg; |
269 | u32 enable_reg; | |
b8e4d893 | 270 | acpi_cpu_flags flags; |
67a119f9 BM |
271 | u32 i; |
272 | u32 j; | |
4be44fcd | 273 | |
b229cf92 | 274 | ACPI_FUNCTION_NAME(ev_gpe_detect); |
1da177e4 LT |
275 | |
276 | /* Check for the case where there are no GPEs */ | |
277 | ||
278 | if (!gpe_xrupt_list) { | |
279 | return (int_status); | |
280 | } | |
281 | ||
967440e3 BM |
282 | /* |
283 | * We need to obtain the GPE lock for both the data structs and registers | |
9f15fc66 BM |
284 | * Note: Not necessary to obtain the hardware lock, since the GPE |
285 | * registers are owned by the gpe_lock. | |
967440e3 | 286 | */ |
4be44fcd | 287 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
4c90ece2 BM |
288 | |
289 | /* Examine all GPE blocks attached to this interrupt level */ | |
290 | ||
1da177e4 LT |
291 | gpe_block = gpe_xrupt_list->gpe_block_list_head; |
292 | while (gpe_block) { | |
293 | /* | |
9f15fc66 BM |
294 | * Read all of the 8-bit GPE status and enable registers in this GPE |
295 | * block, saving all of them. Find all currently active GP events. | |
1da177e4 LT |
296 | */ |
297 | for (i = 0; i < gpe_block->register_count; i++) { | |
52fc0b02 | 298 | |
1da177e4 LT |
299 | /* Get the next status/enable pair */ |
300 | ||
301 | gpe_register_info = &gpe_block->register_info[i]; | |
302 | ||
303 | /* Read the Status Register */ | |
304 | ||
4be44fcd | 305 | status = |
c6b5774c BM |
306 | acpi_hw_read(&status_reg, |
307 | &gpe_register_info->status_address); | |
4be44fcd | 308 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
309 | goto unlock_and_exit; |
310 | } | |
311 | ||
312 | /* Read the Enable Register */ | |
313 | ||
4be44fcd | 314 | status = |
c6b5774c BM |
315 | acpi_hw_read(&enable_reg, |
316 | &gpe_register_info->enable_address); | |
4be44fcd | 317 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
318 | goto unlock_and_exit; |
319 | } | |
320 | ||
4be44fcd LB |
321 | ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS, |
322 | "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n", | |
323 | gpe_register_info->base_gpe_number, | |
324 | status_reg, enable_reg)); | |
1da177e4 | 325 | |
44f6c012 | 326 | /* Check if there is anything active at all in this register */ |
1da177e4 LT |
327 | |
328 | enabled_status_byte = (u8) (status_reg & enable_reg); | |
329 | if (!enabled_status_byte) { | |
52fc0b02 | 330 | |
1da177e4 LT |
331 | /* No active GPEs in this register, move on */ |
332 | ||
333 | continue; | |
334 | } | |
335 | ||
336 | /* Now look at the individual GPEs in this byte register */ | |
337 | ||
338 | for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { | |
52fc0b02 | 339 | |
1da177e4 LT |
340 | /* Examine one GPE bit */ |
341 | ||
69874165 | 342 | if (enabled_status_byte & (1 << j)) { |
1da177e4 LT |
343 | /* |
344 | * Found an active GPE. Dispatch the event to a handler | |
345 | * or method. | |
346 | */ | |
4be44fcd LB |
347 | int_status |= |
348 | acpi_ev_gpe_dispatch(&gpe_block-> | |
67a119f9 | 349 | event_info[((acpi_size) i * ACPI_GPE_REGISTER_WIDTH) + j], j + gpe_register_info->base_gpe_number); |
1da177e4 LT |
350 | } |
351 | } | |
352 | } | |
353 | ||
354 | gpe_block = gpe_block->next; | |
355 | } | |
356 | ||
4be44fcd | 357 | unlock_and_exit: |
1da177e4 | 358 | |
4be44fcd | 359 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
1da177e4 LT |
360 | return (int_status); |
361 | } | |
362 | ||
1da177e4 LT |
363 | /******************************************************************************* |
364 | * | |
365 | * FUNCTION: acpi_ev_asynch_execute_gpe_method | |
366 | * | |
367 | * PARAMETERS: Context (gpe_event_info) - Info for this GPE | |
368 | * | |
369 | * RETURN: None | |
370 | * | |
4119532c BM |
371 | * DESCRIPTION: Perform the actual execution of a GPE control method. This |
372 | * function is called from an invocation of acpi_os_execute and | |
373 | * therefore does NOT execute at interrupt level - so that | |
1da177e4 LT |
374 | * the control method itself is not executed in the context of |
375 | * an interrupt handler. | |
376 | * | |
377 | ******************************************************************************/ | |
17bc54ee | 378 | static void acpi_ev_asynch_enable_gpe(void *context); |
1da177e4 | 379 | |
4be44fcd | 380 | static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context) |
1da177e4 | 381 | { |
4be44fcd | 382 | struct acpi_gpe_event_info *gpe_event_info = (void *)context; |
4be44fcd LB |
383 | acpi_status status; |
384 | struct acpi_gpe_event_info local_gpe_event_info; | |
4119532c | 385 | struct acpi_evaluate_info *info; |
1da177e4 | 386 | |
b229cf92 | 387 | ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method); |
1da177e4 | 388 | |
4be44fcd LB |
389 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
390 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
391 | return_VOID; |
392 | } | |
393 | ||
394 | /* Must revalidate the gpe_number/gpe_block */ | |
395 | ||
4be44fcd LB |
396 | if (!acpi_ev_valid_gpe_event(gpe_event_info)) { |
397 | status = acpi_ut_release_mutex(ACPI_MTX_EVENTS); | |
1da177e4 LT |
398 | return_VOID; |
399 | } | |
400 | ||
401 | /* Set the GPE flags for return to enabled state */ | |
402 | ||
4be44fcd | 403 | (void)acpi_ev_enable_gpe(gpe_event_info, FALSE); |
1da177e4 LT |
404 | |
405 | /* | |
9f15fc66 BM |
406 | * Take a snapshot of the GPE info for this level - we copy the info to |
407 | * prevent a race condition with remove_handler/remove_block. | |
1da177e4 | 408 | */ |
4be44fcd LB |
409 | ACPI_MEMCPY(&local_gpe_event_info, gpe_event_info, |
410 | sizeof(struct acpi_gpe_event_info)); | |
1da177e4 | 411 | |
4be44fcd LB |
412 | status = acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
413 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
414 | return_VOID; |
415 | } | |
416 | ||
417 | /* | |
9f15fc66 BM |
418 | * Must check for control method type dispatch one more time to avoid a |
419 | * race with ev_gpe_install_handler | |
1da177e4 | 420 | */ |
44f6c012 | 421 | if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) == |
4be44fcd | 422 | ACPI_GPE_DISPATCH_METHOD) { |
1da177e4 | 423 | |
4119532c BM |
424 | /* Allocate the evaluation information block */ |
425 | ||
426 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); | |
427 | if (!info) { | |
428 | status = AE_NO_MEMORY; | |
429 | } else { | |
430 | /* | |
431 | * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx | |
432 | * control method that corresponds to this GPE | |
433 | */ | |
434 | info->prefix_node = | |
435 | local_gpe_event_info.dispatch.method_node; | |
4119532c BM |
436 | info->flags = ACPI_IGNORE_RETURN_VALUE; |
437 | ||
438 | status = acpi_ns_evaluate(info); | |
439 | ACPI_FREE(info); | |
440 | } | |
441 | ||
4be44fcd | 442 | if (ACPI_FAILURE(status)) { |
b8e4d893 | 443 | ACPI_EXCEPTION((AE_INFO, status, |
2e42005b | 444 | "while evaluating GPE method [%4.4s]", |
b8e4d893 BM |
445 | acpi_ut_get_node_name |
446 | (local_gpe_event_info.dispatch. | |
4c90ece2 | 447 | method_node))); |
1da177e4 LT |
448 | } |
449 | } | |
17bc54ee AS |
450 | /* Defer enabling of GPE until all notify handlers are done */ |
451 | acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_asynch_enable_gpe, | |
452 | gpe_event_info); | |
453 | return_VOID; | |
454 | } | |
1da177e4 | 455 | |
17bc54ee AS |
456 | static void acpi_ev_asynch_enable_gpe(void *context) |
457 | { | |
458 | struct acpi_gpe_event_info *gpe_event_info = context; | |
459 | acpi_status status; | |
460 | if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == | |
4be44fcd | 461 | ACPI_GPE_LEVEL_TRIGGERED) { |
1da177e4 | 462 | /* |
9f15fc66 BM |
463 | * GPE is level-triggered, we clear the GPE status bit after handling |
464 | * the event. | |
1da177e4 | 465 | */ |
17bc54ee | 466 | status = acpi_hw_clear_gpe(gpe_event_info); |
4be44fcd | 467 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
468 | return_VOID; |
469 | } | |
470 | } | |
471 | ||
472 | /* Enable this GPE */ | |
17bc54ee | 473 | (void)acpi_hw_write_gpe_enable_reg(gpe_event_info); |
1da177e4 LT |
474 | return_VOID; |
475 | } | |
476 | ||
1da177e4 LT |
477 | /******************************************************************************* |
478 | * | |
479 | * FUNCTION: acpi_ev_gpe_dispatch | |
480 | * | |
44f6c012 | 481 | * PARAMETERS: gpe_event_info - Info for this GPE |
1da177e4 LT |
482 | * gpe_number - Number relative to the parent GPE block |
483 | * | |
484 | * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED | |
485 | * | |
486 | * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC) | |
487 | * or method (e.g. _Lxx/_Exx) handler. | |
488 | * | |
489 | * This function executes at interrupt level. | |
490 | * | |
491 | ******************************************************************************/ | |
492 | ||
493 | u32 | |
4be44fcd | 494 | acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number) |
1da177e4 | 495 | { |
4be44fcd | 496 | acpi_status status; |
1da177e4 | 497 | |
b229cf92 | 498 | ACPI_FUNCTION_TRACE(ev_gpe_dispatch); |
1da177e4 | 499 | |
5229e87d | 500 | acpi_os_gpe_count(gpe_number); |
fdffb72d | 501 | |
1da177e4 | 502 | /* |
9f15fc66 | 503 | * If edge-triggered, clear the GPE status bit now. Note that |
1da177e4 LT |
504 | * level-triggered events are cleared after the GPE is serviced. |
505 | */ | |
44f6c012 | 506 | if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == |
4be44fcd LB |
507 | ACPI_GPE_EDGE_TRIGGERED) { |
508 | status = acpi_hw_clear_gpe(gpe_event_info); | |
509 | if (ACPI_FAILURE(status)) { | |
b8e4d893 BM |
510 | ACPI_EXCEPTION((AE_INFO, status, |
511 | "Unable to clear GPE[%2X]", | |
512 | gpe_number)); | |
50eca3eb | 513 | return_UINT32(ACPI_INTERRUPT_NOT_HANDLED); |
1da177e4 LT |
514 | } |
515 | } | |
516 | ||
1da177e4 | 517 | /* |
c5a71569 BM |
518 | * Dispatch the GPE to either an installed handler, or the control method |
519 | * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke | |
520 | * it and do not attempt to run the method. If there is neither a handler | |
521 | * nor a method, we disable this GPE to prevent further such pointless | |
522 | * events from firing. | |
1da177e4 LT |
523 | */ |
524 | switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) { | |
525 | case ACPI_GPE_DISPATCH_HANDLER: | |
526 | ||
527 | /* | |
528 | * Invoke the installed handler (at interrupt level) | |
9f15fc66 BM |
529 | * Ignore return status for now. |
530 | * TBD: leave GPE disabled on error? | |
1da177e4 | 531 | */ |
4be44fcd LB |
532 | (void)gpe_event_info->dispatch.handler->address(gpe_event_info-> |
533 | dispatch. | |
534 | handler-> | |
535 | context); | |
1da177e4 LT |
536 | |
537 | /* It is now safe to clear level-triggered events. */ | |
538 | ||
44f6c012 | 539 | if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == |
4be44fcd LB |
540 | ACPI_GPE_LEVEL_TRIGGERED) { |
541 | status = acpi_hw_clear_gpe(gpe_event_info); | |
542 | if (ACPI_FAILURE(status)) { | |
b8e4d893 BM |
543 | ACPI_EXCEPTION((AE_INFO, status, |
544 | "Unable to clear GPE[%2X]", | |
545 | gpe_number)); | |
50eca3eb | 546 | return_UINT32(ACPI_INTERRUPT_NOT_HANDLED); |
1da177e4 LT |
547 | } |
548 | } | |
549 | break; | |
550 | ||
551 | case ACPI_GPE_DISPATCH_METHOD: | |
552 | ||
553 | /* | |
c5a71569 BM |
554 | * Disable the GPE, so it doesn't keep firing before the method has a |
555 | * chance to run (it runs asynchronously with interrupts enabled). | |
1da177e4 | 556 | */ |
4be44fcd LB |
557 | status = acpi_ev_disable_gpe(gpe_event_info); |
558 | if (ACPI_FAILURE(status)) { | |
b8e4d893 BM |
559 | ACPI_EXCEPTION((AE_INFO, status, |
560 | "Unable to disable GPE[%2X]", | |
561 | gpe_number)); | |
50eca3eb | 562 | return_UINT32(ACPI_INTERRUPT_NOT_HANDLED); |
1da177e4 LT |
563 | } |
564 | ||
565 | /* | |
566 | * Execute the method associated with the GPE | |
567 | * NOTE: Level-triggered GPEs are cleared after the method completes. | |
568 | */ | |
958dd242 BM |
569 | status = acpi_os_execute(OSL_GPE_HANDLER, |
570 | acpi_ev_asynch_execute_gpe_method, | |
571 | gpe_event_info); | |
4be44fcd | 572 | if (ACPI_FAILURE(status)) { |
b8e4d893 BM |
573 | ACPI_EXCEPTION((AE_INFO, status, |
574 | "Unable to queue handler for GPE[%2X] - event disabled", | |
575 | gpe_number)); | |
1da177e4 LT |
576 | } |
577 | break; | |
578 | ||
579 | default: | |
580 | ||
581 | /* No handler or method to run! */ | |
582 | ||
b8e4d893 BM |
583 | ACPI_ERROR((AE_INFO, |
584 | "No handler or method for GPE[%2X], disabling event", | |
585 | gpe_number)); | |
1da177e4 LT |
586 | |
587 | /* | |
9f15fc66 | 588 | * Disable the GPE. The GPE will remain disabled until the ACPICA |
1da177e4 LT |
589 | * Core Subsystem is restarted, or a handler is installed. |
590 | */ | |
4be44fcd LB |
591 | status = acpi_ev_disable_gpe(gpe_event_info); |
592 | if (ACPI_FAILURE(status)) { | |
b8e4d893 BM |
593 | ACPI_EXCEPTION((AE_INFO, status, |
594 | "Unable to disable GPE[%2X]", | |
595 | gpe_number)); | |
50eca3eb | 596 | return_UINT32(ACPI_INTERRUPT_NOT_HANDLED); |
1da177e4 LT |
597 | } |
598 | break; | |
599 | } | |
600 | ||
50eca3eb | 601 | return_UINT32(ACPI_INTERRUPT_HANDLED); |
1da177e4 | 602 | } |