1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: nsload - namespace loading/expanding/contracting procedures
6 * Copyright (C) 2000 - 2018, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
17 #define _COMPONENT ACPI_NAMESPACE
18 ACPI_MODULE_NAME("nsload")
20 /* Local prototypes */
21 #ifdef ACPI_FUTURE_IMPLEMENTATION
22 acpi_status
acpi_ns_unload_namespace(acpi_handle handle
);
24 static acpi_status
acpi_ns_delete_subtree(acpi_handle start_handle
);
27 #ifndef ACPI_NO_METHOD_EXECUTION
28 /*******************************************************************************
30 * FUNCTION: acpi_ns_load_table
32 * PARAMETERS: table_index - Index for table to be loaded
33 * node - Owning NS node
37 * DESCRIPTION: Load one ACPI table into the namespace
39 ******************************************************************************/
42 acpi_ns_load_table(u32 table_index
, struct acpi_namespace_node
*node
)
46 ACPI_FUNCTION_TRACE(ns_load_table
);
48 /* If table already loaded into namespace, just return */
50 if (acpi_tb_is_table_loaded(table_index
)) {
51 status
= AE_ALREADY_EXISTS
;
55 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
56 "**** Loading table into namespace ****\n"));
58 status
= acpi_tb_allocate_owner_id(table_index
);
59 if (ACPI_FAILURE(status
)) {
64 * Parse the table and load the namespace with all named
65 * objects found within. Control methods are NOT parsed
66 * at this time. In fact, the control methods cannot be
67 * parsed until the entire namespace is loaded, because
68 * if a control method makes a forward reference (call)
69 * to another control method, we can't continue parsing
70 * because we don't know how many arguments to parse next!
72 status
= acpi_ns_parse_table(table_index
, node
);
73 if (ACPI_SUCCESS(status
)) {
74 acpi_tb_set_table_loaded_flag(table_index
, TRUE
);
77 * On error, delete any namespace objects created by this table.
78 * We cannot initialize these objects, so delete them. There are
79 * a couple of expecially bad cases:
80 * AE_ALREADY_EXISTS - namespace collision.
81 * AE_NOT_FOUND - the target of a Scope operator does not
82 * exist. This target of Scope must already exist in the
83 * namespace, as per the ACPI specification.
85 acpi_ns_delete_namespace_by_owner(acpi_gbl_root_table_list
.
86 tables
[table_index
].owner_id
);
88 acpi_tb_release_owner_id(table_index
);
89 return_ACPI_STATUS(status
);
93 if (ACPI_FAILURE(status
)) {
94 return_ACPI_STATUS(status
);
98 * Now we can parse the control methods. We always parse
99 * them here for a sanity check, and if configured for
100 * just-in-time parsing, we delete the control method
103 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
104 "**** Begin Table Object Initialization\n"));
106 acpi_ex_enter_interpreter();
107 status
= acpi_ds_initialize_objects(table_index
, node
);
108 acpi_ex_exit_interpreter();
110 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
111 "**** Completed Table Object Initialization\n"));
114 * This case handles the legacy option that groups all module-level
115 * code blocks together and defers execution until all of the tables
116 * are loaded. Execute all of these blocks at this time.
117 * Execute any module-level code that was detected during the table
120 * Note: this option is deprecated and will be eliminated in the
121 * future. Use of this option can cause problems with AML code that
122 * depends upon in-order immediate execution of module-level code.
124 acpi_ns_exec_module_code_list();
125 return_ACPI_STATUS(status
);
128 #ifdef ACPI_OBSOLETE_FUNCTIONS
129 /*******************************************************************************
131 * FUNCTION: acpi_load_namespace
137 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
138 * (DSDT points to either the BIOS or a buffer.)
140 ******************************************************************************/
142 acpi_status
acpi_ns_load_namespace(void)
146 ACPI_FUNCTION_TRACE(acpi_load_name_space
);
148 /* There must be at least a DSDT installed */
150 if (acpi_gbl_DSDT
== NULL
) {
151 ACPI_ERROR((AE_INFO
, "DSDT is not in memory"));
152 return_ACPI_STATUS(AE_NO_ACPI_TABLES
);
156 * Load the namespace. The DSDT is required,
157 * but the SSDT and PSDT tables are optional.
159 status
= acpi_ns_load_table_by_type(ACPI_TABLE_ID_DSDT
);
160 if (ACPI_FAILURE(status
)) {
161 return_ACPI_STATUS(status
);
164 /* Ignore exceptions from these */
166 (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_SSDT
);
167 (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_PSDT
);
169 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT
,
170 "ACPI Namespace successfully loaded at root %p\n",
171 acpi_gbl_root_node
));
173 return_ACPI_STATUS(status
);
177 #ifdef ACPI_FUTURE_IMPLEMENTATION
178 /*******************************************************************************
180 * FUNCTION: acpi_ns_delete_subtree
182 * PARAMETERS: start_handle - Handle in namespace where search begins
186 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
187 * all objects, entries, and scopes in the entire subtree.
189 * Namespace/Interpreter should be locked or the subsystem should
190 * be in shutdown before this routine is called.
192 ******************************************************************************/
194 static acpi_status
acpi_ns_delete_subtree(acpi_handle start_handle
)
197 acpi_handle child_handle
;
198 acpi_handle parent_handle
;
199 acpi_handle next_child_handle
;
203 ACPI_FUNCTION_TRACE(ns_delete_subtree
);
205 parent_handle
= start_handle
;
210 * Traverse the tree of objects until we bubble back up
211 * to where we started.
215 /* Attempt to get the next object in this scope */
217 status
= acpi_get_next_object(ACPI_TYPE_ANY
, parent_handle
,
218 child_handle
, &next_child_handle
);
220 child_handle
= next_child_handle
;
222 /* Did we get a new object? */
224 if (ACPI_SUCCESS(status
)) {
226 /* Check if this object has any children */
229 (acpi_get_next_object
230 (ACPI_TYPE_ANY
, child_handle
, NULL
, &dummy
))) {
232 * There is at least one child of this object,
236 parent_handle
= child_handle
;
241 * No more children in this object, go back up to
242 * the object's parent
246 /* Delete all children now */
248 acpi_ns_delete_children(child_handle
);
250 child_handle
= parent_handle
;
251 status
= acpi_get_parent(parent_handle
, &parent_handle
);
252 if (ACPI_FAILURE(status
)) {
253 return_ACPI_STATUS(status
);
258 /* Now delete the starting object, and we are done */
260 acpi_ns_remove_node(child_handle
);
261 return_ACPI_STATUS(AE_OK
);
264 /*******************************************************************************
266 * FUNCTION: acpi_ns_unload_name_space
268 * PARAMETERS: handle - Root of namespace subtree to be deleted
272 * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
273 * event. Deletes an entire subtree starting from (and
274 * including) the given handle.
276 ******************************************************************************/
278 acpi_status
acpi_ns_unload_namespace(acpi_handle handle
)
282 ACPI_FUNCTION_TRACE(ns_unload_name_space
);
284 /* Parameter validation */
286 if (!acpi_gbl_root_node
) {
287 return_ACPI_STATUS(AE_NO_NAMESPACE
);
291 return_ACPI_STATUS(AE_BAD_PARAMETER
);
294 /* This function does the real work */
296 status
= acpi_ns_delete_subtree(handle
);
297 return_ACPI_STATUS(status
);