Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: evmisc - Miscellaneous event manager support functions |
| 5 | * |
Bob Moore | 840c02c | 2019-01-14 09:55:25 -0800 | [diff] [blame] | 6 | * Copyright (C) 2000 - 2019, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 8 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 11 | #include "accommon.h" |
| 12 | #include "acevents.h" |
| 13 | #include "acnamesp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | #define _COMPONENT ACPI_EVENTS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 16 | ACPI_MODULE_NAME("evmisc") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 18 | /* Local prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 19 | static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | /******************************************************************************* |
| 22 | * |
| 23 | * FUNCTION: acpi_ev_is_notify_object |
| 24 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 25 | * PARAMETERS: node - Node to check |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | * |
| 27 | * RETURN: TRUE if notifies allowed on this object |
| 28 | * |
| 29 | * DESCRIPTION: Check type of node for a object that supports notifies. |
| 30 | * |
| 31 | * TBD: This could be replaced by a flag bit in the node. |
| 32 | * |
| 33 | ******************************************************************************/ |
| 34 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 35 | u8 acpi_ev_is_notify_object(struct acpi_namespace_node *node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | switch (node->type) { |
| 39 | case ACPI_TYPE_DEVICE: |
| 40 | case ACPI_TYPE_PROCESSOR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | case ACPI_TYPE_THERMAL: |
| 42 | /* |
| 43 | * These are the ONLY objects that can receive ACPI notifications |
| 44 | */ |
| 45 | return (TRUE); |
| 46 | |
| 47 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | return (FALSE); |
| 50 | } |
| 51 | } |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /******************************************************************************* |
| 54 | * |
| 55 | * FUNCTION: acpi_ev_queue_notify_request |
| 56 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 57 | * PARAMETERS: node - NS node for the notified object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | * notify_value - Value from the Notify() request |
| 59 | * |
| 60 | * RETURN: Status |
| 61 | * |
| 62 | * DESCRIPTION: Dispatch a device notification event to a previously |
| 63 | * installed handler. |
| 64 | * |
| 65 | ******************************************************************************/ |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | acpi_status |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 68 | acpi_ev_queue_notify_request(struct acpi_namespace_node *node, u32 notify_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 70 | union acpi_operand_object *obj_desc; |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 71 | union acpi_operand_object *handler_list_head = NULL; |
| 72 | union acpi_generic_state *info; |
| 73 | u8 handler_list_id = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 74 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 76 | ACPI_FUNCTION_NAME(ev_queue_notify_request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 78 | /* Are Notifies allowed on this object? */ |
| 79 | |
| 80 | if (!acpi_ev_is_notify_object(node)) { |
| 81 | return (AE_TYPE); |
| 82 | } |
| 83 | |
| 84 | /* Get the correct notify list type (System or Device) */ |
| 85 | |
| 86 | if (notify_value <= ACPI_MAX_SYS_NOTIFY) { |
| 87 | handler_list_id = ACPI_SYSTEM_HANDLER_LIST; |
| 88 | } else { |
| 89 | handler_list_id = ACPI_DEVICE_HANDLER_LIST; |
| 90 | } |
| 91 | |
| 92 | /* Get the notify object attached to the namespace Node */ |
| 93 | |
| 94 | obj_desc = acpi_ns_get_attached_object(node); |
| 95 | if (obj_desc) { |
| 96 | |
| 97 | /* We have an attached object, Get the correct handler list */ |
| 98 | |
| 99 | handler_list_head = |
| 100 | obj_desc->common_notify.notify_list[handler_list_id]; |
| 101 | } |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | /* |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 104 | * If there is no notify handler (Global or Local) |
| 105 | * for this object, just ignore the notify |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | */ |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 107 | if (!acpi_gbl_global_notify[handler_list_id].handler |
| 108 | && !handler_list_head) { |
| 109 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 110 | "No notify handler for Notify, ignoring (%4.4s, %X) node %p\n", |
| 111 | acpi_ut_get_node_name(node), notify_value, |
| 112 | node)); |
| 113 | |
| 114 | return (AE_OK); |
| 115 | } |
| 116 | |
| 117 | /* Setup notify info and schedule the notify dispatcher */ |
| 118 | |
| 119 | info = acpi_ut_create_generic_state(); |
| 120 | if (!info) { |
| 121 | return (AE_NO_MEMORY); |
| 122 | } |
| 123 | |
| 124 | info->common.descriptor_type = ACPI_DESC_TYPE_STATE_NOTIFY; |
| 125 | |
| 126 | info->notify.node = node; |
| 127 | info->notify.value = (u16)notify_value; |
| 128 | info->notify.handler_list_id = handler_list_id; |
| 129 | info->notify.handler_list_head = handler_list_head; |
| 130 | info->notify.global = &acpi_gbl_global_notify[handler_list_id]; |
| 131 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 132 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bob Moore | ea14360 | 2012-02-14 18:23:39 +0800 | [diff] [blame] | 133 | "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n", |
| 134 | acpi_ut_get_node_name(node), |
| 135 | acpi_ut_get_type_name(node->type), notify_value, |
Bob Moore | 06a63e3 | 2014-04-04 12:37:44 +0800 | [diff] [blame] | 136 | acpi_ut_get_notify_name(notify_value, ACPI_TYPE_ANY), |
| 137 | node)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 139 | status = acpi_os_execute(OSL_NOTIFY_HANDLER, |
| 140 | acpi_ev_notify_dispatch, info); |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 141 | if (ACPI_FAILURE(status)) { |
| 142 | acpi_ut_delete_generic_state(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | return (status); |
| 146 | } |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | /******************************************************************************* |
| 149 | * |
| 150 | * FUNCTION: acpi_ev_notify_dispatch |
| 151 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 152 | * PARAMETERS: context - To be passed to the notify handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | * |
| 154 | * RETURN: None. |
| 155 | * |
| 156 | * DESCRIPTION: Dispatch a device notification event to a previously |
| 157 | * installed handler. |
| 158 | * |
| 159 | ******************************************************************************/ |
| 160 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 163 | union acpi_generic_state *info = (union acpi_generic_state *)context; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | union acpi_operand_object *handler_obj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 166 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 168 | /* Invoke a global notify handler if installed */ |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 169 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 170 | if (info->notify.global->handler) { |
| 171 | info->notify.global->handler(info->notify.node, |
| 172 | info->notify.value, |
| 173 | info->notify.global->context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 176 | /* Now invoke the local notify handler(s) if any are installed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 178 | handler_obj = info->notify.handler_list_head; |
| 179 | while (handler_obj) { |
| 180 | handler_obj->notify.handler(info->notify.node, |
| 181 | info->notify.value, |
| 182 | handler_obj->notify.context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 184 | handler_obj = |
| 185 | handler_obj->notify.next[info->notify.handler_list_id]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /* All done with the info object */ |
| 189 | |
Bob Moore | 86ed4bc | 2012-05-03 11:08:19 +0800 | [diff] [blame] | 190 | acpi_ut_delete_generic_state(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 193 | #if (!ACPI_REDUCED_HARDWARE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | /****************************************************************************** |
| 195 | * |
| 196 | * FUNCTION: acpi_ev_terminate |
| 197 | * |
| 198 | * PARAMETERS: none |
| 199 | * |
| 200 | * RETURN: none |
| 201 | * |
| 202 | * DESCRIPTION: Disable events and free memory allocated for table storage. |
| 203 | * |
| 204 | ******************************************************************************/ |
| 205 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | void acpi_ev_terminate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 208 | u32 i; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 211 | ACPI_FUNCTION_TRACE(ev_terminate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
| 213 | if (acpi_gbl_events_initialized) { |
| 214 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 215 | * Disable all event-related functionality. In all cases, on error, |
| 216 | * print a message but obviously we don't abort. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | */ |
| 218 | |
| 219 | /* Disable all fixed events */ |
| 220 | |
| 221 | for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 222 | status = acpi_disable_event(i, 0); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 224 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 225 | "Could not disable fixed event %u", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 226 | (u32) i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
| 230 | /* Disable all GPEs in all GPE blocks */ |
| 231 | |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 232 | status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL); |
Bob Moore | edc5935 | 2019-10-25 14:36:49 -0700 | [diff] [blame] | 233 | if (ACPI_FAILURE(status)) { |
| 234 | ACPI_EXCEPTION((AE_INFO, status, |
| 235 | "Could not disable GPEs in GPE block")); |
| 236 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Bob Moore | 8876016 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 238 | status = acpi_ev_remove_global_lock_handler(); |
| 239 | if (ACPI_FAILURE(status)) { |
Bob Moore | edc5935 | 2019-10-25 14:36:49 -0700 | [diff] [blame] | 240 | ACPI_EXCEPTION((AE_INFO, status, |
| 241 | "Could not remove Global Lock handler")); |
Bob Moore | 8876016 | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 242 | } |
Tomasz Nowicki | 64f3af5 | 2013-06-08 01:00:23 +0000 | [diff] [blame] | 243 | |
| 244 | acpi_gbl_events_initialized = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Lv Zheng | a2fd4b4 | 2013-09-23 09:52:05 +0800 | [diff] [blame] | 247 | /* Remove SCI handlers */ |
| 248 | |
| 249 | status = acpi_ev_remove_all_sci_handlers(); |
| 250 | if (ACPI_FAILURE(status)) { |
| 251 | ACPI_ERROR((AE_INFO, "Could not remove SCI handler")); |
| 252 | } |
| 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | /* Deallocate all handler objects installed within GPE info structs */ |
| 255 | |
Bob Moore | e97d6bf | 2008-12-30 09:45:17 +0800 | [diff] [blame] | 256 | status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL); |
Bob Moore | edc5935 | 2019-10-25 14:36:49 -0700 | [diff] [blame] | 257 | if (ACPI_FAILURE(status)) { |
| 258 | ACPI_EXCEPTION((AE_INFO, status, |
| 259 | "Could not delete GPE handlers")); |
| 260 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
| 262 | /* Return to original mode if necessary */ |
| 263 | |
| 264 | if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 265 | status = acpi_disable(); |
| 266 | if (ACPI_FAILURE(status)) { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 267 | ACPI_WARNING((AE_INFO, "AcpiDisable failed")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | return_VOID; |
| 271 | } |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 272 | |
| 273 | #endif /* !ACPI_REDUCED_HARDWARE */ |