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 | ||
201 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading DSDT\n")); | |
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: | |
221 | ||
222 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading %d SSDTs\n", | |
223 | acpi_gbl_table_lists[ACPI_TABLE_SSDT].count)); | |
224 | ||
225 | /* | |
226 | * Traverse list of SSDT tables | |
227 | */ | |
228 | table_desc = acpi_gbl_table_lists[ACPI_TABLE_SSDT].next; | |
229 | for (i = 0; i < acpi_gbl_table_lists[ACPI_TABLE_SSDT].count; i++) { | |
230 | /* | |
231 | * Only attempt to load table if it is not | |
232 | * already loaded! | |
233 | */ | |
234 | if (!table_desc->loaded_into_namespace) { | |
235 | status = acpi_ns_load_table (table_desc, acpi_gbl_root_node); | |
236 | if (ACPI_FAILURE (status)) { | |
237 | break; | |
238 | } | |
239 | ||
240 | table_desc->loaded_into_namespace = TRUE; | |
241 | } | |
242 | ||
243 | table_desc = table_desc->next; | |
244 | } | |
245 | break; | |
246 | ||
247 | ||
248 | case ACPI_TABLE_PSDT: | |
249 | ||
250 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading %d PSDTs\n", | |
251 | acpi_gbl_table_lists[ACPI_TABLE_PSDT].count)); | |
252 | ||
253 | /* | |
254 | * Traverse list of PSDT tables | |
255 | */ | |
256 | table_desc = acpi_gbl_table_lists[ACPI_TABLE_PSDT].next; | |
257 | ||
258 | for (i = 0; i < acpi_gbl_table_lists[ACPI_TABLE_PSDT].count; i++) { | |
259 | /* Only attempt to load table if it is not already loaded! */ | |
260 | ||
261 | if (!table_desc->loaded_into_namespace) { | |
262 | status = acpi_ns_load_table (table_desc, acpi_gbl_root_node); | |
263 | if (ACPI_FAILURE (status)) { | |
264 | break; | |
265 | } | |
266 | ||
267 | table_desc->loaded_into_namespace = TRUE; | |
268 | } | |
269 | ||
270 | table_desc = table_desc->next; | |
271 | } | |
272 | break; | |
273 | ||
274 | ||
275 | default: | |
276 | status = AE_SUPPORT; | |
277 | break; | |
278 | } | |
279 | ||
280 | ||
281 | unlock_and_exit: | |
282 | (void) acpi_ut_release_mutex (ACPI_MTX_TABLES); | |
283 | return_ACPI_STATUS (status); | |
284 | } | |
285 | ||
286 | ||
287 | /******************************************************************************* | |
288 | * | |
289 | * FUNCTION: acpi_load_namespace | |
290 | * | |
291 | * PARAMETERS: None | |
292 | * | |
293 | * RETURN: Status | |
294 | * | |
295 | * DESCRIPTION: Load the name space from what ever is pointed to by DSDT. | |
296 | * (DSDT points to either the BIOS or a buffer.) | |
297 | * | |
298 | ******************************************************************************/ | |
299 | ||
300 | acpi_status | |
301 | acpi_ns_load_namespace ( | |
302 | void) | |
303 | { | |
304 | acpi_status status; | |
305 | ||
306 | ||
307 | ACPI_FUNCTION_TRACE ("acpi_load_name_space"); | |
308 | ||
309 | ||
310 | /* There must be at least a DSDT installed */ | |
311 | ||
312 | if (acpi_gbl_DSDT == NULL) { | |
313 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "DSDT is not in memory\n")); | |
314 | return_ACPI_STATUS (AE_NO_ACPI_TABLES); | |
315 | } | |
316 | ||
317 | /* | |
318 | * Load the namespace. The DSDT is required, | |
319 | * but the SSDT and PSDT tables are optional. | |
320 | */ | |
321 | status = acpi_ns_load_table_by_type (ACPI_TABLE_DSDT); | |
322 | if (ACPI_FAILURE (status)) { | |
323 | return_ACPI_STATUS (status); | |
324 | } | |
325 | ||
326 | /* Ignore exceptions from these */ | |
327 | ||
328 | (void) acpi_ns_load_table_by_type (ACPI_TABLE_SSDT); | |
329 | (void) acpi_ns_load_table_by_type (ACPI_TABLE_PSDT); | |
330 | ||
331 | ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, | |
332 | "ACPI Namespace successfully loaded at root %p\n", | |
333 | acpi_gbl_root_node)); | |
334 | ||
335 | return_ACPI_STATUS (status); | |
336 | } | |
337 | ||
338 | ||
44f6c012 | 339 | #ifdef ACPI_FUTURE_IMPLEMENTATION |
1da177e4 LT |
340 | /******************************************************************************* |
341 | * | |
342 | * FUNCTION: acpi_ns_delete_subtree | |
343 | * | |
344 | * PARAMETERS: start_handle - Handle in namespace where search begins | |
345 | * | |
346 | * RETURNS Status | |
347 | * | |
348 | * DESCRIPTION: Walks the namespace starting at the given handle and deletes | |
349 | * all objects, entries, and scopes in the entire subtree. | |
350 | * | |
351 | * Namespace/Interpreter should be locked or the subsystem should | |
352 | * be in shutdown before this routine is called. | |
353 | * | |
354 | ******************************************************************************/ | |
355 | ||
44f6c012 | 356 | static acpi_status |
1da177e4 LT |
357 | acpi_ns_delete_subtree ( |
358 | acpi_handle start_handle) | |
359 | { | |
360 | acpi_status status; | |
361 | acpi_handle child_handle; | |
362 | acpi_handle parent_handle; | |
363 | acpi_handle next_child_handle; | |
364 | acpi_handle dummy; | |
365 | u32 level; | |
366 | ||
367 | ||
368 | ACPI_FUNCTION_TRACE ("ns_delete_subtree"); | |
369 | ||
370 | ||
371 | parent_handle = start_handle; | |
372 | child_handle = NULL; | |
373 | level = 1; | |
374 | ||
375 | /* | |
376 | * Traverse the tree of objects until we bubble back up | |
377 | * to where we started. | |
378 | */ | |
379 | while (level > 0) { | |
380 | /* Attempt to get the next object in this scope */ | |
381 | ||
382 | status = acpi_get_next_object (ACPI_TYPE_ANY, parent_handle, | |
383 | child_handle, &next_child_handle); | |
384 | ||
385 | child_handle = next_child_handle; | |
386 | ||
387 | /* Did we get a new object? */ | |
388 | ||
389 | if (ACPI_SUCCESS (status)) { | |
390 | /* Check if this object has any children */ | |
391 | ||
392 | if (ACPI_SUCCESS (acpi_get_next_object (ACPI_TYPE_ANY, child_handle, | |
393 | NULL, &dummy))) { | |
394 | /* | |
395 | * There is at least one child of this object, | |
396 | * visit the object | |
397 | */ | |
398 | level++; | |
399 | parent_handle = child_handle; | |
400 | child_handle = NULL; | |
401 | } | |
402 | } | |
403 | else { | |
404 | /* | |
405 | * No more children in this object, go back up to | |
406 | * the object's parent | |
407 | */ | |
408 | level--; | |
409 | ||
410 | /* Delete all children now */ | |
411 | ||
412 | acpi_ns_delete_children (child_handle); | |
413 | ||
414 | child_handle = parent_handle; | |
415 | status = acpi_get_parent (parent_handle, &parent_handle); | |
416 | if (ACPI_FAILURE (status)) { | |
417 | return_ACPI_STATUS (status); | |
418 | } | |
419 | } | |
420 | } | |
421 | ||
422 | /* Now delete the starting object, and we are done */ | |
423 | ||
424 | acpi_ns_delete_node (child_handle); | |
425 | ||
426 | return_ACPI_STATUS (AE_OK); | |
427 | } | |
428 | ||
429 | ||
430 | /******************************************************************************* | |
431 | * | |
432 | * FUNCTION: acpi_ns_unload_name_space | |
433 | * | |
434 | * PARAMETERS: Handle - Root of namespace subtree to be deleted | |
435 | * | |
436 | * RETURN: Status | |
437 | * | |
438 | * DESCRIPTION: Shrinks the namespace, typically in response to an undocking | |
439 | * event. Deletes an entire subtree starting from (and | |
440 | * including) the given handle. | |
441 | * | |
442 | ******************************************************************************/ | |
443 | ||
444 | acpi_status | |
445 | acpi_ns_unload_namespace ( | |
446 | acpi_handle handle) | |
447 | { | |
448 | acpi_status status; | |
449 | ||
450 | ||
451 | ACPI_FUNCTION_TRACE ("ns_unload_name_space"); | |
452 | ||
453 | ||
454 | /* Parameter validation */ | |
455 | ||
456 | if (!acpi_gbl_root_node) { | |
457 | return_ACPI_STATUS (AE_NO_NAMESPACE); | |
458 | } | |
459 | ||
460 | if (!handle) { | |
461 | return_ACPI_STATUS (AE_BAD_PARAMETER); | |
462 | } | |
463 | ||
464 | /* This function does the real work */ | |
465 | ||
466 | status = acpi_ns_delete_subtree (handle); | |
467 | ||
468 | return_ACPI_STATUS (status); | |
469 | } | |
44f6c012 | 470 | #endif |
1da177e4 LT |
471 | #endif |
472 |