1433d6423SLionel Sambuc /*******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: nsalloc - Namespace allocation and deletion utilities
4433d6423SLionel Sambuc *
5433d6423SLionel Sambuc ******************************************************************************/
6433d6423SLionel Sambuc
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc * All rights reserved.
10433d6423SLionel Sambuc *
11*29492bb7SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek * are met:
14*29492bb7SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek * notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek * without modification.
17*29492bb7SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek * substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek * ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek * including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek * binary redistribution.
22*29492bb7SDavid van Moolenbroek * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek * of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek * from this software without specific prior written permission.
25433d6423SLionel Sambuc *
26*29492bb7SDavid van Moolenbroek * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek * Software Foundation.
29433d6423SLionel Sambuc *
30*29492bb7SDavid van Moolenbroek * NO WARRANTY
31*29492bb7SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek */
43433d6423SLionel Sambuc
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "acnamesp.h"
47433d6423SLionel Sambuc
48433d6423SLionel Sambuc
49433d6423SLionel Sambuc #define _COMPONENT ACPI_NAMESPACE
50433d6423SLionel Sambuc ACPI_MODULE_NAME ("nsalloc")
51433d6423SLionel Sambuc
52433d6423SLionel Sambuc
53433d6423SLionel Sambuc /*******************************************************************************
54433d6423SLionel Sambuc *
55433d6423SLionel Sambuc * FUNCTION: AcpiNsCreateNode
56433d6423SLionel Sambuc *
57433d6423SLionel Sambuc * PARAMETERS: Name - Name of the new node (4 char ACPI name)
58433d6423SLionel Sambuc *
59433d6423SLionel Sambuc * RETURN: New namespace node (Null on failure)
60433d6423SLionel Sambuc *
61433d6423SLionel Sambuc * DESCRIPTION: Create a namespace node
62433d6423SLionel Sambuc *
63433d6423SLionel Sambuc ******************************************************************************/
64433d6423SLionel Sambuc
65433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *
AcpiNsCreateNode(UINT32 Name)66433d6423SLionel Sambuc AcpiNsCreateNode (
67433d6423SLionel Sambuc UINT32 Name)
68433d6423SLionel Sambuc {
69433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node;
70433d6423SLionel Sambuc #ifdef ACPI_DBG_TRACK_ALLOCATIONS
71433d6423SLionel Sambuc UINT32 Temp;
72433d6423SLionel Sambuc #endif
73433d6423SLionel Sambuc
74433d6423SLionel Sambuc
75433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (NsCreateNode);
76433d6423SLionel Sambuc
77433d6423SLionel Sambuc
78433d6423SLionel Sambuc Node = AcpiOsAcquireObject (AcpiGbl_NamespaceCache);
79433d6423SLionel Sambuc if (!Node)
80433d6423SLionel Sambuc {
81433d6423SLionel Sambuc return_PTR (NULL);
82433d6423SLionel Sambuc }
83433d6423SLionel Sambuc
84433d6423SLionel Sambuc ACPI_MEM_TRACKING (AcpiGbl_NsNodeList->TotalAllocated++);
85433d6423SLionel Sambuc
86433d6423SLionel Sambuc #ifdef ACPI_DBG_TRACK_ALLOCATIONS
87433d6423SLionel Sambuc Temp = AcpiGbl_NsNodeList->TotalAllocated -
88433d6423SLionel Sambuc AcpiGbl_NsNodeList->TotalFreed;
89433d6423SLionel Sambuc if (Temp > AcpiGbl_NsNodeList->MaxOccupied)
90433d6423SLionel Sambuc {
91433d6423SLionel Sambuc AcpiGbl_NsNodeList->MaxOccupied = Temp;
92433d6423SLionel Sambuc }
93433d6423SLionel Sambuc #endif
94433d6423SLionel Sambuc
95433d6423SLionel Sambuc Node->Name.Integer = Name;
96433d6423SLionel Sambuc ACPI_SET_DESCRIPTOR_TYPE (Node, ACPI_DESC_TYPE_NAMED);
97433d6423SLionel Sambuc return_PTR (Node);
98433d6423SLionel Sambuc }
99433d6423SLionel Sambuc
100433d6423SLionel Sambuc
101433d6423SLionel Sambuc /*******************************************************************************
102433d6423SLionel Sambuc *
103433d6423SLionel Sambuc * FUNCTION: AcpiNsDeleteNode
104433d6423SLionel Sambuc *
105433d6423SLionel Sambuc * PARAMETERS: Node - Node to be deleted
106433d6423SLionel Sambuc *
107433d6423SLionel Sambuc * RETURN: None
108433d6423SLionel Sambuc *
109433d6423SLionel Sambuc * DESCRIPTION: Delete a namespace node. All node deletions must come through
110433d6423SLionel Sambuc * here. Detaches any attached objects, including any attached
111433d6423SLionel Sambuc * data. If a handler is associated with attached data, it is
112433d6423SLionel Sambuc * invoked before the node is deleted.
113433d6423SLionel Sambuc *
114433d6423SLionel Sambuc ******************************************************************************/
115433d6423SLionel Sambuc
116433d6423SLionel Sambuc void
AcpiNsDeleteNode(ACPI_NAMESPACE_NODE * Node)117433d6423SLionel Sambuc AcpiNsDeleteNode (
118433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node)
119433d6423SLionel Sambuc {
120433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ObjDesc;
121*29492bb7SDavid van Moolenbroek ACPI_OPERAND_OBJECT *NextDesc;
122433d6423SLionel Sambuc
123433d6423SLionel Sambuc
124433d6423SLionel Sambuc ACPI_FUNCTION_NAME (NsDeleteNode);
125433d6423SLionel Sambuc
126433d6423SLionel Sambuc
127433d6423SLionel Sambuc /* Detach an object if there is one */
128433d6423SLionel Sambuc
129433d6423SLionel Sambuc AcpiNsDetachObject (Node);
130433d6423SLionel Sambuc
131433d6423SLionel Sambuc /*
132*29492bb7SDavid van Moolenbroek * Delete an attached data object list if present (objects that were
133*29492bb7SDavid van Moolenbroek * attached via AcpiAttachData). Note: After any normal object is
134*29492bb7SDavid van Moolenbroek * detached above, the only possible remaining object(s) are data
135*29492bb7SDavid van Moolenbroek * objects, in a linked list.
136433d6423SLionel Sambuc */
137433d6423SLionel Sambuc ObjDesc = Node->Object;
138*29492bb7SDavid van Moolenbroek while (ObjDesc &&
139433d6423SLionel Sambuc (ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA))
140433d6423SLionel Sambuc {
141433d6423SLionel Sambuc /* Invoke the attached data deletion handler if present */
142433d6423SLionel Sambuc
143433d6423SLionel Sambuc if (ObjDesc->Data.Handler)
144433d6423SLionel Sambuc {
145433d6423SLionel Sambuc ObjDesc->Data.Handler (Node, ObjDesc->Data.Pointer);
146433d6423SLionel Sambuc }
147433d6423SLionel Sambuc
148*29492bb7SDavid van Moolenbroek NextDesc = ObjDesc->Common.NextObject;
149433d6423SLionel Sambuc AcpiUtRemoveReference (ObjDesc);
150*29492bb7SDavid van Moolenbroek ObjDesc = NextDesc;
151*29492bb7SDavid van Moolenbroek }
152*29492bb7SDavid van Moolenbroek
153*29492bb7SDavid van Moolenbroek /* Special case for the statically allocated root node */
154*29492bb7SDavid van Moolenbroek
155*29492bb7SDavid van Moolenbroek if (Node == AcpiGbl_RootNode)
156*29492bb7SDavid van Moolenbroek {
157*29492bb7SDavid van Moolenbroek return;
158433d6423SLionel Sambuc }
159433d6423SLionel Sambuc
160433d6423SLionel Sambuc /* Now we can delete the node */
161433d6423SLionel Sambuc
162433d6423SLionel Sambuc (void) AcpiOsReleaseObject (AcpiGbl_NamespaceCache, Node);
163433d6423SLionel Sambuc
164433d6423SLionel Sambuc ACPI_MEM_TRACKING (AcpiGbl_NsNodeList->TotalFreed++);
165433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Node %p, Remaining %X\n",
166433d6423SLionel Sambuc Node, AcpiGbl_CurrentNodeCount));
167433d6423SLionel Sambuc }
168433d6423SLionel Sambuc
169433d6423SLionel Sambuc
170433d6423SLionel Sambuc /*******************************************************************************
171433d6423SLionel Sambuc *
172433d6423SLionel Sambuc * FUNCTION: AcpiNsRemoveNode
173433d6423SLionel Sambuc *
174433d6423SLionel Sambuc * PARAMETERS: Node - Node to be removed/deleted
175433d6423SLionel Sambuc *
176433d6423SLionel Sambuc * RETURN: None
177433d6423SLionel Sambuc *
178433d6423SLionel Sambuc * DESCRIPTION: Remove (unlink) and delete a namespace node
179433d6423SLionel Sambuc *
180433d6423SLionel Sambuc ******************************************************************************/
181433d6423SLionel Sambuc
182433d6423SLionel Sambuc void
AcpiNsRemoveNode(ACPI_NAMESPACE_NODE * Node)183433d6423SLionel Sambuc AcpiNsRemoveNode (
184433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node)
185433d6423SLionel Sambuc {
186433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *ParentNode;
187433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *PrevNode;
188433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *NextNode;
189433d6423SLionel Sambuc
190433d6423SLionel Sambuc
191433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_PTR (NsRemoveNode, Node);
192433d6423SLionel Sambuc
193433d6423SLionel Sambuc
194433d6423SLionel Sambuc ParentNode = Node->Parent;
195433d6423SLionel Sambuc
196433d6423SLionel Sambuc PrevNode = NULL;
197433d6423SLionel Sambuc NextNode = ParentNode->Child;
198433d6423SLionel Sambuc
199433d6423SLionel Sambuc /* Find the node that is the previous peer in the parent's child list */
200433d6423SLionel Sambuc
201433d6423SLionel Sambuc while (NextNode != Node)
202433d6423SLionel Sambuc {
203433d6423SLionel Sambuc PrevNode = NextNode;
204433d6423SLionel Sambuc NextNode = NextNode->Peer;
205433d6423SLionel Sambuc }
206433d6423SLionel Sambuc
207433d6423SLionel Sambuc if (PrevNode)
208433d6423SLionel Sambuc {
209433d6423SLionel Sambuc /* Node is not first child, unlink it */
210433d6423SLionel Sambuc
211433d6423SLionel Sambuc PrevNode->Peer = Node->Peer;
212433d6423SLionel Sambuc }
213433d6423SLionel Sambuc else
214433d6423SLionel Sambuc {
215433d6423SLionel Sambuc /*
216433d6423SLionel Sambuc * Node is first child (has no previous peer).
217433d6423SLionel Sambuc * Link peer list to parent
218433d6423SLionel Sambuc */
219433d6423SLionel Sambuc ParentNode->Child = Node->Peer;
220433d6423SLionel Sambuc }
221433d6423SLionel Sambuc
222433d6423SLionel Sambuc /* Delete the node and any attached objects */
223433d6423SLionel Sambuc
224433d6423SLionel Sambuc AcpiNsDeleteNode (Node);
225433d6423SLionel Sambuc return_VOID;
226433d6423SLionel Sambuc }
227433d6423SLionel Sambuc
228433d6423SLionel Sambuc
229433d6423SLionel Sambuc /*******************************************************************************
230433d6423SLionel Sambuc *
231433d6423SLionel Sambuc * FUNCTION: AcpiNsInstallNode
232433d6423SLionel Sambuc *
233433d6423SLionel Sambuc * PARAMETERS: WalkState - Current state of the walk
234433d6423SLionel Sambuc * ParentNode - The parent of the new Node
235433d6423SLionel Sambuc * Node - The new Node to install
236433d6423SLionel Sambuc * Type - ACPI object type of the new Node
237433d6423SLionel Sambuc *
238433d6423SLionel Sambuc * RETURN: None
239433d6423SLionel Sambuc *
240433d6423SLionel Sambuc * DESCRIPTION: Initialize a new namespace node and install it amongst
241433d6423SLionel Sambuc * its peers.
242433d6423SLionel Sambuc *
243433d6423SLionel Sambuc * Note: Current namespace lookup is linear search. This appears
244433d6423SLionel Sambuc * to be sufficient as namespace searches consume only a small
245433d6423SLionel Sambuc * fraction of the execution time of the ACPI subsystem.
246433d6423SLionel Sambuc *
247433d6423SLionel Sambuc ******************************************************************************/
248433d6423SLionel Sambuc
249433d6423SLionel Sambuc void
AcpiNsInstallNode(ACPI_WALK_STATE * WalkState,ACPI_NAMESPACE_NODE * ParentNode,ACPI_NAMESPACE_NODE * Node,ACPI_OBJECT_TYPE Type)250433d6423SLionel Sambuc AcpiNsInstallNode (
251433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState,
252433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *ParentNode, /* Parent */
253433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node, /* New Child*/
254433d6423SLionel Sambuc ACPI_OBJECT_TYPE Type)
255433d6423SLionel Sambuc {
256433d6423SLionel Sambuc ACPI_OWNER_ID OwnerId = 0;
257433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *ChildNode;
258433d6423SLionel Sambuc
259433d6423SLionel Sambuc
260433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (NsInstallNode);
261433d6423SLionel Sambuc
262433d6423SLionel Sambuc
263433d6423SLionel Sambuc if (WalkState)
264433d6423SLionel Sambuc {
265433d6423SLionel Sambuc /*
266433d6423SLionel Sambuc * Get the owner ID from the Walk state. The owner ID is used to
267433d6423SLionel Sambuc * track table deletion and deletion of objects created by methods.
268433d6423SLionel Sambuc */
269433d6423SLionel Sambuc OwnerId = WalkState->OwnerId;
270433d6423SLionel Sambuc
271433d6423SLionel Sambuc if ((WalkState->MethodDesc) &&
272433d6423SLionel Sambuc (ParentNode != WalkState->MethodNode))
273433d6423SLionel Sambuc {
274433d6423SLionel Sambuc /*
275433d6423SLionel Sambuc * A method is creating a new node that is not a child of the
276433d6423SLionel Sambuc * method (it is non-local). Mark the executing method as having
277433d6423SLionel Sambuc * modified the namespace. This is used for cleanup when the
278433d6423SLionel Sambuc * method exits.
279433d6423SLionel Sambuc */
280*29492bb7SDavid van Moolenbroek WalkState->MethodDesc->Method.InfoFlags |= ACPI_METHOD_MODIFIED_NAMESPACE;
281433d6423SLionel Sambuc }
282433d6423SLionel Sambuc }
283433d6423SLionel Sambuc
284433d6423SLionel Sambuc /* Link the new entry into the parent and existing children */
285433d6423SLionel Sambuc
286433d6423SLionel Sambuc Node->Peer = NULL;
287433d6423SLionel Sambuc Node->Parent = ParentNode;
288433d6423SLionel Sambuc ChildNode = ParentNode->Child;
289433d6423SLionel Sambuc
290433d6423SLionel Sambuc if (!ChildNode)
291433d6423SLionel Sambuc {
292433d6423SLionel Sambuc ParentNode->Child = Node;
293433d6423SLionel Sambuc }
294433d6423SLionel Sambuc else
295433d6423SLionel Sambuc {
296433d6423SLionel Sambuc /* Add node to the end of the peer list */
297433d6423SLionel Sambuc
298433d6423SLionel Sambuc while (ChildNode->Peer)
299433d6423SLionel Sambuc {
300433d6423SLionel Sambuc ChildNode = ChildNode->Peer;
301433d6423SLionel Sambuc }
302433d6423SLionel Sambuc
303433d6423SLionel Sambuc ChildNode->Peer = Node;
304433d6423SLionel Sambuc }
305433d6423SLionel Sambuc
306433d6423SLionel Sambuc /* Init the new entry */
307433d6423SLionel Sambuc
308433d6423SLionel Sambuc Node->OwnerId = OwnerId;
309433d6423SLionel Sambuc Node->Type = (UINT8) Type;
310433d6423SLionel Sambuc
311433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
312433d6423SLionel Sambuc "%4.4s (%s) [Node %p Owner %X] added to %4.4s (%s) [Node %p]\n",
313433d6423SLionel Sambuc AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type), Node, OwnerId,
314433d6423SLionel Sambuc AcpiUtGetNodeName (ParentNode), AcpiUtGetTypeName (ParentNode->Type),
315433d6423SLionel Sambuc ParentNode));
316433d6423SLionel Sambuc
317433d6423SLionel Sambuc return_VOID;
318433d6423SLionel Sambuc }
319433d6423SLionel Sambuc
320433d6423SLionel Sambuc
321433d6423SLionel Sambuc /*******************************************************************************
322433d6423SLionel Sambuc *
323433d6423SLionel Sambuc * FUNCTION: AcpiNsDeleteChildren
324433d6423SLionel Sambuc *
325433d6423SLionel Sambuc * PARAMETERS: ParentNode - Delete this objects children
326433d6423SLionel Sambuc *
327433d6423SLionel Sambuc * RETURN: None.
328433d6423SLionel Sambuc *
329433d6423SLionel Sambuc * DESCRIPTION: Delete all children of the parent object. In other words,
330433d6423SLionel Sambuc * deletes a "scope".
331433d6423SLionel Sambuc *
332433d6423SLionel Sambuc ******************************************************************************/
333433d6423SLionel Sambuc
334433d6423SLionel Sambuc void
AcpiNsDeleteChildren(ACPI_NAMESPACE_NODE * ParentNode)335433d6423SLionel Sambuc AcpiNsDeleteChildren (
336433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *ParentNode)
337433d6423SLionel Sambuc {
338433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *NextNode;
339433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *NodeToDelete;
340433d6423SLionel Sambuc
341433d6423SLionel Sambuc
342433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_PTR (NsDeleteChildren, ParentNode);
343433d6423SLionel Sambuc
344433d6423SLionel Sambuc
345433d6423SLionel Sambuc if (!ParentNode)
346433d6423SLionel Sambuc {
347433d6423SLionel Sambuc return_VOID;
348433d6423SLionel Sambuc }
349433d6423SLionel Sambuc
350433d6423SLionel Sambuc /* Deallocate all children at this level */
351433d6423SLionel Sambuc
352433d6423SLionel Sambuc NextNode = ParentNode->Child;
353433d6423SLionel Sambuc while (NextNode)
354433d6423SLionel Sambuc {
355433d6423SLionel Sambuc /* Grandchildren should have all been deleted already */
356433d6423SLionel Sambuc
357433d6423SLionel Sambuc if (NextNode->Child)
358433d6423SLionel Sambuc {
359433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Found a grandchild! P=%p C=%p",
360433d6423SLionel Sambuc ParentNode, NextNode));
361433d6423SLionel Sambuc }
362433d6423SLionel Sambuc
363433d6423SLionel Sambuc /*
364433d6423SLionel Sambuc * Delete this child node and move on to the next child in the list.
365433d6423SLionel Sambuc * No need to unlink the node since we are deleting the entire branch.
366433d6423SLionel Sambuc */
367433d6423SLionel Sambuc NodeToDelete = NextNode;
368433d6423SLionel Sambuc NextNode = NextNode->Peer;
369433d6423SLionel Sambuc AcpiNsDeleteNode (NodeToDelete);
370433d6423SLionel Sambuc };
371433d6423SLionel Sambuc
372433d6423SLionel Sambuc /* Clear the parent's child pointer */
373433d6423SLionel Sambuc
374433d6423SLionel Sambuc ParentNode->Child = NULL;
375433d6423SLionel Sambuc return_VOID;
376433d6423SLionel Sambuc }
377433d6423SLionel Sambuc
378433d6423SLionel Sambuc
379433d6423SLionel Sambuc /*******************************************************************************
380433d6423SLionel Sambuc *
381433d6423SLionel Sambuc * FUNCTION: AcpiNsDeleteNamespaceSubtree
382433d6423SLionel Sambuc *
383433d6423SLionel Sambuc * PARAMETERS: ParentNode - Root of the subtree to be deleted
384433d6423SLionel Sambuc *
385433d6423SLionel Sambuc * RETURN: None.
386433d6423SLionel Sambuc *
387433d6423SLionel Sambuc * DESCRIPTION: Delete a subtree of the namespace. This includes all objects
388433d6423SLionel Sambuc * stored within the subtree.
389433d6423SLionel Sambuc *
390433d6423SLionel Sambuc ******************************************************************************/
391433d6423SLionel Sambuc
392433d6423SLionel Sambuc void
AcpiNsDeleteNamespaceSubtree(ACPI_NAMESPACE_NODE * ParentNode)393433d6423SLionel Sambuc AcpiNsDeleteNamespaceSubtree (
394433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *ParentNode)
395433d6423SLionel Sambuc {
396433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *ChildNode = NULL;
397433d6423SLionel Sambuc UINT32 Level = 1;
398*29492bb7SDavid van Moolenbroek ACPI_STATUS Status;
399433d6423SLionel Sambuc
400433d6423SLionel Sambuc
401433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (NsDeleteNamespaceSubtree);
402433d6423SLionel Sambuc
403433d6423SLionel Sambuc
404433d6423SLionel Sambuc if (!ParentNode)
405433d6423SLionel Sambuc {
406433d6423SLionel Sambuc return_VOID;
407433d6423SLionel Sambuc }
408433d6423SLionel Sambuc
409*29492bb7SDavid van Moolenbroek /* Lock namespace for possible update */
410*29492bb7SDavid van Moolenbroek
411*29492bb7SDavid van Moolenbroek Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
412*29492bb7SDavid van Moolenbroek if (ACPI_FAILURE (Status))
413*29492bb7SDavid van Moolenbroek {
414*29492bb7SDavid van Moolenbroek return_VOID;
415*29492bb7SDavid van Moolenbroek }
416*29492bb7SDavid van Moolenbroek
417433d6423SLionel Sambuc /*
418433d6423SLionel Sambuc * Traverse the tree of objects until we bubble back up
419433d6423SLionel Sambuc * to where we started.
420433d6423SLionel Sambuc */
421433d6423SLionel Sambuc while (Level > 0)
422433d6423SLionel Sambuc {
423433d6423SLionel Sambuc /* Get the next node in this scope (NULL if none) */
424433d6423SLionel Sambuc
425433d6423SLionel Sambuc ChildNode = AcpiNsGetNextNode (ParentNode, ChildNode);
426433d6423SLionel Sambuc if (ChildNode)
427433d6423SLionel Sambuc {
428433d6423SLionel Sambuc /* Found a child node - detach any attached object */
429433d6423SLionel Sambuc
430433d6423SLionel Sambuc AcpiNsDetachObject (ChildNode);
431433d6423SLionel Sambuc
432433d6423SLionel Sambuc /* Check if this node has any children */
433433d6423SLionel Sambuc
434433d6423SLionel Sambuc if (ChildNode->Child)
435433d6423SLionel Sambuc {
436433d6423SLionel Sambuc /*
437433d6423SLionel Sambuc * There is at least one child of this node,
438433d6423SLionel Sambuc * visit the node
439433d6423SLionel Sambuc */
440433d6423SLionel Sambuc Level++;
441433d6423SLionel Sambuc ParentNode = ChildNode;
442433d6423SLionel Sambuc ChildNode = NULL;
443433d6423SLionel Sambuc }
444433d6423SLionel Sambuc }
445433d6423SLionel Sambuc else
446433d6423SLionel Sambuc {
447433d6423SLionel Sambuc /*
448433d6423SLionel Sambuc * No more children of this parent node.
449433d6423SLionel Sambuc * Move up to the grandparent.
450433d6423SLionel Sambuc */
451433d6423SLionel Sambuc Level--;
452433d6423SLionel Sambuc
453433d6423SLionel Sambuc /*
454433d6423SLionel Sambuc * Now delete all of the children of this parent
455433d6423SLionel Sambuc * all at the same time.
456433d6423SLionel Sambuc */
457433d6423SLionel Sambuc AcpiNsDeleteChildren (ParentNode);
458433d6423SLionel Sambuc
459433d6423SLionel Sambuc /* New "last child" is this parent node */
460433d6423SLionel Sambuc
461433d6423SLionel Sambuc ChildNode = ParentNode;
462433d6423SLionel Sambuc
463433d6423SLionel Sambuc /* Move up the tree to the grandparent */
464433d6423SLionel Sambuc
465433d6423SLionel Sambuc ParentNode = ParentNode->Parent;
466433d6423SLionel Sambuc }
467433d6423SLionel Sambuc }
468433d6423SLionel Sambuc
469*29492bb7SDavid van Moolenbroek (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
470433d6423SLionel Sambuc return_VOID;
471433d6423SLionel Sambuc }
472433d6423SLionel Sambuc
473433d6423SLionel Sambuc
474433d6423SLionel Sambuc /*******************************************************************************
475433d6423SLionel Sambuc *
476433d6423SLionel Sambuc * FUNCTION: AcpiNsDeleteNamespaceByOwner
477433d6423SLionel Sambuc *
478433d6423SLionel Sambuc * PARAMETERS: OwnerId - All nodes with this owner will be deleted
479433d6423SLionel Sambuc *
480433d6423SLionel Sambuc * RETURN: Status
481433d6423SLionel Sambuc *
482433d6423SLionel Sambuc * DESCRIPTION: Delete entries within the namespace that are owned by a
483433d6423SLionel Sambuc * specific ID. Used to delete entire ACPI tables. All
484433d6423SLionel Sambuc * reference counts are updated.
485433d6423SLionel Sambuc *
486433d6423SLionel Sambuc * MUTEX: Locks namespace during deletion walk.
487433d6423SLionel Sambuc *
488433d6423SLionel Sambuc ******************************************************************************/
489433d6423SLionel Sambuc
490433d6423SLionel Sambuc void
AcpiNsDeleteNamespaceByOwner(ACPI_OWNER_ID OwnerId)491433d6423SLionel Sambuc AcpiNsDeleteNamespaceByOwner (
492433d6423SLionel Sambuc ACPI_OWNER_ID OwnerId)
493433d6423SLionel Sambuc {
494433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *ChildNode;
495433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *DeletionNode;
496433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *ParentNode;
497433d6423SLionel Sambuc UINT32 Level;
498433d6423SLionel Sambuc ACPI_STATUS Status;
499433d6423SLionel Sambuc
500433d6423SLionel Sambuc
501433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_U32 (NsDeleteNamespaceByOwner, OwnerId);
502433d6423SLionel Sambuc
503433d6423SLionel Sambuc
504433d6423SLionel Sambuc if (OwnerId == 0)
505433d6423SLionel Sambuc {
506433d6423SLionel Sambuc return_VOID;
507433d6423SLionel Sambuc }
508433d6423SLionel Sambuc
509433d6423SLionel Sambuc /* Lock namespace for possible update */
510433d6423SLionel Sambuc
511433d6423SLionel Sambuc Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
512433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
513433d6423SLionel Sambuc {
514433d6423SLionel Sambuc return_VOID;
515433d6423SLionel Sambuc }
516433d6423SLionel Sambuc
517433d6423SLionel Sambuc DeletionNode = NULL;
518433d6423SLionel Sambuc ParentNode = AcpiGbl_RootNode;
519433d6423SLionel Sambuc ChildNode = NULL;
520433d6423SLionel Sambuc Level = 1;
521433d6423SLionel Sambuc
522433d6423SLionel Sambuc /*
523433d6423SLionel Sambuc * Traverse the tree of nodes until we bubble back up
524433d6423SLionel Sambuc * to where we started.
525433d6423SLionel Sambuc */
526433d6423SLionel Sambuc while (Level > 0)
527433d6423SLionel Sambuc {
528433d6423SLionel Sambuc /*
529433d6423SLionel Sambuc * Get the next child of this parent node. When ChildNode is NULL,
530433d6423SLionel Sambuc * the first child of the parent is returned
531433d6423SLionel Sambuc */
532433d6423SLionel Sambuc ChildNode = AcpiNsGetNextNode (ParentNode, ChildNode);
533433d6423SLionel Sambuc
534433d6423SLionel Sambuc if (DeletionNode)
535433d6423SLionel Sambuc {
536433d6423SLionel Sambuc AcpiNsDeleteChildren (DeletionNode);
537433d6423SLionel Sambuc AcpiNsRemoveNode (DeletionNode);
538433d6423SLionel Sambuc DeletionNode = NULL;
539433d6423SLionel Sambuc }
540433d6423SLionel Sambuc
541433d6423SLionel Sambuc if (ChildNode)
542433d6423SLionel Sambuc {
543433d6423SLionel Sambuc if (ChildNode->OwnerId == OwnerId)
544433d6423SLionel Sambuc {
545433d6423SLionel Sambuc /* Found a matching child node - detach any attached object */
546433d6423SLionel Sambuc
547433d6423SLionel Sambuc AcpiNsDetachObject (ChildNode);
548433d6423SLionel Sambuc }
549433d6423SLionel Sambuc
550433d6423SLionel Sambuc /* Check if this node has any children */
551433d6423SLionel Sambuc
552433d6423SLionel Sambuc if (ChildNode->Child)
553433d6423SLionel Sambuc {
554433d6423SLionel Sambuc /*
555433d6423SLionel Sambuc * There is at least one child of this node,
556433d6423SLionel Sambuc * visit the node
557433d6423SLionel Sambuc */
558433d6423SLionel Sambuc Level++;
559433d6423SLionel Sambuc ParentNode = ChildNode;
560433d6423SLionel Sambuc ChildNode = NULL;
561433d6423SLionel Sambuc }
562433d6423SLionel Sambuc else if (ChildNode->OwnerId == OwnerId)
563433d6423SLionel Sambuc {
564433d6423SLionel Sambuc DeletionNode = ChildNode;
565433d6423SLionel Sambuc }
566433d6423SLionel Sambuc }
567433d6423SLionel Sambuc else
568433d6423SLionel Sambuc {
569433d6423SLionel Sambuc /*
570433d6423SLionel Sambuc * No more children of this parent node.
571433d6423SLionel Sambuc * Move up to the grandparent.
572433d6423SLionel Sambuc */
573433d6423SLionel Sambuc Level--;
574433d6423SLionel Sambuc if (Level != 0)
575433d6423SLionel Sambuc {
576433d6423SLionel Sambuc if (ParentNode->OwnerId == OwnerId)
577433d6423SLionel Sambuc {
578433d6423SLionel Sambuc DeletionNode = ParentNode;
579433d6423SLionel Sambuc }
580433d6423SLionel Sambuc }
581433d6423SLionel Sambuc
582433d6423SLionel Sambuc /* New "last child" is this parent node */
583433d6423SLionel Sambuc
584433d6423SLionel Sambuc ChildNode = ParentNode;
585433d6423SLionel Sambuc
586433d6423SLionel Sambuc /* Move up the tree to the grandparent */
587433d6423SLionel Sambuc
588433d6423SLionel Sambuc ParentNode = ParentNode->Parent;
589433d6423SLionel Sambuc }
590433d6423SLionel Sambuc }
591433d6423SLionel Sambuc
592433d6423SLionel Sambuc (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
593433d6423SLionel Sambuc return_VOID;
594433d6423SLionel Sambuc }
595