1 /****************************************************************************** 2 * 3 * Module Name: aslxref - Namespace cross-reference 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2020, 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 "aslcompiler.y.h" 154 #include <contrib/dev/acpica/include/acparser.h> 155 #include <contrib/dev/acpica/include/amlcode.h> 156 #include <contrib/dev/acpica/include/acnamesp.h> 157 #include <contrib/dev/acpica/include/acdispat.h> 158 159 160 #define _COMPONENT ACPI_COMPILER 161 ACPI_MODULE_NAME ("aslxref") 162 163 /* Local prototypes */ 164 165 static ACPI_STATUS 166 XfNamespaceLocateBegin ( 167 ACPI_PARSE_OBJECT *Op, 168 UINT32 Level, 169 void *Context); 170 171 static ACPI_STATUS 172 XfNamespaceLocateEnd ( 173 ACPI_PARSE_OBJECT *Op, 174 UINT32 Level, 175 void *Context); 176 177 static BOOLEAN 178 XfValidateCrossReference ( 179 ACPI_PARSE_OBJECT *Op, 180 const ACPI_OPCODE_INFO *OpInfo, 181 ACPI_NAMESPACE_NODE *Node); 182 183 static ACPI_PARSE_OBJECT * 184 XfGetParentMethod ( 185 ACPI_PARSE_OBJECT *Op); 186 187 static BOOLEAN 188 XfObjectExists ( 189 char *Name); 190 191 static ACPI_STATUS 192 XfCompareOneNamespaceObject ( 193 ACPI_HANDLE ObjHandle, 194 UINT32 Level, 195 void *Context, 196 void **ReturnValue); 197 198 static void 199 XfCheckFieldRange ( 200 ACPI_PARSE_OBJECT *Op, 201 UINT32 RegionBitLength, 202 UINT32 FieldBitOffset, 203 UINT32 FieldBitLength, 204 UINT32 AccessBitWidth); 205 206 207 /******************************************************************************* 208 * 209 * FUNCTION: XfCrossReferenceNamespace 210 * 211 * PARAMETERS: None 212 * 213 * RETURN: Status 214 * 215 * DESCRIPTION: Perform a cross reference check of the parse tree against the 216 * namespace. Every named referenced within the parse tree 217 * should be get resolved with a namespace lookup. If not, the 218 * original reference in the ASL code is invalid -- i.e., refers 219 * to a non-existent object. 220 * 221 * NOTE: The ASL "External" operator causes the name to be inserted into the 222 * namespace so that references to the external name will be resolved 223 * correctly here. 224 * 225 ******************************************************************************/ 226 227 ACPI_STATUS 228 XfCrossReferenceNamespace ( 229 void) 230 { 231 ACPI_WALK_STATE *WalkState; 232 233 234 /* 235 * Create a new walk state for use when looking up names 236 * within the namespace (Passed as context to the callbacks) 237 */ 238 WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL); 239 if (!WalkState) 240 { 241 return (AE_NO_MEMORY); 242 } 243 244 /* Walk the entire parse tree */ 245 246 TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE, 247 XfNamespaceLocateBegin, XfNamespaceLocateEnd, WalkState); 248 249 ACPI_FREE (WalkState); 250 return (AE_OK); 251 } 252 253 254 /******************************************************************************* 255 * 256 * FUNCTION: XfObjectExists 257 * 258 * PARAMETERS: Name - 4 char ACPI name 259 * 260 * RETURN: TRUE if name exists in namespace 261 * 262 * DESCRIPTION: Walk the namespace to find an object 263 * 264 ******************************************************************************/ 265 266 static BOOLEAN 267 XfObjectExists ( 268 char *Name) 269 { 270 ACPI_STATUS Status; 271 272 273 /* Walk entire namespace from the supplied root */ 274 275 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 276 ACPI_UINT32_MAX, FALSE, XfCompareOneNamespaceObject, NULL, 277 Name, NULL); 278 if (Status == AE_CTRL_TRUE) 279 { 280 /* At least one instance of the name was found */ 281 282 return (TRUE); 283 } 284 285 return (FALSE); 286 } 287 288 289 /******************************************************************************* 290 * 291 * FUNCTION: XfCompareOneNamespaceObject 292 * 293 * PARAMETERS: ACPI_WALK_CALLBACK 294 * 295 * RETURN: Status 296 * 297 * DESCRIPTION: Compare name of one object. 298 * 299 ******************************************************************************/ 300 301 static ACPI_STATUS 302 XfCompareOneNamespaceObject ( 303 ACPI_HANDLE ObjHandle, 304 UINT32 Level, 305 void *Context, 306 void **ReturnValue) 307 { 308 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle; 309 310 311 /* Simply check the name */ 312 313 if (*((UINT32 *) (Context)) == Node->Name.Integer) 314 { 315 /* Abort walk if we found one instance */ 316 317 return (AE_CTRL_TRUE); 318 } 319 320 return (AE_OK); 321 } 322 323 324 /******************************************************************************* 325 * 326 * FUNCTION: XfCheckFieldRange 327 * 328 * PARAMETERS: RegionBitLength - Length of entire parent region 329 * FieldBitOffset - Start of the field unit (within region) 330 * FieldBitLength - Entire length of field unit 331 * AccessBitWidth - Access width of the field unit 332 * 333 * RETURN: None 334 * 335 * DESCRIPTION: Check one field unit to make sure it fits in the parent 336 * op region. 337 * 338 * Note: AccessBitWidth must be either 8,16,32, or 64 339 * 340 ******************************************************************************/ 341 342 static void 343 XfCheckFieldRange ( 344 ACPI_PARSE_OBJECT *Op, 345 UINT32 RegionBitLength, 346 UINT32 FieldBitOffset, 347 UINT32 FieldBitLength, 348 UINT32 AccessBitWidth) 349 { 350 UINT32 FieldEndBitOffset; 351 352 353 /* 354 * Check each field unit against the region size. The entire 355 * field unit (start offset plus length) must fit within the 356 * region. 357 */ 358 FieldEndBitOffset = FieldBitOffset + FieldBitLength; 359 360 if (FieldEndBitOffset > RegionBitLength) 361 { 362 /* Field definition itself is beyond the end-of-region */ 363 364 AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_OFFSET, Op, NULL); 365 return; 366 } 367 368 /* 369 * Now check that the field plus AccessWidth doesn't go beyond 370 * the end-of-region. Assumes AccessBitWidth is a power of 2 371 */ 372 FieldEndBitOffset = ACPI_ROUND_UP (FieldEndBitOffset, AccessBitWidth); 373 374 if (FieldEndBitOffset > RegionBitLength) 375 { 376 /* Field definition combined with the access is beyond EOR */ 377 378 AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, Op, NULL); 379 } 380 } 381 382 383 /******************************************************************************* 384 * 385 * FUNCTION: XfGetParentMethod 386 * 387 * PARAMETERS: Op - Parse Op to be checked 388 * 389 * RETURN: Control method Op if found. NULL otherwise 390 * 391 * DESCRIPTION: Find the control method parent of a parse op. Returns NULL if 392 * the input Op is not within a control method. 393 * 394 ******************************************************************************/ 395 396 static ACPI_PARSE_OBJECT * 397 XfGetParentMethod ( 398 ACPI_PARSE_OBJECT *Op) 399 { 400 ACPI_PARSE_OBJECT *NextOp; 401 402 403 NextOp = Op->Asl.Parent; 404 while (NextOp) 405 { 406 if (NextOp->Asl.AmlOpcode == AML_METHOD_OP) 407 { 408 return (NextOp); 409 } 410 411 NextOp = NextOp->Asl.Parent; 412 } 413 414 return (NULL); /* No parent method found */ 415 } 416 417 418 /******************************************************************************* 419 * 420 * FUNCTION: XfNamespaceLocateBegin 421 * 422 * PARAMETERS: ASL_WALK_CALLBACK 423 * 424 * RETURN: Status 425 * 426 * DESCRIPTION: Descending callback used during cross-reference. For named 427 * object references, attempt to locate the name in the 428 * namespace. 429 * 430 * NOTE: ASL references to named fields within resource descriptors are 431 * resolved to integer values here. Therefore, this step is an 432 * important part of the code generation. We don't know that the 433 * name refers to a resource descriptor until now. 434 * 435 ******************************************************************************/ 436 437 static ACPI_STATUS 438 XfNamespaceLocateBegin ( 439 ACPI_PARSE_OBJECT *Op, 440 UINT32 Level, 441 void *Context) 442 { 443 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; 444 ACPI_NAMESPACE_NODE *Node; 445 ACPI_STATUS Status; 446 ACPI_OBJECT_TYPE ObjectType; 447 char *Path; 448 UINT8 PassedArgs; 449 ACPI_PARSE_OBJECT *NextOp; 450 ACPI_PARSE_OBJECT *OwningOp; 451 ACPI_PARSE_OBJECT *SpaceIdOp; 452 UINT32 MinimumLength; 453 UINT32 Offset; 454 UINT32 FieldBitLength; 455 UINT32 TagBitLength; 456 UINT8 Message = 0; 457 const ACPI_OPCODE_INFO *OpInfo; 458 UINT32 Flags; 459 ASL_METHOD_LOCAL *MethodLocals = NULL; 460 ASL_METHOD_LOCAL *MethodArgs = NULL; 461 int RegisterNumber; 462 UINT32 i; 463 ACPI_NAMESPACE_NODE *DeclarationParentMethod; 464 ACPI_PARSE_OBJECT *ReferenceParentMethod; 465 466 467 ACPI_FUNCTION_TRACE_PTR (XfNamespaceLocateBegin, Op); 468 469 470 if ((Op->Asl.AmlOpcode == AML_METHOD_OP) && Op->Asl.Node) 471 { 472 Node = Op->Asl.Node; 473 474 /* Support for method LocalX/ArgX analysis */ 475 476 if (!Node->MethodLocals) 477 { 478 /* Create local/arg info blocks */ 479 480 MethodLocals = UtLocalCalloc ( 481 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_LOCALS); 482 Node->MethodLocals = MethodLocals; 483 484 MethodArgs = UtLocalCalloc ( 485 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_ARGS); 486 Node->MethodArgs = MethodArgs; 487 488 /* 489 * Get the method argument count 490 * First, get the name node 491 */ 492 NextOp = Op->Asl.Child; 493 494 /* Get the NumArguments node */ 495 496 NextOp = NextOp->Asl.Next; 497 Node->ArgCount = (UINT8) 498 (((UINT8) NextOp->Asl.Value.Integer) & 0x07); 499 500 /* We will track all possible ArgXs */ 501 502 for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) 503 { 504 if (i < Node->ArgCount) 505 { 506 /* Real Args are always "initialized" */ 507 508 MethodArgs[i].Flags = ASL_ARG_INITIALIZED; 509 } 510 else 511 { 512 /* Other ArgXs can be used as locals */ 513 514 MethodArgs[i].Flags = ASL_ARG_IS_LOCAL; 515 } 516 517 MethodArgs[i].Op = Op; 518 } 519 } 520 } 521 522 /* 523 * If this node is the actual declaration of a name 524 * [such as the XXXX name in "Method (XXXX)"], 525 * we are not interested in it here. We only care about names that are 526 * references to other objects within the namespace and the parent objects 527 * of name declarations 528 */ 529 if (Op->Asl.CompileFlags & OP_IS_NAME_DECLARATION) 530 { 531 return_ACPI_STATUS (AE_OK); 532 } 533 534 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); 535 536 /* Check method LocalX variables */ 537 538 if (OpInfo->Type == AML_TYPE_LOCAL_VARIABLE) 539 { 540 /* Find parent method Op */ 541 542 NextOp = XfGetParentMethod (Op); 543 if (!NextOp) 544 { 545 return_ACPI_STATUS (AE_OK); 546 } 547 548 /* Get method node */ 549 550 Node = NextOp->Asl.Node; 551 552 RegisterNumber = Op->Asl.AmlOpcode & 0x0007; /* 0x60 through 0x67 */ 553 MethodLocals = Node->MethodLocals; 554 555 if (Op->Asl.CompileFlags & OP_IS_TARGET) 556 { 557 /* Local is being initialized */ 558 559 MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_INITIALIZED; 560 MethodLocals[RegisterNumber].Op = Op; 561 562 return_ACPI_STATUS (AE_OK); 563 } 564 565 /* Mark this Local as referenced */ 566 567 MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_REFERENCED; 568 MethodLocals[RegisterNumber].Op = Op; 569 570 return_ACPI_STATUS (AE_OK); 571 } 572 573 /* Check method ArgX variables */ 574 575 if (OpInfo->Type == AML_TYPE_METHOD_ARGUMENT) 576 { 577 /* Find parent method Op */ 578 579 NextOp = XfGetParentMethod (Op); 580 if (!NextOp) 581 { 582 return_ACPI_STATUS (AE_OK); 583 } 584 585 /* Get method node */ 586 587 Node = NextOp->Asl.Node; 588 589 /* Get Arg # */ 590 591 RegisterNumber = Op->Asl.AmlOpcode - AML_ARG0; /* 0x68 through 0x6F */ 592 MethodArgs = Node->MethodArgs; 593 594 /* Mark this Arg as referenced */ 595 596 MethodArgs[RegisterNumber].Flags |= ASL_ARG_REFERENCED; 597 MethodArgs[RegisterNumber].Op = Op; 598 599 if (Op->Asl.CompileFlags & OP_IS_TARGET) 600 { 601 /* Arg is being initialized */ 602 603 MethodArgs[RegisterNumber].Flags |= ASL_ARG_INITIALIZED; 604 } 605 606 return_ACPI_STATUS (AE_OK); 607 } 608 609 /* 610 * After method ArgX and LocalX, we are only interested in opcodes 611 * that have an associated name 612 */ 613 if ((!(OpInfo->Flags & AML_NAMED)) && 614 (!(OpInfo->Flags & AML_CREATE)) && 615 (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) && 616 (Op->Asl.ParseOpcode != PARSEOP_NAMESEG) && 617 (Op->Asl.ParseOpcode != PARSEOP_METHODCALL) && 618 (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL)) 619 { 620 return_ACPI_STATUS (AE_OK); 621 } 622 623 /* 624 * One special case: CondRefOf operator - we don't care if the name exists 625 * or not at this point, just ignore it, the point of the operator is to 626 * determine if the name exists at runtime. 627 */ 628 if ((Op->Asl.Parent) && 629 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)) 630 { 631 return_ACPI_STATUS (AE_OK); 632 } 633 634 /* 635 * We must enable the "search-to-root" for single NameSegs, but 636 * we have to be very careful about opening up scopes 637 */ 638 Flags = ACPI_NS_SEARCH_PARENT; 639 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || 640 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || 641 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) || 642 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)) 643 { 644 /* 645 * These are name references, do not push the scope stack 646 * for them. 647 */ 648 Flags |= ACPI_NS_DONT_OPEN_SCOPE; 649 } 650 651 /* Get the NamePath from the appropriate place */ 652 653 if (OpInfo->Flags & AML_NAMED) 654 { 655 /* For nearly all NAMED operators, the name reference is the first child */ 656 657 Path = Op->Asl.Child->Asl.Value.String; 658 if (Op->Asl.AmlOpcode == AML_ALIAS_OP) 659 { 660 /* 661 * ALIAS is the only oddball opcode, the name declaration 662 * (alias name) is the second operand 663 */ 664 Path = Op->Asl.Child->Asl.Next->Asl.Value.String; 665 } 666 } 667 else if (OpInfo->Flags & AML_CREATE) 668 { 669 /* Name must appear as the last parameter */ 670 671 NextOp = Op->Asl.Child; 672 while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION)) 673 { 674 NextOp = NextOp->Asl.Next; 675 } 676 677 Path = NextOp->Asl.Value.String; 678 } 679 else 680 { 681 Path = Op->Asl.Value.String; 682 } 683 684 ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); 685 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 686 "Type=%s\n", AcpiUtGetTypeName (ObjectType))); 687 688 /* 689 * Lookup the name in the namespace. Name must exist at this point, or it 690 * is an invalid reference. 691 * 692 * The namespace is also used as a lookup table for references to resource 693 * descriptors and the fields within them. 694 */ 695 AslGbl_NsLookupCount++; 696 697 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType, 698 ACPI_IMODE_EXECUTE, Flags, WalkState, &Node); 699 if (ACPI_FAILURE (Status)) 700 { 701 if (Status == AE_NOT_FOUND) 702 { 703 /* 704 * We didn't find the name reference by path -- we can qualify this 705 * a little better before we print an error message 706 */ 707 if (strlen (Path) == ACPI_NAMESEG_SIZE) 708 { 709 /* A simple, one-segment ACPI name */ 710 711 if (XfObjectExists (Path)) 712 { 713 /* 714 * There exists such a name, but we couldn't get to it 715 * from this scope 716 */ 717 AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op, 718 Op->Asl.ExternalName); 719 } 720 else 721 { 722 /* The name doesn't exist, period */ 723 724 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, 725 Op, Op->Asl.ExternalName); 726 } 727 } 728 else 729 { 730 /* The NamePath contains multiple NameSegs */ 731 732 if ((OpInfo->Flags & AML_CREATE) || 733 (OpInfo->ObjectType == ACPI_TYPE_LOCAL_ALIAS)) 734 { 735 /* 736 * The new name is the last parameter. For the 737 * CreateXXXXField and Alias operators 738 */ 739 NextOp = Op->Asl.Child; 740 while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION)) 741 { 742 NextOp = NextOp->Asl.Next; 743 } 744 745 AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, NextOp, 746 NextOp->Asl.ExternalName); 747 } 748 else if (OpInfo->Flags & AML_NAMED) 749 { 750 /* The new name is the first parameter */ 751 752 AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, Op, 753 Op->Asl.ExternalName); 754 } 755 else if (Path[0] == AML_ROOT_PREFIX) 756 { 757 /* Full namepath from root, the object does not exist */ 758 759 AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op, 760 Op->Asl.ExternalName); 761 } 762 else 763 { 764 /* 765 * Generic "not found" error. Cannot determine whether it 766 * doesn't exist or just can't be reached. However, we 767 * can differentiate between a NameSeg vs. NamePath. 768 */ 769 if (strlen (Op->Asl.ExternalName) == ACPI_NAMESEG_SIZE) 770 { 771 AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op, 772 Op->Asl.ExternalName); 773 } 774 else 775 { 776 AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op, 777 Op->Asl.ExternalName); 778 } 779 } 780 } 781 782 Status = AE_OK; 783 } 784 785 return_ACPI_STATUS (Status); 786 } 787 788 /* Check for an attempt to access an object in another method */ 789 790 if (!XfValidateCrossReference (Op, OpInfo, Node)) 791 { 792 AslError (ASL_ERROR, ASL_MSG_TEMPORARY_OBJECT, Op, 793 Op->Asl.ExternalName); 794 return_ACPI_STATUS (Status); 795 } 796 797 /* Object was found above, check for an illegal forward reference */ 798 799 if (Op->Asl.CompileFlags & OP_NOT_FOUND_DURING_LOAD) 800 { 801 /* 802 * During the load phase, this Op was flagged as a possible 803 * illegal forward reference. In other words, Op is a name path or 804 * name segment that refers to a named object declared after the 805 * reference. In this scinario, Node refers to the actual declaration 806 * and Op is a parse node that references the named object. 807 * 808 * Note: 809 * 810 * Object references inside of control methods are allowed to 811 * refer to objects declared outside of control methods. 812 * 813 * If the declaration and reference are both contained inside of the 814 * same method or outside of any method, this is a forward reference 815 * and should be reported as a compiler error. 816 */ 817 DeclarationParentMethod = UtGetParentMethod (Node); 818 ReferenceParentMethod = XfGetParentMethod (Op); 819 820 /* case 1: declaration and refrence are both outside of method */ 821 822 if (!ReferenceParentMethod && !DeclarationParentMethod) 823 { 824 AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op, 825 Op->Asl.ExternalName); 826 } 827 828 /* case 2: declaration and reference are both inside of the same method */ 829 830 else if (ReferenceParentMethod && DeclarationParentMethod && 831 ReferenceParentMethod == DeclarationParentMethod->Op) 832 { 833 AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op, 834 Op->Asl.ExternalName); 835 } 836 } 837 838 /* Check for a reference vs. name declaration */ 839 840 if (!(OpInfo->Flags & AML_NAMED) && 841 !(OpInfo->Flags & AML_CREATE)) 842 { 843 /* This node has been referenced, mark it for reference check */ 844 845 Node->Flags |= ANOBJ_IS_REFERENCED; 846 } 847 848 /* Attempt to optimize the NamePath */ 849 850 OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node); 851 852 /* 853 * 1) Dereference an alias (A name reference that is an alias) 854 * Aliases are not nested, the alias always points to the final object 855 */ 856 if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) && 857 (Node->Type == ACPI_TYPE_LOCAL_ALIAS)) 858 { 859 /* This node points back to the original PARSEOP_ALIAS */ 860 861 NextOp = Node->Op; 862 863 /* The first child is the alias target op */ 864 865 NextOp = NextOp->Asl.Child; 866 867 /* That in turn points back to original target alias node */ 868 869 if (NextOp->Asl.Node) 870 { 871 Node = NextOp->Asl.Node; 872 } 873 874 /* Else - forward reference to alias, will be resolved later */ 875 } 876 877 /* 2) Check for a reference to a resource descriptor */ 878 879 if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) || 880 (Node->Type == ACPI_TYPE_LOCAL_RESOURCE)) 881 { 882 /* 883 * This was a reference to a field within a resource descriptor. 884 * Extract the associated field offset (either a bit or byte 885 * offset depending on the field type) and change the named 886 * reference into an integer for AML code generation 887 */ 888 Offset = Node->Value; 889 TagBitLength = Node->Length; 890 891 /* 892 * If a field is being created, generate the length (in bits) of 893 * the field. Note: Opcodes other than CreateXxxField and Index 894 * can come through here. For other opcodes, we just need to 895 * convert the resource tag reference to an integer offset. 896 */ 897 switch (Op->Asl.Parent->Asl.AmlOpcode) 898 { 899 case AML_CREATE_FIELD_OP: /* Variable "Length" field, in bits */ 900 /* 901 * We know the length operand is an integer constant because 902 * we know that it contains a reference to a resource 903 * descriptor tag. 904 */ 905 FieldBitLength = (UINT32) Op->Asl.Next->Asl.Value.Integer; 906 break; 907 908 case AML_CREATE_BIT_FIELD_OP: 909 910 FieldBitLength = 1; 911 break; 912 913 case AML_CREATE_BYTE_FIELD_OP: 914 case AML_INDEX_OP: 915 916 FieldBitLength = 8; 917 break; 918 919 case AML_CREATE_WORD_FIELD_OP: 920 921 FieldBitLength = 16; 922 break; 923 924 case AML_CREATE_DWORD_FIELD_OP: 925 926 FieldBitLength = 32; 927 break; 928 929 case AML_CREATE_QWORD_FIELD_OP: 930 931 FieldBitLength = 64; 932 break; 933 934 default: 935 936 FieldBitLength = 0; 937 break; 938 } 939 940 /* Check the field length against the length of the resource tag */ 941 942 if (FieldBitLength) 943 { 944 if (TagBitLength < FieldBitLength) 945 { 946 Message = ASL_MSG_TAG_SMALLER; 947 } 948 else if (TagBitLength > FieldBitLength) 949 { 950 Message = ASL_MSG_TAG_LARGER; 951 } 952 953 if (Message) 954 { 955 sprintf (AslGbl_MsgBuffer, 956 "Size mismatch, Tag: %u bit%s, Field: %u bit%s", 957 TagBitLength, (TagBitLength > 1) ? "s" : "", 958 FieldBitLength, (FieldBitLength > 1) ? "s" : ""); 959 960 AslError (ASL_WARNING, Message, Op, AslGbl_MsgBuffer); 961 } 962 } 963 964 /* Convert the BitOffset to a ByteOffset for certain opcodes */ 965 966 switch (Op->Asl.Parent->Asl.AmlOpcode) 967 { 968 case AML_CREATE_BYTE_FIELD_OP: 969 case AML_CREATE_WORD_FIELD_OP: 970 case AML_CREATE_DWORD_FIELD_OP: 971 case AML_CREATE_QWORD_FIELD_OP: 972 case AML_INDEX_OP: 973 974 Offset = ACPI_DIV_8 (Offset); 975 break; 976 977 default: 978 979 break; 980 } 981 982 /* Now convert this node to an integer whose value is the field offset */ 983 984 Op->Asl.AmlLength = 0; 985 Op->Asl.ParseOpcode = PARSEOP_INTEGER; 986 Op->Asl.Value.Integer = (UINT64) Offset; 987 Op->Asl.CompileFlags |= OP_IS_RESOURCE_FIELD; 988 989 OpcGenerateAmlOpcode (Op); 990 } 991 992 /* 3) Check for a method invocation */ 993 994 else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) && 995 (Node->Type == ACPI_TYPE_METHOD) && 996 (Op->Asl.Parent) && 997 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD)) || 998 999 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)) 1000 { 1001 /* 1002 * A reference to a method within one of these opcodes is not an 1003 * invocation of the method, it is simply a reference to the method. 1004 * 1005 * September 2016: Removed DeRefOf from this list 1006 */ 1007 if ((Op->Asl.Parent) && 1008 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF) || 1009 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_PACKAGE) || 1010 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)|| 1011 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE))) 1012 { 1013 return_ACPI_STATUS (AE_OK); 1014 } 1015 1016 /* 1017 * There are two types of method invocation: 1018 * 1) Invocation with arguments -- the parser recognizes this 1019 * as a METHODCALL. 1020 * 2) Invocation with no arguments --the parser cannot determine that 1021 * this is a method invocation, therefore we have to figure it out 1022 * here. 1023 */ 1024 if (Node->Type != ACPI_TYPE_METHOD) 1025 { 1026 sprintf (AslGbl_MsgBuffer, "%s is a %s", 1027 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type)); 1028 1029 AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, AslGbl_MsgBuffer); 1030 return_ACPI_STATUS (AE_OK); 1031 } 1032 1033 /* Save the method node in the caller's op */ 1034 1035 Op->Asl.Node = Node; 1036 if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF) 1037 { 1038 return_ACPI_STATUS (AE_OK); 1039 } 1040 1041 /* 1042 * This is a method invocation, with or without arguments. 1043 * Count the number of arguments, each appears as a child 1044 * under the parent node 1045 */ 1046 Op->Asl.ParseOpcode = PARSEOP_METHODCALL; 1047 UtSetParseOpName (Op); 1048 1049 PassedArgs = 0; 1050 NextOp = Op->Asl.Child; 1051 1052 while (NextOp) 1053 { 1054 PassedArgs++; 1055 NextOp = NextOp->Asl.Next; 1056 } 1057 1058 if (Node->Value != ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS && 1059 Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL) 1060 { 1061 /* 1062 * Check the parsed arguments with the number expected by the 1063 * method declaration itself 1064 */ 1065 if (PassedArgs != Node->Value) 1066 { 1067 if (Node->Flags & ANOBJ_IS_EXTERNAL) 1068 { 1069 sprintf (AslGbl_MsgBuffer, 1070 "according to previous use, %s requires %u", 1071 Op->Asl.ExternalName, Node->Value); 1072 } 1073 else 1074 { 1075 sprintf (AslGbl_MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 1076 Node->Value); 1077 } 1078 1079 if (PassedArgs < Node->Value) 1080 { 1081 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, AslGbl_MsgBuffer); 1082 } 1083 else 1084 { 1085 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, AslGbl_MsgBuffer); 1086 } 1087 } 1088 } 1089 1090 /* 1091 * At this point, a method call to an external method has been 1092 * detected. As of 11/19/2019, iASL does not support parameter counts 1093 * for methods declared as external. Therefore, save the parameter 1094 * count of the first method call and use this count check other 1095 * method calls to ensure that the methods are being called with the 1096 * same amount of parameters. 1097 */ 1098 else if (Node->Type == ACPI_TYPE_METHOD && 1099 (Node->Flags & ANOBJ_IS_EXTERNAL) && 1100 Node->Value == ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS && 1101 Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL) 1102 { 1103 Node->Value = PassedArgs; 1104 } 1105 } 1106 1107 /* 4) Check for an ASL Field definition */ 1108 1109 else if ((Op->Asl.Parent) && 1110 ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD) || 1111 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD))) 1112 { 1113 /* 1114 * Offset checking for fields. If the parent operation region has a 1115 * constant length (known at compile time), we can check fields 1116 * defined in that region against the region length. This will catch 1117 * fields and field units that cannot possibly fit within the region. 1118 * 1119 * Note: Index fields do not directly reference an operation region, 1120 * thus they are not included in this check. 1121 */ 1122 if (Op == Op->Asl.Parent->Asl.Child) 1123 { 1124 /* 1125 * This is the first child of the field node, which is 1126 * the name of the region. Get the parse node for the 1127 * region -- which contains the length of the region. 1128 */ 1129 OwningOp = Node->Op; 1130 Op->Asl.Parent->Asl.ExtraValue = 1131 ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer); 1132 1133 /* Examine the field access width */ 1134 1135 switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer) 1136 { 1137 case AML_FIELD_ACCESS_ANY: 1138 case AML_FIELD_ACCESS_BYTE: 1139 case AML_FIELD_ACCESS_BUFFER: 1140 default: 1141 1142 MinimumLength = 1; 1143 break; 1144 1145 case AML_FIELD_ACCESS_WORD: 1146 1147 MinimumLength = 2; 1148 break; 1149 1150 case AML_FIELD_ACCESS_DWORD: 1151 1152 MinimumLength = 4; 1153 break; 1154 1155 case AML_FIELD_ACCESS_QWORD: 1156 1157 MinimumLength = 8; 1158 break; 1159 } 1160 1161 /* 1162 * Is the region at least as big as the access width? 1163 * Note: DataTableRegions have 0 length 1164 */ 1165 if (((UINT32) OwningOp->Asl.Value.Integer) && 1166 ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength)) 1167 { 1168 AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL); 1169 } 1170 1171 /* 1172 * Check EC/CMOS/SMBUS fields to make sure that the correct 1173 * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS) 1174 */ 1175 SpaceIdOp = OwningOp->Asl.Child->Asl.Next; 1176 switch ((UINT32) SpaceIdOp->Asl.Value.Integer) 1177 { 1178 case ACPI_ADR_SPACE_EC: 1179 case ACPI_ADR_SPACE_CMOS: 1180 case ACPI_ADR_SPACE_GPIO: 1181 1182 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != 1183 AML_FIELD_ACCESS_BYTE) 1184 { 1185 AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL); 1186 } 1187 break; 1188 1189 case ACPI_ADR_SPACE_SMBUS: 1190 case ACPI_ADR_SPACE_IPMI: 1191 case ACPI_ADR_SPACE_GSBUS: 1192 1193 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != 1194 AML_FIELD_ACCESS_BUFFER) 1195 { 1196 AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL); 1197 } 1198 break; 1199 1200 default: 1201 1202 /* Nothing to do for other address spaces */ 1203 1204 break; 1205 } 1206 } 1207 else 1208 { 1209 /* 1210 * This is one element of the field list. Check to make sure 1211 * that it does not go beyond the end of the parent operation region. 1212 * 1213 * In the code below: 1214 * Op->Asl.Parent->Asl.ExtraValue - Region Length (bits) 1215 * Op->Asl.ExtraValue - Field start offset (bits) 1216 * Op->Asl.Child->Asl.Value.Integer32 - Field length (bits) 1217 * Op->Asl.Child->Asl.ExtraValue - Field access width (bits) 1218 */ 1219 if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child) 1220 { 1221 XfCheckFieldRange (Op, 1222 Op->Asl.Parent->Asl.ExtraValue, 1223 Op->Asl.ExtraValue, 1224 (UINT32) Op->Asl.Child->Asl.Value.Integer, 1225 Op->Asl.Child->Asl.ExtraValue); 1226 } 1227 } 1228 } 1229 1230 /* 1231 * 5) Check for external resolution 1232 * By this point, everything should be loaded in the namespace. If a 1233 * namespace lookup results in a namespace node that is an external, it 1234 * means that this named object was not defined in the input ASL. This 1235 * causes issues because there are plenty of incidents where developers 1236 * use the external keyword to suppress compiler errors about undefined 1237 * objects. Note: this only applies when compiling multiple definition 1238 * blocks. 1239 */ 1240 if (AslGbl_ParseTreeRoot->Asl.Child && AslGbl_ParseTreeRoot->Asl.Child->Asl.Next && 1241 (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL && 1242 Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL) && 1243 (Node->Flags & ANOBJ_IS_EXTERNAL)) 1244 { 1245 AslError (ASL_ERROR, ASL_MSG_UNDEFINED_EXTERNAL, Op, NULL); 1246 } 1247 1248 /* 5) Check for a connection object */ 1249 #if 0 1250 else if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION) 1251 { 1252 return_ACPI_STATUS (Status); 1253 } 1254 #endif 1255 1256 Op->Asl.Node = Node; 1257 return_ACPI_STATUS (Status); 1258 } 1259 1260 1261 /******************************************************************************* 1262 * 1263 * FUNCTION: XfNamespaceLocateEnd 1264 * 1265 * PARAMETERS: ASL_WALK_CALLBACK 1266 * 1267 * RETURN: Status 1268 * 1269 * DESCRIPTION: Ascending callback used during cross reference. We only 1270 * need to worry about scope management here. 1271 * 1272 ******************************************************************************/ 1273 1274 static ACPI_STATUS 1275 XfNamespaceLocateEnd ( 1276 ACPI_PARSE_OBJECT *Op, 1277 UINT32 Level, 1278 void *Context) 1279 { 1280 ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; 1281 const ACPI_OPCODE_INFO *OpInfo; 1282 1283 1284 ACPI_FUNCTION_TRACE (XfNamespaceLocateEnd); 1285 1286 1287 /* We are only interested in opcodes that have an associated name */ 1288 1289 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); 1290 if (!(OpInfo->Flags & AML_NAMED)) 1291 { 1292 return_ACPI_STATUS (AE_OK); 1293 } 1294 1295 /* Not interested in name references, we did not open a scope for them */ 1296 1297 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || 1298 (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || 1299 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) || 1300 (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)) 1301 { 1302 return_ACPI_STATUS (AE_OK); 1303 } 1304 1305 /* Pop the scope stack if necessary */ 1306 1307 if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode))) 1308 { 1309 1310 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 1311 "%s: Popping scope for Op %p\n", 1312 AcpiUtGetTypeName (OpInfo->ObjectType), Op)); 1313 1314 (void) AcpiDsScopeStackPop (WalkState); 1315 } 1316 1317 return_ACPI_STATUS (AE_OK); 1318 } 1319 1320 1321 /******************************************************************************* 1322 * 1323 * FUNCTION: XfValidateCrossReference 1324 * 1325 * PARAMETERS: Op - Parse Op that references the object 1326 * OpInfo - Parse Op info struct 1327 * Node - Node for the referenced object 1328 * 1329 * RETURN: TRUE if the reference is legal, FALSE otherwise 1330 * 1331 * DESCRIPTION: Determine if a reference to another object is allowed. 1332 * 1333 * EXAMPLE: 1334 * Method (A) {Name (INT1, 1)} Declaration of object INT1 1335 * Method (B) (Store (2, \A.INT1)} Illegal reference to object INT1 1336 * (INT1 is temporary, valid only during 1337 * execution of A) 1338 * 1339 * NOTES: 1340 * A null pointer returned by either XfGetParentMethod or 1341 * UtGetParentMethod indicates that the parameter object is not 1342 * within a control method. 1343 * 1344 * Five cases are handled: Case(Op, Node) 1345 * 1) Case(0,0): Op is not within a method, Node is not --> OK 1346 * 2) Case(0,1): Op is not within a method, but Node is --> Illegal 1347 * 3) Case(1,0): Op is within a method, Node is not --> OK 1348 * 4) Case(1,1): Both are within the same method --> OK 1349 * 5) Case(1,1): Both are in methods, but not same method --> Illegal 1350 * 1351 ******************************************************************************/ 1352 1353 static BOOLEAN 1354 XfValidateCrossReference ( 1355 ACPI_PARSE_OBJECT *Op, 1356 const ACPI_OPCODE_INFO *OpInfo, 1357 ACPI_NAMESPACE_NODE *Node) 1358 { 1359 ACPI_PARSE_OBJECT *ReferencingMethodOp; 1360 ACPI_NAMESPACE_NODE *ReferencedMethodNode; 1361 1362 1363 /* Ignore actual named (and related) object declarations */ 1364 1365 if (OpInfo->Flags & (AML_NAMED | AML_CREATE | AML_DEFER | AML_HAS_ARGS)) 1366 { 1367 return (TRUE); 1368 } 1369 1370 /* 1371 * 1) Search upwards in parse tree for owner of the referencing object 1372 * 2) Search upwards in namespace to find the owner of the referenced object 1373 */ 1374 ReferencingMethodOp = XfGetParentMethod (Op); 1375 ReferencedMethodNode = UtGetParentMethod (Node); 1376 1377 if (!ReferencingMethodOp && !ReferencedMethodNode) 1378 { 1379 /* 1380 * 1) Case (0,0): Both Op and Node are not within methods 1381 * --> OK 1382 */ 1383 return (TRUE); 1384 } 1385 1386 if (!ReferencingMethodOp && ReferencedMethodNode) 1387 { 1388 /* 1389 * 2) Case (0,1): Op is not in a method, but Node is within a 1390 * method --> illegal 1391 */ 1392 return (FALSE); 1393 } 1394 else if (ReferencingMethodOp && !ReferencedMethodNode) 1395 { 1396 /* 1397 * 3) Case (1,0): Op is within a method, but Node is not 1398 * --> OK 1399 */ 1400 return (TRUE); 1401 } 1402 else if (ReferencingMethodOp->Asl.Node == ReferencedMethodNode) 1403 { 1404 /* 1405 * 4) Case (1,1): Both Op and Node are within the same method 1406 * --> OK 1407 */ 1408 return (TRUE); 1409 } 1410 else 1411 { 1412 /* 1413 * 5) Case (1,1), Op and Node are in different methods 1414 * --> Illegal 1415 */ 1416 return (FALSE); 1417 } 1418 } 1419