1 /*******************************************************************************
3 * Module Name: nsalloc - Namespace allocation and deletion utilities
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
118 #define __NSALLOC_C__
120 #include <contrib/dev/acpica/acpi.h>
121 #include <contrib/dev/acpica/acnamesp.h>
124 #define _COMPONENT ACPI_NAMESPACE
125 ACPI_MODULE_NAME ("nsalloc")
128 /*******************************************************************************
130 * FUNCTION: AcpiNsCreateNode
132 * PARAMETERS: Name - Name of the new node (4 char ACPI name)
134 * RETURN: New namespace node (Null on failure)
136 * DESCRIPTION: Create a namespace node
138 ******************************************************************************/
140 ACPI_NAMESPACE_NODE *
144 ACPI_NAMESPACE_NODE *Node;
145 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
150 ACPI_FUNCTION_TRACE (NsCreateNode);
153 Node = AcpiOsAcquireObject (AcpiGbl_NamespaceCache);
159 ACPI_MEM_TRACKING (AcpiGbl_NsNodeList->TotalAllocated++);
161 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
162 Temp = AcpiGbl_NsNodeList->TotalAllocated - AcpiGbl_NsNodeList->TotalFreed;
163 if (Temp > AcpiGbl_NsNodeList->MaxOccupied)
165 AcpiGbl_NsNodeList->MaxOccupied = Temp;
169 Node->Name.Integer = Name;
170 ACPI_SET_DESCRIPTOR_TYPE (Node, ACPI_DESC_TYPE_NAMED);
175 /*******************************************************************************
177 * FUNCTION: AcpiNsDeleteNode
179 * PARAMETERS: Node - Node to be deleted
183 * DESCRIPTION: Delete a namespace node
185 ******************************************************************************/
189 ACPI_NAMESPACE_NODE *Node)
191 ACPI_NAMESPACE_NODE *ParentNode;
192 ACPI_NAMESPACE_NODE *PrevNode;
193 ACPI_NAMESPACE_NODE *NextNode;
196 ACPI_FUNCTION_TRACE_PTR (NsDeleteNode, Node);
199 ParentNode = AcpiNsGetParentNode (Node);
202 NextNode = ParentNode->Child;
204 /* Find the node that is the previous peer in the parent's child list */
206 while (NextNode != Node)
209 NextNode = PrevNode->Peer;
214 /* Node is not first child, unlink it */
216 PrevNode->Peer = NextNode->Peer;
217 if (NextNode->Flags & ANOBJ_END_OF_PEER_LIST)
219 PrevNode->Flags |= ANOBJ_END_OF_PEER_LIST;
224 /* Node is first child (has no previous peer) */
226 if (NextNode->Flags & ANOBJ_END_OF_PEER_LIST)
228 /* No peers at all */
230 ParentNode->Child = NULL;
233 { /* Link peer list to parent */
235 ParentNode->Child = NextNode->Peer;
239 ACPI_MEM_TRACKING (AcpiGbl_NsNodeList->TotalFreed++);
242 * Detach an object if there is one, then delete the node
244 AcpiNsDetachObject (Node);
245 (void) AcpiOsReleaseObject (AcpiGbl_NamespaceCache, Node);
250 /*******************************************************************************
252 * FUNCTION: AcpiNsInstallNode
254 * PARAMETERS: WalkState - Current state of the walk
255 * ParentNode - The parent of the new Node
256 * Node - The new Node to install
257 * Type - ACPI object type of the new Node
261 * DESCRIPTION: Initialize a new namespace node and install it amongst
264 * Note: Current namespace lookup is linear search. This appears
265 * to be sufficient as namespace searches consume only a small
266 * fraction of the execution time of the ACPI subsystem.
268 ******************************************************************************/
272 ACPI_WALK_STATE *WalkState,
273 ACPI_NAMESPACE_NODE *ParentNode, /* Parent */
274 ACPI_NAMESPACE_NODE *Node, /* New Child*/
275 ACPI_OBJECT_TYPE Type)
277 ACPI_OWNER_ID OwnerId = 0;
278 ACPI_NAMESPACE_NODE *ChildNode;
281 ACPI_FUNCTION_TRACE (NsInstallNode);
285 * Get the owner ID from the Walk state
286 * The owner ID is used to track table deletion and
287 * deletion of objects created by methods
291 OwnerId = WalkState->OwnerId;
294 /* Link the new entry into the parent and existing children */
296 ChildNode = ParentNode->Child;
299 ParentNode->Child = Node;
300 Node->Flags |= ANOBJ_END_OF_PEER_LIST;
301 Node->Peer = ParentNode;
305 while (!(ChildNode->Flags & ANOBJ_END_OF_PEER_LIST))
307 ChildNode = ChildNode->Peer;
310 ChildNode->Peer = Node;
312 /* Clear end-of-list flag */
314 ChildNode->Flags &= ~ANOBJ_END_OF_PEER_LIST;
315 Node->Flags |= ANOBJ_END_OF_PEER_LIST;
316 Node->Peer = ParentNode;
319 /* Init the new entry */
321 Node->OwnerId = OwnerId;
322 Node->Type = (UINT8) Type;
324 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
325 "%4.4s (%s) [Node %p Owner %X] added to %4.4s (%s) [Node %p]\n",
326 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type), Node, OwnerId,
327 AcpiUtGetNodeName (ParentNode), AcpiUtGetTypeName (ParentNode->Type),
334 /*******************************************************************************
336 * FUNCTION: AcpiNsDeleteChildren
338 * PARAMETERS: ParentNode - Delete this objects children
342 * DESCRIPTION: Delete all children of the parent object. In other words,
345 ******************************************************************************/
348 AcpiNsDeleteChildren (
349 ACPI_NAMESPACE_NODE *ParentNode)
351 ACPI_NAMESPACE_NODE *ChildNode;
352 ACPI_NAMESPACE_NODE *NextNode;
356 ACPI_FUNCTION_TRACE_PTR (NsDeleteChildren, ParentNode);
364 /* If no children, all done! */
366 ChildNode = ParentNode->Child;
373 * Deallocate all children at this level
377 /* Get the things we need */
379 NextNode = ChildNode->Peer;
380 Flags = ChildNode->Flags;
382 /* Grandchildren should have all been deleted already */
384 if (ChildNode->Child)
386 ACPI_ERROR ((AE_INFO, "Found a grandchild! P=%p C=%p",
387 ParentNode, ChildNode));
390 /* Now we can free this child object */
392 ACPI_MEM_TRACKING (AcpiGbl_NsNodeList->TotalFreed++);
394 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Object %p, Remaining %X\n",
395 ChildNode, AcpiGbl_CurrentNodeCount));
398 * Detach an object if there is one, then free the child node
400 AcpiNsDetachObject (ChildNode);
402 /* Now we can delete the node */
404 (void) AcpiOsReleaseObject (AcpiGbl_NamespaceCache, ChildNode);
406 /* And move on to the next child in the list */
408 ChildNode = NextNode;
410 } while (!(Flags & ANOBJ_END_OF_PEER_LIST));
413 /* Clear the parent's child pointer */
415 ParentNode->Child = NULL;
421 /*******************************************************************************
423 * FUNCTION: AcpiNsDeleteNamespaceSubtree
425 * PARAMETERS: ParentNode - Root of the subtree to be deleted
429 * DESCRIPTION: Delete a subtree of the namespace. This includes all objects
430 * stored within the subtree.
432 ******************************************************************************/
435 AcpiNsDeleteNamespaceSubtree (
436 ACPI_NAMESPACE_NODE *ParentNode)
438 ACPI_NAMESPACE_NODE *ChildNode = NULL;
442 ACPI_FUNCTION_TRACE (NsDeleteNamespaceSubtree);
451 * Traverse the tree of objects until we bubble back up
452 * to where we started.
456 /* Get the next node in this scope (NULL if none) */
458 ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode, ChildNode);
461 /* Found a child node - detach any attached object */
463 AcpiNsDetachObject (ChildNode);
465 /* Check if this node has any children */
467 if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, NULL))
470 * There is at least one child of this node,
474 ParentNode = ChildNode;
481 * No more children of this parent node.
482 * Move up to the grandparent.
487 * Now delete all of the children of this parent
488 * all at the same time.
490 AcpiNsDeleteChildren (ParentNode);
492 /* New "last child" is this parent node */
494 ChildNode = ParentNode;
496 /* Move up the tree to the grandparent */
498 ParentNode = AcpiNsGetParentNode (ParentNode);
506 /*******************************************************************************
508 * FUNCTION: AcpiNsDeleteNamespaceByOwner
510 * PARAMETERS: OwnerId - All nodes with this owner will be deleted
514 * DESCRIPTION: Delete entries within the namespace that are owned by a
515 * specific ID. Used to delete entire ACPI tables. All
516 * reference counts are updated.
518 * MUTEX: Locks namespace during deletion walk.
520 ******************************************************************************/
523 AcpiNsDeleteNamespaceByOwner (
524 ACPI_OWNER_ID OwnerId)
526 ACPI_NAMESPACE_NODE *ChildNode;
527 ACPI_NAMESPACE_NODE *DeletionNode;
528 ACPI_NAMESPACE_NODE *ParentNode;
533 ACPI_FUNCTION_TRACE_U32 (NsDeleteNamespaceByOwner, OwnerId);
541 /* Lock namespace for possible update */
543 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
544 if (ACPI_FAILURE (Status))
550 ParentNode = AcpiGbl_RootNode;
555 * Traverse the tree of nodes until we bubble back up
556 * to where we started.
561 * Get the next child of this parent node. When ChildNode is NULL,
562 * the first child of the parent is returned
564 ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode, ChildNode);
568 AcpiNsDeleteChildren (DeletionNode);
569 AcpiNsDeleteNode (DeletionNode);
575 if (ChildNode->OwnerId == OwnerId)
577 /* Found a matching child node - detach any attached object */
579 AcpiNsDetachObject (ChildNode);
582 /* Check if this node has any children */
584 if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, NULL))
587 * There is at least one child of this node,
591 ParentNode = ChildNode;
594 else if (ChildNode->OwnerId == OwnerId)
596 DeletionNode = ChildNode;
602 * No more children of this parent node.
603 * Move up to the grandparent.
608 if (ParentNode->OwnerId == OwnerId)
610 DeletionNode = ParentNode;
614 /* New "last child" is this parent node */
616 ChildNode = ParentNode;
618 /* Move up the tree to the grandparent */
620 ParentNode = AcpiNsGetParentNode (ParentNode);
624 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);