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 - 2019, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include "aslcompiler.h"
153 #include "aslcompiler.y.h"
154 #include "acparser.h"
155 #include "amlcode.h"
156 #include "acnamesp.h"
157 #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 
464 
465     ACPI_FUNCTION_TRACE_PTR (XfNamespaceLocateBegin, Op);
466 
467 
468     if ((Op->Asl.AmlOpcode == AML_METHOD_OP) && Op->Asl.Node)
469     {
470         Node = Op->Asl.Node;
471 
472         /* Support for method LocalX/ArgX analysis */
473 
474         if (!Node->MethodLocals)
475         {
476             /* Create local/arg info blocks */
477 
478             MethodLocals = UtLocalCalloc (
479                 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_LOCALS);
480             Node->MethodLocals = MethodLocals;
481 
482             MethodArgs = UtLocalCalloc (
483                 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_ARGS);
484             Node->MethodArgs = MethodArgs;
485 
486             /*
487              * Get the method argument count
488              * First, get the name node
489              */
490             NextOp = Op->Asl.Child;
491 
492             /* Get the NumArguments node */
493 
494             NextOp = NextOp->Asl.Next;
495             Node->ArgCount = (UINT8)
496                 (((UINT8) NextOp->Asl.Value.Integer) & 0x07);
497 
498             /* We will track all possible ArgXs */
499 
500             for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
501             {
502                 if (i < Node->ArgCount)
503                 {
504                     /* Real Args are always "initialized" */
505 
506                     MethodArgs[i].Flags = ASL_ARG_INITIALIZED;
507                 }
508                 else
509                 {
510                     /* Other ArgXs can be used as locals */
511 
512                     MethodArgs[i].Flags = ASL_ARG_IS_LOCAL;
513                 }
514 
515                 MethodArgs[i].Op = Op;
516             }
517         }
518     }
519 
520     /*
521      * If this node is the actual declaration of a name
522      * [such as the XXXX name in "Method (XXXX)"],
523      * we are not interested in it here. We only care about names that are
524      * references to other objects within the namespace and the parent objects
525      * of name declarations
526      */
527     if (Op->Asl.CompileFlags & OP_IS_NAME_DECLARATION)
528     {
529         return_ACPI_STATUS (AE_OK);
530     }
531 
532     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
533 
534     /* Check method LocalX variables */
535 
536     if (OpInfo->Type == AML_TYPE_LOCAL_VARIABLE)
537     {
538         /* Find parent method Op */
539 
540         NextOp = XfGetParentMethod (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         RegisterNumber = Op->Asl.AmlOpcode & 0x0007; /* 0x60 through 0x67 */
551         MethodLocals = Node->MethodLocals;
552 
553         if (Op->Asl.CompileFlags & OP_IS_TARGET)
554         {
555             /* Local is being initialized */
556 
557             MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_INITIALIZED;
558             MethodLocals[RegisterNumber].Op = Op;
559 
560             return_ACPI_STATUS (AE_OK);
561         }
562 
563         /* Mark this Local as referenced */
564 
565         MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_REFERENCED;
566         MethodLocals[RegisterNumber].Op = Op;
567 
568         return_ACPI_STATUS (AE_OK);
569     }
570 
571     /* Check method ArgX variables */
572 
573     if (OpInfo->Type == AML_TYPE_METHOD_ARGUMENT)
574     {
575         /* Find parent method Op */
576 
577         NextOp = XfGetParentMethod (Op);
578         if (!NextOp)
579         {
580             return_ACPI_STATUS (AE_OK);
581         }
582 
583         /* Get method node */
584 
585         Node = NextOp->Asl.Node;
586 
587         /* Get Arg # */
588 
589         RegisterNumber = Op->Asl.AmlOpcode - AML_ARG0; /* 0x68 through 0x6F */
590         MethodArgs = Node->MethodArgs;
591 
592         /* Mark this Arg as referenced */
593 
594         MethodArgs[RegisterNumber].Flags |= ASL_ARG_REFERENCED;
595         MethodArgs[RegisterNumber].Op = Op;
596 
597         if (Op->Asl.CompileFlags & OP_IS_TARGET)
598         {
599             /* Arg is being initialized */
600 
601             MethodArgs[RegisterNumber].Flags |= ASL_ARG_INITIALIZED;
602         }
603 
604         return_ACPI_STATUS (AE_OK);
605     }
606 
607     /*
608      * After method ArgX and LocalX, we are only interested in opcodes
609      * that have an associated name
610      */
611     if ((!(OpInfo->Flags & AML_NAMED)) &&
612         (!(OpInfo->Flags & AML_CREATE)) &&
613         (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
614         (Op->Asl.ParseOpcode != PARSEOP_NAMESEG)    &&
615         (Op->Asl.ParseOpcode != PARSEOP_METHODCALL) &&
616         (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
617     {
618         return_ACPI_STATUS (AE_OK);
619     }
620 
621     /*
622      * One special case: CondRefOf operator - we don't care if the name exists
623      * or not at this point, just ignore it, the point of the operator is to
624      * determine if the name exists at runtime.
625      */
626     if ((Op->Asl.Parent) &&
627         (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
628     {
629         return_ACPI_STATUS (AE_OK);
630     }
631 
632     /*
633      * We must enable the "search-to-root" for single NameSegs, but
634      * we have to be very careful about opening up scopes
635      */
636     Flags = ACPI_NS_SEARCH_PARENT;
637     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
638         (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)    ||
639         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
640         (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
641     {
642         /*
643          * These are name references, do not push the scope stack
644          * for them.
645          */
646         Flags |= ACPI_NS_DONT_OPEN_SCOPE;
647     }
648 
649     /* Get the NamePath from the appropriate place */
650 
651     if (OpInfo->Flags & AML_NAMED)
652     {
653         /* For nearly all NAMED operators, the name reference is the first child */
654 
655         Path = Op->Asl.Child->Asl.Value.String;
656         if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
657         {
658             /*
659              * ALIAS is the only oddball opcode, the name declaration
660              * (alias name) is the second operand
661              */
662             Path = Op->Asl.Child->Asl.Next->Asl.Value.String;
663         }
664     }
665     else if (OpInfo->Flags & AML_CREATE)
666     {
667         /* Name must appear as the last parameter */
668 
669         NextOp = Op->Asl.Child;
670         while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION))
671         {
672             NextOp = NextOp->Asl.Next;
673         }
674 
675         Path = NextOp->Asl.Value.String;
676     }
677     else
678     {
679         Path = Op->Asl.Value.String;
680     }
681 
682     ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
683     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
684         "Type=%s\n", AcpiUtGetTypeName (ObjectType)));
685 
686     /*
687      * Lookup the name in the namespace. Name must exist at this point, or it
688      * is an invalid reference.
689      *
690      * The namespace is also used as a lookup table for references to resource
691      * descriptors and the fields within them.
692      */
693     AslGbl_NsLookupCount++;
694 
695     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
696         ACPI_IMODE_EXECUTE, Flags, WalkState, &Node);
697     if (ACPI_FAILURE (Status))
698     {
699         if (Status == AE_NOT_FOUND)
700         {
701             /*
702              * We didn't find the name reference by path -- we can qualify this
703              * a little better before we print an error message
704              */
705             if (strlen (Path) == ACPI_NAME_SIZE)
706             {
707                 /* A simple, one-segment ACPI name */
708 
709                 if (XfObjectExists (Path))
710                 {
711                     /*
712                      * There exists such a name, but we couldn't get to it
713                      * from this scope
714                      */
715                     AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op,
716                         Op->Asl.ExternalName);
717                 }
718                 else
719                 {
720                     /* The name doesn't exist, period */
721 
722                     AslError (ASL_ERROR, ASL_MSG_NOT_EXIST,
723                         Op, Op->Asl.ExternalName);
724                 }
725             }
726             else
727             {
728                 /* The NamePath contains multiple NameSegs */
729 
730                 if ((OpInfo->Flags & AML_CREATE) ||
731                     (OpInfo->ObjectType == ACPI_TYPE_LOCAL_ALIAS))
732                 {
733                     /*
734                      * The new name is the last parameter. For the
735                      * CreateXXXXField and Alias operators
736                      */
737                     NextOp = Op->Asl.Child;
738                     while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION))
739                     {
740                         NextOp = NextOp->Asl.Next;
741                     }
742 
743                     AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, NextOp,
744                         NextOp->Asl.ExternalName);
745                 }
746                 else if (OpInfo->Flags & AML_NAMED)
747                 {
748                     /* The new name is the first parameter */
749 
750                     AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, Op,
751                         Op->Asl.ExternalName);
752                 }
753                 else if (Path[0] == AML_ROOT_PREFIX)
754                 {
755                     /* Full namepath from root, the object does not exist */
756 
757                     AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op,
758                         Op->Asl.ExternalName);
759                 }
760                 else
761                 {
762                     /*
763                      * Generic "not found" error. Cannot determine whether it
764                      * doesn't exist or just can't be reached. However, we
765                      * can differentiate between a NameSeg vs. NamePath.
766                      */
767                     if (strlen (Op->Asl.ExternalName) == ACPI_NAME_SIZE)
768                     {
769                         AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
770                             Op->Asl.ExternalName);
771                     }
772                     else
773                     {
774                         AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
775                             Op->Asl.ExternalName);
776                     }
777                 }
778             }
779 
780             Status = AE_OK;
781         }
782 
783         return_ACPI_STATUS (Status);
784     }
785 
786     /* Check for an attempt to access an object in another method */
787 
788     if (!XfValidateCrossReference (Op, OpInfo, Node))
789     {
790         AslError (ASL_ERROR, ASL_MSG_TEMPORARY_OBJECT, Op,
791             Op->Asl.ExternalName);
792         return_ACPI_STATUS (Status);
793     }
794 
795     /* Object was found above, check for an illegal forward reference */
796 
797     if (Op->Asl.CompileFlags & OP_NOT_FOUND_DURING_LOAD)
798     {
799         /*
800          * During the load phase, this Op was flagged as a possible
801          * illegal forward reference
802          *
803          * Note: Allow "forward references" from within a method to an
804          * object that is not within any method (module-level code)
805          */
806         if (!WalkState->ScopeInfo || (UtGetParentMethod (Node) &&
807             !UtNodeIsDescendantOf (WalkState->ScopeInfo->Scope.Node,
808                 UtGetParentMethod (Node))))
809         {
810             AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op,
811                 Op->Asl.ExternalName);
812         }
813     }
814 
815     /* Check for a reference vs. name declaration */
816 
817     if (!(OpInfo->Flags & AML_NAMED) &&
818         !(OpInfo->Flags & AML_CREATE))
819     {
820         /* This node has been referenced, mark it for reference check */
821 
822         Node->Flags |= ANOBJ_IS_REFERENCED;
823     }
824 
825     /* Attempt to optimize the NamePath */
826 
827     OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node);
828 
829     /*
830      * 1) Dereference an alias (A name reference that is an alias)
831      *    Aliases are not nested, the alias always points to the final object
832      */
833     if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) &&
834         (Node->Type == ACPI_TYPE_LOCAL_ALIAS))
835     {
836         /* This node points back to the original PARSEOP_ALIAS */
837 
838         NextOp = Node->Op;
839 
840         /* The first child is the alias target op */
841 
842         NextOp = NextOp->Asl.Child;
843 
844         /* That in turn points back to original target alias node */
845 
846         if (NextOp->Asl.Node)
847         {
848             Node = NextOp->Asl.Node;
849         }
850 
851         /* Else - forward reference to alias, will be resolved later */
852     }
853 
854     /* 2) Check for a reference to a resource descriptor */
855 
856     if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
857         (Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
858     {
859         /*
860          * This was a reference to a field within a resource descriptor.
861          * Extract the associated field offset (either a bit or byte
862          * offset depending on the field type) and change the named
863          * reference into an integer for AML code generation
864          */
865         Offset = Node->Value;
866         TagBitLength = Node->Length;
867 
868         /*
869          * If a field is being created, generate the length (in bits) of
870          * the field. Note: Opcodes other than CreateXxxField and Index
871          * can come through here. For other opcodes, we just need to
872          * convert the resource tag reference to an integer offset.
873          */
874         switch (Op->Asl.Parent->Asl.AmlOpcode)
875         {
876         case AML_CREATE_FIELD_OP: /* Variable "Length" field, in bits */
877             /*
878              * We know the length operand is an integer constant because
879              * we know that it contains a reference to a resource
880              * descriptor tag.
881              */
882             FieldBitLength = (UINT32) Op->Asl.Next->Asl.Value.Integer;
883             break;
884 
885         case AML_CREATE_BIT_FIELD_OP:
886 
887             FieldBitLength = 1;
888             break;
889 
890         case AML_CREATE_BYTE_FIELD_OP:
891         case AML_INDEX_OP:
892 
893             FieldBitLength = 8;
894             break;
895 
896         case AML_CREATE_WORD_FIELD_OP:
897 
898             FieldBitLength = 16;
899             break;
900 
901         case AML_CREATE_DWORD_FIELD_OP:
902 
903             FieldBitLength = 32;
904             break;
905 
906         case AML_CREATE_QWORD_FIELD_OP:
907 
908             FieldBitLength = 64;
909             break;
910 
911         default:
912 
913             FieldBitLength = 0;
914             break;
915         }
916 
917         /* Check the field length against the length of the resource tag */
918 
919         if (FieldBitLength)
920         {
921             if (TagBitLength < FieldBitLength)
922             {
923                 Message = ASL_MSG_TAG_SMALLER;
924             }
925             else if (TagBitLength > FieldBitLength)
926             {
927                 Message = ASL_MSG_TAG_LARGER;
928             }
929 
930             if (Message)
931             {
932                 sprintf (AslGbl_MsgBuffer,
933                     "Size mismatch, Tag: %u bit%s, Field: %u bit%s",
934                     TagBitLength, (TagBitLength > 1) ? "s" : "",
935                     FieldBitLength, (FieldBitLength > 1) ? "s" : "");
936 
937                 AslError (ASL_WARNING, Message, Op, AslGbl_MsgBuffer);
938             }
939         }
940 
941         /* Convert the BitOffset to a ByteOffset for certain opcodes */
942 
943         switch (Op->Asl.Parent->Asl.AmlOpcode)
944         {
945         case AML_CREATE_BYTE_FIELD_OP:
946         case AML_CREATE_WORD_FIELD_OP:
947         case AML_CREATE_DWORD_FIELD_OP:
948         case AML_CREATE_QWORD_FIELD_OP:
949         case AML_INDEX_OP:
950 
951             Offset = ACPI_DIV_8 (Offset);
952             break;
953 
954         default:
955 
956             break;
957         }
958 
959         /* Now convert this node to an integer whose value is the field offset */
960 
961         Op->Asl.AmlLength = 0;
962         Op->Asl.ParseOpcode = PARSEOP_INTEGER;
963         Op->Asl.Value.Integer = (UINT64) Offset;
964         Op->Asl.CompileFlags |= OP_IS_RESOURCE_FIELD;
965 
966         OpcGenerateAmlOpcode (Op);
967     }
968 
969     /* 3) Check for a method invocation */
970 
971     else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) &&
972                 (Node->Type == ACPI_TYPE_METHOD) &&
973                 (Op->Asl.Parent) &&
974                 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD))   ||
975 
976                 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
977     {
978         /*
979          * A reference to a method within one of these opcodes is not an
980          * invocation of the method, it is simply a reference to the method.
981          *
982          * September 2016: Removed DeRefOf from this list
983          */
984         if ((Op->Asl.Parent) &&
985             ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF)     ||
986             (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_PACKAGE)    ||
987             (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)||
988             (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE)))
989         {
990             return_ACPI_STATUS (AE_OK);
991         }
992 
993         /*
994          * There are two types of method invocation:
995          * 1) Invocation with arguments -- the parser recognizes this
996          *    as a METHODCALL.
997          * 2) Invocation with no arguments --the parser cannot determine that
998          *    this is a method invocation, therefore we have to figure it out
999          *    here.
1000          */
1001         if (Node->Type != ACPI_TYPE_METHOD)
1002         {
1003             sprintf (AslGbl_MsgBuffer, "%s is a %s",
1004                 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
1005 
1006             AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, AslGbl_MsgBuffer);
1007             return_ACPI_STATUS (AE_OK);
1008         }
1009 
1010         /* Save the method node in the caller's op */
1011 
1012         Op->Asl.Node = Node;
1013         if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)
1014         {
1015             return_ACPI_STATUS (AE_OK);
1016         }
1017 
1018         /*
1019          * This is a method invocation, with or without arguments.
1020          * Count the number of arguments, each appears as a child
1021          * under the parent node
1022          */
1023         Op->Asl.ParseOpcode = PARSEOP_METHODCALL;
1024         UtSetParseOpName (Op);
1025 
1026         PassedArgs = 0;
1027         NextOp = Op->Asl.Child;
1028 
1029         while (NextOp)
1030         {
1031             PassedArgs++;
1032             NextOp = NextOp->Asl.Next;
1033         }
1034 
1035         if (Node->Value != ASL_EXTERNAL_METHOD &&
1036             Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL)
1037         {
1038             /*
1039              * Check the parsed arguments with the number expected by the
1040              * method declaration itself
1041              */
1042             if (PassedArgs != Node->Value)
1043             {
1044                 sprintf (AslGbl_MsgBuffer, "%s requires %u", Op->Asl.ExternalName,
1045                     Node->Value);
1046 
1047                 if (PassedArgs < Node->Value)
1048                 {
1049                     AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, AslGbl_MsgBuffer);
1050                 }
1051                 else
1052                 {
1053                     AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, AslGbl_MsgBuffer);
1054                 }
1055             }
1056         }
1057     }
1058 
1059     /* 4) Check for an ASL Field definition */
1060 
1061     else if ((Op->Asl.Parent) &&
1062             ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD)     ||
1063              (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD)))
1064     {
1065         /*
1066          * Offset checking for fields. If the parent operation region has a
1067          * constant length (known at compile time), we can check fields
1068          * defined in that region against the region length. This will catch
1069          * fields and field units that cannot possibly fit within the region.
1070          *
1071          * Note: Index fields do not directly reference an operation region,
1072          * thus they are not included in this check.
1073          */
1074         if (Op == Op->Asl.Parent->Asl.Child)
1075         {
1076             /*
1077              * This is the first child of the field node, which is
1078              * the name of the region. Get the parse node for the
1079              * region -- which contains the length of the region.
1080              */
1081             OwningOp = Node->Op;
1082             Op->Asl.Parent->Asl.ExtraValue =
1083                 ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer);
1084 
1085             /* Examine the field access width */
1086 
1087             switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer)
1088             {
1089             case AML_FIELD_ACCESS_ANY:
1090             case AML_FIELD_ACCESS_BYTE:
1091             case AML_FIELD_ACCESS_BUFFER:
1092             default:
1093 
1094                 MinimumLength = 1;
1095                 break;
1096 
1097             case AML_FIELD_ACCESS_WORD:
1098 
1099                 MinimumLength = 2;
1100                 break;
1101 
1102             case AML_FIELD_ACCESS_DWORD:
1103 
1104                 MinimumLength = 4;
1105                 break;
1106 
1107             case AML_FIELD_ACCESS_QWORD:
1108 
1109                 MinimumLength = 8;
1110                 break;
1111             }
1112 
1113             /*
1114              * Is the region at least as big as the access width?
1115              * Note: DataTableRegions have 0 length
1116              */
1117             if (((UINT32) OwningOp->Asl.Value.Integer) &&
1118                 ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength))
1119             {
1120                 AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL);
1121             }
1122 
1123             /*
1124              * Check EC/CMOS/SMBUS fields to make sure that the correct
1125              * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS)
1126              */
1127             SpaceIdOp = OwningOp->Asl.Child->Asl.Next;
1128             switch ((UINT32) SpaceIdOp->Asl.Value.Integer)
1129             {
1130             case ACPI_ADR_SPACE_EC:
1131             case ACPI_ADR_SPACE_CMOS:
1132             case ACPI_ADR_SPACE_GPIO:
1133 
1134                 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
1135                     AML_FIELD_ACCESS_BYTE)
1136                 {
1137                     AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL);
1138                 }
1139                 break;
1140 
1141             case ACPI_ADR_SPACE_SMBUS:
1142             case ACPI_ADR_SPACE_IPMI:
1143             case ACPI_ADR_SPACE_GSBUS:
1144 
1145                 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
1146                     AML_FIELD_ACCESS_BUFFER)
1147                 {
1148                     AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL);
1149                 }
1150                 break;
1151 
1152             default:
1153 
1154                 /* Nothing to do for other address spaces */
1155 
1156                 break;
1157             }
1158         }
1159         else
1160         {
1161             /*
1162              * This is one element of the field list. Check to make sure
1163              * that it does not go beyond the end of the parent operation region.
1164              *
1165              * In the code below:
1166              *    Op->Asl.Parent->Asl.ExtraValue      - Region Length (bits)
1167              *    Op->Asl.ExtraValue                  - Field start offset (bits)
1168              *    Op->Asl.Child->Asl.Value.Integer32  - Field length (bits)
1169              *    Op->Asl.Child->Asl.ExtraValue       - Field access width (bits)
1170              */
1171             if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child)
1172             {
1173                 XfCheckFieldRange (Op,
1174                     Op->Asl.Parent->Asl.ExtraValue,
1175                     Op->Asl.ExtraValue,
1176                     (UINT32) Op->Asl.Child->Asl.Value.Integer,
1177                     Op->Asl.Child->Asl.ExtraValue);
1178             }
1179         }
1180     }
1181 
1182     /* 5) Check for a connection object */
1183 #if 0
1184     else if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION)
1185     {
1186         return_ACPI_STATUS (Status);
1187     }
1188 #endif
1189 
1190     Op->Asl.Node = Node;
1191     return_ACPI_STATUS (Status);
1192 }
1193 
1194 
1195 /*******************************************************************************
1196  *
1197  * FUNCTION:    XfNamespaceLocateEnd
1198  *
1199  * PARAMETERS:  ASL_WALK_CALLBACK
1200  *
1201  * RETURN:      Status
1202  *
1203  * DESCRIPTION: Ascending callback used during cross reference. We only
1204  *              need to worry about scope management here.
1205  *
1206  ******************************************************************************/
1207 
1208 static ACPI_STATUS
1209 XfNamespaceLocateEnd (
1210     ACPI_PARSE_OBJECT       *Op,
1211     UINT32                  Level,
1212     void                    *Context)
1213 {
1214     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
1215     const ACPI_OPCODE_INFO  *OpInfo;
1216 
1217 
1218     ACPI_FUNCTION_TRACE (XfNamespaceLocateEnd);
1219 
1220 
1221     /* We are only interested in opcodes that have an associated name */
1222 
1223     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1224     if (!(OpInfo->Flags & AML_NAMED))
1225     {
1226         return_ACPI_STATUS (AE_OK);
1227     }
1228 
1229     /* Not interested in name references, we did not open a scope for them */
1230 
1231     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
1232         (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)    ||
1233         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
1234         (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
1235     {
1236         return_ACPI_STATUS (AE_OK);
1237     }
1238 
1239     /* Pop the scope stack if necessary */
1240 
1241     if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode)))
1242     {
1243 
1244         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1245             "%s: Popping scope for Op %p\n",
1246             AcpiUtGetTypeName (OpInfo->ObjectType), Op));
1247 
1248         (void) AcpiDsScopeStackPop (WalkState);
1249     }
1250 
1251     return_ACPI_STATUS (AE_OK);
1252 }
1253 
1254 
1255 /*******************************************************************************
1256  *
1257  * FUNCTION:    XfValidateCrossReference
1258  *
1259  * PARAMETERS:  Op                      - Parse Op that references the object
1260  *              OpInfo                  - Parse Op info struct
1261  *              Node                    - Node for the referenced object
1262  *
1263  * RETURN:      TRUE if the reference is legal, FALSE otherwise
1264  *
1265  * DESCRIPTION: Determine if a reference to another object is allowed.
1266  *
1267  * EXAMPLE:
1268  *      Method (A) {Name (INT1, 1)}     Declaration of object INT1
1269  *      Method (B) (Store (2, \A.INT1)} Illegal reference to object INT1
1270  *                                      (INT1 is temporary, valid only during
1271  *                                      execution of A)
1272  *
1273  * NOTES:
1274  *      A null pointer returned by either XfGetParentMethod or
1275  *      UtGetParentMethod indicates that the parameter object is not
1276  *      within a control method.
1277  *
1278  *      Five cases are handled: Case(Op, Node)
1279  *      1) Case(0,0): Op is not within a method, Node is not    --> OK
1280  *      2) Case(0,1): Op is not within a method, but Node is    --> Illegal
1281  *      3) Case(1,0): Op is within a method, Node is not        --> OK
1282  *      4) Case(1,1): Both are within the same method           --> OK
1283  *      5) Case(1,1): Both are in methods, but not same method  --> Illegal
1284  *
1285  ******************************************************************************/
1286 
1287 static BOOLEAN
1288 XfValidateCrossReference (
1289     ACPI_PARSE_OBJECT       *Op,
1290     const ACPI_OPCODE_INFO  *OpInfo,
1291     ACPI_NAMESPACE_NODE     *Node)
1292 {
1293     ACPI_PARSE_OBJECT       *ReferencingMethodOp;
1294     ACPI_NAMESPACE_NODE     *ReferencedMethodNode;
1295 
1296 
1297     /* Ignore actual named (and related) object declarations */
1298 
1299     if (OpInfo->Flags & (AML_NAMED | AML_CREATE | AML_DEFER | AML_HAS_ARGS))
1300     {
1301         return (TRUE);
1302     }
1303 
1304     /*
1305      * 1) Search upwards in parse tree for owner of the referencing object
1306      * 2) Search upwards in namespace to find the owner of the referenced object
1307      */
1308     ReferencingMethodOp = XfGetParentMethod (Op);
1309     ReferencedMethodNode = UtGetParentMethod (Node);
1310 
1311     if (!ReferencingMethodOp && !ReferencedMethodNode)
1312     {
1313         /*
1314          * 1) Case (0,0): Both Op and Node are not within methods
1315          * --> OK
1316          */
1317         return (TRUE);
1318     }
1319 
1320     if (!ReferencingMethodOp && ReferencedMethodNode)
1321     {
1322         /*
1323          * 2) Case (0,1): Op is not in a method, but Node is within a
1324          * method --> illegal
1325          */
1326         return (FALSE);
1327     }
1328     else if (ReferencingMethodOp && !ReferencedMethodNode)
1329     {
1330         /*
1331          * 3) Case (1,0): Op is within a method, but Node is not
1332          * --> OK
1333          */
1334         return (TRUE);
1335     }
1336     else if (ReferencingMethodOp->Asl.Node == ReferencedMethodNode)
1337     {
1338         /*
1339          * 4) Case (1,1): Both Op and Node are within the same method
1340          * --> OK
1341          */
1342         return (TRUE);
1343     }
1344     else
1345     {
1346         /*
1347          * 5) Case (1,1), Op and Node are in different methods
1348          * --> Illegal
1349          */
1350         return (FALSE);
1351     }
1352 }
1353