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