blob: d24d7d31f40ce6ba85c2c1eaaf87f489143a189a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: evgpe - General Purpose Event handling and dispatch
4 *
5 *****************************************************************************/
6
7/*
Bob Moorea8357b02010-01-22 19:07:36 +08008 * Copyright (C) 2000 - 2010, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acevents.h"
47#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("evgpe")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Robert Moore44f6c012005-04-18 22:49:35 -040052/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040053static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/*******************************************************************************
56 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 * FUNCTION: acpi_ev_update_gpe_enable_masks
58 *
59 * PARAMETERS: gpe_event_info - GPE to update
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 *
61 * RETURN: Status
62 *
Lin Ming0f849d22010-04-06 14:52:37 +080063 * DESCRIPTION: Updates GPE register enable masks based upon whether there are
64 * references (either wake or run) to this GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 *
66 ******************************************************************************/
67
68acpi_status
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010069acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Len Brown4be44fc2005-08-05 00:44:28 -040071 struct acpi_gpe_register_info *gpe_register_info;
Rafael J. Wysockie4e9a732010-06-08 10:48:26 +020072 u32 register_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Bob Mooreb229cf92006-04-21 17:15:00 -040074 ACPI_FUNCTION_TRACE(ev_update_gpe_enable_masks);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 gpe_register_info = gpe_event_info->register_info;
77 if (!gpe_register_info) {
Len Brown4be44fc2005-08-05 00:44:28 -040078 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 }
Bob Moored4913dc2009-03-06 10:05:18 +080080
Lin Mingb76df672010-07-01 10:07:17 +080081 register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info,
Rafael J. Wysockie4e9a732010-06-08 10:48:26 +020082 gpe_register_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Lin Ming0f849d22010-04-06 14:52:37 +080084 /* Clear the wake/run bits up front */
85
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010086 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake, register_bit);
87 ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Lin Ming0f849d22010-04-06 14:52:37 +080089 /* Set the mask bits only if there are references to this GPE */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Lin Ming0f849d22010-04-06 14:52:37 +080091 if (gpe_event_info->runtime_count) {
92 ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit);
93 }
94
95 if (gpe_event_info->wakeup_count) {
Len Brown4be44fc2005-08-05 00:44:28 -040096 ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit);
Lin Ming0f849d22010-04-06 14:52:37 +080097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Len Brown4be44fc2005-08-05 00:44:28 -040099 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
Lin Ming0f849d22010-04-06 14:52:37 +0800102
103/*******************************************************************************
104 *
105 * FUNCTION: acpi_ev_low_get_gpe_info
106 *
107 * PARAMETERS: gpe_number - Raw GPE number
108 * gpe_block - A GPE info block
109 *
110 * RETURN: A GPE event_info struct. NULL if not a valid GPE (The gpe_number
111 * is not within the specified GPE block)
112 *
113 * DESCRIPTION: Returns the event_info struct associated with this GPE. This is
114 * the low-level implementation of ev_get_gpe_event_info.
115 *
116 ******************************************************************************/
117
118struct acpi_gpe_event_info *acpi_ev_low_get_gpe_info(u32 gpe_number,
119 struct acpi_gpe_block_info
120 *gpe_block)
121{
122 u32 gpe_index;
123
124 /*
125 * Validate that the gpe_number is within the specified gpe_block.
126 * (Two steps)
127 */
128 if (!gpe_block || (gpe_number < gpe_block->block_base_number)) {
129 return (NULL);
130 }
131
132 gpe_index = gpe_number - gpe_block->block_base_number;
133 if (gpe_index >= gpe_block->gpe_count) {
134 return (NULL);
135 }
136
137 return (&gpe_block->event_info[gpe_index]);
138}
139
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141/*******************************************************************************
142 *
143 * FUNCTION: acpi_ev_get_gpe_event_info
144 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800145 * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 * gpe_number - Raw GPE number
147 *
148 * RETURN: A GPE event_info struct. NULL if not a valid GPE
149 *
150 * DESCRIPTION: Returns the event_info struct associated with this GPE.
151 * Validates the gpe_block and the gpe_number
152 *
153 * Should be called only when the GPE lists are semaphore locked
154 * and not subject to change.
155 *
156 ******************************************************************************/
157
Len Brown4be44fc2005-08-05 00:44:28 -0400158struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
159 u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
Len Brown4be44fc2005-08-05 00:44:28 -0400161 union acpi_operand_object *obj_desc;
Lin Ming0f849d22010-04-06 14:52:37 +0800162 struct acpi_gpe_event_info *gpe_info;
Bob Moore67a119f2008-06-10 13:42:13 +0800163 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Len Brown4be44fc2005-08-05 00:44:28 -0400165 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Bob Moore186c3072010-04-27 11:32:28 +0800167 /* A NULL gpe_device means use the FADT-defined GPE block(s) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 if (!gpe_device) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 /* Examine GPE Block 0 and 1 (These blocks are permanent) */
172
173 for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) {
Lin Ming0f849d22010-04-06 14:52:37 +0800174 gpe_info = acpi_ev_low_get_gpe_info(gpe_number,
175 acpi_gbl_gpe_fadt_blocks
176 [i]);
177 if (gpe_info) {
178 return (gpe_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
180 }
181
182 /* The gpe_number was not in the range of either FADT GPE block */
183
184 return (NULL);
185 }
186
187 /* A Non-NULL gpe_device means this is a GPE Block Device */
188
Len Brownfd350942007-05-09 23:34:35 -0400189 obj_desc = acpi_ns_get_attached_object((struct acpi_namespace_node *)
190 gpe_device);
Len Brown4be44fc2005-08-05 00:44:28 -0400191 if (!obj_desc || !obj_desc->device.gpe_block) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return (NULL);
193 }
194
Lin Ming0f849d22010-04-06 14:52:37 +0800195 return (acpi_ev_low_get_gpe_info
196 (gpe_number, obj_desc->device.gpe_block));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197}
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199/*******************************************************************************
200 *
201 * FUNCTION: acpi_ev_gpe_detect
202 *
203 * PARAMETERS: gpe_xrupt_list - Interrupt block for this interrupt.
204 * Can have multiple GPE blocks attached.
205 *
206 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
207 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800208 * DESCRIPTION: Detect if any GP events have occurred. This function is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 * executed at interrupt level.
210 *
211 ******************************************************************************/
212
Len Brown4be44fc2005-08-05 00:44:28 -0400213u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Len Brown4be44fc2005-08-05 00:44:28 -0400215 acpi_status status;
216 struct acpi_gpe_block_info *gpe_block;
Bob Moore08978312005-10-21 00:00:00 -0400217 struct acpi_gpe_register_info *gpe_register_info;
218 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
219 u8 enabled_status_byte;
220 u32 status_reg;
221 u32 enable_reg;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500222 acpi_cpu_flags flags;
Bob Moore67a119f2008-06-10 13:42:13 +0800223 u32 i;
224 u32 j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Bob Mooreb229cf92006-04-21 17:15:00 -0400226 ACPI_FUNCTION_NAME(ev_gpe_detect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 /* Check for the case where there are no GPEs */
229
230 if (!gpe_xrupt_list) {
231 return (int_status);
232 }
233
Bob Moore967440e32006-06-23 17:04:00 -0400234 /*
235 * We need to obtain the GPE lock for both the data structs and registers
Bob Moore9f15fc62008-11-12 16:01:56 +0800236 * Note: Not necessary to obtain the hardware lock, since the GPE
237 * registers are owned by the gpe_lock.
Bob Moore967440e32006-06-23 17:04:00 -0400238 */
Len Brown4be44fc2005-08-05 00:44:28 -0400239 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Bob Moore4c90ece2006-06-08 16:29:00 -0400240
241 /* Examine all GPE blocks attached to this interrupt level */
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 gpe_block = gpe_xrupt_list->gpe_block_list_head;
244 while (gpe_block) {
245 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800246 * Read all of the 8-bit GPE status and enable registers in this GPE
247 * block, saving all of them. Find all currently active GP events.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 */
249 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 /* Get the next status/enable pair */
252
253 gpe_register_info = &gpe_block->register_info[i];
254
255 /* Read the Status Register */
256
Len Brown4be44fc2005-08-05 00:44:28 -0400257 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800258 acpi_hw_read(&status_reg,
259 &gpe_register_info->status_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400260 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 goto unlock_and_exit;
262 }
263
264 /* Read the Enable Register */
265
Len Brown4be44fc2005-08-05 00:44:28 -0400266 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800267 acpi_hw_read(&enable_reg,
268 &gpe_register_info->enable_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400269 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 goto unlock_and_exit;
271 }
272
Len Brown4be44fc2005-08-05 00:44:28 -0400273 ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
274 "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n",
275 gpe_register_info->base_gpe_number,
276 status_reg, enable_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Robert Moore44f6c012005-04-18 22:49:35 -0400278 /* Check if there is anything active at all in this register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280 enabled_status_byte = (u8) (status_reg & enable_reg);
281 if (!enabled_status_byte) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 /* No active GPEs in this register, move on */
284
285 continue;
286 }
287
288 /* Now look at the individual GPEs in this byte register */
289
290 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 /* Examine one GPE bit */
293
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300294 if (enabled_status_byte & (1 << j)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 /*
296 * Found an active GPE. Dispatch the event to a handler
297 * or method.
298 */
Len Brown4be44fc2005-08-05 00:44:28 -0400299 int_status |=
300 acpi_ev_gpe_dispatch(&gpe_block->
Bob Moore67a119f2008-06-10 13:42:13 +0800301 event_info[((acpi_size) i * ACPI_GPE_REGISTER_WIDTH) + j], j + gpe_register_info->base_gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
303 }
304 }
305
306 gpe_block = gpe_block->next;
307 }
308
Len Brown4be44fc2005-08-05 00:44:28 -0400309 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Len Brown4be44fc2005-08-05 00:44:28 -0400311 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 return (int_status);
313}
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315/*******************************************************************************
316 *
317 * FUNCTION: acpi_ev_asynch_execute_gpe_method
318 *
319 * PARAMETERS: Context (gpe_event_info) - Info for this GPE
320 *
321 * RETURN: None
322 *
Bob Moore41195322006-05-26 16:36:00 -0400323 * DESCRIPTION: Perform the actual execution of a GPE control method. This
324 * function is called from an invocation of acpi_os_execute and
325 * therefore does NOT execute at interrupt level - so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 * the control method itself is not executed in the context of
327 * an interrupt handler.
328 *
329 ******************************************************************************/
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300330static void acpi_ev_asynch_enable_gpe(void *context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Len Brown4be44fc2005-08-05 00:44:28 -0400332static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333{
Len Brown4be44fc2005-08-05 00:44:28 -0400334 struct acpi_gpe_event_info *gpe_event_info = (void *)context;
Len Brown4be44fc2005-08-05 00:44:28 -0400335 acpi_status status;
336 struct acpi_gpe_event_info local_gpe_event_info;
Bob Moore41195322006-05-26 16:36:00 -0400337 struct acpi_evaluate_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Bob Mooreb229cf92006-04-21 17:15:00 -0400339 ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Len Brown4be44fc2005-08-05 00:44:28 -0400341 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
342 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 return_VOID;
344 }
345
346 /* Must revalidate the gpe_number/gpe_block */
347
Len Brown4be44fc2005-08-05 00:44:28 -0400348 if (!acpi_ev_valid_gpe_event(gpe_event_info)) {
349 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 return_VOID;
351 }
352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800354 * Take a snapshot of the GPE info for this level - we copy the info to
355 * prevent a race condition with remove_handler/remove_block.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 */
Len Brown4be44fc2005-08-05 00:44:28 -0400357 ACPI_MEMCPY(&local_gpe_event_info, gpe_event_info,
358 sizeof(struct acpi_gpe_event_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Len Brown4be44fc2005-08-05 00:44:28 -0400360 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
361 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 return_VOID;
363 }
364
365 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800366 * Must check for control method type dispatch one more time to avoid a
367 * race with ev_gpe_install_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 */
Robert Moore44f6c012005-04-18 22:49:35 -0400369 if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400370 ACPI_GPE_DISPATCH_METHOD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Bob Moore41195322006-05-26 16:36:00 -0400372 /* Allocate the evaluation information block */
373
374 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
375 if (!info) {
376 status = AE_NO_MEMORY;
377 } else {
378 /*
379 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx
380 * control method that corresponds to this GPE
381 */
382 info->prefix_node =
383 local_gpe_event_info.dispatch.method_node;
Bob Moore41195322006-05-26 16:36:00 -0400384 info->flags = ACPI_IGNORE_RETURN_VALUE;
385
386 status = acpi_ns_evaluate(info);
387 ACPI_FREE(info);
388 }
389
Len Brown4be44fc2005-08-05 00:44:28 -0400390 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500391 ACPI_EXCEPTION((AE_INFO, status,
Bob Moore2e420052007-02-02 19:48:18 +0300392 "while evaluating GPE method [%4.4s]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500393 acpi_ut_get_node_name
394 (local_gpe_event_info.dispatch.
Bob Moore4c90ece2006-06-08 16:29:00 -0400395 method_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 }
397 }
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300398 /* Defer enabling of GPE until all notify handlers are done */
399 acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_asynch_enable_gpe,
400 gpe_event_info);
401 return_VOID;
402}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300404static void acpi_ev_asynch_enable_gpe(void *context)
405{
406 struct acpi_gpe_event_info *gpe_event_info = context;
407 acpi_status status;
408 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400409 ACPI_GPE_LEVEL_TRIGGERED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800411 * GPE is level-triggered, we clear the GPE status bit after handling
412 * the event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 */
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300414 status = acpi_hw_clear_gpe(gpe_event_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400415 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 return_VOID;
417 }
418 }
419
420 /* Enable this GPE */
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300421 (void)acpi_hw_write_gpe_enable_reg(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 return_VOID;
423}
424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425/*******************************************************************************
426 *
427 * FUNCTION: acpi_ev_gpe_dispatch
428 *
Robert Moore44f6c012005-04-18 22:49:35 -0400429 * PARAMETERS: gpe_event_info - Info for this GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 * gpe_number - Number relative to the parent GPE block
431 *
432 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
433 *
434 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
435 * or method (e.g. _Lxx/_Exx) handler.
436 *
437 * This function executes at interrupt level.
438 *
439 ******************************************************************************/
440
441u32
Len Brown4be44fc2005-08-05 00:44:28 -0400442acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443{
Len Brown4be44fc2005-08-05 00:44:28 -0400444 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Bob Mooreb229cf92006-04-21 17:15:00 -0400446 ACPI_FUNCTION_TRACE(ev_gpe_dispatch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Len Brown5229e872008-02-06 01:26:55 -0500448 acpi_os_gpe_count(gpe_number);
Bob Moorefdffb722007-02-02 19:48:19 +0300449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800451 * If edge-triggered, clear the GPE status bit now. Note that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 * level-triggered events are cleared after the GPE is serviced.
453 */
Robert Moore44f6c012005-04-18 22:49:35 -0400454 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400455 ACPI_GPE_EDGE_TRIGGERED) {
456 status = acpi_hw_clear_gpe(gpe_event_info);
457 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500458 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800459 "Unable to clear GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500460 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400461 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 }
463 }
464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 /*
Bob Moorec5a71562007-02-02 19:48:19 +0300466 * Dispatch the GPE to either an installed handler, or the control method
467 * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke
468 * it and do not attempt to run the method. If there is neither a handler
469 * nor a method, we disable this GPE to prevent further such pointless
470 * events from firing.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 */
472 switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {
473 case ACPI_GPE_DISPATCH_HANDLER:
474
475 /*
476 * Invoke the installed handler (at interrupt level)
Bob Moore9f15fc62008-11-12 16:01:56 +0800477 * Ignore return status for now.
478 * TBD: leave GPE disabled on error?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 */
Len Brown4be44fc2005-08-05 00:44:28 -0400480 (void)gpe_event_info->dispatch.handler->address(gpe_event_info->
481 dispatch.
482 handler->
483 context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 /* It is now safe to clear level-triggered events. */
486
Robert Moore44f6c012005-04-18 22:49:35 -0400487 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400488 ACPI_GPE_LEVEL_TRIGGERED) {
489 status = acpi_hw_clear_gpe(gpe_event_info);
490 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500491 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800492 "Unable to clear GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500493 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400494 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
496 }
497 break;
498
499 case ACPI_GPE_DISPATCH_METHOD:
500
501 /*
Bob Moorec5a71562007-02-02 19:48:19 +0300502 * Disable the GPE, so it doesn't keep firing before the method has a
503 * chance to run (it runs asynchronously with interrupts enabled).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 */
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200505 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
Len Brown4be44fc2005-08-05 00:44:28 -0400506 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500507 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800508 "Unable to disable GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500509 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400510 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 }
512
513 /*
514 * Execute the method associated with the GPE
515 * NOTE: Level-triggered GPEs are cleared after the method completes.
516 */
Bob Moore958dd242006-05-12 17:12:00 -0400517 status = acpi_os_execute(OSL_GPE_HANDLER,
518 acpi_ev_asynch_execute_gpe_method,
519 gpe_event_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400520 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500521 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800522 "Unable to queue handler for GPE[0x%2X] - event disabled",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500523 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 }
525 break;
526
527 default:
528
Lin Ming0f849d22010-04-06 14:52:37 +0800529 /*
530 * No handler or method to run!
531 * 03/2010: This case should no longer be possible. We will not allow
532 * a GPE to be enabled if it has no handler or method.
533 */
Bob Mooreb8e4d892006-01-27 16:43:00 -0500534 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800535 "No handler or method for GPE[0x%2X], disabling event",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500536 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800539 * Disable the GPE. The GPE will remain disabled a handler
540 * is installed or ACPICA is restarted.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 */
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200542 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
Len Brown4be44fc2005-08-05 00:44:28 -0400543 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500544 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800545 "Unable to disable GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500546 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400547 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 }
549 break;
550 }
551
Bob Moore50eca3e2005-09-30 19:03:00 -0400552 return_UINT32(ACPI_INTERRUPT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553}