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 | |
Rafael J. Wysocki | b9ca3d7 | 2014-07-23 13:11:59 +0800 | [diff] [blame] | 129 | /* |
| 130 | * Ensure that we have a valid GPE number and that there is some way |
| 131 | * of handling the GPE (handler or a GPE method). In other words, we |
| 132 | * won't allow a valid GPE to be enabled if there is no way to handle it. |
| 133 | */ |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 134 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
| 135 | if (gpe_event_info) { |
Rafael J. Wysocki | b9ca3d7 | 2014-07-23 13:11:59 +0800 | [diff] [blame] | 136 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) != |
| 137 | ACPI_GPE_DISPATCH_NONE) { |
| 138 | status = acpi_ev_add_gpe_reference(gpe_event_info); |
| 139 | } else { |
| 140 | status = AE_NO_HANDLER; |
| 141 | } |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 145 | return_ACPI_STATUS(status); |
| 146 | } |
| 147 | ACPI_EXPORT_SYMBOL(acpi_enable_gpe) |
| 148 | |
| 149 | /******************************************************************************* |
| 150 | * |
| 151 | * FUNCTION: acpi_disable_gpe |
| 152 | * |
| 153 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
| 154 | * gpe_number - GPE level within the GPE block |
| 155 | * |
| 156 | * RETURN: Status |
| 157 | * |
| 158 | * DESCRIPTION: Remove a reference to a GPE. When the last reference is |
| 159 | * removed, only then is the GPE disabled (for runtime GPEs), or |
| 160 | * the GPE mask bit disabled (for wake GPEs) |
| 161 | * |
| 162 | ******************************************************************************/ |
| 163 | |
| 164 | acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number) |
| 165 | { |
| 166 | acpi_status status = AE_BAD_PARAMETER; |
| 167 | struct acpi_gpe_event_info *gpe_event_info; |
| 168 | acpi_cpu_flags flags; |
| 169 | |
| 170 | ACPI_FUNCTION_TRACE(acpi_disable_gpe); |
| 171 | |
| 172 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 173 | |
| 174 | /* Ensure that we have a valid GPE number */ |
| 175 | |
| 176 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
| 177 | if (gpe_event_info) { |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 178 | status = acpi_ev_remove_gpe_reference(gpe_event_info) ; |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 182 | return_ACPI_STATUS(status); |
| 183 | } |
Lv Zheng | 3e8214e | 2012-12-19 05:37:15 +0000 | [diff] [blame] | 184 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 185 | ACPI_EXPORT_SYMBOL(acpi_disable_gpe) |
| 186 | |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame] | 187 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 188 | /******************************************************************************* |
| 189 | * |
Rafael J. Wysocki | c12f07d | 2014-07-23 13:12:16 +0800 | [diff] [blame] | 190 | * FUNCTION: acpi_mark_gpe_for_wake |
| 191 | * |
| 192 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
| 193 | * gpe_number - GPE level within the GPE block |
| 194 | * |
| 195 | * RETURN: Status |
| 196 | * |
| 197 | * DESCRIPTION: Mark a GPE as having the ability to wake the system. Simply |
| 198 | * sets the ACPI_GPE_CAN_WAKE flag. |
| 199 | * |
| 200 | * Some potential callers of acpi_setup_gpe_for_wake may know in advance that |
| 201 | * there won't be any notify handlers installed for device wake notifications |
| 202 | * from the given GPE (one example is a button GPE in Linux). For these cases, |
| 203 | * acpi_mark_gpe_for_wake should be used instead of acpi_setup_gpe_for_wake. |
| 204 | * This will set the ACPI_GPE_CAN_WAKE flag for the GPE without trying to |
| 205 | * setup implicit wake notification for it (since there's no handler method). |
| 206 | * |
| 207 | ******************************************************************************/ |
| 208 | acpi_status acpi_mark_gpe_for_wake(acpi_handle gpe_device, u32 gpe_number) |
| 209 | { |
| 210 | struct acpi_gpe_event_info *gpe_event_info; |
| 211 | acpi_status status = AE_BAD_PARAMETER; |
| 212 | acpi_cpu_flags flags; |
| 213 | |
| 214 | ACPI_FUNCTION_TRACE(acpi_mark_gpe_for_wake); |
| 215 | |
| 216 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 217 | |
| 218 | /* Ensure that we have a valid GPE number */ |
| 219 | |
| 220 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
| 221 | if (gpe_event_info) { |
| 222 | |
| 223 | /* Mark the GPE as a possible wake event */ |
| 224 | |
| 225 | gpe_event_info->flags |= ACPI_GPE_CAN_WAKE; |
| 226 | status = AE_OK; |
| 227 | } |
| 228 | |
| 229 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 230 | return_ACPI_STATUS(status); |
| 231 | } |
| 232 | |
| 233 | ACPI_EXPORT_SYMBOL(acpi_mark_gpe_for_wake) |
| 234 | |
| 235 | /******************************************************************************* |
| 236 | * |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 237 | * FUNCTION: acpi_setup_gpe_for_wake |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 238 | * |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame] | 239 | * PARAMETERS: wake_device - Device associated with the GPE (via _PRW) |
| 240 | * gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
| 241 | * gpe_number - GPE level within the GPE block |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 242 | * |
| 243 | * RETURN: Status |
| 244 | * |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame] | 245 | * DESCRIPTION: Mark a GPE as having the ability to wake the system. This |
| 246 | * interface is intended to be used as the host executes the |
| 247 | * _PRW methods (Power Resources for Wake) in the system tables. |
| 248 | * Each _PRW appears under a Device Object (The wake_device), and |
| 249 | * contains the info for the wake GPE associated with the |
| 250 | * wake_device. |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 251 | * |
| 252 | ******************************************************************************/ |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame] | 253 | acpi_status |
| 254 | acpi_setup_gpe_for_wake(acpi_handle wake_device, |
| 255 | acpi_handle gpe_device, u32 gpe_number) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 256 | { |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 257 | acpi_status status; |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 258 | struct acpi_gpe_event_info *gpe_event_info; |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame] | 259 | struct acpi_namespace_node *device_node; |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 260 | struct acpi_gpe_notify_info *notify; |
| 261 | struct acpi_gpe_notify_info *new_notify; |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 262 | acpi_cpu_flags flags; |
| 263 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 264 | ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 265 | |
Lin Ming | bba63a2 | 2010-12-13 13:39:17 +0800 | [diff] [blame] | 266 | /* Parameter Validation */ |
| 267 | |
| 268 | if (!wake_device) { |
| 269 | /* |
| 270 | * By forcing wake_device to be valid, we automatically enable the |
| 271 | * implicit notify feature on all hosts. |
| 272 | */ |
| 273 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 274 | } |
| 275 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 276 | /* Handle root object case */ |
| 277 | |
| 278 | if (wake_device == ACPI_ROOT_OBJECT) { |
| 279 | device_node = acpi_gbl_root_node; |
| 280 | } else { |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 281 | device_node = |
| 282 | ACPI_CAST_PTR(struct acpi_namespace_node, wake_device); |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 283 | } |
| 284 | |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 285 | /* Validate wake_device is of type Device */ |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 286 | |
| 287 | if (device_node->type != ACPI_TYPE_DEVICE) { |
| 288 | return_ACPI_STATUS (AE_BAD_PARAMETER); |
| 289 | } |
| 290 | |
| 291 | /* |
| 292 | * Allocate a new notify object up front, in case it is needed. |
| 293 | * Memory allocation while holding a spinlock is a big no-no |
| 294 | * on some hosts. |
| 295 | */ |
| 296 | new_notify = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_notify_info)); |
| 297 | if (!new_notify) { |
| 298 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 299 | } |
| 300 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 301 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 302 | |
| 303 | /* Ensure that we have a valid GPE number */ |
| 304 | |
| 305 | 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] | 306 | if (!gpe_event_info) { |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 307 | status = AE_BAD_PARAMETER; |
Rafael J. Wysocki | 2d55951 | 2011-02-12 01:39:15 +0100 | [diff] [blame] | 308 | goto unlock_and_exit; |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 309 | } |
| 310 | |
Rafael J. Wysocki | 2d55951 | 2011-02-12 01:39:15 +0100 | [diff] [blame] | 311 | /* |
| 312 | * If there is no method or handler for this GPE, then the |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 313 | * wake_device will be notified whenever this GPE fires. This is |
| 314 | * 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] | 315 | * level-triggered (for windows compatibility). |
| 316 | */ |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 317 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
| 318 | ACPI_GPE_DISPATCH_NONE) { |
| 319 | /* |
| 320 | * This is the first device for implicit notify on this GPE. |
| 321 | * Just set the flags here, and enter the NOTIFY block below. |
| 322 | */ |
| 323 | gpe_event_info->flags = |
| 324 | (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED); |
Rafael J. Wysocki | 2d55951 | 2011-02-12 01:39:15 +0100 | [diff] [blame] | 325 | } |
| 326 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 327 | /* |
| 328 | * If we already have an implicit notify on this GPE, add |
| 329 | * this device to the notify list. |
| 330 | */ |
| 331 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
| 332 | ACPI_GPE_DISPATCH_NOTIFY) { |
Rafael J. Wysocki | 981858b | 2011-02-24 19:59:21 +0100 | [diff] [blame] | 333 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 334 | /* Ensure that the device is not already in the list */ |
Rafael J. Wysocki | 981858b | 2011-02-24 19:59:21 +0100 | [diff] [blame] | 335 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 336 | notify = gpe_event_info->dispatch.notify_list; |
| 337 | while (notify) { |
| 338 | if (notify->device_node == device_node) { |
| 339 | status = AE_ALREADY_EXISTS; |
| 340 | goto unlock_and_exit; |
| 341 | } |
| 342 | notify = notify->next; |
Rafael J. Wysocki | 981858b | 2011-02-24 19:59:21 +0100 | [diff] [blame] | 343 | } |
| 344 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 345 | /* Add this device to the notify list for this GPE */ |
| 346 | |
| 347 | new_notify->device_node = device_node; |
| 348 | new_notify->next = gpe_event_info->dispatch.notify_list; |
| 349 | gpe_event_info->dispatch.notify_list = new_notify; |
| 350 | new_notify = NULL; |
Rafael J. Wysocki | 981858b | 2011-02-24 19:59:21 +0100 | [diff] [blame] | 351 | } |
| 352 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 353 | /* Mark the GPE as a possible wake event */ |
| 354 | |
Rafael J. Wysocki | 2d55951 | 2011-02-12 01:39:15 +0100 | [diff] [blame] | 355 | gpe_event_info->flags |= ACPI_GPE_CAN_WAKE; |
| 356 | status = AE_OK; |
| 357 | |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 358 | unlock_and_exit: |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 359 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Bob Moore | 5816b34 | 2012-06-29 10:04:17 +0800 | [diff] [blame] | 360 | |
| 361 | /* Delete the notify object if it was not used above */ |
| 362 | |
| 363 | if (new_notify) { |
| 364 | ACPI_FREE(new_notify); |
| 365 | } |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 366 | return_ACPI_STATUS(status); |
| 367 | } |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 368 | ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 369 | |
| 370 | /******************************************************************************* |
| 371 | * |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 372 | * FUNCTION: acpi_set_gpe_wake_mask |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 373 | * |
| 374 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
| 375 | * gpe_number - GPE level within the GPE block |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 376 | * action - Enable or Disable |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 377 | * |
| 378 | * RETURN: Status |
| 379 | * |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 380 | * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must |
| 381 | * already be marked as a WAKE GPE. |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 382 | * |
| 383 | ******************************************************************************/ |
| 384 | |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 385 | acpi_status |
| 386 | 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] | 387 | { |
| 388 | acpi_status status = AE_OK; |
| 389 | struct acpi_gpe_event_info *gpe_event_info; |
| 390 | struct acpi_gpe_register_info *gpe_register_info; |
| 391 | acpi_cpu_flags flags; |
| 392 | u32 register_bit; |
| 393 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 394 | ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 395 | |
| 396 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 397 | |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 398 | /* |
| 399 | * Ensure that we have a valid GPE number and that this GPE is in |
| 400 | * fact a wake GPE |
| 401 | */ |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 402 | 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] | 403 | if (!gpe_event_info) { |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 404 | status = AE_BAD_PARAMETER; |
| 405 | goto unlock_and_exit; |
| 406 | } |
| 407 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 408 | if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) { |
| 409 | status = AE_TYPE; |
| 410 | goto unlock_and_exit; |
| 411 | } |
| 412 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 413 | gpe_register_info = gpe_event_info->register_info; |
| 414 | if (!gpe_register_info) { |
| 415 | status = AE_NOT_EXIST; |
| 416 | goto unlock_and_exit; |
| 417 | } |
| 418 | |
Feng Tang | 1d94e1e | 2012-08-17 11:10:02 +0800 | [diff] [blame] | 419 | register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 420 | |
| 421 | /* Perform the action */ |
| 422 | |
| 423 | switch (action) { |
| 424 | case ACPI_GPE_ENABLE: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 425 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 426 | ACPI_SET_BIT(gpe_register_info->enable_for_wake, |
| 427 | (u8)register_bit); |
| 428 | break; |
| 429 | |
| 430 | case ACPI_GPE_DISABLE: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 431 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 432 | ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake, |
| 433 | (u8)register_bit); |
| 434 | break; |
| 435 | |
| 436 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 437 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 438 | ACPI_ERROR((AE_INFO, "%u, Invalid action", action)); |
| 439 | status = AE_BAD_PARAMETER; |
| 440 | break; |
| 441 | } |
| 442 | |
| 443 | unlock_and_exit: |
| 444 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 445 | return_ACPI_STATUS(status); |
| 446 | } |
| 447 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 448 | ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 449 | |
| 450 | /******************************************************************************* |
| 451 | * |
| 452 | * FUNCTION: acpi_clear_gpe |
| 453 | * |
| 454 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
| 455 | * gpe_number - GPE level within the GPE block |
| 456 | * |
| 457 | * RETURN: Status |
| 458 | * |
| 459 | * DESCRIPTION: Clear an ACPI event (general purpose) |
| 460 | * |
| 461 | ******************************************************************************/ |
| 462 | acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number) |
| 463 | { |
| 464 | acpi_status status = AE_OK; |
| 465 | struct acpi_gpe_event_info *gpe_event_info; |
| 466 | acpi_cpu_flags flags; |
| 467 | |
| 468 | ACPI_FUNCTION_TRACE(acpi_clear_gpe); |
| 469 | |
| 470 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 471 | |
| 472 | /* Ensure that we have a valid GPE number */ |
| 473 | |
| 474 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
| 475 | if (!gpe_event_info) { |
| 476 | status = AE_BAD_PARAMETER; |
| 477 | goto unlock_and_exit; |
| 478 | } |
| 479 | |
| 480 | status = acpi_hw_clear_gpe(gpe_event_info); |
| 481 | |
| 482 | unlock_and_exit: |
| 483 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 484 | return_ACPI_STATUS(status); |
| 485 | } |
| 486 | |
| 487 | ACPI_EXPORT_SYMBOL(acpi_clear_gpe) |
| 488 | |
| 489 | /******************************************************************************* |
| 490 | * |
| 491 | * FUNCTION: acpi_get_gpe_status |
| 492 | * |
| 493 | * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1 |
| 494 | * gpe_number - GPE level within the GPE block |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 495 | * event_status - Where the current status of the event |
| 496 | * will be returned |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 497 | * |
| 498 | * RETURN: Status |
| 499 | * |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 500 | * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 501 | * |
| 502 | ******************************************************************************/ |
| 503 | acpi_status |
| 504 | acpi_get_gpe_status(acpi_handle gpe_device, |
| 505 | u32 gpe_number, acpi_event_status *event_status) |
| 506 | { |
| 507 | acpi_status status = AE_OK; |
| 508 | struct acpi_gpe_event_info *gpe_event_info; |
| 509 | acpi_cpu_flags flags; |
| 510 | |
| 511 | ACPI_FUNCTION_TRACE(acpi_get_gpe_status); |
| 512 | |
| 513 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 514 | |
| 515 | /* Ensure that we have a valid GPE number */ |
| 516 | |
| 517 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
| 518 | if (!gpe_event_info) { |
| 519 | status = AE_BAD_PARAMETER; |
| 520 | goto unlock_and_exit; |
| 521 | } |
| 522 | |
| 523 | /* Obtain status on the requested GPE number */ |
| 524 | |
| 525 | status = acpi_hw_get_gpe_status(gpe_event_info, event_status); |
| 526 | |
| 527 | if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) |
| 528 | *event_status |= ACPI_EVENT_FLAG_HANDLE; |
| 529 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 530 | unlock_and_exit: |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 531 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 532 | return_ACPI_STATUS(status); |
| 533 | } |
| 534 | |
| 535 | ACPI_EXPORT_SYMBOL(acpi_get_gpe_status) |
| 536 | |
| 537 | /****************************************************************************** |
| 538 | * |
| 539 | * FUNCTION: acpi_disable_all_gpes |
| 540 | * |
| 541 | * PARAMETERS: None |
| 542 | * |
| 543 | * RETURN: Status |
| 544 | * |
| 545 | * DESCRIPTION: Disable and clear all GPEs in all GPE blocks |
| 546 | * |
| 547 | ******************************************************************************/ |
| 548 | |
| 549 | acpi_status acpi_disable_all_gpes(void) |
| 550 | { |
| 551 | acpi_status status; |
| 552 | |
| 553 | ACPI_FUNCTION_TRACE(acpi_disable_all_gpes); |
| 554 | |
| 555 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 556 | if (ACPI_FAILURE(status)) { |
| 557 | return_ACPI_STATUS(status); |
| 558 | } |
| 559 | |
| 560 | status = acpi_hw_disable_all_gpes(); |
| 561 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 562 | |
| 563 | return_ACPI_STATUS(status); |
| 564 | } |
| 565 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 566 | ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes) |
| 567 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 568 | /****************************************************************************** |
| 569 | * |
| 570 | * FUNCTION: acpi_enable_all_runtime_gpes |
| 571 | * |
| 572 | * PARAMETERS: None |
| 573 | * |
| 574 | * RETURN: Status |
| 575 | * |
| 576 | * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks |
| 577 | * |
| 578 | ******************************************************************************/ |
| 579 | |
| 580 | acpi_status acpi_enable_all_runtime_gpes(void) |
| 581 | { |
| 582 | acpi_status status; |
| 583 | |
| 584 | ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes); |
| 585 | |
| 586 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 587 | if (ACPI_FAILURE(status)) { |
| 588 | return_ACPI_STATUS(status); |
| 589 | } |
| 590 | |
| 591 | status = acpi_hw_enable_all_runtime_gpes(); |
| 592 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 593 | |
| 594 | return_ACPI_STATUS(status); |
| 595 | } |
| 596 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 597 | ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes) |
| 598 | |
Rafael J. Wysocki | e0fa975 | 2014-09-30 02:25:42 +0200 | [diff] [blame] | 599 | /****************************************************************************** |
| 600 | * |
| 601 | * FUNCTION: acpi_enable_all_wakeup_gpes |
| 602 | * |
| 603 | * PARAMETERS: None |
| 604 | * |
| 605 | * RETURN: Status |
| 606 | * |
| 607 | * DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in |
| 608 | * all GPE blocks. |
| 609 | * |
| 610 | ******************************************************************************/ |
| 611 | |
| 612 | acpi_status acpi_enable_all_wakeup_gpes(void) |
| 613 | { |
| 614 | acpi_status status; |
| 615 | |
| 616 | ACPI_FUNCTION_TRACE(acpi_enable_all_wakeup_gpes); |
| 617 | |
| 618 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 619 | if (ACPI_FAILURE(status)) { |
| 620 | return_ACPI_STATUS(status); |
| 621 | } |
| 622 | |
| 623 | status = acpi_hw_enable_all_wakeup_gpes(); |
| 624 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 625 | |
| 626 | return_ACPI_STATUS(status); |
| 627 | } |
| 628 | |
| 629 | ACPI_EXPORT_SYMBOL(acpi_enable_all_wakeup_gpes) |
| 630 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 631 | /******************************************************************************* |
| 632 | * |
| 633 | * FUNCTION: acpi_install_gpe_block |
| 634 | * |
| 635 | * PARAMETERS: gpe_device - Handle to the parent GPE Block Device |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 636 | * gpe_block_address - Address and space_ID |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 637 | * register_count - Number of GPE register pairs in the block |
| 638 | * interrupt_number - H/W interrupt for the block |
| 639 | * |
| 640 | * RETURN: Status |
| 641 | * |
Lin Ming | da50337 | 2010-12-13 13:39:37 +0800 | [diff] [blame] | 642 | * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not |
| 643 | * enabled here. |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 644 | * |
| 645 | ******************************************************************************/ |
| 646 | acpi_status |
| 647 | acpi_install_gpe_block(acpi_handle gpe_device, |
| 648 | struct acpi_generic_address *gpe_block_address, |
| 649 | u32 register_count, u32 interrupt_number) |
| 650 | { |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 651 | acpi_status status; |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 652 | union acpi_operand_object *obj_desc; |
| 653 | struct acpi_namespace_node *node; |
| 654 | struct acpi_gpe_block_info *gpe_block; |
| 655 | |
| 656 | ACPI_FUNCTION_TRACE(acpi_install_gpe_block); |
| 657 | |
| 658 | if ((!gpe_device) || (!gpe_block_address) || (!register_count)) { |
| 659 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 660 | } |
| 661 | |
| 662 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 663 | if (ACPI_FAILURE(status)) { |
Bob Moore | 68aafc3 | 2012-10-31 02:26:01 +0000 | [diff] [blame] | 664 | return_ACPI_STATUS(status); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | node = acpi_ns_validate_handle(gpe_device); |
| 668 | if (!node) { |
| 669 | status = AE_BAD_PARAMETER; |
| 670 | goto unlock_and_exit; |
| 671 | } |
| 672 | |
Bob Moore | 9186fb5 | 2014-02-08 09:42:19 +0800 | [diff] [blame] | 673 | /* Validate the parent device */ |
| 674 | |
| 675 | if (node->type != ACPI_TYPE_DEVICE) { |
| 676 | status = AE_TYPE; |
| 677 | goto unlock_and_exit; |
| 678 | } |
| 679 | |
| 680 | if (node->object) { |
| 681 | status = AE_ALREADY_EXISTS; |
| 682 | goto unlock_and_exit; |
| 683 | } |
| 684 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 685 | /* |
| 686 | * For user-installed GPE Block Devices, the gpe_block_base_number |
| 687 | * is always zero |
| 688 | */ |
Bob Moore | 7505da4 | 2014-04-30 10:06:15 +0800 | [diff] [blame] | 689 | status = acpi_ev_create_gpe_block(node, gpe_block_address->address, |
| 690 | gpe_block_address->space_id, |
| 691 | register_count, 0, interrupt_number, |
| 692 | &gpe_block); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 693 | if (ACPI_FAILURE(status)) { |
| 694 | goto unlock_and_exit; |
| 695 | } |
| 696 | |
| 697 | /* Install block in the device_object attached to the node */ |
| 698 | |
| 699 | obj_desc = acpi_ns_get_attached_object(node); |
| 700 | if (!obj_desc) { |
| 701 | |
| 702 | /* |
| 703 | * No object, create a new one (Device nodes do not always have |
| 704 | * an attached object) |
| 705 | */ |
| 706 | obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE); |
| 707 | if (!obj_desc) { |
| 708 | status = AE_NO_MEMORY; |
| 709 | goto unlock_and_exit; |
| 710 | } |
| 711 | |
| 712 | status = |
| 713 | acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE); |
| 714 | |
| 715 | /* Remove local reference to the object */ |
| 716 | |
| 717 | acpi_ut_remove_reference(obj_desc); |
| 718 | |
| 719 | if (ACPI_FAILURE(status)) { |
| 720 | goto unlock_and_exit; |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | /* Now install the GPE block in the device_object */ |
| 725 | |
| 726 | obj_desc->device.gpe_block = gpe_block; |
| 727 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 728 | unlock_and_exit: |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 729 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 730 | return_ACPI_STATUS(status); |
| 731 | } |
| 732 | |
| 733 | ACPI_EXPORT_SYMBOL(acpi_install_gpe_block) |
| 734 | |
| 735 | /******************************************************************************* |
| 736 | * |
| 737 | * FUNCTION: acpi_remove_gpe_block |
| 738 | * |
| 739 | * PARAMETERS: gpe_device - Handle to the parent GPE Block Device |
| 740 | * |
| 741 | * RETURN: Status |
| 742 | * |
| 743 | * DESCRIPTION: Remove a previously installed block of GPE registers |
| 744 | * |
| 745 | ******************************************************************************/ |
| 746 | acpi_status acpi_remove_gpe_block(acpi_handle gpe_device) |
| 747 | { |
| 748 | union acpi_operand_object *obj_desc; |
| 749 | acpi_status status; |
| 750 | struct acpi_namespace_node *node; |
| 751 | |
| 752 | ACPI_FUNCTION_TRACE(acpi_remove_gpe_block); |
| 753 | |
| 754 | if (!gpe_device) { |
| 755 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 756 | } |
| 757 | |
| 758 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 759 | if (ACPI_FAILURE(status)) { |
Bob Moore | 68aafc3 | 2012-10-31 02:26:01 +0000 | [diff] [blame] | 760 | return_ACPI_STATUS(status); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | node = acpi_ns_validate_handle(gpe_device); |
| 764 | if (!node) { |
| 765 | status = AE_BAD_PARAMETER; |
| 766 | goto unlock_and_exit; |
| 767 | } |
| 768 | |
Bob Moore | 9186fb5 | 2014-02-08 09:42:19 +0800 | [diff] [blame] | 769 | /* Validate the parent device */ |
| 770 | |
| 771 | if (node->type != ACPI_TYPE_DEVICE) { |
| 772 | status = AE_TYPE; |
| 773 | goto unlock_and_exit; |
| 774 | } |
| 775 | |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 776 | /* Get the device_object attached to the node */ |
| 777 | |
| 778 | obj_desc = acpi_ns_get_attached_object(node); |
| 779 | if (!obj_desc || !obj_desc->device.gpe_block) { |
| 780 | return_ACPI_STATUS(AE_NULL_OBJECT); |
| 781 | } |
| 782 | |
| 783 | /* Delete the GPE block (but not the device_object) */ |
| 784 | |
| 785 | status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block); |
| 786 | if (ACPI_SUCCESS(status)) { |
| 787 | obj_desc->device.gpe_block = NULL; |
| 788 | } |
| 789 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 790 | unlock_and_exit: |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 791 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 792 | return_ACPI_STATUS(status); |
| 793 | } |
| 794 | |
| 795 | ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block) |
| 796 | |
| 797 | /******************************************************************************* |
| 798 | * |
| 799 | * FUNCTION: acpi_get_gpe_device |
| 800 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 801 | * PARAMETERS: index - System GPE index (0-current_gpe_count) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 802 | * gpe_device - Where the parent GPE Device is returned |
| 803 | * |
| 804 | * RETURN: Status |
| 805 | * |
| 806 | * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL |
| 807 | * gpe device indicates that the gpe number is contained in one of |
| 808 | * the FADT-defined gpe blocks. Otherwise, the GPE block device. |
| 809 | * |
| 810 | ******************************************************************************/ |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 811 | acpi_status acpi_get_gpe_device(u32 index, acpi_handle * gpe_device) |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 812 | { |
| 813 | struct acpi_gpe_device_info info; |
| 814 | acpi_status status; |
| 815 | |
| 816 | ACPI_FUNCTION_TRACE(acpi_get_gpe_device); |
| 817 | |
| 818 | if (!gpe_device) { |
| 819 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 820 | } |
| 821 | |
| 822 | if (index >= acpi_current_gpe_count) { |
| 823 | return_ACPI_STATUS(AE_NOT_EXIST); |
| 824 | } |
| 825 | |
| 826 | /* Setup and walk the GPE list */ |
| 827 | |
| 828 | info.index = index; |
| 829 | info.status = AE_NOT_EXIST; |
| 830 | info.gpe_device = NULL; |
| 831 | info.next_block_base_index = 0; |
| 832 | |
| 833 | status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info); |
| 834 | if (ACPI_FAILURE(status)) { |
| 835 | return_ACPI_STATUS(status); |
| 836 | } |
| 837 | |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 838 | *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device); |
Lin Ming | 3cfd53d | 2010-12-13 13:36:02 +0800 | [diff] [blame] | 839 | return_ACPI_STATUS(info.status); |
| 840 | } |
| 841 | |
| 842 | ACPI_EXPORT_SYMBOL(acpi_get_gpe_device) |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 843 | #endif /* !ACPI_REDUCED_HARDWARE */ |