nsalloc.c revision 87031
1/******************************************************************************* 2 * 3 * Module Name: nsalloc - Namespace allocation and deletion utilities 4 * $Revision: 62 $ 5 * 6 ******************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp. 13 * All rights reserved. 14 * 15 * 2. License 16 * 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 20 * property rights. 21 * 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 28 * 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; 37 * 38 * The above copyright and patent license is granted only if the following 39 * conditions are met: 40 * 41 * 3. Conditions 42 * 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. 54 * 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 65 * make. 66 * 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 71 * distribution. 72 * 73 * 3.4. Intel retains all right, title, and interest in and to the Original 74 * Intel Code. 75 * 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. 80 * 81 * 4. Disclaimer and Export Compliance 82 * 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 89 * PARTICULAR PURPOSE. 90 * 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 98 * LIMITED REMEDY. 99 * 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. 114 * 115 *****************************************************************************/ 116 117 118#define __NSALLOC_C__ 119 120#include "acpi.h" 121#include "acnamesp.h" 122#include "acinterp.h" 123 124 125#define _COMPONENT ACPI_NAMESPACE 126 MODULE_NAME ("nsalloc") 127 128 129/******************************************************************************* 130 * 131 * FUNCTION: AcpiNsCreateNode 132 * 133 * PARAMETERS: AcpiName - Name of the new node 134 * 135 * RETURN: None 136 * 137 * DESCRIPTION: Create a namespace node 138 * 139 ******************************************************************************/ 140 141ACPI_NAMESPACE_NODE * 142AcpiNsCreateNode ( 143 UINT32 Name) 144{ 145 ACPI_NAMESPACE_NODE *Node; 146 147 148 FUNCTION_TRACE ("NsCreateNode"); 149 150 151 Node = ACPI_MEM_CALLOCATE (sizeof (ACPI_NAMESPACE_NODE)); 152 if (!Node) 153 { 154 return_PTR (NULL); 155 } 156 157 ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalAllocated++); 158 159 Node->DataType = ACPI_DESC_TYPE_NAMED; 160 Node->Name = Name; 161 Node->ReferenceCount = 1; 162 163 return_PTR (Node); 164} 165 166 167/******************************************************************************* 168 * 169 * FUNCTION: AcpiNsDeleteNode 170 * 171 * PARAMETERS: Node - Node to be deleted 172 * 173 * RETURN: None 174 * 175 * DESCRIPTION: Delete a namespace node 176 * 177 ******************************************************************************/ 178 179void 180AcpiNsDeleteNode ( 181 ACPI_NAMESPACE_NODE *Node) 182{ 183 ACPI_NAMESPACE_NODE *ParentNode; 184 ACPI_NAMESPACE_NODE *PrevNode; 185 ACPI_NAMESPACE_NODE *NextNode; 186 187 188 FUNCTION_TRACE_PTR ("NsDeleteNode", Node); 189 190 191 ParentNode = AcpiNsGetParentObject (Node); 192 193 PrevNode = NULL; 194 NextNode = ParentNode->Child; 195 196 while (NextNode != Node) 197 { 198 PrevNode = NextNode; 199 NextNode = PrevNode->Peer; 200 } 201 202 if (PrevNode) 203 { 204 PrevNode->Peer = NextNode->Peer; 205 if (NextNode->Flags & ANOBJ_END_OF_PEER_LIST) 206 { 207 PrevNode->Flags |= ANOBJ_END_OF_PEER_LIST; 208 } 209 } 210 else 211 { 212 ParentNode->Child = NextNode->Peer; 213 } 214 215 216 ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalFreed++); 217 218 /* 219 * Detach an object if there is one then delete the node 220 */ 221 AcpiNsDetachObject (Node); 222 ACPI_MEM_FREE (Node); 223 return_VOID; 224} 225 226 227/******************************************************************************* 228 * 229 * FUNCTION: AcpiNsInstallNode 230 * 231 * PARAMETERS: WalkState - Current state of the walk 232 * ParentNode - The parent of the new Node 233 * Node - The new Node to install 234 * Type - ACPI object type of the new Node 235 * 236 * RETURN: None 237 * 238 * DESCRIPTION: Initialize a new namespace node and install it amongst 239 * its peers. 240 * 241 * Note: Current namespace lookup is linear search, so the nodes 242 * are not linked in any particular order. 243 * 244 ******************************************************************************/ 245 246void 247AcpiNsInstallNode ( 248 ACPI_WALK_STATE *WalkState, 249 ACPI_NAMESPACE_NODE *ParentNode, /* Parent */ 250 ACPI_NAMESPACE_NODE *Node, /* New Child*/ 251 ACPI_OBJECT_TYPE8 Type) 252{ 253 UINT16 OwnerId = TABLE_ID_DSDT; 254 ACPI_NAMESPACE_NODE *ChildNode; 255 256 257 FUNCTION_TRACE ("NsInstallNode"); 258 259 260 /* 261 * Get the owner ID from the Walk state 262 * The owner ID is used to track table deletion and 263 * deletion of objects created by methods 264 */ 265 if (WalkState) 266 { 267 OwnerId = WalkState->OwnerId; 268 } 269 270 /* Link the new entry into the parent and existing children */ 271 272 ChildNode = ParentNode->Child; 273 if (!ChildNode) 274 { 275 ParentNode->Child = Node; 276 } 277 else 278 { 279 while (!(ChildNode->Flags & ANOBJ_END_OF_PEER_LIST)) 280 { 281 ChildNode = ChildNode->Peer; 282 } 283 284 ChildNode->Peer = Node; 285 286 /* Clear end-of-list flag */ 287 288 ChildNode->Flags &= ~ANOBJ_END_OF_PEER_LIST; 289 } 290 291 /* Init the new entry */ 292 293 Node->OwnerId = OwnerId; 294 Node->Flags |= ANOBJ_END_OF_PEER_LIST; 295 Node->Peer = ParentNode; 296 297 298 /* 299 * If adding a name with unknown type, or having to 300 * add the region in order to define fields in it, we 301 * have a forward reference. 302 */ 303 if ((ACPI_TYPE_ANY == Type) || 304 (INTERNAL_TYPE_FIELD_DEFN == Type) || 305 (INTERNAL_TYPE_BANK_FIELD_DEFN == Type)) 306 { 307 /* 308 * We don't want to abort here, however! 309 * We will fill in the actual type when the 310 * real definition is found later. 311 */ 312 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "[%4.4s] is a forward reference\n", 313 (char*)&Node->Name)); 314 } 315 316 /* 317 * The DefFieldDefn and BankFieldDefn cases are actually 318 * looking up the Region in which the field will be defined 319 */ 320 if ((INTERNAL_TYPE_FIELD_DEFN == Type) || 321 (INTERNAL_TYPE_BANK_FIELD_DEFN == Type)) 322 { 323 Type = ACPI_TYPE_REGION; 324 } 325 326 /* 327 * Scope, DefAny, and IndexFieldDefn are bogus "types" which do 328 * not actually have anything to do with the type of the name 329 * being looked up. Save any other value of Type as the type of 330 * the entry. 331 */ 332 if ((Type != INTERNAL_TYPE_SCOPE) && 333 (Type != INTERNAL_TYPE_DEF_ANY) && 334 (Type != INTERNAL_TYPE_INDEX_FIELD_DEFN)) 335 { 336 Node->Type = (UINT8) Type; 337 } 338 339 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%4.4s added to %p at %p\n", 340 (char*)&Node->Name, ParentNode, Node)); 341 342 /* 343 * Increment the reference count(s) of all parents up to 344 * the root! 345 */ 346 while ((Node = AcpiNsGetParentObject (Node)) != NULL) 347 { 348 Node->ReferenceCount++; 349 } 350 351 return_VOID; 352} 353 354 355/******************************************************************************* 356 * 357 * FUNCTION: AcpiNsDeleteChildren 358 * 359 * PARAMETERS: ParentNode - Delete this objects children 360 * 361 * RETURN: None. 362 * 363 * DESCRIPTION: Delete all children of the parent object. Deletes a 364 * "scope". 365 * 366 ******************************************************************************/ 367 368void 369AcpiNsDeleteChildren ( 370 ACPI_NAMESPACE_NODE *ParentNode) 371{ 372 ACPI_NAMESPACE_NODE *ChildNode; 373 ACPI_NAMESPACE_NODE *NextNode; 374 UINT8 Flags; 375 376 377 FUNCTION_TRACE_PTR ("NsDeleteChildren", ParentNode); 378 379 380 if (!ParentNode) 381 { 382 return_VOID; 383 } 384 385 /* If no children, all done! */ 386 387 ChildNode = ParentNode->Child; 388 if (!ChildNode) 389 { 390 return_VOID; 391 } 392 393 /* 394 * Deallocate all children at this level 395 */ 396 do 397 { 398 /* Get the things we need */ 399 400 NextNode = ChildNode->Peer; 401 Flags = ChildNode->Flags; 402 403 /* Grandchildren should have all been deleted already */ 404 405 if (ChildNode->Child) 406 { 407 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Found a grandchild! P=%p C=%p\n", 408 ParentNode, ChildNode)); 409 } 410 411 /* Now we can free this child object */ 412 413 ACPI_MEM_TRACKING (AcpiGbl_MemoryLists[ACPI_MEM_LIST_NSNODE].TotalFreed++); 414 415 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Object %p, Remaining %X\n", 416 ChildNode, AcpiGbl_CurrentNodeCount)); 417 418 /* 419 * Detach an object if there is one, then free the child node 420 */ 421 AcpiNsDetachObject (ChildNode); 422 ACPI_MEM_FREE (ChildNode); 423 424 /* And move on to the next child in the list */ 425 426 ChildNode = NextNode; 427 428 } while (!(Flags & ANOBJ_END_OF_PEER_LIST)); 429 430 431 /* Clear the parent's child pointer */ 432 433 ParentNode->Child = NULL; 434 435 return_VOID; 436} 437 438 439/******************************************************************************* 440 * 441 * FUNCTION: AcpiNsDeleteNamespaceSubtree 442 * 443 * PARAMETERS: ParentNode - Root of the subtree to be deleted 444 * 445 * RETURN: None. 446 * 447 * DESCRIPTION: Delete a subtree of the namespace. This includes all objects 448 * stored within the subtree. Scope tables are deleted also 449 * 450 ******************************************************************************/ 451 452ACPI_STATUS 453AcpiNsDeleteNamespaceSubtree ( 454 ACPI_NAMESPACE_NODE *ParentNode) 455{ 456 ACPI_NAMESPACE_NODE *ChildNode = NULL; 457 UINT32 Level = 1; 458 459 460 FUNCTION_TRACE ("NsDeleteNamespaceSubtree"); 461 462 463 if (!ParentNode) 464 { 465 return_ACPI_STATUS (AE_OK); 466 } 467 468 /* 469 * Traverse the tree of objects until we bubble back up 470 * to where we started. 471 */ 472 while (Level > 0) 473 { 474 /* Get the next node in this scope (NULL if none) */ 475 476 ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode, 477 ChildNode); 478 if (ChildNode) 479 { 480 /* Found a child node - detach any attached object */ 481 482 AcpiNsDetachObject (ChildNode); 483 484 /* Check if this node has any children */ 485 486 if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, 0)) 487 { 488 /* 489 * There is at least one child of this node, 490 * visit the node 491 */ 492 Level++; 493 ParentNode = ChildNode; 494 ChildNode = 0; 495 } 496 } 497 else 498 { 499 /* 500 * No more children of this parent node. 501 * Move up to the grandparent. 502 */ 503 Level--; 504 505 /* 506 * Now delete all of the children of this parent 507 * all at the same time. 508 */ 509 AcpiNsDeleteChildren (ParentNode); 510 511 /* New "last child" is this parent node */ 512 513 ChildNode = ParentNode; 514 515 /* Move up the tree to the grandparent */ 516 517 ParentNode = AcpiNsGetParentObject (ParentNode); 518 } 519 } 520 521 return_ACPI_STATUS (AE_OK); 522} 523 524 525/******************************************************************************* 526 * 527 * FUNCTION: AcpiNsRemoveReference 528 * 529 * PARAMETERS: Node - Named node whose reference count is to be 530 * decremented 531 * 532 * RETURN: None. 533 * 534 * DESCRIPTION: Remove a Node reference. Decrements the reference count 535 * of all parent Nodes up to the root. Any node along 536 * the way that reaches zero references is freed. 537 * 538 ******************************************************************************/ 539 540static void 541AcpiNsRemoveReference ( 542 ACPI_NAMESPACE_NODE *Node) 543{ 544 ACPI_NAMESPACE_NODE *NextNode; 545 546 547 FUNCTION_ENTRY (); 548 549 550 /* 551 * Decrement the reference count(s) of this node and all 552 * nodes up to the root, Delete anything with zero remaining references. 553 */ 554 NextNode = Node; 555 while (NextNode) 556 { 557 /* Decrement the reference count on this node*/ 558 559 NextNode->ReferenceCount--; 560 561 /* Delete the node if no more references */ 562 563 if (!NextNode->ReferenceCount) 564 { 565 /* Delete all children and delete the node */ 566 567 AcpiNsDeleteChildren (NextNode); 568 AcpiNsDeleteNode (NextNode); 569 } 570 571 /* Move up to parent */ 572 573 NextNode = AcpiNsGetParentObject (NextNode); 574 } 575} 576 577 578/******************************************************************************* 579 * 580 * FUNCTION: AcpiNsDeleteNamespaceByOwner 581 * 582 * PARAMETERS: OwnerId - All nodes with this owner will be deleted 583 * 584 * RETURN: Status 585 * 586 * DESCRIPTION: Delete entries within the namespace that are owned by a 587 * specific ID. Used to delete entire ACPI tables. All 588 * reference counts are updated. 589 * 590 ******************************************************************************/ 591 592ACPI_STATUS 593AcpiNsDeleteNamespaceByOwner ( 594 UINT16 OwnerId) 595{ 596 ACPI_NAMESPACE_NODE *ChildNode; 597 UINT32 Level; 598 ACPI_NAMESPACE_NODE *ParentNode; 599 600 601 FUNCTION_TRACE ("NsDeleteNamespaceByOwner"); 602 603 604 ParentNode = AcpiGbl_RootNode; 605 ChildNode = 0; 606 Level = 1; 607 608 /* 609 * Traverse the tree of nodes until we bubble back up 610 * to where we started. 611 */ 612 while (Level > 0) 613 { 614 /* Get the next node in this scope (NULL if none) */ 615 616 ChildNode = AcpiNsGetNextNode (ACPI_TYPE_ANY, ParentNode, 617 ChildNode); 618 if (ChildNode) 619 { 620 if (ChildNode->OwnerId == OwnerId) 621 { 622 /* Found a child node - detach any attached object */ 623 624 AcpiNsDetachObject (ChildNode); 625 } 626 627 /* Check if this node has any children */ 628 629 if (AcpiNsGetNextNode (ACPI_TYPE_ANY, ChildNode, 0)) 630 { 631 /* 632 * There is at least one child of this node, 633 * visit the node 634 */ 635 Level++; 636 ParentNode = ChildNode; 637 ChildNode = 0; 638 } 639 else if (ChildNode->OwnerId == OwnerId) 640 { 641 AcpiNsRemoveReference (ChildNode); 642 } 643 } 644 else 645 { 646 /* 647 * No more children of this parent node. 648 * Move up to the grandparent. 649 */ 650 Level--; 651 652 if (Level != 0) 653 { 654 if (ParentNode->OwnerId == OwnerId) 655 { 656 AcpiNsRemoveReference (ParentNode); 657 } 658 } 659 660 /* New "last child" is this parent node */ 661 662 ChildNode = ParentNode; 663 664 /* Move up the tree to the grandparent */ 665 666 ParentNode = AcpiNsGetParentObject (ParentNode); 667 } 668 } 669 670 return_ACPI_STATUS (AE_OK); 671} 672 673 674