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 - 2018, 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 Node->OwnerId != WalkState->OwnerId) 321 { 322 Node->Type = (UINT8) ACPI_TYPE_LOCAL_REGION_FIELD; 323 } 324 else 325 { 326 /* 327 * The name already exists in this scope 328 * But continue processing the elements 329 */ 330 AslDualParseOpError (ASL_WARNING, ASL_MSG_EXTERN_COLLISION, Child, 331 Child->Asl.Value.String, ASL_MSG_EXTERN_FOUND_HERE, Node->Op, 332 Node->Op->Asl.ExternalName); 333 } 334 } 335 else 336 { 337 Child->Asl.Node = Node; 338 Node->Op = Child; 339 } 340 break; 341 } 342 343 Child = Child->Asl.Next; 344 } 345 346 return (AE_OK); 347 } 348 349 350 /******************************************************************************* 351 * 352 * FUNCTION: LdLoadResourceElements 353 * 354 * PARAMETERS: Op - Parent node (Resource Descriptor) 355 * WalkState - Current walk state 356 * 357 * RETURN: Status 358 * 359 * DESCRIPTION: Enter the named elements of the resource descriptor (children 360 * of the parent) into the namespace. 361 * 362 * NOTE: In the real AML namespace, these named elements never exist. But 363 * we simply use the namespace here as a symbol table so we can look 364 * them up as they are referenced. 365 * 366 ******************************************************************************/ 367 368 static ACPI_STATUS 369 LdLoadResourceElements ( 370 ACPI_PARSE_OBJECT *Op, 371 ACPI_WALK_STATE *WalkState) 372 { 373 ACPI_PARSE_OBJECT *InitializerOp = NULL; 374 ACPI_NAMESPACE_NODE *Node; 375 ACPI_STATUS Status; 376 377 378 /* 379 * Enter the resource name into the namespace. Name must not already exist. 380 * This opens a scope, so later field names are guaranteed to be new/unique. 381 */ 382 Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath, 383 ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1, 384 ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND, 385 WalkState, &Node); 386 if (ACPI_FAILURE (Status)) 387 { 388 if (Status == AE_ALREADY_EXISTS) 389 { 390 /* Actual node causing the error was saved in ParentMethod */ 391 392 AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, 393 (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod, 394 Op->Asl.Namepath, ASL_MSG_FOUND_HERE, Node->Op, 395 Node->Op->Asl.ExternalName); 396 return (AE_OK); 397 } 398 return (Status); 399 } 400 401 Node->Value = (UINT32) Op->Asl.Value.Integer; 402 Node->Op = Op; 403 Op->Asl.Node = Node; 404 405 /* 406 * Now enter the predefined fields, for easy lookup when referenced 407 * by the source ASL 408 */ 409 InitializerOp = ASL_GET_CHILD_NODE (Op); 410 while (InitializerOp) 411 { 412 if (InitializerOp->Asl.ExternalName) 413 { 414 Status = AcpiNsLookup (WalkState->ScopeInfo, 415 InitializerOp->Asl.ExternalName, 416 ACPI_TYPE_LOCAL_RESOURCE_FIELD, 417 ACPI_IMODE_LOAD_PASS1, 418 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, 419 NULL, &Node); 420 if (ACPI_FAILURE (Status)) 421 { 422 return (Status); 423 } 424 425 /* 426 * Store the field offset and length in the namespace node 427 * so it can be used when the field is referenced 428 */ 429 Node->Value = InitializerOp->Asl.Value.Tag.BitOffset; 430 Node->Length = InitializerOp->Asl.Value.Tag.BitLength; 431 InitializerOp->Asl.Node = Node; 432 Node->Op = InitializerOp; 433 } 434 435 InitializerOp = ASL_GET_PEER_NODE (InitializerOp); 436 } 437 438 return (AE_OK); 439 } 440 441 442 /******************************************************************************* 443 * 444 * FUNCTION: LdNamespace1Begin 445 * 446 * PARAMETERS: ASL_WALK_CALLBACK 447 * 448 * RETURN: Status 449 * 450 * DESCRIPTION: Descending callback used during the parse tree walk. If this 451 * is a named AML opcode, enter into the namespace 452 * 453 ******************************************************************************/ 454 455 static ACPI_STATUS 456 LdNamespace1Begin ( 457 ACPI_PARSE_OBJECT *Op, 458 UINT32 Level, 459 void *Context) 460 { 461 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; 462 ACPI_NAMESPACE_NODE *Node; 463 ACPI_PARSE_OBJECT *MethodOp; 464 ACPI_STATUS Status; 465 ACPI_OBJECT_TYPE ObjectType; 466 ACPI_OBJECT_TYPE ActualObjectType = ACPI_TYPE_ANY; 467 char *Path; 468 UINT32 Flags = ACPI_NS_NO_UPSEARCH; 469 ACPI_PARSE_OBJECT *Arg; 470 UINT32 i; 471 BOOLEAN ForceNewScope = FALSE; 472 ACPI_OWNER_ID OwnerId = 0; 473 474 475 ACPI_FUNCTION_NAME (LdNamespace1Begin); 476 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n", 477 Op, Op->Asl.ParseOpName)); 478 479 if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK) 480 { 481 /* 482 * Allocate an OwnerId for this block. This helps identify the owners 483 * of each namespace node. This is used in determining whether if 484 * certain external declarations cause redefinition errors. 485 */ 486 Status = AcpiUtAllocateOwnerId (&OwnerId); 487 WalkState->OwnerId = OwnerId; 488 if (ACPI_FAILURE (Status)) 489 { 490 AslCoreSubsystemError (Op, Status, 491 "Failure to allocate owner ID to this definition block.", FALSE); 492 return_ACPI_STATUS (Status); 493 } 494 } 495 496 /* 497 * We are only interested in opcodes that have an associated name 498 * (or multiple names) 499 */ 500 switch (Op->Asl.AmlOpcode) 501 { 502 case AML_BANK_FIELD_OP: 503 case AML_INDEX_FIELD_OP: 504 case AML_FIELD_OP: 505 506 Status = LdLoadFieldElements (Op, WalkState); 507 return (Status); 508 509 case AML_INT_CONNECTION_OP: 510 511 512 if (Op->Asl.Child->Asl.AmlOpcode != AML_INT_NAMEPATH_OP) 513 { 514 break; 515 } 516 Arg = Op->Asl.Child; 517 518 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Asl.ExternalName, 519 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, 520 WalkState, &Node); 521 if (ACPI_FAILURE (Status)) 522 { 523 break; 524 } 525 526 if (Node->Type == ACPI_TYPE_BUFFER) 527 { 528 Arg->Asl.Node = Node; 529 530 Arg = Node->Op->Asl.Child; /* Get namepath */ 531 Arg = Arg->Asl.Next; /* Get actual buffer */ 532 Arg = Arg->Asl.Child; /* Buffer length */ 533 Arg = Arg->Asl.Next; /* RAW_DATA buffer */ 534 } 535 break; 536 537 default: 538 539 /* All other opcodes go below */ 540 541 break; 542 } 543 544 /* Check if this object has already been installed in the namespace */ 545 546 if (Op->Asl.Node) 547 { 548 return (AE_OK); 549 } 550 551 Path = Op->Asl.Namepath; 552 if (!Path) 553 { 554 return (AE_OK); 555 } 556 557 /* Map the raw opcode into an internal object type */ 558 559 switch (Op->Asl.ParseOpcode) 560 { 561 case PARSEOP_NAME: 562 563 Arg = Op->Asl.Child; /* Get the NameSeg/NameString node */ 564 Arg = Arg->Asl.Next; /* First peer is the object to be associated with the name */ 565 566 /* 567 * If this name refers to a ResourceTemplate, we will need to open 568 * a new scope so that the resource subfield names can be entered into 569 * the namespace underneath this name 570 */ 571 if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC) 572 { 573 ForceNewScope = TRUE; 574 } 575 576 /* Get the data type associated with the named object, not the name itself */ 577 578 /* Log2 loop to convert from Btype (binary) to Etype (encoded) */ 579 580 ObjectType = 1; 581 for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2) 582 { 583 ObjectType++; 584 } 585 break; 586 587 588 case PARSEOP_EXTERNAL: 589 /* 590 * "External" simply enters a name and type into the namespace. 591 * We must be careful to not open a new scope, however, no matter 592 * what type the external name refers to (e.g., a method) 593 * 594 * first child is name, next child is ObjectType 595 */ 596 ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer; 597 ObjectType = ACPI_TYPE_ANY; 598 599 /* 600 * We will mark every new node along the path as "External". This 601 * allows some or all of the nodes to be created later in the ASL 602 * code. Handles cases like this: 603 * 604 * External (\_SB_.PCI0.ABCD, IntObj) 605 * Scope (_SB_) 606 * { 607 * Device (PCI0) 608 * { 609 * } 610 * } 611 * Method (X) 612 * { 613 * Store (\_SB_.PCI0.ABCD, Local0) 614 * } 615 */ 616 Flags |= ACPI_NS_EXTERNAL; 617 break; 618 619 case PARSEOP_DEFAULT_ARG: 620 621 if (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC) 622 { 623 Status = LdLoadResourceElements (Op, WalkState); 624 return_ACPI_STATUS (Status); 625 } 626 627 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); 628 break; 629 630 case PARSEOP_SCOPE: 631 /* 632 * The name referenced by Scope(Name) must already exist at this point. 633 * In other words, forward references for Scope() are not supported. 634 * The only real reason for this is that the MS interpreter cannot 635 * handle this case. Perhaps someday this case can go away. 636 */ 637 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY, 638 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, 639 WalkState, &(Node)); 640 if (ACPI_FAILURE (Status)) 641 { 642 if (Status == AE_NOT_FOUND) 643 { 644 /* The name was not found, go ahead and create it */ 645 646 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, 647 ACPI_TYPE_LOCAL_SCOPE, 648 ACPI_IMODE_LOAD_PASS1, Flags, 649 WalkState, &(Node)); 650 if (ACPI_FAILURE (Status)) 651 { 652 return_ACPI_STATUS (Status); 653 } 654 655 /* 656 * However, this is an error -- primarily because the MS 657 * interpreter can't handle a forward reference from the 658 * Scope() operator. 659 */ 660 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op, 661 Op->Asl.ExternalName); 662 AslError (ASL_ERROR, ASL_MSG_SCOPE_FWD_REF, Op, 663 Op->Asl.ExternalName); 664 goto FinishNode; 665 } 666 667 AslCoreSubsystemError (Op, Status, 668 "Failure from namespace lookup", FALSE); 669 670 return_ACPI_STATUS (Status); 671 } 672 else /* Status AE_OK */ 673 { 674 /* 675 * Do not allow references to external scopes from the DSDT. 676 * This is because the DSDT is always loaded first, and the 677 * external reference cannot be resolved -- causing a runtime 678 * error because Scope() must be resolved immediately. 679 * 10/2015. 680 */ 681 if ((Node->Flags & ANOBJ_IS_EXTERNAL) && 682 (ACPI_COMPARE_NAME (Gbl_TableSignature, "DSDT"))) 683 { 684 /* However, allowed if the reference is within a method */ 685 686 MethodOp = Op->Asl.Parent; 687 while (MethodOp && 688 (MethodOp->Asl.ParseOpcode != PARSEOP_METHOD)) 689 { 690 MethodOp = MethodOp->Asl.Parent; 691 } 692 693 if (!MethodOp) 694 { 695 /* Not in a control method, error */ 696 697 AslError (ASL_ERROR, ASL_MSG_CROSS_TABLE_SCOPE, Op, NULL); 698 } 699 } 700 } 701 702 /* We found a node with this name, now check the type */ 703 704 switch (Node->Type) 705 { 706 case ACPI_TYPE_LOCAL_SCOPE: 707 case ACPI_TYPE_DEVICE: 708 case ACPI_TYPE_POWER: 709 case ACPI_TYPE_PROCESSOR: 710 case ACPI_TYPE_THERMAL: 711 712 /* These are acceptable types - they all open a new scope */ 713 break; 714 715 case ACPI_TYPE_INTEGER: 716 case ACPI_TYPE_STRING: 717 case ACPI_TYPE_BUFFER: 718 /* 719 * These types we will allow, but we will change the type. 720 * This enables some existing code of the form: 721 * 722 * Name (DEB, 0) 723 * Scope (DEB) { ... } 724 * 725 * Which is used to workaround the fact that the MS interpreter 726 * does not allow Scope() forward references. 727 */ 728 sprintf (MsgBuffer, "%s [%s], changing type to [Scope]", 729 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type)); 730 AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer); 731 732 /* Switch the type to scope, open the new scope */ 733 734 Node->Type = ACPI_TYPE_LOCAL_SCOPE; 735 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE, 736 WalkState); 737 if (ACPI_FAILURE (Status)) 738 { 739 return_ACPI_STATUS (Status); 740 } 741 break; 742 743 default: 744 745 /* All other types are an error */ 746 747 sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName, 748 AcpiUtGetTypeName (Node->Type)); 749 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer); 750 751 /* 752 * However, switch the type to be an actual scope so 753 * that compilation can continue without generating a whole 754 * cascade of additional errors. Open the new scope. 755 */ 756 Node->Type = ACPI_TYPE_LOCAL_SCOPE; 757 Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE, 758 WalkState); 759 if (ACPI_FAILURE (Status)) 760 { 761 return_ACPI_STATUS (Status); 762 } 763 break; 764 } 765 766 Status = AE_OK; 767 goto FinishNode; 768 769 770 default: 771 772 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); 773 break; 774 } 775 776 777 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n", 778 Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType))); 779 780 /* The name must not already exist */ 781 782 Flags |= ACPI_NS_ERROR_IF_FOUND; 783 784 /* 785 * Enter the named type into the internal namespace. We enter the name 786 * as we go downward in the parse tree. Any necessary subobjects that 787 * involve arguments to the opcode must be created as we go back up the 788 * parse tree later. 789 */ 790 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType, 791 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node); 792 if (ACPI_FAILURE (Status)) 793 { 794 if (Status == AE_ALREADY_EXISTS) 795 { 796 /* The name already exists in this scope */ 797 798 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE) 799 { 800 /* Allow multiple references to the same scope */ 801 802 Node->Type = (UINT8) ObjectType; 803 Status = AE_OK; 804 } 805 else if ((Node->Flags & ANOBJ_IS_EXTERNAL) && 806 (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL)) 807 { 808 /* 809 * Allow one create on an object or segment that was 810 * previously declared External only if WalkState->OwnerId and 811 * Node->OwnerId are different (meaning that the current WalkState 812 * and the Node are in different tables). 813 */ 814 Node->Flags &= ~ANOBJ_IS_EXTERNAL; 815 Node->Type = (UINT8) ObjectType; 816 817 /* Just retyped a node, probably will need to open a scope */ 818 819 if (AcpiNsOpensScope (ObjectType)) 820 { 821 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState); 822 if (ACPI_FAILURE (Status)) 823 { 824 return_ACPI_STATUS (Status); 825 } 826 } 827 828 Status = AE_OK; 829 830 if (Node->OwnerId == WalkState->OwnerId && 831 !(Node->Flags & IMPLICIT_EXTERNAL)) 832 { 833 AslDualParseOpError (ASL_WARNING, ASL_MSG_EXTERN_COLLISION, Op, 834 Op->Asl.ExternalName, ASL_MSG_EXTERN_FOUND_HERE, Node->Op, 835 Node->Op->Asl.ExternalName); 836 } 837 if (Node->Flags & IMPLICIT_EXTERNAL) 838 { 839 Node->Flags &= ~IMPLICIT_EXTERNAL; 840 } 841 } 842 else if (!(Node->Flags & ANOBJ_IS_EXTERNAL) && 843 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)) 844 { 845 /* 846 * Allow externals in same scope as the definition of the 847 * actual object. Similar to C. Allows multiple definition 848 * blocks that refer to each other in the same file. However, 849 * do not allow name declaration and an external declaration 850 * within the same table. This is considered a re-declaration. 851 */ 852 Status = AE_OK; 853 854 if (Node->OwnerId == WalkState->OwnerId) 855 { 856 AslDualParseOpError (ASL_WARNING, ASL_MSG_EXTERN_COLLISION, Op, 857 Op->Asl.ExternalName, ASL_MSG_EXTERN_FOUND_HERE, Node->Op, 858 Node->Op->Asl.ExternalName); 859 } 860 } 861 else if ((Node->Flags & ANOBJ_IS_EXTERNAL) && 862 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) && 863 (ObjectType == ACPI_TYPE_ANY)) 864 { 865 /* 866 * Allow update of externals of unknown type. 867 * In the case that multiple definition blocks are being 868 * parsed, updating the OwnerId allows enables subsequent calls 869 * of this method to understand which table the most recent 870 * external declaration was seen. Without this OwnerId update, 871 * code like the following is allowed to compile: 872 * 873 * DefinitionBlock("externtest.aml", "DSDT", 0x02, "Intel", "Many", 0x00000001) 874 * { 875 * External(ERRS,methodobj) 876 * Method (MAIN) 877 * { 878 * Name(NUM2, 0) 879 * ERRS(1,2,3) 880 * } 881 * } 882 * 883 * DefinitionBlock("externtest.aml", "SSDT", 0x02, "Intel", "Many", 0x00000001) 884 * { 885 * if (0) 886 * { 887 * External(ERRS,methodobj) 888 * } 889 * Method (ERRS,3) 890 * {} 891 * 892 * } 893 */ 894 Node->OwnerId = WalkState->OwnerId; 895 896 if (AcpiNsOpensScope (ActualObjectType)) 897 { 898 Node->Type = (UINT8) ActualObjectType; 899 Status = AE_OK; 900 } 901 else 902 { 903 sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName, 904 AcpiUtGetTypeName (Node->Type)); 905 AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer); 906 return_ACPI_STATUS (AE_OK); 907 } 908 } 909 else 910 { 911 /* Valid error, object already exists */ 912 913 AslDualParseOpError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op, 914 Op->Asl.ExternalName, ASL_MSG_FOUND_HERE, Node->Op, 915 Node->Op->Asl.ExternalName); 916 return_ACPI_STATUS (AE_OK); 917 } 918 } 919 else 920 { 921 AslCoreSubsystemError (Op, Status, 922 "Failure from namespace lookup", FALSE); 923 return_ACPI_STATUS (Status); 924 } 925 } 926 927 if (ForceNewScope) 928 { 929 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState); 930 if (ACPI_FAILURE (Status)) 931 { 932 return_ACPI_STATUS (Status); 933 } 934 } 935 936 FinishNode: 937 /* 938 * Point the parse node to the new namespace node, and point 939 * the Node back to the original Parse node 940 */ 941 Op->Asl.Node = Node; 942 Node->Op = Op; 943 944 /* Set the actual data type if appropriate (EXTERNAL term only) */ 945 946 if (ActualObjectType != ACPI_TYPE_ANY) 947 { 948 Node->Type = (UINT8) ActualObjectType; 949 Node->Value = ASL_EXTERNAL_METHOD; 950 } 951 952 if (Op->Asl.ParseOpcode == PARSEOP_METHOD) 953 { 954 /* 955 * Get the method argument count from "Extra" and save 956 * it in the namespace node 957 */ 958 Node->Value = (UINT32) Op->Asl.Extra; 959 } 960 961 return_ACPI_STATUS (Status); 962 } 963 964 965 /******************************************************************************* 966 * 967 * FUNCTION: LdNamespace2Begin 968 * 969 * PARAMETERS: ASL_WALK_CALLBACK 970 * 971 * RETURN: Status 972 * 973 * DESCRIPTION: Descending callback used during the pass 2 parse tree walk. 974 * Second pass resolves some forward references. 975 * 976 * Notes: 977 * Currently only needs to handle the Alias operator. 978 * Could be used to allow forward references from the Scope() operator, but 979 * the MS interpreter does not allow this, so this compiler does not either. 980 * 981 ******************************************************************************/ 982 983 static ACPI_STATUS 984 LdNamespace2Begin ( 985 ACPI_PARSE_OBJECT *Op, 986 UINT32 Level, 987 void *Context) 988 { 989 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; 990 ACPI_STATUS Status; 991 ACPI_NAMESPACE_NODE *Node; 992 ACPI_OBJECT_TYPE ObjectType; 993 BOOLEAN ForceNewScope = FALSE; 994 ACPI_PARSE_OBJECT *Arg; 995 char *Path; 996 ACPI_NAMESPACE_NODE *TargetNode; 997 998 999 ACPI_FUNCTION_NAME (LdNamespace2Begin); 1000 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n", 1001 Op, Op->Asl.ParseOpName)); 1002 1003 1004 /* Ignore Ops with no namespace node */ 1005 1006 Node = Op->Asl.Node; 1007 if (!Node) 1008 { 1009 return (AE_OK); 1010 } 1011 1012 /* Get the type to determine if we should push the scope */ 1013 1014 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) && 1015 (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC)) 1016 { 1017 ObjectType = ACPI_TYPE_LOCAL_RESOURCE; 1018 } 1019 else 1020 { 1021 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); 1022 } 1023 1024 /* Push scope for Resource Templates */ 1025 1026 if (Op->Asl.ParseOpcode == PARSEOP_NAME) 1027 { 1028 if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC) 1029 { 1030 ForceNewScope = TRUE; 1031 } 1032 } 1033 1034 /* Push the scope stack */ 1035 1036 if (ForceNewScope || AcpiNsOpensScope (ObjectType)) 1037 { 1038 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState); 1039 if (ACPI_FAILURE (Status)) 1040 { 1041 return_ACPI_STATUS (Status); 1042 } 1043 } 1044 1045 if (Op->Asl.ParseOpcode == PARSEOP_ALIAS) 1046 { 1047 /* Complete the alias node by getting and saving the target node */ 1048 1049 /* First child is the alias target */ 1050 1051 Arg = Op->Asl.Child; 1052 1053 /* Get the target pathname */ 1054 1055 Path = Arg->Asl.Namepath; 1056 if (!Path) 1057 { 1058 Status = UtInternalizeName (Arg->Asl.ExternalName, &Path); 1059 if (ACPI_FAILURE (Status)) 1060 { 1061 return (Status); 1062 } 1063 } 1064 1065 /* Get the NS node associated with the target. It must exist. */ 1066 1067 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY, 1068 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, 1069 WalkState, &TargetNode); 1070 if (ACPI_FAILURE (Status)) 1071 { 1072 if (Status == AE_NOT_FOUND) 1073 { 1074 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op, 1075 Op->Asl.ExternalName); 1076 1077 /* 1078 * The name was not found, go ahead and create it. 1079 * This prevents more errors later. 1080 */ 1081 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, 1082 ACPI_TYPE_ANY, 1083 ACPI_IMODE_LOAD_PASS1, ACPI_NS_NO_UPSEARCH, 1084 WalkState, &(Node)); 1085 return (AE_OK); 1086 } 1087 1088 AslCoreSubsystemError (Op, Status, 1089 "Failure from namespace lookup", FALSE); 1090 return (AE_OK); 1091 } 1092 1093 /* Save the target node within the alias node */ 1094 1095 Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode); 1096 } 1097 1098 return (AE_OK); 1099 } 1100 1101 1102 /******************************************************************************* 1103 * 1104 * FUNCTION: LdCommonNamespaceEnd 1105 * 1106 * PARAMETERS: ASL_WALK_CALLBACK 1107 * 1108 * RETURN: Status 1109 * 1110 * DESCRIPTION: Ascending callback used during the loading of the namespace, 1111 * We only need to worry about managing the scope stack here. 1112 * 1113 ******************************************************************************/ 1114 1115 static ACPI_STATUS 1116 LdCommonNamespaceEnd ( 1117 ACPI_PARSE_OBJECT *Op, 1118 UINT32 Level, 1119 void *Context) 1120 { 1121 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; 1122 ACPI_OBJECT_TYPE ObjectType; 1123 BOOLEAN ForceNewScope = FALSE; 1124 1125 1126 ACPI_FUNCTION_NAME (LdCommonNamespaceEnd); 1127 1128 1129 /* We are only interested in opcodes that have an associated name */ 1130 1131 if (!Op->Asl.Namepath) 1132 { 1133 return (AE_OK); 1134 } 1135 1136 /* Get the type to determine if we should pop the scope */ 1137 1138 if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) && 1139 (Op->Asl.CompileFlags == OP_IS_RESOURCE_DESC)) 1140 { 1141 /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */ 1142 1143 ObjectType = ACPI_TYPE_LOCAL_RESOURCE; 1144 } 1145 else 1146 { 1147 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); 1148 } 1149 1150 /* Pop scope that was pushed for Resource Templates */ 1151 1152 if (Op->Asl.ParseOpcode == PARSEOP_NAME) 1153 { 1154 if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC) 1155 { 1156 ForceNewScope = TRUE; 1157 } 1158 } 1159 1160 /* Pop the scope stack */ 1161 1162 if (ForceNewScope || AcpiNsOpensScope (ObjectType)) 1163 { 1164 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 1165 "(%s): Popping scope for Op [%s] %p\n", 1166 AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op)); 1167 1168 (void) AcpiDsScopeStackPop (WalkState); 1169 } 1170 1171 return (AE_OK); 1172 } 1173