Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Module Name: nsalloc - Namespace allocation and deletion utilities |
| 4 | * |
| 5 | ******************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
| 45 | #include <acpi/acnamesp.h> |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define _COMPONENT ACPI_NAMESPACE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 48 | ACPI_MODULE_NAME("nsalloc") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | /******************************************************************************* |
| 51 | * |
| 52 | * FUNCTION: acpi_ns_create_node |
| 53 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 54 | * PARAMETERS: Name - Name of the new node (4 char ACPI name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 56 | * RETURN: New namespace node (Null on failure) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | * |
| 58 | * DESCRIPTION: Create a namespace node |
| 59 | * |
| 60 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 61 | struct acpi_namespace_node *acpi_ns_create_node(u32 name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 63 | struct acpi_namespace_node *node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 65 | ACPI_FUNCTION_TRACE(ns_create_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 67 | node = acpi_os_acquire_object(acpi_gbl_namespace_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | if (!node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | return_PTR(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 72 | ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_allocated++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 74 | node->name.integer = name; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | ACPI_SET_DESCRIPTOR_TYPE(node, ACPI_DESC_TYPE_NAMED); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 76 | return_PTR(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /******************************************************************************* |
| 80 | * |
| 81 | * FUNCTION: acpi_ns_delete_node |
| 82 | * |
| 83 | * PARAMETERS: Node - Node to be deleted |
| 84 | * |
| 85 | * RETURN: None |
| 86 | * |
| 87 | * DESCRIPTION: Delete a namespace node |
| 88 | * |
| 89 | ******************************************************************************/ |
| 90 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 91 | void acpi_ns_delete_node(struct acpi_namespace_node *node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | struct acpi_namespace_node *parent_node; |
| 94 | struct acpi_namespace_node *prev_node; |
| 95 | struct acpi_namespace_node *next_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 97 | ACPI_FUNCTION_TRACE_PTR(ns_delete_node, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 99 | parent_node = acpi_ns_get_parent_node(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | prev_node = NULL; |
| 102 | next_node = parent_node->child; |
| 103 | |
| 104 | /* Find the node that is the previous peer in the parent's child list */ |
| 105 | |
| 106 | while (next_node != node) { |
| 107 | prev_node = next_node; |
| 108 | next_node = prev_node->peer; |
| 109 | } |
| 110 | |
| 111 | if (prev_node) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /* Node is not first child, unlink it */ |
| 114 | |
| 115 | prev_node->peer = next_node->peer; |
| 116 | if (next_node->flags & ANOBJ_END_OF_PEER_LIST) { |
| 117 | prev_node->flags |= ANOBJ_END_OF_PEER_LIST; |
| 118 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | /* Node is first child (has no previous peer) */ |
| 121 | |
| 122 | if (next_node->flags & ANOBJ_END_OF_PEER_LIST) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | /* No peers at all */ |
| 125 | |
| 126 | parent_node->child = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 127 | } else { /* Link peer list to parent */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | parent_node->child = next_node->peer; |
| 130 | } |
| 131 | } |
| 132 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_freed++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | /* |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 136 | * Detach an object if there is one, then delete the node |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | acpi_ns_detach_object(node); |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 139 | (void)acpi_os_release_object(acpi_gbl_namespace_cache, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | return_VOID; |
| 141 | } |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | /******************************************************************************* |
| 144 | * |
| 145 | * FUNCTION: acpi_ns_install_node |
| 146 | * |
| 147 | * PARAMETERS: walk_state - Current state of the walk |
| 148 | * parent_node - The parent of the new Node |
| 149 | * Node - The new Node to install |
| 150 | * Type - ACPI object type of the new Node |
| 151 | * |
| 152 | * RETURN: None |
| 153 | * |
| 154 | * DESCRIPTION: Initialize a new namespace node and install it amongst |
| 155 | * its peers. |
| 156 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 157 | * Note: Current namespace lookup is linear search. This appears |
| 158 | * to be sufficient as namespace searches consume only a small |
| 159 | * fraction of the execution time of the ACPI subsystem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | * |
| 161 | ******************************************************************************/ |
| 162 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | void acpi_ns_install_node(struct acpi_walk_state *walk_state, struct acpi_namespace_node *parent_node, /* Parent */ |
| 164 | struct acpi_namespace_node *node, /* New Child */ |
| 165 | acpi_object_type type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 167 | acpi_owner_id owner_id = 0; |
| 168 | struct acpi_namespace_node *child_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 170 | ACPI_FUNCTION_TRACE(ns_install_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | /* |
| 173 | * Get the owner ID from the Walk state |
| 174 | * The owner ID is used to track table deletion and |
| 175 | * deletion of objects created by methods |
| 176 | */ |
| 177 | if (walk_state) { |
| 178 | owner_id = walk_state->owner_id; |
| 179 | } |
| 180 | |
| 181 | /* Link the new entry into the parent and existing children */ |
| 182 | |
| 183 | child_node = parent_node->child; |
| 184 | if (!child_node) { |
| 185 | parent_node->child = node; |
| 186 | node->flags |= ANOBJ_END_OF_PEER_LIST; |
| 187 | node->peer = parent_node; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 188 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | while (!(child_node->flags & ANOBJ_END_OF_PEER_LIST)) { |
| 190 | child_node = child_node->peer; |
| 191 | } |
| 192 | |
| 193 | child_node->peer = node; |
| 194 | |
| 195 | /* Clear end-of-list flag */ |
| 196 | |
| 197 | child_node->flags &= ~ANOBJ_END_OF_PEER_LIST; |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 198 | node->flags |= ANOBJ_END_OF_PEER_LIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | node->peer = parent_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /* Init the new entry */ |
| 203 | |
| 204 | node->owner_id = owner_id; |
| 205 | node->type = (u8) type; |
| 206 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 207 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
| 208 | "%4.4s (%s) [Node %p Owner %X] added to %4.4s (%s) [Node %p]\n", |
| 209 | acpi_ut_get_node_name(node), |
| 210 | acpi_ut_get_type_name(node->type), node, owner_id, |
| 211 | acpi_ut_get_node_name(parent_node), |
| 212 | acpi_ut_get_type_name(parent_node->type), |
| 213 | parent_node)); |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 214 | |
| 215 | return_VOID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | /******************************************************************************* |
| 219 | * |
| 220 | * FUNCTION: acpi_ns_delete_children |
| 221 | * |
| 222 | * PARAMETERS: parent_node - Delete this objects children |
| 223 | * |
| 224 | * RETURN: None. |
| 225 | * |
| 226 | * DESCRIPTION: Delete all children of the parent object. In other words, |
| 227 | * deletes a "scope". |
| 228 | * |
| 229 | ******************************************************************************/ |
| 230 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 231 | void acpi_ns_delete_children(struct acpi_namespace_node *parent_node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 233 | struct acpi_namespace_node *child_node; |
| 234 | struct acpi_namespace_node *next_node; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 235 | u8 flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 237 | ACPI_FUNCTION_TRACE_PTR(ns_delete_children, parent_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
| 239 | if (!parent_node) { |
| 240 | return_VOID; |
| 241 | } |
| 242 | |
| 243 | /* If no children, all done! */ |
| 244 | |
| 245 | child_node = parent_node->child; |
| 246 | if (!child_node) { |
| 247 | return_VOID; |
| 248 | } |
| 249 | |
| 250 | /* |
| 251 | * Deallocate all children at this level |
| 252 | */ |
| 253 | do { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | /* Get the things we need */ |
| 256 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 257 | next_node = child_node->peer; |
| 258 | flags = child_node->flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
| 260 | /* Grandchildren should have all been deleted already */ |
| 261 | |
| 262 | if (child_node->child) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 263 | ACPI_ERROR((AE_INFO, "Found a grandchild! P=%p C=%p", |
| 264 | parent_node, child_node)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /* Now we can free this child object */ |
| 268 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 269 | ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_freed++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, |
| 272 | "Object %p, Remaining %X\n", child_node, |
| 273 | acpi_gbl_current_node_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
| 275 | /* |
| 276 | * Detach an object if there is one, then free the child node |
| 277 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 278 | acpi_ns_detach_object(child_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | /* Now we can delete the node */ |
| 281 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 282 | (void)acpi_os_release_object(acpi_gbl_namespace_cache, |
| 283 | child_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | /* And move on to the next child in the list */ |
| 286 | |
| 287 | child_node = next_node; |
| 288 | |
| 289 | } while (!(flags & ANOBJ_END_OF_PEER_LIST)); |
| 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | /* Clear the parent's child pointer */ |
| 292 | |
| 293 | parent_node->child = NULL; |
| 294 | |
| 295 | return_VOID; |
| 296 | } |
| 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | /******************************************************************************* |
| 299 | * |
| 300 | * FUNCTION: acpi_ns_delete_namespace_subtree |
| 301 | * |
| 302 | * PARAMETERS: parent_node - Root of the subtree to be deleted |
| 303 | * |
| 304 | * RETURN: None. |
| 305 | * |
| 306 | * DESCRIPTION: Delete a subtree of the namespace. This includes all objects |
| 307 | * stored within the subtree. |
| 308 | * |
| 309 | ******************************************************************************/ |
| 310 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 311 | void acpi_ns_delete_namespace_subtree(struct acpi_namespace_node *parent_node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 313 | struct acpi_namespace_node *child_node = NULL; |
| 314 | u32 level = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 316 | ACPI_FUNCTION_TRACE(ns_delete_namespace_subtree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
| 318 | if (!parent_node) { |
| 319 | return_VOID; |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * Traverse the tree of objects until we bubble back up |
| 324 | * to where we started. |
| 325 | */ |
| 326 | while (level > 0) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | /* Get the next node in this scope (NULL if none) */ |
| 329 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 330 | child_node = |
| 331 | acpi_ns_get_next_node(ACPI_TYPE_ANY, parent_node, |
| 332 | child_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | if (child_node) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | /* Found a child node - detach any attached object */ |
| 336 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 337 | acpi_ns_detach_object(child_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | /* Check if this node has any children */ |
| 340 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 341 | if (acpi_ns_get_next_node |
| 342 | (ACPI_TYPE_ANY, child_node, NULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | /* |
| 344 | * There is at least one child of this node, |
| 345 | * visit the node |
| 346 | */ |
| 347 | level++; |
| 348 | parent_node = child_node; |
| 349 | child_node = NULL; |
| 350 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 351 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | /* |
| 353 | * No more children of this parent node. |
| 354 | * Move up to the grandparent. |
| 355 | */ |
| 356 | level--; |
| 357 | |
| 358 | /* |
| 359 | * Now delete all of the children of this parent |
| 360 | * all at the same time. |
| 361 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 362 | acpi_ns_delete_children(parent_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
| 364 | /* New "last child" is this parent node */ |
| 365 | |
| 366 | child_node = parent_node; |
| 367 | |
| 368 | /* Move up the tree to the grandparent */ |
| 369 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 370 | parent_node = acpi_ns_get_parent_node(parent_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
| 374 | return_VOID; |
| 375 | } |
| 376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | /******************************************************************************* |
| 378 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | * FUNCTION: acpi_ns_delete_namespace_by_owner |
| 380 | * |
| 381 | * PARAMETERS: owner_id - All nodes with this owner will be deleted |
| 382 | * |
| 383 | * RETURN: Status |
| 384 | * |
| 385 | * DESCRIPTION: Delete entries within the namespace that are owned by a |
| 386 | * specific ID. Used to delete entire ACPI tables. All |
| 387 | * reference counts are updated. |
| 388 | * |
| 389 | ******************************************************************************/ |
| 390 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 391 | void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 393 | struct acpi_namespace_node *child_node; |
| 394 | struct acpi_namespace_node *deletion_node; |
| 395 | u32 level; |
| 396 | struct acpi_namespace_node *parent_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 398 | ACPI_FUNCTION_TRACE_U32(ns_delete_namespace_by_owner, owner_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 400 | if (owner_id == 0) { |
| 401 | return_VOID; |
| 402 | } |
| 403 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 404 | deletion_node = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 405 | parent_node = acpi_gbl_root_node; |
| 406 | child_node = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 407 | level = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
| 409 | /* |
| 410 | * Traverse the tree of nodes until we bubble back up |
| 411 | * to where we started. |
| 412 | */ |
| 413 | while (level > 0) { |
| 414 | /* |
| 415 | * Get the next child of this parent node. When child_node is NULL, |
| 416 | * the first child of the parent is returned |
| 417 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 418 | child_node = |
| 419 | acpi_ns_get_next_node(ACPI_TYPE_ANY, parent_node, |
| 420 | child_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | if (deletion_node) { |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 423 | acpi_ns_delete_children(deletion_node); |
| 424 | acpi_ns_delete_node(deletion_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | deletion_node = NULL; |
| 426 | } |
| 427 | |
| 428 | if (child_node) { |
| 429 | if (child_node->owner_id == owner_id) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | /* Found a matching child node - detach any attached object */ |
| 432 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 433 | acpi_ns_detach_object(child_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /* Check if this node has any children */ |
| 437 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 438 | if (acpi_ns_get_next_node |
| 439 | (ACPI_TYPE_ANY, child_node, NULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | /* |
| 441 | * There is at least one child of this node, |
| 442 | * visit the node |
| 443 | */ |
| 444 | level++; |
| 445 | parent_node = child_node; |
| 446 | child_node = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 447 | } else if (child_node->owner_id == owner_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | deletion_node = child_node; |
| 449 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 450 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | /* |
| 452 | * No more children of this parent node. |
| 453 | * Move up to the grandparent. |
| 454 | */ |
| 455 | level--; |
| 456 | if (level != 0) { |
| 457 | if (parent_node->owner_id == owner_id) { |
| 458 | deletion_node = parent_node; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | /* New "last child" is this parent node */ |
| 463 | |
| 464 | child_node = parent_node; |
| 465 | |
| 466 | /* Move up the tree to the grandparent */ |
| 467 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 468 | parent_node = acpi_ns_get_parent_node(parent_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | |
| 472 | return_VOID; |
| 473 | } |