blob: b9d50ef9f3eceee3dcdce101de77d940bdb59a38 [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 *
63 * DESCRIPTION: Updates GPE register enable masks based on the GPE type
64 *
65 ******************************************************************************/
66
67acpi_status
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010068acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Len Brown4be44fc2005-08-05 00:44:28 -040070 struct acpi_gpe_register_info *gpe_register_info;
71 u8 register_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Bob Mooreb229cf92006-04-21 17:15:00 -040073 ACPI_FUNCTION_TRACE(ev_update_gpe_enable_masks);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 gpe_register_info = gpe_event_info->register_info;
76 if (!gpe_register_info) {
Len Brown4be44fc2005-08-05 00:44:28 -040077 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 }
Bob Moored4913dc2009-03-06 10:05:18 +080079
Alexey Starikovskiy69874162007-02-02 19:48:19 +030080 register_bit = (u8)
81 (1 <<
82 (gpe_event_info->gpe_number - gpe_register_info->base_gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010084 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake, register_bit);
85 ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010087 if (gpe_event_info->runtime_count)
Len Brown4be44fc2005-08-05 00:44:28 -040088 ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010090 if (gpe_event_info->wakeup_count)
Len Brown4be44fc2005-08-05 00:44:28 -040091 ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Len Brown4be44fc2005-08-05 00:44:28 -040093 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/*******************************************************************************
97 *
98 * FUNCTION: acpi_ev_enable_gpe
99 *
100 * PARAMETERS: gpe_event_info - GPE to enable
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 *
102 * RETURN: Status
103 *
104 * DESCRIPTION: Enable a GPE based on the GPE type
105 *
106 ******************************************************************************/
107
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100108acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
Len Brown4be44fc2005-08-05 00:44:28 -0400110 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Bob Mooreb229cf92006-04-21 17:15:00 -0400112 ACPI_FUNCTION_TRACE(ev_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 /* Make sure HW enable masks are updated */
115
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100116 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
117 if (ACPI_FAILURE(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400118 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Rafael J. Wysockibf02bd22010-03-16 23:21:55 +0100120 /* Clear the GPE (of stale events), then enable it */
121 status = acpi_hw_clear_gpe(gpe_event_info);
122 if (ACPI_FAILURE(status))
123 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Rafael J. Wysockibf02bd22010-03-16 23:21:55 +0100125 /* Enable the requested GPE */
126 status = acpi_hw_write_gpe_enable_reg(gpe_event_info);
127 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130/*******************************************************************************
131 *
132 * FUNCTION: acpi_ev_disable_gpe
133 *
134 * PARAMETERS: gpe_event_info - GPE to disable
135 *
136 * RETURN: Status
137 *
138 * DESCRIPTION: Disable a GPE based on the GPE type
139 *
140 ******************************************************************************/
141
Len Brown4be44fc2005-08-05 00:44:28 -0400142acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Len Brown4be44fc2005-08-05 00:44:28 -0400144 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Bob Mooreb229cf92006-04-21 17:15:00 -0400146 ACPI_FUNCTION_TRACE(ev_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 /* Make sure HW enable masks are updated */
149
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100150 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
151 if (ACPI_FAILURE(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400152 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Bob Mooree38e8a02008-06-13 08:28:55 +0800154 /*
155 * Even if we don't know the GPE type, make sure that we always
156 * disable it. low_disable_gpe will just clear the enable bit for this
157 * GPE and write it. It will not write out the current GPE enable mask,
158 * since this may inadvertently enable GPEs too early, if a rogue GPE has
159 * come in during ACPICA initialization - possibly as a result of AML or
160 * other code that has enabled the GPE.
161 */
162 status = acpi_hw_low_disable_gpe(gpe_event_info);
163 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164}
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166/*******************************************************************************
167 *
168 * FUNCTION: acpi_ev_get_gpe_event_info
169 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800170 * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 * gpe_number - Raw GPE number
172 *
173 * RETURN: A GPE event_info struct. NULL if not a valid GPE
174 *
175 * DESCRIPTION: Returns the event_info struct associated with this GPE.
176 * Validates the gpe_block and the gpe_number
177 *
178 * Should be called only when the GPE lists are semaphore locked
179 * and not subject to change.
180 *
181 ******************************************************************************/
182
Len Brown4be44fc2005-08-05 00:44:28 -0400183struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
184 u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
Len Brown4be44fc2005-08-05 00:44:28 -0400186 union acpi_operand_object *obj_desc;
187 struct acpi_gpe_block_info *gpe_block;
Bob Moore67a119f2008-06-10 13:42:13 +0800188 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Len Brown4be44fc2005-08-05 00:44:28 -0400190 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 /* A NULL gpe_block means use the FADT-defined GPE block(s) */
193
194 if (!gpe_device) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 /* Examine GPE Block 0 and 1 (These blocks are permanent) */
197
198 for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) {
199 gpe_block = acpi_gbl_gpe_fadt_blocks[i];
200 if (gpe_block) {
Len Brown4be44fc2005-08-05 00:44:28 -0400201 if ((gpe_number >= gpe_block->block_base_number)
202 && (gpe_number <
203 gpe_block->block_base_number +
204 (gpe_block->register_count * 8))) {
205 return (&gpe_block->
206 event_info[gpe_number -
207 gpe_block->
208 block_base_number]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 }
210 }
211 }
212
213 /* The gpe_number was not in the range of either FADT GPE block */
214
215 return (NULL);
216 }
217
218 /* A Non-NULL gpe_device means this is a GPE Block Device */
219
Len Brownfd350942007-05-09 23:34:35 -0400220 obj_desc = acpi_ns_get_attached_object((struct acpi_namespace_node *)
221 gpe_device);
Len Brown4be44fc2005-08-05 00:44:28 -0400222 if (!obj_desc || !obj_desc->device.gpe_block) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 return (NULL);
224 }
225
226 gpe_block = obj_desc->device.gpe_block;
227
228 if ((gpe_number >= gpe_block->block_base_number) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400229 (gpe_number <
230 gpe_block->block_base_number + (gpe_block->register_count * 8))) {
231 return (&gpe_block->
232 event_info[gpe_number - gpe_block->block_base_number]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 }
234
235 return (NULL);
236}
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238/*******************************************************************************
239 *
240 * FUNCTION: acpi_ev_gpe_detect
241 *
242 * PARAMETERS: gpe_xrupt_list - Interrupt block for this interrupt.
243 * Can have multiple GPE blocks attached.
244 *
245 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
246 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800247 * DESCRIPTION: Detect if any GP events have occurred. This function is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 * executed at interrupt level.
249 *
250 ******************************************************************************/
251
Len Brown4be44fc2005-08-05 00:44:28 -0400252u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Len Brown4be44fc2005-08-05 00:44:28 -0400254 acpi_status status;
255 struct acpi_gpe_block_info *gpe_block;
Bob Moore08978312005-10-21 00:00:00 -0400256 struct acpi_gpe_register_info *gpe_register_info;
257 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
258 u8 enabled_status_byte;
259 u32 status_reg;
260 u32 enable_reg;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500261 acpi_cpu_flags flags;
Bob Moore67a119f2008-06-10 13:42:13 +0800262 u32 i;
263 u32 j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Bob Mooreb229cf92006-04-21 17:15:00 -0400265 ACPI_FUNCTION_NAME(ev_gpe_detect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 /* Check for the case where there are no GPEs */
268
269 if (!gpe_xrupt_list) {
270 return (int_status);
271 }
272
Bob Moore967440e32006-06-23 17:04:00 -0400273 /*
274 * We need to obtain the GPE lock for both the data structs and registers
Bob Moore9f15fc62008-11-12 16:01:56 +0800275 * Note: Not necessary to obtain the hardware lock, since the GPE
276 * registers are owned by the gpe_lock.
Bob Moore967440e32006-06-23 17:04:00 -0400277 */
Len Brown4be44fc2005-08-05 00:44:28 -0400278 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Bob Moore4c90ece2006-06-08 16:29:00 -0400279
280 /* Examine all GPE blocks attached to this interrupt level */
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 gpe_block = gpe_xrupt_list->gpe_block_list_head;
283 while (gpe_block) {
284 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800285 * Read all of the 8-bit GPE status and enable registers in this GPE
286 * block, saving all of them. Find all currently active GP events.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 */
288 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 /* Get the next status/enable pair */
291
292 gpe_register_info = &gpe_block->register_info[i];
293
294 /* Read the Status Register */
295
Len Brown4be44fc2005-08-05 00:44:28 -0400296 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800297 acpi_hw_read(&status_reg,
298 &gpe_register_info->status_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400299 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 goto unlock_and_exit;
301 }
302
303 /* Read the Enable Register */
304
Len Brown4be44fc2005-08-05 00:44:28 -0400305 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800306 acpi_hw_read(&enable_reg,
307 &gpe_register_info->enable_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400308 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 goto unlock_and_exit;
310 }
311
Len Brown4be44fc2005-08-05 00:44:28 -0400312 ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
313 "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n",
314 gpe_register_info->base_gpe_number,
315 status_reg, enable_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Robert Moore44f6c012005-04-18 22:49:35 -0400317 /* Check if there is anything active at all in this register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319 enabled_status_byte = (u8) (status_reg & enable_reg);
320 if (!enabled_status_byte) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 /* No active GPEs in this register, move on */
323
324 continue;
325 }
326
327 /* Now look at the individual GPEs in this byte register */
328
329 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 /* Examine one GPE bit */
332
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300333 if (enabled_status_byte & (1 << j)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 /*
335 * Found an active GPE. Dispatch the event to a handler
336 * or method.
337 */
Len Brown4be44fc2005-08-05 00:44:28 -0400338 int_status |=
339 acpi_ev_gpe_dispatch(&gpe_block->
Bob Moore67a119f2008-06-10 13:42:13 +0800340 event_info[((acpi_size) i * ACPI_GPE_REGISTER_WIDTH) + j], j + gpe_register_info->base_gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342 }
343 }
344
345 gpe_block = gpe_block->next;
346 }
347
Len Brown4be44fc2005-08-05 00:44:28 -0400348 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Len Brown4be44fc2005-08-05 00:44:28 -0400350 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 return (int_status);
352}
353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354/*******************************************************************************
355 *
356 * FUNCTION: acpi_ev_asynch_execute_gpe_method
357 *
358 * PARAMETERS: Context (gpe_event_info) - Info for this GPE
359 *
360 * RETURN: None
361 *
Bob Moore41195322006-05-26 16:36:00 -0400362 * DESCRIPTION: Perform the actual execution of a GPE control method. This
363 * function is called from an invocation of acpi_os_execute and
364 * therefore does NOT execute at interrupt level - so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 * the control method itself is not executed in the context of
366 * an interrupt handler.
367 *
368 ******************************************************************************/
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300369static void acpi_ev_asynch_enable_gpe(void *context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Len Brown4be44fc2005-08-05 00:44:28 -0400371static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372{
Len Brown4be44fc2005-08-05 00:44:28 -0400373 struct acpi_gpe_event_info *gpe_event_info = (void *)context;
Len Brown4be44fc2005-08-05 00:44:28 -0400374 acpi_status status;
375 struct acpi_gpe_event_info local_gpe_event_info;
Bob Moore41195322006-05-26 16:36:00 -0400376 struct acpi_evaluate_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Bob Mooreb229cf92006-04-21 17:15:00 -0400378 ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Len Brown4be44fc2005-08-05 00:44:28 -0400380 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
381 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 return_VOID;
383 }
384
385 /* Must revalidate the gpe_number/gpe_block */
386
Len Brown4be44fc2005-08-05 00:44:28 -0400387 if (!acpi_ev_valid_gpe_event(gpe_event_info)) {
388 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 return_VOID;
390 }
391
392 /* Set the GPE flags for return to enabled state */
393
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100394 (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800397 * Take a snapshot of the GPE info for this level - we copy the info to
398 * prevent a race condition with remove_handler/remove_block.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 */
Len Brown4be44fc2005-08-05 00:44:28 -0400400 ACPI_MEMCPY(&local_gpe_event_info, gpe_event_info,
401 sizeof(struct acpi_gpe_event_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Len Brown4be44fc2005-08-05 00:44:28 -0400403 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
404 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 return_VOID;
406 }
407
408 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800409 * Must check for control method type dispatch one more time to avoid a
410 * race with ev_gpe_install_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 */
Robert Moore44f6c012005-04-18 22:49:35 -0400412 if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400413 ACPI_GPE_DISPATCH_METHOD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Bob Moore41195322006-05-26 16:36:00 -0400415 /* Allocate the evaluation information block */
416
417 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
418 if (!info) {
419 status = AE_NO_MEMORY;
420 } else {
421 /*
422 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx
423 * control method that corresponds to this GPE
424 */
425 info->prefix_node =
426 local_gpe_event_info.dispatch.method_node;
Bob Moore41195322006-05-26 16:36:00 -0400427 info->flags = ACPI_IGNORE_RETURN_VALUE;
428
429 status = acpi_ns_evaluate(info);
430 ACPI_FREE(info);
431 }
432
Len Brown4be44fc2005-08-05 00:44:28 -0400433 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500434 ACPI_EXCEPTION((AE_INFO, status,
Bob Moore2e420052007-02-02 19:48:18 +0300435 "while evaluating GPE method [%4.4s]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500436 acpi_ut_get_node_name
437 (local_gpe_event_info.dispatch.
Bob Moore4c90ece2006-06-08 16:29:00 -0400438 method_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 }
440 }
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300441 /* Defer enabling of GPE until all notify handlers are done */
442 acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_asynch_enable_gpe,
443 gpe_event_info);
444 return_VOID;
445}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300447static void acpi_ev_asynch_enable_gpe(void *context)
448{
449 struct acpi_gpe_event_info *gpe_event_info = context;
450 acpi_status status;
451 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400452 ACPI_GPE_LEVEL_TRIGGERED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800454 * GPE is level-triggered, we clear the GPE status bit after handling
455 * the event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 */
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300457 status = acpi_hw_clear_gpe(gpe_event_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400458 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 return_VOID;
460 }
461 }
462
463 /* Enable this GPE */
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300464 (void)acpi_hw_write_gpe_enable_reg(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 return_VOID;
466}
467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468/*******************************************************************************
469 *
470 * FUNCTION: acpi_ev_gpe_dispatch
471 *
Robert Moore44f6c012005-04-18 22:49:35 -0400472 * PARAMETERS: gpe_event_info - Info for this GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 * gpe_number - Number relative to the parent GPE block
474 *
475 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
476 *
477 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
478 * or method (e.g. _Lxx/_Exx) handler.
479 *
480 * This function executes at interrupt level.
481 *
482 ******************************************************************************/
483
484u32
Len Brown4be44fc2005-08-05 00:44:28 -0400485acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
Len Brown4be44fc2005-08-05 00:44:28 -0400487 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Bob Mooreb229cf92006-04-21 17:15:00 -0400489 ACPI_FUNCTION_TRACE(ev_gpe_dispatch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Len Brown5229e872008-02-06 01:26:55 -0500491 acpi_os_gpe_count(gpe_number);
Bob Moorefdffb722007-02-02 19:48:19 +0300492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800494 * If edge-triggered, clear the GPE status bit now. Note that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 * level-triggered events are cleared after the GPE is serviced.
496 */
Robert Moore44f6c012005-04-18 22:49:35 -0400497 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400498 ACPI_GPE_EDGE_TRIGGERED) {
499 status = acpi_hw_clear_gpe(gpe_event_info);
500 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500501 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800502 "Unable to clear GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500503 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400504 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 }
506 }
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 /*
Bob Moorec5a71562007-02-02 19:48:19 +0300509 * Dispatch the GPE to either an installed handler, or the control method
510 * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke
511 * it and do not attempt to run the method. If there is neither a handler
512 * nor a method, we disable this GPE to prevent further such pointless
513 * events from firing.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 */
515 switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {
516 case ACPI_GPE_DISPATCH_HANDLER:
517
518 /*
519 * Invoke the installed handler (at interrupt level)
Bob Moore9f15fc62008-11-12 16:01:56 +0800520 * Ignore return status for now.
521 * TBD: leave GPE disabled on error?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 */
Len Brown4be44fc2005-08-05 00:44:28 -0400523 (void)gpe_event_info->dispatch.handler->address(gpe_event_info->
524 dispatch.
525 handler->
526 context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 /* It is now safe to clear level-triggered events. */
529
Robert Moore44f6c012005-04-18 22:49:35 -0400530 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400531 ACPI_GPE_LEVEL_TRIGGERED) {
532 status = acpi_hw_clear_gpe(gpe_event_info);
533 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500534 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800535 "Unable to clear GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500536 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400537 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 }
539 }
540 break;
541
542 case ACPI_GPE_DISPATCH_METHOD:
543
544 /*
Bob Moorec5a71562007-02-02 19:48:19 +0300545 * Disable the GPE, so it doesn't keep firing before the method has a
546 * chance to run (it runs asynchronously with interrupts enabled).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 */
Len Brown4be44fc2005-08-05 00:44:28 -0400548 status = acpi_ev_disable_gpe(gpe_event_info);
549 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500550 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800551 "Unable to disable GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500552 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400553 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 }
555
556 /*
557 * Execute the method associated with the GPE
558 * NOTE: Level-triggered GPEs are cleared after the method completes.
559 */
Bob Moore958dd242006-05-12 17:12:00 -0400560 status = acpi_os_execute(OSL_GPE_HANDLER,
561 acpi_ev_asynch_execute_gpe_method,
562 gpe_event_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400563 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500564 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800565 "Unable to queue handler for GPE[0x%2X] - event disabled",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500566 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 }
568 break;
569
570 default:
571
572 /* No handler or method to run! */
573
Bob Mooreb8e4d892006-01-27 16:43:00 -0500574 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800575 "No handler or method for GPE[0x%2X], disabling event",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500576 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800579 * Disable the GPE. The GPE will remain disabled until the ACPICA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 * Core Subsystem is restarted, or a handler is installed.
581 */
Len Brown4be44fc2005-08-05 00:44:28 -0400582 status = acpi_ev_disable_gpe(gpe_event_info);
583 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500584 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800585 "Unable to disable GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500586 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400587 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
589 break;
590 }
591
Bob Moore50eca3e2005-09-30 19:03:00 -0400592 return_UINT32(ACPI_INTERRUPT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593}