1 /******************************************************************************
3 * Module Name: nsload - namespace loading/expanding/contracting procedures
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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")
53 /* Local prototypes */
56 acpi_ns_load_table_by_type (
57 acpi_table_type table_type);
59 #ifdef ACPI_FUTURE_IMPLEMENTATION
61 acpi_ns_unload_namespace (
65 acpi_ns_delete_subtree (
66 acpi_handle start_handle);
70 #ifndef ACPI_NO_METHOD_EXECUTION
71 /*******************************************************************************
73 * FUNCTION: acpi_ns_load_table
75 * PARAMETERS: table_desc - Descriptor for table to be loaded
76 * Node - Owning NS node
80 * DESCRIPTION: Load one ACPI table into the namespace
82 ******************************************************************************/
86 struct acpi_table_desc *table_desc,
87 struct acpi_namespace_node *node)
92 ACPI_FUNCTION_TRACE ("ns_load_table");
95 /* Check if table contains valid AML (must be DSDT, PSDT, SSDT, etc.) */
97 if (!(acpi_gbl_table_data[table_desc->type].flags & ACPI_TABLE_EXECUTABLE)) {
98 /* Just ignore this table */
100 return_ACPI_STATUS (AE_OK);
103 /* Check validity of the AML start and length */
105 if (!table_desc->aml_start) {
106 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null AML pointer\n"));
107 return_ACPI_STATUS (AE_BAD_PARAMETER);
110 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AML block at %p\n",
111 table_desc->aml_start));
113 /* Ignore table if there is no AML contained within */
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);
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!
130 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
131 "**** Loading table into namespace ****\n"));
133 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
134 if (ACPI_FAILURE (status)) {
135 return_ACPI_STATUS (status);
138 status = acpi_ns_parse_table (table_desc, node->child);
139 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
141 if (ACPI_FAILURE (status)) {
142 return_ACPI_STATUS (status);
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
151 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
152 "**** Begin Table Method Parsing and Object Initialization ****\n"));
154 status = acpi_ds_initialize_objects (table_desc, node);
156 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
157 "**** Completed Table Method Parsing and Object Initialization ****\n"));
159 return_ACPI_STATUS (status);
163 /*******************************************************************************
165 * FUNCTION: acpi_ns_load_table_by_type
167 * PARAMETERS: table_type - Id of the table type to load
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.
175 ******************************************************************************/
178 acpi_ns_load_table_by_type (
179 acpi_table_type table_type)
183 struct acpi_table_desc *table_desc;
186 ACPI_FUNCTION_TRACE ("ns_load_table_by_type");
189 status = acpi_ut_acquire_mutex (ACPI_MTX_TABLES);
190 if (ACPI_FAILURE (status)) {
191 return_ACPI_STATUS (status);
195 * Table types supported are:
196 * DSDT (one), SSDT/PSDT (multiple)
198 switch (table_type) {
199 case ACPI_TABLE_DSDT:
201 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading DSDT\n"));
203 table_desc = acpi_gbl_table_lists[ACPI_TABLE_DSDT].next;
205 /* If table already loaded into namespace, just return */
207 if (table_desc->loaded_into_namespace) {
208 goto unlock_and_exit;
211 /* Now load the single DSDT */
213 status = acpi_ns_load_table (table_desc, acpi_gbl_root_node);
214 if (ACPI_SUCCESS (status)) {
215 table_desc->loaded_into_namespace = TRUE;
220 case ACPI_TABLE_SSDT:
222 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading %d SSDTs\n",
223 acpi_gbl_table_lists[ACPI_TABLE_SSDT].count));
226 * Traverse list of SSDT tables
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++) {
231 * Only attempt to load table if it is not
234 if (!table_desc->loaded_into_namespace) {
235 status = acpi_ns_load_table (table_desc, acpi_gbl_root_node);
236 if (ACPI_FAILURE (status)) {
240 table_desc->loaded_into_namespace = TRUE;
243 table_desc = table_desc->next;
248 case ACPI_TABLE_PSDT:
250 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading %d PSDTs\n",
251 acpi_gbl_table_lists[ACPI_TABLE_PSDT].count));
254 * Traverse list of PSDT tables
256 table_desc = acpi_gbl_table_lists[ACPI_TABLE_PSDT].next;
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! */
261 if (!table_desc->loaded_into_namespace) {
262 status = acpi_ns_load_table (table_desc, acpi_gbl_root_node);
263 if (ACPI_FAILURE (status)) {
267 table_desc->loaded_into_namespace = TRUE;
270 table_desc = table_desc->next;
282 (void) acpi_ut_release_mutex (ACPI_MTX_TABLES);
283 return_ACPI_STATUS (status);
287 /*******************************************************************************
289 * FUNCTION: acpi_load_namespace
295 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
296 * (DSDT points to either the BIOS or a buffer.)
298 ******************************************************************************/
301 acpi_ns_load_namespace (
307 ACPI_FUNCTION_TRACE ("acpi_load_name_space");
310 /* There must be at least a DSDT installed */
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);
318 * Load the namespace. The DSDT is required,
319 * but the SSDT and PSDT tables are optional.
321 status = acpi_ns_load_table_by_type (ACPI_TABLE_DSDT);
322 if (ACPI_FAILURE (status)) {
323 return_ACPI_STATUS (status);
326 /* Ignore exceptions from these */
328 (void) acpi_ns_load_table_by_type (ACPI_TABLE_SSDT);
329 (void) acpi_ns_load_table_by_type (ACPI_TABLE_PSDT);
331 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
332 "ACPI Namespace successfully loaded at root %p\n",
333 acpi_gbl_root_node));
335 return_ACPI_STATUS (status);
339 #ifdef ACPI_FUTURE_IMPLEMENTATION
340 /*******************************************************************************
342 * FUNCTION: acpi_ns_delete_subtree
344 * PARAMETERS: start_handle - Handle in namespace where search begins
348 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
349 * all objects, entries, and scopes in the entire subtree.
351 * Namespace/Interpreter should be locked or the subsystem should
352 * be in shutdown before this routine is called.
354 ******************************************************************************/
357 acpi_ns_delete_subtree (
358 acpi_handle start_handle)
361 acpi_handle child_handle;
362 acpi_handle parent_handle;
363 acpi_handle next_child_handle;
368 ACPI_FUNCTION_TRACE ("ns_delete_subtree");
371 parent_handle = start_handle;
376 * Traverse the tree of objects until we bubble back up
377 * to where we started.
380 /* Attempt to get the next object in this scope */
382 status = acpi_get_next_object (ACPI_TYPE_ANY, parent_handle,
383 child_handle, &next_child_handle);
385 child_handle = next_child_handle;
387 /* Did we get a new object? */
389 if (ACPI_SUCCESS (status)) {
390 /* Check if this object has any children */
392 if (ACPI_SUCCESS (acpi_get_next_object (ACPI_TYPE_ANY, child_handle,
395 * There is at least one child of this object,
399 parent_handle = child_handle;
405 * No more children in this object, go back up to
406 * the object's parent
410 /* Delete all children now */
412 acpi_ns_delete_children (child_handle);
414 child_handle = parent_handle;
415 status = acpi_get_parent (parent_handle, &parent_handle);
416 if (ACPI_FAILURE (status)) {
417 return_ACPI_STATUS (status);
422 /* Now delete the starting object, and we are done */
424 acpi_ns_delete_node (child_handle);
426 return_ACPI_STATUS (AE_OK);
430 /*******************************************************************************
432 * FUNCTION: acpi_ns_unload_name_space
434 * PARAMETERS: Handle - Root of namespace subtree to be deleted
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.
442 ******************************************************************************/
445 acpi_ns_unload_namespace (
451 ACPI_FUNCTION_TRACE ("ns_unload_name_space");
454 /* Parameter validation */
456 if (!acpi_gbl_root_node) {
457 return_ACPI_STATUS (AE_NO_NAMESPACE);
461 return_ACPI_STATUS (AE_BAD_PARAMETER);
464 /* This function does the real work */
466 status = acpi_ns_delete_subtree (handle);
468 return_ACPI_STATUS (status);