Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs) |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | fbb7a2d | 2014-02-08 09:42:25 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2014, Intel Corp. |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [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 | |
Lv Zheng | 839e928 | 2013-10-29 09:29:51 +0800 | [diff] [blame] | 44 | #define EXPORT_ACPI_INTERFACES |
| 45 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 46 | #include <acpi/acpi.h> |
| 47 | #include "accommon.h" |
| 48 | #include "acevents.h" |
| 49 | #include "acnamesp.h" |
| 50 | |
| 51 | #define _COMPONENT ACPI_EVENTS |
| 52 | ACPI_MODULE_NAME("evxfgpe") |
| 53 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 54 | #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 55 | /******************************************************************************* |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 56 | * |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 57 | * FUNCTION: acpi_update_all_gpes |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 58 | * |
| 59 | * PARAMETERS: None |
| 60 | * |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 61 | * RETURN: Status |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 62 | * |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 63 | * DESCRIPTION: Complete GPE initialization and enable all GPEs that have |
| 64 | * associated _Lxx or _Exx methods and are not pointed to by any |
| 65 | * device _PRW methods (this indicates that these GPEs are |
| 66 | * generally intended for system or device wakeup. Such GPEs |
| 67 | * have to be enabled directly when the devices whose _PRW |
| 68 | * methods point to them are set up for wakeup signaling.) |
| 69 | * |
| 70 | * NOTE: Should be called after any GPEs are added to the system. Primarily, |
| 71 | * after the system _PRW methods have been run, but also after a GPE Block |
| 72 | * Device has been added or if any new GPE methods have been added via a |
| 73 | * dynamic table load. |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 74 | * |
| 75 | ******************************************************************************/ |
| 76 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 77 | acpi_status acpi_update_all_gpes(void) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 78 | { |
| 79 | acpi_status status; |
| 80 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 81 | ACPI_FUNCTION_TRACE(acpi_update_all_gpes); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 82 | |
| 83 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 84 | if (ACPI_FAILURE(status)) { |
| 85 | return_ACPI_STATUS(status); |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | if (acpi_gbl_all_gpes_initialized) { |
| 89 | goto unlock_and_exit; |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | status = acpi_ev_walk_gpe_list(acpi_ev_initialize_gpe_block, NULL); |
| 93 | if (ACPI_SUCCESS(status)) { |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 94 | acpi_gbl_all_gpes_initialized = TRUE; |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 95 | } |
| 96 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 97 | unlock_and_exit: |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 98 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 99 | |
| 100 | return_ACPI_STATUS(status); |
| 101 | } |
| 102 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 103 | ACPI_EXPORT_SYMBOL(acpi_update_all_gpes) |
| 104 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 105 | /******************************************************************************* |
| 106 | * |
| 107 | * FUNCTION: acpi_enable_gpe |
| 108 | * |
| 109 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
| 110 | * gpe_number - GPE level within the GPE block |
| 111 | * |
| 112 | * RETURN: Status |
| 113 | * |
| 114 | * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is |
| 115 | * hardware-enabled. |
| 116 | * |
| 117 | ******************************************************************************/ |
| 118 | |
| 119 | acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number) |
| 120 | { |
| 121 | acpi_status status = AE_BAD_PARAMETER; |
| 122 | struct acpi_gpe_event_info *gpe_event_info; |
| 123 | acpi_cpu_flags flags; |
| 124 | |
| 125 | ACPI_FUNCTION_TRACE(acpi_enable_gpe); |
| 126 | |
| 127 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 128 | |
| 129 | /* Ensure that we have a valid GPE number */ |
| 130 | |
| 131 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
| 132 | if (gpe_event_info) { |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 133 | status = acpi_ev_add_gpe_reference(gpe_event_info); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 137 | return_ACPI_STATUS(status); |
| 138 | } |
| 139 | ACPI_EXPORT_SYMBOL(acpi_enable_gpe) |
| 140 | |
| 141 | /******************************************************************************* |
| 142 | * |
| 143 | * FUNCTION: acpi_disable_gpe |
| 144 | * |
| 145 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
| 146 | * gpe_number - GPE level within the GPE block |
| 147 | * |
| 148 | * RETURN: Status |
| 149 | * |
| 150 | * DESCRIPTION: Remove a reference to a GPE. When the last reference is |
| 151 | * removed, only then is the GPE disabled (for runtime GPEs), or |
| 152 | * the GPE mask bit disabled (for wake GPEs) |
| 153 | * |
| 154 | ******************************************************************************/ |
| 155 | |
| 156 | acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number) |
| 157 | { |
| 158 | acpi_status status = AE_BAD_PARAMETER; |
| 159 | struct acpi_gpe_event_info *gpe_event_info; |
| 160 | acpi_cpu_flags flags; |
| 161 | |
| 162 | ACPI_FUNCTION_TRACE(acpi_disable_gpe); |
| 163 | |
| 164 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 165 | |
| 166 | /* Ensure that we have a valid GPE number */ |
| 167 | |
| 168 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
| 169 | if (gpe_event_info) { |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 170 | status = acpi_ev_remove_gpe_reference(gpe_event_info) ; |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 174 | return_ACPI_STATUS(status); |
| 175 | } |
Lv Zheng | 3e8214e | 2012-12-19 05:37:15 +0000 | [diff] [blame] | 176 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 177 | ACPI_EXPORT_SYMBOL(acpi_disable_gpe) |
| 178 | |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame] | 179 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 180 | /******************************************************************************* |
| 181 | * |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 182 | * FUNCTION: acpi_setup_gpe_for_wake |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 183 | * |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame] | 184 | * PARAMETERS: wake_device - Device associated with the GPE (via _PRW) |
| 185 | * gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
| 186 | * gpe_number - GPE level within the GPE block |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 187 | * |
| 188 | * RETURN: Status |
| 189 | * |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame] | 190 | * DESCRIPTION: Mark a GPE as having the ability to wake the system. This |
| 191 | * interface is intended to be used as the host executes the |
| 192 | * _PRW methods (Power Resources for Wake) in the system tables. |
| 193 | * Each _PRW appears under a Device Object (The wake_device), and |
| 194 | * contains the info for the wake GPE associated with the |
| 195 | * wake_device. |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 196 | * |
| 197 | ******************************************************************************/ |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame] | 198 | acpi_status |
| 199 | acpi_setup_gpe_for_wake(acpi_handle wake_device, |
| 200 | acpi_handle gpe_device, u32 gpe_number) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 201 | { |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 202 | acpi_status status; |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 203 | struct acpi_gpe_event_info *gpe_event_info; |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame] | 204 | struct acpi_namespace_node *device_node; |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 205 | struct acpi_gpe_notify_info *notify; |
| 206 | struct acpi_gpe_notify_info *new_notify; |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 207 | acpi_cpu_flags flags; |
| 208 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 209 | ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 210 | |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame] | 211 | /* Parameter Validation */ |
| 212 | |
| 213 | if (!wake_device) { |
| 214 | /* |
| 215 | * By forcing wake_device to be valid, we automatically enable the |
| 216 | * implicit notify feature on all hosts. |
| 217 | */ |
| 218 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 219 | } |
| 220 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 221 | /* Handle root object case */ |
| 222 | |
| 223 | if (wake_device == ACPI_ROOT_OBJECT) { |
| 224 | device_node = acpi_gbl_root_node; |
| 225 | } else { |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 226 | device_node = |
| 227 | ACPI_CAST_PTR(struct acpi_namespace_node, wake_device); |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 228 | } |
| 229 | |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 230 | /* Validate wake_device is of type Device */ |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 231 | |
| 232 | if (device_node->type != ACPI_TYPE_DEVICE) { |
| 233 | return_ACPI_STATUS (AE_BAD_PARAMETER); |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Allocate a new notify object up front, in case it is needed. |
| 238 | * Memory allocation while holding a spinlock is a big no-no |
| 239 | * on some hosts. |
| 240 | */ |
| 241 | new_notify = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_notify_info)); |
| 242 | if (!new_notify) { |
| 243 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 244 | } |
| 245 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 246 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 247 | |
| 248 | /* Ensure that we have a valid GPE number */ |
| 249 | |
| 250 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
Rafael J. Wysocki | 2d55951 | 2011-02-12 01:39:15 +0100 | [diff] [blame] | 251 | if (!gpe_event_info) { |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 252 | status = AE_BAD_PARAMETER; |
Rafael J. Wysocki | 2d55951 | 2011-02-12 01:39:15 +0100 | [diff] [blame] | 253 | goto unlock_and_exit; |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 254 | } |
| 255 | |
Rafael J. Wysocki | 2d55951 | 2011-02-12 01:39:15 +0100 | [diff] [blame] | 256 | /* |
| 257 | * If there is no method or handler for this GPE, then the |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 258 | * wake_device will be notified whenever this GPE fires. This is |
| 259 | * known as an "implicit notify". Note: The GPE is assumed to be |
Rafael J. Wysocki | 2d55951 | 2011-02-12 01:39:15 +0100 | [diff] [blame] | 260 | * level-triggered (for windows compatibility). |
| 261 | */ |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 262 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
| 263 | ACPI_GPE_DISPATCH_NONE) { |
| 264 | /* |
| 265 | * This is the first device for implicit notify on this GPE. |
| 266 | * Just set the flags here, and enter the NOTIFY block below. |
| 267 | */ |
| 268 | gpe_event_info->flags = |
| 269 | (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED); |
Rafael J. Wysocki | 2d55951 | 2011-02-12 01:39:15 +0100 | [diff] [blame] | 270 | } |
| 271 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 272 | /* |
| 273 | * If we already have an implicit notify on this GPE, add |
| 274 | * this device to the notify list. |
| 275 | */ |
| 276 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
| 277 | ACPI_GPE_DISPATCH_NOTIFY) { |
Rafael J. Wysocki | 981858b | 2011-02-24 19:59:21 +0100 | [diff] [blame] | 278 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 279 | /* Ensure that the device is not already in the list */ |
Rafael J. Wysocki | 981858b | 2011-02-24 19:59:21 +0100 | [diff] [blame] | 280 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 281 | notify = gpe_event_info->dispatch.notify_list; |
| 282 | while (notify) { |
| 283 | if (notify->device_node == device_node) { |
| 284 | status = AE_ALREADY_EXISTS; |
| 285 | goto unlock_and_exit; |
| 286 | } |
| 287 | notify = notify->next; |
Rafael J. Wysocki | 981858b | 2011-02-24 19:59:21 +0100 | [diff] [blame] | 288 | } |
| 289 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 290 | /* Add this device to the notify list for this GPE */ |
| 291 | |
| 292 | new_notify->device_node = device_node; |
| 293 | new_notify->next = gpe_event_info->dispatch.notify_list; |
| 294 | gpe_event_info->dispatch.notify_list = new_notify; |
| 295 | new_notify = NULL; |
Rafael J. Wysocki | 981858b | 2011-02-24 19:59:21 +0100 | [diff] [blame] | 296 | } |
| 297 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 298 | /* Mark the GPE as a possible wake event */ |
| 299 | |
Rafael J. Wysocki | 2d55951 | 2011-02-12 01:39:15 +0100 | [diff] [blame] | 300 | gpe_event_info->flags |= ACPI_GPE_CAN_WAKE; |
| 301 | status = AE_OK; |
| 302 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 303 | unlock_and_exit: |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 304 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 305 | |
| 306 | /* Delete the notify object if it was not used above */ |
| 307 | |
| 308 | if (new_notify) { |
| 309 | ACPI_FREE(new_notify); |
| 310 | } |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 311 | return_ACPI_STATUS(status); |
| 312 | } |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 313 | ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 314 | |
| 315 | /******************************************************************************* |
| 316 | * |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 317 | * FUNCTION: acpi_set_gpe_wake_mask |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 318 | * |
| 319 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
| 320 | * gpe_number - GPE level within the GPE block |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 321 | * action - Enable or Disable |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 322 | * |
| 323 | * RETURN: Status |
| 324 | * |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 325 | * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must |
| 326 | * already be marked as a WAKE GPE. |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 327 | * |
| 328 | ******************************************************************************/ |
| 329 | |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 330 | acpi_status |
| 331 | acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 332 | { |
| 333 | acpi_status status = AE_OK; |
| 334 | struct acpi_gpe_event_info *gpe_event_info; |
| 335 | struct acpi_gpe_register_info *gpe_register_info; |
| 336 | acpi_cpu_flags flags; |
| 337 | u32 register_bit; |
| 338 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 339 | ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 340 | |
| 341 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 342 | |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 343 | /* |
| 344 | * Ensure that we have a valid GPE number and that this GPE is in |
| 345 | * fact a wake GPE |
| 346 | */ |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 347 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 348 | if (!gpe_event_info) { |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 349 | status = AE_BAD_PARAMETER; |
| 350 | goto unlock_and_exit; |
| 351 | } |
| 352 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 353 | if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) { |
| 354 | status = AE_TYPE; |
| 355 | goto unlock_and_exit; |
| 356 | } |
| 357 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 358 | gpe_register_info = gpe_event_info->register_info; |
| 359 | if (!gpe_register_info) { |
| 360 | status = AE_NOT_EXIST; |
| 361 | goto unlock_and_exit; |
| 362 | } |
| 363 | |
Feng Tang | 1d94e1e | 2012-08-17 11:10:02 +0800 | [diff] [blame] | 364 | register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 365 | |
| 366 | /* Perform the action */ |
| 367 | |
| 368 | switch (action) { |
| 369 | case ACPI_GPE_ENABLE: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 370 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 371 | ACPI_SET_BIT(gpe_register_info->enable_for_wake, |
| 372 | (u8)register_bit); |
| 373 | break; |
| 374 | |
| 375 | case ACPI_GPE_DISABLE: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 376 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 377 | ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake, |
| 378 | (u8)register_bit); |
| 379 | break; |
| 380 | |
| 381 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 382 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 383 | ACPI_ERROR((AE_INFO, "%u, Invalid action", action)); |
| 384 | status = AE_BAD_PARAMETER; |
| 385 | break; |
| 386 | } |
| 387 | |
| 388 | unlock_and_exit: |
| 389 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 390 | return_ACPI_STATUS(status); |
| 391 | } |
| 392 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 393 | ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 394 | |
| 395 | /******************************************************************************* |
| 396 | * |
| 397 | * FUNCTION: acpi_clear_gpe |
| 398 | * |
| 399 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
| 400 | * gpe_number - GPE level within the GPE block |
| 401 | * |
| 402 | * RETURN: Status |
| 403 | * |
| 404 | * DESCRIPTION: Clear an ACPI event (general purpose) |
| 405 | * |
| 406 | ******************************************************************************/ |
| 407 | acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number) |
| 408 | { |
| 409 | acpi_status status = AE_OK; |
| 410 | struct acpi_gpe_event_info *gpe_event_info; |
| 411 | acpi_cpu_flags flags; |
| 412 | |
| 413 | ACPI_FUNCTION_TRACE(acpi_clear_gpe); |
| 414 | |
| 415 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 416 | |
| 417 | /* Ensure that we have a valid GPE number */ |
| 418 | |
| 419 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
| 420 | if (!gpe_event_info) { |
| 421 | status = AE_BAD_PARAMETER; |
| 422 | goto unlock_and_exit; |
| 423 | } |
| 424 | |
| 425 | status = acpi_hw_clear_gpe(gpe_event_info); |
| 426 | |
| 427 | unlock_and_exit: |
| 428 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 429 | return_ACPI_STATUS(status); |
| 430 | } |
| 431 | |
| 432 | ACPI_EXPORT_SYMBOL(acpi_clear_gpe) |
| 433 | |
| 434 | /******************************************************************************* |
| 435 | * |
| 436 | * FUNCTION: acpi_get_gpe_status |
| 437 | * |
| 438 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
| 439 | * gpe_number - GPE level within the GPE block |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 440 | * event_status - Where the current status of the event |
| 441 | * will be returned |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 442 | * |
| 443 | * RETURN: Status |
| 444 | * |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 445 | * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 446 | * |
| 447 | ******************************************************************************/ |
| 448 | acpi_status |
| 449 | acpi_get_gpe_status(acpi_handle gpe_device, |
| 450 | u32 gpe_number, acpi_event_status *event_status) |
| 451 | { |
| 452 | acpi_status status = AE_OK; |
| 453 | struct acpi_gpe_event_info *gpe_event_info; |
| 454 | acpi_cpu_flags flags; |
| 455 | |
| 456 | ACPI_FUNCTION_TRACE(acpi_get_gpe_status); |
| 457 | |
| 458 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 459 | |
| 460 | /* Ensure that we have a valid GPE number */ |
| 461 | |
| 462 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
| 463 | if (!gpe_event_info) { |
| 464 | status = AE_BAD_PARAMETER; |
| 465 | goto unlock_and_exit; |
| 466 | } |
| 467 | |
| 468 | /* Obtain status on the requested GPE number */ |
| 469 | |
| 470 | status = acpi_hw_get_gpe_status(gpe_event_info, event_status); |
| 471 | |
| 472 | if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) |
| 473 | *event_status |= ACPI_EVENT_FLAG_HANDLE; |
| 474 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 475 | unlock_and_exit: |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 476 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 477 | return_ACPI_STATUS(status); |
| 478 | } |
| 479 | |
| 480 | ACPI_EXPORT_SYMBOL(acpi_get_gpe_status) |
| 481 | |
| 482 | /****************************************************************************** |
| 483 | * |
| 484 | * FUNCTION: acpi_disable_all_gpes |
| 485 | * |
| 486 | * PARAMETERS: None |
| 487 | * |
| 488 | * RETURN: Status |
| 489 | * |
| 490 | * DESCRIPTION: Disable and clear all GPEs in all GPE blocks |
| 491 | * |
| 492 | ******************************************************************************/ |
| 493 | |
| 494 | acpi_status acpi_disable_all_gpes(void) |
| 495 | { |
| 496 | acpi_status status; |
| 497 | |
| 498 | ACPI_FUNCTION_TRACE(acpi_disable_all_gpes); |
| 499 | |
| 500 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 501 | if (ACPI_FAILURE(status)) { |
| 502 | return_ACPI_STATUS(status); |
| 503 | } |
| 504 | |
| 505 | status = acpi_hw_disable_all_gpes(); |
| 506 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 507 | |
| 508 | return_ACPI_STATUS(status); |
| 509 | } |
| 510 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 511 | ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes) |
| 512 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 513 | /****************************************************************************** |
| 514 | * |
| 515 | * FUNCTION: acpi_enable_all_runtime_gpes |
| 516 | * |
| 517 | * PARAMETERS: None |
| 518 | * |
| 519 | * RETURN: Status |
| 520 | * |
| 521 | * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks |
| 522 | * |
| 523 | ******************************************************************************/ |
| 524 | |
| 525 | acpi_status acpi_enable_all_runtime_gpes(void) |
| 526 | { |
| 527 | acpi_status status; |
| 528 | |
| 529 | ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes); |
| 530 | |
| 531 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 532 | if (ACPI_FAILURE(status)) { |
| 533 | return_ACPI_STATUS(status); |
| 534 | } |
| 535 | |
| 536 | status = acpi_hw_enable_all_runtime_gpes(); |
| 537 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 538 | |
| 539 | return_ACPI_STATUS(status); |
| 540 | } |
| 541 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 542 | ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes) |
| 543 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 544 | /******************************************************************************* |
| 545 | * |
| 546 | * FUNCTION: acpi_install_gpe_block |
| 547 | * |
| 548 | * PARAMETERS: gpe_device - Handle to the parent GPE Block Device |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 549 | * gpe_block_address - Address and space_ID |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 550 | * register_count - Number of GPE register pairs in the block |
| 551 | * interrupt_number - H/W interrupt for the block |
| 552 | * |
| 553 | * RETURN: Status |
| 554 | * |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 555 | * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not |
| 556 | * enabled here. |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 557 | * |
| 558 | ******************************************************************************/ |
| 559 | acpi_status |
| 560 | acpi_install_gpe_block(acpi_handle gpe_device, |
| 561 | struct acpi_generic_address *gpe_block_address, |
| 562 | u32 register_count, u32 interrupt_number) |
| 563 | { |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 564 | acpi_status status; |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 565 | union acpi_operand_object *obj_desc; |
| 566 | struct acpi_namespace_node *node; |
| 567 | struct acpi_gpe_block_info *gpe_block; |
| 568 | |
| 569 | ACPI_FUNCTION_TRACE(acpi_install_gpe_block); |
| 570 | |
| 571 | if ((!gpe_device) || (!gpe_block_address) || (!register_count)) { |
| 572 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 573 | } |
| 574 | |
| 575 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 576 | if (ACPI_FAILURE(status)) { |
Bob Moore | 68aafc3 | 2012-10-31 02:26:01 +0000 | [diff] [blame] | 577 | return_ACPI_STATUS(status); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | node = acpi_ns_validate_handle(gpe_device); |
| 581 | if (!node) { |
| 582 | status = AE_BAD_PARAMETER; |
| 583 | goto unlock_and_exit; |
| 584 | } |
| 585 | |
Bob Moore | 9186fb5 | 2014-02-08 09:42:19 +0800 | [diff] [blame] | 586 | /* Validate the parent device */ |
| 587 | |
| 588 | if (node->type != ACPI_TYPE_DEVICE) { |
| 589 | status = AE_TYPE; |
| 590 | goto unlock_and_exit; |
| 591 | } |
| 592 | |
| 593 | if (node->object) { |
| 594 | status = AE_ALREADY_EXISTS; |
| 595 | goto unlock_and_exit; |
| 596 | } |
| 597 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 598 | /* |
| 599 | * For user-installed GPE Block Devices, the gpe_block_base_number |
| 600 | * is always zero |
| 601 | */ |
| 602 | status = |
| 603 | acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0, |
| 604 | interrupt_number, &gpe_block); |
| 605 | if (ACPI_FAILURE(status)) { |
| 606 | goto unlock_and_exit; |
| 607 | } |
| 608 | |
| 609 | /* Install block in the device_object attached to the node */ |
| 610 | |
| 611 | obj_desc = acpi_ns_get_attached_object(node); |
| 612 | if (!obj_desc) { |
| 613 | |
| 614 | /* |
| 615 | * No object, create a new one (Device nodes do not always have |
| 616 | * an attached object) |
| 617 | */ |
| 618 | obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE); |
| 619 | if (!obj_desc) { |
| 620 | status = AE_NO_MEMORY; |
| 621 | goto unlock_and_exit; |
| 622 | } |
| 623 | |
| 624 | status = |
| 625 | acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE); |
| 626 | |
| 627 | /* Remove local reference to the object */ |
| 628 | |
| 629 | acpi_ut_remove_reference(obj_desc); |
| 630 | |
| 631 | if (ACPI_FAILURE(status)) { |
| 632 | goto unlock_and_exit; |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | /* Now install the GPE block in the device_object */ |
| 637 | |
| 638 | obj_desc->device.gpe_block = gpe_block; |
| 639 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 640 | unlock_and_exit: |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 641 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 642 | return_ACPI_STATUS(status); |
| 643 | } |
| 644 | |
| 645 | ACPI_EXPORT_SYMBOL(acpi_install_gpe_block) |
| 646 | |
| 647 | /******************************************************************************* |
| 648 | * |
| 649 | * FUNCTION: acpi_remove_gpe_block |
| 650 | * |
| 651 | * PARAMETERS: gpe_device - Handle to the parent GPE Block Device |
| 652 | * |
| 653 | * RETURN: Status |
| 654 | * |
| 655 | * DESCRIPTION: Remove a previously installed block of GPE registers |
| 656 | * |
| 657 | ******************************************************************************/ |
| 658 | acpi_status acpi_remove_gpe_block(acpi_handle gpe_device) |
| 659 | { |
| 660 | union acpi_operand_object *obj_desc; |
| 661 | acpi_status status; |
| 662 | struct acpi_namespace_node *node; |
| 663 | |
| 664 | ACPI_FUNCTION_TRACE(acpi_remove_gpe_block); |
| 665 | |
| 666 | if (!gpe_device) { |
| 667 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 668 | } |
| 669 | |
| 670 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 671 | if (ACPI_FAILURE(status)) { |
Bob Moore | 68aafc3 | 2012-10-31 02:26:01 +0000 | [diff] [blame] | 672 | return_ACPI_STATUS(status); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | node = acpi_ns_validate_handle(gpe_device); |
| 676 | if (!node) { |
| 677 | status = AE_BAD_PARAMETER; |
| 678 | goto unlock_and_exit; |
| 679 | } |
| 680 | |
Bob Moore | 9186fb5 | 2014-02-08 09:42:19 +0800 | [diff] [blame] | 681 | /* Validate the parent device */ |
| 682 | |
| 683 | if (node->type != ACPI_TYPE_DEVICE) { |
| 684 | status = AE_TYPE; |
| 685 | goto unlock_and_exit; |
| 686 | } |
| 687 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 688 | /* Get the device_object attached to the node */ |
| 689 | |
| 690 | obj_desc = acpi_ns_get_attached_object(node); |
| 691 | if (!obj_desc || !obj_desc->device.gpe_block) { |
| 692 | return_ACPI_STATUS(AE_NULL_OBJECT); |
| 693 | } |
| 694 | |
| 695 | /* Delete the GPE block (but not the device_object) */ |
| 696 | |
| 697 | status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block); |
| 698 | if (ACPI_SUCCESS(status)) { |
| 699 | obj_desc->device.gpe_block = NULL; |
| 700 | } |
| 701 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 702 | unlock_and_exit: |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 703 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 704 | return_ACPI_STATUS(status); |
| 705 | } |
| 706 | |
| 707 | ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block) |
| 708 | |
| 709 | /******************************************************************************* |
| 710 | * |
| 711 | * FUNCTION: acpi_get_gpe_device |
| 712 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 713 | * PARAMETERS: index - System GPE index (0-current_gpe_count) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 714 | * gpe_device - Where the parent GPE Device is returned |
| 715 | * |
| 716 | * RETURN: Status |
| 717 | * |
| 718 | * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL |
| 719 | * gpe device indicates that the gpe number is contained in one of |
| 720 | * the FADT-defined gpe blocks. Otherwise, the GPE block device. |
| 721 | * |
| 722 | ******************************************************************************/ |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 723 | acpi_status acpi_get_gpe_device(u32 index, acpi_handle * gpe_device) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 724 | { |
| 725 | struct acpi_gpe_device_info info; |
| 726 | acpi_status status; |
| 727 | |
| 728 | ACPI_FUNCTION_TRACE(acpi_get_gpe_device); |
| 729 | |
| 730 | if (!gpe_device) { |
| 731 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 732 | } |
| 733 | |
| 734 | if (index >= acpi_current_gpe_count) { |
| 735 | return_ACPI_STATUS(AE_NOT_EXIST); |
| 736 | } |
| 737 | |
| 738 | /* Setup and walk the GPE list */ |
| 739 | |
| 740 | info.index = index; |
| 741 | info.status = AE_NOT_EXIST; |
| 742 | info.gpe_device = NULL; |
| 743 | info.next_block_base_index = 0; |
| 744 | |
| 745 | status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info); |
| 746 | if (ACPI_FAILURE(status)) { |
| 747 | return_ACPI_STATUS(status); |
| 748 | } |
| 749 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 750 | *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 751 | return_ACPI_STATUS(info.status); |
| 752 | } |
| 753 | |
| 754 | ACPI_EXPORT_SYMBOL(acpi_get_gpe_device) |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 755 | #endif /* !ACPI_REDUCED_HARDWARE */ |