1 /******************************************************************************
3 * Module Name: asllookup- Namespace lookup functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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"
52 #define _COMPONENT ACPI_COMPILER
53 ACPI_MODULE_NAME ("asllookup")
55 /* Local prototypes */
59 ACPI_HANDLE ObjHandle,
64 static ACPI_PARSE_OBJECT *
66 ACPI_PARSE_OBJECT *Op);
69 /*******************************************************************************
71 * FUNCTION: LkFindUnreferencedObjects
77 * DESCRIPTION: Namespace walk to find objects that are not referenced in any
78 * way. Must be called after the namespace has been cross
81 ******************************************************************************/
84 LkFindUnreferencedObjects (
88 /* Walk entire namespace from the supplied root */
90 (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
91 ACPI_UINT32_MAX, FALSE, LkIsObjectUsed, NULL,
96 /*******************************************************************************
98 * FUNCTION: LkIsObjectUsed
100 * PARAMETERS: ACPI_WALK_CALLBACK
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 ******************************************************************************/
115 ACPI_HANDLE ObjHandle,
120 ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
121 ACPI_NAMESPACE_NODE *Next;
124 /* Referenced flag is set during the namespace xref */
126 if (Node->Flags & ANOBJ_IS_REFERENCED)
136 /* These types are typically never directly referenced, ignore them */
140 case ACPI_TYPE_DEVICE:
141 case ACPI_TYPE_PROCESSOR:
142 case ACPI_TYPE_POWER:
143 case ACPI_TYPE_THERMAL:
144 case ACPI_TYPE_LOCAL_RESOURCE:
153 /* Determine if the name is within a control method */
158 if (Next->Type == ACPI_TYPE_METHOD)
161 * Name is within a method, therefore it is temporary.
162 * Issue a remark even if it is a reserved name (starts
163 * with an underscore).
165 sprintf (MsgBuffer, "Name is within method [%4.4s]",
167 AslError (ASL_REMARK, ASL_MSG_NOT_REFERENCED,
168 LkGetNameOp (Node->Op), MsgBuffer);
175 /* The name is not within a control method */
178 * Ignore names that start with an underscore. These are the reserved
179 * ACPI names and are typically not referenced since they are meant
180 * to be called by the host OS.
182 if (Node->Name.Ascii[0] == '_')
188 * What remains is an unresolved user name that is not within a method.
189 * However, the object could be referenced via another table, so issue
190 * the warning at level 2.
192 AslError (ASL_WARNING2, ASL_MSG_NOT_REFERENCED,
193 LkGetNameOp (Node->Op), NULL);
198 /*******************************************************************************
200 * FUNCTION: LkGetNameOp
202 * PARAMETERS: Op - Current Op
204 * RETURN: NameOp associated with the input op
206 * DESCRIPTION: Find the name declaration op associated with the operator
208 ******************************************************************************/
210 static ACPI_PARSE_OBJECT *
212 ACPI_PARSE_OBJECT *Op)
214 const ACPI_OPCODE_INFO *OpInfo;
215 ACPI_PARSE_OBJECT *NameOp = Op;
218 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
221 /* Get the NamePath from the appropriate place */
223 if (OpInfo->Flags & AML_NAMED)
225 /* For nearly all NAMED operators, the name reference is the first child */
227 NameOp = Op->Asl.Child;
228 if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
231 * ALIAS is the only oddball opcode, the name declaration
232 * (alias name) is the second operand
234 NameOp = Op->Asl.Child->Asl.Next;
237 else if (OpInfo->Flags & AML_CREATE)
239 /* Name must appear as the last parameter */
241 NameOp = Op->Asl.Child;
242 while (!(NameOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
244 NameOp = NameOp->Asl.Next;