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