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