1 /******************************************************************************
3 * Module Name: nsload - namespace loading/expanding/contracting procedures
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <acpi/acpi.h>
51 #define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME("nsload")
54 /* Local prototypes */
55 #ifdef ACPI_FUTURE_IMPLEMENTATION
56 acpi_status acpi_ns_unload_namespace(acpi_handle handle);
58 static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
61 #ifndef ACPI_NO_METHOD_EXECUTION
62 /*******************************************************************************
64 * FUNCTION: acpi_ns_load_table
66 * PARAMETERS: table_index - Index for table to be loaded
67 * node - Owning NS node
71 * DESCRIPTION: Load one ACPI table into the namespace
73 ******************************************************************************/
76 acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node)
80 ACPI_FUNCTION_TRACE(ns_load_table);
82 acpi_ex_enter_interpreter();
85 * Parse the table and load the namespace with all named
86 * objects found within. Control methods are NOT parsed
87 * at this time. In fact, the control methods cannot be
88 * 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!
93 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
94 if (ACPI_FAILURE(status)) {
98 /* If table already loaded into namespace, just return */
100 if (acpi_tb_is_table_loaded(table_index)) {
101 status = AE_ALREADY_EXISTS;
105 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
106 "**** Loading table into namespace ****\n"));
108 status = acpi_tb_allocate_owner_id(table_index);
109 if (ACPI_FAILURE(status)) {
113 status = acpi_ns_parse_table(table_index, node);
114 if (ACPI_SUCCESS(status)) {
115 acpi_tb_set_table_loaded_flag(table_index, TRUE);
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.
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);
130 acpi_tb_release_owner_id(table_index);
131 return_ACPI_STATUS(status);
135 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
137 (void)acpi_ex_exit_interpreter();
139 if (ACPI_FAILURE(status)) {
140 return_ACPI_STATUS(status);
144 * Now we can parse the control methods. We always parse
145 * them here for a sanity check, and if configured for
146 * just-in-time parsing, we delete the control method
149 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
150 "**** Begin Table Object Initialization\n"));
152 status = acpi_ds_initialize_objects(table_index, node);
154 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
155 "**** Completed Table Object Initialization\n"));
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.
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.
170 if (!acpi_gbl_group_module_level_code) {
171 acpi_ns_exec_module_code_list();
174 return_ACPI_STATUS(status);
177 #ifdef ACPI_OBSOLETE_FUNCTIONS
178 /*******************************************************************************
180 * FUNCTION: acpi_load_namespace
186 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
187 * (DSDT points to either the BIOS or a buffer.)
189 ******************************************************************************/
191 acpi_status acpi_ns_load_namespace(void)
195 ACPI_FUNCTION_TRACE(acpi_load_name_space);
197 /* There must be at least a DSDT installed */
199 if (acpi_gbl_DSDT == NULL) {
200 ACPI_ERROR((AE_INFO, "DSDT is not in memory"));
201 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
205 * Load the namespace. The DSDT is required,
206 * but the SSDT and PSDT tables are optional.
208 status = acpi_ns_load_table_by_type(ACPI_TABLE_ID_DSDT);
209 if (ACPI_FAILURE(status)) {
210 return_ACPI_STATUS(status);
213 /* Ignore exceptions from these */
215 (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_SSDT);
216 (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_PSDT);
218 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
219 "ACPI Namespace successfully loaded at root %p\n",
220 acpi_gbl_root_node));
222 return_ACPI_STATUS(status);
226 #ifdef ACPI_FUTURE_IMPLEMENTATION
227 /*******************************************************************************
229 * FUNCTION: acpi_ns_delete_subtree
231 * PARAMETERS: start_handle - Handle in namespace where search begins
235 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
236 * all objects, entries, and scopes in the entire subtree.
238 * Namespace/Interpreter should be locked or the subsystem should
239 * be in shutdown before this routine is called.
241 ******************************************************************************/
243 static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle)
246 acpi_handle child_handle;
247 acpi_handle parent_handle;
248 acpi_handle next_child_handle;
252 ACPI_FUNCTION_TRACE(ns_delete_subtree);
254 parent_handle = start_handle;
259 * Traverse the tree of objects until we bubble back up
260 * to where we started.
264 /* Attempt to get the next object in this scope */
266 status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle,
267 child_handle, &next_child_handle);
269 child_handle = next_child_handle;
271 /* Did we get a new object? */
273 if (ACPI_SUCCESS(status)) {
275 /* Check if this object has any children */
278 (acpi_get_next_object
279 (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) {
281 * There is at least one child of this object,
285 parent_handle = child_handle;
290 * No more children in this object, go back up to
291 * the object's parent
295 /* Delete all children now */
297 acpi_ns_delete_children(child_handle);
299 child_handle = parent_handle;
300 status = acpi_get_parent(parent_handle, &parent_handle);
301 if (ACPI_FAILURE(status)) {
302 return_ACPI_STATUS(status);
307 /* Now delete the starting object, and we are done */
309 acpi_ns_remove_node(child_handle);
310 return_ACPI_STATUS(AE_OK);
313 /*******************************************************************************
315 * FUNCTION: acpi_ns_unload_name_space
317 * PARAMETERS: handle - Root of namespace subtree to be deleted
321 * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
322 * event. Deletes an entire subtree starting from (and
323 * including) the given handle.
325 ******************************************************************************/
327 acpi_status acpi_ns_unload_namespace(acpi_handle handle)
331 ACPI_FUNCTION_TRACE(ns_unload_name_space);
333 /* Parameter validation */
335 if (!acpi_gbl_root_node) {
336 return_ACPI_STATUS(AE_NO_NAMESPACE);
340 return_ACPI_STATUS(AE_BAD_PARAMETER);
343 /* This function does the real work */
345 status = acpi_ns_delete_subtree(handle);
346 return_ACPI_STATUS(status);