blob: 80acfd35f3ecb3cd31c225859edfca7c31a155a4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: nsload - namespace loading/expanding/contracting procedures
4 *
5 *****************************************************************************/
6
7/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acnamesp.h>
46#include <acpi/acdispat.h>
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("nsload")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Robert Moore44f6c012005-04-18 22:49:35 -040051/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040052static acpi_status acpi_ns_load_table_by_type(acpi_table_type table_type);
Robert Moore44f6c012005-04-18 22:49:35 -040053
54#ifdef ACPI_FUTURE_IMPLEMENTATION
Len Brown4be44fc2005-08-05 00:44:28 -040055acpi_status acpi_ns_unload_namespace(acpi_handle handle);
Robert Moore44f6c012005-04-18 22:49:35 -040056
Len Brown4be44fc2005-08-05 00:44:28 -040057static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
Robert Moore44f6c012005-04-18 22:49:35 -040058#endif
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#ifndef ACPI_NO_METHOD_EXECUTION
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/*******************************************************************************
62 *
63 * FUNCTION: acpi_ns_load_table
64 *
65 * PARAMETERS: table_desc - Descriptor for table to be loaded
66 * Node - Owning NS node
67 *
68 * RETURN: Status
69 *
70 * DESCRIPTION: Load one ACPI table into the namespace
71 *
72 ******************************************************************************/
73
74acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040075acpi_ns_load_table(struct acpi_table_desc *table_desc,
76 struct acpi_namespace_node *node)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
Len Brown4be44fc2005-08-05 00:44:28 -040078 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Len Brown4be44fc2005-08-05 00:44:28 -040080 ACPI_FUNCTION_TRACE("ns_load_table");
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 /* Check if table contains valid AML (must be DSDT, PSDT, SSDT, etc.) */
83
Len Brown4be44fc2005-08-05 00:44:28 -040084 if (!
85 (acpi_gbl_table_data[table_desc->type].
86 flags & ACPI_TABLE_EXECUTABLE)) {
Bob Moore52fc0b02006-10-02 00:00:00 -040087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 /* Just ignore this table */
89
Len Brown4be44fc2005-08-05 00:44:28 -040090 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 }
92
93 /* Check validity of the AML start and length */
94
95 if (!table_desc->aml_start) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050096 ACPI_ERROR((AE_INFO, "Null AML pointer"));
Len Brown4be44fc2005-08-05 00:44:28 -040097 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 }
99
Len Brown4be44fc2005-08-05 00:44:28 -0400100 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "AML block at %p\n",
101 table_desc->aml_start));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 /* Ignore table if there is no AML contained within */
104
105 if (!table_desc->aml_length) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500106 ACPI_WARNING((AE_INFO, "Zero-length AML block in table [%4.4s]",
107 table_desc->pointer->signature));
Len Brown4be44fc2005-08-05 00:44:28 -0400108 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 }
110
111 /*
112 * Parse the table and load the namespace with all named
113 * objects found within. Control methods are NOT parsed
114 * at this time. In fact, the control methods cannot be
115 * parsed until the entire namespace is loaded, because
116 * if a control method makes a forward reference (call)
117 * to another control method, we can't continue parsing
118 * because we don't know how many arguments to parse next!
119 */
Len Brown4be44fc2005-08-05 00:44:28 -0400120 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
121 "**** Loading table into namespace ****\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Len Brown4be44fc2005-08-05 00:44:28 -0400123 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
124 if (ACPI_FAILURE(status)) {
125 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 }
127
Len Brown4be44fc2005-08-05 00:44:28 -0400128 status = acpi_ns_parse_table(table_desc, node->child);
129 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Len Brown4be44fc2005-08-05 00:44:28 -0400131 if (ACPI_FAILURE(status)) {
132 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 }
134
135 /*
136 * Now we can parse the control methods. We always parse
137 * them here for a sanity check, and if configured for
138 * just-in-time parsing, we delete the control method
139 * parse trees.
140 */
Len Brown4be44fc2005-08-05 00:44:28 -0400141 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
142 "**** Begin Table Method Parsing and Object Initialization ****\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Len Brown4be44fc2005-08-05 00:44:28 -0400144 status = acpi_ds_initialize_objects(table_desc, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Len Brown4be44fc2005-08-05 00:44:28 -0400146 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
147 "**** Completed Table Method Parsing and Object Initialization ****\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Len Brown4be44fc2005-08-05 00:44:28 -0400149 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152/*******************************************************************************
153 *
154 * FUNCTION: acpi_ns_load_table_by_type
155 *
156 * PARAMETERS: table_type - Id of the table type to load
157 *
158 * RETURN: Status
159 *
160 * DESCRIPTION: Load an ACPI table or tables into the namespace. All tables
161 * of the given type are loaded. The mechanism allows this
162 * routine to be called repeatedly.
163 *
164 ******************************************************************************/
165
Len Brown4be44fc2005-08-05 00:44:28 -0400166static acpi_status acpi_ns_load_table_by_type(acpi_table_type table_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167{
Len Brown4be44fc2005-08-05 00:44:28 -0400168 u32 i;
169 acpi_status status;
170 struct acpi_table_desc *table_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Len Brown4be44fc2005-08-05 00:44:28 -0400172 ACPI_FUNCTION_TRACE("ns_load_table_by_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Len Brown4be44fc2005-08-05 00:44:28 -0400174 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
175 if (ACPI_FAILURE(status)) {
176 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
178
179 /*
180 * Table types supported are:
181 * DSDT (one), SSDT/PSDT (multiple)
182 */
183 switch (table_type) {
184 case ACPI_TABLE_DSDT:
185
Len Brown4be44fc2005-08-05 00:44:28 -0400186 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Namespace load: DSDT\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 table_desc = acpi_gbl_table_lists[ACPI_TABLE_DSDT].next;
189
190 /* If table already loaded into namespace, just return */
191
192 if (table_desc->loaded_into_namespace) {
193 goto unlock_and_exit;
194 }
195
196 /* Now load the single DSDT */
197
Len Brown4be44fc2005-08-05 00:44:28 -0400198 status = acpi_ns_load_table(table_desc, acpi_gbl_root_node);
199 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 table_desc->loaded_into_namespace = TRUE;
201 }
202 break;
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 case ACPI_TABLE_SSDT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 case ACPI_TABLE_PSDT:
206
Len Brown4be44fc2005-08-05 00:44:28 -0400207 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
208 "Namespace load: %d SSDT or PSDTs\n",
209 acpi_gbl_table_lists[table_type].count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 /*
Robert Moore0c9938c2005-07-29 15:15:00 -0700212 * Traverse list of SSDT or PSDT tables
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 */
Robert Moore0c9938c2005-07-29 15:15:00 -0700214 table_desc = acpi_gbl_table_lists[table_type].next;
215 for (i = 0; i < acpi_gbl_table_lists[table_type].count; i++) {
216 /*
217 * Only attempt to load table into namespace if it is not
218 * already loaded!
219 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 if (!table_desc->loaded_into_namespace) {
Len Brown4be44fc2005-08-05 00:44:28 -0400221 status =
222 acpi_ns_load_table(table_desc,
223 acpi_gbl_root_node);
224 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 break;
226 }
227
228 table_desc->loaded_into_namespace = TRUE;
229 }
230
231 table_desc = table_desc->next;
232 }
233 break;
234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 default:
236 status = AE_SUPPORT;
237 break;
238 }
239
Len Brown4be44fc2005-08-05 00:44:28 -0400240 unlock_and_exit:
241 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
242 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243}
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245/*******************************************************************************
246 *
247 * FUNCTION: acpi_load_namespace
248 *
249 * PARAMETERS: None
250 *
251 * RETURN: Status
252 *
253 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
254 * (DSDT points to either the BIOS or a buffer.)
255 *
256 ******************************************************************************/
257
Len Brown4be44fc2005-08-05 00:44:28 -0400258acpi_status acpi_ns_load_namespace(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
Len Brown4be44fc2005-08-05 00:44:28 -0400260 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Len Brown4be44fc2005-08-05 00:44:28 -0400262 ACPI_FUNCTION_TRACE("acpi_load_name_space");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 /* There must be at least a DSDT installed */
265
266 if (acpi_gbl_DSDT == NULL) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500267 ACPI_ERROR((AE_INFO, "DSDT is not in memory"));
Len Brown4be44fc2005-08-05 00:44:28 -0400268 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 }
270
271 /*
272 * Load the namespace. The DSDT is required,
273 * but the SSDT and PSDT tables are optional.
274 */
Len Brown4be44fc2005-08-05 00:44:28 -0400275 status = acpi_ns_load_table_by_type(ACPI_TABLE_DSDT);
276 if (ACPI_FAILURE(status)) {
277 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 }
279
280 /* Ignore exceptions from these */
281
Len Brown4be44fc2005-08-05 00:44:28 -0400282 (void)acpi_ns_load_table_by_type(ACPI_TABLE_SSDT);
283 (void)acpi_ns_load_table_by_type(ACPI_TABLE_PSDT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Len Brown4be44fc2005-08-05 00:44:28 -0400285 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
286 "ACPI Namespace successfully loaded at root %p\n",
287 acpi_gbl_root_node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Len Brown4be44fc2005-08-05 00:44:28 -0400289 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
Robert Moore44f6c012005-04-18 22:49:35 -0400292#ifdef ACPI_FUTURE_IMPLEMENTATION
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293/*******************************************************************************
294 *
295 * FUNCTION: acpi_ns_delete_subtree
296 *
297 * PARAMETERS: start_handle - Handle in namespace where search begins
298 *
299 * RETURNS Status
300 *
301 * DESCRIPTION: Walks the namespace starting at the given handle and deletes
302 * all objects, entries, and scopes in the entire subtree.
303 *
304 * Namespace/Interpreter should be locked or the subsystem should
305 * be in shutdown before this routine is called.
306 *
307 ******************************************************************************/
308
Len Brown4be44fc2005-08-05 00:44:28 -0400309static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Len Brown4be44fc2005-08-05 00:44:28 -0400311 acpi_status status;
312 acpi_handle child_handle;
313 acpi_handle parent_handle;
314 acpi_handle next_child_handle;
315 acpi_handle dummy;
316 u32 level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Len Brown4be44fc2005-08-05 00:44:28 -0400318 ACPI_FUNCTION_TRACE("ns_delete_subtree");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 parent_handle = start_handle;
321 child_handle = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400322 level = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 /*
325 * Traverse the tree of objects until we bubble back up
326 * to where we started.
327 */
328 while (level > 0) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 /* Attempt to get the next object in this scope */
331
Len Brown4be44fc2005-08-05 00:44:28 -0400332 status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle,
333 child_handle, &next_child_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335 child_handle = next_child_handle;
336
337 /* Did we get a new object? */
338
Len Brown4be44fc2005-08-05 00:44:28 -0400339 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 /* Check if this object has any children */
342
Len Brown4be44fc2005-08-05 00:44:28 -0400343 if (ACPI_SUCCESS
344 (acpi_get_next_object
345 (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 /*
347 * There is at least one child of this object,
348 * visit the object
349 */
350 level++;
351 parent_handle = child_handle;
352 child_handle = NULL;
353 }
Len Brown4be44fc2005-08-05 00:44:28 -0400354 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 /*
356 * No more children in this object, go back up to
357 * the object's parent
358 */
359 level--;
360
361 /* Delete all children now */
362
Len Brown4be44fc2005-08-05 00:44:28 -0400363 acpi_ns_delete_children(child_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
365 child_handle = parent_handle;
Len Brown4be44fc2005-08-05 00:44:28 -0400366 status = acpi_get_parent(parent_handle, &parent_handle);
367 if (ACPI_FAILURE(status)) {
368 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 }
370 }
371 }
372
373 /* Now delete the starting object, and we are done */
374
Len Brown4be44fc2005-08-05 00:44:28 -0400375 acpi_ns_delete_node(child_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Len Brown4be44fc2005-08-05 00:44:28 -0400377 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380/*******************************************************************************
381 *
382 * FUNCTION: acpi_ns_unload_name_space
383 *
384 * PARAMETERS: Handle - Root of namespace subtree to be deleted
385 *
386 * RETURN: Status
387 *
388 * DESCRIPTION: Shrinks the namespace, typically in response to an undocking
389 * event. Deletes an entire subtree starting from (and
390 * including) the given handle.
391 *
392 ******************************************************************************/
393
Len Brown4be44fc2005-08-05 00:44:28 -0400394acpi_status acpi_ns_unload_namespace(acpi_handle handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Len Brown4be44fc2005-08-05 00:44:28 -0400396 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Len Brown4be44fc2005-08-05 00:44:28 -0400398 ACPI_FUNCTION_TRACE("ns_unload_name_space");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 /* Parameter validation */
401
402 if (!acpi_gbl_root_node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400403 return_ACPI_STATUS(AE_NO_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
405
406 if (!handle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400407 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 }
409
410 /* This function does the real work */
411
Len Brown4be44fc2005-08-05 00:44:28 -0400412 status = acpi_ns_delete_subtree(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Len Brown4be44fc2005-08-05 00:44:28 -0400414 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
Robert Moore44f6c012005-04-18 22:49:35 -0400416#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#endif