Home | History | Annotate | Line # | Download | only in namespace
nsalloc.c revision 1.1.1.2.2.2
      1  1.1.1.2.2.2  bouyer /*******************************************************************************
      2  1.1.1.2.2.2  bouyer  *
      3  1.1.1.2.2.2  bouyer  * Module Name: nsalloc - Namespace allocation and deletion utilities
      4  1.1.1.2.2.2  bouyer  *
      5  1.1.1.2.2.2  bouyer  ******************************************************************************/
      6  1.1.1.2.2.2  bouyer 
      7  1.1.1.2.2.2  bouyer /*
      8  1.1.1.2.2.2  bouyer  * Copyright (C) 2000 - 2011, Intel Corp.
      9  1.1.1.2.2.2  bouyer  * All rights reserved.
     10  1.1.1.2.2.2  bouyer  *
     11  1.1.1.2.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2.2.2  bouyer  * modification, are permitted provided that the following conditions
     13  1.1.1.2.2.2  bouyer  * are met:
     14  1.1.1.2.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2.2.2  bouyer  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2.2.2  bouyer  *    without modification.
     17  1.1.1.2.2.2  bouyer  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2.2.2  bouyer  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2.2.2  bouyer  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2.2.2  bouyer  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2.2.2  bouyer  *    binary redistribution.
     22  1.1.1.2.2.2  bouyer  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2.2.2  bouyer  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2.2.2  bouyer  *    from this software without specific prior written permission.
     25  1.1.1.2.2.2  bouyer  *
     26  1.1.1.2.2.2  bouyer  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2.2.2  bouyer  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2.2.2  bouyer  * Software Foundation.
     29  1.1.1.2.2.2  bouyer  *
     30  1.1.1.2.2.2  bouyer  * NO WARRANTY
     31  1.1.1.2.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2.2.2  bouyer  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2.2.2  bouyer  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2.2.2  bouyer  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2.2.2  bouyer  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2.2.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2.2.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2.2.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2.2.2  bouyer  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2.2.2  bouyer  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2.2.2  bouyer  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2.2.2  bouyer  */
     43  1.1.1.2.2.2  bouyer 
     44  1.1.1.2.2.2  bouyer 
     45  1.1.1.2.2.2  bouyer #define __NSALLOC_C__
     46  1.1.1.2.2.2  bouyer 
     47  1.1.1.2.2.2  bouyer #include "acpi.h"
     48  1.1.1.2.2.2  bouyer #include "accommon.h"
     49  1.1.1.2.2.2  bouyer #include "acnamesp.h"
     50  1.1.1.2.2.2  bouyer 
     51  1.1.1.2.2.2  bouyer 
     52  1.1.1.2.2.2  bouyer #define _COMPONENT          ACPI_NAMESPACE
     53  1.1.1.2.2.2  bouyer         ACPI_MODULE_NAME    ("nsalloc")
     54  1.1.1.2.2.2  bouyer 
     55  1.1.1.2.2.2  bouyer 
     56  1.1.1.2.2.2  bouyer /*******************************************************************************
     57  1.1.1.2.2.2  bouyer  *
     58  1.1.1.2.2.2  bouyer  * FUNCTION:    AcpiNsCreateNode
     59  1.1.1.2.2.2  bouyer  *
     60  1.1.1.2.2.2  bouyer  * PARAMETERS:  Name            - Name of the new node (4 char ACPI name)
     61  1.1.1.2.2.2  bouyer  *
     62  1.1.1.2.2.2  bouyer  * RETURN:      New namespace node (Null on failure)
     63  1.1.1.2.2.2  bouyer  *
     64  1.1.1.2.2.2  bouyer  * DESCRIPTION: Create a namespace node
     65  1.1.1.2.2.2  bouyer  *
     66  1.1.1.2.2.2  bouyer  ******************************************************************************/
     67  1.1.1.2.2.2  bouyer 
     68  1.1.1.2.2.2  bouyer ACPI_NAMESPACE_NODE *
     69  1.1.1.2.2.2  bouyer AcpiNsCreateNode (
     70  1.1.1.2.2.2  bouyer     UINT32                  Name)
     71  1.1.1.2.2.2  bouyer {
     72  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *Node;
     73  1.1.1.2.2.2  bouyer #ifdef ACPI_DBG_TRACK_ALLOCATIONS
     74  1.1.1.2.2.2  bouyer     UINT32                  Temp;
     75  1.1.1.2.2.2  bouyer #endif
     76  1.1.1.2.2.2  bouyer 
     77  1.1.1.2.2.2  bouyer 
     78  1.1.1.2.2.2  bouyer     ACPI_FUNCTION_TRACE (NsCreateNode);
     79  1.1.1.2.2.2  bouyer 
     80  1.1.1.2.2.2  bouyer 
     81  1.1.1.2.2.2  bouyer     Node = AcpiOsAcquireObject (AcpiGbl_NamespaceCache);
     82  1.1.1.2.2.2  bouyer     if (!Node)
     83  1.1.1.2.2.2  bouyer     {
     84  1.1.1.2.2.2  bouyer         return_PTR (NULL);
     85  1.1.1.2.2.2  bouyer     }
     86  1.1.1.2.2.2  bouyer 
     87  1.1.1.2.2.2  bouyer     ACPI_MEM_TRACKING (AcpiGbl_NsNodeList->TotalAllocated++);
     88  1.1.1.2.2.2  bouyer 
     89  1.1.1.2.2.2  bouyer #ifdef ACPI_DBG_TRACK_ALLOCATIONS
     90  1.1.1.2.2.2  bouyer         Temp = AcpiGbl_NsNodeList->TotalAllocated -
     91  1.1.1.2.2.2  bouyer                 AcpiGbl_NsNodeList->TotalFreed;
     92  1.1.1.2.2.2  bouyer         if (Temp > AcpiGbl_NsNodeList->MaxOccupied)
     93  1.1.1.2.2.2  bouyer         {
     94  1.1.1.2.2.2  bouyer             AcpiGbl_NsNodeList->MaxOccupied = Temp;
     95  1.1.1.2.2.2  bouyer         }
     96  1.1.1.2.2.2  bouyer #endif
     97  1.1.1.2.2.2  bouyer 
     98  1.1.1.2.2.2  bouyer     Node->Name.Integer = Name;
     99  1.1.1.2.2.2  bouyer     ACPI_SET_DESCRIPTOR_TYPE (Node, ACPI_DESC_TYPE_NAMED);
    100  1.1.1.2.2.2  bouyer     return_PTR (Node);
    101  1.1.1.2.2.2  bouyer }
    102  1.1.1.2.2.2  bouyer 
    103  1.1.1.2.2.2  bouyer 
    104  1.1.1.2.2.2  bouyer /*******************************************************************************
    105  1.1.1.2.2.2  bouyer  *
    106  1.1.1.2.2.2  bouyer  * FUNCTION:    AcpiNsDeleteNode
    107  1.1.1.2.2.2  bouyer  *
    108  1.1.1.2.2.2  bouyer  * PARAMETERS:  Node            - Node to be deleted
    109  1.1.1.2.2.2  bouyer  *
    110  1.1.1.2.2.2  bouyer  * RETURN:      None
    111  1.1.1.2.2.2  bouyer  *
    112  1.1.1.2.2.2  bouyer  * DESCRIPTION: Delete a namespace node. All node deletions must come through
    113  1.1.1.2.2.2  bouyer  *              here. Detaches any attached objects, including any attached
    114  1.1.1.2.2.2  bouyer  *              data. If a handler is associated with attached data, it is
    115  1.1.1.2.2.2  bouyer  *              invoked before the node is deleted.
    116  1.1.1.2.2.2  bouyer  *
    117  1.1.1.2.2.2  bouyer  ******************************************************************************/
    118  1.1.1.2.2.2  bouyer 
    119  1.1.1.2.2.2  bouyer void
    120  1.1.1.2.2.2  bouyer AcpiNsDeleteNode (
    121  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *Node)
    122  1.1.1.2.2.2  bouyer {
    123  1.1.1.2.2.2  bouyer     ACPI_OPERAND_OBJECT     *ObjDesc;
    124  1.1.1.2.2.2  bouyer 
    125  1.1.1.2.2.2  bouyer 
    126  1.1.1.2.2.2  bouyer     ACPI_FUNCTION_NAME (NsDeleteNode);
    127  1.1.1.2.2.2  bouyer 
    128  1.1.1.2.2.2  bouyer 
    129  1.1.1.2.2.2  bouyer     /* Detach an object if there is one */
    130  1.1.1.2.2.2  bouyer 
    131  1.1.1.2.2.2  bouyer     AcpiNsDetachObject (Node);
    132  1.1.1.2.2.2  bouyer 
    133  1.1.1.2.2.2  bouyer     /*
    134  1.1.1.2.2.2  bouyer      * Delete an attached data object if present (an object that was created
    135  1.1.1.2.2.2  bouyer      * and attached via AcpiAttachData). Note: After any normal object is
    136  1.1.1.2.2.2  bouyer      * detached above, the only possible remaining object is a data object.
    137  1.1.1.2.2.2  bouyer      */
    138  1.1.1.2.2.2  bouyer     ObjDesc = Node->Object;
    139  1.1.1.2.2.2  bouyer     if (ObjDesc &&
    140  1.1.1.2.2.2  bouyer         (ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA))
    141  1.1.1.2.2.2  bouyer     {
    142  1.1.1.2.2.2  bouyer         /* Invoke the attached data deletion handler if present */
    143  1.1.1.2.2.2  bouyer 
    144  1.1.1.2.2.2  bouyer         if (ObjDesc->Data.Handler)
    145  1.1.1.2.2.2  bouyer         {
    146  1.1.1.2.2.2  bouyer             ObjDesc->Data.Handler (Node, ObjDesc->Data.Pointer);
    147  1.1.1.2.2.2  bouyer         }
    148  1.1.1.2.2.2  bouyer 
    149  1.1.1.2.2.2  bouyer         AcpiUtRemoveReference (ObjDesc);
    150  1.1.1.2.2.2  bouyer     }
    151  1.1.1.2.2.2  bouyer 
    152  1.1.1.2.2.2  bouyer     /* Now we can delete the node */
    153  1.1.1.2.2.2  bouyer 
    154  1.1.1.2.2.2  bouyer     (void) AcpiOsReleaseObject (AcpiGbl_NamespaceCache, Node);
    155  1.1.1.2.2.2  bouyer 
    156  1.1.1.2.2.2  bouyer     ACPI_MEM_TRACKING (AcpiGbl_NsNodeList->TotalFreed++);
    157  1.1.1.2.2.2  bouyer     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Node %p, Remaining %X\n",
    158  1.1.1.2.2.2  bouyer         Node, AcpiGbl_CurrentNodeCount));
    159  1.1.1.2.2.2  bouyer }
    160  1.1.1.2.2.2  bouyer 
    161  1.1.1.2.2.2  bouyer 
    162  1.1.1.2.2.2  bouyer /*******************************************************************************
    163  1.1.1.2.2.2  bouyer  *
    164  1.1.1.2.2.2  bouyer  * FUNCTION:    AcpiNsRemoveNode
    165  1.1.1.2.2.2  bouyer  *
    166  1.1.1.2.2.2  bouyer  * PARAMETERS:  Node            - Node to be removed/deleted
    167  1.1.1.2.2.2  bouyer  *
    168  1.1.1.2.2.2  bouyer  * RETURN:      None
    169  1.1.1.2.2.2  bouyer  *
    170  1.1.1.2.2.2  bouyer  * DESCRIPTION: Remove (unlink) and delete a namespace node
    171  1.1.1.2.2.2  bouyer  *
    172  1.1.1.2.2.2  bouyer  ******************************************************************************/
    173  1.1.1.2.2.2  bouyer 
    174  1.1.1.2.2.2  bouyer void
    175  1.1.1.2.2.2  bouyer AcpiNsRemoveNode (
    176  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *Node)
    177  1.1.1.2.2.2  bouyer {
    178  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *ParentNode;
    179  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *PrevNode;
    180  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *NextNode;
    181  1.1.1.2.2.2  bouyer 
    182  1.1.1.2.2.2  bouyer 
    183  1.1.1.2.2.2  bouyer     ACPI_FUNCTION_TRACE_PTR (NsRemoveNode, Node);
    184  1.1.1.2.2.2  bouyer 
    185  1.1.1.2.2.2  bouyer 
    186  1.1.1.2.2.2  bouyer     ParentNode = Node->Parent;
    187  1.1.1.2.2.2  bouyer 
    188  1.1.1.2.2.2  bouyer     PrevNode = NULL;
    189  1.1.1.2.2.2  bouyer     NextNode = ParentNode->Child;
    190  1.1.1.2.2.2  bouyer 
    191  1.1.1.2.2.2  bouyer     /* Find the node that is the previous peer in the parent's child list */
    192  1.1.1.2.2.2  bouyer 
    193  1.1.1.2.2.2  bouyer     while (NextNode != Node)
    194  1.1.1.2.2.2  bouyer     {
    195  1.1.1.2.2.2  bouyer         PrevNode = NextNode;
    196  1.1.1.2.2.2  bouyer         NextNode = NextNode->Peer;
    197  1.1.1.2.2.2  bouyer     }
    198  1.1.1.2.2.2  bouyer 
    199  1.1.1.2.2.2  bouyer     if (PrevNode)
    200  1.1.1.2.2.2  bouyer     {
    201  1.1.1.2.2.2  bouyer         /* Node is not first child, unlink it */
    202  1.1.1.2.2.2  bouyer 
    203  1.1.1.2.2.2  bouyer         PrevNode->Peer = Node->Peer;
    204  1.1.1.2.2.2  bouyer     }
    205  1.1.1.2.2.2  bouyer     else
    206  1.1.1.2.2.2  bouyer     {
    207  1.1.1.2.2.2  bouyer         /*
    208  1.1.1.2.2.2  bouyer          * Node is first child (has no previous peer).
    209  1.1.1.2.2.2  bouyer          * Link peer list to parent
    210  1.1.1.2.2.2  bouyer          */
    211  1.1.1.2.2.2  bouyer         ParentNode->Child = Node->Peer;
    212  1.1.1.2.2.2  bouyer     }
    213  1.1.1.2.2.2  bouyer 
    214  1.1.1.2.2.2  bouyer     /* Delete the node and any attached objects */
    215  1.1.1.2.2.2  bouyer 
    216  1.1.1.2.2.2  bouyer     AcpiNsDeleteNode (Node);
    217  1.1.1.2.2.2  bouyer     return_VOID;
    218  1.1.1.2.2.2  bouyer }
    219  1.1.1.2.2.2  bouyer 
    220  1.1.1.2.2.2  bouyer 
    221  1.1.1.2.2.2  bouyer /*******************************************************************************
    222  1.1.1.2.2.2  bouyer  *
    223  1.1.1.2.2.2  bouyer  * FUNCTION:    AcpiNsInstallNode
    224  1.1.1.2.2.2  bouyer  *
    225  1.1.1.2.2.2  bouyer  * PARAMETERS:  WalkState       - Current state of the walk
    226  1.1.1.2.2.2  bouyer  *              ParentNode      - The parent of the new Node
    227  1.1.1.2.2.2  bouyer  *              Node            - The new Node to install
    228  1.1.1.2.2.2  bouyer  *              Type            - ACPI object type of the new Node
    229  1.1.1.2.2.2  bouyer  *
    230  1.1.1.2.2.2  bouyer  * RETURN:      None
    231  1.1.1.2.2.2  bouyer  *
    232  1.1.1.2.2.2  bouyer  * DESCRIPTION: Initialize a new namespace node and install it amongst
    233  1.1.1.2.2.2  bouyer  *              its peers.
    234  1.1.1.2.2.2  bouyer  *
    235  1.1.1.2.2.2  bouyer  *              Note: Current namespace lookup is linear search. This appears
    236  1.1.1.2.2.2  bouyer  *              to be sufficient as namespace searches consume only a small
    237  1.1.1.2.2.2  bouyer  *              fraction of the execution time of the ACPI subsystem.
    238  1.1.1.2.2.2  bouyer  *
    239  1.1.1.2.2.2  bouyer  ******************************************************************************/
    240  1.1.1.2.2.2  bouyer 
    241  1.1.1.2.2.2  bouyer void
    242  1.1.1.2.2.2  bouyer AcpiNsInstallNode (
    243  1.1.1.2.2.2  bouyer     ACPI_WALK_STATE         *WalkState,
    244  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *ParentNode,    /* Parent */
    245  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *Node,          /* New Child*/
    246  1.1.1.2.2.2  bouyer     ACPI_OBJECT_TYPE        Type)
    247  1.1.1.2.2.2  bouyer {
    248  1.1.1.2.2.2  bouyer     ACPI_OWNER_ID           OwnerId = 0;
    249  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *ChildNode;
    250  1.1.1.2.2.2  bouyer 
    251  1.1.1.2.2.2  bouyer 
    252  1.1.1.2.2.2  bouyer     ACPI_FUNCTION_TRACE (NsInstallNode);
    253  1.1.1.2.2.2  bouyer 
    254  1.1.1.2.2.2  bouyer 
    255  1.1.1.2.2.2  bouyer     if (WalkState)
    256  1.1.1.2.2.2  bouyer     {
    257  1.1.1.2.2.2  bouyer         /*
    258  1.1.1.2.2.2  bouyer          * Get the owner ID from the Walk state. The owner ID is used to
    259  1.1.1.2.2.2  bouyer          * track table deletion and deletion of objects created by methods.
    260  1.1.1.2.2.2  bouyer          */
    261  1.1.1.2.2.2  bouyer         OwnerId = WalkState->OwnerId;
    262  1.1.1.2.2.2  bouyer 
    263  1.1.1.2.2.2  bouyer         if ((WalkState->MethodDesc) &&
    264  1.1.1.2.2.2  bouyer             (ParentNode != WalkState->MethodNode))
    265  1.1.1.2.2.2  bouyer         {
    266  1.1.1.2.2.2  bouyer             /*
    267  1.1.1.2.2.2  bouyer              * A method is creating a new node that is not a child of the
    268  1.1.1.2.2.2  bouyer              * method (it is non-local). Mark the executing method as having
    269  1.1.1.2.2.2  bouyer              * modified the namespace. This is used for cleanup when the
    270  1.1.1.2.2.2  bouyer              * method exits.
    271  1.1.1.2.2.2  bouyer              */
    272  1.1.1.2.2.2  bouyer             WalkState->MethodDesc->Method.InfoFlags |= ACPI_METHOD_MODIFIED_NAMESPACE;
    273  1.1.1.2.2.2  bouyer         }
    274  1.1.1.2.2.2  bouyer     }
    275  1.1.1.2.2.2  bouyer 
    276  1.1.1.2.2.2  bouyer     /* Link the new entry into the parent and existing children */
    277  1.1.1.2.2.2  bouyer 
    278  1.1.1.2.2.2  bouyer     Node->Peer = NULL;
    279  1.1.1.2.2.2  bouyer     Node->Parent = ParentNode;
    280  1.1.1.2.2.2  bouyer     ChildNode = ParentNode->Child;
    281  1.1.1.2.2.2  bouyer 
    282  1.1.1.2.2.2  bouyer     if (!ChildNode)
    283  1.1.1.2.2.2  bouyer     {
    284  1.1.1.2.2.2  bouyer         ParentNode->Child = Node;
    285  1.1.1.2.2.2  bouyer     }
    286  1.1.1.2.2.2  bouyer     else
    287  1.1.1.2.2.2  bouyer     {
    288  1.1.1.2.2.2  bouyer         /* Add node to the end of the peer list */
    289  1.1.1.2.2.2  bouyer 
    290  1.1.1.2.2.2  bouyer         while (ChildNode->Peer)
    291  1.1.1.2.2.2  bouyer         {
    292  1.1.1.2.2.2  bouyer             ChildNode = ChildNode->Peer;
    293  1.1.1.2.2.2  bouyer         }
    294  1.1.1.2.2.2  bouyer 
    295  1.1.1.2.2.2  bouyer         ChildNode->Peer = Node;
    296  1.1.1.2.2.2  bouyer     }
    297  1.1.1.2.2.2  bouyer 
    298  1.1.1.2.2.2  bouyer     /* Init the new entry */
    299  1.1.1.2.2.2  bouyer 
    300  1.1.1.2.2.2  bouyer     Node->OwnerId = OwnerId;
    301  1.1.1.2.2.2  bouyer     Node->Type = (UINT8) Type;
    302  1.1.1.2.2.2  bouyer 
    303  1.1.1.2.2.2  bouyer     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    304  1.1.1.2.2.2  bouyer         "%4.4s (%s) [Node %p Owner %X] added to %4.4s (%s) [Node %p]\n",
    305  1.1.1.2.2.2  bouyer         AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type), Node, OwnerId,
    306  1.1.1.2.2.2  bouyer         AcpiUtGetNodeName (ParentNode), AcpiUtGetTypeName (ParentNode->Type),
    307  1.1.1.2.2.2  bouyer         ParentNode));
    308  1.1.1.2.2.2  bouyer 
    309  1.1.1.2.2.2  bouyer     return_VOID;
    310  1.1.1.2.2.2  bouyer }
    311  1.1.1.2.2.2  bouyer 
    312  1.1.1.2.2.2  bouyer 
    313  1.1.1.2.2.2  bouyer /*******************************************************************************
    314  1.1.1.2.2.2  bouyer  *
    315  1.1.1.2.2.2  bouyer  * FUNCTION:    AcpiNsDeleteChildren
    316  1.1.1.2.2.2  bouyer  *
    317  1.1.1.2.2.2  bouyer  * PARAMETERS:  ParentNode      - Delete this objects children
    318  1.1.1.2.2.2  bouyer  *
    319  1.1.1.2.2.2  bouyer  * RETURN:      None.
    320  1.1.1.2.2.2  bouyer  *
    321  1.1.1.2.2.2  bouyer  * DESCRIPTION: Delete all children of the parent object. In other words,
    322  1.1.1.2.2.2  bouyer  *              deletes a "scope".
    323  1.1.1.2.2.2  bouyer  *
    324  1.1.1.2.2.2  bouyer  ******************************************************************************/
    325  1.1.1.2.2.2  bouyer 
    326  1.1.1.2.2.2  bouyer void
    327  1.1.1.2.2.2  bouyer AcpiNsDeleteChildren (
    328  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *ParentNode)
    329  1.1.1.2.2.2  bouyer {
    330  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *NextNode;
    331  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *NodeToDelete;
    332  1.1.1.2.2.2  bouyer 
    333  1.1.1.2.2.2  bouyer 
    334  1.1.1.2.2.2  bouyer     ACPI_FUNCTION_TRACE_PTR (NsDeleteChildren, ParentNode);
    335  1.1.1.2.2.2  bouyer 
    336  1.1.1.2.2.2  bouyer 
    337  1.1.1.2.2.2  bouyer     if (!ParentNode)
    338  1.1.1.2.2.2  bouyer     {
    339  1.1.1.2.2.2  bouyer         return_VOID;
    340  1.1.1.2.2.2  bouyer     }
    341  1.1.1.2.2.2  bouyer 
    342  1.1.1.2.2.2  bouyer     /* Deallocate all children at this level */
    343  1.1.1.2.2.2  bouyer 
    344  1.1.1.2.2.2  bouyer     NextNode = ParentNode->Child;
    345  1.1.1.2.2.2  bouyer     while (NextNode)
    346  1.1.1.2.2.2  bouyer     {
    347  1.1.1.2.2.2  bouyer         /* Grandchildren should have all been deleted already */
    348  1.1.1.2.2.2  bouyer 
    349  1.1.1.2.2.2  bouyer         if (NextNode->Child)
    350  1.1.1.2.2.2  bouyer         {
    351  1.1.1.2.2.2  bouyer             ACPI_ERROR ((AE_INFO, "Found a grandchild! P=%p C=%p",
    352  1.1.1.2.2.2  bouyer                 ParentNode, NextNode));
    353  1.1.1.2.2.2  bouyer         }
    354  1.1.1.2.2.2  bouyer 
    355  1.1.1.2.2.2  bouyer         /*
    356  1.1.1.2.2.2  bouyer          * Delete this child node and move on to the next child in the list.
    357  1.1.1.2.2.2  bouyer          * No need to unlink the node since we are deleting the entire branch.
    358  1.1.1.2.2.2  bouyer          */
    359  1.1.1.2.2.2  bouyer         NodeToDelete = NextNode;
    360  1.1.1.2.2.2  bouyer         NextNode = NextNode->Peer;
    361  1.1.1.2.2.2  bouyer         AcpiNsDeleteNode (NodeToDelete);
    362  1.1.1.2.2.2  bouyer     };
    363  1.1.1.2.2.2  bouyer 
    364  1.1.1.2.2.2  bouyer     /* Clear the parent's child pointer */
    365  1.1.1.2.2.2  bouyer 
    366  1.1.1.2.2.2  bouyer     ParentNode->Child = NULL;
    367  1.1.1.2.2.2  bouyer     return_VOID;
    368  1.1.1.2.2.2  bouyer }
    369  1.1.1.2.2.2  bouyer 
    370  1.1.1.2.2.2  bouyer 
    371  1.1.1.2.2.2  bouyer /*******************************************************************************
    372  1.1.1.2.2.2  bouyer  *
    373  1.1.1.2.2.2  bouyer  * FUNCTION:    AcpiNsDeleteNamespaceSubtree
    374  1.1.1.2.2.2  bouyer  *
    375  1.1.1.2.2.2  bouyer  * PARAMETERS:  ParentNode      - Root of the subtree to be deleted
    376  1.1.1.2.2.2  bouyer  *
    377  1.1.1.2.2.2  bouyer  * RETURN:      None.
    378  1.1.1.2.2.2  bouyer  *
    379  1.1.1.2.2.2  bouyer  * DESCRIPTION: Delete a subtree of the namespace.  This includes all objects
    380  1.1.1.2.2.2  bouyer  *              stored within the subtree.
    381  1.1.1.2.2.2  bouyer  *
    382  1.1.1.2.2.2  bouyer  ******************************************************************************/
    383  1.1.1.2.2.2  bouyer 
    384  1.1.1.2.2.2  bouyer void
    385  1.1.1.2.2.2  bouyer AcpiNsDeleteNamespaceSubtree (
    386  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *ParentNode)
    387  1.1.1.2.2.2  bouyer {
    388  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *ChildNode = NULL;
    389  1.1.1.2.2.2  bouyer     UINT32                  Level = 1;
    390  1.1.1.2.2.2  bouyer     ACPI_STATUS             Status;
    391  1.1.1.2.2.2  bouyer 
    392  1.1.1.2.2.2  bouyer 
    393  1.1.1.2.2.2  bouyer     ACPI_FUNCTION_TRACE (NsDeleteNamespaceSubtree);
    394  1.1.1.2.2.2  bouyer 
    395  1.1.1.2.2.2  bouyer 
    396  1.1.1.2.2.2  bouyer     if (!ParentNode)
    397  1.1.1.2.2.2  bouyer     {
    398  1.1.1.2.2.2  bouyer         return_VOID;
    399  1.1.1.2.2.2  bouyer     }
    400  1.1.1.2.2.2  bouyer 
    401  1.1.1.2.2.2  bouyer     /* Lock namespace for possible update */
    402  1.1.1.2.2.2  bouyer 
    403  1.1.1.2.2.2  bouyer     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    404  1.1.1.2.2.2  bouyer     if (ACPI_FAILURE (Status))
    405  1.1.1.2.2.2  bouyer     {
    406  1.1.1.2.2.2  bouyer         return_VOID;
    407  1.1.1.2.2.2  bouyer     }
    408  1.1.1.2.2.2  bouyer 
    409  1.1.1.2.2.2  bouyer     /*
    410  1.1.1.2.2.2  bouyer      * Traverse the tree of objects until we bubble back up
    411  1.1.1.2.2.2  bouyer      * to where we started.
    412  1.1.1.2.2.2  bouyer      */
    413  1.1.1.2.2.2  bouyer     while (Level > 0)
    414  1.1.1.2.2.2  bouyer     {
    415  1.1.1.2.2.2  bouyer         /* Get the next node in this scope (NULL if none) */
    416  1.1.1.2.2.2  bouyer 
    417  1.1.1.2.2.2  bouyer         ChildNode = AcpiNsGetNextNode (ParentNode, ChildNode);
    418  1.1.1.2.2.2  bouyer         if (ChildNode)
    419  1.1.1.2.2.2  bouyer         {
    420  1.1.1.2.2.2  bouyer             /* Found a child node - detach any attached object */
    421  1.1.1.2.2.2  bouyer 
    422  1.1.1.2.2.2  bouyer             AcpiNsDetachObject (ChildNode);
    423  1.1.1.2.2.2  bouyer 
    424  1.1.1.2.2.2  bouyer             /* Check if this node has any children */
    425  1.1.1.2.2.2  bouyer 
    426  1.1.1.2.2.2  bouyer             if (ChildNode->Child)
    427  1.1.1.2.2.2  bouyer             {
    428  1.1.1.2.2.2  bouyer                 /*
    429  1.1.1.2.2.2  bouyer                  * There is at least one child of this node,
    430  1.1.1.2.2.2  bouyer                  * visit the node
    431  1.1.1.2.2.2  bouyer                  */
    432  1.1.1.2.2.2  bouyer                 Level++;
    433  1.1.1.2.2.2  bouyer                 ParentNode = ChildNode;
    434  1.1.1.2.2.2  bouyer                 ChildNode  = NULL;
    435  1.1.1.2.2.2  bouyer             }
    436  1.1.1.2.2.2  bouyer         }
    437  1.1.1.2.2.2  bouyer         else
    438  1.1.1.2.2.2  bouyer         {
    439  1.1.1.2.2.2  bouyer             /*
    440  1.1.1.2.2.2  bouyer              * No more children of this parent node.
    441  1.1.1.2.2.2  bouyer              * Move up to the grandparent.
    442  1.1.1.2.2.2  bouyer              */
    443  1.1.1.2.2.2  bouyer             Level--;
    444  1.1.1.2.2.2  bouyer 
    445  1.1.1.2.2.2  bouyer             /*
    446  1.1.1.2.2.2  bouyer              * Now delete all of the children of this parent
    447  1.1.1.2.2.2  bouyer              * all at the same time.
    448  1.1.1.2.2.2  bouyer              */
    449  1.1.1.2.2.2  bouyer             AcpiNsDeleteChildren (ParentNode);
    450  1.1.1.2.2.2  bouyer 
    451  1.1.1.2.2.2  bouyer             /* New "last child" is this parent node */
    452  1.1.1.2.2.2  bouyer 
    453  1.1.1.2.2.2  bouyer             ChildNode = ParentNode;
    454  1.1.1.2.2.2  bouyer 
    455  1.1.1.2.2.2  bouyer             /* Move up the tree to the grandparent */
    456  1.1.1.2.2.2  bouyer 
    457  1.1.1.2.2.2  bouyer             ParentNode = ParentNode->Parent;
    458  1.1.1.2.2.2  bouyer         }
    459  1.1.1.2.2.2  bouyer     }
    460  1.1.1.2.2.2  bouyer 
    461  1.1.1.2.2.2  bouyer     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    462  1.1.1.2.2.2  bouyer     return_VOID;
    463  1.1.1.2.2.2  bouyer }
    464  1.1.1.2.2.2  bouyer 
    465  1.1.1.2.2.2  bouyer 
    466  1.1.1.2.2.2  bouyer /*******************************************************************************
    467  1.1.1.2.2.2  bouyer  *
    468  1.1.1.2.2.2  bouyer  * FUNCTION:    AcpiNsDeleteNamespaceByOwner
    469  1.1.1.2.2.2  bouyer  *
    470  1.1.1.2.2.2  bouyer  * PARAMETERS:  OwnerId     - All nodes with this owner will be deleted
    471  1.1.1.2.2.2  bouyer  *
    472  1.1.1.2.2.2  bouyer  * RETURN:      Status
    473  1.1.1.2.2.2  bouyer  *
    474  1.1.1.2.2.2  bouyer  * DESCRIPTION: Delete entries within the namespace that are owned by a
    475  1.1.1.2.2.2  bouyer  *              specific ID.  Used to delete entire ACPI tables.  All
    476  1.1.1.2.2.2  bouyer  *              reference counts are updated.
    477  1.1.1.2.2.2  bouyer  *
    478  1.1.1.2.2.2  bouyer  * MUTEX:       Locks namespace during deletion walk.
    479  1.1.1.2.2.2  bouyer  *
    480  1.1.1.2.2.2  bouyer  ******************************************************************************/
    481  1.1.1.2.2.2  bouyer 
    482  1.1.1.2.2.2  bouyer void
    483  1.1.1.2.2.2  bouyer AcpiNsDeleteNamespaceByOwner (
    484  1.1.1.2.2.2  bouyer     ACPI_OWNER_ID            OwnerId)
    485  1.1.1.2.2.2  bouyer {
    486  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *ChildNode;
    487  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *DeletionNode;
    488  1.1.1.2.2.2  bouyer     ACPI_NAMESPACE_NODE     *ParentNode;
    489  1.1.1.2.2.2  bouyer     UINT32                  Level;
    490  1.1.1.2.2.2  bouyer     ACPI_STATUS             Status;
    491  1.1.1.2.2.2  bouyer 
    492  1.1.1.2.2.2  bouyer 
    493  1.1.1.2.2.2  bouyer     ACPI_FUNCTION_TRACE_U32 (NsDeleteNamespaceByOwner, OwnerId);
    494  1.1.1.2.2.2  bouyer 
    495  1.1.1.2.2.2  bouyer 
    496  1.1.1.2.2.2  bouyer     if (OwnerId == 0)
    497  1.1.1.2.2.2  bouyer     {
    498  1.1.1.2.2.2  bouyer         return_VOID;
    499  1.1.1.2.2.2  bouyer     }
    500  1.1.1.2.2.2  bouyer 
    501  1.1.1.2.2.2  bouyer     /* Lock namespace for possible update */
    502  1.1.1.2.2.2  bouyer 
    503  1.1.1.2.2.2  bouyer     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    504  1.1.1.2.2.2  bouyer     if (ACPI_FAILURE (Status))
    505  1.1.1.2.2.2  bouyer     {
    506  1.1.1.2.2.2  bouyer         return_VOID;
    507  1.1.1.2.2.2  bouyer     }
    508  1.1.1.2.2.2  bouyer 
    509  1.1.1.2.2.2  bouyer     DeletionNode = NULL;
    510  1.1.1.2.2.2  bouyer     ParentNode = AcpiGbl_RootNode;
    511  1.1.1.2.2.2  bouyer     ChildNode = NULL;
    512  1.1.1.2.2.2  bouyer     Level = 1;
    513  1.1.1.2.2.2  bouyer 
    514  1.1.1.2.2.2  bouyer     /*
    515  1.1.1.2.2.2  bouyer      * Traverse the tree of nodes until we bubble back up
    516  1.1.1.2.2.2  bouyer      * to where we started.
    517  1.1.1.2.2.2  bouyer      */
    518  1.1.1.2.2.2  bouyer     while (Level > 0)
    519  1.1.1.2.2.2  bouyer     {
    520  1.1.1.2.2.2  bouyer         /*
    521  1.1.1.2.2.2  bouyer          * Get the next child of this parent node. When ChildNode is NULL,
    522  1.1.1.2.2.2  bouyer          * the first child of the parent is returned
    523  1.1.1.2.2.2  bouyer          */
    524  1.1.1.2.2.2  bouyer         ChildNode = AcpiNsGetNextNode (ParentNode, ChildNode);
    525  1.1.1.2.2.2  bouyer 
    526  1.1.1.2.2.2  bouyer         if (DeletionNode)
    527  1.1.1.2.2.2  bouyer         {
    528  1.1.1.2.2.2  bouyer             AcpiNsDeleteChildren (DeletionNode);
    529  1.1.1.2.2.2  bouyer             AcpiNsRemoveNode (DeletionNode);
    530  1.1.1.2.2.2  bouyer             DeletionNode = NULL;
    531  1.1.1.2.2.2  bouyer         }
    532  1.1.1.2.2.2  bouyer 
    533  1.1.1.2.2.2  bouyer         if (ChildNode)
    534  1.1.1.2.2.2  bouyer         {
    535  1.1.1.2.2.2  bouyer             if (ChildNode->OwnerId == OwnerId)
    536  1.1.1.2.2.2  bouyer             {
    537  1.1.1.2.2.2  bouyer                 /* Found a matching child node - detach any attached object */
    538  1.1.1.2.2.2  bouyer 
    539  1.1.1.2.2.2  bouyer                 AcpiNsDetachObject (ChildNode);
    540  1.1.1.2.2.2  bouyer             }
    541  1.1.1.2.2.2  bouyer 
    542  1.1.1.2.2.2  bouyer             /* Check if this node has any children */
    543  1.1.1.2.2.2  bouyer 
    544  1.1.1.2.2.2  bouyer             if (ChildNode->Child)
    545  1.1.1.2.2.2  bouyer             {
    546  1.1.1.2.2.2  bouyer                 /*
    547  1.1.1.2.2.2  bouyer                  * There is at least one child of this node,
    548  1.1.1.2.2.2  bouyer                  * visit the node
    549  1.1.1.2.2.2  bouyer                  */
    550  1.1.1.2.2.2  bouyer                 Level++;
    551  1.1.1.2.2.2  bouyer                 ParentNode = ChildNode;
    552  1.1.1.2.2.2  bouyer                 ChildNode  = NULL;
    553  1.1.1.2.2.2  bouyer             }
    554  1.1.1.2.2.2  bouyer             else if (ChildNode->OwnerId == OwnerId)
    555  1.1.1.2.2.2  bouyer             {
    556  1.1.1.2.2.2  bouyer                 DeletionNode = ChildNode;
    557  1.1.1.2.2.2  bouyer             }
    558  1.1.1.2.2.2  bouyer         }
    559  1.1.1.2.2.2  bouyer         else
    560  1.1.1.2.2.2  bouyer         {
    561  1.1.1.2.2.2  bouyer             /*
    562  1.1.1.2.2.2  bouyer              * No more children of this parent node.
    563  1.1.1.2.2.2  bouyer              * Move up to the grandparent.
    564  1.1.1.2.2.2  bouyer              */
    565  1.1.1.2.2.2  bouyer             Level--;
    566  1.1.1.2.2.2  bouyer             if (Level != 0)
    567  1.1.1.2.2.2  bouyer             {
    568  1.1.1.2.2.2  bouyer                 if (ParentNode->OwnerId == OwnerId)
    569  1.1.1.2.2.2  bouyer                 {
    570  1.1.1.2.2.2  bouyer                     DeletionNode = ParentNode;
    571  1.1.1.2.2.2  bouyer                 }
    572  1.1.1.2.2.2  bouyer             }
    573  1.1.1.2.2.2  bouyer 
    574  1.1.1.2.2.2  bouyer             /* New "last child" is this parent node */
    575  1.1.1.2.2.2  bouyer 
    576  1.1.1.2.2.2  bouyer             ChildNode = ParentNode;
    577  1.1.1.2.2.2  bouyer 
    578  1.1.1.2.2.2  bouyer             /* Move up the tree to the grandparent */
    579  1.1.1.2.2.2  bouyer 
    580  1.1.1.2.2.2  bouyer             ParentNode = ParentNode->Parent;
    581  1.1.1.2.2.2  bouyer         }
    582  1.1.1.2.2.2  bouyer     }
    583  1.1.1.2.2.2  bouyer 
    584  1.1.1.2.2.2  bouyer     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    585  1.1.1.2.2.2  bouyer     return_VOID;
    586  1.1.1.2.2.2  bouyer }
    587  1.1.1.2.2.2  bouyer 
    588  1.1.1.2.2.2  bouyer 
    589