asllookup.c revision 1.4 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.2 christos /*
8 1.4 christos * Copyright (C) 2000 - 2015, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.2 christos * Redistribution and use in source and binary forms, with or without
12 1.2 christos * modification, are permitted provided that the following conditions
13 1.2 christos * are met:
14 1.2 christos * 1. Redistributions of source code must retain the above copyright
15 1.2 christos * notice, this list of conditions, and the following disclaimer,
16 1.2 christos * without modification.
17 1.2 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.2 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.2 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.2 christos * including a substantially similar Disclaimer requirement for further
21 1.2 christos * binary redistribution.
22 1.2 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.2 christos * of any contributors may be used to endorse or promote products derived
24 1.2 christos * from this software without specific prior written permission.
25 1.2 christos *
26 1.2 christos * Alternatively, this software may be distributed under the terms of the
27 1.2 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.2 christos * Software Foundation.
29 1.2 christos *
30 1.2 christos * NO WARRANTY
31 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.2 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.2 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.2 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.2 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.2 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.2 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.2 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.2 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.2 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.2 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.2 christos */
43 1.1 jruoho
44 1.1 jruoho #include "aslcompiler.h"
45 1.1 jruoho #include "aslcompiler.y.h"
46 1.1 jruoho #include "acparser.h"
47 1.1 jruoho #include "amlcode.h"
48 1.1 jruoho #include "acnamesp.h"
49 1.1 jruoho #include "acdispat.h"
50 1.1 jruoho
51 1.1 jruoho
52 1.1 jruoho #define _COMPONENT ACPI_COMPILER
53 1.1 jruoho ACPI_MODULE_NAME ("asllookup")
54 1.1 jruoho
55 1.1 jruoho /* Local prototypes */
56 1.1 jruoho
57 1.1 jruoho static ACPI_STATUS
58 1.1 jruoho LkIsObjectUsed (
59 1.1 jruoho ACPI_HANDLE ObjHandle,
60 1.1 jruoho UINT32 Level,
61 1.1 jruoho void *Context,
62 1.1 jruoho void **ReturnValue);
63 1.1 jruoho
64 1.2 christos static ACPI_PARSE_OBJECT *
65 1.1 jruoho LkGetNameOp (
66 1.1 jruoho ACPI_PARSE_OBJECT *Op);
67 1.1 jruoho
68 1.1 jruoho
69 1.1 jruoho /*******************************************************************************
70 1.1 jruoho *
71 1.2 christos * FUNCTION: LkFindUnreferencedObjects
72 1.1 jruoho *
73 1.2 christos * PARAMETERS: None
74 1.1 jruoho *
75 1.1 jruoho * RETURN: None
76 1.1 jruoho *
77 1.2 christos * DESCRIPTION: Namespace walk to find objects that are not referenced in any
78 1.2 christos * way. Must be called after the namespace has been cross
79 1.2 christos * referenced.
80 1.1 jruoho *
81 1.1 jruoho ******************************************************************************/
82 1.1 jruoho
83 1.1 jruoho void
84 1.2 christos LkFindUnreferencedObjects (
85 1.2 christos void)
86 1.1 jruoho {
87 1.1 jruoho
88 1.2 christos /* Walk entire namespace from the supplied root */
89 1.2 christos
90 1.2 christos (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
91 1.2 christos ACPI_UINT32_MAX, FALSE, LkIsObjectUsed, NULL,
92 1.2 christos NULL, NULL);
93 1.1 jruoho }
94 1.1 jruoho
95 1.1 jruoho
96 1.1 jruoho /*******************************************************************************
97 1.1 jruoho *
98 1.2 christos * FUNCTION: LkIsObjectUsed
99 1.1 jruoho *
100 1.1 jruoho * PARAMETERS: ACPI_WALK_CALLBACK
101 1.1 jruoho *
102 1.1 jruoho * RETURN: Status
103 1.1 jruoho *
104 1.2 christos * DESCRIPTION: Check for an unreferenced namespace object and emit a warning.
105 1.2 christos * We have to be careful, because some types and names are
106 1.2 christos * typically or always unreferenced, we don't want to issue
107 1.2 christos * excessive warnings. Note: Names that are declared within a
108 1.2 christos * control method are temporary, so we always issue a remark
109 1.2 christos * if they are not referenced.
110 1.1 jruoho *
111 1.1 jruoho ******************************************************************************/
112 1.1 jruoho
113 1.1 jruoho static ACPI_STATUS
114 1.2 christos LkIsObjectUsed (
115 1.1 jruoho ACPI_HANDLE ObjHandle,
116 1.1 jruoho UINT32 Level,
117 1.1 jruoho void *Context,
118 1.1 jruoho void **ReturnValue)
119 1.1 jruoho {
120 1.2 christos ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
121 1.2 christos ACPI_NAMESPACE_NODE *Next;
122 1.1 jruoho
123 1.1 jruoho
124 1.2 christos /* Referenced flag is set during the namespace xref */
125 1.2 christos
126 1.2 christos if (Node->Flags & ANOBJ_IS_REFERENCED)
127 1.1 jruoho {
128 1.2 christos return (AE_OK);
129 1.1 jruoho }
130 1.1 jruoho
131 1.2 christos if (!Node->Op)
132 1.1 jruoho {
133 1.1 jruoho return (AE_OK);
134 1.1 jruoho }
135 1.1 jruoho
136 1.2 christos /* These types are typically never directly referenced, ignore them */
137 1.1 jruoho
138 1.2 christos switch (Node->Type)
139 1.2 christos {
140 1.2 christos case ACPI_TYPE_DEVICE:
141 1.2 christos case ACPI_TYPE_PROCESSOR:
142 1.2 christos case ACPI_TYPE_POWER:
143 1.2 christos case ACPI_TYPE_THERMAL:
144 1.2 christos case ACPI_TYPE_LOCAL_RESOURCE:
145 1.1 jruoho
146 1.2 christos return (AE_OK);
147 1.1 jruoho
148 1.2 christos default:
149 1.1 jruoho
150 1.2 christos break;
151 1.2 christos }
152 1.1 jruoho
153 1.2 christos /* Determine if the name is within a control method */
154 1.1 jruoho
155 1.2 christos Next = Node->Parent;
156 1.2 christos while (Next)
157 1.1 jruoho {
158 1.2 christos if (Next->Type == ACPI_TYPE_METHOD)
159 1.2 christos {
160 1.2 christos /*
161 1.2 christos * Name is within a method, therefore it is temporary.
162 1.2 christos * Issue a remark even if it is a reserved name (starts
163 1.2 christos * with an underscore).
164 1.2 christos */
165 1.2 christos snprintf (MsgBuffer, sizeof(MsgBuffer), "Name is within method [%4.4s]",
166 1.2 christos Next->Name.Ascii);
167 1.2 christos AslError (ASL_REMARK, ASL_MSG_NOT_REFERENCED,
168 1.2 christos LkGetNameOp (Node->Op), MsgBuffer);
169 1.2 christos return (AE_OK);
170 1.2 christos }
171 1.1 jruoho
172 1.2 christos Next = Next->Parent;
173 1.1 jruoho }
174 1.1 jruoho
175 1.2 christos /* The name is not within a control method */
176 1.1 jruoho
177 1.2 christos /*
178 1.2 christos * Ignore names that start with an underscore. These are the reserved
179 1.2 christos * ACPI names and are typically not referenced since they are meant
180 1.2 christos * to be called by the host OS.
181 1.2 christos */
182 1.2 christos if (Node->Name.Ascii[0] == '_')
183 1.1 jruoho {
184 1.2 christos return (AE_OK);
185 1.1 jruoho }
186 1.1 jruoho
187 1.2 christos /*
188 1.2 christos * What remains is an unresolved user name that is not within a method.
189 1.2 christos * However, the object could be referenced via another table, so issue
190 1.2 christos * the warning at level 2.
191 1.2 christos */
192 1.2 christos AslError (ASL_WARNING2, ASL_MSG_NOT_REFERENCED,
193 1.2 christos LkGetNameOp (Node->Op), NULL);
194 1.2 christos return (AE_OK);
195 1.1 jruoho }
196 1.1 jruoho
197 1.1 jruoho
198 1.1 jruoho /*******************************************************************************
199 1.1 jruoho *
200 1.1 jruoho * FUNCTION: LkGetNameOp
201 1.1 jruoho *
202 1.1 jruoho * PARAMETERS: Op - Current Op
203 1.1 jruoho *
204 1.1 jruoho * RETURN: NameOp associated with the input op
205 1.1 jruoho *
206 1.1 jruoho * DESCRIPTION: Find the name declaration op associated with the operator
207 1.1 jruoho *
208 1.1 jruoho ******************************************************************************/
209 1.1 jruoho
210 1.2 christos static ACPI_PARSE_OBJECT *
211 1.1 jruoho LkGetNameOp (
212 1.1 jruoho ACPI_PARSE_OBJECT *Op)
213 1.1 jruoho {
214 1.1 jruoho const ACPI_OPCODE_INFO *OpInfo;
215 1.1 jruoho ACPI_PARSE_OBJECT *NameOp = Op;
216 1.1 jruoho
217 1.1 jruoho
218 1.1 jruoho OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
219 1.1 jruoho
220 1.1 jruoho
221 1.1 jruoho /* Get the NamePath from the appropriate place */
222 1.1 jruoho
223 1.1 jruoho if (OpInfo->Flags & AML_NAMED)
224 1.1 jruoho {
225 1.1 jruoho /* For nearly all NAMED operators, the name reference is the first child */
226 1.1 jruoho
227 1.1 jruoho NameOp = Op->Asl.Child;
228 1.1 jruoho if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
229 1.1 jruoho {
230 1.1 jruoho /*
231 1.1 jruoho * ALIAS is the only oddball opcode, the name declaration
232 1.1 jruoho * (alias name) is the second operand
233 1.1 jruoho */
234 1.1 jruoho NameOp = Op->Asl.Child->Asl.Next;
235 1.1 jruoho }
236 1.1 jruoho }
237 1.1 jruoho else if (OpInfo->Flags & AML_CREATE)
238 1.1 jruoho {
239 1.1 jruoho /* Name must appear as the last parameter */
240 1.1 jruoho
241 1.1 jruoho NameOp = Op->Asl.Child;
242 1.1 jruoho while (!(NameOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
243 1.1 jruoho {
244 1.1 jruoho NameOp = NameOp->Asl.Next;
245 1.1 jruoho }
246 1.1 jruoho }
247 1.1 jruoho
248 1.1 jruoho return (NameOp);
249 1.1 jruoho }
250