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