1 1.1 jruoho /****************************************************************************** 2 1.1 jruoho * 3 1.2 christos * Module Name: asllookup- Namespace lookup functions 4 1.1 jruoho * 5 1.1 jruoho *****************************************************************************/ 6 1.1 jruoho 7 1.17 christos /****************************************************************************** 8 1.17 christos * 9 1.17 christos * 1. Copyright Notice 10 1.17 christos * 11 1.18 christos * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp. 12 1.1 jruoho * All rights reserved. 13 1.1 jruoho * 14 1.17 christos * 2. License 15 1.17 christos * 16 1.17 christos * 2.1. This is your license from Intel Corp. under its intellectual property 17 1.17 christos * rights. You may have additional license terms from the party that provided 18 1.17 christos * you this software, covering your right to use that party's intellectual 19 1.17 christos * property rights. 20 1.17 christos * 21 1.17 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 1.17 christos * copy of the source code appearing in this file ("Covered Code") an 23 1.17 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 1.17 christos * base code distributed originally by Intel ("Original Intel Code") to copy, 25 1.17 christos * make derivatives, distribute, use and display any portion of the Covered 26 1.17 christos * Code in any form, with the right to sublicense such rights; and 27 1.17 christos * 28 1.17 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 1.17 christos * license (with the right to sublicense), under only those claims of Intel 30 1.17 christos * patents that are infringed by the Original Intel Code, to make, use, sell, 31 1.17 christos * offer to sell, and import the Covered Code and derivative works thereof 32 1.17 christos * solely to the minimum extent necessary to exercise the above copyright 33 1.17 christos * license, and in no event shall the patent license extend to any additions 34 1.17 christos * to or modifications of the Original Intel Code. No other license or right 35 1.17 christos * is granted directly or by implication, estoppel or otherwise; 36 1.17 christos * 37 1.17 christos * The above copyright and patent license is granted only if the following 38 1.17 christos * conditions are met: 39 1.17 christos * 40 1.17 christos * 3. Conditions 41 1.17 christos * 42 1.17 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 1.17 christos * Redistribution of source code of any substantial portion of the Covered 44 1.17 christos * Code or modification with rights to further distribute source must include 45 1.17 christos * the above Copyright Notice, the above License, this list of Conditions, 46 1.17 christos * and the following Disclaimer and Export Compliance provision. In addition, 47 1.17 christos * Licensee must cause all Covered Code to which Licensee contributes to 48 1.17 christos * contain a file documenting the changes Licensee made to create that Covered 49 1.17 christos * Code and the date of any change. Licensee must include in that file the 50 1.17 christos * documentation of any changes made by any predecessor Licensee. Licensee 51 1.17 christos * must include a prominent statement that the modification is derived, 52 1.17 christos * directly or indirectly, from Original Intel Code. 53 1.17 christos * 54 1.17 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 1.17 christos * Redistribution of source code of any substantial portion of the Covered 56 1.17 christos * Code or modification without rights to further distribute source must 57 1.17 christos * include the following Disclaimer and Export Compliance provision in the 58 1.17 christos * documentation and/or other materials provided with distribution. In 59 1.17 christos * addition, Licensee may not authorize further sublicense of source of any 60 1.17 christos * portion of the Covered Code, and must include terms to the effect that the 61 1.17 christos * license from Licensee to its licensee is limited to the intellectual 62 1.17 christos * property embodied in the software Licensee provides to its licensee, and 63 1.17 christos * not to intellectual property embodied in modifications its licensee may 64 1.17 christos * make. 65 1.17 christos * 66 1.17 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 1.17 christos * substantial portion of the Covered Code or modification must reproduce the 68 1.17 christos * above Copyright Notice, and the following Disclaimer and Export Compliance 69 1.17 christos * provision in the documentation and/or other materials provided with the 70 1.17 christos * distribution. 71 1.17 christos * 72 1.17 christos * 3.4. Intel retains all right, title, and interest in and to the Original 73 1.17 christos * Intel Code. 74 1.17 christos * 75 1.17 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 1.17 christos * Intel shall be used in advertising or otherwise to promote the sale, use or 77 1.17 christos * other dealings in products derived from or relating to the Covered Code 78 1.17 christos * without prior written authorization from Intel. 79 1.17 christos * 80 1.17 christos * 4. Disclaimer and Export Compliance 81 1.17 christos * 82 1.17 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 1.17 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 1.17 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 1.17 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 1.17 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 1.17 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 1.17 christos * PARTICULAR PURPOSE. 89 1.17 christos * 90 1.17 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 1.17 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 1.17 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 1.17 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 1.17 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 1.17 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 1.17 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 1.17 christos * LIMITED REMEDY. 98 1.17 christos * 99 1.17 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 1.17 christos * software or system incorporating such software without first obtaining any 101 1.17 christos * required license or other approval from the U. S. Department of Commerce or 102 1.17 christos * any other agency or department of the United States Government. In the 103 1.17 christos * event Licensee exports any such software from the United States or 104 1.17 christos * re-exports any such software from a foreign destination, Licensee shall 105 1.17 christos * ensure that the distribution and export/re-export of the software is in 106 1.17 christos * compliance with all laws, regulations, orders, or other restrictions of the 107 1.17 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 1.17 christos * any of its subsidiaries will export/re-export any technical data, process, 109 1.17 christos * software, or service, directly or indirectly, to any country for which the 110 1.17 christos * United States government or any agency thereof requires an export license, 111 1.17 christos * other governmental approval, or letter of assurance, without first obtaining 112 1.17 christos * such license, approval or letter. 113 1.17 christos * 114 1.17 christos ***************************************************************************** 115 1.17 christos * 116 1.17 christos * Alternatively, you may choose to be licensed under the terms of the 117 1.17 christos * following license: 118 1.17 christos * 119 1.2 christos * Redistribution and use in source and binary forms, with or without 120 1.2 christos * modification, are permitted provided that the following conditions 121 1.2 christos * are met: 122 1.2 christos * 1. Redistributions of source code must retain the above copyright 123 1.2 christos * notice, this list of conditions, and the following disclaimer, 124 1.2 christos * without modification. 125 1.2 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 1.2 christos * substantially similar to the "NO WARRANTY" disclaimer below 127 1.2 christos * ("Disclaimer") and any redistribution must be conditioned upon 128 1.2 christos * including a substantially similar Disclaimer requirement for further 129 1.2 christos * binary redistribution. 130 1.2 christos * 3. Neither the names of the above-listed copyright holders nor the names 131 1.2 christos * of any contributors may be used to endorse or promote products derived 132 1.2 christos * from this software without specific prior written permission. 133 1.2 christos * 134 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 1.2 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 1.14 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 1.2 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 1.17 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 1.17 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 1.17 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 1.17 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 1.17 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 1.17 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 1.17 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 1.17 christos * 146 1.17 christos * Alternatively, you may choose to be licensed under the terms of the 147 1.17 christos * GNU General Public License ("GPL") version 2 as published by the Free 148 1.17 christos * Software Foundation. 149 1.17 christos * 150 1.17 christos *****************************************************************************/ 151 1.1 jruoho 152 1.1 jruoho #include "aslcompiler.h" 153 1.1 jruoho #include "aslcompiler.y.h" 154 1.1 jruoho #include "acparser.h" 155 1.1 jruoho #include "amlcode.h" 156 1.1 jruoho #include "acnamesp.h" 157 1.1 jruoho #include "acdispat.h" 158 1.1 jruoho 159 1.1 jruoho 160 1.1 jruoho #define _COMPONENT ACPI_COMPILER 161 1.1 jruoho ACPI_MODULE_NAME ("asllookup") 162 1.1 jruoho 163 1.1 jruoho /* Local prototypes */ 164 1.1 jruoho 165 1.1 jruoho static ACPI_STATUS 166 1.1 jruoho LkIsObjectUsed ( 167 1.1 jruoho ACPI_HANDLE ObjHandle, 168 1.1 jruoho UINT32 Level, 169 1.1 jruoho void *Context, 170 1.1 jruoho void **ReturnValue); 171 1.1 jruoho 172 1.2 christos static ACPI_PARSE_OBJECT * 173 1.1 jruoho LkGetNameOp ( 174 1.1 jruoho ACPI_PARSE_OBJECT *Op); 175 1.1 jruoho 176 1.1 jruoho 177 1.1 jruoho /******************************************************************************* 178 1.1 jruoho * 179 1.2 christos * FUNCTION: LkFindUnreferencedObjects 180 1.1 jruoho * 181 1.2 christos * PARAMETERS: None 182 1.1 jruoho * 183 1.1 jruoho * RETURN: None 184 1.1 jruoho * 185 1.2 christos * DESCRIPTION: Namespace walk to find objects that are not referenced in any 186 1.2 christos * way. Must be called after the namespace has been cross 187 1.2 christos * referenced. 188 1.1 jruoho * 189 1.1 jruoho ******************************************************************************/ 190 1.1 jruoho 191 1.1 jruoho void 192 1.2 christos LkFindUnreferencedObjects ( 193 1.2 christos void) 194 1.1 jruoho { 195 1.1 jruoho 196 1.2 christos /* Walk entire namespace from the supplied root */ 197 1.2 christos 198 1.2 christos (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 199 1.2 christos ACPI_UINT32_MAX, FALSE, LkIsObjectUsed, NULL, 200 1.2 christos NULL, NULL); 201 1.1 jruoho } 202 1.1 jruoho 203 1.1 jruoho 204 1.1 jruoho /******************************************************************************* 205 1.1 jruoho * 206 1.2 christos * FUNCTION: LkIsObjectUsed 207 1.1 jruoho * 208 1.1 jruoho * PARAMETERS: ACPI_WALK_CALLBACK 209 1.1 jruoho * 210 1.1 jruoho * RETURN: Status 211 1.1 jruoho * 212 1.2 christos * DESCRIPTION: Check for an unreferenced namespace object and emit a warning. 213 1.2 christos * We have to be careful, because some types and names are 214 1.2 christos * typically or always unreferenced, we don't want to issue 215 1.2 christos * excessive warnings. Note: Names that are declared within a 216 1.2 christos * control method are temporary, so we always issue a remark 217 1.2 christos * if they are not referenced. 218 1.1 jruoho * 219 1.1 jruoho ******************************************************************************/ 220 1.1 jruoho 221 1.1 jruoho static ACPI_STATUS 222 1.2 christos LkIsObjectUsed ( 223 1.1 jruoho ACPI_HANDLE ObjHandle, 224 1.1 jruoho UINT32 Level, 225 1.1 jruoho void *Context, 226 1.1 jruoho void **ReturnValue) 227 1.1 jruoho { 228 1.2 christos ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle); 229 1.2 christos ACPI_NAMESPACE_NODE *Next; 230 1.5 christos ASL_METHOD_LOCAL *MethodLocals; 231 1.5 christos ASL_METHOD_LOCAL *MethodArgs; 232 1.5 christos UINT32 i; 233 1.1 jruoho 234 1.1 jruoho 235 1.5 christos if (Node->Type == ACPI_TYPE_METHOD) 236 1.5 christos { 237 1.5 christos if (!Node->Op || !Node->MethodLocals) 238 1.5 christos { 239 1.5 christos return (AE_OK); 240 1.5 christos } 241 1.5 christos 242 1.5 christos MethodLocals = (ASL_METHOD_LOCAL *) Node->MethodLocals; 243 1.5 christos MethodArgs = (ASL_METHOD_LOCAL *) Node->MethodArgs; 244 1.5 christos 245 1.5 christos /* 246 1.5 christos * Analysis of LocalX variables 247 1.5 christos */ 248 1.5 christos for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) 249 1.5 christos { 250 1.5 christos /* Warn for Locals that are set but never referenced */ 251 1.5 christos 252 1.5 christos if ((MethodLocals[i].Flags & ASL_LOCAL_INITIALIZED) && 253 1.5 christos (!(MethodLocals[i].Flags & ASL_LOCAL_REFERENCED))) 254 1.5 christos { 255 1.11 christos sprintf (AslGbl_MsgBuffer, "Local%u", i); 256 1.5 christos AslError (ASL_WARNING, ASL_MSG_LOCAL_NOT_USED, 257 1.11 christos MethodLocals[i].Op, AslGbl_MsgBuffer); 258 1.5 christos } 259 1.5 christos } 260 1.5 christos 261 1.5 christos /* 262 1.5 christos * Analysis of ArgX variables (standard method arguments, 263 1.5 christos * and remaining unused ArgX can also be used as locals) 264 1.5 christos */ 265 1.5 christos for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) 266 1.5 christos { 267 1.5 christos if (MethodArgs[i].Flags & ASL_ARG_IS_LOCAL) 268 1.5 christos { 269 1.5 christos /* Warn if ArgX is being used as a local, but not referenced */ 270 1.5 christos 271 1.5 christos if ((MethodArgs[i].Flags & ASL_ARG_INITIALIZED) && 272 1.5 christos (!(MethodArgs[i].Flags & ASL_ARG_REFERENCED))) 273 1.5 christos { 274 1.11 christos sprintf (AslGbl_MsgBuffer, "Arg%u", i); 275 1.5 christos AslError (ASL_WARNING, ASL_MSG_ARG_AS_LOCAL_NOT_USED, 276 1.11 christos MethodArgs[i].Op, AslGbl_MsgBuffer); 277 1.5 christos } 278 1.5 christos } 279 1.5 christos else 280 1.5 christos { 281 1.5 christos /* 282 1.5 christos * Remark if a normal method ArgX is not referenced. 283 1.5 christos * We ignore the predefined methods since often, not 284 1.5 christos * all arguments are needed or used. 285 1.5 christos */ 286 1.5 christos if ((Node->Name.Ascii[0] != '_') && 287 1.5 christos (!(MethodArgs[i].Flags & ASL_ARG_REFERENCED))) 288 1.5 christos { 289 1.11 christos sprintf (AslGbl_MsgBuffer, "Arg%u", i); 290 1.5 christos AslError (ASL_REMARK, ASL_MSG_ARG_NOT_USED, 291 1.11 christos MethodArgs[i].Op, AslGbl_MsgBuffer); 292 1.5 christos } 293 1.5 christos } 294 1.5 christos } 295 1.5 christos } 296 1.5 christos 297 1.2 christos /* Referenced flag is set during the namespace xref */ 298 1.2 christos 299 1.2 christos if (Node->Flags & ANOBJ_IS_REFERENCED) 300 1.1 jruoho { 301 1.2 christos return (AE_OK); 302 1.1 jruoho } 303 1.1 jruoho 304 1.2 christos if (!Node->Op) 305 1.1 jruoho { 306 1.1 jruoho return (AE_OK); 307 1.1 jruoho } 308 1.1 jruoho 309 1.2 christos /* These types are typically never directly referenced, ignore them */ 310 1.1 jruoho 311 1.2 christos switch (Node->Type) 312 1.2 christos { 313 1.2 christos case ACPI_TYPE_DEVICE: 314 1.2 christos case ACPI_TYPE_PROCESSOR: 315 1.2 christos case ACPI_TYPE_POWER: 316 1.2 christos case ACPI_TYPE_THERMAL: 317 1.2 christos case ACPI_TYPE_LOCAL_RESOURCE: 318 1.7 christos case ACPI_TYPE_LOCAL_RESOURCE_FIELD: /* Names assigned to descriptor elements */ 319 1.1 jruoho 320 1.2 christos return (AE_OK); 321 1.1 jruoho 322 1.2 christos default: 323 1.1 jruoho 324 1.2 christos break; 325 1.2 christos } 326 1.1 jruoho 327 1.2 christos /* Determine if the name is within a control method */ 328 1.1 jruoho 329 1.2 christos Next = Node->Parent; 330 1.2 christos while (Next) 331 1.1 jruoho { 332 1.2 christos if (Next->Type == ACPI_TYPE_METHOD) 333 1.2 christos { 334 1.2 christos /* 335 1.2 christos * Name is within a method, therefore it is temporary. 336 1.2 christos * Issue a remark even if it is a reserved name (starts 337 1.2 christos * with an underscore). 338 1.2 christos */ 339 1.11 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Name [%4.4s] is within a method [%4.4s]", 340 1.7 christos Node->Name.Ascii, Next->Name.Ascii); 341 1.2 christos AslError (ASL_REMARK, ASL_MSG_NOT_REFERENCED, 342 1.11 christos LkGetNameOp (Node->Op), AslGbl_MsgBuffer); 343 1.2 christos return (AE_OK); 344 1.2 christos } 345 1.1 jruoho 346 1.2 christos Next = Next->Parent; 347 1.1 jruoho } 348 1.1 jruoho 349 1.2 christos /* The name is not within a control method */ 350 1.1 jruoho 351 1.2 christos /* 352 1.2 christos * Ignore names that start with an underscore. These are the reserved 353 1.2 christos * ACPI names and are typically not referenced since they are meant 354 1.2 christos * to be called by the host OS. 355 1.2 christos */ 356 1.2 christos if (Node->Name.Ascii[0] == '_') 357 1.1 jruoho { 358 1.2 christos return (AE_OK); 359 1.1 jruoho } 360 1.1 jruoho 361 1.2 christos /* 362 1.2 christos * What remains is an unresolved user name that is not within a method. 363 1.2 christos * However, the object could be referenced via another table, so issue 364 1.2 christos * the warning at level 2. 365 1.2 christos */ 366 1.2 christos AslError (ASL_WARNING2, ASL_MSG_NOT_REFERENCED, 367 1.2 christos LkGetNameOp (Node->Op), NULL); 368 1.2 christos return (AE_OK); 369 1.1 jruoho } 370 1.1 jruoho 371 1.1 jruoho 372 1.1 jruoho /******************************************************************************* 373 1.1 jruoho * 374 1.1 jruoho * FUNCTION: LkGetNameOp 375 1.1 jruoho * 376 1.1 jruoho * PARAMETERS: Op - Current Op 377 1.1 jruoho * 378 1.1 jruoho * RETURN: NameOp associated with the input op 379 1.1 jruoho * 380 1.1 jruoho * DESCRIPTION: Find the name declaration op associated with the operator 381 1.1 jruoho * 382 1.1 jruoho ******************************************************************************/ 383 1.1 jruoho 384 1.2 christos static ACPI_PARSE_OBJECT * 385 1.1 jruoho LkGetNameOp ( 386 1.1 jruoho ACPI_PARSE_OBJECT *Op) 387 1.1 jruoho { 388 1.1 jruoho const ACPI_OPCODE_INFO *OpInfo; 389 1.1 jruoho ACPI_PARSE_OBJECT *NameOp = Op; 390 1.1 jruoho 391 1.1 jruoho 392 1.1 jruoho OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); 393 1.1 jruoho 394 1.1 jruoho 395 1.1 jruoho /* Get the NamePath from the appropriate place */ 396 1.1 jruoho 397 1.1 jruoho if (OpInfo->Flags & AML_NAMED) 398 1.1 jruoho { 399 1.1 jruoho /* For nearly all NAMED operators, the name reference is the first child */ 400 1.1 jruoho 401 1.1 jruoho NameOp = Op->Asl.Child; 402 1.1 jruoho if (Op->Asl.AmlOpcode == AML_ALIAS_OP) 403 1.1 jruoho { 404 1.1 jruoho /* 405 1.1 jruoho * ALIAS is the only oddball opcode, the name declaration 406 1.1 jruoho * (alias name) is the second operand 407 1.1 jruoho */ 408 1.1 jruoho NameOp = Op->Asl.Child->Asl.Next; 409 1.1 jruoho } 410 1.1 jruoho } 411 1.1 jruoho else if (OpInfo->Flags & AML_CREATE) 412 1.1 jruoho { 413 1.1 jruoho /* Name must appear as the last parameter */ 414 1.1 jruoho 415 1.1 jruoho NameOp = Op->Asl.Child; 416 1.9 christos while (!(NameOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION)) 417 1.1 jruoho { 418 1.1 jruoho NameOp = NameOp->Asl.Next; 419 1.1 jruoho } 420 1.1 jruoho } 421 1.1 jruoho 422 1.1 jruoho return (NameOp); 423 1.1 jruoho } 424