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