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