1 1.1 christos /****************************************************************************** 2 1.1 christos * 3 1.1 christos * Module Name: aslmethod.c - Control method analysis walk 4 1.1 christos * 5 1.1 christos *****************************************************************************/ 6 1.1 christos 7 1.1.1.20 christos /****************************************************************************** 8 1.1.1.20 christos * 9 1.1.1.20 christos * 1. Copyright Notice 10 1.1.1.20 christos * 11 1.1.1.21 christos * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp. 12 1.1 christos * All rights reserved. 13 1.1 christos * 14 1.1.1.20 christos * 2. License 15 1.1.1.20 christos * 16 1.1.1.20 christos * 2.1. This is your license from Intel Corp. under its intellectual property 17 1.1.1.20 christos * rights. You may have additional license terms from the party that provided 18 1.1.1.20 christos * you this software, covering your right to use that party's intellectual 19 1.1.1.20 christos * property rights. 20 1.1.1.20 christos * 21 1.1.1.20 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 1.1.1.20 christos * copy of the source code appearing in this file ("Covered Code") an 23 1.1.1.20 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 1.1.1.20 christos * base code distributed originally by Intel ("Original Intel Code") to copy, 25 1.1.1.20 christos * make derivatives, distribute, use and display any portion of the Covered 26 1.1.1.20 christos * Code in any form, with the right to sublicense such rights; and 27 1.1.1.20 christos * 28 1.1.1.20 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 1.1.1.20 christos * license (with the right to sublicense), under only those claims of Intel 30 1.1.1.20 christos * patents that are infringed by the Original Intel Code, to make, use, sell, 31 1.1.1.20 christos * offer to sell, and import the Covered Code and derivative works thereof 32 1.1.1.20 christos * solely to the minimum extent necessary to exercise the above copyright 33 1.1.1.20 christos * license, and in no event shall the patent license extend to any additions 34 1.1.1.20 christos * to or modifications of the Original Intel Code. No other license or right 35 1.1.1.20 christos * is granted directly or by implication, estoppel or otherwise; 36 1.1.1.20 christos * 37 1.1.1.20 christos * The above copyright and patent license is granted only if the following 38 1.1.1.20 christos * conditions are met: 39 1.1.1.20 christos * 40 1.1.1.20 christos * 3. Conditions 41 1.1.1.20 christos * 42 1.1.1.20 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 1.1.1.20 christos * Redistribution of source code of any substantial portion of the Covered 44 1.1.1.20 christos * Code or modification with rights to further distribute source must include 45 1.1.1.20 christos * the above Copyright Notice, the above License, this list of Conditions, 46 1.1.1.20 christos * and the following Disclaimer and Export Compliance provision. In addition, 47 1.1.1.20 christos * Licensee must cause all Covered Code to which Licensee contributes to 48 1.1.1.20 christos * contain a file documenting the changes Licensee made to create that Covered 49 1.1.1.20 christos * Code and the date of any change. Licensee must include in that file the 50 1.1.1.20 christos * documentation of any changes made by any predecessor Licensee. Licensee 51 1.1.1.20 christos * must include a prominent statement that the modification is derived, 52 1.1.1.20 christos * directly or indirectly, from Original Intel Code. 53 1.1.1.20 christos * 54 1.1.1.20 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 1.1.1.20 christos * Redistribution of source code of any substantial portion of the Covered 56 1.1.1.20 christos * Code or modification without rights to further distribute source must 57 1.1.1.20 christos * include the following Disclaimer and Export Compliance provision in the 58 1.1.1.20 christos * documentation and/or other materials provided with distribution. In 59 1.1.1.20 christos * addition, Licensee may not authorize further sublicense of source of any 60 1.1.1.20 christos * portion of the Covered Code, and must include terms to the effect that the 61 1.1.1.20 christos * license from Licensee to its licensee is limited to the intellectual 62 1.1.1.20 christos * property embodied in the software Licensee provides to its licensee, and 63 1.1.1.20 christos * not to intellectual property embodied in modifications its licensee may 64 1.1.1.20 christos * make. 65 1.1.1.20 christos * 66 1.1.1.20 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 1.1.1.20 christos * substantial portion of the Covered Code or modification must reproduce the 68 1.1.1.20 christos * above Copyright Notice, and the following Disclaimer and Export Compliance 69 1.1.1.20 christos * provision in the documentation and/or other materials provided with the 70 1.1.1.20 christos * distribution. 71 1.1.1.20 christos * 72 1.1.1.20 christos * 3.4. Intel retains all right, title, and interest in and to the Original 73 1.1.1.20 christos * Intel Code. 74 1.1.1.20 christos * 75 1.1.1.20 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 1.1.1.20 christos * Intel shall be used in advertising or otherwise to promote the sale, use or 77 1.1.1.20 christos * other dealings in products derived from or relating to the Covered Code 78 1.1.1.20 christos * without prior written authorization from Intel. 79 1.1.1.20 christos * 80 1.1.1.20 christos * 4. Disclaimer and Export Compliance 81 1.1.1.20 christos * 82 1.1.1.20 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 1.1.1.20 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 1.1.1.20 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 1.1.1.20 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 1.1.1.20 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 1.1.1.20 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 1.1.1.20 christos * PARTICULAR PURPOSE. 89 1.1.1.20 christos * 90 1.1.1.20 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 1.1.1.20 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 1.1.1.20 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 1.1.1.20 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 1.1.1.20 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 1.1.1.20 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 1.1.1.20 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 1.1.1.20 christos * LIMITED REMEDY. 98 1.1.1.20 christos * 99 1.1.1.20 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 1.1.1.20 christos * software or system incorporating such software without first obtaining any 101 1.1.1.20 christos * required license or other approval from the U. S. Department of Commerce or 102 1.1.1.20 christos * any other agency or department of the United States Government. In the 103 1.1.1.20 christos * event Licensee exports any such software from the United States or 104 1.1.1.20 christos * re-exports any such software from a foreign destination, Licensee shall 105 1.1.1.20 christos * ensure that the distribution and export/re-export of the software is in 106 1.1.1.20 christos * compliance with all laws, regulations, orders, or other restrictions of the 107 1.1.1.20 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 1.1.1.20 christos * any of its subsidiaries will export/re-export any technical data, process, 109 1.1.1.20 christos * software, or service, directly or indirectly, to any country for which the 110 1.1.1.20 christos * United States government or any agency thereof requires an export license, 111 1.1.1.20 christos * other governmental approval, or letter of assurance, without first obtaining 112 1.1.1.20 christos * such license, approval or letter. 113 1.1.1.20 christos * 114 1.1.1.20 christos ***************************************************************************** 115 1.1.1.20 christos * 116 1.1.1.20 christos * Alternatively, you may choose to be licensed under the terms of the 117 1.1.1.20 christos * following license: 118 1.1.1.20 christos * 119 1.1 christos * Redistribution and use in source and binary forms, with or without 120 1.1 christos * modification, are permitted provided that the following conditions 121 1.1 christos * are met: 122 1.1 christos * 1. Redistributions of source code must retain the above copyright 123 1.1 christos * notice, this list of conditions, and the following disclaimer, 124 1.1 christos * without modification. 125 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below 127 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon 128 1.1 christos * including a substantially similar Disclaimer requirement for further 129 1.1 christos * binary redistribution. 130 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names 131 1.1 christos * of any contributors may be used to endorse or promote products derived 132 1.1 christos * from this software without specific prior written permission. 133 1.1 christos * 134 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 1.1.1.16 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 1.1.1.20 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 1.1.1.20 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 1.1.1.20 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 1.1.1.20 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 1.1.1.20 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 1.1.1.20 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 1.1.1.20 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 1.1.1.20 christos * 146 1.1.1.20 christos * Alternatively, you may choose to be licensed under the terms of the 147 1.1.1.20 christos * GNU General Public License ("GPL") version 2 as published by the Free 148 1.1.1.20 christos * Software Foundation. 149 1.1.1.20 christos * 150 1.1.1.20 christos *****************************************************************************/ 151 1.1 christos 152 1.1 christos #include "aslcompiler.h" 153 1.1 christos #include "aslcompiler.y.h" 154 1.1.1.14 christos #include "acnamesp.h" 155 1.1 christos #include "acparser.h" 156 1.1 christos #include "amlcode.h" 157 1.1 christos 158 1.1 christos 159 1.1 christos #define _COMPONENT ACPI_COMPILER 160 1.1 christos ACPI_MODULE_NAME ("aslmethod") 161 1.1 christos 162 1.1 christos 163 1.1 christos /* Local prototypes */ 164 1.1 christos 165 1.1.1.6 christos static void 166 1.1 christos MtCheckNamedObjectInMethod ( 167 1.1 christos ACPI_PARSE_OBJECT *Op, 168 1.1 christos ASL_METHOD_INFO *MethodInfo); 169 1.1 christos 170 1.1.1.14 christos static void 171 1.1.1.14 christos MtCheckStaticOperationRegionInMethod ( 172 1.1.1.14 christos ACPI_PARSE_OBJECT *Op); 173 1.1.1.14 christos 174 1.1 christos 175 1.1 christos /******************************************************************************* 176 1.1 christos * 177 1.1 christos * FUNCTION: MtMethodAnalysisWalkBegin 178 1.1 christos * 179 1.1 christos * PARAMETERS: ASL_WALK_CALLBACK 180 1.1 christos * 181 1.1 christos * RETURN: Status 182 1.1 christos * 183 1.1 christos * DESCRIPTION: Descending callback for the analysis walk. Check methods for: 184 1.1 christos * 1) Initialized local variables 185 1.1 christos * 2) Valid arguments 186 1.1 christos * 3) Return types 187 1.1 christos * 188 1.1 christos ******************************************************************************/ 189 1.1 christos 190 1.1 christos ACPI_STATUS 191 1.1 christos MtMethodAnalysisWalkBegin ( 192 1.1 christos ACPI_PARSE_OBJECT *Op, 193 1.1 christos UINT32 Level, 194 1.1 christos void *Context) 195 1.1 christos { 196 1.1 christos ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context; 197 1.1 christos ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack; 198 1.1 christos ACPI_PARSE_OBJECT *Next; 199 1.1 christos UINT32 RegisterNumber; 200 1.1 christos UINT32 i; 201 1.1 christos char LocalName[] = "Local0"; 202 1.1 christos char ArgName[] = "Arg0"; 203 1.1 christos ACPI_PARSE_OBJECT *ArgNode; 204 1.1 christos ACPI_PARSE_OBJECT *NextType; 205 1.1 christos UINT8 ActualArgs = 0; 206 1.1.1.13 christos BOOLEAN HidExists; 207 1.1.1.13 christos BOOLEAN AdrExists; 208 1.1.1.17 christos BOOLEAN PrsExists; 209 1.1.1.17 christos BOOLEAN CrsExists; 210 1.1.1.17 christos BOOLEAN SrsExists; 211 1.1.1.17 christos BOOLEAN DisExists; 212 1.1 christos 213 1.1 christos 214 1.1.1.6 christos /* Build cross-reference output file if requested */ 215 1.1.1.6 christos 216 1.1.1.11 christos if (AslGbl_CrossReferenceOutput) 217 1.1.1.6 christos { 218 1.1.1.6 christos OtXrefWalkPart1 (Op, Level, MethodInfo); 219 1.1.1.6 christos } 220 1.1.1.6 christos 221 1.1 christos switch (Op->Asl.ParseOpcode) 222 1.1 christos { 223 1.1 christos case PARSEOP_METHOD: 224 1.1 christos 225 1.1.1.11 christos AslGbl_TotalMethods++; 226 1.1 christos 227 1.1 christos /* Create and init method info */ 228 1.1 christos 229 1.1.1.5 christos MethodInfo = UtLocalCalloc (sizeof (ASL_METHOD_INFO)); 230 1.1 christos MethodInfo->Next = WalkInfo->MethodStack; 231 1.1 christos MethodInfo->Op = Op; 232 1.1 christos 233 1.1 christos WalkInfo->MethodStack = MethodInfo; 234 1.1 christos 235 1.1.1.2 christos /* 236 1.1.1.2 christos * Special handling for _PSx methods. Dependency rules (same scope): 237 1.1.1.2 christos * 238 1.1.1.2 christos * 1) _PS0 - One of these must exist: _PS1, _PS2, _PS3 239 1.1.1.2 christos * 2) _PS1/_PS2/_PS3: A _PS0 must exist 240 1.1.1.2 christos */ 241 1.1.1.12 christos if (ACPI_COMPARE_NAMESEG (METHOD_NAME__PS0, Op->Asl.NameSeg)) 242 1.1.1.2 christos { 243 1.1.1.2 christos /* For _PS0, one of _PS1/_PS2/_PS3 must exist */ 244 1.1.1.2 christos 245 1.1.1.2 christos if ((!ApFindNameInScope (METHOD_NAME__PS1, Op)) && 246 1.1.1.2 christos (!ApFindNameInScope (METHOD_NAME__PS2, Op)) && 247 1.1.1.2 christos (!ApFindNameInScope (METHOD_NAME__PS3, Op))) 248 1.1.1.2 christos { 249 1.1.1.2 christos AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, 250 1.1.1.2 christos "_PS0 requires one of _PS1/_PS2/_PS3 in same scope"); 251 1.1.1.2 christos } 252 1.1.1.2 christos } 253 1.1.1.2 christos else if ( 254 1.1.1.12 christos ACPI_COMPARE_NAMESEG (METHOD_NAME__PS1, Op->Asl.NameSeg) || 255 1.1.1.12 christos ACPI_COMPARE_NAMESEG (METHOD_NAME__PS2, Op->Asl.NameSeg) || 256 1.1.1.12 christos ACPI_COMPARE_NAMESEG (METHOD_NAME__PS3, Op->Asl.NameSeg)) 257 1.1.1.2 christos { 258 1.1.1.2 christos /* For _PS1/_PS2/_PS3, a _PS0 must exist */ 259 1.1.1.2 christos 260 1.1.1.2 christos if (!ApFindNameInScope (METHOD_NAME__PS0, Op)) 261 1.1.1.2 christos { 262 1.1.1.11 christos sprintf (AslGbl_MsgBuffer, 263 1.1.1.2 christos "%4.4s requires _PS0 in same scope", Op->Asl.NameSeg); 264 1.1.1.2 christos 265 1.1.1.2 christos AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, 266 1.1.1.11 christos AslGbl_MsgBuffer); 267 1.1.1.2 christos } 268 1.1.1.2 christos } 269 1.1.1.2 christos 270 1.1.1.2 christos /* Get the name node */ 271 1.1 christos 272 1.1 christos Next = Op->Asl.Child; 273 1.1 christos 274 1.1 christos /* Get the NumArguments node */ 275 1.1 christos 276 1.1 christos Next = Next->Asl.Next; 277 1.1 christos MethodInfo->NumArguments = (UINT8) 278 1.1 christos (((UINT8) Next->Asl.Value.Integer) & 0x07); 279 1.1 christos 280 1.1 christos /* Get the SerializeRule and SyncLevel nodes, ignored here */ 281 1.1 christos 282 1.1 christos Next = Next->Asl.Next; 283 1.1 christos MethodInfo->ShouldBeSerialized = (UINT8) Next->Asl.Value.Integer; 284 1.1 christos 285 1.1 christos Next = Next->Asl.Next; 286 1.1 christos ArgNode = Next; 287 1.1 christos 288 1.1 christos /* Get the ReturnType node */ 289 1.1 christos 290 1.1 christos Next = Next->Asl.Next; 291 1.1 christos 292 1.1 christos NextType = Next->Asl.Child; 293 1.1 christos 294 1.1.1.14 christos MethodInfo->ValidReturnTypes = MtProcessTypeOp (NextType); 295 1.1.1.16 christos Op->Asl.AcpiBtype |= MethodInfo->ValidReturnTypes; 296 1.1 christos 297 1.1 christos /* Get the ParameterType node */ 298 1.1 christos 299 1.1 christos Next = Next->Asl.Next; 300 1.1 christos 301 1.1 christos NextType = Next->Asl.Child; 302 1.1.1.14 christos if (!NextType) 303 1.1 christos { 304 1.1.1.14 christos /* 305 1.1.1.14 christos * The optional parameter types list was omitted at the source 306 1.1.1.14 christos * level. Use the Argument count parameter instead. 307 1.1.1.14 christos */ 308 1.1.1.14 christos ActualArgs = MethodInfo->NumArguments; 309 1.1.1.14 christos } 310 1.1.1.14 christos else 311 1.1.1.14 christos { 312 1.1.1.14 christos ActualArgs = MtProcessParameterTypeList (NextType, 313 1.1.1.14 christos MethodInfo->ValidArgTypes); 314 1.1.1.15 christos MethodInfo->NumArguments = ActualArgs; 315 1.1.1.15 christos ArgNode->Asl.Value.Integer |= ActualArgs; 316 1.1 christos } 317 1.1 christos 318 1.1 christos if ((MethodInfo->NumArguments) && 319 1.1 christos (MethodInfo->NumArguments != ActualArgs)) 320 1.1 christos { 321 1.1.1.14 christos sprintf (AslGbl_MsgBuffer, 322 1.1.1.14 christos "Length = %u", ActualArgs); 323 1.1.1.14 christos AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_MISMATCH, 324 1.1.1.14 christos Op->Asl.Child->Asl.Next, AslGbl_MsgBuffer); 325 1.1 christos } 326 1.1 christos 327 1.1 christos /* Allow numarguments == 0 for Function() */ 328 1.1 christos 329 1.1 christos if ((!MethodInfo->NumArguments) && (ActualArgs)) 330 1.1 christos { 331 1.1 christos MethodInfo->NumArguments = ActualArgs; 332 1.1 christos ArgNode->Asl.Value.Integer |= ActualArgs; 333 1.1 christos } 334 1.1 christos 335 1.1 christos /* 336 1.1 christos * Actual arguments are initialized at method entry. 337 1.1 christos * All other ArgX "registers" can be used as locals, so we 338 1.1 christos * track their initialization. 339 1.1 christos */ 340 1.1 christos for (i = 0; i < MethodInfo->NumArguments; i++) 341 1.1 christos { 342 1.1 christos MethodInfo->ArgInitialized[i] = TRUE; 343 1.1 christos } 344 1.1 christos break; 345 1.1 christos 346 1.1 christos case PARSEOP_METHODCALL: 347 1.1 christos 348 1.1.1.9 christos /* Check for a recursive method call */ 349 1.1.1.9 christos 350 1.1 christos if (MethodInfo && 351 1.1 christos (Op->Asl.Node == MethodInfo->Op->Asl.Node)) 352 1.1 christos { 353 1.1.1.9 christos if (MethodInfo->CreatesNamedObjects) 354 1.1.1.9 christos { 355 1.1.1.9 christos /* 356 1.1.1.9 christos * This is an error, as it will fail at runtime on all ACPI 357 1.1.1.9 christos * implementations. Any named object declarations will be 358 1.1.1.9 christos * executed twice, causing failure the second time. Note, 359 1.1.1.9 christos * this is independent of whether the method is declared 360 1.1.1.9 christos * Serialized, because the same thread is attempting to 361 1.1.1.9 christos * reenter the method, and this will always succeed. 362 1.1.1.9 christos */ 363 1.1.1.9 christos AslDualParseOpError (ASL_ERROR, ASL_MSG_ILLEGAL_RECURSION, Op, 364 1.1.1.9 christos Op->Asl.Value.String, ASL_MSG_FOUND_HERE, MethodInfo->Op, 365 1.1.1.9 christos MethodInfo->Op->Asl.ExternalName); 366 1.1.1.9 christos } 367 1.1.1.9 christos else 368 1.1.1.9 christos { 369 1.1.1.9 christos /* Method does not create objects, issue a remark */ 370 1.1.1.9 christos 371 1.1.1.9 christos AslError (ASL_REMARK, ASL_MSG_RECURSION, Op, Op->Asl.ExternalName); 372 1.1.1.9 christos } 373 1.1 christos } 374 1.1 christos break; 375 1.1 christos 376 1.1 christos case PARSEOP_LOCAL0: 377 1.1 christos case PARSEOP_LOCAL1: 378 1.1 christos case PARSEOP_LOCAL2: 379 1.1 christos case PARSEOP_LOCAL3: 380 1.1 christos case PARSEOP_LOCAL4: 381 1.1 christos case PARSEOP_LOCAL5: 382 1.1 christos case PARSEOP_LOCAL6: 383 1.1 christos case PARSEOP_LOCAL7: 384 1.1 christos 385 1.1 christos if (!MethodInfo) 386 1.1 christos { 387 1.1 christos /* 388 1.1 christos * Local was used outside a control method, or there was an error 389 1.1 christos * in the method declaration. 390 1.1 christos */ 391 1.1.1.5 christos AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, 392 1.1.1.5 christos Op, Op->Asl.ExternalName); 393 1.1 christos return (AE_ERROR); 394 1.1 christos } 395 1.1 christos 396 1.1.1.4 christos RegisterNumber = (Op->Asl.AmlOpcode & 0x0007); 397 1.1 christos 398 1.1 christos /* 399 1.1 christos * If the local is being used as a target, mark the local 400 1.1 christos * initialized 401 1.1 christos */ 402 1.1.1.8 christos if (Op->Asl.CompileFlags & OP_IS_TARGET) 403 1.1 christos { 404 1.1 christos MethodInfo->LocalInitialized[RegisterNumber] = TRUE; 405 1.1 christos } 406 1.1 christos 407 1.1 christos /* 408 1.1 christos * Otherwise, this is a reference, check if the local 409 1.1 christos * has been previously initialized. 410 1.1 christos * 411 1.1 christos * The only operator that accepts an uninitialized value is ObjectType() 412 1.1 christos */ 413 1.1 christos else if ((!MethodInfo->LocalInitialized[RegisterNumber]) && 414 1.1 christos (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE)) 415 1.1 christos { 416 1.1 christos LocalName[strlen (LocalName) -1] = (char) (RegisterNumber + 0x30); 417 1.1 christos AslError (ASL_ERROR, ASL_MSG_LOCAL_INIT, Op, LocalName); 418 1.1 christos } 419 1.1 christos break; 420 1.1 christos 421 1.1 christos case PARSEOP_ARG0: 422 1.1 christos case PARSEOP_ARG1: 423 1.1 christos case PARSEOP_ARG2: 424 1.1 christos case PARSEOP_ARG3: 425 1.1 christos case PARSEOP_ARG4: 426 1.1 christos case PARSEOP_ARG5: 427 1.1 christos case PARSEOP_ARG6: 428 1.1 christos 429 1.1 christos if (!MethodInfo) 430 1.1 christos { 431 1.1 christos /* 432 1.1 christos * Arg was used outside a control method, or there was an error 433 1.1 christos * in the method declaration. 434 1.1 christos */ 435 1.1.1.5 christos AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, 436 1.1.1.5 christos Op, Op->Asl.ExternalName); 437 1.1 christos return (AE_ERROR); 438 1.1 christos } 439 1.1 christos 440 1.1 christos RegisterNumber = (Op->Asl.AmlOpcode & 0x000F) - 8; 441 1.1 christos ArgName[strlen (ArgName) -1] = (char) (RegisterNumber + 0x30); 442 1.1 christos 443 1.1 christos /* 444 1.1 christos * If the Arg is being used as a target, mark the local 445 1.1 christos * initialized 446 1.1 christos */ 447 1.1.1.8 christos if (Op->Asl.CompileFlags & OP_IS_TARGET) 448 1.1 christos { 449 1.1 christos MethodInfo->ArgInitialized[RegisterNumber] = TRUE; 450 1.1 christos } 451 1.1 christos 452 1.1 christos /* 453 1.1 christos * Otherwise, this is a reference, check if the Arg 454 1.1 christos * has been previously initialized. 455 1.1 christos * 456 1.1 christos * The only operator that accepts an uninitialized value is ObjectType() 457 1.1 christos */ 458 1.1 christos else if ((!MethodInfo->ArgInitialized[RegisterNumber]) && 459 1.1.1.5 christos (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE)) 460 1.1 christos { 461 1.1 christos AslError (ASL_ERROR, ASL_MSG_ARG_INIT, Op, ArgName); 462 1.1 christos } 463 1.1 christos 464 1.1 christos /* Flag this arg if it is not a "real" argument to the method */ 465 1.1 christos 466 1.1 christos if (RegisterNumber >= MethodInfo->NumArguments) 467 1.1 christos { 468 1.1 christos AslError (ASL_REMARK, ASL_MSG_NOT_PARAMETER, Op, ArgName); 469 1.1 christos } 470 1.1 christos break; 471 1.1 christos 472 1.1 christos case PARSEOP_RETURN: 473 1.1 christos 474 1.1 christos if (!MethodInfo) 475 1.1 christos { 476 1.1 christos /* 477 1.1 christos * Probably was an error in the method declaration, 478 1.1 christos * no additional error here 479 1.1 christos */ 480 1.1 christos ACPI_WARNING ((AE_INFO, "%p, No parent method", Op)); 481 1.1 christos return (AE_ERROR); 482 1.1 christos } 483 1.1 christos 484 1.1 christos /* 485 1.1 christos * A child indicates a possible return value. A simple Return or 486 1.1.1.8 christos * Return() is marked with OP_IS_NULL_RETURN by the parser so 487 1.1 christos * that it is not counted as a "real" return-with-value, although 488 1.1 christos * the AML code that is actually emitted is Return(0). The AML 489 1.1 christos * definition of Return has a required parameter, so we are 490 1.1 christos * forced to convert a null return to Return(0). 491 1.1 christos */ 492 1.1 christos if ((Op->Asl.Child) && 493 1.1 christos (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && 494 1.1.1.8 christos (!(Op->Asl.Child->Asl.CompileFlags & OP_IS_NULL_RETURN))) 495 1.1 christos { 496 1.1 christos MethodInfo->NumReturnWithValue++; 497 1.1 christos } 498 1.1 christos else 499 1.1 christos { 500 1.1 christos MethodInfo->NumReturnNoValue++; 501 1.1 christos } 502 1.1 christos break; 503 1.1 christos 504 1.1 christos case PARSEOP_BREAK: 505 1.1 christos case PARSEOP_CONTINUE: 506 1.1 christos 507 1.1 christos Next = Op->Asl.Parent; 508 1.1 christos while (Next) 509 1.1 christos { 510 1.1 christos if (Next->Asl.ParseOpcode == PARSEOP_WHILE) 511 1.1 christos { 512 1.1 christos break; 513 1.1 christos } 514 1.1 christos Next = Next->Asl.Parent; 515 1.1 christos } 516 1.1 christos 517 1.1 christos if (!Next) 518 1.1 christos { 519 1.1 christos AslError (ASL_ERROR, ASL_MSG_NO_WHILE, Op, NULL); 520 1.1 christos } 521 1.1 christos break; 522 1.1 christos 523 1.1 christos case PARSEOP_STALL: 524 1.1 christos 525 1.1 christos /* We can range check if the argument is an integer */ 526 1.1 christos 527 1.1 christos if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) && 528 1.1 christos (Op->Asl.Child->Asl.Value.Integer > ACPI_UINT8_MAX)) 529 1.1 christos { 530 1.1 christos AslError (ASL_ERROR, ASL_MSG_INVALID_TIME, Op, NULL); 531 1.1 christos } 532 1.1 christos break; 533 1.1 christos 534 1.1 christos case PARSEOP_DEVICE: 535 1.1.1.2 christos 536 1.1.1.13 christos /* Check usage of _HID and _ADR objects */ 537 1.1.1.13 christos 538 1.1.1.13 christos HidExists = ApFindNameInDeviceTree (METHOD_NAME__HID, Op); 539 1.1.1.13 christos AdrExists = ApFindNameInDeviceTree (METHOD_NAME__ADR, Op); 540 1.1.1.13 christos 541 1.1.1.13 christos if (!HidExists && !AdrExists) 542 1.1.1.2 christos { 543 1.1.1.17 christos AslError (ASL_ERROR, ASL_MSG_MISSING_DEPENDENCY, Op, 544 1.1.1.17 christos "Device object requires a _HID or _ADR"); 545 1.1.1.2 christos } 546 1.1.1.13 christos else if (HidExists && AdrExists) 547 1.1.1.13 christos { 548 1.1.1.13 christos /* 549 1.1.1.21 christos * "A device object must contain either an _HID object or 550 1.1.1.21 christos * an _ADR object, but must not contain both". 551 1.1.1.21 christos * (ACPI spec 6.3, Errata A Section 6.1, page 327) 552 1.1.1.13 christos */ 553 1.1.1.13 christos AslError (ASL_WARNING, ASL_MSG_MULTIPLE_TYPES, Op, 554 1.1.1.13 christos "Device object requires either a _HID or _ADR, but not both"); 555 1.1.1.13 christos } 556 1.1.1.17 christos 557 1.1.1.17 christos /* 558 1.1.1.17 christos * Check usage of _CRS, _DIS, _PRS, and _SRS objects (July 2021). 559 1.1.1.17 christos * 560 1.1.1.17 christos * Under the Device Object: 561 1.1.1.17 christos * 562 1.1.1.17 christos * 1) If _PRS present, must have _CRS and _SRS 563 1.1.1.17 christos * 2) If _SRS present, must have _PRS (_PRS requires _CRS and _SRS) 564 1.1.1.17 christos * 3) If _DIS present, must have _SRS (_SRS requires _PRS, _PRS requires _CRS and _SRS) 565 1.1.1.17 christos * 4) If _SRS present, probably should have a _DIS (Remark only) 566 1.1.1.17 christos */ 567 1.1.1.17 christos CrsExists = ApFindNameInDeviceTree (METHOD_NAME__CRS, Op); 568 1.1.1.17 christos DisExists = ApFindNameInDeviceTree (METHOD_NAME__DIS, Op); 569 1.1.1.17 christos PrsExists = ApFindNameInDeviceTree (METHOD_NAME__PRS, Op); 570 1.1.1.17 christos SrsExists = ApFindNameInDeviceTree (METHOD_NAME__SRS, Op); 571 1.1.1.17 christos 572 1.1.1.17 christos /* 1) If _PRS is present, must have a _CRS and _SRS */ 573 1.1.1.17 christos 574 1.1.1.17 christos if (PrsExists) 575 1.1.1.17 christos { 576 1.1.1.17 christos if (!CrsExists) 577 1.1.1.17 christos { 578 1.1.1.17 christos AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, 579 1.1.1.17 christos "Device has a _PRS, missing a _CRS, required"); 580 1.1.1.17 christos } 581 1.1.1.17 christos if (!SrsExists) 582 1.1.1.17 christos { 583 1.1.1.17 christos AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, 584 1.1.1.17 christos "Device has a _PRS, missing a _SRS, required"); 585 1.1.1.17 christos } 586 1.1.1.17 christos } 587 1.1.1.17 christos 588 1.1.1.17 christos /* 2) If _SRS is present, must have _PRS (_PRS requires _CRS and _SRS) */ 589 1.1.1.17 christos 590 1.1.1.17 christos if ((SrsExists) && (!PrsExists)) 591 1.1.1.17 christos { 592 1.1.1.17 christos AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, 593 1.1.1.17 christos "Device has a _SRS, missing a _PRS, required"); 594 1.1.1.17 christos } 595 1.1.1.17 christos 596 1.1.1.17 christos /* 3) If _DIS is present, must have a _SRS */ 597 1.1.1.17 christos 598 1.1.1.17 christos if ((DisExists) && (!SrsExists)) 599 1.1.1.17 christos { 600 1.1.1.17 christos AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, 601 1.1.1.17 christos "Device has a _DIS, missing a _SRS, required"); 602 1.1.1.17 christos } 603 1.1.1.17 christos 604 1.1.1.17 christos /* 605 1.1.1.17 christos * 4) If _SRS is present, should have a _DIS (_PRS requires _CRS 606 1.1.1.17 christos * and _SRS) Remark only. 607 1.1.1.17 christos */ 608 1.1.1.17 christos if ((SrsExists) && (!DisExists)) 609 1.1.1.17 christos { 610 1.1.1.17 christos AslError (ASL_REMARK, ASL_MSG_MISSING_DEPENDENCY, Op, 611 1.1.1.17 christos "Device has a _SRS, no corresponding _DIS"); 612 1.1.1.17 christos } 613 1.1.1.2 christos break; 614 1.1.1.2 christos 615 1.1 christos case PARSEOP_EVENT: 616 1.1 christos case PARSEOP_MUTEX: 617 1.1 christos case PARSEOP_OPERATIONREGION: 618 1.1 christos case PARSEOP_POWERRESOURCE: 619 1.1 christos case PARSEOP_PROCESSOR: 620 1.1 christos case PARSEOP_THERMALZONE: 621 1.1 christos 622 1.1 christos /* 623 1.1 christos * The first operand is a name to be created in the namespace. 624 1.1 christos * Check against the reserved list. 625 1.1 christos */ 626 1.1 christos i = ApCheckForPredefinedName (Op, Op->Asl.NameSeg); 627 1.1 christos if (i < ACPI_VALID_RESERVED_NAME_MAX) 628 1.1 christos { 629 1.1.1.5 christos AslError (ASL_ERROR, ASL_MSG_RESERVED_USE, 630 1.1.1.5 christos Op, Op->Asl.ExternalName); 631 1.1 christos } 632 1.1.1.14 christos 633 1.1.1.14 christos MtCheckStaticOperationRegionInMethod (Op); 634 1.1 christos break; 635 1.1 christos 636 1.1 christos case PARSEOP_NAME: 637 1.1 christos 638 1.1 christos /* Typecheck any predefined names statically defined with Name() */ 639 1.1 christos 640 1.1 christos ApCheckForPredefinedObject (Op, Op->Asl.NameSeg); 641 1.1 christos 642 1.1 christos /* Special typechecking for _HID */ 643 1.1 christos 644 1.1.1.13 christos if (ACPI_COMPARE_NAMESEG (METHOD_NAME__HID, Op->Asl.NameSeg)) 645 1.1 christos { 646 1.1 christos Next = Op->Asl.Child->Asl.Next; 647 1.1 christos AnCheckId (Next, ASL_TYPE_HID); 648 1.1 christos } 649 1.1 christos 650 1.1 christos /* Special typechecking for _CID */ 651 1.1 christos 652 1.1.1.13 christos else if (ACPI_COMPARE_NAMESEG (METHOD_NAME__CID, Op->Asl.NameSeg)) 653 1.1 christos { 654 1.1 christos Next = Op->Asl.Child->Asl.Next; 655 1.1 christos 656 1.1 christos if ((Next->Asl.ParseOpcode == PARSEOP_PACKAGE) || 657 1.1 christos (Next->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)) 658 1.1 christos { 659 1.1 christos Next = Next->Asl.Child; 660 1.1 christos while (Next) 661 1.1 christos { 662 1.1 christos AnCheckId (Next, ASL_TYPE_CID); 663 1.1 christos Next = Next->Asl.Next; 664 1.1 christos } 665 1.1 christos } 666 1.1 christos else 667 1.1 christos { 668 1.1 christos AnCheckId (Next, ASL_TYPE_CID); 669 1.1 christos } 670 1.1 christos } 671 1.1.1.2 christos 672 1.1 christos break; 673 1.1 christos 674 1.1 christos default: 675 1.1 christos 676 1.1 christos break; 677 1.1 christos } 678 1.1 christos 679 1.1 christos /* Check for named object creation within a non-serialized method */ 680 1.1 christos 681 1.1 christos MtCheckNamedObjectInMethod (Op, MethodInfo); 682 1.1 christos return (AE_OK); 683 1.1 christos } 684 1.1 christos 685 1.1 christos 686 1.1 christos /******************************************************************************* 687 1.1 christos * 688 1.1.1.14 christos * FUNCTION: MtProcessTypeOp 689 1.1.1.14 christos * 690 1.1.1.14 christos * PARAMETERS: Op - Op representing a btype 691 1.1.1.14 christos * 692 1.1.1.14 christos * RETURN: Btype represented by Op 693 1.1.1.14 christos * 694 1.1.1.14 christos * DESCRIPTION: Process a parse object that represents single parameter type or 695 1.1.1.14 christos * a return type in method, function, and external declarations. 696 1.1.1.14 christos * 697 1.1.1.14 christos ******************************************************************************/ 698 1.1.1.14 christos 699 1.1.1.14 christos UINT32 700 1.1.1.14 christos MtProcessTypeOp ( 701 1.1.1.14 christos ACPI_PARSE_OBJECT *TypeOp) 702 1.1.1.14 christos { 703 1.1.1.14 christos UINT32 Btype = ACPI_BTYPE_ANY; 704 1.1.1.14 christos 705 1.1.1.14 christos 706 1.1.1.14 christos while (TypeOp) 707 1.1.1.14 christos { 708 1.1.1.14 christos Btype |= AnMapObjTypeToBtype (TypeOp); 709 1.1.1.14 christos TypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; 710 1.1.1.14 christos TypeOp = TypeOp->Asl.Next; 711 1.1.1.14 christos } 712 1.1.1.14 christos 713 1.1.1.14 christos return (Btype); 714 1.1.1.14 christos } 715 1.1.1.14 christos 716 1.1.1.14 christos 717 1.1.1.14 christos /******************************************************************************* 718 1.1.1.14 christos * 719 1.1.1.14 christos * FUNCTION: MtProcessParameterTypeList 720 1.1.1.14 christos * 721 1.1.1.14 christos * PARAMETERS: Op - Op representing a btype 722 1.1.1.14 christos * 723 1.1.1.14 christos * RETURN: Btype represented by Op 724 1.1.1.14 christos * 725 1.1.1.14 christos * DESCRIPTION: Process a parse object that represents a parameter type list in 726 1.1.1.14 christos * method, function, and external declarations. 727 1.1.1.14 christos * 728 1.1.1.14 christos ******************************************************************************/ 729 1.1.1.14 christos 730 1.1.1.14 christos UINT8 731 1.1.1.14 christos MtProcessParameterTypeList ( 732 1.1.1.14 christos ACPI_PARSE_OBJECT *ParamTypeOp, 733 1.1.1.14 christos UINT32 *TypeList) 734 1.1.1.14 christos { 735 1.1.1.14 christos UINT8 ParameterCount = 0; 736 1.1.1.14 christos 737 1.1.1.14 christos 738 1.1.1.15 christos if (ParamTypeOp && ParamTypeOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) 739 1.1.1.15 christos { 740 1.1.1.15 christos /* Special case for a single parameter without braces */ 741 1.1.1.15 christos 742 1.1.1.15 christos TypeList[ParameterCount] = 743 1.1.1.15 christos MtProcessTypeOp (ParamTypeOp); 744 1.1.1.15 christos 745 1.1.1.15 christos return (1); 746 1.1.1.15 christos } 747 1.1.1.15 christos 748 1.1.1.14 christos while (ParamTypeOp) 749 1.1.1.14 christos { 750 1.1.1.14 christos TypeList[ParameterCount] = 751 1.1.1.14 christos MtProcessTypeOp (ParamTypeOp->Asl.Child); 752 1.1.1.14 christos 753 1.1.1.14 christos ParameterCount++; 754 1.1.1.14 christos ParamTypeOp = ParamTypeOp->Asl.Next; 755 1.1.1.14 christos } 756 1.1.1.14 christos 757 1.1.1.14 christos return (ParameterCount); 758 1.1.1.14 christos } 759 1.1.1.14 christos 760 1.1.1.14 christos 761 1.1.1.14 christos /******************************************************************************* 762 1.1.1.14 christos * 763 1.1 christos * FUNCTION: MtCheckNamedObjectInMethod 764 1.1 christos * 765 1.1 christos * PARAMETERS: Op - Current parser op 766 1.1 christos * MethodInfo - Info for method being parsed 767 1.1 christos * 768 1.1 christos * RETURN: None 769 1.1 christos * 770 1.1 christos * DESCRIPTION: Detect if a non-serialized method is creating a named object, 771 1.1 christos * which could possibly cause problems if two threads execute 772 1.1 christos * the method concurrently. Emit a remark in this case. 773 1.1 christos * 774 1.1 christos ******************************************************************************/ 775 1.1 christos 776 1.1.1.6 christos static void 777 1.1 christos MtCheckNamedObjectInMethod ( 778 1.1 christos ACPI_PARSE_OBJECT *Op, 779 1.1 christos ASL_METHOD_INFO *MethodInfo) 780 1.1 christos { 781 1.1 christos const ACPI_OPCODE_INFO *OpInfo; 782 1.1.1.14 christos char *ExternalPath; 783 1.1 christos 784 1.1 christos 785 1.1.1.5 christos /* We don't care about actual method declarations or scopes */ 786 1.1 christos 787 1.1.1.5 christos if ((Op->Asl.AmlOpcode == AML_METHOD_OP) || 788 1.1.1.5 christos (Op->Asl.AmlOpcode == AML_SCOPE_OP)) 789 1.1 christos { 790 1.1 christos return; 791 1.1 christos } 792 1.1 christos 793 1.1.1.9 christos /* Determine if we are creating a named object within a method */ 794 1.1.1.9 christos 795 1.1.1.9 christos if (!MethodInfo) 796 1.1.1.9 christos { 797 1.1.1.9 christos return; 798 1.1.1.9 christos } 799 1.1 christos 800 1.1 christos OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); 801 1.1.1.15 christos if ((OpInfo->Class == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_FIELD_OP)) 802 1.1 christos { 803 1.1 christos /* 804 1.1.1.9 christos * 1) Mark the method as a method that creates named objects. 805 1.1.1.9 christos * 806 1.1.1.14 christos * 2) Issue a remark indicating the inefficiency of creating named 807 1.1.1.14 christos * objects within a method (Except for compiler-emitted temporary 808 1.1.1.14 christos * variables). 809 1.1.1.14 christos * 810 1.1.1.14 christos * 3) If the method is non-serialized, emit a remark that the method 811 1.1.1.9 christos * should be serialized. 812 1.1 christos * 813 1.1 christos * Reason: If a thread blocks within the method for any reason, and 814 1.1.1.9 christos * another thread enters the method, the method will fail because 815 1.1.1.9 christos * an attempt will be made to create the same object twice. 816 1.1.1.15 christos * 817 1.1.1.15 christos * Note: The Field opcode is disallowed here because Field() does not 818 1.1.1.15 christos * create a new named object. 819 1.1 christos */ 820 1.1.1.14 christos ExternalPath = AcpiNsGetNormalizedPathname (MethodInfo->Op->Asl.Node, TRUE); 821 1.1.1.14 christos 822 1.1.1.14 christos /* No error for compiler temp variables (name starts with "_T_") */ 823 1.1.1.14 christos 824 1.1.1.14 christos if ((Op->Asl.NameSeg[0] != '_') && 825 1.1.1.14 christos (Op->Asl.NameSeg[1] != 'T') && 826 1.1.1.14 christos (Op->Asl.NameSeg[2] != '_')) 827 1.1.1.14 christos { 828 1.1.1.14 christos AslError (ASL_REMARK, ASL_MSG_NAMED_OBJECT_CREATION, Op, 829 1.1.1.14 christos ExternalPath); 830 1.1.1.14 christos } 831 1.1.1.14 christos 832 1.1.1.9 christos MethodInfo->CreatesNamedObjects = TRUE; 833 1.1.1.9 christos if (!MethodInfo->ShouldBeSerialized) 834 1.1 christos { 835 1.1 christos AslError (ASL_REMARK, ASL_MSG_SERIALIZED_REQUIRED, MethodInfo->Op, 836 1.1.1.14 christos ExternalPath); 837 1.1 christos 838 1.1 christos /* Emit message only ONCE per method */ 839 1.1 christos 840 1.1 christos MethodInfo->ShouldBeSerialized = TRUE; 841 1.1 christos } 842 1.1.1.14 christos 843 1.1.1.14 christos if (ExternalPath) 844 1.1.1.14 christos { 845 1.1.1.14 christos ACPI_FREE (ExternalPath); 846 1.1.1.14 christos } 847 1.1 christos } 848 1.1 christos } 849 1.1 christos 850 1.1 christos 851 1.1 christos /******************************************************************************* 852 1.1 christos * 853 1.1.1.14 christos * FUNCTION: MtCheckStaticOperationRegionInMethod 854 1.1.1.14 christos * 855 1.1.1.14 christos * PARAMETERS: Op - Current parser op 856 1.1.1.14 christos * 857 1.1.1.14 christos * RETURN: None 858 1.1.1.14 christos * 859 1.1.1.14 christos * DESCRIPTION: Warns if an Operation Region with static address or length 860 1.1.1.14 christos * is declared inside a control method 861 1.1.1.14 christos * 862 1.1.1.14 christos ******************************************************************************/ 863 1.1.1.14 christos 864 1.1.1.14 christos static void 865 1.1.1.14 christos MtCheckStaticOperationRegionInMethod( 866 1.1.1.14 christos ACPI_PARSE_OBJECT* Op) 867 1.1.1.14 christos { 868 1.1.1.14 christos ACPI_PARSE_OBJECT* AddressOp; 869 1.1.1.14 christos ACPI_PARSE_OBJECT* LengthOp; 870 1.1.1.14 christos 871 1.1.1.14 christos 872 1.1.1.14 christos if (Op->Asl.ParseOpcode != PARSEOP_OPERATIONREGION) 873 1.1.1.14 christos { 874 1.1.1.14 christos return; 875 1.1.1.14 christos } 876 1.1.1.14 christos 877 1.1.1.14 christos /* 878 1.1.1.14 christos * OperationRegion should have 4 arguments defined. At this point, we 879 1.1.1.14 christos * assume that the parse tree is well-formed. 880 1.1.1.14 christos */ 881 1.1.1.14 christos AddressOp = Op->Asl.Child->Asl.Next->Asl.Next; 882 1.1.1.14 christos LengthOp = Op->Asl.Child->Asl.Next->Asl.Next->Asl.Next; 883 1.1.1.14 christos 884 1.1.1.14 christos if (UtGetParentMethodOp (Op) && 885 1.1.1.14 christos AddressOp->Asl.ParseOpcode == PARSEOP_INTEGER && 886 1.1.1.14 christos LengthOp->Asl.ParseOpcode == PARSEOP_INTEGER) 887 1.1.1.14 christos { 888 1.1.1.14 christos /* 889 1.1.1.14 christos * At this point, a static operation region declared inside of a 890 1.1.1.14 christos * control method has been found. Throw a warning because this is 891 1.1.1.14 christos * highly inefficient. 892 1.1.1.14 christos */ 893 1.1.1.14 christos AslError(ASL_WARNING, ASL_MSG_STATIC_OPREGION_IN_METHOD, Op, NULL); 894 1.1.1.14 christos } 895 1.1.1.14 christos 896 1.1.1.14 christos return; 897 1.1.1.14 christos } 898 1.1.1.14 christos 899 1.1.1.14 christos 900 1.1.1.14 christos /******************************************************************************* 901 1.1.1.14 christos * 902 1.1 christos * FUNCTION: MtMethodAnalysisWalkEnd 903 1.1 christos * 904 1.1 christos * PARAMETERS: ASL_WALK_CALLBACK 905 1.1 christos * 906 1.1 christos * RETURN: Status 907 1.1 christos * 908 1.1 christos * DESCRIPTION: Ascending callback for analysis walk. Complete method 909 1.1 christos * return analysis. 910 1.1 christos * 911 1.1 christos ******************************************************************************/ 912 1.1 christos 913 1.1 christos ACPI_STATUS 914 1.1 christos MtMethodAnalysisWalkEnd ( 915 1.1 christos ACPI_PARSE_OBJECT *Op, 916 1.1 christos UINT32 Level, 917 1.1 christos void *Context) 918 1.1 christos { 919 1.1 christos ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context; 920 1.1 christos ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack; 921 1.1.1.14 christos char *ExternalPath; 922 1.1 christos 923 1.1 christos 924 1.1 christos switch (Op->Asl.ParseOpcode) 925 1.1 christos { 926 1.1 christos case PARSEOP_METHOD: 927 1.1 christos case PARSEOP_RETURN: 928 1.1 christos 929 1.1 christos if (!MethodInfo) 930 1.1 christos { 931 1.1 christos printf ("No method info for method! [%s]\n", Op->Asl.Namepath); 932 1.1 christos AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op, 933 1.1 christos "No method info for this method"); 934 1.1 christos 935 1.1 christos CmCleanupAndExit (); 936 1.1 christos return (AE_AML_INTERNAL); 937 1.1 christos } 938 1.1 christos break; 939 1.1 christos 940 1.1 christos default: 941 1.1 christos 942 1.1 christos break; 943 1.1 christos } 944 1.1 christos 945 1.1 christos switch (Op->Asl.ParseOpcode) 946 1.1 christos { 947 1.1 christos case PARSEOP_METHOD: 948 1.1 christos 949 1.1 christos WalkInfo->MethodStack = MethodInfo->Next; 950 1.1 christos 951 1.1 christos /* 952 1.1 christos * Check if there is no return statement at the end of the 953 1.1 christos * method AND we can actually get there -- i.e., the execution 954 1.1 christos * of the method can possibly terminate without a return statement. 955 1.1 christos */ 956 1.1 christos if ((!AnLastStatementIsReturn (Op)) && 957 1.1.1.8 christos (!(Op->Asl.CompileFlags & OP_HAS_NO_EXIT))) 958 1.1 christos { 959 1.1 christos /* 960 1.1 christos * No return statement, and execution can possibly exit 961 1.1 christos * via this path. This is equivalent to Return () 962 1.1 christos */ 963 1.1 christos MethodInfo->NumReturnNoValue++; 964 1.1 christos } 965 1.1 christos 966 1.1 christos /* 967 1.1 christos * Check for case where some return statements have a return value 968 1.1 christos * and some do not. Exit without a return statement is a return with 969 1.1 christos * no value 970 1.1 christos */ 971 1.1 christos if (MethodInfo->NumReturnNoValue && 972 1.1 christos MethodInfo->NumReturnWithValue) 973 1.1 christos { 974 1.1.1.14 christos ExternalPath = AcpiNsGetNormalizedPathname (Op->Asl.Node, TRUE); 975 1.1.1.14 christos 976 1.1 christos AslError (ASL_WARNING, ASL_MSG_RETURN_TYPES, Op, 977 1.1.1.14 christos ExternalPath); 978 1.1.1.14 christos 979 1.1.1.14 christos if (ExternalPath) 980 1.1.1.14 christos { 981 1.1.1.14 christos ACPI_FREE (ExternalPath); 982 1.1.1.14 christos } 983 1.1 christos } 984 1.1 christos 985 1.1 christos /* 986 1.1 christos * If there are any RETURN() statements with no value, or there is a 987 1.1 christos * control path that allows the method to exit without a return value, 988 1.1 christos * we mark the method as a method that does not return a value. This 989 1.1 christos * knowledge can be used to check method invocations that expect a 990 1.1 christos * returned value. 991 1.1 christos */ 992 1.1 christos if (MethodInfo->NumReturnNoValue) 993 1.1 christos { 994 1.1 christos if (MethodInfo->NumReturnWithValue) 995 1.1 christos { 996 1.1.1.8 christos Op->Asl.CompileFlags |= OP_METHOD_SOME_NO_RETVAL; 997 1.1 christos } 998 1.1 christos else 999 1.1 christos { 1000 1.1.1.8 christos Op->Asl.CompileFlags |= OP_METHOD_NO_RETVAL; 1001 1.1 christos } 1002 1.1 christos } 1003 1.1 christos 1004 1.1 christos /* 1005 1.1 christos * Check predefined method names for correct return behavior 1006 1.1 christos * and correct number of arguments. Also, some special checks 1007 1.1 christos * For GPE and _REG methods. 1008 1.1 christos */ 1009 1.1 christos if (ApCheckForPredefinedMethod (Op, MethodInfo)) 1010 1.1 christos { 1011 1.1 christos /* Special check for two names like _L01 and _E01 in same scope */ 1012 1.1 christos 1013 1.1 christos ApCheckForGpeNameConflict (Op); 1014 1.1 christos 1015 1.1 christos /* 1016 1.1 christos * Special check for _REG: Must have an operation region definition 1017 1.1 christos * within the same scope! 1018 1.1 christos */ 1019 1.1 christos ApCheckRegMethod (Op); 1020 1.1 christos } 1021 1.1 christos 1022 1.1 christos ACPI_FREE (MethodInfo); 1023 1.1 christos break; 1024 1.1 christos 1025 1.1 christos case PARSEOP_NAME: 1026 1.1 christos 1027 1.1 christos /* Special check for two names like _L01 and _E01 in same scope */ 1028 1.1 christos 1029 1.1 christos ApCheckForGpeNameConflict (Op); 1030 1.1 christos break; 1031 1.1 christos 1032 1.1 christos case PARSEOP_RETURN: 1033 1.1 christos 1034 1.1 christos /* 1035 1.1 christos * If the parent is a predefined method name, attempt to typecheck 1036 1.1 christos * the return value. Only static types can be validated. 1037 1.1 christos */ 1038 1.1 christos ApCheckPredefinedReturnValue (Op, MethodInfo); 1039 1.1 christos 1040 1.1 christos /* 1041 1.1 christos * The parent block does not "exit" and continue execution -- the 1042 1.1 christos * method is terminated here with the Return() statement. 1043 1.1 christos */ 1044 1.1.1.8 christos Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT; 1045 1.1 christos 1046 1.1 christos /* Used in the "typing" pass later */ 1047 1.1 christos 1048 1.1 christos Op->Asl.ParentMethod = MethodInfo->Op; 1049 1.1 christos 1050 1.1 christos /* 1051 1.1 christos * If there is a peer node after the return statement, then this 1052 1.1 christos * node is unreachable code -- i.e., it won't be executed because of 1053 1.1 christos * the preceding Return() statement. 1054 1.1 christos */ 1055 1.1 christos if (Op->Asl.Next) 1056 1.1 christos { 1057 1.1.1.5 christos AslError (ASL_WARNING, ASL_MSG_UNREACHABLE_CODE, 1058 1.1.1.5 christos Op->Asl.Next, NULL); 1059 1.1 christos } 1060 1.1 christos break; 1061 1.1 christos 1062 1.1 christos case PARSEOP_IF: 1063 1.1 christos 1064 1.1.1.8 christos if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) && 1065 1.1 christos (Op->Asl.Next) && 1066 1.1 christos (Op->Asl.Next->Asl.ParseOpcode == PARSEOP_ELSE)) 1067 1.1 christos { 1068 1.1 christos /* 1069 1.1 christos * This IF has a corresponding ELSE. The IF block has no exit, 1070 1.1 christos * (it contains an unconditional Return) 1071 1.1 christos * mark the ELSE block to remember this fact. 1072 1.1 christos */ 1073 1.1.1.8 christos Op->Asl.Next->Asl.CompileFlags |= OP_IF_HAS_NO_EXIT; 1074 1.1 christos } 1075 1.1 christos break; 1076 1.1 christos 1077 1.1 christos case PARSEOP_ELSE: 1078 1.1 christos 1079 1.1.1.8 christos if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) && 1080 1.1.1.8 christos (Op->Asl.CompileFlags & OP_IF_HAS_NO_EXIT)) 1081 1.1 christos { 1082 1.1 christos /* 1083 1.1 christos * This ELSE block has no exit and the corresponding IF block 1084 1.1 christos * has no exit either. Therefore, the parent node has no exit. 1085 1.1 christos */ 1086 1.1.1.8 christos Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT; 1087 1.1 christos } 1088 1.1 christos break; 1089 1.1 christos 1090 1.1 christos 1091 1.1 christos default: 1092 1.1 christos 1093 1.1.1.8 christos if ((Op->Asl.CompileFlags & OP_HAS_NO_EXIT) && 1094 1.1 christos (Op->Asl.Parent)) 1095 1.1 christos { 1096 1.1 christos /* If this node has no exit, then the parent has no exit either */ 1097 1.1 christos 1098 1.1.1.8 christos Op->Asl.Parent->Asl.CompileFlags |= OP_HAS_NO_EXIT; 1099 1.1 christos } 1100 1.1 christos break; 1101 1.1 christos } 1102 1.1 christos 1103 1.1 christos return (AE_OK); 1104 1.1 christos } 1105