nsalloc.c revision 99679
167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: nsalloc - Namespace allocation and deletion utilities
499679Siwasaki *              $Revision: 74 $
567754Smsmith *
667754Smsmith ******************************************************************************/
767754Smsmith
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
1291116Smsmith * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
1370243Smsmith * All rights reserved.
1467754Smsmith *
1567754Smsmith * 2. License
1667754Smsmith *
1767754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
1867754Smsmith * rights.  You may have additional license terms from the party that provided
1967754Smsmith * you this software, covering your right to use that party's intellectual
2067754Smsmith * property rights.
2167754Smsmith *
2267754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2367754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2467754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2567754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2667754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2767754Smsmith * Code in any form, with the right to sublicense such rights; and
2867754Smsmith *
2967754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3067754Smsmith * license (with the right to sublicense), under only those claims of Intel
3167754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3267754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3367754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3467754Smsmith * license, and in no event shall the patent license extend to any additions
3567754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3667754Smsmith * is granted directly or by implication, estoppel or otherwise;
3767754Smsmith *
3867754Smsmith * The above copyright and patent license is granted only if the following
3967754Smsmith * conditions are met:
4067754Smsmith *
4167754Smsmith * 3. Conditions
4267754Smsmith *
4367754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4467754Smsmith * Redistribution of source code of any substantial portion of the Covered
4567754Smsmith * Code or modification with rights to further distribute source must include
4667754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4767754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
4867754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
4967754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5067754Smsmith * Code and the date of any change.  Licensee must include in that file the
5167754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5267754Smsmith * must include a prominent statement that the modification is derived,
5367754Smsmith * directly or indirectly, from Original Intel Code.
5467754Smsmith *
5567754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5667754Smsmith * Redistribution of source code of any substantial portion of the Covered
5767754Smsmith * Code or modification without rights to further distribute source must
5867754Smsmith * include the following Disclaimer and Export Compliance provision in the
5967754Smsmith * documentation and/or other materials provided with distribution.  In
6067754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6167754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6267754Smsmith * license from Licensee to its licensee is limited to the intellectual
6367754Smsmith * property embodied in the software Licensee provides to its licensee, and
6467754Smsmith * not to intellectual property embodied in modifications its licensee may
6567754Smsmith * make.
6667754Smsmith *
6767754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
6867754Smsmith * substantial portion of the Covered Code or modification must reproduce the
6967754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7067754Smsmith * provision in the documentation and/or other materials provided with the
7167754Smsmith * distribution.
7267754Smsmith *
7367754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7467754Smsmith * Intel Code.
7567754Smsmith *
7667754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7767754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
7867754Smsmith * other dealings in products derived from or relating to the Covered Code
7967754Smsmith * without prior written authorization from Intel.
8067754Smsmith *
8167754Smsmith * 4. Disclaimer and Export Compliance
8267754Smsmith *
8367754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8467754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8567754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8667754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8767754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8867754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8967754Smsmith * PARTICULAR PURPOSE.
9067754Smsmith *
9167754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9267754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9367754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9467754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9567754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9667754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9767754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9867754Smsmith * LIMITED REMEDY.
9967754Smsmith *
10067754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10167754Smsmith * software or system incorporating such software without first obtaining any
10267754Smsmith * required license or other approval from the U. S. Department of Commerce or
10367754Smsmith * any other agency or department of the United States Government.  In the
10467754Smsmith * event Licensee exports any such software from the United States or
10567754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10667754Smsmith * ensure that the distribution and export/re-export of the software is in
10767754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10867754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10967754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11067754Smsmith * software, or service, directly or indirectly, to any country for which the
11167754Smsmith * United States government or any agency thereof requires an export license,
11267754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11367754Smsmith * such license, approval or letter.
11467754Smsmith *
11567754Smsmith *****************************************************************************/
11667754Smsmith
11767754Smsmith
11867754Smsmith#define __NSALLOC_C__
11967754Smsmith
12067754Smsmith#include "acpi.h"
12167754Smsmith#include "acnamesp.h"
12267754Smsmith
12367754Smsmith
12477424Smsmith#define _COMPONENT          ACPI_NAMESPACE
12591116Smsmith        ACPI_MODULE_NAME    ("nsalloc")
12667754Smsmith
12767754Smsmith
12867754Smsmith/*******************************************************************************
12967754Smsmith *
13067754Smsmith * FUNCTION:    AcpiNsCreateNode
13167754Smsmith *
13283174Smsmith * PARAMETERS:  AcpiName        - Name of the new node
13367754Smsmith *
13467754Smsmith * RETURN:      None
13567754Smsmith *
13683174Smsmith * DESCRIPTION: Create a namespace node
13767754Smsmith *
13867754Smsmith ******************************************************************************/
13967754Smsmith
14067754SmsmithACPI_NAMESPACE_NODE *
14167754SmsmithAcpiNsCreateNode (
14284491Smsmith    UINT32                  Name)
14367754Smsmith{
14467754Smsmith    ACPI_NAMESPACE_NODE     *Node;
14567754Smsmith
14683174Smsmith
14791116Smsmith    ACPI_FUNCTION_TRACE ("NsCreateNode");
14867754Smsmith
14967754Smsmith
15080062Smsmith    Node = ACPI_MEM_CALLOCATE (sizeof (ACPI_NAMESPACE_NODE));
15167754Smsmith    if (!Node)
15267754Smsmith    {
15367754Smsmith        return_PTR (NULL);
15467754Smsmith    }
15567754Smsmith
15682367Smsmith    ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalAllocated++);
15767754Smsmith
15899146Siwasaki    Node->Name.Integer   = Name;
15967754Smsmith    Node->ReferenceCount = 1;
16091116Smsmith    ACPI_SET_DESCRIPTOR_TYPE (Node, ACPI_DESC_TYPE_NAMED);
16167754Smsmith
16267754Smsmith    return_PTR (Node);
16367754Smsmith}
16467754Smsmith
16567754Smsmith
16667754Smsmith/*******************************************************************************
16767754Smsmith *
16867754Smsmith * FUNCTION:    AcpiNsDeleteNode
16967754Smsmith *
17083174Smsmith * PARAMETERS:  Node            - Node to be deleted
17167754Smsmith *
17267754Smsmith * RETURN:      None
17367754Smsmith *
17483174Smsmith * DESCRIPTION: Delete a namespace node
17567754Smsmith *
17667754Smsmith ******************************************************************************/
17767754Smsmith
17867754Smsmithvoid
17967754SmsmithAcpiNsDeleteNode (
18067754Smsmith    ACPI_NAMESPACE_NODE     *Node)
18167754Smsmith{
18267754Smsmith    ACPI_NAMESPACE_NODE     *ParentNode;
18367754Smsmith    ACPI_NAMESPACE_NODE     *PrevNode;
18467754Smsmith    ACPI_NAMESPACE_NODE     *NextNode;
18567754Smsmith
18667754Smsmith
18791116Smsmith    ACPI_FUNCTION_TRACE_PTR ("NsDeleteNode", Node);
18867754Smsmith
18983174Smsmith
19091116Smsmith    ParentNode = AcpiNsGetParentNode (Node);
19167754Smsmith
19267754Smsmith    PrevNode = NULL;
19367754Smsmith    NextNode = ParentNode->Child;
19467754Smsmith
19567754Smsmith    while (NextNode != Node)
19667754Smsmith    {
19767754Smsmith        PrevNode = NextNode;
19867754Smsmith        NextNode = PrevNode->Peer;
19967754Smsmith    }
20067754Smsmith
20167754Smsmith    if (PrevNode)
20267754Smsmith    {
20367754Smsmith        PrevNode->Peer = NextNode->Peer;
20467754Smsmith        if (NextNode->Flags & ANOBJ_END_OF_PEER_LIST)
20567754Smsmith        {
20667754Smsmith            PrevNode->Flags |= ANOBJ_END_OF_PEER_LIST;
20767754Smsmith        }
20867754Smsmith    }
20967754Smsmith    else
21067754Smsmith    {
21167754Smsmith        ParentNode->Child = NextNode->Peer;
21267754Smsmith    }
21367754Smsmith
21467754Smsmith
21582367Smsmith    ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalFreed++);
21667754Smsmith
21767754Smsmith    /*
21887031Smsmith     * Detach an object if there is one then delete the node
21967754Smsmith     */
22087031Smsmith    AcpiNsDetachObject (Node);
22180062Smsmith    ACPI_MEM_FREE (Node);
22267754Smsmith    return_VOID;
22367754Smsmith}
22467754Smsmith
22567754Smsmith
22667754Smsmith/*******************************************************************************
22767754Smsmith *
22867754Smsmith * FUNCTION:    AcpiNsInstallNode
22967754Smsmith *
23067754Smsmith * PARAMETERS:  WalkState       - Current state of the walk
23167754Smsmith *              ParentNode      - The parent of the new Node
23283174Smsmith *              Node            - The new Node to install
23367754Smsmith *              Type            - ACPI object type of the new Node
23467754Smsmith *
23567754Smsmith * RETURN:      None
23667754Smsmith *
23787031Smsmith * DESCRIPTION: Initialize a new namespace node and install it amongst
23887031Smsmith *              its peers.
23967754Smsmith *
24087031Smsmith *              Note: Current namespace lookup is linear search, so the nodes
24191116Smsmith *              are not linked in any particular order.
24287031Smsmith *
24367754Smsmith ******************************************************************************/
24467754Smsmith
24567754Smsmithvoid
24667754SmsmithAcpiNsInstallNode (
24767754Smsmith    ACPI_WALK_STATE         *WalkState,
24867754Smsmith    ACPI_NAMESPACE_NODE     *ParentNode,    /* Parent */
24983174Smsmith    ACPI_NAMESPACE_NODE     *Node,          /* New Child*/
25091116Smsmith    ACPI_OBJECT_TYPE        Type)
25167754Smsmith{
25267754Smsmith    UINT16                  OwnerId = TABLE_ID_DSDT;
25367754Smsmith    ACPI_NAMESPACE_NODE     *ChildNode;
25467754Smsmith
25567754Smsmith
25691116Smsmith    ACPI_FUNCTION_TRACE ("NsInstallNode");
25767754Smsmith
25867754Smsmith
25967754Smsmith    /*
26067754Smsmith     * Get the owner ID from the Walk state
26167754Smsmith     * The owner ID is used to track table deletion and
26267754Smsmith     * deletion of objects created by methods
26367754Smsmith     */
26467754Smsmith    if (WalkState)
26567754Smsmith    {
26667754Smsmith        OwnerId = WalkState->OwnerId;
26767754Smsmith    }
26867754Smsmith
26987031Smsmith    /* Link the new entry into the parent and existing children */
27067754Smsmith
27167754Smsmith    ChildNode = ParentNode->Child;
27267754Smsmith    if (!ChildNode)
27367754Smsmith    {
27467754Smsmith        ParentNode->Child = Node;
27567754Smsmith    }
27667754Smsmith    else
27767754Smsmith    {
27867754Smsmith        while (!(ChildNode->Flags & ANOBJ_END_OF_PEER_LIST))
27967754Smsmith        {
28067754Smsmith            ChildNode = ChildNode->Peer;
28167754Smsmith        }
28267754Smsmith
28367754Smsmith        ChildNode->Peer = Node;
28467754Smsmith
28567754Smsmith        /* Clear end-of-list flag */
28667754Smsmith
28767754Smsmith        ChildNode->Flags &= ~ANOBJ_END_OF_PEER_LIST;
28867754Smsmith    }
28967754Smsmith
29067754Smsmith    /* Init the new entry */
29167754Smsmith
29267754Smsmith    Node->OwnerId   = OwnerId;
29367754Smsmith    Node->Flags     |= ANOBJ_END_OF_PEER_LIST;
29467754Smsmith    Node->Peer      = ParentNode;
29567754Smsmith
29667754Smsmith
29767754Smsmith    /*
29867754Smsmith     * If adding a name with unknown type, or having to
29967754Smsmith     * add the region in order to define fields in it, we
30067754Smsmith     * have a forward reference.
30167754Smsmith     */
30267754Smsmith    if ((ACPI_TYPE_ANY == Type) ||
30377424Smsmith        (INTERNAL_TYPE_FIELD_DEFN == Type) ||
30467754Smsmith        (INTERNAL_TYPE_BANK_FIELD_DEFN == Type))
30567754Smsmith    {
30667754Smsmith        /*
30767754Smsmith         * We don't want to abort here, however!
30867754Smsmith         * We will fill in the actual type when the
30967754Smsmith         * real definition is found later.
31067754Smsmith         */
31199146Siwasaki        ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "[%4.4s] is a forward reference\n",
31299679Siwasaki            Node->Name.Ascii));
31367754Smsmith    }
31467754Smsmith
31567754Smsmith    /*
31667754Smsmith     * The DefFieldDefn and BankFieldDefn cases are actually
31767754Smsmith     * looking up the Region in which the field will be defined
31867754Smsmith     */
31977424Smsmith    if ((INTERNAL_TYPE_FIELD_DEFN == Type) ||
32067754Smsmith        (INTERNAL_TYPE_BANK_FIELD_DEFN == Type))
32167754Smsmith    {
32267754Smsmith        Type = ACPI_TYPE_REGION;
32367754Smsmith    }
32467754Smsmith
32567754Smsmith    /*
32667754Smsmith     * Scope, DefAny, and IndexFieldDefn are bogus "types" which do
32767754Smsmith     * not actually have anything to do with the type of the name
32867754Smsmith     * being looked up.  Save any other value of Type as the type of
32967754Smsmith     * the entry.
33067754Smsmith     */
33167754Smsmith    if ((Type != INTERNAL_TYPE_SCOPE) &&
33267754Smsmith        (Type != INTERNAL_TYPE_DEF_ANY) &&
33367754Smsmith        (Type != INTERNAL_TYPE_INDEX_FIELD_DEFN))
33467754Smsmith    {
33567754Smsmith        Node->Type = (UINT8) Type;
33667754Smsmith    }
33767754Smsmith
33882367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%4.4s added to %p at %p\n",
33999679Siwasaki        Node->Name.Ascii, ParentNode, Node));
34067754Smsmith
34167754Smsmith    /*
34267754Smsmith     * Increment the reference count(s) of all parents up to
34367754Smsmith     * the root!
34467754Smsmith     */
34591116Smsmith    while ((Node = AcpiNsGetParentNode (Node)) != NULL)
34667754Smsmith    {
34767754Smsmith        Node->ReferenceCount++;
34867754Smsmith    }
34967754Smsmith
35067754Smsmith    return_VOID;
35167754Smsmith}
35267754Smsmith
35367754Smsmith
35467754Smsmith/*******************************************************************************
35567754Smsmith *
35667754Smsmith * FUNCTION:    AcpiNsDeleteChildren
35767754Smsmith *
35867754Smsmith * PARAMETERS:  ParentNode      - Delete this objects children
35967754Smsmith *
36067754Smsmith * RETURN:      None.
36167754Smsmith *
36291116Smsmith * DESCRIPTION: Delete all children of the parent object. In other words,
36391116Smsmith *              deletes a "scope".
36467754Smsmith *
36567754Smsmith ******************************************************************************/
36667754Smsmith
36767754Smsmithvoid
36867754SmsmithAcpiNsDeleteChildren (
36967754Smsmith    ACPI_NAMESPACE_NODE     *ParentNode)
37067754Smsmith{
37167754Smsmith    ACPI_NAMESPACE_NODE     *ChildNode;
37267754Smsmith    ACPI_NAMESPACE_NODE     *NextNode;
37367754Smsmith    UINT8                   Flags;
37467754Smsmith
37567754Smsmith
37691116Smsmith    ACPI_FUNCTION_TRACE_PTR ("NsDeleteChildren", ParentNode);
37767754Smsmith
37867754Smsmith
37967754Smsmith    if (!ParentNode)
38067754Smsmith    {
38167754Smsmith        return_VOID;
38267754Smsmith    }
38367754Smsmith
38467754Smsmith    /* If no children, all done! */
38567754Smsmith
38667754Smsmith    ChildNode = ParentNode->Child;
38767754Smsmith    if (!ChildNode)
38867754Smsmith    {
38967754Smsmith        return_VOID;
39067754Smsmith    }
39167754Smsmith
39267754Smsmith    /*
39367754Smsmith     * Deallocate all children at this level
39467754Smsmith     */
39567754Smsmith    do
39667754Smsmith    {
39767754Smsmith        /* Get the things we need */
39867754Smsmith
39967754Smsmith        NextNode    = ChildNode->Peer;
40067754Smsmith        Flags       = ChildNode->Flags;
40167754Smsmith
40267754Smsmith        /* Grandchildren should have all been deleted already */
40367754Smsmith
40467754Smsmith        if (ChildNode->Child)
40567754Smsmith        {
40685756Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Found a grandchild! P=%p C=%p\n",
40767754Smsmith                ParentNode, ChildNode));
40867754Smsmith        }
40967754Smsmith
41067754Smsmith        /* Now we can free this child object */
41167754Smsmith
41282367Smsmith        ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalFreed++);
41367754Smsmith
41499146Siwasaki        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Object %p, Remaining %X\n",
41567754Smsmith            ChildNode, AcpiGbl_CurrentNodeCount));
41667754Smsmith
41767754Smsmith        /*
41885756Smsmith         * Detach an object if there is one, then free the child node
41967754Smsmith         */
42085756Smsmith        AcpiNsDetachObject (ChildNode);
42180062Smsmith        ACPI_MEM_FREE (ChildNode);
42267754Smsmith
42367754Smsmith        /* And move on to the next child in the list */
42467754Smsmith
42567754Smsmith        ChildNode = NextNode;
42667754Smsmith
42767754Smsmith    } while (!(Flags & ANOBJ_END_OF_PEER_LIST));
42867754Smsmith
42967754Smsmith
43067754Smsmith    /* Clear the parent's child pointer */
43167754Smsmith
43267754Smsmith    ParentNode->Child = NULL;
43367754Smsmith
43467754Smsmith    return_VOID;
43567754Smsmith}
43667754Smsmith
43767754Smsmith
43867754Smsmith/*******************************************************************************
43967754Smsmith *
44067754Smsmith * FUNCTION:    AcpiNsDeleteNamespaceSubtree
44167754Smsmith *
44283174Smsmith * PARAMETERS:  ParentNode      - Root of the subtree to be deleted
44367754Smsmith *
44467754Smsmith * RETURN:      None.
44567754Smsmith *
44667754Smsmith * DESCRIPTION: Delete a subtree of the namespace.  This includes all objects
44791116Smsmith *              stored within the subtree.
44867754Smsmith *
44967754Smsmith ******************************************************************************/
45067754Smsmith
45199679Siwasakivoid
45267754SmsmithAcpiNsDeleteNamespaceSubtree (
45367754Smsmith    ACPI_NAMESPACE_NODE     *ParentNode)
45467754Smsmith{
45584491Smsmith    ACPI_NAMESPACE_NODE     *ChildNode = NULL;
45684491Smsmith    UINT32                  Level = 1;
45767754Smsmith
45867754Smsmith
45991116Smsmith    ACPI_FUNCTION_TRACE ("NsDeleteNamespaceSubtree");
46067754Smsmith
46167754Smsmith
46267754Smsmith    if (!ParentNode)
46367754Smsmith    {
46499679Siwasaki        return_VOID;
46567754Smsmith    }
46667754Smsmith
46767754Smsmith    /*
46867754Smsmith     * Traverse the tree of objects until we bubble back up
46967754Smsmith     * to where we started.
47067754Smsmith     */
47167754Smsmith    while (Level > 0)
47267754Smsmith    {
47385756Smsmith        /* Get the next node in this scope (NULL if none) */
47485756Smsmith
47585756Smsmith        ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode,
47667754Smsmith                                            ChildNode);
47767754Smsmith        if (ChildNode)
47867754Smsmith        {
47985756Smsmith            /* Found a child node - detach any attached object */
48067754Smsmith
48185756Smsmith            AcpiNsDetachObject (ChildNode);
48267754Smsmith
48385756Smsmith            /* Check if this node has any children */
48467754Smsmith
48585756Smsmith            if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, 0))
48667754Smsmith            {
48767754Smsmith                /*
48885756Smsmith                 * There is at least one child of this node,
48985756Smsmith                 * visit the node
49067754Smsmith                 */
49167754Smsmith                Level++;
49267754Smsmith                ParentNode    = ChildNode;
49367754Smsmith                ChildNode     = 0;
49467754Smsmith            }
49567754Smsmith        }
49667754Smsmith        else
49767754Smsmith        {
49867754Smsmith            /*
49985756Smsmith             * No more children of this parent node.
50085756Smsmith             * Move up to the grandparent.
50167754Smsmith             */
50267754Smsmith            Level--;
50367754Smsmith
50467754Smsmith            /*
50567754Smsmith             * Now delete all of the children of this parent
50667754Smsmith             * all at the same time.
50767754Smsmith             */
50867754Smsmith            AcpiNsDeleteChildren (ParentNode);
50967754Smsmith
51085756Smsmith            /* New "last child" is this parent node */
51167754Smsmith
51267754Smsmith            ChildNode = ParentNode;
51367754Smsmith
51485756Smsmith            /* Move up the tree to the grandparent */
51567754Smsmith
51691116Smsmith            ParentNode = AcpiNsGetParentNode (ParentNode);
51767754Smsmith        }
51867754Smsmith    }
51967754Smsmith
52099679Siwasaki    return_VOID;
52167754Smsmith}
52267754Smsmith
52367754Smsmith
52467754Smsmith/*******************************************************************************
52567754Smsmith *
52667754Smsmith * FUNCTION:    AcpiNsRemoveReference
52767754Smsmith *
52885756Smsmith * PARAMETERS:  Node           - Named node whose reference count is to be
52983174Smsmith *                               decremented
53067754Smsmith *
53167754Smsmith * RETURN:      None.
53267754Smsmith *
53367754Smsmith * DESCRIPTION: Remove a Node reference.  Decrements the reference count
53485756Smsmith *              of all parent Nodes up to the root.  Any node along
53567754Smsmith *              the way that reaches zero references is freed.
53667754Smsmith *
53767754Smsmith ******************************************************************************/
53867754Smsmith
53969450Smsmithstatic void
54067754SmsmithAcpiNsRemoveReference (
54167754Smsmith    ACPI_NAMESPACE_NODE     *Node)
54267754Smsmith{
54391116Smsmith    ACPI_NAMESPACE_NODE     *ParentNode;
54491116Smsmith    ACPI_NAMESPACE_NODE     *ThisNode;
54567754Smsmith
54667754Smsmith
54791116Smsmith    ACPI_FUNCTION_ENTRY ();
54883174Smsmith
54983174Smsmith
55067754Smsmith    /*
55185756Smsmith     * Decrement the reference count(s) of this node and all
55285756Smsmith     * nodes up to the root,  Delete anything with zero remaining references.
55367754Smsmith     */
55491116Smsmith    ThisNode = Node;
55591116Smsmith    while (ThisNode)
55667754Smsmith    {
55791116Smsmith        /* Prepare to move up to parent */
55867754Smsmith
55991116Smsmith        ParentNode = AcpiNsGetParentNode (ThisNode);
56067754Smsmith
56191116Smsmith        /* Decrement the reference count on this node */
56291116Smsmith
56391116Smsmith        ThisNode->ReferenceCount--;
56491116Smsmith
56585756Smsmith        /* Delete the node if no more references */
56667754Smsmith
56791116Smsmith        if (!ThisNode->ReferenceCount)
56867754Smsmith        {
56985756Smsmith            /* Delete all children and delete the node */
57067754Smsmith
57191116Smsmith            AcpiNsDeleteChildren (ThisNode);
57291116Smsmith            AcpiNsDeleteNode (ThisNode);
57367754Smsmith        }
57467754Smsmith
57591116Smsmith        ThisNode = ParentNode;
57667754Smsmith    }
57767754Smsmith}
57867754Smsmith
57967754Smsmith
58067754Smsmith/*******************************************************************************
58167754Smsmith *
58267754Smsmith * FUNCTION:    AcpiNsDeleteNamespaceByOwner
58367754Smsmith *
58483174Smsmith * PARAMETERS:  OwnerId     - All nodes with this owner will be deleted
58567754Smsmith *
58683174Smsmith * RETURN:      Status
58767754Smsmith *
58867754Smsmith * DESCRIPTION: Delete entries within the namespace that are owned by a
58967754Smsmith *              specific ID.  Used to delete entire ACPI tables.  All
59067754Smsmith *              reference counts are updated.
59167754Smsmith *
59267754Smsmith ******************************************************************************/
59367754Smsmith
59499679Siwasakivoid
59567754SmsmithAcpiNsDeleteNamespaceByOwner (
59667754Smsmith    UINT16                  OwnerId)
59767754Smsmith{
59867754Smsmith    ACPI_NAMESPACE_NODE     *ChildNode;
59991116Smsmith    ACPI_NAMESPACE_NODE     *DeletionNode;
60067754Smsmith    UINT32                  Level;
60167754Smsmith    ACPI_NAMESPACE_NODE     *ParentNode;
60267754Smsmith
60367754Smsmith
60491116Smsmith    ACPI_FUNCTION_TRACE_U32 ("NsDeleteNamespaceByOwner", OwnerId);
60567754Smsmith
60667754Smsmith
60791116Smsmith    ParentNode    = AcpiGbl_RootNode;
60891116Smsmith    ChildNode     = NULL;
60991116Smsmith    DeletionNode  = NULL;
61091116Smsmith    Level         = 1;
61167754Smsmith
61267754Smsmith    /*
61385756Smsmith     * Traverse the tree of nodes until we bubble back up
61467754Smsmith     * to where we started.
61567754Smsmith     */
61667754Smsmith    while (Level > 0)
61767754Smsmith    {
61891116Smsmith        /*
61991116Smsmith         * Get the next child of this parent node. When ChildNode is NULL,
62091116Smsmith         * the first child of the parent is returned
62191116Smsmith         */
62291116Smsmith        ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode, ChildNode);
62385756Smsmith
62491116Smsmith        if (DeletionNode)
62591116Smsmith        {
62691116Smsmith            AcpiNsRemoveReference (DeletionNode);
62791116Smsmith            DeletionNode = NULL;
62891116Smsmith        }
62991116Smsmith
63067754Smsmith        if (ChildNode)
63167754Smsmith        {
63267754Smsmith            if (ChildNode->OwnerId == OwnerId)
63367754Smsmith            {
63491116Smsmith                /* Found a matching child node - detach any attached object */
63585756Smsmith
63685756Smsmith                AcpiNsDetachObject (ChildNode);
63767754Smsmith            }
63867754Smsmith
63985756Smsmith            /* Check if this node has any children */
64067754Smsmith
64191116Smsmith            if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, NULL))
64267754Smsmith            {
64367754Smsmith                /*
64485756Smsmith                 * There is at least one child of this node,
64585756Smsmith                 * visit the node
64667754Smsmith                 */
64767754Smsmith                Level++;
64867754Smsmith                ParentNode    = ChildNode;
64991116Smsmith                ChildNode     = NULL;
65067754Smsmith            }
65167754Smsmith            else if (ChildNode->OwnerId == OwnerId)
65267754Smsmith            {
65391116Smsmith                DeletionNode = ChildNode;
65467754Smsmith            }
65567754Smsmith        }
65667754Smsmith        else
65767754Smsmith        {
65867754Smsmith            /*
65985756Smsmith             * No more children of this parent node.
66085756Smsmith             * Move up to the grandparent.
66167754Smsmith             */
66267754Smsmith            Level--;
66367754Smsmith            if (Level != 0)
66467754Smsmith            {
66567754Smsmith                if (ParentNode->OwnerId == OwnerId)
66667754Smsmith                {
66791116Smsmith                    DeletionNode = ParentNode;
66867754Smsmith                }
66967754Smsmith            }
67067754Smsmith
67185756Smsmith            /* New "last child" is this parent node */
67267754Smsmith
67367754Smsmith            ChildNode = ParentNode;
67467754Smsmith
67585756Smsmith            /* Move up the tree to the grandparent */
67667754Smsmith
67791116Smsmith            ParentNode = AcpiNsGetParentNode (ParentNode);
67867754Smsmith        }
67967754Smsmith    }
68067754Smsmith
68199679Siwasaki    return_VOID;
68267754Smsmith}
68367754Smsmith
68467754Smsmith
685