| 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 | 6c9deb7 | 2007-02-02 19:48:24 +0300 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2007, R. Byron Moore | 
| 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> | 
|  | 45 | #include <acpi/acnamesp.h> | 
|  | 46 | #include <acpi/acevents.h> | 
|  | 47 | #include <acpi/acinterp.h> | 
|  | 48 |  | 
|  | 49 | #define _COMPONENT          ACPI_EVENTS | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("evxface") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 |  | 
|  | 52 | /******************************************************************************* | 
|  | 53 | * | 
|  | 54 | * FUNCTION:    acpi_install_exception_handler | 
|  | 55 | * | 
|  | 56 | * PARAMETERS:  Handler         - Pointer to the handler function for the | 
|  | 57 | *                                event | 
|  | 58 | * | 
|  | 59 | * RETURN:      Status | 
|  | 60 | * | 
|  | 61 | * DESCRIPTION: Saves the pointer to the handler function | 
|  | 62 | * | 
|  | 63 | ******************************************************************************/ | 
|  | 64 | #ifdef ACPI_FUTURE_USAGE | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 65 | acpi_status acpi_install_exception_handler(acpi_exception_handler handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 67 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 69 | ACPI_FUNCTION_TRACE(acpi_install_exception_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 71 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | 
|  | 72 | if (ACPI_FAILURE(status)) { | 
|  | 73 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } | 
|  | 75 |  | 
|  | 76 | /* Don't allow two handlers. */ | 
|  | 77 |  | 
|  | 78 | if (acpi_gbl_exception_handler) { | 
|  | 79 | status = AE_ALREADY_EXISTS; | 
|  | 80 | goto cleanup; | 
|  | 81 | } | 
|  | 82 |  | 
|  | 83 | /* Install the handler */ | 
|  | 84 |  | 
|  | 85 | acpi_gbl_exception_handler = handler; | 
|  | 86 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | cleanup: | 
|  | 88 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | 
|  | 89 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 91 |  | 
|  | 92 | ACPI_EXPORT_SYMBOL(acpi_install_exception_handler) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | #endif				/*  ACPI_FUTURE_USAGE  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | /******************************************************************************* | 
|  | 95 | * | 
|  | 96 | * FUNCTION:    acpi_install_fixed_event_handler | 
|  | 97 | * | 
|  | 98 | * PARAMETERS:  Event           - Event type to enable. | 
|  | 99 | *              Handler         - Pointer to the handler function for the | 
|  | 100 | *                                event | 
|  | 101 | *              Context         - Value passed to the handler on each GPE | 
|  | 102 | * | 
|  | 103 | * RETURN:      Status | 
|  | 104 | * | 
|  | 105 | * DESCRIPTION: Saves the pointer to the handler function and then enables the | 
|  | 106 | *              event. | 
|  | 107 | * | 
|  | 108 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 110 | acpi_install_fixed_event_handler(u32 event, | 
|  | 111 | acpi_event_handler handler, void *context) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 115 | ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 |  | 
|  | 117 | /* Parameter validation */ | 
|  | 118 |  | 
|  | 119 | if (event > ACPI_EVENT_MAX) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 120 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } | 
|  | 122 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 123 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | 
|  | 124 | if (ACPI_FAILURE(status)) { | 
|  | 125 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } | 
|  | 127 |  | 
|  | 128 | /* Don't allow two handlers. */ | 
|  | 129 |  | 
|  | 130 | if (NULL != acpi_gbl_fixed_event_handlers[event].handler) { | 
|  | 131 | status = AE_ALREADY_EXISTS; | 
|  | 132 | goto cleanup; | 
|  | 133 | } | 
|  | 134 |  | 
|  | 135 | /* Install the handler before enabling the event */ | 
|  | 136 |  | 
|  | 137 | acpi_gbl_fixed_event_handlers[event].handler = handler; | 
|  | 138 | acpi_gbl_fixed_event_handlers[event].context = context; | 
|  | 139 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 140 | status = acpi_clear_event(event); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | if (ACPI_SUCCESS(status)) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 142 | status = acpi_enable_event(event, 0); | 
|  | 143 | if (ACPI_FAILURE(status)) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 144 | ACPI_WARNING((AE_INFO, "Could not enable fixed event %X", | 
|  | 145 | event)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 |  | 
|  | 147 | /* Remove the handler */ | 
|  | 148 |  | 
|  | 149 | acpi_gbl_fixed_event_handlers[event].handler = NULL; | 
|  | 150 | acpi_gbl_fixed_event_handlers[event].context = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 151 | } else { | 
|  | 152 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 153 | "Enabled fixed event %X, Handler=%p\n", event, | 
|  | 154 | handler)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | } | 
|  | 156 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | cleanup: | 
|  | 158 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | 
|  | 159 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 162 | ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 |  | 
|  | 164 | /******************************************************************************* | 
|  | 165 | * | 
|  | 166 | * FUNCTION:    acpi_remove_fixed_event_handler | 
|  | 167 | * | 
|  | 168 | * PARAMETERS:  Event           - Event type to disable. | 
|  | 169 | *              Handler         - Address of the handler | 
|  | 170 | * | 
|  | 171 | * RETURN:      Status | 
|  | 172 | * | 
|  | 173 | * DESCRIPTION: Disables the event and unregisters the event handler. | 
|  | 174 | * | 
|  | 175 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | acpi_remove_fixed_event_handler(u32 event, acpi_event_handler handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | acpi_status status = AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 181 | ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 |  | 
|  | 183 | /* Parameter validation */ | 
|  | 184 |  | 
|  | 185 | if (event > ACPI_EVENT_MAX) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 186 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } | 
|  | 188 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 189 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | 
|  | 190 | if (ACPI_FAILURE(status)) { | 
|  | 191 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } | 
|  | 193 |  | 
|  | 194 | /* Disable the event before removing the handler */ | 
|  | 195 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | status = acpi_disable_event(event, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 |  | 
|  | 198 | /* Always Remove the handler */ | 
|  | 199 |  | 
|  | 200 | acpi_gbl_fixed_event_handlers[event].handler = NULL; | 
|  | 201 | acpi_gbl_fixed_event_handlers[event].context = NULL; | 
|  | 202 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | if (ACPI_FAILURE(status)) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 204 | ACPI_WARNING((AE_INFO, | 
|  | 205 | "Could not write to fixed event enable register %X", | 
|  | 206 | event)); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 207 | } else { | 
| Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 208 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Disabled fixed event %X\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | event)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } | 
|  | 211 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 212 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | 
|  | 213 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 216 | ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 |  | 
|  | 218 | /******************************************************************************* | 
|  | 219 | * | 
|  | 220 | * FUNCTION:    acpi_install_notify_handler | 
|  | 221 | * | 
|  | 222 | * PARAMETERS:  Device          - The device for which notifies will be handled | 
|  | 223 | *              handler_type    - The type of handler: | 
|  | 224 | *                                  ACPI_SYSTEM_NOTIFY: system_handler (00-7f) | 
|  | 225 | *                                  ACPI_DEVICE_NOTIFY: driver_handler (80-ff) | 
|  | 226 | *                                  ACPI_ALL_NOTIFY:  both system and device | 
|  | 227 | *              Handler         - Address of the handler | 
|  | 228 | *              Context         - Value passed to the handler on each GPE | 
|  | 229 | * | 
|  | 230 | * RETURN:      Status | 
|  | 231 | * | 
|  | 232 | * DESCRIPTION: Install a handler for notifies on an ACPI device | 
|  | 233 | * | 
|  | 234 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 236 | acpi_install_notify_handler(acpi_handle device, | 
|  | 237 | u32 handler_type, | 
|  | 238 | acpi_notify_handler handler, void *context) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 240 | union acpi_operand_object *obj_desc; | 
|  | 241 | union acpi_operand_object *notify_obj; | 
|  | 242 | struct acpi_namespace_node *node; | 
|  | 243 | acpi_status status; | 
| 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_install_notify_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 |  | 
|  | 247 | /* Parameter validation */ | 
|  | 248 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 249 | if ((!device) || | 
|  | 250 | (!handler) || (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 | } | 
|  | 253 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 254 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 255 | if (ACPI_FAILURE(status)) { | 
|  | 256 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } | 
|  | 258 |  | 
|  | 259 | /* Convert and validate the device handle */ | 
|  | 260 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 261 | node = acpi_ns_map_handle_to_node(device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | if (!node) { | 
|  | 263 | status = AE_BAD_PARAMETER; | 
|  | 264 | goto unlock_and_exit; | 
|  | 265 | } | 
|  | 266 |  | 
|  | 267 | /* | 
|  | 268 | * Root Object: | 
|  | 269 | * Registering a notify handler on the root object indicates that the | 
|  | 270 | * caller wishes to receive notifications for all objects.  Note that | 
|  | 271 | * only one <external> global handler can be regsitered (per notify type). | 
|  | 272 | */ | 
|  | 273 | if (device == ACPI_ROOT_OBJECT) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 274 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | /* Make sure the handler is not already installed */ | 
|  | 276 |  | 
|  | 277 | if (((handler_type & ACPI_SYSTEM_NOTIFY) && | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 278 | acpi_gbl_system_notify.handler) || | 
|  | 279 | ((handler_type & ACPI_DEVICE_NOTIFY) && | 
|  | 280 | acpi_gbl_device_notify.handler)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | status = AE_ALREADY_EXISTS; | 
|  | 282 | goto unlock_and_exit; | 
|  | 283 | } | 
|  | 284 |  | 
|  | 285 | if (handler_type & ACPI_SYSTEM_NOTIFY) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 286 | acpi_gbl_system_notify.node = node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | acpi_gbl_system_notify.handler = handler; | 
|  | 288 | acpi_gbl_system_notify.context = context; | 
|  | 289 | } | 
|  | 290 |  | 
|  | 291 | if (handler_type & ACPI_DEVICE_NOTIFY) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 292 | acpi_gbl_device_notify.node = node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | acpi_gbl_device_notify.handler = handler; | 
|  | 294 | acpi_gbl_device_notify.context = context; | 
|  | 295 | } | 
|  | 296 |  | 
|  | 297 | /* Global notify handler installed */ | 
|  | 298 | } | 
|  | 299 |  | 
|  | 300 | /* | 
|  | 301 | * All Other Objects: | 
|  | 302 | * Caller will only receive notifications specific to the target object. | 
|  | 303 | * Note that only certain object types can receive notifications. | 
|  | 304 | */ | 
|  | 305 | else { | 
|  | 306 | /* Notifies allowed on this object? */ | 
|  | 307 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | if (!acpi_ev_is_notify_object(node)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | status = AE_TYPE; | 
|  | 310 | goto unlock_and_exit; | 
|  | 311 | } | 
|  | 312 |  | 
|  | 313 | /* Check for an existing internal object */ | 
|  | 314 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 315 | obj_desc = acpi_ns_get_attached_object(node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | if (obj_desc) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 317 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | /* Object exists - make sure there's no handler */ | 
|  | 319 |  | 
|  | 320 | if (((handler_type & ACPI_SYSTEM_NOTIFY) && | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 321 | obj_desc->common_notify.system_notify) || | 
|  | 322 | ((handler_type & ACPI_DEVICE_NOTIFY) && | 
|  | 323 | obj_desc->common_notify.device_notify)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | status = AE_ALREADY_EXISTS; | 
|  | 325 | goto unlock_and_exit; | 
|  | 326 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 327 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | /* Create a new object */ | 
|  | 329 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | obj_desc = acpi_ut_create_internal_object(node->type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | if (!obj_desc) { | 
|  | 332 | status = AE_NO_MEMORY; | 
|  | 333 | goto unlock_and_exit; | 
|  | 334 | } | 
|  | 335 |  | 
|  | 336 | /* Attach new object to the Node */ | 
|  | 337 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 338 | status = | 
|  | 339 | acpi_ns_attach_object(device, obj_desc, node->type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 |  | 
|  | 341 | /* Remove local reference to the object */ | 
|  | 342 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 343 | acpi_ut_remove_reference(obj_desc); | 
|  | 344 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | goto unlock_and_exit; | 
|  | 346 | } | 
|  | 347 | } | 
|  | 348 |  | 
|  | 349 | /* Install the handler */ | 
|  | 350 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 351 | notify_obj = | 
|  | 352 | acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (!notify_obj) { | 
|  | 354 | status = AE_NO_MEMORY; | 
|  | 355 | goto unlock_and_exit; | 
|  | 356 | } | 
|  | 357 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 358 | notify_obj->notify.node = node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | notify_obj->notify.handler = handler; | 
|  | 360 | notify_obj->notify.context = context; | 
|  | 361 |  | 
|  | 362 | if (handler_type & ACPI_SYSTEM_NOTIFY) { | 
|  | 363 | obj_desc->common_notify.system_notify = notify_obj; | 
|  | 364 | } | 
|  | 365 |  | 
|  | 366 | if (handler_type & ACPI_DEVICE_NOTIFY) { | 
|  | 367 | obj_desc->common_notify.device_notify = notify_obj; | 
|  | 368 | } | 
|  | 369 |  | 
|  | 370 | if (handler_type == ACPI_ALL_NOTIFY) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 371 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | /* Extra ref if installed in both */ | 
|  | 373 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 374 | acpi_ut_add_reference(notify_obj); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } | 
|  | 376 | } | 
|  | 377 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 378 | unlock_and_exit: | 
|  | 379 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
|  | 380 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 383 | ACPI_EXPORT_SYMBOL(acpi_install_notify_handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 |  | 
|  | 385 | /******************************************************************************* | 
|  | 386 | * | 
|  | 387 | * FUNCTION:    acpi_remove_notify_handler | 
|  | 388 | * | 
|  | 389 | * PARAMETERS:  Device          - The device for which notifies will be handled | 
|  | 390 | *              handler_type    - The type of handler: | 
|  | 391 | *                                  ACPI_SYSTEM_NOTIFY: system_handler (00-7f) | 
|  | 392 | *                                  ACPI_DEVICE_NOTIFY: driver_handler (80-ff) | 
|  | 393 | *                                  ACPI_ALL_NOTIFY:  both system and device | 
|  | 394 | *              Handler         - Address of the handler | 
|  | 395 | * | 
|  | 396 | * RETURN:      Status | 
|  | 397 | * | 
|  | 398 | * DESCRIPTION: Remove a handler for notifies on an ACPI device | 
|  | 399 | * | 
|  | 400 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 402 | acpi_remove_notify_handler(acpi_handle device, | 
|  | 403 | u32 handler_type, acpi_notify_handler handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 405 | union acpi_operand_object *notify_obj; | 
|  | 406 | union acpi_operand_object *obj_desc; | 
|  | 407 | struct acpi_namespace_node *node; | 
|  | 408 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 410 | ACPI_FUNCTION_TRACE(acpi_remove_notify_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 |  | 
|  | 412 | /* Parameter validation */ | 
|  | 413 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 414 | if ((!device) || | 
|  | 415 | (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 416 | status = AE_BAD_PARAMETER; | 
|  | 417 | goto exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } | 
|  | 419 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 420 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 421 | if (ACPI_FAILURE(status)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 422 | goto exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } | 
|  | 424 |  | 
|  | 425 | /* Convert and validate the device handle */ | 
|  | 426 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 427 | node = acpi_ns_map_handle_to_node(device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | if (!node) { | 
|  | 429 | status = AE_BAD_PARAMETER; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 430 | goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } | 
|  | 432 |  | 
|  | 433 | /* Root Object */ | 
|  | 434 |  | 
|  | 435 | if (device == ACPI_ROOT_OBJECT) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 436 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 437 | "Removing notify handler for namespace root object\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 |  | 
|  | 439 | if (((handler_type & ACPI_SYSTEM_NOTIFY) && | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 440 | !acpi_gbl_system_notify.handler) || | 
|  | 441 | ((handler_type & ACPI_DEVICE_NOTIFY) && | 
|  | 442 | !acpi_gbl_device_notify.handler)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | status = AE_NOT_EXIST; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 444 | goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } | 
|  | 446 |  | 
|  | 447 | /* Make sure all deferred tasks are completed */ | 
|  | 448 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 449 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | acpi_os_wait_events_complete(NULL); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 451 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 452 | if (ACPI_FAILURE(status)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 453 | goto exit; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 454 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 |  | 
|  | 456 | if (handler_type & ACPI_SYSTEM_NOTIFY) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 457 | acpi_gbl_system_notify.node = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | acpi_gbl_system_notify.handler = NULL; | 
|  | 459 | acpi_gbl_system_notify.context = NULL; | 
|  | 460 | } | 
|  | 461 |  | 
|  | 462 | if (handler_type & ACPI_DEVICE_NOTIFY) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 463 | acpi_gbl_device_notify.node = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | acpi_gbl_device_notify.handler = NULL; | 
|  | 465 | acpi_gbl_device_notify.context = NULL; | 
|  | 466 | } | 
|  | 467 | } | 
|  | 468 |  | 
|  | 469 | /* All Other Objects */ | 
|  | 470 |  | 
|  | 471 | else { | 
|  | 472 | /* Notifies allowed on this object? */ | 
|  | 473 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 474 | if (!acpi_ev_is_notify_object(node)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | status = AE_TYPE; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 476 | goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } | 
|  | 478 |  | 
|  | 479 | /* Check for an existing internal object */ | 
|  | 480 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 481 | obj_desc = acpi_ns_get_attached_object(node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | if (!obj_desc) { | 
|  | 483 | status = AE_NOT_EXIST; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 484 | goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } | 
|  | 486 |  | 
|  | 487 | /* Object exists - make sure there's an existing handler */ | 
|  | 488 |  | 
|  | 489 | if (handler_type & ACPI_SYSTEM_NOTIFY) { | 
|  | 490 | notify_obj = obj_desc->common_notify.system_notify; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 491 | if (!notify_obj) { | 
|  | 492 | status = AE_NOT_EXIST; | 
|  | 493 | goto unlock_and_exit; | 
|  | 494 | } | 
|  | 495 |  | 
|  | 496 | if (notify_obj->notify.handler != handler) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | status = AE_BAD_PARAMETER; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 498 | goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } | 
|  | 500 | /* Make sure all deferred tasks are completed */ | 
|  | 501 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 502 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | acpi_os_wait_events_complete(NULL); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 504 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 505 | if (ACPI_FAILURE(status)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 506 | goto exit; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 507 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 |  | 
|  | 509 | /* Remove the handler */ | 
|  | 510 | obj_desc->common_notify.system_notify = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 511 | acpi_ut_remove_reference(notify_obj); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } | 
|  | 513 |  | 
|  | 514 | if (handler_type & ACPI_DEVICE_NOTIFY) { | 
|  | 515 | notify_obj = obj_desc->common_notify.device_notify; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 516 | if (!notify_obj) { | 
|  | 517 | status = AE_NOT_EXIST; | 
|  | 518 | goto unlock_and_exit; | 
|  | 519 | } | 
|  | 520 |  | 
|  | 521 | if (notify_obj->notify.handler != handler) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | status = AE_BAD_PARAMETER; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 523 | goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | } | 
|  | 525 | /* Make sure all deferred tasks are completed */ | 
|  | 526 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 527 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | acpi_os_wait_events_complete(NULL); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 529 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 530 | if (ACPI_FAILURE(status)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 531 | goto exit; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 532 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 |  | 
|  | 534 | /* Remove the handler */ | 
|  | 535 | obj_desc->common_notify.device_notify = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 536 | acpi_ut_remove_reference(notify_obj); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } | 
|  | 538 | } | 
|  | 539 |  | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 540 | unlock_and_exit: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 541 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 542 | exit: | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 543 | if (ACPI_FAILURE(status)) | 
|  | 544 | ACPI_EXCEPTION((AE_INFO, status, "Removing notify handler")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 545 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 548 | ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 |  | 
|  | 550 | /******************************************************************************* | 
|  | 551 | * | 
|  | 552 | * FUNCTION:    acpi_install_gpe_handler | 
|  | 553 | * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 554 | * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for FADT | 
|  | 555 | *                                defined GPEs) | 
|  | 556 | *              gpe_number      - The GPE number within the GPE block | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | *              Type            - Whether this GPE should be treated as an | 
|  | 558 | *                                edge- or level-triggered interrupt. | 
|  | 559 | *              Address         - Address of the handler | 
|  | 560 | *              Context         - Value passed to the handler on each GPE | 
|  | 561 | * | 
|  | 562 | * RETURN:      Status | 
|  | 563 | * | 
|  | 564 | * DESCRIPTION: Install a handler for a General Purpose Event. | 
|  | 565 | * | 
|  | 566 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 568 | acpi_install_gpe_handler(acpi_handle gpe_device, | 
|  | 569 | u32 gpe_number, | 
|  | 570 | u32 type, acpi_event_handler address, void *context) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 572 | struct acpi_gpe_event_info *gpe_event_info; | 
|  | 573 | struct acpi_handler_info *handler; | 
|  | 574 | acpi_status status; | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 575 | acpi_cpu_flags flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 577 | ACPI_FUNCTION_TRACE(acpi_install_gpe_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 |  | 
|  | 579 | /* Parameter validation */ | 
|  | 580 |  | 
|  | 581 | if ((!address) || (type > ACPI_GPE_XRUPT_TYPE_MASK)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 582 | status = AE_BAD_PARAMETER; | 
|  | 583 | goto exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | } | 
|  | 585 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 586 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | 
|  | 587 | if (ACPI_FAILURE(status)) { | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 588 | goto exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | } | 
|  | 590 |  | 
|  | 591 | /* Ensure that we have a valid GPE number */ | 
|  | 592 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 593 | 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] | 594 | if (!gpe_event_info) { | 
|  | 595 | status = AE_BAD_PARAMETER; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 596 | goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } | 
|  | 598 |  | 
|  | 599 | /* Make sure that there isn't a handler there already */ | 
|  | 600 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 601 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == | 
|  | 602 | ACPI_GPE_DISPATCH_HANDLER) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | status = AE_ALREADY_EXISTS; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 604 | goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } | 
|  | 606 |  | 
|  | 607 | /* Allocate and init handler object */ | 
|  | 608 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 609 | handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_handler_info)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | if (!handler) { | 
|  | 611 | status = AE_NO_MEMORY; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 612 | goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } | 
|  | 614 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 615 | handler->address = address; | 
|  | 616 | handler->context = context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | handler->method_node = gpe_event_info->dispatch.method_node; | 
|  | 618 |  | 
|  | 619 | /* Disable the GPE before installing the handler */ | 
|  | 620 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 621 | status = acpi_ev_disable_gpe(gpe_event_info); | 
|  | 622 | if (ACPI_FAILURE(status)) { | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 623 | goto unlock_and_exit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } | 
|  | 625 |  | 
|  | 626 | /* Install the handler */ | 
|  | 627 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 628 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | gpe_event_info->dispatch.handler = handler; | 
|  | 630 |  | 
|  | 631 | /* Setup up dispatch flags to indicate handler (vs. method) */ | 
|  | 632 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 633 | gpe_event_info->flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);	/* Clear bits */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER); | 
|  | 635 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 636 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 |  | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 638 | unlock_and_exit: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 639 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 640 | exit: | 
| Thomas Renninger | e8406b4 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 641 | if (ACPI_FAILURE(status)) | 
|  | 642 | ACPI_EXCEPTION((AE_INFO, status, | 
|  | 643 | "Installing notify handler failed")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 644 | return_ACPI_STATUS(status); | 
| 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 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 647 | ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 |  | 
|  | 649 | /******************************************************************************* | 
|  | 650 | * | 
|  | 651 | * FUNCTION:    acpi_remove_gpe_handler | 
|  | 652 | * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 653 | * PARAMETERS:  gpe_device      - Namespace node for the GPE (NULL for FADT | 
|  | 654 | *                                defined GPEs) | 
|  | 655 | *              gpe_number      - The event to remove a handler | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | *              Address         - Address of the handler | 
|  | 657 | * | 
|  | 658 | * RETURN:      Status | 
|  | 659 | * | 
|  | 660 | * DESCRIPTION: Remove a handler for a General Purpose acpi_event. | 
|  | 661 | * | 
|  | 662 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 664 | acpi_remove_gpe_handler(acpi_handle gpe_device, | 
|  | 665 | u32 gpe_number, acpi_event_handler address) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 667 | struct acpi_gpe_event_info *gpe_event_info; | 
|  | 668 | struct acpi_handler_info *handler; | 
|  | 669 | acpi_status status; | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 670 | acpi_cpu_flags flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 672 | ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 |  | 
|  | 674 | /* Parameter validation */ | 
|  | 675 |  | 
|  | 676 | if (!address) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 677 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | } | 
|  | 679 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 680 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | 
|  | 681 | if (ACPI_FAILURE(status)) { | 
|  | 682 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } | 
|  | 684 |  | 
|  | 685 | /* Ensure that we have a valid GPE number */ | 
|  | 686 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 687 | 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] | 688 | if (!gpe_event_info) { | 
|  | 689 | status = AE_BAD_PARAMETER; | 
|  | 690 | goto unlock_and_exit; | 
|  | 691 | } | 
|  | 692 |  | 
|  | 693 | /* Make sure that a handler is indeed installed */ | 
|  | 694 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 695 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) != | 
|  | 696 | ACPI_GPE_DISPATCH_HANDLER) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | status = AE_NOT_EXIST; | 
|  | 698 | goto unlock_and_exit; | 
|  | 699 | } | 
|  | 700 |  | 
|  | 701 | /* Make sure that the installed handler is the same */ | 
|  | 702 |  | 
|  | 703 | if (gpe_event_info->dispatch.handler->address != address) { | 
|  | 704 | status = AE_BAD_PARAMETER; | 
|  | 705 | goto unlock_and_exit; | 
|  | 706 | } | 
|  | 707 |  | 
|  | 708 | /* Disable the GPE before removing the handler */ | 
|  | 709 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 710 | status = acpi_ev_disable_gpe(gpe_event_info); | 
|  | 711 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | goto unlock_and_exit; | 
|  | 713 | } | 
|  | 714 |  | 
|  | 715 | /* Make sure all deferred tasks are completed */ | 
|  | 716 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 717 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | acpi_os_wait_events_complete(NULL); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 719 | status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); | 
|  | 720 | if (ACPI_FAILURE(status)) { | 
|  | 721 | return_ACPI_STATUS(status); | 
|  | 722 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 |  | 
|  | 724 | /* Remove the handler */ | 
|  | 725 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 726 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | handler = gpe_event_info->dispatch.handler; | 
|  | 728 |  | 
|  | 729 | /* Restore Method node (if any), set dispatch flags */ | 
|  | 730 |  | 
|  | 731 | gpe_event_info->dispatch.method_node = handler->method_node; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 732 | gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK;	/* Clear bits */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | if (handler->method_node) { | 
|  | 734 | gpe_event_info->flags |= ACPI_GPE_DISPATCH_METHOD; | 
|  | 735 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 736 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 |  | 
|  | 738 | /* Now we can free the handler object */ | 
|  | 739 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 740 | ACPI_FREE(handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 742 | unlock_and_exit: | 
|  | 743 | (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); | 
|  | 744 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 747 | ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 |  | 
|  | 749 | /******************************************************************************* | 
|  | 750 | * | 
|  | 751 | * FUNCTION:    acpi_acquire_global_lock | 
|  | 752 | * | 
|  | 753 | * PARAMETERS:  Timeout         - How long the caller is willing to wait | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 754 | *              Handle          - Where the handle to the lock is returned | 
|  | 755 | *                                (if acquired) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | * | 
|  | 757 | * RETURN:      Status | 
|  | 758 | * | 
|  | 759 | * DESCRIPTION: Acquire the ACPI Global Lock | 
|  | 760 | * | 
|  | 761 | ******************************************************************************/ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 762 | acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 764 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 |  | 
|  | 766 | if (!handle) { | 
|  | 767 | return (AE_BAD_PARAMETER); | 
|  | 768 | } | 
|  | 769 |  | 
| Len Brown | 4d2acd9 | 2007-05-09 22:56:38 -0400 | [diff] [blame] | 770 | /* Must lock interpreter to prevent race conditions */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 |  | 
| Len Brown | 4d2acd9 | 2007-05-09 22:56:38 -0400 | [diff] [blame] | 772 | acpi_ex_enter_interpreter(); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 773 | status = acpi_ev_acquire_global_lock(timeout); | 
|  | 774 | acpi_ex_exit_interpreter(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 776 | if (ACPI_SUCCESS(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | acpi_gbl_global_lock_handle++; | 
|  | 778 | *handle = acpi_gbl_global_lock_handle; | 
|  | 779 | } | 
|  | 780 |  | 
|  | 781 | return (status); | 
|  | 782 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 784 | ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 |  | 
|  | 786 | /******************************************************************************* | 
|  | 787 | * | 
|  | 788 | * FUNCTION:    acpi_release_global_lock | 
|  | 789 | * | 
|  | 790 | * PARAMETERS:  Handle      - Returned from acpi_acquire_global_lock | 
|  | 791 | * | 
|  | 792 | * RETURN:      Status | 
|  | 793 | * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 794 | * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | * | 
|  | 796 | ******************************************************************************/ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 797 | acpi_status acpi_release_global_lock(u32 handle) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 799 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 |  | 
|  | 801 | if (handle != acpi_gbl_global_lock_handle) { | 
|  | 802 | return (AE_NOT_ACQUIRED); | 
|  | 803 | } | 
|  | 804 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 805 | status = acpi_ev_release_global_lock(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | return (status); | 
|  | 807 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 809 | ACPI_EXPORT_SYMBOL(acpi_release_global_lock) |