1efcc2a30SJung-uk Kim /****************************************************************************** 2efcc2a30SJung-uk Kim * 3efcc2a30SJung-uk Kim * Module Name: aslmethod.c - Control method analysis walk 4efcc2a30SJung-uk Kim * 5efcc2a30SJung-uk Kim *****************************************************************************/ 6efcc2a30SJung-uk Kim 70d84335fSJung-uk Kim /****************************************************************************** 80d84335fSJung-uk Kim * 90d84335fSJung-uk Kim * 1. Copyright Notice 100d84335fSJung-uk Kim * 11f425b8beSJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2020, Intel Corp. 12efcc2a30SJung-uk Kim * All rights reserved. 13efcc2a30SJung-uk Kim * 140d84335fSJung-uk Kim * 2. License 150d84335fSJung-uk Kim * 160d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property 170d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided 180d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual 190d84335fSJung-uk Kim * property rights. 200d84335fSJung-uk Kim * 210d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 220d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an 230d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 240d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy, 250d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered 260d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and 270d84335fSJung-uk Kim * 280d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 290d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel 300d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell, 310d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof 320d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright 330d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions 340d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right 350d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise; 360d84335fSJung-uk Kim * 370d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following 380d84335fSJung-uk Kim * conditions are met: 390d84335fSJung-uk Kim * 400d84335fSJung-uk Kim * 3. Conditions 410d84335fSJung-uk Kim * 420d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 430d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 440d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include 450d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions, 460d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition, 470d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to 480d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered 490d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the 500d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee 510d84335fSJung-uk Kim * must include a prominent statement that the modification is derived, 520d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code. 530d84335fSJung-uk Kim * 540d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 550d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 560d84335fSJung-uk Kim * Code or modification without rights to further distribute source must 570d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the 580d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In 590d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any 600d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the 610d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual 620d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and 630d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may 640d84335fSJung-uk Kim * make. 650d84335fSJung-uk Kim * 660d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any 670d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the 680d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance 690d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the 700d84335fSJung-uk Kim * distribution. 710d84335fSJung-uk Kim * 720d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original 730d84335fSJung-uk Kim * Intel Code. 740d84335fSJung-uk Kim * 750d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 760d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or 770d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code 780d84335fSJung-uk Kim * without prior written authorization from Intel. 790d84335fSJung-uk Kim * 800d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance 810d84335fSJung-uk Kim * 820d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 830d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 840d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 850d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 860d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 870d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 880d84335fSJung-uk Kim * PARTICULAR PURPOSE. 890d84335fSJung-uk Kim * 900d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 910d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 920d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 930d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 940d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 950d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 960d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 970d84335fSJung-uk Kim * LIMITED REMEDY. 980d84335fSJung-uk Kim * 990d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this 1000d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any 1010d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or 1020d84335fSJung-uk Kim * any other agency or department of the United States Government. In the 1030d84335fSJung-uk Kim * event Licensee exports any such software from the United States or 1040d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall 1050d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in 1060d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the 1070d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 1080d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process, 1090d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the 1100d84335fSJung-uk Kim * United States government or any agency thereof requires an export license, 1110d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining 1120d84335fSJung-uk Kim * such license, approval or letter. 1130d84335fSJung-uk Kim * 1140d84335fSJung-uk Kim ***************************************************************************** 1150d84335fSJung-uk Kim * 1160d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 1170d84335fSJung-uk Kim * following license: 1180d84335fSJung-uk Kim * 119efcc2a30SJung-uk Kim * Redistribution and use in source and binary forms, with or without 120efcc2a30SJung-uk Kim * modification, are permitted provided that the following conditions 121efcc2a30SJung-uk Kim * are met: 122efcc2a30SJung-uk Kim * 1. Redistributions of source code must retain the above copyright 123efcc2a30SJung-uk Kim * notice, this list of conditions, and the following disclaimer, 124efcc2a30SJung-uk Kim * without modification. 125efcc2a30SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126efcc2a30SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below 127efcc2a30SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon 128efcc2a30SJung-uk Kim * including a substantially similar Disclaimer requirement for further 129efcc2a30SJung-uk Kim * binary redistribution. 130efcc2a30SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names 131efcc2a30SJung-uk Kim * of any contributors may be used to endorse or promote products derived 132efcc2a30SJung-uk Kim * from this software without specific prior written permission. 133efcc2a30SJung-uk Kim * 1340d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1350d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1360d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1370d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1380d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1390d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1400d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1410d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1420d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1430d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1440d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1450d84335fSJung-uk Kim * 1460d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 147efcc2a30SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free 148efcc2a30SJung-uk Kim * Software Foundation. 149efcc2a30SJung-uk Kim * 1500d84335fSJung-uk Kim *****************************************************************************/ 151efcc2a30SJung-uk Kim 152efcc2a30SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h> 153efcc2a30SJung-uk Kim #include "aslcompiler.y.h" 154ec0234b4SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h> 155a9d8d09cSJung-uk Kim #include <contrib/dev/acpica/include/acparser.h> 156a9d8d09cSJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h> 157efcc2a30SJung-uk Kim 158efcc2a30SJung-uk Kim 159efcc2a30SJung-uk Kim #define _COMPONENT ACPI_COMPILER 160efcc2a30SJung-uk Kim ACPI_MODULE_NAME ("aslmethod") 161efcc2a30SJung-uk Kim 162efcc2a30SJung-uk Kim 163a9d8d09cSJung-uk Kim /* Local prototypes */ 164a9d8d09cSJung-uk Kim 165f8146b88SJung-uk Kim static void 166a9d8d09cSJung-uk Kim MtCheckNamedObjectInMethod ( 167a9d8d09cSJung-uk Kim ACPI_PARSE_OBJECT *Op, 168a9d8d09cSJung-uk Kim ASL_METHOD_INFO *MethodInfo); 169a9d8d09cSJung-uk Kim 170ec0234b4SJung-uk Kim static void 171ec0234b4SJung-uk Kim MtCheckStaticOperationRegionInMethod ( 172ec0234b4SJung-uk Kim ACPI_PARSE_OBJECT *Op); 173ec0234b4SJung-uk Kim 174a9d8d09cSJung-uk Kim 175efcc2a30SJung-uk Kim /******************************************************************************* 176efcc2a30SJung-uk Kim * 177efcc2a30SJung-uk Kim * FUNCTION: MtMethodAnalysisWalkBegin 178efcc2a30SJung-uk Kim * 179efcc2a30SJung-uk Kim * PARAMETERS: ASL_WALK_CALLBACK 180efcc2a30SJung-uk Kim * 181efcc2a30SJung-uk Kim * RETURN: Status 182efcc2a30SJung-uk Kim * 183efcc2a30SJung-uk Kim * DESCRIPTION: Descending callback for the analysis walk. Check methods for: 184efcc2a30SJung-uk Kim * 1) Initialized local variables 185efcc2a30SJung-uk Kim * 2) Valid arguments 186efcc2a30SJung-uk Kim * 3) Return types 187efcc2a30SJung-uk Kim * 188efcc2a30SJung-uk Kim ******************************************************************************/ 189efcc2a30SJung-uk Kim 190efcc2a30SJung-uk Kim ACPI_STATUS 191efcc2a30SJung-uk Kim MtMethodAnalysisWalkBegin ( 192efcc2a30SJung-uk Kim ACPI_PARSE_OBJECT *Op, 193efcc2a30SJung-uk Kim UINT32 Level, 194efcc2a30SJung-uk Kim void *Context) 195efcc2a30SJung-uk Kim { 196efcc2a30SJung-uk Kim ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context; 197efcc2a30SJung-uk Kim ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack; 198efcc2a30SJung-uk Kim ACPI_PARSE_OBJECT *Next; 199efcc2a30SJung-uk Kim UINT32 RegisterNumber; 200efcc2a30SJung-uk Kim UINT32 i; 201efcc2a30SJung-uk Kim char LocalName[] = "Local0"; 202efcc2a30SJung-uk Kim char ArgName[] = "Arg0"; 203efcc2a30SJung-uk Kim ACPI_PARSE_OBJECT *ArgNode; 204efcc2a30SJung-uk Kim ACPI_PARSE_OBJECT *NextType; 205efcc2a30SJung-uk Kim UINT8 ActualArgs = 0; 206a009b7dcSJung-uk Kim BOOLEAN HidExists; 207a009b7dcSJung-uk Kim BOOLEAN AdrExists; 208efcc2a30SJung-uk Kim 209efcc2a30SJung-uk Kim 210f8146b88SJung-uk Kim /* Build cross-reference output file if requested */ 211f8146b88SJung-uk Kim 2126f1f1a63SJung-uk Kim if (AslGbl_CrossReferenceOutput) 213f8146b88SJung-uk Kim { 214f8146b88SJung-uk Kim OtXrefWalkPart1 (Op, Level, MethodInfo); 215f8146b88SJung-uk Kim } 216f8146b88SJung-uk Kim 217efcc2a30SJung-uk Kim switch (Op->Asl.ParseOpcode) 218efcc2a30SJung-uk Kim { 219efcc2a30SJung-uk Kim case PARSEOP_METHOD: 220efcc2a30SJung-uk Kim 2216f1f1a63SJung-uk Kim AslGbl_TotalMethods++; 222efcc2a30SJung-uk Kim 223efcc2a30SJung-uk Kim /* Create and init method info */ 224efcc2a30SJung-uk Kim 225efcc2a30SJung-uk Kim MethodInfo = UtLocalCalloc (sizeof (ASL_METHOD_INFO)); 226efcc2a30SJung-uk Kim MethodInfo->Next = WalkInfo->MethodStack; 227efcc2a30SJung-uk Kim MethodInfo->Op = Op; 228efcc2a30SJung-uk Kim 229efcc2a30SJung-uk Kim WalkInfo->MethodStack = MethodInfo; 230efcc2a30SJung-uk Kim 231313a0c13SJung-uk Kim /* 232313a0c13SJung-uk Kim * Special handling for _PSx methods. Dependency rules (same scope): 233313a0c13SJung-uk Kim * 234313a0c13SJung-uk Kim * 1) _PS0 - One of these must exist: _PS1, _PS2, _PS3 235313a0c13SJung-uk Kim * 2) _PS1/_PS2/_PS3: A _PS0 must exist 236313a0c13SJung-uk Kim */ 237278f0de6SJung-uk Kim if (ACPI_COMPARE_NAMESEG (METHOD_NAME__PS0, Op->Asl.NameSeg)) 238313a0c13SJung-uk Kim { 239313a0c13SJung-uk Kim /* For _PS0, one of _PS1/_PS2/_PS3 must exist */ 240313a0c13SJung-uk Kim 241313a0c13SJung-uk Kim if ((!ApFindNameInScope (METHOD_NAME__PS1, Op)) && 242313a0c13SJung-uk Kim (!ApFindNameInScope (METHOD_NAME__PS2, Op)) && 243313a0c13SJung-uk Kim (!ApFindNameInScope (METHOD_NAME__PS3, Op))) 244313a0c13SJung-uk Kim { 245313a0c13SJung-uk Kim AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, 246313a0c13SJung-uk Kim "_PS0 requires one of _PS1/_PS2/_PS3 in same scope"); 247313a0c13SJung-uk Kim } 248313a0c13SJung-uk Kim } 249313a0c13SJung-uk Kim else if ( 250278f0de6SJung-uk Kim ACPI_COMPARE_NAMESEG (METHOD_NAME__PS1, Op->Asl.NameSeg) || 251278f0de6SJung-uk Kim ACPI_COMPARE_NAMESEG (METHOD_NAME__PS2, Op->Asl.NameSeg) || 252278f0de6SJung-uk Kim ACPI_COMPARE_NAMESEG (METHOD_NAME__PS3, Op->Asl.NameSeg)) 253313a0c13SJung-uk Kim { 254313a0c13SJung-uk Kim /* For _PS1/_PS2/_PS3, a _PS0 must exist */ 255313a0c13SJung-uk Kim 256313a0c13SJung-uk Kim if (!ApFindNameInScope (METHOD_NAME__PS0, Op)) 257313a0c13SJung-uk Kim { 2586f1f1a63SJung-uk Kim sprintf (AslGbl_MsgBuffer, 259313a0c13SJung-uk Kim "%4.4s requires _PS0 in same scope", Op->Asl.NameSeg); 260313a0c13SJung-uk Kim 261313a0c13SJung-uk Kim AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, 2626f1f1a63SJung-uk Kim AslGbl_MsgBuffer); 263313a0c13SJung-uk Kim } 264313a0c13SJung-uk Kim } 265313a0c13SJung-uk Kim 266313a0c13SJung-uk Kim /* Get the name node */ 267efcc2a30SJung-uk Kim 268efcc2a30SJung-uk Kim Next = Op->Asl.Child; 269efcc2a30SJung-uk Kim 270efcc2a30SJung-uk Kim /* Get the NumArguments node */ 271efcc2a30SJung-uk Kim 272efcc2a30SJung-uk Kim Next = Next->Asl.Next; 273efcc2a30SJung-uk Kim MethodInfo->NumArguments = (UINT8) 274efcc2a30SJung-uk Kim (((UINT8) Next->Asl.Value.Integer) & 0x07); 275efcc2a30SJung-uk Kim 276efcc2a30SJung-uk Kim /* Get the SerializeRule and SyncLevel nodes, ignored here */ 277efcc2a30SJung-uk Kim 278efcc2a30SJung-uk Kim Next = Next->Asl.Next; 279a9d8d09cSJung-uk Kim MethodInfo->ShouldBeSerialized = (UINT8) Next->Asl.Value.Integer; 280a9d8d09cSJung-uk Kim 281efcc2a30SJung-uk Kim Next = Next->Asl.Next; 282efcc2a30SJung-uk Kim ArgNode = Next; 283efcc2a30SJung-uk Kim 284efcc2a30SJung-uk Kim /* Get the ReturnType node */ 285efcc2a30SJung-uk Kim 286efcc2a30SJung-uk Kim Next = Next->Asl.Next; 287efcc2a30SJung-uk Kim 288efcc2a30SJung-uk Kim NextType = Next->Asl.Child; 289efcc2a30SJung-uk Kim 290ec0234b4SJung-uk Kim MethodInfo->ValidReturnTypes = MtProcessTypeOp (NextType); 291efcc2a30SJung-uk Kim 292efcc2a30SJung-uk Kim /* Get the ParameterType node */ 293efcc2a30SJung-uk Kim 294efcc2a30SJung-uk Kim Next = Next->Asl.Next; 295efcc2a30SJung-uk Kim 296efcc2a30SJung-uk Kim NextType = Next->Asl.Child; 297ec0234b4SJung-uk Kim if (!NextType) 298efcc2a30SJung-uk Kim { 299ec0234b4SJung-uk Kim /* 300ec0234b4SJung-uk Kim * The optional parameter types list was omitted at the source 301ec0234b4SJung-uk Kim * level. Use the Argument count parameter instead. 302ec0234b4SJung-uk Kim */ 303ec0234b4SJung-uk Kim ActualArgs = MethodInfo->NumArguments; 304efcc2a30SJung-uk Kim } 305efcc2a30SJung-uk Kim else 306efcc2a30SJung-uk Kim { 307ec0234b4SJung-uk Kim ActualArgs = MtProcessParameterTypeList (NextType, 308ec0234b4SJung-uk Kim MethodInfo->ValidArgTypes); 309*61b18036SJung-uk Kim MethodInfo->NumArguments = ActualArgs; 310*61b18036SJung-uk Kim ArgNode->Asl.Value.Integer |= ActualArgs; 311efcc2a30SJung-uk Kim } 312efcc2a30SJung-uk Kim 313efcc2a30SJung-uk Kim if ((MethodInfo->NumArguments) && 314efcc2a30SJung-uk Kim (MethodInfo->NumArguments != ActualArgs)) 315efcc2a30SJung-uk Kim { 316ec0234b4SJung-uk Kim sprintf (AslGbl_MsgBuffer, 317ec0234b4SJung-uk Kim "Length = %u", ActualArgs); 318ec0234b4SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_MISMATCH, 319ec0234b4SJung-uk Kim Op->Asl.Child->Asl.Next, AslGbl_MsgBuffer); 320efcc2a30SJung-uk Kim } 321efcc2a30SJung-uk Kim 322efcc2a30SJung-uk Kim /* Allow numarguments == 0 for Function() */ 323efcc2a30SJung-uk Kim 324efcc2a30SJung-uk Kim if ((!MethodInfo->NumArguments) && (ActualArgs)) 325efcc2a30SJung-uk Kim { 326efcc2a30SJung-uk Kim MethodInfo->NumArguments = ActualArgs; 327efcc2a30SJung-uk Kim ArgNode->Asl.Value.Integer |= ActualArgs; 328efcc2a30SJung-uk Kim } 329efcc2a30SJung-uk Kim 330efcc2a30SJung-uk Kim /* 331efcc2a30SJung-uk Kim * Actual arguments are initialized at method entry. 332efcc2a30SJung-uk Kim * All other ArgX "registers" can be used as locals, so we 333efcc2a30SJung-uk Kim * track their initialization. 334efcc2a30SJung-uk Kim */ 335efcc2a30SJung-uk Kim for (i = 0; i < MethodInfo->NumArguments; i++) 336efcc2a30SJung-uk Kim { 337efcc2a30SJung-uk Kim MethodInfo->ArgInitialized[i] = TRUE; 338efcc2a30SJung-uk Kim } 339efcc2a30SJung-uk Kim break; 340efcc2a30SJung-uk Kim 341efcc2a30SJung-uk Kim case PARSEOP_METHODCALL: 342efcc2a30SJung-uk Kim 34367d9aa44SJung-uk Kim /* Check for a recursive method call */ 34467d9aa44SJung-uk Kim 345efcc2a30SJung-uk Kim if (MethodInfo && 346efcc2a30SJung-uk Kim (Op->Asl.Node == MethodInfo->Op->Asl.Node)) 347efcc2a30SJung-uk Kim { 34867d9aa44SJung-uk Kim if (MethodInfo->CreatesNamedObjects) 34967d9aa44SJung-uk Kim { 35067d9aa44SJung-uk Kim /* 35167d9aa44SJung-uk Kim * This is an error, as it will fail at runtime on all ACPI 35267d9aa44SJung-uk Kim * implementations. Any named object declarations will be 35367d9aa44SJung-uk Kim * executed twice, causing failure the second time. Note, 35467d9aa44SJung-uk Kim * this is independent of whether the method is declared 35567d9aa44SJung-uk Kim * Serialized, because the same thread is attempting to 35667d9aa44SJung-uk Kim * reenter the method, and this will always succeed. 35767d9aa44SJung-uk Kim */ 35867d9aa44SJung-uk Kim AslDualParseOpError (ASL_ERROR, ASL_MSG_ILLEGAL_RECURSION, Op, 35967d9aa44SJung-uk Kim Op->Asl.Value.String, ASL_MSG_FOUND_HERE, MethodInfo->Op, 36067d9aa44SJung-uk Kim MethodInfo->Op->Asl.ExternalName); 36167d9aa44SJung-uk Kim } 36267d9aa44SJung-uk Kim else 36367d9aa44SJung-uk Kim { 36467d9aa44SJung-uk Kim /* Method does not create objects, issue a remark */ 36567d9aa44SJung-uk Kim 366efcc2a30SJung-uk Kim AslError (ASL_REMARK, ASL_MSG_RECURSION, Op, Op->Asl.ExternalName); 367efcc2a30SJung-uk Kim } 36867d9aa44SJung-uk Kim } 369efcc2a30SJung-uk Kim break; 370efcc2a30SJung-uk Kim 371efcc2a30SJung-uk Kim case PARSEOP_LOCAL0: 372efcc2a30SJung-uk Kim case PARSEOP_LOCAL1: 373efcc2a30SJung-uk Kim case PARSEOP_LOCAL2: 374efcc2a30SJung-uk Kim case PARSEOP_LOCAL3: 375efcc2a30SJung-uk Kim case PARSEOP_LOCAL4: 376efcc2a30SJung-uk Kim case PARSEOP_LOCAL5: 377efcc2a30SJung-uk Kim case PARSEOP_LOCAL6: 378efcc2a30SJung-uk Kim case PARSEOP_LOCAL7: 379efcc2a30SJung-uk Kim 380efcc2a30SJung-uk Kim if (!MethodInfo) 381efcc2a30SJung-uk Kim { 382efcc2a30SJung-uk Kim /* 383efcc2a30SJung-uk Kim * Local was used outside a control method, or there was an error 384efcc2a30SJung-uk Kim * in the method declaration. 385efcc2a30SJung-uk Kim */ 386f8146b88SJung-uk Kim AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, 387f8146b88SJung-uk Kim Op, Op->Asl.ExternalName); 388efcc2a30SJung-uk Kim return (AE_ERROR); 389efcc2a30SJung-uk Kim } 390efcc2a30SJung-uk Kim 391fe0f0bbbSJung-uk Kim RegisterNumber = (Op->Asl.AmlOpcode & 0x0007); 392efcc2a30SJung-uk Kim 393efcc2a30SJung-uk Kim /* 394efcc2a30SJung-uk Kim * If the local is being used as a target, mark the local 395efcc2a30SJung-uk Kim * initialized 396efcc2a30SJung-uk Kim */ 3975f9b24faSJung-uk Kim if (Op->Asl.CompileFlags & OP_IS_TARGET) 398efcc2a30SJung-uk Kim { 399efcc2a30SJung-uk Kim MethodInfo->LocalInitialized[RegisterNumber] = TRUE; 400efcc2a30SJung-uk Kim } 401efcc2a30SJung-uk Kim 402efcc2a30SJung-uk Kim /* 403efcc2a30SJung-uk Kim * Otherwise, this is a reference, check if the local 404efcc2a30SJung-uk Kim * has been previously initialized. 405efcc2a30SJung-uk Kim * 406efcc2a30SJung-uk Kim * The only operator that accepts an uninitialized value is ObjectType() 407efcc2a30SJung-uk Kim */ 408efcc2a30SJung-uk Kim else if ((!MethodInfo->LocalInitialized[RegisterNumber]) && 409efcc2a30SJung-uk Kim (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE)) 410efcc2a30SJung-uk Kim { 411efcc2a30SJung-uk Kim LocalName[strlen (LocalName) -1] = (char) (RegisterNumber + 0x30); 412efcc2a30SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_LOCAL_INIT, Op, LocalName); 413efcc2a30SJung-uk Kim } 414efcc2a30SJung-uk Kim break; 415efcc2a30SJung-uk Kim 416efcc2a30SJung-uk Kim case PARSEOP_ARG0: 417efcc2a30SJung-uk Kim case PARSEOP_ARG1: 418efcc2a30SJung-uk Kim case PARSEOP_ARG2: 419efcc2a30SJung-uk Kim case PARSEOP_ARG3: 420efcc2a30SJung-uk Kim case PARSEOP_ARG4: 421efcc2a30SJung-uk Kim case PARSEOP_ARG5: 422efcc2a30SJung-uk Kim case PARSEOP_ARG6: 423efcc2a30SJung-uk Kim 424efcc2a30SJung-uk Kim if (!MethodInfo) 425efcc2a30SJung-uk Kim { 426efcc2a30SJung-uk Kim /* 427efcc2a30SJung-uk Kim * Arg was used outside a control method, or there was an error 428efcc2a30SJung-uk Kim * in the method declaration. 429efcc2a30SJung-uk Kim */ 430f8146b88SJung-uk Kim AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, 431f8146b88SJung-uk Kim Op, Op->Asl.ExternalName); 432efcc2a30SJung-uk Kim return (AE_ERROR); 433efcc2a30SJung-uk Kim } 434efcc2a30SJung-uk Kim 435efcc2a30SJung-uk Kim RegisterNumber = (Op->Asl.AmlOpcode & 0x000F) - 8; 436efcc2a30SJung-uk Kim ArgName[strlen (ArgName) -1] = (char) (RegisterNumber + 0x30); 437efcc2a30SJung-uk Kim 438efcc2a30SJung-uk Kim /* 439efcc2a30SJung-uk Kim * If the Arg is being used as a target, mark the local 440efcc2a30SJung-uk Kim * initialized 441efcc2a30SJung-uk Kim */ 4425f9b24faSJung-uk Kim if (Op->Asl.CompileFlags & OP_IS_TARGET) 443efcc2a30SJung-uk Kim { 444efcc2a30SJung-uk Kim MethodInfo->ArgInitialized[RegisterNumber] = TRUE; 445efcc2a30SJung-uk Kim } 446efcc2a30SJung-uk Kim 447efcc2a30SJung-uk Kim /* 448efcc2a30SJung-uk Kim * Otherwise, this is a reference, check if the Arg 449efcc2a30SJung-uk Kim * has been previously initialized. 450efcc2a30SJung-uk Kim * 451efcc2a30SJung-uk Kim * The only operator that accepts an uninitialized value is ObjectType() 452efcc2a30SJung-uk Kim */ 453efcc2a30SJung-uk Kim else if ((!MethodInfo->ArgInitialized[RegisterNumber]) && 454efcc2a30SJung-uk Kim (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE)) 455efcc2a30SJung-uk Kim { 456efcc2a30SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_ARG_INIT, Op, ArgName); 457efcc2a30SJung-uk Kim } 458efcc2a30SJung-uk Kim 459efcc2a30SJung-uk Kim /* Flag this arg if it is not a "real" argument to the method */ 460efcc2a30SJung-uk Kim 461efcc2a30SJung-uk Kim if (RegisterNumber >= MethodInfo->NumArguments) 462efcc2a30SJung-uk Kim { 463efcc2a30SJung-uk Kim AslError (ASL_REMARK, ASL_MSG_NOT_PARAMETER, Op, ArgName); 464efcc2a30SJung-uk Kim } 465efcc2a30SJung-uk Kim break; 466efcc2a30SJung-uk Kim 467efcc2a30SJung-uk Kim case PARSEOP_RETURN: 468efcc2a30SJung-uk Kim 469efcc2a30SJung-uk Kim if (!MethodInfo) 470efcc2a30SJung-uk Kim { 471efcc2a30SJung-uk Kim /* 472efcc2a30SJung-uk Kim * Probably was an error in the method declaration, 473efcc2a30SJung-uk Kim * no additional error here 474efcc2a30SJung-uk Kim */ 475efcc2a30SJung-uk Kim ACPI_WARNING ((AE_INFO, "%p, No parent method", Op)); 476efcc2a30SJung-uk Kim return (AE_ERROR); 477efcc2a30SJung-uk Kim } 478efcc2a30SJung-uk Kim 479efcc2a30SJung-uk Kim /* 480efcc2a30SJung-uk Kim * A child indicates a possible return value. A simple Return or 4815f9b24faSJung-uk Kim * Return() is marked with OP_IS_NULL_RETURN by the parser so 482efcc2a30SJung-uk Kim * that it is not counted as a "real" return-with-value, although 483efcc2a30SJung-uk Kim * the AML code that is actually emitted is Return(0). The AML 484efcc2a30SJung-uk Kim * definition of Return has a required parameter, so we are 485efcc2a30SJung-uk Kim * forced to convert a null return to Return(0). 486efcc2a30SJung-uk Kim */ 487efcc2a30SJung-uk Kim if ((Op->Asl.Child) && 488efcc2a30SJung-uk Kim (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && 4895f9b24faSJung-uk Kim (!(Op->Asl.Child->Asl.CompileFlags & OP_IS_NULL_RETURN))) 490efcc2a30SJung-uk Kim { 491efcc2a30SJung-uk Kim MethodInfo->NumReturnWithValue++; 492efcc2a30SJung-uk Kim } 493efcc2a30SJung-uk Kim else 494efcc2a30SJung-uk Kim { 495efcc2a30SJung-uk Kim MethodInfo->NumReturnNoValue++; 496efcc2a30SJung-uk Kim } 497efcc2a30SJung-uk Kim break; 498efcc2a30SJung-uk Kim 499efcc2a30SJung-uk Kim case PARSEOP_BREAK: 500efcc2a30SJung-uk Kim case PARSEOP_CONTINUE: 501efcc2a30SJung-uk Kim 502efcc2a30SJung-uk Kim Next = Op->Asl.Parent; 503efcc2a30SJung-uk Kim while (Next) 504efcc2a30SJung-uk Kim { 505efcc2a30SJung-uk Kim if (Next->Asl.ParseOpcode == PARSEOP_WHILE) 506efcc2a30SJung-uk Kim { 507efcc2a30SJung-uk Kim break; 508efcc2a30SJung-uk Kim } 509efcc2a30SJung-uk Kim Next = Next->Asl.Parent; 510efcc2a30SJung-uk Kim } 511efcc2a30SJung-uk Kim 512efcc2a30SJung-uk Kim if (!Next) 513efcc2a30SJung-uk Kim { 514efcc2a30SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_NO_WHILE, Op, NULL); 515efcc2a30SJung-uk Kim } 516efcc2a30SJung-uk Kim break; 517efcc2a30SJung-uk Kim 518efcc2a30SJung-uk Kim case PARSEOP_STALL: 519efcc2a30SJung-uk Kim 520efcc2a30SJung-uk Kim /* We can range check if the argument is an integer */ 521efcc2a30SJung-uk Kim 522efcc2a30SJung-uk Kim if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) && 523efcc2a30SJung-uk Kim (Op->Asl.Child->Asl.Value.Integer > ACPI_UINT8_MAX)) 524efcc2a30SJung-uk Kim { 525efcc2a30SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_INVALID_TIME, Op, NULL); 526efcc2a30SJung-uk Kim } 527efcc2a30SJung-uk Kim break; 528efcc2a30SJung-uk Kim 529efcc2a30SJung-uk Kim case PARSEOP_DEVICE: 530313a0c13SJung-uk Kim 531a009b7dcSJung-uk Kim /* Check usage of _HID and _ADR objects */ 532a009b7dcSJung-uk Kim 533a009b7dcSJung-uk Kim HidExists = ApFindNameInDeviceTree (METHOD_NAME__HID, Op); 534a009b7dcSJung-uk Kim AdrExists = ApFindNameInDeviceTree (METHOD_NAME__ADR, Op); 535a009b7dcSJung-uk Kim 536a009b7dcSJung-uk Kim if (!HidExists && !AdrExists) 537313a0c13SJung-uk Kim { 538313a0c13SJung-uk Kim AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, 539313a0c13SJung-uk Kim "Device object requires a _HID or _ADR in same scope"); 540313a0c13SJung-uk Kim } 541a009b7dcSJung-uk Kim else if (HidExists && AdrExists) 542a009b7dcSJung-uk Kim { 543a009b7dcSJung-uk Kim /* 544a009b7dcSJung-uk Kim * According to the ACPI spec, "A device object must contain 545a009b7dcSJung-uk Kim * either an _HID object or an _ADR object, but should not contain 546a009b7dcSJung-uk Kim * both". 547a009b7dcSJung-uk Kim */ 548a009b7dcSJung-uk Kim AslError (ASL_WARNING, ASL_MSG_MULTIPLE_TYPES, Op, 549a009b7dcSJung-uk Kim "Device object requires either a _HID or _ADR, but not both"); 550a009b7dcSJung-uk Kim } 551313a0c13SJung-uk Kim break; 552313a0c13SJung-uk Kim 553efcc2a30SJung-uk Kim case PARSEOP_EVENT: 554efcc2a30SJung-uk Kim case PARSEOP_MUTEX: 555efcc2a30SJung-uk Kim case PARSEOP_OPERATIONREGION: 556efcc2a30SJung-uk Kim case PARSEOP_POWERRESOURCE: 557efcc2a30SJung-uk Kim case PARSEOP_PROCESSOR: 558efcc2a30SJung-uk Kim case PARSEOP_THERMALZONE: 559efcc2a30SJung-uk Kim 560efcc2a30SJung-uk Kim /* 561efcc2a30SJung-uk Kim * The first operand is a name to be created in the namespace. 562efcc2a30SJung-uk Kim * Check against the reserved list. 563efcc2a30SJung-uk Kim */ 564efcc2a30SJung-uk Kim i = ApCheckForPredefinedName (Op, Op->Asl.NameSeg); 565efcc2a30SJung-uk Kim if (i < ACPI_VALID_RESERVED_NAME_MAX) 566efcc2a30SJung-uk Kim { 567f8146b88SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_RESERVED_USE, 568f8146b88SJung-uk Kim Op, Op->Asl.ExternalName); 569efcc2a30SJung-uk Kim } 570ec0234b4SJung-uk Kim 571ec0234b4SJung-uk Kim MtCheckStaticOperationRegionInMethod (Op); 572efcc2a30SJung-uk Kim break; 573efcc2a30SJung-uk Kim 574efcc2a30SJung-uk Kim case PARSEOP_NAME: 575efcc2a30SJung-uk Kim 576efcc2a30SJung-uk Kim /* Typecheck any predefined names statically defined with Name() */ 577efcc2a30SJung-uk Kim 578efcc2a30SJung-uk Kim ApCheckForPredefinedObject (Op, Op->Asl.NameSeg); 579efcc2a30SJung-uk Kim 580efcc2a30SJung-uk Kim /* Special typechecking for _HID */ 581efcc2a30SJung-uk Kim 582f9a6772eSJung-uk Kim if (ACPI_COMPARE_NAMESEG (METHOD_NAME__HID, Op->Asl.NameSeg)) 583efcc2a30SJung-uk Kim { 584efcc2a30SJung-uk Kim Next = Op->Asl.Child->Asl.Next; 585efcc2a30SJung-uk Kim AnCheckId (Next, ASL_TYPE_HID); 586efcc2a30SJung-uk Kim } 587efcc2a30SJung-uk Kim 588efcc2a30SJung-uk Kim /* Special typechecking for _CID */ 589efcc2a30SJung-uk Kim 590f9a6772eSJung-uk Kim else if (ACPI_COMPARE_NAMESEG (METHOD_NAME__CID, Op->Asl.NameSeg)) 591efcc2a30SJung-uk Kim { 592efcc2a30SJung-uk Kim Next = Op->Asl.Child->Asl.Next; 593efcc2a30SJung-uk Kim 594efcc2a30SJung-uk Kim if ((Next->Asl.ParseOpcode == PARSEOP_PACKAGE) || 595efcc2a30SJung-uk Kim (Next->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)) 596efcc2a30SJung-uk Kim { 597efcc2a30SJung-uk Kim Next = Next->Asl.Child; 598efcc2a30SJung-uk Kim while (Next) 599efcc2a30SJung-uk Kim { 600efcc2a30SJung-uk Kim AnCheckId (Next, ASL_TYPE_CID); 601efcc2a30SJung-uk Kim Next = Next->Asl.Next; 602efcc2a30SJung-uk Kim } 603efcc2a30SJung-uk Kim } 604efcc2a30SJung-uk Kim else 605efcc2a30SJung-uk Kim { 606efcc2a30SJung-uk Kim AnCheckId (Next, ASL_TYPE_CID); 607efcc2a30SJung-uk Kim } 608efcc2a30SJung-uk Kim } 609313a0c13SJung-uk Kim 610efcc2a30SJung-uk Kim break; 611efcc2a30SJung-uk Kim 612efcc2a30SJung-uk Kim default: 613a9d8d09cSJung-uk Kim 614efcc2a30SJung-uk Kim break; 615efcc2a30SJung-uk Kim } 616efcc2a30SJung-uk Kim 617a9d8d09cSJung-uk Kim /* Check for named object creation within a non-serialized method */ 618a9d8d09cSJung-uk Kim 619a9d8d09cSJung-uk Kim MtCheckNamedObjectInMethod (Op, MethodInfo); 620efcc2a30SJung-uk Kim return (AE_OK); 621efcc2a30SJung-uk Kim } 622efcc2a30SJung-uk Kim 623efcc2a30SJung-uk Kim 624efcc2a30SJung-uk Kim /******************************************************************************* 625efcc2a30SJung-uk Kim * 626ec0234b4SJung-uk Kim * FUNCTION: MtProcessTypeOp 627ec0234b4SJung-uk Kim * 628ec0234b4SJung-uk Kim * PARAMETERS: Op - Op representing a btype 629ec0234b4SJung-uk Kim * 630ec0234b4SJung-uk Kim * RETURN: Btype represented by Op 631ec0234b4SJung-uk Kim * 632ec0234b4SJung-uk Kim * DESCRIPTION: Process a parse object that represents single parameter type or 633ec0234b4SJung-uk Kim * a return type in method, function, and external declarations. 634ec0234b4SJung-uk Kim * 635ec0234b4SJung-uk Kim ******************************************************************************/ 636ec0234b4SJung-uk Kim 637ec0234b4SJung-uk Kim UINT32 638ec0234b4SJung-uk Kim MtProcessTypeOp ( 639ec0234b4SJung-uk Kim ACPI_PARSE_OBJECT *TypeOp) 640ec0234b4SJung-uk Kim { 641ec0234b4SJung-uk Kim UINT32 Btype = ACPI_BTYPE_ANY; 642ec0234b4SJung-uk Kim 643ec0234b4SJung-uk Kim 644ec0234b4SJung-uk Kim while (TypeOp) 645ec0234b4SJung-uk Kim { 646ec0234b4SJung-uk Kim Btype |= AnMapObjTypeToBtype (TypeOp); 647ec0234b4SJung-uk Kim TypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; 648ec0234b4SJung-uk Kim TypeOp = TypeOp->Asl.Next; 649ec0234b4SJung-uk Kim } 650ec0234b4SJung-uk Kim 651ec0234b4SJung-uk Kim return (Btype); 652ec0234b4SJung-uk Kim } 653ec0234b4SJung-uk Kim 654ec0234b4SJung-uk Kim 655ec0234b4SJung-uk Kim /******************************************************************************* 656ec0234b4SJung-uk Kim * 657ec0234b4SJung-uk Kim * FUNCTION: MtProcessParameterTypeList 658ec0234b4SJung-uk Kim * 659ec0234b4SJung-uk Kim * PARAMETERS: Op - Op representing a btype 660ec0234b4SJung-uk Kim * 661ec0234b4SJung-uk Kim * RETURN: Btype represented by Op 662ec0234b4SJung-uk Kim * 663ec0234b4SJung-uk Kim * DESCRIPTION: Process a parse object that represents a parameter type list in 664ec0234b4SJung-uk Kim * method, function, and external declarations. 665ec0234b4SJung-uk Kim * 666ec0234b4SJung-uk Kim ******************************************************************************/ 667ec0234b4SJung-uk Kim 668ec0234b4SJung-uk Kim UINT8 669ec0234b4SJung-uk Kim MtProcessParameterTypeList ( 670ec0234b4SJung-uk Kim ACPI_PARSE_OBJECT *ParamTypeOp, 671ec0234b4SJung-uk Kim UINT32 *TypeList) 672ec0234b4SJung-uk Kim { 673ec0234b4SJung-uk Kim UINT8 ParameterCount = 0; 674ec0234b4SJung-uk Kim 675ec0234b4SJung-uk Kim 676*61b18036SJung-uk Kim if (ParamTypeOp && ParamTypeOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) 677*61b18036SJung-uk Kim { 678*61b18036SJung-uk Kim /* Special case for a single parameter without braces */ 679*61b18036SJung-uk Kim 680*61b18036SJung-uk Kim TypeList[ParameterCount] = 681*61b18036SJung-uk Kim MtProcessTypeOp (ParamTypeOp); 682*61b18036SJung-uk Kim 683*61b18036SJung-uk Kim return (1); 684*61b18036SJung-uk Kim } 685*61b18036SJung-uk Kim 686ec0234b4SJung-uk Kim while (ParamTypeOp) 687ec0234b4SJung-uk Kim { 688ec0234b4SJung-uk Kim TypeList[ParameterCount] = 689ec0234b4SJung-uk Kim MtProcessTypeOp (ParamTypeOp->Asl.Child); 690ec0234b4SJung-uk Kim 691ec0234b4SJung-uk Kim ParameterCount++; 692ec0234b4SJung-uk Kim ParamTypeOp = ParamTypeOp->Asl.Next; 693ec0234b4SJung-uk Kim } 694ec0234b4SJung-uk Kim 695ec0234b4SJung-uk Kim return (ParameterCount); 696ec0234b4SJung-uk Kim } 697ec0234b4SJung-uk Kim 698ec0234b4SJung-uk Kim 699ec0234b4SJung-uk Kim /******************************************************************************* 700ec0234b4SJung-uk Kim * 701a9d8d09cSJung-uk Kim * FUNCTION: MtCheckNamedObjectInMethod 702a9d8d09cSJung-uk Kim * 703a9d8d09cSJung-uk Kim * PARAMETERS: Op - Current parser op 704a9d8d09cSJung-uk Kim * MethodInfo - Info for method being parsed 705a9d8d09cSJung-uk Kim * 706a9d8d09cSJung-uk Kim * RETURN: None 707a9d8d09cSJung-uk Kim * 708a9d8d09cSJung-uk Kim * DESCRIPTION: Detect if a non-serialized method is creating a named object, 709a9d8d09cSJung-uk Kim * which could possibly cause problems if two threads execute 710a9d8d09cSJung-uk Kim * the method concurrently. Emit a remark in this case. 711a9d8d09cSJung-uk Kim * 712a9d8d09cSJung-uk Kim ******************************************************************************/ 713a9d8d09cSJung-uk Kim 714f8146b88SJung-uk Kim static void 715a9d8d09cSJung-uk Kim MtCheckNamedObjectInMethod ( 716a9d8d09cSJung-uk Kim ACPI_PARSE_OBJECT *Op, 717a9d8d09cSJung-uk Kim ASL_METHOD_INFO *MethodInfo) 718a9d8d09cSJung-uk Kim { 719a9d8d09cSJung-uk Kim const ACPI_OPCODE_INFO *OpInfo; 720ec0234b4SJung-uk Kim char *ExternalPath; 721a9d8d09cSJung-uk Kim 722a9d8d09cSJung-uk Kim 723f8146b88SJung-uk Kim /* We don't care about actual method declarations or scopes */ 724a9d8d09cSJung-uk Kim 725f8146b88SJung-uk Kim if ((Op->Asl.AmlOpcode == AML_METHOD_OP) || 726f8146b88SJung-uk Kim (Op->Asl.AmlOpcode == AML_SCOPE_OP)) 727a9d8d09cSJung-uk Kim { 728a9d8d09cSJung-uk Kim return; 729a9d8d09cSJung-uk Kim } 730a9d8d09cSJung-uk Kim 73167d9aa44SJung-uk Kim /* Determine if we are creating a named object within a method */ 73267d9aa44SJung-uk Kim 73367d9aa44SJung-uk Kim if (!MethodInfo) 73467d9aa44SJung-uk Kim { 73567d9aa44SJung-uk Kim return; 73667d9aa44SJung-uk Kim } 737a9d8d09cSJung-uk Kim 738a9d8d09cSJung-uk Kim OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); 7390b229c80SJung-uk Kim if ((OpInfo->Class == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_FIELD_OP)) 740a9d8d09cSJung-uk Kim { 741a9d8d09cSJung-uk Kim /* 74267d9aa44SJung-uk Kim * 1) Mark the method as a method that creates named objects. 74367d9aa44SJung-uk Kim * 744ec0234b4SJung-uk Kim * 2) Issue a remark indicating the inefficiency of creating named 745ec0234b4SJung-uk Kim * objects within a method (Except for compiler-emitted temporary 746ec0234b4SJung-uk Kim * variables). 747ec0234b4SJung-uk Kim * 748ec0234b4SJung-uk Kim * 3) If the method is non-serialized, emit a remark that the method 74967d9aa44SJung-uk Kim * should be serialized. 750a9d8d09cSJung-uk Kim * 751a9d8d09cSJung-uk Kim * Reason: If a thread blocks within the method for any reason, and 75267d9aa44SJung-uk Kim * another thread enters the method, the method will fail because 75367d9aa44SJung-uk Kim * an attempt will be made to create the same object twice. 7540b229c80SJung-uk Kim * 7550b229c80SJung-uk Kim * Note: The Field opcode is disallowed here because Field() does not 7560b229c80SJung-uk Kim * create a new named object. 757a9d8d09cSJung-uk Kim */ 758ec0234b4SJung-uk Kim ExternalPath = AcpiNsGetNormalizedPathname (MethodInfo->Op->Asl.Node, TRUE); 759ec0234b4SJung-uk Kim 760ec0234b4SJung-uk Kim /* No error for compiler temp variables (name starts with "_T_") */ 761ec0234b4SJung-uk Kim 762ec0234b4SJung-uk Kim if ((Op->Asl.NameSeg[0] != '_') && 763ec0234b4SJung-uk Kim (Op->Asl.NameSeg[1] != 'T') && 764ec0234b4SJung-uk Kim (Op->Asl.NameSeg[2] != '_')) 765ec0234b4SJung-uk Kim { 766ec0234b4SJung-uk Kim AslError (ASL_REMARK, ASL_MSG_NAMED_OBJECT_CREATION, Op, 767ec0234b4SJung-uk Kim ExternalPath); 768ec0234b4SJung-uk Kim } 769ec0234b4SJung-uk Kim 77067d9aa44SJung-uk Kim MethodInfo->CreatesNamedObjects = TRUE; 77167d9aa44SJung-uk Kim if (!MethodInfo->ShouldBeSerialized) 772a9d8d09cSJung-uk Kim { 773a9d8d09cSJung-uk Kim AslError (ASL_REMARK, ASL_MSG_SERIALIZED_REQUIRED, MethodInfo->Op, 774ec0234b4SJung-uk Kim ExternalPath); 775a9d8d09cSJung-uk Kim 776a9d8d09cSJung-uk Kim /* Emit message only ONCE per method */ 777a9d8d09cSJung-uk Kim 778a9d8d09cSJung-uk Kim MethodInfo->ShouldBeSerialized = TRUE; 779a9d8d09cSJung-uk Kim } 780ec0234b4SJung-uk Kim 781ec0234b4SJung-uk Kim if (ExternalPath) 782ec0234b4SJung-uk Kim { 783ec0234b4SJung-uk Kim ACPI_FREE (ExternalPath); 784a9d8d09cSJung-uk Kim } 785a9d8d09cSJung-uk Kim } 786ec0234b4SJung-uk Kim } 787ec0234b4SJung-uk Kim 788ec0234b4SJung-uk Kim 789ec0234b4SJung-uk Kim /******************************************************************************* 790ec0234b4SJung-uk Kim * 791ec0234b4SJung-uk Kim * FUNCTION: MtCheckStaticOperationRegionInMethod 792ec0234b4SJung-uk Kim * 793ec0234b4SJung-uk Kim * PARAMETERS: Op - Current parser op 794ec0234b4SJung-uk Kim * 795ec0234b4SJung-uk Kim * RETURN: None 796ec0234b4SJung-uk Kim * 797ec0234b4SJung-uk Kim * DESCRIPTION: Warns if an Operation Region with static address or length 798ec0234b4SJung-uk Kim * is declared inside a control method 799ec0234b4SJung-uk Kim * 800ec0234b4SJung-uk Kim ******************************************************************************/ 801ec0234b4SJung-uk Kim 802ec0234b4SJung-uk Kim static void 803ec0234b4SJung-uk Kim MtCheckStaticOperationRegionInMethod( 804ec0234b4SJung-uk Kim ACPI_PARSE_OBJECT* Op) 805ec0234b4SJung-uk Kim { 806ec0234b4SJung-uk Kim ACPI_PARSE_OBJECT* AddressOp; 807ec0234b4SJung-uk Kim ACPI_PARSE_OBJECT* LengthOp; 808ec0234b4SJung-uk Kim 809ec0234b4SJung-uk Kim 810ec0234b4SJung-uk Kim if (Op->Asl.ParseOpcode != PARSEOP_OPERATIONREGION) 811ec0234b4SJung-uk Kim { 812ec0234b4SJung-uk Kim return; 813ec0234b4SJung-uk Kim } 814ec0234b4SJung-uk Kim 815ec0234b4SJung-uk Kim /* 816ec0234b4SJung-uk Kim * OperationRegion should have 4 arguments defined. At this point, we 817ec0234b4SJung-uk Kim * assume that the parse tree is well-formed. 818ec0234b4SJung-uk Kim */ 819ec0234b4SJung-uk Kim AddressOp = Op->Asl.Child->Asl.Next->Asl.Next; 820ec0234b4SJung-uk Kim LengthOp = Op->Asl.Child->Asl.Next->Asl.Next->Asl.Next; 821ec0234b4SJung-uk Kim 822ec0234b4SJung-uk Kim if (UtGetParentMethodOp (Op) && 823ec0234b4SJung-uk Kim AddressOp->Asl.ParseOpcode == PARSEOP_INTEGER && 824ec0234b4SJung-uk Kim LengthOp->Asl.ParseOpcode == PARSEOP_INTEGER) 825ec0234b4SJung-uk Kim { 826ec0234b4SJung-uk Kim /* 827ec0234b4SJung-uk Kim * At this point, a static operation region declared inside of a 828ec0234b4SJung-uk Kim * control method has been found. Throw a warning because this is 829ec0234b4SJung-uk Kim * highly inefficient. 830ec0234b4SJung-uk Kim */ 831ec0234b4SJung-uk Kim AslError(ASL_WARNING, ASL_MSG_STATIC_OPREGION_IN_METHOD, Op, NULL); 832ec0234b4SJung-uk Kim } 833ec0234b4SJung-uk Kim 834ec0234b4SJung-uk Kim return; 835ec0234b4SJung-uk Kim } 836a9d8d09cSJung-uk Kim 837a9d8d09cSJung-uk Kim 838a9d8d09cSJung-uk Kim /******************************************************************************* 839a9d8d09cSJung-uk Kim * 840efcc2a30SJung-uk Kim * FUNCTION: MtMethodAnalysisWalkEnd 841efcc2a30SJung-uk Kim * 842efcc2a30SJung-uk Kim * PARAMETERS: ASL_WALK_CALLBACK 843efcc2a30SJung-uk Kim * 844efcc2a30SJung-uk Kim * RETURN: Status 845efcc2a30SJung-uk Kim * 846efcc2a30SJung-uk Kim * DESCRIPTION: Ascending callback for analysis walk. Complete method 847efcc2a30SJung-uk Kim * return analysis. 848efcc2a30SJung-uk Kim * 849efcc2a30SJung-uk Kim ******************************************************************************/ 850efcc2a30SJung-uk Kim 851efcc2a30SJung-uk Kim ACPI_STATUS 852efcc2a30SJung-uk Kim MtMethodAnalysisWalkEnd ( 853efcc2a30SJung-uk Kim ACPI_PARSE_OBJECT *Op, 854efcc2a30SJung-uk Kim UINT32 Level, 855efcc2a30SJung-uk Kim void *Context) 856efcc2a30SJung-uk Kim { 857efcc2a30SJung-uk Kim ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context; 858efcc2a30SJung-uk Kim ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack; 859ec0234b4SJung-uk Kim char *ExternalPath; 860efcc2a30SJung-uk Kim 861efcc2a30SJung-uk Kim 862efcc2a30SJung-uk Kim switch (Op->Asl.ParseOpcode) 863efcc2a30SJung-uk Kim { 864efcc2a30SJung-uk Kim case PARSEOP_METHOD: 865efcc2a30SJung-uk Kim case PARSEOP_RETURN: 866a9d8d09cSJung-uk Kim 867efcc2a30SJung-uk Kim if (!MethodInfo) 868efcc2a30SJung-uk Kim { 869efcc2a30SJung-uk Kim printf ("No method info for method! [%s]\n", Op->Asl.Namepath); 870efcc2a30SJung-uk Kim AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op, 871efcc2a30SJung-uk Kim "No method info for this method"); 872efcc2a30SJung-uk Kim 873efcc2a30SJung-uk Kim CmCleanupAndExit (); 874efcc2a30SJung-uk Kim return (AE_AML_INTERNAL); 875efcc2a30SJung-uk Kim } 876efcc2a30SJung-uk Kim break; 877efcc2a30SJung-uk Kim 878efcc2a30SJung-uk Kim default: 879a9d8d09cSJung-uk Kim 880efcc2a30SJung-uk Kim break; 881efcc2a30SJung-uk Kim } 882efcc2a30SJung-uk Kim 883efcc2a30SJung-uk Kim switch (Op->Asl.ParseOpcode) 884efcc2a30SJung-uk Kim { 885efcc2a30SJung-uk Kim case PARSEOP_METHOD: 886efcc2a30SJung-uk Kim 887efcc2a30SJung-uk Kim WalkInfo->MethodStack = MethodInfo->Next; 888efcc2a30SJung-uk Kim 889efcc2a30SJung-uk Kim /* 890efcc2a30SJung-uk Kim * Check if there is no return statement at the end of the 891efcc2a30SJung-uk Kim * method AND we can actually get there -- i.e., the execution 892efcc2a30SJung-uk Kim * of the method can possibly terminate without a return statement. 893efcc2a30SJung-uk Kim */ 894efcc2a30SJung-uk Kim if ((!AnLastStatementIsReturn (Op)) && 8955f9b24faSJung-uk Kim (!(Op->Asl.CompileFlags & OP_HAS_NO_EXIT))) 896efcc2a30SJung-uk Kim { 897efcc2a30SJung-uk Kim /* 898efcc2a30SJung-uk Kim * No return statement, and execution can possibly exit 899efcc2a30SJung-uk Kim * via this path. This is equivalent to Return () 900efcc2a30SJung-uk Kim */ 901efcc2a30SJung-uk Kim MethodInfo->NumReturnNoValue++; 902efcc2a30SJung-uk Kim } 903efcc2a30SJung-uk Kim 904efcc2a30SJung-uk Kim /* 905efcc2a30SJung-uk Kim * Check for case where some return statements have a return value 906efcc2a30SJung-uk Kim * and some do not. Exit without a return statement is a return with 907efcc2a30SJung-uk Kim * no value 908efcc2a30SJung-uk Kim */ 909efcc2a30SJung-uk Kim if (MethodInfo->NumReturnNoValue && 910efcc2a30SJung-uk Kim MethodInfo->NumReturnWithValue) 911efcc2a30SJung-uk Kim { 912ec0234b4SJung-uk Kim ExternalPath = AcpiNsGetNormalizedPathname (Op->Asl.Node, TRUE); 913ec0234b4SJung-uk Kim 914efcc2a30SJung-uk Kim AslError (ASL_WARNING, ASL_MSG_RETURN_TYPES, Op, 915ec0234b4SJung-uk Kim ExternalPath); 916ec0234b4SJung-uk Kim 917ec0234b4SJung-uk Kim if (ExternalPath) 918ec0234b4SJung-uk Kim { 919ec0234b4SJung-uk Kim ACPI_FREE (ExternalPath); 920ec0234b4SJung-uk Kim } 921efcc2a30SJung-uk Kim } 922efcc2a30SJung-uk Kim 923efcc2a30SJung-uk Kim /* 924efcc2a30SJung-uk Kim * If there are any RETURN() statements with no value, or there is a 925efcc2a30SJung-uk Kim * control path that allows the method to exit without a return value, 926efcc2a30SJung-uk Kim * we mark the method as a method that does not return a value. This 927efcc2a30SJung-uk Kim * knowledge can be used to check method invocations that expect a 928efcc2a30SJung-uk Kim * returned value. 929efcc2a30SJung-uk Kim */ 930efcc2a30SJung-uk Kim if (MethodInfo->NumReturnNoValue) 931efcc2a30SJung-uk Kim { 932efcc2a30SJung-uk Kim if (MethodInfo->NumReturnWithValue) 933efcc2a30SJung-uk Kim { 9345f9b24faSJung-uk Kim Op->Asl.CompileFlags |= OP_METHOD_SOME_NO_RETVAL; 935efcc2a30SJung-uk Kim } 936efcc2a30SJung-uk Kim else 937efcc2a30SJung-uk Kim { 9385f9b24faSJung-uk Kim Op->Asl.CompileFlags |= OP_METHOD_NO_RETVAL; 939efcc2a30SJung-uk Kim } 940efcc2a30SJung-uk Kim } 941efcc2a30SJung-uk Kim 942efcc2a30SJung-uk Kim /* 943efcc2a30SJung-uk Kim * Check predefined method names for correct return behavior 944efcc2a30SJung-uk Kim * and correct number of arguments. Also, some special checks 945efcc2a30SJung-uk Kim * For GPE and _REG methods. 946efcc2a30SJung-uk Kim */ 947efcc2a30SJung-uk Kim if (ApCheckForPredefinedMethod (Op, MethodInfo)) 948efcc2a30SJung-uk Kim { 949efcc2a30SJung-uk Kim /* Special check for two names like _L01 and _E01 in same scope */ 950efcc2a30SJung-uk Kim 951efcc2a30SJung-uk Kim ApCheckForGpeNameConflict (Op); 952efcc2a30SJung-uk Kim 953efcc2a30SJung-uk Kim /* 954efcc2a30SJung-uk Kim * Special check for _REG: Must have an operation region definition 955efcc2a30SJung-uk Kim * within the same scope! 956efcc2a30SJung-uk Kim */ 957efcc2a30SJung-uk Kim ApCheckRegMethod (Op); 958efcc2a30SJung-uk Kim } 959efcc2a30SJung-uk Kim 960efcc2a30SJung-uk Kim ACPI_FREE (MethodInfo); 961efcc2a30SJung-uk Kim break; 962efcc2a30SJung-uk Kim 963efcc2a30SJung-uk Kim case PARSEOP_NAME: 964efcc2a30SJung-uk Kim 965efcc2a30SJung-uk Kim /* Special check for two names like _L01 and _E01 in same scope */ 966efcc2a30SJung-uk Kim 967efcc2a30SJung-uk Kim ApCheckForGpeNameConflict (Op); 968efcc2a30SJung-uk Kim break; 969efcc2a30SJung-uk Kim 970efcc2a30SJung-uk Kim case PARSEOP_RETURN: 971efcc2a30SJung-uk Kim 972efcc2a30SJung-uk Kim /* 973efcc2a30SJung-uk Kim * If the parent is a predefined method name, attempt to typecheck 974efcc2a30SJung-uk Kim * the return value. Only static types can be validated. 975efcc2a30SJung-uk Kim */ 976efcc2a30SJung-uk Kim ApCheckPredefinedReturnValue (Op, MethodInfo); 977efcc2a30SJung-uk Kim 978efcc2a30SJung-uk Kim /* 979efcc2a30SJung-uk Kim * The parent block does not "exit" and continue execution -- the 980efcc2a30SJung-uk Kim * method is terminated here with the Return() statement. 981efcc2a30SJung-uk Kim */ 9825f9b24faSJung-uk Kim Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT; 983efcc2a30SJung-uk Kim 984efcc2a30SJung-uk Kim /* Used in the "typing" pass later */ 985efcc2a30SJung-uk Kim 986efcc2a30SJung-uk Kim Op->Asl.ParentMethod = MethodInfo->Op; 987efcc2a30SJung-uk Kim 988efcc2a30SJung-uk Kim /* 989efcc2a30SJung-uk Kim * If there is a peer node after the return statement, then this 990efcc2a30SJung-uk Kim * node is unreachable code -- i.e., it won't be executed because of 991efcc2a30SJung-uk Kim * the preceding Return() statement. 992efcc2a30SJung-uk Kim */ 993efcc2a30SJung-uk Kim if (Op->Asl.Next) 994efcc2a30SJung-uk Kim { 995f8146b88SJung-uk Kim AslError (ASL_WARNING, ASL_MSG_UNREACHABLE_CODE, 996f8146b88SJung-uk Kim Op->Asl.Next, NULL); 997efcc2a30SJung-uk Kim } 998efcc2a30SJung-uk Kim break; 999efcc2a30SJung-uk Kim 1000efcc2a30SJung-uk Kim case PARSEOP_IF: 1001efcc2a30SJung-uk Kim 10025f9b24faSJung-uk Kim if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) && 1003efcc2a30SJung-uk Kim (Op->Asl.Next) && 1004efcc2a30SJung-uk Kim (Op->Asl.Next->Asl.ParseOpcode == PARSEOP_ELSE)) 1005efcc2a30SJung-uk Kim { 1006efcc2a30SJung-uk Kim /* 1007efcc2a30SJung-uk Kim * This IF has a corresponding ELSE. The IF block has no exit, 1008efcc2a30SJung-uk Kim * (it contains an unconditional Return) 1009efcc2a30SJung-uk Kim * mark the ELSE block to remember this fact. 1010efcc2a30SJung-uk Kim */ 10115f9b24faSJung-uk Kim Op->Asl.Next->Asl.CompileFlags |= OP_IF_HAS_NO_EXIT; 1012efcc2a30SJung-uk Kim } 1013efcc2a30SJung-uk Kim break; 1014efcc2a30SJung-uk Kim 1015efcc2a30SJung-uk Kim case PARSEOP_ELSE: 1016efcc2a30SJung-uk Kim 10175f9b24faSJung-uk Kim if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) && 10185f9b24faSJung-uk Kim (Op->Asl.CompileFlags & OP_IF_HAS_NO_EXIT)) 1019efcc2a30SJung-uk Kim { 1020efcc2a30SJung-uk Kim /* 1021efcc2a30SJung-uk Kim * This ELSE block has no exit and the corresponding IF block 1022efcc2a30SJung-uk Kim * has no exit either. Therefore, the parent node has no exit. 1023efcc2a30SJung-uk Kim */ 10245f9b24faSJung-uk Kim Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT; 1025efcc2a30SJung-uk Kim } 1026efcc2a30SJung-uk Kim break; 1027efcc2a30SJung-uk Kim 1028efcc2a30SJung-uk Kim 1029efcc2a30SJung-uk Kim default: 1030efcc2a30SJung-uk Kim 10315f9b24faSJung-uk Kim if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) && 1032efcc2a30SJung-uk Kim (Op->Asl.Parent)) 1033efcc2a30SJung-uk Kim { 1034efcc2a30SJung-uk Kim /* If this node has no exit, then the parent has no exit either */ 1035efcc2a30SJung-uk Kim 10365f9b24faSJung-uk Kim Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT; 1037efcc2a30SJung-uk Kim } 1038efcc2a30SJung-uk Kim break; 1039efcc2a30SJung-uk Kim } 1040efcc2a30SJung-uk Kim 1041efcc2a30SJung-uk Kim return (AE_OK); 1042efcc2a30SJung-uk Kim } 1043