blob: 51ef9f5e002da1048c4e99d2b8939d0c35976633 [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 Moore77848132012-01-12 13:27:23 +08008 * Copyright (C) 2000 - 2012, 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 *
59 * PARAMETERS: Node - Node to check
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 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{
71 switch (node->type) {
72 case ACPI_TYPE_DEVICE:
73 case ACPI_TYPE_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 case ACPI_TYPE_THERMAL:
75 /*
76 * These are the ONLY objects that can receive ACPI notifications
77 */
78 return (TRUE);
79
80 default:
81 return (FALSE);
82 }
83}
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/*******************************************************************************
86 *
87 * FUNCTION: acpi_ev_queue_notify_request
88 *
89 * PARAMETERS: Node - NS node for the notified object
90 * notify_value - Value from the Notify() request
91 *
92 * RETURN: Status
93 *
94 * DESCRIPTION: Dispatch a device notification event to a previously
95 * installed handler.
96 *
97 ******************************************************************************/
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400100acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
101 u32 notify_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
Len Brown4be44fc2005-08-05 00:44:28 -0400103 union acpi_operand_object *obj_desc;
104 union acpi_operand_object *handler_obj = NULL;
105 union acpi_generic_state *notify_info;
106 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Bob Mooreb229cf92006-04-21 17:15:00 -0400108 ACPI_FUNCTION_NAME(ev_queue_notify_request);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 /*
Bob Mooreea143602012-02-14 18:23:39 +0800111 * For value 0x03 (Ejection Request), may need to run a device method.
112 * For value 0x02 (Device Wake), if _PRW exists, may need to run
113 * the _PS0 method.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 * For value 0x80 (Status Change) on the power button or sleep button,
Bob Mooreea143602012-02-14 18:23:39 +0800115 * initiate soft-off or sleep operation.
116 *
117 * For all cases, simply dispatch the notify to the handler.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 */
Len Brown4be44fc2005-08-05 00:44:28 -0400119 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Mooreea143602012-02-14 18:23:39 +0800120 "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n",
121 acpi_ut_get_node_name(node),
122 acpi_ut_get_type_name(node->type), notify_value,
123 acpi_ut_get_notify_name(notify_value), node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 /* Get the notify object attached to the NS Node */
126
Len Brown4be44fc2005-08-05 00:44:28 -0400127 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 if (obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400129
Bob Mooreea143602012-02-14 18:23:39 +0800130 /* We have the notify object, Get the correct handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 switch (node->type) {
Zhang Rui514d18d2008-04-10 19:06:44 +0400133
Bob Mooreea143602012-02-14 18:23:39 +0800134 /* Notify is allowed only on these types */
Zhang Rui514d18d2008-04-10 19:06:44 +0400135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 case ACPI_TYPE_DEVICE:
137 case ACPI_TYPE_THERMAL:
138 case ACPI_TYPE_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 if (notify_value <= ACPI_MAX_SYS_NOTIFY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400141 handler_obj =
142 obj_desc->common_notify.system_notify;
143 } else {
144 handler_obj =
145 obj_desc->common_notify.device_notify;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
147 break;
148
149 default:
Bob Moore9f15fc62008-11-12 16:01:56 +0800150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 /* All other types are not supported */
Bob Moore9f15fc62008-11-12 16:01:56 +0800152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 return (AE_TYPE);
154 }
155 }
156
Zhang Rui514d18d2008-04-10 19:06:44 +0400157 /*
Bob Mooreea143602012-02-14 18:23:39 +0800158 * If there is a handler to run, schedule the dispatcher.
Zhang Rui514d18d2008-04-10 19:06:44 +0400159 * Check for:
160 * 1) Global system notify handler
161 * 2) Global device notify handler
162 * 3) Per-device notify handler
163 */
Bob Moored4913dc2009-03-06 10:05:18 +0800164 if ((acpi_gbl_system_notify.handler &&
165 (notify_value <= ACPI_MAX_SYS_NOTIFY)) ||
166 (acpi_gbl_device_notify.handler &&
167 (notify_value > ACPI_MAX_SYS_NOTIFY)) || handler_obj) {
Len Brown4be44fc2005-08-05 00:44:28 -0400168 notify_info = acpi_ut_create_generic_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 if (!notify_info) {
170 return (AE_NO_MEMORY);
171 }
172
Zhang Rui514d18d2008-04-10 19:06:44 +0400173 if (!handler_obj) {
174 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Moored4913dc2009-03-06 10:05:18 +0800175 "Executing system notify handler for Notify (%4.4s, %X) "
176 "node %p\n",
Zhang Rui514d18d2008-04-10 19:06:44 +0400177 acpi_ut_get_node_name(node),
178 notify_value, node));
179 }
180
Bob Moore616861242006-03-17 16:44:00 -0500181 notify_info->common.descriptor_type =
182 ACPI_DESC_TYPE_STATE_NOTIFY;
Len Brown4be44fc2005-08-05 00:44:28 -0400183 notify_info->notify.node = node;
184 notify_info->notify.value = (u16) notify_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 notify_info->notify.handler_obj = handler_obj;
186
Len Brown40d07082007-05-09 22:59:38 -0400187 status =
188 acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_notify_dispatch,
189 notify_info);
190 if (ACPI_FAILURE(status)) {
191 acpi_ut_delete_generic_state(notify_info);
192 }
Zhang Rui514d18d2008-04-10 19:06:44 +0400193 } else {
Bob Moore9f15fc62008-11-12 16:01:56 +0800194 /* There is no notify handler (per-device or system) for this device */
195
Len Brown4be44fc2005-08-05 00:44:28 -0400196 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Zhang Rui514d18d2008-04-10 19:06:44 +0400197 "No notify handler for Notify (%4.4s, %X) node %p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400198 acpi_ut_get_node_name(node), notify_value,
199 node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 }
201
202 return (status);
203}
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205/*******************************************************************************
206 *
207 * FUNCTION: acpi_ev_notify_dispatch
208 *
Robert Moore44f6c012005-04-18 22:49:35 -0400209 * PARAMETERS: Context - To be passed to the notify handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 *
211 * RETURN: None.
212 *
213 * DESCRIPTION: Dispatch a device notification event to a previously
214 * installed handler.
215 *
216 ******************************************************************************/
217
Len Brown4be44fc2005-08-05 00:44:28 -0400218static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
Len Brown4be44fc2005-08-05 00:44:28 -0400220 union acpi_generic_state *notify_info =
221 (union acpi_generic_state *)context;
222 acpi_notify_handler global_handler = NULL;
223 void *global_context = NULL;
224 union acpi_operand_object *handler_obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Len Brown4be44fc2005-08-05 00:44:28 -0400226 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800229 * We will invoke a global notify handler if installed. This is done
230 * _before_ we invoke the per-device handler attached to the device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 */
232 if (notify_info->notify.value <= ACPI_MAX_SYS_NOTIFY) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 /* Global system notification handler */
235
236 if (acpi_gbl_system_notify.handler) {
237 global_handler = acpi_gbl_system_notify.handler;
238 global_context = acpi_gbl_system_notify.context;
239 }
Len Brown4be44fc2005-08-05 00:44:28 -0400240 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 /* Global driver notification handler */
242
243 if (acpi_gbl_device_notify.handler) {
244 global_handler = acpi_gbl_device_notify.handler;
245 global_context = acpi_gbl_device_notify.context;
246 }
247 }
248
249 /* Invoke the system handler first, if present */
250
251 if (global_handler) {
Len Brown4be44fc2005-08-05 00:44:28 -0400252 global_handler(notify_info->notify.node,
253 notify_info->notify.value, global_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 }
255
256 /* Now invoke the per-device handler, if present */
257
258 handler_obj = notify_info->notify.handler_obj;
259 if (handler_obj) {
Rafael J. Wysocki3f0be672010-02-17 23:42:59 +0100260 struct acpi_object_notify_handler *notifier;
261
262 notifier = &handler_obj->notify;
263 while (notifier) {
264 notifier->handler(notify_info->notify.node,
265 notify_info->notify.value,
266 notifier->context);
267 notifier = notifier->next;
268 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 }
270
271 /* All done with the info object */
272
Len Brown4be44fc2005-08-05 00:44:28 -0400273 acpi_ut_delete_generic_state(notify_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274}
275
Bob Moore33620c52012-02-14 18:14:27 +0800276#if (!ACPI_REDUCED_HARDWARE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277/******************************************************************************
278 *
279 * FUNCTION: acpi_ev_terminate
280 *
281 * PARAMETERS: none
282 *
283 * RETURN: none
284 *
285 * DESCRIPTION: Disable events and free memory allocated for table storage.
286 *
287 ******************************************************************************/
288
Len Brown4be44fc2005-08-05 00:44:28 -0400289void acpi_ev_terminate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
Bob Moore67a119f2008-06-10 13:42:13 +0800291 u32 i;
Len Brown4be44fc2005-08-05 00:44:28 -0400292 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Bob Mooreb229cf92006-04-21 17:15:00 -0400294 ACPI_FUNCTION_TRACE(ev_terminate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 if (acpi_gbl_events_initialized) {
297 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800298 * Disable all event-related functionality. In all cases, on error,
299 * print a message but obviously we don't abort.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 */
301
302 /* Disable all fixed events */
303
304 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
Bob Moore67a119f2008-06-10 13:42:13 +0800305 status = acpi_disable_event(i, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400306 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500307 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800308 "Could not disable fixed event %u",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500309 (u32) i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311 }
312
313 /* Disable all GPEs in all GPE blocks */
314
Bob Mooree97d6bf2008-12-30 09:45:17 +0800315 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 /* Remove SCI handler */
318
Len Brown4be44fc2005-08-05 00:44:28 -0400319 status = acpi_ev_remove_sci_handler();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500321 ACPI_ERROR((AE_INFO, "Could not remove SCI handler"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 }
Bob Moore88760162007-02-02 19:48:22 +0300323
324 status = acpi_ev_remove_global_lock_handler();
325 if (ACPI_FAILURE(status)) {
326 ACPI_ERROR((AE_INFO,
327 "Could not remove Global Lock handler"));
328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 }
330
331 /* Deallocate all handler objects installed within GPE info structs */
332
Bob Mooree97d6bf2008-12-30 09:45:17 +0800333 status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335 /* Return to original mode if necessary */
336
337 if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400338 status = acpi_disable();
339 if (ACPI_FAILURE(status)) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400340 ACPI_WARNING((AE_INFO, "AcpiDisable failed"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342 }
343 return_VOID;
344}
Bob Moore33620c52012-02-14 18:14:27 +0800345
346#endif /* !ACPI_REDUCED_HARDWARE */