Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygennsalloc.c
Go to the documentation of this file.
00001 /******************************************************************************* 00002 * 00003 * Module Name: nsalloc - Namespace allocation and deletion utilities 00004 * 00005 ******************************************************************************/ 00006 00007 /****************************************************************************** 00008 * 00009 * 1. Copyright Notice 00010 * 00011 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp. 00012 * All rights reserved. 00013 * 00014 * 2. License 00015 * 00016 * 2.1. This is your license from Intel Corp. under its intellectual property 00017 * rights. You may have additional license terms from the party that provided 00018 * you this software, covering your right to use that party's intellectual 00019 * property rights. 00020 * 00021 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 00022 * copy of the source code appearing in this file ("Covered Code") an 00023 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 00024 * base code distributed originally by Intel ("Original Intel Code") to copy, 00025 * make derivatives, distribute, use and display any portion of the Covered 00026 * Code in any form, with the right to sublicense such rights; and 00027 * 00028 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 00029 * license (with the right to sublicense), under only those claims of Intel 00030 * patents that are infringed by the Original Intel Code, to make, use, sell, 00031 * offer to sell, and import the Covered Code and derivative works thereof 00032 * solely to the minimum extent necessary to exercise the above copyright 00033 * license, and in no event shall the patent license extend to any additions 00034 * to or modifications of the Original Intel Code. No other license or right 00035 * is granted directly or by implication, estoppel or otherwise; 00036 * 00037 * The above copyright and patent license is granted only if the following 00038 * conditions are met: 00039 * 00040 * 3. Conditions 00041 * 00042 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 00043 * Redistribution of source code of any substantial portion of the Covered 00044 * Code or modification with rights to further distribute source must include 00045 * the above Copyright Notice, the above License, this list of Conditions, 00046 * and the following Disclaimer and Export Compliance provision. In addition, 00047 * Licensee must cause all Covered Code to which Licensee contributes to 00048 * contain a file documenting the changes Licensee made to create that Covered 00049 * Code and the date of any change. Licensee must include in that file the 00050 * documentation of any changes made by any predecessor Licensee. Licensee 00051 * must include a prominent statement that the modification is derived, 00052 * directly or indirectly, from Original Intel Code. 00053 * 00054 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 00055 * Redistribution of source code of any substantial portion of the Covered 00056 * Code or modification without rights to further distribute source must 00057 * include the following Disclaimer and Export Compliance provision in the 00058 * documentation and/or other materials provided with distribution. In 00059 * addition, Licensee may not authorize further sublicense of source of any 00060 * portion of the Covered Code, and must include terms to the effect that the 00061 * license from Licensee to its licensee is limited to the intellectual 00062 * property embodied in the software Licensee provides to its licensee, and 00063 * not to intellectual property embodied in modifications its licensee may 00064 * make. 00065 * 00066 * 3.3. Redistribution of Executable. Redistribution in executable form of any 00067 * substantial portion of the Covered Code or modification must reproduce the 00068 * above Copyright Notice, and the following Disclaimer and Export Compliance 00069 * provision in the documentation and/or other materials provided with the 00070 * distribution. 00071 * 00072 * 3.4. Intel retains all right, title, and interest in and to the Original 00073 * Intel Code. 00074 * 00075 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 00076 * Intel shall be used in advertising or otherwise to promote the sale, use or 00077 * other dealings in products derived from or relating to the Covered Code 00078 * without prior written authorization from Intel. 00079 * 00080 * 4. Disclaimer and Export Compliance 00081 * 00082 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 00083 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 00084 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 00085 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 00086 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 00087 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 00088 * PARTICULAR PURPOSE. 00089 * 00090 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 00091 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 00092 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 00093 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 00094 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 00095 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 00096 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 00097 * LIMITED REMEDY. 00098 * 00099 * 4.3. Licensee shall not export, either directly or indirectly, any of this 00100 * software or system incorporating such software without first obtaining any 00101 * required license or other approval from the U. S. Department of Commerce or 00102 * any other agency or department of the United States Government. In the 00103 * event Licensee exports any such software from the United States or 00104 * re-exports any such software from a foreign destination, Licensee shall 00105 * ensure that the distribution and export/re-export of the software is in 00106 * compliance with all laws, regulations, orders, or other restrictions of the 00107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 00108 * any of its subsidiaries will export/re-export any technical data, process, 00109 * software, or service, directly or indirectly, to any country for which the 00110 * United States government or any agency thereof requires an export license, 00111 * other governmental approval, or letter of assurance, without first obtaining 00112 * such license, approval or letter. 00113 * 00114 *****************************************************************************/ 00115 00116 00117 #define __NSALLOC_C__ 00118 00119 #include "acpi.h" 00120 #include "accommon.h" 00121 #include "acnamesp.h" 00122 00123 00124 #define _COMPONENT ACPI_NAMESPACE 00125 ACPI_MODULE_NAME ("nsalloc") 00126 00127 00128 /******************************************************************************* 00129 * 00130 * FUNCTION: AcpiNsCreateNode 00131 * 00132 * PARAMETERS: Name - Name of the new node (4 char ACPI name) 00133 * 00134 * RETURN: New namespace node (Null on failure) 00135 * 00136 * DESCRIPTION: Create a namespace node 00137 * 00138 ******************************************************************************/ 00139 00140 ACPI_NAMESPACE_NODE * 00141 AcpiNsCreateNode ( 00142 UINT32 Name) 00143 { 00144 ACPI_NAMESPACE_NODE *Node; 00145 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 00146 UINT32 Temp; 00147 #endif 00148 00149 00150 ACPI_FUNCTION_TRACE (NsCreateNode); 00151 00152 00153 Node = AcpiOsAcquireObject (AcpiGbl_NamespaceCache); 00154 if (!Node) 00155 { 00156 return_PTR (NULL); 00157 } 00158 00159 ACPI_MEM_TRACKING (AcpiGbl_NsNodeList->TotalAllocated++); 00160 00161 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 00162 Temp = AcpiGbl_NsNodeList->TotalAllocated - 00163 AcpiGbl_NsNodeList->TotalFreed; 00164 if (Temp > AcpiGbl_NsNodeList->MaxOccupied) 00165 { 00166 AcpiGbl_NsNodeList->MaxOccupied = Temp; 00167 } 00168 #endif 00169 00170 Node->Name.Integer = Name; 00171 ACPI_SET_DESCRIPTOR_TYPE (Node, ACPI_DESC_TYPE_NAMED); 00172 return_PTR (Node); 00173 } 00174 00175 00176 /******************************************************************************* 00177 * 00178 * FUNCTION: AcpiNsDeleteNode 00179 * 00180 * PARAMETERS: Node - Node to be deleted 00181 * 00182 * RETURN: None 00183 * 00184 * DESCRIPTION: Delete a namespace node. All node deletions must come through 00185 * here. Detaches any attached objects, including any attached 00186 * data. If a handler is associated with attached data, it is 00187 * invoked before the node is deleted. 00188 * 00189 ******************************************************************************/ 00190 00191 void 00192 AcpiNsDeleteNode ( 00193 ACPI_NAMESPACE_NODE *Node) 00194 { 00195 ACPI_OPERAND_OBJECT *ObjDesc; 00196 00197 00198 ACPI_FUNCTION_NAME (NsDeleteNode); 00199 00200 00201 /* Detach an object if there is one */ 00202 00203 AcpiNsDetachObject (Node); 00204 00205 /* 00206 * Delete an attached data object if present (an object that was created 00207 * and attached via AcpiAttachData). Note: After any normal object is 00208 * detached above, the only possible remaining object is a data object. 00209 */ 00210 ObjDesc = Node->Object; 00211 if (ObjDesc && 00212 (ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA)) 00213 { 00214 /* Invoke the attached data deletion handler if present */ 00215 00216 if (ObjDesc->Data.Handler) 00217 { 00218 ObjDesc->Data.Handler (Node, ObjDesc->Data.Pointer); 00219 } 00220 00221 AcpiUtRemoveReference (ObjDesc); 00222 } 00223 00224 /* Now we can delete the node */ 00225 00226 (void) AcpiOsReleaseObject (AcpiGbl_NamespaceCache, Node); 00227 00228 ACPI_MEM_TRACKING (AcpiGbl_NsNodeList->TotalFreed++); 00229 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Node %p, Remaining %X\n", 00230 Node, AcpiGbl_CurrentNodeCount)); 00231 } 00232 00233 00234 /******************************************************************************* 00235 * 00236 * FUNCTION: AcpiNsRemoveNode 00237 * 00238 * PARAMETERS: Node - Node to be removed/deleted 00239 * 00240 * RETURN: None 00241 * 00242 * DESCRIPTION: Remove (unlink) and delete a namespace node 00243 * 00244 ******************************************************************************/ 00245 00246 void 00247 AcpiNsRemoveNode ( 00248 ACPI_NAMESPACE_NODE *Node) 00249 { 00250 ACPI_NAMESPACE_NODE *ParentNode; 00251 ACPI_NAMESPACE_NODE *PrevNode; 00252 ACPI_NAMESPACE_NODE *NextNode; 00253 00254 00255 ACPI_FUNCTION_TRACE_PTR (NsRemoveNode, Node); 00256 00257 00258 ParentNode = Node->Parent; 00259 00260 PrevNode = NULL; 00261 NextNode = ParentNode->Child; 00262 00263 /* Find the node that is the previous peer in the parent's child list */ 00264 00265 while (NextNode != Node) 00266 { 00267 PrevNode = NextNode; 00268 NextNode = NextNode->Peer; 00269 } 00270 00271 if (PrevNode) 00272 { 00273 /* Node is not first child, unlink it */ 00274 00275 PrevNode->Peer = Node->Peer; 00276 } 00277 else 00278 { 00279 /* 00280 * Node is first child (has no previous peer). 00281 * Link peer list to parent 00282 */ 00283 ParentNode->Child = Node->Peer; 00284 } 00285 00286 /* Delete the node and any attached objects */ 00287 00288 AcpiNsDeleteNode (Node); 00289 return_VOID; 00290 } 00291 00292 00293 /******************************************************************************* 00294 * 00295 * FUNCTION: AcpiNsInstallNode 00296 * 00297 * PARAMETERS: WalkState - Current state of the walk 00298 * ParentNode - The parent of the new Node 00299 * Node - The new Node to install 00300 * Type - ACPI object type of the new Node 00301 * 00302 * RETURN: None 00303 * 00304 * DESCRIPTION: Initialize a new namespace node and install it amongst 00305 * its peers. 00306 * 00307 * Note: Current namespace lookup is linear search. This appears 00308 * to be sufficient as namespace searches consume only a small 00309 * fraction of the execution time of the ACPI subsystem. 00310 * 00311 ******************************************************************************/ 00312 00313 void 00314 AcpiNsInstallNode ( 00315 ACPI_WALK_STATE *WalkState, 00316 ACPI_NAMESPACE_NODE *ParentNode, /* Parent */ 00317 ACPI_NAMESPACE_NODE *Node, /* New Child*/ 00318 ACPI_OBJECT_TYPE Type) 00319 { 00320 ACPI_OWNER_ID OwnerId = 0; 00321 ACPI_NAMESPACE_NODE *ChildNode; 00322 00323 00324 ACPI_FUNCTION_TRACE (NsInstallNode); 00325 00326 00327 if (WalkState) 00328 { 00329 /* 00330 * Get the owner ID from the Walk state. The owner ID is used to 00331 * track table deletion and deletion of objects created by methods. 00332 */ 00333 OwnerId = WalkState->OwnerId; 00334 00335 if ((WalkState->MethodDesc) && 00336 (ParentNode != WalkState->MethodNode)) 00337 { 00338 /* 00339 * A method is creating a new node that is not a child of the 00340 * method (it is non-local). Mark the executing method as having 00341 * modified the namespace. This is used for cleanup when the 00342 * method exits. 00343 */ 00344 WalkState->MethodDesc->Method.InfoFlags |= ACPI_METHOD_MODIFIED_NAMESPACE; 00345 } 00346 } 00347 00348 /* Link the new entry into the parent and existing children */ 00349 00350 Node->Peer = NULL; 00351 Node->Parent = ParentNode; 00352 ChildNode = ParentNode->Child; 00353 00354 if (!ChildNode) 00355 { 00356 ParentNode->Child = Node; 00357 } 00358 else 00359 { 00360 /* Add node to the end of the peer list */ 00361 00362 while (ChildNode->Peer) 00363 { 00364 ChildNode = ChildNode->Peer; 00365 } 00366 00367 ChildNode->Peer = Node; 00368 } 00369 00370 /* Init the new entry */ 00371 00372 Node->OwnerId = OwnerId; 00373 Node->Type = (UINT8) Type; 00374 00375 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 00376 "%4.4s (%s) [Node %p Owner %X] added to %4.4s (%s) [Node %p]\n", 00377 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type), Node, OwnerId, 00378 AcpiUtGetNodeName (ParentNode), AcpiUtGetTypeName (ParentNode->Type), 00379 ParentNode)); 00380 00381 return_VOID; 00382 } 00383 00384 00385 /******************************************************************************* 00386 * 00387 * FUNCTION: AcpiNsDeleteChildren 00388 * 00389 * PARAMETERS: ParentNode - Delete this objects children 00390 * 00391 * RETURN: None. 00392 * 00393 * DESCRIPTION: Delete all children of the parent object. In other words, 00394 * deletes a "scope". 00395 * 00396 ******************************************************************************/ 00397 00398 void 00399 AcpiNsDeleteChildren ( 00400 ACPI_NAMESPACE_NODE *ParentNode) 00401 { 00402 ACPI_NAMESPACE_NODE *NextNode; 00403 ACPI_NAMESPACE_NODE *NodeToDelete; 00404 00405 00406 ACPI_FUNCTION_TRACE_PTR (NsDeleteChildren, ParentNode); 00407 00408 00409 if (!ParentNode) 00410 { 00411 return_VOID; 00412 } 00413 00414 /* Deallocate all children at this level */ 00415 00416 NextNode = ParentNode->Child; 00417 while (NextNode) 00418 { 00419 /* Grandchildren should have all been deleted already */ 00420 00421 if (NextNode->Child) 00422 { 00423 ACPI_ERROR ((AE_INFO, "Found a grandchild! P=%p C=%p", 00424 ParentNode, NextNode)); 00425 } 00426 00427 /* 00428 * Delete this child node and move on to the next child in the list. 00429 * No need to unlink the node since we are deleting the entire branch. 00430 */ 00431 NodeToDelete = NextNode; 00432 NextNode = NextNode->Peer; 00433 AcpiNsDeleteNode (NodeToDelete); 00434 }; 00435 00436 /* Clear the parent's child pointer */ 00437 00438 ParentNode->Child = NULL; 00439 return_VOID; 00440 } 00441 00442 00443 /******************************************************************************* 00444 * 00445 * FUNCTION: AcpiNsDeleteNamespaceSubtree 00446 * 00447 * PARAMETERS: ParentNode - Root of the subtree to be deleted 00448 * 00449 * RETURN: None. 00450 * 00451 * DESCRIPTION: Delete a subtree of the namespace. This includes all objects 00452 * stored within the subtree. 00453 * 00454 ******************************************************************************/ 00455 00456 void 00457 AcpiNsDeleteNamespaceSubtree ( 00458 ACPI_NAMESPACE_NODE *ParentNode) 00459 { 00460 ACPI_NAMESPACE_NODE *ChildNode = NULL; 00461 UINT32 Level = 1; 00462 ACPI_STATUS Status; 00463 00464 00465 ACPI_FUNCTION_TRACE (NsDeleteNamespaceSubtree); 00466 00467 00468 if (!ParentNode) 00469 { 00470 return_VOID; 00471 } 00472 00473 /* Lock namespace for possible update */ 00474 00475 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 00476 if (ACPI_FAILURE (Status)) 00477 { 00478 return_VOID; 00479 } 00480 00481 /* 00482 * Traverse the tree of objects until we bubble back up 00483 * to where we started. 00484 */ 00485 while (Level > 0) 00486 { 00487 /* Get the next node in this scope (NULL if none) */ 00488 00489 ChildNode = AcpiNsGetNextNode (ParentNode, ChildNode); 00490 if (ChildNode) 00491 { 00492 /* Found a child node - detach any attached object */ 00493 00494 AcpiNsDetachObject (ChildNode); 00495 00496 /* Check if this node has any children */ 00497 00498 if (ChildNode->Child) 00499 { 00500 /* 00501 * There is at least one child of this node, 00502 * visit the node 00503 */ 00504 Level++; 00505 ParentNode = ChildNode; 00506 ChildNode = NULL; 00507 } 00508 } 00509 else 00510 { 00511 /* 00512 * No more children of this parent node. 00513 * Move up to the grandparent. 00514 */ 00515 Level--; 00516 00517 /* 00518 * Now delete all of the children of this parent 00519 * all at the same time. 00520 */ 00521 AcpiNsDeleteChildren (ParentNode); 00522 00523 /* New "last child" is this parent node */ 00524 00525 ChildNode = ParentNode; 00526 00527 /* Move up the tree to the grandparent */ 00528 00529 ParentNode = ParentNode->Parent; 00530 } 00531 } 00532 00533 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 00534 return_VOID; 00535 } 00536 00537 00538 /******************************************************************************* 00539 * 00540 * FUNCTION: AcpiNsDeleteNamespaceByOwner 00541 * 00542 * PARAMETERS: OwnerId - All nodes with this owner will be deleted 00543 * 00544 * RETURN: Status 00545 * 00546 * DESCRIPTION: Delete entries within the namespace that are owned by a 00547 * specific ID. Used to delete entire ACPI tables. All 00548 * reference counts are updated. 00549 * 00550 * MUTEX: Locks namespace during deletion walk. 00551 * 00552 ******************************************************************************/ 00553 00554 void 00555 AcpiNsDeleteNamespaceByOwner ( 00556 ACPI_OWNER_ID OwnerId) 00557 { 00558 ACPI_NAMESPACE_NODE *ChildNode; 00559 ACPI_NAMESPACE_NODE *DeletionNode; 00560 ACPI_NAMESPACE_NODE *ParentNode; 00561 UINT32 Level; 00562 ACPI_STATUS Status; 00563 00564 00565 ACPI_FUNCTION_TRACE_U32 (NsDeleteNamespaceByOwner, OwnerId); 00566 00567 00568 if (OwnerId == 0) 00569 { 00570 return_VOID; 00571 } 00572 00573 /* Lock namespace for possible update */ 00574 00575 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 00576 if (ACPI_FAILURE (Status)) 00577 { 00578 return_VOID; 00579 } 00580 00581 DeletionNode = NULL; 00582 ParentNode = AcpiGbl_RootNode; 00583 ChildNode = NULL; 00584 Level = 1; 00585 00586 /* 00587 * Traverse the tree of nodes until we bubble back up 00588 * to where we started. 00589 */ 00590 while (Level > 0) 00591 { 00592 /* 00593 * Get the next child of this parent node. When ChildNode is NULL, 00594 * the first child of the parent is returned 00595 */ 00596 ChildNode = AcpiNsGetNextNode (ParentNode, ChildNode); 00597 00598 if (DeletionNode) 00599 { 00600 AcpiNsDeleteChildren (DeletionNode); 00601 AcpiNsRemoveNode (DeletionNode); 00602 DeletionNode = NULL; 00603 } 00604 00605 if (ChildNode) 00606 { 00607 if (ChildNode->OwnerId == OwnerId) 00608 { 00609 /* Found a matching child node - detach any attached object */ 00610 00611 AcpiNsDetachObject (ChildNode); 00612 } 00613 00614 /* Check if this node has any children */ 00615 00616 if (ChildNode->Child) 00617 { 00618 /* 00619 * There is at least one child of this node, 00620 * visit the node 00621 */ 00622 Level++; 00623 ParentNode = ChildNode; 00624 ChildNode = NULL; 00625 } 00626 else if (ChildNode->OwnerId == OwnerId) 00627 { 00628 DeletionNode = ChildNode; 00629 } 00630 } 00631 else 00632 { 00633 /* 00634 * No more children of this parent node. 00635 * Move up to the grandparent. 00636 */ 00637 Level--; 00638 if (Level != 0) 00639 { 00640 if (ParentNode->OwnerId == OwnerId) 00641 { 00642 DeletionNode = ParentNode; 00643 } 00644 } 00645 00646 /* New "last child" is this parent node */ 00647 00648 ChildNode = ParentNode; 00649 00650 /* Move up the tree to the grandparent */ 00651 00652 ParentNode = ParentNode->Parent; 00653 } 00654 } 00655 00656 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 00657 return_VOID; 00658 } 00659 00660 Generated on Sat May 26 2012 04:25:53 for ReactOS by
1.7.6.1
|