1 /******************************************************************************
2  *
3  * Module Name: aslmethod.c - Control method analysis walk
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 "aslcompiler.h"
153 #include "aslcompiler.y.h"
154 #include "acnamesp.h"
155 #include "acparser.h"
156 #include "amlcode.h"
157 
158 
159 #define _COMPONENT          ACPI_COMPILER
160         ACPI_MODULE_NAME    ("aslmethod")
161 
162 
163 /* Local prototypes */
164 
165 static void
166 MtCheckNamedObjectInMethod (
167     ACPI_PARSE_OBJECT       *Op,
168     ASL_METHOD_INFO         *MethodInfo);
169 
170 static void
171 MtCheckStaticOperationRegionInMethod (
172     ACPI_PARSE_OBJECT       *Op);
173 
174 
175 /*******************************************************************************
176  *
177  * FUNCTION:    MtMethodAnalysisWalkBegin
178  *
179  * PARAMETERS:  ASL_WALK_CALLBACK
180  *
181  * RETURN:      Status
182  *
183  * DESCRIPTION: Descending callback for the analysis walk. Check methods for:
184  *              1) Initialized local variables
185  *              2) Valid arguments
186  *              3) Return types
187  *
188  ******************************************************************************/
189 
190 ACPI_STATUS
191 MtMethodAnalysisWalkBegin (
192     ACPI_PARSE_OBJECT       *Op,
193     UINT32                  Level,
194     void                    *Context)
195 {
196     ASL_ANALYSIS_WALK_INFO  *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
197     ASL_METHOD_INFO         *MethodInfo = WalkInfo->MethodStack;
198     ACPI_PARSE_OBJECT       *Next;
199     UINT32                  RegisterNumber;
200     UINT32                  i;
201     char                    LocalName[] = "Local0";
202     char                    ArgName[] = "Arg0";
203     ACPI_PARSE_OBJECT       *ArgNode;
204     ACPI_PARSE_OBJECT       *NextType;
205     UINT8                   ActualArgs = 0;
206     BOOLEAN                 HidExists;
207     BOOLEAN                 AdrExists;
208 
209 
210     /* Build cross-reference output file if requested */
211 
212     if (AslGbl_CrossReferenceOutput)
213     {
214         OtXrefWalkPart1 (Op, Level, MethodInfo);
215     }
216 
217     switch (Op->Asl.ParseOpcode)
218     {
219     case PARSEOP_METHOD:
220 
221         AslGbl_TotalMethods++;
222 
223         /* Create and init method info */
224 
225         MethodInfo = UtLocalCalloc (sizeof (ASL_METHOD_INFO));
226         MethodInfo->Next = WalkInfo->MethodStack;
227         MethodInfo->Op = Op;
228 
229         WalkInfo->MethodStack = MethodInfo;
230 
231         /*
232          * Special handling for _PSx methods. Dependency rules (same scope):
233          *
234          * 1) _PS0 - One of these must exist: _PS1, _PS2, _PS3
235          * 2) _PS1/_PS2/_PS3: A _PS0 must exist
236          */
237         if (ACPI_COMPARE_NAMESEG (METHOD_NAME__PS0, Op->Asl.NameSeg))
238         {
239             /* For _PS0, one of _PS1/_PS2/_PS3 must exist */
240 
241             if ((!ApFindNameInScope (METHOD_NAME__PS1, Op)) &&
242                 (!ApFindNameInScope (METHOD_NAME__PS2, Op)) &&
243                 (!ApFindNameInScope (METHOD_NAME__PS3, Op)))
244             {
245                 AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
246                     "_PS0 requires one of _PS1/_PS2/_PS3 in same scope");
247             }
248         }
249         else if (
250             ACPI_COMPARE_NAMESEG (METHOD_NAME__PS1, Op->Asl.NameSeg) ||
251             ACPI_COMPARE_NAMESEG (METHOD_NAME__PS2, Op->Asl.NameSeg) ||
252             ACPI_COMPARE_NAMESEG (METHOD_NAME__PS3, Op->Asl.NameSeg))
253         {
254             /* For _PS1/_PS2/_PS3, a _PS0 must exist */
255 
256             if (!ApFindNameInScope (METHOD_NAME__PS0, Op))
257             {
258                 sprintf (AslGbl_MsgBuffer,
259                     "%4.4s requires _PS0 in same scope", Op->Asl.NameSeg);
260 
261                 AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
262                     AslGbl_MsgBuffer);
263             }
264         }
265 
266         /* Get the name node */
267 
268         Next = Op->Asl.Child;
269 
270         /* Get the NumArguments node */
271 
272         Next = Next->Asl.Next;
273         MethodInfo->NumArguments = (UINT8)
274             (((UINT8) Next->Asl.Value.Integer) & 0x07);
275 
276         /* Get the SerializeRule and SyncLevel nodes, ignored here */
277 
278         Next = Next->Asl.Next;
279         MethodInfo->ShouldBeSerialized = (UINT8) Next->Asl.Value.Integer;
280 
281         Next = Next->Asl.Next;
282         ArgNode = Next;
283 
284         /* Get the ReturnType node */
285 
286         Next = Next->Asl.Next;
287 
288         NextType = Next->Asl.Child;
289 
290         MethodInfo->ValidReturnTypes = MtProcessTypeOp (NextType);
291         Op->Asl.AcpiBtype |= MethodInfo->ValidReturnTypes;
292 
293         /* Get the ParameterType node */
294 
295         Next = Next->Asl.Next;
296 
297         NextType = Next->Asl.Child;
298         if (!NextType)
299         {
300             /*
301              * The optional parameter types list was omitted  at the source
302              * level. Use the Argument count parameter instead.
303              */
304             ActualArgs = MethodInfo->NumArguments;
305         }
306         else
307         {
308             ActualArgs = MtProcessParameterTypeList (NextType,
309                 MethodInfo->ValidArgTypes);
310             MethodInfo->NumArguments = ActualArgs;
311             ArgNode->Asl.Value.Integer |= ActualArgs;
312         }
313 
314         if ((MethodInfo->NumArguments) &&
315             (MethodInfo->NumArguments != ActualArgs))
316         {
317             sprintf (AslGbl_MsgBuffer,
318                 "Length = %u", ActualArgs);
319             AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_MISMATCH,
320                 Op->Asl.Child->Asl.Next, AslGbl_MsgBuffer);
321         }
322 
323         /* Allow numarguments == 0 for Function() */
324 
325         if ((!MethodInfo->NumArguments) && (ActualArgs))
326         {
327             MethodInfo->NumArguments = ActualArgs;
328             ArgNode->Asl.Value.Integer |= ActualArgs;
329         }
330 
331         /*
332          * Actual arguments are initialized at method entry.
333          * All other ArgX "registers" can be used as locals, so we
334          * track their initialization.
335          */
336         for (i = 0; i < MethodInfo->NumArguments; i++)
337         {
338             MethodInfo->ArgInitialized[i] = TRUE;
339         }
340         break;
341 
342     case PARSEOP_METHODCALL:
343 
344         /* Check for a recursive method call */
345 
346         if (MethodInfo &&
347            (Op->Asl.Node == MethodInfo->Op->Asl.Node))
348         {
349             if (MethodInfo->CreatesNamedObjects)
350             {
351                 /*
352                  * This is an error, as it will fail at runtime on all ACPI
353                  * implementations. Any named object declarations will be
354                  * executed twice, causing failure the second time. Note,
355                  * this is independent of whether the method is declared
356                  * Serialized, because the same thread is attempting to
357                  * reenter the method, and this will always succeed.
358                  */
359                 AslDualParseOpError (ASL_ERROR, ASL_MSG_ILLEGAL_RECURSION, Op,
360                     Op->Asl.Value.String, ASL_MSG_FOUND_HERE, MethodInfo->Op,
361                     MethodInfo->Op->Asl.ExternalName);
362             }
363             else
364             {
365                 /* Method does not create objects, issue a remark */
366 
367                 AslError (ASL_REMARK, ASL_MSG_RECURSION, Op, Op->Asl.ExternalName);
368             }
369         }
370         break;
371 
372     case PARSEOP_LOCAL0:
373     case PARSEOP_LOCAL1:
374     case PARSEOP_LOCAL2:
375     case PARSEOP_LOCAL3:
376     case PARSEOP_LOCAL4:
377     case PARSEOP_LOCAL5:
378     case PARSEOP_LOCAL6:
379     case PARSEOP_LOCAL7:
380 
381         if (!MethodInfo)
382         {
383             /*
384              * Local was used outside a control method, or there was an error
385              * in the method declaration.
386              */
387             AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD,
388                 Op, Op->Asl.ExternalName);
389             return (AE_ERROR);
390         }
391 
392         RegisterNumber = (Op->Asl.AmlOpcode & 0x0007);
393 
394         /*
395          * If the local is being used as a target, mark the local
396          * initialized
397          */
398         if (Op->Asl.CompileFlags & OP_IS_TARGET)
399         {
400             MethodInfo->LocalInitialized[RegisterNumber] = TRUE;
401         }
402 
403         /*
404          * Otherwise, this is a reference, check if the local
405          * has been previously initialized.
406          *
407          * The only operator that accepts an uninitialized value is ObjectType()
408          */
409         else if ((!MethodInfo->LocalInitialized[RegisterNumber]) &&
410                  (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
411         {
412             LocalName[strlen (LocalName) -1] = (char) (RegisterNumber + 0x30);
413             AslError (ASL_ERROR, ASL_MSG_LOCAL_INIT, Op, LocalName);
414         }
415         break;
416 
417     case PARSEOP_ARG0:
418     case PARSEOP_ARG1:
419     case PARSEOP_ARG2:
420     case PARSEOP_ARG3:
421     case PARSEOP_ARG4:
422     case PARSEOP_ARG5:
423     case PARSEOP_ARG6:
424 
425         if (!MethodInfo)
426         {
427             /*
428              * Arg was used outside a control method, or there was an error
429              * in the method declaration.
430              */
431             AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD,
432                 Op, Op->Asl.ExternalName);
433             return (AE_ERROR);
434         }
435 
436         RegisterNumber = (Op->Asl.AmlOpcode & 0x000F) - 8;
437         ArgName[strlen (ArgName) -1] = (char) (RegisterNumber + 0x30);
438 
439         /*
440          * If the Arg is being used as a target, mark the local
441          * initialized
442          */
443         if (Op->Asl.CompileFlags & OP_IS_TARGET)
444         {
445             MethodInfo->ArgInitialized[RegisterNumber] = TRUE;
446         }
447 
448         /*
449          * Otherwise, this is a reference, check if the Arg
450          * has been previously initialized.
451          *
452          * The only operator that accepts an uninitialized value is ObjectType()
453          */
454         else if ((!MethodInfo->ArgInitialized[RegisterNumber]) &&
455             (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
456         {
457             AslError (ASL_ERROR, ASL_MSG_ARG_INIT, Op, ArgName);
458         }
459 
460         /* Flag this arg if it is not a "real" argument to the method */
461 
462         if (RegisterNumber >= MethodInfo->NumArguments)
463         {
464             AslError (ASL_REMARK, ASL_MSG_NOT_PARAMETER, Op, ArgName);
465         }
466         break;
467 
468     case PARSEOP_RETURN:
469 
470         if (!MethodInfo)
471         {
472             /*
473              * Probably was an error in the method declaration,
474              * no additional error here
475              */
476             ACPI_WARNING ((AE_INFO, "%p, No parent method", Op));
477             return (AE_ERROR);
478         }
479 
480         /*
481          * A child indicates a possible return value. A simple Return or
482          * Return() is marked with OP_IS_NULL_RETURN by the parser so
483          * that it is not counted as a "real" return-with-value, although
484          * the AML code that is actually emitted is Return(0). The AML
485          * definition of Return has a required parameter, so we are
486          * forced to convert a null return to Return(0).
487          */
488         if ((Op->Asl.Child) &&
489             (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
490             (!(Op->Asl.Child->Asl.CompileFlags & OP_IS_NULL_RETURN)))
491         {
492             MethodInfo->NumReturnWithValue++;
493         }
494         else
495         {
496             MethodInfo->NumReturnNoValue++;
497         }
498         break;
499 
500     case PARSEOP_BREAK:
501     case PARSEOP_CONTINUE:
502 
503         Next = Op->Asl.Parent;
504         while (Next)
505         {
506             if (Next->Asl.ParseOpcode == PARSEOP_WHILE)
507             {
508                 break;
509             }
510             Next = Next->Asl.Parent;
511         }
512 
513         if (!Next)
514         {
515             AslError (ASL_ERROR, ASL_MSG_NO_WHILE, Op, NULL);
516         }
517         break;
518 
519     case PARSEOP_STALL:
520 
521         /* We can range check if the argument is an integer */
522 
523         if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) &&
524             (Op->Asl.Child->Asl.Value.Integer > ACPI_UINT8_MAX))
525         {
526             AslError (ASL_ERROR, ASL_MSG_INVALID_TIME, Op, NULL);
527         }
528         break;
529 
530     case PARSEOP_DEVICE:
531 
532         /* Check usage of _HID and _ADR objects */
533 
534         HidExists = ApFindNameInDeviceTree (METHOD_NAME__HID, Op);
535         AdrExists = ApFindNameInDeviceTree (METHOD_NAME__ADR, Op);
536 
537         if (!HidExists && !AdrExists)
538         {
539             AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
540                 "Device object requires a _HID or _ADR in same scope");
541         }
542         else if (HidExists && AdrExists)
543         {
544             /*
545              * According to the ACPI spec, "A device object must contain
546              * either an _HID object or an _ADR object, but should not contain
547              * both".
548              */
549             AslError (ASL_WARNING, ASL_MSG_MULTIPLE_TYPES, Op,
550                 "Device object requires either a _HID or _ADR, but not both");
551         }
552         break;
553 
554     case PARSEOP_EVENT:
555     case PARSEOP_MUTEX:
556     case PARSEOP_OPERATIONREGION:
557     case PARSEOP_POWERRESOURCE:
558     case PARSEOP_PROCESSOR:
559     case PARSEOP_THERMALZONE:
560 
561         /*
562          * The first operand is a name to be created in the namespace.
563          * Check against the reserved list.
564          */
565         i = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
566         if (i < ACPI_VALID_RESERVED_NAME_MAX)
567         {
568             AslError (ASL_ERROR, ASL_MSG_RESERVED_USE,
569                 Op, Op->Asl.ExternalName);
570         }
571 
572         MtCheckStaticOperationRegionInMethod (Op);
573         break;
574 
575     case PARSEOP_NAME:
576 
577         /* Typecheck any predefined names statically defined with Name() */
578 
579         ApCheckForPredefinedObject (Op, Op->Asl.NameSeg);
580 
581         /* Special typechecking for _HID */
582 
583         if (ACPI_COMPARE_NAMESEG (METHOD_NAME__HID, Op->Asl.NameSeg))
584         {
585             Next = Op->Asl.Child->Asl.Next;
586             AnCheckId (Next, ASL_TYPE_HID);
587         }
588 
589         /* Special typechecking for _CID */
590 
591         else if (ACPI_COMPARE_NAMESEG (METHOD_NAME__CID, Op->Asl.NameSeg))
592         {
593             Next = Op->Asl.Child->Asl.Next;
594 
595             if ((Next->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
596                 (Next->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE))
597             {
598                 Next = Next->Asl.Child;
599                 while (Next)
600                 {
601                     AnCheckId (Next, ASL_TYPE_CID);
602                     Next = Next->Asl.Next;
603                 }
604             }
605             else
606             {
607                 AnCheckId (Next, ASL_TYPE_CID);
608             }
609         }
610 
611         break;
612 
613     default:
614 
615         break;
616     }
617 
618     /* Check for named object creation within a non-serialized method */
619 
620     MtCheckNamedObjectInMethod (Op, MethodInfo);
621     return (AE_OK);
622 }
623 
624 
625 /*******************************************************************************
626  *
627  * FUNCTION:    MtProcessTypeOp
628  *
629  * PARAMETERS:  Op                  - Op representing a btype
630  *
631  * RETURN:      Btype represented by Op
632  *
633  * DESCRIPTION: Process a parse object that represents single parameter type or
634  *              a return type in method, function, and external declarations.
635  *
636  ******************************************************************************/
637 
638 UINT32
639 MtProcessTypeOp (
640     ACPI_PARSE_OBJECT       *TypeOp)
641 {
642     UINT32                  Btype = ACPI_BTYPE_ANY;
643 
644 
645     while (TypeOp)
646     {
647         Btype |= AnMapObjTypeToBtype (TypeOp);
648         TypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
649         TypeOp = TypeOp->Asl.Next;
650     }
651 
652     return (Btype);
653 }
654 
655 
656 /*******************************************************************************
657  *
658  * FUNCTION:    MtProcessParameterTypeList
659  *
660  * PARAMETERS:  Op                  - Op representing a btype
661  *
662  * RETURN:      Btype represented by Op
663  *
664  * DESCRIPTION: Process a parse object that represents a parameter type list in
665  *              method, function, and external declarations.
666  *
667  ******************************************************************************/
668 
669 UINT8
670 MtProcessParameterTypeList (
671     ACPI_PARSE_OBJECT       *ParamTypeOp,
672     UINT32                  *TypeList)
673 {
674     UINT8                   ParameterCount = 0;
675 
676 
677     if (ParamTypeOp && ParamTypeOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
678     {
679         /* Special case for a single parameter without braces */
680 
681         TypeList[ParameterCount] =
682             MtProcessTypeOp (ParamTypeOp);
683 
684         return (1);
685     }
686 
687     while (ParamTypeOp)
688     {
689         TypeList[ParameterCount] =
690             MtProcessTypeOp (ParamTypeOp->Asl.Child);
691 
692         ParameterCount++;
693         ParamTypeOp = ParamTypeOp->Asl.Next;
694     }
695 
696     return (ParameterCount);
697 }
698 
699 
700 /*******************************************************************************
701  *
702  * FUNCTION:    MtCheckNamedObjectInMethod
703  *
704  * PARAMETERS:  Op                  - Current parser op
705  *              MethodInfo          - Info for method being parsed
706  *
707  * RETURN:      None
708  *
709  * DESCRIPTION: Detect if a non-serialized method is creating a named object,
710  *              which could possibly cause problems if two threads execute
711  *              the method concurrently. Emit a remark in this case.
712  *
713  ******************************************************************************/
714 
715 static void
716 MtCheckNamedObjectInMethod (
717     ACPI_PARSE_OBJECT       *Op,
718     ASL_METHOD_INFO         *MethodInfo)
719 {
720     const ACPI_OPCODE_INFO  *OpInfo;
721     char                    *ExternalPath;
722 
723 
724     /* We don't care about actual method declarations or scopes */
725 
726     if ((Op->Asl.AmlOpcode == AML_METHOD_OP) ||
727         (Op->Asl.AmlOpcode == AML_SCOPE_OP))
728     {
729         return;
730     }
731 
732     /* Determine if we are creating a named object within a method */
733 
734     if (!MethodInfo)
735     {
736         return;
737     }
738 
739     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
740     if ((OpInfo->Class == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_FIELD_OP))
741     {
742         /*
743          * 1) Mark the method as a method that creates named objects.
744          *
745          * 2) Issue a remark indicating the inefficiency of creating named
746          * objects within a method (Except for compiler-emitted temporary
747          * variables).
748          *
749          * 3) If the method is non-serialized, emit a remark that the method
750          * should be serialized.
751          *
752          * Reason: If a thread blocks within the method for any reason, and
753          * another thread enters the method, the method will fail because
754          * an attempt will be made to create the same object twice.
755          *
756          * Note: The Field opcode is disallowed here because Field() does not
757          * create a new named object.
758          */
759         ExternalPath = AcpiNsGetNormalizedPathname (MethodInfo->Op->Asl.Node, TRUE);
760 
761         /* No error for compiler temp variables (name starts with "_T_") */
762 
763         if ((Op->Asl.NameSeg[0] != '_') &&
764             (Op->Asl.NameSeg[1] != 'T') &&
765             (Op->Asl.NameSeg[2] != '_'))
766         {
767             AslError (ASL_REMARK, ASL_MSG_NAMED_OBJECT_CREATION, Op,
768                 ExternalPath);
769         }
770 
771         MethodInfo->CreatesNamedObjects = TRUE;
772         if (!MethodInfo->ShouldBeSerialized)
773         {
774             AslError (ASL_REMARK, ASL_MSG_SERIALIZED_REQUIRED, MethodInfo->Op,
775                 ExternalPath);
776 
777             /* Emit message only ONCE per method */
778 
779             MethodInfo->ShouldBeSerialized = TRUE;
780         }
781 
782         if (ExternalPath)
783         {
784             ACPI_FREE (ExternalPath);
785         }
786     }
787 }
788 
789 
790 /*******************************************************************************
791  *
792  * FUNCTION:    MtCheckStaticOperationRegionInMethod
793  *
794  * PARAMETERS:  Op                  - Current parser op
795  *
796  * RETURN:      None
797  *
798  * DESCRIPTION: Warns if an Operation Region with static address or length
799  *              is declared inside a control method
800  *
801  ******************************************************************************/
802 
803 static void
804 MtCheckStaticOperationRegionInMethod(
805     ACPI_PARSE_OBJECT*       Op)
806 {
807     ACPI_PARSE_OBJECT*       AddressOp;
808     ACPI_PARSE_OBJECT*       LengthOp;
809 
810 
811     if (Op->Asl.ParseOpcode != PARSEOP_OPERATIONREGION)
812     {
813         return;
814     }
815 
816     /*
817      * OperationRegion should have 4 arguments defined. At this point, we
818      * assume that the parse tree is well-formed.
819      */
820     AddressOp = Op->Asl.Child->Asl.Next->Asl.Next;
821     LengthOp = Op->Asl.Child->Asl.Next->Asl.Next->Asl.Next;
822 
823     if (UtGetParentMethodOp (Op) &&
824         AddressOp->Asl.ParseOpcode == PARSEOP_INTEGER &&
825         LengthOp->Asl.ParseOpcode == PARSEOP_INTEGER)
826     {
827         /*
828          * At this point, a static operation region declared inside of a
829          * control method has been found. Throw a warning because this is
830          * highly inefficient.
831          */
832         AslError(ASL_WARNING, ASL_MSG_STATIC_OPREGION_IN_METHOD, Op, NULL);
833     }
834 
835     return;
836 }
837 
838 
839 /*******************************************************************************
840  *
841  * FUNCTION:    MtMethodAnalysisWalkEnd
842  *
843  * PARAMETERS:  ASL_WALK_CALLBACK
844  *
845  * RETURN:      Status
846  *
847  * DESCRIPTION: Ascending callback for analysis walk. Complete method
848  *              return analysis.
849  *
850  ******************************************************************************/
851 
852 ACPI_STATUS
853 MtMethodAnalysisWalkEnd (
854     ACPI_PARSE_OBJECT       *Op,
855     UINT32                  Level,
856     void                    *Context)
857 {
858     ASL_ANALYSIS_WALK_INFO  *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
859     ASL_METHOD_INFO         *MethodInfo = WalkInfo->MethodStack;
860     char                    *ExternalPath;
861 
862 
863     switch (Op->Asl.ParseOpcode)
864     {
865     case PARSEOP_METHOD:
866     case PARSEOP_RETURN:
867 
868         if (!MethodInfo)
869         {
870             printf ("No method info for method! [%s]\n", Op->Asl.Namepath);
871             AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
872                 "No method info for this method");
873 
874             CmCleanupAndExit ();
875             return (AE_AML_INTERNAL);
876         }
877         break;
878 
879     default:
880 
881         break;
882     }
883 
884     switch (Op->Asl.ParseOpcode)
885     {
886     case PARSEOP_METHOD:
887 
888         WalkInfo->MethodStack = MethodInfo->Next;
889 
890         /*
891          * Check if there is no return statement at the end of the
892          * method AND we can actually get there -- i.e., the execution
893          * of the method can possibly terminate without a return statement.
894          */
895         if ((!AnLastStatementIsReturn (Op)) &&
896             (!(Op->Asl.CompileFlags & OP_HAS_NO_EXIT)))
897         {
898             /*
899              * No return statement, and execution can possibly exit
900              * via this path. This is equivalent to Return ()
901              */
902             MethodInfo->NumReturnNoValue++;
903         }
904 
905         /*
906          * Check for case where some return statements have a return value
907          * and some do not. Exit without a return statement is a return with
908          * no value
909          */
910         if (MethodInfo->NumReturnNoValue &&
911             MethodInfo->NumReturnWithValue)
912         {
913             ExternalPath = AcpiNsGetNormalizedPathname (Op->Asl.Node, TRUE);
914 
915             AslError (ASL_WARNING, ASL_MSG_RETURN_TYPES, Op,
916                 ExternalPath);
917 
918             if (ExternalPath)
919             {
920                 ACPI_FREE (ExternalPath);
921             }
922         }
923 
924         /*
925          * If there are any RETURN() statements with no value, or there is a
926          * control path that allows the method to exit without a return value,
927          * we mark the method as a method that does not return a value. This
928          * knowledge can be used to check method invocations that expect a
929          * returned value.
930          */
931         if (MethodInfo->NumReturnNoValue)
932         {
933             if (MethodInfo->NumReturnWithValue)
934             {
935                 Op->Asl.CompileFlags |= OP_METHOD_SOME_NO_RETVAL;
936             }
937             else
938             {
939                 Op->Asl.CompileFlags |= OP_METHOD_NO_RETVAL;
940             }
941         }
942 
943         /*
944          * Check predefined method names for correct return behavior
945          * and correct number of arguments. Also, some special checks
946          * For GPE and _REG methods.
947          */
948         if (ApCheckForPredefinedMethod (Op, MethodInfo))
949         {
950             /* Special check for two names like _L01 and _E01 in same scope */
951 
952             ApCheckForGpeNameConflict (Op);
953 
954             /*
955              * Special check for _REG: Must have an operation region definition
956              * within the same scope!
957              */
958             ApCheckRegMethod (Op);
959         }
960 
961         ACPI_FREE (MethodInfo);
962         break;
963 
964     case PARSEOP_NAME:
965 
966          /* Special check for two names like _L01 and _E01 in same scope */
967 
968         ApCheckForGpeNameConflict (Op);
969         break;
970 
971     case PARSEOP_RETURN:
972 
973         /*
974          * If the parent is a predefined method name, attempt to typecheck
975          * the return value. Only static types can be validated.
976          */
977         ApCheckPredefinedReturnValue (Op, MethodInfo);
978 
979         /*
980          * The parent block does not "exit" and continue execution -- the
981          * method is terminated here with the Return() statement.
982          */
983         Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT;
984 
985         /* Used in the "typing" pass later */
986 
987         Op->Asl.ParentMethod = MethodInfo->Op;
988 
989         /*
990          * If there is a peer node after the return statement, then this
991          * node is unreachable code -- i.e., it won't be executed because of
992          * the preceding Return() statement.
993          */
994         if (Op->Asl.Next)
995         {
996             AslError (ASL_WARNING, ASL_MSG_UNREACHABLE_CODE,
997                 Op->Asl.Next, NULL);
998         }
999         break;
1000 
1001     case PARSEOP_IF:
1002 
1003         if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) &&
1004             (Op->Asl.Next) &&
1005             (Op->Asl.Next->Asl.ParseOpcode == PARSEOP_ELSE))
1006         {
1007             /*
1008              * This IF has a corresponding ELSE. The IF block has no exit,
1009              * (it contains an unconditional Return)
1010              * mark the ELSE block to remember this fact.
1011              */
1012             Op->Asl.Next->Asl.CompileFlags |= OP_IF_HAS_NO_EXIT;
1013         }
1014         break;
1015 
1016     case PARSEOP_ELSE:
1017 
1018         if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) &&
1019             (Op->Asl.CompileFlags & OP_IF_HAS_NO_EXIT))
1020         {
1021             /*
1022              * This ELSE block has no exit and the corresponding IF block
1023              * has no exit either. Therefore, the parent node has no exit.
1024              */
1025             Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT;
1026         }
1027         break;
1028 
1029 
1030     default:
1031 
1032         if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) &&
1033             (Op->Asl.Parent))
1034         {
1035             /* If this node has no exit, then the parent has no exit either */
1036 
1037             Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT;
1038         }
1039         break;
1040     }
1041 
1042     return (AE_OK);
1043 }
1044