Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: nsload - namespace loading/expanding/contracting procedures | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
75a44ce0 | 8 | * Copyright (C) 2000 - 2008, Intel Corp. |
1da177e4 LT |
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 | ||
1da177e4 | 44 | #include <acpi/acpi.h> |
e2f7a777 LB |
45 | #include "accommon.h" |
46 | #include "acnamesp.h" | |
47 | #include "acdispat.h" | |
48 | #include "actables.h" | |
1da177e4 | 49 | |
1da177e4 | 50 | #define _COMPONENT ACPI_NAMESPACE |
4be44fcd | 51 | ACPI_MODULE_NAME("nsload") |
1da177e4 | 52 | |
44f6c012 | 53 | /* Local prototypes */ |
44f6c012 | 54 | #ifdef ACPI_FUTURE_IMPLEMENTATION |
4be44fcd | 55 | acpi_status acpi_ns_unload_namespace(acpi_handle handle); |
44f6c012 | 56 | |
4be44fcd | 57 | static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle); |
44f6c012 | 58 | #endif |
1da177e4 | 59 | |
44f6c012 | 60 | #ifndef ACPI_NO_METHOD_EXECUTION |
1da177e4 LT |
61 | /******************************************************************************* |
62 | * | |
63 | * FUNCTION: acpi_ns_load_table | |
64 | * | |
f3d2e786 | 65 | * PARAMETERS: table_index - Index for table to be loaded |
1da177e4 LT |
66 | * Node - Owning NS node |
67 | * | |
68 | * RETURN: Status | |
69 | * | |
70 | * DESCRIPTION: Load one ACPI table into the namespace | |
71 | * | |
72 | ******************************************************************************/ | |
73 | ||
74 | acpi_status | |
67a119f9 | 75 | acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node) |
1da177e4 | 76 | { |
4be44fcd | 77 | acpi_status status; |
1da177e4 | 78 | |
b229cf92 | 79 | ACPI_FUNCTION_TRACE(ns_load_table); |
1da177e4 | 80 | |
1da177e4 LT |
81 | /* |
82 | * Parse the table and load the namespace with all named | |
83 | * objects found within. Control methods are NOT parsed | |
84 | * at this time. In fact, the control methods cannot be | |
85 | * parsed until the entire namespace is loaded, because | |
86 | * if a control method makes a forward reference (call) | |
87 | * to another control method, we can't continue parsing | |
88 | * because we don't know how many arguments to parse next! | |
89 | */ | |
f3d2e786 BM |
90 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
91 | if (ACPI_FAILURE(status)) { | |
92 | return_ACPI_STATUS(status); | |
93 | } | |
94 | ||
95 | /* If table already loaded into namespace, just return */ | |
96 | ||
97 | if (acpi_tb_is_table_loaded(table_index)) { | |
98 | status = AE_ALREADY_EXISTS; | |
99 | goto unlock; | |
100 | } | |
101 | ||
4be44fcd LB |
102 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
103 | "**** Loading table into namespace ****\n")); | |
1da177e4 | 104 | |
f3d2e786 | 105 | status = acpi_tb_allocate_owner_id(table_index); |
4be44fcd | 106 | if (ACPI_FAILURE(status)) { |
f3d2e786 | 107 | goto unlock; |
1da177e4 LT |
108 | } |
109 | ||
7f4ac9f9 | 110 | status = acpi_ns_parse_table(table_index, node); |
f3d2e786 BM |
111 | if (ACPI_SUCCESS(status)) { |
112 | acpi_tb_set_table_loaded_flag(table_index, TRUE); | |
113 | } else { | |
1d18c058 | 114 | (void)acpi_tb_release_owner_id(table_index); |
f3d2e786 BM |
115 | } |
116 | ||
117 | unlock: | |
4be44fcd | 118 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
1da177e4 | 119 | |
4be44fcd LB |
120 | if (ACPI_FAILURE(status)) { |
121 | return_ACPI_STATUS(status); | |
1da177e4 LT |
122 | } |
123 | ||
124 | /* | |
125 | * Now we can parse the control methods. We always parse | |
126 | * them here for a sanity check, and if configured for | |
127 | * just-in-time parsing, we delete the control method | |
128 | * parse trees. | |
129 | */ | |
4be44fcd LB |
130 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
131 | "**** Begin Table Method Parsing and Object Initialization ****\n")); | |
1da177e4 | 132 | |
f3d2e786 | 133 | status = acpi_ds_initialize_objects(table_index, node); |
1da177e4 | 134 | |
4be44fcd LB |
135 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
136 | "**** Completed Table Method Parsing and Object Initialization ****\n")); | |
1da177e4 | 137 | |
4be44fcd | 138 | return_ACPI_STATUS(status); |
1da177e4 LT |
139 | } |
140 | ||
f3d2e786 | 141 | #ifdef ACPI_OBSOLETE_FUNCTIONS |
1da177e4 LT |
142 | /******************************************************************************* |
143 | * | |
144 | * FUNCTION: acpi_load_namespace | |
145 | * | |
146 | * PARAMETERS: None | |
147 | * | |
148 | * RETURN: Status | |
149 | * | |
150 | * DESCRIPTION: Load the name space from what ever is pointed to by DSDT. | |
151 | * (DSDT points to either the BIOS or a buffer.) | |
152 | * | |
153 | ******************************************************************************/ | |
154 | ||
4be44fcd | 155 | acpi_status acpi_ns_load_namespace(void) |
1da177e4 | 156 | { |
4be44fcd | 157 | acpi_status status; |
1da177e4 | 158 | |
b229cf92 | 159 | ACPI_FUNCTION_TRACE(acpi_load_name_space); |
1da177e4 LT |
160 | |
161 | /* There must be at least a DSDT installed */ | |
162 | ||
163 | if (acpi_gbl_DSDT == NULL) { | |
b8e4d893 | 164 | ACPI_ERROR((AE_INFO, "DSDT is not in memory")); |
4be44fcd | 165 | return_ACPI_STATUS(AE_NO_ACPI_TABLES); |
1da177e4 LT |
166 | } |
167 | ||
168 | /* | |
169 | * Load the namespace. The DSDT is required, | |
170 | * but the SSDT and PSDT tables are optional. | |
171 | */ | |
b229cf92 | 172 | status = acpi_ns_load_table_by_type(ACPI_TABLE_ID_DSDT); |
4be44fcd LB |
173 | if (ACPI_FAILURE(status)) { |
174 | return_ACPI_STATUS(status); | |
1da177e4 LT |
175 | } |
176 | ||
177 | /* Ignore exceptions from these */ | |
178 | ||
b229cf92 BM |
179 | (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_SSDT); |
180 | (void)acpi_ns_load_table_by_type(ACPI_TABLE_ID_PSDT); | |
1da177e4 | 181 | |
4be44fcd LB |
182 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, |
183 | "ACPI Namespace successfully loaded at root %p\n", | |
184 | acpi_gbl_root_node)); | |
1da177e4 | 185 | |
4be44fcd | 186 | return_ACPI_STATUS(status); |
1da177e4 | 187 | } |
f3d2e786 | 188 | #endif |
1da177e4 | 189 | |
44f6c012 | 190 | #ifdef ACPI_FUTURE_IMPLEMENTATION |
1da177e4 LT |
191 | /******************************************************************************* |
192 | * | |
193 | * FUNCTION: acpi_ns_delete_subtree | |
194 | * | |
195 | * PARAMETERS: start_handle - Handle in namespace where search begins | |
196 | * | |
197 | * RETURNS Status | |
198 | * | |
199 | * DESCRIPTION: Walks the namespace starting at the given handle and deletes | |
200 | * all objects, entries, and scopes in the entire subtree. | |
201 | * | |
202 | * Namespace/Interpreter should be locked or the subsystem should | |
203 | * be in shutdown before this routine is called. | |
204 | * | |
205 | ******************************************************************************/ | |
206 | ||
4be44fcd | 207 | static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle) |
1da177e4 | 208 | { |
4be44fcd LB |
209 | acpi_status status; |
210 | acpi_handle child_handle; | |
211 | acpi_handle parent_handle; | |
212 | acpi_handle next_child_handle; | |
213 | acpi_handle dummy; | |
214 | u32 level; | |
1da177e4 | 215 | |
b229cf92 | 216 | ACPI_FUNCTION_TRACE(ns_delete_subtree); |
1da177e4 LT |
217 | |
218 | parent_handle = start_handle; | |
219 | child_handle = NULL; | |
4be44fcd | 220 | level = 1; |
1da177e4 LT |
221 | |
222 | /* | |
223 | * Traverse the tree of objects until we bubble back up | |
224 | * to where we started. | |
225 | */ | |
226 | while (level > 0) { | |
52fc0b02 | 227 | |
1da177e4 LT |
228 | /* Attempt to get the next object in this scope */ |
229 | ||
4be44fcd LB |
230 | status = acpi_get_next_object(ACPI_TYPE_ANY, parent_handle, |
231 | child_handle, &next_child_handle); | |
1da177e4 LT |
232 | |
233 | child_handle = next_child_handle; | |
234 | ||
235 | /* Did we get a new object? */ | |
236 | ||
4be44fcd | 237 | if (ACPI_SUCCESS(status)) { |
52fc0b02 | 238 | |
1da177e4 LT |
239 | /* Check if this object has any children */ |
240 | ||
4be44fcd LB |
241 | if (ACPI_SUCCESS |
242 | (acpi_get_next_object | |
243 | (ACPI_TYPE_ANY, child_handle, NULL, &dummy))) { | |
1da177e4 LT |
244 | /* |
245 | * There is at least one child of this object, | |
246 | * visit the object | |
247 | */ | |
248 | level++; | |
249 | parent_handle = child_handle; | |
250 | child_handle = NULL; | |
251 | } | |
4be44fcd | 252 | } else { |
1da177e4 LT |
253 | /* |
254 | * No more children in this object, go back up to | |
255 | * the object's parent | |
256 | */ | |
257 | level--; | |
258 | ||
259 | /* Delete all children now */ | |
260 | ||
4be44fcd | 261 | acpi_ns_delete_children(child_handle); |
1da177e4 LT |
262 | |
263 | child_handle = parent_handle; | |
4be44fcd LB |
264 | status = acpi_get_parent(parent_handle, &parent_handle); |
265 | if (ACPI_FAILURE(status)) { | |
266 | return_ACPI_STATUS(status); | |
1da177e4 LT |
267 | } |
268 | } | |
269 | } | |
270 | ||
271 | /* Now delete the starting object, and we are done */ | |
272 | ||
4be44fcd | 273 | acpi_ns_delete_node(child_handle); |
1da177e4 | 274 | |
4be44fcd | 275 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
276 | } |
277 | ||
1da177e4 LT |
278 | /******************************************************************************* |
279 | * | |
280 | * FUNCTION: acpi_ns_unload_name_space | |
281 | * | |
282 | * PARAMETERS: Handle - Root of namespace subtree to be deleted | |
283 | * | |
284 | * RETURN: Status | |
285 | * | |
286 | * DESCRIPTION: Shrinks the namespace, typically in response to an undocking | |
287 | * event. Deletes an entire subtree starting from (and | |
288 | * including) the given handle. | |
289 | * | |
290 | ******************************************************************************/ | |
291 | ||
4be44fcd | 292 | acpi_status acpi_ns_unload_namespace(acpi_handle handle) |
1da177e4 | 293 | { |
4be44fcd | 294 | acpi_status status; |
1da177e4 | 295 | |
b229cf92 | 296 | ACPI_FUNCTION_TRACE(ns_unload_name_space); |
1da177e4 LT |
297 | |
298 | /* Parameter validation */ | |
299 | ||
300 | if (!acpi_gbl_root_node) { | |
4be44fcd | 301 | return_ACPI_STATUS(AE_NO_NAMESPACE); |
1da177e4 LT |
302 | } |
303 | ||
304 | if (!handle) { | |
4be44fcd | 305 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
306 | } |
307 | ||
308 | /* This function does the real work */ | |
309 | ||
4be44fcd | 310 | status = acpi_ns_delete_subtree(handle); |
1da177e4 | 311 | |
4be44fcd | 312 | return_ACPI_STATUS(status); |
1da177e4 | 313 | } |
44f6c012 | 314 | #endif |
1da177e4 | 315 | #endif |