initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / acpi / namespace / nsload.c
blob314ec6659a72a38a5d0cd5085a9fdd48f7c0b2d4
1 /******************************************************************************
3 * Module Name: nsload - namespace loading/expanding/contracting procedures
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2004, R. Byron Moore
9 * All rights reserved.
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.
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acnamesp.h>
47 #include <acpi/acdispat.h>
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsload")
54 #ifndef ACPI_NO_METHOD_EXECUTION
56 /*******************************************************************************
58 * FUNCTION: acpi_ns_load_table
60 * PARAMETERS: table_desc - Descriptor for table to be loaded
61 * Node - Owning NS node
63 * RETURN: Status
65 * DESCRIPTION: Load one ACPI table into the namespace
67 ******************************************************************************/
69 acpi_status
70 acpi_ns_load_table (
71 struct acpi_table_desc *table_desc,
72 struct acpi_namespace_node *node)
74 acpi_status status;
77 ACPI_FUNCTION_TRACE ("ns_load_table");
80 /* Check if table contains valid AML (must be DSDT, PSDT, SSDT, etc.) */
82 if (!(acpi_gbl_table_data[table_desc->type].flags & ACPI_TABLE_EXECUTABLE)) {
83 /* Just ignore this table */
85 return_ACPI_STATUS (AE_OK);
88 /* Check validity of the AML start and length */
90 if (!table_desc->aml_start) {
91 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null AML pointer\n"));
92 return_ACPI_STATUS (AE_BAD_PARAMETER);
95 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AML block at %p\n", table_desc->aml_start));
97 /* Ignore table if there is no AML contained within */
99 if (!table_desc->aml_length) {
100 ACPI_REPORT_WARNING (("Zero-length AML block in table [%4.4s]\n", table_desc->pointer->signature));
101 return_ACPI_STATUS (AE_OK);
105 * Parse the table and load the namespace with all named
106 * objects found within. Control methods are NOT parsed
107 * at this time. In fact, the control methods cannot be
108 * parsed until the entire namespace is loaded, because
109 * if a control method makes a forward reference (call)
110 * to another control method, we can't continue parsing
111 * because we don't know how many arguments to parse next!
113 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "**** Loading table into namespace ****\n"));
115 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
116 if (ACPI_FAILURE (status)) {
117 return_ACPI_STATUS (status);
120 status = acpi_ns_parse_table (table_desc, node->child);
121 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
123 if (ACPI_FAILURE (status)) {
124 return_ACPI_STATUS (status);
128 * Now we can parse the control methods. We always parse
129 * them here for a sanity check, and if configured for
130 * just-in-time parsing, we delete the control method
131 * parse trees.
133 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
134 "**** Begin Table Method Parsing and Object Initialization ****\n"));
136 status = acpi_ds_initialize_objects (table_desc, node);
138 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
139 "**** Completed Table Method Parsing and Object Initialization ****\n"));
141 return_ACPI_STATUS (status);
145 /*******************************************************************************
147 * FUNCTION: acpi_ns_load_table_by_type
149 * PARAMETERS: table_type - Id of the table type to load
151 * RETURN: Status
153 * DESCRIPTION: Load an ACPI table or tables into the namespace. All tables
154 * of the given type are loaded. The mechanism allows this
155 * routine to be called repeatedly.
157 ******************************************************************************/
159 acpi_status
160 acpi_ns_load_table_by_type (
161 acpi_table_type table_type)
163 u32 i;
164 acpi_status status;
165 struct acpi_table_desc *table_desc;
168 ACPI_FUNCTION_TRACE ("ns_load_table_by_type");
171 status = acpi_ut_acquire_mutex (ACPI_MTX_TABLES);
172 if (ACPI_FAILURE (status)) {
173 return_ACPI_STATUS (status);
177 * Table types supported are:
178 * DSDT (one), SSDT/PSDT (multiple)
180 switch (table_type) {
181 case ACPI_TABLE_DSDT:
183 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading DSDT\n"));
185 table_desc = acpi_gbl_table_lists[ACPI_TABLE_DSDT].next;
187 /* If table already loaded into namespace, just return */
189 if (table_desc->loaded_into_namespace) {
190 goto unlock_and_exit;
193 /* Now load the single DSDT */
195 status = acpi_ns_load_table (table_desc, acpi_gbl_root_node);
196 if (ACPI_SUCCESS (status)) {
197 table_desc->loaded_into_namespace = TRUE;
200 break;
203 case ACPI_TABLE_SSDT:
205 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading %d SSDTs\n",
206 acpi_gbl_table_lists[ACPI_TABLE_SSDT].count));
209 * Traverse list of SSDT tables
211 table_desc = acpi_gbl_table_lists[ACPI_TABLE_SSDT].next;
212 for (i = 0; i < acpi_gbl_table_lists[ACPI_TABLE_SSDT].count; i++) {
214 * Only attempt to load table if it is not
215 * already loaded!
217 if (!table_desc->loaded_into_namespace) {
218 status = acpi_ns_load_table (table_desc, acpi_gbl_root_node);
219 if (ACPI_FAILURE (status)) {
220 break;
223 table_desc->loaded_into_namespace = TRUE;
226 table_desc = table_desc->next;
228 break;
231 case ACPI_TABLE_PSDT:
233 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading %d PSDTs\n",
234 acpi_gbl_table_lists[ACPI_TABLE_PSDT].count));
237 * Traverse list of PSDT tables
239 table_desc = acpi_gbl_table_lists[ACPI_TABLE_PSDT].next;
241 for (i = 0; i < acpi_gbl_table_lists[ACPI_TABLE_PSDT].count; i++) {
242 /* Only attempt to load table if it is not already loaded! */
244 if (!table_desc->loaded_into_namespace) {
245 status = acpi_ns_load_table (table_desc, acpi_gbl_root_node);
246 if (ACPI_FAILURE (status)) {
247 break;
250 table_desc->loaded_into_namespace = TRUE;
253 table_desc = table_desc->next;
256 break;
259 default:
260 status = AE_SUPPORT;
261 break;
265 unlock_and_exit:
266 (void) acpi_ut_release_mutex (ACPI_MTX_TABLES);
267 return_ACPI_STATUS (status);
271 /*******************************************************************************
273 * FUNCTION: acpi_load_namespace
275 * PARAMETERS: None
277 * RETURN: Status
279 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
280 * (DSDT points to either the BIOS or a buffer.)
282 ******************************************************************************/
284 acpi_status
285 acpi_ns_load_namespace (
286 void)
288 acpi_status status;
291 ACPI_FUNCTION_TRACE ("acpi_load_name_space");
294 /* There must be at least a DSDT installed */
296 if (acpi_gbl_DSDT == NULL) {
297 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "DSDT is not in memory\n"));
298 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
302 * Load the namespace. The DSDT is required,
303 * but the SSDT and PSDT tables are optional.
305 status = acpi_ns_load_table_by_type (ACPI_TABLE_DSDT);
306 if (ACPI_FAILURE (status)) {
307 return_ACPI_STATUS (status);
310 /* Ignore exceptions from these */
312 (void) acpi_ns_load_table_by_type (ACPI_TABLE_SSDT);
313 (void) acpi_ns_load_table_by_type (ACPI_TABLE_PSDT);
315 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
316 "ACPI Namespace successfully loaded at root %p\n",
317 acpi_gbl_root_node));
319 return_ACPI_STATUS (status);
323 /*******************************************************************************
325 * FUNCTION: acpi_ns_delete_subtree
327 * PARAMETERS: start_handle - Handle in namespace where search begins
329 * RETURNS Status
331 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
332 * all objects, entries, and scopes in the entire subtree.
334 * Namespace/Interpreter should be locked or the subsystem should
335 * be in shutdown before this routine is called.
337 ******************************************************************************/
339 acpi_status
340 acpi_ns_delete_subtree (
341 acpi_handle start_handle)
343 acpi_status status;
344 acpi_handle child_handle;
345 acpi_handle parent_handle;
346 acpi_handle next_child_handle;
347 acpi_handle dummy;
348 u32 level;
351 ACPI_FUNCTION_TRACE ("ns_delete_subtree");
354 parent_handle = start_handle;
355 child_handle = NULL;
356 level = 1;
359 * Traverse the tree of objects until we bubble back up
360 * to where we started.
362 while (level > 0) {
363 /* Attempt to get the next object in this scope */
365 status = acpi_get_next_object (ACPI_TYPE_ANY, parent_handle,
366 child_handle, &next_child_handle);
368 child_handle = next_child_handle;
370 /* Did we get a new object? */
372 if (ACPI_SUCCESS (status)) {
373 /* Check if this object has any children */
375 if (ACPI_SUCCESS (acpi_get_next_object (ACPI_TYPE_ANY, child_handle,
376 NULL, &dummy))) {
378 * There is at least one child of this object,
379 * visit the object
381 level++;
382 parent_handle = child_handle;
383 child_handle = NULL;
386 else {
388 * No more children in this object, go back up to
389 * the object's parent
391 level--;
393 /* Delete all children now */
395 acpi_ns_delete_children (child_handle);
397 child_handle = parent_handle;
398 status = acpi_get_parent (parent_handle, &parent_handle);
399 if (ACPI_FAILURE (status)) {
400 return_ACPI_STATUS (status);
405 /* Now delete the starting object, and we are done */
407 acpi_ns_delete_node (child_handle);
409 return_ACPI_STATUS (AE_OK);
413 /*******************************************************************************
415 * FUNCTION: acpi_ns_unload_name_space
417 * PARAMETERS: Handle - Root of namespace subtree to be deleted
419 * RETURN: Status
421 * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
422 * event. Deletes an entire subtree starting from (and
423 * including) the given handle.
425 ******************************************************************************/
427 acpi_status
428 acpi_ns_unload_namespace (
429 acpi_handle handle)
431 acpi_status status;
434 ACPI_FUNCTION_TRACE ("ns_unload_name_space");
437 /* Parameter validation */
439 if (!acpi_gbl_root_node) {
440 return_ACPI_STATUS (AE_NO_NAMESPACE);
443 if (!handle) {
444 return_ACPI_STATUS (AE_BAD_PARAMETER);
447 /* This function does the real work */
449 status = acpi_ns_delete_subtree (handle);
451 return_ACPI_STATUS (status);
454 #endif