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