9822 want iasl
[unleashed.git] / usr / src / cmd / acpi / iasl / asllookup.c
blobfed35fd7870a4b520f69738a147f8041a4ba0f51
1 /******************************************************************************
3 * Module Name: asllookup- Namespace lookup functions
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include "aslcompiler.h"
45 #include "aslcompiler.y.h"
46 #include "acparser.h"
47 #include "amlcode.h"
48 #include "acnamesp.h"
49 #include "acdispat.h"
52 #define _COMPONENT ACPI_COMPILER
53 ACPI_MODULE_NAME ("asllookup")
55 /* Local prototypes */
57 static ACPI_STATUS
58 LkIsObjectUsed (
59 ACPI_HANDLE ObjHandle,
60 UINT32 Level,
61 void *Context,
62 void **ReturnValue);
64 static ACPI_PARSE_OBJECT *
65 LkGetNameOp (
66 ACPI_PARSE_OBJECT *Op);
69 /*******************************************************************************
71 * FUNCTION: LkFindUnreferencedObjects
73 * PARAMETERS: None
75 * RETURN: None
77 * DESCRIPTION: Namespace walk to find objects that are not referenced in any
78 * way. Must be called after the namespace has been cross
79 * referenced.
81 ******************************************************************************/
83 void
84 LkFindUnreferencedObjects (
85 void)
88 /* Walk entire namespace from the supplied root */
90 (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
91 ACPI_UINT32_MAX, FALSE, LkIsObjectUsed, NULL,
92 NULL, NULL);
96 /*******************************************************************************
98 * FUNCTION: LkIsObjectUsed
100 * PARAMETERS: ACPI_WALK_CALLBACK
102 * RETURN: Status
104 * DESCRIPTION: Check for an unreferenced namespace object and emit a warning.
105 * We have to be careful, because some types and names are
106 * typically or always unreferenced, we don't want to issue
107 * excessive warnings. Note: Names that are declared within a
108 * control method are temporary, so we always issue a remark
109 * if they are not referenced.
111 ******************************************************************************/
113 static ACPI_STATUS
114 LkIsObjectUsed (
115 ACPI_HANDLE ObjHandle,
116 UINT32 Level,
117 void *Context,
118 void **ReturnValue)
120 ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
121 ACPI_NAMESPACE_NODE *Next;
122 ASL_METHOD_LOCAL *MethodLocals;
123 ASL_METHOD_LOCAL *MethodArgs;
124 UINT32 i;
127 if (Node->Type == ACPI_TYPE_METHOD)
129 if (!Node->Op || !Node->MethodLocals)
131 return (AE_OK);
134 MethodLocals = (ASL_METHOD_LOCAL *) Node->MethodLocals;
135 MethodArgs = (ASL_METHOD_LOCAL *) Node->MethodArgs;
138 * Analysis of LocalX variables
140 for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
142 /* Warn for Locals that are set but never referenced */
144 if ((MethodLocals[i].Flags & ASL_LOCAL_INITIALIZED) &&
145 (!(MethodLocals[i].Flags & ASL_LOCAL_REFERENCED)))
147 sprintf (MsgBuffer, "Local%u", i);
148 AslError (ASL_WARNING, ASL_MSG_LOCAL_NOT_USED,
149 MethodLocals[i].Op, MsgBuffer);
154 * Analysis of ArgX variables (standard method arguments,
155 * and remaining unused ArgX can also be used as locals)
157 for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
159 if (MethodArgs[i].Flags & ASL_ARG_IS_LOCAL)
161 /* Warn if ArgX is being used as a local, but not referenced */
163 if ((MethodArgs[i].Flags & ASL_ARG_INITIALIZED) &&
164 (!(MethodArgs[i].Flags & ASL_ARG_REFERENCED)))
166 sprintf (MsgBuffer, "Arg%u", i);
167 AslError (ASL_WARNING, ASL_MSG_ARG_AS_LOCAL_NOT_USED,
168 MethodArgs[i].Op, MsgBuffer);
171 else
174 * Remark if a normal method ArgX is not referenced.
175 * We ignore the predefined methods since often, not
176 * all arguments are needed or used.
178 if ((Node->Name.Ascii[0] != '_') &&
179 (!(MethodArgs[i].Flags & ASL_ARG_REFERENCED)))
181 sprintf (MsgBuffer, "Arg%u", i);
182 AslError (ASL_REMARK, ASL_MSG_ARG_NOT_USED,
183 MethodArgs[i].Op, MsgBuffer);
189 /* Referenced flag is set during the namespace xref */
191 if (Node->Flags & ANOBJ_IS_REFERENCED)
193 return (AE_OK);
196 if (!Node->Op)
198 return (AE_OK);
201 /* These types are typically never directly referenced, ignore them */
203 switch (Node->Type)
205 case ACPI_TYPE_DEVICE:
206 case ACPI_TYPE_PROCESSOR:
207 case ACPI_TYPE_POWER:
208 case ACPI_TYPE_THERMAL:
209 case ACPI_TYPE_LOCAL_RESOURCE:
210 case ACPI_TYPE_LOCAL_RESOURCE_FIELD: /* Names assigned to descriptor elements */
212 return (AE_OK);
214 default:
216 break;
219 /* Determine if the name is within a control method */
221 Next = Node->Parent;
222 while (Next)
224 if (Next->Type == ACPI_TYPE_METHOD)
227 * Name is within a method, therefore it is temporary.
228 * Issue a remark even if it is a reserved name (starts
229 * with an underscore).
231 sprintf (MsgBuffer, "Name [%4.4s] is within a method [%4.4s]",
232 Node->Name.Ascii, Next->Name.Ascii);
233 AslError (ASL_REMARK, ASL_MSG_NOT_REFERENCED,
234 LkGetNameOp (Node->Op), MsgBuffer);
235 return (AE_OK);
238 Next = Next->Parent;
241 /* The name is not within a control method */
244 * Ignore names that start with an underscore. These are the reserved
245 * ACPI names and are typically not referenced since they are meant
246 * to be called by the host OS.
248 if (Node->Name.Ascii[0] == '_')
250 return (AE_OK);
254 * What remains is an unresolved user name that is not within a method.
255 * However, the object could be referenced via another table, so issue
256 * the warning at level 2.
258 AslError (ASL_WARNING2, ASL_MSG_NOT_REFERENCED,
259 LkGetNameOp (Node->Op), NULL);
260 return (AE_OK);
264 /*******************************************************************************
266 * FUNCTION: LkGetNameOp
268 * PARAMETERS: Op - Current Op
270 * RETURN: NameOp associated with the input op
272 * DESCRIPTION: Find the name declaration op associated with the operator
274 ******************************************************************************/
276 static ACPI_PARSE_OBJECT *
277 LkGetNameOp (
278 ACPI_PARSE_OBJECT *Op)
280 const ACPI_OPCODE_INFO *OpInfo;
281 ACPI_PARSE_OBJECT *NameOp = Op;
284 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
287 /* Get the NamePath from the appropriate place */
289 if (OpInfo->Flags & AML_NAMED)
291 /* For nearly all NAMED operators, the name reference is the first child */
293 NameOp = Op->Asl.Child;
294 if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
297 * ALIAS is the only oddball opcode, the name declaration
298 * (alias name) is the second operand
300 NameOp = Op->Asl.Child->Asl.Next;
303 else if (OpInfo->Flags & AML_CREATE)
305 /* Name must appear as the last parameter */
307 NameOp = Op->Asl.Child;
308 while (!(NameOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
310 NameOp = NameOp->Asl.Next;
314 return (NameOp);