blob: bc3f598257a20b97a8826cf9bd3a5fae7fd3aa3b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Module Name: nsalloc - Namespace allocation and deletion utilities
4 *
5 ******************************************************************************/
6
7/*
Bob Moore25f044e2013-01-25 05:38:56 +00008 * Copyright (C) 2000 - 2013, Intel Corp.
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>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("nsalloc")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/*******************************************************************************
52 *
53 * FUNCTION: acpi_ns_create_node
54 *
Bob Mooreba494be2012-07-12 09:40:10 +080055 * PARAMETERS: name - Name of the new node (4 char ACPI name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 *
Robert Moore44f6c012005-04-18 22:49:35 -040057 * RETURN: New namespace node (Null on failure)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 *
59 * DESCRIPTION: Create a namespace node
60 *
61 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040062struct acpi_namespace_node *acpi_ns_create_node(u32 name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Len Brown4be44fc2005-08-05 00:44:28 -040064 struct acpi_namespace_node *node;
Valery A. Podrezovafbb9e62007-02-02 19:48:23 +030065#ifdef ACPI_DBG_TRACK_ALLOCATIONS
66 u32 temp;
67#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Bob Mooreb229cf92006-04-21 17:15:00 -040069 ACPI_FUNCTION_TRACE(ns_create_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Bob Moore616861242006-03-17 16:44:00 -050071 node = acpi_os_acquire_object(acpi_gbl_namespace_cache);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 if (!node) {
Len Brown4be44fc2005-08-05 00:44:28 -040073 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 }
75
Len Brown4be44fc2005-08-05 00:44:28 -040076 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_allocated++);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Valery A. Podrezovafbb9e62007-02-02 19:48:23 +030078#ifdef ACPI_DBG_TRACK_ALLOCATIONS
Bob Moored4913dc2009-03-06 10:05:18 +080079 temp = acpi_gbl_ns_node_list->total_allocated -
Valery A. Podrezovafbb9e62007-02-02 19:48:23 +030080 acpi_gbl_ns_node_list->total_freed;
81 if (temp > acpi_gbl_ns_node_list->max_occupied) {
82 acpi_gbl_ns_node_list->max_occupied = temp;
83 }
84#endif
85
Len Brown4be44fc2005-08-05 00:44:28 -040086 node->name.integer = name;
Len Brown4be44fc2005-08-05 00:44:28 -040087 ACPI_SET_DESCRIPTOR_TYPE(node, ACPI_DESC_TYPE_NAMED);
Len Brown4be44fc2005-08-05 00:44:28 -040088 return_PTR(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091/*******************************************************************************
92 *
93 * FUNCTION: acpi_ns_delete_node
94 *
Bob Mooreba494be2012-07-12 09:40:10 +080095 * PARAMETERS: node - Node to be deleted
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 *
97 * RETURN: None
98 *
Bob Moore8e4319c2009-06-29 13:43:27 +080099 * DESCRIPTION: Delete a namespace node. All node deletions must come through
100 * here. Detaches any attached objects, including any attached
101 * data. If a handler is associated with attached data, it is
102 * invoked before the node is deleted.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 *
104 ******************************************************************************/
105
Len Brown4be44fc2005-08-05 00:44:28 -0400106void acpi_ns_delete_node(struct acpi_namespace_node *node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Bob Moore8e4319c2009-06-29 13:43:27 +0800108 union acpi_operand_object *obj_desc;
Tomasz Nowicki794ba092013-11-21 12:19:55 +0800109 union acpi_operand_object *next_desc;
Bob Moore8e4319c2009-06-29 13:43:27 +0800110
111 ACPI_FUNCTION_NAME(ns_delete_node);
112
113 /* Detach an object if there is one */
114
115 acpi_ns_detach_object(node);
116
117 /*
Tomasz Nowicki794ba092013-11-21 12:19:55 +0800118 * Delete an attached data object list if present (objects that were
119 * attached via acpi_attach_data). Note: After any normal object is
120 * detached above, the only possible remaining object(s) are data
121 * objects, in a linked list.
Bob Moore8e4319c2009-06-29 13:43:27 +0800122 */
123 obj_desc = node->object;
Tomasz Nowicki794ba092013-11-21 12:19:55 +0800124 while (obj_desc && (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA)) {
Bob Moore8e4319c2009-06-29 13:43:27 +0800125
126 /* Invoke the attached data deletion handler if present */
127
128 if (obj_desc->data.handler) {
129 obj_desc->data.handler(node, obj_desc->data.pointer);
130 }
131
Tomasz Nowicki794ba092013-11-21 12:19:55 +0800132 next_desc = obj_desc->common.next_object;
Bob Moore8e4319c2009-06-29 13:43:27 +0800133 acpi_ut_remove_reference(obj_desc);
Tomasz Nowicki794ba092013-11-21 12:19:55 +0800134 obj_desc = next_desc;
Bob Moore8e4319c2009-06-29 13:43:27 +0800135 }
136
137 /* Now we can delete the node */
138
139 (void)acpi_os_release_object(acpi_gbl_namespace_cache, node);
140
141 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_freed++);
142 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Node %p, Remaining %X\n",
143 node, acpi_gbl_current_node_count));
144}
145
146/*******************************************************************************
147 *
148 * FUNCTION: acpi_ns_remove_node
149 *
Bob Mooreba494be2012-07-12 09:40:10 +0800150 * PARAMETERS: node - Node to be removed/deleted
Bob Moore8e4319c2009-06-29 13:43:27 +0800151 *
152 * RETURN: None
153 *
154 * DESCRIPTION: Remove (unlink) and delete a namespace node
155 *
156 ******************************************************************************/
157
158void acpi_ns_remove_node(struct acpi_namespace_node *node)
159{
Len Brown4be44fc2005-08-05 00:44:28 -0400160 struct acpi_namespace_node *parent_node;
161 struct acpi_namespace_node *prev_node;
162 struct acpi_namespace_node *next_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Bob Moore8e4319c2009-06-29 13:43:27 +0800164 ACPI_FUNCTION_TRACE_PTR(ns_remove_node, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800166 parent_node = node->parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 prev_node = NULL;
169 next_node = parent_node->child;
170
171 /* Find the node that is the previous peer in the parent's child list */
172
173 while (next_node != node) {
174 prev_node = next_node;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800175 next_node = next_node->peer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 }
177
178 if (prev_node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 /* Node is not first child, unlink it */
181
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800182 prev_node->peer = node->peer;
Len Brown4be44fc2005-08-05 00:44:28 -0400183 } else {
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800184 /*
185 * Node is first child (has no previous peer).
186 * Link peer list to parent
187 */
188 parent_node->child = node->peer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 }
190
Bob Moore8e4319c2009-06-29 13:43:27 +0800191 /* Delete the node and any attached objects */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Bob Moore8e4319c2009-06-29 13:43:27 +0800193 acpi_ns_delete_node(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 return_VOID;
195}
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197/*******************************************************************************
198 *
199 * FUNCTION: acpi_ns_install_node
200 *
201 * PARAMETERS: walk_state - Current state of the walk
202 * parent_node - The parent of the new Node
Bob Mooreba494be2012-07-12 09:40:10 +0800203 * node - The new Node to install
204 * type - ACPI object type of the new Node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 *
206 * RETURN: None
207 *
208 * DESCRIPTION: Initialize a new namespace node and install it amongst
209 * its peers.
210 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700211 * Note: Current namespace lookup is linear search. This appears
212 * to be sufficient as namespace searches consume only a small
213 * fraction of the execution time of the ACPI subsystem.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 *
215 ******************************************************************************/
216
Len Brown4be44fc2005-08-05 00:44:28 -0400217void acpi_ns_install_node(struct acpi_walk_state *walk_state, struct acpi_namespace_node *parent_node, /* Parent */
218 struct acpi_namespace_node *node, /* New Child */
219 acpi_object_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Len Brown4be44fc2005-08-05 00:44:28 -0400221 acpi_owner_id owner_id = 0;
222 struct acpi_namespace_node *child_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Bob Mooreb229cf92006-04-21 17:15:00 -0400224 ACPI_FUNCTION_TRACE(ns_install_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 if (walk_state) {
Alexey Starikovskiya9fc0312010-05-26 13:59:51 +0800227 /*
228 * Get the owner ID from the Walk state. The owner ID is used to
229 * track table deletion and deletion of objects created by methods.
230 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 owner_id = walk_state->owner_id;
Alexey Starikovskiya9fc0312010-05-26 13:59:51 +0800232
233 if ((walk_state->method_desc) &&
234 (parent_node != walk_state->method_node)) {
235 /*
236 * A method is creating a new node that is not a child of the
237 * method (it is non-local). Mark the executing method as having
238 * modified the namespace. This is used for cleanup when the
239 * method exits.
240 */
Lin Ming26294842011-01-12 09:19:43 +0800241 walk_state->method_desc->method.info_flags |=
242 ACPI_METHOD_MODIFIED_NAMESPACE;
Alexey Starikovskiya9fc0312010-05-26 13:59:51 +0800243 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 }
245
246 /* Link the new entry into the parent and existing children */
247
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800248 node->peer = NULL;
249 node->parent = parent_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 child_node = parent_node->child;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 if (!child_node) {
253 parent_node->child = node;
Len Brown4be44fc2005-08-05 00:44:28 -0400254 } else {
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800255 /* Add node to the end of the peer list */
256
257 while (child_node->peer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 child_node = child_node->peer;
259 }
260
261 child_node->peer = node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
263
264 /* Init the new entry */
265
266 node->owner_id = owner_id;
267 node->type = (u8) type;
268
Len Brown4be44fc2005-08-05 00:44:28 -0400269 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
270 "%4.4s (%s) [Node %p Owner %X] added to %4.4s (%s) [Node %p]\n",
271 acpi_ut_get_node_name(node),
272 acpi_ut_get_type_name(node->type), node, owner_id,
273 acpi_ut_get_node_name(parent_node),
274 acpi_ut_get_type_name(parent_node->type),
275 parent_node));
Bob Moore793c2382006-03-31 00:00:00 -0500276
277 return_VOID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278}
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280/*******************************************************************************
281 *
282 * FUNCTION: acpi_ns_delete_children
283 *
284 * PARAMETERS: parent_node - Delete this objects children
285 *
286 * RETURN: None.
287 *
288 * DESCRIPTION: Delete all children of the parent object. In other words,
289 * deletes a "scope".
290 *
291 ******************************************************************************/
292
Len Brown4be44fc2005-08-05 00:44:28 -0400293void acpi_ns_delete_children(struct acpi_namespace_node *parent_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Len Brown4be44fc2005-08-05 00:44:28 -0400295 struct acpi_namespace_node *next_node;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800296 struct acpi_namespace_node *node_to_delete;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Bob Mooreb229cf92006-04-21 17:15:00 -0400298 ACPI_FUNCTION_TRACE_PTR(ns_delete_children, parent_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300 if (!parent_node) {
301 return_VOID;
302 }
303
Bob Moored4913dc2009-03-06 10:05:18 +0800304 /* Deallocate all children at this level */
305
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800306 next_node = parent_node->child;
307 while (next_node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309 /* Grandchildren should have all been deleted already */
310
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800311 if (next_node->child) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500312 ACPI_ERROR((AE_INFO, "Found a grandchild! P=%p C=%p",
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800313 parent_node, next_node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 }
315
Bob Moore8e4319c2009-06-29 13:43:27 +0800316 /*
317 * Delete this child node and move on to the next child in the list.
318 * No need to unlink the node since we are deleting the entire branch.
319 */
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800320 node_to_delete = next_node;
321 next_node = next_node->peer;
322 acpi_ns_delete_node(node_to_delete);
323 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 /* Clear the parent's child pointer */
326
327 parent_node->child = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 return_VOID;
329}
330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331/*******************************************************************************
332 *
333 * FUNCTION: acpi_ns_delete_namespace_subtree
334 *
335 * PARAMETERS: parent_node - Root of the subtree to be deleted
336 *
337 * RETURN: None.
338 *
Bob Moore73a30902012-10-31 02:26:55 +0000339 * DESCRIPTION: Delete a subtree of the namespace. This includes all objects
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 * stored within the subtree.
341 *
342 ******************************************************************************/
343
Len Brown4be44fc2005-08-05 00:44:28 -0400344void acpi_ns_delete_namespace_subtree(struct acpi_namespace_node *parent_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
Len Brown4be44fc2005-08-05 00:44:28 -0400346 struct acpi_namespace_node *child_node = NULL;
347 u32 level = 1;
Dana Myers5d3131f2011-01-12 09:09:31 +0800348 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Bob Mooreb229cf92006-04-21 17:15:00 -0400350 ACPI_FUNCTION_TRACE(ns_delete_namespace_subtree);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352 if (!parent_node) {
353 return_VOID;
354 }
355
Dana Myers5d3131f2011-01-12 09:09:31 +0800356 /* Lock namespace for possible update */
357
358 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
359 if (ACPI_FAILURE(status)) {
360 return_VOID;
361 }
362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 /*
364 * Traverse the tree of objects until we bubble back up
365 * to where we started.
366 */
367 while (level > 0) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 /* Get the next node in this scope (NULL if none) */
370
Bob Moore8c725bf2009-05-21 10:27:51 +0800371 child_node = acpi_ns_get_next_node(parent_node, child_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 if (child_node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 /* Found a child node - detach any attached object */
375
Len Brown4be44fc2005-08-05 00:44:28 -0400376 acpi_ns_detach_object(child_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 /* Check if this node has any children */
379
Bob Moore8c725bf2009-05-21 10:27:51 +0800380 if (child_node->child) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 /*
382 * There is at least one child of this node,
383 * visit the node
384 */
385 level++;
386 parent_node = child_node;
387 child_node = NULL;
388 }
Len Brown4be44fc2005-08-05 00:44:28 -0400389 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 /*
391 * No more children of this parent node.
392 * Move up to the grandparent.
393 */
394 level--;
395
396 /*
397 * Now delete all of the children of this parent
398 * all at the same time.
399 */
Len Brown4be44fc2005-08-05 00:44:28 -0400400 acpi_ns_delete_children(parent_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402 /* New "last child" is this parent node */
403
404 child_node = parent_node;
405
406 /* Move up the tree to the grandparent */
407
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800408 parent_node = parent_node->parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 }
410 }
411
Dana Myers5d3131f2011-01-12 09:09:31 +0800412 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 return_VOID;
414}
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416/*******************************************************************************
417 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 * FUNCTION: acpi_ns_delete_namespace_by_owner
419 *
420 * PARAMETERS: owner_id - All nodes with this owner will be deleted
421 *
422 * RETURN: Status
423 *
424 * DESCRIPTION: Delete entries within the namespace that are owned by a
Bob Moore73a30902012-10-31 02:26:55 +0000425 * specific ID. Used to delete entire ACPI tables. All
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 * reference counts are updated.
427 *
Bob Mooref6dd9222006-07-07 20:44:38 -0400428 * MUTEX: Locks namespace during deletion walk.
429 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 ******************************************************************************/
431
Len Brown4be44fc2005-08-05 00:44:28 -0400432void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
Len Brown4be44fc2005-08-05 00:44:28 -0400434 struct acpi_namespace_node *child_node;
435 struct acpi_namespace_node *deletion_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400436 struct acpi_namespace_node *parent_node;
Bob Mooref6dd9222006-07-07 20:44:38 -0400437 u32 level;
438 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Bob Mooreb229cf92006-04-21 17:15:00 -0400440 ACPI_FUNCTION_TRACE_U32(ns_delete_namespace_by_owner, owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Robert Moore0c9938c2005-07-29 15:15:00 -0700442 if (owner_id == 0) {
443 return_VOID;
444 }
445
Bob Mooref6dd9222006-07-07 20:44:38 -0400446 /* Lock namespace for possible update */
447
448 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
449 if (ACPI_FAILURE(status)) {
450 return_VOID;
451 }
452
Bob Moore616861242006-03-17 16:44:00 -0500453 deletion_node = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400454 parent_node = acpi_gbl_root_node;
455 child_node = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400456 level = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 /*
459 * Traverse the tree of nodes until we bubble back up
460 * to where we started.
461 */
462 while (level > 0) {
463 /*
464 * Get the next child of this parent node. When child_node is NULL,
465 * the first child of the parent is returned
466 */
Bob Moore8c725bf2009-05-21 10:27:51 +0800467 child_node = acpi_ns_get_next_node(parent_node, child_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469 if (deletion_node) {
Bob Moore616861242006-03-17 16:44:00 -0500470 acpi_ns_delete_children(deletion_node);
Bob Moore8e4319c2009-06-29 13:43:27 +0800471 acpi_ns_remove_node(deletion_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 deletion_node = NULL;
473 }
474
475 if (child_node) {
476 if (child_node->owner_id == owner_id) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 /* Found a matching child node - detach any attached object */
479
Len Brown4be44fc2005-08-05 00:44:28 -0400480 acpi_ns_detach_object(child_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 }
482
483 /* Check if this node has any children */
484
Bob Moore8c725bf2009-05-21 10:27:51 +0800485 if (child_node->child) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 /*
487 * There is at least one child of this node,
488 * visit the node
489 */
490 level++;
491 parent_node = child_node;
492 child_node = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400493 } else if (child_node->owner_id == owner_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 deletion_node = child_node;
495 }
Len Brown4be44fc2005-08-05 00:44:28 -0400496 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 /*
498 * No more children of this parent node.
499 * Move up to the grandparent.
500 */
501 level--;
502 if (level != 0) {
503 if (parent_node->owner_id == owner_id) {
504 deletion_node = parent_node;
505 }
506 }
507
508 /* New "last child" is this parent node */
509
510 child_node = parent_node;
511
512 /* Move up the tree to the grandparent */
513
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800514 parent_node = parent_node->parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 }
516 }
517
Bob Mooref6dd9222006-07-07 20:44:38 -0400518 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 return_VOID;
520}