Merge remote-tracking branch 'asoc/topic/simple' into asoc-next
[deliverable/linux.git] / drivers / acpi / acpica / nsload.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: nsload - namespace loading/expanding/contracting procedures
4 *
5 *****************************************************************************/
6
7/*
c8100dc4 8 * Copyright (C) 2000 - 2016, Intel Corp.
1da177e4
LT
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
1da177e4 44#include <acpi/acpi.h>
e2f7a777
LB
45#include "accommon.h"
46#include "acnamesp.h"
47#include "acdispat.h"
48#include "actables.h"
1da177e4 49
1da177e4 50#define _COMPONENT ACPI_NAMESPACE
4be44fcd 51ACPI_MODULE_NAME("nsload")
1da177e4 52
44f6c012 53/* Local prototypes */
44f6c012 54#ifdef ACPI_FUTURE_IMPLEMENTATION
4be44fcd 55acpi_status acpi_ns_unload_namespace(acpi_handle handle);
44f6c012 56
4be44fcd 57static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
44f6c012 58#endif
1da177e4 59
44f6c012 60#ifndef ACPI_NO_METHOD_EXECUTION
1da177e4
LT
61/*******************************************************************************
62 *
63 * FUNCTION: acpi_ns_load_table
64 *
f3d2e786 65 * PARAMETERS: table_index - Index for table to be loaded
ba494bee 66 * node - Owning NS node
1da177e4
LT
67 *
68 * RETURN: Status
69 *
70 * DESCRIPTION: Load one ACPI table into the namespace
71 *
72 ******************************************************************************/
73
74acpi_status
67a119f9 75acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node)
1da177e4 76{
4be44fcd 77 acpi_status status;
1da177e4 78
b229cf92 79 ACPI_FUNCTION_TRACE(ns_load_table);
1da177e4 80
1da177e4
LT
81 /*
82 * Parse the table and load the namespace with all named
73a3090a
BM
83 * objects found within. Control methods are NOT parsed
84 * at this time. In fact, the control methods cannot be
1da177e4
LT
85 * parsed until the entire namespace is loaded, because
86 * if a control method makes a forward reference (call)
87 * to another control method, we can't continue parsing
88 * because we don't know how many arguments to parse next!
89 */
f3d2e786
BM
90 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
91 if (ACPI_FAILURE(status)) {
92 return_ACPI_STATUS(status);
93 }
94
95 /* If table already loaded into namespace, just return */
96
97 if (acpi_tb_is_table_loaded(table_index)) {
98 status = AE_ALREADY_EXISTS;
99 goto unlock;
100 }
101
4be44fcd
LB
102 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
103 "**** Loading table into namespace ****\n"));
1da177e4 104
f3d2e786 105 status = acpi_tb_allocate_owner_id(table_index);
4be44fcd 106 if (ACPI_FAILURE(status)) {
f3d2e786 107 goto unlock;
1da177e4
LT
108 }
109
7f4ac9f9 110 status = acpi_ns_parse_table(table_index, node);
f3d2e786
BM
111 if (ACPI_SUCCESS(status)) {
112 acpi_tb_set_table_loaded_flag(table_index, TRUE);
113 } else {
4712f71b
BM
114 /*
115 * On error, delete any namespace objects created by this table.
116 * We cannot initialize these objects, so delete them. There are
117 * a couple of expecially bad cases:
118 * AE_ALREADY_EXISTS - namespace collision.
119 * AE_NOT_FOUND - the target of a Scope operator does not
120 * exist. This target of Scope must already exist in the
121 * namespace, as per the ACPI specification.
122 */
123 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
124 acpi_ns_delete_namespace_by_owner(acpi_gbl_root_table_list.
125 tables[table_index].owner_id);
126 acpi_tb_release_owner_id(table_index);
127
128 return_ACPI_STATUS(status);
f3d2e786
BM
129 }
130
10622bf8 131unlock:
4be44fcd 132 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4 133
4be44fcd
LB
134 if (ACPI_FAILURE(status)) {
135 return_ACPI_STATUS(status);
1da177e4
LT
136 }
137
138 /*
73a3090a 139 * Now we can parse the control methods. We always parse
1da177e4
LT
140 * them here for a sanity check, and if configured for
141 * just-in-time parsing, we delete the control method
142 * parse trees.
143 */
4be44fcd 144 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
22b5afce 145 "**** Begin Table Object Initialization\n"));
1da177e4 146
f3d2e786 147 status = acpi_ds_initialize_objects(table_index, node);
1da177e4 148
4be44fcd 149 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
22b5afce 150 "**** Completed Table Object Initialization\n"));
1da177e4 151
2785ce8d
BM
152 /*
153 * Execute any module-level code that was detected during the table load
154 * phase. Although illegal since ACPI 2.0, there are many machines that
155 * contain this type of code. Each block of detected executable AML code
156 * outside of any control method is wrapped with a temporary control
157 * method object and placed on a global list. The methods on this list
158 * are executed below.
159 *
160 * This case executes the module-level code for each table immediately
161 * after the table has been loaded. This provides compatibility with
162 * other ACPI implementations. Optionally, the execution can be deferred
163 * until later, see acpi_initialize_objects.
164 */
165 if (!acpi_gbl_group_module_level_code) {
166 acpi_ns_exec_module_code_list();
167 }
168
4be44fcd 169 return_ACPI_STATUS(status);
1da177e4
LT
170}
171
f3d2e786 172#ifdef ACPI_OBSOLETE_FUNCTIONS
1da177e4
LT
173/*******************************************************************************
174 *
175 * FUNCTION: acpi_load_namespace
176 *
177 * PARAMETERS: None
178 *
179 * RETURN: Status
180 *
181 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
182 * (DSDT points to either the BIOS or a buffer.)
183 *
184 ******************************************************************************/
185
4be44fcd 186acpi_status acpi_ns_load_namespace(void)
1da177e4 187{
4be44fcd 188 acpi_status status;
1da177e4 189
b229cf92 190 ACPI_FUNCTION_TRACE(acpi_load_name_space);
1da177e4
LT
191
192 /* There must be at least a DSDT installed */
193
194 if (acpi_gbl_DSDT == NULL) {
b8e4d893 195 ACPI_ERROR((AE_INFO, "DSDT is not in memory"));
4be44fcd 196 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
1da177e4
LT
197 }
198
199 /*
73a3090a 200 * Load the namespace. The DSDT is required,
1da177e4
LT
201 * but the SSDT and PSDT tables are optional.
202 */
b229cf92 203 status = acpi_ns_load_table_by_type(ACPI_TABLE_ID_DSDT);
4be44fcd
LB
204 if (ACPI_FAILURE(status)) {
205 return_ACPI_STATUS(status);
1da177e4
LT
206 }
207
208 /* Ignore exceptions from these */
209
b229cf92
BM
210 (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_SSDT);
211 (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_PSDT);
1da177e4 212
4be44fcd
LB
213 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
214 "ACPI Namespace successfully loaded at root %p\n",
215 acpi_gbl_root_node));
1da177e4 216
4be44fcd 217 return_ACPI_STATUS(status);
1da177e4 218}
f3d2e786 219#endif
1da177e4 220
44f6c012 221#ifdef ACPI_FUTURE_IMPLEMENTATION
1da177e4
LT
222/*******************************************************************************
223 *
224 * FUNCTION: acpi_ns_delete_subtree
225 *
226 * PARAMETERS: start_handle - Handle in namespace where search begins
227 *
228 * RETURNS Status
229 *
230 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
231 * all objects, entries, and scopes in the entire subtree.
232 *
233 * Namespace/Interpreter should be locked or the subsystem should
234 * be in shutdown before this routine is called.
235 *
236 ******************************************************************************/
237
4be44fcd 238static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle)
1da177e4 239{
4be44fcd
LB
240 acpi_status status;
241 acpi_handle child_handle;
242 acpi_handle parent_handle;
243 acpi_handle next_child_handle;
244 acpi_handle dummy;
245 u32 level;
1da177e4 246
b229cf92 247 ACPI_FUNCTION_TRACE(ns_delete_subtree);
1da177e4
LT
248
249 parent_handle = start_handle;
250 child_handle = NULL;
4be44fcd 251 level = 1;
1da177e4
LT
252
253 /*
254 * Traverse the tree of objects until we bubble back up
255 * to where we started.
256 */
257 while (level > 0) {
52fc0b02 258
1da177e4
LT
259 /* Attempt to get the next object in this scope */
260
4be44fcd
LB
261 status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle,
262 child_handle, &next_child_handle);
1da177e4
LT
263
264 child_handle = next_child_handle;
265
266 /* Did we get a new object? */
267
4be44fcd 268 if (ACPI_SUCCESS(status)) {
52fc0b02 269
1da177e4
LT
270 /* Check if this object has any children */
271
4be44fcd
LB
272 if (ACPI_SUCCESS
273 (acpi_get_next_object
274 (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) {
1da177e4
LT
275 /*
276 * There is at least one child of this object,
277 * visit the object
278 */
279 level++;
280 parent_handle = child_handle;
281 child_handle = NULL;
282 }
4be44fcd 283 } else {
1da177e4
LT
284 /*
285 * No more children in this object, go back up to
286 * the object's parent
287 */
288 level--;
289
290 /* Delete all children now */
291
4be44fcd 292 acpi_ns_delete_children(child_handle);
1da177e4
LT
293
294 child_handle = parent_handle;
4be44fcd
LB
295 status = acpi_get_parent(parent_handle, &parent_handle);
296 if (ACPI_FAILURE(status)) {
297 return_ACPI_STATUS(status);
1da177e4
LT
298 }
299 }
300 }
301
302 /* Now delete the starting object, and we are done */
303
8e4319c4 304 acpi_ns_remove_node(child_handle);
4be44fcd 305 return_ACPI_STATUS(AE_OK);
1da177e4
LT
306}
307
1da177e4
LT
308/*******************************************************************************
309 *
310 * FUNCTION: acpi_ns_unload_name_space
311 *
ba494bee 312 * PARAMETERS: handle - Root of namespace subtree to be deleted
1da177e4
LT
313 *
314 * RETURN: Status
315 *
316 * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
73a3090a 317 * event. Deletes an entire subtree starting from (and
1da177e4
LT
318 * including) the given handle.
319 *
320 ******************************************************************************/
321
4be44fcd 322acpi_status acpi_ns_unload_namespace(acpi_handle handle)
1da177e4 323{
4be44fcd 324 acpi_status status;
1da177e4 325
b229cf92 326 ACPI_FUNCTION_TRACE(ns_unload_name_space);
1da177e4
LT
327
328 /* Parameter validation */
329
330 if (!acpi_gbl_root_node) {
4be44fcd 331 return_ACPI_STATUS(AE_NO_NAMESPACE);
1da177e4
LT
332 }
333
334 if (!handle) {
4be44fcd 335 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
336 }
337
338 /* This function does the real work */
339
4be44fcd 340 status = acpi_ns_delete_subtree(handle);
4be44fcd 341 return_ACPI_STATUS(status);
1da177e4 342}
44f6c012 343#endif
1da177e4 344#endif
This page took 0.673995 seconds and 5 git commands to generate.