nsalloc.c revision 80062
167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: nsalloc - Namespace allocation and deletion utilities
480062Smsmith *              $Revision: 51 $
567754Smsmith *
667754Smsmith ******************************************************************************/
767754Smsmith
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
1271867Smsmith * Some or all of this work - Copyright (c) 1999, 2000, 2001, 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#include "acinterp.h"
12367754Smsmith
12467754Smsmith
12577424Smsmith#define _COMPONENT          ACPI_NAMESPACE
12667754Smsmith        MODULE_NAME         ("nsalloc")
12767754Smsmith
12867754Smsmith
12967754Smsmith/*******************************************************************************
13067754Smsmith *
13167754Smsmith * FUNCTION:    AcpiNsCreateNode
13267754Smsmith *
13367754Smsmith * PARAMETERS:
13467754Smsmith *
13567754Smsmith * RETURN:      None
13667754Smsmith *
13767754Smsmith * DESCRIPTION:
13867754Smsmith *
13967754Smsmith ******************************************************************************/
14067754Smsmith
14167754SmsmithACPI_NAMESPACE_NODE *
14267754SmsmithAcpiNsCreateNode (
14367754Smsmith    UINT32                  AcpiName)
14467754Smsmith{
14567754Smsmith    ACPI_NAMESPACE_NODE     *Node;
14667754Smsmith
14767754Smsmith    FUNCTION_TRACE ("NsCreateNode");
14867754Smsmith
14967754Smsmith
15080062Smsmith    Node = ACPI_MEM_CALLOCATE (sizeof (ACPI_NAMESPACE_NODE));
15167754Smsmith    if (!Node)
15267754Smsmith    {
15367754Smsmith        return_PTR (NULL);
15467754Smsmith    }
15567754Smsmith
15667754Smsmith    INCREMENT_NAME_TABLE_METRICS (sizeof (ACPI_NAMESPACE_NODE));
15767754Smsmith
15867754Smsmith    Node->DataType       = ACPI_DESC_TYPE_NAMED;
15967754Smsmith    Node->Name           = AcpiName;
16067754Smsmith    Node->ReferenceCount = 1;
16167754Smsmith
16267754Smsmith    return_PTR (Node);
16367754Smsmith}
16467754Smsmith
16567754Smsmith
16667754Smsmith/*******************************************************************************
16767754Smsmith *
16867754Smsmith * FUNCTION:    AcpiNsDeleteNode
16967754Smsmith *
17067754Smsmith * PARAMETERS:
17167754Smsmith *
17267754Smsmith * RETURN:      None
17367754Smsmith *
17467754Smsmith * DESCRIPTION:
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
18767754Smsmith    FUNCTION_TRACE_PTR ("NsDeleteNode", Node);
18867754Smsmith
18967754Smsmith    ParentNode = AcpiNsGetParentObject (Node);
19067754Smsmith
19167754Smsmith    PrevNode = NULL;
19267754Smsmith    NextNode = ParentNode->Child;
19367754Smsmith
19467754Smsmith    while (NextNode != Node)
19567754Smsmith    {
19667754Smsmith        PrevNode = NextNode;
19767754Smsmith        NextNode = PrevNode->Peer;
19867754Smsmith    }
19967754Smsmith
20067754Smsmith    if (PrevNode)
20167754Smsmith    {
20267754Smsmith        PrevNode->Peer = NextNode->Peer;
20367754Smsmith        if (NextNode->Flags & ANOBJ_END_OF_PEER_LIST)
20467754Smsmith        {
20567754Smsmith            PrevNode->Flags |= ANOBJ_END_OF_PEER_LIST;
20667754Smsmith        }
20767754Smsmith    }
20867754Smsmith    else
20967754Smsmith    {
21067754Smsmith        ParentNode->Child = NextNode->Peer;
21167754Smsmith    }
21267754Smsmith
21367754Smsmith
21467754Smsmith    DECREMENT_NAME_TABLE_METRICS (sizeof (ACPI_NAMESPACE_NODE));
21567754Smsmith
21667754Smsmith    /*
21767754Smsmith     * Detach an object if there is one
21867754Smsmith     */
21967754Smsmith
22067754Smsmith    if (Node->Object)
22167754Smsmith    {
22267754Smsmith        AcpiNsDetachObject (Node);
22367754Smsmith    }
22467754Smsmith
22580062Smsmith    ACPI_MEM_FREE (Node);
22667754Smsmith    return_VOID;
22767754Smsmith}
22867754Smsmith
22967754Smsmith
23067754Smsmith/*******************************************************************************
23167754Smsmith *
23267754Smsmith * FUNCTION:    AcpiNsInstallNode
23367754Smsmith *
23467754Smsmith * PARAMETERS:  WalkState       - Current state of the walk
23567754Smsmith *              ParentNode      - The parent of the new Node
23667754Smsmith *              Node        - The new Node to install
23767754Smsmith *              Type            - ACPI object type of the new Node
23867754Smsmith *
23967754Smsmith * RETURN:      None
24067754Smsmith *
24167754Smsmith * DESCRIPTION: Initialize a new entry within a namespace table.
24267754Smsmith *
24367754Smsmith ******************************************************************************/
24467754Smsmith
24567754Smsmithvoid
24667754SmsmithAcpiNsInstallNode (
24767754Smsmith    ACPI_WALK_STATE         *WalkState,
24867754Smsmith    ACPI_NAMESPACE_NODE     *ParentNode,    /* Parent */
24967754Smsmith    ACPI_NAMESPACE_NODE     *Node,      /* New Child*/
25077424Smsmith    ACPI_OBJECT_TYPE8       Type)
25167754Smsmith{
25267754Smsmith    UINT16                  OwnerId = TABLE_ID_DSDT;
25367754Smsmith    ACPI_NAMESPACE_NODE     *ChildNode;
25467754Smsmith
25567754Smsmith
25667754Smsmith    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
26967754Smsmith
27067754Smsmith    /* link the new entry into the parent and existing children */
27167754Smsmith
27267754Smsmith    /* TBD: Could be first, last, or alphabetic */
27367754Smsmith
27467754Smsmith    ChildNode = ParentNode->Child;
27567754Smsmith    if (!ChildNode)
27667754Smsmith    {
27767754Smsmith        ParentNode->Child = Node;
27867754Smsmith    }
27967754Smsmith
28067754Smsmith    else
28167754Smsmith    {
28267754Smsmith        while (!(ChildNode->Flags & ANOBJ_END_OF_PEER_LIST))
28367754Smsmith        {
28467754Smsmith            ChildNode = ChildNode->Peer;
28567754Smsmith        }
28667754Smsmith
28767754Smsmith        ChildNode->Peer = Node;
28867754Smsmith
28967754Smsmith        /* Clear end-of-list flag */
29067754Smsmith
29167754Smsmith        ChildNode->Flags &= ~ANOBJ_END_OF_PEER_LIST;
29267754Smsmith    }
29367754Smsmith
29467754Smsmith    /* Init the new entry */
29567754Smsmith
29667754Smsmith    Node->OwnerId   = OwnerId;
29767754Smsmith    Node->Flags     |= ANOBJ_END_OF_PEER_LIST;
29867754Smsmith    Node->Peer      = ParentNode;
29967754Smsmith
30067754Smsmith
30167754Smsmith    /*
30267754Smsmith     * If adding a name with unknown type, or having to
30367754Smsmith     * add the region in order to define fields in it, we
30467754Smsmith     * have a forward reference.
30567754Smsmith     */
30667754Smsmith    if ((ACPI_TYPE_ANY == Type) ||
30777424Smsmith        (INTERNAL_TYPE_FIELD_DEFN == Type) ||
30867754Smsmith        (INTERNAL_TYPE_BANK_FIELD_DEFN == Type))
30967754Smsmith    {
31067754Smsmith        /*
31167754Smsmith         * We don't want to abort here, however!
31267754Smsmith         * We will fill in the actual type when the
31367754Smsmith         * real definition is found later.
31467754Smsmith         */
31577424Smsmith        DEBUG_PRINTP (ACPI_INFO, ("[%4.4s] is a forward reference\n",
31667754Smsmith            &Node->Name));
31767754Smsmith    }
31867754Smsmith
31967754Smsmith    /*
32067754Smsmith     * The DefFieldDefn and BankFieldDefn cases are actually
32167754Smsmith     * looking up the Region in which the field will be defined
32267754Smsmith     */
32377424Smsmith    if ((INTERNAL_TYPE_FIELD_DEFN == Type) ||
32467754Smsmith        (INTERNAL_TYPE_BANK_FIELD_DEFN == Type))
32567754Smsmith    {
32667754Smsmith        Type = ACPI_TYPE_REGION;
32767754Smsmith    }
32867754Smsmith
32967754Smsmith    /*
33067754Smsmith     * Scope, DefAny, and IndexFieldDefn are bogus "types" which do
33167754Smsmith     * not actually have anything to do with the type of the name
33267754Smsmith     * being looked up.  Save any other value of Type as the type of
33367754Smsmith     * the entry.
33467754Smsmith     */
33567754Smsmith    if ((Type != INTERNAL_TYPE_SCOPE) &&
33667754Smsmith        (Type != INTERNAL_TYPE_DEF_ANY) &&
33767754Smsmith        (Type != INTERNAL_TYPE_INDEX_FIELD_DEFN))
33867754Smsmith    {
33967754Smsmith        Node->Type = (UINT8) Type;
34067754Smsmith    }
34167754Smsmith
34277424Smsmith    DEBUG_PRINTP (TRACE_NAMES, ("%4.4s added to %p at %p\n",
34367754Smsmith        &Node->Name, ParentNode, Node));
34467754Smsmith
34567754Smsmith    /*
34667754Smsmith     * Increment the reference count(s) of all parents up to
34767754Smsmith     * the root!
34867754Smsmith     */
34967754Smsmith    while ((Node = AcpiNsGetParentObject (Node)) != NULL)
35067754Smsmith    {
35167754Smsmith        Node->ReferenceCount++;
35267754Smsmith    }
35367754Smsmith
35467754Smsmith    return_VOID;
35567754Smsmith}
35667754Smsmith
35767754Smsmith
35867754Smsmith/*******************************************************************************
35967754Smsmith *
36067754Smsmith * FUNCTION:    AcpiNsDeleteChildren
36167754Smsmith *
36267754Smsmith * PARAMETERS:  ParentNode      - Delete this objects children
36367754Smsmith *
36467754Smsmith * RETURN:      None.
36567754Smsmith *
36667754Smsmith * DESCRIPTION: Delete all children of the parent object. Deletes a
36767754Smsmith *              "scope".
36867754Smsmith *
36967754Smsmith ******************************************************************************/
37067754Smsmith
37167754Smsmithvoid
37267754SmsmithAcpiNsDeleteChildren (
37367754Smsmith    ACPI_NAMESPACE_NODE     *ParentNode)
37467754Smsmith{
37567754Smsmith    ACPI_NAMESPACE_NODE     *ChildNode;
37667754Smsmith    ACPI_NAMESPACE_NODE     *NextNode;
37767754Smsmith    UINT8                   Flags;
37867754Smsmith
37967754Smsmith
38067754Smsmith    FUNCTION_TRACE_PTR ("AcpiNsDeleteChildren", ParentNode);
38167754Smsmith
38267754Smsmith
38367754Smsmith    if (!ParentNode)
38467754Smsmith    {
38567754Smsmith        return_VOID;
38667754Smsmith    }
38767754Smsmith
38867754Smsmith    /* If no children, all done! */
38967754Smsmith
39067754Smsmith    ChildNode = ParentNode->Child;
39167754Smsmith    if (!ChildNode)
39267754Smsmith    {
39367754Smsmith        return_VOID;
39467754Smsmith    }
39567754Smsmith
39667754Smsmith    /*
39767754Smsmith     * Deallocate all children at this level
39867754Smsmith     */
39967754Smsmith    do
40067754Smsmith    {
40167754Smsmith        /* Get the things we need */
40267754Smsmith
40367754Smsmith        NextNode    = ChildNode->Peer;
40467754Smsmith        Flags       = ChildNode->Flags;
40567754Smsmith
40667754Smsmith        /* Grandchildren should have all been deleted already */
40767754Smsmith
40867754Smsmith        if (ChildNode->Child)
40967754Smsmith        {
41077424Smsmith            DEBUG_PRINTP (ACPI_ERROR, ("Found a grandchild! P=%X C=%X\n",
41167754Smsmith                ParentNode, ChildNode));
41267754Smsmith        }
41367754Smsmith
41467754Smsmith        /* Now we can free this child object */
41567754Smsmith
41667754Smsmith        DECREMENT_NAME_TABLE_METRICS (sizeof (ACPI_NAMESPACE_NODE));
41767754Smsmith
41877424Smsmith        DEBUG_PRINTP (ACPI_INFO, ("Object %p, Remaining %X\n",
41967754Smsmith            ChildNode, AcpiGbl_CurrentNodeCount));
42067754Smsmith
42167754Smsmith        /*
42267754Smsmith         * Detach an object if there is one
42367754Smsmith         */
42467754Smsmith
42567754Smsmith        if (ChildNode->Object)
42667754Smsmith        {
42767754Smsmith            AcpiNsDetachObject (ChildNode);
42867754Smsmith        }
42967754Smsmith
43080062Smsmith        ACPI_MEM_FREE (ChildNode);
43167754Smsmith
43267754Smsmith        /* And move on to the next child in the list */
43367754Smsmith
43467754Smsmith        ChildNode = NextNode;
43567754Smsmith
43667754Smsmith    } while (!(Flags & ANOBJ_END_OF_PEER_LIST));
43767754Smsmith
43867754Smsmith
43967754Smsmith    /* Clear the parent's child pointer */
44067754Smsmith
44167754Smsmith    ParentNode->Child = NULL;
44267754Smsmith
44367754Smsmith    return_VOID;
44467754Smsmith}
44567754Smsmith
44667754Smsmith
44767754Smsmith/*******************************************************************************
44867754Smsmith *
44967754Smsmith * FUNCTION:    AcpiNsDeleteNamespaceSubtree
45067754Smsmith *
45167754Smsmith * PARAMETERS:  None.
45267754Smsmith *
45367754Smsmith * RETURN:      None.
45467754Smsmith *
45567754Smsmith * DESCRIPTION: Delete a subtree of the namespace.  This includes all objects
45667754Smsmith *              stored within the subtree.  Scope tables are deleted also
45767754Smsmith *
45867754Smsmith ******************************************************************************/
45967754Smsmith
46067754SmsmithACPI_STATUS
46167754SmsmithAcpiNsDeleteNamespaceSubtree (
46267754Smsmith    ACPI_NAMESPACE_NODE     *ParentNode)
46367754Smsmith{
46467754Smsmith    ACPI_NAMESPACE_NODE     *ChildNode;
46567754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
46667754Smsmith    UINT32                  Level;
46767754Smsmith
46867754Smsmith
46967754Smsmith    FUNCTION_TRACE ("NsDeleteNamespaceSubtree");
47067754Smsmith
47167754Smsmith
47267754Smsmith    if (!ParentNode)
47367754Smsmith    {
47467754Smsmith        return_ACPI_STATUS (AE_OK);
47567754Smsmith    }
47667754Smsmith
47767754Smsmith
47867754Smsmith    ChildNode   = 0;
47967754Smsmith    Level       = 1;
48067754Smsmith
48167754Smsmith    /*
48267754Smsmith     * Traverse the tree of objects until we bubble back up
48367754Smsmith     * to where we started.
48467754Smsmith     */
48567754Smsmith
48667754Smsmith    while (Level > 0)
48767754Smsmith    {
48867754Smsmith        /*
48967754Smsmith         * Get the next typed object in this scope.
49067754Smsmith         * Null returned if not found
49167754Smsmith         */
49267754Smsmith
49367754Smsmith        ChildNode = AcpiNsGetNextObject (ACPI_TYPE_ANY, ParentNode,
49467754Smsmith                                            ChildNode);
49567754Smsmith        if (ChildNode)
49667754Smsmith        {
49767754Smsmith            /*
49867754Smsmith             * Found an object - delete the object within
49967754Smsmith             * the Value field
50067754Smsmith             */
50167754Smsmith
50267754Smsmith            ObjDesc = AcpiNsGetAttachedObject (ChildNode);
50367754Smsmith            if (ObjDesc)
50467754Smsmith            {
50567754Smsmith                AcpiNsDetachObject (ChildNode);
50677424Smsmith                AcpiUtRemoveReference (ObjDesc);
50767754Smsmith            }
50867754Smsmith
50967754Smsmith
51067754Smsmith            /* Check if this object has any children */
51167754Smsmith
51267754Smsmith            if (AcpiNsGetNextObject (ACPI_TYPE_ANY, ChildNode, 0))
51367754Smsmith            {
51467754Smsmith                /*
51567754Smsmith                 * There is at least one child of this object,
51667754Smsmith                 * visit the object
51767754Smsmith                 */
51867754Smsmith
51967754Smsmith                Level++;
52067754Smsmith                ParentNode    = ChildNode;
52167754Smsmith                ChildNode     = 0;
52267754Smsmith            }
52367754Smsmith        }
52467754Smsmith
52567754Smsmith        else
52667754Smsmith        {
52767754Smsmith            /*
52867754Smsmith             * No more children in this object.
52967754Smsmith             * We will move up to the grandparent.
53067754Smsmith             */
53167754Smsmith            Level--;
53267754Smsmith
53367754Smsmith            /*
53467754Smsmith             * Now delete all of the children of this parent
53567754Smsmith             * all at the same time.
53667754Smsmith             */
53767754Smsmith            AcpiNsDeleteChildren (ParentNode);
53867754Smsmith
53967754Smsmith            /* New "last child" is this parent object */
54067754Smsmith
54167754Smsmith            ChildNode = ParentNode;
54267754Smsmith
54367754Smsmith            /* Now we can move up the tree to the grandparent */
54467754Smsmith
54567754Smsmith            ParentNode = AcpiNsGetParentObject (ParentNode);
54667754Smsmith        }
54767754Smsmith    }
54867754Smsmith
54967754Smsmith
55067754Smsmith    return_ACPI_STATUS (AE_OK);
55167754Smsmith}
55267754Smsmith
55367754Smsmith
55467754Smsmith/*******************************************************************************
55567754Smsmith *
55667754Smsmith * FUNCTION:    AcpiNsRemoveReference
55767754Smsmith *
55867754Smsmith * PARAMETERS:  Node           - Named object whose reference count is to be
55967754Smsmith *                                decremented
56067754Smsmith *
56167754Smsmith * RETURN:      None.
56267754Smsmith *
56367754Smsmith * DESCRIPTION: Remove a Node reference.  Decrements the reference count
56467754Smsmith *              of all parent Nodes up to the root.  Any object along
56567754Smsmith *              the way that reaches zero references is freed.
56667754Smsmith *
56767754Smsmith ******************************************************************************/
56867754Smsmith
56969450Smsmithstatic void
57067754SmsmithAcpiNsRemoveReference (
57167754Smsmith    ACPI_NAMESPACE_NODE     *Node)
57267754Smsmith{
57367754Smsmith    ACPI_NAMESPACE_NODE     *NextNode;
57467754Smsmith
57567754Smsmith
57667754Smsmith    /*
57767754Smsmith     * Decrement the reference count(s) of this object and all
57867754Smsmith     * objects up to the root,  Delete anything with zero remaining references.
57967754Smsmith     */
58067754Smsmith    NextNode = Node;
58167754Smsmith    while (NextNode)
58267754Smsmith    {
58367754Smsmith        /* Decrement the reference count on this object*/
58467754Smsmith
58567754Smsmith        NextNode->ReferenceCount--;
58667754Smsmith
58767754Smsmith        /* Delete the object if no more references */
58867754Smsmith
58967754Smsmith        if (!NextNode->ReferenceCount)
59067754Smsmith        {
59167754Smsmith            /* Delete all children and delete the object */
59267754Smsmith
59367754Smsmith            AcpiNsDeleteChildren (NextNode);
59467754Smsmith            AcpiNsDeleteNode (NextNode);
59567754Smsmith        }
59667754Smsmith
59767754Smsmith        /* Move up to parent */
59867754Smsmith
59967754Smsmith        NextNode = AcpiNsGetParentObject (NextNode);
60067754Smsmith    }
60167754Smsmith}
60267754Smsmith
60367754Smsmith
60467754Smsmith/*******************************************************************************
60567754Smsmith *
60667754Smsmith * FUNCTION:    AcpiNsDeleteNamespaceByOwner
60767754Smsmith *
60867754Smsmith * PARAMETERS:  None.
60967754Smsmith *
61067754Smsmith * RETURN:      None.
61167754Smsmith *
61267754Smsmith * DESCRIPTION: Delete entries within the namespace that are owned by a
61367754Smsmith *              specific ID.  Used to delete entire ACPI tables.  All
61467754Smsmith *              reference counts are updated.
61567754Smsmith *
61667754Smsmith ******************************************************************************/
61767754Smsmith
61867754SmsmithACPI_STATUS
61967754SmsmithAcpiNsDeleteNamespaceByOwner (
62067754Smsmith    UINT16                  OwnerId)
62167754Smsmith{
62267754Smsmith    ACPI_NAMESPACE_NODE     *ChildNode;
62367754Smsmith    UINT32                  Level;
62467754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
62567754Smsmith    ACPI_NAMESPACE_NODE     *ParentNode;
62667754Smsmith
62767754Smsmith
62867754Smsmith    FUNCTION_TRACE ("NsDeleteNamespaceSubtree");
62967754Smsmith
63067754Smsmith
63167754Smsmith    ParentNode  = AcpiGbl_RootNode;
63267754Smsmith    ChildNode   = 0;
63367754Smsmith    Level       = 1;
63467754Smsmith
63567754Smsmith    /*
63667754Smsmith     * Traverse the tree of objects until we bubble back up
63767754Smsmith     * to where we started.
63867754Smsmith     */
63967754Smsmith
64067754Smsmith    while (Level > 0)
64167754Smsmith    {
64267754Smsmith        /*
64367754Smsmith         * Get the next typed object in this scope.
64467754Smsmith         * Null returned if not found
64567754Smsmith         */
64667754Smsmith
64767754Smsmith        ChildNode = AcpiNsGetNextObject (ACPI_TYPE_ANY, ParentNode,
64867754Smsmith                                            ChildNode);
64967754Smsmith
65067754Smsmith        if (ChildNode)
65167754Smsmith        {
65267754Smsmith            if (ChildNode->OwnerId == OwnerId)
65367754Smsmith            {
65467754Smsmith                /*
65567754Smsmith                 * Found an object - delete the object within
65667754Smsmith                 * the Value field
65767754Smsmith                 */
65867754Smsmith
65967754Smsmith                ObjDesc = AcpiNsGetAttachedObject (ChildNode);
66067754Smsmith                if (ObjDesc)
66167754Smsmith                {
66267754Smsmith                    AcpiNsDetachObject (ChildNode);
66377424Smsmith                    AcpiUtRemoveReference (ObjDesc);
66467754Smsmith                }
66567754Smsmith            }
66667754Smsmith
66767754Smsmith            /* Check if this object has any children */
66867754Smsmith
66967754Smsmith            if (AcpiNsGetNextObject (ACPI_TYPE_ANY, ChildNode, 0))
67067754Smsmith            {
67167754Smsmith                /*
67267754Smsmith                 * There is at least one child of this object,
67367754Smsmith                 * visit the object
67467754Smsmith                 */
67567754Smsmith
67667754Smsmith                Level++;
67767754Smsmith                ParentNode    = ChildNode;
67867754Smsmith                ChildNode     = 0;
67967754Smsmith            }
68067754Smsmith
68167754Smsmith            else if (ChildNode->OwnerId == OwnerId)
68267754Smsmith            {
68367754Smsmith                AcpiNsRemoveReference (ChildNode);
68467754Smsmith            }
68567754Smsmith        }
68667754Smsmith
68767754Smsmith        else
68867754Smsmith        {
68967754Smsmith            /*
69067754Smsmith             * No more children in this object.  Move up to grandparent.
69167754Smsmith             */
69267754Smsmith            Level--;
69367754Smsmith
69467754Smsmith            if (Level != 0)
69567754Smsmith            {
69667754Smsmith                if (ParentNode->OwnerId == OwnerId)
69767754Smsmith                {
69867754Smsmith                    AcpiNsRemoveReference (ParentNode);
69967754Smsmith                }
70067754Smsmith            }
70167754Smsmith
70267754Smsmith            /* New "last child" is this parent object */
70367754Smsmith
70467754Smsmith            ChildNode = ParentNode;
70567754Smsmith
70667754Smsmith            /* Now we can move up the tree to the grandparent */
70767754Smsmith
70867754Smsmith            ParentNode = AcpiNsGetParentObject (ParentNode);
70967754Smsmith        }
71067754Smsmith    }
71167754Smsmith
71267754Smsmith
71367754Smsmith    return_ACPI_STATUS (AE_OK);
71467754Smsmith}
71567754Smsmith
71667754Smsmith
717