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