1 /******************************************************************************
3 * Module Name: aslmethod.c - Control method analysis walk
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2020, Intel Corp.
12 * All rights reserved.
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
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
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;
37 * The above copyright and patent license is granted only if the following
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.
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
80 * 4. Disclaimer and Export Compliance
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
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
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.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
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.
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.
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.
150 *****************************************************************************/
152 #include <contrib/dev/acpica/compiler/aslcompiler.h>
153 #include "aslcompiler.y.h"
154 #include <contrib/dev/acpica/include/acnamesp.h>
155 #include <contrib/dev/acpica/include/acparser.h>
156 #include <contrib/dev/acpica/include/amlcode.h>
159 #define _COMPONENT ACPI_COMPILER
160 ACPI_MODULE_NAME ("aslmethod")
163 /* Local prototypes */
166 MtCheckNamedObjectInMethod (
167 ACPI_PARSE_OBJECT *Op,
168 ASL_METHOD_INFO *MethodInfo);
171 MtCheckStaticOperationRegionInMethod (
172 ACPI_PARSE_OBJECT *Op);
175 /*******************************************************************************
177 * FUNCTION: MtMethodAnalysisWalkBegin
179 * PARAMETERS: ASL_WALK_CALLBACK
183 * DESCRIPTION: Descending callback for the analysis walk. Check methods for:
184 * 1) Initialized local variables
188 ******************************************************************************/
191 MtMethodAnalysisWalkBegin (
192 ACPI_PARSE_OBJECT *Op,
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;
201 char LocalName[] = "Local0";
202 char ArgName[] = "Arg0";
203 ACPI_PARSE_OBJECT *ArgNode;
204 ACPI_PARSE_OBJECT *NextType;
205 UINT8 ActualArgs = 0;
210 /* Build cross-reference output file if requested */
212 if (AslGbl_CrossReferenceOutput)
214 OtXrefWalkPart1 (Op, Level, MethodInfo);
217 switch (Op->Asl.ParseOpcode)
221 AslGbl_TotalMethods++;
223 /* Create and init method info */
225 MethodInfo = UtLocalCalloc (sizeof (ASL_METHOD_INFO));
226 MethodInfo->Next = WalkInfo->MethodStack;
229 WalkInfo->MethodStack = MethodInfo;
232 * Special handling for _PSx methods. Dependency rules (same scope):
234 * 1) _PS0 - One of these must exist: _PS1, _PS2, _PS3
235 * 2) _PS1/_PS2/_PS3: A _PS0 must exist
237 if (ACPI_COMPARE_NAMESEG (METHOD_NAME__PS0, Op->Asl.NameSeg))
239 /* For _PS0, one of _PS1/_PS2/_PS3 must exist */
241 if ((!ApFindNameInScope (METHOD_NAME__PS1, Op)) &&
242 (!ApFindNameInScope (METHOD_NAME__PS2, Op)) &&
243 (!ApFindNameInScope (METHOD_NAME__PS3, Op)))
245 AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
246 "_PS0 requires one of _PS1/_PS2/_PS3 in same scope");
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))
254 /* For _PS1/_PS2/_PS3, a _PS0 must exist */
256 if (!ApFindNameInScope (METHOD_NAME__PS0, Op))
258 sprintf (AslGbl_MsgBuffer,
259 "%4.4s requires _PS0 in same scope", Op->Asl.NameSeg);
261 AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
266 /* Get the name node */
268 Next = Op->Asl.Child;
270 /* Get the NumArguments node */
272 Next = Next->Asl.Next;
273 MethodInfo->NumArguments = (UINT8)
274 (((UINT8) Next->Asl.Value.Integer) & 0x07);
276 /* Get the SerializeRule and SyncLevel nodes, ignored here */
278 Next = Next->Asl.Next;
279 MethodInfo->ShouldBeSerialized = (UINT8) Next->Asl.Value.Integer;
281 Next = Next->Asl.Next;
284 /* Get the ReturnType node */
286 Next = Next->Asl.Next;
288 NextType = Next->Asl.Child;
290 MethodInfo->ValidReturnTypes = MtProcessTypeOp (NextType);
292 /* Get the ParameterType node */
294 Next = Next->Asl.Next;
296 NextType = Next->Asl.Child;
300 * The optional parameter types list was omitted at the source
301 * level. Use the Argument count parameter instead.
303 ActualArgs = MethodInfo->NumArguments;
307 ActualArgs = MtProcessParameterTypeList (NextType,
308 MethodInfo->ValidArgTypes);
309 MethodInfo->NumArguments = ActualArgs;
310 ArgNode->Asl.Value.Integer |= ActualArgs;
313 if ((MethodInfo->NumArguments) &&
314 (MethodInfo->NumArguments != ActualArgs))
316 sprintf (AslGbl_MsgBuffer,
317 "Length = %u", ActualArgs);
318 AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_MISMATCH,
319 Op->Asl.Child->Asl.Next, AslGbl_MsgBuffer);
322 /* Allow numarguments == 0 for Function() */
324 if ((!MethodInfo->NumArguments) && (ActualArgs))
326 MethodInfo->NumArguments = ActualArgs;
327 ArgNode->Asl.Value.Integer |= ActualArgs;
331 * Actual arguments are initialized at method entry.
332 * All other ArgX "registers" can be used as locals, so we
333 * track their initialization.
335 for (i = 0; i < MethodInfo->NumArguments; i++)
337 MethodInfo->ArgInitialized[i] = TRUE;
341 case PARSEOP_METHODCALL:
343 /* Check for a recursive method call */
346 (Op->Asl.Node == MethodInfo->Op->Asl.Node))
348 if (MethodInfo->CreatesNamedObjects)
351 * This is an error, as it will fail at runtime on all ACPI
352 * implementations. Any named object declarations will be
353 * executed twice, causing failure the second time. Note,
354 * this is independent of whether the method is declared
355 * Serialized, because the same thread is attempting to
356 * reenter the method, and this will always succeed.
358 AslDualParseOpError (ASL_ERROR, ASL_MSG_ILLEGAL_RECURSION, Op,
359 Op->Asl.Value.String, ASL_MSG_FOUND_HERE, MethodInfo->Op,
360 MethodInfo->Op->Asl.ExternalName);
364 /* Method does not create objects, issue a remark */
366 AslError (ASL_REMARK, ASL_MSG_RECURSION, Op, Op->Asl.ExternalName);
383 * Local was used outside a control method, or there was an error
384 * in the method declaration.
386 AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD,
387 Op, Op->Asl.ExternalName);
391 RegisterNumber = (Op->Asl.AmlOpcode & 0x0007);
394 * If the local is being used as a target, mark the local
397 if (Op->Asl.CompileFlags & OP_IS_TARGET)
399 MethodInfo->LocalInitialized[RegisterNumber] = TRUE;
403 * Otherwise, this is a reference, check if the local
404 * has been previously initialized.
406 * The only operator that accepts an uninitialized value is ObjectType()
408 else if ((!MethodInfo->LocalInitialized[RegisterNumber]) &&
409 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
411 LocalName[strlen (LocalName) -1] = (char) (RegisterNumber + 0x30);
412 AslError (ASL_ERROR, ASL_MSG_LOCAL_INIT, Op, LocalName);
427 * Arg was used outside a control method, or there was an error
428 * in the method declaration.
430 AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD,
431 Op, Op->Asl.ExternalName);
435 RegisterNumber = (Op->Asl.AmlOpcode & 0x000F) - 8;
436 ArgName[strlen (ArgName) -1] = (char) (RegisterNumber + 0x30);
439 * If the Arg is being used as a target, mark the local
442 if (Op->Asl.CompileFlags & OP_IS_TARGET)
444 MethodInfo->ArgInitialized[RegisterNumber] = TRUE;
448 * Otherwise, this is a reference, check if the Arg
449 * has been previously initialized.
451 * The only operator that accepts an uninitialized value is ObjectType()
453 else if ((!MethodInfo->ArgInitialized[RegisterNumber]) &&
454 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE))
456 AslError (ASL_ERROR, ASL_MSG_ARG_INIT, Op, ArgName);
459 /* Flag this arg if it is not a "real" argument to the method */
461 if (RegisterNumber >= MethodInfo->NumArguments)
463 AslError (ASL_REMARK, ASL_MSG_NOT_PARAMETER, Op, ArgName);
472 * Probably was an error in the method declaration,
473 * no additional error here
475 ACPI_WARNING ((AE_INFO, "%p, No parent method", Op));
480 * A child indicates a possible return value. A simple Return or
481 * Return() is marked with OP_IS_NULL_RETURN by the parser so
482 * that it is not counted as a "real" return-with-value, although
483 * the AML code that is actually emitted is Return(0). The AML
484 * definition of Return has a required parameter, so we are
485 * forced to convert a null return to Return(0).
487 if ((Op->Asl.Child) &&
488 (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
489 (!(Op->Asl.Child->Asl.CompileFlags & OP_IS_NULL_RETURN)))
491 MethodInfo->NumReturnWithValue++;
495 MethodInfo->NumReturnNoValue++;
500 case PARSEOP_CONTINUE:
502 Next = Op->Asl.Parent;
505 if (Next->Asl.ParseOpcode == PARSEOP_WHILE)
509 Next = Next->Asl.Parent;
514 AslError (ASL_ERROR, ASL_MSG_NO_WHILE, Op, NULL);
520 /* We can range check if the argument is an integer */
522 if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) &&
523 (Op->Asl.Child->Asl.Value.Integer > ACPI_UINT8_MAX))
525 AslError (ASL_ERROR, ASL_MSG_INVALID_TIME, Op, NULL);
531 /* Check usage of _HID and _ADR objects */
533 HidExists = ApFindNameInDeviceTree (METHOD_NAME__HID, Op);
534 AdrExists = ApFindNameInDeviceTree (METHOD_NAME__ADR, Op);
536 if (!HidExists && !AdrExists)
538 AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op,
539 "Device object requires a _HID or _ADR in same scope");
541 else if (HidExists && AdrExists)
544 * According to the ACPI spec, "A device object must contain
545 * either an _HID object or an _ADR object, but should not contain
548 AslError (ASL_WARNING, ASL_MSG_MULTIPLE_TYPES, Op,
549 "Device object requires either a _HID or _ADR, but not both");
555 case PARSEOP_OPERATIONREGION:
556 case PARSEOP_POWERRESOURCE:
557 case PARSEOP_PROCESSOR:
558 case PARSEOP_THERMALZONE:
561 * The first operand is a name to be created in the namespace.
562 * Check against the reserved list.
564 i = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
565 if (i < ACPI_VALID_RESERVED_NAME_MAX)
567 AslError (ASL_ERROR, ASL_MSG_RESERVED_USE,
568 Op, Op->Asl.ExternalName);
571 MtCheckStaticOperationRegionInMethod (Op);
576 /* Typecheck any predefined names statically defined with Name() */
578 ApCheckForPredefinedObject (Op, Op->Asl.NameSeg);
580 /* Special typechecking for _HID */
582 if (ACPI_COMPARE_NAMESEG (METHOD_NAME__HID, Op->Asl.NameSeg))
584 Next = Op->Asl.Child->Asl.Next;
585 AnCheckId (Next, ASL_TYPE_HID);
588 /* Special typechecking for _CID */
590 else if (ACPI_COMPARE_NAMESEG (METHOD_NAME__CID, Op->Asl.NameSeg))
592 Next = Op->Asl.Child->Asl.Next;
594 if ((Next->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
595 (Next->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE))
597 Next = Next->Asl.Child;
600 AnCheckId (Next, ASL_TYPE_CID);
601 Next = Next->Asl.Next;
606 AnCheckId (Next, ASL_TYPE_CID);
617 /* Check for named object creation within a non-serialized method */
619 MtCheckNamedObjectInMethod (Op, MethodInfo);
624 /*******************************************************************************
626 * FUNCTION: MtProcessTypeOp
628 * PARAMETERS: Op - Op representing a btype
630 * RETURN: Btype represented by Op
632 * DESCRIPTION: Process a parse object that represents single parameter type or
633 * a return type in method, function, and external declarations.
635 ******************************************************************************/
639 ACPI_PARSE_OBJECT *TypeOp)
641 UINT32 Btype = ACPI_BTYPE_ANY;
646 Btype |= AnMapObjTypeToBtype (TypeOp);
647 TypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
648 TypeOp = TypeOp->Asl.Next;
655 /*******************************************************************************
657 * FUNCTION: MtProcessParameterTypeList
659 * PARAMETERS: Op - Op representing a btype
661 * RETURN: Btype represented by Op
663 * DESCRIPTION: Process a parse object that represents a parameter type list in
664 * method, function, and external declarations.
666 ******************************************************************************/
669 MtProcessParameterTypeList (
670 ACPI_PARSE_OBJECT *ParamTypeOp,
673 UINT8 ParameterCount = 0;
676 if (ParamTypeOp && ParamTypeOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
678 /* Special case for a single parameter without braces */
680 TypeList[ParameterCount] =
681 MtProcessTypeOp (ParamTypeOp);
688 TypeList[ParameterCount] =
689 MtProcessTypeOp (ParamTypeOp->Asl.Child);
692 ParamTypeOp = ParamTypeOp->Asl.Next;
695 return (ParameterCount);
699 /*******************************************************************************
701 * FUNCTION: MtCheckNamedObjectInMethod
703 * PARAMETERS: Op - Current parser op
704 * MethodInfo - Info for method being parsed
708 * DESCRIPTION: Detect if a non-serialized method is creating a named object,
709 * which could possibly cause problems if two threads execute
710 * the method concurrently. Emit a remark in this case.
712 ******************************************************************************/
715 MtCheckNamedObjectInMethod (
716 ACPI_PARSE_OBJECT *Op,
717 ASL_METHOD_INFO *MethodInfo)
719 const ACPI_OPCODE_INFO *OpInfo;
723 /* We don't care about actual method declarations or scopes */
725 if ((Op->Asl.AmlOpcode == AML_METHOD_OP) ||
726 (Op->Asl.AmlOpcode == AML_SCOPE_OP))
731 /* Determine if we are creating a named object within a method */
738 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
739 if ((OpInfo->Class == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_FIELD_OP))
742 * 1) Mark the method as a method that creates named objects.
744 * 2) Issue a remark indicating the inefficiency of creating named
745 * objects within a method (Except for compiler-emitted temporary
748 * 3) If the method is non-serialized, emit a remark that the method
749 * should be serialized.
751 * Reason: If a thread blocks within the method for any reason, and
752 * another thread enters the method, the method will fail because
753 * an attempt will be made to create the same object twice.
755 * Note: The Field opcode is disallowed here because Field() does not
756 * create a new named object.
758 ExternalPath = AcpiNsGetNormalizedPathname (MethodInfo->Op->Asl.Node, TRUE);
760 /* No error for compiler temp variables (name starts with "_T_") */
762 if ((Op->Asl.NameSeg[0] != '_') &&
763 (Op->Asl.NameSeg[1] != 'T') &&
764 (Op->Asl.NameSeg[2] != '_'))
766 AslError (ASL_REMARK, ASL_MSG_NAMED_OBJECT_CREATION, Op,
770 MethodInfo->CreatesNamedObjects = TRUE;
771 if (!MethodInfo->ShouldBeSerialized)
773 AslError (ASL_REMARK, ASL_MSG_SERIALIZED_REQUIRED, MethodInfo->Op,
776 /* Emit message only ONCE per method */
778 MethodInfo->ShouldBeSerialized = TRUE;
783 ACPI_FREE (ExternalPath);
789 /*******************************************************************************
791 * FUNCTION: MtCheckStaticOperationRegionInMethod
793 * PARAMETERS: Op - Current parser op
797 * DESCRIPTION: Warns if an Operation Region with static address or length
798 * is declared inside a control method
800 ******************************************************************************/
803 MtCheckStaticOperationRegionInMethod(
804 ACPI_PARSE_OBJECT* Op)
806 ACPI_PARSE_OBJECT* AddressOp;
807 ACPI_PARSE_OBJECT* LengthOp;
810 if (Op->Asl.ParseOpcode != PARSEOP_OPERATIONREGION)
816 * OperationRegion should have 4 arguments defined. At this point, we
817 * assume that the parse tree is well-formed.
819 AddressOp = Op->Asl.Child->Asl.Next->Asl.Next;
820 LengthOp = Op->Asl.Child->Asl.Next->Asl.Next->Asl.Next;
822 if (UtGetParentMethodOp (Op) &&
823 AddressOp->Asl.ParseOpcode == PARSEOP_INTEGER &&
824 LengthOp->Asl.ParseOpcode == PARSEOP_INTEGER)
827 * At this point, a static operation region declared inside of a
828 * control method has been found. Throw a warning because this is
829 * highly inefficient.
831 AslError(ASL_WARNING, ASL_MSG_STATIC_OPREGION_IN_METHOD, Op, NULL);
838 /*******************************************************************************
840 * FUNCTION: MtMethodAnalysisWalkEnd
842 * PARAMETERS: ASL_WALK_CALLBACK
846 * DESCRIPTION: Ascending callback for analysis walk. Complete method
849 ******************************************************************************/
852 MtMethodAnalysisWalkEnd (
853 ACPI_PARSE_OBJECT *Op,
857 ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context;
858 ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack;
862 switch (Op->Asl.ParseOpcode)
869 printf ("No method info for method! [%s]\n", Op->Asl.Namepath);
870 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
871 "No method info for this method");
874 return (AE_AML_INTERNAL);
883 switch (Op->Asl.ParseOpcode)
887 WalkInfo->MethodStack = MethodInfo->Next;
890 * Check if there is no return statement at the end of the
891 * method AND we can actually get there -- i.e., the execution
892 * of the method can possibly terminate without a return statement.
894 if ((!AnLastStatementIsReturn (Op)) &&
895 (!(Op->Asl.CompileFlags & OP_HAS_NO_EXIT)))
898 * No return statement, and execution can possibly exit
899 * via this path. This is equivalent to Return ()
901 MethodInfo->NumReturnNoValue++;
905 * Check for case where some return statements have a return value
906 * and some do not. Exit without a return statement is a return with
909 if (MethodInfo->NumReturnNoValue &&
910 MethodInfo->NumReturnWithValue)
912 ExternalPath = AcpiNsGetNormalizedPathname (Op->Asl.Node, TRUE);
914 AslError (ASL_WARNING, ASL_MSG_RETURN_TYPES, Op,
919 ACPI_FREE (ExternalPath);
924 * If there are any RETURN() statements with no value, or there is a
925 * control path that allows the method to exit without a return value,
926 * we mark the method as a method that does not return a value. This
927 * knowledge can be used to check method invocations that expect a
930 if (MethodInfo->NumReturnNoValue)
932 if (MethodInfo->NumReturnWithValue)
934 Op->Asl.CompileFlags |= OP_METHOD_SOME_NO_RETVAL;
938 Op->Asl.CompileFlags |= OP_METHOD_NO_RETVAL;
943 * Check predefined method names for correct return behavior
944 * and correct number of arguments. Also, some special checks
945 * For GPE and _REG methods.
947 if (ApCheckForPredefinedMethod (Op, MethodInfo))
949 /* Special check for two names like _L01 and _E01 in same scope */
951 ApCheckForGpeNameConflict (Op);
954 * Special check for _REG: Must have an operation region definition
955 * within the same scope!
957 ApCheckRegMethod (Op);
960 ACPI_FREE (MethodInfo);
965 /* Special check for two names like _L01 and _E01 in same scope */
967 ApCheckForGpeNameConflict (Op);
973 * If the parent is a predefined method name, attempt to typecheck
974 * the return value. Only static types can be validated.
976 ApCheckPredefinedReturnValue (Op, MethodInfo);
979 * The parent block does not "exit" and continue execution -- the
980 * method is terminated here with the Return() statement.
982 Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT;
984 /* Used in the "typing" pass later */
986 Op->Asl.ParentMethod = MethodInfo->Op;
989 * If there is a peer node after the return statement, then this
990 * node is unreachable code -- i.e., it won't be executed because of
991 * the preceding Return() statement.
995 AslError (ASL_WARNING, ASL_MSG_UNREACHABLE_CODE,
1002 if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) &&
1004 (Op->Asl.Next->Asl.ParseOpcode == PARSEOP_ELSE))
1007 * This IF has a corresponding ELSE. The IF block has no exit,
1008 * (it contains an unconditional Return)
1009 * mark the ELSE block to remember this fact.
1011 Op->Asl.Next->Asl.CompileFlags |= OP_IF_HAS_NO_EXIT;
1017 if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) &&
1018 (Op->Asl.CompileFlags & OP_IF_HAS_NO_EXIT))
1021 * This ELSE block has no exit and the corresponding IF block
1022 * has no exit either. Therefore, the parent node has no exit.
1024 Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT;
1031 if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) &&
1034 /* If this node has no exit, then the parent has no exit either */
1036 Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT;