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 | /* |
Len Brown | 75a44ce | 2008-04-23 23:00:13 -0400 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2008, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions, and the following disclaimer, |
| 16 | * without modification. |
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 20 | * including a substantially similar Disclaimer requirement for further |
| 21 | * binary redistribution. |
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 23 | * of any contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * |
| 26 | * Alternatively, this software may be distributed under the terms of the |
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 28 | * Software Foundation. |
| 29 | * |
| 30 | * NO WARRANTY |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGES. |
| 42 | */ |
| 43 | |
| 44 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" |
| 46 | #include "acevents.h" |
| 47 | #include "acnamesp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define _COMPONENT ACPI_EVENTS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("evgpe") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | /* Local prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 53 | static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /******************************************************************************* |
| 56 | * |
| 57 | * FUNCTION: acpi_ev_set_gpe_type |
| 58 | * |
| 59 | * PARAMETERS: gpe_event_info - GPE to set |
| 60 | * Type - New type |
| 61 | * |
| 62 | * RETURN: Status |
| 63 | * |
| 64 | * DESCRIPTION: Sets the new type for the GPE (wake, run, or wake/run) |
| 65 | * |
| 66 | ******************************************************************************/ |
| 67 | |
| 68 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | acpi_ev_set_gpe_type(struct acpi_gpe_event_info *gpe_event_info, u8 type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 71 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 73 | ACPI_FUNCTION_TRACE(ev_set_gpe_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | /* Validate type and update register enable masks */ |
| 76 | |
| 77 | switch (type) { |
| 78 | case ACPI_GPE_TYPE_WAKE: |
| 79 | case ACPI_GPE_TYPE_RUNTIME: |
| 80 | case ACPI_GPE_TYPE_WAKE_RUN: |
| 81 | break; |
| 82 | |
| 83 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* Disable the GPE if currently enabled */ |
| 88 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 89 | status = acpi_ev_disable_gpe(gpe_event_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | /* Type was validated above */ |
| 92 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | gpe_event_info->flags &= ~ACPI_GPE_TYPE_MASK; /* Clear type bits */ |
| 94 | gpe_event_info->flags |= type; /* Insert type */ |
| 95 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /******************************************************************************* |
| 99 | * |
| 100 | * FUNCTION: acpi_ev_update_gpe_enable_masks |
| 101 | * |
| 102 | * PARAMETERS: gpe_event_info - GPE to update |
| 103 | * Type - What to do: ACPI_GPE_DISABLE or |
| 104 | * ACPI_GPE_ENABLE |
| 105 | * |
| 106 | * RETURN: Status |
| 107 | * |
| 108 | * DESCRIPTION: Updates GPE register enable masks based on the GPE type |
| 109 | * |
| 110 | ******************************************************************************/ |
| 111 | |
| 112 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info, |
| 114 | u8 type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 116 | struct acpi_gpe_register_info *gpe_register_info; |
| 117 | u8 register_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 119 | ACPI_FUNCTION_TRACE(ev_update_gpe_enable_masks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | gpe_register_info = gpe_event_info->register_info; |
| 122 | if (!gpe_register_info) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 123 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
Alexey Starikovskiy | 6987416 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 125 | register_bit = (u8) |
| 126 | (1 << |
| 127 | (gpe_event_info->gpe_number - gpe_register_info->base_gpe_number)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 129 | /* 1) Disable case. Simply clear all enable bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | if (type == ACPI_GPE_DISABLE) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 132 | ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake, |
| 133 | register_bit); |
| 134 | ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit); |
| 135 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 138 | /* 2) Enable case. Set/Clear the appropriate enable bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) { |
| 141 | case ACPI_GPE_TYPE_WAKE: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 142 | ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit); |
| 143 | ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | break; |
| 145 | |
| 146 | case ACPI_GPE_TYPE_RUNTIME: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake, |
| 148 | register_bit); |
| 149 | ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | break; |
| 151 | |
| 152 | case ACPI_GPE_TYPE_WAKE_RUN: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit); |
| 154 | ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | break; |
| 156 | |
| 157 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 158 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | /******************************************************************************* |
| 165 | * |
| 166 | * FUNCTION: acpi_ev_enable_gpe |
| 167 | * |
| 168 | * PARAMETERS: gpe_event_info - GPE to enable |
| 169 | * write_to_hardware - Enable now, or just mark data structs |
| 170 | * (WAKE GPEs should be deferred) |
| 171 | * |
| 172 | * RETURN: Status |
| 173 | * |
| 174 | * DESCRIPTION: Enable a GPE based on the GPE type |
| 175 | * |
| 176 | ******************************************************************************/ |
| 177 | |
| 178 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info, |
| 180 | u8 write_to_hardware) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 182 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 184 | ACPI_FUNCTION_TRACE(ev_enable_gpe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
| 186 | /* Make sure HW enable masks are updated */ |
| 187 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 188 | status = |
| 189 | acpi_ev_update_gpe_enable_masks(gpe_event_info, ACPI_GPE_ENABLE); |
| 190 | if (ACPI_FAILURE(status)) { |
| 191 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /* Mark wake-enabled or HW enable, or both */ |
| 195 | |
| 196 | switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) { |
| 197 | case ACPI_GPE_TYPE_WAKE: |
| 198 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 199 | ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | break; |
| 201 | |
| 202 | case ACPI_GPE_TYPE_WAKE_RUN: |
| 203 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | /*lint -fallthrough */ |
| 207 | |
| 208 | case ACPI_GPE_TYPE_RUNTIME: |
| 209 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 210 | ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
| 212 | if (write_to_hardware) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | /* Clear the GPE (of stale events), then enable it */ |
| 215 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | status = acpi_hw_clear_gpe(gpe_event_info); |
| 217 | if (ACPI_FAILURE(status)) { |
| 218 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /* Enable the requested runtime GPE */ |
| 222 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | status = acpi_hw_write_gpe_enable_reg(gpe_event_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | break; |
| 226 | |
| 227 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 228 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 231 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | /******************************************************************************* |
| 235 | * |
| 236 | * FUNCTION: acpi_ev_disable_gpe |
| 237 | * |
| 238 | * PARAMETERS: gpe_event_info - GPE to disable |
| 239 | * |
| 240 | * RETURN: Status |
| 241 | * |
| 242 | * DESCRIPTION: Disable a GPE based on the GPE type |
| 243 | * |
| 244 | ******************************************************************************/ |
| 245 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 246 | acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 250 | ACPI_FUNCTION_TRACE(ev_disable_gpe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | /* Make sure HW enable masks are updated */ |
| 253 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 254 | status = |
| 255 | acpi_ev_update_gpe_enable_masks(gpe_event_info, ACPI_GPE_DISABLE); |
| 256 | if (ACPI_FAILURE(status)) { |
| 257 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Bob Moore | e38e8a0 | 2008-06-13 08:28:55 +0800 | [diff] [blame] | 260 | /* Clear the appropriate enabled flags for this GPE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
| 262 | switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) { |
| 263 | case ACPI_GPE_TYPE_WAKE: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 264 | ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | break; |
| 266 | |
| 267 | case ACPI_GPE_TYPE_WAKE_RUN: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 268 | ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Zhang Rui | a7f9b1f | 2007-11-20 13:38:59 -0500 | [diff] [blame] | 270 | /* fallthrough */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | case ACPI_GPE_TYPE_RUNTIME: |
| 273 | |
| 274 | /* Disable the requested runtime GPE */ |
| 275 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 276 | ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED); |
Bob Moore | e38e8a0 | 2008-06-13 08:28:55 +0800 | [diff] [blame] | 277 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | default: |
Bob Moore | e38e8a0 | 2008-06-13 08:28:55 +0800 | [diff] [blame] | 280 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Bob Moore | e38e8a0 | 2008-06-13 08:28:55 +0800 | [diff] [blame] | 283 | /* |
| 284 | * Even if we don't know the GPE type, make sure that we always |
| 285 | * disable it. low_disable_gpe will just clear the enable bit for this |
| 286 | * GPE and write it. It will not write out the current GPE enable mask, |
| 287 | * since this may inadvertently enable GPEs too early, if a rogue GPE has |
| 288 | * come in during ACPICA initialization - possibly as a result of AML or |
| 289 | * other code that has enabled the GPE. |
| 290 | */ |
| 291 | status = acpi_hw_low_disable_gpe(gpe_event_info); |
| 292 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | /******************************************************************************* |
| 296 | * |
| 297 | * FUNCTION: acpi_ev_get_gpe_event_info |
| 298 | * |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 299 | * PARAMETERS: gpe_device - Device node. NULL for GPE0/GPE1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | * gpe_number - Raw GPE number |
| 301 | * |
| 302 | * RETURN: A GPE event_info struct. NULL if not a valid GPE |
| 303 | * |
| 304 | * DESCRIPTION: Returns the event_info struct associated with this GPE. |
| 305 | * Validates the gpe_block and the gpe_number |
| 306 | * |
| 307 | * Should be called only when the GPE lists are semaphore locked |
| 308 | * and not subject to change. |
| 309 | * |
| 310 | ******************************************************************************/ |
| 311 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 312 | struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device, |
| 313 | u32 gpe_number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 315 | union acpi_operand_object *obj_desc; |
| 316 | struct acpi_gpe_block_info *gpe_block; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 317 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
| 321 | /* A NULL gpe_block means use the FADT-defined GPE block(s) */ |
| 322 | |
| 323 | if (!gpe_device) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | /* Examine GPE Block 0 and 1 (These blocks are permanent) */ |
| 326 | |
| 327 | for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) { |
| 328 | gpe_block = acpi_gbl_gpe_fadt_blocks[i]; |
| 329 | if (gpe_block) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | if ((gpe_number >= gpe_block->block_base_number) |
| 331 | && (gpe_number < |
| 332 | gpe_block->block_base_number + |
| 333 | (gpe_block->register_count * 8))) { |
| 334 | return (&gpe_block-> |
| 335 | event_info[gpe_number - |
| 336 | gpe_block-> |
| 337 | block_base_number]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | /* The gpe_number was not in the range of either FADT GPE block */ |
| 343 | |
| 344 | return (NULL); |
| 345 | } |
| 346 | |
| 347 | /* A Non-NULL gpe_device means this is a GPE Block Device */ |
| 348 | |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 349 | obj_desc = acpi_ns_get_attached_object((struct acpi_namespace_node *) |
| 350 | gpe_device); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 351 | if (!obj_desc || !obj_desc->device.gpe_block) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | return (NULL); |
| 353 | } |
| 354 | |
| 355 | gpe_block = obj_desc->device.gpe_block; |
| 356 | |
| 357 | if ((gpe_number >= gpe_block->block_base_number) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 358 | (gpe_number < |
| 359 | gpe_block->block_base_number + (gpe_block->register_count * 8))) { |
| 360 | return (&gpe_block-> |
| 361 | event_info[gpe_number - gpe_block->block_base_number]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | return (NULL); |
| 365 | } |
| 366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | /******************************************************************************* |
| 368 | * |
| 369 | * FUNCTION: acpi_ev_gpe_detect |
| 370 | * |
| 371 | * PARAMETERS: gpe_xrupt_list - Interrupt block for this interrupt. |
| 372 | * Can have multiple GPE blocks attached. |
| 373 | * |
| 374 | * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED |
| 375 | * |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 376 | * DESCRIPTION: Detect if any GP events have occurred. This function is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | * executed at interrupt level. |
| 378 | * |
| 379 | ******************************************************************************/ |
| 380 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 381 | 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] | 382 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 383 | acpi_status status; |
| 384 | struct acpi_gpe_block_info *gpe_block; |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 385 | struct acpi_gpe_register_info *gpe_register_info; |
| 386 | u32 int_status = ACPI_INTERRUPT_NOT_HANDLED; |
| 387 | u8 enabled_status_byte; |
| 388 | u32 status_reg; |
| 389 | u32 enable_reg; |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 390 | acpi_cpu_flags flags; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 391 | u32 i; |
| 392 | u32 j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 394 | ACPI_FUNCTION_NAME(ev_gpe_detect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
| 396 | /* Check for the case where there are no GPEs */ |
| 397 | |
| 398 | if (!gpe_xrupt_list) { |
| 399 | return (int_status); |
| 400 | } |
| 401 | |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 402 | /* |
| 403 | * 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] | 404 | * Note: Not necessary to obtain the hardware lock, since the GPE |
| 405 | * registers are owned by the gpe_lock. |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 406 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 407 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
Bob Moore | 4c90ece | 2006-06-08 16:29:00 -0400 | [diff] [blame] | 408 | |
| 409 | /* Examine all GPE blocks attached to this interrupt level */ |
| 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | gpe_block = gpe_xrupt_list->gpe_block_list_head; |
| 412 | while (gpe_block) { |
| 413 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 414 | * Read all of the 8-bit GPE status and enable registers in this GPE |
| 415 | * block, saving all of them. Find all currently active GP events. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | */ |
| 417 | for (i = 0; i < gpe_block->register_count; i++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | /* Get the next status/enable pair */ |
| 420 | |
| 421 | gpe_register_info = &gpe_block->register_info[i]; |
| 422 | |
| 423 | /* Read the Status Register */ |
| 424 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 425 | status = |
Bob Moore | ecfbbc7 | 2008-12-31 02:55:32 +0800 | [diff] [blame] | 426 | acpi_read(&status_reg, |
| 427 | &gpe_register_info->status_address); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 428 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | goto unlock_and_exit; |
| 430 | } |
| 431 | |
| 432 | /* Read the Enable Register */ |
| 433 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 434 | status = |
Bob Moore | ecfbbc7 | 2008-12-31 02:55:32 +0800 | [diff] [blame] | 435 | acpi_read(&enable_reg, |
| 436 | &gpe_register_info->enable_address); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 437 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | goto unlock_and_exit; |
| 439 | } |
| 440 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 441 | ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS, |
| 442 | "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n", |
| 443 | gpe_register_info->base_gpe_number, |
| 444 | status_reg, enable_reg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 446 | /* Check if there is anything active at all in this register */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 448 | enabled_status_byte = (u8) (status_reg & enable_reg); |
| 449 | if (!enabled_status_byte) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | /* No active GPEs in this register, move on */ |
| 452 | |
| 453 | continue; |
| 454 | } |
| 455 | |
| 456 | /* Now look at the individual GPEs in this byte register */ |
| 457 | |
| 458 | for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | /* Examine one GPE bit */ |
| 461 | |
Alexey Starikovskiy | 6987416 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 462 | if (enabled_status_byte & (1 << j)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | /* |
| 464 | * Found an active GPE. Dispatch the event to a handler |
| 465 | * or method. |
| 466 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 467 | int_status |= |
| 468 | acpi_ev_gpe_dispatch(&gpe_block-> |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 469 | 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] | 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | gpe_block = gpe_block->next; |
| 475 | } |
| 476 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 477 | unlock_and_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 479 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | return (int_status); |
| 481 | } |
| 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | /******************************************************************************* |
| 484 | * |
| 485 | * FUNCTION: acpi_ev_asynch_execute_gpe_method |
| 486 | * |
| 487 | * PARAMETERS: Context (gpe_event_info) - Info for this GPE |
| 488 | * |
| 489 | * RETURN: None |
| 490 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 491 | * DESCRIPTION: Perform the actual execution of a GPE control method. This |
| 492 | * function is called from an invocation of acpi_os_execute and |
| 493 | * therefore does NOT execute at interrupt level - so that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | * the control method itself is not executed in the context of |
| 495 | * an interrupt handler. |
| 496 | * |
| 497 | ******************************************************************************/ |
Alexey Starikovskiy | 17bc54e | 2007-11-13 13:05:45 +0300 | [diff] [blame] | 498 | static void acpi_ev_asynch_enable_gpe(void *context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 500 | 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] | 501 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 502 | struct acpi_gpe_event_info *gpe_event_info = (void *)context; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 503 | acpi_status status; |
| 504 | struct acpi_gpe_event_info local_gpe_event_info; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 505 | struct acpi_evaluate_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 507 | ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 509 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 510 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | return_VOID; |
| 512 | } |
| 513 | |
| 514 | /* Must revalidate the gpe_number/gpe_block */ |
| 515 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 516 | if (!acpi_ev_valid_gpe_event(gpe_event_info)) { |
| 517 | status = acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | return_VOID; |
| 519 | } |
| 520 | |
| 521 | /* Set the GPE flags for return to enabled state */ |
| 522 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 523 | (void)acpi_ev_enable_gpe(gpe_event_info, FALSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
| 525 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 526 | * Take a snapshot of the GPE info for this level - we copy the info to |
| 527 | * prevent a race condition with remove_handler/remove_block. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 529 | ACPI_MEMCPY(&local_gpe_event_info, gpe_event_info, |
| 530 | sizeof(struct acpi_gpe_event_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 532 | status = acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 533 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | return_VOID; |
| 535 | } |
| 536 | |
| 537 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 538 | * Must check for control method type dispatch one more time to avoid a |
| 539 | * race with ev_gpe_install_handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 541 | if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) == |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 542 | ACPI_GPE_DISPATCH_METHOD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 544 | /* Allocate the evaluation information block */ |
| 545 | |
| 546 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); |
| 547 | if (!info) { |
| 548 | status = AE_NO_MEMORY; |
| 549 | } else { |
| 550 | /* |
| 551 | * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx |
| 552 | * control method that corresponds to this GPE |
| 553 | */ |
| 554 | info->prefix_node = |
| 555 | local_gpe_event_info.dispatch.method_node; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 556 | info->flags = ACPI_IGNORE_RETURN_VALUE; |
| 557 | |
| 558 | status = acpi_ns_evaluate(info); |
| 559 | ACPI_FREE(info); |
| 560 | } |
| 561 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 562 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 563 | ACPI_EXCEPTION((AE_INFO, status, |
Bob Moore | 2e42005 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 564 | "while evaluating GPE method [%4.4s]", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 565 | acpi_ut_get_node_name |
| 566 | (local_gpe_event_info.dispatch. |
Bob Moore | 4c90ece | 2006-06-08 16:29:00 -0400 | [diff] [blame] | 567 | method_node))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
| 569 | } |
Alexey Starikovskiy | 17bc54e | 2007-11-13 13:05:45 +0300 | [diff] [blame] | 570 | /* Defer enabling of GPE until all notify handlers are done */ |
| 571 | acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_asynch_enable_gpe, |
| 572 | gpe_event_info); |
| 573 | return_VOID; |
| 574 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Alexey Starikovskiy | 17bc54e | 2007-11-13 13:05:45 +0300 | [diff] [blame] | 576 | static void acpi_ev_asynch_enable_gpe(void *context) |
| 577 | { |
| 578 | struct acpi_gpe_event_info *gpe_event_info = context; |
| 579 | acpi_status status; |
| 580 | if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 581 | ACPI_GPE_LEVEL_TRIGGERED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 583 | * GPE is level-triggered, we clear the GPE status bit after handling |
| 584 | * the event. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | */ |
Alexey Starikovskiy | 17bc54e | 2007-11-13 13:05:45 +0300 | [diff] [blame] | 586 | status = acpi_hw_clear_gpe(gpe_event_info); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 587 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | return_VOID; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | /* Enable this GPE */ |
Alexey Starikovskiy | 17bc54e | 2007-11-13 13:05:45 +0300 | [diff] [blame] | 593 | (void)acpi_hw_write_gpe_enable_reg(gpe_event_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | return_VOID; |
| 595 | } |
| 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | /******************************************************************************* |
| 598 | * |
| 599 | * FUNCTION: acpi_ev_gpe_dispatch |
| 600 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 601 | * PARAMETERS: gpe_event_info - Info for this GPE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | * gpe_number - Number relative to the parent GPE block |
| 603 | * |
| 604 | * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED |
| 605 | * |
| 606 | * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC) |
| 607 | * or method (e.g. _Lxx/_Exx) handler. |
| 608 | * |
| 609 | * This function executes at interrupt level. |
| 610 | * |
| 611 | ******************************************************************************/ |
| 612 | |
| 613 | u32 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 614 | acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 616 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 618 | ACPI_FUNCTION_TRACE(ev_gpe_dispatch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
Len Brown | 5229e87 | 2008-02-06 01:26:55 -0500 | [diff] [blame] | 620 | acpi_os_gpe_count(gpe_number); |
Bob Moore | fdffb72 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 623 | * If edge-triggered, clear the GPE status bit now. Note that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | * level-triggered events are cleared after the GPE is serviced. |
| 625 | */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 626 | if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 627 | ACPI_GPE_EDGE_TRIGGERED) { |
| 628 | status = acpi_hw_clear_gpe(gpe_event_info); |
| 629 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 630 | ACPI_EXCEPTION((AE_INFO, status, |
| 631 | "Unable to clear GPE[%2X]", |
| 632 | gpe_number)); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 633 | return_UINT32(ACPI_INTERRUPT_NOT_HANDLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | /* |
Bob Moore | c5a7156 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 638 | * Dispatch the GPE to either an installed handler, or the control method |
| 639 | * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke |
| 640 | * it and do not attempt to run the method. If there is neither a handler |
| 641 | * nor a method, we disable this GPE to prevent further such pointless |
| 642 | * events from firing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | */ |
| 644 | switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) { |
| 645 | case ACPI_GPE_DISPATCH_HANDLER: |
| 646 | |
| 647 | /* |
| 648 | * Invoke the installed handler (at interrupt level) |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 649 | * Ignore return status for now. |
| 650 | * TBD: leave GPE disabled on error? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 652 | (void)gpe_event_info->dispatch.handler->address(gpe_event_info-> |
| 653 | dispatch. |
| 654 | handler-> |
| 655 | context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
| 657 | /* It is now safe to clear level-triggered events. */ |
| 658 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 659 | if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) == |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 660 | ACPI_GPE_LEVEL_TRIGGERED) { |
| 661 | status = acpi_hw_clear_gpe(gpe_event_info); |
| 662 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 663 | ACPI_EXCEPTION((AE_INFO, status, |
| 664 | "Unable to clear GPE[%2X]", |
| 665 | gpe_number)); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 666 | return_UINT32(ACPI_INTERRUPT_NOT_HANDLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | } |
| 668 | } |
| 669 | break; |
| 670 | |
| 671 | case ACPI_GPE_DISPATCH_METHOD: |
| 672 | |
| 673 | /* |
Bob Moore | c5a7156 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 674 | * Disable the GPE, so it doesn't keep firing before the method has a |
| 675 | * chance to run (it runs asynchronously with interrupts enabled). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 677 | status = acpi_ev_disable_gpe(gpe_event_info); |
| 678 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 679 | ACPI_EXCEPTION((AE_INFO, status, |
| 680 | "Unable to disable GPE[%2X]", |
| 681 | gpe_number)); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 682 | return_UINT32(ACPI_INTERRUPT_NOT_HANDLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | /* |
| 686 | * Execute the method associated with the GPE |
| 687 | * NOTE: Level-triggered GPEs are cleared after the method completes. |
| 688 | */ |
Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 689 | status = acpi_os_execute(OSL_GPE_HANDLER, |
| 690 | acpi_ev_asynch_execute_gpe_method, |
| 691 | gpe_event_info); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 692 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 693 | ACPI_EXCEPTION((AE_INFO, status, |
| 694 | "Unable to queue handler for GPE[%2X] - event disabled", |
| 695 | gpe_number)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | } |
| 697 | break; |
| 698 | |
| 699 | default: |
| 700 | |
| 701 | /* No handler or method to run! */ |
| 702 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 703 | ACPI_ERROR((AE_INFO, |
| 704 | "No handler or method for GPE[%2X], disabling event", |
| 705 | gpe_number)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
| 707 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 708 | * Disable the GPE. The GPE will remain disabled until the ACPICA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | * Core Subsystem is restarted, or a handler is installed. |
| 710 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 711 | status = acpi_ev_disable_gpe(gpe_event_info); |
| 712 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 713 | ACPI_EXCEPTION((AE_INFO, status, |
| 714 | "Unable to disable GPE[%2X]", |
| 715 | gpe_number)); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 716 | return_UINT32(ACPI_INTERRUPT_NOT_HANDLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | break; |
| 719 | } |
| 720 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 721 | return_UINT32(ACPI_INTERRUPT_HANDLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | } |