Loading...
1/******************************************************************************
2 *
3 * Module Name: nsload - namespace loading/expanding/contracting procedures
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2011, Intel Corp.
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
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "acnamesp.h"
47#include "acdispat.h"
48#include "actables.h"
49
50#define _COMPONENT ACPI_NAMESPACE
51ACPI_MODULE_NAME("nsload")
52
53/* Local prototypes */
54#ifdef ACPI_FUTURE_IMPLEMENTATION
55acpi_status acpi_ns_unload_namespace(acpi_handle handle);
56
57static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
58#endif
59
60#ifndef ACPI_NO_METHOD_EXECUTION
61/*******************************************************************************
62 *
63 * FUNCTION: acpi_ns_load_table
64 *
65 * PARAMETERS: table_index - Index for table to be loaded
66 * Node - Owning NS node
67 *
68 * RETURN: Status
69 *
70 * DESCRIPTION: Load one ACPI table into the namespace
71 *
72 ******************************************************************************/
73
74acpi_status
75acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node)
76{
77 acpi_status status;
78
79 ACPI_FUNCTION_TRACE(ns_load_table);
80
81 /*
82 * Parse the table and load the namespace with all named
83 * objects found within. Control methods are NOT parsed
84 * at this time. In fact, the control methods cannot be
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 */
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
102 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
103 "**** Loading table into namespace ****\n"));
104
105 status = acpi_tb_allocate_owner_id(table_index);
106 if (ACPI_FAILURE(status)) {
107 goto unlock;
108 }
109
110 status = acpi_ns_parse_table(table_index, node);
111 if (ACPI_SUCCESS(status)) {
112 acpi_tb_set_table_loaded_flag(table_index, TRUE);
113 } else {
114 (void)acpi_tb_release_owner_id(table_index);
115 }
116
117 unlock:
118 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
119
120 if (ACPI_FAILURE(status)) {
121 return_ACPI_STATUS(status);
122 }
123
124 /*
125 * Now we can parse the control methods. We always parse
126 * them here for a sanity check, and if configured for
127 * just-in-time parsing, we delete the control method
128 * parse trees.
129 */
130 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
131 "**** Begin Table Method Parsing and Object Initialization\n"));
132
133 status = acpi_ds_initialize_objects(table_index, node);
134
135 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
136 "**** Completed Table Method Parsing and Object Initialization\n"));
137
138 return_ACPI_STATUS(status);
139}
140
141#ifdef ACPI_OBSOLETE_FUNCTIONS
142/*******************************************************************************
143 *
144 * FUNCTION: acpi_load_namespace
145 *
146 * PARAMETERS: None
147 *
148 * RETURN: Status
149 *
150 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
151 * (DSDT points to either the BIOS or a buffer.)
152 *
153 ******************************************************************************/
154
155acpi_status acpi_ns_load_namespace(void)
156{
157 acpi_status status;
158
159 ACPI_FUNCTION_TRACE(acpi_load_name_space);
160
161 /* There must be at least a DSDT installed */
162
163 if (acpi_gbl_DSDT == NULL) {
164 ACPI_ERROR((AE_INFO, "DSDT is not in memory"));
165 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
166 }
167
168 /*
169 * Load the namespace. The DSDT is required,
170 * but the SSDT and PSDT tables are optional.
171 */
172 status = acpi_ns_load_table_by_type(ACPI_TABLE_ID_DSDT);
173 if (ACPI_FAILURE(status)) {
174 return_ACPI_STATUS(status);
175 }
176
177 /* Ignore exceptions from these */
178
179 (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_SSDT);
180 (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_PSDT);
181
182 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
183 "ACPI Namespace successfully loaded at root %p\n",
184 acpi_gbl_root_node));
185
186 return_ACPI_STATUS(status);
187}
188#endif
189
190#ifdef ACPI_FUTURE_IMPLEMENTATION
191/*******************************************************************************
192 *
193 * FUNCTION: acpi_ns_delete_subtree
194 *
195 * PARAMETERS: start_handle - Handle in namespace where search begins
196 *
197 * RETURNS Status
198 *
199 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
200 * all objects, entries, and scopes in the entire subtree.
201 *
202 * Namespace/Interpreter should be locked or the subsystem should
203 * be in shutdown before this routine is called.
204 *
205 ******************************************************************************/
206
207static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle)
208{
209 acpi_status status;
210 acpi_handle child_handle;
211 acpi_handle parent_handle;
212 acpi_handle next_child_handle;
213 acpi_handle dummy;
214 u32 level;
215
216 ACPI_FUNCTION_TRACE(ns_delete_subtree);
217
218 parent_handle = start_handle;
219 child_handle = NULL;
220 level = 1;
221
222 /*
223 * Traverse the tree of objects until we bubble back up
224 * to where we started.
225 */
226 while (level > 0) {
227
228 /* Attempt to get the next object in this scope */
229
230 status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle,
231 child_handle, &next_child_handle);
232
233 child_handle = next_child_handle;
234
235 /* Did we get a new object? */
236
237 if (ACPI_SUCCESS(status)) {
238
239 /* Check if this object has any children */
240
241 if (ACPI_SUCCESS
242 (acpi_get_next_object
243 (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) {
244 /*
245 * There is at least one child of this object,
246 * visit the object
247 */
248 level++;
249 parent_handle = child_handle;
250 child_handle = NULL;
251 }
252 } else {
253 /*
254 * No more children in this object, go back up to
255 * the object's parent
256 */
257 level--;
258
259 /* Delete all children now */
260
261 acpi_ns_delete_children(child_handle);
262
263 child_handle = parent_handle;
264 status = acpi_get_parent(parent_handle, &parent_handle);
265 if (ACPI_FAILURE(status)) {
266 return_ACPI_STATUS(status);
267 }
268 }
269 }
270
271 /* Now delete the starting object, and we are done */
272
273 acpi_ns_remove_node(child_handle);
274 return_ACPI_STATUS(AE_OK);
275}
276
277/*******************************************************************************
278 *
279 * FUNCTION: acpi_ns_unload_name_space
280 *
281 * PARAMETERS: Handle - Root of namespace subtree to be deleted
282 *
283 * RETURN: Status
284 *
285 * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
286 * event. Deletes an entire subtree starting from (and
287 * including) the given handle.
288 *
289 ******************************************************************************/
290
291acpi_status acpi_ns_unload_namespace(acpi_handle handle)
292{
293 acpi_status status;
294
295 ACPI_FUNCTION_TRACE(ns_unload_name_space);
296
297 /* Parameter validation */
298
299 if (!acpi_gbl_root_node) {
300 return_ACPI_STATUS(AE_NO_NAMESPACE);
301 }
302
303 if (!handle) {
304 return_ACPI_STATUS(AE_BAD_PARAMETER);
305 }
306
307 /* This function does the real work */
308
309 status = acpi_ns_delete_subtree(handle);
310
311 return_ACPI_STATUS(status);
312}
313#endif
314#endif
1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2/******************************************************************************
3 *
4 * Module Name: nsload - namespace loading/expanding/contracting procedures
5 *
6 * Copyright (C) 2000 - 2018, Intel Corp.
7 *
8 *****************************************************************************/
9
10#include <acpi/acpi.h>
11#include "accommon.h"
12#include "acnamesp.h"
13#include "acdispat.h"
14#include "actables.h"
15#include "acinterp.h"
16
17#define _COMPONENT ACPI_NAMESPACE
18ACPI_MODULE_NAME("nsload")
19
20/* Local prototypes */
21#ifdef ACPI_FUTURE_IMPLEMENTATION
22acpi_status acpi_ns_unload_namespace(acpi_handle handle);
23
24static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
25#endif
26
27#ifndef ACPI_NO_METHOD_EXECUTION
28/*******************************************************************************
29 *
30 * FUNCTION: acpi_ns_load_table
31 *
32 * PARAMETERS: table_index - Index for table to be loaded
33 * node - Owning NS node
34 *
35 * RETURN: Status
36 *
37 * DESCRIPTION: Load one ACPI table into the namespace
38 *
39 ******************************************************************************/
40
41acpi_status
42acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node)
43{
44 acpi_status status;
45
46 ACPI_FUNCTION_TRACE(ns_load_table);
47
48 /* If table already loaded into namespace, just return */
49
50 if (acpi_tb_is_table_loaded(table_index)) {
51 status = AE_ALREADY_EXISTS;
52 goto unlock;
53 }
54
55 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
56 "**** Loading table into namespace ****\n"));
57
58 status = acpi_tb_allocate_owner_id(table_index);
59 if (ACPI_FAILURE(status)) {
60 goto unlock;
61 }
62
63 /*
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!
71 */
72 status = acpi_ns_parse_table(table_index, node);
73 if (ACPI_SUCCESS(status)) {
74 acpi_tb_set_table_loaded_flag(table_index, TRUE);
75 } else {
76 /*
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.
84 */
85 acpi_ns_delete_namespace_by_owner(acpi_gbl_root_table_list.
86 tables[table_index].owner_id);
87
88 acpi_tb_release_owner_id(table_index);
89 return_ACPI_STATUS(status);
90 }
91
92unlock:
93 if (ACPI_FAILURE(status)) {
94 return_ACPI_STATUS(status);
95 }
96
97 /*
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
101 * parse trees.
102 */
103 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
104 "**** Begin Table Object Initialization\n"));
105
106 acpi_ex_enter_interpreter();
107 status = acpi_ds_initialize_objects(table_index, node);
108 acpi_ex_exit_interpreter();
109
110 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
111 "**** Completed Table Object Initialization\n"));
112
113 /*
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
118 * load phase.
119 *
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.
123 */
124 acpi_ns_exec_module_code_list();
125 return_ACPI_STATUS(status);
126}
127
128#ifdef ACPI_OBSOLETE_FUNCTIONS
129/*******************************************************************************
130 *
131 * FUNCTION: acpi_load_namespace
132 *
133 * PARAMETERS: None
134 *
135 * RETURN: Status
136 *
137 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
138 * (DSDT points to either the BIOS or a buffer.)
139 *
140 ******************************************************************************/
141
142acpi_status acpi_ns_load_namespace(void)
143{
144 acpi_status status;
145
146 ACPI_FUNCTION_TRACE(acpi_load_name_space);
147
148 /* There must be at least a DSDT installed */
149
150 if (acpi_gbl_DSDT == NULL) {
151 ACPI_ERROR((AE_INFO, "DSDT is not in memory"));
152 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
153 }
154
155 /*
156 * Load the namespace. The DSDT is required,
157 * but the SSDT and PSDT tables are optional.
158 */
159 status = acpi_ns_load_table_by_type(ACPI_TABLE_ID_DSDT);
160 if (ACPI_FAILURE(status)) {
161 return_ACPI_STATUS(status);
162 }
163
164 /* Ignore exceptions from these */
165
166 (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_SSDT);
167 (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_PSDT);
168
169 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
170 "ACPI Namespace successfully loaded at root %p\n",
171 acpi_gbl_root_node));
172
173 return_ACPI_STATUS(status);
174}
175#endif
176
177#ifdef ACPI_FUTURE_IMPLEMENTATION
178/*******************************************************************************
179 *
180 * FUNCTION: acpi_ns_delete_subtree
181 *
182 * PARAMETERS: start_handle - Handle in namespace where search begins
183 *
184 * RETURNS Status
185 *
186 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
187 * all objects, entries, and scopes in the entire subtree.
188 *
189 * Namespace/Interpreter should be locked or the subsystem should
190 * be in shutdown before this routine is called.
191 *
192 ******************************************************************************/
193
194static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle)
195{
196 acpi_status status;
197 acpi_handle child_handle;
198 acpi_handle parent_handle;
199 acpi_handle next_child_handle;
200 acpi_handle dummy;
201 u32 level;
202
203 ACPI_FUNCTION_TRACE(ns_delete_subtree);
204
205 parent_handle = start_handle;
206 child_handle = NULL;
207 level = 1;
208
209 /*
210 * Traverse the tree of objects until we bubble back up
211 * to where we started.
212 */
213 while (level > 0) {
214
215 /* Attempt to get the next object in this scope */
216
217 status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle,
218 child_handle, &next_child_handle);
219
220 child_handle = next_child_handle;
221
222 /* Did we get a new object? */
223
224 if (ACPI_SUCCESS(status)) {
225
226 /* Check if this object has any children */
227
228 if (ACPI_SUCCESS
229 (acpi_get_next_object
230 (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) {
231 /*
232 * There is at least one child of this object,
233 * visit the object
234 */
235 level++;
236 parent_handle = child_handle;
237 child_handle = NULL;
238 }
239 } else {
240 /*
241 * No more children in this object, go back up to
242 * the object's parent
243 */
244 level--;
245
246 /* Delete all children now */
247
248 acpi_ns_delete_children(child_handle);
249
250 child_handle = parent_handle;
251 status = acpi_get_parent(parent_handle, &parent_handle);
252 if (ACPI_FAILURE(status)) {
253 return_ACPI_STATUS(status);
254 }
255 }
256 }
257
258 /* Now delete the starting object, and we are done */
259
260 acpi_ns_remove_node(child_handle);
261 return_ACPI_STATUS(AE_OK);
262}
263
264/*******************************************************************************
265 *
266 * FUNCTION: acpi_ns_unload_name_space
267 *
268 * PARAMETERS: handle - Root of namespace subtree to be deleted
269 *
270 * RETURN: Status
271 *
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.
275 *
276 ******************************************************************************/
277
278acpi_status acpi_ns_unload_namespace(acpi_handle handle)
279{
280 acpi_status status;
281
282 ACPI_FUNCTION_TRACE(ns_unload_name_space);
283
284 /* Parameter validation */
285
286 if (!acpi_gbl_root_node) {
287 return_ACPI_STATUS(AE_NO_NAMESPACE);
288 }
289
290 if (!handle) {
291 return_ACPI_STATUS(AE_BAD_PARAMETER);
292 }
293
294 /* This function does the real work */
295
296 status = acpi_ns_delete_subtree(handle);
297 return_ACPI_STATUS(status);
298}
299#endif
300#endif