| 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 | 6c9deb7 | 2007-02-02 19:48:24 +0300 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2007, 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; | 
| Valery A. Podrezov | afbb9e6 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 64 | #ifdef ACPI_DBG_TRACK_ALLOCATIONS | 
|  | 65 | u32 temp; | 
|  | 66 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 68 | ACPI_FUNCTION_TRACE(ns_create_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 |  | 
| Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 70 | node = acpi_os_acquire_object(acpi_gbl_namespace_cache); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | if (!node) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 72 | return_PTR(NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } | 
|  | 74 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_allocated++); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 |  | 
| Valery A. Podrezov | afbb9e6 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 77 | #ifdef ACPI_DBG_TRACK_ALLOCATIONS | 
|  | 78 | temp = | 
|  | 79 | acpi_gbl_ns_node_list->total_allocated - | 
|  | 80 | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | node->name.integer = name; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | ACPI_SET_DESCRIPTOR_TYPE(node, ACPI_DESC_TYPE_NAMED); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 88 | return_PTR(node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } | 
|  | 90 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /******************************************************************************* | 
|  | 92 | * | 
|  | 93 | * FUNCTION:    acpi_ns_delete_node | 
|  | 94 | * | 
|  | 95 | * PARAMETERS:  Node            - Node to be deleted | 
|  | 96 | * | 
|  | 97 | * RETURN:      None | 
|  | 98 | * | 
|  | 99 | * DESCRIPTION: Delete a namespace node | 
|  | 100 | * | 
|  | 101 | ******************************************************************************/ | 
|  | 102 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 103 | void acpi_ns_delete_node(struct acpi_namespace_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 | struct acpi_namespace_node *parent_node; | 
|  | 106 | struct acpi_namespace_node *prev_node; | 
|  | 107 | struct acpi_namespace_node *next_node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 109 | ACPI_FUNCTION_TRACE_PTR(ns_delete_node, node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 111 | parent_node = acpi_ns_get_parent_node(node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 |  | 
|  | 113 | prev_node = NULL; | 
|  | 114 | next_node = parent_node->child; | 
|  | 115 |  | 
|  | 116 | /* Find the node that is the previous peer in the parent's child list */ | 
|  | 117 |  | 
|  | 118 | while (next_node != node) { | 
|  | 119 | prev_node = next_node; | 
|  | 120 | next_node = prev_node->peer; | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 | if (prev_node) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 124 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | /* Node is not first child, unlink it */ | 
|  | 126 |  | 
|  | 127 | prev_node->peer = next_node->peer; | 
|  | 128 | if (next_node->flags & ANOBJ_END_OF_PEER_LIST) { | 
|  | 129 | prev_node->flags |= ANOBJ_END_OF_PEER_LIST; | 
|  | 130 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 131 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /* Node is first child (has no previous peer) */ | 
|  | 133 |  | 
|  | 134 | if (next_node->flags & ANOBJ_END_OF_PEER_LIST) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 135 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | /* No peers at all */ | 
|  | 137 |  | 
|  | 138 | parent_node->child = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 139 | } else {	/* Link peer list to parent */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 |  | 
|  | 141 | parent_node->child = next_node->peer; | 
|  | 142 | } | 
|  | 143 | } | 
|  | 144 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_freed++); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 |  | 
|  | 147 | /* | 
| Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 148 | * Detach an object if there is one, then delete the node | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | acpi_ns_detach_object(node); | 
| Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 151 | (void)acpi_os_release_object(acpi_gbl_namespace_cache, node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | return_VOID; | 
|  | 153 | } | 
|  | 154 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | /******************************************************************************* | 
|  | 156 | * | 
|  | 157 | * FUNCTION:    acpi_ns_install_node | 
|  | 158 | * | 
|  | 159 | * PARAMETERS:  walk_state      - Current state of the walk | 
|  | 160 | *              parent_node     - The parent of the new Node | 
|  | 161 | *              Node            - The new Node to install | 
|  | 162 | *              Type            - ACPI object type of the new Node | 
|  | 163 | * | 
|  | 164 | * RETURN:      None | 
|  | 165 | * | 
|  | 166 | * DESCRIPTION: Initialize a new namespace node and install it amongst | 
|  | 167 | *              its peers. | 
|  | 168 | * | 
| Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 169 | *              Note: Current namespace lookup is linear search. This appears | 
|  | 170 | *              to be sufficient as namespace searches consume only a small | 
|  | 171 | *              fraction of the execution time of the ACPI subsystem. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | * | 
|  | 173 | ******************************************************************************/ | 
|  | 174 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 175 | void acpi_ns_install_node(struct acpi_walk_state *walk_state, struct acpi_namespace_node *parent_node,	/* Parent */ | 
|  | 176 | struct acpi_namespace_node *node,	/* New Child */ | 
|  | 177 | acpi_object_type type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | acpi_owner_id owner_id = 0; | 
|  | 180 | struct acpi_namespace_node *child_node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 182 | ACPI_FUNCTION_TRACE(ns_install_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 |  | 
|  | 184 | /* | 
|  | 185 | * Get the owner ID from the Walk state | 
|  | 186 | * The owner ID is used to track table deletion and | 
|  | 187 | * deletion of objects created by methods | 
|  | 188 | */ | 
|  | 189 | if (walk_state) { | 
|  | 190 | owner_id = walk_state->owner_id; | 
|  | 191 | } | 
|  | 192 |  | 
|  | 193 | /* Link the new entry into the parent and existing children */ | 
|  | 194 |  | 
|  | 195 | child_node = parent_node->child; | 
|  | 196 | if (!child_node) { | 
|  | 197 | parent_node->child = node; | 
|  | 198 | node->flags |= ANOBJ_END_OF_PEER_LIST; | 
|  | 199 | node->peer = parent_node; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 200 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | while (!(child_node->flags & ANOBJ_END_OF_PEER_LIST)) { | 
|  | 202 | child_node = child_node->peer; | 
|  | 203 | } | 
|  | 204 |  | 
|  | 205 | child_node->peer = node; | 
|  | 206 |  | 
|  | 207 | /* Clear end-of-list flag */ | 
|  | 208 |  | 
|  | 209 | child_node->flags &= ~ANOBJ_END_OF_PEER_LIST; | 
| Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 210 | node->flags |= ANOBJ_END_OF_PEER_LIST; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | node->peer = parent_node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } | 
|  | 213 |  | 
|  | 214 | /* Init the new entry */ | 
|  | 215 |  | 
|  | 216 | node->owner_id = owner_id; | 
|  | 217 | node->type = (u8) type; | 
|  | 218 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, | 
|  | 220 | "%4.4s (%s) [Node %p Owner %X] added to %4.4s (%s) [Node %p]\n", | 
|  | 221 | acpi_ut_get_node_name(node), | 
|  | 222 | acpi_ut_get_type_name(node->type), node, owner_id, | 
|  | 223 | acpi_ut_get_node_name(parent_node), | 
|  | 224 | acpi_ut_get_type_name(parent_node->type), | 
|  | 225 | parent_node)); | 
| Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 226 |  | 
|  | 227 | return_VOID; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 247 | u8 flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 249 | ACPI_FUNCTION_TRACE_PTR(ns_delete_children, parent_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 |  | 
|  | 251 | if (!parent_node) { | 
|  | 252 | return_VOID; | 
|  | 253 | } | 
|  | 254 |  | 
|  | 255 | /* If no children, all done! */ | 
|  | 256 |  | 
|  | 257 | child_node = parent_node->child; | 
|  | 258 | if (!child_node) { | 
|  | 259 | return_VOID; | 
|  | 260 | } | 
|  | 261 |  | 
|  | 262 | /* | 
|  | 263 | * Deallocate all children at this level | 
|  | 264 | */ | 
|  | 265 | do { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 266 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | /* Now we can delete the node */ | 
|  | 293 |  | 
| Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 294 | (void)acpi_os_release_object(acpi_gbl_namespace_cache, | 
|  | 295 | child_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 |  | 
|  | 297 | /* And move on to the next child in the list */ | 
|  | 298 |  | 
|  | 299 | child_node = next_node; | 
|  | 300 |  | 
|  | 301 | } while (!(flags & ANOBJ_END_OF_PEER_LIST)); | 
|  | 302 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | /* Clear the parent's child pointer */ | 
|  | 304 |  | 
|  | 305 | parent_node->child = NULL; | 
|  | 306 |  | 
|  | 307 | return_VOID; | 
|  | 308 | } | 
|  | 309 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | /******************************************************************************* | 
|  | 311 | * | 
|  | 312 | * FUNCTION:    acpi_ns_delete_namespace_subtree | 
|  | 313 | * | 
|  | 314 | * PARAMETERS:  parent_node     - Root of the subtree to be deleted | 
|  | 315 | * | 
|  | 316 | * RETURN:      None. | 
|  | 317 | * | 
|  | 318 | * DESCRIPTION: Delete a subtree of the namespace.  This includes all objects | 
|  | 319 | *              stored within the subtree. | 
|  | 320 | * | 
|  | 321 | ******************************************************************************/ | 
|  | 322 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 323 | void acpi_ns_delete_namespace_subtree(struct acpi_namespace_node *parent_node) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 325 | struct acpi_namespace_node *child_node = NULL; | 
|  | 326 | u32 level = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 328 | ACPI_FUNCTION_TRACE(ns_delete_namespace_subtree); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 |  | 
|  | 330 | if (!parent_node) { | 
|  | 331 | return_VOID; | 
|  | 332 | } | 
|  | 333 |  | 
|  | 334 | /* | 
|  | 335 | * Traverse the tree of objects until we bubble back up | 
|  | 336 | * to where we started. | 
|  | 337 | */ | 
|  | 338 | while (level > 0) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 339 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | /* Get the next node in this scope (NULL if none) */ | 
|  | 341 |  | 
| Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 342 | child_node = | 
|  | 343 | acpi_ns_get_next_node(ACPI_TYPE_ANY, parent_node, | 
|  | 344 | child_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | if (child_node) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 346 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | /* Found a child node - detach any attached object */ | 
|  | 348 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 349 | acpi_ns_detach_object(child_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 |  | 
|  | 351 | /* Check if this node has any children */ | 
|  | 352 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 353 | if (acpi_ns_get_next_node | 
|  | 354 | (ACPI_TYPE_ANY, child_node, NULL)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | /* | 
|  | 356 | * There is at least one child of this node, | 
|  | 357 | * visit the node | 
|  | 358 | */ | 
|  | 359 | level++; | 
|  | 360 | parent_node = child_node; | 
|  | 361 | child_node = NULL; | 
|  | 362 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 363 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | /* | 
|  | 365 | * No more children of this parent node. | 
|  | 366 | * Move up to the grandparent. | 
|  | 367 | */ | 
|  | 368 | level--; | 
|  | 369 |  | 
|  | 370 | /* | 
|  | 371 | * Now delete all of the children of this parent | 
|  | 372 | * all at the same time. | 
|  | 373 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 374 | acpi_ns_delete_children(parent_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 |  | 
|  | 376 | /* New "last child" is this parent node */ | 
|  | 377 |  | 
|  | 378 | child_node = parent_node; | 
|  | 379 |  | 
|  | 380 | /* Move up the tree to the grandparent */ | 
|  | 381 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 382 | parent_node = acpi_ns_get_parent_node(parent_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } | 
|  | 384 | } | 
|  | 385 |  | 
|  | 386 | return_VOID; | 
|  | 387 | } | 
|  | 388 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | /******************************************************************************* | 
|  | 390 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | * FUNCTION:    acpi_ns_delete_namespace_by_owner | 
|  | 392 | * | 
|  | 393 | * PARAMETERS:  owner_id    - All nodes with this owner will be deleted | 
|  | 394 | * | 
|  | 395 | * RETURN:      Status | 
|  | 396 | * | 
|  | 397 | * DESCRIPTION: Delete entries within the namespace that are owned by a | 
|  | 398 | *              specific ID.  Used to delete entire ACPI tables.  All | 
|  | 399 | *              reference counts are updated. | 
|  | 400 | * | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 401 | * MUTEX:       Locks namespace during deletion walk. | 
|  | 402 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | ******************************************************************************/ | 
|  | 404 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 405 | void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 407 | struct acpi_namespace_node *child_node; | 
|  | 408 | struct acpi_namespace_node *deletion_node; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 409 | struct acpi_namespace_node *parent_node; | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 410 | u32 level; | 
|  | 411 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 413 | ACPI_FUNCTION_TRACE_U32(ns_delete_namespace_by_owner, owner_id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 |  | 
| Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 415 | if (owner_id == 0) { | 
|  | 416 | return_VOID; | 
|  | 417 | } | 
|  | 418 |  | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 419 | /* Lock namespace for possible update */ | 
|  | 420 |  | 
|  | 421 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 422 | if (ACPI_FAILURE(status)) { | 
|  | 423 | return_VOID; | 
|  | 424 | } | 
|  | 425 |  | 
| Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 426 | deletion_node = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 427 | parent_node = acpi_gbl_root_node; | 
|  | 428 | child_node = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 429 | level = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 |  | 
|  | 431 | /* | 
|  | 432 | * Traverse the tree of nodes until we bubble back up | 
|  | 433 | * to where we started. | 
|  | 434 | */ | 
|  | 435 | while (level > 0) { | 
|  | 436 | /* | 
|  | 437 | * Get the next child of this parent node. When child_node is NULL, | 
|  | 438 | * the first child of the parent is returned | 
|  | 439 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 440 | child_node = | 
|  | 441 | acpi_ns_get_next_node(ACPI_TYPE_ANY, parent_node, | 
|  | 442 | child_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 |  | 
|  | 444 | if (deletion_node) { | 
| Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 445 | acpi_ns_delete_children(deletion_node); | 
|  | 446 | acpi_ns_delete_node(deletion_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | deletion_node = NULL; | 
|  | 448 | } | 
|  | 449 |  | 
|  | 450 | if (child_node) { | 
|  | 451 | if (child_node->owner_id == owner_id) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 452 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | /* Found a matching child node - detach any attached object */ | 
|  | 454 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 455 | acpi_ns_detach_object(child_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | } | 
|  | 457 |  | 
|  | 458 | /* Check if this node has any children */ | 
|  | 459 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 460 | if (acpi_ns_get_next_node | 
|  | 461 | (ACPI_TYPE_ANY, child_node, NULL)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | /* | 
|  | 463 | * There is at least one child of this node, | 
|  | 464 | * visit the node | 
|  | 465 | */ | 
|  | 466 | level++; | 
|  | 467 | parent_node = child_node; | 
|  | 468 | child_node = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 469 | } else if (child_node->owner_id == owner_id) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | deletion_node = child_node; | 
|  | 471 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 472 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | /* | 
|  | 474 | * No more children of this parent node. | 
|  | 475 | * Move up to the grandparent. | 
|  | 476 | */ | 
|  | 477 | level--; | 
|  | 478 | if (level != 0) { | 
|  | 479 | if (parent_node->owner_id == owner_id) { | 
|  | 480 | deletion_node = parent_node; | 
|  | 481 | } | 
|  | 482 | } | 
|  | 483 |  | 
|  | 484 | /* New "last child" is this parent node */ | 
|  | 485 |  | 
|  | 486 | child_node = parent_node; | 
|  | 487 |  | 
|  | 488 | /* Move up the tree to the grandparent */ | 
|  | 489 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 490 | parent_node = acpi_ns_get_parent_node(parent_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } | 
|  | 492 | } | 
|  | 493 |  | 
| Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 494 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | return_VOID; | 
|  | 496 | } |