Also document BGE_FAKE_AUTONEG in LINT.
[dragonfly.git] / sys / contrib / dev / acpica / nsalloc.c
1 /*******************************************************************************
2  *
3  * Module Name: nsalloc - Namespace allocation and deletion utilities
4  *              $Revision: 82 $
5  *
6  ******************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/nsalloc.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $                                                               */
117
118
119 #define __NSALLOC_C__
120
121 #include "acpi.h"
122 #include "acnamesp.h"
123
124
125 #define _COMPONENT          ACPI_NAMESPACE
126         ACPI_MODULE_NAME    ("nsalloc")
127
128
129 /*******************************************************************************
130  *
131  * FUNCTION:    AcpiNsCreateNode
132  *
133  * PARAMETERS:  AcpiName        - Name of the new node
134  *
135  * RETURN:      None
136  *
137  * DESCRIPTION: Create a namespace node
138  *
139  ******************************************************************************/
140
141 ACPI_NAMESPACE_NODE *
142 AcpiNsCreateNode (
143     UINT32                  Name)
144 {
145     ACPI_NAMESPACE_NODE     *Node;
146
147
148     ACPI_FUNCTION_TRACE ("NsCreateNode");
149
150
151     Node = ACPI_MEM_CALLOCATE (sizeof (ACPI_NAMESPACE_NODE));
152     if (!Node)
153     {
154         return_PTR (NULL);
155     }
156
157     ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalAllocated++);
158
159     Node->Name.Integer   = Name;
160     Node->ReferenceCount = 1;
161     ACPI_SET_DESCRIPTOR_TYPE (Node, ACPI_DESC_TYPE_NAMED);
162
163     return_PTR (Node);
164 }
165
166
167 /*******************************************************************************
168  *
169  * FUNCTION:    AcpiNsDeleteNode
170  *
171  * PARAMETERS:  Node            - Node to be deleted
172  *
173  * RETURN:      None
174  *
175  * DESCRIPTION: Delete a namespace node
176  *
177  ******************************************************************************/
178
179 void
180 AcpiNsDeleteNode (
181     ACPI_NAMESPACE_NODE     *Node)
182 {
183     ACPI_NAMESPACE_NODE     *ParentNode;
184     ACPI_NAMESPACE_NODE     *PrevNode;
185     ACPI_NAMESPACE_NODE     *NextNode;
186
187
188     ACPI_FUNCTION_TRACE_PTR ("NsDeleteNode", Node);
189
190
191     ParentNode = AcpiNsGetParentNode (Node);
192
193     PrevNode = NULL;
194     NextNode = ParentNode->Child;
195
196     /* Find the node that is the previous peer in the parent's child list */
197
198     while (NextNode != Node)
199     {
200         PrevNode = NextNode;
201         NextNode = PrevNode->Peer;
202     }
203
204     if (PrevNode)
205     {
206         /* Node is not first child, unlink it */
207
208         PrevNode->Peer = NextNode->Peer;
209         if (NextNode->Flags & ANOBJ_END_OF_PEER_LIST)
210         {
211             PrevNode->Flags |= ANOBJ_END_OF_PEER_LIST;
212         }
213     }
214     else
215     {
216         /* Node is first child (has no previous peer) */
217
218         if (NextNode->Flags & ANOBJ_END_OF_PEER_LIST)
219         {
220             /* No peers at all */
221
222             ParentNode->Child = NULL;
223         }
224         else
225         {   /* Link peer list to parent */
226
227             ParentNode->Child = NextNode->Peer;
228         }
229     }
230
231
232     ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalFreed++);
233
234     /*
235      * Detach an object if there is one then delete the node
236      */
237     AcpiNsDetachObject (Node);
238     ACPI_MEM_FREE (Node);
239     return_VOID;
240 }
241
242
243 #ifdef ACPI_ALPHABETIC_NAMESPACE
244 /*******************************************************************************
245  *
246  * FUNCTION:    AcpiNsCompareNames
247  *
248  * PARAMETERS:  Name1           - First name to compare
249  *              Name2           - Second name to compare
250  *
251  * RETURN:      value from strncmp
252  *
253  * DESCRIPTION: Compare two ACPI names.  Names that are prefixed with an
254  *              underscore are forced to be alphabetically first.
255  *
256  ******************************************************************************/
257
258 int
259 AcpiNsCompareNames (
260     char                    *Name1,
261     char                    *Name2)
262 {
263     char                    ReversedName1[ACPI_NAME_SIZE];
264     char                    ReversedName2[ACPI_NAME_SIZE];
265     UINT32                  i;
266     UINT32                  j;
267
268
269     /*
270      * Replace all instances of "underscore" with a value that is smaller so
271      * that all names that are prefixed with underscore(s) are alphabetically
272      * first.
273      *
274      * Reverse the name bytewise so we can just do a 32-bit compare instead
275      * of a strncmp.
276      */
277     for (i = 0, j= (ACPI_NAME_SIZE - 1); i < ACPI_NAME_SIZE; i++, j--)
278     {
279         ReversedName1[j] = Name1[i];
280         if (Name1[i] == '_')
281         {
282             ReversedName1[j] = '*';
283         }
284
285         ReversedName2[j] = Name2[i];
286         if (Name2[i] == '_')
287         {
288             ReversedName2[j] = '*';
289         }
290     }
291
292     return (*(int *) ReversedName1 - *(int *) ReversedName2);
293 }
294 #endif
295
296
297 /*******************************************************************************
298  *
299  * FUNCTION:    AcpiNsInstallNode
300  *
301  * PARAMETERS:  WalkState       - Current state of the walk
302  *              ParentNode      - The parent of the new Node
303  *              Node            - The new Node to install
304  *              Type            - ACPI object type of the new Node
305  *
306  * RETURN:      None
307  *
308  * DESCRIPTION: Initialize a new namespace node and install it amongst
309  *              its peers.
310  *
311  *              Note: Current namespace lookup is linear search.  However, the
312  *              nodes are linked in alphabetical order to 1) put all reserved
313  *              names (start with underscore) first, and to 2) make a readable
314  *              namespace dump.
315  *
316  ******************************************************************************/
317
318 void
319 AcpiNsInstallNode (
320     ACPI_WALK_STATE         *WalkState,
321     ACPI_NAMESPACE_NODE     *ParentNode,    /* Parent */
322     ACPI_NAMESPACE_NODE     *Node,          /* New Child*/
323     ACPI_OBJECT_TYPE        Type)
324 {
325     UINT16                  OwnerId = TABLE_ID_DSDT;
326     ACPI_NAMESPACE_NODE     *ChildNode;
327 #ifdef ACPI_ALPHABETIC_NAMESPACE
328
329     ACPI_NAMESPACE_NODE     *PreviousChildNode;
330 #endif
331
332
333     ACPI_FUNCTION_TRACE ("NsInstallNode");
334
335
336     /*
337      * Get the owner ID from the Walk state
338      * The owner ID is used to track table deletion and
339      * deletion of objects created by methods
340      */
341     if (WalkState)
342     {
343         OwnerId = WalkState->OwnerId;
344     }
345
346     /* Link the new entry into the parent and existing children */
347
348     ChildNode = ParentNode->Child;
349     if (!ChildNode)
350     {
351         ParentNode->Child = Node;
352         Node->Flags |= ANOBJ_END_OF_PEER_LIST;
353         Node->Peer = ParentNode;
354     }
355     else
356     {
357 #ifdef ACPI_ALPHABETIC_NAMESPACE
358         /*
359          * Walk the list whilst searching for the the correct
360          * alphabetic placement.
361          */
362         PreviousChildNode = NULL;
363         while (AcpiNsCompareNames (ChildNode->Name.Ascii, Node->Name.Ascii) < 0)
364         {
365             if (ChildNode->Flags & ANOBJ_END_OF_PEER_LIST)
366             {
367                 /* Last peer;  Clear end-of-list flag */
368
369                 ChildNode->Flags &= ~ANOBJ_END_OF_PEER_LIST;
370
371                 /* This node is the new peer to the child node */
372
373                 ChildNode->Peer = Node;
374
375                 /* This node is the new end-of-list */
376
377                 Node->Flags |= ANOBJ_END_OF_PEER_LIST;
378                 Node->Peer = ParentNode;
379                 break;
380             }
381
382             /* Get next peer */
383
384             PreviousChildNode = ChildNode;
385             ChildNode = ChildNode->Peer;
386         }
387
388         /* Did the node get inserted at the end-of-list? */
389
390         if (!(Node->Flags & ANOBJ_END_OF_PEER_LIST))
391         {
392             /*
393              * Loop above terminated without reaching the end-of-list.
394              * Insert the new node at the current location
395              */
396             if (PreviousChildNode)
397             {
398                 /* Insert node alphabetically */
399
400                 Node->Peer = ChildNode;
401                 PreviousChildNode->Peer = Node;
402             }
403             else
404             {
405                 /* Insert node alphabetically at start of list */
406
407                 Node->Peer = ChildNode;
408                 ParentNode->Child = Node;
409             }
410         }
411 #else
412         while (!(ChildNode->Flags & ANOBJ_END_OF_PEER_LIST))
413         {
414             ChildNode = ChildNode->Peer;
415         }
416
417         ChildNode->Peer = Node;
418
419         /* Clear end-of-list flag */
420
421         ChildNode->Flags &= ~ANOBJ_END_OF_PEER_LIST;
422         Node->Flags     |= ANOBJ_END_OF_PEER_LIST;
423         Node->Peer = ParentNode;
424 #endif
425     }
426
427     /* Init the new entry */
428
429     Node->OwnerId = OwnerId;
430     Node->Type = (UINT8) Type;
431
432     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%4.4s (%s) added to %4.4s (%s) %p at %p\n",
433         Node->Name.Ascii, AcpiUtGetTypeName (Node->Type),
434         ParentNode->Name.Ascii, AcpiUtGetTypeName (ParentNode->Type), ParentNode, Node));
435
436     /*
437      * Increment the reference count(s) of all parents up to
438      * the root!
439      */
440     while ((Node = AcpiNsGetParentNode (Node)) != NULL)
441     {
442         Node->ReferenceCount++;
443     }
444
445     return_VOID;
446 }
447
448
449 /*******************************************************************************
450  *
451  * FUNCTION:    AcpiNsDeleteChildren
452  *
453  * PARAMETERS:  ParentNode      - Delete this objects children
454  *
455  * RETURN:      None.
456  *
457  * DESCRIPTION: Delete all children of the parent object. In other words,
458  *              deletes a "scope".
459  *
460  ******************************************************************************/
461
462 void
463 AcpiNsDeleteChildren (
464     ACPI_NAMESPACE_NODE     *ParentNode)
465 {
466     ACPI_NAMESPACE_NODE     *ChildNode;
467     ACPI_NAMESPACE_NODE     *NextNode;
468     ACPI_NAMESPACE_NODE     *Node;
469     UINT8                   Flags;
470
471
472     ACPI_FUNCTION_TRACE_PTR ("NsDeleteChildren", ParentNode);
473
474
475     if (!ParentNode)
476     {
477         return_VOID;
478     }
479
480     /* If no children, all done! */
481
482     ChildNode = ParentNode->Child;
483     if (!ChildNode)
484     {
485         return_VOID;
486     }
487
488     /*
489      * Deallocate all children at this level
490      */
491     do
492     {
493         /* Get the things we need */
494
495         NextNode    = ChildNode->Peer;
496         Flags       = ChildNode->Flags;
497
498         /* Grandchildren should have all been deleted already */
499
500         if (ChildNode->Child)
501         {
502             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Found a grandchild! P=%p C=%p\n",
503                 ParentNode, ChildNode));
504         }
505
506         /* Now we can free this child object */
507
508         ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalFreed++);
509
510         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Object %p, Remaining %X\n",
511             ChildNode, AcpiGbl_CurrentNodeCount));
512
513         /*
514          * Detach an object if there is one, then free the child node
515          */
516         AcpiNsDetachObject (ChildNode);
517
518         /*
519          * Decrement the reference count(s) of all parents up to
520          * the root! (counts were incremented when the node was created)
521          */
522         Node = ChildNode;
523         while ((Node = AcpiNsGetParentNode (Node)) != NULL)
524         {
525             Node->ReferenceCount--;
526         }
527
528         /* There should be only one reference remaining on this node */
529
530         if (ChildNode->ReferenceCount != 1)
531         {
532             ACPI_REPORT_WARNING (("Existing references (%d) on node being deleted (%p)\n",
533                 ChildNode->ReferenceCount, ChildNode));
534         }
535
536         /* Now we can delete the node */
537
538         ACPI_MEM_FREE (ChildNode);
539
540         /* And move on to the next child in the list */
541
542         ChildNode = NextNode;
543
544     } while (!(Flags & ANOBJ_END_OF_PEER_LIST));
545
546
547     /* Clear the parent's child pointer */
548
549     ParentNode->Child = NULL;
550
551     return_VOID;
552 }
553
554
555 /*******************************************************************************
556  *
557  * FUNCTION:    AcpiNsDeleteNamespaceSubtree
558  *
559  * PARAMETERS:  ParentNode      - Root of the subtree to be deleted
560  *
561  * RETURN:      None.
562  *
563  * DESCRIPTION: Delete a subtree of the namespace.  This includes all objects
564  *              stored within the subtree.
565  *
566  ******************************************************************************/
567
568 void
569 AcpiNsDeleteNamespaceSubtree (
570     ACPI_NAMESPACE_NODE     *ParentNode)
571 {
572     ACPI_NAMESPACE_NODE     *ChildNode = NULL;
573     UINT32                  Level = 1;
574
575
576     ACPI_FUNCTION_TRACE ("NsDeleteNamespaceSubtree");
577
578
579     if (!ParentNode)
580     {
581         return_VOID;
582     }
583
584     /*
585      * Traverse the tree of objects until we bubble back up
586      * to where we started.
587      */
588     while (Level > 0)
589     {
590         /* Get the next node in this scope (NULL if none) */
591
592         ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode,
593                                             ChildNode);
594         if (ChildNode)
595         {
596             /* Found a child node - detach any attached object */
597
598             AcpiNsDetachObject (ChildNode);
599
600             /* Check if this node has any children */
601
602             if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, 0))
603             {
604                 /*
605                  * There is at least one child of this node,
606                  * visit the node
607                  */
608                 Level++;
609                 ParentNode    = ChildNode;
610                 ChildNode     = 0;
611             }
612         }
613         else
614         {
615             /*
616              * No more children of this parent node.
617              * Move up to the grandparent.
618              */
619             Level--;
620
621             /*
622              * Now delete all of the children of this parent
623              * all at the same time.
624              */
625             AcpiNsDeleteChildren (ParentNode);
626
627             /* New "last child" is this parent node */
628
629             ChildNode = ParentNode;
630
631             /* Move up the tree to the grandparent */
632
633             ParentNode = AcpiNsGetParentNode (ParentNode);
634         }
635     }
636
637     return_VOID;
638 }
639
640
641 /*******************************************************************************
642  *
643  * FUNCTION:    AcpiNsRemoveReference
644  *
645  * PARAMETERS:  Node           - Named node whose reference count is to be
646  *                               decremented
647  *
648  * RETURN:      None.
649  *
650  * DESCRIPTION: Remove a Node reference.  Decrements the reference count
651  *              of all parent Nodes up to the root.  Any node along
652  *              the way that reaches zero references is freed.
653  *
654  ******************************************************************************/
655
656 static void
657 AcpiNsRemoveReference (
658     ACPI_NAMESPACE_NODE     *Node)
659 {
660     ACPI_NAMESPACE_NODE     *ParentNode;
661     ACPI_NAMESPACE_NODE     *ThisNode;
662
663
664     ACPI_FUNCTION_ENTRY ();
665
666
667     /*
668      * Decrement the reference count(s) of this node and all
669      * nodes up to the root,  Delete anything with zero remaining references.
670      */
671     ThisNode = Node;
672     while (ThisNode)
673     {
674         /* Prepare to move up to parent */
675
676         ParentNode = AcpiNsGetParentNode (ThisNode);
677
678         /* Decrement the reference count on this node */
679
680         ThisNode->ReferenceCount--;
681
682         /* Delete the node if no more references */
683
684         if (!ThisNode->ReferenceCount)
685         {
686             /* Delete all children and delete the node */
687
688             AcpiNsDeleteChildren (ThisNode);
689             AcpiNsDeleteNode (ThisNode);
690         }
691
692         ThisNode = ParentNode;
693     }
694 }
695
696
697 /*******************************************************************************
698  *
699  * FUNCTION:    AcpiNsDeleteNamespaceByOwner
700  *
701  * PARAMETERS:  OwnerId     - All nodes with this owner will be deleted
702  *
703  * RETURN:      Status
704  *
705  * DESCRIPTION: Delete entries within the namespace that are owned by a
706  *              specific ID.  Used to delete entire ACPI tables.  All
707  *              reference counts are updated.
708  *
709  ******************************************************************************/
710
711 void
712 AcpiNsDeleteNamespaceByOwner (
713     UINT16                  OwnerId)
714 {
715     ACPI_NAMESPACE_NODE     *ChildNode;
716     ACPI_NAMESPACE_NODE     *DeletionNode;
717     UINT32                  Level;
718     ACPI_NAMESPACE_NODE     *ParentNode;
719
720
721     ACPI_FUNCTION_TRACE_U32 ("NsDeleteNamespaceByOwner", OwnerId);
722
723
724     ParentNode    = AcpiGbl_RootNode;
725     ChildNode     = NULL;
726     DeletionNode  = NULL;
727     Level         = 1;
728
729     /*
730      * Traverse the tree of nodes until we bubble back up
731      * to where we started.
732      */
733     while (Level > 0)
734     {
735         /*
736          * Get the next child of this parent node. When ChildNode is NULL,
737          * the first child of the parent is returned
738          */
739         ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode, ChildNode);
740
741         if (DeletionNode)
742         {
743             AcpiNsRemoveReference (DeletionNode);
744             DeletionNode = NULL;
745         }
746
747         if (ChildNode)
748         {
749             if (ChildNode->OwnerId == OwnerId)
750             {
751                 /* Found a matching child node - detach any attached object */
752
753                 AcpiNsDetachObject (ChildNode);
754             }
755
756             /* Check if this node has any children */
757
758             if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, NULL))
759             {
760                 /*
761                  * There is at least one child of this node,
762                  * visit the node
763                  */
764                 Level++;
765                 ParentNode    = ChildNode;
766                 ChildNode     = NULL;
767             }
768             else if (ChildNode->OwnerId == OwnerId)
769             {
770                 DeletionNode = ChildNode;
771             }
772         }
773         else
774         {
775             /*
776              * No more children of this parent node.
777              * Move up to the grandparent.
778              */
779             Level--;
780             if (Level != 0)
781             {
782                 if (ParentNode->OwnerId == OwnerId)
783                 {
784                     DeletionNode = ParentNode;
785                 }
786             }
787
788             /* New "last child" is this parent node */
789
790             ChildNode = ParentNode;
791
792             /* Move up the tree to the grandparent */
793
794             ParentNode = AcpiNsGetParentNode (ParentNode);
795         }
796     }
797
798     return_VOID;
799 }
800
801