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