xref: /titanic_50/usr/src/uts/intel/io/acpica/events/evmisc.c (revision 385cc6b4ad1792caef3f84eb61eed3f27085801f)
1ae115bc7Smrj /******************************************************************************
2ae115bc7Smrj  *
3ae115bc7Smrj  * Module Name: evmisc - Miscellaneous event manager support functions
4ae115bc7Smrj  *
5ae115bc7Smrj  *****************************************************************************/
6ae115bc7Smrj 
726f3cdf0SGordon Ross /*
8*385cc6b4SJerry Jelinek  * Copyright (C) 2000 - 2016, Intel Corp.
9ae115bc7Smrj  * All rights reserved.
10ae115bc7Smrj  *
1126f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
1226f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
1326f3cdf0SGordon Ross  * are met:
1426f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
1526f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
1626f3cdf0SGordon Ross  *    without modification.
1726f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1826f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
1926f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
2026f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
2126f3cdf0SGordon Ross  *    binary redistribution.
2226f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
2326f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
2426f3cdf0SGordon Ross  *    from this software without specific prior written permission.
25ae115bc7Smrj  *
2626f3cdf0SGordon Ross  * Alternatively, this software may be distributed under the terms of the
2726f3cdf0SGordon Ross  * GNU General Public License ("GPL") version 2 as published by the Free
2826f3cdf0SGordon Ross  * Software Foundation.
29ae115bc7Smrj  *
3026f3cdf0SGordon Ross  * NO WARRANTY
3126f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3226f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3326f3cdf0SGordon Ross  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3426f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3526f3cdf0SGordon Ross  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3626f3cdf0SGordon Ross  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3726f3cdf0SGordon Ross  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3826f3cdf0SGordon Ross  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3926f3cdf0SGordon Ross  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4026f3cdf0SGordon Ross  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4126f3cdf0SGordon Ross  * POSSIBILITY OF SUCH DAMAGES.
4226f3cdf0SGordon Ross  */
43ae115bc7Smrj 
44ae115bc7Smrj #include "acpi.h"
45aa2aa9a6SDana Myers #include "accommon.h"
46ae115bc7Smrj #include "acevents.h"
47ae115bc7Smrj #include "acnamesp.h"
48ae115bc7Smrj 
49ae115bc7Smrj #define _COMPONENT          ACPI_EVENTS
50ae115bc7Smrj         ACPI_MODULE_NAME    ("evmisc")
51ae115bc7Smrj 
52ae115bc7Smrj 
53ae115bc7Smrj /* Local prototypes */
54ae115bc7Smrj 
55ae115bc7Smrj static void ACPI_SYSTEM_XFACE
56ae115bc7Smrj AcpiEvNotifyDispatch (
57ae115bc7Smrj     void                    *Context);
58ae115bc7Smrj 
59ae115bc7Smrj 
60ae115bc7Smrj /*******************************************************************************
61ae115bc7Smrj  *
62ae115bc7Smrj  * FUNCTION:    AcpiEvIsNotifyObject
63ae115bc7Smrj  *
64ae115bc7Smrj  * PARAMETERS:  Node            - Node to check
65ae115bc7Smrj  *
66ae115bc7Smrj  * RETURN:      TRUE if notifies allowed on this object
67ae115bc7Smrj  *
68ae115bc7Smrj  * DESCRIPTION: Check type of node for a object that supports notifies.
69ae115bc7Smrj  *
70ae115bc7Smrj  *              TBD: This could be replaced by a flag bit in the node.
71ae115bc7Smrj  *
72ae115bc7Smrj  ******************************************************************************/
73ae115bc7Smrj 
74ae115bc7Smrj BOOLEAN
AcpiEvIsNotifyObject(ACPI_NAMESPACE_NODE * Node)75ae115bc7Smrj AcpiEvIsNotifyObject (
76ae115bc7Smrj     ACPI_NAMESPACE_NODE     *Node)
77ae115bc7Smrj {
78*385cc6b4SJerry Jelinek 
79ae115bc7Smrj     switch (Node->Type)
80ae115bc7Smrj     {
81ae115bc7Smrj     case ACPI_TYPE_DEVICE:
82ae115bc7Smrj     case ACPI_TYPE_PROCESSOR:
83ae115bc7Smrj     case ACPI_TYPE_THERMAL:
84ae115bc7Smrj         /*
85ae115bc7Smrj          * These are the ONLY objects that can receive ACPI notifications
86ae115bc7Smrj          */
87ae115bc7Smrj         return (TRUE);
88ae115bc7Smrj 
89ae115bc7Smrj     default:
90*385cc6b4SJerry Jelinek 
91ae115bc7Smrj         return (FALSE);
92ae115bc7Smrj     }
93ae115bc7Smrj }
94ae115bc7Smrj 
95ae115bc7Smrj 
96ae115bc7Smrj /*******************************************************************************
97ae115bc7Smrj  *
98ae115bc7Smrj  * FUNCTION:    AcpiEvQueueNotifyRequest
99ae115bc7Smrj  *
100ae115bc7Smrj  * PARAMETERS:  Node            - NS node for the notified object
101ae115bc7Smrj  *              NotifyValue     - Value from the Notify() request
102ae115bc7Smrj  *
103ae115bc7Smrj  * RETURN:      Status
104ae115bc7Smrj  *
105ae115bc7Smrj  * DESCRIPTION: Dispatch a device notification event to a previously
106ae115bc7Smrj  *              installed handler.
107ae115bc7Smrj  *
108ae115bc7Smrj  ******************************************************************************/
109ae115bc7Smrj 
110ae115bc7Smrj ACPI_STATUS
AcpiEvQueueNotifyRequest(ACPI_NAMESPACE_NODE * Node,UINT32 NotifyValue)111ae115bc7Smrj AcpiEvQueueNotifyRequest (
112ae115bc7Smrj     ACPI_NAMESPACE_NODE     *Node,
113ae115bc7Smrj     UINT32                  NotifyValue)
114ae115bc7Smrj {
115ae115bc7Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
116*385cc6b4SJerry Jelinek     ACPI_OPERAND_OBJECT     *HandlerListHead = NULL;
117*385cc6b4SJerry Jelinek     ACPI_GENERIC_STATE      *Info;
118*385cc6b4SJerry Jelinek     UINT8                   HandlerListId = 0;
119ae115bc7Smrj     ACPI_STATUS             Status = AE_OK;
120ae115bc7Smrj 
121ae115bc7Smrj 
122ae115bc7Smrj     ACPI_FUNCTION_NAME (EvQueueNotifyRequest);
123ae115bc7Smrj 
124ae115bc7Smrj 
125*385cc6b4SJerry Jelinek     /* Are Notifies allowed on this object? */
126ae115bc7Smrj 
127*385cc6b4SJerry Jelinek     if (!AcpiEvIsNotifyObject (Node))
128*385cc6b4SJerry Jelinek     {
129*385cc6b4SJerry Jelinek         return (AE_TYPE);
130*385cc6b4SJerry Jelinek     }
131*385cc6b4SJerry Jelinek 
132*385cc6b4SJerry Jelinek     /* Get the correct notify list type (System or Device) */
133*385cc6b4SJerry Jelinek 
134*385cc6b4SJerry Jelinek     if (NotifyValue <= ACPI_MAX_SYS_NOTIFY)
135*385cc6b4SJerry Jelinek     {
136*385cc6b4SJerry Jelinek         HandlerListId = ACPI_SYSTEM_HANDLER_LIST;
137*385cc6b4SJerry Jelinek     }
138*385cc6b4SJerry Jelinek     else
139*385cc6b4SJerry Jelinek     {
140*385cc6b4SJerry Jelinek         HandlerListId = ACPI_DEVICE_HANDLER_LIST;
141*385cc6b4SJerry Jelinek     }
142*385cc6b4SJerry Jelinek 
143*385cc6b4SJerry Jelinek     /* Get the notify object attached to the namespace Node */
144ae115bc7Smrj 
145ae115bc7Smrj     ObjDesc = AcpiNsGetAttachedObject (Node);
146ae115bc7Smrj     if (ObjDesc)
147ae115bc7Smrj     {
148*385cc6b4SJerry Jelinek         /* We have an attached object, Get the correct handler list */
149ae115bc7Smrj 
150*385cc6b4SJerry Jelinek         HandlerListHead = ObjDesc->CommonNotify.NotifyList[HandlerListId];
151ae115bc7Smrj     }
152ae115bc7Smrj 
153db2bae30SDana Myers     /*
154*385cc6b4SJerry Jelinek      * If there is no notify handler (Global or Local)
155*385cc6b4SJerry Jelinek      * for this object, just ignore the notify
156db2bae30SDana Myers      */
157*385cc6b4SJerry Jelinek     if (!AcpiGbl_GlobalNotify[HandlerListId].Handler && !HandlerListHead)
158ae115bc7Smrj     {
159*385cc6b4SJerry Jelinek         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
160*385cc6b4SJerry Jelinek             "No notify handler for Notify, ignoring (%4.4s, %X) node %p\n",
161*385cc6b4SJerry Jelinek             AcpiUtGetNodeName (Node), NotifyValue, Node));
162*385cc6b4SJerry Jelinek 
163*385cc6b4SJerry Jelinek         return (AE_OK);
164*385cc6b4SJerry Jelinek     }
165*385cc6b4SJerry Jelinek 
166*385cc6b4SJerry Jelinek     /* Setup notify info and schedule the notify dispatcher */
167*385cc6b4SJerry Jelinek 
168*385cc6b4SJerry Jelinek     Info = AcpiUtCreateGenericState ();
169*385cc6b4SJerry Jelinek     if (!Info)
170ae115bc7Smrj     {
171ae115bc7Smrj         return (AE_NO_MEMORY);
172ae115bc7Smrj     }
173ae115bc7Smrj 
174*385cc6b4SJerry Jelinek     Info->Common.DescriptorType = ACPI_DESC_TYPE_STATE_NOTIFY;
175*385cc6b4SJerry Jelinek 
176*385cc6b4SJerry Jelinek     Info->Notify.Node = Node;
177*385cc6b4SJerry Jelinek     Info->Notify.Value = (UINT16) NotifyValue;
178*385cc6b4SJerry Jelinek     Info->Notify.HandlerListId = HandlerListId;
179*385cc6b4SJerry Jelinek     Info->Notify.HandlerListHead = HandlerListHead;
180*385cc6b4SJerry Jelinek     Info->Notify.Global = &AcpiGbl_GlobalNotify[HandlerListId];
181*385cc6b4SJerry Jelinek 
182db2bae30SDana Myers     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
183*385cc6b4SJerry Jelinek         "Dispatching Notify on [%4.4s] (%s) Value 0x%2.2X (%s) Node %p\n",
184*385cc6b4SJerry Jelinek         AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type),
185*385cc6b4SJerry Jelinek         NotifyValue, AcpiUtGetNotifyName (NotifyValue, ACPI_TYPE_ANY), Node));
186db2bae30SDana Myers 
187*385cc6b4SJerry Jelinek     Status = AcpiOsExecute (OSL_NOTIFY_HANDLER,
188*385cc6b4SJerry Jelinek         AcpiEvNotifyDispatch, Info);
189ae115bc7Smrj     if (ACPI_FAILURE (Status))
190ae115bc7Smrj     {
191*385cc6b4SJerry Jelinek         AcpiUtDeleteGenericState (Info);
192ae115bc7Smrj     }
193ae115bc7Smrj 
194ae115bc7Smrj     return (Status);
195ae115bc7Smrj }
196ae115bc7Smrj 
197ae115bc7Smrj 
198ae115bc7Smrj /*******************************************************************************
199ae115bc7Smrj  *
200ae115bc7Smrj  * FUNCTION:    AcpiEvNotifyDispatch
201ae115bc7Smrj  *
202ae115bc7Smrj  * PARAMETERS:  Context         - To be passed to the notify handler
203ae115bc7Smrj  *
204ae115bc7Smrj  * RETURN:      None.
205ae115bc7Smrj  *
206ae115bc7Smrj  * DESCRIPTION: Dispatch a device notification event to a previously
207ae115bc7Smrj  *              installed handler.
208ae115bc7Smrj  *
209ae115bc7Smrj  ******************************************************************************/
210ae115bc7Smrj 
211ae115bc7Smrj static void ACPI_SYSTEM_XFACE
AcpiEvNotifyDispatch(void * Context)212ae115bc7Smrj AcpiEvNotifyDispatch (
213ae115bc7Smrj     void                    *Context)
214ae115bc7Smrj {
215*385cc6b4SJerry Jelinek     ACPI_GENERIC_STATE      *Info = (ACPI_GENERIC_STATE *) Context;
216ae115bc7Smrj     ACPI_OPERAND_OBJECT     *HandlerObj;
217ae115bc7Smrj 
218ae115bc7Smrj 
219ae115bc7Smrj     ACPI_FUNCTION_ENTRY ();
220ae115bc7Smrj 
221ae115bc7Smrj 
222*385cc6b4SJerry Jelinek     /* Invoke a global notify handler if installed */
223ae115bc7Smrj 
224*385cc6b4SJerry Jelinek     if (Info->Notify.Global->Handler)
225ae115bc7Smrj     {
226*385cc6b4SJerry Jelinek         Info->Notify.Global->Handler (Info->Notify.Node,
227*385cc6b4SJerry Jelinek             Info->Notify.Value,
228*385cc6b4SJerry Jelinek             Info->Notify.Global->Context);
229ae115bc7Smrj     }
230ae115bc7Smrj 
231*385cc6b4SJerry Jelinek     /* Now invoke the local notify handler(s) if any are installed */
232ae115bc7Smrj 
233*385cc6b4SJerry Jelinek     HandlerObj = Info->Notify.HandlerListHead;
234*385cc6b4SJerry Jelinek     while (HandlerObj)
235ae115bc7Smrj     {
236*385cc6b4SJerry Jelinek         HandlerObj->Notify.Handler (Info->Notify.Node,
237*385cc6b4SJerry Jelinek             Info->Notify.Value,
238ae115bc7Smrj             HandlerObj->Notify.Context);
239*385cc6b4SJerry Jelinek 
240*385cc6b4SJerry Jelinek         HandlerObj = HandlerObj->Notify.Next[Info->Notify.HandlerListId];
241ae115bc7Smrj     }
242ae115bc7Smrj 
243ae115bc7Smrj     /* All done with the info object */
244ae115bc7Smrj 
245*385cc6b4SJerry Jelinek     AcpiUtDeleteGenericState (Info);
246ae115bc7Smrj }
247ae115bc7Smrj 
248ae115bc7Smrj 
249*385cc6b4SJerry Jelinek #if (!ACPI_REDUCED_HARDWARE)
250ae115bc7Smrj /******************************************************************************
251ae115bc7Smrj  *
252ae115bc7Smrj  * FUNCTION:    AcpiEvTerminate
253ae115bc7Smrj  *
254ae115bc7Smrj  * PARAMETERS:  none
255ae115bc7Smrj  *
256ae115bc7Smrj  * RETURN:      none
257ae115bc7Smrj  *
258ae115bc7Smrj  * DESCRIPTION: Disable events and free memory allocated for table storage.
259ae115bc7Smrj  *
260ae115bc7Smrj  ******************************************************************************/
261ae115bc7Smrj 
262ae115bc7Smrj void
AcpiEvTerminate(void)263ae115bc7Smrj AcpiEvTerminate (
264ae115bc7Smrj     void)
265ae115bc7Smrj {
266db2bae30SDana Myers     UINT32                  i;
267ae115bc7Smrj     ACPI_STATUS             Status;
268ae115bc7Smrj 
269ae115bc7Smrj 
270ae115bc7Smrj     ACPI_FUNCTION_TRACE (EvTerminate);
271ae115bc7Smrj 
272ae115bc7Smrj 
273ae115bc7Smrj     if (AcpiGbl_EventsInitialized)
274ae115bc7Smrj     {
275ae115bc7Smrj         /*
276aa2aa9a6SDana Myers          * Disable all event-related functionality. In all cases, on error,
277aa2aa9a6SDana Myers          * print a message but obviously we don't abort.
278ae115bc7Smrj          */
279ae115bc7Smrj 
280ae115bc7Smrj         /* Disable all fixed events */
281ae115bc7Smrj 
282ae115bc7Smrj         for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
283ae115bc7Smrj         {
284db2bae30SDana Myers             Status = AcpiDisableEvent (i, 0);
285ae115bc7Smrj             if (ACPI_FAILURE (Status))
286ae115bc7Smrj             {
287ae115bc7Smrj                 ACPI_ERROR ((AE_INFO,
28826f3cdf0SGordon Ross                     "Could not disable fixed event %u", (UINT32) i));
289ae115bc7Smrj             }
290ae115bc7Smrj         }
291ae115bc7Smrj 
292ae115bc7Smrj         /* Disable all GPEs in all GPE blocks */
293ae115bc7Smrj 
294aa2aa9a6SDana Myers         Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
295ae115bc7Smrj 
296db2bae30SDana Myers         Status = AcpiEvRemoveGlobalLockHandler ();
297db2bae30SDana Myers         if (ACPI_FAILURE(Status))
298db2bae30SDana Myers         {
299db2bae30SDana Myers             ACPI_ERROR ((AE_INFO,
300db2bae30SDana Myers                 "Could not remove Global Lock handler"));
301db2bae30SDana Myers         }
302*385cc6b4SJerry Jelinek 
303*385cc6b4SJerry Jelinek         AcpiGbl_EventsInitialized = FALSE;
304*385cc6b4SJerry Jelinek     }
305*385cc6b4SJerry Jelinek 
306*385cc6b4SJerry Jelinek     /* Remove SCI handlers */
307*385cc6b4SJerry Jelinek 
308*385cc6b4SJerry Jelinek     Status = AcpiEvRemoveAllSciHandlers ();
309*385cc6b4SJerry Jelinek     if (ACPI_FAILURE(Status))
310*385cc6b4SJerry Jelinek     {
311*385cc6b4SJerry Jelinek         ACPI_ERROR ((AE_INFO,
312*385cc6b4SJerry Jelinek             "Could not remove SCI handler"));
313ae115bc7Smrj     }
314ae115bc7Smrj 
315ae115bc7Smrj     /* Deallocate all handler objects installed within GPE info structs */
316ae115bc7Smrj 
317aa2aa9a6SDana Myers     Status = AcpiEvWalkGpeList (AcpiEvDeleteGpeHandlers, NULL);
318ae115bc7Smrj 
319ae115bc7Smrj     /* Return to original mode if necessary */
320ae115bc7Smrj 
321ae115bc7Smrj     if (AcpiGbl_OriginalMode == ACPI_SYS_MODE_LEGACY)
322ae115bc7Smrj     {
323ae115bc7Smrj         Status = AcpiDisable ();
324ae115bc7Smrj         if (ACPI_FAILURE (Status))
325ae115bc7Smrj         {
326ae115bc7Smrj             ACPI_WARNING ((AE_INFO, "AcpiDisable failed"));
327ae115bc7Smrj         }
328ae115bc7Smrj     }
329ae115bc7Smrj     return_VOID;
330ae115bc7Smrj }
331*385cc6b4SJerry Jelinek 
332*385cc6b4SJerry Jelinek #endif /* !ACPI_REDUCED_HARDWARE */
333