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