blob: c67d78c5995fc90348f4bddd20350d7ac814d313 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: evmisc - Miscellaneous event manager support functions
4 *
5 *****************************************************************************/
6
7/*
Bob Moorec8100dc2016-01-15 08:17:03 +08008 * Copyright (C) 2000 - 2016, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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 Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acevents.h"
47#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("evmisc")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Robert Moore44f6c012005-04-18 22:49:35 -040052/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040053static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context);
Robert Moore44f6c012005-04-18 22:49:35 -040054
Linus Torvalds1da177e2005-04-16 15:20:36 -070055/*******************************************************************************
56 *
57 * FUNCTION: acpi_ev_is_notify_object
58 *
Bob Mooreba494be2012-07-12 09:40:10 +080059 * PARAMETERS: node - Node to check
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 *
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 Brown4be44fc2005-08-05 00:44:28 -040069u8 acpi_ev_is_notify_object(struct acpi_namespace_node *node)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Bob Moore1fad8732015-12-29 13:54:36 +080071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 switch (node->type) {
73 case ACPI_TYPE_DEVICE:
74 case ACPI_TYPE_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 case ACPI_TYPE_THERMAL:
76 /*
77 * These are the ONLY objects that can receive ACPI notifications
78 */
79 return (TRUE);
80
81 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +000082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 return (FALSE);
84 }
85}
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087/*******************************************************************************
88 *
89 * FUNCTION: acpi_ev_queue_notify_request
90 *
Bob Mooreba494be2012-07-12 09:40:10 +080091 * PARAMETERS: node - NS node for the notified object
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 * notify_value - Value from the Notify() request
93 *
94 * RETURN: Status
95 *
96 * DESCRIPTION: Dispatch a device notification event to a previously
97 * installed handler.
98 *
99 ******************************************************************************/
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400102acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
103 u32 notify_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Len Brown4be44fc2005-08-05 00:44:28 -0400105 union acpi_operand_object *obj_desc;
Bob Moore86ed4bc2012-05-03 11:08:19 +0800106 union acpi_operand_object *handler_list_head = NULL;
107 union acpi_generic_state *info;
108 u8 handler_list_id = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400109 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Bob Mooreb229cf92006-04-21 17:15:00 -0400111 ACPI_FUNCTION_NAME(ev_queue_notify_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Bob Moore86ed4bc2012-05-03 11:08:19 +0800113 /* Are Notifies allowed on this object? */
114
115 if (!acpi_ev_is_notify_object(node)) {
116 return (AE_TYPE);
117 }
118
119 /* Get the correct notify list type (System or Device) */
120
121 if (notify_value <= ACPI_MAX_SYS_NOTIFY) {
122 handler_list_id = ACPI_SYSTEM_HANDLER_LIST;
123 } else {
124 handler_list_id = ACPI_DEVICE_HANDLER_LIST;
125 }
126
127 /* Get the notify object attached to the namespace Node */
128
129 obj_desc = acpi_ns_get_attached_object(node);
130 if (obj_desc) {
131
132 /* We have an attached object, Get the correct handler list */
133
134 handler_list_head =
135 obj_desc->common_notify.notify_list[handler_list_id];
136 }
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 /*
Bob Moore86ed4bc2012-05-03 11:08:19 +0800139 * If there is no notify handler (Global or Local)
140 * for this object, just ignore the notify
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 */
Bob Moore86ed4bc2012-05-03 11:08:19 +0800142 if (!acpi_gbl_global_notify[handler_list_id].handler
143 && !handler_list_head) {
144 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
145 "No notify handler for Notify, ignoring (%4.4s, %X) node %p\n",
146 acpi_ut_get_node_name(node), notify_value,
147 node));
148
149 return (AE_OK);
150 }
151
152 /* Setup notify info and schedule the notify dispatcher */
153
154 info = acpi_ut_create_generic_state();
155 if (!info) {
156 return (AE_NO_MEMORY);
157 }
158
159 info->common.descriptor_type = ACPI_DESC_TYPE_STATE_NOTIFY;
160
161 info->notify.node = node;
162 info->notify.value = (u16)notify_value;
163 info->notify.handler_list_id = handler_list_id;
164 info->notify.handler_list_head = handler_list_head;
165 info->notify.global = &acpi_gbl_global_notify[handler_list_id];
166
Len Brown4be44fc2005-08-05 00:44:28 -0400167 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Mooreea143602012-02-14 18:23:39 +0800168 "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n",
169 acpi_ut_get_node_name(node),
170 acpi_ut_get_type_name(node->type), notify_value,
Bob Moore06a63e32014-04-04 12:37:44 +0800171 acpi_ut_get_notify_name(notify_value, ACPI_TYPE_ANY),
172 node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Bob Moore1fad8732015-12-29 13:54:36 +0800174 status = acpi_os_execute(OSL_NOTIFY_HANDLER,
175 acpi_ev_notify_dispatch, info);
Bob Moore86ed4bc2012-05-03 11:08:19 +0800176 if (ACPI_FAILURE(status)) {
177 acpi_ut_delete_generic_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 }
179
180 return (status);
181}
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183/*******************************************************************************
184 *
185 * FUNCTION: acpi_ev_notify_dispatch
186 *
Bob Mooreba494be2012-07-12 09:40:10 +0800187 * PARAMETERS: context - To be passed to the notify handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 *
189 * RETURN: None.
190 *
191 * DESCRIPTION: Dispatch a device notification event to a previously
192 * installed handler.
193 *
194 ******************************************************************************/
195
Len Brown4be44fc2005-08-05 00:44:28 -0400196static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
Bob Moore86ed4bc2012-05-03 11:08:19 +0800198 union acpi_generic_state *info = (union acpi_generic_state *)context;
Len Brown4be44fc2005-08-05 00:44:28 -0400199 union acpi_operand_object *handler_obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Len Brown4be44fc2005-08-05 00:44:28 -0400201 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Bob Moore86ed4bc2012-05-03 11:08:19 +0800203 /* Invoke a global notify handler if installed */
Bob Moore52fc0b02006-10-02 00:00:00 -0400204
Bob Moore86ed4bc2012-05-03 11:08:19 +0800205 if (info->notify.global->handler) {
206 info->notify.global->handler(info->notify.node,
207 info->notify.value,
208 info->notify.global->context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 }
210
Bob Moore86ed4bc2012-05-03 11:08:19 +0800211 /* Now invoke the local notify handler(s) if any are installed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Bob Moore86ed4bc2012-05-03 11:08:19 +0800213 handler_obj = info->notify.handler_list_head;
214 while (handler_obj) {
215 handler_obj->notify.handler(info->notify.node,
216 info->notify.value,
217 handler_obj->notify.context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Bob Moore86ed4bc2012-05-03 11:08:19 +0800219 handler_obj =
220 handler_obj->notify.next[info->notify.handler_list_id];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 }
222
223 /* All done with the info object */
224
Bob Moore86ed4bc2012-05-03 11:08:19 +0800225 acpi_ut_delete_generic_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
227
Bob Moore33620c52012-02-14 18:14:27 +0800228#if (!ACPI_REDUCED_HARDWARE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229/******************************************************************************
230 *
231 * FUNCTION: acpi_ev_terminate
232 *
233 * PARAMETERS: none
234 *
235 * RETURN: none
236 *
237 * DESCRIPTION: Disable events and free memory allocated for table storage.
238 *
239 ******************************************************************************/
240
Len Brown4be44fc2005-08-05 00:44:28 -0400241void acpi_ev_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Bob Moore67a119f2008-06-10 13:42:13 +0800243 u32 i;
Len Brown4be44fc2005-08-05 00:44:28 -0400244 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Bob Mooreb229cf92006-04-21 17:15:00 -0400246 ACPI_FUNCTION_TRACE(ev_terminate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248 if (acpi_gbl_events_initialized) {
249 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800250 * Disable all event-related functionality. In all cases, on error,
251 * print a message but obviously we don't abort.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 */
253
254 /* Disable all fixed events */
255
256 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
Bob Moore67a119f2008-06-10 13:42:13 +0800257 status = acpi_disable_event(i, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400258 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500259 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800260 "Could not disable fixed event %u",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500261 (u32) i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
263 }
264
265 /* Disable all GPEs in all GPE blocks */
266
Bob Mooree97d6bf2008-12-30 09:45:17 +0800267 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Bob Moore88760162007-02-02 19:48:22 +0300269 status = acpi_ev_remove_global_lock_handler();
270 if (ACPI_FAILURE(status)) {
271 ACPI_ERROR((AE_INFO,
272 "Could not remove Global Lock handler"));
273 }
Tomasz Nowicki64f3af52013-06-08 01:00:23 +0000274
275 acpi_gbl_events_initialized = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 }
277
Lv Zhenga2fd4b42013-09-23 09:52:05 +0800278 /* Remove SCI handlers */
279
280 status = acpi_ev_remove_all_sci_handlers();
281 if (ACPI_FAILURE(status)) {
282 ACPI_ERROR((AE_INFO, "Could not remove SCI handler"));
283 }
284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 /* Deallocate all handler objects installed within GPE info structs */
286
Bob Mooree97d6bf2008-12-30 09:45:17 +0800287 status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 /* Return to original mode if necessary */
290
291 if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400292 status = acpi_disable();
293 if (ACPI_FAILURE(status)) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400294 ACPI_WARNING((AE_INFO, "AcpiDisable failed"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 }
296 }
297 return_VOID;
298}
Bob Moore33620c52012-02-14 18:14:27 +0800299
300#endif /* !ACPI_REDUCED_HARDWARE */