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