blob: 2095dfb72bcb3c9fd7a48512c3024d58e09e6c76 [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 Moorefbb7a2d2014-02-08 09:42:25 +08008 * Copyright (C) 2000 - 2014, 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")
Bob Moore33620c52012-02-14 18:14:27 +080051#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
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
Lin Ming5a284cd2010-12-13 13:39:07 +080055static void ACPI_SYSTEM_XFACE acpi_ev_asynch_enable_gpe(void *context);
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/*******************************************************************************
58 *
Rafael J. Wysockia44061a2010-07-01 10:11:45 +080059 * FUNCTION: acpi_ev_update_gpe_enable_mask
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 *
61 * PARAMETERS: gpe_event_info - GPE to update
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 *
63 * RETURN: Status
64 *
Rafael J. Wysockia44061a2010-07-01 10:11:45 +080065 * DESCRIPTION: Updates GPE register enable mask based upon whether there are
66 * runtime references to this GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 *
68 ******************************************************************************/
69
70acpi_status
Rafael J. Wysockia44061a2010-07-01 10:11:45 +080071acpi_ev_update_gpe_enable_mask(struct acpi_gpe_event_info *gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
Len Brown4be44fc2005-08-05 00:44:28 -040073 struct acpi_gpe_register_info *gpe_register_info;
Rafael J. Wysockie4e9a732010-06-08 10:48:26 +020074 u32 register_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Rafael J. Wysockia44061a2010-07-01 10:11:45 +080076 ACPI_FUNCTION_TRACE(ev_update_gpe_enable_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78 gpe_register_info = gpe_event_info->register_info;
79 if (!gpe_register_info) {
Len Brown4be44fc2005-08-05 00:44:28 -040080 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 }
Bob Moored4913dc2009-03-06 10:05:18 +080082
Feng Tang1d94e1e2012-08-17 11:10:02 +080083 register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Rafael J. Wysockia44061a2010-07-01 10:11:45 +080085 /* Clear the run bit up front */
Lin Ming0f849d22010-04-06 14:52:37 +080086
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +010087 ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Rafael J. Wysockia44061a2010-07-01 10:11:45 +080089 /* Set the mask bit 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) {
Lv Zheng1f86e8c2012-10-31 02:25:45 +000092 ACPI_SET_BIT(gpe_register_info->enable_for_run,
93 (u8)register_bit);
Lin Ming0f849d22010-04-06 14:52:37 +080094 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Len Brown4be44fc2005-08-05 00:44:28 -040096 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
Rafael J. Wysocki3bd741b2010-07-01 11:01:12 +080099/*******************************************************************************
100 *
101 * FUNCTION: acpi_ev_enable_gpe
102 *
Lv Zhengf19f1a72014-10-10 10:39:39 +0800103 * PARAMETERS: gpe_event_info - GPE to enable
Rafael J. Wysocki3bd741b2010-07-01 11:01:12 +0800104 *
105 * RETURN: Status
106 *
Lin Mingda503372010-12-13 13:39:37 +0800107 * DESCRIPTION: Clear a GPE of stale events and enable it.
Rafael J. Wysocki3bd741b2010-07-01 11:01:12 +0800108 *
109 ******************************************************************************/
Lv Zhengf19f1a72014-10-10 10:39:39 +0800110
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000111acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
Rafael J. Wysocki3bd741b2010-07-01 11:01:12 +0800112{
113 acpi_status status;
114
115 ACPI_FUNCTION_TRACE(ev_enable_gpe);
116
117 /*
Lin Mingbba63a22010-12-13 13:39:17 +0800118 * We will only allow a GPE to be enabled if it has either an associated
119 * method (_Lxx/_Exx) or a handler, or is using the implicit notify
120 * feature. Otherwise, the GPE will be immediately disabled by
121 * acpi_ev_gpe_dispatch the first time it fires.
Rafael J. Wysocki3bd741b2010-07-01 11:01:12 +0800122 */
Lin Mingbba63a22010-12-13 13:39:17 +0800123 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
124 ACPI_GPE_DISPATCH_NONE) {
Rafael J. Wysocki3bd741b2010-07-01 11:01:12 +0800125 return_ACPI_STATUS(AE_NO_HANDLER);
126 }
127
128 /* Clear the GPE (of stale events) */
Lv Zhengf19f1a72014-10-10 10:39:39 +0800129
Rafael J. Wysocki3bd741b2010-07-01 11:01:12 +0800130 status = acpi_hw_clear_gpe(gpe_event_info);
131 if (ACPI_FAILURE(status)) {
132 return_ACPI_STATUS(status);
133 }
134
135 /* Enable the requested GPE */
Rafael J. Wysocki3bd741b2010-07-01 11:01:12 +0800136
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000137 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE);
Rafael J. Wysocki3bd741b2010-07-01 11:01:12 +0800138 return_ACPI_STATUS(status);
139}
140
Lin Ming0f849d22010-04-06 14:52:37 +0800141/*******************************************************************************
142 *
Lin Ming3a378982010-12-13 13:36:15 +0800143 * FUNCTION: acpi_ev_add_gpe_reference
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200144 *
Lin Mingda503372010-12-13 13:39:37 +0800145 * PARAMETERS: gpe_event_info - Add a reference to this GPE
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200146 *
147 * RETURN: Status
148 *
149 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
150 * hardware-enabled.
151 *
152 ******************************************************************************/
153
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000154acpi_status
155acpi_ev_add_gpe_reference(struct acpi_gpe_event_info *gpe_event_info)
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200156{
157 acpi_status status = AE_OK;
158
Lin Ming3a378982010-12-13 13:36:15 +0800159 ACPI_FUNCTION_TRACE(ev_add_gpe_reference);
160
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200161 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
162 return_ACPI_STATUS(AE_LIMIT);
163 }
164
165 gpe_event_info->runtime_count++;
166 if (gpe_event_info->runtime_count == 1) {
Lin Mingda503372010-12-13 13:39:37 +0800167
168 /* Enable on first reference */
169
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200170 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
171 if (ACPI_SUCCESS(status)) {
172 status = acpi_ev_enable_gpe(gpe_event_info);
173 }
174
175 if (ACPI_FAILURE(status)) {
176 gpe_event_info->runtime_count--;
177 }
178 }
179
180 return_ACPI_STATUS(status);
181}
182
183/*******************************************************************************
184 *
Lin Ming3a378982010-12-13 13:36:15 +0800185 * FUNCTION: acpi_ev_remove_gpe_reference
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200186 *
Lin Mingda503372010-12-13 13:39:37 +0800187 * PARAMETERS: gpe_event_info - Remove a reference to this GPE
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200188 *
189 * RETURN: Status
190 *
191 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
192 * removed, the GPE is hardware-disabled.
193 *
194 ******************************************************************************/
195
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000196acpi_status
197acpi_ev_remove_gpe_reference(struct acpi_gpe_event_info *gpe_event_info)
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200198{
199 acpi_status status = AE_OK;
200
Lin Ming3a378982010-12-13 13:36:15 +0800201 ACPI_FUNCTION_TRACE(ev_remove_gpe_reference);
202
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200203 if (!gpe_event_info->runtime_count) {
204 return_ACPI_STATUS(AE_LIMIT);
205 }
206
207 gpe_event_info->runtime_count--;
208 if (!gpe_event_info->runtime_count) {
Lin Mingda503372010-12-13 13:39:37 +0800209
210 /* Disable on last reference */
211
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200212 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
213 if (ACPI_SUCCESS(status)) {
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000214 status =
215 acpi_hw_low_set_gpe(gpe_event_info,
Lv Zhengf19f1a72014-10-10 10:39:39 +0800216 ACPI_GPE_DISABLE);
Rafael J. Wysocki28f4f8a2010-08-03 23:55:14 +0200217 }
218
219 if (ACPI_FAILURE(status)) {
220 gpe_event_info->runtime_count++;
221 }
222 }
223
224 return_ACPI_STATUS(status);
225}
226
227/*******************************************************************************
228 *
Lin Ming0f849d22010-04-06 14:52:37 +0800229 * FUNCTION: acpi_ev_low_get_gpe_info
230 *
231 * PARAMETERS: gpe_number - Raw GPE number
232 * gpe_block - A GPE info block
233 *
234 * RETURN: A GPE event_info struct. NULL if not a valid GPE (The gpe_number
235 * is not within the specified GPE block)
236 *
237 * DESCRIPTION: Returns the event_info struct associated with this GPE. This is
238 * the low-level implementation of ev_get_gpe_event_info.
239 *
240 ******************************************************************************/
241
242struct acpi_gpe_event_info *acpi_ev_low_get_gpe_info(u32 gpe_number,
243 struct acpi_gpe_block_info
244 *gpe_block)
245{
246 u32 gpe_index;
247
248 /*
249 * Validate that the gpe_number is within the specified gpe_block.
250 * (Two steps)
251 */
252 if (!gpe_block || (gpe_number < gpe_block->block_base_number)) {
253 return (NULL);
254 }
255
256 gpe_index = gpe_number - gpe_block->block_base_number;
257 if (gpe_index >= gpe_block->gpe_count) {
258 return (NULL);
259 }
260
261 return (&gpe_block->event_info[gpe_index]);
262}
263
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265/*******************************************************************************
266 *
267 * FUNCTION: acpi_ev_get_gpe_event_info
268 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800269 * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 * gpe_number - Raw GPE number
271 *
272 * RETURN: A GPE event_info struct. NULL if not a valid GPE
273 *
274 * DESCRIPTION: Returns the event_info struct associated with this GPE.
275 * Validates the gpe_block and the gpe_number
276 *
277 * Should be called only when the GPE lists are semaphore locked
278 * and not subject to change.
279 *
280 ******************************************************************************/
281
Len Brown4be44fc2005-08-05 00:44:28 -0400282struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
283 u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Len Brown4be44fc2005-08-05 00:44:28 -0400285 union acpi_operand_object *obj_desc;
Lin Ming0f849d22010-04-06 14:52:37 +0800286 struct acpi_gpe_event_info *gpe_info;
Bob Moore67a119f2008-06-10 13:42:13 +0800287 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Len Brown4be44fc2005-08-05 00:44:28 -0400289 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Bob Moore186c3072010-04-27 11:32:28 +0800291 /* A NULL gpe_device means use the FADT-defined GPE block(s) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 if (!gpe_device) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 /* Examine GPE Block 0 and 1 (These blocks are permanent) */
296
297 for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) {
Lin Ming0f849d22010-04-06 14:52:37 +0800298 gpe_info = acpi_ev_low_get_gpe_info(gpe_number,
299 acpi_gbl_gpe_fadt_blocks
300 [i]);
301 if (gpe_info) {
302 return (gpe_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
304 }
305
306 /* The gpe_number was not in the range of either FADT GPE block */
307
308 return (NULL);
309 }
310
311 /* A Non-NULL gpe_device means this is a GPE Block Device */
312
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000313 obj_desc =
314 acpi_ns_get_attached_object((struct acpi_namespace_node *)
Len Brownfd350942007-05-09 23:34:35 -0400315 gpe_device);
Len Brown4be44fc2005-08-05 00:44:28 -0400316 if (!obj_desc || !obj_desc->device.gpe_block) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 return (NULL);
318 }
319
Lin Ming0f849d22010-04-06 14:52:37 +0800320 return (acpi_ev_low_get_gpe_info
321 (gpe_number, obj_desc->device.gpe_block));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322}
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324/*******************************************************************************
325 *
326 * FUNCTION: acpi_ev_gpe_detect
327 *
328 * PARAMETERS: gpe_xrupt_list - Interrupt block for this interrupt.
329 * Can have multiple GPE blocks attached.
330 *
331 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
332 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800333 * DESCRIPTION: Detect if any GP events have occurred. This function is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 * executed at interrupt level.
335 *
336 ******************************************************************************/
337
Lv Zhengf19f1a72014-10-10 10:39:39 +0800338u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info *gpe_xrupt_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339{
Len Brown4be44fc2005-08-05 00:44:28 -0400340 acpi_status status;
341 struct acpi_gpe_block_info *gpe_block;
Bob Moore08978312005-10-21 00:00:00 -0400342 struct acpi_gpe_register_info *gpe_register_info;
343 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
344 u8 enabled_status_byte;
345 u32 status_reg;
346 u32 enable_reg;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500347 acpi_cpu_flags flags;
Bob Moore67a119f2008-06-10 13:42:13 +0800348 u32 i;
349 u32 j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Bob Mooreb229cf92006-04-21 17:15:00 -0400351 ACPI_FUNCTION_NAME(ev_gpe_detect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 /* Check for the case where there are no GPEs */
354
355 if (!gpe_xrupt_list) {
356 return (int_status);
357 }
358
Bob Moore967440e32006-06-23 17:04:00 -0400359 /*
360 * We need to obtain the GPE lock for both the data structs and registers
Bob Moore9f15fc62008-11-12 16:01:56 +0800361 * Note: Not necessary to obtain the hardware lock, since the GPE
362 * registers are owned by the gpe_lock.
Bob Moore967440e32006-06-23 17:04:00 -0400363 */
Len Brown4be44fc2005-08-05 00:44:28 -0400364 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Bob Moore4c90ece2006-06-08 16:29:00 -0400365
366 /* Examine all GPE blocks attached to this interrupt level */
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 gpe_block = gpe_xrupt_list->gpe_block_list_head;
369 while (gpe_block) {
370 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800371 * Read all of the 8-bit GPE status and enable registers in this GPE
372 * block, saving all of them. Find all currently active GP events.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 */
374 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 /* Get the next status/enable pair */
377
378 gpe_register_info = &gpe_block->register_info[i];
379
Lin Ming6dfad332011-02-14 15:29:34 +0800380 /*
381 * Optimization: If there are no GPEs enabled within this
382 * register, we can safely ignore the entire register.
383 */
384 if (!(gpe_register_info->enable_for_run |
385 gpe_register_info->enable_for_wake)) {
Bob Mooree1154eb2012-08-17 10:55:14 +0800386 ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
Bob Moore7505da42014-04-30 10:06:15 +0800387 "Ignore disabled registers for GPE %02X-%02X: "
Bob Mooree1154eb2012-08-17 10:55:14 +0800388 "RunEnable=%02X, WakeEnable=%02X\n",
389 gpe_register_info->
390 base_gpe_number,
391 gpe_register_info->
392 base_gpe_number +
393 (ACPI_GPE_REGISTER_WIDTH - 1),
394 gpe_register_info->
395 enable_for_run,
396 gpe_register_info->
397 enable_for_wake));
Lin Ming6dfad332011-02-14 15:29:34 +0800398 continue;
399 }
400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 /* Read the Status Register */
402
Len Brown4be44fc2005-08-05 00:44:28 -0400403 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800404 acpi_hw_read(&status_reg,
405 &gpe_register_info->status_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400406 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 goto unlock_and_exit;
408 }
409
410 /* Read the Enable Register */
411
Len Brown4be44fc2005-08-05 00:44:28 -0400412 status =
Bob Moorec6b57742009-06-24 09:44:06 +0800413 acpi_hw_read(&enable_reg,
414 &gpe_register_info->enable_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400415 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 goto unlock_and_exit;
417 }
418
Len Brown4be44fc2005-08-05 00:44:28 -0400419 ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
Bob Moore7505da42014-04-30 10:06:15 +0800420 "Read registers for GPE %02X-%02X: Status=%02X, Enable=%02X, "
Bob Mooree1154eb2012-08-17 10:55:14 +0800421 "RunEnable=%02X, WakeEnable=%02X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400422 gpe_register_info->base_gpe_number,
Bob Mooree1154eb2012-08-17 10:55:14 +0800423 gpe_register_info->base_gpe_number +
424 (ACPI_GPE_REGISTER_WIDTH - 1),
425 status_reg, enable_reg,
426 gpe_register_info->enable_for_run,
427 gpe_register_info->enable_for_wake));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Robert Moore44f6c012005-04-18 22:49:35 -0400429 /* Check if there is anything active at all in this register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Lv Zhengf19f1a72014-10-10 10:39:39 +0800431 enabled_status_byte = (u8)(status_reg & enable_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 if (!enabled_status_byte) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 /* No active GPEs in this register, move on */
435
436 continue;
437 }
438
439 /* Now look at the individual GPEs in this byte register */
440
441 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 /* Examine one GPE bit */
444
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300445 if (enabled_status_byte & (1 << j)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 /*
447 * Found an active GPE. Dispatch the event to a handler
448 * or method.
449 */
Len Brown4be44fc2005-08-05 00:44:28 -0400450 int_status |=
Lin Ming8b6cd8a2010-12-13 13:38:46 +0800451 acpi_ev_gpe_dispatch(gpe_block->
452 node,
453 &gpe_block->
Lv Zhengf19f1a72014-10-10 10:39:39 +0800454 event_info[((acpi_size) i * ACPI_GPE_REGISTER_WIDTH) + j], j + gpe_register_info->base_gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
456 }
457 }
458
459 gpe_block = gpe_block->next;
460 }
461
Lv Zheng10622bf2013-10-29 09:30:02 +0800462unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Len Brown4be44fc2005-08-05 00:44:28 -0400464 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 return (int_status);
466}
467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468/*******************************************************************************
469 *
470 * FUNCTION: acpi_ev_asynch_execute_gpe_method
471 *
472 * PARAMETERS: Context (gpe_event_info) - Info for this GPE
473 *
474 * RETURN: None
475 *
Bob Moore41195322006-05-26 16:36:00 -0400476 * DESCRIPTION: Perform the actual execution of a GPE control method. This
477 * function is called from an invocation of acpi_os_execute and
478 * therefore does NOT execute at interrupt level - so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 * the control method itself is not executed in the context of
480 * an interrupt handler.
481 *
482 ******************************************************************************/
483
Len Brown4be44fc2005-08-05 00:44:28 -0400484static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
Lin Ming5a284cd2010-12-13 13:39:07 +0800486 struct acpi_gpe_event_info *gpe_event_info = context;
Len Brown4be44fc2005-08-05 00:44:28 -0400487 acpi_status status;
Lin Ming5a284cd2010-12-13 13:39:07 +0800488 struct acpi_gpe_event_info *local_gpe_event_info;
Bob Moore41195322006-05-26 16:36:00 -0400489 struct acpi_evaluate_info *info;
Bob Moore5816b342012-06-29 10:04:17 +0800490 struct acpi_gpe_notify_info *notify;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Bob Mooreb229cf92006-04-21 17:15:00 -0400492 ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Lin Ming5a284cd2010-12-13 13:39:07 +0800494 /* Allocate a local GPE block */
495
496 local_gpe_event_info =
497 ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_event_info));
498 if (!local_gpe_event_info) {
499 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, "while handling a GPE"));
500 return_VOID;
501 }
502
Len Brown4be44fc2005-08-05 00:44:28 -0400503 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
504 if (ACPI_FAILURE(status)) {
Jesper Juhlbe33b762011-01-16 20:37:52 +0100505 ACPI_FREE(local_gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 return_VOID;
507 }
508
509 /* Must revalidate the gpe_number/gpe_block */
510
Len Brown4be44fc2005-08-05 00:44:28 -0400511 if (!acpi_ev_valid_gpe_event(gpe_event_info)) {
512 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Jesper Juhlbe33b762011-01-16 20:37:52 +0100513 ACPI_FREE(local_gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 return_VOID;
515 }
516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800518 * Take a snapshot of the GPE info for this level - we copy the info to
519 * prevent a race condition with remove_handler/remove_block.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 */
Lin Ming5a284cd2010-12-13 13:39:07 +0800521 ACPI_MEMCPY(local_gpe_event_info, gpe_event_info,
Len Brown4be44fc2005-08-05 00:44:28 -0400522 sizeof(struct acpi_gpe_event_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Len Brown4be44fc2005-08-05 00:44:28 -0400524 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
525 if (ACPI_FAILURE(status)) {
Lv Zhengab3b2482013-10-29 09:29:40 +0800526 ACPI_FREE(local_gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 return_VOID;
528 }
529
Lin Mingbba63a22010-12-13 13:39:17 +0800530 /* Do the correct dispatch - normal method or implicit notify */
531
532 switch (local_gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {
533 case ACPI_GPE_DISPATCH_NOTIFY:
Lin Mingbba63a22010-12-13 13:39:17 +0800534 /*
535 * Implicit notify.
536 * Dispatch a DEVICE_WAKE notify to the appropriate handler.
537 * NOTE: the request is queued for execution after this method
538 * completes. The notify handlers are NOT invoked synchronously
539 * from this thread -- because handlers may in turn run other
540 * control methods.
Bob Moore5816b342012-06-29 10:04:17 +0800541 *
542 * June 2012: Expand implicit notify mechanism to support
543 * notifies on multiple device objects.
Lin Mingbba63a22010-12-13 13:39:17 +0800544 */
Bob Moore5816b342012-06-29 10:04:17 +0800545 notify = local_gpe_event_info->dispatch.notify_list;
546 while (ACPI_SUCCESS(status) && notify) {
547 status =
548 acpi_ev_queue_notify_request(notify->device_node,
549 ACPI_NOTIFY_DEVICE_WAKE);
Rafael J. Wysocki981858b2011-02-24 19:59:21 +0100550
Bob Moore5816b342012-06-29 10:04:17 +0800551 notify = notify->next;
Rafael J. Wysocki981858b2011-02-24 19:59:21 +0100552 }
553
Lin Mingbba63a22010-12-13 13:39:17 +0800554 break;
555
556 case ACPI_GPE_DISPATCH_METHOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
Bob Moore41195322006-05-26 16:36:00 -0400558 /* Allocate the evaluation information block */
559
560 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
561 if (!info) {
562 status = AE_NO_MEMORY;
563 } else {
564 /*
Lv Zheng75c80442012-12-19 05:36:49 +0000565 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the
566 * _Lxx/_Exx control method that corresponds to this GPE
Bob Moore41195322006-05-26 16:36:00 -0400567 */
568 info->prefix_node =
Lin Ming5a284cd2010-12-13 13:39:07 +0800569 local_gpe_event_info->dispatch.method_node;
Bob Moore41195322006-05-26 16:36:00 -0400570 info->flags = ACPI_IGNORE_RETURN_VALUE;
571
572 status = acpi_ns_evaluate(info);
573 ACPI_FREE(info);
574 }
575
Len Brown4be44fc2005-08-05 00:44:28 -0400576 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500577 ACPI_EXCEPTION((AE_INFO, status,
Bob Moore2e420052007-02-02 19:48:18 +0300578 "while evaluating GPE method [%4.4s]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500579 acpi_ut_get_node_name
Lin Ming5a284cd2010-12-13 13:39:07 +0800580 (local_gpe_event_info->dispatch.
Bob Moore4c90ece2006-06-08 16:29:00 -0400581 method_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 }
Lin Mingbba63a22010-12-13 13:39:17 +0800583 break;
584
585 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000586
587 return_VOID; /* Should never happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
Lin Ming5a284cd2010-12-13 13:39:07 +0800589
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300590 /* Defer enabling of GPE until all notify handlers are done */
Lin Ming5a284cd2010-12-13 13:39:07 +0800591
592 status = acpi_os_execute(OSL_NOTIFY_HANDLER,
593 acpi_ev_asynch_enable_gpe,
594 local_gpe_event_info);
595 if (ACPI_FAILURE(status)) {
596 ACPI_FREE(local_gpe_event_info);
597 }
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300598 return_VOID;
599}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Lin Mingbba63a22010-12-13 13:39:17 +0800601
Lin Ming5a284cd2010-12-13 13:39:07 +0800602/*******************************************************************************
603 *
604 * FUNCTION: acpi_ev_asynch_enable_gpe
605 *
606 * PARAMETERS: Context (gpe_event_info) - Info for this GPE
607 * Callback from acpi_os_execute
608 *
609 * RETURN: None
610 *
611 * DESCRIPTION: Asynchronous clear/enable for GPE. This allows the GPE to
Lin Mingbba63a22010-12-13 13:39:17 +0800612 * complete (i.e., finish execution of Notify)
Lin Ming5a284cd2010-12-13 13:39:07 +0800613 *
614 ******************************************************************************/
615
616static void ACPI_SYSTEM_XFACE acpi_ev_asynch_enable_gpe(void *context)
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300617{
618 struct acpi_gpe_event_info *gpe_event_info = context;
Lin Mingbba63a22010-12-13 13:39:17 +0800619
620 (void)acpi_ev_finish_gpe(gpe_event_info);
621
622 ACPI_FREE(gpe_event_info);
623 return;
624}
625
626
627/*******************************************************************************
628 *
629 * FUNCTION: acpi_ev_finish_gpe
630 *
631 * PARAMETERS: gpe_event_info - Info for this GPE
632 *
633 * RETURN: Status
634 *
635 * DESCRIPTION: Clear/Enable a GPE. Common code that is used after execution
636 * of a GPE method or a synchronous or asynchronous GPE handler.
637 *
638 ******************************************************************************/
639
Lv Zhengf19f1a72014-10-10 10:39:39 +0800640acpi_status acpi_ev_finish_gpe(struct acpi_gpe_event_info * gpe_event_info)
Lin Mingbba63a22010-12-13 13:39:17 +0800641{
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300642 acpi_status status;
Lin Ming5a284cd2010-12-13 13:39:07 +0800643
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300644 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400645 ACPI_GPE_LEVEL_TRIGGERED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 /*
Lin Mingbba63a22010-12-13 13:39:17 +0800647 * GPE is level-triggered, we clear the GPE status bit after
648 * handling the event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 */
Alexey Starikovskiy17bc54e2007-11-13 13:05:45 +0300650 status = acpi_hw_clear_gpe(gpe_event_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400651 if (ACPI_FAILURE(status)) {
Lin Mingbba63a22010-12-13 13:39:17 +0800652 return (status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 }
654 }
655
Bob Moorede5668f2010-07-06 10:30:37 +0800656 /*
Lin Mingbba63a22010-12-13 13:39:17 +0800657 * Enable this GPE, conditionally. This means that the GPE will
658 * only be physically enabled if the enable_for_run bit is set
659 * in the event_info.
Bob Moorede5668f2010-07-06 10:30:37 +0800660 */
Lin Ming3a378982010-12-13 13:36:15 +0800661 (void)acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_CONDITIONAL_ENABLE);
Lin Mingbba63a22010-12-13 13:39:17 +0800662 return (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663}
664
Lin Mingbba63a22010-12-13 13:39:17 +0800665
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666/*******************************************************************************
667 *
668 * FUNCTION: acpi_ev_gpe_dispatch
669 *
Lv Zhengf19f1a72014-10-10 10:39:39 +0800670 * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1
671 * gpe_event_info - Info for this GPE
672 * gpe_number - Number relative to the parent GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 *
674 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
675 *
676 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
677 * or method (e.g. _Lxx/_Exx) handler.
678 *
679 * This function executes at interrupt level.
680 *
681 ******************************************************************************/
682
683u32
Lin Ming8b6cd8a2010-12-13 13:38:46 +0800684acpi_ev_gpe_dispatch(struct acpi_namespace_node *gpe_device,
Lv Zhengf19f1a72014-10-10 10:39:39 +0800685 struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
Len Brown4be44fc2005-08-05 00:44:28 -0400687 acpi_status status;
Lin Mingbba63a22010-12-13 13:39:17 +0800688 u32 return_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
Bob Mooreb229cf92006-04-21 17:15:00 -0400690 ACPI_FUNCTION_TRACE(ev_gpe_dispatch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Lin Minga0fcdb22010-12-13 13:39:26 +0800692 /* Invoke global event handler if present */
693
694 acpi_gpe_count++;
695 if (acpi_gbl_global_event_handler) {
696 acpi_gbl_global_event_handler(ACPI_EVENT_TYPE_GPE, gpe_device,
697 gpe_number,
698 acpi_gbl_global_event_handler_context);
699 }
Bob Moorefdffb722007-02-02 19:48:19 +0300700
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 /*
Lin Mingbba63a22010-12-13 13:39:17 +0800702 * Always disable the GPE so that it does not keep firing before
703 * any asynchronous activity completes (either from the execution
704 * of a GPE method or an asynchronous GPE handler.)
705 *
706 * If there is no handler or method to run, just disable the
707 * GPE and leave it disabled permanently to prevent further such
708 * pointless events from firing.
709 */
710 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
711 if (ACPI_FAILURE(status)) {
712 ACPI_EXCEPTION((AE_INFO, status,
Bob Moore7505da42014-04-30 10:06:15 +0800713 "Unable to disable GPE %02X", gpe_number));
Bob Moorefd1af712013-03-08 09:22:23 +0000714 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Lin Mingbba63a22010-12-13 13:39:17 +0800715 }
716
717 /*
Lv Zheng6ec5e122014-06-15 08:42:31 +0800718 * If edge-triggered, clear the GPE status bit now. Note that
719 * level-triggered events are cleared after the GPE is serviced.
720 */
721 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
722 ACPI_GPE_EDGE_TRIGGERED) {
723 status = acpi_hw_clear_gpe(gpe_event_info);
724 if (ACPI_FAILURE(status)) {
725 ACPI_EXCEPTION((AE_INFO, status,
726 "Unable to clear GPE %02X",
727 gpe_number));
728 (void)acpi_hw_low_set_gpe(gpe_event_info,
729 ACPI_GPE_CONDITIONAL_ENABLE);
730 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
731 }
732 }
733
734 /*
Lin Mingbba63a22010-12-13 13:39:17 +0800735 * Dispatch the GPE to either an installed handler or the control
736 * method associated with this GPE (_Lxx or _Exx). If a handler
737 * exists, we invoke it and do not attempt to run the method.
738 * If there is neither a handler nor a method, leave the GPE
739 * disabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 */
741 switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {
742 case ACPI_GPE_DISPATCH_HANDLER:
743
Lin Mingbba63a22010-12-13 13:39:17 +0800744 /* Invoke the installed handler (at interrupt level) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Lin Mingbba63a22010-12-13 13:39:17 +0800746 return_value =
747 gpe_event_info->dispatch.handler->address(gpe_device,
748 gpe_number,
749 gpe_event_info->
750 dispatch.handler->
751 context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Lin Mingbba63a22010-12-13 13:39:17 +0800753 /* If requested, clear (if level-triggered) and reenable the GPE */
754
755 if (return_value & ACPI_REENABLE_GPE) {
756 (void)acpi_ev_finish_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 }
758 break;
759
760 case ACPI_GPE_DISPATCH_METHOD:
Lin Mingbba63a22010-12-13 13:39:17 +0800761 case ACPI_GPE_DISPATCH_NOTIFY:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 /*
763 * Execute the method associated with the GPE
764 * NOTE: Level-triggered GPEs are cleared after the method completes.
765 */
Bob Moore958dd242006-05-12 17:12:00 -0400766 status = acpi_os_execute(OSL_GPE_HANDLER,
767 acpi_ev_asynch_execute_gpe_method,
768 gpe_event_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400769 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500770 ACPI_EXCEPTION((AE_INFO, status,
Bob Moore7505da42014-04-30 10:06:15 +0800771 "Unable to queue handler for GPE %02X - event disabled",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500772 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 }
774 break;
775
776 default:
Lin Ming0f849d22010-04-06 14:52:37 +0800777 /*
778 * No handler or method to run!
779 * 03/2010: This case should no longer be possible. We will not allow
780 * a GPE to be enabled if it has no handler or method.
781 */
Bob Mooreb8e4d892006-01-27 16:43:00 -0500782 ACPI_ERROR((AE_INFO,
Bob Moore7505da42014-04-30 10:06:15 +0800783 "No handler or method for GPE %02X, disabling event",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500784 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 break;
787 }
788
Bob Moorefd1af712013-03-08 09:22:23 +0000789 return_UINT32(ACPI_INTERRUPT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790}
Bob Moore33620c52012-02-14 18:14:27 +0800791
792#endif /* !ACPI_REDUCED_HARDWARE */