blob: 7a6a3e6f4be09dbc7522d17c10d3b03be579227d [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 *
Rafael J. Wysockia44061a2010-07-01 10:11:45 +080057 * FUNCTION: acpi_ev_update_gpe_enable_mask
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 *
59 * PARAMETERS: gpe_event_info - GPE to update
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 *
61 * RETURN: Status
62 *
Rafael J. Wysockia44061a2010-07-01 10:11:45 +080063 * DESCRIPTION: Updates GPE register enable mask based upon whether there are
64 * runtime references to this GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 *
66 ******************************************************************************/
67
68acpi_status
Rafael J. Wysockia44061a2010-07-01 10:11:45 +080069acpi_ev_update_gpe_enable_mask(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
Rafael J. Wysockia44061a2010-07-01 10:11:45 +080074 ACPI_FUNCTION_TRACE(ev_update_gpe_enable_mask);
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
Rafael J. Wysockia44061a2010-07-01 10:11:45 +080084 /* Clear the run bit up front */
Lin Ming0f849d22010-04-06 14:52:37 +080085
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010086 ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Rafael J. Wysockia44061a2010-07-01 10:11:45 +080088 /* Set the mask bit only if there are references to this GPE */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Lin Ming0f849d22010-04-06 14:52:37 +080090 if (gpe_event_info->runtime_count) {
Rafael J. Wysockia44061a2010-07-01 10:11:45 +080091 ACPI_SET_BIT(gpe_register_info->enable_for_run, (u8)register_bit);
Lin Ming0f849d22010-04-06 14:52:37 +080092 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Len Brown4be44fc2005-08-05 00:44:28 -040094 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Rafael J. Wysocki3bd741b2010-07-01 11:01:12 +080097/*******************************************************************************
98 *
99 * FUNCTION: acpi_ev_enable_gpe
100 *
101 * PARAMETERS: gpe_event_info - GPE to enable
102 *
103 * RETURN: Status
104 *
105 * DESCRIPTION: Clear the given GPE from stale events and enable it.
106 *
107 ******************************************************************************/
108acpi_status
109acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
110{
111 acpi_status status;
112
113 ACPI_FUNCTION_TRACE(ev_enable_gpe);
114
115 /*
116 * We will only allow a GPE to be enabled if it has either an
117 * associated method (_Lxx/_Exx) or a handler. Otherwise, the
118 * GPE will be immediately disabled by acpi_ev_gpe_dispatch the
119 * first time it fires.
120 */
121 if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)) {
122 return_ACPI_STATUS(AE_NO_HANDLER);
123 }
124
125 /* Clear the GPE (of stale events) */
126 status = acpi_hw_clear_gpe(gpe_event_info);
127 if (ACPI_FAILURE(status)) {
128 return_ACPI_STATUS(status);
129 }
130
131 /* Enable the requested GPE */
132 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE);
133
134 return_ACPI_STATUS(status);
135}
136
Lin Ming0f849d22010-04-06 14:52:37 +0800137
138/*******************************************************************************
139 *
140 * FUNCTION: acpi_ev_low_get_gpe_info
141 *
142 * PARAMETERS: gpe_number - Raw GPE number
143 * gpe_block - A GPE info block
144 *
145 * RETURN: A GPE event_info struct. NULL if not a valid GPE (The gpe_number
146 * is not within the specified GPE block)
147 *
148 * DESCRIPTION: Returns the event_info struct associated with this GPE. This is
149 * the low-level implementation of ev_get_gpe_event_info.
150 *
151 ******************************************************************************/
152
153struct acpi_gpe_event_info *acpi_ev_low_get_gpe_info(u32 gpe_number,
154 struct acpi_gpe_block_info
155 *gpe_block)
156{
157 u32 gpe_index;
158
159 /*
160 * Validate that the gpe_number is within the specified gpe_block.
161 * (Two steps)
162 */
163 if (!gpe_block || (gpe_number < gpe_block->block_base_number)) {
164 return (NULL);
165 }
166
167 gpe_index = gpe_number - gpe_block->block_base_number;
168 if (gpe_index >= gpe_block->gpe_count) {
169 return (NULL);
170 }
171
172 return (&gpe_block->event_info[gpe_index]);
173}
174
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176/*******************************************************************************
177 *
178 * FUNCTION: acpi_ev_get_gpe_event_info
179 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800180 * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 * gpe_number - Raw GPE number
182 *
183 * RETURN: A GPE event_info struct. NULL if not a valid GPE
184 *
185 * DESCRIPTION: Returns the event_info struct associated with this GPE.
186 * Validates the gpe_block and the gpe_number
187 *
188 * Should be called only when the GPE lists are semaphore locked
189 * and not subject to change.
190 *
191 ******************************************************************************/
192
Len Brown4be44fc2005-08-05 00:44:28 -0400193struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
194 u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Len Brown4be44fc2005-08-05 00:44:28 -0400196 union acpi_operand_object *obj_desc;
Lin Ming0f849d22010-04-06 14:52:37 +0800197 struct acpi_gpe_event_info *gpe_info;
Bob Moore67a119f2008-06-10 13:42:13 +0800198 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Len Brown4be44fc2005-08-05 00:44:28 -0400200 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Bob Moore186c3072010-04-27 11:32:28 +0800202 /* A NULL gpe_device means use the FADT-defined GPE block(s) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 if (!gpe_device) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 /* Examine GPE Block 0 and 1 (These blocks are permanent) */
207
208 for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) {
Lin Ming0f849d22010-04-06 14:52:37 +0800209 gpe_info = acpi_ev_low_get_gpe_info(gpe_number,
210 acpi_gbl_gpe_fadt_blocks
211 [i]);
212 if (gpe_info) {
213 return (gpe_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 }
215 }
216
217 /* The gpe_number was not in the range of either FADT GPE block */
218
219 return (NULL);
220 }
221
222 /* A Non-NULL gpe_device means this is a GPE Block Device */
223
Len Brownfd350942007-05-09 23:34:35 -0400224 obj_desc = acpi_ns_get_attached_object((struct acpi_namespace_node *)
225 gpe_device);
Len Brown4be44fc2005-08-05 00:44:28 -0400226 if (!obj_desc || !obj_desc->device.gpe_block) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 return (NULL);
228 }
229
Lin Ming0f849d22010-04-06 14:52:37 +0800230 return (acpi_ev_low_get_gpe_info
231 (gpe_number, obj_desc->device.gpe_block));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234/*******************************************************************************
235 *
236 * FUNCTION: acpi_ev_gpe_detect
237 *
238 * PARAMETERS: gpe_xrupt_list - Interrupt block for this interrupt.
239 * Can have multiple GPE blocks attached.
240 *
241 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
242 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800243 * DESCRIPTION: Detect if any GP events have occurred. This function is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 * executed at interrupt level.
245 *
246 ******************************************************************************/
247
Len Brown4be44fc2005-08-05 00:44:28 -0400248u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
Len Brown4be44fc2005-08-05 00:44:28 -0400250 acpi_status status;
251 struct acpi_gpe_block_info *gpe_block;
Bob Moore08978312005-10-21 00:00:00 -0400252 struct acpi_gpe_register_info *gpe_register_info;
253 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
254 u8 enabled_status_byte;
255 u32 status_reg;
256 u32 enable_reg;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500257 acpi_cpu_flags flags;
Bob Moore67a119f2008-06-10 13:42:13 +0800258 u32 i;
259 u32 j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Bob Mooreb229cf92006-04-21 17:15:00 -0400261 ACPI_FUNCTION_NAME(ev_gpe_detect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 /* Check for the case where there are no GPEs */
264
265 if (!gpe_xrupt_list) {
266 return (int_status);
267 }
268
Bob Moore967440e32006-06-23 17:04:00 -0400269 /*
270 * We need to obtain the GPE lock for both the data structs and registers
Bob Moore9f15fc62008-11-12 16:01:56 +0800271 * Note: Not necessary to obtain the hardware lock, since the GPE
272 * registers are owned by the gpe_lock.
Bob Moore967440e32006-06-23 17:04:00 -0400273 */
Len Brown4be44fc2005-08-05 00:44:28 -0400274 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Bob Moore4c90ece2006-06-08 16:29:00 -0400275
276 /* Examine all GPE blocks attached to this interrupt level */
277
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 gpe_block = gpe_xrupt_list->gpe_block_list_head;
279 while (gpe_block) {
280 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800281 * Read all of the 8-bit GPE status and enable registers in this GPE
282 * block, saving all of them. Find all currently active GP events.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 */
284 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 /* Get the next status/enable pair */
287
288 gpe_register_info = &gpe_block->register_info[i];
289
290 /* Read the Status Register */
291
Len Brown4be44fc2005-08-05 00:44:28 -0400292 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800293 acpi_hw_read(&status_reg,
294 &gpe_register_info->status_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400295 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 goto unlock_and_exit;
297 }
298
299 /* Read the Enable Register */
300
Len Brown4be44fc2005-08-05 00:44:28 -0400301 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800302 acpi_hw_read(&enable_reg,
303 &gpe_register_info->enable_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400304 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 goto unlock_and_exit;
306 }
307
Len Brown4be44fc2005-08-05 00:44:28 -0400308 ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
309 "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n",
310 gpe_register_info->base_gpe_number,
311 status_reg, enable_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Robert Moore44f6c012005-04-18 22:49:35 -0400313 /* Check if there is anything active at all in this register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315 enabled_status_byte = (u8) (status_reg & enable_reg);
316 if (!enabled_status_byte) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 /* No active GPEs in this register, move on */
319
320 continue;
321 }
322
323 /* Now look at the individual GPEs in this byte register */
324
325 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 /* Examine one GPE bit */
328
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300329 if (enabled_status_byte & (1 << j)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 /*
331 * Found an active GPE. Dispatch the event to a handler
332 * or method.
333 */
Len Brown4be44fc2005-08-05 00:44:28 -0400334 int_status |=
335 acpi_ev_gpe_dispatch(&gpe_block->
Bob Moore67a119f2008-06-10 13:42:13 +0800336 event_info[((acpi_size) i * ACPI_GPE_REGISTER_WIDTH) + j], j + gpe_register_info->base_gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 }
338 }
339 }
340
341 gpe_block = gpe_block->next;
342 }
343
Len Brown4be44fc2005-08-05 00:44:28 -0400344 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Len Brown4be44fc2005-08-05 00:44:28 -0400346 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 return (int_status);
348}
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350/*******************************************************************************
351 *
352 * FUNCTION: acpi_ev_asynch_execute_gpe_method
353 *
354 * PARAMETERS: Context (gpe_event_info) - Info for this GPE
355 *
356 * RETURN: None
357 *
Bob Moore41195322006-05-26 16:36:00 -0400358 * DESCRIPTION: Perform the actual execution of a GPE control method. This
359 * function is called from an invocation of acpi_os_execute and
360 * therefore does NOT execute at interrupt level - so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 * the control method itself is not executed in the context of
362 * an interrupt handler.
363 *
364 ******************************************************************************/
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300365static void acpi_ev_asynch_enable_gpe(void *context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Len Brown4be44fc2005-08-05 00:44:28 -0400367static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
Len Brown4be44fc2005-08-05 00:44:28 -0400369 struct acpi_gpe_event_info *gpe_event_info = (void *)context;
Len Brown4be44fc2005-08-05 00:44:28 -0400370 acpi_status status;
371 struct acpi_gpe_event_info local_gpe_event_info;
Bob Moore41195322006-05-26 16:36:00 -0400372 struct acpi_evaluate_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Bob Mooreb229cf92006-04-21 17:15:00 -0400374 ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Len Brown4be44fc2005-08-05 00:44:28 -0400376 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
377 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 return_VOID;
379 }
380
381 /* Must revalidate the gpe_number/gpe_block */
382
Len Brown4be44fc2005-08-05 00:44:28 -0400383 if (!acpi_ev_valid_gpe_event(gpe_event_info)) {
384 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 return_VOID;
386 }
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800389 * Take a snapshot of the GPE info for this level - we copy the info to
390 * prevent a race condition with remove_handler/remove_block.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 */
Len Brown4be44fc2005-08-05 00:44:28 -0400392 ACPI_MEMCPY(&local_gpe_event_info, gpe_event_info,
393 sizeof(struct acpi_gpe_event_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Len Brown4be44fc2005-08-05 00:44:28 -0400395 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
396 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 return_VOID;
398 }
399
400 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800401 * Must check for control method type dispatch one more time to avoid a
402 * race with ev_gpe_install_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 */
Robert Moore44f6c012005-04-18 22:49:35 -0400404 if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400405 ACPI_GPE_DISPATCH_METHOD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Bob Moore41195322006-05-26 16:36:00 -0400407 /* Allocate the evaluation information block */
408
409 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
410 if (!info) {
411 status = AE_NO_MEMORY;
412 } else {
413 /*
414 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx
415 * control method that corresponds to this GPE
416 */
417 info->prefix_node =
418 local_gpe_event_info.dispatch.method_node;
Bob Moore41195322006-05-26 16:36:00 -0400419 info->flags = ACPI_IGNORE_RETURN_VALUE;
420
421 status = acpi_ns_evaluate(info);
422 ACPI_FREE(info);
423 }
424
Len Brown4be44fc2005-08-05 00:44:28 -0400425 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500426 ACPI_EXCEPTION((AE_INFO, status,
Bob Moore2e420052007-02-02 19:48:18 +0300427 "while evaluating GPE method [%4.4s]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500428 acpi_ut_get_node_name
429 (local_gpe_event_info.dispatch.
Bob Moore4c90ece2006-06-08 16:29:00 -0400430 method_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 }
432 }
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300433 /* Defer enabling of GPE until all notify handlers are done */
434 acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_asynch_enable_gpe,
435 gpe_event_info);
436 return_VOID;
437}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300439static void acpi_ev_asynch_enable_gpe(void *context)
440{
441 struct acpi_gpe_event_info *gpe_event_info = context;
442 acpi_status status;
443 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400444 ACPI_GPE_LEVEL_TRIGGERED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800446 * GPE is level-triggered, we clear the GPE status bit after handling
447 * the event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 */
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300449 status = acpi_hw_clear_gpe(gpe_event_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400450 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 return_VOID;
452 }
453 }
454
Bob Moorede5668f2010-07-06 10:30:37 +0800455 /*
456 * Enable this GPE, conditionally. This means that the GPE will only be
457 * physically enabled if the enable_for_run bit is set in the event_info
458 */
459 (void)acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_COND_ENABLE);
460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 return_VOID;
462}
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464/*******************************************************************************
465 *
466 * FUNCTION: acpi_ev_gpe_dispatch
467 *
Robert Moore44f6c012005-04-18 22:49:35 -0400468 * PARAMETERS: gpe_event_info - Info for this GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 * gpe_number - Number relative to the parent GPE block
470 *
471 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
472 *
473 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
474 * or method (e.g. _Lxx/_Exx) handler.
475 *
476 * This function executes at interrupt level.
477 *
478 ******************************************************************************/
479
480u32
Len Brown4be44fc2005-08-05 00:44:28 -0400481acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
Len Brown4be44fc2005-08-05 00:44:28 -0400483 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Bob Mooreb229cf92006-04-21 17:15:00 -0400485 ACPI_FUNCTION_TRACE(ev_gpe_dispatch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Len Brown5229e872008-02-06 01:26:55 -0500487 acpi_os_gpe_count(gpe_number);
Bob Moorefdffb722007-02-02 19:48:19 +0300488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800490 * If edge-triggered, clear the GPE status bit now. Note that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 * level-triggered events are cleared after the GPE is serviced.
492 */
Robert Moore44f6c012005-04-18 22:49:35 -0400493 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400494 ACPI_GPE_EDGE_TRIGGERED) {
495 status = acpi_hw_clear_gpe(gpe_event_info);
496 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500497 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800498 "Unable to clear GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500499 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400500 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502 }
503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 /*
Bob Moorec5a71562007-02-02 19:48:19 +0300505 * Dispatch the GPE to either an installed handler, or the control method
506 * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke
507 * it and do not attempt to run the method. If there is neither a handler
508 * nor a method, we disable this GPE to prevent further such pointless
509 * events from firing.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 */
511 switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {
512 case ACPI_GPE_DISPATCH_HANDLER:
513
514 /*
515 * Invoke the installed handler (at interrupt level)
Bob Moore9f15fc62008-11-12 16:01:56 +0800516 * Ignore return status for now.
517 * TBD: leave GPE disabled on error?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 */
Len Brown4be44fc2005-08-05 00:44:28 -0400519 (void)gpe_event_info->dispatch.handler->address(gpe_event_info->
520 dispatch.
521 handler->
522 context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 /* It is now safe to clear level-triggered events. */
525
Robert Moore44f6c012005-04-18 22:49:35 -0400526 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400527 ACPI_GPE_LEVEL_TRIGGERED) {
528 status = acpi_hw_clear_gpe(gpe_event_info);
529 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500530 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800531 "Unable to clear GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500532 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400533 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
535 }
536 break;
537
538 case ACPI_GPE_DISPATCH_METHOD:
539
540 /*
Bob Moorec5a71562007-02-02 19:48:19 +0300541 * Disable the GPE, so it doesn't keep firing before the method has a
542 * chance to run (it runs asynchronously with interrupts enabled).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 */
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200544 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
Len Brown4be44fc2005-08-05 00:44:28 -0400545 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500546 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800547 "Unable to disable GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500548 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400549 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 }
551
552 /*
553 * Execute the method associated with the GPE
554 * NOTE: Level-triggered GPEs are cleared after the method completes.
555 */
Bob Moore958dd242006-05-12 17:12:00 -0400556 status = acpi_os_execute(OSL_GPE_HANDLER,
557 acpi_ev_asynch_execute_gpe_method,
558 gpe_event_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400559 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500560 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800561 "Unable to queue handler for GPE[0x%2X] - event disabled",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500562 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 }
564 break;
565
566 default:
567
Lin Ming0f849d22010-04-06 14:52:37 +0800568 /*
569 * No handler or method to run!
570 * 03/2010: This case should no longer be possible. We will not allow
571 * a GPE to be enabled if it has no handler or method.
572 */
Bob Mooreb8e4d892006-01-27 16:43:00 -0500573 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800574 "No handler or method for GPE[0x%2X], disabling event",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500575 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800578 * Disable the GPE. The GPE will remain disabled a handler
579 * is installed or ACPICA is restarted.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 */
Rafael J. Wysockifd247442010-06-08 10:49:08 +0200581 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
Len Brown4be44fc2005-08-05 00:44:28 -0400582 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500583 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800584 "Unable to disable GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500585 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400586 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
588 break;
589 }
590
Bob Moore50eca3e2005-09-30 19:03:00 -0400591 return_UINT32(ACPI_INTERRUPT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592}