dswload.c revision 138287
1/****************************************************************************** 2 * 3 * Module Name: dswload - Dispatcher namespace load callbacks 4 * $Revision: 88 $ 5 * 6 *****************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999 - 2004, 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 __DSWLOAD_C__ 118 119#include "acpi.h" 120#include "acparser.h" 121#include "amlcode.h" 122#include "acdispat.h" 123#include "acinterp.h" 124#include "acnamesp.h" 125#include "acevents.h" 126 127#ifdef _ACPI_ASL_COMPILER 128#include "acdisasm.h" 129#endif 130 131#define _COMPONENT ACPI_DISPATCHER 132 ACPI_MODULE_NAME ("dswload") 133 134 135/******************************************************************************* 136 * 137 * FUNCTION: AcpiDsInitCallbacks 138 * 139 * PARAMETERS: WalkState - Current state of the parse tree walk 140 * PassNumber - 1, 2, or 3 141 * 142 * RETURN: Status 143 * 144 * DESCRIPTION: Init walk state callbacks 145 * 146 ******************************************************************************/ 147 148ACPI_STATUS 149AcpiDsInitCallbacks ( 150 ACPI_WALK_STATE *WalkState, 151 UINT32 PassNumber) 152{ 153 154 switch (PassNumber) 155 { 156 case 1: 157 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE; 158 WalkState->DescendingCallback = AcpiDsLoad1BeginOp; 159 WalkState->AscendingCallback = AcpiDsLoad1EndOp; 160 break; 161 162 case 2: 163 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE; 164 WalkState->DescendingCallback = AcpiDsLoad2BeginOp; 165 WalkState->AscendingCallback = AcpiDsLoad2EndOp; 166 break; 167 168 case 3: 169#ifndef ACPI_NO_METHOD_EXECUTION 170 WalkState->ParseFlags |= ACPI_PARSE_EXECUTE | ACPI_PARSE_DELETE_TREE; 171 WalkState->DescendingCallback = AcpiDsExecBeginOp; 172 WalkState->AscendingCallback = AcpiDsExecEndOp; 173#endif 174 break; 175 176 default: 177 return (AE_BAD_PARAMETER); 178 } 179 180 return (AE_OK); 181} 182 183 184/******************************************************************************* 185 * 186 * FUNCTION: AcpiDsLoad1BeginOp 187 * 188 * PARAMETERS: WalkState - Current state of the parse tree walk 189 * Op - Op that has been just been reached in the 190 * walk; Arguments have not been evaluated yet. 191 * 192 * RETURN: Status 193 * 194 * DESCRIPTION: Descending callback used during the loading of ACPI tables. 195 * 196 ******************************************************************************/ 197 198ACPI_STATUS 199AcpiDsLoad1BeginOp ( 200 ACPI_WALK_STATE *WalkState, 201 ACPI_PARSE_OBJECT **OutOp) 202{ 203 ACPI_PARSE_OBJECT *Op; 204 ACPI_NAMESPACE_NODE *Node; 205 ACPI_STATUS Status; 206 ACPI_OBJECT_TYPE ObjectType; 207 char *Path; 208 UINT32 Flags; 209 210 211 ACPI_FUNCTION_NAME ("DsLoad1BeginOp"); 212 213 214 Op = WalkState->Op; 215 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState)); 216 217 /* We are only interested in opcodes that have an associated name */ 218 219 if (Op) 220 { 221 if (!(WalkState->OpInfo->Flags & AML_NAMED)) 222 { 223#if 0 224 if ((WalkState->OpInfo->Class == AML_CLASS_EXECUTE) || 225 (WalkState->OpInfo->Class == AML_CLASS_CONTROL)) 226 { 227 AcpiOsPrintf ("\n\n***EXECUTABLE OPCODE %s***\n\n", WalkState->OpInfo->Name); 228 *OutOp = Op; 229 return (AE_CTRL_SKIP); 230 } 231#endif 232 *OutOp = Op; 233 return (AE_OK); 234 } 235 236 /* Check if this object has already been installed in the namespace */ 237 238 if (Op->Common.Node) 239 { 240 *OutOp = Op; 241 return (AE_OK); 242 } 243 } 244 245 Path = AcpiPsGetNextNamestring (&WalkState->ParserState); 246 247 /* Map the raw opcode into an internal object type */ 248 249 ObjectType = WalkState->OpInfo->ObjectType; 250 251 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 252 "State=%p Op=%p [%s]\n", WalkState, Op, AcpiUtGetTypeName (ObjectType))); 253 254 switch (WalkState->Opcode) 255 { 256 case AML_SCOPE_OP: 257 258 /* 259 * The target name of the Scope() operator must exist at this point so 260 * that we can actually open the scope to enter new names underneath it. 261 * Allow search-to-root for single namesegs. 262 */ 263 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType, 264 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node)); 265#ifdef _ACPI_ASL_COMPILER 266 if (Status == AE_NOT_FOUND) 267 { 268 /* 269 * Table disassembly: 270 * Target of Scope() not found. Generate an External for it, and 271 * insert the name into the namespace. 272 */ 273 AcpiDmAddToExternalList (Path); 274 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType, 275 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, WalkState, &(Node)); 276 } 277#endif 278 if (ACPI_FAILURE (Status)) 279 { 280 ACPI_REPORT_NSERROR (Path, Status); 281 return (Status); 282 } 283 284 /* 285 * Check to make sure that the target is 286 * one of the opcodes that actually opens a scope 287 */ 288 switch (Node->Type) 289 { 290 case ACPI_TYPE_LOCAL_SCOPE: /* Scope */ 291 case ACPI_TYPE_DEVICE: 292 case ACPI_TYPE_POWER: 293 case ACPI_TYPE_PROCESSOR: 294 case ACPI_TYPE_THERMAL: 295 296 /* These are acceptable types */ 297 break; 298 299 case ACPI_TYPE_INTEGER: 300 case ACPI_TYPE_STRING: 301 case ACPI_TYPE_BUFFER: 302 303 /* 304 * These types we will allow, but we will change the type. This 305 * enables some existing code of the form: 306 * 307 * Name (DEB, 0) 308 * Scope (DEB) { ... } 309 * 310 * Note: silently change the type here. On the second pass, we will report a warning 311 */ 312 313 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n", 314 Path, AcpiUtGetTypeName (Node->Type))); 315 316 Node->Type = ACPI_TYPE_ANY; 317 WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY; 318 break; 319 320 default: 321 322 /* All other types are an error */ 323 324 ACPI_REPORT_ERROR (("Invalid type (%s) for target of Scope operator [%4.4s] (Cannot override)\n", 325 AcpiUtGetTypeName (Node->Type), Path)); 326 327 return (AE_AML_OPERAND_TYPE); 328 } 329 break; 330 331 332 default: 333 334 /* 335 * For all other named opcodes, we will enter the name into the namespace. 336 * 337 * Setup the search flags. 338 * Since we are entering a name into the namespace, we do not want to 339 * enable the search-to-root upsearch. 340 * 341 * There are only two conditions where it is acceptable that the name 342 * already exists: 343 * 1) the Scope() operator can reopen a scoping object that was 344 * previously defined (Scope, Method, Device, etc.) 345 * 2) Whenever we are parsing a deferred opcode (OpRegion, Buffer, 346 * BufferField, or Package), the name of the object is already 347 * in the namespace. 348 */ 349 if (WalkState->DeferredNode) 350 { 351 /* This name is already in the namespace, get the node */ 352 353 Node = WalkState->DeferredNode; 354 Status = AE_OK; 355 break; 356 } 357 358 Flags = ACPI_NS_NO_UPSEARCH; 359 if ((WalkState->Opcode != AML_SCOPE_OP) && 360 (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP))) 361 { 362 Flags |= ACPI_NS_ERROR_IF_FOUND; 363 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n", 364 AcpiUtGetTypeName (ObjectType))); 365 } 366 else 367 { 368 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Both Find or Create allowed\n", 369 AcpiUtGetTypeName (ObjectType))); 370 } 371 372 /* 373 * Enter the named type into the internal namespace. We enter the name 374 * as we go downward in the parse tree. Any necessary subobjects that involve 375 * arguments to the opcode must be created as we go back up the parse tree later. 376 */ 377 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType, 378 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &(Node)); 379 if (ACPI_FAILURE (Status)) 380 { 381 ACPI_REPORT_NSERROR (Path, Status); 382 return (Status); 383 } 384 break; 385 } 386 387 388 /* Common exit */ 389 390 if (!Op) 391 { 392 /* Create a new op */ 393 394 Op = AcpiPsAllocOp (WalkState->Opcode); 395 if (!Op) 396 { 397 return (AE_NO_MEMORY); 398 } 399 } 400 401 /* Initialize */ 402 403 Op->Named.Name = Node->Name.Integer; 404 405#if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY)) 406 Op->Named.Path = (UINT8 *) Path; 407#endif 408 409 410 /* 411 * Put the Node in the "op" object that the parser uses, so we 412 * can get it again quickly when this scope is closed 413 */ 414 Op->Common.Node = Node; 415 AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op); 416 417 *OutOp = Op; 418 return (Status); 419} 420 421 422/******************************************************************************* 423 * 424 * FUNCTION: AcpiDsLoad1EndOp 425 * 426 * PARAMETERS: WalkState - Current state of the parse tree walk 427 * Op - Op that has been just been completed in the 428 * walk; Arguments have now been evaluated. 429 * 430 * RETURN: Status 431 * 432 * DESCRIPTION: Ascending callback used during the loading of the namespace, 433 * both control methods and everything else. 434 * 435 ******************************************************************************/ 436 437ACPI_STATUS 438AcpiDsLoad1EndOp ( 439 ACPI_WALK_STATE *WalkState) 440{ 441 ACPI_PARSE_OBJECT *Op; 442 ACPI_OBJECT_TYPE ObjectType; 443 ACPI_STATUS Status = AE_OK; 444 445 446 ACPI_FUNCTION_NAME ("DsLoad1EndOp"); 447 448 449 Op = WalkState->Op; 450 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState)); 451 452 /* We are only interested in opcodes that have an associated name */ 453 454 if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD))) 455 { 456 return (AE_OK); 457 } 458 459 /* Get the object type to determine if we should pop the scope */ 460 461 ObjectType = WalkState->OpInfo->ObjectType; 462 463#ifndef ACPI_NO_METHOD_EXECUTION 464 if (WalkState->OpInfo->Flags & AML_FIELD) 465 { 466 if (WalkState->Opcode == AML_FIELD_OP || 467 WalkState->Opcode == AML_BANK_FIELD_OP || 468 WalkState->Opcode == AML_INDEX_FIELD_OP) 469 { 470 Status = AcpiDsInitFieldObjects (Op, WalkState); 471 } 472 return (Status); 473 } 474 475 476 if (Op->Common.AmlOpcode == AML_REGION_OP) 477 { 478 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length, 479 (ACPI_ADR_SPACE_TYPE) ((Op->Common.Value.Arg)->Common.Value.Integer), WalkState); 480 if (ACPI_FAILURE (Status)) 481 { 482 return (Status); 483 } 484 } 485#endif 486 487 if (Op->Common.AmlOpcode == AML_NAME_OP) 488 { 489 /* For Name opcode, get the object type from the argument */ 490 491 if (Op->Common.Value.Arg) 492 { 493 ObjectType = (AcpiPsGetOpcodeInfo ((Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType; 494 Op->Common.Node->Type = (UINT8) ObjectType; 495 } 496 } 497 498 if (Op->Common.AmlOpcode == AML_METHOD_OP) 499 { 500 /* 501 * MethodOp PkgLength NameString MethodFlags TermList 502 * 503 * Note: We must create the method node/object pair as soon as we 504 * see the method declaration. This allows later pass1 parsing 505 * of invocations of the method (need to know the number of 506 * arguments.) 507 */ 508 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 509 "LOADING-Method: State=%p Op=%p NamedObj=%p\n", 510 WalkState, Op, Op->Named.Node)); 511 512 if (!AcpiNsGetAttachedObject (Op->Named.Node)) 513 { 514 WalkState->Operands[0] = (void *) Op->Named.Node; 515 WalkState->NumOperands = 1; 516 517 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg); 518 if (ACPI_SUCCESS (Status)) 519 { 520 Status = AcpiExCreateMethod (Op->Named.Data, 521 Op->Named.Length, WalkState); 522 } 523 WalkState->Operands[0] = NULL; 524 WalkState->NumOperands = 0; 525 526 if (ACPI_FAILURE (Status)) 527 { 528 return (Status); 529 } 530 } 531 } 532 533 /* Pop the scope stack */ 534 535 if (AcpiNsOpensScope (ObjectType)) 536 { 537 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n", 538 AcpiUtGetTypeName (ObjectType), Op)); 539 540 Status = AcpiDsScopeStackPop (WalkState); 541 } 542 543 return (Status); 544} 545 546 547/******************************************************************************* 548 * 549 * FUNCTION: AcpiDsLoad2BeginOp 550 * 551 * PARAMETERS: WalkState - Current state of the parse tree walk 552 * Op - Op that has been just been reached in the 553 * walk; Arguments have not been evaluated yet. 554 * 555 * RETURN: Status 556 * 557 * DESCRIPTION: Descending callback used during the loading of ACPI tables. 558 * 559 ******************************************************************************/ 560 561ACPI_STATUS 562AcpiDsLoad2BeginOp ( 563 ACPI_WALK_STATE *WalkState, 564 ACPI_PARSE_OBJECT **OutOp) 565{ 566 ACPI_PARSE_OBJECT *Op; 567 ACPI_NAMESPACE_NODE *Node; 568 ACPI_STATUS Status; 569 ACPI_OBJECT_TYPE ObjectType; 570 char *BufferPtr; 571 572 573 ACPI_FUNCTION_TRACE ("DsLoad2BeginOp"); 574 575 576 Op = WalkState->Op; 577 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState)); 578 579 if (Op) 580 { 581 /* We only care about Namespace opcodes here */ 582 583 if ((!(WalkState->OpInfo->Flags & AML_NSOPCODE) && (WalkState->Opcode != AML_INT_NAMEPATH_OP)) || 584 (!(WalkState->OpInfo->Flags & AML_NAMED))) 585 { 586 return_ACPI_STATUS (AE_OK); 587 } 588 589 /* 590 * Get the name we are going to enter or lookup in the namespace 591 */ 592 if (WalkState->Opcode == AML_INT_NAMEPATH_OP) 593 { 594 /* For Namepath op, get the path string */ 595 596 BufferPtr = Op->Common.Value.String; 597 if (!BufferPtr) 598 { 599 /* No name, just exit */ 600 601 return_ACPI_STATUS (AE_OK); 602 } 603 } 604 else 605 { 606 /* Get name from the op */ 607 608 BufferPtr = (char *) &Op->Named.Name; 609 } 610 } 611 else 612 { 613 /* Get the namestring from the raw AML */ 614 615 BufferPtr = AcpiPsGetNextNamestring (&WalkState->ParserState); 616 } 617 618 /* Map the opcode into an internal object type */ 619 620 ObjectType = WalkState->OpInfo->ObjectType; 621 622 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 623 "State=%p Op=%p Type=%X\n", WalkState, Op, ObjectType)); 624 625 626 switch (WalkState->Opcode) 627 { 628 case AML_FIELD_OP: 629 case AML_BANK_FIELD_OP: 630 case AML_INDEX_FIELD_OP: 631 632 Node = NULL; 633 Status = AE_OK; 634 break; 635 636 case AML_INT_NAMEPATH_OP: 637 638 /* 639 * The NamePath is an object reference to an existing object. Don't enter the 640 * name into the namespace, but look it up for use later 641 */ 642 Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType, 643 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node)); 644 break; 645 646 case AML_SCOPE_OP: 647 648 /* 649 * The Path is an object reference to an existing object. Don't enter the 650 * name into the namespace, but look it up for use later 651 */ 652 Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType, 653 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node)); 654 if (ACPI_FAILURE (Status)) 655 { 656#ifdef _ACPI_ASL_COMPILER 657 if (Status == AE_NOT_FOUND) 658 { 659 Status = AE_OK; 660 } 661 else 662 { 663 ACPI_REPORT_NSERROR (BufferPtr, Status); 664 } 665#else 666 ACPI_REPORT_NSERROR (BufferPtr, Status); 667#endif 668 return_ACPI_STATUS (Status); 669 } 670 /* 671 * We must check to make sure that the target is 672 * one of the opcodes that actually opens a scope 673 */ 674 switch (Node->Type) 675 { 676 case ACPI_TYPE_LOCAL_SCOPE: /* Scope */ 677 case ACPI_TYPE_DEVICE: 678 case ACPI_TYPE_POWER: 679 case ACPI_TYPE_PROCESSOR: 680 case ACPI_TYPE_THERMAL: 681 682 /* These are acceptable types */ 683 break; 684 685 case ACPI_TYPE_INTEGER: 686 case ACPI_TYPE_STRING: 687 case ACPI_TYPE_BUFFER: 688 689 /* 690 * These types we will allow, but we will change the type. This 691 * enables some existing code of the form: 692 * 693 * Name (DEB, 0) 694 * Scope (DEB) { ... } 695 */ 696 697 ACPI_REPORT_WARNING (("Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n", 698 BufferPtr, AcpiUtGetTypeName (Node->Type))); 699 700 Node->Type = ACPI_TYPE_ANY; 701 WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY; 702 break; 703 704 default: 705 706 /* All other types are an error */ 707 708 ACPI_REPORT_ERROR (("Invalid type (%s) for target of Scope operator [%4.4s]\n", 709 AcpiUtGetTypeName (Node->Type), BufferPtr)); 710 711 return (AE_AML_OPERAND_TYPE); 712 } 713 break; 714 715 default: 716 717 /* All other opcodes */ 718 719 if (Op && Op->Common.Node) 720 { 721 /* This op/node was previously entered into the namespace */ 722 723 Node = Op->Common.Node; 724 725 if (AcpiNsOpensScope (ObjectType)) 726 { 727 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState); 728 if (ACPI_FAILURE (Status)) 729 { 730 return_ACPI_STATUS (Status); 731 } 732 733 } 734 return_ACPI_STATUS (AE_OK); 735 } 736 737 /* 738 * Enter the named type into the internal namespace. We enter the name 739 * as we go downward in the parse tree. Any necessary subobjects that involve 740 * arguments to the opcode must be created as we go back up the parse tree later. 741 * 742 * Note: Name may already exist if we are executing a deferred opcode. 743 */ 744 if (WalkState->DeferredNode) 745 { 746 /* This name is already in the namespace, get the node */ 747 748 Node = WalkState->DeferredNode; 749 Status = AE_OK; 750 break; 751 } 752 753 Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType, 754 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, WalkState, &(Node)); 755 break; 756 } 757 758 if (ACPI_FAILURE (Status)) 759 { 760 ACPI_REPORT_NSERROR (BufferPtr, Status); 761 return_ACPI_STATUS (Status); 762 } 763 764 765 if (!Op) 766 { 767 /* Create a new op */ 768 769 Op = AcpiPsAllocOp (WalkState->Opcode); 770 if (!Op) 771 { 772 return_ACPI_STATUS (AE_NO_MEMORY); 773 } 774 775 /* Initialize the new op */ 776 777 if (Node) 778 { 779 Op->Named.Name = Node->Name.Integer; 780 } 781 if (OutOp) 782 { 783 *OutOp = Op; 784 } 785 } 786 787 /* 788 * Put the Node in the "op" object that the parser uses, so we 789 * can get it again quickly when this scope is closed 790 */ 791 Op->Common.Node = Node; 792 793 return_ACPI_STATUS (Status); 794} 795 796 797/******************************************************************************* 798 * 799 * FUNCTION: AcpiDsLoad2EndOp 800 * 801 * PARAMETERS: WalkState - Current state of the parse tree walk 802 * Op - Op that has been just been completed in the 803 * walk; Arguments have now been evaluated. 804 * 805 * RETURN: Status 806 * 807 * DESCRIPTION: Ascending callback used during the loading of the namespace, 808 * both control methods and everything else. 809 * 810 ******************************************************************************/ 811 812ACPI_STATUS 813AcpiDsLoad2EndOp ( 814 ACPI_WALK_STATE *WalkState) 815{ 816 ACPI_PARSE_OBJECT *Op; 817 ACPI_STATUS Status = AE_OK; 818 ACPI_OBJECT_TYPE ObjectType; 819 ACPI_NAMESPACE_NODE *Node; 820 ACPI_PARSE_OBJECT *Arg; 821 ACPI_NAMESPACE_NODE *NewNode; 822#ifndef ACPI_NO_METHOD_EXECUTION 823 UINT32 i; 824#endif 825 826 827 ACPI_FUNCTION_TRACE ("DsLoad2EndOp"); 828 829 Op = WalkState->Op; 830 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n", 831 WalkState->OpInfo->Name, Op, WalkState)); 832 833 /* Only interested in opcodes that have namespace objects */ 834 835 if (!(WalkState->OpInfo->Flags & AML_NSOBJECT)) 836 { 837 return_ACPI_STATUS (AE_OK); 838 } 839 840 if (Op->Common.AmlOpcode == AML_SCOPE_OP) 841 { 842 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 843 "Ending scope Op=%p State=%p\n", Op, WalkState)); 844 } 845 846 847 ObjectType = WalkState->OpInfo->ObjectType; 848 849 /* 850 * Get the Node/name from the earlier lookup 851 * (It was saved in the *op structure) 852 */ 853 Node = Op->Common.Node; 854 855 /* 856 * Put the Node on the object stack (Contains the ACPI Name of 857 * this object) 858 */ 859 WalkState->Operands[0] = (void *) Node; 860 WalkState->NumOperands = 1; 861 862 /* Pop the scope stack */ 863 864 if (AcpiNsOpensScope (ObjectType) && (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP)) 865 { 866 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n", 867 AcpiUtGetTypeName (ObjectType), Op)); 868 869 Status = AcpiDsScopeStackPop (WalkState); 870 if (ACPI_FAILURE (Status)) 871 { 872 goto Cleanup; 873 } 874 } 875 876 /* 877 * Named operations are as follows: 878 * 879 * AML_ALIAS 880 * AML_BANKFIELD 881 * AML_CREATEBITFIELD 882 * AML_CREATEBYTEFIELD 883 * AML_CREATEDWORDFIELD 884 * AML_CREATEFIELD 885 * AML_CREATEQWORDFIELD 886 * AML_CREATEWORDFIELD 887 * AML_DATA_REGION 888 * AML_DEVICE 889 * AML_EVENT 890 * AML_FIELD 891 * AML_INDEXFIELD 892 * AML_METHOD 893 * AML_METHODCALL 894 * AML_MUTEX 895 * AML_NAME 896 * AML_NAMEDFIELD 897 * AML_OPREGION 898 * AML_POWERRES 899 * AML_PROCESSOR 900 * AML_SCOPE 901 * AML_THERMALZONE 902 */ 903 904 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 905 "Create-Load [%s] State=%p Op=%p NamedObj=%p\n", 906 AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node)); 907 908 /* Decode the opcode */ 909 910 Arg = Op->Common.Value.Arg; 911 912 switch (WalkState->OpInfo->Type) 913 { 914#ifndef ACPI_NO_METHOD_EXECUTION 915 916 case AML_TYPE_CREATE_FIELD: 917 918 /* 919 * Create the field object, but the field buffer and index must 920 * be evaluated later during the execution phase 921 */ 922 Status = AcpiDsCreateBufferField (Op, WalkState); 923 break; 924 925 926 case AML_TYPE_NAMED_FIELD: 927 928 switch (Op->Common.AmlOpcode) 929 { 930 case AML_INDEX_FIELD_OP: 931 932 Status = AcpiDsCreateIndexField (Op, (ACPI_HANDLE) Arg->Common.Node, 933 WalkState); 934 break; 935 936 case AML_BANK_FIELD_OP: 937 938 Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState); 939 break; 940 941 case AML_FIELD_OP: 942 943 Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState); 944 break; 945 946 default: 947 /* All NAMED_FIELD opcodes must be handled above */ 948 break; 949 } 950 break; 951 952 953 case AML_TYPE_NAMED_SIMPLE: 954 955 Status = AcpiDsCreateOperands (WalkState, Arg); 956 if (ACPI_FAILURE (Status)) 957 { 958 goto Cleanup; 959 } 960 961 switch (Op->Common.AmlOpcode) 962 { 963 case AML_PROCESSOR_OP: 964 965 Status = AcpiExCreateProcessor (WalkState); 966 break; 967 968 case AML_POWER_RES_OP: 969 970 Status = AcpiExCreatePowerResource (WalkState); 971 break; 972 973 case AML_MUTEX_OP: 974 975 Status = AcpiExCreateMutex (WalkState); 976 break; 977 978 case AML_EVENT_OP: 979 980 Status = AcpiExCreateEvent (WalkState); 981 break; 982 983 case AML_DATA_REGION_OP: 984 985 Status = AcpiExCreateTableRegion (WalkState); 986 break; 987 988 case AML_ALIAS_OP: 989 990 Status = AcpiExCreateAlias (WalkState); 991 break; 992 993 default: 994 /* Unknown opcode */ 995 996 Status = AE_OK; 997 goto Cleanup; 998 } 999 1000 /* Delete operands */ 1001 1002 for (i = 1; i < WalkState->NumOperands; i++) 1003 { 1004 AcpiUtRemoveReference (WalkState->Operands[i]); 1005 WalkState->Operands[i] = NULL; 1006 } 1007 1008 break; 1009#endif /* ACPI_NO_METHOD_EXECUTION */ 1010 1011 case AML_TYPE_NAMED_COMPLEX: 1012 1013 switch (Op->Common.AmlOpcode) 1014 { 1015#ifndef ACPI_NO_METHOD_EXECUTION 1016 case AML_REGION_OP: 1017 /* 1018 * The OpRegion is not fully parsed at this time. Only valid argument is the SpaceId. 1019 * (We must save the address of the AML of the address and length operands) 1020 */ 1021 /* 1022 * If we have a valid region, initialize it 1023 * Namespace is NOT locked at this point. 1024 */ 1025 Status = AcpiEvInitializeRegion (AcpiNsGetAttachedObject (Node), FALSE); 1026 if (ACPI_FAILURE (Status)) 1027 { 1028 /* 1029 * If AE_NOT_EXIST is returned, it is not fatal 1030 * because many regions get created before a handler 1031 * is installed for said region. 1032 */ 1033 if (AE_NOT_EXIST == Status) 1034 { 1035 Status = AE_OK; 1036 } 1037 } 1038 break; 1039 1040 1041 case AML_NAME_OP: 1042 1043 Status = AcpiDsCreateNode (WalkState, Node, Op); 1044 break; 1045#endif /* ACPI_NO_METHOD_EXECUTION */ 1046 1047 1048 default: 1049 /* All NAMED_COMPLEX opcodes must be handled above */ 1050 /* Note: Method objects were already created in Pass 1 */ 1051 break; 1052 } 1053 break; 1054 1055 1056 case AML_CLASS_INTERNAL: 1057 1058 /* case AML_INT_NAMEPATH_OP: */ 1059 break; 1060 1061 1062 case AML_CLASS_METHOD_CALL: 1063 1064 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 1065 "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n", 1066 WalkState, Op, Node)); 1067 1068 /* 1069 * Lookup the method name and save the Node 1070 */ 1071 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String, 1072 ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2, 1073 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, 1074 WalkState, &(NewNode)); 1075 if (ACPI_SUCCESS (Status)) 1076 { 1077 /* 1078 * Make sure that what we found is indeed a method 1079 * We didn't search for a method on purpose, to see if the name would resolve 1080 */ 1081 if (NewNode->Type != ACPI_TYPE_METHOD) 1082 { 1083 Status = AE_AML_OPERAND_TYPE; 1084 } 1085 1086 /* We could put the returned object (Node) on the object stack for later, but 1087 * for now, we will put it in the "op" object that the parser uses, so we 1088 * can get it again at the end of this scope 1089 */ 1090 Op->Common.Node = NewNode; 1091 } 1092 else 1093 { 1094 ACPI_REPORT_NSERROR (Arg->Common.Value.String, Status); 1095 } 1096 break; 1097 1098 1099 default: 1100 break; 1101 } 1102 1103Cleanup: 1104 1105 /* Remove the Node pushed at the very beginning */ 1106 1107 WalkState->Operands[0] = NULL; 1108 WalkState->NumOperands = 0; 1109 return_ACPI_STATUS (Status); 1110} 1111 1112 1113