Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: evmisc - Miscellaneous event manager support functions |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
David E. Box | 82a8094 | 2015-02-05 15:20:45 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2015, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions, and the following disclaimer, |
| 16 | * without modification. |
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 20 | * including a substantially similar Disclaimer requirement for further |
| 21 | * binary redistribution. |
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 23 | * of any contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * |
| 26 | * Alternatively, this software may be distributed under the terms of the |
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 28 | * Software Foundation. |
| 29 | * |
| 30 | * NO WARRANTY |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGES. |
| 42 | */ |
| 43 | |
| 44 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" |
| 46 | #include "acevents.h" |
| 47 | #include "acnamesp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define _COMPONENT ACPI_EVENTS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("evmisc") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | /* Local prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 53 | static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | /******************************************************************************* |
| 56 | * |
| 57 | * FUNCTION: acpi_ev_is_notify_object |
| 58 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 59 | * PARAMETERS: node - Node to check |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | * |
| 61 | * RETURN: TRUE if notifies allowed on this object |
| 62 | * |
| 63 | * DESCRIPTION: Check type of node for a object that supports notifies. |
| 64 | * |
| 65 | * TBD: This could be replaced by a flag bit in the node. |
| 66 | * |
| 67 | ******************************************************************************/ |
| 68 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | u8 acpi_ev_is_notify_object(struct acpi_namespace_node *node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
| 71 | switch (node->type) { |
| 72 | case ACPI_TYPE_DEVICE: |
| 73 | case ACPI_TYPE_PROCESSOR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | case ACPI_TYPE_THERMAL: |
| 75 | /* |
| 76 | * These are the ONLY objects that can receive ACPI notifications |
| 77 | */ |
| 78 | return (TRUE); |
| 79 | |
| 80 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | return (FALSE); |
| 83 | } |
| 84 | } |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /******************************************************************************* |
| 87 | * |
| 88 | * FUNCTION: acpi_ev_queue_notify_request |
| 89 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 90 | * PARAMETERS: node - NS node for the notified object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | * notify_value - Value from the Notify() request |
| 92 | * |
| 93 | * RETURN: Status |
| 94 | * |
| 95 | * DESCRIPTION: Dispatch a device notification event to a previously |
| 96 | * installed handler. |
| 97 | * |
| 98 | ******************************************************************************/ |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 101 | acpi_ev_queue_notify_request(struct acpi_namespace_node * node, |
| 102 | u32 notify_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 104 | union acpi_operand_object *obj_desc; |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 105 | union acpi_operand_object *handler_list_head = NULL; |
| 106 | union acpi_generic_state *info; |
| 107 | u8 handler_list_id = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 108 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 110 | ACPI_FUNCTION_NAME(ev_queue_notify_request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 112 | /* Are Notifies allowed on this object? */ |
| 113 | |
| 114 | if (!acpi_ev_is_notify_object(node)) { |
| 115 | return (AE_TYPE); |
| 116 | } |
| 117 | |
| 118 | /* Get the correct notify list type (System or Device) */ |
| 119 | |
| 120 | if (notify_value <= ACPI_MAX_SYS_NOTIFY) { |
| 121 | handler_list_id = ACPI_SYSTEM_HANDLER_LIST; |
| 122 | } else { |
| 123 | handler_list_id = ACPI_DEVICE_HANDLER_LIST; |
| 124 | } |
| 125 | |
| 126 | /* Get the notify object attached to the namespace Node */ |
| 127 | |
| 128 | obj_desc = acpi_ns_get_attached_object(node); |
| 129 | if (obj_desc) { |
| 130 | |
| 131 | /* We have an attached object, Get the correct handler list */ |
| 132 | |
| 133 | handler_list_head = |
| 134 | obj_desc->common_notify.notify_list[handler_list_id]; |
| 135 | } |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /* |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 138 | * If there is no notify handler (Global or Local) |
| 139 | * for this object, just ignore the notify |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | */ |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 141 | if (!acpi_gbl_global_notify[handler_list_id].handler |
| 142 | && !handler_list_head) { |
| 143 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 144 | "No notify handler for Notify, ignoring (%4.4s, %X) node %p\n", |
| 145 | acpi_ut_get_node_name(node), notify_value, |
| 146 | node)); |
| 147 | |
| 148 | return (AE_OK); |
| 149 | } |
| 150 | |
| 151 | /* Setup notify info and schedule the notify dispatcher */ |
| 152 | |
| 153 | info = acpi_ut_create_generic_state(); |
| 154 | if (!info) { |
| 155 | return (AE_NO_MEMORY); |
| 156 | } |
| 157 | |
| 158 | info->common.descriptor_type = ACPI_DESC_TYPE_STATE_NOTIFY; |
| 159 | |
| 160 | info->notify.node = node; |
| 161 | info->notify.value = (u16)notify_value; |
| 162 | info->notify.handler_list_id = handler_list_id; |
| 163 | info->notify.handler_list_head = handler_list_head; |
| 164 | info->notify.global = &acpi_gbl_global_notify[handler_list_id]; |
| 165 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 166 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bob Moore | ea14360 | 2012-02-14 18:23:39 +0800 | [diff] [blame] | 167 | "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n", |
| 168 | acpi_ut_get_node_name(node), |
| 169 | acpi_ut_get_type_name(node->type), notify_value, |
Bob Moore | 06a63e3 | 2014-04-04 12:37:44 +0800 | [diff] [blame] | 170 | acpi_ut_get_notify_name(notify_value, ACPI_TYPE_ANY), |
| 171 | node)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 173 | status = acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_notify_dispatch, |
| 174 | info); |
| 175 | if (ACPI_FAILURE(status)) { |
| 176 | acpi_ut_delete_generic_state(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | return (status); |
| 180 | } |
| 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | /******************************************************************************* |
| 183 | * |
| 184 | * FUNCTION: acpi_ev_notify_dispatch |
| 185 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 186 | * PARAMETERS: context - To be passed to the notify handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | * |
| 188 | * RETURN: None. |
| 189 | * |
| 190 | * DESCRIPTION: Dispatch a device notification event to a previously |
| 191 | * installed handler. |
| 192 | * |
| 193 | ******************************************************************************/ |
| 194 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 197 | union acpi_generic_state *info = (union acpi_generic_state *)context; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 198 | union acpi_operand_object *handler_obj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 200 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 202 | /* Invoke a global notify handler if installed */ |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 203 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 204 | if (info->notify.global->handler) { |
| 205 | info->notify.global->handler(info->notify.node, |
| 206 | info->notify.value, |
| 207 | info->notify.global->context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 210 | /* Now invoke the local notify handler(s) if any are installed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 212 | handler_obj = info->notify.handler_list_head; |
| 213 | while (handler_obj) { |
| 214 | handler_obj->notify.handler(info->notify.node, |
| 215 | info->notify.value, |
| 216 | handler_obj->notify.context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 218 | handler_obj = |
| 219 | handler_obj->notify.next[info->notify.handler_list_id]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /* All done with the info object */ |
| 223 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 224 | acpi_ut_delete_generic_state(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 227 | #if (!ACPI_REDUCED_HARDWARE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | /****************************************************************************** |
| 229 | * |
| 230 | * FUNCTION: acpi_ev_terminate |
| 231 | * |
| 232 | * PARAMETERS: none |
| 233 | * |
| 234 | * RETURN: none |
| 235 | * |
| 236 | * DESCRIPTION: Disable events and free memory allocated for table storage. |
| 237 | * |
| 238 | ******************************************************************************/ |
| 239 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 240 | void acpi_ev_terminate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 242 | u32 i; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 245 | ACPI_FUNCTION_TRACE(ev_terminate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | if (acpi_gbl_events_initialized) { |
| 248 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 249 | * Disable all event-related functionality. In all cases, on error, |
| 250 | * print a message but obviously we don't abort. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | */ |
| 252 | |
| 253 | /* Disable all fixed events */ |
| 254 | |
| 255 | for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 256 | status = acpi_disable_event(i, 0); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 257 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 258 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 259 | "Could not disable fixed event %u", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 260 | (u32) i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
| 264 | /* Disable all GPEs in all GPE blocks */ |
| 265 | |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 266 | status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Bob Moore | 8876016 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 268 | status = acpi_ev_remove_global_lock_handler(); |
| 269 | if (ACPI_FAILURE(status)) { |
| 270 | ACPI_ERROR((AE_INFO, |
| 271 | "Could not remove Global Lock handler")); |
| 272 | } |
Tomasz Nowicki | 64f3af5 | 2013-06-08 01:00:23 +0000 | [diff] [blame] | 273 | |
| 274 | acpi_gbl_events_initialized = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 277 | /* Remove SCI handlers */ |
| 278 | |
| 279 | status = acpi_ev_remove_all_sci_handlers(); |
| 280 | if (ACPI_FAILURE(status)) { |
| 281 | ACPI_ERROR((AE_INFO, "Could not remove SCI handler")); |
| 282 | } |
| 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | /* Deallocate all handler objects installed within GPE info structs */ |
| 285 | |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 286 | status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | /* Return to original mode if necessary */ |
| 289 | |
| 290 | if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | status = acpi_disable(); |
| 292 | if (ACPI_FAILURE(status)) { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 293 | ACPI_WARNING((AE_INFO, "AcpiDisable failed")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | return_VOID; |
| 297 | } |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 298 | |
| 299 | #endif /* !ACPI_REDUCED_HARDWARE */ |