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