blob: 297f6aacd7d406c4ca107d96878d98d72fde23b3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: nsload - namespace loading/expanding/contracting procedures
4 *
5 *****************************************************************************/
6
7/*
Bob Moorec8100dc2016-01-15 08:17:03 +08008 * Copyright (C) 2000 - 2016, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acnamesp.h"
47#include "acdispat.h"
48#include "actables.h"
Lv Zheng45209042016-07-05 13:53:12 +080049#include "acinterp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040052ACPI_MODULE_NAME("nsload")
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Robert Moore44f6c012005-04-18 22:49:35 -040054/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040055#ifdef ACPI_FUTURE_IMPLEMENTATION
Len Brown4be44fc2005-08-05 00:44:28 -040056acpi_status acpi_ns_unload_namespace(acpi_handle handle);
Robert Moore44f6c012005-04-18 22:49:35 -040057
Len Brown4be44fc2005-08-05 00:44:28 -040058static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
Robert Moore44f6c012005-04-18 22:49:35 -040059#endif
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#ifndef ACPI_NO_METHOD_EXECUTION
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/*******************************************************************************
63 *
64 * FUNCTION: acpi_ns_load_table
65 *
Bob Mooref3d2e782007-02-02 19:48:18 +030066 * PARAMETERS: table_index - Index for table to be loaded
Bob Mooreba494be2012-07-12 09:40:10 +080067 * node - Owning NS node
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 *
69 * RETURN: Status
70 *
71 * DESCRIPTION: Load one ACPI table into the namespace
72 *
73 ******************************************************************************/
74
75acpi_status
Bob Moore67a119f2008-06-10 13:42:13 +080076acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
Len Brown4be44fc2005-08-05 00:44:28 -040078 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Bob Mooreb229cf92006-04-21 17:15:00 -040080 ACPI_FUNCTION_TRACE(ns_load_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Lv Zheng45209042016-07-05 13:53:12 +080082 acpi_ex_enter_interpreter();
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 /*
85 * Parse the table and load the namespace with all named
Bob Moore73a30902012-10-31 02:26:55 +000086 * objects found within. Control methods are NOT parsed
87 * at this time. In fact, the control methods cannot be
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 * parsed until the entire namespace is loaded, because
89 * if a control method makes a forward reference (call)
90 * to another control method, we can't continue parsing
91 * because we don't know how many arguments to parse next!
92 */
Len Brown4be44fc2005-08-05 00:44:28 -040093 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
94 if (ACPI_FAILURE(status)) {
Lv Zheng45209042016-07-05 13:53:12 +080095 goto unlock_interp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 }
97
Bob Mooref3d2e782007-02-02 19:48:18 +030098 /* If table already loaded into namespace, just return */
99
100 if (acpi_tb_is_table_loaded(table_index)) {
101 status = AE_ALREADY_EXISTS;
102 goto unlock;
103 }
104
105 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
106 "**** Loading table into namespace ****\n"));
107
108 status = acpi_tb_allocate_owner_id(table_index);
109 if (ACPI_FAILURE(status)) {
110 goto unlock;
111 }
112
Bob Moore7f4ac9f2008-04-10 19:06:39 +0400113 status = acpi_ns_parse_table(table_index, node);
Bob Mooref3d2e782007-02-02 19:48:18 +0300114 if (ACPI_SUCCESS(status)) {
115 acpi_tb_set_table_loaded_flag(table_index, TRUE);
116 } else {
Bob Moore4712f712015-08-25 10:28:26 +0800117 /*
118 * On error, delete any namespace objects created by this table.
119 * We cannot initialize these objects, so delete them. There are
120 * a couple of expecially bad cases:
121 * AE_ALREADY_EXISTS - namespace collision.
122 * AE_NOT_FOUND - the target of a Scope operator does not
123 * exist. This target of Scope must already exist in the
124 * namespace, as per the ACPI specification.
125 */
126 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
127 acpi_ns_delete_namespace_by_owner(acpi_gbl_root_table_list.
128 tables[table_index].owner_id);
Bob Moore4712f712015-08-25 10:28:26 +0800129
Lv Zheng80b28812016-03-24 09:38:28 +0800130 acpi_tb_release_owner_id(table_index);
Bob Moore4712f712015-08-25 10:28:26 +0800131 return_ACPI_STATUS(status);
Bob Mooref3d2e782007-02-02 19:48:18 +0300132 }
133
Lv Zheng10622bf2013-10-29 09:30:02 +0800134unlock:
Len Brown4be44fc2005-08-05 00:44:28 -0400135 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Lv Zheng45209042016-07-05 13:53:12 +0800136unlock_interp:
137 (void)acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Len Brown4be44fc2005-08-05 00:44:28 -0400139 if (ACPI_FAILURE(status)) {
140 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
142
143 /*
Bob Moore73a30902012-10-31 02:26:55 +0000144 * Now we can parse the control methods. We always parse
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 * them here for a sanity check, and if configured for
146 * just-in-time parsing, we delete the control method
147 * parse trees.
148 */
Len Brown4be44fc2005-08-05 00:44:28 -0400149 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Moore22b5afc2014-03-24 14:49:00 +0800150 "**** Begin Table Object Initialization\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Bob Mooref3d2e782007-02-02 19:48:18 +0300152 status = acpi_ds_initialize_objects(table_index, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Len Brown4be44fc2005-08-05 00:44:28 -0400154 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Moore22b5afc2014-03-24 14:49:00 +0800155 "**** Completed Table Object Initialization\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Bob Moore2785ce82015-12-29 14:04:19 +0800157 /*
158 * Execute any module-level code that was detected during the table load
159 * phase. Although illegal since ACPI 2.0, there are many machines that
160 * contain this type of code. Each block of detected executable AML code
161 * outside of any control method is wrapped with a temporary control
162 * method object and placed on a global list. The methods on this list
163 * are executed below.
164 *
165 * This case executes the module-level code for each table immediately
166 * after the table has been loaded. This provides compatibility with
167 * other ACPI implementations. Optionally, the execution can be deferred
168 * until later, see acpi_initialize_objects.
169 */
170 if (!acpi_gbl_group_module_level_code) {
171 acpi_ns_exec_module_code_list();
172 }
173
Len Brown4be44fc2005-08-05 00:44:28 -0400174 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175}
176
Bob Mooref3d2e782007-02-02 19:48:18 +0300177#ifdef ACPI_OBSOLETE_FUNCTIONS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178/*******************************************************************************
179 *
180 * FUNCTION: acpi_load_namespace
181 *
182 * PARAMETERS: None
183 *
184 * RETURN: Status
185 *
186 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
187 * (DSDT points to either the BIOS or a buffer.)
188 *
189 ******************************************************************************/
190
Len Brown4be44fc2005-08-05 00:44:28 -0400191acpi_status acpi_ns_load_namespace(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Len Brown4be44fc2005-08-05 00:44:28 -0400193 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Bob Mooreb229cf92006-04-21 17:15:00 -0400195 ACPI_FUNCTION_TRACE(acpi_load_name_space);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 /* There must be at least a DSDT installed */
198
199 if (acpi_gbl_DSDT == NULL) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500200 ACPI_ERROR((AE_INFO, "DSDT is not in memory"));
Len Brown4be44fc2005-08-05 00:44:28 -0400201 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
203
204 /*
Bob Moore73a30902012-10-31 02:26:55 +0000205 * Load the namespace. The DSDT is required,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 * but the SSDT and PSDT tables are optional.
207 */
Bob Mooreb229cf92006-04-21 17:15:00 -0400208 status = acpi_ns_load_table_by_type(ACPI_TABLE_ID_DSDT);
Len Brown4be44fc2005-08-05 00:44:28 -0400209 if (ACPI_FAILURE(status)) {
210 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
212
213 /* Ignore exceptions from these */
214
Bob Mooreb229cf92006-04-21 17:15:00 -0400215 (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_SSDT);
216 (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_PSDT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Len Brown4be44fc2005-08-05 00:44:28 -0400218 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
219 "ACPI Namespace successfully loaded at root %p\n",
220 acpi_gbl_root_node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Len Brown4be44fc2005-08-05 00:44:28 -0400222 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
Bob Mooref3d2e782007-02-02 19:48:18 +0300224#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Robert Moore44f6c012005-04-18 22:49:35 -0400226#ifdef ACPI_FUTURE_IMPLEMENTATION
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227/*******************************************************************************
228 *
229 * FUNCTION: acpi_ns_delete_subtree
230 *
231 * PARAMETERS: start_handle - Handle in namespace where search begins
232 *
233 * RETURNS Status
234 *
235 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
236 * all objects, entries, and scopes in the entire subtree.
237 *
238 * Namespace/Interpreter should be locked or the subsystem should
239 * be in shutdown before this routine is called.
240 *
241 ******************************************************************************/
242
Len Brown4be44fc2005-08-05 00:44:28 -0400243static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Len Brown4be44fc2005-08-05 00:44:28 -0400245 acpi_status status;
246 acpi_handle child_handle;
247 acpi_handle parent_handle;
248 acpi_handle next_child_handle;
249 acpi_handle dummy;
250 u32 level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Bob Mooreb229cf92006-04-21 17:15:00 -0400252 ACPI_FUNCTION_TRACE(ns_delete_subtree);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254 parent_handle = start_handle;
255 child_handle = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400256 level = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258 /*
259 * Traverse the tree of objects until we bubble back up
260 * to where we started.
261 */
262 while (level > 0) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 /* Attempt to get the next object in this scope */
265
Len Brown4be44fc2005-08-05 00:44:28 -0400266 status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle,
267 child_handle, &next_child_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269 child_handle = next_child_handle;
270
271 /* Did we get a new object? */
272
Len Brown4be44fc2005-08-05 00:44:28 -0400273 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 /* Check if this object has any children */
276
Len Brown4be44fc2005-08-05 00:44:28 -0400277 if (ACPI_SUCCESS
278 (acpi_get_next_object
279 (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 /*
281 * There is at least one child of this object,
282 * visit the object
283 */
284 level++;
285 parent_handle = child_handle;
286 child_handle = NULL;
287 }
Len Brown4be44fc2005-08-05 00:44:28 -0400288 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 /*
290 * No more children in this object, go back up to
291 * the object's parent
292 */
293 level--;
294
295 /* Delete all children now */
296
Len Brown4be44fc2005-08-05 00:44:28 -0400297 acpi_ns_delete_children(child_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299 child_handle = parent_handle;
Len Brown4be44fc2005-08-05 00:44:28 -0400300 status = acpi_get_parent(parent_handle, &parent_handle);
301 if (ACPI_FAILURE(status)) {
302 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
304 }
305 }
306
307 /* Now delete the starting object, and we are done */
308
Bob Moore8e4319c2009-06-29 13:43:27 +0800309 acpi_ns_remove_node(child_handle);
Len Brown4be44fc2005-08-05 00:44:28 -0400310 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313/*******************************************************************************
314 *
315 * FUNCTION: acpi_ns_unload_name_space
316 *
Bob Mooreba494be2012-07-12 09:40:10 +0800317 * PARAMETERS: handle - Root of namespace subtree to be deleted
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 *
319 * RETURN: Status
320 *
321 * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
Bob Moore73a30902012-10-31 02:26:55 +0000322 * event. Deletes an entire subtree starting from (and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 * including) the given handle.
324 *
325 ******************************************************************************/
326
Len Brown4be44fc2005-08-05 00:44:28 -0400327acpi_status acpi_ns_unload_namespace(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328{
Len Brown4be44fc2005-08-05 00:44:28 -0400329 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Bob Mooreb229cf92006-04-21 17:15:00 -0400331 ACPI_FUNCTION_TRACE(ns_unload_name_space);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333 /* Parameter validation */
334
335 if (!acpi_gbl_root_node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400336 return_ACPI_STATUS(AE_NO_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 }
338
339 if (!handle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400340 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342
343 /* This function does the real work */
344
Len Brown4be44fc2005-08-05 00:44:28 -0400345 status = acpi_ns_delete_subtree(handle);
Len Brown4be44fc2005-08-05 00:44:28 -0400346 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347}
Robert Moore44f6c012005-04-18 22:49:35 -0400348#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349#endif