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