1 /****************************************************************************** 2 * 3 * Module Name: dswload - Dispatcher namespace load callbacks 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 ***************************************************************************** 115 * 116 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include <contrib/dev/acpica/compiler/aslcompiler.h> 153 #include <contrib/dev/acpica/include/amlcode.h> 154 #include <contrib/dev/acpica/include/acdispat.h> 155 #include <contrib/dev/acpica/include/acnamesp.h> 156 157 #include "aslcompiler.y.h" 158 159 #define _COMPONENT ACPI_COMPILER 160 ACPI_MODULE_NAME ("aslload") 161 162 /* Local prototypes */ 163 164 static ACPI_STATUS 165 LdLoadFieldElements ( 166 ACPI_PARSE_OBJECT *Op, 167 ACPI_WALK_STATE *WalkState); 168 169 static ACPI_STATUS 170 LdLoadResourceElements ( 171 ACPI_PARSE_OBJECT *Op, 172 ACPI_WALK_STATE *WalkState); 173 174 static ACPI_STATUS 175 LdNamespace1Begin ( 176 ACPI_PARSE_OBJECT *Op, 177 UINT32 Level, 178 void *Context); 179 180 static ACPI_STATUS 181 LdNamespace2Begin ( 182 ACPI_PARSE_OBJECT *Op, 183 UINT32 Level, 184 void *Context); 185 186 static ACPI_STATUS 187 LdCommonNamespaceEnd ( 188 ACPI_PARSE_OBJECT *Op, 189 UINT32 Level, 190 void *Context); 191 192 193 /******************************************************************************* 194 * 195 * FUNCTION: LdLoadNamespace 196 * 197 * PARAMETERS: RootOp - Root of the parse tree 198 * 199 * RETURN: Status 200 * 201 * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the 202 * named ASL/AML objects into the namespace. The namespace is 203 * constructed in order to resolve named references and references 204 * to named fields within resource templates/descriptors. 205 * 206 ******************************************************************************/ 207 208 ACPI_STATUS 209 LdLoadNamespace ( 210 ACPI_PARSE_OBJECT *RootOp) 211 { 212 ACPI_WALK_STATE *WalkState; 213 214 215 /* Create a new walk state */ 216 217 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL); 218 if (!WalkState) 219 { 220 return (AE_NO_MEMORY); 221 } 222 223 /* Walk the entire parse tree, first pass */ 224 225 TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin, 226 LdCommonNamespaceEnd, WalkState); 227 228 /* Second pass to handle forward references */ 229 230 TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace2Begin, 231 LdCommonNamespaceEnd, WalkState); 232 233 /* Dump the namespace if debug is enabled */ 234 235 AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX); 236 ACPI_FREE (WalkState); 237 return (AE_OK); 238 } 239 240 241 /******************************************************************************* 242 * 243 * FUNCTION: LdLoadFieldElements 244 * 245 * PARAMETERS: Op - Parent node (Field) 246 * WalkState - Current walk state 247 * 248 * RETURN: Status 249 * 250 * DESCRIPTION: Enter the named elements of the field (children of the parent) 251 * into the namespace. 252 * 253 ******************************************************************************/ 254 255 static ACPI_STATUS 256 LdLoadFieldElements ( 257 ACPI_PARSE_OBJECT *Op, 258 ACPI_WALK_STATE *WalkState) 259 { 260 ACPI_PARSE_OBJECT *Child = NULL; 261 ACPI_NAMESPACE_NODE *Node; 262 ACPI_STATUS Status; 263 264 265 /* Get the first named field element */ 266 267 switch (Op->Asl.AmlOpcode) 268 { 269 case AML_BANK_FIELD_OP: 270 271 Child = UtGetArg (Op, 6); 272 break; 273 274 case AML_INDEX_FIELD_OP: 275 276 Child = UtGetArg (Op, 5); 277 break; 278 279 case AML_FIELD_OP: 280 281 Child = UtGetArg (Op, 4); 282 break; 283 284 default: 285 286 /* No other opcodes should arrive here */ 287 288 return (AE_BAD_PARAMETER); 289 } 290 291 /* Enter all elements into the namespace */ 292 293 while (Child) 294 { 295 switch (Child->Asl.AmlOpcode) 296 { 297 case AML_INT_RESERVEDFIELD_OP: 298 case AML_INT_ACCESSFIELD_OP: 299 case AML_INT_CONNECTION_OP: 300 break; 301 302 default: 303 304 Status = AcpiNsLookup (WalkState->ScopeInfo, 305 Child->Asl.Value.String, 306 ACPI_TYPE_LOCAL_REGION_FIELD, 307 ACPI_IMODE_LOAD_PASS1, 308 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | 309 ACPI_NS_ERROR_IF_FOUND, NULL, &Node); 310 if (ACPI_FAILURE (Status)) 311 { 312 if (Status != AE_ALREADY_EXISTS) 313 { 314 AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child, 315 Child->Asl.Value.String); 316 return (Status); 317 } 318 else if (Status == AE_ALREADY_EXISTS && 319 (Node->Flags & ANOBJ_IS_EXTERNAL)) 320 { 321 Node->Type = (UINT8) ACPI_TYPE_LOCAL_REGION_FIELD; 322 } 323 else 324 { 325 /* 326 * The name already exists in this scope 327 * But continue processing the elements 328 */ 329 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child, 330 Child->Asl.Value.String); 331 } 332 } 333 else 334 { 335 Child->Asl.Node = Node; 336 Node->Op = Child; 337 } 338 break; 339 } 340 341 Child = Child->Asl.Next; 342 } 343 344 return (AE_OK); 345 } 346 347 348 /******************************************************************************* 349 * 350 * FUNCTION: LdLoadResourceElements 351 * 352 * PARAMETERS: Op - Parent node (Resource Descriptor) 353 * WalkState - Current walk state 354 * 355 * RETURN: Status 356 * 357 * DESCRIPTION: Enter the named elements of the resource descriptor (children 358 * of the parent) into the namespace. 359 * 360 * NOTE: In the real AML namespace, these named elements never exist. But 361 * we simply use the namespace here as a symbol table so we can look 362 * them up as they are referenced. 363 * 364 ******************************************************************************/ 365 366 static ACPI_STATUS 367 LdLoadResourceElements ( 368 ACPI_PARSE_OBJECT *Op, 369 ACPI_WALK_STATE *WalkState) 370 { 371 ACPI_PARSE_OBJECT *InitializerOp = NULL; 372 ACPI_NAMESPACE_NODE *Node; 373 ACPI_STATUS Status; 374 375 376 /* 377 * Enter the resource name into the namespace. Name must not already exist. 378 * This opens a scope, so later field names are guaranteed to be new/unique. 379 */ 380 Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath, 381 ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1, 382 ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND, 383 WalkState, &Node); 384 if (ACPI_FAILURE (Status)) 385 { 386 if (Status == AE_ALREADY_EXISTS) 387 { 388 /* Actual node causing the error was saved in ParentMethod */ 389 390 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, 391 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod, Op->Asl.Namepath); 392 return (AE_OK); 393 } 394 return (Status); 395 } 396 397 Node->Value = (UINT32) Op->Asl.Value.Integer; 398 Node->Op = Op; 399 Op->Asl.Node = Node; 400 401 /* 402 * Now enter the predefined fields, for easy lookup when referenced 403 * by the source ASL 404 */ 405 InitializerOp = ASL_GET_CHILD_NODE (Op); 406 while (InitializerOp) 407 { 408 if (InitializerOp->Asl.ExternalName) 409 { 410 Status = AcpiNsLookup (WalkState->ScopeInfo, 411 InitializerOp->Asl.ExternalName, 412 ACPI_TYPE_LOCAL_RESOURCE_FIELD, 413 ACPI_IMODE_LOAD_PASS1, 414 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, 415 NULL, &Node); 416 if (ACPI_FAILURE (Status)) 417 { 418 return (Status); 419 } 420 421 /* 422 * Store the field offset and length in the namespace node 423 * so it can be used when the field is referenced 424 */ 425 Node->Value = InitializerOp->Asl.Value.Tag.BitOffset; 426 Node->Length = InitializerOp->Asl.Value.Tag.BitLength; 427 InitializerOp->Asl.Node = Node; 428 Node->Op = InitializerOp; 429 } 430 431 InitializerOp = ASL_GET_PEER_NODE (InitializerOp); 432 } 433 434 return (AE_OK); 435 } 436 437 438 /******************************************************************************* 439 * 440 * FUNCTION: LdNamespace1Begin 441 * 442 * PARAMETERS: ASL_WALK_CALLBACK 443 * 444 * RETURN: Status 445 * 446 * DESCRIPTION: Descending callback used during the parse tree walk. If this 447 * is a named AML opcode, enter into the namespace 448 * 449 ******************************************************************************/ 450 451 static ACPI_STATUS 452 LdNamespace1Begin ( 453 ACPI_PARSE_OBJECT *Op, 454 UINT32 Level, 455 void *Context) 456 { 457 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; 458 ACPI_NAMESPACE_NODE *Node; 459 ACPI_PARSE_OBJECT *MethodOp; 460 ACPI_STATUS Status; 461 ACPI_OBJECT_TYPE ObjectType; 462 ACPI_OBJECT_TYPE ActualObjectType = ACPI_TYPE_ANY; 463 char *Path; 464 UINT32 Flags = ACPI_NS_NO_UPSEARCH; 465 ACPI_PARSE_OBJECT *Arg; 466 UINT32 i; 467 BOOLEAN ForceNewScope = FALSE; 468 ACPI_OWNER_ID OwnerId = 0; 469 470 471 ACPI_FUNCTION_NAME (LdNamespace1Begin); 472 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n", 473 Op, Op->Asl.ParseOpName)); 474 475 if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK) 476 { 477 /* 478 * Allocate an OwnerId for this block. This helps identify the owners 479 * of each namespace node. This is used in determining whether if 480 * certain external declarations cause redefinition errors. 481 */ 482 Status = AcpiUtAllocateOwnerId (&OwnerId); 483 WalkState->OwnerId = OwnerId; 484 if (ACPI_FAILURE (Status)) 485 { 486 AslCoreSubsystemError (Op, Status, 487 "Failure to allocate owner ID to this definition block.", FALSE); 488 return_ACPI_STATUS (Status); 489 } 490 } 491 492 /* 493 * We are only interested in opcodes that have an associated name 494 * (or multiple names) 495 */ 496 switch (Op->Asl.AmlOpcode) 497 { 498 case AML_BANK_FIELD_OP: 499 case AML_INDEX_FIELD_OP: 500 case AML_FIELD_OP: 501 502 Status = LdLoadFieldElements (Op, WalkState); 503 return (Status); 504 505 case AML_INT_CONNECTION_OP: 506 507 508 if (Op->Asl.Child->Asl.AmlOpcode != AML_INT_NAMEPATH_OP) 509 { 510 break; 511 } 512 Arg = Op->Asl.Child; 513 514 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Asl.ExternalName, 515 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, 516 WalkState, &Node); 517 if (ACPI_FAILURE (Status)) 518 { 519 break; 520 } 521 522 if (Node->Type == ACPI_TYPE_BUFFER) 523 { 524 Arg->Asl.Node = Node; 525 526 Arg = Node->Op->Asl.Child; /* Get namepath */ 527 Arg = Arg->Asl.Next; /* Get actual buffer */ 528 Arg = Arg->Asl.Child; /* Buffer length */ 529 Arg = Arg->Asl.Next; /* RAW_DATA buffer */ 530 } 531 break; 532 533 default: 534 535 /* All other opcodes go below */ 536 537 break; 538 } 539 540 /* Check if this object has already been installed in the namespace */ 541 542 if (Op->Asl.Node) 543 { 544 return (AE_OK); 545 } 546 547 Path = Op->Asl.Namepath; 548 if (!Path) 549 { 550 return (AE_OK); 551 } 552 553 /* Map the raw opcode into an internal object type */ 554 555 switch (Op->Asl.ParseOpcode) 556 { 557 case PARSEOP_NAME: 558 559 Arg = Op->Asl.Child; /* Get the NameSeg/NameString node */ 560 Arg = Arg->Asl.Next; /* First peer is the object to be associated with the name */ 561 562 /* 563 * If this name refers to a ResourceTemplate, we will need to open 564 * a new scope so that the resource subfield names can be entered into 565 * the namespace underneath this name 566 */ 567 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC) 568 { 569 ForceNewScope = TRUE; 570 } 571 572 /* Get the data type associated with the named object, not the name itself */ 573 574 /* Log2 loop to convert from Btype (binary) to Etype (encoded) */ 575 576 ObjectType = 1; 577 for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2) 578 { 579 ObjectType++; 580 } 581 break; 582 583 584 case PARSEOP_EXTERNAL: 585 /* 586 * "External" simply enters a name and type into the namespace. 587 * We must be careful to not open a new scope, however, no matter 588 * what type the external name refers to (e.g., a method) 589 * 590 * first child is name, next child is ObjectType 591 */ 592 ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer; 593 ObjectType = ACPI_TYPE_ANY; 594 595 /* 596 * We will mark every new node along the path as "External". This 597 * allows some or all of the nodes to be created later in the ASL 598 * code. Handles cases like this: 599 * 600 * External (\_SB_.PCI0.ABCD, IntObj) 601 * Scope (_SB_) 602 * { 603 * Device (PCI0) 604 * { 605 * } 606 * } 607 * Method (X) 608 * { 609 * Store (\_SB_.PCI0.ABCD, Local0) 610 * } 611 */ 612 Flags |= ACPI_NS_EXTERNAL; 613 break; 614 615 case PARSEOP_DEFAULT_ARG: 616 617 if (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC) 618 { 619 Status = LdLoadResourceElements (Op, WalkState); 620 return_ACPI_STATUS (Status); 621 } 622 623 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); 624 break; 625 626 case PARSEOP_SCOPE: 627 /* 628 * The name referenced by Scope(Name) must already exist at this point. 629 * In other words, forward references for Scope() are not supported. 630 * The only real reason for this is that the MS interpreter cannot 631 * handle this case. Perhaps someday this case can go away. 632 */ 633 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY, 634 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, 635 WalkState, &(Node)); 636 if (ACPI_FAILURE (Status)) 637 { 638 if (Status == AE_NOT_FOUND) 639 { 640 /* The name was not found, go ahead and create it */ 641 642 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, 643 ACPI_TYPE_LOCAL_SCOPE, 644 ACPI_IMODE_LOAD_PASS1, Flags, 645 WalkState, &(Node)); 646 if (ACPI_FAILURE (Status)) 647 { 648 return_ACPI_STATUS (Status); 649 } 650 651 /* 652 * However, this is an error -- primarily because the MS 653 * interpreter can't handle a forward reference from the 654 * Scope() operator. 655 */ 656 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op, 657 Op->Asl.ExternalName); 658 AslError (ASL_ERROR, ASL_MSG_SCOPE_FWD_REF, Op, 659 Op->Asl.ExternalName); 660 goto FinishNode; 661 } 662 663 AslCoreSubsystemError (Op, Status, 664 "Failure from namespace lookup", FALSE); 665 666 return_ACPI_STATUS (Status); 667 } 668 else /* Status AE_OK */ 669 { 670 /* 671 * Do not allow references to external scopes from the DSDT. 672 * This is because the DSDT is always loaded first, and the 673 * external reference cannot be resolved -- causing a runtime 674 * error because Scope() must be resolved immediately. 675 * 10/2015. 676 */ 677 if ((Node->Flags & ANOBJ_IS_EXTERNAL) && 678 (ACPI_COMPARE_NAME (Gbl_TableSignature, "DSDT"))) 679 { 680 /* However, allowed if the reference is within a method */ 681 682 MethodOp = Op->Asl.Parent; 683 while (MethodOp && 684 (MethodOp->Asl.ParseOpcode != PARSEOP_METHOD)) 685 { 686 MethodOp = MethodOp->Asl.Parent; 687 } 688 689 if (!MethodOp) 690 { 691 /* Not in a control method, error */ 692 693 AslError (ASL_ERROR, ASL_MSG_CROSS_TABLE_SCOPE, Op, NULL); 694 } 695 } 696 } 697 698 /* We found a node with this name, now check the type */ 699 700 switch (Node->Type) 701 { 702 case ACPI_TYPE_LOCAL_SCOPE: 703 case ACPI_TYPE_DEVICE: 704 case ACPI_TYPE_POWER: 705 case ACPI_TYPE_PROCESSOR: 706 case ACPI_TYPE_THERMAL: 707 708 /* These are acceptable types - they all open a new scope */ 709 break; 710 711 case ACPI_TYPE_INTEGER: 712 case ACPI_TYPE_STRING: 713 case ACPI_TYPE_BUFFER: 714 /* 715 * These types we will allow, but we will change the type. 716 * This enables some existing code of the form: 717 * 718 * Name (DEB, 0) 719 * Scope (DEB) { ... } 720 * 721 * Which is used to workaround the fact that the MS interpreter 722 * does not allow Scope() forward references. 723 */ 724 sprintf (MsgBuffer, "%s [%s], changing type to [Scope]", 725 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type)); 726 AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer); 727 728 /* Switch the type to scope, open the new scope */ 729 730 Node->Type = ACPI_TYPE_LOCAL_SCOPE; 731 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE, 732 WalkState); 733 if (ACPI_FAILURE (Status)) 734 { 735 return_ACPI_STATUS (Status); 736 } 737 break; 738 739 default: 740 741 /* All other types are an error */ 742 743 sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName, 744 AcpiUtGetTypeName (Node->Type)); 745 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer); 746 747 /* 748 * However, switch the type to be an actual scope so 749 * that compilation can continue without generating a whole 750 * cascade of additional errors. Open the new scope. 751 */ 752 Node->Type = ACPI_TYPE_LOCAL_SCOPE; 753 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE, 754 WalkState); 755 if (ACPI_FAILURE (Status)) 756 { 757 return_ACPI_STATUS (Status); 758 } 759 break; 760 } 761 762 Status = AE_OK; 763 goto FinishNode; 764 765 766 default: 767 768 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); 769 break; 770 } 771 772 773 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n", 774 Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType))); 775 776 /* The name must not already exist */ 777 778 Flags |= ACPI_NS_ERROR_IF_FOUND; 779 780 /* 781 * Enter the named type into the internal namespace. We enter the name 782 * as we go downward in the parse tree. Any necessary subobjects that 783 * involve arguments to the opcode must be created as we go back up the 784 * parse tree later. 785 */ 786 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType, 787 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node); 788 if (ACPI_FAILURE (Status)) 789 { 790 if (Status == AE_ALREADY_EXISTS) 791 { 792 /* The name already exists in this scope */ 793 794 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE) 795 { 796 /* Allow multiple references to the same scope */ 797 798 Node->Type = (UINT8) ObjectType; 799 Status = AE_OK; 800 } 801 else if ((Node->Flags & ANOBJ_IS_EXTERNAL) && 802 (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL)) 803 { 804 /* 805 * Allow one create on an object or segment that was 806 * previously declared External only if WalkState->OwnerId and 807 * Node->OwnerId are found in different tables (meaning that 808 * they have differnt OwnerIds). 809 */ 810 Node->Flags &= ~ANOBJ_IS_EXTERNAL; 811 Node->Type = (UINT8) ObjectType; 812 813 /* Just retyped a node, probably will need to open a scope */ 814 815 if (AcpiNsOpensScope (ObjectType)) 816 { 817 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState); 818 if (ACPI_FAILURE (Status)) 819 { 820 return_ACPI_STATUS (Status); 821 } 822 } 823 824 Status = AE_OK; 825 826 if (Node->OwnerId == WalkState->OwnerId) 827 { 828 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op, 829 Op->Asl.ExternalName); 830 } 831 } 832 else if (!(Node->Flags & ANOBJ_IS_EXTERNAL) && 833 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)) 834 { 835 /* 836 * Allow externals in same scope as the definition of the 837 * actual object. Similar to C. Allows multiple definition 838 * blocks that refer to each other in the same file. However, 839 * do not allow name declaration and an external declaration 840 * within the same table. This is considered a re-declaration. 841 */ 842 Status = AE_OK; 843 844 if (Node->OwnerId == WalkState->OwnerId) 845 { 846 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op, 847 Op->Asl.ExternalName); 848 } 849 } 850 else if ((Node->Flags & ANOBJ_IS_EXTERNAL) && 851 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) && 852 (ObjectType == ACPI_TYPE_ANY)) 853 { 854 /* 855 * Allow update of externals of unknown type. 856 * In the case that multiple definition blocks are being 857 * parsed, updating the OwnerId allows enables subsequent calls 858 * of this method to understand which table the most recent 859 * external declaration was seen. Without this OwnerId update, 860 * code like the following is allowed to compile: 861 * 862 * DefinitionBlock("externtest.aml", "DSDT", 0x02, "Intel", "Many", 0x00000001) 863 * { 864 * External(ERRS,methodobj) 865 * Method (MAIN) 866 * { 867 * Name(NUM2, 0) 868 * ERRS(1,2,3) 869 * } 870 * } 871 * 872 * DefinitionBlock("externtest.aml", "SSDT", 0x02, "Intel", "Many", 0x00000001) 873 * { 874 * if (0) 875 * { 876 * External(ERRS,methodobj) 877 * } 878 * Method (ERRS,3) 879 * {} 880 * 881 * } 882 */ 883 Node->OwnerId = WalkState->OwnerId; 884 885 if (AcpiNsOpensScope (ActualObjectType)) 886 { 887 Node->Type = (UINT8) ActualObjectType; 888 Status = AE_OK; 889 } 890 else 891 { 892 sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName, 893 AcpiUtGetTypeName (Node->Type)); 894 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer); 895 return_ACPI_STATUS (AE_OK); 896 } 897 } 898 else 899 { 900 /* Valid error, object already exists */ 901 902 AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op, 903 Op->Asl.ExternalName); 904 return_ACPI_STATUS (AE_OK); 905 } 906 } 907 else 908 { 909 AslCoreSubsystemError (Op, Status, 910 "Failure from namespace lookup", FALSE); 911 return_ACPI_STATUS (Status); 912 } 913 } 914 915 if (ForceNewScope) 916 { 917 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState); 918 if (ACPI_FAILURE (Status)) 919 { 920 return_ACPI_STATUS (Status); 921 } 922 } 923 924 FinishNode: 925 /* 926 * Point the parse node to the new namespace node, and point 927 * the Node back to the original Parse node 928 */ 929 Op->Asl.Node = Node; 930 Node->Op = Op; 931 932 /* Set the actual data type if appropriate (EXTERNAL term only) */ 933 934 if (ActualObjectType != ACPI_TYPE_ANY) 935 { 936 Node->Type = (UINT8) ActualObjectType; 937 Node->Value = ASL_EXTERNAL_METHOD; 938 } 939 940 if (Op->Asl.ParseOpcode == PARSEOP_METHOD) 941 { 942 /* 943 * Get the method argument count from "Extra" and save 944 * it in the namespace node 945 */ 946 Node->Value = (UINT32) Op->Asl.Extra; 947 } 948 949 return_ACPI_STATUS (Status); 950 } 951 952 953 /******************************************************************************* 954 * 955 * FUNCTION: LdNamespace2Begin 956 * 957 * PARAMETERS: ASL_WALK_CALLBACK 958 * 959 * RETURN: Status 960 * 961 * DESCRIPTION: Descending callback used during the pass 2 parse tree walk. 962 * Second pass resolves some forward references. 963 * 964 * Notes: 965 * Currently only needs to handle the Alias operator. 966 * Could be used to allow forward references from the Scope() operator, but 967 * the MS interpreter does not allow this, so this compiler does not either. 968 * 969 ******************************************************************************/ 970 971 static ACPI_STATUS 972 LdNamespace2Begin ( 973 ACPI_PARSE_OBJECT *Op, 974 UINT32 Level, 975 void *Context) 976 { 977 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; 978 ACPI_STATUS Status; 979 ACPI_NAMESPACE_NODE *Node; 980 ACPI_OBJECT_TYPE ObjectType; 981 BOOLEAN ForceNewScope = FALSE; 982 ACPI_PARSE_OBJECT *Arg; 983 char *Path; 984 ACPI_NAMESPACE_NODE *TargetNode; 985 986 987 ACPI_FUNCTION_NAME (LdNamespace2Begin); 988 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n", 989 Op, Op->Asl.ParseOpName)); 990 991 992 /* Ignore Ops with no namespace node */ 993 994 Node = Op->Asl.Node; 995 if (!Node) 996 { 997 return (AE_OK); 998 } 999 1000 /* Get the type to determine if we should push the scope */ 1001 1002 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) && 1003 (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC)) 1004 { 1005 ObjectType = ACPI_TYPE_LOCAL_RESOURCE; 1006 } 1007 else 1008 { 1009 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); 1010 } 1011 1012 /* Push scope for Resource Templates */ 1013 1014 if (Op->Asl.ParseOpcode == PARSEOP_NAME) 1015 { 1016 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC) 1017 { 1018 ForceNewScope = TRUE; 1019 } 1020 } 1021 1022 /* Push the scope stack */ 1023 1024 if (ForceNewScope || AcpiNsOpensScope (ObjectType)) 1025 { 1026 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState); 1027 if (ACPI_FAILURE (Status)) 1028 { 1029 return_ACPI_STATUS (Status); 1030 } 1031 } 1032 1033 if (Op->Asl.ParseOpcode == PARSEOP_ALIAS) 1034 { 1035 /* Complete the alias node by getting and saving the target node */ 1036 1037 /* First child is the alias target */ 1038 1039 Arg = Op->Asl.Child; 1040 1041 /* Get the target pathname */ 1042 1043 Path = Arg->Asl.Namepath; 1044 if (!Path) 1045 { 1046 Status = UtInternalizeName (Arg->Asl.ExternalName, &Path); 1047 if (ACPI_FAILURE (Status)) 1048 { 1049 return (Status); 1050 } 1051 } 1052 1053 /* Get the NS node associated with the target. It must exist. */ 1054 1055 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY, 1056 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, 1057 WalkState, &TargetNode); 1058 if (ACPI_FAILURE (Status)) 1059 { 1060 if (Status == AE_NOT_FOUND) 1061 { 1062 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op, 1063 Op->Asl.ExternalName); 1064 1065 /* 1066 * The name was not found, go ahead and create it. 1067 * This prevents more errors later. 1068 */ 1069 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, 1070 ACPI_TYPE_ANY, 1071 ACPI_IMODE_LOAD_PASS1, ACPI_NS_NO_UPSEARCH, 1072 WalkState, &(Node)); 1073 return (AE_OK); 1074 } 1075 1076 AslCoreSubsystemError (Op, Status, 1077 "Failure from namespace lookup", FALSE); 1078 return (AE_OK); 1079 } 1080 1081 /* Save the target node within the alias node */ 1082 1083 Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode); 1084 } 1085 1086 return (AE_OK); 1087 } 1088 1089 1090 /******************************************************************************* 1091 * 1092 * FUNCTION: LdCommonNamespaceEnd 1093 * 1094 * PARAMETERS: ASL_WALK_CALLBACK 1095 * 1096 * RETURN: Status 1097 * 1098 * DESCRIPTION: Ascending callback used during the loading of the namespace, 1099 * We only need to worry about managing the scope stack here. 1100 * 1101 ******************************************************************************/ 1102 1103 static ACPI_STATUS 1104 LdCommonNamespaceEnd ( 1105 ACPI_PARSE_OBJECT *Op, 1106 UINT32 Level, 1107 void *Context) 1108 { 1109 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; 1110 ACPI_OBJECT_TYPE ObjectType; 1111 BOOLEAN ForceNewScope = FALSE; 1112 1113 1114 ACPI_FUNCTION_NAME (LdCommonNamespaceEnd); 1115 1116 1117 /* We are only interested in opcodes that have an associated name */ 1118 1119 if (!Op->Asl.Namepath) 1120 { 1121 return (AE_OK); 1122 } 1123 1124 /* Get the type to determine if we should pop the scope */ 1125 1126 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) && 1127 (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC)) 1128 { 1129 /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */ 1130 1131 ObjectType = ACPI_TYPE_LOCAL_RESOURCE; 1132 } 1133 else 1134 { 1135 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); 1136 } 1137 1138 /* Pop scope that was pushed for Resource Templates */ 1139 1140 if (Op->Asl.ParseOpcode == PARSEOP_NAME) 1141 { 1142 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC) 1143 { 1144 ForceNewScope = TRUE; 1145 } 1146 } 1147 1148 /* Pop the scope stack */ 1149 1150 if (ForceNewScope || AcpiNsOpensScope (ObjectType)) 1151 { 1152 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 1153 "(%s): Popping scope for Op [%s] %p\n", 1154 AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op)); 1155 1156 (void) AcpiDsScopeStackPop (WalkState); 1157 } 1158 1159 return (AE_OK); 1160 } 1161