nsload.c revision 84491
1/****************************************************************************** 2 * 3 * Module Name: nsload - namespace loading/expanding/contracting procedures 4 * $Revision: 47 $ 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#define __NSLOAD_C__ 118 119#include "acpi.h" 120#include "acinterp.h" 121#include "acnamesp.h" 122#include "amlcode.h" 123#include "acparser.h" 124#include "acdispat.h" 125#include "acdebug.h" 126 127 128#define _COMPONENT ACPI_NAMESPACE 129 MODULE_NAME ("nsload") 130 131 132/******************************************************************************* 133 * 134 * FUNCTION: AcpiLoadNamespace 135 * 136 * PARAMETERS: DisplayAmlDuringLoad 137 * 138 * RETURN: Status 139 * 140 * DESCRIPTION: Load the name space from what ever is pointed to by DSDT. 141 * (DSDT points to either the BIOS or a buffer.) 142 * 143 ******************************************************************************/ 144 145ACPI_STATUS 146AcpiNsLoadNamespace ( 147 void) 148{ 149 ACPI_STATUS Status; 150 151 152 FUNCTION_TRACE ("AcpiLoadNameSpace"); 153 154 155 /* There must be at least a DSDT installed */ 156 157 if (AcpiGbl_DSDT == NULL) 158 { 159 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "DSDT is not in memory\n")); 160 return_ACPI_STATUS (AE_NO_ACPI_TABLES); 161 } 162 163 164 /* 165 * Load the namespace. The DSDT is required, 166 * but the SSDT and PSDT tables are optional. 167 */ 168 Status = AcpiNsLoadTableByType (ACPI_TABLE_DSDT); 169 if (ACPI_FAILURE (Status)) 170 { 171 return_ACPI_STATUS (Status); 172 } 173 174 /* Ignore exceptions from these */ 175 176 AcpiNsLoadTableByType (ACPI_TABLE_SSDT); 177 AcpiNsLoadTableByType (ACPI_TABLE_PSDT); 178 179 180 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, 181 "ACPI Namespace successfully loaded at root %p\n", 182 AcpiGbl_RootNode)); 183 184 185 return_ACPI_STATUS (Status); 186} 187 188 189/******************************************************************************* 190 * 191 * FUNCTION: AcpiNsOneParsePass 192 * 193 * PARAMETERS: 194 * 195 * RETURN: Status 196 * 197 * DESCRIPTION: 198 * 199 ******************************************************************************/ 200 201ACPI_STATUS 202AcpiNsOneCompleteParse ( 203 UINT32 PassNumber, 204 ACPI_TABLE_DESC *TableDesc) 205{ 206 ACPI_PARSE_OBJECT *ParseRoot; 207 ACPI_STATUS Status; 208 ACPI_WALK_STATE *WalkState; 209 210 211 FUNCTION_TRACE ("NsOneCompleteParse"); 212 213 214 /* Create and init a Root Node */ 215 216 ParseRoot = AcpiPsAllocOp (AML_SCOPE_OP); 217 if (!ParseRoot) 218 { 219 return_ACPI_STATUS (AE_NO_MEMORY); 220 } 221 222 ((ACPI_PARSE2_OBJECT *) ParseRoot)->Name = ACPI_ROOT_NAME; 223 224 225 /* Create and initialize a new walk state */ 226 227 WalkState = AcpiDsCreateWalkState (TABLE_ID_DSDT, 228 NULL, NULL, NULL); 229 if (!WalkState) 230 { 231 AcpiPsFreeOp (ParseRoot); 232 return_ACPI_STATUS (AE_NO_MEMORY); 233 } 234 235 Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL, TableDesc->AmlStart, 236 TableDesc->AmlLength, NULL, NULL, PassNumber); 237 if (ACPI_FAILURE (Status)) 238 { 239 AcpiDsDeleteWalkState (WalkState); 240 return_ACPI_STATUS (Status); 241 } 242 243 /* Parse the AML */ 244 245 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "*PARSE* pass %d parse\n", PassNumber)); 246 Status = AcpiPsParseAml (WalkState); 247 248 AcpiPsDeleteParseTree (ParseRoot); 249 return_ACPI_STATUS (Status); 250} 251 252 253/******************************************************************************* 254 * 255 * FUNCTION: AcpiNsParseTable 256 * 257 * PARAMETERS: TableDesc - An ACPI table descriptor for table to parse 258 * StartNode - Where to enter the table into the namespace 259 * 260 * RETURN: Status 261 * 262 * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops 263 * 264 ******************************************************************************/ 265 266ACPI_STATUS 267AcpiNsParseTable ( 268 ACPI_TABLE_DESC *TableDesc, 269 ACPI_NAMESPACE_NODE *StartNode) 270{ 271 ACPI_STATUS Status; 272 273 274 FUNCTION_TRACE ("NsParseTable"); 275 276 277 /* 278 * AML Parse, pass 1 279 * 280 * In this pass, we load most of the namespace. Control methods 281 * are not parsed until later. A parse tree is not created. Instead, 282 * each Parser Op subtree is deleted when it is finished. This saves 283 * a great deal of memory, and allows a small cache of parse objects 284 * to service the entire parse. The second pass of the parse then 285 * performs another complete parse of the AML.. 286 */ 287 Status = AcpiNsOneCompleteParse (1, TableDesc); 288 if (ACPI_FAILURE (Status)) 289 { 290 return_ACPI_STATUS (Status); 291 } 292 293 294 /* 295 * AML Parse, pass 2 296 * 297 * In this pass, we resolve forward references and other things 298 * that could not be completed during the first pass. 299 * Another complete parse of the AML is performed, but the 300 * overhead of this is compensated for by the fact that the 301 * parse objects are all cached. 302 */ 303 Status = AcpiNsOneCompleteParse (2, TableDesc); 304 if (ACPI_FAILURE (Status)) 305 { 306 return_ACPI_STATUS (Status); 307 } 308 309 return_ACPI_STATUS (Status); 310} 311 312 313/******************************************************************************* 314 * 315 * FUNCTION: AcpiNsLoadTable 316 * 317 * PARAMETERS: TableDesc - Descriptor for table to be loaded 318 * Node - Owning NS node 319 * 320 * RETURN: Status 321 * 322 * DESCRIPTION: Load one ACPI table into the namespace 323 * 324 ******************************************************************************/ 325 326ACPI_STATUS 327AcpiNsLoadTable ( 328 ACPI_TABLE_DESC *TableDesc, 329 ACPI_NAMESPACE_NODE *Node) 330{ 331 ACPI_STATUS Status; 332 333 334 FUNCTION_TRACE ("NsLoadTable"); 335 336 337 if (!TableDesc->AmlStart) 338 { 339 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null AML pointer\n")); 340 return_ACPI_STATUS (AE_BAD_PARAMETER); 341 } 342 343 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AML block at %p\n", TableDesc->AmlStart)); 344 345 346 if (!TableDesc->AmlLength) 347 { 348 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Zero-length AML block\n")); 349 return_ACPI_STATUS (AE_BAD_PARAMETER); 350 } 351 352 353 /* 354 * Parse the table and load the namespace with all named 355 * objects found within. Control methods are NOT parsed 356 * at this time. In fact, the control methods cannot be 357 * parsed until the entire namespace is loaded, because 358 * if a control method makes a forward reference (call) 359 * to another control method, we can't continue parsing 360 * because we don't know how many arguments to parse next! 361 */ 362 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "**** Loading table into namespace ****\n")); 363 364 AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 365 Status = AcpiNsParseTable (TableDesc, Node->Child); 366 AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 367 368 if (ACPI_FAILURE (Status)) 369 { 370 return_ACPI_STATUS (Status); 371 } 372 373 /* 374 * Now we can parse the control methods. We always parse 375 * them here for a sanity check, and if configured for 376 * just-in-time parsing, we delete the control method 377 * parse trees. 378 */ 379 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 380 "**** Begin Table Method Parsing and Object Initialization ****\n")); 381 382 Status = AcpiDsInitializeObjects (TableDesc, Node); 383 384 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 385 "**** Completed Table Method Parsing and Object Initialization ****\n")); 386 387 return_ACPI_STATUS (Status); 388} 389 390 391/******************************************************************************* 392 * 393 * FUNCTION: AcpiNsLoadTableByType 394 * 395 * PARAMETERS: TableType - Id of the table type to load 396 * 397 * RETURN: Status 398 * 399 * DESCRIPTION: Load an ACPI table or tables into the namespace. All tables 400 * of the given type are loaded. The mechanism allows this 401 * routine to be called repeatedly. 402 * 403 ******************************************************************************/ 404 405ACPI_STATUS 406AcpiNsLoadTableByType ( 407 ACPI_TABLE_TYPE TableType) 408{ 409 UINT32 i; 410 ACPI_STATUS Status = AE_OK; 411 ACPI_TABLE_DESC *TableDesc; 412 413 414 FUNCTION_TRACE ("NsLoadTableByType"); 415 416 417 AcpiUtAcquireMutex (ACPI_MTX_TABLES); 418 419 420 /* 421 * Table types supported are: 422 * DSDT (one), SSDT/PSDT (multiple) 423 */ 424 switch (TableType) 425 { 426 427 case ACPI_TABLE_DSDT: 428 429 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading DSDT\n")); 430 431 TableDesc = &AcpiGbl_AcpiTables[ACPI_TABLE_DSDT]; 432 433 /* If table already loaded into namespace, just return */ 434 435 if (TableDesc->LoadedIntoNamespace) 436 { 437 goto UnlockAndExit; 438 } 439 440 TableDesc->TableId = TABLE_ID_DSDT; 441 442 /* Now load the single DSDT */ 443 444 Status = AcpiNsLoadTable (TableDesc, AcpiGbl_RootNode); 445 if (ACPI_SUCCESS (Status)) 446 { 447 TableDesc->LoadedIntoNamespace = TRUE; 448 } 449 450 break; 451 452 453 case ACPI_TABLE_SSDT: 454 455 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading %d SSDTs\n", 456 AcpiGbl_AcpiTables[ACPI_TABLE_SSDT].Count)); 457 458 /* 459 * Traverse list of SSDT tables 460 */ 461 TableDesc = &AcpiGbl_AcpiTables[ACPI_TABLE_SSDT]; 462 for (i = 0; i < AcpiGbl_AcpiTables[ACPI_TABLE_SSDT].Count; i++) 463 { 464 /* 465 * Only attempt to load table if it is not 466 * already loaded! 467 */ 468 if (!TableDesc->LoadedIntoNamespace) 469 { 470 Status = AcpiNsLoadTable (TableDesc, AcpiGbl_RootNode); 471 if (ACPI_FAILURE (Status)) 472 { 473 break; 474 } 475 476 TableDesc->LoadedIntoNamespace = TRUE; 477 } 478 479 TableDesc = TableDesc->Next; 480 } 481 break; 482 483 484 case ACPI_TABLE_PSDT: 485 486 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Loading %d PSDTs\n", 487 AcpiGbl_AcpiTables[ACPI_TABLE_PSDT].Count)); 488 489 /* 490 * Traverse list of PSDT tables 491 */ 492 TableDesc = &AcpiGbl_AcpiTables[ACPI_TABLE_PSDT]; 493 494 for (i = 0; i < AcpiGbl_AcpiTables[ACPI_TABLE_PSDT].Count; i++) 495 { 496 /* Only attempt to load table if it is not already loaded! */ 497 498 if (!TableDesc->LoadedIntoNamespace) 499 { 500 Status = AcpiNsLoadTable (TableDesc, AcpiGbl_RootNode); 501 if (ACPI_FAILURE (Status)) 502 { 503 break; 504 } 505 506 TableDesc->LoadedIntoNamespace = TRUE; 507 } 508 509 TableDesc = TableDesc->Next; 510 } 511 512 break; 513 514 515 default: 516 Status = AE_SUPPORT; 517 break; 518 } 519 520 521UnlockAndExit: 522 523 AcpiUtReleaseMutex (ACPI_MTX_TABLES); 524 525 return_ACPI_STATUS (Status); 526 527} 528 529 530/******************************************************************************* 531 * 532 * FUNCTION: AcpiNsDeleteSubtree 533 * 534 * PARAMETERS: StartHandle - Handle in namespace where search begins 535 * 536 * RETURNS Status 537 * 538 * DESCRIPTION: Walks the namespace starting at the given handle and deletes 539 * all objects, entries, and scopes in the entire subtree. 540 * 541 * TBD: [Investigate] What if any part of this subtree is in use? 542 * (i.e. on one of the object stacks?) 543 * 544 ******************************************************************************/ 545 546ACPI_STATUS 547AcpiNsDeleteSubtree ( 548 ACPI_HANDLE StartHandle) 549{ 550 ACPI_STATUS Status; 551 ACPI_HANDLE ChildHandle; 552 ACPI_HANDLE ParentHandle; 553 ACPI_HANDLE NextChildHandle; 554 ACPI_HANDLE Dummy; 555 UINT32 Level; 556 557 558 FUNCTION_TRACE ("NsDeleteSubtree"); 559 560 561 ParentHandle = StartHandle; 562 ChildHandle = 0; 563 Level = 1; 564 565 /* 566 * Traverse the tree of objects until we bubble back up 567 * to where we started. 568 */ 569 while (Level > 0) 570 { 571 /* Attempt to get the next object in this scope */ 572 573 Status = AcpiGetNextObject (ACPI_TYPE_ANY, ParentHandle, 574 ChildHandle, &NextChildHandle); 575 576 ChildHandle = NextChildHandle; 577 578 579 /* Did we get a new object? */ 580 581 if (ACPI_SUCCESS (Status)) 582 { 583 /* Check if this object has any children */ 584 585 if (ACPI_SUCCESS (AcpiGetNextObject (ACPI_TYPE_ANY, ChildHandle, 586 0, &Dummy))) 587 { 588 /* 589 * There is at least one child of this object, 590 * visit the object 591 */ 592 Level++; 593 ParentHandle = ChildHandle; 594 ChildHandle = 0; 595 } 596 } 597 598 else 599 { 600 /* 601 * No more children in this object, go back up to 602 * the object's parent 603 */ 604 Level--; 605 606 /* Delete all children now */ 607 608 AcpiNsDeleteChildren (ChildHandle); 609 610 ChildHandle = ParentHandle; 611 AcpiGetParent (ParentHandle, &ParentHandle); 612 } 613 } 614 615 /* Now delete the starting object, and we are done */ 616 617 AcpiNsDeleteNode (ChildHandle); 618 619 return_ACPI_STATUS (AE_OK); 620} 621 622 623/******************************************************************************* 624 * 625 * FUNCTION: AcpiNsUnloadNameSpace 626 * 627 * PARAMETERS: Handle - Root of namespace subtree to be deleted 628 * 629 * RETURN: Status 630 * 631 * DESCRIPTION: Shrinks the namespace, typically in response to an undocking 632 * event. Deletes an entire subtree starting from (and 633 * including) the given handle. 634 * 635 ******************************************************************************/ 636 637ACPI_STATUS 638AcpiNsUnloadNamespace ( 639 ACPI_HANDLE Handle) 640{ 641 ACPI_STATUS Status; 642 643 644 FUNCTION_TRACE ("NsUnloadNameSpace"); 645 646 647 /* Parameter validation */ 648 649 if (!AcpiGbl_RootNode) 650 { 651 return_ACPI_STATUS (AE_NO_NAMESPACE); 652 } 653 654 if (!Handle) 655 { 656 return_ACPI_STATUS (AE_BAD_PARAMETER); 657 } 658 659 660 /* This function does the real work */ 661 662 Status = AcpiNsDeleteSubtree (Handle); 663 664 return_ACPI_STATUS (Status); 665} 666 667 668