blob: 57eeb3bde41ea861a8d0cd196f1155bb329276d3 [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
Rafael J. Wysockie4e9a732010-06-08 10:48:26 +020081 register_bit = acpi_hw_gpe_register_bit(gpe_event_info,
82 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/*******************************************************************************
103 *
104 * FUNCTION: acpi_ev_enable_gpe
105 *
106 * PARAMETERS: gpe_event_info - GPE to enable
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 *
108 * RETURN: Status
109 *
Lin Ming0f849d22010-04-06 14:52:37 +0800110 * DESCRIPTION: Hardware-enable a GPE. Always enables the GPE, regardless
111 * of type or number of references.
112 *
113 * Note: The GPE lock should be already acquired when this function is called.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 *
115 ******************************************************************************/
116
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100117acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Len Brown4be44fc2005-08-05 00:44:28 -0400119 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Lin Ming0f849d22010-04-06 14:52:37 +0800121
Bob Mooreb229cf92006-04-21 17:15:00 -0400122 ACPI_FUNCTION_TRACE(ev_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Lin Ming0f849d22010-04-06 14:52:37 +0800124
125 /*
126 * We will only allow a GPE to be enabled if it has either an
127 * associated method (_Lxx/_Exx) or a handler. Otherwise, the
128 * GPE will be immediately disabled by acpi_ev_gpe_dispatch the
129 * first time it fires.
130 */
131 if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)) {
132 return_ACPI_STATUS(AE_NO_HANDLER);
133 }
134
135 /* Ensure the HW enable masks are current */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100137 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
Lin Ming0f849d22010-04-06 14:52:37 +0800138 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400139 return_ACPI_STATUS(status);
Lin Ming0f849d22010-04-06 14:52:37 +0800140 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Lin Ming0f849d22010-04-06 14:52:37 +0800142 /* Clear the GPE (of stale events) */
143
Rafael J. Wysockibf02bd22010-03-16 23:21:55 +0100144 status = acpi_hw_clear_gpe(gpe_event_info);
Lin Ming0f849d22010-04-06 14:52:37 +0800145 if (ACPI_FAILURE(status)) {
Rafael J. Wysockibf02bd22010-03-16 23:21:55 +0100146 return_ACPI_STATUS(status);
Lin Ming0f849d22010-04-06 14:52:37 +0800147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Rafael J. Wysockibf02bd22010-03-16 23:21:55 +0100149 /* Enable the requested GPE */
Lin Ming0f849d22010-04-06 14:52:37 +0800150
Rafael J. Wysockibf02bd22010-03-16 23:21:55 +0100151 status = acpi_hw_write_gpe_enable_reg(gpe_event_info);
152 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155/*******************************************************************************
156 *
157 * FUNCTION: acpi_ev_disable_gpe
158 *
159 * PARAMETERS: gpe_event_info - GPE to disable
160 *
161 * RETURN: Status
162 *
Lin Ming0f849d22010-04-06 14:52:37 +0800163 * DESCRIPTION: Hardware-disable a GPE. Always disables the requested GPE,
164 * regardless of the type or number of references.
165 *
166 * Note: The GPE lock should be already acquired when this function is called.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 *
168 ******************************************************************************/
169
Len Brown4be44fc2005-08-05 00:44:28 -0400170acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Len Brown4be44fc2005-08-05 00:44:28 -0400172 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Bob Mooreb229cf92006-04-21 17:15:00 -0400174 ACPI_FUNCTION_TRACE(ev_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Bob Mooree38e8a02008-06-13 08:28:55 +0800177 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800178 * Note: Always disable the GPE, even if we think that that it is already
179 * disabled. It is possible that the AML or some other code has enabled
180 * the GPE behind our back.
181 */
182
183 /* Ensure the HW enable masks are current */
184
185 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
186 if (ACPI_FAILURE(status)) {
187 return_ACPI_STATUS(status);
188 }
189
190 /*
191 * Always H/W disable this GPE, even if we don't know the GPE type.
192 * Simply clear the enable bit for this particular GPE, but do not
193 * write out the current GPE enable mask since this may inadvertently
194 * enable GPEs too early. An example is a rogue GPE that has arrived
195 * during ACPICA initialization - possibly because AML or other code
196 * has enabled the GPE.
Bob Mooree38e8a02008-06-13 08:28:55 +0800197 */
198 status = acpi_hw_low_disable_gpe(gpe_event_info);
199 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
201
Lin Ming0f849d22010-04-06 14:52:37 +0800202
203/*******************************************************************************
204 *
205 * FUNCTION: acpi_ev_low_get_gpe_info
206 *
207 * PARAMETERS: gpe_number - Raw GPE number
208 * gpe_block - A GPE info block
209 *
210 * RETURN: A GPE event_info struct. NULL if not a valid GPE (The gpe_number
211 * is not within the specified GPE block)
212 *
213 * DESCRIPTION: Returns the event_info struct associated with this GPE. This is
214 * the low-level implementation of ev_get_gpe_event_info.
215 *
216 ******************************************************************************/
217
218struct acpi_gpe_event_info *acpi_ev_low_get_gpe_info(u32 gpe_number,
219 struct acpi_gpe_block_info
220 *gpe_block)
221{
222 u32 gpe_index;
223
224 /*
225 * Validate that the gpe_number is within the specified gpe_block.
226 * (Two steps)
227 */
228 if (!gpe_block || (gpe_number < gpe_block->block_base_number)) {
229 return (NULL);
230 }
231
232 gpe_index = gpe_number - gpe_block->block_base_number;
233 if (gpe_index >= gpe_block->gpe_count) {
234 return (NULL);
235 }
236
237 return (&gpe_block->event_info[gpe_index]);
238}
239
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241/*******************************************************************************
242 *
243 * FUNCTION: acpi_ev_get_gpe_event_info
244 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800245 * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 * gpe_number - Raw GPE number
247 *
248 * RETURN: A GPE event_info struct. NULL if not a valid GPE
249 *
250 * DESCRIPTION: Returns the event_info struct associated with this GPE.
251 * Validates the gpe_block and the gpe_number
252 *
253 * Should be called only when the GPE lists are semaphore locked
254 * and not subject to change.
255 *
256 ******************************************************************************/
257
Len Brown4be44fc2005-08-05 00:44:28 -0400258struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
259 u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Len Brown4be44fc2005-08-05 00:44:28 -0400261 union acpi_operand_object *obj_desc;
Lin Ming0f849d22010-04-06 14:52:37 +0800262 struct acpi_gpe_event_info *gpe_info;
Bob Moore67a119f2008-06-10 13:42:13 +0800263 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Len Brown4be44fc2005-08-05 00:44:28 -0400265 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 /* A NULL gpe_block means use the FADT-defined GPE block(s) */
268
269 if (!gpe_device) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 /* Examine GPE Block 0 and 1 (These blocks are permanent) */
272
273 for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) {
Lin Ming0f849d22010-04-06 14:52:37 +0800274 gpe_info = acpi_ev_low_get_gpe_info(gpe_number,
275 acpi_gbl_gpe_fadt_blocks
276 [i]);
277 if (gpe_info) {
278 return (gpe_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 }
280 }
281
282 /* The gpe_number was not in the range of either FADT GPE block */
283
284 return (NULL);
285 }
286
287 /* A Non-NULL gpe_device means this is a GPE Block Device */
288
Len Brownfd350942007-05-09 23:34:35 -0400289 obj_desc = acpi_ns_get_attached_object((struct acpi_namespace_node *)
290 gpe_device);
Len Brown4be44fc2005-08-05 00:44:28 -0400291 if (!obj_desc || !obj_desc->device.gpe_block) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 return (NULL);
293 }
294
Lin Ming0f849d22010-04-06 14:52:37 +0800295 return (acpi_ev_low_get_gpe_info
296 (gpe_number, obj_desc->device.gpe_block));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299/*******************************************************************************
300 *
301 * FUNCTION: acpi_ev_gpe_detect
302 *
303 * PARAMETERS: gpe_xrupt_list - Interrupt block for this interrupt.
304 * Can have multiple GPE blocks attached.
305 *
306 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
307 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800308 * DESCRIPTION: Detect if any GP events have occurred. This function is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 * executed at interrupt level.
310 *
311 ******************************************************************************/
312
Len Brown4be44fc2005-08-05 00:44:28 -0400313u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
Len Brown4be44fc2005-08-05 00:44:28 -0400315 acpi_status status;
316 struct acpi_gpe_block_info *gpe_block;
Bob Moore08978312005-10-21 00:00:00 -0400317 struct acpi_gpe_register_info *gpe_register_info;
318 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
319 u8 enabled_status_byte;
320 u32 status_reg;
321 u32 enable_reg;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500322 acpi_cpu_flags flags;
Bob Moore67a119f2008-06-10 13:42:13 +0800323 u32 i;
324 u32 j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Bob Mooreb229cf92006-04-21 17:15:00 -0400326 ACPI_FUNCTION_NAME(ev_gpe_detect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 /* Check for the case where there are no GPEs */
329
330 if (!gpe_xrupt_list) {
331 return (int_status);
332 }
333
Bob Moore967440e32006-06-23 17:04:00 -0400334 /*
335 * We need to obtain the GPE lock for both the data structs and registers
Bob Moore9f15fc62008-11-12 16:01:56 +0800336 * Note: Not necessary to obtain the hardware lock, since the GPE
337 * registers are owned by the gpe_lock.
Bob Moore967440e32006-06-23 17:04:00 -0400338 */
Len Brown4be44fc2005-08-05 00:44:28 -0400339 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Bob Moore4c90ece2006-06-08 16:29:00 -0400340
341 /* Examine all GPE blocks attached to this interrupt level */
342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 gpe_block = gpe_xrupt_list->gpe_block_list_head;
344 while (gpe_block) {
345 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800346 * Read all of the 8-bit GPE status and enable registers in this GPE
347 * block, saving all of them. Find all currently active GP events.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 */
349 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 /* Get the next status/enable pair */
352
353 gpe_register_info = &gpe_block->register_info[i];
354
355 /* Read the Status Register */
356
Len Brown4be44fc2005-08-05 00:44:28 -0400357 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800358 acpi_hw_read(&status_reg,
359 &gpe_register_info->status_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400360 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 goto unlock_and_exit;
362 }
363
364 /* Read the Enable Register */
365
Len Brown4be44fc2005-08-05 00:44:28 -0400366 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800367 acpi_hw_read(&enable_reg,
368 &gpe_register_info->enable_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400369 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 goto unlock_and_exit;
371 }
372
Len Brown4be44fc2005-08-05 00:44:28 -0400373 ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
374 "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n",
375 gpe_register_info->base_gpe_number,
376 status_reg, enable_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Robert Moore44f6c012005-04-18 22:49:35 -0400378 /* Check if there is anything active at all in this register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
380 enabled_status_byte = (u8) (status_reg & enable_reg);
381 if (!enabled_status_byte) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400382
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 /* No active GPEs in this register, move on */
384
385 continue;
386 }
387
388 /* Now look at the individual GPEs in this byte register */
389
390 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 /* Examine one GPE bit */
393
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300394 if (enabled_status_byte & (1 << j)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 /*
396 * Found an active GPE. Dispatch the event to a handler
397 * or method.
398 */
Len Brown4be44fc2005-08-05 00:44:28 -0400399 int_status |=
400 acpi_ev_gpe_dispatch(&gpe_block->
Bob Moore67a119f2008-06-10 13:42:13 +0800401 event_info[((acpi_size) i * ACPI_GPE_REGISTER_WIDTH) + j], j + gpe_register_info->base_gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
403 }
404 }
405
406 gpe_block = gpe_block->next;
407 }
408
Len Brown4be44fc2005-08-05 00:44:28 -0400409 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Len Brown4be44fc2005-08-05 00:44:28 -0400411 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 return (int_status);
413}
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415/*******************************************************************************
416 *
417 * FUNCTION: acpi_ev_asynch_execute_gpe_method
418 *
419 * PARAMETERS: Context (gpe_event_info) - Info for this GPE
420 *
421 * RETURN: None
422 *
Bob Moore41195322006-05-26 16:36:00 -0400423 * DESCRIPTION: Perform the actual execution of a GPE control method. This
424 * function is called from an invocation of acpi_os_execute and
425 * therefore does NOT execute at interrupt level - so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 * the control method itself is not executed in the context of
427 * an interrupt handler.
428 *
429 ******************************************************************************/
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300430static void acpi_ev_asynch_enable_gpe(void *context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Len Brown4be44fc2005-08-05 00:44:28 -0400432static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
Len Brown4be44fc2005-08-05 00:44:28 -0400434 struct acpi_gpe_event_info *gpe_event_info = (void *)context;
Len Brown4be44fc2005-08-05 00:44:28 -0400435 acpi_status status;
436 struct acpi_gpe_event_info local_gpe_event_info;
Bob Moore41195322006-05-26 16:36:00 -0400437 struct acpi_evaluate_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Bob Mooreb229cf92006-04-21 17:15:00 -0400439 ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Len Brown4be44fc2005-08-05 00:44:28 -0400441 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
442 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 return_VOID;
444 }
445
446 /* Must revalidate the gpe_number/gpe_block */
447
Len Brown4be44fc2005-08-05 00:44:28 -0400448 if (!acpi_ev_valid_gpe_event(gpe_event_info)) {
449 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 return_VOID;
451 }
452
Lin Ming0f849d22010-04-06 14:52:37 +0800453 /* Update the GPE register masks for return to enabled state */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Rafael J. Wysockicbbc0de2010-02-24 00:52:08 +0100455 (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800458 * Take a snapshot of the GPE info for this level - we copy the info to
459 * prevent a race condition with remove_handler/remove_block.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 */
Len Brown4be44fc2005-08-05 00:44:28 -0400461 ACPI_MEMCPY(&local_gpe_event_info, gpe_event_info,
462 sizeof(struct acpi_gpe_event_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Len Brown4be44fc2005-08-05 00:44:28 -0400464 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
465 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 return_VOID;
467 }
468
469 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800470 * Must check for control method type dispatch one more time to avoid a
471 * race with ev_gpe_install_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 */
Robert Moore44f6c012005-04-18 22:49:35 -0400473 if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400474 ACPI_GPE_DISPATCH_METHOD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Bob Moore41195322006-05-26 16:36:00 -0400476 /* Allocate the evaluation information block */
477
478 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
479 if (!info) {
480 status = AE_NO_MEMORY;
481 } else {
482 /*
483 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx
484 * control method that corresponds to this GPE
485 */
486 info->prefix_node =
487 local_gpe_event_info.dispatch.method_node;
Bob Moore41195322006-05-26 16:36:00 -0400488 info->flags = ACPI_IGNORE_RETURN_VALUE;
489
490 status = acpi_ns_evaluate(info);
491 ACPI_FREE(info);
492 }
493
Len Brown4be44fc2005-08-05 00:44:28 -0400494 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500495 ACPI_EXCEPTION((AE_INFO, status,
Bob Moore2e420052007-02-02 19:48:18 +0300496 "while evaluating GPE method [%4.4s]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500497 acpi_ut_get_node_name
498 (local_gpe_event_info.dispatch.
Bob Moore4c90ece2006-06-08 16:29:00 -0400499 method_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 }
501 }
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300502 /* Defer enabling of GPE until all notify handlers are done */
503 acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_asynch_enable_gpe,
504 gpe_event_info);
505 return_VOID;
506}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300508static void acpi_ev_asynch_enable_gpe(void *context)
509{
510 struct acpi_gpe_event_info *gpe_event_info = context;
511 acpi_status status;
512 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400513 ACPI_GPE_LEVEL_TRIGGERED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800515 * GPE is level-triggered, we clear the GPE status bit after handling
516 * the event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 */
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300518 status = acpi_hw_clear_gpe(gpe_event_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400519 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 return_VOID;
521 }
522 }
523
524 /* Enable this GPE */
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300525 (void)acpi_hw_write_gpe_enable_reg(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 return_VOID;
527}
528
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529/*******************************************************************************
530 *
531 * FUNCTION: acpi_ev_gpe_dispatch
532 *
Robert Moore44f6c012005-04-18 22:49:35 -0400533 * PARAMETERS: gpe_event_info - Info for this GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 * gpe_number - Number relative to the parent GPE block
535 *
536 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
537 *
538 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
539 * or method (e.g. _Lxx/_Exx) handler.
540 *
541 * This function executes at interrupt level.
542 *
543 ******************************************************************************/
544
545u32
Len Brown4be44fc2005-08-05 00:44:28 -0400546acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{
Len Brown4be44fc2005-08-05 00:44:28 -0400548 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Bob Mooreb229cf92006-04-21 17:15:00 -0400550 ACPI_FUNCTION_TRACE(ev_gpe_dispatch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Len Brown5229e872008-02-06 01:26:55 -0500552 acpi_os_gpe_count(gpe_number);
Bob Moorefdffb722007-02-02 19:48:19 +0300553
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800555 * If edge-triggered, clear the GPE status bit now. Note that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 * level-triggered events are cleared after the GPE is serviced.
557 */
Robert Moore44f6c012005-04-18 22:49:35 -0400558 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400559 ACPI_GPE_EDGE_TRIGGERED) {
560 status = acpi_hw_clear_gpe(gpe_event_info);
561 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500562 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800563 "Unable to clear GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500564 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400565 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 }
567 }
568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 /*
Bob Moorec5a71562007-02-02 19:48:19 +0300570 * Dispatch the GPE to either an installed handler, or the control method
571 * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke
572 * it and do not attempt to run the method. If there is neither a handler
573 * nor a method, we disable this GPE to prevent further such pointless
574 * events from firing.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 */
576 switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {
577 case ACPI_GPE_DISPATCH_HANDLER:
578
579 /*
580 * Invoke the installed handler (at interrupt level)
Bob Moore9f15fc62008-11-12 16:01:56 +0800581 * Ignore return status for now.
582 * TBD: leave GPE disabled on error?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 */
Len Brown4be44fc2005-08-05 00:44:28 -0400584 (void)gpe_event_info->dispatch.handler->address(gpe_event_info->
585 dispatch.
586 handler->
587 context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589 /* It is now safe to clear level-triggered events. */
590
Robert Moore44f6c012005-04-18 22:49:35 -0400591 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400592 ACPI_GPE_LEVEL_TRIGGERED) {
593 status = acpi_hw_clear_gpe(gpe_event_info);
594 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500595 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800596 "Unable to clear GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500597 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400598 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
600 }
601 break;
602
603 case ACPI_GPE_DISPATCH_METHOD:
604
605 /*
Bob Moorec5a71562007-02-02 19:48:19 +0300606 * Disable the GPE, so it doesn't keep firing before the method has a
607 * chance to run (it runs asynchronously with interrupts enabled).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 */
Len Brown4be44fc2005-08-05 00:44:28 -0400609 status = acpi_ev_disable_gpe(gpe_event_info);
610 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500611 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800612 "Unable to disable GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500613 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400614 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 }
616
617 /*
618 * Execute the method associated with the GPE
619 * NOTE: Level-triggered GPEs are cleared after the method completes.
620 */
Bob Moore958dd242006-05-12 17:12:00 -0400621 status = acpi_os_execute(OSL_GPE_HANDLER,
622 acpi_ev_asynch_execute_gpe_method,
623 gpe_event_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400624 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500625 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800626 "Unable to queue handler for GPE[0x%2X] - event disabled",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500627 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 }
629 break;
630
631 default:
632
Lin Ming0f849d22010-04-06 14:52:37 +0800633 /*
634 * No handler or method to run!
635 * 03/2010: This case should no longer be possible. We will not allow
636 * a GPE to be enabled if it has no handler or method.
637 */
Bob Mooreb8e4d892006-01-27 16:43:00 -0500638 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800639 "No handler or method for GPE[0x%2X], disabling event",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500640 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
642 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800643 * Disable the GPE. The GPE will remain disabled a handler
644 * is installed or ACPICA is restarted.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 */
Len Brown4be44fc2005-08-05 00:44:28 -0400646 status = acpi_ev_disable_gpe(gpe_event_info);
647 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500648 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooref6a22b02010-03-05 17:56:40 +0800649 "Unable to disable GPE[0x%2X]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500650 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400651 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653 break;
654 }
655
Bob Moore50eca3e2005-09-30 19:03:00 -0400656 return_UINT32(ACPI_INTERRUPT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}