1 /******************************************************************************
3 * Module Name: evmisc - Miscellaneous event manager support functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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.
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
95 /*******************************************************************************
97 * FUNCTION: AcpiEvQueueNotifyRequest
99 * PARAMETERS: Node - NS node for the notified object
100 * NotifyValue - Value from the Notify() request
104 * DESCRIPTION: Dispatch a device notification event to a previously
107 ******************************************************************************/
110 AcpiEvQueueNotifyRequest (
111 ACPI_NAMESPACE_NODE
*Node
,
114 ACPI_OPERAND_OBJECT
*ObjDesc
;
115 ACPI_OPERAND_OBJECT
*HandlerListHead
= NULL
;
116 ACPI_GENERIC_STATE
*Info
;
117 UINT8 HandlerListId
= 0;
118 ACPI_STATUS Status
= AE_OK
;
121 ACPI_FUNCTION_NAME (EvQueueNotifyRequest
);
124 /* Are Notifies allowed on this object? */
126 if (!AcpiEvIsNotifyObject (Node
))
131 /* Get the correct notify list type (System or Device) */
133 if (NotifyValue
<= ACPI_MAX_SYS_NOTIFY
)
135 HandlerListId
= ACPI_SYSTEM_HANDLER_LIST
;
139 HandlerListId
= ACPI_DEVICE_HANDLER_LIST
;
142 /* Get the notify object attached to the namespace Node */
144 ObjDesc
= AcpiNsGetAttachedObject (Node
);
147 /* We have an attached object, Get the correct handler list */
149 HandlerListHead
= ObjDesc
->CommonNotify
.NotifyList
[HandlerListId
];
153 * If there is no notify handler (Global or Local)
154 * for this object, just ignore the notify
156 if (!AcpiGbl_GlobalNotify
[HandlerListId
].Handler
&& !HandlerListHead
)
158 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
159 "No notify handler for Notify, ignoring (%4.4s, %X) node %p\n",
160 AcpiUtGetNodeName (Node
), NotifyValue
, Node
));
165 /* Setup notify info and schedule the notify dispatcher */
167 Info
= AcpiUtCreateGenericState ();
170 return (AE_NO_MEMORY
);
173 Info
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE_NOTIFY
;
175 Info
->Notify
.Node
= Node
;
176 Info
->Notify
.Value
= (UINT16
) NotifyValue
;
177 Info
->Notify
.HandlerListId
= HandlerListId
;
178 Info
->Notify
.HandlerListHead
= HandlerListHead
;
179 Info
->Notify
.Global
= &AcpiGbl_GlobalNotify
[HandlerListId
];
181 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
182 "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n",
183 AcpiUtGetNodeName (Node
), AcpiUtGetTypeName (Node
->Type
),
184 NotifyValue
, AcpiUtGetNotifyName (NotifyValue
), Node
));
186 Status
= AcpiOsExecute (OSL_NOTIFY_HANDLER
, AcpiEvNotifyDispatch
,
188 if (ACPI_FAILURE (Status
))
190 AcpiUtDeleteGenericState (Info
);
197 /*******************************************************************************
199 * FUNCTION: AcpiEvNotifyDispatch
201 * PARAMETERS: Context - To be passed to the notify handler
205 * DESCRIPTION: Dispatch a device notification event to a previously
208 ******************************************************************************/
210 static void ACPI_SYSTEM_XFACE
211 AcpiEvNotifyDispatch (
214 ACPI_GENERIC_STATE
*Info
= (ACPI_GENERIC_STATE
*) Context
;
215 ACPI_OPERAND_OBJECT
*HandlerObj
;
218 ACPI_FUNCTION_ENTRY ();
221 /* Invoke a global notify handler if installed */
223 if (Info
->Notify
.Global
->Handler
)
225 Info
->Notify
.Global
->Handler (Info
->Notify
.Node
,
227 Info
->Notify
.Global
->Context
);
230 /* Now invoke the local notify handler(s) if any are installed */
232 HandlerObj
= Info
->Notify
.HandlerListHead
;
235 HandlerObj
->Notify
.Handler (Info
->Notify
.Node
,
237 HandlerObj
->Notify
.Context
);
239 HandlerObj
= HandlerObj
->Notify
.Next
[Info
->Notify
.HandlerListId
];
242 /* All done with the info object */
244 AcpiUtDeleteGenericState (Info
);
248 #if (!ACPI_REDUCED_HARDWARE)
249 /******************************************************************************
251 * FUNCTION: AcpiEvTerminate
257 * DESCRIPTION: Disable events and free memory allocated for table storage.
259 ******************************************************************************/
269 ACPI_FUNCTION_TRACE (EvTerminate
);
272 if (AcpiGbl_EventsInitialized
)
275 * Disable all event-related functionality. In all cases, on error,
276 * print a message but obviously we don't abort.
279 /* Disable all fixed events */
281 for (i
= 0; i
< ACPI_NUM_FIXED_EVENTS
; i
++)
283 Status
= AcpiDisableEvent (i
, 0);
284 if (ACPI_FAILURE (Status
))
286 ACPI_ERROR ((AE_INFO
,
287 "Could not disable fixed event %u", (UINT32
) i
));
291 /* Disable all GPEs in all GPE blocks */
293 Status
= AcpiEvWalkGpeList (AcpiHwDisableGpeBlock
, NULL
);
295 Status
= AcpiEvRemoveGlobalLockHandler ();
296 if (ACPI_FAILURE(Status
))
298 ACPI_ERROR ((AE_INFO
,
299 "Could not remove Global Lock handler"));
302 AcpiGbl_EventsInitialized
= FALSE
;
305 /* Remove SCI handlers */
307 Status
= AcpiEvRemoveAllSciHandlers ();
308 if (ACPI_FAILURE(Status
))
310 ACPI_ERROR ((AE_INFO
,
311 "Could not remove SCI handler"));
314 /* Deallocate all handler objects installed within GPE info structs */
316 Status
= AcpiEvWalkGpeList (AcpiEvDeleteGpeHandlers
, NULL
);
318 /* Return to original mode if necessary */
320 if (AcpiGbl_OriginalMode
== ACPI_SYS_MODE_LEGACY
)
322 Status
= AcpiDisable ();
323 if (ACPI_FAILURE (Status
))
325 ACPI_WARNING ((AE_INFO
, "AcpiDisable failed"));
331 #endif /* !ACPI_REDUCED_HARDWARE */