blob: 35933be58cd4fe24c9bd19fed8f3a81d0e387558 [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 Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
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>
45#include <acpi/acevents.h>
46#include <acpi/acnamesp.h>
47
48#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("evgpe")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Robert Moore44f6c012005-04-18 22:49:35 -040051/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040052static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/*******************************************************************************
55 *
56 * FUNCTION: acpi_ev_set_gpe_type
57 *
58 * PARAMETERS: gpe_event_info - GPE to set
59 * Type - New type
60 *
61 * RETURN: Status
62 *
63 * DESCRIPTION: Sets the new type for the GPE (wake, run, or wake/run)
64 *
65 ******************************************************************************/
66
67acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040068acpi_ev_set_gpe_type(struct acpi_gpe_event_info *gpe_event_info, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Len Brown4be44fc2005-08-05 00:44:28 -040070 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Bob Mooreb229cf92006-04-21 17:15:00 -040072 ACPI_FUNCTION_TRACE(ev_set_gpe_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74 /* Validate type and update register enable masks */
75
76 switch (type) {
77 case ACPI_GPE_TYPE_WAKE:
78 case ACPI_GPE_TYPE_RUNTIME:
79 case ACPI_GPE_TYPE_WAKE_RUN:
80 break;
81
82 default:
Len Brown4be44fc2005-08-05 00:44:28 -040083 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 }
85
86 /* Disable the GPE if currently enabled */
87
Len Brown4be44fc2005-08-05 00:44:28 -040088 status = acpi_ev_disable_gpe(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90 /* Type was validated above */
91
Len Brown4be44fc2005-08-05 00:44:28 -040092 gpe_event_info->flags &= ~ACPI_GPE_TYPE_MASK; /* Clear type bits */
93 gpe_event_info->flags |= type; /* Insert type */
94 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097/*******************************************************************************
98 *
99 * FUNCTION: acpi_ev_update_gpe_enable_masks
100 *
101 * PARAMETERS: gpe_event_info - GPE to update
102 * Type - What to do: ACPI_GPE_DISABLE or
103 * ACPI_GPE_ENABLE
104 *
105 * RETURN: Status
106 *
107 * DESCRIPTION: Updates GPE register enable masks based on the GPE type
108 *
109 ******************************************************************************/
110
111acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400112acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
113 u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Len Brown4be44fc2005-08-05 00:44:28 -0400115 struct acpi_gpe_register_info *gpe_register_info;
116 u8 register_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Bob Mooreb229cf92006-04-21 17:15:00 -0400118 ACPI_FUNCTION_TRACE(ev_update_gpe_enable_masks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120 gpe_register_info = gpe_event_info->register_info;
121 if (!gpe_register_info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400122 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 }
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300124 register_bit = (u8)
125 (1 <<
126 (gpe_event_info->gpe_number - gpe_register_info->base_gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 /* 1) Disable case. Simply clear all enable bits */
129
130 if (type == ACPI_GPE_DISABLE) {
Len Brown4be44fc2005-08-05 00:44:28 -0400131 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
132 register_bit);
133 ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
134 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136
137 /* 2) Enable case. Set/Clear the appropriate enable bits */
138
139 switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) {
140 case ACPI_GPE_TYPE_WAKE:
Len Brown4be44fc2005-08-05 00:44:28 -0400141 ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit);
142 ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 break;
144
145 case ACPI_GPE_TYPE_RUNTIME:
Len Brown4be44fc2005-08-05 00:44:28 -0400146 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
147 register_bit);
148 ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 break;
150
151 case ACPI_GPE_TYPE_WAKE_RUN:
Len Brown4be44fc2005-08-05 00:44:28 -0400152 ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit);
153 ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 break;
155
156 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400157 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 }
159
Len Brown4be44fc2005-08-05 00:44:28 -0400160 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163/*******************************************************************************
164 *
165 * FUNCTION: acpi_ev_enable_gpe
166 *
167 * PARAMETERS: gpe_event_info - GPE to enable
168 * write_to_hardware - Enable now, or just mark data structs
169 * (WAKE GPEs should be deferred)
170 *
171 * RETURN: Status
172 *
173 * DESCRIPTION: Enable a GPE based on the GPE type
174 *
175 ******************************************************************************/
176
177acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400178acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info,
179 u8 write_to_hardware)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
Len Brown4be44fc2005-08-05 00:44:28 -0400181 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Bob Mooreb229cf92006-04-21 17:15:00 -0400183 ACPI_FUNCTION_TRACE(ev_enable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 /* Make sure HW enable masks are updated */
186
Len Brown4be44fc2005-08-05 00:44:28 -0400187 status =
188 acpi_ev_update_gpe_enable_masks(gpe_event_info, ACPI_GPE_ENABLE);
189 if (ACPI_FAILURE(status)) {
190 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 }
192
193 /* Mark wake-enabled or HW enable, or both */
194
195 switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) {
196 case ACPI_GPE_TYPE_WAKE:
197
Len Brown4be44fc2005-08-05 00:44:28 -0400198 ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 break;
200
201 case ACPI_GPE_TYPE_WAKE_RUN:
202
Len Brown4be44fc2005-08-05 00:44:28 -0400203 ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205 /*lint -fallthrough */
206
207 case ACPI_GPE_TYPE_RUNTIME:
208
Len Brown4be44fc2005-08-05 00:44:28 -0400209 ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 if (write_to_hardware) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 /* Clear the GPE (of stale events), then enable it */
214
Len Brown4be44fc2005-08-05 00:44:28 -0400215 status = acpi_hw_clear_gpe(gpe_event_info);
216 if (ACPI_FAILURE(status)) {
217 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 }
219
220 /* Enable the requested runtime GPE */
221
Len Brown4be44fc2005-08-05 00:44:28 -0400222 status = acpi_hw_write_gpe_enable_reg(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 }
224 break;
225
226 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400227 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 }
229
Len Brown4be44fc2005-08-05 00:44:28 -0400230 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233/*******************************************************************************
234 *
235 * FUNCTION: acpi_ev_disable_gpe
236 *
237 * PARAMETERS: gpe_event_info - GPE to disable
238 *
239 * RETURN: Status
240 *
241 * DESCRIPTION: Disable a GPE based on the GPE type
242 *
243 ******************************************************************************/
244
Len Brown4be44fc2005-08-05 00:44:28 -0400245acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
Len Brown4be44fc2005-08-05 00:44:28 -0400247 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Bob Mooreb229cf92006-04-21 17:15:00 -0400249 ACPI_FUNCTION_TRACE(ev_disable_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251 if (!(gpe_event_info->flags & ACPI_GPE_ENABLE_MASK)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400252 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 }
254
255 /* Make sure HW enable masks are updated */
256
Len Brown4be44fc2005-08-05 00:44:28 -0400257 status =
258 acpi_ev_update_gpe_enable_masks(gpe_event_info, ACPI_GPE_DISABLE);
259 if (ACPI_FAILURE(status)) {
260 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 }
262
263 /* Mark wake-disabled or HW disable, or both */
264
265 switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) {
266 case ACPI_GPE_TYPE_WAKE:
Len Brown4be44fc2005-08-05 00:44:28 -0400267 ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 break;
269
270 case ACPI_GPE_TYPE_WAKE_RUN:
Len Brown4be44fc2005-08-05 00:44:28 -0400271 ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273 /*lint -fallthrough */
274
275 case ACPI_GPE_TYPE_RUNTIME:
276
277 /* Disable the requested runtime GPE */
278
Len Brown4be44fc2005-08-05 00:44:28 -0400279 ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED);
280 status = acpi_hw_write_gpe_enable_reg(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 break;
282
283 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400284 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 }
286
Len Brown4be44fc2005-08-05 00:44:28 -0400287 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290/*******************************************************************************
291 *
292 * FUNCTION: acpi_ev_get_gpe_event_info
293 *
294 * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1
295 * gpe_number - Raw GPE number
296 *
297 * RETURN: A GPE event_info struct. NULL if not a valid GPE
298 *
299 * DESCRIPTION: Returns the event_info struct associated with this GPE.
300 * Validates the gpe_block and the gpe_number
301 *
302 * Should be called only when the GPE lists are semaphore locked
303 * and not subject to change.
304 *
305 ******************************************************************************/
306
Len Brown4be44fc2005-08-05 00:44:28 -0400307struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
308 u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Len Brown4be44fc2005-08-05 00:44:28 -0400310 union acpi_operand_object *obj_desc;
311 struct acpi_gpe_block_info *gpe_block;
312 acpi_native_uint i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Len Brown4be44fc2005-08-05 00:44:28 -0400314 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 /* A NULL gpe_block means use the FADT-defined GPE block(s) */
317
318 if (!gpe_device) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 /* Examine GPE Block 0 and 1 (These blocks are permanent) */
321
322 for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) {
323 gpe_block = acpi_gbl_gpe_fadt_blocks[i];
324 if (gpe_block) {
Len Brown4be44fc2005-08-05 00:44:28 -0400325 if ((gpe_number >= gpe_block->block_base_number)
326 && (gpe_number <
327 gpe_block->block_base_number +
328 (gpe_block->register_count * 8))) {
329 return (&gpe_block->
330 event_info[gpe_number -
331 gpe_block->
332 block_base_number]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 }
334 }
335 }
336
337 /* The gpe_number was not in the range of either FADT GPE block */
338
339 return (NULL);
340 }
341
342 /* A Non-NULL gpe_device means this is a GPE Block Device */
343
Len Brown4be44fc2005-08-05 00:44:28 -0400344 obj_desc =
345 acpi_ns_get_attached_object((struct acpi_namespace_node *)
346 gpe_device);
347 if (!obj_desc || !obj_desc->device.gpe_block) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 return (NULL);
349 }
350
351 gpe_block = obj_desc->device.gpe_block;
352
353 if ((gpe_number >= gpe_block->block_base_number) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400354 (gpe_number <
355 gpe_block->block_base_number + (gpe_block->register_count * 8))) {
356 return (&gpe_block->
357 event_info[gpe_number - gpe_block->block_base_number]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 }
359
360 return (NULL);
361}
362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363/*******************************************************************************
364 *
365 * FUNCTION: acpi_ev_gpe_detect
366 *
367 * PARAMETERS: gpe_xrupt_list - Interrupt block for this interrupt.
368 * Can have multiple GPE blocks attached.
369 *
370 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
371 *
372 * DESCRIPTION: Detect if any GP events have occurred. This function is
373 * executed at interrupt level.
374 *
375 ******************************************************************************/
376
Len Brown4be44fc2005-08-05 00:44:28 -0400377u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
Len Brown4be44fc2005-08-05 00:44:28 -0400379 acpi_status status;
380 struct acpi_gpe_block_info *gpe_block;
Bob Moore08978312005-10-21 00:00:00 -0400381 struct acpi_gpe_register_info *gpe_register_info;
382 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
383 u8 enabled_status_byte;
384 u32 status_reg;
385 u32 enable_reg;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500386 acpi_cpu_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400387 acpi_native_uint i;
388 acpi_native_uint j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Bob Mooreb229cf92006-04-21 17:15:00 -0400390 ACPI_FUNCTION_NAME(ev_gpe_detect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 /* Check for the case where there are no GPEs */
393
394 if (!gpe_xrupt_list) {
395 return (int_status);
396 }
397
Bob Moore967440e32006-06-23 17:04:00 -0400398 /*
399 * We need to obtain the GPE lock for both the data structs and registers
400 * Note: Not necessary to obtain the hardware lock, since the GPE registers
401 * are owned by the gpe_lock.
402 */
Len Brown4be44fc2005-08-05 00:44:28 -0400403 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Bob Moore4c90ece2006-06-08 16:29:00 -0400404
405 /* Examine all GPE blocks attached to this interrupt level */
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 gpe_block = gpe_xrupt_list->gpe_block_list_head;
408 while (gpe_block) {
409 /*
410 * Read all of the 8-bit GPE status and enable registers
411 * in this GPE block, saving all of them.
412 * Find all currently active GP events.
413 */
414 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 /* Get the next status/enable pair */
417
418 gpe_register_info = &gpe_block->register_info[i];
419
420 /* Read the Status Register */
421
Len Brown4be44fc2005-08-05 00:44:28 -0400422 status =
423 acpi_hw_low_level_read(ACPI_GPE_REGISTER_WIDTH,
424 &status_reg,
425 &gpe_register_info->
426 status_address);
427 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 goto unlock_and_exit;
429 }
430
431 /* Read the Enable Register */
432
Len Brown4be44fc2005-08-05 00:44:28 -0400433 status =
434 acpi_hw_low_level_read(ACPI_GPE_REGISTER_WIDTH,
435 &enable_reg,
436 &gpe_register_info->
437 enable_address);
438 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 goto unlock_and_exit;
440 }
441
Len Brown4be44fc2005-08-05 00:44:28 -0400442 ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
443 "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n",
444 gpe_register_info->base_gpe_number,
445 status_reg, enable_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Robert Moore44f6c012005-04-18 22:49:35 -0400447 /* Check if there is anything active at all in this register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 enabled_status_byte = (u8) (status_reg & enable_reg);
450 if (!enabled_status_byte) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 /* No active GPEs in this register, move on */
453
454 continue;
455 }
456
457 /* Now look at the individual GPEs in this byte register */
458
459 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 /* Examine one GPE bit */
462
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300463 if (enabled_status_byte & (1 << j)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 /*
465 * Found an active GPE. Dispatch the event to a handler
466 * or method.
467 */
Len Brown4be44fc2005-08-05 00:44:28 -0400468 int_status |=
469 acpi_ev_gpe_dispatch(&gpe_block->
470 event_info[(i *
471 ACPI_GPE_REGISTER_WIDTH)
472 +
473 j],
474 (u32) j +
475 gpe_register_info->
476 base_gpe_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 }
478 }
479 }
480
481 gpe_block = gpe_block->next;
482 }
483
Len Brown4be44fc2005-08-05 00:44:28 -0400484 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Len Brown4be44fc2005-08-05 00:44:28 -0400486 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 return (int_status);
488}
489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490/*******************************************************************************
491 *
492 * FUNCTION: acpi_ev_asynch_execute_gpe_method
493 *
494 * PARAMETERS: Context (gpe_event_info) - Info for this GPE
495 *
496 * RETURN: None
497 *
Bob Moore41195322006-05-26 16:36:00 -0400498 * DESCRIPTION: Perform the actual execution of a GPE control method. This
499 * function is called from an invocation of acpi_os_execute and
500 * therefore does NOT execute at interrupt level - so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 * the control method itself is not executed in the context of
502 * an interrupt handler.
503 *
504 ******************************************************************************/
505
Len Brown4be44fc2005-08-05 00:44:28 -0400506static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
Len Brown4be44fc2005-08-05 00:44:28 -0400508 struct acpi_gpe_event_info *gpe_event_info = (void *)context;
Len Brown4be44fc2005-08-05 00:44:28 -0400509 acpi_status status;
510 struct acpi_gpe_event_info local_gpe_event_info;
Bob Moore41195322006-05-26 16:36:00 -0400511 struct acpi_evaluate_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Bob Mooreb229cf92006-04-21 17:15:00 -0400513 ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Len Brown4be44fc2005-08-05 00:44:28 -0400515 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
516 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 return_VOID;
518 }
519
520 /* Must revalidate the gpe_number/gpe_block */
521
Len Brown4be44fc2005-08-05 00:44:28 -0400522 if (!acpi_ev_valid_gpe_event(gpe_event_info)) {
523 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 return_VOID;
525 }
526
527 /* Set the GPE flags for return to enabled state */
528
Len Brown4be44fc2005-08-05 00:44:28 -0400529 (void)acpi_ev_enable_gpe(gpe_event_info, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 /*
532 * Take a snapshot of the GPE info for this level - we copy the
533 * info to prevent a race condition with remove_handler/remove_block.
534 */
Len Brown4be44fc2005-08-05 00:44:28 -0400535 ACPI_MEMCPY(&local_gpe_event_info, gpe_event_info,
536 sizeof(struct acpi_gpe_event_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Len Brown4be44fc2005-08-05 00:44:28 -0400538 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
539 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 return_VOID;
541 }
542
543 /*
544 * Must check for control method type dispatch one more
545 * time to avoid race with ev_gpe_install_handler
546 */
Robert Moore44f6c012005-04-18 22:49:35 -0400547 if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400548 ACPI_GPE_DISPATCH_METHOD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Bob Moore41195322006-05-26 16:36:00 -0400550 /* Allocate the evaluation information block */
551
552 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
553 if (!info) {
554 status = AE_NO_MEMORY;
555 } else {
556 /*
557 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx
558 * control method that corresponds to this GPE
559 */
560 info->prefix_node =
561 local_gpe_event_info.dispatch.method_node;
562 info->parameters =
563 ACPI_CAST_PTR(union acpi_operand_object *,
564 gpe_event_info);
565 info->parameter_type = ACPI_PARAM_GPE;
566 info->flags = ACPI_IGNORE_RETURN_VALUE;
567
568 status = acpi_ns_evaluate(info);
569 ACPI_FREE(info);
570 }
571
Len Brown4be44fc2005-08-05 00:44:28 -0400572 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500573 ACPI_EXCEPTION((AE_INFO, status,
Bob Moore2e420052007-02-02 19:48:18 +0300574 "while evaluating GPE method [%4.4s]",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500575 acpi_ut_get_node_name
576 (local_gpe_event_info.dispatch.
Bob Moore4c90ece2006-06-08 16:29:00 -0400577 method_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 }
579 }
580
Robert Moore44f6c012005-04-18 22:49:35 -0400581 if ((local_gpe_event_info.flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400582 ACPI_GPE_LEVEL_TRIGGERED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 /*
584 * GPE is level-triggered, we clear the GPE status bit after
585 * handling the event.
586 */
Len Brown4be44fc2005-08-05 00:44:28 -0400587 status = acpi_hw_clear_gpe(&local_gpe_event_info);
588 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 return_VOID;
590 }
591 }
592
593 /* Enable this GPE */
594
Len Brown4be44fc2005-08-05 00:44:28 -0400595 (void)acpi_hw_write_gpe_enable_reg(&local_gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 return_VOID;
597}
598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599/*******************************************************************************
600 *
601 * FUNCTION: acpi_ev_gpe_dispatch
602 *
Robert Moore44f6c012005-04-18 22:49:35 -0400603 * PARAMETERS: gpe_event_info - Info for this GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 * gpe_number - Number relative to the parent GPE block
605 *
606 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
607 *
608 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
609 * or method (e.g. _Lxx/_Exx) handler.
610 *
611 * This function executes at interrupt level.
612 *
613 ******************************************************************************/
614
615u32
Len Brown4be44fc2005-08-05 00:44:28 -0400616acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
Len Brown4be44fc2005-08-05 00:44:28 -0400618 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Bob Mooreb229cf92006-04-21 17:15:00 -0400620 ACPI_FUNCTION_TRACE(ev_gpe_dispatch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Bob Moorefdffb722007-02-02 19:48:19 +0300622 acpi_gpe_count++;
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 /*
625 * If edge-triggered, clear the GPE status bit now. Note that
626 * level-triggered events are cleared after the GPE is serviced.
627 */
Robert Moore44f6c012005-04-18 22:49:35 -0400628 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400629 ACPI_GPE_EDGE_TRIGGERED) {
630 status = acpi_hw_clear_gpe(gpe_event_info);
631 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500632 ACPI_EXCEPTION((AE_INFO, status,
633 "Unable to clear GPE[%2X]",
634 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400635 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
637 }
638
Bob Moorec5a71562007-02-02 19:48:19 +0300639 if (!acpi_gbl_system_awake_and_running) {
640 /*
641 * We just woke up because of a wake GPE. Disable any further GPEs
642 * until we are fully up and running (Only wake GPEs should be enabled
643 * at this time, but we just brute-force disable them all.)
644 * 1) We must disable this particular wake GPE so it won't fire again
645 * 2) We want to disable all wake GPEs, since we are now awake
646 */
647 (void)acpi_hw_disable_all_gpes();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
649
650 /*
Bob Moorec5a71562007-02-02 19:48:19 +0300651 * Dispatch the GPE to either an installed handler, or the control method
652 * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke
653 * it and do not attempt to run the method. If there is neither a handler
654 * nor a method, we disable this GPE to prevent further such pointless
655 * events from firing.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 */
657 switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {
658 case ACPI_GPE_DISPATCH_HANDLER:
659
660 /*
661 * Invoke the installed handler (at interrupt level)
662 * Ignore return status for now. TBD: leave GPE disabled on error?
663 */
Len Brown4be44fc2005-08-05 00:44:28 -0400664 (void)gpe_event_info->dispatch.handler->address(gpe_event_info->
665 dispatch.
666 handler->
667 context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
669 /* It is now safe to clear level-triggered events. */
670
Robert Moore44f6c012005-04-18 22:49:35 -0400671 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400672 ACPI_GPE_LEVEL_TRIGGERED) {
673 status = acpi_hw_clear_gpe(gpe_event_info);
674 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500675 ACPI_EXCEPTION((AE_INFO, status,
676 "Unable to clear GPE[%2X]",
677 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400678 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 }
680 }
681 break;
682
683 case ACPI_GPE_DISPATCH_METHOD:
684
685 /*
Bob Moorec5a71562007-02-02 19:48:19 +0300686 * Disable the GPE, so it doesn't keep firing before the method has a
687 * chance to run (it runs asynchronously with interrupts enabled).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 */
Len Brown4be44fc2005-08-05 00:44:28 -0400689 status = acpi_ev_disable_gpe(gpe_event_info);
690 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500691 ACPI_EXCEPTION((AE_INFO, status,
692 "Unable to disable GPE[%2X]",
693 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400694 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 }
696
697 /*
698 * Execute the method associated with the GPE
699 * NOTE: Level-triggered GPEs are cleared after the method completes.
700 */
Bob Moore958dd242006-05-12 17:12:00 -0400701 status = acpi_os_execute(OSL_GPE_HANDLER,
702 acpi_ev_asynch_execute_gpe_method,
703 gpe_event_info);
Len Brown4be44fc2005-08-05 00:44:28 -0400704 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500705 ACPI_EXCEPTION((AE_INFO, status,
706 "Unable to queue handler for GPE[%2X] - event disabled",
707 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 }
709 break;
710
711 default:
712
713 /* No handler or method to run! */
714
Bob Mooreb8e4d892006-01-27 16:43:00 -0500715 ACPI_ERROR((AE_INFO,
716 "No handler or method for GPE[%2X], disabling event",
717 gpe_number));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
719 /*
Bob Moorec5a71562007-02-02 19:48:19 +0300720 * Disable the GPE. The GPE will remain disabled until the ACPI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 * Core Subsystem is restarted, or a handler is installed.
722 */
Len Brown4be44fc2005-08-05 00:44:28 -0400723 status = acpi_ev_disable_gpe(gpe_event_info);
724 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500725 ACPI_EXCEPTION((AE_INFO, status,
726 "Unable to disable GPE[%2X]",
727 gpe_number));
Bob Moore50eca3e2005-09-30 19:03:00 -0400728 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 }
730 break;
731 }
732
Bob Moore50eca3e2005-09-30 19:03:00 -0400733 return_UINT32(ACPI_INTERRUPT_HANDLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734}