Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: evxface - External interfaces for ACPI events |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
David E. Box | 82a8094 | 2015-02-05 15:20:45 +0800 | [diff] [blame^] | 8 | * Copyright (C) 2000 - 2015, 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 | |
Lv Zheng | 839e928 | 2013-10-29 09:29:51 +0800 | [diff] [blame] | 44 | #define EXPORT_ACPI_INTERFACES |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 47 | #include "accommon.h" |
| 48 | #include "acnamesp.h" |
| 49 | #include "acevents.h" |
| 50 | #include "acinterp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | #define _COMPONENT ACPI_EVENTS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 53 | ACPI_MODULE_NAME("evxface") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | /******************************************************************************* |
| 57 | * |
| 58 | * FUNCTION: acpi_install_notify_handler |
| 59 | * |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 60 | * PARAMETERS: device - The device for which notifies will be handled |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | * handler_type - The type of handler: |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 62 | * ACPI_SYSTEM_NOTIFY: System Handler (00-7F) |
| 63 | * ACPI_DEVICE_NOTIFY: Device Handler (80-FF) |
| 64 | * ACPI_ALL_NOTIFY: Both System and Device |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 65 | * handler - Address of the handler |
| 66 | * context - Value passed to the handler on each GPE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | * |
| 68 | * RETURN: Status |
| 69 | * |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 70 | * DESCRIPTION: Install a handler for notifications on an ACPI Device, |
| 71 | * thermal_zone, or Processor object. |
| 72 | * |
| 73 | * NOTES: The Root namespace object may have only one handler for each |
| 74 | * type of notify (System/Device). Device/Thermal/Processor objects |
| 75 | * may have one device notify handler, and multiple system notify |
| 76 | * handlers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | * |
| 78 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | acpi_install_notify_handler(acpi_handle device, |
| 81 | u32 handler_type, |
| 82 | acpi_notify_handler handler, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 84 | struct acpi_namespace_node *node = |
| 85 | ACPI_CAST_PTR(struct acpi_namespace_node, device); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | union acpi_operand_object *obj_desc; |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 87 | union acpi_operand_object *handler_obj; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 88 | acpi_status status; |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 89 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 91 | ACPI_FUNCTION_TRACE(acpi_install_notify_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | /* Parameter validation */ |
| 94 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 95 | if ((!device) || (!handler) || (!handler_type) || |
| 96 | (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 97 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 100 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 101 | if (ACPI_FAILURE(status)) { |
| 102 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | /* |
| 106 | * Root Object: |
| 107 | * Registering a notify handler on the root object indicates that the |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 108 | * caller wishes to receive notifications for all objects. Note that |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 109 | * only one global handler can be registered per notify type. |
| 110 | * Ensure that a handler is not already installed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | */ |
| 112 | if (device == ACPI_ROOT_OBJECT) { |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 113 | for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { |
| 114 | if (handler_type & (i + 1)) { |
| 115 | if (acpi_gbl_global_notify[i].handler) { |
Rafael J. Wysocki | 3f0be67 | 2010-02-17 23:42:59 +0100 | [diff] [blame] | 116 | status = AE_ALREADY_EXISTS; |
| 117 | goto unlock_and_exit; |
| 118 | } |
| 119 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 120 | acpi_gbl_global_notify[i].handler = handler; |
| 121 | acpi_gbl_global_notify[i].context = context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 125 | goto unlock_and_exit; /* Global notify handler installed, all done */ |
| 126 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 128 | /* |
| 129 | * All Other Objects: |
| 130 | * Caller will only receive notifications specific to the target |
| 131 | * object. Note that only certain object types are allowed to |
| 132 | * receive notifications. |
| 133 | */ |
| 134 | |
| 135 | /* Are Notifies allowed on this object? */ |
| 136 | |
| 137 | if (!acpi_ev_is_notify_object(node)) { |
| 138 | status = AE_TYPE; |
| 139 | goto unlock_and_exit; |
| 140 | } |
| 141 | |
| 142 | /* Check for an existing internal object, might not exist */ |
| 143 | |
| 144 | obj_desc = acpi_ns_get_attached_object(node); |
| 145 | if (!obj_desc) { |
| 146 | |
| 147 | /* Create a new object */ |
| 148 | |
| 149 | obj_desc = acpi_ut_create_internal_object(node->type); |
| 150 | if (!obj_desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | status = AE_NO_MEMORY; |
| 152 | goto unlock_and_exit; |
| 153 | } |
| 154 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 155 | /* Attach new object to the Node, remove local reference */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 157 | status = acpi_ns_attach_object(device, obj_desc, node->type); |
| 158 | acpi_ut_remove_reference(obj_desc); |
| 159 | if (ACPI_FAILURE(status)) { |
| 160 | goto unlock_and_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 164 | /* Ensure that the handler is not already installed in the lists */ |
| 165 | |
| 166 | for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { |
| 167 | if (handler_type & (i + 1)) { |
| 168 | handler_obj = obj_desc->common_notify.notify_list[i]; |
| 169 | while (handler_obj) { |
| 170 | if (handler_obj->notify.handler == handler) { |
| 171 | status = AE_ALREADY_EXISTS; |
| 172 | goto unlock_and_exit; |
| 173 | } |
| 174 | |
| 175 | handler_obj = handler_obj->notify.next[i]; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /* Create and populate a new notify handler object */ |
| 181 | |
| 182 | handler_obj = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY); |
| 183 | if (!handler_obj) { |
| 184 | status = AE_NO_MEMORY; |
| 185 | goto unlock_and_exit; |
| 186 | } |
| 187 | |
| 188 | handler_obj->notify.node = node; |
| 189 | handler_obj->notify.handler_type = handler_type; |
| 190 | handler_obj->notify.handler = handler; |
| 191 | handler_obj->notify.context = context; |
| 192 | |
| 193 | /* Install the handler at the list head(s) */ |
| 194 | |
| 195 | for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { |
| 196 | if (handler_type & (i + 1)) { |
| 197 | handler_obj->notify.next[i] = |
| 198 | obj_desc->common_notify.notify_list[i]; |
| 199 | |
| 200 | obj_desc->common_notify.notify_list[i] = handler_obj; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /* Add an extra reference if handler was installed in both lists */ |
| 205 | |
| 206 | if (handler_type == ACPI_ALL_NOTIFY) { |
| 207 | acpi_ut_add_reference(handler_obj); |
| 208 | } |
| 209 | |
| 210 | unlock_and_exit: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 211 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 212 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 215 | ACPI_EXPORT_SYMBOL(acpi_install_notify_handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | /******************************************************************************* |
| 218 | * |
| 219 | * FUNCTION: acpi_remove_notify_handler |
| 220 | * |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 221 | * PARAMETERS: device - The device for which the handler is installed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | * handler_type - The type of handler: |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 223 | * ACPI_SYSTEM_NOTIFY: System Handler (00-7F) |
| 224 | * ACPI_DEVICE_NOTIFY: Device Handler (80-FF) |
| 225 | * ACPI_ALL_NOTIFY: Both System and Device |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 226 | * handler - Address of the handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | * |
| 228 | * RETURN: Status |
| 229 | * |
| 230 | * DESCRIPTION: Remove a handler for notifies on an ACPI device |
| 231 | * |
| 232 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 234 | acpi_remove_notify_handler(acpi_handle device, |
| 235 | u32 handler_type, acpi_notify_handler handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 237 | struct acpi_namespace_node *node = |
| 238 | ACPI_CAST_PTR(struct acpi_namespace_node, device); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 239 | union acpi_operand_object *obj_desc; |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 240 | union acpi_operand_object *handler_obj; |
| 241 | union acpi_operand_object *previous_handler_obj; |
Lv Zheng | 69c841b | 2014-04-04 12:37:51 +0800 | [diff] [blame] | 242 | acpi_status status = AE_OK; |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 243 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 245 | ACPI_FUNCTION_TRACE(acpi_remove_notify_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | /* Parameter validation */ |
| 248 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 249 | if ((!device) || (!handler) || (!handler_type) || |
| 250 | (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { |
| 251 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
Lv Zheng | 3e8214e | 2012-12-19 05:37:15 +0000 | [diff] [blame] | 253 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 254 | /* Root Object. Global handlers are removed here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 256 | if (device == ACPI_ROOT_OBJECT) { |
| 257 | for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { |
| 258 | if (handler_type & (i + 1)) { |
Lv Zheng | 69c841b | 2014-04-04 12:37:51 +0800 | [diff] [blame] | 259 | status = |
| 260 | acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 261 | if (ACPI_FAILURE(status)) { |
| 262 | return_ACPI_STATUS(status); |
| 263 | } |
| 264 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 265 | if (!acpi_gbl_global_notify[i].handler || |
| 266 | (acpi_gbl_global_notify[i].handler != |
| 267 | handler)) { |
| 268 | status = AE_NOT_EXIST; |
| 269 | goto unlock_and_exit; |
| 270 | } |
| 271 | |
| 272 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 273 | "Removing global notify handler\n")); |
| 274 | |
| 275 | acpi_gbl_global_notify[i].handler = NULL; |
| 276 | acpi_gbl_global_notify[i].context = NULL; |
Lv Zheng | 69c841b | 2014-04-04 12:37:51 +0800 | [diff] [blame] | 277 | |
| 278 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 279 | |
| 280 | /* Make sure all deferred notify tasks are completed */ |
| 281 | |
| 282 | acpi_os_wait_events_complete(); |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | |
Lv Zheng | 69c841b | 2014-04-04 12:37:51 +0800 | [diff] [blame] | 286 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 289 | /* All other objects: Are Notifies allowed on this object? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 291 | if (!acpi_ev_is_notify_object(node)) { |
Lv Zheng | 69c841b | 2014-04-04 12:37:51 +0800 | [diff] [blame] | 292 | return_ACPI_STATUS(AE_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 295 | /* Must have an existing internal object */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 297 | obj_desc = acpi_ns_get_attached_object(node); |
| 298 | if (!obj_desc) { |
Lv Zheng | 69c841b | 2014-04-04 12:37:51 +0800 | [diff] [blame] | 299 | return_ACPI_STATUS(AE_NOT_EXIST); |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 300 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 302 | /* Internal object exists. Find the handler and remove it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 304 | for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) { |
| 305 | if (handler_type & (i + 1)) { |
Lv Zheng | 69c841b | 2014-04-04 12:37:51 +0800 | [diff] [blame] | 306 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 307 | if (ACPI_FAILURE(status)) { |
| 308 | return_ACPI_STATUS(status); |
| 309 | } |
| 310 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 311 | handler_obj = obj_desc->common_notify.notify_list[i]; |
| 312 | previous_handler_obj = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 314 | /* Attempt to find the handler in the handler list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 316 | while (handler_obj && |
| 317 | (handler_obj->notify.handler != handler)) { |
| 318 | previous_handler_obj = handler_obj; |
| 319 | handler_obj = handler_obj->notify.next[i]; |
| 320 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 322 | if (!handler_obj) { |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 323 | status = AE_NOT_EXIST; |
| 324 | goto unlock_and_exit; |
| 325 | } |
| 326 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 327 | /* Remove the handler object from the list */ |
| 328 | |
| 329 | if (previous_handler_obj) { /* Handler is not at the list head */ |
| 330 | previous_handler_obj->notify.next[i] = |
| 331 | handler_obj->notify.next[i]; |
| 332 | } else { /* Handler is at the list head */ |
| 333 | |
| 334 | obj_desc->common_notify.notify_list[i] = |
| 335 | handler_obj->notify.next[i]; |
Rafael J. Wysocki | 3f0be67 | 2010-02-17 23:42:59 +0100 | [diff] [blame] | 336 | } |
| 337 | |
Lv Zheng | 69c841b | 2014-04-04 12:37:51 +0800 | [diff] [blame] | 338 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 339 | |
| 340 | /* Make sure all deferred notify tasks are completed */ |
| 341 | |
| 342 | acpi_os_wait_events_complete(); |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 343 | acpi_ut_remove_reference(handler_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
Lv Zheng | 69c841b | 2014-04-04 12:37:51 +0800 | [diff] [blame] | 347 | return_ACPI_STATUS(status); |
| 348 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 349 | unlock_and_exit: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 350 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 351 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 354 | ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | /******************************************************************************* |
| 357 | * |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 358 | * FUNCTION: acpi_install_exception_handler |
| 359 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 360 | * PARAMETERS: handler - Pointer to the handler function for the |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 361 | * event |
| 362 | * |
| 363 | * RETURN: Status |
| 364 | * |
| 365 | * DESCRIPTION: Saves the pointer to the handler function |
| 366 | * |
| 367 | ******************************************************************************/ |
| 368 | #ifdef ACPI_FUTURE_USAGE |
| 369 | acpi_status acpi_install_exception_handler(acpi_exception_handler handler) |
| 370 | { |
| 371 | acpi_status status; |
| 372 | |
| 373 | ACPI_FUNCTION_TRACE(acpi_install_exception_handler); |
| 374 | |
| 375 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 376 | if (ACPI_FAILURE(status)) { |
| 377 | return_ACPI_STATUS(status); |
| 378 | } |
| 379 | |
| 380 | /* Don't allow two handlers. */ |
| 381 | |
| 382 | if (acpi_gbl_exception_handler) { |
| 383 | status = AE_ALREADY_EXISTS; |
| 384 | goto cleanup; |
| 385 | } |
| 386 | |
| 387 | /* Install the handler */ |
| 388 | |
| 389 | acpi_gbl_exception_handler = handler; |
| 390 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 391 | cleanup: |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 392 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 393 | return_ACPI_STATUS(status); |
| 394 | } |
| 395 | |
| 396 | ACPI_EXPORT_SYMBOL(acpi_install_exception_handler) |
| 397 | #endif /* ACPI_FUTURE_USAGE */ |
| 398 | |
| 399 | #if (!ACPI_REDUCED_HARDWARE) |
| 400 | /******************************************************************************* |
| 401 | * |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 402 | * FUNCTION: acpi_install_sci_handler |
| 403 | * |
| 404 | * PARAMETERS: address - Address of the handler |
| 405 | * context - Value passed to the handler on each SCI |
| 406 | * |
| 407 | * RETURN: Status |
| 408 | * |
| 409 | * DESCRIPTION: Install a handler for a System Control Interrupt. |
| 410 | * |
| 411 | ******************************************************************************/ |
| 412 | acpi_status acpi_install_sci_handler(acpi_sci_handler address, void *context) |
| 413 | { |
| 414 | struct acpi_sci_handler_info *new_sci_handler; |
| 415 | struct acpi_sci_handler_info *sci_handler; |
| 416 | acpi_cpu_flags flags; |
| 417 | acpi_status status; |
| 418 | |
| 419 | ACPI_FUNCTION_TRACE(acpi_install_sci_handler); |
| 420 | |
| 421 | if (!address) { |
| 422 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 423 | } |
| 424 | |
| 425 | /* Allocate and init a handler object */ |
| 426 | |
| 427 | new_sci_handler = ACPI_ALLOCATE(sizeof(struct acpi_sci_handler_info)); |
| 428 | if (!new_sci_handler) { |
| 429 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 430 | } |
| 431 | |
| 432 | new_sci_handler->address = address; |
| 433 | new_sci_handler->context = context; |
| 434 | |
| 435 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 436 | if (ACPI_FAILURE(status)) { |
| 437 | goto exit; |
| 438 | } |
| 439 | |
| 440 | /* Lock list during installation */ |
| 441 | |
| 442 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 443 | sci_handler = acpi_gbl_sci_handler_list; |
| 444 | |
| 445 | /* Ensure handler does not already exist */ |
| 446 | |
| 447 | while (sci_handler) { |
| 448 | if (address == sci_handler->address) { |
| 449 | status = AE_ALREADY_EXISTS; |
| 450 | goto unlock_and_exit; |
| 451 | } |
| 452 | |
| 453 | sci_handler = sci_handler->next; |
| 454 | } |
| 455 | |
| 456 | /* Install the new handler into the global list (at head) */ |
| 457 | |
| 458 | new_sci_handler->next = acpi_gbl_sci_handler_list; |
| 459 | acpi_gbl_sci_handler_list = new_sci_handler; |
| 460 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 461 | unlock_and_exit: |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 462 | |
| 463 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 464 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 465 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 466 | exit: |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 467 | if (ACPI_FAILURE(status)) { |
| 468 | ACPI_FREE(new_sci_handler); |
| 469 | } |
| 470 | return_ACPI_STATUS(status); |
| 471 | } |
| 472 | |
Bob Moore | 1d44efa | 2014-04-04 12:36:47 +0800 | [diff] [blame] | 473 | ACPI_EXPORT_SYMBOL(acpi_install_sci_handler) |
| 474 | |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 475 | /******************************************************************************* |
| 476 | * |
| 477 | * FUNCTION: acpi_remove_sci_handler |
| 478 | * |
| 479 | * PARAMETERS: address - Address of the handler |
| 480 | * |
| 481 | * RETURN: Status |
| 482 | * |
| 483 | * DESCRIPTION: Remove a handler for a System Control Interrupt. |
| 484 | * |
| 485 | ******************************************************************************/ |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 486 | acpi_status acpi_remove_sci_handler(acpi_sci_handler address) |
| 487 | { |
| 488 | struct acpi_sci_handler_info *prev_sci_handler; |
| 489 | struct acpi_sci_handler_info *next_sci_handler; |
| 490 | acpi_cpu_flags flags; |
| 491 | acpi_status status; |
| 492 | |
| 493 | ACPI_FUNCTION_TRACE(acpi_remove_sci_handler); |
| 494 | |
| 495 | if (!address) { |
| 496 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 497 | } |
| 498 | |
| 499 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 500 | if (ACPI_FAILURE(status)) { |
| 501 | return_ACPI_STATUS(status); |
| 502 | } |
| 503 | |
| 504 | /* Remove the SCI handler with lock */ |
| 505 | |
| 506 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 507 | |
| 508 | prev_sci_handler = NULL; |
| 509 | next_sci_handler = acpi_gbl_sci_handler_list; |
| 510 | while (next_sci_handler) { |
| 511 | if (next_sci_handler->address == address) { |
| 512 | |
| 513 | /* Unlink and free the SCI handler info block */ |
| 514 | |
| 515 | if (prev_sci_handler) { |
| 516 | prev_sci_handler->next = next_sci_handler->next; |
| 517 | } else { |
| 518 | acpi_gbl_sci_handler_list = |
| 519 | next_sci_handler->next; |
| 520 | } |
| 521 | |
| 522 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 523 | ACPI_FREE(next_sci_handler); |
| 524 | goto unlock_and_exit; |
| 525 | } |
| 526 | |
| 527 | prev_sci_handler = next_sci_handler; |
| 528 | next_sci_handler = next_sci_handler->next; |
| 529 | } |
| 530 | |
| 531 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 532 | status = AE_NOT_EXIST; |
| 533 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 534 | unlock_and_exit: |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 535 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 536 | return_ACPI_STATUS(status); |
| 537 | } |
| 538 | |
Bob Moore | 1d44efa | 2014-04-04 12:36:47 +0800 | [diff] [blame] | 539 | ACPI_EXPORT_SYMBOL(acpi_remove_sci_handler) |
| 540 | |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 541 | /******************************************************************************* |
| 542 | * |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 543 | * FUNCTION: acpi_install_global_event_handler |
| 544 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 545 | * PARAMETERS: handler - Pointer to the global event handler function |
| 546 | * context - Value passed to the handler on each event |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 547 | * |
| 548 | * RETURN: Status |
| 549 | * |
| 550 | * DESCRIPTION: Saves the pointer to the handler function. The global handler |
| 551 | * is invoked upon each incoming GPE and Fixed Event. It is |
| 552 | * invoked at interrupt level at the time of the event dispatch. |
| 553 | * Can be used to update event counters, etc. |
| 554 | * |
| 555 | ******************************************************************************/ |
| 556 | acpi_status |
Lv Zheng | 644ef74 | 2012-10-31 02:25:36 +0000 | [diff] [blame] | 557 | acpi_install_global_event_handler(acpi_gbl_event_handler handler, void *context) |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 558 | { |
| 559 | acpi_status status; |
| 560 | |
| 561 | ACPI_FUNCTION_TRACE(acpi_install_global_event_handler); |
| 562 | |
| 563 | /* Parameter validation */ |
| 564 | |
| 565 | if (!handler) { |
| 566 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 567 | } |
| 568 | |
| 569 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 570 | if (ACPI_FAILURE(status)) { |
| 571 | return_ACPI_STATUS(status); |
| 572 | } |
| 573 | |
| 574 | /* Don't allow two handlers. */ |
| 575 | |
| 576 | if (acpi_gbl_global_event_handler) { |
| 577 | status = AE_ALREADY_EXISTS; |
| 578 | goto cleanup; |
| 579 | } |
| 580 | |
| 581 | acpi_gbl_global_event_handler = handler; |
| 582 | acpi_gbl_global_event_handler_context = context; |
| 583 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 584 | cleanup: |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 585 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 586 | return_ACPI_STATUS(status); |
| 587 | } |
| 588 | |
| 589 | ACPI_EXPORT_SYMBOL(acpi_install_global_event_handler) |
| 590 | |
| 591 | /******************************************************************************* |
| 592 | * |
| 593 | * FUNCTION: acpi_install_fixed_event_handler |
| 594 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 595 | * PARAMETERS: event - Event type to enable. |
| 596 | * handler - Pointer to the handler function for the |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 597 | * event |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 598 | * context - Value passed to the handler on each GPE |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 599 | * |
| 600 | * RETURN: Status |
| 601 | * |
| 602 | * DESCRIPTION: Saves the pointer to the handler function and then enables the |
| 603 | * event. |
| 604 | * |
| 605 | ******************************************************************************/ |
| 606 | acpi_status |
| 607 | acpi_install_fixed_event_handler(u32 event, |
| 608 | acpi_event_handler handler, void *context) |
| 609 | { |
| 610 | acpi_status status; |
| 611 | |
| 612 | ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler); |
| 613 | |
| 614 | /* Parameter validation */ |
| 615 | |
| 616 | if (event > ACPI_EVENT_MAX) { |
| 617 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 618 | } |
| 619 | |
| 620 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 621 | if (ACPI_FAILURE(status)) { |
| 622 | return_ACPI_STATUS(status); |
| 623 | } |
| 624 | |
Bob Moore | d4d3219 | 2013-03-08 09:21:41 +0000 | [diff] [blame] | 625 | /* Do not allow multiple handlers */ |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 626 | |
Bob Moore | d4d3219 | 2013-03-08 09:21:41 +0000 | [diff] [blame] | 627 | if (acpi_gbl_fixed_event_handlers[event].handler) { |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 628 | status = AE_ALREADY_EXISTS; |
| 629 | goto cleanup; |
| 630 | } |
| 631 | |
| 632 | /* Install the handler before enabling the event */ |
| 633 | |
| 634 | acpi_gbl_fixed_event_handlers[event].handler = handler; |
| 635 | acpi_gbl_fixed_event_handlers[event].context = context; |
| 636 | |
| 637 | status = acpi_clear_event(event); |
| 638 | if (ACPI_SUCCESS(status)) |
| 639 | status = acpi_enable_event(event, 0); |
| 640 | if (ACPI_FAILURE(status)) { |
Bob Moore | d4d3219 | 2013-03-08 09:21:41 +0000 | [diff] [blame] | 641 | ACPI_WARNING((AE_INFO, |
| 642 | "Could not enable fixed event - %s (%u)", |
| 643 | acpi_ut_get_event_name(event), event)); |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 644 | |
| 645 | /* Remove the handler */ |
| 646 | |
| 647 | acpi_gbl_fixed_event_handlers[event].handler = NULL; |
| 648 | acpi_gbl_fixed_event_handlers[event].context = NULL; |
| 649 | } else { |
| 650 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bob Moore | d4d3219 | 2013-03-08 09:21:41 +0000 | [diff] [blame] | 651 | "Enabled fixed event %s (%X), Handler=%p\n", |
| 652 | acpi_ut_get_event_name(event), event, |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 653 | handler)); |
| 654 | } |
| 655 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 656 | cleanup: |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 657 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 658 | return_ACPI_STATUS(status); |
| 659 | } |
| 660 | |
| 661 | ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler) |
| 662 | |
| 663 | /******************************************************************************* |
| 664 | * |
| 665 | * FUNCTION: acpi_remove_fixed_event_handler |
| 666 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 667 | * PARAMETERS: event - Event type to disable. |
| 668 | * handler - Address of the handler |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 669 | * |
| 670 | * RETURN: Status |
| 671 | * |
| 672 | * DESCRIPTION: Disables the event and unregisters the event handler. |
| 673 | * |
| 674 | ******************************************************************************/ |
| 675 | acpi_status |
| 676 | acpi_remove_fixed_event_handler(u32 event, acpi_event_handler handler) |
| 677 | { |
| 678 | acpi_status status = AE_OK; |
| 679 | |
| 680 | ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler); |
| 681 | |
| 682 | /* Parameter validation */ |
| 683 | |
| 684 | if (event > ACPI_EVENT_MAX) { |
| 685 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 686 | } |
| 687 | |
| 688 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 689 | if (ACPI_FAILURE(status)) { |
| 690 | return_ACPI_STATUS(status); |
| 691 | } |
| 692 | |
| 693 | /* Disable the event before removing the handler */ |
| 694 | |
| 695 | status = acpi_disable_event(event, 0); |
| 696 | |
| 697 | /* Always Remove the handler */ |
| 698 | |
| 699 | acpi_gbl_fixed_event_handlers[event].handler = NULL; |
| 700 | acpi_gbl_fixed_event_handlers[event].context = NULL; |
| 701 | |
| 702 | if (ACPI_FAILURE(status)) { |
| 703 | ACPI_WARNING((AE_INFO, |
Bob Moore | d4d3219 | 2013-03-08 09:21:41 +0000 | [diff] [blame] | 704 | "Could not disable fixed event - %s (%u)", |
| 705 | acpi_ut_get_event_name(event), event)); |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 706 | } else { |
Bob Moore | d4d3219 | 2013-03-08 09:21:41 +0000 | [diff] [blame] | 707 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 708 | "Disabled fixed event - %s (%X)\n", |
| 709 | acpi_ut_get_event_name(event), event)); |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 713 | return_ACPI_STATUS(status); |
| 714 | } |
| 715 | |
| 716 | ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler) |
| 717 | |
| 718 | /******************************************************************************* |
| 719 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | * FUNCTION: acpi_install_gpe_handler |
| 721 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 722 | * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT |
| 723 | * defined GPEs) |
| 724 | * gpe_number - The GPE number within the GPE block |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 725 | * type - Whether this GPE should be treated as an |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | * edge- or level-triggered interrupt. |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 727 | * address - Address of the handler |
| 728 | * context - Value passed to the handler on each GPE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | * |
| 730 | * RETURN: Status |
| 731 | * |
| 732 | * DESCRIPTION: Install a handler for a General Purpose Event. |
| 733 | * |
| 734 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 736 | acpi_install_gpe_handler(acpi_handle gpe_device, |
| 737 | u32 gpe_number, |
Lin Ming | 8b6cd8a | 2010-12-13 13:38:46 +0800 | [diff] [blame] | 738 | u32 type, acpi_gpe_handler address, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 740 | struct acpi_gpe_event_info *gpe_event_info; |
Lin Ming | 8b6cd8a | 2010-12-13 13:38:46 +0800 | [diff] [blame] | 741 | struct acpi_gpe_handler_info *handler; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 742 | acpi_status status; |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 743 | acpi_cpu_flags flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 745 | ACPI_FUNCTION_TRACE(acpi_install_gpe_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
| 747 | /* Parameter validation */ |
| 748 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 749 | if ((!address) || (type & ~ACPI_GPE_XRUPT_TYPE_MASK)) { |
| 750 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 753 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 754 | if (ACPI_FAILURE(status)) { |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 755 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 758 | /* Allocate and init handler object (before lock) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
Lin Ming | 8b6cd8a | 2010-12-13 13:38:46 +0800 | [diff] [blame] | 760 | handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_handler_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | if (!handler) { |
| 762 | status = AE_NO_MEMORY; |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 763 | goto unlock_and_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 766 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 767 | |
| 768 | /* Ensure that we have a valid GPE number */ |
| 769 | |
| 770 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
| 771 | if (!gpe_event_info) { |
| 772 | status = AE_BAD_PARAMETER; |
| 773 | goto free_and_exit; |
| 774 | } |
| 775 | |
| 776 | /* Make sure that there isn't a handler there already */ |
| 777 | |
Lv Zheng | 7c43312 | 2015-02-05 15:20:29 +0800 | [diff] [blame] | 778 | if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) == |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 779 | ACPI_GPE_DISPATCH_HANDLER) { |
| 780 | status = AE_ALREADY_EXISTS; |
| 781 | goto free_and_exit; |
| 782 | } |
| 783 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 784 | handler->address = address; |
| 785 | handler->context = context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | handler->method_node = gpe_event_info->dispatch.method_node; |
Lv Zheng | 3e8214e | 2012-12-19 05:37:15 +0000 | [diff] [blame] | 787 | handler->original_flags = (u8)(gpe_event_info->flags & |
| 788 | (ACPI_GPE_XRUPT_TYPE_MASK | |
Lv Zheng | f19f1a7 | 2014-10-10 10:39:39 +0800 | [diff] [blame] | 789 | ACPI_GPE_DISPATCH_MASK)); |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 790 | |
| 791 | /* |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 792 | * If the GPE is associated with a method, it may have been enabled |
Rafael J. Wysocki | a210080 | 2010-09-16 00:30:43 +0200 | [diff] [blame] | 793 | * automatically during initialization, in which case it has to be |
| 794 | * disabled now to avoid spurious execution of the handler. |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 795 | */ |
Lv Zheng | 7c43312 | 2015-02-05 15:20:29 +0800 | [diff] [blame] | 796 | if (((ACPI_GPE_DISPATCH_TYPE(handler->original_flags) == |
| 797 | ACPI_GPE_DISPATCH_METHOD) || |
| 798 | (ACPI_GPE_DISPATCH_TYPE(handler->original_flags) == |
| 799 | ACPI_GPE_DISPATCH_NOTIFY)) && gpe_event_info->runtime_count) { |
Lv Zheng | 437b751 | 2014-10-10 10:39:45 +0800 | [diff] [blame] | 800 | handler->originally_enabled = TRUE; |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 801 | (void)acpi_ev_remove_gpe_reference(gpe_event_info); |
Lv Zheng | 437b751 | 2014-10-10 10:39:45 +0800 | [diff] [blame] | 802 | |
| 803 | /* Sanity check of original type against new type */ |
| 804 | |
| 805 | if (type != |
| 806 | (u32)(gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK)) { |
| 807 | ACPI_WARNING((AE_INFO, |
| 808 | "GPE type mismatch (level/edge)")); |
| 809 | } |
Rafael J. Wysocki | a210080 | 2010-09-16 00:30:43 +0200 | [diff] [blame] | 810 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | /* Install the handler */ |
| 813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | gpe_event_info->dispatch.handler = handler; |
| 815 | |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 816 | /* Setup up dispatch flags to indicate handler (vs. method/notify) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 818 | gpe_event_info->flags &= |
| 819 | ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); |
Lv Zheng | f19f1a7 | 2014-10-10 10:39:39 +0800 | [diff] [blame] | 820 | gpe_event_info->flags |= (u8)(type | ACPI_GPE_DISPATCH_HANDLER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 822 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
Lin Ming | 0f849d2 | 2010-04-06 14:52:37 +0800 | [diff] [blame] | 824 | unlock_and_exit: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 825 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 826 | return_ACPI_STATUS(status); |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 827 | |
| 828 | free_and_exit: |
| 829 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 830 | ACPI_FREE(handler); |
| 831 | goto unlock_and_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 834 | ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
| 836 | /******************************************************************************* |
| 837 | * |
| 838 | * FUNCTION: acpi_remove_gpe_handler |
| 839 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 840 | * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT |
| 841 | * defined GPEs) |
| 842 | * gpe_number - The event to remove a handler |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 843 | * address - Address of the handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | * |
| 845 | * RETURN: Status |
| 846 | * |
| 847 | * DESCRIPTION: Remove a handler for a General Purpose acpi_event. |
| 848 | * |
| 849 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 851 | acpi_remove_gpe_handler(acpi_handle gpe_device, |
Lin Ming | 8b6cd8a | 2010-12-13 13:38:46 +0800 | [diff] [blame] | 852 | u32 gpe_number, acpi_gpe_handler address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 854 | struct acpi_gpe_event_info *gpe_event_info; |
Lin Ming | 8b6cd8a | 2010-12-13 13:38:46 +0800 | [diff] [blame] | 855 | struct acpi_gpe_handler_info *handler; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 856 | acpi_status status; |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 857 | acpi_cpu_flags flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 859 | ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
| 861 | /* Parameter validation */ |
| 862 | |
| 863 | if (!address) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 864 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 867 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); |
| 868 | if (ACPI_FAILURE(status)) { |
| 869 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 872 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | /* Ensure that we have a valid GPE number */ |
| 875 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 876 | gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | if (!gpe_event_info) { |
| 878 | status = AE_BAD_PARAMETER; |
| 879 | goto unlock_and_exit; |
| 880 | } |
| 881 | |
| 882 | /* Make sure that a handler is indeed installed */ |
| 883 | |
Lv Zheng | 7c43312 | 2015-02-05 15:20:29 +0800 | [diff] [blame] | 884 | if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) != |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 885 | ACPI_GPE_DISPATCH_HANDLER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | status = AE_NOT_EXIST; |
| 887 | goto unlock_and_exit; |
| 888 | } |
| 889 | |
| 890 | /* Make sure that the installed handler is the same */ |
| 891 | |
| 892 | if (gpe_event_info->dispatch.handler->address != address) { |
| 893 | status = AE_BAD_PARAMETER; |
| 894 | goto unlock_and_exit; |
| 895 | } |
| 896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | /* Remove the handler */ |
| 898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | handler = gpe_event_info->dispatch.handler; |
Lv Zheng | c539251 | 2015-02-05 15:20:14 +0800 | [diff] [blame] | 900 | gpe_event_info->dispatch.handler = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
| 902 | /* Restore Method node (if any), set dispatch flags */ |
| 903 | |
| 904 | gpe_event_info->dispatch.method_node = handler->method_node; |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 905 | gpe_event_info->flags &= |
Lv Zheng | f19f1a7 | 2014-10-10 10:39:39 +0800 | [diff] [blame] | 906 | ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 907 | gpe_event_info->flags |= handler->original_flags; |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 908 | |
| 909 | /* |
Rafael J. Wysocki | a210080 | 2010-09-16 00:30:43 +0200 | [diff] [blame] | 910 | * If the GPE was previously associated with a method and it was |
| 911 | * enabled, it should be enabled at this point to restore the |
| 912 | * post-initialization configuration. |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 913 | */ |
Lv Zheng | 7c43312 | 2015-02-05 15:20:29 +0800 | [diff] [blame] | 914 | if (((ACPI_GPE_DISPATCH_TYPE(handler->original_flags) == |
| 915 | ACPI_GPE_DISPATCH_METHOD) || |
| 916 | (ACPI_GPE_DISPATCH_TYPE(handler->original_flags) == |
| 917 | ACPI_GPE_DISPATCH_NOTIFY)) && handler->originally_enabled) { |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 918 | (void)acpi_ev_add_gpe_reference(gpe_event_info); |
Lv Zheng | 3e8214e | 2012-12-19 05:37:15 +0000 | [diff] [blame] | 919 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | |
Lv Zheng | 69c841b | 2014-04-04 12:37:51 +0800 | [diff] [blame] | 921 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 922 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 923 | |
| 924 | /* Make sure all deferred GPE tasks are completed */ |
| 925 | |
| 926 | acpi_os_wait_events_complete(); |
| 927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | /* Now we can free the handler object */ |
| 929 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 930 | ACPI_FREE(handler); |
Lv Zheng | 69c841b | 2014-04-04 12:37:51 +0800 | [diff] [blame] | 931 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | |
Rafael J. Wysocki | 28f4f8a | 2010-08-03 23:55:14 +0200 | [diff] [blame] | 933 | unlock_and_exit: |
| 934 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 935 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 936 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); |
| 937 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 940 | ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
| 942 | /******************************************************************************* |
| 943 | * |
| 944 | * FUNCTION: acpi_acquire_global_lock |
| 945 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 946 | * PARAMETERS: timeout - How long the caller is willing to wait |
| 947 | * handle - Where the handle to the lock is returned |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 948 | * (if acquired) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | * |
| 950 | * RETURN: Status |
| 951 | * |
| 952 | * DESCRIPTION: Acquire the ACPI Global Lock |
| 953 | * |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame] | 954 | * Note: Allows callers with the same thread ID to acquire the global lock |
| 955 | * multiple times. In other words, externally, the behavior of the global lock |
| 956 | * is identical to an AML mutex. On the first acquire, a new handle is |
| 957 | * returned. On any subsequent calls to acquire by the same thread, the same |
| 958 | * handle is returned. |
| 959 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | ******************************************************************************/ |
Lv Zheng | f19f1a7 | 2014-10-10 10:39:39 +0800 | [diff] [blame] | 961 | acpi_status acpi_acquire_global_lock(u16 timeout, u32 *handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 963 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | |
| 965 | if (!handle) { |
| 966 | return (AE_BAD_PARAMETER); |
| 967 | } |
| 968 | |
Len Brown | 4d2acd9 | 2007-05-09 22:56:38 -0400 | [diff] [blame] | 969 | /* Must lock interpreter to prevent race conditions */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
Len Brown | 4d2acd9 | 2007-05-09 22:56:38 -0400 | [diff] [blame] | 971 | acpi_ex_enter_interpreter(); |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame] | 972 | |
| 973 | status = acpi_ex_acquire_mutex_object(timeout, |
| 974 | acpi_gbl_global_lock_mutex, |
| 975 | acpi_os_get_thread_id()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 977 | if (ACPI_SUCCESS(status)) { |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame] | 978 | |
Bob Moore | e5567af | 2008-04-10 19:06:38 +0400 | [diff] [blame] | 979 | /* Return the global lock handle (updated in acpi_ev_acquire_global_lock) */ |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame] | 980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | *handle = acpi_gbl_global_lock_handle; |
| 982 | } |
| 983 | |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame] | 984 | acpi_ex_exit_interpreter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | return (status); |
| 986 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 988 | ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
| 990 | /******************************************************************************* |
| 991 | * |
| 992 | * FUNCTION: acpi_release_global_lock |
| 993 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 994 | * PARAMETERS: handle - Returned from acpi_acquire_global_lock |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | * |
| 996 | * RETURN: Status |
| 997 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 998 | * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | * |
| 1000 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1001 | acpi_status acpi_release_global_lock(u32 handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1003 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
Bob Moore | f02e9fa | 2008-04-10 19:06:37 +0400 | [diff] [blame] | 1005 | if (!handle || (handle != acpi_gbl_global_lock_handle)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | return (AE_NOT_ACQUIRED); |
| 1007 | } |
| 1008 | |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame] | 1009 | status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | return (status); |
| 1011 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 1013 | ACPI_EXPORT_SYMBOL(acpi_release_global_lock) |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 1014 | #endif /* !ACPI_REDUCED_HARDWARE */ |