1 /******************************************************************************
3 * Module Name: evmisc - Miscellaneous event manager support functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acevents.h>
47 #include <contrib/dev/acpica/include/acnamesp.h>
49 #define _COMPONENT ACPI_EVENTS
50 ACPI_MODULE_NAME ("evmisc")
53 /* Local prototypes */
55 static void ACPI_SYSTEM_XFACE
56 AcpiEvNotifyDispatch (
60 /*******************************************************************************
62 * FUNCTION: AcpiEvIsNotifyObject
64 * PARAMETERS: Node - Node to check
66 * RETURN: TRUE if notifies allowed on this object
68 * DESCRIPTION: Check type of node for a object that supports notifies.
70 * TBD: This could be replaced by a flag bit in the node.
72 ******************************************************************************/
75 AcpiEvIsNotifyObject (
76 ACPI_NAMESPACE_NODE *Node)
80 case ACPI_TYPE_DEVICE:
81 case ACPI_TYPE_PROCESSOR:
82 case ACPI_TYPE_THERMAL:
84 * These are the ONLY objects that can receive ACPI notifications
94 /*******************************************************************************
96 * FUNCTION: AcpiEvQueueNotifyRequest
98 * PARAMETERS: Node - NS node for the notified object
99 * NotifyValue - Value from the Notify() request
103 * DESCRIPTION: Dispatch a device notification event to a previously
106 ******************************************************************************/
109 AcpiEvQueueNotifyRequest (
110 ACPI_NAMESPACE_NODE *Node,
113 ACPI_OPERAND_OBJECT *ObjDesc;
114 ACPI_OPERAND_OBJECT *HandlerObj = NULL;
115 ACPI_GENERIC_STATE *NotifyInfo;
116 ACPI_STATUS Status = AE_OK;
119 ACPI_FUNCTION_NAME (EvQueueNotifyRequest);
123 * For value 3 (Ejection Request), some device method may need to be run.
124 * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need
126 * For value 0x80 (Status Change) on the power button or sleep button,
127 * initiate soft-off or sleep operation?
129 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
130 "Dispatching Notify on [%4.4s] Node %p Value 0x%2.2X (%s)\n",
131 AcpiUtGetNodeName (Node), Node, NotifyValue,
132 AcpiUtGetNotifyName (NotifyValue)));
134 /* Get the notify object attached to the NS Node */
136 ObjDesc = AcpiNsGetAttachedObject (Node);
139 /* We have the notify object, Get the right handler */
143 /* Notify allowed only on these types */
145 case ACPI_TYPE_DEVICE:
146 case ACPI_TYPE_THERMAL:
147 case ACPI_TYPE_PROCESSOR:
149 if (NotifyValue <= ACPI_MAX_SYS_NOTIFY)
151 HandlerObj = ObjDesc->CommonNotify.SystemNotify;
155 HandlerObj = ObjDesc->CommonNotify.DeviceNotify;
161 /* All other types are not supported */
168 * If there is any handler to run, schedule the dispatcher.
170 * 1) Global system notify handler
171 * 2) Global device notify handler
172 * 3) Per-device notify handler
174 if ((AcpiGbl_SystemNotify.Handler &&
175 (NotifyValue <= ACPI_MAX_SYS_NOTIFY)) ||
176 (AcpiGbl_DeviceNotify.Handler &&
177 (NotifyValue > ACPI_MAX_SYS_NOTIFY)) ||
180 NotifyInfo = AcpiUtCreateGenericState ();
183 return (AE_NO_MEMORY);
188 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
189 "Executing system notify handler for Notify (%4.4s, %X) "
191 AcpiUtGetNodeName (Node), NotifyValue, Node));
194 NotifyInfo->Common.DescriptorType = ACPI_DESC_TYPE_STATE_NOTIFY;
195 NotifyInfo->Notify.Node = Node;
196 NotifyInfo->Notify.Value = (UINT16) NotifyValue;
197 NotifyInfo->Notify.HandlerObj = HandlerObj;
199 Status = AcpiOsExecute (
200 OSL_NOTIFY_HANDLER, AcpiEvNotifyDispatch, NotifyInfo);
201 if (ACPI_FAILURE (Status))
203 AcpiUtDeleteGenericState (NotifyInfo);
208 /* There is no notify handler (per-device or system) for this device */
210 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
211 "No notify handler for Notify (%4.4s, %X) node %p\n",
212 AcpiUtGetNodeName (Node), NotifyValue, Node));
219 /*******************************************************************************
221 * FUNCTION: AcpiEvNotifyDispatch
223 * PARAMETERS: Context - To be passed to the notify handler
227 * DESCRIPTION: Dispatch a device notification event to a previously
230 ******************************************************************************/
232 static void ACPI_SYSTEM_XFACE
233 AcpiEvNotifyDispatch (
236 ACPI_GENERIC_STATE *NotifyInfo = (ACPI_GENERIC_STATE *) Context;
237 ACPI_NOTIFY_HANDLER GlobalHandler = NULL;
238 void *GlobalContext = NULL;
239 ACPI_OPERAND_OBJECT *HandlerObj;
242 ACPI_FUNCTION_ENTRY ();
246 * We will invoke a global notify handler if installed. This is done
247 * _before_ we invoke the per-device handler attached to the device.
249 if (NotifyInfo->Notify.Value <= ACPI_MAX_SYS_NOTIFY)
251 /* Global system notification handler */
253 if (AcpiGbl_SystemNotify.Handler)
255 GlobalHandler = AcpiGbl_SystemNotify.Handler;
256 GlobalContext = AcpiGbl_SystemNotify.Context;
261 /* Global driver notification handler */
263 if (AcpiGbl_DeviceNotify.Handler)
265 GlobalHandler = AcpiGbl_DeviceNotify.Handler;
266 GlobalContext = AcpiGbl_DeviceNotify.Context;
270 /* Invoke the system handler first, if present */
274 GlobalHandler (NotifyInfo->Notify.Node, NotifyInfo->Notify.Value,
278 /* Now invoke the per-device handler, if present */
280 HandlerObj = NotifyInfo->Notify.HandlerObj;
283 HandlerObj->Notify.Handler (NotifyInfo->Notify.Node,
284 NotifyInfo->Notify.Value,
285 HandlerObj->Notify.Context);
288 /* All done with the info object */
290 AcpiUtDeleteGenericState (NotifyInfo);
294 /******************************************************************************
296 * FUNCTION: AcpiEvTerminate
302 * DESCRIPTION: Disable events and free memory allocated for table storage.
304 ******************************************************************************/
314 ACPI_FUNCTION_TRACE (EvTerminate);
317 if (AcpiGbl_EventsInitialized)
320 * Disable all event-related functionality. In all cases, on error,
321 * print a message but obviously we don't abort.
324 /* Disable all fixed events */
326 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
328 Status = AcpiDisableEvent (i, 0);
329 if (ACPI_FAILURE (Status))
331 ACPI_ERROR ((AE_INFO,
332 "Could not disable fixed event %u", (UINT32) i));
336 /* Disable all GPEs in all GPE blocks */
338 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
340 /* Remove SCI handler */
342 Status = AcpiEvRemoveSciHandler ();
343 if (ACPI_FAILURE(Status))
345 ACPI_ERROR ((AE_INFO,
346 "Could not remove SCI handler"));
349 Status = AcpiEvRemoveGlobalLockHandler ();
350 if (ACPI_FAILURE(Status))
352 ACPI_ERROR ((AE_INFO,
353 "Could not remove Global Lock handler"));
357 /* Deallocate all handler objects installed within GPE info structs */
359 Status = AcpiEvWalkGpeList (AcpiEvDeleteGpeHandlers, NULL);
361 /* Return to original mode if necessary */
363 if (AcpiGbl_OriginalMode == ACPI_SYS_MODE_LEGACY)
365 Status = AcpiDisable ();
366 if (ACPI_FAILURE (Status))
368 ACPI_WARNING ((AE_INFO, "AcpiDisable failed"));