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