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 BOOLEAN
184 XfObjectExists (
185     char                    *Name);
186 
187 static ACPI_STATUS
188 XfCompareOneNamespaceObject (
189     ACPI_HANDLE             ObjHandle,
190     UINT32                  Level,
191     void                    *Context,
192     void                    **ReturnValue);
193 
194 static void
195 XfCheckFieldRange (
196     ACPI_PARSE_OBJECT       *Op,
197     UINT32                  RegionBitLength,
198     UINT32                  FieldBitOffset,
199     UINT32                  FieldBitLength,
200     UINT32                  AccessBitWidth);
201 
202 
203 /*******************************************************************************
204  *
205  * FUNCTION:    XfCrossReferenceNamespace
206  *
207  * PARAMETERS:  None
208  *
209  * RETURN:      Status
210  *
211  * DESCRIPTION: Perform a cross reference check of the parse tree against the
212  *              namespace. Every named referenced within the parse tree
213  *              should be get resolved with a namespace lookup. If not, the
214  *              original reference in the ASL code is invalid -- i.e., refers
215  *              to a non-existent object.
216  *
217  * NOTE:  The ASL "External" operator causes the name to be inserted into the
218  *        namespace so that references to the external name will be resolved
219  *        correctly here.
220  *
221  ******************************************************************************/
222 
223 ACPI_STATUS
224 XfCrossReferenceNamespace (
225     void)
226 {
227     ACPI_WALK_STATE         *WalkState;
228 
229 
230     /*
231      * Create a new walk state for use when looking up names
232      * within the namespace (Passed as context to the callbacks)
233      */
234     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
235     if (!WalkState)
236     {
237         return (AE_NO_MEMORY);
238     }
239 
240     /* Walk the entire parse tree */
241 
242     TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
243         XfNamespaceLocateBegin, XfNamespaceLocateEnd, WalkState);
244 
245     ACPI_FREE (WalkState);
246     return (AE_OK);
247 }
248 
249 
250 /*******************************************************************************
251  *
252  * FUNCTION:    XfObjectExists
253  *
254  * PARAMETERS:  Name            - 4 char ACPI name
255  *
256  * RETURN:      TRUE if name exists in namespace
257  *
258  * DESCRIPTION: Walk the namespace to find an object
259  *
260  ******************************************************************************/
261 
262 static BOOLEAN
263 XfObjectExists (
264     char                    *Name)
265 {
266     ACPI_STATUS             Status;
267 
268 
269     /* Walk entire namespace from the supplied root */
270 
271     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
272         ACPI_UINT32_MAX, FALSE, XfCompareOneNamespaceObject, NULL,
273         Name, NULL);
274     if (Status == AE_CTRL_TRUE)
275     {
276         /* At least one instance of the name was found */
277 
278         return (TRUE);
279     }
280 
281     return (FALSE);
282 }
283 
284 
285 /*******************************************************************************
286  *
287  * FUNCTION:    XfCompareOneNamespaceObject
288  *
289  * PARAMETERS:  ACPI_WALK_CALLBACK
290  *
291  * RETURN:      Status
292  *
293  * DESCRIPTION: Compare name of one object.
294  *
295  ******************************************************************************/
296 
297 static ACPI_STATUS
298 XfCompareOneNamespaceObject (
299     ACPI_HANDLE             ObjHandle,
300     UINT32                  Level,
301     void                    *Context,
302     void                    **ReturnValue)
303 {
304     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
305 
306 
307     /* Simply check the name */
308 
309     if (*((UINT32 *) (Context)) == Node->Name.Integer)
310     {
311         /* Abort walk if we found one instance */
312 
313         return (AE_CTRL_TRUE);
314     }
315 
316     return (AE_OK);
317 }
318 
319 
320 /*******************************************************************************
321  *
322  * FUNCTION:    XfCheckFieldRange
323  *
324  * PARAMETERS:  RegionBitLength     - Length of entire parent region
325  *              FieldBitOffset      - Start of the field unit (within region)
326  *              FieldBitLength      - Entire length of field unit
327  *              AccessBitWidth      - Access width of the field unit
328  *
329  * RETURN:      None
330  *
331  * DESCRIPTION: Check one field unit to make sure it fits in the parent
332  *              op region.
333  *
334  * Note: AccessBitWidth must be either 8,16,32, or 64
335  *
336  ******************************************************************************/
337 
338 static void
339 XfCheckFieldRange (
340     ACPI_PARSE_OBJECT       *Op,
341     UINT32                  RegionBitLength,
342     UINT32                  FieldBitOffset,
343     UINT32                  FieldBitLength,
344     UINT32                  AccessBitWidth)
345 {
346     UINT32                  FieldEndBitOffset;
347 
348 
349     /*
350      * Check each field unit against the region size. The entire
351      * field unit (start offset plus length) must fit within the
352      * region.
353      */
354     FieldEndBitOffset = FieldBitOffset + FieldBitLength;
355 
356     if (FieldEndBitOffset > RegionBitLength)
357     {
358         /* Field definition itself is beyond the end-of-region */
359 
360         AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_OFFSET, Op, NULL);
361         return;
362     }
363 
364     /*
365      * Now check that the field plus AccessWidth doesn't go beyond
366      * the end-of-region. Assumes AccessBitWidth is a power of 2
367      */
368     FieldEndBitOffset = ACPI_ROUND_UP (FieldEndBitOffset, AccessBitWidth);
369 
370     if (FieldEndBitOffset > RegionBitLength)
371     {
372         /* Field definition combined with the access is beyond EOR */
373 
374         AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, Op, NULL);
375     }
376 }
377 
378 
379 /*******************************************************************************
380  *
381  * FUNCTION:    XfNamespaceLocateBegin
382  *
383  * PARAMETERS:  ASL_WALK_CALLBACK
384  *
385  * RETURN:      Status
386  *
387  * DESCRIPTION: Descending callback used during cross-reference. For named
388  *              object references, attempt to locate the name in the
389  *              namespace.
390  *
391  * NOTE: ASL references to named fields within resource descriptors are
392  *       resolved to integer values here. Therefore, this step is an
393  *       important part of the code generation. We don't know that the
394  *       name refers to a resource descriptor until now.
395  *
396  ******************************************************************************/
397 
398 static ACPI_STATUS
399 XfNamespaceLocateBegin (
400     ACPI_PARSE_OBJECT       *Op,
401     UINT32                  Level,
402     void                    *Context)
403 {
404     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
405     ACPI_NAMESPACE_NODE     *Node;
406     ACPI_STATUS             Status;
407     ACPI_OBJECT_TYPE        ObjectType;
408     char                    *Path;
409     UINT8                   PassedArgs;
410     ACPI_PARSE_OBJECT       *NextOp;
411     ACPI_PARSE_OBJECT       *OwningOp;
412     ACPI_PARSE_OBJECT       *SpaceIdOp;
413     UINT32                  MinimumLength;
414     UINT32                  Offset;
415     UINT32                  FieldBitLength;
416     UINT32                  TagBitLength;
417     UINT8                   Message = 0;
418     const ACPI_OPCODE_INFO  *OpInfo;
419     UINT32                  Flags;
420     ASL_METHOD_LOCAL        *MethodLocals = NULL;
421     ASL_METHOD_LOCAL        *MethodArgs = NULL;
422     int                     RegisterNumber;
423     UINT32                  i;
424     ACPI_NAMESPACE_NODE     *DeclarationParentMethod;
425     ACPI_PARSE_OBJECT       *ReferenceParentMethod;
426 
427 
428     ACPI_FUNCTION_TRACE_PTR (XfNamespaceLocateBegin, Op);
429 
430 
431     if ((Op->Asl.AmlOpcode == AML_METHOD_OP) && Op->Asl.Node)
432     {
433         Node = Op->Asl.Node;
434 
435         /* Support for method LocalX/ArgX analysis */
436 
437         if (!Node->MethodLocals)
438         {
439             /* Create local/arg info blocks */
440 
441             MethodLocals = UtLocalCalloc (
442                 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_LOCALS);
443             Node->MethodLocals = MethodLocals;
444 
445             MethodArgs = UtLocalCalloc (
446                 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_ARGS);
447             Node->MethodArgs = MethodArgs;
448 
449             /*
450              * Get the method argument count
451              * First, get the name node
452              */
453             NextOp = Op->Asl.Child;
454 
455             /* Get the NumArguments node */
456 
457             NextOp = NextOp->Asl.Next;
458             Node->ArgCount = (UINT8)
459                 (((UINT8) NextOp->Asl.Value.Integer) & 0x07);
460 
461             /* We will track all possible ArgXs */
462 
463             for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
464             {
465                 if (i < Node->ArgCount)
466                 {
467                     /* Real Args are always "initialized" */
468 
469                     MethodArgs[i].Flags = ASL_ARG_INITIALIZED;
470                 }
471                 else
472                 {
473                     /* Other ArgXs can be used as locals */
474 
475                     MethodArgs[i].Flags = ASL_ARG_IS_LOCAL;
476                 }
477 
478                 MethodArgs[i].Op = Op;
479             }
480         }
481     }
482 
483     /*
484      * If this node is the actual declaration of a name
485      * [such as the XXXX name in "Method (XXXX)"],
486      * we are not interested in it here. We only care about names that are
487      * references to other objects within the namespace and the parent objects
488      * of name declarations
489      */
490     if (Op->Asl.CompileFlags & OP_IS_NAME_DECLARATION)
491     {
492         return_ACPI_STATUS (AE_OK);
493     }
494 
495     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
496 
497     /* Check method LocalX variables */
498 
499     if (OpInfo->Type == AML_TYPE_LOCAL_VARIABLE)
500     {
501         /* Find parent method Op */
502 
503         NextOp = UtGetParentMethodOp (Op);
504         if (!NextOp)
505         {
506             return_ACPI_STATUS (AE_OK);
507         }
508 
509         /* Get method node */
510 
511         Node = NextOp->Asl.Node;
512 
513         RegisterNumber = Op->Asl.AmlOpcode & 0x0007; /* 0x60 through 0x67 */
514         MethodLocals = Node->MethodLocals;
515 
516         if (Op->Asl.CompileFlags & OP_IS_TARGET)
517         {
518             /* Local is being initialized */
519 
520             MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_INITIALIZED;
521             MethodLocals[RegisterNumber].Op = Op;
522 
523             return_ACPI_STATUS (AE_OK);
524         }
525 
526         /* Mark this Local as referenced */
527 
528         MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_REFERENCED;
529         MethodLocals[RegisterNumber].Op = Op;
530 
531         return_ACPI_STATUS (AE_OK);
532     }
533 
534     /* Check method ArgX variables */
535 
536     if (OpInfo->Type == AML_TYPE_METHOD_ARGUMENT)
537     {
538         /* Find parent method Op */
539 
540         NextOp = UtGetParentMethodOp (Op);
541         if (!NextOp)
542         {
543             return_ACPI_STATUS (AE_OK);
544         }
545 
546         /* Get method node */
547 
548         Node = NextOp->Asl.Node;
549 
550         /* Get Arg # */
551 
552         RegisterNumber = Op->Asl.AmlOpcode - AML_ARG0; /* 0x68 through 0x6F */
553         MethodArgs = Node->MethodArgs;
554 
555         /* Mark this Arg as referenced */
556 
557         MethodArgs[RegisterNumber].Flags |= ASL_ARG_REFERENCED;
558         MethodArgs[RegisterNumber].Op = Op;
559 
560         if (Op->Asl.CompileFlags & OP_IS_TARGET)
561         {
562             /* Arg is being initialized */
563 
564             MethodArgs[RegisterNumber].Flags |= ASL_ARG_INITIALIZED;
565         }
566 
567         return_ACPI_STATUS (AE_OK);
568     }
569 
570     /*
571      * After method ArgX and LocalX, we are only interested in opcodes
572      * that have an associated name
573      */
574     if ((!(OpInfo->Flags & AML_NAMED)) &&
575         (!(OpInfo->Flags & AML_CREATE)) &&
576         (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
577         (Op->Asl.ParseOpcode != PARSEOP_NAMESEG)    &&
578         (Op->Asl.ParseOpcode != PARSEOP_METHODCALL) &&
579         (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
580     {
581         return_ACPI_STATUS (AE_OK);
582     }
583 
584     /*
585      * One special case: CondRefOf operator - we don't care if the name exists
586      * or not at this point, just ignore it, the point of the operator is to
587      * determine if the name exists at runtime.
588      */
589     if ((Op->Asl.Parent) &&
590         (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
591     {
592         return_ACPI_STATUS (AE_OK);
593     }
594 
595     /*
596      * We must enable the "search-to-root" for single NameSegs, but
597      * we have to be very careful about opening up scopes
598      */
599     Flags = ACPI_NS_SEARCH_PARENT;
600     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
601         (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)    ||
602         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
603         (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
604     {
605         /*
606          * These are name references, do not push the scope stack
607          * for them.
608          */
609         Flags |= ACPI_NS_DONT_OPEN_SCOPE;
610     }
611 
612     /* Get the NamePath from the appropriate place */
613 
614     if (OpInfo->Flags & AML_NAMED)
615     {
616         /* For nearly all NAMED operators, the name reference is the first child */
617 
618         Path = Op->Asl.Child->Asl.Value.String;
619         if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
620         {
621             /*
622              * ALIAS is the only oddball opcode, the name declaration
623              * (alias name) is the second operand
624              */
625             Path = Op->Asl.Child->Asl.Next->Asl.Value.String;
626         }
627     }
628     else if (OpInfo->Flags & AML_CREATE)
629     {
630         /* Name must appear as the last parameter */
631 
632         NextOp = Op->Asl.Child;
633         while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION))
634         {
635             NextOp = NextOp->Asl.Next;
636         }
637 
638         Path = NextOp->Asl.Value.String;
639     }
640     else
641     {
642         Path = Op->Asl.Value.String;
643     }
644 
645     ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
646     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
647         "Type=%s\n", AcpiUtGetTypeName (ObjectType)));
648 
649     /*
650      * Lookup the name in the namespace. Name must exist at this point, or it
651      * is an invalid reference.
652      *
653      * The namespace is also used as a lookup table for references to resource
654      * descriptors and the fields within them.
655      */
656     AslGbl_NsLookupCount++;
657 
658     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
659         ACPI_IMODE_EXECUTE, Flags, WalkState, &Node);
660     if (ACPI_FAILURE (Status))
661     {
662         if (Status == AE_NOT_FOUND)
663         {
664             /*
665              * We didn't find the name reference by path -- we can qualify this
666              * a little better before we print an error message
667              */
668             if (strlen (Path) == ACPI_NAMESEG_SIZE)
669             {
670                 /* A simple, one-segment ACPI name */
671 
672                 if (XfObjectExists (Path))
673                 {
674                     /*
675                      * There exists such a name, but we couldn't get to it
676                      * from this scope
677                      */
678                     AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op,
679                         Op->Asl.ExternalName);
680                 }
681                 else
682                 {
683                     /* The name doesn't exist, period */
684 
685                     AslError (ASL_ERROR, ASL_MSG_NOT_EXIST,
686                         Op, Op->Asl.ExternalName);
687                 }
688             }
689             else
690             {
691                 /* The NamePath contains multiple NameSegs */
692 
693                 if ((OpInfo->Flags & AML_CREATE) ||
694                     (OpInfo->ObjectType == ACPI_TYPE_LOCAL_ALIAS))
695                 {
696                     /*
697                      * The new name is the last parameter. For the
698                      * CreateXXXXField and Alias operators
699                      */
700                     NextOp = Op->Asl.Child;
701                     while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION))
702                     {
703                         NextOp = NextOp->Asl.Next;
704                     }
705 
706                     AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, NextOp,
707                         NextOp->Asl.ExternalName);
708                 }
709                 else if (OpInfo->Flags & AML_NAMED)
710                 {
711                     /* The new name is the first parameter */
712 
713                     AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, Op,
714                         Op->Asl.ExternalName);
715                 }
716                 else if (Path[0] == AML_ROOT_PREFIX)
717                 {
718                     /* Full namepath from root, the object does not exist */
719 
720                     AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op,
721                         Op->Asl.ExternalName);
722                 }
723                 else
724                 {
725                     /*
726                      * Generic "not found" error. Cannot determine whether it
727                      * doesn't exist or just can't be reached. However, we
728                      * can differentiate between a NameSeg vs. NamePath.
729                      */
730                     if (strlen (Op->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
731                     {
732                         AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
733                             Op->Asl.ExternalName);
734                     }
735                     else
736                     {
737                         AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
738                             Op->Asl.ExternalName);
739                     }
740                 }
741             }
742 
743             Status = AE_OK;
744         }
745 
746         return_ACPI_STATUS (Status);
747     }
748 
749     /* Check for an attempt to access an object in another method */
750 
751     if (!XfValidateCrossReference (Op, OpInfo, Node))
752     {
753         AslError (ASL_ERROR, ASL_MSG_TEMPORARY_OBJECT, Op,
754             Op->Asl.ExternalName);
755         return_ACPI_STATUS (Status);
756     }
757 
758    /* Object was found above, check for an illegal forward reference */
759 
760     if (Op->Asl.CompileFlags & OP_NOT_FOUND_DURING_LOAD)
761     {
762         /*
763          * During the load phase, this Op was flagged as a possible
764          * illegal forward reference. In other words, Op is a name path or
765          * name segment that refers to a named object declared after the
766          * reference. In this scinario, Node refers to the actual declaration
767          * and Op is a parse node that references the named object.
768          *
769          * Note:
770          *
771          * Object references inside of control methods are allowed to
772          * refer to objects declared outside of control methods.
773          *
774          * If the declaration and reference are both contained inside of the
775          * same method or outside of any method, this is a forward reference
776          * and should be reported as a compiler error.
777          */
778         DeclarationParentMethod = UtGetParentMethodNode (Node);
779         ReferenceParentMethod = UtGetParentMethodOp (Op);
780 
781         /* case 1: declaration and reference are both outside of method */
782 
783         if (!ReferenceParentMethod && !DeclarationParentMethod)
784         {
785             AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op,
786                 Op->Asl.ExternalName);
787         }
788 
789         /* case 2: declaration and reference are both inside of the same method */
790 
791         else if (ReferenceParentMethod && DeclarationParentMethod &&
792             ReferenceParentMethod == DeclarationParentMethod->Op)
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_UNKNOWN_PARAMS &&
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                 if (Node->Flags & ANOBJ_IS_EXTERNAL)
1029                 {
1030                     sprintf (AslGbl_MsgBuffer,
1031                         "according to previous use, %s requires %u",
1032                         Op->Asl.ExternalName, Node->Value);
1033                 }
1034                 else
1035                 {
1036                     sprintf (AslGbl_MsgBuffer, "%s requires %u", Op->Asl.ExternalName,
1037                         Node->Value);
1038                 }
1039 
1040                 if (PassedArgs < Node->Value)
1041                 {
1042                     AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, AslGbl_MsgBuffer);
1043                 }
1044                 else
1045                 {
1046                     AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, AslGbl_MsgBuffer);
1047                 }
1048             }
1049         }
1050 
1051         /*
1052          * At this point, a method call to an external method has been
1053          * detected. As of 11/19/2019, iASL does not support parameter counts
1054          * for methods declared as external. Therefore, save the parameter
1055          * count of the first method call and use this count check other
1056          * method calls to ensure that the methods are being called with the
1057          * same amount of parameters.
1058          */
1059         else if (Node->Type == ACPI_TYPE_METHOD &&
1060             (Node->Flags & ANOBJ_IS_EXTERNAL) &&
1061             Node->Value == ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS &&
1062             Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL)
1063         {
1064             Node->Value = PassedArgs;
1065         }
1066     }
1067 
1068     /* 4) Check for an ASL Field definition */
1069 
1070     else if ((Op->Asl.Parent) &&
1071             ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD)     ||
1072              (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD)))
1073     {
1074         /*
1075          * Offset checking for fields. If the parent operation region has a
1076          * constant length (known at compile time), we can check fields
1077          * defined in that region against the region length. This will catch
1078          * fields and field units that cannot possibly fit within the region.
1079          *
1080          * Note: Index fields do not directly reference an operation region,
1081          * thus they are not included in this check.
1082          */
1083         if (Op == Op->Asl.Parent->Asl.Child)
1084         {
1085             /*
1086              * This is the first child of the field node, which is
1087              * the name of the region. Get the parse node for the
1088              * region -- which contains the length of the region.
1089              */
1090             OwningOp = Node->Op;
1091             Op->Asl.Parent->Asl.ExtraValue =
1092                 ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer);
1093 
1094             /* Examine the field access width */
1095 
1096             switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer)
1097             {
1098             case AML_FIELD_ACCESS_ANY:
1099             case AML_FIELD_ACCESS_BYTE:
1100             case AML_FIELD_ACCESS_BUFFER:
1101             default:
1102 
1103                 MinimumLength = 1;
1104                 break;
1105 
1106             case AML_FIELD_ACCESS_WORD:
1107 
1108                 MinimumLength = 2;
1109                 break;
1110 
1111             case AML_FIELD_ACCESS_DWORD:
1112 
1113                 MinimumLength = 4;
1114                 break;
1115 
1116             case AML_FIELD_ACCESS_QWORD:
1117 
1118                 MinimumLength = 8;
1119                 break;
1120             }
1121 
1122             /*
1123              * Is the region at least as big as the access width?
1124              * Note: DataTableRegions have 0 length
1125              */
1126             if (((UINT32) OwningOp->Asl.Value.Integer) &&
1127                 ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength))
1128             {
1129                 AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL);
1130             }
1131 
1132             /*
1133              * Check EC/CMOS/SMBUS fields to make sure that the correct
1134              * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS)
1135              */
1136             SpaceIdOp = OwningOp->Asl.Child->Asl.Next;
1137             switch ((UINT32) SpaceIdOp->Asl.Value.Integer)
1138             {
1139             case ACPI_ADR_SPACE_EC:
1140             case ACPI_ADR_SPACE_CMOS:
1141             case ACPI_ADR_SPACE_GPIO:
1142 
1143                 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
1144                     AML_FIELD_ACCESS_BYTE)
1145                 {
1146                     AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL);
1147                 }
1148                 break;
1149 
1150             case ACPI_ADR_SPACE_SMBUS:
1151             case ACPI_ADR_SPACE_IPMI:
1152             case ACPI_ADR_SPACE_GSBUS:
1153 
1154                 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
1155                     AML_FIELD_ACCESS_BUFFER)
1156                 {
1157                     AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL);
1158                 }
1159                 break;
1160 
1161             default:
1162 
1163                 /* Nothing to do for other address spaces */
1164 
1165                 break;
1166             }
1167         }
1168         else
1169         {
1170             /*
1171              * This is one element of the field list. Check to make sure
1172              * that it does not go beyond the end of the parent operation region.
1173              *
1174              * In the code below:
1175              *    Op->Asl.Parent->Asl.ExtraValue      - Region Length (bits)
1176              *    Op->Asl.ExtraValue                  - Field start offset (bits)
1177              *    Op->Asl.Child->Asl.Value.Integer32  - Field length (bits)
1178              *    Op->Asl.Child->Asl.ExtraValue       - Field access width (bits)
1179              */
1180             if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child)
1181             {
1182                 XfCheckFieldRange (Op,
1183                     Op->Asl.Parent->Asl.ExtraValue,
1184                     Op->Asl.ExtraValue,
1185                     (UINT32) Op->Asl.Child->Asl.Value.Integer,
1186                     Op->Asl.Child->Asl.ExtraValue);
1187             }
1188         }
1189     }
1190 
1191     /*
1192      * 5) Check for external resolution
1193      * By this point, everything should be loaded in the namespace. If a
1194      * namespace lookup results in a namespace node that is an external, it
1195      * means that this named object was not defined in the input ASL. This
1196      * causes issues because there are plenty of incidents where developers
1197      * use the external keyword to suppress compiler errors about undefined
1198      * objects. Note: this only applies when compiling multiple definition
1199      * blocks.
1200      */
1201     if (AslGbl_ParseTreeRoot->Asl.Child && AslGbl_ParseTreeRoot->Asl.Child->Asl.Next &&
1202         (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL &&
1203         Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL) &&
1204         (Node->Flags & ANOBJ_IS_EXTERNAL))
1205     {
1206         AslError (ASL_ERROR, ASL_MSG_UNDEFINED_EXTERNAL, Op, NULL);
1207     }
1208 
1209     /* 5) Check for a connection object */
1210 #if 0
1211     else if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION)
1212     {
1213         return_ACPI_STATUS (Status);
1214     }
1215 #endif
1216 
1217     Op->Asl.Node = Node;
1218     return_ACPI_STATUS (Status);
1219 }
1220 
1221 
1222 /*******************************************************************************
1223  *
1224  * FUNCTION:    XfNamespaceLocateEnd
1225  *
1226  * PARAMETERS:  ASL_WALK_CALLBACK
1227  *
1228  * RETURN:      Status
1229  *
1230  * DESCRIPTION: Ascending callback used during cross reference. We only
1231  *              need to worry about scope management here.
1232  *
1233  ******************************************************************************/
1234 
1235 static ACPI_STATUS
1236 XfNamespaceLocateEnd (
1237     ACPI_PARSE_OBJECT       *Op,
1238     UINT32                  Level,
1239     void                    *Context)
1240 {
1241     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
1242     const ACPI_OPCODE_INFO  *OpInfo;
1243 
1244 
1245     ACPI_FUNCTION_TRACE (XfNamespaceLocateEnd);
1246 
1247 
1248     /* We are only interested in opcodes that have an associated name */
1249 
1250     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1251     if (!(OpInfo->Flags & AML_NAMED))
1252     {
1253         return_ACPI_STATUS (AE_OK);
1254     }
1255 
1256     /* Not interested in name references, we did not open a scope for them */
1257 
1258     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
1259         (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)    ||
1260         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
1261         (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
1262     {
1263         return_ACPI_STATUS (AE_OK);
1264     }
1265 
1266     /* Pop the scope stack if necessary */
1267 
1268     if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode)))
1269     {
1270 
1271         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1272             "%s: Popping scope for Op %p\n",
1273             AcpiUtGetTypeName (OpInfo->ObjectType), Op));
1274 
1275         (void) AcpiDsScopeStackPop (WalkState);
1276     }
1277 
1278     return_ACPI_STATUS (AE_OK);
1279 }
1280 
1281 
1282 /*******************************************************************************
1283  *
1284  * FUNCTION:    XfValidateCrossReference
1285  *
1286  * PARAMETERS:  Op                      - Parse Op that references the object
1287  *              OpInfo                  - Parse Op info struct
1288  *              Node                    - Node for the referenced object
1289  *
1290  * RETURN:      TRUE if the reference is legal, FALSE otherwise
1291  *
1292  * DESCRIPTION: Determine if a reference to another object is allowed.
1293  *
1294  * EXAMPLE:
1295  *      Method (A) {Name (INT1, 1)}     Declaration of object INT1
1296  *      Method (B) (Store (2, \A.INT1)} Illegal reference to object INT1
1297  *                                      (INT1 is temporary, valid only during
1298  *                                      execution of A)
1299  *
1300  * NOTES:
1301  *      A null pointer returned by either UtGetParentMethodOp or
1302  *      UtGetParentMethodNode indicates that the parameter object is not
1303  *      within a control method.
1304  *
1305  *      Five cases are handled: Case(Op, Node)
1306  *      1) Case(0,0): Op is not within a method, Node is not    --> OK
1307  *      2) Case(0,1): Op is not within a method, but Node is    --> Illegal
1308  *      3) Case(1,0): Op is within a method, Node is not        --> OK
1309  *      4) Case(1,1): Both are within the same method           --> OK
1310  *      5) Case(1,1): Both are in methods, but not same method  --> Illegal
1311  *
1312  ******************************************************************************/
1313 
1314 static BOOLEAN
1315 XfValidateCrossReference (
1316     ACPI_PARSE_OBJECT       *Op,
1317     const ACPI_OPCODE_INFO  *OpInfo,
1318     ACPI_NAMESPACE_NODE     *Node)
1319 {
1320     ACPI_PARSE_OBJECT       *ReferencingMethodOp;
1321     ACPI_NAMESPACE_NODE     *ReferencedMethodNode;
1322 
1323 
1324     /* Ignore actual named (and related) object declarations */
1325 
1326     if (OpInfo->Flags & (AML_NAMED | AML_CREATE | AML_DEFER | AML_HAS_ARGS))
1327     {
1328         return (TRUE);
1329     }
1330 
1331     /*
1332      * 1) Search upwards in parse tree for owner of the referencing object
1333      * 2) Search upwards in namespace to find the owner of the referenced object
1334      */
1335     ReferencingMethodOp = UtGetParentMethodOp (Op);
1336     ReferencedMethodNode = UtGetParentMethodNode (Node);
1337 
1338     if (!ReferencingMethodOp && !ReferencedMethodNode)
1339     {
1340         /*
1341          * 1) Case (0,0): Both Op and Node are not within methods
1342          * --> OK
1343          */
1344         return (TRUE);
1345     }
1346 
1347     if (!ReferencingMethodOp && ReferencedMethodNode)
1348     {
1349         /*
1350          * 2) Case (0,1): Op is not in a method, but Node is within a
1351          * method --> illegal
1352          */
1353         return (FALSE);
1354     }
1355     else if (ReferencingMethodOp && !ReferencedMethodNode)
1356     {
1357         /*
1358          * 3) Case (1,0): Op is within a method, but Node is not
1359          * --> OK
1360          */
1361         return (TRUE);
1362     }
1363     else if (ReferencingMethodOp->Asl.Node == ReferencedMethodNode)
1364     {
1365         /*
1366          * 4) Case (1,1): Both Op and Node are within the same method
1367          * --> OK
1368          */
1369         return (TRUE);
1370     }
1371     else
1372     {
1373         /*
1374          * 5) Case (1,1), Op and Node are in different methods
1375          * --> Illegal
1376          */
1377         return (FALSE);
1378     }
1379 }
1380