Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: nsload - namespace loading/expanding/contracting procedures | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | |
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 | ||
45 | #include <acpi/acpi.h> | |
46 | #include <acpi/acnamesp.h> | |
47 | #include <acpi/acdispat.h> | |
48 | ||
49 | ||
50 | #define _COMPONENT ACPI_NAMESPACE | |
51 | ACPI_MODULE_NAME ("nsload") | |
52 | ||
44f6c012 | 53 | /* Local prototypes */ |
1da177e4 | 54 | |
44f6c012 RM |
55 | static acpi_status |
56 | acpi_ns_load_table_by_type ( | |
57 | acpi_table_type table_type); | |
58 | ||
59 | #ifdef ACPI_FUTURE_IMPLEMENTATION | |
60 | acpi_status | |
61 | acpi_ns_unload_namespace ( | |
62 | acpi_handle handle); | |
63 | ||
64 | static acpi_status | |
65 | acpi_ns_delete_subtree ( | |
66 | acpi_handle start_handle); | |
67 | #endif | |
1da177e4 | 68 | |
44f6c012 RM |
69 | |
70 | #ifndef ACPI_NO_METHOD_EXECUTION | |
1da177e4 LT |
71 | /******************************************************************************* |
72 | * | |
73 | * FUNCTION: acpi_ns_load_table | |
74 | * | |
75 | * PARAMETERS: table_desc - Descriptor for table to be loaded | |
76 | * Node - Owning NS node | |
77 | * | |
78 | * RETURN: Status | |
79 | * | |
80 | * DESCRIPTION: Load one ACPI table into the namespace | |
81 | * | |
82 | ******************************************************************************/ | |
83 | ||
84 | acpi_status | |
85 | acpi_ns_load_table ( | |
86 | struct acpi_table_desc *table_desc, | |
87 | struct acpi_namespace_node *node) | |
88 | { | |
89 | acpi_status status; | |
90 | ||
91 | ||
92 | ACPI_FUNCTION_TRACE ("ns_load_table"); | |
93 | ||
94 | ||
95 | /* Check if table contains valid AML (must be DSDT, PSDT, SSDT, etc.) */ | |
96 | ||
97 | if (!(acpi_gbl_table_data[table_desc->type].flags & ACPI_TABLE_EXECUTABLE)) { | |
98 | /* Just ignore this table */ | |
99 | ||
100 | return_ACPI_STATUS (AE_OK); | |
101 | } | |
102 | ||
103 | /* Check validity of the AML start and length */ | |
104 | ||
105 | if (!table_desc->aml_start) { | |
106 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null AML pointer\n")); | |
107 | return_ACPI_STATUS (AE_BAD_PARAMETER); | |
108 | } | |
109 | ||
110 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AML block at %p\n", | |
111 | table_desc->aml_start)); | |
112 | ||
113 | /* Ignore table if there is no AML contained within */ | |
114 | ||
115 | if (!table_desc->aml_length) { | |
116 | ACPI_REPORT_WARNING (("Zero-length AML block in table [%4.4s]\n", | |
117 | table_desc->pointer->signature)); | |
118 | return_ACPI_STATUS (AE_OK); | |
119 | } | |
120 | ||
121 | /* | |
122 | * Parse the table and load the namespace with all named | |
123 | * objects found within. Control methods are NOT parsed | |
124 | * at this time. In fact, the control methods cannot be | |
125 | * parsed until the entire namespace is loaded, because | |
126 | * if a control method makes a forward reference (call) | |
127 | * to another control method, we can't continue parsing | |
128 | * because we don't know how many arguments to parse next! | |
129 | */ | |
130 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, | |
131 | "**** Loading table into namespace ****\n")); | |
132 | ||
133 | status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE); | |
134 | if (ACPI_FAILURE (status)) { | |
135 | return_ACPI_STATUS (status); | |
136 | } | |
137 | ||
138 | status = acpi_ns_parse_table (table_desc, node->child); | |
139 | (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE); | |
140 | ||
141 | if (ACPI_FAILURE (status)) { | |
142 | return_ACPI_STATUS (status); | |
143 | } | |
144 | ||
145 | /* | |
146 | * Now we can parse the control methods. We always parse | |
147 | * them here for a sanity check, and if configured for | |
148 | * just-in-time parsing, we delete the control method | |
149 | * parse trees. | |
150 | */ | |
151 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, | |
152 | "**** Begin Table Method Parsing and Object Initialization ****\n")); | |
153 | ||
154 | status = acpi_ds_initialize_objects (table_desc, node); | |
155 | ||
156 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, | |
157 | "**** Completed Table Method Parsing and Object Initialization ****\n")); | |
158 | ||
159 | return_ACPI_STATUS (status); | |
160 | } | |
161 | ||
162 | ||
163 | /******************************************************************************* | |
164 | * | |
165 | * FUNCTION: acpi_ns_load_table_by_type | |
166 | * | |
167 | * PARAMETERS: table_type - Id of the table type to load | |
168 | * | |
169 | * RETURN: Status | |
170 | * | |
171 | * DESCRIPTION: Load an ACPI table or tables into the namespace. All tables | |
172 | * of the given type are loaded. The mechanism allows this | |
173 | * routine to be called repeatedly. | |
174 | * | |
175 | ******************************************************************************/ | |
176 | ||
44f6c012 | 177 | static acpi_status |
1da177e4 LT |
178 | acpi_ns_load_table_by_type ( |
179 | acpi_table_type table_type) | |
180 | { | |
181 | u32 i; | |
182 | acpi_status status; | |
183 | struct acpi_table_desc *table_desc; | |
184 | ||
185 | ||
186 | ACPI_FUNCTION_TRACE ("ns_load_table_by_type"); | |
187 | ||
188 | ||
189 | status = acpi_ut_acquire_mutex (ACPI_MTX_TABLES); | |
190 | if (ACPI_FAILURE (status)) { | |
191 | return_ACPI_STATUS (status); | |
192 | } | |
193 | ||
194 | /* | |
195 | * Table types supported are: | |
196 | * DSDT (one), SSDT/PSDT (multiple) | |
197 | */ | |
198 | switch (table_type) { | |
199 | case ACPI_TABLE_DSDT: | |
200 | ||
0c9938cc | 201 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace load: DSDT\n")); |
1da177e4 LT |
202 | |
203 | table_desc = acpi_gbl_table_lists[ACPI_TABLE_DSDT].next; | |
204 | ||
205 | /* If table already loaded into namespace, just return */ | |
206 | ||
207 | if (table_desc->loaded_into_namespace) { | |
208 | goto unlock_and_exit; | |
209 | } | |
210 | ||
211 | /* Now load the single DSDT */ | |
212 | ||
213 | status = acpi_ns_load_table (table_desc, acpi_gbl_root_node); | |
214 | if (ACPI_SUCCESS (status)) { | |
215 | table_desc->loaded_into_namespace = TRUE; | |
216 | } | |
217 | break; | |
218 | ||
219 | ||
220 | case ACPI_TABLE_SSDT: | |
0c9938cc | 221 | case ACPI_TABLE_PSDT: |
1da177e4 | 222 | |
0c9938cc RM |
223 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace load: %d SSDT or PSDTs\n", |
224 | acpi_gbl_table_lists[table_type].count)); | |
1da177e4 LT |
225 | |
226 | /* | |
0c9938cc | 227 | * Traverse list of SSDT or PSDT tables |
1da177e4 | 228 | */ |
0c9938cc RM |
229 | table_desc = acpi_gbl_table_lists[table_type].next; |
230 | for (i = 0; i < acpi_gbl_table_lists[table_type].count; i++) { | |
1da177e4 | 231 | /* |
0c9938cc | 232 | * Only attempt to load table into namespace if it is not |
1da177e4 LT |
233 | * already loaded! |
234 | */ | |
235 | if (!table_desc->loaded_into_namespace) { | |
236 | status = acpi_ns_load_table (table_desc, acpi_gbl_root_node); | |
237 | if (ACPI_FAILURE (status)) { | |
238 | break; | |
239 | } | |
240 | ||
241 | table_desc->loaded_into_namespace = TRUE; | |
242 | } | |
243 | ||
244 | table_desc = table_desc->next; | |
245 | } | |
246 | break; | |
247 | ||
248 | ||
1da177e4 LT |
249 | default: |
250 | status = AE_SUPPORT; | |
251 | break; | |
252 | } | |
253 | ||
254 | ||
255 | unlock_and_exit: | |
256 | (void) acpi_ut_release_mutex (ACPI_MTX_TABLES); | |
257 | return_ACPI_STATUS (status); | |
258 | } | |
259 | ||
260 | ||
261 | /******************************************************************************* | |
262 | * | |
263 | * FUNCTION: acpi_load_namespace | |
264 | * | |
265 | * PARAMETERS: None | |
266 | * | |
267 | * RETURN: Status | |
268 | * | |
269 | * DESCRIPTION: Load the name space from what ever is pointed to by DSDT. | |
270 | * (DSDT points to either the BIOS or a buffer.) | |
271 | * | |
272 | ******************************************************************************/ | |
273 | ||
274 | acpi_status | |
275 | acpi_ns_load_namespace ( | |
276 | void) | |
277 | { | |
278 | acpi_status status; | |
279 | ||
280 | ||
281 | ACPI_FUNCTION_TRACE ("acpi_load_name_space"); | |
282 | ||
283 | ||
284 | /* There must be at least a DSDT installed */ | |
285 | ||
286 | if (acpi_gbl_DSDT == NULL) { | |
287 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "DSDT is not in memory\n")); | |
288 | return_ACPI_STATUS (AE_NO_ACPI_TABLES); | |
289 | } | |
290 | ||
291 | /* | |
292 | * Load the namespace. The DSDT is required, | |
293 | * but the SSDT and PSDT tables are optional. | |
294 | */ | |
295 | status = acpi_ns_load_table_by_type (ACPI_TABLE_DSDT); | |
296 | if (ACPI_FAILURE (status)) { | |
297 | return_ACPI_STATUS (status); | |
298 | } | |
299 | ||
300 | /* Ignore exceptions from these */ | |
301 | ||
302 | (void) acpi_ns_load_table_by_type (ACPI_TABLE_SSDT); | |
303 | (void) acpi_ns_load_table_by_type (ACPI_TABLE_PSDT); | |
304 | ||
305 | ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, | |
306 | "ACPI Namespace successfully loaded at root %p\n", | |
307 | acpi_gbl_root_node)); | |
308 | ||
309 | return_ACPI_STATUS (status); | |
310 | } | |
311 | ||
312 | ||
44f6c012 | 313 | #ifdef ACPI_FUTURE_IMPLEMENTATION |
1da177e4 LT |
314 | /******************************************************************************* |
315 | * | |
316 | * FUNCTION: acpi_ns_delete_subtree | |
317 | * | |
318 | * PARAMETERS: start_handle - Handle in namespace where search begins | |
319 | * | |
320 | * RETURNS Status | |
321 | * | |
322 | * DESCRIPTION: Walks the namespace starting at the given handle and deletes | |
323 | * all objects, entries, and scopes in the entire subtree. | |
324 | * | |
325 | * Namespace/Interpreter should be locked or the subsystem should | |
326 | * be in shutdown before this routine is called. | |
327 | * | |
328 | ******************************************************************************/ | |
329 | ||
44f6c012 | 330 | static acpi_status |
1da177e4 LT |
331 | acpi_ns_delete_subtree ( |
332 | acpi_handle start_handle) | |
333 | { | |
334 | acpi_status status; | |
335 | acpi_handle child_handle; | |
336 | acpi_handle parent_handle; | |
337 | acpi_handle next_child_handle; | |
338 | acpi_handle dummy; | |
339 | u32 level; | |
340 | ||
341 | ||
342 | ACPI_FUNCTION_TRACE ("ns_delete_subtree"); | |
343 | ||
344 | ||
345 | parent_handle = start_handle; | |
346 | child_handle = NULL; | |
347 | level = 1; | |
348 | ||
349 | /* | |
350 | * Traverse the tree of objects until we bubble back up | |
351 | * to where we started. | |
352 | */ | |
353 | while (level > 0) { | |
354 | /* Attempt to get the next object in this scope */ | |
355 | ||
356 | status = acpi_get_next_object (ACPI_TYPE_ANY, parent_handle, | |
357 | child_handle, &next_child_handle); | |
358 | ||
359 | child_handle = next_child_handle; | |
360 | ||
361 | /* Did we get a new object? */ | |
362 | ||
363 | if (ACPI_SUCCESS (status)) { | |
364 | /* Check if this object has any children */ | |
365 | ||
366 | if (ACPI_SUCCESS (acpi_get_next_object (ACPI_TYPE_ANY, child_handle, | |
367 | NULL, &dummy))) { | |
368 | /* | |
369 | * There is at least one child of this object, | |
370 | * visit the object | |
371 | */ | |
372 | level++; | |
373 | parent_handle = child_handle; | |
374 | child_handle = NULL; | |
375 | } | |
376 | } | |
377 | else { | |
378 | /* | |
379 | * No more children in this object, go back up to | |
380 | * the object's parent | |
381 | */ | |
382 | level--; | |
383 | ||
384 | /* Delete all children now */ | |
385 | ||
386 | acpi_ns_delete_children (child_handle); | |
387 | ||
388 | child_handle = parent_handle; | |
389 | status = acpi_get_parent (parent_handle, &parent_handle); | |
390 | if (ACPI_FAILURE (status)) { | |
391 | return_ACPI_STATUS (status); | |
392 | } | |
393 | } | |
394 | } | |
395 | ||
396 | /* Now delete the starting object, and we are done */ | |
397 | ||
398 | acpi_ns_delete_node (child_handle); | |
399 | ||
400 | return_ACPI_STATUS (AE_OK); | |
401 | } | |
402 | ||
403 | ||
404 | /******************************************************************************* | |
405 | * | |
406 | * FUNCTION: acpi_ns_unload_name_space | |
407 | * | |
408 | * PARAMETERS: Handle - Root of namespace subtree to be deleted | |
409 | * | |
410 | * RETURN: Status | |
411 | * | |
412 | * DESCRIPTION: Shrinks the namespace, typically in response to an undocking | |
413 | * event. Deletes an entire subtree starting from (and | |
414 | * including) the given handle. | |
415 | * | |
416 | ******************************************************************************/ | |
417 | ||
418 | acpi_status | |
419 | acpi_ns_unload_namespace ( | |
420 | acpi_handle handle) | |
421 | { | |
422 | acpi_status status; | |
423 | ||
424 | ||
425 | ACPI_FUNCTION_TRACE ("ns_unload_name_space"); | |
426 | ||
427 | ||
428 | /* Parameter validation */ | |
429 | ||
430 | if (!acpi_gbl_root_node) { | |
431 | return_ACPI_STATUS (AE_NO_NAMESPACE); | |
432 | } | |
433 | ||
434 | if (!handle) { | |
435 | return_ACPI_STATUS (AE_BAD_PARAMETER); | |
436 | } | |
437 | ||
438 | /* This function does the real work */ | |
439 | ||
440 | status = acpi_ns_delete_subtree (handle); | |
441 | ||
442 | return_ACPI_STATUS (status); | |
443 | } | |
44f6c012 | 444 | #endif |
1da177e4 LT |
445 | #endif |
446 |