1 /******************************************************************************
2  *
3  * Module Name: utxfinit - External interfaces for ACPICA initialization
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2016, 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 EXPORT_ACPI_INTERFACES
45 
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "acevents.h"
49 #include "acnamesp.h"
50 #include "acdebug.h"
51 #include "actables.h"
52 
53 #define _COMPONENT          ACPI_UTILITIES
54         ACPI_MODULE_NAME    ("utxfinit")
55 
56 /* For AcpiExec only */
57 void
58 AeDoObjectOverrides (
59     void);
60 
61 
62 /*******************************************************************************
63  *
64  * FUNCTION:    AcpiInitializeSubsystem
65  *
66  * PARAMETERS:  None
67  *
68  * RETURN:      Status
69  *
70  * DESCRIPTION: Initializes all global variables. This is the first function
71  *              called, so any early initialization belongs here.
72  *
73  ******************************************************************************/
74 
75 ACPI_STATUS
76 AcpiInitializeSubsystem (
77     void)
78 {
79     ACPI_STATUS             Status;
80 
81 
82     ACPI_FUNCTION_TRACE (AcpiInitializeSubsystem);
83 
84 
85     AcpiGbl_StartupFlags = ACPI_SUBSYSTEM_INITIALIZE;
86     ACPI_DEBUG_EXEC (AcpiUtInitStackPtrTrace ());
87 
88     /* Initialize the OS-Dependent layer */
89 
90     Status = AcpiOsInitialize ();
91     if (ACPI_FAILURE (Status))
92     {
93         ACPI_EXCEPTION ((AE_INFO, Status, "During OSL initialization"));
94         return_ACPI_STATUS (Status);
95     }
96 
97     /* Initialize all globals used by the subsystem */
98 
99     Status = AcpiUtInitGlobals ();
100     if (ACPI_FAILURE (Status))
101     {
102         ACPI_EXCEPTION ((AE_INFO, Status, "During initialization of globals"));
103         return_ACPI_STATUS (Status);
104     }
105 
106     /* Create the default mutex objects */
107 
108     Status = AcpiUtMutexInitialize ();
109     if (ACPI_FAILURE (Status))
110     {
111         ACPI_EXCEPTION ((AE_INFO, Status, "During Global Mutex creation"));
112         return_ACPI_STATUS (Status);
113     }
114 
115     /*
116      * Initialize the namespace manager and
117      * the root of the namespace tree
118      */
119     Status = AcpiNsRootInitialize ();
120     if (ACPI_FAILURE (Status))
121     {
122         ACPI_EXCEPTION ((AE_INFO, Status, "During Namespace initialization"));
123         return_ACPI_STATUS (Status);
124     }
125 
126     /* Initialize the global OSI interfaces list with the static names */
127 
128     Status = AcpiUtInitializeInterfaces ();
129     if (ACPI_FAILURE (Status))
130     {
131         ACPI_EXCEPTION ((AE_INFO, Status, "During OSI interfaces initialization"));
132         return_ACPI_STATUS (Status);
133     }
134 
135     return_ACPI_STATUS (AE_OK);
136 }
137 
138 ACPI_EXPORT_SYMBOL_INIT (AcpiInitializeSubsystem)
139 
140 
141 /*******************************************************************************
142  *
143  * FUNCTION:    AcpiEnableSubsystem
144  *
145  * PARAMETERS:  Flags               - Init/enable Options
146  *
147  * RETURN:      Status
148  *
149  * DESCRIPTION: Completes the subsystem initialization including hardware.
150  *              Puts system into ACPI mode if it isn't already.
151  *
152  ******************************************************************************/
153 
154 ACPI_STATUS
155 AcpiEnableSubsystem (
156     UINT32                  Flags)
157 {
158     ACPI_STATUS             Status = AE_OK;
159 
160 
161     ACPI_FUNCTION_TRACE (AcpiEnableSubsystem);
162 
163 
164     /*
165      * The early initialization phase is complete. The namespace is loaded,
166      * and we can now support address spaces other than Memory, I/O, and
167      * PCI_Config.
168      */
169     AcpiGbl_EarlyInitialization = FALSE;
170 
171     /*
172      * Install the default operation region handlers. These are the
173      * handlers that are defined by the ACPI specification to be
174      * "always accessible" -- namely, SystemMemory, SystemIO, and
175      * PCI_Config. This also means that no _REG methods need to be
176      * run for these address spaces. We need to have these handlers
177      * installed before any AML code can be executed, especially any
178      * module-level code (11/2015).
179      */
180     if (!AcpiGbl_GroupModuleLevelCode)
181     {
182         Status = AcpiEvInstallRegionHandlers ();
183         if (ACPI_FAILURE (Status))
184         {
185             ACPI_EXCEPTION ((AE_INFO, Status, "During Region initialization"));
186             return_ACPI_STATUS (Status);
187         }
188     }
189 
190 #if (!ACPI_REDUCED_HARDWARE)
191 
192     /* Enable ACPI mode */
193 
194     if (!(Flags & ACPI_NO_ACPI_ENABLE))
195     {
196         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Going into ACPI mode\n"));
197 
198         AcpiGbl_OriginalMode = AcpiHwGetMode();
199 
200         Status = AcpiEnable ();
201         if (ACPI_FAILURE (Status))
202         {
203             ACPI_WARNING ((AE_INFO, "AcpiEnable failed"));
204             return_ACPI_STATUS (Status);
205         }
206     }
207 
208     /*
209      * Obtain a permanent mapping for the FACS. This is required for the
210      * Global Lock and the Firmware Waking Vector
211      */
212     if (!(Flags & ACPI_NO_FACS_INIT))
213     {
214         Status = AcpiTbInitializeFacs ();
215         if (ACPI_FAILURE (Status))
216         {
217             ACPI_WARNING ((AE_INFO, "Could not map the FACS table"));
218             return_ACPI_STATUS (Status);
219         }
220     }
221 
222     /*
223      * Initialize ACPI Event handling (Fixed and General Purpose)
224      *
225      * Note1: We must have the hardware and events initialized before we can
226      * execute any control methods safely. Any control method can require
227      * ACPI hardware support, so the hardware must be fully initialized before
228      * any method execution!
229      *
230      * Note2: Fixed events are initialized and enabled here. GPEs are
231      * initialized, but cannot be enabled until after the hardware is
232      * completely initialized (SCI and GlobalLock activated) and the various
233      * initialization control methods are run (_REG, _STA, _INI) on the
234      * entire namespace.
235      */
236     if (!(Flags & ACPI_NO_EVENT_INIT))
237     {
238         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
239             "[Init] Initializing ACPI events\n"));
240 
241         Status = AcpiEvInitializeEvents ();
242         if (ACPI_FAILURE (Status))
243         {
244             return_ACPI_STATUS (Status);
245         }
246     }
247 
248     /*
249      * Install the SCI handler and Global Lock handler. This completes the
250      * hardware initialization.
251      */
252     if (!(Flags & ACPI_NO_HANDLER_INIT))
253     {
254         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
255             "[Init] Installing SCI/GL handlers\n"));
256 
257         Status = AcpiEvInstallXruptHandlers ();
258         if (ACPI_FAILURE (Status))
259         {
260             return_ACPI_STATUS (Status);
261         }
262     }
263 
264 #endif /* !ACPI_REDUCED_HARDWARE */
265 
266     return_ACPI_STATUS (Status);
267 }
268 
269 ACPI_EXPORT_SYMBOL_INIT (AcpiEnableSubsystem)
270 
271 
272 /*******************************************************************************
273  *
274  * FUNCTION:    AcpiInitializeObjects
275  *
276  * PARAMETERS:  Flags               - Init/enable Options
277  *
278  * RETURN:      Status
279  *
280  * DESCRIPTION: Completes namespace initialization by initializing device
281  *              objects and executing AML code for Regions, buffers, etc.
282  *
283  ******************************************************************************/
284 
285 ACPI_STATUS
286 AcpiInitializeObjects (
287     UINT32                  Flags)
288 {
289     ACPI_STATUS             Status = AE_OK;
290 
291 
292     ACPI_FUNCTION_TRACE (AcpiInitializeObjects);
293 
294 
295 #ifdef ACPI_EXEC_APP
296     /*
297      * This call implements the "initialization file" option for AcpiExec.
298      * This is the precise point that we want to perform the overrides.
299      */
300     AeDoObjectOverrides ();
301 #endif
302 
303     /*
304      * Execute any module-level code that was detected during the table load
305      * phase. Although illegal since ACPI 2.0, there are many machines that
306      * contain this type of code. Each block of detected executable AML code
307      * outside of any control method is wrapped with a temporary control
308      * method object and placed on a global list. The methods on this list
309      * are executed below.
310      *
311      * This case executes the module-level code for all tables only after
312      * all of the tables have been loaded. It is a legacy option and is
313      * not compatible with other ACPI implementations. See AcpiNsLoadTable.
314      */
315     if (AcpiGbl_GroupModuleLevelCode)
316     {
317         AcpiNsExecModuleCodeList ();
318     }
319 
320     /*
321      * Initialize the objects that remain uninitialized. This runs the
322      * executable AML that may be part of the declaration of these objects:
323      * OperationRegions, BufferFields, Buffers, and Packages.
324      */
325     if (!(Flags & ACPI_NO_OBJECT_INIT))
326     {
327         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
328             "[Init] Completing Initialization of ACPI Objects\n"));
329 
330         Status = AcpiNsInitializeObjects ();
331         if (ACPI_FAILURE (Status))
332         {
333             return_ACPI_STATUS (Status);
334         }
335     }
336 
337     AcpiGbl_NamespaceInitialized = TRUE;
338 
339     /*
340      * Initialize all device/region objects in the namespace. This runs
341      * the device _STA and _INI methods and region _REG methods.
342      */
343     if (!(Flags & (ACPI_NO_DEVICE_INIT | ACPI_NO_ADDRESS_SPACE_INIT)))
344     {
345         Status = AcpiNsInitializeDevices (Flags);
346         if (ACPI_FAILURE (Status))
347         {
348             return_ACPI_STATUS (Status);
349         }
350     }
351 
352     /*
353      * Empty the caches (delete the cached objects) on the assumption that
354      * the table load filled them up more than they will be at runtime --
355      * thus wasting non-paged memory.
356      */
357     Status = AcpiPurgeCachedObjects ();
358 
359     AcpiGbl_StartupFlags |= ACPI_INITIALIZED_OK;
360     return_ACPI_STATUS (Status);
361 }
362 
363 ACPI_EXPORT_SYMBOL_INIT (AcpiInitializeObjects)
364