aslanalyze.c revision 1.1.1.17 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1.1.2 jruoho * Module Name: aslanalyze.c - Support functions for parse tree walks
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.17 christos * Copyright (C) 2000 - 2021, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.17 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "aslcompiler.h"
45 1.1 jruoho #include "aslcompiler.y.h"
46 1.1.1.16 christos #include "acnamesp.h"
47 1.1.1.2 jruoho #include <string.h>
48 1.1.1.2 jruoho
49 1.1 jruoho
50 1.1 jruoho #define _COMPONENT ACPI_COMPILER
51 1.1 jruoho ACPI_MODULE_NAME ("aslanalyze")
52 1.1 jruoho
53 1.1 jruoho
54 1.1.1.9 christos /* Local Prototypes */
55 1.1.1.9 christos
56 1.1.1.9 christos static ACPI_STATUS
57 1.1.1.9 christos ApDeviceSubtreeWalk (
58 1.1.1.9 christos ACPI_PARSE_OBJECT *Op,
59 1.1.1.9 christos UINT32 Level,
60 1.1.1.9 christos void *Context);
61 1.1.1.9 christos
62 1.1.1.9 christos
63 1.1 jruoho /*******************************************************************************
64 1.1 jruoho *
65 1.1 jruoho * FUNCTION: AnIsInternalMethod
66 1.1 jruoho *
67 1.1.1.2 jruoho * PARAMETERS: Op - Current op
68 1.1 jruoho *
69 1.1 jruoho * RETURN: Boolean
70 1.1 jruoho *
71 1.1 jruoho * DESCRIPTION: Check for an internal control method.
72 1.1 jruoho *
73 1.1 jruoho ******************************************************************************/
74 1.1 jruoho
75 1.1.1.2 jruoho BOOLEAN
76 1.1 jruoho AnIsInternalMethod (
77 1.1 jruoho ACPI_PARSE_OBJECT *Op)
78 1.1 jruoho {
79 1.1 jruoho
80 1.1.1.7 christos if ((!strcmp (Op->Asl.ExternalName, "\\_OSI")) ||
81 1.1.1.7 christos (!strcmp (Op->Asl.ExternalName, "_OSI")))
82 1.1 jruoho {
83 1.1 jruoho return (TRUE);
84 1.1 jruoho }
85 1.1 jruoho
86 1.1 jruoho return (FALSE);
87 1.1 jruoho }
88 1.1 jruoho
89 1.1 jruoho
90 1.1 jruoho /*******************************************************************************
91 1.1 jruoho *
92 1.1 jruoho * FUNCTION: AnGetInternalMethodReturnType
93 1.1 jruoho *
94 1.1.1.2 jruoho * PARAMETERS: Op - Current op
95 1.1 jruoho *
96 1.1 jruoho * RETURN: Btype
97 1.1 jruoho *
98 1.1 jruoho * DESCRIPTION: Get the return type of an internal method
99 1.1 jruoho *
100 1.1 jruoho ******************************************************************************/
101 1.1 jruoho
102 1.1.1.2 jruoho UINT32
103 1.1 jruoho AnGetInternalMethodReturnType (
104 1.1 jruoho ACPI_PARSE_OBJECT *Op)
105 1.1 jruoho {
106 1.1 jruoho
107 1.1.1.7 christos if ((!strcmp (Op->Asl.ExternalName, "\\_OSI")) ||
108 1.1.1.7 christos (!strcmp (Op->Asl.ExternalName, "_OSI")))
109 1.1 jruoho {
110 1.1 jruoho return (ACPI_BTYPE_STRING);
111 1.1 jruoho }
112 1.1 jruoho
113 1.1 jruoho return (0);
114 1.1 jruoho }
115 1.1 jruoho
116 1.1 jruoho
117 1.1 jruoho /*******************************************************************************
118 1.1 jruoho *
119 1.1.1.2 jruoho * FUNCTION: AnCheckId
120 1.1 jruoho *
121 1.1.1.2 jruoho * PARAMETERS: Op - Current parse op
122 1.1.1.2 jruoho * Type - HID or CID
123 1.1 jruoho *
124 1.1.1.2 jruoho * RETURN: None
125 1.1 jruoho *
126 1.1.1.2 jruoho * DESCRIPTION: Perform various checks on _HID and _CID strings. Only limited
127 1.1.1.2 jruoho * checks can be performed on _CID strings.
128 1.1 jruoho *
129 1.1 jruoho ******************************************************************************/
130 1.1 jruoho
131 1.1.1.2 jruoho void
132 1.1.1.2 jruoho AnCheckId (
133 1.1.1.2 jruoho ACPI_PARSE_OBJECT *Op,
134 1.1.1.2 jruoho ACPI_NAME Type)
135 1.1 jruoho {
136 1.1.1.2 jruoho UINT32 i;
137 1.1.1.2 jruoho ACPI_SIZE Length;
138 1.1 jruoho
139 1.1 jruoho
140 1.1.1.2 jruoho /* Only care about string versions of _HID/_CID (integers are legal) */
141 1.1 jruoho
142 1.1.1.2 jruoho if (Op->Asl.ParseOpcode != PARSEOP_STRING_LITERAL)
143 1.1 jruoho {
144 1.1 jruoho return;
145 1.1 jruoho }
146 1.1 jruoho
147 1.1.1.2 jruoho /* For both _HID and _CID, the string must be non-null */
148 1.1 jruoho
149 1.1.1.2 jruoho Length = strlen (Op->Asl.Value.String);
150 1.1.1.2 jruoho if (!Length)
151 1.1 jruoho {
152 1.1.1.8 christos AslError (ASL_ERROR, ASL_MSG_NULL_STRING, Op, NULL);
153 1.1.1.2 jruoho return;
154 1.1 jruoho }
155 1.1 jruoho
156 1.1 jruoho /*
157 1.1.1.2 jruoho * One of the things we want to catch here is the use of a leading
158 1.1.1.2 jruoho * asterisk in the string -- an odd construct that certain platform
159 1.1.1.2 jruoho * manufacturers are fond of. Technically, a leading asterisk is OK
160 1.1.1.2 jruoho * for _CID, but a valid use of this has not been seen.
161 1.1 jruoho */
162 1.1.1.2 jruoho if (*Op->Asl.Value.String == '*')
163 1.1 jruoho {
164 1.1.1.2 jruoho AslError (ASL_ERROR, ASL_MSG_LEADING_ASTERISK,
165 1.1.1.2 jruoho Op, Op->Asl.Value.String);
166 1.1.1.2 jruoho return;
167 1.1 jruoho }
168 1.1 jruoho
169 1.1.1.2 jruoho /* _CID strings are bus-specific, no more checks can be performed */
170 1.1 jruoho
171 1.1.1.2 jruoho if (Type == ASL_TYPE_CID)
172 1.1 jruoho {
173 1.1.1.2 jruoho return;
174 1.1 jruoho }
175 1.1 jruoho
176 1.1.1.2 jruoho /* For _HID, all characters must be alphanumeric */
177 1.1 jruoho
178 1.1.1.2 jruoho for (i = 0; Op->Asl.Value.String[i]; i++)
179 1.1.1.2 jruoho {
180 1.1.1.2 jruoho if (!isalnum ((int) Op->Asl.Value.String[i]))
181 1.1 jruoho {
182 1.1.1.2 jruoho AslError (ASL_ERROR, ASL_MSG_ALPHANUMERIC_STRING,
183 1.1.1.2 jruoho Op, Op->Asl.Value.String);
184 1.1.1.4 christos return;
185 1.1 jruoho }
186 1.1 jruoho }
187 1.1 jruoho
188 1.1.1.4 christos /*
189 1.1.1.4 christos * _HID String must be one of these forms:
190 1.1.1.4 christos *
191 1.1.1.4 christos * "AAA####" A is an uppercase letter and # is a hex digit
192 1.1.1.4 christos * "ACPI####" # is a hex digit
193 1.1.1.4 christos * "NNNN####" N is an uppercase letter or decimal digit (0-9)
194 1.1.1.4 christos * # is a hex digit (ACPI 5.0)
195 1.1.1.4 christos */
196 1.1.1.2 jruoho if ((Length < 7) || (Length > 8))
197 1.1.1.2 jruoho {
198 1.1.1.2 jruoho AslError (ASL_ERROR, ASL_MSG_HID_LENGTH,
199 1.1.1.2 jruoho Op, Op->Asl.Value.String);
200 1.1.1.2 jruoho return;
201 1.1.1.2 jruoho }
202 1.1 jruoho
203 1.1.1.8 christos /* _HID Length is valid (7 or 8), now check prefix (first 3 or 4 chars) */
204 1.1 jruoho
205 1.1.1.4 christos if (Length == 7)
206 1.1.1.2 jruoho {
207 1.1.1.4 christos /* AAA####: Ensure the alphabetic prefix is all uppercase */
208 1.1.1.4 christos
209 1.1.1.4 christos for (i = 0; i < 3; i++)
210 1.1.1.4 christos {
211 1.1.1.4 christos if (!isupper ((int) Op->Asl.Value.String[i]))
212 1.1.1.4 christos {
213 1.1.1.4 christos AslError (ASL_ERROR, ASL_MSG_UPPER_CASE,
214 1.1.1.4 christos Op, &Op->Asl.Value.String[i]);
215 1.1.1.4 christos return;
216 1.1.1.4 christos }
217 1.1.1.4 christos }
218 1.1.1.4 christos }
219 1.1.1.4 christos else /* Length == 8 */
220 1.1.1.4 christos {
221 1.1.1.4 christos /*
222 1.1.1.4 christos * ACPI#### or NNNN####:
223 1.1.1.4 christos * Ensure the prefix contains only uppercase alpha or decimal digits
224 1.1.1.4 christos */
225 1.1.1.4 christos for (i = 0; i < 4; i++)
226 1.1.1.4 christos {
227 1.1.1.4 christos if (!isupper ((int) Op->Asl.Value.String[i]) &&
228 1.1.1.4 christos !isdigit ((int) Op->Asl.Value.String[i]))
229 1.1.1.4 christos {
230 1.1.1.4 christos AslError (ASL_ERROR, ASL_MSG_HID_PREFIX,
231 1.1.1.4 christos Op, &Op->Asl.Value.String[i]);
232 1.1.1.4 christos return;
233 1.1.1.4 christos }
234 1.1.1.4 christos }
235 1.1.1.2 jruoho }
236 1.1.1.2 jruoho
237 1.1.1.4 christos /* Remaining characters (suffix) must be hex digits */
238 1.1 jruoho
239 1.1.1.4 christos for (; i < Length; i++)
240 1.1.1.2 jruoho {
241 1.1.1.4 christos if (!isxdigit ((int) Op->Asl.Value.String[i]))
242 1.1.1.2 jruoho {
243 1.1.1.8 christos AslError (ASL_ERROR, ASL_MSG_HID_SUFFIX,
244 1.1.1.8 christos Op, &Op->Asl.Value.String[i]);
245 1.1.1.2 jruoho break;
246 1.1.1.2 jruoho }
247 1.1.1.2 jruoho }
248 1.1 jruoho }
249 1.1 jruoho
250 1.1 jruoho
251 1.1 jruoho /*******************************************************************************
252 1.1 jruoho *
253 1.1.1.2 jruoho * FUNCTION: AnLastStatementIsReturn
254 1.1 jruoho *
255 1.1.1.2 jruoho * PARAMETERS: Op - A method parse node
256 1.1 jruoho *
257 1.1.1.2 jruoho * RETURN: TRUE if last statement is an ASL RETURN. False otherwise
258 1.1 jruoho *
259 1.1.1.2 jruoho * DESCRIPTION: Walk down the list of top level statements within a method
260 1.1.1.2 jruoho * to find the last one. Check if that last statement is in
261 1.1.1.2 jruoho * fact a RETURN statement.
262 1.1 jruoho *
263 1.1 jruoho ******************************************************************************/
264 1.1 jruoho
265 1.1.1.2 jruoho BOOLEAN
266 1.1.1.2 jruoho AnLastStatementIsReturn (
267 1.1.1.2 jruoho ACPI_PARSE_OBJECT *Op)
268 1.1 jruoho {
269 1.1.1.2 jruoho ACPI_PARSE_OBJECT *Next;
270 1.1 jruoho
271 1.1 jruoho
272 1.1.1.2 jruoho /* Check if last statement is a return */
273 1.1 jruoho
274 1.1.1.2 jruoho Next = ASL_GET_CHILD_NODE (Op);
275 1.1.1.2 jruoho while (Next)
276 1.1.1.2 jruoho {
277 1.1.1.2 jruoho if ((!Next->Asl.Next) &&
278 1.1.1.2 jruoho (Next->Asl.ParseOpcode == PARSEOP_RETURN))
279 1.1 jruoho {
280 1.1.1.2 jruoho return (TRUE);
281 1.1 jruoho }
282 1.1 jruoho
283 1.1.1.2 jruoho Next = ASL_GET_PEER_NODE (Next);
284 1.1 jruoho }
285 1.1 jruoho
286 1.1.1.2 jruoho return (FALSE);
287 1.1 jruoho }
288 1.1 jruoho
289 1.1 jruoho
290 1.1 jruoho /*******************************************************************************
291 1.1 jruoho *
292 1.1 jruoho * FUNCTION: AnCheckMethodReturnValue
293 1.1 jruoho *
294 1.1 jruoho * PARAMETERS: Op - Parent
295 1.1 jruoho * OpInfo - Parent info
296 1.1 jruoho * ArgOp - Method invocation op
297 1.1 jruoho * RequiredBtypes - What caller requires
298 1.1 jruoho * ThisNodeBtype - What this node returns (if anything)
299 1.1 jruoho *
300 1.1 jruoho * RETURN: None
301 1.1 jruoho *
302 1.1 jruoho * DESCRIPTION: Check a method invocation for 1) A return value and if it does
303 1.1 jruoho * in fact return a value, 2) check the type of the return value.
304 1.1 jruoho *
305 1.1 jruoho ******************************************************************************/
306 1.1 jruoho
307 1.1.1.2 jruoho void
308 1.1 jruoho AnCheckMethodReturnValue (
309 1.1 jruoho ACPI_PARSE_OBJECT *Op,
310 1.1 jruoho const ACPI_OPCODE_INFO *OpInfo,
311 1.1 jruoho ACPI_PARSE_OBJECT *ArgOp,
312 1.1 jruoho UINT32 RequiredBtypes,
313 1.1 jruoho UINT32 ThisNodeBtype)
314 1.1 jruoho {
315 1.1 jruoho ACPI_PARSE_OBJECT *OwningOp;
316 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
317 1.1.1.16 christos char *ExternalPath;
318 1.1 jruoho
319 1.1 jruoho
320 1.1 jruoho Node = ArgOp->Asl.Node;
321 1.1 jruoho
322 1.1.1.9 christos if (!Node)
323 1.1.1.9 christos {
324 1.1.1.9 christos /* No error message, this can happen and is OK */
325 1.1.1.9 christos
326 1.1.1.9 christos return;
327 1.1.1.9 christos }
328 1.1 jruoho
329 1.1 jruoho /* Examine the parent op of this method */
330 1.1 jruoho
331 1.1 jruoho OwningOp = Node->Op;
332 1.1.1.16 christos ExternalPath = AcpiNsGetNormalizedPathname (Node, TRUE);
333 1.1.1.16 christos
334 1.1.1.11 christos if (OwningOp->Asl.CompileFlags & OP_METHOD_NO_RETVAL)
335 1.1 jruoho {
336 1.1 jruoho /* Method NEVER returns a value */
337 1.1 jruoho
338 1.1.1.16 christos AslError (ASL_ERROR, ASL_MSG_NO_RETVAL, Op, ExternalPath);
339 1.1 jruoho }
340 1.1.1.11 christos else if (OwningOp->Asl.CompileFlags & OP_METHOD_SOME_NO_RETVAL)
341 1.1 jruoho {
342 1.1 jruoho /* Method SOMETIMES returns a value, SOMETIMES not */
343 1.1 jruoho
344 1.1.1.16 christos AslError (ASL_WARNING, ASL_MSG_SOME_NO_RETVAL, Op, ExternalPath);
345 1.1 jruoho }
346 1.1 jruoho else if (!(ThisNodeBtype & RequiredBtypes))
347 1.1 jruoho {
348 1.1 jruoho /* Method returns a value, but the type is wrong */
349 1.1 jruoho
350 1.1.1.13 christos AnFormatBtype (AslGbl_StringBuffer, ThisNodeBtype);
351 1.1.1.13 christos AnFormatBtype (AslGbl_StringBuffer2, RequiredBtypes);
352 1.1 jruoho
353 1.1 jruoho /*
354 1.1 jruoho * The case where the method does not return any value at all
355 1.1 jruoho * was already handled in the namespace cross reference
356 1.1 jruoho * -- Only issue an error if the method in fact returns a value,
357 1.1 jruoho * but it is of the wrong type
358 1.1 jruoho */
359 1.1 jruoho if (ThisNodeBtype != 0)
360 1.1 jruoho {
361 1.1.1.13 christos sprintf (AslGbl_MsgBuffer,
362 1.1 jruoho "Method returns [%s], %s operator requires [%s]",
363 1.1.1.13 christos AslGbl_StringBuffer, OpInfo->Name, AslGbl_StringBuffer2);
364 1.1 jruoho
365 1.1.1.17 christos AslError (ASL_WARNING, ASL_MSG_INVALID_TYPE, ArgOp, AslGbl_MsgBuffer);
366 1.1 jruoho }
367 1.1 jruoho }
368 1.1.1.16 christos
369 1.1.1.16 christos if (ExternalPath)
370 1.1.1.16 christos {
371 1.1.1.16 christos ACPI_FREE (ExternalPath);
372 1.1.1.16 christos }
373 1.1 jruoho }
374 1.1 jruoho
375 1.1 jruoho
376 1.1 jruoho /*******************************************************************************
377 1.1 jruoho *
378 1.1 jruoho * FUNCTION: AnIsResultUsed
379 1.1 jruoho *
380 1.1.1.2 jruoho * PARAMETERS: Op - Parent op for the operator
381 1.1 jruoho *
382 1.1 jruoho * RETURN: TRUE if result from this operation is actually consumed
383 1.1 jruoho *
384 1.1 jruoho * DESCRIPTION: Determine if the function result value from an operator is
385 1.1 jruoho * used.
386 1.1 jruoho *
387 1.1 jruoho ******************************************************************************/
388 1.1 jruoho
389 1.1 jruoho BOOLEAN
390 1.1 jruoho AnIsResultUsed (
391 1.1 jruoho ACPI_PARSE_OBJECT *Op)
392 1.1 jruoho {
393 1.1 jruoho ACPI_PARSE_OBJECT *Parent;
394 1.1 jruoho
395 1.1 jruoho
396 1.1 jruoho switch (Op->Asl.ParseOpcode)
397 1.1 jruoho {
398 1.1 jruoho case PARSEOP_INCREMENT:
399 1.1 jruoho case PARSEOP_DECREMENT:
400 1.1 jruoho
401 1.1 jruoho /* These are standalone operators, no return value */
402 1.1 jruoho
403 1.1 jruoho return (TRUE);
404 1.1 jruoho
405 1.1 jruoho default:
406 1.1.1.4 christos
407 1.1 jruoho break;
408 1.1 jruoho }
409 1.1 jruoho
410 1.1 jruoho /* Examine parent to determine if the return value is used */
411 1.1 jruoho
412 1.1 jruoho Parent = Op->Asl.Parent;
413 1.1 jruoho switch (Parent->Asl.ParseOpcode)
414 1.1 jruoho {
415 1.1 jruoho /* If/While - check if the operator is the predicate */
416 1.1 jruoho
417 1.1 jruoho case PARSEOP_IF:
418 1.1 jruoho case PARSEOP_WHILE:
419 1.1 jruoho
420 1.1 jruoho /* First child is the predicate */
421 1.1 jruoho
422 1.1 jruoho if (Parent->Asl.Child == Op)
423 1.1 jruoho {
424 1.1 jruoho return (TRUE);
425 1.1 jruoho }
426 1.1.1.8 christos
427 1.1 jruoho return (FALSE);
428 1.1 jruoho
429 1.1 jruoho /* Not used if one of these is the parent */
430 1.1 jruoho
431 1.1 jruoho case PARSEOP_METHOD:
432 1.1.1.8 christos case PARSEOP_DEFINITION_BLOCK:
433 1.1 jruoho case PARSEOP_ELSE:
434 1.1 jruoho
435 1.1 jruoho return (FALSE);
436 1.1 jruoho
437 1.1 jruoho default:
438 1.1.1.4 christos
439 1.1 jruoho /* Any other type of parent means that the result is used */
440 1.1 jruoho
441 1.1 jruoho return (TRUE);
442 1.1 jruoho }
443 1.1 jruoho }
444 1.1 jruoho
445 1.1 jruoho
446 1.1 jruoho /*******************************************************************************
447 1.1 jruoho *
448 1.1.1.2 jruoho * FUNCTION: ApCheckForGpeNameConflict
449 1.1 jruoho *
450 1.1.1.2 jruoho * PARAMETERS: Op - Current parse op
451 1.1 jruoho *
452 1.1.1.2 jruoho * RETURN: None
453 1.1 jruoho *
454 1.1.1.2 jruoho * DESCRIPTION: Check for a conflict between GPE names within this scope.
455 1.1.1.2 jruoho * Conflict means two GPE names with the same GPE number, but
456 1.1.1.2 jruoho * different types -- such as _L1C and _E1C.
457 1.1 jruoho *
458 1.1 jruoho ******************************************************************************/
459 1.1 jruoho
460 1.1.1.2 jruoho void
461 1.1.1.2 jruoho ApCheckForGpeNameConflict (
462 1.1.1.2 jruoho ACPI_PARSE_OBJECT *Op)
463 1.1 jruoho {
464 1.1.1.2 jruoho ACPI_PARSE_OBJECT *NextOp;
465 1.1.1.2 jruoho UINT32 GpeNumber;
466 1.1.1.14 christos char Name[ACPI_NAMESEG_SIZE + 1];
467 1.1.1.14 christos char Target[ACPI_NAMESEG_SIZE];
468 1.1 jruoho
469 1.1 jruoho
470 1.1.1.2 jruoho /* Need a null-terminated string version of NameSeg */
471 1.1.1.2 jruoho
472 1.1.1.15 christos ACPI_MOVE_32_TO_32 (Name, Op->Asl.NameSeg);
473 1.1.1.14 christos Name[ACPI_NAMESEG_SIZE] = 0;
474 1.1 jruoho
475 1.1 jruoho /*
476 1.1.1.2 jruoho * For a GPE method:
477 1.1.1.2 jruoho * 1st char must be underscore
478 1.1.1.2 jruoho * 2nd char must be L or E
479 1.1.1.2 jruoho * 3rd/4th chars must be a hex number
480 1.1 jruoho */
481 1.1.1.2 jruoho if ((Name[0] != '_') ||
482 1.1.1.2 jruoho ((Name[1] != 'L') && (Name[1] != 'E')))
483 1.1 jruoho {
484 1.1.1.2 jruoho return;
485 1.1.1.2 jruoho }
486 1.1 jruoho
487 1.1.1.2 jruoho /* Verify 3rd/4th chars are a valid hex value */
488 1.1 jruoho
489 1.1.1.7 christos GpeNumber = strtoul (&Name[2], NULL, 16);
490 1.1.1.2 jruoho if (GpeNumber == ACPI_UINT32_MAX)
491 1.1.1.2 jruoho {
492 1.1.1.2 jruoho return;
493 1.1 jruoho }
494 1.1 jruoho
495 1.1 jruoho /*
496 1.1.1.2 jruoho * We are now sure we have an _Lxx or _Exx.
497 1.1.1.2 jruoho * Create the target name that would cause collision (Flip E/L)
498 1.1 jruoho */
499 1.1.1.2 jruoho ACPI_MOVE_32_TO_32 (Target, Name);
500 1.1 jruoho
501 1.1.1.2 jruoho /* Inject opposite letter ("L" versus "E") */
502 1.1 jruoho
503 1.1.1.2 jruoho if (Name[1] == 'L')
504 1.1.1.2 jruoho {
505 1.1.1.2 jruoho Target[1] = 'E';
506 1.1.1.2 jruoho }
507 1.1.1.2 jruoho else /* Name[1] == 'E' */
508 1.1.1.2 jruoho {
509 1.1.1.2 jruoho Target[1] = 'L';
510 1.1.1.2 jruoho }
511 1.1 jruoho
512 1.1.1.2 jruoho /* Search all peers (objects within this scope) for target match */
513 1.1 jruoho
514 1.1.1.2 jruoho NextOp = Op->Asl.Next;
515 1.1.1.2 jruoho while (NextOp)
516 1.1.1.2 jruoho {
517 1.1 jruoho /*
518 1.1.1.2 jruoho * We mostly care about methods, but check Name() constructs also,
519 1.1.1.2 jruoho * even though they will get another error for not being a method.
520 1.1.1.2 jruoho * All GPE names must be defined as control methods.
521 1.1 jruoho */
522 1.1.1.2 jruoho if ((NextOp->Asl.ParseOpcode == PARSEOP_METHOD) ||
523 1.1.1.2 jruoho (NextOp->Asl.ParseOpcode == PARSEOP_NAME))
524 1.1 jruoho {
525 1.1.1.14 christos if (ACPI_COMPARE_NAMESEG (Target, NextOp->Asl.NameSeg))
526 1.1.1.2 jruoho {
527 1.1.1.2 jruoho /* Found both _Exy and _Lxy in the same scope, error */
528 1.1 jruoho
529 1.1.1.2 jruoho AslError (ASL_ERROR, ASL_MSG_GPE_NAME_CONFLICT, NextOp,
530 1.1.1.2 jruoho Name);
531 1.1.1.2 jruoho return;
532 1.1.1.2 jruoho }
533 1.1 jruoho }
534 1.1 jruoho
535 1.1.1.2 jruoho NextOp = NextOp->Asl.Next;
536 1.1 jruoho }
537 1.1 jruoho
538 1.1.1.2 jruoho /* OK, no conflict found */
539 1.1 jruoho
540 1.1.1.2 jruoho return;
541 1.1 jruoho }
542 1.1.1.3 jruoho
543 1.1.1.3 jruoho
544 1.1.1.3 jruoho /*******************************************************************************
545 1.1.1.3 jruoho *
546 1.1.1.3 jruoho * FUNCTION: ApCheckRegMethod
547 1.1.1.3 jruoho *
548 1.1.1.3 jruoho * PARAMETERS: Op - Current parse op
549 1.1.1.3 jruoho *
550 1.1.1.3 jruoho * RETURN: None
551 1.1.1.3 jruoho *
552 1.1.1.3 jruoho * DESCRIPTION: Ensure that a _REG method has a corresponding Operation
553 1.1.1.3 jruoho * Region declaration within the same scope. Note: _REG is defined
554 1.1.1.3 jruoho * to have two arguments and must therefore be defined as a
555 1.1.1.3 jruoho * control method.
556 1.1.1.3 jruoho *
557 1.1.1.3 jruoho ******************************************************************************/
558 1.1.1.3 jruoho
559 1.1.1.3 jruoho void
560 1.1.1.3 jruoho ApCheckRegMethod (
561 1.1.1.3 jruoho ACPI_PARSE_OBJECT *Op)
562 1.1.1.3 jruoho {
563 1.1.1.3 jruoho ACPI_PARSE_OBJECT *Next;
564 1.1.1.3 jruoho ACPI_PARSE_OBJECT *Parent;
565 1.1.1.3 jruoho
566 1.1.1.3 jruoho
567 1.1.1.3 jruoho /* We are only interested in _REG methods */
568 1.1.1.3 jruoho
569 1.1.1.14 christos if (!ACPI_COMPARE_NAMESEG (METHOD_NAME__REG, &Op->Asl.NameSeg))
570 1.1.1.3 jruoho {
571 1.1.1.3 jruoho return;
572 1.1.1.3 jruoho }
573 1.1.1.3 jruoho
574 1.1.1.3 jruoho /* Get the start of the current scope */
575 1.1.1.3 jruoho
576 1.1.1.3 jruoho Parent = Op->Asl.Parent;
577 1.1.1.3 jruoho Next = Parent->Asl.Child;
578 1.1.1.3 jruoho
579 1.1.1.3 jruoho /* Search entire scope for an operation region declaration */
580 1.1.1.3 jruoho
581 1.1.1.3 jruoho while (Next)
582 1.1.1.3 jruoho {
583 1.1.1.3 jruoho if (Next->Asl.ParseOpcode == PARSEOP_OPERATIONREGION)
584 1.1.1.3 jruoho {
585 1.1.1.3 jruoho return; /* Found region, OK */
586 1.1.1.3 jruoho }
587 1.1.1.3 jruoho
588 1.1.1.3 jruoho Next = Next->Asl.Next;
589 1.1.1.3 jruoho }
590 1.1.1.3 jruoho
591 1.1.1.3 jruoho /* No region found, issue warning */
592 1.1.1.3 jruoho
593 1.1.1.3 jruoho AslError (ASL_WARNING, ASL_MSG_NO_REGION, Op, NULL);
594 1.1.1.3 jruoho }
595 1.1.1.5 christos
596 1.1.1.5 christos
597 1.1.1.5 christos /*******************************************************************************
598 1.1.1.5 christos *
599 1.1.1.9 christos * FUNCTION: ApFindNameInDeviceTree
600 1.1.1.9 christos *
601 1.1.1.9 christos * PARAMETERS: Name - Name to search for
602 1.1.1.9 christos * Op - Current parse op
603 1.1.1.9 christos *
604 1.1.1.9 christos * RETURN: TRUE if name found in the same scope as Op.
605 1.1.1.9 christos *
606 1.1.1.9 christos * DESCRIPTION: Determine if a name appears in the same scope as Op, as either
607 1.1.1.9 christos * a Method() or a Name(). "Same scope" can mean under an If or
608 1.1.1.9 christos * Else statement.
609 1.1.1.9 christos *
610 1.1.1.9 christos * NOTE: Detects _HID/_ADR in this type of construct (legal in ACPI 6.1+)
611 1.1.1.9 christos *
612 1.1.1.9 christos * Scope (\_SB.PCI0)
613 1.1.1.9 christos * {
614 1.1.1.9 christos * Device (I2C0)
615 1.1.1.9 christos * {
616 1.1.1.9 christos * If (SMD0 != 4) {
617 1.1.1.9 christos * Name (_HID, "INT3442")
618 1.1.1.9 christos * } Else {
619 1.1.1.9 christos * Name (_ADR, 0x400)
620 1.1.1.9 christos * }
621 1.1.1.9 christos * }
622 1.1.1.9 christos * }
623 1.1.1.9 christos ******************************************************************************/
624 1.1.1.9 christos
625 1.1.1.9 christos BOOLEAN
626 1.1.1.9 christos ApFindNameInDeviceTree (
627 1.1.1.9 christos char *Name,
628 1.1.1.9 christos ACPI_PARSE_OBJECT *Op)
629 1.1.1.9 christos {
630 1.1.1.9 christos ACPI_STATUS Status;
631 1.1.1.9 christos
632 1.1.1.9 christos
633 1.1.1.9 christos Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD,
634 1.1.1.9 christos ApDeviceSubtreeWalk, NULL, Name);
635 1.1.1.9 christos
636 1.1.1.9 christos if (Status == AE_CTRL_TRUE)
637 1.1.1.9 christos {
638 1.1.1.9 christos return (TRUE); /* Found a match */
639 1.1.1.9 christos }
640 1.1.1.9 christos
641 1.1.1.9 christos return (FALSE);
642 1.1.1.9 christos }
643 1.1.1.9 christos
644 1.1.1.9 christos
645 1.1.1.9 christos /* Callback function for interface above */
646 1.1.1.9 christos
647 1.1.1.9 christos static ACPI_STATUS
648 1.1.1.9 christos ApDeviceSubtreeWalk (
649 1.1.1.9 christos ACPI_PARSE_OBJECT *Op,
650 1.1.1.9 christos UINT32 Level,
651 1.1.1.9 christos void *Context)
652 1.1.1.9 christos {
653 1.1.1.9 christos char *Name = ACPI_CAST_PTR (char, Context);
654 1.1.1.9 christos
655 1.1.1.9 christos
656 1.1.1.9 christos switch (Op->Asl.ParseOpcode)
657 1.1.1.9 christos {
658 1.1.1.9 christos case PARSEOP_DEVICE:
659 1.1.1.9 christos
660 1.1.1.9 christos /* Level 0 is the starting device, ignore it */
661 1.1.1.9 christos
662 1.1.1.9 christos if (Level > 0)
663 1.1.1.9 christos {
664 1.1.1.9 christos /* Ignore sub-devices */
665 1.1.1.9 christos
666 1.1.1.9 christos return (AE_CTRL_DEPTH);
667 1.1.1.9 christos }
668 1.1.1.9 christos break;
669 1.1.1.9 christos
670 1.1.1.9 christos case PARSEOP_NAME:
671 1.1.1.9 christos case PARSEOP_METHOD:
672 1.1.1.9 christos
673 1.1.1.9 christos /* These are what we are looking for */
674 1.1.1.9 christos
675 1.1.1.14 christos if (ACPI_COMPARE_NAMESEG (Name, Op->Asl.NameSeg))
676 1.1.1.9 christos {
677 1.1.1.9 christos return (AE_CTRL_TRUE);
678 1.1.1.9 christos }
679 1.1.1.9 christos return (AE_CTRL_DEPTH);
680 1.1.1.9 christos
681 1.1.1.9 christos case PARSEOP_SCOPE:
682 1.1.1.9 christos case PARSEOP_FIELD:
683 1.1.1.9 christos case PARSEOP_OPERATIONREGION:
684 1.1.1.9 christos
685 1.1.1.9 christos /*
686 1.1.1.9 christos * We want to ignore these, because either they can be large
687 1.1.1.9 christos * subtrees or open a scope to somewhere else.
688 1.1.1.9 christos */
689 1.1.1.9 christos return (AE_CTRL_DEPTH);
690 1.1.1.9 christos
691 1.1.1.9 christos default:
692 1.1.1.9 christos break;
693 1.1.1.9 christos }
694 1.1.1.9 christos
695 1.1.1.9 christos return (AE_OK);
696 1.1.1.9 christos }
697 1.1.1.9 christos
698 1.1.1.9 christos
699 1.1.1.9 christos /*******************************************************************************
700 1.1.1.9 christos *
701 1.1.1.5 christos * FUNCTION: ApFindNameInScope
702 1.1.1.5 christos *
703 1.1.1.5 christos * PARAMETERS: Name - Name to search for
704 1.1.1.5 christos * Op - Current parse op
705 1.1.1.5 christos *
706 1.1.1.5 christos * RETURN: TRUE if name found in the same scope as Op.
707 1.1.1.5 christos *
708 1.1.1.5 christos * DESCRIPTION: Determine if a name appears in the same scope as Op, as either
709 1.1.1.5 christos * a Method() or a Name().
710 1.1.1.5 christos *
711 1.1.1.5 christos ******************************************************************************/
712 1.1.1.5 christos
713 1.1.1.5 christos BOOLEAN
714 1.1.1.5 christos ApFindNameInScope (
715 1.1.1.5 christos char *Name,
716 1.1.1.5 christos ACPI_PARSE_OBJECT *Op)
717 1.1.1.5 christos {
718 1.1.1.5 christos ACPI_PARSE_OBJECT *Next;
719 1.1.1.5 christos ACPI_PARSE_OBJECT *Parent;
720 1.1.1.5 christos
721 1.1.1.5 christos
722 1.1.1.5 christos /* Get the start of the current scope */
723 1.1.1.5 christos
724 1.1.1.5 christos Parent = Op->Asl.Parent;
725 1.1.1.5 christos Next = Parent->Asl.Child;
726 1.1.1.5 christos
727 1.1.1.5 christos /* Search entire scope for a match to the name */
728 1.1.1.5 christos
729 1.1.1.5 christos while (Next)
730 1.1.1.5 christos {
731 1.1.1.5 christos if ((Next->Asl.ParseOpcode == PARSEOP_METHOD) ||
732 1.1.1.5 christos (Next->Asl.ParseOpcode == PARSEOP_NAME))
733 1.1.1.5 christos {
734 1.1.1.14 christos if (ACPI_COMPARE_NAMESEG (Name, Next->Asl.NameSeg))
735 1.1.1.5 christos {
736 1.1.1.5 christos return (TRUE);
737 1.1.1.5 christos }
738 1.1.1.5 christos }
739 1.1.1.5 christos
740 1.1.1.5 christos Next = Next->Asl.Next;
741 1.1.1.5 christos }
742 1.1.1.5 christos
743 1.1.1.5 christos return (FALSE);
744 1.1.1.5 christos }
745