1 /******************************************************************************
3 * Module Name: evmisc - Miscellaneous event manager support functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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
)
81 case ACPI_TYPE_DEVICE
:
82 case ACPI_TYPE_PROCESSOR
:
83 case ACPI_TYPE_THERMAL
:
85 * These are the ONLY objects that can receive ACPI notifications
96 /*******************************************************************************
98 * FUNCTION: AcpiEvQueueNotifyRequest
100 * PARAMETERS: Node - NS node for the notified object
101 * NotifyValue - Value from the Notify() request
105 * DESCRIPTION: Dispatch a device notification event to a previously
108 ******************************************************************************/
111 AcpiEvQueueNotifyRequest (
112 ACPI_NAMESPACE_NODE
*Node
,
115 ACPI_OPERAND_OBJECT
*ObjDesc
;
116 ACPI_OPERAND_OBJECT
*HandlerListHead
= NULL
;
117 ACPI_GENERIC_STATE
*Info
;
118 UINT8 HandlerListId
= 0;
119 ACPI_STATUS Status
= AE_OK
;
122 ACPI_FUNCTION_NAME (EvQueueNotifyRequest
);
125 /* Are Notifies allowed on this object? */
127 if (!AcpiEvIsNotifyObject (Node
))
132 /* Get the correct notify list type (System or Device) */
134 if (NotifyValue
<= ACPI_MAX_SYS_NOTIFY
)
136 HandlerListId
= ACPI_SYSTEM_HANDLER_LIST
;
140 HandlerListId
= ACPI_DEVICE_HANDLER_LIST
;
143 /* Get the notify object attached to the namespace Node */
145 ObjDesc
= AcpiNsGetAttachedObject (Node
);
148 /* We have an attached object, Get the correct handler list */
150 HandlerListHead
= ObjDesc
->CommonNotify
.NotifyList
[HandlerListId
];
154 * If there is no notify handler (Global or Local)
155 * for this object, just ignore the notify
157 if (!AcpiGbl_GlobalNotify
[HandlerListId
].Handler
&& !HandlerListHead
)
159 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
160 "No notify handler for Notify, ignoring (%4.4s, %X) node %p\n",
161 AcpiUtGetNodeName (Node
), NotifyValue
, Node
));
166 /* Setup notify info and schedule the notify dispatcher */
168 Info
= AcpiUtCreateGenericState ();
171 return (AE_NO_MEMORY
);
174 Info
->Common
.DescriptorType
= ACPI_DESC_TYPE_STATE_NOTIFY
;
176 Info
->Notify
.Node
= Node
;
177 Info
->Notify
.Value
= (UINT16
) NotifyValue
;
178 Info
->Notify
.HandlerListId
= HandlerListId
;
179 Info
->Notify
.HandlerListHead
= HandlerListHead
;
180 Info
->Notify
.Global
= &AcpiGbl_GlobalNotify
[HandlerListId
];
182 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
183 "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n",
184 AcpiUtGetNodeName (Node
), AcpiUtGetTypeName (Node
->Type
),
185 NotifyValue
, AcpiUtGetNotifyName (NotifyValue
, ACPI_TYPE_ANY
), Node
));
187 Status
= AcpiOsExecute (OSL_NOTIFY_HANDLER
,
188 AcpiEvNotifyDispatch
, Info
);
189 if (ACPI_FAILURE (Status
))
191 AcpiUtDeleteGenericState (Info
);
198 /*******************************************************************************
200 * FUNCTION: AcpiEvNotifyDispatch
202 * PARAMETERS: Context - To be passed to the notify handler
206 * DESCRIPTION: Dispatch a device notification event to a previously
209 ******************************************************************************/
211 static void ACPI_SYSTEM_XFACE
212 AcpiEvNotifyDispatch (
215 ACPI_GENERIC_STATE
*Info
= (ACPI_GENERIC_STATE
*) Context
;
216 ACPI_OPERAND_OBJECT
*HandlerObj
;
219 ACPI_FUNCTION_ENTRY ();
222 /* Invoke a global notify handler if installed */
224 if (Info
->Notify
.Global
->Handler
)
226 Info
->Notify
.Global
->Handler (Info
->Notify
.Node
,
228 Info
->Notify
.Global
->Context
);
231 /* Now invoke the local notify handler(s) if any are installed */
233 HandlerObj
= Info
->Notify
.HandlerListHead
;
236 HandlerObj
->Notify
.Handler (Info
->Notify
.Node
,
238 HandlerObj
->Notify
.Context
);
240 HandlerObj
= HandlerObj
->Notify
.Next
[Info
->Notify
.HandlerListId
];
243 /* All done with the info object */
245 AcpiUtDeleteGenericState (Info
);
249 #if (!ACPI_REDUCED_HARDWARE)
250 /******************************************************************************
252 * FUNCTION: AcpiEvTerminate
258 * DESCRIPTION: Disable events and free memory allocated for table storage.
260 ******************************************************************************/
270 ACPI_FUNCTION_TRACE (EvTerminate
);
273 if (AcpiGbl_EventsInitialized
)
276 * Disable all event-related functionality. In all cases, on error,
277 * print a message but obviously we don't abort.
280 /* Disable all fixed events */
282 for (i
= 0; i
< ACPI_NUM_FIXED_EVENTS
; i
++)
284 Status
= AcpiDisableEvent (i
, 0);
285 if (ACPI_FAILURE (Status
))
287 ACPI_ERROR ((AE_INFO
,
288 "Could not disable fixed event %u", (UINT32
) i
));
292 /* Disable all GPEs in all GPE blocks */
294 Status
= AcpiEvWalkGpeList (AcpiHwDisableGpeBlock
, NULL
);
296 Status
= AcpiEvRemoveGlobalLockHandler ();
297 if (ACPI_FAILURE(Status
))
299 ACPI_ERROR ((AE_INFO
,
300 "Could not remove Global Lock handler"));
303 AcpiGbl_EventsInitialized
= FALSE
;
306 /* Remove SCI handlers */
308 Status
= AcpiEvRemoveAllSciHandlers ();
309 if (ACPI_FAILURE(Status
))
311 ACPI_ERROR ((AE_INFO
,
312 "Could not remove SCI handler"));
315 /* Deallocate all handler objects installed within GPE info structs */
317 Status
= AcpiEvWalkGpeList (AcpiEvDeleteGpeHandlers
, NULL
);
319 /* Return to original mode if necessary */
321 if (AcpiGbl_OriginalMode
== ACPI_SYS_MODE_LEGACY
)
323 Status
= AcpiDisable ();
324 if (ACPI_FAILURE (Status
))
326 ACPI_WARNING ((AE_INFO
, "AcpiDisable failed"));
332 #endif /* !ACPI_REDUCED_HARDWARE */