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