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