Loading...
1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2/*******************************************************************************
3 *
4 * Module Name: nsalloc - Namespace allocation and deletion utilities
5 *
6 ******************************************************************************/
7
8#include <acpi/acpi.h>
9#include "accommon.h"
10#include "acnamesp.h"
11
12#define _COMPONENT ACPI_NAMESPACE
13ACPI_MODULE_NAME("nsalloc")
14
15/*******************************************************************************
16 *
17 * FUNCTION: acpi_ns_create_node
18 *
19 * PARAMETERS: name - Name of the new node (4 char ACPI name)
20 *
21 * RETURN: New namespace node (Null on failure)
22 *
23 * DESCRIPTION: Create a namespace node
24 *
25 ******************************************************************************/
26struct acpi_namespace_node *acpi_ns_create_node(u32 name)
27{
28 struct acpi_namespace_node *node;
29#ifdef ACPI_DBG_TRACK_ALLOCATIONS
30 u32 temp;
31#endif
32
33 ACPI_FUNCTION_TRACE(ns_create_node);
34
35 node = acpi_os_acquire_object(acpi_gbl_namespace_cache);
36 if (!node) {
37 return_PTR(NULL);
38 }
39
40 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_allocated++);
41
42#ifdef ACPI_DBG_TRACK_ALLOCATIONS
43 temp = acpi_gbl_ns_node_list->total_allocated -
44 acpi_gbl_ns_node_list->total_freed;
45 if (temp > acpi_gbl_ns_node_list->max_occupied) {
46 acpi_gbl_ns_node_list->max_occupied = temp;
47 }
48#endif
49
50 node->name.integer = name;
51 ACPI_SET_DESCRIPTOR_TYPE(node, ACPI_DESC_TYPE_NAMED);
52 return_PTR(node);
53}
54
55/*******************************************************************************
56 *
57 * FUNCTION: acpi_ns_delete_node
58 *
59 * PARAMETERS: node - Node to be deleted
60 *
61 * RETURN: None
62 *
63 * DESCRIPTION: Delete a namespace node. All node deletions must come through
64 * here. Detaches any attached objects, including any attached
65 * data. If a handler is associated with attached data, it is
66 * invoked before the node is deleted.
67 *
68 ******************************************************************************/
69
70void acpi_ns_delete_node(struct acpi_namespace_node *node)
71{
72 union acpi_operand_object *obj_desc;
73 union acpi_operand_object *next_desc;
74
75 ACPI_FUNCTION_NAME(ns_delete_node);
76
77 if (!node) {
78 return_VOID;
79 }
80
81 /* Detach an object if there is one */
82
83 acpi_ns_detach_object(node);
84
85 /*
86 * Delete an attached data object list if present (objects that were
87 * attached via acpi_attach_data). Note: After any normal object is
88 * detached above, the only possible remaining object(s) are data
89 * objects, in a linked list.
90 */
91 obj_desc = node->object;
92 while (obj_desc && (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA)) {
93
94 /* Invoke the attached data deletion handler if present */
95
96 if (obj_desc->data.handler) {
97 obj_desc->data.handler(node, obj_desc->data.pointer);
98 }
99
100 next_desc = obj_desc->common.next_object;
101 acpi_ut_remove_reference(obj_desc);
102 obj_desc = next_desc;
103 }
104
105 /* Special case for the statically allocated root node */
106
107 if (node == acpi_gbl_root_node) {
108 return;
109 }
110
111 /* Now we can delete the node */
112
113 (void)acpi_os_release_object(acpi_gbl_namespace_cache, node);
114
115 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_freed++);
116 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Node %p, Remaining %X\n",
117 node, acpi_gbl_current_node_count));
118}
119
120/*******************************************************************************
121 *
122 * FUNCTION: acpi_ns_remove_node
123 *
124 * PARAMETERS: node - Node to be removed/deleted
125 *
126 * RETURN: None
127 *
128 * DESCRIPTION: Remove (unlink) and delete a namespace node
129 *
130 ******************************************************************************/
131
132void acpi_ns_remove_node(struct acpi_namespace_node *node)
133{
134 struct acpi_namespace_node *parent_node;
135 struct acpi_namespace_node *prev_node;
136 struct acpi_namespace_node *next_node;
137
138 ACPI_FUNCTION_TRACE_PTR(ns_remove_node, node);
139
140 parent_node = node->parent;
141
142 prev_node = NULL;
143 next_node = parent_node->child;
144
145 /* Find the node that is the previous peer in the parent's child list */
146
147 while (next_node != node) {
148 prev_node = next_node;
149 next_node = next_node->peer;
150 }
151
152 if (prev_node) {
153
154 /* Node is not first child, unlink it */
155
156 prev_node->peer = node->peer;
157 } else {
158 /*
159 * Node is first child (has no previous peer).
160 * Link peer list to parent
161 */
162 parent_node->child = node->peer;
163 }
164
165 /* Delete the node and any attached objects */
166
167 acpi_ns_delete_node(node);
168 return_VOID;
169}
170
171/*******************************************************************************
172 *
173 * FUNCTION: acpi_ns_install_node
174 *
175 * PARAMETERS: walk_state - Current state of the walk
176 * parent_node - The parent of the new Node
177 * node - The new Node to install
178 * type - ACPI object type of the new Node
179 *
180 * RETURN: None
181 *
182 * DESCRIPTION: Initialize a new namespace node and install it amongst
183 * its peers.
184 *
185 * Note: Current namespace lookup is linear search. This appears
186 * to be sufficient as namespace searches consume only a small
187 * fraction of the execution time of the ACPI subsystem.
188 *
189 ******************************************************************************/
190
191void acpi_ns_install_node(struct acpi_walk_state *walk_state, struct acpi_namespace_node *parent_node, /* Parent */
192 struct acpi_namespace_node *node, /* New Child */
193 acpi_object_type type)
194{
195 acpi_owner_id owner_id = 0;
196 struct acpi_namespace_node *child_node;
197
198 ACPI_FUNCTION_TRACE(ns_install_node);
199
200 if (walk_state) {
201 /*
202 * Get the owner ID from the Walk state. The owner ID is used to
203 * track table deletion and deletion of objects created by methods.
204 */
205 owner_id = walk_state->owner_id;
206
207 if ((walk_state->method_desc) &&
208 (parent_node != walk_state->method_node)) {
209 /*
210 * A method is creating a new node that is not a child of the
211 * method (it is non-local). Mark the executing method as having
212 * modified the namespace. This is used for cleanup when the
213 * method exits.
214 */
215 walk_state->method_desc->method.info_flags |=
216 ACPI_METHOD_MODIFIED_NAMESPACE;
217 }
218 }
219
220 /* Link the new entry into the parent and existing children */
221
222 node->peer = NULL;
223 node->parent = parent_node;
224 child_node = parent_node->child;
225
226 if (!child_node) {
227 parent_node->child = node;
228 } else {
229 /* Add node to the end of the peer list */
230
231 while (child_node->peer) {
232 child_node = child_node->peer;
233 }
234
235 child_node->peer = node;
236 }
237
238 /* Init the new entry */
239
240 node->owner_id = owner_id;
241 node->type = (u8) type;
242
243 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
244 "%4.4s (%s) [Node %p Owner %3.3X] added to %4.4s (%s) [Node %p]\n",
245 acpi_ut_get_node_name(node),
246 acpi_ut_get_type_name(node->type), node, owner_id,
247 acpi_ut_get_node_name(parent_node),
248 acpi_ut_get_type_name(parent_node->type),
249 parent_node));
250
251 return_VOID;
252}
253
254/*******************************************************************************
255 *
256 * FUNCTION: acpi_ns_delete_children
257 *
258 * PARAMETERS: parent_node - Delete this objects children
259 *
260 * RETURN: None.
261 *
262 * DESCRIPTION: Delete all children of the parent object. In other words,
263 * deletes a "scope".
264 *
265 ******************************************************************************/
266
267void acpi_ns_delete_children(struct acpi_namespace_node *parent_node)
268{
269 struct acpi_namespace_node *next_node;
270 struct acpi_namespace_node *node_to_delete;
271
272 ACPI_FUNCTION_TRACE_PTR(ns_delete_children, parent_node);
273
274 if (!parent_node) {
275 return_VOID;
276 }
277
278 /* Deallocate all children at this level */
279
280 next_node = parent_node->child;
281 while (next_node) {
282
283 /* Grandchildren should have all been deleted already */
284
285 if (next_node->child) {
286 ACPI_ERROR((AE_INFO, "Found a grandchild! P=%p C=%p",
287 parent_node, next_node));
288 }
289
290 /*
291 * Delete this child node and move on to the next child in the list.
292 * No need to unlink the node since we are deleting the entire branch.
293 */
294 node_to_delete = next_node;
295 next_node = next_node->peer;
296 acpi_ns_delete_node(node_to_delete);
297 };
298
299 /* Clear the parent's child pointer */
300
301 parent_node->child = NULL;
302 return_VOID;
303}
304
305/*******************************************************************************
306 *
307 * FUNCTION: acpi_ns_delete_namespace_subtree
308 *
309 * PARAMETERS: parent_node - Root of the subtree to be deleted
310 *
311 * RETURN: None.
312 *
313 * DESCRIPTION: Delete a subtree of the namespace. This includes all objects
314 * stored within the subtree.
315 *
316 ******************************************************************************/
317
318void acpi_ns_delete_namespace_subtree(struct acpi_namespace_node *parent_node)
319{
320 struct acpi_namespace_node *child_node = NULL;
321 u32 level = 1;
322 acpi_status status;
323
324 ACPI_FUNCTION_TRACE(ns_delete_namespace_subtree);
325
326 if (!parent_node) {
327 return_VOID;
328 }
329
330 /* Lock namespace for possible update */
331
332 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
333 if (ACPI_FAILURE(status)) {
334 return_VOID;
335 }
336
337 /*
338 * Traverse the tree of objects until we bubble back up
339 * to where we started.
340 */
341 while (level > 0) {
342
343 /* Get the next node in this scope (NULL if none) */
344
345 child_node = acpi_ns_get_next_node(parent_node, child_node);
346 if (child_node) {
347
348 /* Found a child node - detach any attached object */
349
350 acpi_ns_detach_object(child_node);
351
352 /* Check if this node has any children */
353
354 if (child_node->child) {
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 }
363 } else {
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 */
374 acpi_ns_delete_children(parent_node);
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
382 parent_node = parent_node->parent;
383 }
384 }
385
386 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
387 return_VOID;
388}
389
390/*******************************************************************************
391 *
392 * FUNCTION: acpi_ns_delete_namespace_by_owner
393 *
394 * PARAMETERS: owner_id - All nodes with this owner will be deleted
395 *
396 * RETURN: Status
397 *
398 * DESCRIPTION: Delete entries within the namespace that are owned by a
399 * specific ID. Used to delete entire ACPI tables. All
400 * reference counts are updated.
401 *
402 * MUTEX: Locks namespace during deletion walk.
403 *
404 ******************************************************************************/
405
406void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id)
407{
408 struct acpi_namespace_node *child_node;
409 struct acpi_namespace_node *deletion_node;
410 struct acpi_namespace_node *parent_node;
411 u32 level;
412 acpi_status status;
413
414 ACPI_FUNCTION_TRACE_U32(ns_delete_namespace_by_owner, owner_id);
415
416 if (owner_id == 0) {
417 return_VOID;
418 }
419
420 /* Lock namespace for possible update */
421
422 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
423 if (ACPI_FAILURE(status)) {
424 return_VOID;
425 }
426
427 deletion_node = NULL;
428 parent_node = acpi_gbl_root_node;
429 child_node = NULL;
430 level = 1;
431
432 /*
433 * Traverse the tree of nodes until we bubble back up
434 * to where we started.
435 */
436 while (level > 0) {
437 /*
438 * Get the next child of this parent node. When child_node is NULL,
439 * the first child of the parent is returned
440 */
441 child_node = acpi_ns_get_next_node(parent_node, child_node);
442
443 if (deletion_node) {
444 acpi_ns_delete_children(deletion_node);
445 acpi_ns_remove_node(deletion_node);
446 deletion_node = NULL;
447 }
448
449 if (child_node) {
450 if (child_node->owner_id == owner_id) {
451
452 /* Found a matching child node - detach any attached object */
453
454 acpi_ns_detach_object(child_node);
455 }
456
457 /* Check if this node has any children */
458
459 if (child_node->child) {
460 /*
461 * There is at least one child of this node,
462 * visit the node
463 */
464 level++;
465 parent_node = child_node;
466 child_node = NULL;
467 } else if (child_node->owner_id == owner_id) {
468 deletion_node = child_node;
469 }
470 } else {
471 /*
472 * No more children of this parent node.
473 * Move up to the grandparent.
474 */
475 level--;
476 if (level != 0) {
477 if (parent_node->owner_id == owner_id) {
478 deletion_node = parent_node;
479 }
480 }
481
482 /* New "last child" is this parent node */
483
484 child_node = parent_node;
485
486 /* Move up the tree to the grandparent */
487
488 parent_node = parent_node->parent;
489 }
490 }
491
492 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
493 return_VOID;
494}
1/*******************************************************************************
2 *
3 * Module Name: nsalloc - Namespace allocation and deletion utilities
4 *
5 ******************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2016, Intel Corp.
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
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "acnamesp.h"
47
48#define _COMPONENT ACPI_NAMESPACE
49ACPI_MODULE_NAME("nsalloc")
50
51/*******************************************************************************
52 *
53 * FUNCTION: acpi_ns_create_node
54 *
55 * PARAMETERS: name - Name of the new node (4 char ACPI name)
56 *
57 * RETURN: New namespace node (Null on failure)
58 *
59 * DESCRIPTION: Create a namespace node
60 *
61 ******************************************************************************/
62struct acpi_namespace_node *acpi_ns_create_node(u32 name)
63{
64 struct acpi_namespace_node *node;
65#ifdef ACPI_DBG_TRACK_ALLOCATIONS
66 u32 temp;
67#endif
68
69 ACPI_FUNCTION_TRACE(ns_create_node);
70
71 node = acpi_os_acquire_object(acpi_gbl_namespace_cache);
72 if (!node) {
73 return_PTR(NULL);
74 }
75
76 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_allocated++);
77
78#ifdef ACPI_DBG_TRACK_ALLOCATIONS
79 temp = 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
86 node->name.integer = name;
87 ACPI_SET_DESCRIPTOR_TYPE(node, ACPI_DESC_TYPE_NAMED);
88 return_PTR(node);
89}
90
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. 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.
103 *
104 ******************************************************************************/
105
106void acpi_ns_delete_node(struct acpi_namespace_node *node)
107{
108 union acpi_operand_object *obj_desc;
109 union acpi_operand_object *next_desc;
110
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 /*
118 * 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.
122 */
123 obj_desc = node->object;
124 while (obj_desc && (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA)) {
125
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
132 next_desc = obj_desc->common.next_object;
133 acpi_ut_remove_reference(obj_desc);
134 obj_desc = next_desc;
135 }
136
137 /* Special case for the statically allocated root node */
138
139 if (node == acpi_gbl_root_node) {
140 return;
141 }
142
143 /* Now we can delete the node */
144
145 (void)acpi_os_release_object(acpi_gbl_namespace_cache, node);
146
147 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_freed++);
148 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Node %p, Remaining %X\n",
149 node, acpi_gbl_current_node_count));
150}
151
152/*******************************************************************************
153 *
154 * FUNCTION: acpi_ns_remove_node
155 *
156 * PARAMETERS: node - Node to be removed/deleted
157 *
158 * RETURN: None
159 *
160 * DESCRIPTION: Remove (unlink) and delete a namespace node
161 *
162 ******************************************************************************/
163
164void acpi_ns_remove_node(struct acpi_namespace_node *node)
165{
166 struct acpi_namespace_node *parent_node;
167 struct acpi_namespace_node *prev_node;
168 struct acpi_namespace_node *next_node;
169
170 ACPI_FUNCTION_TRACE_PTR(ns_remove_node, node);
171
172 parent_node = node->parent;
173
174 prev_node = NULL;
175 next_node = parent_node->child;
176
177 /* Find the node that is the previous peer in the parent's child list */
178
179 while (next_node != node) {
180 prev_node = next_node;
181 next_node = next_node->peer;
182 }
183
184 if (prev_node) {
185
186 /* Node is not first child, unlink it */
187
188 prev_node->peer = node->peer;
189 } else {
190 /*
191 * Node is first child (has no previous peer).
192 * Link peer list to parent
193 */
194 parent_node->child = node->peer;
195 }
196
197 /* Delete the node and any attached objects */
198
199 acpi_ns_delete_node(node);
200 return_VOID;
201}
202
203/*******************************************************************************
204 *
205 * FUNCTION: acpi_ns_install_node
206 *
207 * PARAMETERS: walk_state - Current state of the walk
208 * parent_node - The parent of the new Node
209 * node - The new Node to install
210 * type - ACPI object type of the new Node
211 *
212 * RETURN: None
213 *
214 * DESCRIPTION: Initialize a new namespace node and install it amongst
215 * its peers.
216 *
217 * Note: Current namespace lookup is linear search. This appears
218 * to be sufficient as namespace searches consume only a small
219 * fraction of the execution time of the ACPI subsystem.
220 *
221 ******************************************************************************/
222
223void acpi_ns_install_node(struct acpi_walk_state *walk_state, struct acpi_namespace_node *parent_node, /* Parent */
224 struct acpi_namespace_node *node, /* New Child */
225 acpi_object_type type)
226{
227 acpi_owner_id owner_id = 0;
228 struct acpi_namespace_node *child_node;
229
230 ACPI_FUNCTION_TRACE(ns_install_node);
231
232 if (walk_state) {
233 /*
234 * Get the owner ID from the Walk state. The owner ID is used to
235 * track table deletion and deletion of objects created by methods.
236 */
237 owner_id = walk_state->owner_id;
238
239 if ((walk_state->method_desc) &&
240 (parent_node != walk_state->method_node)) {
241 /*
242 * A method is creating a new node that is not a child of the
243 * method (it is non-local). Mark the executing method as having
244 * modified the namespace. This is used for cleanup when the
245 * method exits.
246 */
247 walk_state->method_desc->method.info_flags |=
248 ACPI_METHOD_MODIFIED_NAMESPACE;
249 }
250 }
251
252 /* Link the new entry into the parent and existing children */
253
254 node->peer = NULL;
255 node->parent = parent_node;
256 child_node = parent_node->child;
257
258 if (!child_node) {
259 parent_node->child = node;
260 } else {
261 /* Add node to the end of the peer list */
262
263 while (child_node->peer) {
264 child_node = child_node->peer;
265 }
266
267 child_node->peer = node;
268 }
269
270 /* Init the new entry */
271
272 node->owner_id = owner_id;
273 node->type = (u8) type;
274
275 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
276 "%4.4s (%s) [Node %p Owner %X] added to %4.4s (%s) [Node %p]\n",
277 acpi_ut_get_node_name(node),
278 acpi_ut_get_type_name(node->type), node, owner_id,
279 acpi_ut_get_node_name(parent_node),
280 acpi_ut_get_type_name(parent_node->type),
281 parent_node));
282
283 return_VOID;
284}
285
286/*******************************************************************************
287 *
288 * FUNCTION: acpi_ns_delete_children
289 *
290 * PARAMETERS: parent_node - Delete this objects children
291 *
292 * RETURN: None.
293 *
294 * DESCRIPTION: Delete all children of the parent object. In other words,
295 * deletes a "scope".
296 *
297 ******************************************************************************/
298
299void acpi_ns_delete_children(struct acpi_namespace_node *parent_node)
300{
301 struct acpi_namespace_node *next_node;
302 struct acpi_namespace_node *node_to_delete;
303
304 ACPI_FUNCTION_TRACE_PTR(ns_delete_children, parent_node);
305
306 if (!parent_node) {
307 return_VOID;
308 }
309
310 /* Deallocate all children at this level */
311
312 next_node = parent_node->child;
313 while (next_node) {
314
315 /* Grandchildren should have all been deleted already */
316
317 if (next_node->child) {
318 ACPI_ERROR((AE_INFO, "Found a grandchild! P=%p C=%p",
319 parent_node, next_node));
320 }
321
322 /*
323 * Delete this child node and move on to the next child in the list.
324 * No need to unlink the node since we are deleting the entire branch.
325 */
326 node_to_delete = next_node;
327 next_node = next_node->peer;
328 acpi_ns_delete_node(node_to_delete);
329 };
330
331 /* Clear the parent's child pointer */
332
333 parent_node->child = NULL;
334 return_VOID;
335}
336
337/*******************************************************************************
338 *
339 * FUNCTION: acpi_ns_delete_namespace_subtree
340 *
341 * PARAMETERS: parent_node - Root of the subtree to be deleted
342 *
343 * RETURN: None.
344 *
345 * DESCRIPTION: Delete a subtree of the namespace. This includes all objects
346 * stored within the subtree.
347 *
348 ******************************************************************************/
349
350void acpi_ns_delete_namespace_subtree(struct acpi_namespace_node *parent_node)
351{
352 struct acpi_namespace_node *child_node = NULL;
353 u32 level = 1;
354 acpi_status status;
355
356 ACPI_FUNCTION_TRACE(ns_delete_namespace_subtree);
357
358 if (!parent_node) {
359 return_VOID;
360 }
361
362 /* Lock namespace for possible update */
363
364 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
365 if (ACPI_FAILURE(status)) {
366 return_VOID;
367 }
368
369 /*
370 * Traverse the tree of objects until we bubble back up
371 * to where we started.
372 */
373 while (level > 0) {
374
375 /* Get the next node in this scope (NULL if none) */
376
377 child_node = acpi_ns_get_next_node(parent_node, child_node);
378 if (child_node) {
379
380 /* Found a child node - detach any attached object */
381
382 acpi_ns_detach_object(child_node);
383
384 /* Check if this node has any children */
385
386 if (child_node->child) {
387 /*
388 * There is at least one child of this node,
389 * visit the node
390 */
391 level++;
392 parent_node = child_node;
393 child_node = NULL;
394 }
395 } else {
396 /*
397 * No more children of this parent node.
398 * Move up to the grandparent.
399 */
400 level--;
401
402 /*
403 * Now delete all of the children of this parent
404 * all at the same time.
405 */
406 acpi_ns_delete_children(parent_node);
407
408 /* New "last child" is this parent node */
409
410 child_node = parent_node;
411
412 /* Move up the tree to the grandparent */
413
414 parent_node = parent_node->parent;
415 }
416 }
417
418 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
419 return_VOID;
420}
421
422/*******************************************************************************
423 *
424 * FUNCTION: acpi_ns_delete_namespace_by_owner
425 *
426 * PARAMETERS: owner_id - All nodes with this owner will be deleted
427 *
428 * RETURN: Status
429 *
430 * DESCRIPTION: Delete entries within the namespace that are owned by a
431 * specific ID. Used to delete entire ACPI tables. All
432 * reference counts are updated.
433 *
434 * MUTEX: Locks namespace during deletion walk.
435 *
436 ******************************************************************************/
437
438void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id)
439{
440 struct acpi_namespace_node *child_node;
441 struct acpi_namespace_node *deletion_node;
442 struct acpi_namespace_node *parent_node;
443 u32 level;
444 acpi_status status;
445
446 ACPI_FUNCTION_TRACE_U32(ns_delete_namespace_by_owner, owner_id);
447
448 if (owner_id == 0) {
449 return_VOID;
450 }
451
452 /* Lock namespace for possible update */
453
454 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
455 if (ACPI_FAILURE(status)) {
456 return_VOID;
457 }
458
459 deletion_node = NULL;
460 parent_node = acpi_gbl_root_node;
461 child_node = NULL;
462 level = 1;
463
464 /*
465 * Traverse the tree of nodes until we bubble back up
466 * to where we started.
467 */
468 while (level > 0) {
469 /*
470 * Get the next child of this parent node. When child_node is NULL,
471 * the first child of the parent is returned
472 */
473 child_node = acpi_ns_get_next_node(parent_node, child_node);
474
475 if (deletion_node) {
476 acpi_ns_delete_children(deletion_node);
477 acpi_ns_remove_node(deletion_node);
478 deletion_node = NULL;
479 }
480
481 if (child_node) {
482 if (child_node->owner_id == owner_id) {
483
484 /* Found a matching child node - detach any attached object */
485
486 acpi_ns_detach_object(child_node);
487 }
488
489 /* Check if this node has any children */
490
491 if (child_node->child) {
492 /*
493 * There is at least one child of this node,
494 * visit the node
495 */
496 level++;
497 parent_node = child_node;
498 child_node = NULL;
499 } else if (child_node->owner_id == owner_id) {
500 deletion_node = child_node;
501 }
502 } else {
503 /*
504 * No more children of this parent node.
505 * Move up to the grandparent.
506 */
507 level--;
508 if (level != 0) {
509 if (parent_node->owner_id == owner_id) {
510 deletion_node = parent_node;
511 }
512 }
513
514 /* New "last child" is this parent node */
515
516 child_node = parent_node;
517
518 /* Move up the tree to the grandparent */
519
520 parent_node = parent_node->parent;
521 }
522 }
523
524 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
525 return_VOID;
526}