Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: evgpe - General Purpose Event handling and dispatch |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | a8357b0 | 2010-01-22 19:07:36 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2010, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * 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 Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" |
| 46 | #include "acevents.h" |
| 47 | #include "acnamesp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define _COMPONENT ACPI_EVENTS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("evgpe") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | /* Local prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 53 | static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Lin Ming | 5a284cd | 2010-12-13 13:39:07 +0800 | [diff] [blame] | 55 | static void ACPI_SYSTEM_XFACE acpi_ev_asynch_enable_gpe(void *context); |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | /******************************************************************************* |
| 58 | * |
Rafael J. Wysocki | a44061a | 2010-07-01 10:11:45 +0800 | [diff] [blame] | 59 | * FUNCTION: acpi_ev_update_gpe_enable_mask |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | * |
| 61 | * PARAMETERS: gpe_event_info - GPE to update |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * |
| 63 | * RETURN: Status |
| 64 | * |
Rafael J. Wysocki | a44061a | 2010-07-01 10:11:45 +0800 | [diff] [blame] | 65 | * DESCRIPTION: Updates GPE register enable mask based upon whether there are |
| 66 | * runtime references to this GPE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | * |
| 68 | ******************************************************************************/ |
| 69 | |
| 70 | acpi_status |
Rafael J. Wysocki | a44061a | 2010-07-01 10:11:45 +0800 | [diff] [blame] | 71 | acpi_ev_update_gpe_enable_mask(struct acpi_gpe_event_info *gpe_event_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 73 | struct acpi_gpe_register_info *gpe_register_info; |
Rafael J. Wysocki | e4e9a73 | 2010-06-08 10:48:26 +0200 | [diff] [blame] | 74 | u32 register_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Rafael J. Wysocki | a44061a | 2010-07-01 10:11:45 +0800 | [diff] [blame] | 76 | ACPI_FUNCTION_TRACE(ev_update_gpe_enable_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | gpe_register_info = gpe_event_info->register_info; |
| 79 | if (!gpe_register_info) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 82 | |
Lin Ming | b76df67 | 2010-07-01 10:07:17 +0800 | [diff] [blame] | 83 | register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info, |
Rafael J. Wysocki | e4e9a73 | 2010-06-08 10:48:26 +0200 | [diff] [blame] | 84 | gpe_register_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Rafael J. Wysocki | a44061a | 2010-07-01 10:11:45 +0800 | [diff] [blame] | 86 | /* Clear the run bit up front */ |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 87 | |
Rafael J. Wysocki | 9630bdd | 2010-02-17 23:41:07 +0100 | [diff] [blame] | 88 | ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Rafael J. Wysocki | a44061a | 2010-07-01 10:11:45 +0800 | [diff] [blame] | 90 | /* Set the mask bit only if there are references to this GPE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 92 | if (gpe_event_info->runtime_count) { |
Rafael J. Wysocki | a44061a | 2010-07-01 10:11:45 +0800 | [diff] [blame] | 93 | ACPI_SET_BIT(gpe_register_info->enable_for_run, (u8)register_bit); |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 94 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 96 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Rafael J. Wysocki | 3bd741b | 2010-07-01 11:01:12 +0800 | [diff] [blame] | 99 | /******************************************************************************* |
| 100 | * |
| 101 | * FUNCTION: acpi_ev_enable_gpe |
| 102 | * |
| 103 | * PARAMETERS: gpe_event_info - GPE to enable |
| 104 | * |
| 105 | * RETURN: Status |
| 106 | * |
| 107 | * DESCRIPTION: Clear the given GPE from stale events and enable it. |
| 108 | * |
| 109 | ******************************************************************************/ |
| 110 | acpi_status |
| 111 | acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info) |
| 112 | { |
| 113 | acpi_status status; |
| 114 | |
| 115 | ACPI_FUNCTION_TRACE(ev_enable_gpe); |
| 116 | |
| 117 | /* |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 118 | * 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. Wysocki | 3bd741b | 2010-07-01 11:01:12 +0800 | [diff] [blame] | 122 | */ |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 123 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
| 124 | ACPI_GPE_DISPATCH_NONE) { |
Rafael J. Wysocki | 3bd741b | 2010-07-01 11:01:12 +0800 | [diff] [blame] | 125 | return_ACPI_STATUS(AE_NO_HANDLER); |
| 126 | } |
| 127 | |
| 128 | /* Clear the GPE (of stale events) */ |
| 129 | status = acpi_hw_clear_gpe(gpe_event_info); |
| 130 | if (ACPI_FAILURE(status)) { |
| 131 | return_ACPI_STATUS(status); |
| 132 | } |
| 133 | |
| 134 | /* Enable the requested GPE */ |
| 135 | status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE); |
| 136 | |
| 137 | return_ACPI_STATUS(status); |
| 138 | } |
| 139 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 140 | |
| 141 | /******************************************************************************* |
| 142 | * |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 143 | * FUNCTION: acpi_ev_add_gpe_reference |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 144 | * |
| 145 | * PARAMETERS: gpe_event_info - GPE to enable |
| 146 | * |
| 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 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 154 | acpi_status acpi_ev_add_gpe_reference(struct acpi_gpe_event_info *gpe_event_info) |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 155 | { |
| 156 | acpi_status status = AE_OK; |
| 157 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 158 | ACPI_FUNCTION_TRACE(ev_add_gpe_reference); |
| 159 | |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 160 | if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) { |
| 161 | return_ACPI_STATUS(AE_LIMIT); |
| 162 | } |
| 163 | |
| 164 | gpe_event_info->runtime_count++; |
| 165 | if (gpe_event_info->runtime_count == 1) { |
| 166 | status = acpi_ev_update_gpe_enable_mask(gpe_event_info); |
| 167 | if (ACPI_SUCCESS(status)) { |
| 168 | status = acpi_ev_enable_gpe(gpe_event_info); |
| 169 | } |
| 170 | |
| 171 | if (ACPI_FAILURE(status)) { |
| 172 | gpe_event_info->runtime_count--; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | return_ACPI_STATUS(status); |
| 177 | } |
| 178 | |
| 179 | /******************************************************************************* |
| 180 | * |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 181 | * FUNCTION: acpi_ev_remove_gpe_reference |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 182 | * |
| 183 | * PARAMETERS: gpe_event_info - GPE to disable |
| 184 | * |
| 185 | * RETURN: Status |
| 186 | * |
| 187 | * DESCRIPTION: Remove a reference to a GPE. When the last reference is |
| 188 | * removed, the GPE is hardware-disabled. |
| 189 | * |
| 190 | ******************************************************************************/ |
| 191 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 192 | acpi_status acpi_ev_remove_gpe_reference(struct acpi_gpe_event_info *gpe_event_info) |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 193 | { |
| 194 | acpi_status status = AE_OK; |
| 195 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 196 | ACPI_FUNCTION_TRACE(ev_remove_gpe_reference); |
| 197 | |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 198 | if (!gpe_event_info->runtime_count) { |
| 199 | return_ACPI_STATUS(AE_LIMIT); |
| 200 | } |
| 201 | |
| 202 | gpe_event_info->runtime_count--; |
| 203 | if (!gpe_event_info->runtime_count) { |
| 204 | status = acpi_ev_update_gpe_enable_mask(gpe_event_info); |
| 205 | if (ACPI_SUCCESS(status)) { |
| 206 | status = acpi_hw_low_set_gpe(gpe_event_info, |
| 207 | ACPI_GPE_DISABLE); |
| 208 | } |
| 209 | |
| 210 | if (ACPI_FAILURE(status)) { |
| 211 | gpe_event_info->runtime_count++; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | return_ACPI_STATUS(status); |
| 216 | } |
| 217 | |
| 218 | /******************************************************************************* |
| 219 | * |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 220 | * FUNCTION: acpi_ev_low_get_gpe_info |
| 221 | * |
| 222 | * PARAMETERS: gpe_number - Raw GPE number |
| 223 | * gpe_block - A GPE info block |
| 224 | * |
| 225 | * RETURN: A GPE event_info struct. NULL if not a valid GPE (The gpe_number |
| 226 | * is not within the specified GPE block) |
| 227 | * |
| 228 | * DESCRIPTION: Returns the event_info struct associated with this GPE. This is |
| 229 | * the low-level implementation of ev_get_gpe_event_info. |
| 230 | * |
| 231 | ******************************************************************************/ |
| 232 | |
| 233 | struct acpi_gpe_event_info *acpi_ev_low_get_gpe_info(u32 gpe_number, |
| 234 | struct acpi_gpe_block_info |
| 235 | *gpe_block) |
| 236 | { |
| 237 | u32 gpe_index; |
| 238 | |
| 239 | /* |
| 240 | * Validate that the gpe_number is within the specified gpe_block. |
| 241 | * (Two steps) |
| 242 | */ |
| 243 | if (!gpe_block || (gpe_number < gpe_block->block_base_number)) { |
| 244 | return (NULL); |
| 245 | } |
| 246 | |
| 247 | gpe_index = gpe_number - gpe_block->block_base_number; |
| 248 | if (gpe_index >= gpe_block->gpe_count) { |
| 249 | return (NULL); |
| 250 | } |
| 251 | |
| 252 | return (&gpe_block->event_info[gpe_index]); |
| 253 | } |
| 254 | |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | /******************************************************************************* |
| 257 | * |
| 258 | * FUNCTION: acpi_ev_get_gpe_event_info |
| 259 | * |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 260 | * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | * gpe_number - Raw GPE number |
| 262 | * |
| 263 | * RETURN: A GPE event_info struct. NULL if not a valid GPE |
| 264 | * |
| 265 | * DESCRIPTION: Returns the event_info struct associated with this GPE. |
| 266 | * Validates the gpe_block and the gpe_number |
| 267 | * |
| 268 | * Should be called only when the GPE lists are semaphore locked |
| 269 | * and not subject to change. |
| 270 | * |
| 271 | ******************************************************************************/ |
| 272 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 273 | struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device, |
| 274 | u32 gpe_number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 276 | union acpi_operand_object *obj_desc; |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 277 | struct acpi_gpe_event_info *gpe_info; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 278 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 280 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Bob Moore | 186c307 | 2010-04-27 11:32:28 +0800 | [diff] [blame] | 282 | /* A NULL gpe_device means use the FADT-defined GPE block(s) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | if (!gpe_device) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | /* Examine GPE Block 0 and 1 (These blocks are permanent) */ |
| 287 | |
| 288 | for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) { |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 289 | gpe_info = acpi_ev_low_get_gpe_info(gpe_number, |
| 290 | acpi_gbl_gpe_fadt_blocks |
| 291 | [i]); |
| 292 | if (gpe_info) { |
| 293 | return (gpe_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
| 297 | /* The gpe_number was not in the range of either FADT GPE block */ |
| 298 | |
| 299 | return (NULL); |
| 300 | } |
| 301 | |
| 302 | /* A Non-NULL gpe_device means this is a GPE Block Device */ |
| 303 | |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 304 | obj_desc = acpi_ns_get_attached_object((struct acpi_namespace_node *) |
| 305 | gpe_device); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 306 | if (!obj_desc || !obj_desc->device.gpe_block) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | return (NULL); |
| 308 | } |
| 309 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 310 | return (acpi_ev_low_get_gpe_info |
| 311 | (gpe_number, obj_desc->device.gpe_block)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | /******************************************************************************* |
| 315 | * |
| 316 | * FUNCTION: acpi_ev_gpe_detect |
| 317 | * |
| 318 | * PARAMETERS: gpe_xrupt_list - Interrupt block for this interrupt. |
| 319 | * Can have multiple GPE blocks attached. |
| 320 | * |
| 321 | * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED |
| 322 | * |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 323 | * DESCRIPTION: Detect if any GP events have occurred. This function is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | * executed at interrupt level. |
| 325 | * |
| 326 | ******************************************************************************/ |
| 327 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 328 | u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | acpi_status status; |
| 331 | struct acpi_gpe_block_info *gpe_block; |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 332 | struct acpi_gpe_register_info *gpe_register_info; |
| 333 | u32 int_status = ACPI_INTERRUPT_NOT_HANDLED; |
| 334 | u8 enabled_status_byte; |
| 335 | u32 status_reg; |
| 336 | u32 enable_reg; |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 337 | acpi_cpu_flags flags; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 338 | u32 i; |
| 339 | u32 j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 341 | ACPI_FUNCTION_NAME(ev_gpe_detect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | /* Check for the case where there are no GPEs */ |
| 344 | |
| 345 | if (!gpe_xrupt_list) { |
| 346 | return (int_status); |
| 347 | } |
| 348 | |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 349 | /* |
| 350 | * We need to obtain the GPE lock for both the data structs and registers |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 351 | * Note: Not necessary to obtain the hardware lock, since the GPE |
| 352 | * registers are owned by the gpe_lock. |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 353 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 354 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Bob Moore | 4c90ece | 2006-06-08 16:29:00 -0400 | [diff] [blame] | 355 | |
| 356 | /* Examine all GPE blocks attached to this interrupt level */ |
| 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | gpe_block = gpe_xrupt_list->gpe_block_list_head; |
| 359 | while (gpe_block) { |
| 360 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 361 | * Read all of the 8-bit GPE status and enable registers in this GPE |
| 362 | * block, saving all of them. Find all currently active GP events. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | */ |
| 364 | for (i = 0; i < gpe_block->register_count; i++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | /* Get the next status/enable pair */ |
| 367 | |
| 368 | gpe_register_info = &gpe_block->register_info[i]; |
| 369 | |
| 370 | /* Read the Status Register */ |
| 371 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 372 | status = |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 373 | acpi_hw_read(&status_reg, |
| 374 | &gpe_register_info->status_address); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 375 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | goto unlock_and_exit; |
| 377 | } |
| 378 | |
| 379 | /* Read the Enable Register */ |
| 380 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 381 | status = |
Bob Moore | c6b5774 | 2009-06-24 09:44:06 +0800 | [diff] [blame] | 382 | acpi_hw_read(&enable_reg, |
| 383 | &gpe_register_info->enable_address); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 384 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | goto unlock_and_exit; |
| 386 | } |
| 387 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 388 | ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS, |
| 389 | "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n", |
| 390 | gpe_register_info->base_gpe_number, |
| 391 | status_reg, enable_reg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 393 | /* Check if there is anything active at all in this register */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | enabled_status_byte = (u8) (status_reg & enable_reg); |
| 396 | if (!enabled_status_byte) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | /* No active GPEs in this register, move on */ |
| 399 | |
| 400 | continue; |
| 401 | } |
| 402 | |
| 403 | /* Now look at the individual GPEs in this byte register */ |
| 404 | |
| 405 | for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | /* Examine one GPE bit */ |
| 408 | |
Alexey Starikovskiy | 6987416 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 409 | if (enabled_status_byte & (1 << j)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | /* |
| 411 | * Found an active GPE. Dispatch the event to a handler |
| 412 | * or method. |
| 413 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 414 | int_status |= |
Lin Ming | 8b6cd8a | 2010-12-13 13:38:46 +0800 | [diff] [blame] | 415 | acpi_ev_gpe_dispatch(gpe_block-> |
| 416 | node, |
| 417 | &gpe_block-> |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 418 | event_info[((acpi_size) i * ACPI_GPE_REGISTER_WIDTH) + j], j + gpe_register_info->base_gpe_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | gpe_block = gpe_block->next; |
| 424 | } |
| 425 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 426 | unlock_and_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 428 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | return (int_status); |
| 430 | } |
| 431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | /******************************************************************************* |
| 433 | * |
| 434 | * FUNCTION: acpi_ev_asynch_execute_gpe_method |
| 435 | * |
| 436 | * PARAMETERS: Context (gpe_event_info) - Info for this GPE |
| 437 | * |
| 438 | * RETURN: None |
| 439 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 440 | * DESCRIPTION: Perform the actual execution of a GPE control method. This |
| 441 | * function is called from an invocation of acpi_os_execute and |
| 442 | * therefore does NOT execute at interrupt level - so that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | * the control method itself is not executed in the context of |
| 444 | * an interrupt handler. |
| 445 | * |
| 446 | ******************************************************************************/ |
| 447 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 448 | static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | { |
Lin Ming | 5a284cd | 2010-12-13 13:39:07 +0800 | [diff] [blame] | 450 | struct acpi_gpe_event_info *gpe_event_info = context; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 451 | acpi_status status; |
Lin Ming | 5a284cd | 2010-12-13 13:39:07 +0800 | [diff] [blame] | 452 | struct acpi_gpe_event_info *local_gpe_event_info; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 453 | struct acpi_evaluate_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 455 | ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | |
Lin Ming | 5a284cd | 2010-12-13 13:39:07 +0800 | [diff] [blame] | 457 | /* Allocate a local GPE block */ |
| 458 | |
| 459 | local_gpe_event_info = |
| 460 | ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_event_info)); |
| 461 | if (!local_gpe_event_info) { |
| 462 | ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, "while handling a GPE")); |
| 463 | return_VOID; |
| 464 | } |
| 465 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 466 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 467 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | return_VOID; |
| 469 | } |
| 470 | |
| 471 | /* Must revalidate the gpe_number/gpe_block */ |
| 472 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 473 | if (!acpi_ev_valid_gpe_event(gpe_event_info)) { |
| 474 | status = acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | return_VOID; |
| 476 | } |
| 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 479 | * Take a snapshot of the GPE info for this level - we copy the info to |
| 480 | * prevent a race condition with remove_handler/remove_block. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | */ |
Lin Ming | 5a284cd | 2010-12-13 13:39:07 +0800 | [diff] [blame] | 482 | ACPI_MEMCPY(local_gpe_event_info, gpe_event_info, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 483 | sizeof(struct acpi_gpe_event_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 485 | status = acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 486 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | return_VOID; |
| 488 | } |
| 489 | |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 490 | /* Do the correct dispatch - normal method or implicit notify */ |
| 491 | |
| 492 | switch (local_gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) { |
| 493 | case ACPI_GPE_DISPATCH_NOTIFY: |
| 494 | |
| 495 | /* |
| 496 | * Implicit notify. |
| 497 | * Dispatch a DEVICE_WAKE notify to the appropriate handler. |
| 498 | * NOTE: the request is queued for execution after this method |
| 499 | * completes. The notify handlers are NOT invoked synchronously |
| 500 | * from this thread -- because handlers may in turn run other |
| 501 | * control methods. |
| 502 | */ |
| 503 | status = |
| 504 | acpi_ev_queue_notify_request(local_gpe_event_info->dispatch. |
| 505 | device_node, |
| 506 | ACPI_NOTIFY_DEVICE_WAKE); |
| 507 | break; |
| 508 | |
| 509 | case ACPI_GPE_DISPATCH_METHOD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 511 | /* Allocate the evaluation information block */ |
| 512 | |
| 513 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); |
| 514 | if (!info) { |
| 515 | status = AE_NO_MEMORY; |
| 516 | } else { |
| 517 | /* |
| 518 | * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx |
| 519 | * control method that corresponds to this GPE |
| 520 | */ |
| 521 | info->prefix_node = |
Lin Ming | 5a284cd | 2010-12-13 13:39:07 +0800 | [diff] [blame] | 522 | local_gpe_event_info->dispatch.method_node; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 523 | info->flags = ACPI_IGNORE_RETURN_VALUE; |
| 524 | |
| 525 | status = acpi_ns_evaluate(info); |
| 526 | ACPI_FREE(info); |
| 527 | } |
| 528 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 529 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 530 | ACPI_EXCEPTION((AE_INFO, status, |
Bob Moore | 2e42005 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 531 | "while evaluating GPE method [%4.4s]", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 532 | acpi_ut_get_node_name |
Lin Ming | 5a284cd | 2010-12-13 13:39:07 +0800 | [diff] [blame] | 533 | (local_gpe_event_info->dispatch. |
Bob Moore | 4c90ece | 2006-06-08 16:29:00 -0400 | [diff] [blame] | 534 | method_node))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 536 | |
| 537 | break; |
| 538 | |
| 539 | default: |
| 540 | return_VOID; /* Should never happen */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | } |
Lin Ming | 5a284cd | 2010-12-13 13:39:07 +0800 | [diff] [blame] | 542 | |
Alexey Starikovskiy | 17bc54e | 2007-11-13 13:05:45 +0300 | [diff] [blame] | 543 | /* Defer enabling of GPE until all notify handlers are done */ |
Lin Ming | 5a284cd | 2010-12-13 13:39:07 +0800 | [diff] [blame] | 544 | |
| 545 | status = acpi_os_execute(OSL_NOTIFY_HANDLER, |
| 546 | acpi_ev_asynch_enable_gpe, |
| 547 | local_gpe_event_info); |
| 548 | if (ACPI_FAILURE(status)) { |
| 549 | ACPI_FREE(local_gpe_event_info); |
| 550 | } |
Alexey Starikovskiy | 17bc54e | 2007-11-13 13:05:45 +0300 | [diff] [blame] | 551 | return_VOID; |
| 552 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 554 | |
Lin Ming | 5a284cd | 2010-12-13 13:39:07 +0800 | [diff] [blame] | 555 | /******************************************************************************* |
| 556 | * |
| 557 | * FUNCTION: acpi_ev_asynch_enable_gpe |
| 558 | * |
| 559 | * PARAMETERS: Context (gpe_event_info) - Info for this GPE |
| 560 | * Callback from acpi_os_execute |
| 561 | * |
| 562 | * RETURN: None |
| 563 | * |
| 564 | * DESCRIPTION: Asynchronous clear/enable for GPE. This allows the GPE to |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 565 | * complete (i.e., finish execution of Notify) |
Lin Ming | 5a284cd | 2010-12-13 13:39:07 +0800 | [diff] [blame] | 566 | * |
| 567 | ******************************************************************************/ |
| 568 | |
| 569 | static void ACPI_SYSTEM_XFACE acpi_ev_asynch_enable_gpe(void *context) |
Alexey Starikovskiy | 17bc54e | 2007-11-13 13:05:45 +0300 | [diff] [blame] | 570 | { |
| 571 | struct acpi_gpe_event_info *gpe_event_info = context; |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 572 | |
| 573 | (void)acpi_ev_finish_gpe(gpe_event_info); |
| 574 | |
| 575 | ACPI_FREE(gpe_event_info); |
| 576 | return; |
| 577 | } |
| 578 | |
| 579 | |
| 580 | /******************************************************************************* |
| 581 | * |
| 582 | * FUNCTION: acpi_ev_finish_gpe |
| 583 | * |
| 584 | * PARAMETERS: gpe_event_info - Info for this GPE |
| 585 | * |
| 586 | * RETURN: Status |
| 587 | * |
| 588 | * DESCRIPTION: Clear/Enable a GPE. Common code that is used after execution |
| 589 | * of a GPE method or a synchronous or asynchronous GPE handler. |
| 590 | * |
| 591 | ******************************************************************************/ |
| 592 | |
| 593 | acpi_status acpi_ev_finish_gpe(struct acpi_gpe_event_info *gpe_event_info) |
| 594 | { |
Alexey Starikovskiy | 17bc54e | 2007-11-13 13:05:45 +0300 | [diff] [blame] | 595 | acpi_status status; |
Lin Ming | 5a284cd | 2010-12-13 13:39:07 +0800 | [diff] [blame] | 596 | |
Alexey Starikovskiy | 17bc54e | 2007-11-13 13:05:45 +0300 | [diff] [blame] | 597 | if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 598 | ACPI_GPE_LEVEL_TRIGGERED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | /* |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 600 | * GPE is level-triggered, we clear the GPE status bit after |
| 601 | * handling the event. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | */ |
Alexey Starikovskiy | 17bc54e | 2007-11-13 13:05:45 +0300 | [diff] [blame] | 603 | status = acpi_hw_clear_gpe(gpe_event_info); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 604 | if (ACPI_FAILURE(status)) { |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 605 | return (status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
Bob Moore | de5668f | 2010-07-06 10:30:37 +0800 | [diff] [blame] | 609 | /* |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 610 | * Enable this GPE, conditionally. This means that the GPE will |
| 611 | * only be physically enabled if the enable_for_run bit is set |
| 612 | * in the event_info. |
Bob Moore | de5668f | 2010-07-06 10:30:37 +0800 | [diff] [blame] | 613 | */ |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 614 | (void)acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_CONDITIONAL_ENABLE); |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 615 | return (AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | /******************************************************************************* |
| 620 | * |
| 621 | * FUNCTION: acpi_ev_gpe_dispatch |
| 622 | * |
Lin Ming | 8b6cd8a | 2010-12-13 13:38:46 +0800 | [diff] [blame] | 623 | * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1 |
| 624 | * gpe_event_info - Info for this GPE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | * gpe_number - Number relative to the parent GPE block |
| 626 | * |
| 627 | * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED |
| 628 | * |
| 629 | * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC) |
| 630 | * or method (e.g. _Lxx/_Exx) handler. |
| 631 | * |
| 632 | * This function executes at interrupt level. |
| 633 | * |
| 634 | ******************************************************************************/ |
| 635 | |
| 636 | u32 |
Lin Ming | 8b6cd8a | 2010-12-13 13:38:46 +0800 | [diff] [blame] | 637 | acpi_ev_gpe_dispatch(struct acpi_namespace_node *gpe_device, |
| 638 | struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 640 | acpi_status status; |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 641 | u32 return_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 643 | ACPI_FUNCTION_TRACE(ev_gpe_dispatch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Len Brown | 5229e87 | 2008-02-06 01:26:55 -0500 | [diff] [blame] | 645 | acpi_os_gpe_count(gpe_number); |
Bob Moore | fdffb72 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 648 | * If edge-triggered, clear the GPE status bit now. Note that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | * level-triggered events are cleared after the GPE is serviced. |
| 650 | */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 651 | if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 652 | ACPI_GPE_EDGE_TRIGGERED) { |
| 653 | status = acpi_hw_clear_gpe(gpe_event_info); |
| 654 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 655 | ACPI_EXCEPTION((AE_INFO, status, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 656 | "Unable to clear GPE[0x%2X]", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 657 | gpe_number)); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 658 | return_UINT32(ACPI_INTERRUPT_NOT_HANDLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | /* |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 663 | * Always disable the GPE so that it does not keep firing before |
| 664 | * any asynchronous activity completes (either from the execution |
| 665 | * of a GPE method or an asynchronous GPE handler.) |
| 666 | * |
| 667 | * If there is no handler or method to run, just disable the |
| 668 | * GPE and leave it disabled permanently to prevent further such |
| 669 | * pointless events from firing. |
| 670 | */ |
| 671 | status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE); |
| 672 | if (ACPI_FAILURE(status)) { |
| 673 | ACPI_EXCEPTION((AE_INFO, status, |
| 674 | "Unable to disable GPE%02X", gpe_number)); |
| 675 | return_UINT32(ACPI_INTERRUPT_NOT_HANDLED); |
| 676 | } |
| 677 | |
| 678 | /* |
| 679 | * Dispatch the GPE to either an installed handler or the control |
| 680 | * method associated with this GPE (_Lxx or _Exx). If a handler |
| 681 | * exists, we invoke it and do not attempt to run the method. |
| 682 | * If there is neither a handler nor a method, leave the GPE |
| 683 | * disabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | */ |
| 685 | switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) { |
| 686 | case ACPI_GPE_DISPATCH_HANDLER: |
| 687 | |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 688 | /* Invoke the installed handler (at interrupt level) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 690 | return_value = |
| 691 | gpe_event_info->dispatch.handler->address(gpe_device, |
| 692 | gpe_number, |
| 693 | gpe_event_info-> |
| 694 | dispatch.handler-> |
| 695 | context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 697 | /* If requested, clear (if level-triggered) and reenable the GPE */ |
| 698 | |
| 699 | if (return_value & ACPI_REENABLE_GPE) { |
| 700 | (void)acpi_ev_finish_gpe(gpe_event_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | } |
| 702 | break; |
| 703 | |
| 704 | case ACPI_GPE_DISPATCH_METHOD: |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame^] | 705 | case ACPI_GPE_DISPATCH_NOTIFY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
| 707 | /* |
| 708 | * Execute the method associated with the GPE |
| 709 | * NOTE: Level-triggered GPEs are cleared after the method completes. |
| 710 | */ |
Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 711 | status = acpi_os_execute(OSL_GPE_HANDLER, |
| 712 | acpi_ev_asynch_execute_gpe_method, |
| 713 | gpe_event_info); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 714 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 715 | ACPI_EXCEPTION((AE_INFO, status, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 716 | "Unable to queue handler for GPE[0x%2X] - event disabled", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 717 | gpe_number)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | } |
| 719 | break; |
| 720 | |
| 721 | default: |
| 722 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 723 | /* |
| 724 | * No handler or method to run! |
| 725 | * 03/2010: This case should no longer be possible. We will not allow |
| 726 | * a GPE to be enabled if it has no handler or method. |
| 727 | */ |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 728 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 729 | "No handler or method for GPE[0x%2X], disabling event", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 730 | gpe_number)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | break; |
| 733 | } |
| 734 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 735 | return_UINT32(ACPI_INTERRUPT_HANDLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |