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