blob: 083a76891889244596453059885ef3007aab8320 [file] [log] [blame]
Bob Moored9783482012-08-17 10:51:47 +08001/******************************************************************************
2 *
3 * Module Name: utxfinit - External interfaces for ACPICA initialization
4 *
5 *****************************************************************************/
6
7/*
David E. Box82a80942015-02-05 15:20:45 +08008 * Copyright (C) 2000 - 2015, Intel Corp.
Bob Moored9783482012-08-17 10:51:47 +08009 * 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
Lv Zheng839e9282013-10-29 09:29:51 +080044#define EXPORT_ACPI_INTERFACES
45
Bob Moored9783482012-08-17 10:51:47 +080046#include <acpi/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
54ACPI_MODULE_NAME("utxfinit")
55
Bob Mooreb4878672014-11-27 14:26:07 +080056/* For acpi_exec only */
57void ae_do_object_overrides(void);
58
Bob Moored9783482012-08-17 10:51:47 +080059/*******************************************************************************
60 *
61 * FUNCTION: acpi_initialize_subsystem
62 *
63 * PARAMETERS: None
64 *
65 * RETURN: Status
66 *
67 * DESCRIPTION: Initializes all global variables. This is the first function
68 * called, so any early initialization belongs here.
69 *
70 ******************************************************************************/
Bob Mooreb4878672014-11-27 14:26:07 +080071
Lv Zheng45c9f782013-10-31 09:31:24 +080072acpi_status __init acpi_initialize_subsystem(void)
Bob Moored9783482012-08-17 10:51:47 +080073{
74 acpi_status status;
75
76 ACPI_FUNCTION_TRACE(acpi_initialize_subsystem);
77
78 acpi_gbl_startup_flags = ACPI_SUBSYSTEM_INITIALIZE;
79 ACPI_DEBUG_EXEC(acpi_ut_init_stack_ptr_trace());
80
81 /* Initialize the OS-Dependent layer */
82
83 status = acpi_os_initialize();
84 if (ACPI_FAILURE(status)) {
85 ACPI_EXCEPTION((AE_INFO, status, "During OSL initialization"));
86 return_ACPI_STATUS(status);
87 }
88
89 /* Initialize all globals used by the subsystem */
90
91 status = acpi_ut_init_globals();
92 if (ACPI_FAILURE(status)) {
93 ACPI_EXCEPTION((AE_INFO, status,
94 "During initialization of globals"));
95 return_ACPI_STATUS(status);
96 }
97
98 /* Create the default mutex objects */
99
100 status = acpi_ut_mutex_initialize();
101 if (ACPI_FAILURE(status)) {
102 ACPI_EXCEPTION((AE_INFO, status,
103 "During Global Mutex creation"));
104 return_ACPI_STATUS(status);
105 }
106
107 /*
108 * Initialize the namespace manager and
109 * the root of the namespace tree
110 */
111 status = acpi_ns_root_initialize();
112 if (ACPI_FAILURE(status)) {
113 ACPI_EXCEPTION((AE_INFO, status,
114 "During Namespace initialization"));
115 return_ACPI_STATUS(status);
116 }
117
118 /* Initialize the global OSI interfaces list with the static names */
119
120 status = acpi_ut_initialize_interfaces();
121 if (ACPI_FAILURE(status)) {
122 ACPI_EXCEPTION((AE_INFO, status,
123 "During OSI interfaces initialization"));
124 return_ACPI_STATUS(status);
125 }
126
127 /* If configured, initialize the AML debugger */
128
Bob Moore1a2c4782014-01-08 13:44:38 +0800129#ifdef ACPI_DEBUGGER
130 status = acpi_db_initialize();
131 if (ACPI_FAILURE(status)) {
132 ACPI_EXCEPTION((AE_INFO, status,
133 "During Debugger initialization"));
134 return_ACPI_STATUS(status);
135 }
136#endif
137
138 return_ACPI_STATUS(AE_OK);
Bob Moored9783482012-08-17 10:51:47 +0800139}
Lv Zhengd21f6002013-10-29 09:30:10 +0800140
141ACPI_EXPORT_SYMBOL_INIT(acpi_initialize_subsystem)
Bob Moored9783482012-08-17 10:51:47 +0800142
143/*******************************************************************************
144 *
145 * FUNCTION: acpi_enable_subsystem
146 *
147 * PARAMETERS: flags - Init/enable Options
148 *
149 * RETURN: Status
150 *
151 * DESCRIPTION: Completes the subsystem initialization including hardware.
152 * Puts system into ACPI mode if it isn't already.
153 *
154 ******************************************************************************/
Lv Zheng45c9f782013-10-31 09:31:24 +0800155acpi_status __init acpi_enable_subsystem(u32 flags)
Bob Moored9783482012-08-17 10:51:47 +0800156{
157 acpi_status status = AE_OK;
158
159 ACPI_FUNCTION_TRACE(acpi_enable_subsystem);
160
161#if (!ACPI_REDUCED_HARDWARE)
162
163 /* Enable ACPI mode */
164
165 if (!(flags & ACPI_NO_ACPI_ENABLE)) {
166 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
167 "[Init] Going into ACPI mode\n"));
168
169 acpi_gbl_original_mode = acpi_hw_get_mode();
170
171 status = acpi_enable();
172 if (ACPI_FAILURE(status)) {
173 ACPI_WARNING((AE_INFO, "AcpiEnable failed"));
174 return_ACPI_STATUS(status);
175 }
176 }
177
178 /*
179 * Obtain a permanent mapping for the FACS. This is required for the
180 * Global Lock and the Firmware Waking Vector
181 */
182 status = acpi_tb_initialize_facs();
183 if (ACPI_FAILURE(status)) {
184 ACPI_WARNING((AE_INFO, "Could not map the FACS table"));
185 return_ACPI_STATUS(status);
186 }
187#endif /* !ACPI_REDUCED_HARDWARE */
188
189 /*
190 * Install the default op_region handlers. These are installed unless
191 * other handlers have already been installed via the
192 * install_address_space_handler interface.
193 */
194 if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
195 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
196 "[Init] Installing default address space handlers\n"));
197
198 status = acpi_ev_install_region_handlers();
199 if (ACPI_FAILURE(status)) {
200 return_ACPI_STATUS(status);
201 }
202 }
203#if (!ACPI_REDUCED_HARDWARE)
204 /*
205 * Initialize ACPI Event handling (Fixed and General Purpose)
206 *
207 * Note1: We must have the hardware and events initialized before we can
208 * execute any control methods safely. Any control method can require
209 * ACPI hardware support, so the hardware must be fully initialized before
210 * any method execution!
211 *
212 * Note2: Fixed events are initialized and enabled here. GPEs are
213 * initialized, but cannot be enabled until after the hardware is
214 * completely initialized (SCI and global_lock activated) and the various
215 * initialization control methods are run (_REG, _STA, _INI) on the
216 * entire namespace.
217 */
218 if (!(flags & ACPI_NO_EVENT_INIT)) {
219 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
220 "[Init] Initializing ACPI events\n"));
221
222 status = acpi_ev_initialize_events();
223 if (ACPI_FAILURE(status)) {
224 return_ACPI_STATUS(status);
225 }
226 }
227
228 /*
229 * Install the SCI handler and Global Lock handler. This completes the
230 * hardware initialization.
231 */
232 if (!(flags & ACPI_NO_HANDLER_INIT)) {
233 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
234 "[Init] Installing SCI/GL handlers\n"));
235
236 status = acpi_ev_install_xrupt_handlers();
237 if (ACPI_FAILURE(status)) {
238 return_ACPI_STATUS(status);
239 }
240 }
241#endif /* !ACPI_REDUCED_HARDWARE */
242
243 return_ACPI_STATUS(status);
244}
Lv Zhengd21f6002013-10-29 09:30:10 +0800245
246ACPI_EXPORT_SYMBOL_INIT(acpi_enable_subsystem)
Bob Moored9783482012-08-17 10:51:47 +0800247
248/*******************************************************************************
249 *
250 * FUNCTION: acpi_initialize_objects
251 *
252 * PARAMETERS: flags - Init/enable Options
253 *
254 * RETURN: Status
255 *
256 * DESCRIPTION: Completes namespace initialization by initializing device
257 * objects and executing AML code for Regions, buffers, etc.
258 *
259 ******************************************************************************/
Lv Zheng45c9f782013-10-31 09:31:24 +0800260acpi_status __init acpi_initialize_objects(u32 flags)
Bob Moored9783482012-08-17 10:51:47 +0800261{
262 acpi_status status = AE_OK;
263
264 ACPI_FUNCTION_TRACE(acpi_initialize_objects);
265
266 /*
267 * Run all _REG methods
268 *
269 * Note: Any objects accessed by the _REG methods will be automatically
270 * initialized, even if they contain executable AML (see the call to
271 * acpi_ns_initialize_objects below).
272 */
273 if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
274 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
275 "[Init] Executing _REG OpRegion methods\n"));
276
277 status = acpi_ev_initialize_op_regions();
278 if (ACPI_FAILURE(status)) {
279 return_ACPI_STATUS(status);
280 }
281 }
Bob Mooreb4878672014-11-27 14:26:07 +0800282#ifdef ACPI_EXEC_APP
283 /*
284 * This call implements the "initialization file" option for acpi_exec.
285 * This is the precise point that we want to perform the overrides.
286 */
287 ae_do_object_overrides();
288#endif
Bob Moored9783482012-08-17 10:51:47 +0800289
290 /*
291 * Execute any module-level code that was detected during the table load
292 * phase. Although illegal since ACPI 2.0, there are many machines that
293 * contain this type of code. Each block of detected executable AML code
294 * outside of any control method is wrapped with a temporary control
295 * method object and placed on a global list. The methods on this list
296 * are executed below.
297 */
298 acpi_ns_exec_module_code_list();
299
300 /*
301 * Initialize the objects that remain uninitialized. This runs the
302 * executable AML that may be part of the declaration of these objects:
303 * operation_regions, buffer_fields, Buffers, and Packages.
304 */
305 if (!(flags & ACPI_NO_OBJECT_INIT)) {
306 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
307 "[Init] Completing Initialization of ACPI Objects\n"));
308
309 status = acpi_ns_initialize_objects();
310 if (ACPI_FAILURE(status)) {
311 return_ACPI_STATUS(status);
312 }
313 }
314
315 /*
316 * Initialize all device objects in the namespace. This runs the device
317 * _STA and _INI methods.
318 */
319 if (!(flags & ACPI_NO_DEVICE_INIT)) {
320 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
321 "[Init] Initializing ACPI Devices\n"));
322
323 status = acpi_ns_initialize_devices();
324 if (ACPI_FAILURE(status)) {
325 return_ACPI_STATUS(status);
326 }
327 }
328
329 /*
330 * Empty the caches (delete the cached objects) on the assumption that
331 * the table load filled them up more than they will be at runtime --
332 * thus wasting non-paged memory.
333 */
334 status = acpi_purge_cached_objects();
335
336 acpi_gbl_startup_flags |= ACPI_INITIALIZED_OK;
337 return_ACPI_STATUS(status);
338}
Lv Zhengd21f6002013-10-29 09:30:10 +0800339
340ACPI_EXPORT_SYMBOL_INIT(acpi_initialize_objects)