]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/acpi/acpica/utxfinit.c
ACPICA: Events: Enhance acpi_ev_execute_reg_method() to ensure no _REG evaluations...
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / acpica / utxfinit.c
CommitLineData
d978348b
BM
1/******************************************************************************
2 *
3 * Module Name: utxfinit - External interfaces for ACPICA initialization
4 *
5 *****************************************************************************/
6
7/*
82a80941 8 * Copyright (C) 2000 - 2015, Intel Corp.
d978348b
BM
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
839e928f
LZ
44#define EXPORT_ACPI_INTERFACES
45
d978348b
BM
46#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
b487867c
BM
56/* For acpi_exec only */
57void ae_do_object_overrides(void);
58
d978348b
BM
59/*******************************************************************************
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 ******************************************************************************/
b487867c 71
45c9f78b 72acpi_status __init acpi_initialize_subsystem(void)
d978348b
BM
73{
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
1a2c4783 127 return_ACPI_STATUS(AE_OK);
d978348b 128}
d21f600b
LZ
129
130ACPI_EXPORT_SYMBOL_INIT(acpi_initialize_subsystem)
d978348b
BM
131
132/*******************************************************************************
133 *
134 * FUNCTION: acpi_enable_subsystem
135 *
136 * PARAMETERS: flags - Init/enable Options
137 *
138 * RETURN: Status
139 *
140 * DESCRIPTION: Completes the subsystem initialization including hardware.
141 * Puts system into ACPI mode if it isn't already.
142 *
143 ******************************************************************************/
45c9f78b 144acpi_status __init acpi_enable_subsystem(u32 flags)
d978348b
BM
145{
146 acpi_status status = AE_OK;
147
148 ACPI_FUNCTION_TRACE(acpi_enable_subsystem);
149
7b738064
BM
150 /*
151 * The early initialization phase is complete. The namespace is loaded,
152 * and we can now support address spaces other than Memory, I/O, and
153 * PCI_Config.
154 */
155 acpi_gbl_early_initialization = FALSE;
156
2e1beaf6
LZ
157 /*
158 * Install the default operation region handlers. These are the
159 * handlers that are defined by the ACPI specification to be
160 * "always accessible" -- namely, system_memory, system_IO, and
161 * PCI_Config. This also means that no _REG methods need to be
162 * run for these address spaces. We need to have these handlers
163 * installed before any AML code can be executed, especially any
164 * module-level code (11/2015).
165 */
166 status = acpi_ev_install_region_handlers();
167 if (ACPI_FAILURE(status)) {
168 ACPI_EXCEPTION((AE_INFO, status,
169 "During Region initialization"));
170 return_ACPI_STATUS(status);
171 }
d978348b
BM
172#if (!ACPI_REDUCED_HARDWARE)
173
174 /* Enable ACPI mode */
175
176 if (!(flags & ACPI_NO_ACPI_ENABLE)) {
177 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
178 "[Init] Going into ACPI mode\n"));
179
180 acpi_gbl_original_mode = acpi_hw_get_mode();
181
182 status = acpi_enable();
183 if (ACPI_FAILURE(status)) {
184 ACPI_WARNING((AE_INFO, "AcpiEnable failed"));
185 return_ACPI_STATUS(status);
186 }
187 }
188
189 /*
190 * Obtain a permanent mapping for the FACS. This is required for the
191 * Global Lock and the Firmware Waking Vector
192 */
c04be184
LZ
193 if (!(flags & ACPI_NO_FACS_INIT)) {
194 status = acpi_tb_initialize_facs();
195 if (ACPI_FAILURE(status)) {
196 ACPI_WARNING((AE_INFO, "Could not map the FACS table"));
197 return_ACPI_STATUS(status);
198 }
d978348b 199 }
d978348b 200
d978348b
BM
201 /*
202 * Initialize ACPI Event handling (Fixed and General Purpose)
203 *
204 * Note1: We must have the hardware and events initialized before we can
205 * execute any control methods safely. Any control method can require
206 * ACPI hardware support, so the hardware must be fully initialized before
207 * any method execution!
208 *
209 * Note2: Fixed events are initialized and enabled here. GPEs are
210 * initialized, but cannot be enabled until after the hardware is
211 * completely initialized (SCI and global_lock activated) and the various
212 * initialization control methods are run (_REG, _STA, _INI) on the
213 * entire namespace.
214 */
215 if (!(flags & ACPI_NO_EVENT_INIT)) {
216 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
217 "[Init] Initializing ACPI events\n"));
218
219 status = acpi_ev_initialize_events();
220 if (ACPI_FAILURE(status)) {
221 return_ACPI_STATUS(status);
222 }
223 }
224
225 /*
226 * Install the SCI handler and Global Lock handler. This completes the
227 * hardware initialization.
228 */
229 if (!(flags & ACPI_NO_HANDLER_INIT)) {
230 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
231 "[Init] Installing SCI/GL handlers\n"));
232
233 status = acpi_ev_install_xrupt_handlers();
234 if (ACPI_FAILURE(status)) {
235 return_ACPI_STATUS(status);
236 }
237 }
238#endif /* !ACPI_REDUCED_HARDWARE */
239
240 return_ACPI_STATUS(status);
241}
d21f600b
LZ
242
243ACPI_EXPORT_SYMBOL_INIT(acpi_enable_subsystem)
d978348b
BM
244
245/*******************************************************************************
246 *
247 * FUNCTION: acpi_initialize_objects
248 *
249 * PARAMETERS: flags - Init/enable Options
250 *
251 * RETURN: Status
252 *
253 * DESCRIPTION: Completes namespace initialization by initializing device
254 * objects and executing AML code for Regions, buffers, etc.
255 *
256 ******************************************************************************/
45c9f78b 257acpi_status __init acpi_initialize_objects(u32 flags)
d978348b
BM
258{
259 acpi_status status = AE_OK;
260
261 ACPI_FUNCTION_TRACE(acpi_initialize_objects);
262
263 /*
264 * Run all _REG methods
265 *
266 * Note: Any objects accessed by the _REG methods will be automatically
267 * initialized, even if they contain executable AML (see the call to
268 * acpi_ns_initialize_objects below).
269 */
efaed9be 270 acpi_gbl_reg_methods_enabled = TRUE;
d978348b
BM
271 if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
272 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
273 "[Init] Executing _REG OpRegion methods\n"));
274
275 status = acpi_ev_initialize_op_regions();
276 if (ACPI_FAILURE(status)) {
277 return_ACPI_STATUS(status);
278 }
279 }
b487867c
BM
280#ifdef ACPI_EXEC_APP
281 /*
282 * This call implements the "initialization file" option for acpi_exec.
283 * This is the precise point that we want to perform the overrides.
284 */
285 ae_do_object_overrides();
286#endif
d978348b
BM
287
288 /*
289 * Execute any module-level code that was detected during the table load
290 * phase. Although illegal since ACPI 2.0, there are many machines that
291 * contain this type of code. Each block of detected executable AML code
292 * outside of any control method is wrapped with a temporary control
293 * method object and placed on a global list. The methods on this list
294 * are executed below.
295 */
296 acpi_ns_exec_module_code_list();
297
298 /*
299 * Initialize the objects that remain uninitialized. This runs the
300 * executable AML that may be part of the declaration of these objects:
301 * operation_regions, buffer_fields, Buffers, and Packages.
302 */
303 if (!(flags & ACPI_NO_OBJECT_INIT)) {
304 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
305 "[Init] Completing Initialization of ACPI Objects\n"));
306
307 status = acpi_ns_initialize_objects();
308 if (ACPI_FAILURE(status)) {
309 return_ACPI_STATUS(status);
310 }
311 }
312
313 /*
314 * Initialize all device objects in the namespace. This runs the device
315 * _STA and _INI methods.
316 */
317 if (!(flags & ACPI_NO_DEVICE_INIT)) {
318 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
319 "[Init] Initializing ACPI Devices\n"));
320
321 status = acpi_ns_initialize_devices();
322 if (ACPI_FAILURE(status)) {
323 return_ACPI_STATUS(status);
324 }
325 }
326
327 /*
328 * Empty the caches (delete the cached objects) on the assumption that
329 * the table load filled them up more than they will be at runtime --
330 * thus wasting non-paged memory.
331 */
332 status = acpi_purge_cached_objects();
333
334 acpi_gbl_startup_flags |= ACPI_INITIALIZED_OK;
335 return_ACPI_STATUS(status);
336}
d21f600b
LZ
337
338ACPI_EXPORT_SYMBOL_INIT(acpi_initialize_objects)