blob: aa98fe07cd1b11ac76e6e0f26e2e069ece200264 [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/******************************************************************************
3 *
4 * Module Name: evmisc - Miscellaneous event manager support functions
5 *
Bob Moore840c02c2019-01-14 09:55:25 -08006 * Copyright (C) 2000 - 2019, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Erik Schmauss95857632018-03-14 16:13:07 -07008 *****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050011#include "accommon.h"
12#include "acevents.h"
13#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040016ACPI_MODULE_NAME("evmisc")
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Robert Moore44f6c012005-04-18 22:49:35 -040018/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040019static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context);
Robert Moore44f6c012005-04-18 22:49:35 -040020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021/*******************************************************************************
22 *
23 * FUNCTION: acpi_ev_is_notify_object
24 *
Bob Mooreba494be2012-07-12 09:40:10 +080025 * PARAMETERS: node - Node to check
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 *
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 Brown4be44fc2005-08-05 00:44:28 -040035u8 acpi_ev_is_notify_object(struct acpi_namespace_node *node)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
Bob Moore1fad8732015-12-29 13:54:36 +080037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 switch (node->type) {
39 case ACPI_TYPE_DEVICE:
40 case ACPI_TYPE_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 case ACPI_TYPE_THERMAL:
42 /*
43 * These are the ONLY objects that can receive ACPI notifications
44 */
45 return (TRUE);
46
47 default:
Chao Guan1d1ea1b72013-06-08 00:58:14 +000048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 return (FALSE);
50 }
51}
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/*******************************************************************************
54 *
55 * FUNCTION: acpi_ev_queue_notify_request
56 *
Bob Mooreba494be2012-07-12 09:40:10 +080057 * PARAMETERS: node - NS node for the notified object
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 * 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 Torvalds1da177e2005-04-16 15:20:36 -070067acpi_status
Lv Zhengf5c1e1c2016-05-05 12:57:53 +080068acpi_ev_queue_notify_request(struct acpi_namespace_node *node, u32 notify_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Len Brown4be44fc2005-08-05 00:44:28 -040070 union acpi_operand_object *obj_desc;
Bob Moore86ed4bc2012-05-03 11:08:19 +080071 union acpi_operand_object *handler_list_head = NULL;
72 union acpi_generic_state *info;
73 u8 handler_list_id = 0;
Len Brown4be44fc2005-08-05 00:44:28 -040074 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Bob Mooreb229cf92006-04-21 17:15:00 -040076 ACPI_FUNCTION_NAME(ev_queue_notify_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Bob Moore86ed4bc2012-05-03 11:08:19 +080078 /* 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 Torvalds1da177e2005-04-16 15:20:36 -0700103 /*
Bob Moore86ed4bc2012-05-03 11:08:19 +0800104 * If there is no notify handler (Global or Local)
105 * for this object, just ignore the notify
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 */
Bob Moore86ed4bc2012-05-03 11:08:19 +0800107 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 Brown4be44fc2005-08-05 00:44:28 -0400132 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Mooreea143602012-02-14 18:23:39 +0800133 "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 Moore06a63e32014-04-04 12:37:44 +0800136 acpi_ut_get_notify_name(notify_value, ACPI_TYPE_ANY),
137 node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Bob Moore1fad8732015-12-29 13:54:36 +0800139 status = acpi_os_execute(OSL_NOTIFY_HANDLER,
140 acpi_ev_notify_dispatch, info);
Bob Moore86ed4bc2012-05-03 11:08:19 +0800141 if (ACPI_FAILURE(status)) {
142 acpi_ut_delete_generic_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
144
145 return (status);
146}
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148/*******************************************************************************
149 *
150 * FUNCTION: acpi_ev_notify_dispatch
151 *
Bob Mooreba494be2012-07-12 09:40:10 +0800152 * PARAMETERS: context - To be passed to the notify handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 *
154 * RETURN: None.
155 *
156 * DESCRIPTION: Dispatch a device notification event to a previously
157 * installed handler.
158 *
159 ******************************************************************************/
160
Len Brown4be44fc2005-08-05 00:44:28 -0400161static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
Bob Moore86ed4bc2012-05-03 11:08:19 +0800163 union acpi_generic_state *info = (union acpi_generic_state *)context;
Len Brown4be44fc2005-08-05 00:44:28 -0400164 union acpi_operand_object *handler_obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Len Brown4be44fc2005-08-05 00:44:28 -0400166 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Bob Moore86ed4bc2012-05-03 11:08:19 +0800168 /* Invoke a global notify handler if installed */
Bob Moore52fc0b02006-10-02 00:00:00 -0400169
Bob Moore86ed4bc2012-05-03 11:08:19 +0800170 if (info->notify.global->handler) {
171 info->notify.global->handler(info->notify.node,
172 info->notify.value,
173 info->notify.global->context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 }
175
Bob Moore86ed4bc2012-05-03 11:08:19 +0800176 /* Now invoke the local notify handler(s) if any are installed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Bob Moore86ed4bc2012-05-03 11:08:19 +0800178 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 Torvalds1da177e2005-04-16 15:20:36 -0700183
Bob Moore86ed4bc2012-05-03 11:08:19 +0800184 handler_obj =
185 handler_obj->notify.next[info->notify.handler_list_id];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
187
188 /* All done with the info object */
189
Bob Moore86ed4bc2012-05-03 11:08:19 +0800190 acpi_ut_delete_generic_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191}
192
Bob Moore33620c52012-02-14 18:14:27 +0800193#if (!ACPI_REDUCED_HARDWARE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194/******************************************************************************
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 Brown4be44fc2005-08-05 00:44:28 -0400206void acpi_ev_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
Bob Moore67a119f2008-06-10 13:42:13 +0800208 u32 i;
Len Brown4be44fc2005-08-05 00:44:28 -0400209 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Bob Mooreb229cf92006-04-21 17:15:00 -0400211 ACPI_FUNCTION_TRACE(ev_terminate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213 if (acpi_gbl_events_initialized) {
214 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800215 * Disable all event-related functionality. In all cases, on error,
216 * print a message but obviously we don't abort.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 */
218
219 /* Disable all fixed events */
220
221 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
Bob Moore67a119f2008-06-10 13:42:13 +0800222 status = acpi_disable_event(i, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400223 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500224 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800225 "Could not disable fixed event %u",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500226 (u32) i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 }
228 }
229
230 /* Disable all GPEs in all GPE blocks */
231
Bob Mooree97d6bf2008-12-30 09:45:17 +0800232 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
Bob Mooreedc59352019-10-25 14:36:49 -0700233 if (ACPI_FAILURE(status)) {
234 ACPI_EXCEPTION((AE_INFO, status,
235 "Could not disable GPEs in GPE block"));
236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Bob Moore88760162007-02-02 19:48:22 +0300238 status = acpi_ev_remove_global_lock_handler();
239 if (ACPI_FAILURE(status)) {
Bob Mooreedc59352019-10-25 14:36:49 -0700240 ACPI_EXCEPTION((AE_INFO, status,
241 "Could not remove Global Lock handler"));
Bob Moore88760162007-02-02 19:48:22 +0300242 }
Tomasz Nowicki64f3af52013-06-08 01:00:23 +0000243
244 acpi_gbl_events_initialized = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 }
246
Lv Zhenga2fd4b42013-09-23 09:52:05 +0800247 /* 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 Torvalds1da177e2005-04-16 15:20:36 -0700254 /* Deallocate all handler objects installed within GPE info structs */
255
Bob Mooree97d6bf2008-12-30 09:45:17 +0800256 status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL);
Bob Mooreedc59352019-10-25 14:36:49 -0700257 if (ACPI_FAILURE(status)) {
258 ACPI_EXCEPTION((AE_INFO, status,
259 "Could not delete GPE handlers"));
260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 /* Return to original mode if necessary */
263
264 if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400265 status = acpi_disable();
266 if (ACPI_FAILURE(status)) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400267 ACPI_WARNING((AE_INFO, "AcpiDisable failed"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269 }
270 return_VOID;
271}
Bob Moore33620c52012-02-14 18:14:27 +0800272
273#endif /* !ACPI_REDUCED_HARDWARE */