blob: 0b453467a5a02f2eebcb0cbbf0ce009f444b7495 [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/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, 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
120 /* Mark wake-enabled or HW enable, or both */
121
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100122 if (gpe_event_info->runtime_count) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100123 /* Clear the GPE (of stale events), then enable it */
124 status = acpi_hw_clear_gpe(gpe_event_info);
125 if (ACPI_FAILURE(status))
126 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100128 /* Enable the requested runtime GPE */
129 status = acpi_hw_write_gpe_enable_reg(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131
Len Brown4be44fc2005-08-05 00:44:28 -0400132 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/*******************************************************************************
136 *
137 * FUNCTION: acpi_ev_disable_gpe
138 *
139 * PARAMETERS: gpe_event_info - GPE to disable
140 *
141 * RETURN: Status
142 *
143 * DESCRIPTION: Disable a GPE based on the GPE type
144 *
145 ******************************************************************************/
146
Len Brown4be44fc2005-08-05 00:44:28 -0400147acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
Len Brown4be44fc2005-08-05 00:44:28 -0400149 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Bob Mooreb229cf92006-04-21 17:15:00 -0400151 ACPI_FUNCTION_TRACE(ev_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 /* Make sure HW enable masks are updated */
154
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100155 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
156 if (ACPI_FAILURE(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400157 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Bob Mooree38e8a02008-06-13 08:28:55 +0800159 /*
160 * Even if we don't know the GPE type, make sure that we always
161 * disable it. low_disable_gpe will just clear the enable bit for this
162 * GPE and write it. It will not write out the current GPE enable mask,
163 * since this may inadvertently enable GPEs too early, if a rogue GPE has
164 * come in during ACPICA initialization - possibly as a result of AML or
165 * other code that has enabled the GPE.
166 */
167 status = acpi_hw_low_disable_gpe(gpe_event_info);
168 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171/*******************************************************************************
172 *
173 * FUNCTION: acpi_ev_get_gpe_event_info
174 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800175 * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 * gpe_number - Raw GPE number
177 *
178 * RETURN: A GPE event_info struct. NULL if not a valid GPE
179 *
180 * DESCRIPTION: Returns the event_info struct associated with this GPE.
181 * Validates the gpe_block and the gpe_number
182 *
183 * Should be called only when the GPE lists are semaphore locked
184 * and not subject to change.
185 *
186 ******************************************************************************/
187
Len Brown4be44fc2005-08-05 00:44:28 -0400188struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
189 u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Len Brown4be44fc2005-08-05 00:44:28 -0400191 union acpi_operand_object *obj_desc;
192 struct acpi_gpe_block_info *gpe_block;
Bob Moore67a119f2008-06-10 13:42:13 +0800193 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Len Brown4be44fc2005-08-05 00:44:28 -0400195 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 /* A NULL gpe_block means use the FADT-defined GPE block(s) */
198
199 if (!gpe_device) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 /* Examine GPE Block 0 and 1 (These blocks are permanent) */
202
203 for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) {
204 gpe_block = acpi_gbl_gpe_fadt_blocks[i];
205 if (gpe_block) {
Len Brown4be44fc2005-08-05 00:44:28 -0400206 if ((gpe_number >= gpe_block->block_base_number)
207 && (gpe_number <
208 gpe_block->block_base_number +
209 (gpe_block->register_count * 8))) {
210 return (&gpe_block->
211 event_info[gpe_number -
212 gpe_block->
213 block_base_number]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 }
215 }
216 }
217
218 /* The gpe_number was not in the range of either FADT GPE block */
219
220 return (NULL);
221 }
222
223 /* A Non-NULL gpe_device means this is a GPE Block Device */
224
Len Brownfd350942007-05-09 23:34:35 -0400225 obj_desc = acpi_ns_get_attached_object((struct acpi_namespace_node *)
226 gpe_device);
Len Brown4be44fc2005-08-05 00:44:28 -0400227 if (!obj_desc || !obj_desc->device.gpe_block) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return (NULL);
229 }
230
231 gpe_block = obj_desc->device.gpe_block;
232
233 if ((gpe_number >= gpe_block->block_base_number) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400234 (gpe_number <
235 gpe_block->block_base_number + (gpe_block->register_count * 8))) {
236 return (&gpe_block->
237 event_info[gpe_number - gpe_block->block_base_number]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 }
239
240 return (NULL);
241}
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243/*******************************************************************************
244 *
245 * FUNCTION: acpi_ev_gpe_detect
246 *
247 * PARAMETERS: gpe_xrupt_list - Interrupt block for this interrupt.
248 * Can have multiple GPE blocks attached.
249 *
250 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
251 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800252 * DESCRIPTION: Detect if any GP events have occurred. This function is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 * executed at interrupt level.
254 *
255 ******************************************************************************/
256
Len Brown4be44fc2005-08-05 00:44:28 -0400257u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
Len Brown4be44fc2005-08-05 00:44:28 -0400259 acpi_status status;
260 struct acpi_gpe_block_info *gpe_block;
Bob Moore08978312005-10-21 00:00:00 -0400261 struct acpi_gpe_register_info *gpe_register_info;
262 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
263 u8 enabled_status_byte;
264 u32 status_reg;
265 u32 enable_reg;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500266 acpi_cpu_flags flags;
Bob Moore67a119f2008-06-10 13:42:13 +0800267 u32 i;
268 u32 j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Bob Mooreb229cf92006-04-21 17:15:00 -0400270 ACPI_FUNCTION_NAME(ev_gpe_detect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272 /* Check for the case where there are no GPEs */
273
274 if (!gpe_xrupt_list) {
275 return (int_status);
276 }
277
Bob Moore967440e2006-06-23 17:04:00 -0400278 /*
279 * We need to obtain the GPE lock for both the data structs and registers
Bob Moore9f15fc62008-11-12 16:01:56 +0800280 * Note: Not necessary to obtain the hardware lock, since the GPE
281 * registers are owned by the gpe_lock.
Bob Moore967440e2006-06-23 17:04:00 -0400282 */
Len Brown4be44fc2005-08-05 00:44:28 -0400283 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Bob Moore4c90ece2006-06-08 16:29:00 -0400284
285 /* Examine all GPE blocks attached to this interrupt level */
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 gpe_block = gpe_xrupt_list->gpe_block_list_head;
288 while (gpe_block) {
289 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800290 * Read all of the 8-bit GPE status and enable registers in this GPE
291 * block, saving all of them. Find all currently active GP events.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 */
293 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 /* Get the next status/enable pair */
296
297 gpe_register_info = &gpe_block->register_info[i];
298
299 /* Read the Status Register */
300
Len Brown4be44fc2005-08-05 00:44:28 -0400301 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800302 acpi_hw_read(&status_reg,
303 &gpe_register_info->status_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
308 /* Read the Enable Register */
309
Len Brown4be44fc2005-08-05 00:44:28 -0400310 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800311 acpi_hw_read(&enable_reg,
312 &gpe_register_info->enable_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400313 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 goto unlock_and_exit;
315 }
316
Len Brown4be44fc2005-08-05 00:44:28 -0400317 ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
318 "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n",
319 gpe_register_info->base_gpe_number,
320 status_reg, enable_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Robert Moore44f6c012005-04-18 22:49:35 -0400322 /* Check if there is anything active at all in this register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 enabled_status_byte = (u8) (status_reg & enable_reg);
325 if (!enabled_status_byte) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 /* No active GPEs in this register, move on */
328
329 continue;
330 }
331
332 /* Now look at the individual GPEs in this byte register */
333
334 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 /* Examine one GPE bit */
337
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300338 if (enabled_status_byte & (1 << j)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 /*
340 * Found an active GPE. Dispatch the event to a handler
341 * or method.
342 */
Len Brown4be44fc2005-08-05 00:44:28 -0400343 int_status |=
344 acpi_ev_gpe_dispatch(&gpe_block->
Bob Moore67a119f2008-06-10 13:42:13 +0800345 event_info[((acpi_size) i * ACPI_GPE_REGISTER_WIDTH) + j], j + gpe_register_info->base_gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
347 }
348 }
349
350 gpe_block = gpe_block->next;
351 }
352
Len Brown4be44fc2005-08-05 00:44:28 -0400353 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Len Brown4be44fc2005-08-05 00:44:28 -0400355 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 return (int_status);
357}
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359/*******************************************************************************
360 *
361 * FUNCTION: acpi_ev_asynch_execute_gpe_method
362 *
363 * PARAMETERS: Context (gpe_event_info) - Info for this GPE
364 *
365 * RETURN: None
366 *
Bob Moore41195322006-05-26 16:36:00 -0400367 * DESCRIPTION: Perform the actual execution of a GPE control method. This
368 * function is called from an invocation of acpi_os_execute and
369 * therefore does NOT execute at interrupt level - so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 * the control method itself is not executed in the context of
371 * an interrupt handler.
372 *
373 ******************************************************************************/
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300374static void acpi_ev_asynch_enable_gpe(void *context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Len Brown4be44fc2005-08-05 00:44:28 -0400376static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377{
Len Brown4be44fc2005-08-05 00:44:28 -0400378 struct acpi_gpe_event_info *gpe_event_info = (void *)context;
Len Brown4be44fc2005-08-05 00:44:28 -0400379 acpi_status status;
380 struct acpi_gpe_event_info local_gpe_event_info;
Bob Moore41195322006-05-26 16:36:00 -0400381 struct acpi_evaluate_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Bob Mooreb229cf92006-04-21 17:15:00 -0400383 ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Len Brown4be44fc2005-08-05 00:44:28 -0400385 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
386 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 return_VOID;
388 }
389
390 /* Must revalidate the gpe_number/gpe_block */
391
Len Brown4be44fc2005-08-05 00:44:28 -0400392 if (!acpi_ev_valid_gpe_event(gpe_event_info)) {
393 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 return_VOID;
395 }
396
397 /* Set the GPE flags for return to enabled state */
398
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100399 (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800402 * Take a snapshot of the GPE info for this level - we copy the info to
403 * prevent a race condition with remove_handler/remove_block.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 */
Len Brown4be44fc2005-08-05 00:44:28 -0400405 ACPI_MEMCPY(&local_gpe_event_info, gpe_event_info,
406 sizeof(struct acpi_gpe_event_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Len Brown4be44fc2005-08-05 00:44:28 -0400408 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
409 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 return_VOID;
411 }
412
413 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800414 * Must check for control method type dispatch one more time to avoid a
415 * race with ev_gpe_install_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 */
Robert Moore44f6c012005-04-18 22:49:35 -0400417 if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400418 ACPI_GPE_DISPATCH_METHOD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Bob Moore41195322006-05-26 16:36:00 -0400420 /* Allocate the evaluation information block */
421
422 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
423 if (!info) {
424 status = AE_NO_MEMORY;
425 } else {
426 /*
427 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx
428 * control method that corresponds to this GPE
429 */
430 info->prefix_node =
431 local_gpe_event_info.dispatch.method_node;
Bob Moore41195322006-05-26 16:36:00 -0400432 info->flags = ACPI_IGNORE_RETURN_VALUE;
433
434 status = acpi_ns_evaluate(info);
435 ACPI_FREE(info);
436 }
437
Len Brown4be44fc2005-08-05 00:44:28 -0400438 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500439 ACPI_EXCEPTION((AE_INFO, status,
Bob Moore2e420052007-02-02 19:48:18 +0300440 "while evaluating GPE method [%4.4s]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500441 acpi_ut_get_node_name
442 (local_gpe_event_info.dispatch.
Bob Moore4c90ece2006-06-08 16:29:00 -0400443 method_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 }
445 }
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300446 /* Defer enabling of GPE until all notify handlers are done */
447 acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_asynch_enable_gpe,
448 gpe_event_info);
449 return_VOID;
450}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300452static void acpi_ev_asynch_enable_gpe(void *context)
453{
454 struct acpi_gpe_event_info *gpe_event_info = context;
455 acpi_status status;
456 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400457 ACPI_GPE_LEVEL_TRIGGERED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800459 * GPE is level-triggered, we clear the GPE status bit after handling
460 * the event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 */
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300462 status = acpi_hw_clear_gpe(gpe_event_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400463 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 return_VOID;
465 }
466 }
467
468 /* Enable this GPE */
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300469 (void)acpi_hw_write_gpe_enable_reg(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 return_VOID;
471}
472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473/*******************************************************************************
474 *
475 * FUNCTION: acpi_ev_gpe_dispatch
476 *
Robert Moore44f6c012005-04-18 22:49:35 -0400477 * PARAMETERS: gpe_event_info - Info for this GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 * gpe_number - Number relative to the parent GPE block
479 *
480 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
481 *
482 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
483 * or method (e.g. _Lxx/_Exx) handler.
484 *
485 * This function executes at interrupt level.
486 *
487 ******************************************************************************/
488
489u32
Len Brown4be44fc2005-08-05 00:44:28 -0400490acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
Len Brown4be44fc2005-08-05 00:44:28 -0400492 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Bob Mooreb229cf92006-04-21 17:15:00 -0400494 ACPI_FUNCTION_TRACE(ev_gpe_dispatch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Len Brown5229e872008-02-06 01:26:55 -0500496 acpi_os_gpe_count(gpe_number);
Bob Moorefdffb722007-02-02 19:48:19 +0300497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800499 * If edge-triggered, clear the GPE status bit now. Note that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 * level-triggered events are cleared after the GPE is serviced.
501 */
Robert Moore44f6c012005-04-18 22:49:35 -0400502 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400503 ACPI_GPE_EDGE_TRIGGERED) {
504 status = acpi_hw_clear_gpe(gpe_event_info);
505 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500506 ACPI_EXCEPTION((AE_INFO, status,
507 "Unable to clear GPE[%2X]",
508 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400509 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 }
511 }
512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 /*
Bob Moorec5a71562007-02-02 19:48:19 +0300514 * Dispatch the GPE to either an installed handler, or the control method
515 * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke
516 * it and do not attempt to run the method. If there is neither a handler
517 * nor a method, we disable this GPE to prevent further such pointless
518 * events from firing.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 */
520 switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {
521 case ACPI_GPE_DISPATCH_HANDLER:
522
523 /*
524 * Invoke the installed handler (at interrupt level)
Bob Moore9f15fc62008-11-12 16:01:56 +0800525 * Ignore return status for now.
526 * TBD: leave GPE disabled on error?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 */
Len Brown4be44fc2005-08-05 00:44:28 -0400528 (void)gpe_event_info->dispatch.handler->address(gpe_event_info->
529 dispatch.
530 handler->
531 context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533 /* It is now safe to clear level-triggered events. */
534
Robert Moore44f6c012005-04-18 22:49:35 -0400535 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400536 ACPI_GPE_LEVEL_TRIGGERED) {
537 status = acpi_hw_clear_gpe(gpe_event_info);
538 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500539 ACPI_EXCEPTION((AE_INFO, status,
540 "Unable to clear GPE[%2X]",
541 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400542 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 }
544 }
545 break;
546
547 case ACPI_GPE_DISPATCH_METHOD:
548
549 /*
Bob Moorec5a71562007-02-02 19:48:19 +0300550 * Disable the GPE, so it doesn't keep firing before the method has a
551 * chance to run (it runs asynchronously with interrupts enabled).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 */
Len Brown4be44fc2005-08-05 00:44:28 -0400553 status = acpi_ev_disable_gpe(gpe_event_info);
554 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500555 ACPI_EXCEPTION((AE_INFO, status,
556 "Unable to disable GPE[%2X]",
557 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400558 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 }
560
561 /*
562 * Execute the method associated with the GPE
563 * NOTE: Level-triggered GPEs are cleared after the method completes.
564 */
Bob Moore958dd242006-05-12 17:12:00 -0400565 status = acpi_os_execute(OSL_GPE_HANDLER,
566 acpi_ev_asynch_execute_gpe_method,
567 gpe_event_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400568 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500569 ACPI_EXCEPTION((AE_INFO, status,
570 "Unable to queue handler for GPE[%2X] - event disabled",
571 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 }
573 break;
574
575 default:
576
577 /* No handler or method to run! */
578
Bob Mooreb8e4d892006-01-27 16:43:00 -0500579 ACPI_ERROR((AE_INFO,
580 "No handler or method for GPE[%2X], disabling event",
581 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800584 * Disable the GPE. The GPE will remain disabled until the ACPICA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 * Core Subsystem is restarted, or a handler is installed.
586 */
Len Brown4be44fc2005-08-05 00:44:28 -0400587 status = acpi_ev_disable_gpe(gpe_event_info);
588 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500589 ACPI_EXCEPTION((AE_INFO, status,
590 "Unable to disable GPE[%2X]",
591 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400592 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 }
594 break;
595 }
596
Bob Moore50eca3e2005-09-30 19:03:00 -0400597 return_UINT32(ACPI_INTERRUPT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598}