xref: /titanic_44/usr/src/uts/intel/io/acpica/utilities/utinit.c (revision cb56572868bfc488bbd3ab847b09db2a25554d44)
1ae115bc7Smrj /******************************************************************************
2ae115bc7Smrj  *
3ae115bc7Smrj  * Module Name: utinit - Common ACPI subsystem initialization
4ae115bc7Smrj  *
5ae115bc7Smrj  *****************************************************************************/
6ae115bc7Smrj 
726f3cdf0SGordon Ross /*
8*cb565728SJerry 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 "acnamesp.h"
47ae115bc7Smrj #include "acevents.h"
48db2bae30SDana Myers #include "actables.h"
49ae115bc7Smrj 
50ae115bc7Smrj #define _COMPONENT          ACPI_UTILITIES
51ae115bc7Smrj         ACPI_MODULE_NAME    ("utinit")
52ae115bc7Smrj 
53ae115bc7Smrj /* Local prototypes */
54ae115bc7Smrj 
55ae115bc7Smrj static void AcpiUtTerminate (
56ae115bc7Smrj     void);
57ae115bc7Smrj 
58*cb565728SJerry Jelinek #if (!ACPI_REDUCED_HARDWARE)
59ae115bc7Smrj 
60*cb565728SJerry Jelinek static void
61*cb565728SJerry Jelinek AcpiUtFreeGpeLists (
62*cb565728SJerry Jelinek     void);
63*cb565728SJerry Jelinek 
64*cb565728SJerry Jelinek #else
65*cb565728SJerry Jelinek 
66*cb565728SJerry Jelinek #define AcpiUtFreeGpeLists()
67*cb565728SJerry Jelinek #endif /* !ACPI_REDUCED_HARDWARE */
68*cb565728SJerry Jelinek 
69*cb565728SJerry Jelinek 
70*cb565728SJerry Jelinek #if (!ACPI_REDUCED_HARDWARE)
71ae115bc7Smrj /******************************************************************************
72ae115bc7Smrj  *
73*cb565728SJerry Jelinek  * FUNCTION:    AcpiUtFreeGpeLists
74ae115bc7Smrj  *
75ae115bc7Smrj  * PARAMETERS:  none
76ae115bc7Smrj  *
77ae115bc7Smrj  * RETURN:      none
78ae115bc7Smrj  *
79*cb565728SJerry Jelinek  * DESCRIPTION: Free global GPE lists
80ae115bc7Smrj  *
81ae115bc7Smrj  ******************************************************************************/
82ae115bc7Smrj 
83ae115bc7Smrj static void
AcpiUtFreeGpeLists(void)84*cb565728SJerry Jelinek AcpiUtFreeGpeLists (
85ae115bc7Smrj     void)
86ae115bc7Smrj {
87ae115bc7Smrj     ACPI_GPE_BLOCK_INFO     *GpeBlock;
88ae115bc7Smrj     ACPI_GPE_BLOCK_INFO     *NextGpeBlock;
89ae115bc7Smrj     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo;
90ae115bc7Smrj     ACPI_GPE_XRUPT_INFO     *NextGpeXruptInfo;
91ae115bc7Smrj 
92ae115bc7Smrj 
93ae115bc7Smrj     /* Free global GPE blocks and related info structures */
94ae115bc7Smrj 
95ae115bc7Smrj     GpeXruptInfo = AcpiGbl_GpeXruptListHead;
96ae115bc7Smrj     while (GpeXruptInfo)
97ae115bc7Smrj     {
98ae115bc7Smrj         GpeBlock = GpeXruptInfo->GpeBlockListHead;
99ae115bc7Smrj         while (GpeBlock)
100ae115bc7Smrj         {
101ae115bc7Smrj             NextGpeBlock = GpeBlock->Next;
102ae115bc7Smrj             ACPI_FREE (GpeBlock->EventInfo);
103ae115bc7Smrj             ACPI_FREE (GpeBlock->RegisterInfo);
104ae115bc7Smrj             ACPI_FREE (GpeBlock);
105ae115bc7Smrj 
106ae115bc7Smrj             GpeBlock = NextGpeBlock;
107ae115bc7Smrj         }
108ae115bc7Smrj         NextGpeXruptInfo = GpeXruptInfo->Next;
109ae115bc7Smrj         ACPI_FREE (GpeXruptInfo);
110ae115bc7Smrj         GpeXruptInfo = NextGpeXruptInfo;
111ae115bc7Smrj     }
112*cb565728SJerry Jelinek }
113*cb565728SJerry Jelinek #endif /* !ACPI_REDUCED_HARDWARE */
114ae115bc7Smrj 
115*cb565728SJerry Jelinek 
116*cb565728SJerry Jelinek /*******************************************************************************
117*cb565728SJerry Jelinek  *
118*cb565728SJerry Jelinek  * FUNCTION:    AcpiUtInitGlobals
119*cb565728SJerry Jelinek  *
120*cb565728SJerry Jelinek  * PARAMETERS:  None
121*cb565728SJerry Jelinek  *
122*cb565728SJerry Jelinek  * RETURN:      Status
123*cb565728SJerry Jelinek  *
124*cb565728SJerry Jelinek  * DESCRIPTION: Initialize ACPICA globals. All globals that require specific
125*cb565728SJerry Jelinek  *              initialization should be initialized here. This allows for
126*cb565728SJerry Jelinek  *              a warm restart.
127*cb565728SJerry Jelinek  *
128*cb565728SJerry Jelinek  ******************************************************************************/
129*cb565728SJerry Jelinek 
130*cb565728SJerry Jelinek ACPI_STATUS
AcpiUtInitGlobals(void)131*cb565728SJerry Jelinek AcpiUtInitGlobals (
132*cb565728SJerry Jelinek     void)
133*cb565728SJerry Jelinek {
134*cb565728SJerry Jelinek     ACPI_STATUS             Status;
135*cb565728SJerry Jelinek     UINT32                  i;
136*cb565728SJerry Jelinek 
137*cb565728SJerry Jelinek 
138*cb565728SJerry Jelinek     ACPI_FUNCTION_TRACE (UtInitGlobals);
139*cb565728SJerry Jelinek 
140*cb565728SJerry Jelinek 
141*cb565728SJerry Jelinek     /* Create all memory caches */
142*cb565728SJerry Jelinek 
143*cb565728SJerry Jelinek     Status = AcpiUtCreateCaches ();
144*cb565728SJerry Jelinek     if (ACPI_FAILURE (Status))
145*cb565728SJerry Jelinek     {
146*cb565728SJerry Jelinek         return_ACPI_STATUS (Status);
147*cb565728SJerry Jelinek     }
148*cb565728SJerry Jelinek 
149*cb565728SJerry Jelinek     /* Address Range lists */
150*cb565728SJerry Jelinek 
151*cb565728SJerry Jelinek     for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++)
152*cb565728SJerry Jelinek     {
153*cb565728SJerry Jelinek         AcpiGbl_AddressRangeList[i] = NULL;
154*cb565728SJerry Jelinek     }
155*cb565728SJerry Jelinek 
156*cb565728SJerry Jelinek     /* Mutex locked flags */
157*cb565728SJerry Jelinek 
158*cb565728SJerry Jelinek     for (i = 0; i < ACPI_NUM_MUTEX; i++)
159*cb565728SJerry Jelinek     {
160*cb565728SJerry Jelinek         AcpiGbl_MutexInfo[i].Mutex          = NULL;
161*cb565728SJerry Jelinek         AcpiGbl_MutexInfo[i].ThreadId       = ACPI_MUTEX_NOT_ACQUIRED;
162*cb565728SJerry Jelinek         AcpiGbl_MutexInfo[i].UseCount       = 0;
163*cb565728SJerry Jelinek     }
164*cb565728SJerry Jelinek 
165*cb565728SJerry Jelinek     for (i = 0; i < ACPI_NUM_OWNERID_MASKS; i++)
166*cb565728SJerry Jelinek     {
167*cb565728SJerry Jelinek         AcpiGbl_OwnerIdMask[i]              = 0;
168*cb565728SJerry Jelinek     }
169*cb565728SJerry Jelinek 
170*cb565728SJerry Jelinek     /* Last OwnerID is never valid */
171*cb565728SJerry Jelinek 
172*cb565728SJerry Jelinek     AcpiGbl_OwnerIdMask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000;
173*cb565728SJerry Jelinek 
174*cb565728SJerry Jelinek     /* Event counters */
175*cb565728SJerry Jelinek 
176*cb565728SJerry Jelinek     AcpiMethodCount                     = 0;
177*cb565728SJerry Jelinek     AcpiSciCount                        = 0;
178*cb565728SJerry Jelinek     AcpiGpeCount                        = 0;
179*cb565728SJerry Jelinek 
180*cb565728SJerry Jelinek     for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
181*cb565728SJerry Jelinek     {
182*cb565728SJerry Jelinek         AcpiFixedEventCount[i]              = 0;
183*cb565728SJerry Jelinek     }
184*cb565728SJerry Jelinek 
185*cb565728SJerry Jelinek #if (!ACPI_REDUCED_HARDWARE)
186*cb565728SJerry Jelinek 
187*cb565728SJerry Jelinek     /* GPE/SCI support */
188*cb565728SJerry Jelinek 
189*cb565728SJerry Jelinek     AcpiGbl_AllGpesInitialized          = FALSE;
190*cb565728SJerry Jelinek     AcpiGbl_GpeXruptListHead            = NULL;
191*cb565728SJerry Jelinek     AcpiGbl_GpeFadtBlocks[0]            = NULL;
192*cb565728SJerry Jelinek     AcpiGbl_GpeFadtBlocks[1]            = NULL;
193*cb565728SJerry Jelinek     AcpiCurrentGpeCount                 = 0;
194*cb565728SJerry Jelinek 
195*cb565728SJerry Jelinek     AcpiGbl_GlobalEventHandler          = NULL;
196*cb565728SJerry Jelinek     AcpiGbl_SciHandlerList              = NULL;
197*cb565728SJerry Jelinek 
198*cb565728SJerry Jelinek #endif /* !ACPI_REDUCED_HARDWARE */
199*cb565728SJerry Jelinek 
200*cb565728SJerry Jelinek     /* Global handlers */
201*cb565728SJerry Jelinek 
202*cb565728SJerry Jelinek     AcpiGbl_GlobalNotify[0].Handler     = NULL;
203*cb565728SJerry Jelinek     AcpiGbl_GlobalNotify[1].Handler     = NULL;
204*cb565728SJerry Jelinek     AcpiGbl_ExceptionHandler            = NULL;
205*cb565728SJerry Jelinek     AcpiGbl_InitHandler                 = NULL;
206*cb565728SJerry Jelinek     AcpiGbl_TableHandler                = NULL;
207*cb565728SJerry Jelinek     AcpiGbl_InterfaceHandler            = NULL;
208*cb565728SJerry Jelinek 
209*cb565728SJerry Jelinek     /* Global Lock support */
210*cb565728SJerry Jelinek 
211*cb565728SJerry Jelinek     AcpiGbl_GlobalLockSemaphore         = NULL;
212*cb565728SJerry Jelinek     AcpiGbl_GlobalLockMutex             = NULL;
213*cb565728SJerry Jelinek     AcpiGbl_GlobalLockAcquired          = FALSE;
214*cb565728SJerry Jelinek     AcpiGbl_GlobalLockHandle            = 0;
215*cb565728SJerry Jelinek     AcpiGbl_GlobalLockPresent           = FALSE;
216*cb565728SJerry Jelinek 
217*cb565728SJerry Jelinek     /* Miscellaneous variables */
218*cb565728SJerry Jelinek 
219*cb565728SJerry Jelinek     AcpiGbl_DSDT                        = NULL;
220*cb565728SJerry Jelinek     AcpiGbl_CmSingleStep                = FALSE;
221*cb565728SJerry Jelinek     AcpiGbl_Shutdown                    = FALSE;
222*cb565728SJerry Jelinek     AcpiGbl_NsLookupCount               = 0;
223*cb565728SJerry Jelinek     AcpiGbl_PsFindCount                 = 0;
224*cb565728SJerry Jelinek     AcpiGbl_AcpiHardwarePresent         = TRUE;
225*cb565728SJerry Jelinek     AcpiGbl_LastOwnerIdIndex            = 0;
226*cb565728SJerry Jelinek     AcpiGbl_NextOwnerIdOffset           = 0;
227*cb565728SJerry Jelinek     AcpiGbl_DebuggerConfiguration       = DEBUGGER_THREADING;
228*cb565728SJerry Jelinek     AcpiGbl_OsiMutex                    = NULL;
229*cb565728SJerry Jelinek     AcpiGbl_MaxLoopIterations           = 0xFFFF;
230*cb565728SJerry Jelinek 
231*cb565728SJerry Jelinek     /* Hardware oriented */
232*cb565728SJerry Jelinek 
233*cb565728SJerry Jelinek     AcpiGbl_EventsInitialized           = FALSE;
234*cb565728SJerry Jelinek     AcpiGbl_SystemAwakeAndRunning       = TRUE;
235*cb565728SJerry Jelinek 
236*cb565728SJerry Jelinek     /* Namespace */
237*cb565728SJerry Jelinek 
238*cb565728SJerry Jelinek     AcpiGbl_ModuleCodeList              = NULL;
239*cb565728SJerry Jelinek     AcpiGbl_RootNode                    = NULL;
240*cb565728SJerry Jelinek     AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
241*cb565728SJerry Jelinek     AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
242*cb565728SJerry Jelinek     AcpiGbl_RootNodeStruct.Type         = ACPI_TYPE_DEVICE;
243*cb565728SJerry Jelinek     AcpiGbl_RootNodeStruct.Parent       = NULL;
244*cb565728SJerry Jelinek     AcpiGbl_RootNodeStruct.Child        = NULL;
245*cb565728SJerry Jelinek     AcpiGbl_RootNodeStruct.Peer         = NULL;
246*cb565728SJerry Jelinek     AcpiGbl_RootNodeStruct.Object       = NULL;
247*cb565728SJerry Jelinek 
248*cb565728SJerry Jelinek 
249*cb565728SJerry Jelinek #ifdef ACPI_DISASSEMBLER
250*cb565728SJerry Jelinek     AcpiGbl_ExternalList                = NULL;
251*cb565728SJerry Jelinek     AcpiGbl_NumExternalMethods          = 0;
252*cb565728SJerry Jelinek     AcpiGbl_ResolvedExternalMethods     = 0;
253*cb565728SJerry Jelinek #endif
254*cb565728SJerry Jelinek 
255*cb565728SJerry Jelinek #ifdef ACPI_DEBUG_OUTPUT
256*cb565728SJerry Jelinek     AcpiGbl_LowestStackPointer          = ACPI_CAST_PTR (ACPI_SIZE, ACPI_SIZE_MAX);
257*cb565728SJerry Jelinek #endif
258*cb565728SJerry Jelinek 
259*cb565728SJerry Jelinek #ifdef ACPI_DBG_TRACK_ALLOCATIONS
260*cb565728SJerry Jelinek     AcpiGbl_DisplayFinalMemStats        = FALSE;
261*cb565728SJerry Jelinek     AcpiGbl_DisableMemTracking          = FALSE;
262*cb565728SJerry Jelinek #endif
263*cb565728SJerry Jelinek 
264*cb565728SJerry Jelinek     return_ACPI_STATUS (AE_OK);
265*cb565728SJerry Jelinek }
266*cb565728SJerry Jelinek 
267*cb565728SJerry Jelinek 
268*cb565728SJerry Jelinek /******************************************************************************
269*cb565728SJerry Jelinek  *
270*cb565728SJerry Jelinek  * FUNCTION:    AcpiUtTerminate
271*cb565728SJerry Jelinek  *
272*cb565728SJerry Jelinek  * PARAMETERS:  none
273*cb565728SJerry Jelinek  *
274*cb565728SJerry Jelinek  * RETURN:      none
275*cb565728SJerry Jelinek  *
276*cb565728SJerry Jelinek  * DESCRIPTION: Free global memory
277*cb565728SJerry Jelinek  *
278*cb565728SJerry Jelinek  ******************************************************************************/
279*cb565728SJerry Jelinek 
280*cb565728SJerry Jelinek static void
AcpiUtTerminate(void)281*cb565728SJerry Jelinek AcpiUtTerminate (
282*cb565728SJerry Jelinek     void)
283*cb565728SJerry Jelinek {
284*cb565728SJerry Jelinek     ACPI_FUNCTION_TRACE (UtTerminate);
285*cb565728SJerry Jelinek 
286*cb565728SJerry Jelinek     AcpiUtFreeGpeLists ();
287*cb565728SJerry Jelinek     AcpiUtDeleteAddressLists ();
288ae115bc7Smrj     return_VOID;
289ae115bc7Smrj }
290ae115bc7Smrj 
291ae115bc7Smrj 
292ae115bc7Smrj /*******************************************************************************
293ae115bc7Smrj  *
294ae115bc7Smrj  * FUNCTION:    AcpiUtSubsystemShutdown
295ae115bc7Smrj  *
29657190917SDana Myers  * PARAMETERS:  None
297ae115bc7Smrj  *
29857190917SDana Myers  * RETURN:      None
299ae115bc7Smrj  *
30057190917SDana Myers  * DESCRIPTION: Shutdown the various components. Do not delete the mutex
30157190917SDana Myers  *              objects here, because the AML debugger may be still running.
302ae115bc7Smrj  *
303ae115bc7Smrj  ******************************************************************************/
304ae115bc7Smrj 
305ae115bc7Smrj void
AcpiUtSubsystemShutdown(void)306ae115bc7Smrj AcpiUtSubsystemShutdown (
307ae115bc7Smrj     void)
308ae115bc7Smrj {
309ae115bc7Smrj     ACPI_FUNCTION_TRACE (UtSubsystemShutdown);
310ae115bc7Smrj 
311ae115bc7Smrj 
312*cb565728SJerry Jelinek     /* Just exit if subsystem is already shutdown */
313*cb565728SJerry Jelinek 
314*cb565728SJerry Jelinek     if (AcpiGbl_Shutdown)
315*cb565728SJerry Jelinek     {
316*cb565728SJerry Jelinek         ACPI_ERROR ((AE_INFO, "ACPI Subsystem is already terminated"));
317*cb565728SJerry Jelinek         return_VOID;
318*cb565728SJerry Jelinek     }
319*cb565728SJerry Jelinek 
320*cb565728SJerry Jelinek     /* Subsystem appears active, go ahead and shut it down */
321*cb565728SJerry Jelinek 
322*cb565728SJerry Jelinek     AcpiGbl_Shutdown = TRUE;
323*cb565728SJerry Jelinek     AcpiGbl_StartupFlags = 0;
324*cb565728SJerry Jelinek     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
325*cb565728SJerry Jelinek 
326db2bae30SDana Myers #ifndef ACPI_ASL_COMPILER
327db2bae30SDana Myers 
328ae115bc7Smrj     /* Close the AcpiEvent Handling */
329ae115bc7Smrj 
330ae115bc7Smrj     AcpiEvTerminate ();
33126f3cdf0SGordon Ross 
33226f3cdf0SGordon Ross     /* Delete any dynamic _OSI interfaces */
33326f3cdf0SGordon Ross 
33426f3cdf0SGordon Ross     AcpiUtInterfaceTerminate ();
335db2bae30SDana Myers #endif
336ae115bc7Smrj 
337ae115bc7Smrj     /* Close the Namespace */
338ae115bc7Smrj 
339ae115bc7Smrj     AcpiNsTerminate ();
340ae115bc7Smrj 
341db2bae30SDana Myers     /* Delete the ACPI tables */
342db2bae30SDana Myers 
343db2bae30SDana Myers     AcpiTbTerminate ();
344db2bae30SDana Myers 
345ae115bc7Smrj     /* Close the globals */
346ae115bc7Smrj 
347ae115bc7Smrj     AcpiUtTerminate ();
348ae115bc7Smrj 
349ae115bc7Smrj     /* Purge the local caches */
350ae115bc7Smrj 
351ae115bc7Smrj     (void) AcpiUtDeleteCaches ();
352ae115bc7Smrj     return_VOID;
353ae115bc7Smrj }
354