aslxref.c revision 1.18 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: aslxref - Namespace cross-reference
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.17 christos * Copyright (C) 2000 - 2020, Intel Corp.
9 1.1 christos * All rights reserved.
10 1.1 christos *
11 1.1 christos * Redistribution and use in source and binary forms, with or without
12 1.1 christos * modification, are permitted provided that the following conditions
13 1.1 christos * are met:
14 1.1 christos * 1. Redistributions of source code must retain the above copyright
15 1.1 christos * notice, this list of conditions, and the following disclaimer,
16 1.1 christos * without modification.
17 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 christos * including a substantially similar Disclaimer requirement for further
21 1.1 christos * binary redistribution.
22 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 christos * of any contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * Alternatively, this software may be distributed under the terms of the
27 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 christos * Software Foundation.
29 1.1 christos *
30 1.1 christos * NO WARRANTY
31 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.1 christos */
43 1.1 christos
44 1.1 christos #include "aslcompiler.h"
45 1.1 christos #include "aslcompiler.y.h"
46 1.1 christos #include "acparser.h"
47 1.1 christos #include "amlcode.h"
48 1.1 christos #include "acnamesp.h"
49 1.1 christos #include "acdispat.h"
50 1.1 christos
51 1.1 christos
52 1.1 christos #define _COMPONENT ACPI_COMPILER
53 1.1 christos ACPI_MODULE_NAME ("aslxref")
54 1.1 christos
55 1.1 christos /* Local prototypes */
56 1.1 christos
57 1.1 christos static ACPI_STATUS
58 1.1 christos XfNamespaceLocateBegin (
59 1.1 christos ACPI_PARSE_OBJECT *Op,
60 1.1 christos UINT32 Level,
61 1.1 christos void *Context);
62 1.1 christos
63 1.1 christos static ACPI_STATUS
64 1.1 christos XfNamespaceLocateEnd (
65 1.1 christos ACPI_PARSE_OBJECT *Op,
66 1.1 christos UINT32 Level,
67 1.1 christos void *Context);
68 1.1 christos
69 1.14 christos static BOOLEAN
70 1.14 christos XfValidateCrossReference (
71 1.14 christos ACPI_PARSE_OBJECT *Op,
72 1.14 christos const ACPI_OPCODE_INFO *OpInfo,
73 1.14 christos ACPI_NAMESPACE_NODE *Node);
74 1.14 christos
75 1.1 christos static BOOLEAN
76 1.1 christos XfObjectExists (
77 1.1 christos char *Name);
78 1.1 christos
79 1.1 christos static ACPI_STATUS
80 1.1 christos XfCompareOneNamespaceObject (
81 1.1 christos ACPI_HANDLE ObjHandle,
82 1.1 christos UINT32 Level,
83 1.1 christos void *Context,
84 1.1 christos void **ReturnValue);
85 1.1 christos
86 1.1 christos static void
87 1.1 christos XfCheckFieldRange (
88 1.1 christos ACPI_PARSE_OBJECT *Op,
89 1.1 christos UINT32 RegionBitLength,
90 1.1 christos UINT32 FieldBitOffset,
91 1.1 christos UINT32 FieldBitLength,
92 1.1 christos UINT32 AccessBitWidth);
93 1.1 christos
94 1.18 christos static BOOLEAN
95 1.18 christos XfFindCondRefOfName (
96 1.18 christos ACPI_NAMESPACE_NODE *Node,
97 1.18 christos ACPI_PARSE_OBJECT *Op);
98 1.18 christos
99 1.18 christos static BOOLEAN
100 1.18 christos XfRefIsGuardedByIfCondRefOf (
101 1.18 christos ACPI_NAMESPACE_NODE *Node,
102 1.18 christos ACPI_PARSE_OBJECT *Op);
103 1.18 christos
104 1.1 christos
105 1.1 christos /*******************************************************************************
106 1.1 christos *
107 1.1 christos * FUNCTION: XfCrossReferenceNamespace
108 1.1 christos *
109 1.1 christos * PARAMETERS: None
110 1.1 christos *
111 1.1 christos * RETURN: Status
112 1.1 christos *
113 1.1 christos * DESCRIPTION: Perform a cross reference check of the parse tree against the
114 1.1 christos * namespace. Every named referenced within the parse tree
115 1.1 christos * should be get resolved with a namespace lookup. If not, the
116 1.1 christos * original reference in the ASL code is invalid -- i.e., refers
117 1.1 christos * to a non-existent object.
118 1.1 christos *
119 1.1 christos * NOTE: The ASL "External" operator causes the name to be inserted into the
120 1.1 christos * namespace so that references to the external name will be resolved
121 1.1 christos * correctly here.
122 1.1 christos *
123 1.1 christos ******************************************************************************/
124 1.1 christos
125 1.1 christos ACPI_STATUS
126 1.1 christos XfCrossReferenceNamespace (
127 1.1 christos void)
128 1.1 christos {
129 1.1 christos ACPI_WALK_STATE *WalkState;
130 1.1 christos
131 1.1 christos
132 1.1 christos /*
133 1.1 christos * Create a new walk state for use when looking up names
134 1.1 christos * within the namespace (Passed as context to the callbacks)
135 1.1 christos */
136 1.1 christos WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
137 1.1 christos if (!WalkState)
138 1.1 christos {
139 1.1 christos return (AE_NO_MEMORY);
140 1.1 christos }
141 1.1 christos
142 1.1 christos /* Walk the entire parse tree */
143 1.1 christos
144 1.13 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
145 1.7 christos XfNamespaceLocateBegin, XfNamespaceLocateEnd, WalkState);
146 1.3 christos
147 1.3 christos ACPI_FREE (WalkState);
148 1.1 christos return (AE_OK);
149 1.1 christos }
150 1.1 christos
151 1.1 christos
152 1.1 christos /*******************************************************************************
153 1.1 christos *
154 1.1 christos * FUNCTION: XfObjectExists
155 1.1 christos *
156 1.1 christos * PARAMETERS: Name - 4 char ACPI name
157 1.1 christos *
158 1.1 christos * RETURN: TRUE if name exists in namespace
159 1.1 christos *
160 1.1 christos * DESCRIPTION: Walk the namespace to find an object
161 1.1 christos *
162 1.1 christos ******************************************************************************/
163 1.1 christos
164 1.1 christos static BOOLEAN
165 1.1 christos XfObjectExists (
166 1.1 christos char *Name)
167 1.1 christos {
168 1.1 christos ACPI_STATUS Status;
169 1.1 christos
170 1.1 christos
171 1.1 christos /* Walk entire namespace from the supplied root */
172 1.1 christos
173 1.1 christos Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
174 1.6 christos ACPI_UINT32_MAX, FALSE, XfCompareOneNamespaceObject, NULL,
175 1.6 christos Name, NULL);
176 1.1 christos if (Status == AE_CTRL_TRUE)
177 1.1 christos {
178 1.1 christos /* At least one instance of the name was found */
179 1.1 christos
180 1.1 christos return (TRUE);
181 1.1 christos }
182 1.1 christos
183 1.1 christos return (FALSE);
184 1.1 christos }
185 1.1 christos
186 1.1 christos
187 1.1 christos /*******************************************************************************
188 1.1 christos *
189 1.1 christos * FUNCTION: XfCompareOneNamespaceObject
190 1.1 christos *
191 1.1 christos * PARAMETERS: ACPI_WALK_CALLBACK
192 1.1 christos *
193 1.1 christos * RETURN: Status
194 1.1 christos *
195 1.1 christos * DESCRIPTION: Compare name of one object.
196 1.1 christos *
197 1.1 christos ******************************************************************************/
198 1.1 christos
199 1.1 christos static ACPI_STATUS
200 1.1 christos XfCompareOneNamespaceObject (
201 1.1 christos ACPI_HANDLE ObjHandle,
202 1.1 christos UINT32 Level,
203 1.1 christos void *Context,
204 1.1 christos void **ReturnValue)
205 1.1 christos {
206 1.1 christos ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
207 1.1 christos
208 1.1 christos
209 1.1 christos /* Simply check the name */
210 1.1 christos
211 1.1 christos if (*((UINT32 *) (Context)) == Node->Name.Integer)
212 1.1 christos {
213 1.1 christos /* Abort walk if we found one instance */
214 1.1 christos
215 1.1 christos return (AE_CTRL_TRUE);
216 1.1 christos }
217 1.1 christos
218 1.1 christos return (AE_OK);
219 1.1 christos }
220 1.1 christos
221 1.1 christos
222 1.1 christos /*******************************************************************************
223 1.1 christos *
224 1.1 christos * FUNCTION: XfCheckFieldRange
225 1.1 christos *
226 1.1 christos * PARAMETERS: RegionBitLength - Length of entire parent region
227 1.1 christos * FieldBitOffset - Start of the field unit (within region)
228 1.1 christos * FieldBitLength - Entire length of field unit
229 1.1 christos * AccessBitWidth - Access width of the field unit
230 1.1 christos *
231 1.1 christos * RETURN: None
232 1.1 christos *
233 1.1 christos * DESCRIPTION: Check one field unit to make sure it fits in the parent
234 1.1 christos * op region.
235 1.1 christos *
236 1.1 christos * Note: AccessBitWidth must be either 8,16,32, or 64
237 1.1 christos *
238 1.1 christos ******************************************************************************/
239 1.1 christos
240 1.1 christos static void
241 1.1 christos XfCheckFieldRange (
242 1.1 christos ACPI_PARSE_OBJECT *Op,
243 1.1 christos UINT32 RegionBitLength,
244 1.1 christos UINT32 FieldBitOffset,
245 1.1 christos UINT32 FieldBitLength,
246 1.1 christos UINT32 AccessBitWidth)
247 1.1 christos {
248 1.1 christos UINT32 FieldEndBitOffset;
249 1.1 christos
250 1.1 christos
251 1.1 christos /*
252 1.1 christos * Check each field unit against the region size. The entire
253 1.1 christos * field unit (start offset plus length) must fit within the
254 1.1 christos * region.
255 1.1 christos */
256 1.1 christos FieldEndBitOffset = FieldBitOffset + FieldBitLength;
257 1.1 christos
258 1.1 christos if (FieldEndBitOffset > RegionBitLength)
259 1.1 christos {
260 1.1 christos /* Field definition itself is beyond the end-of-region */
261 1.1 christos
262 1.1 christos AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_OFFSET, Op, NULL);
263 1.1 christos return;
264 1.1 christos }
265 1.1 christos
266 1.1 christos /*
267 1.1 christos * Now check that the field plus AccessWidth doesn't go beyond
268 1.1 christos * the end-of-region. Assumes AccessBitWidth is a power of 2
269 1.1 christos */
270 1.1 christos FieldEndBitOffset = ACPI_ROUND_UP (FieldEndBitOffset, AccessBitWidth);
271 1.1 christos
272 1.1 christos if (FieldEndBitOffset > RegionBitLength)
273 1.1 christos {
274 1.1 christos /* Field definition combined with the access is beyond EOR */
275 1.1 christos
276 1.1 christos AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, Op, NULL);
277 1.1 christos }
278 1.1 christos }
279 1.1 christos
280 1.3 christos
281 1.3 christos /*******************************************************************************
282 1.3 christos *
283 1.1 christos * FUNCTION: XfNamespaceLocateBegin
284 1.1 christos *
285 1.1 christos * PARAMETERS: ASL_WALK_CALLBACK
286 1.1 christos *
287 1.1 christos * RETURN: Status
288 1.1 christos *
289 1.1 christos * DESCRIPTION: Descending callback used during cross-reference. For named
290 1.1 christos * object references, attempt to locate the name in the
291 1.1 christos * namespace.
292 1.1 christos *
293 1.1 christos * NOTE: ASL references to named fields within resource descriptors are
294 1.1 christos * resolved to integer values here. Therefore, this step is an
295 1.1 christos * important part of the code generation. We don't know that the
296 1.1 christos * name refers to a resource descriptor until now.
297 1.1 christos *
298 1.1 christos ******************************************************************************/
299 1.1 christos
300 1.1 christos static ACPI_STATUS
301 1.1 christos XfNamespaceLocateBegin (
302 1.1 christos ACPI_PARSE_OBJECT *Op,
303 1.1 christos UINT32 Level,
304 1.1 christos void *Context)
305 1.1 christos {
306 1.1 christos ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
307 1.1 christos ACPI_NAMESPACE_NODE *Node;
308 1.1 christos ACPI_STATUS Status;
309 1.1 christos ACPI_OBJECT_TYPE ObjectType;
310 1.1 christos char *Path;
311 1.1 christos UINT8 PassedArgs;
312 1.1 christos ACPI_PARSE_OBJECT *NextOp;
313 1.1 christos ACPI_PARSE_OBJECT *OwningOp;
314 1.1 christos ACPI_PARSE_OBJECT *SpaceIdOp;
315 1.1 christos UINT32 MinimumLength;
316 1.1 christos UINT32 Offset;
317 1.1 christos UINT32 FieldBitLength;
318 1.1 christos UINT32 TagBitLength;
319 1.1 christos UINT8 Message = 0;
320 1.1 christos const ACPI_OPCODE_INFO *OpInfo;
321 1.1 christos UINT32 Flags;
322 1.5 christos ASL_METHOD_LOCAL *MethodLocals = NULL;
323 1.5 christos ASL_METHOD_LOCAL *MethodArgs = NULL;
324 1.5 christos int RegisterNumber;
325 1.5 christos UINT32 i;
326 1.15 christos ACPI_NAMESPACE_NODE *DeclarationParentMethod;
327 1.15 christos ACPI_PARSE_OBJECT *ReferenceParentMethod;
328 1.1 christos
329 1.1 christos
330 1.1 christos ACPI_FUNCTION_TRACE_PTR (XfNamespaceLocateBegin, Op);
331 1.1 christos
332 1.5 christos
333 1.5 christos if ((Op->Asl.AmlOpcode == AML_METHOD_OP) && Op->Asl.Node)
334 1.5 christos {
335 1.5 christos Node = Op->Asl.Node;
336 1.5 christos
337 1.5 christos /* Support for method LocalX/ArgX analysis */
338 1.5 christos
339 1.5 christos if (!Node->MethodLocals)
340 1.5 christos {
341 1.5 christos /* Create local/arg info blocks */
342 1.5 christos
343 1.5 christos MethodLocals = UtLocalCalloc (
344 1.5 christos sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_LOCALS);
345 1.5 christos Node->MethodLocals = MethodLocals;
346 1.5 christos
347 1.5 christos MethodArgs = UtLocalCalloc (
348 1.5 christos sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_ARGS);
349 1.5 christos Node->MethodArgs = MethodArgs;
350 1.5 christos
351 1.5 christos /*
352 1.5 christos * Get the method argument count
353 1.5 christos * First, get the name node
354 1.5 christos */
355 1.5 christos NextOp = Op->Asl.Child;
356 1.5 christos
357 1.5 christos /* Get the NumArguments node */
358 1.5 christos
359 1.5 christos NextOp = NextOp->Asl.Next;
360 1.5 christos Node->ArgCount = (UINT8)
361 1.5 christos (((UINT8) NextOp->Asl.Value.Integer) & 0x07);
362 1.5 christos
363 1.14 christos /* We will track all possible ArgXs */
364 1.5 christos
365 1.5 christos for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
366 1.5 christos {
367 1.5 christos if (i < Node->ArgCount)
368 1.5 christos {
369 1.5 christos /* Real Args are always "initialized" */
370 1.5 christos
371 1.5 christos MethodArgs[i].Flags = ASL_ARG_INITIALIZED;
372 1.5 christos }
373 1.5 christos else
374 1.5 christos {
375 1.5 christos /* Other ArgXs can be used as locals */
376 1.5 christos
377 1.5 christos MethodArgs[i].Flags = ASL_ARG_IS_LOCAL;
378 1.5 christos }
379 1.5 christos
380 1.5 christos MethodArgs[i].Op = Op;
381 1.5 christos }
382 1.5 christos }
383 1.5 christos }
384 1.5 christos
385 1.1 christos /*
386 1.1 christos * If this node is the actual declaration of a name
387 1.1 christos * [such as the XXXX name in "Method (XXXX)"],
388 1.1 christos * we are not interested in it here. We only care about names that are
389 1.1 christos * references to other objects within the namespace and the parent objects
390 1.1 christos * of name declarations
391 1.1 christos */
392 1.10 christos if (Op->Asl.CompileFlags & OP_IS_NAME_DECLARATION)
393 1.1 christos {
394 1.1 christos return_ACPI_STATUS (AE_OK);
395 1.1 christos }
396 1.1 christos
397 1.5 christos OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
398 1.5 christos
399 1.5 christos /* Check method LocalX variables */
400 1.5 christos
401 1.5 christos if (OpInfo->Type == AML_TYPE_LOCAL_VARIABLE)
402 1.5 christos {
403 1.5 christos /* Find parent method Op */
404 1.5 christos
405 1.17 christos NextOp = UtGetParentMethodOp (Op);
406 1.5 christos if (!NextOp)
407 1.5 christos {
408 1.5 christos return_ACPI_STATUS (AE_OK);
409 1.5 christos }
410 1.5 christos
411 1.5 christos /* Get method node */
412 1.5 christos
413 1.5 christos Node = NextOp->Asl.Node;
414 1.5 christos
415 1.5 christos RegisterNumber = Op->Asl.AmlOpcode & 0x0007; /* 0x60 through 0x67 */
416 1.5 christos MethodLocals = Node->MethodLocals;
417 1.5 christos
418 1.10 christos if (Op->Asl.CompileFlags & OP_IS_TARGET)
419 1.5 christos {
420 1.5 christos /* Local is being initialized */
421 1.5 christos
422 1.5 christos MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_INITIALIZED;
423 1.5 christos MethodLocals[RegisterNumber].Op = Op;
424 1.5 christos
425 1.5 christos return_ACPI_STATUS (AE_OK);
426 1.5 christos }
427 1.5 christos
428 1.5 christos /* Mark this Local as referenced */
429 1.5 christos
430 1.5 christos MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_REFERENCED;
431 1.5 christos MethodLocals[RegisterNumber].Op = Op;
432 1.5 christos
433 1.5 christos return_ACPI_STATUS (AE_OK);
434 1.5 christos }
435 1.5 christos
436 1.5 christos /* Check method ArgX variables */
437 1.5 christos
438 1.5 christos if (OpInfo->Type == AML_TYPE_METHOD_ARGUMENT)
439 1.5 christos {
440 1.5 christos /* Find parent method Op */
441 1.5 christos
442 1.17 christos NextOp = UtGetParentMethodOp (Op);
443 1.5 christos if (!NextOp)
444 1.5 christos {
445 1.5 christos return_ACPI_STATUS (AE_OK);
446 1.5 christos }
447 1.5 christos
448 1.5 christos /* Get method node */
449 1.5 christos
450 1.5 christos Node = NextOp->Asl.Node;
451 1.5 christos
452 1.5 christos /* Get Arg # */
453 1.5 christos
454 1.5 christos RegisterNumber = Op->Asl.AmlOpcode - AML_ARG0; /* 0x68 through 0x6F */
455 1.5 christos MethodArgs = Node->MethodArgs;
456 1.5 christos
457 1.9 christos /* Mark this Arg as referenced */
458 1.9 christos
459 1.9 christos MethodArgs[RegisterNumber].Flags |= ASL_ARG_REFERENCED;
460 1.9 christos MethodArgs[RegisterNumber].Op = Op;
461 1.9 christos
462 1.10 christos if (Op->Asl.CompileFlags & OP_IS_TARGET)
463 1.5 christos {
464 1.5 christos /* Arg is being initialized */
465 1.5 christos
466 1.5 christos MethodArgs[RegisterNumber].Flags |= ASL_ARG_INITIALIZED;
467 1.5 christos }
468 1.5 christos
469 1.5 christos return_ACPI_STATUS (AE_OK);
470 1.5 christos }
471 1.1 christos
472 1.5 christos /*
473 1.5 christos * After method ArgX and LocalX, we are only interested in opcodes
474 1.5 christos * that have an associated name
475 1.5 christos */
476 1.1 christos if ((!(OpInfo->Flags & AML_NAMED)) &&
477 1.1 christos (!(OpInfo->Flags & AML_CREATE)) &&
478 1.1 christos (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
479 1.1 christos (Op->Asl.ParseOpcode != PARSEOP_NAMESEG) &&
480 1.10 christos (Op->Asl.ParseOpcode != PARSEOP_METHODCALL) &&
481 1.15 christos (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL))
482 1.1 christos {
483 1.1 christos return_ACPI_STATUS (AE_OK);
484 1.1 christos }
485 1.1 christos
486 1.1 christos /*
487 1.1 christos * We must enable the "search-to-root" for single NameSegs, but
488 1.1 christos * we have to be very careful about opening up scopes
489 1.1 christos */
490 1.1 christos Flags = ACPI_NS_SEARCH_PARENT;
491 1.1 christos if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
492 1.1 christos (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
493 1.10 christos (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
494 1.18 christos (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) ||
495 1.18 christos (Op->Asl.ParseOpcode == PARSEOP_CONDREFOF))
496 1.1 christos {
497 1.1 christos /*
498 1.1 christos * These are name references, do not push the scope stack
499 1.1 christos * for them.
500 1.1 christos */
501 1.1 christos Flags |= ACPI_NS_DONT_OPEN_SCOPE;
502 1.1 christos }
503 1.1 christos
504 1.1 christos /* Get the NamePath from the appropriate place */
505 1.1 christos
506 1.1 christos if (OpInfo->Flags & AML_NAMED)
507 1.1 christos {
508 1.1 christos /* For nearly all NAMED operators, the name reference is the first child */
509 1.1 christos
510 1.1 christos Path = Op->Asl.Child->Asl.Value.String;
511 1.1 christos if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
512 1.1 christos {
513 1.1 christos /*
514 1.1 christos * ALIAS is the only oddball opcode, the name declaration
515 1.1 christos * (alias name) is the second operand
516 1.1 christos */
517 1.1 christos Path = Op->Asl.Child->Asl.Next->Asl.Value.String;
518 1.1 christos }
519 1.1 christos }
520 1.1 christos else if (OpInfo->Flags & AML_CREATE)
521 1.1 christos {
522 1.1 christos /* Name must appear as the last parameter */
523 1.1 christos
524 1.1 christos NextOp = Op->Asl.Child;
525 1.10 christos while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION))
526 1.1 christos {
527 1.1 christos NextOp = NextOp->Asl.Next;
528 1.1 christos }
529 1.6 christos
530 1.1 christos Path = NextOp->Asl.Value.String;
531 1.1 christos }
532 1.1 christos else
533 1.1 christos {
534 1.1 christos Path = Op->Asl.Value.String;
535 1.1 christos }
536 1.1 christos
537 1.1 christos ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
538 1.1 christos ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
539 1.1 christos "Type=%s\n", AcpiUtGetTypeName (ObjectType)));
540 1.1 christos
541 1.1 christos /*
542 1.1 christos * Lookup the name in the namespace. Name must exist at this point, or it
543 1.1 christos * is an invalid reference.
544 1.1 christos *
545 1.1 christos * The namespace is also used as a lookup table for references to resource
546 1.1 christos * descriptors and the fields within them.
547 1.1 christos */
548 1.13 christos AslGbl_NsLookupCount++;
549 1.1 christos
550 1.1 christos Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
551 1.12 christos ACPI_IMODE_EXECUTE, Flags, WalkState, &Node);
552 1.1 christos if (ACPI_FAILURE (Status))
553 1.1 christos {
554 1.1 christos if (Status == AE_NOT_FOUND)
555 1.1 christos {
556 1.1 christos /*
557 1.1 christos * We didn't find the name reference by path -- we can qualify this
558 1.1 christos * a little better before we print an error message
559 1.1 christos */
560 1.18 christos
561 1.18 christos if ((Op->Asl.Parent) &&
562 1.18 christos (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
563 1.18 christos {
564 1.18 christos /*
565 1.18 christos * One special case: CondRefOf operator - if the name doesn't
566 1.18 christos * exist at this point, it means that there's no actual or
567 1.18 christos * external declaration. If the name is not found, just ignore
568 1.18 christos * it, the point of the operator is to determine if the name
569 1.18 christos * exists at runtime. We wanted to see if this named object
570 1.18 christos * exists to facilitate analysis to allow protected usage of
571 1.18 christos * undeclared externals.
572 1.18 christos */
573 1.18 christos return_ACPI_STATUS (AE_OK);
574 1.18 christos }
575 1.18 christos else if (strlen (Path) == ACPI_NAMESEG_SIZE)
576 1.1 christos {
577 1.1 christos /* A simple, one-segment ACPI name */
578 1.1 christos
579 1.1 christos if (XfObjectExists (Path))
580 1.1 christos {
581 1.1 christos /*
582 1.1 christos * There exists such a name, but we couldn't get to it
583 1.1 christos * from this scope
584 1.1 christos */
585 1.1 christos AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op,
586 1.1 christos Op->Asl.ExternalName);
587 1.1 christos }
588 1.1 christos else
589 1.1 christos {
590 1.1 christos /* The name doesn't exist, period */
591 1.1 christos
592 1.1 christos AslError (ASL_ERROR, ASL_MSG_NOT_EXIST,
593 1.1 christos Op, Op->Asl.ExternalName);
594 1.1 christos }
595 1.1 christos }
596 1.1 christos else
597 1.1 christos {
598 1.13 christos /* The NamePath contains multiple NameSegs */
599 1.1 christos
600 1.13 christos if ((OpInfo->Flags & AML_CREATE) ||
601 1.13 christos (OpInfo->ObjectType == ACPI_TYPE_LOCAL_ALIAS))
602 1.1 christos {
603 1.13 christos /*
604 1.13 christos * The new name is the last parameter. For the
605 1.13 christos * CreateXXXXField and Alias operators
606 1.13 christos */
607 1.13 christos NextOp = Op->Asl.Child;
608 1.13 christos while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION))
609 1.13 christos {
610 1.13 christos NextOp = NextOp->Asl.Next;
611 1.13 christos }
612 1.13 christos
613 1.13 christos AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, NextOp,
614 1.13 christos NextOp->Asl.ExternalName);
615 1.13 christos }
616 1.13 christos else if (OpInfo->Flags & AML_NAMED)
617 1.13 christos {
618 1.13 christos /* The new name is the first parameter */
619 1.13 christos
620 1.13 christos AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, Op,
621 1.13 christos Op->Asl.ExternalName);
622 1.13 christos }
623 1.13 christos else if (Path[0] == AML_ROOT_PREFIX)
624 1.13 christos {
625 1.13 christos /* Full namepath from root, the object does not exist */
626 1.1 christos
627 1.1 christos AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op,
628 1.1 christos Op->Asl.ExternalName);
629 1.1 christos }
630 1.1 christos else
631 1.1 christos {
632 1.1 christos /*
633 1.13 christos * Generic "not found" error. Cannot determine whether it
634 1.13 christos * doesn't exist or just can't be reached. However, we
635 1.13 christos * can differentiate between a NameSeg vs. NamePath.
636 1.1 christos */
637 1.14 christos if (strlen (Op->Asl.ExternalName) == ACPI_NAMESEG_SIZE)
638 1.13 christos {
639 1.13 christos AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
640 1.13 christos Op->Asl.ExternalName);
641 1.13 christos }
642 1.13 christos else
643 1.13 christos {
644 1.13 christos AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op,
645 1.13 christos Op->Asl.ExternalName);
646 1.13 christos }
647 1.1 christos }
648 1.1 christos }
649 1.1 christos
650 1.1 christos Status = AE_OK;
651 1.1 christos }
652 1.1 christos
653 1.1 christos return_ACPI_STATUS (Status);
654 1.1 christos }
655 1.1 christos
656 1.14 christos /* Check for an attempt to access an object in another method */
657 1.14 christos
658 1.14 christos if (!XfValidateCrossReference (Op, OpInfo, Node))
659 1.14 christos {
660 1.14 christos AslError (ASL_ERROR, ASL_MSG_TEMPORARY_OBJECT, Op,
661 1.14 christos Op->Asl.ExternalName);
662 1.14 christos return_ACPI_STATUS (Status);
663 1.14 christos }
664 1.14 christos
665 1.15 christos /* Object was found above, check for an illegal forward reference */
666 1.12 christos
667 1.12 christos if (Op->Asl.CompileFlags & OP_NOT_FOUND_DURING_LOAD)
668 1.12 christos {
669 1.12 christos /*
670 1.12 christos * During the load phase, this Op was flagged as a possible
671 1.15 christos * illegal forward reference. In other words, Op is a name path or
672 1.15 christos * name segment that refers to a named object declared after the
673 1.15 christos * reference. In this scinario, Node refers to the actual declaration
674 1.15 christos * and Op is a parse node that references the named object.
675 1.12 christos *
676 1.15 christos * Note:
677 1.15 christos *
678 1.15 christos * Object references inside of control methods are allowed to
679 1.15 christos * refer to objects declared outside of control methods.
680 1.15 christos *
681 1.15 christos * If the declaration and reference are both contained inside of the
682 1.15 christos * same method or outside of any method, this is a forward reference
683 1.15 christos * and should be reported as a compiler error.
684 1.12 christos */
685 1.17 christos DeclarationParentMethod = UtGetParentMethodNode (Node);
686 1.17 christos ReferenceParentMethod = UtGetParentMethodOp (Op);
687 1.15 christos
688 1.17 christos /* case 1: declaration and reference are both outside of method */
689 1.15 christos
690 1.15 christos if (!ReferenceParentMethod && !DeclarationParentMethod)
691 1.12 christos {
692 1.12 christos AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op,
693 1.12 christos Op->Asl.ExternalName);
694 1.12 christos }
695 1.15 christos
696 1.15 christos /* case 2: declaration and reference are both inside of the same method */
697 1.15 christos
698 1.15 christos else if (ReferenceParentMethod && DeclarationParentMethod &&
699 1.15 christos ReferenceParentMethod == DeclarationParentMethod->Op)
700 1.15 christos {
701 1.15 christos AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op,
702 1.15 christos Op->Asl.ExternalName);
703 1.15 christos }
704 1.12 christos }
705 1.12 christos
706 1.1 christos /* Check for a reference vs. name declaration */
707 1.1 christos
708 1.1 christos if (!(OpInfo->Flags & AML_NAMED) &&
709 1.1 christos !(OpInfo->Flags & AML_CREATE))
710 1.1 christos {
711 1.1 christos /* This node has been referenced, mark it for reference check */
712 1.1 christos
713 1.1 christos Node->Flags |= ANOBJ_IS_REFERENCED;
714 1.1 christos }
715 1.1 christos
716 1.1 christos /* Attempt to optimize the NamePath */
717 1.1 christos
718 1.1 christos OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node);
719 1.1 christos
720 1.1 christos /*
721 1.1 christos * 1) Dereference an alias (A name reference that is an alias)
722 1.1 christos * Aliases are not nested, the alias always points to the final object
723 1.1 christos */
724 1.1 christos if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) &&
725 1.1 christos (Node->Type == ACPI_TYPE_LOCAL_ALIAS))
726 1.1 christos {
727 1.1 christos /* This node points back to the original PARSEOP_ALIAS */
728 1.1 christos
729 1.1 christos NextOp = Node->Op;
730 1.1 christos
731 1.1 christos /* The first child is the alias target op */
732 1.1 christos
733 1.1 christos NextOp = NextOp->Asl.Child;
734 1.1 christos
735 1.1 christos /* That in turn points back to original target alias node */
736 1.1 christos
737 1.1 christos if (NextOp->Asl.Node)
738 1.1 christos {
739 1.1 christos Node = NextOp->Asl.Node;
740 1.1 christos }
741 1.1 christos
742 1.1 christos /* Else - forward reference to alias, will be resolved later */
743 1.1 christos }
744 1.1 christos
745 1.1 christos /* 2) Check for a reference to a resource descriptor */
746 1.1 christos
747 1.1 christos if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
748 1.1 christos (Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
749 1.1 christos {
750 1.1 christos /*
751 1.1 christos * This was a reference to a field within a resource descriptor.
752 1.1 christos * Extract the associated field offset (either a bit or byte
753 1.1 christos * offset depending on the field type) and change the named
754 1.1 christos * reference into an integer for AML code generation
755 1.1 christos */
756 1.1 christos Offset = Node->Value;
757 1.1 christos TagBitLength = Node->Length;
758 1.1 christos
759 1.1 christos /*
760 1.1 christos * If a field is being created, generate the length (in bits) of
761 1.1 christos * the field. Note: Opcodes other than CreateXxxField and Index
762 1.1 christos * can come through here. For other opcodes, we just need to
763 1.1 christos * convert the resource tag reference to an integer offset.
764 1.1 christos */
765 1.1 christos switch (Op->Asl.Parent->Asl.AmlOpcode)
766 1.1 christos {
767 1.1 christos case AML_CREATE_FIELD_OP: /* Variable "Length" field, in bits */
768 1.1 christos /*
769 1.1 christos * We know the length operand is an integer constant because
770 1.1 christos * we know that it contains a reference to a resource
771 1.1 christos * descriptor tag.
772 1.1 christos */
773 1.1 christos FieldBitLength = (UINT32) Op->Asl.Next->Asl.Value.Integer;
774 1.1 christos break;
775 1.1 christos
776 1.1 christos case AML_CREATE_BIT_FIELD_OP:
777 1.1 christos
778 1.1 christos FieldBitLength = 1;
779 1.1 christos break;
780 1.1 christos
781 1.1 christos case AML_CREATE_BYTE_FIELD_OP:
782 1.1 christos case AML_INDEX_OP:
783 1.1 christos
784 1.1 christos FieldBitLength = 8;
785 1.1 christos break;
786 1.1 christos
787 1.1 christos case AML_CREATE_WORD_FIELD_OP:
788 1.1 christos
789 1.1 christos FieldBitLength = 16;
790 1.1 christos break;
791 1.1 christos
792 1.1 christos case AML_CREATE_DWORD_FIELD_OP:
793 1.1 christos
794 1.1 christos FieldBitLength = 32;
795 1.1 christos break;
796 1.1 christos
797 1.1 christos case AML_CREATE_QWORD_FIELD_OP:
798 1.1 christos
799 1.1 christos FieldBitLength = 64;
800 1.1 christos break;
801 1.1 christos
802 1.1 christos default:
803 1.1 christos
804 1.1 christos FieldBitLength = 0;
805 1.1 christos break;
806 1.1 christos }
807 1.1 christos
808 1.1 christos /* Check the field length against the length of the resource tag */
809 1.1 christos
810 1.1 christos if (FieldBitLength)
811 1.1 christos {
812 1.1 christos if (TagBitLength < FieldBitLength)
813 1.1 christos {
814 1.1 christos Message = ASL_MSG_TAG_SMALLER;
815 1.1 christos }
816 1.1 christos else if (TagBitLength > FieldBitLength)
817 1.1 christos {
818 1.1 christos Message = ASL_MSG_TAG_LARGER;
819 1.1 christos }
820 1.1 christos
821 1.1 christos if (Message)
822 1.1 christos {
823 1.13 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer),
824 1.6 christos "Size mismatch, Tag: %u bit%s, Field: %u bit%s",
825 1.1 christos TagBitLength, (TagBitLength > 1) ? "s" : "",
826 1.1 christos FieldBitLength, (FieldBitLength > 1) ? "s" : "");
827 1.1 christos
828 1.13 christos AslError (ASL_WARNING, Message, Op, AslGbl_MsgBuffer);
829 1.1 christos }
830 1.1 christos }
831 1.1 christos
832 1.1 christos /* Convert the BitOffset to a ByteOffset for certain opcodes */
833 1.1 christos
834 1.1 christos switch (Op->Asl.Parent->Asl.AmlOpcode)
835 1.1 christos {
836 1.1 christos case AML_CREATE_BYTE_FIELD_OP:
837 1.1 christos case AML_CREATE_WORD_FIELD_OP:
838 1.1 christos case AML_CREATE_DWORD_FIELD_OP:
839 1.1 christos case AML_CREATE_QWORD_FIELD_OP:
840 1.1 christos case AML_INDEX_OP:
841 1.1 christos
842 1.1 christos Offset = ACPI_DIV_8 (Offset);
843 1.1 christos break;
844 1.1 christos
845 1.1 christos default:
846 1.1 christos
847 1.1 christos break;
848 1.1 christos }
849 1.1 christos
850 1.1 christos /* Now convert this node to an integer whose value is the field offset */
851 1.1 christos
852 1.1 christos Op->Asl.AmlLength = 0;
853 1.1 christos Op->Asl.ParseOpcode = PARSEOP_INTEGER;
854 1.1 christos Op->Asl.Value.Integer = (UINT64) Offset;
855 1.10 christos Op->Asl.CompileFlags |= OP_IS_RESOURCE_FIELD;
856 1.1 christos
857 1.1 christos OpcGenerateAmlOpcode (Op);
858 1.1 christos }
859 1.1 christos
860 1.1 christos /* 3) Check for a method invocation */
861 1.1 christos
862 1.1 christos else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) &&
863 1.1 christos (Node->Type == ACPI_TYPE_METHOD) &&
864 1.1 christos (Op->Asl.Parent) &&
865 1.1 christos (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD)) ||
866 1.1 christos
867 1.1 christos (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
868 1.1 christos {
869 1.1 christos /*
870 1.1 christos * A reference to a method within one of these opcodes is not an
871 1.1 christos * invocation of the method, it is simply a reference to the method.
872 1.8 christos *
873 1.8 christos * September 2016: Removed DeRefOf from this list
874 1.1 christos */
875 1.1 christos if ((Op->Asl.Parent) &&
876 1.8 christos ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF) ||
877 1.4 christos (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_PACKAGE) ||
878 1.4 christos (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)||
879 1.1 christos (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE)))
880 1.1 christos {
881 1.1 christos return_ACPI_STATUS (AE_OK);
882 1.1 christos }
883 1.8 christos
884 1.1 christos /*
885 1.1 christos * There are two types of method invocation:
886 1.1 christos * 1) Invocation with arguments -- the parser recognizes this
887 1.1 christos * as a METHODCALL.
888 1.1 christos * 2) Invocation with no arguments --the parser cannot determine that
889 1.1 christos * this is a method invocation, therefore we have to figure it out
890 1.1 christos * here.
891 1.1 christos */
892 1.1 christos if (Node->Type != ACPI_TYPE_METHOD)
893 1.1 christos {
894 1.13 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "%s is a %s",
895 1.6 christos Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
896 1.1 christos
897 1.13 christos AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, AslGbl_MsgBuffer);
898 1.1 christos return_ACPI_STATUS (AE_OK);
899 1.1 christos }
900 1.1 christos
901 1.1 christos /* Save the method node in the caller's op */
902 1.1 christos
903 1.1 christos Op->Asl.Node = Node;
904 1.1 christos if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)
905 1.1 christos {
906 1.1 christos return_ACPI_STATUS (AE_OK);
907 1.1 christos }
908 1.1 christos
909 1.1 christos /*
910 1.1 christos * This is a method invocation, with or without arguments.
911 1.1 christos * Count the number of arguments, each appears as a child
912 1.1 christos * under the parent node
913 1.1 christos */
914 1.1 christos Op->Asl.ParseOpcode = PARSEOP_METHODCALL;
915 1.1 christos UtSetParseOpName (Op);
916 1.1 christos
917 1.1 christos PassedArgs = 0;
918 1.6 christos NextOp = Op->Asl.Child;
919 1.1 christos
920 1.1 christos while (NextOp)
921 1.1 christos {
922 1.1 christos PassedArgs++;
923 1.1 christos NextOp = NextOp->Asl.Next;
924 1.1 christos }
925 1.1 christos
926 1.16 christos if (Node->Value != ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS &&
927 1.7 christos Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL)
928 1.1 christos {
929 1.1 christos /*
930 1.1 christos * Check the parsed arguments with the number expected by the
931 1.1 christos * method declaration itself
932 1.1 christos */
933 1.1 christos if (PassedArgs != Node->Value)
934 1.1 christos {
935 1.16 christos if (Node->Flags & ANOBJ_IS_EXTERNAL)
936 1.16 christos {
937 1.16 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer),
938 1.16 christos "according to previous use, %s requires %u",
939 1.16 christos Op->Asl.ExternalName, Node->Value);
940 1.16 christos }
941 1.16 christos else
942 1.16 christos {
943 1.16 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer),
944 1.16 christos "%s requires %u", Op->Asl.ExternalName,
945 1.16 christos Node->Value);
946 1.16 christos }
947 1.1 christos
948 1.1 christos if (PassedArgs < Node->Value)
949 1.1 christos {
950 1.13 christos AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, AslGbl_MsgBuffer);
951 1.1 christos }
952 1.1 christos else
953 1.1 christos {
954 1.13 christos AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, AslGbl_MsgBuffer);
955 1.1 christos }
956 1.1 christos }
957 1.1 christos }
958 1.16 christos
959 1.16 christos /*
960 1.16 christos * At this point, a method call to an external method has been
961 1.16 christos * detected. As of 11/19/2019, iASL does not support parameter counts
962 1.16 christos * for methods declared as external. Therefore, save the parameter
963 1.16 christos * count of the first method call and use this count check other
964 1.16 christos * method calls to ensure that the methods are being called with the
965 1.16 christos * same amount of parameters.
966 1.16 christos */
967 1.16 christos else if (Node->Type == ACPI_TYPE_METHOD &&
968 1.16 christos (Node->Flags & ANOBJ_IS_EXTERNAL) &&
969 1.16 christos Node->Value == ASL_EXTERNAL_METHOD_UNKNOWN_PARAMS &&
970 1.16 christos Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL)
971 1.16 christos {
972 1.16 christos Node->Value = PassedArgs;
973 1.16 christos }
974 1.1 christos }
975 1.1 christos
976 1.1 christos /* 4) Check for an ASL Field definition */
977 1.1 christos
978 1.1 christos else if ((Op->Asl.Parent) &&
979 1.1 christos ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD) ||
980 1.1 christos (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD)))
981 1.1 christos {
982 1.1 christos /*
983 1.1 christos * Offset checking for fields. If the parent operation region has a
984 1.1 christos * constant length (known at compile time), we can check fields
985 1.1 christos * defined in that region against the region length. This will catch
986 1.1 christos * fields and field units that cannot possibly fit within the region.
987 1.1 christos *
988 1.1 christos * Note: Index fields do not directly reference an operation region,
989 1.1 christos * thus they are not included in this check.
990 1.1 christos */
991 1.1 christos if (Op == Op->Asl.Parent->Asl.Child)
992 1.1 christos {
993 1.1 christos /*
994 1.1 christos * This is the first child of the field node, which is
995 1.1 christos * the name of the region. Get the parse node for the
996 1.1 christos * region -- which contains the length of the region.
997 1.1 christos */
998 1.1 christos OwningOp = Node->Op;
999 1.1 christos Op->Asl.Parent->Asl.ExtraValue =
1000 1.1 christos ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer);
1001 1.1 christos
1002 1.1 christos /* Examine the field access width */
1003 1.1 christos
1004 1.1 christos switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer)
1005 1.1 christos {
1006 1.1 christos case AML_FIELD_ACCESS_ANY:
1007 1.1 christos case AML_FIELD_ACCESS_BYTE:
1008 1.1 christos case AML_FIELD_ACCESS_BUFFER:
1009 1.1 christos default:
1010 1.1 christos
1011 1.1 christos MinimumLength = 1;
1012 1.1 christos break;
1013 1.1 christos
1014 1.1 christos case AML_FIELD_ACCESS_WORD:
1015 1.1 christos
1016 1.1 christos MinimumLength = 2;
1017 1.1 christos break;
1018 1.1 christos
1019 1.1 christos case AML_FIELD_ACCESS_DWORD:
1020 1.1 christos
1021 1.1 christos MinimumLength = 4;
1022 1.1 christos break;
1023 1.1 christos
1024 1.1 christos case AML_FIELD_ACCESS_QWORD:
1025 1.1 christos
1026 1.1 christos MinimumLength = 8;
1027 1.1 christos break;
1028 1.1 christos }
1029 1.1 christos
1030 1.1 christos /*
1031 1.1 christos * Is the region at least as big as the access width?
1032 1.1 christos * Note: DataTableRegions have 0 length
1033 1.1 christos */
1034 1.1 christos if (((UINT32) OwningOp->Asl.Value.Integer) &&
1035 1.1 christos ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength))
1036 1.1 christos {
1037 1.1 christos AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL);
1038 1.1 christos }
1039 1.1 christos
1040 1.1 christos /*
1041 1.1 christos * Check EC/CMOS/SMBUS fields to make sure that the correct
1042 1.1 christos * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS)
1043 1.1 christos */
1044 1.1 christos SpaceIdOp = OwningOp->Asl.Child->Asl.Next;
1045 1.1 christos switch ((UINT32) SpaceIdOp->Asl.Value.Integer)
1046 1.1 christos {
1047 1.1 christos case ACPI_ADR_SPACE_EC:
1048 1.1 christos case ACPI_ADR_SPACE_CMOS:
1049 1.1 christos case ACPI_ADR_SPACE_GPIO:
1050 1.1 christos
1051 1.6 christos if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
1052 1.6 christos AML_FIELD_ACCESS_BYTE)
1053 1.1 christos {
1054 1.1 christos AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL);
1055 1.1 christos }
1056 1.1 christos break;
1057 1.1 christos
1058 1.1 christos case ACPI_ADR_SPACE_SMBUS:
1059 1.1 christos case ACPI_ADR_SPACE_IPMI:
1060 1.1 christos case ACPI_ADR_SPACE_GSBUS:
1061 1.1 christos
1062 1.6 christos if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
1063 1.6 christos AML_FIELD_ACCESS_BUFFER)
1064 1.1 christos {
1065 1.1 christos AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL);
1066 1.1 christos }
1067 1.1 christos break;
1068 1.1 christos
1069 1.1 christos default:
1070 1.1 christos
1071 1.1 christos /* Nothing to do for other address spaces */
1072 1.1 christos
1073 1.1 christos break;
1074 1.1 christos }
1075 1.1 christos }
1076 1.1 christos else
1077 1.1 christos {
1078 1.1 christos /*
1079 1.1 christos * This is one element of the field list. Check to make sure
1080 1.1 christos * that it does not go beyond the end of the parent operation region.
1081 1.1 christos *
1082 1.1 christos * In the code below:
1083 1.1 christos * Op->Asl.Parent->Asl.ExtraValue - Region Length (bits)
1084 1.1 christos * Op->Asl.ExtraValue - Field start offset (bits)
1085 1.1 christos * Op->Asl.Child->Asl.Value.Integer32 - Field length (bits)
1086 1.1 christos * Op->Asl.Child->Asl.ExtraValue - Field access width (bits)
1087 1.1 christos */
1088 1.1 christos if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child)
1089 1.1 christos {
1090 1.1 christos XfCheckFieldRange (Op,
1091 1.6 christos Op->Asl.Parent->Asl.ExtraValue,
1092 1.6 christos Op->Asl.ExtraValue,
1093 1.6 christos (UINT32) Op->Asl.Child->Asl.Value.Integer,
1094 1.6 christos Op->Asl.Child->Asl.ExtraValue);
1095 1.1 christos }
1096 1.1 christos }
1097 1.1 christos }
1098 1.1 christos
1099 1.14 christos /*
1100 1.14 christos * 5) Check for external resolution
1101 1.18 christos *
1102 1.14 christos * By this point, everything should be loaded in the namespace. If a
1103 1.14 christos * namespace lookup results in a namespace node that is an external, it
1104 1.14 christos * means that this named object was not defined in the input ASL. This
1105 1.14 christos * causes issues because there are plenty of incidents where developers
1106 1.14 christos * use the external keyword to suppress compiler errors about undefined
1107 1.14 christos * objects. Note: this only applies when compiling multiple definition
1108 1.14 christos * blocks.
1109 1.18 christos *
1110 1.18 christos * Do not check for external resolution in the following cases:
1111 1.18 christos *
1112 1.18 christos * case 1) External (ABCD)
1113 1.18 christos *
1114 1.18 christos * This declares ABCD as an external so there is no requirement for
1115 1.18 christos * ABCD to be loaded in the namespace when analyzing the actual
1116 1.18 christos * External() statement.
1117 1.18 christos *
1118 1.18 christos * case 2) CondRefOf (ABCD)
1119 1.18 christos *
1120 1.18 christos * This operator will query the ACPI namespace on the existence of
1121 1.18 christos * ABCD. If ABCD does not exist, this operator will return a 0
1122 1.18 christos * without incurring AML runtime errors. Therefore, ABCD is allowed
1123 1.18 christos * to not exist when analyzing the CondRefOf operator.
1124 1.18 christos *
1125 1.18 christos * case 3) External (ABCD)
1126 1.18 christos * if (CondRefOf (ABCD))
1127 1.18 christos * {
1128 1.18 christos * Store (0, ABCD)
1129 1.18 christos * }
1130 1.18 christos *
1131 1.18 christos * In this case, ABCD is accessed only if it exists due to the if
1132 1.18 christos * statement so there is no need to flag the ABCD nested in the
1133 1.18 christos * store operator.
1134 1.14 christos */
1135 1.14 christos if (AslGbl_ParseTreeRoot->Asl.Child && AslGbl_ParseTreeRoot->Asl.Child->Asl.Next &&
1136 1.18 christos (Node->Flags & ANOBJ_IS_EXTERNAL) &&
1137 1.18 christos Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL &&
1138 1.18 christos Op->Asl.ParseOpcode != PARSEOP_EXTERNAL &&
1139 1.18 christos Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_CONDREFOF &&
1140 1.18 christos !XfRefIsGuardedByIfCondRefOf (Node, Op))
1141 1.14 christos {
1142 1.14 christos AslError (ASL_ERROR, ASL_MSG_UNDEFINED_EXTERNAL, Op, NULL);
1143 1.14 christos }
1144 1.14 christos
1145 1.3 christos /* 5) Check for a connection object */
1146 1.3 christos #if 0
1147 1.3 christos else if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION)
1148 1.3 christos {
1149 1.3 christos return_ACPI_STATUS (Status);
1150 1.3 christos }
1151 1.3 christos #endif
1152 1.3 christos
1153 1.1 christos Op->Asl.Node = Node;
1154 1.1 christos return_ACPI_STATUS (Status);
1155 1.1 christos }
1156 1.1 christos
1157 1.1 christos
1158 1.1 christos /*******************************************************************************
1159 1.1 christos *
1160 1.18 christos * FUNCTION: XfRefIsGuardedByIfCondRefOf
1161 1.18 christos *
1162 1.18 christos * PARAMETERS: Node - Named object reference node
1163 1.18 christos * Op - Named object reference parse node
1164 1.18 christos *
1165 1.18 christos * RETURN: BOOLEAN
1166 1.18 christos *
1167 1.18 christos * DESCRIPTION: returns true if Op checked inside if (CondRefOf (...))
1168 1.18 christos * refers to Node.
1169 1.18 christos *
1170 1.18 christos ******************************************************************************/
1171 1.18 christos
1172 1.18 christos static BOOLEAN
1173 1.18 christos XfRefIsGuardedByIfCondRefOf (
1174 1.18 christos ACPI_NAMESPACE_NODE *Node,
1175 1.18 christos ACPI_PARSE_OBJECT *Op)
1176 1.18 christos {
1177 1.18 christos ACPI_PARSE_OBJECT *Parent = Op->Asl.Parent;
1178 1.18 christos
1179 1.18 christos
1180 1.18 christos while (Parent)
1181 1.18 christos {
1182 1.18 christos if (Parent->Asl.ParseOpcode == PARSEOP_IF &&
1183 1.18 christos XfFindCondRefOfName (Node, Parent->Asl.Child))
1184 1.18 christos {
1185 1.18 christos return (TRUE);
1186 1.18 christos }
1187 1.18 christos
1188 1.18 christos Parent = Parent->Asl.Parent;
1189 1.18 christos }
1190 1.18 christos
1191 1.18 christos return (FALSE);
1192 1.18 christos }
1193 1.18 christos
1194 1.18 christos
1195 1.18 christos /*******************************************************************************
1196 1.18 christos *
1197 1.18 christos * FUNCTION: XfRefIsGuardedByIfCondRefOf
1198 1.18 christos *
1199 1.18 christos * PARAMETERS: Node - Named object reference node
1200 1.18 christos * Op - Named object reference parse node
1201 1.18 christos *
1202 1.18 christos * RETURN: BOOLEAN
1203 1.18 christos *
1204 1.18 christos * DESCRIPTION: returns true if Op checked inside if (CondRefOf (...))
1205 1.18 christos * refers to Node.
1206 1.18 christos *
1207 1.18 christos ******************************************************************************/
1208 1.18 christos
1209 1.18 christos static BOOLEAN
1210 1.18 christos XfFindCondRefOfName (
1211 1.18 christos ACPI_NAMESPACE_NODE *Node,
1212 1.18 christos ACPI_PARSE_OBJECT *Op)
1213 1.18 christos {
1214 1.18 christos BOOLEAN CondRefOfFound = FALSE;
1215 1.18 christos
1216 1.18 christos
1217 1.18 christos if (!Op)
1218 1.18 christos {
1219 1.18 christos return (FALSE);
1220 1.18 christos }
1221 1.18 christos
1222 1.18 christos switch (Op->Asl.ParseOpcode)
1223 1.18 christos {
1224 1.18 christos case PARSEOP_CONDREFOF:
1225 1.18 christos
1226 1.18 christos return (Op->Asl.Child->Common.Node == Node);
1227 1.18 christos break;
1228 1.18 christos
1229 1.18 christos case PARSEOP_LAND:
1230 1.18 christos
1231 1.18 christos CondRefOfFound = XfFindCondRefOfName (Node, Op->Asl.Child);
1232 1.18 christos if (CondRefOfFound)
1233 1.18 christos {
1234 1.18 christos return (TRUE);
1235 1.18 christos }
1236 1.18 christos
1237 1.18 christos return (XfFindCondRefOfName (Node, Op->Asl.Child->Asl.Next));
1238 1.18 christos break;
1239 1.18 christos
1240 1.18 christos default:
1241 1.18 christos
1242 1.18 christos return (FALSE);
1243 1.18 christos break;
1244 1.18 christos }
1245 1.18 christos }
1246 1.18 christos
1247 1.18 christos
1248 1.18 christos /*******************************************************************************
1249 1.18 christos *
1250 1.1 christos * FUNCTION: XfNamespaceLocateEnd
1251 1.1 christos *
1252 1.1 christos * PARAMETERS: ASL_WALK_CALLBACK
1253 1.1 christos *
1254 1.1 christos * RETURN: Status
1255 1.1 christos *
1256 1.1 christos * DESCRIPTION: Ascending callback used during cross reference. We only
1257 1.1 christos * need to worry about scope management here.
1258 1.1 christos *
1259 1.1 christos ******************************************************************************/
1260 1.1 christos
1261 1.1 christos static ACPI_STATUS
1262 1.1 christos XfNamespaceLocateEnd (
1263 1.1 christos ACPI_PARSE_OBJECT *Op,
1264 1.1 christos UINT32 Level,
1265 1.1 christos void *Context)
1266 1.1 christos {
1267 1.1 christos ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context;
1268 1.1 christos const ACPI_OPCODE_INFO *OpInfo;
1269 1.1 christos
1270 1.1 christos
1271 1.1 christos ACPI_FUNCTION_TRACE (XfNamespaceLocateEnd);
1272 1.1 christos
1273 1.1 christos
1274 1.1 christos /* We are only interested in opcodes that have an associated name */
1275 1.1 christos
1276 1.1 christos OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1277 1.1 christos if (!(OpInfo->Flags & AML_NAMED))
1278 1.1 christos {
1279 1.1 christos return_ACPI_STATUS (AE_OK);
1280 1.1 christos }
1281 1.1 christos
1282 1.1 christos /* Not interested in name references, we did not open a scope for them */
1283 1.1 christos
1284 1.1 christos if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
1285 1.1 christos (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
1286 1.10 christos (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) ||
1287 1.10 christos (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL))
1288 1.1 christos {
1289 1.1 christos return_ACPI_STATUS (AE_OK);
1290 1.1 christos }
1291 1.1 christos
1292 1.1 christos /* Pop the scope stack if necessary */
1293 1.1 christos
1294 1.1 christos if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode)))
1295 1.1 christos {
1296 1.1 christos
1297 1.1 christos ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1298 1.1 christos "%s: Popping scope for Op %p\n",
1299 1.1 christos AcpiUtGetTypeName (OpInfo->ObjectType), Op));
1300 1.1 christos
1301 1.1 christos (void) AcpiDsScopeStackPop (WalkState);
1302 1.1 christos }
1303 1.1 christos
1304 1.1 christos return_ACPI_STATUS (AE_OK);
1305 1.1 christos }
1306 1.14 christos
1307 1.14 christos
1308 1.14 christos /*******************************************************************************
1309 1.14 christos *
1310 1.14 christos * FUNCTION: XfValidateCrossReference
1311 1.14 christos *
1312 1.14 christos * PARAMETERS: Op - Parse Op that references the object
1313 1.14 christos * OpInfo - Parse Op info struct
1314 1.14 christos * Node - Node for the referenced object
1315 1.14 christos *
1316 1.14 christos * RETURN: TRUE if the reference is legal, FALSE otherwise
1317 1.14 christos *
1318 1.14 christos * DESCRIPTION: Determine if a reference to another object is allowed.
1319 1.14 christos *
1320 1.14 christos * EXAMPLE:
1321 1.14 christos * Method (A) {Name (INT1, 1)} Declaration of object INT1
1322 1.14 christos * Method (B) (Store (2, \A.INT1)} Illegal reference to object INT1
1323 1.14 christos * (INT1 is temporary, valid only during
1324 1.14 christos * execution of A)
1325 1.14 christos *
1326 1.14 christos * NOTES:
1327 1.17 christos * A null pointer returned by either UtGetParentMethodOp or
1328 1.17 christos * UtGetParentMethodNode indicates that the parameter object is not
1329 1.14 christos * within a control method.
1330 1.14 christos *
1331 1.14 christos * Five cases are handled: Case(Op, Node)
1332 1.14 christos * 1) Case(0,0): Op is not within a method, Node is not --> OK
1333 1.14 christos * 2) Case(0,1): Op is not within a method, but Node is --> Illegal
1334 1.14 christos * 3) Case(1,0): Op is within a method, Node is not --> OK
1335 1.14 christos * 4) Case(1,1): Both are within the same method --> OK
1336 1.14 christos * 5) Case(1,1): Both are in methods, but not same method --> Illegal
1337 1.14 christos *
1338 1.14 christos ******************************************************************************/
1339 1.14 christos
1340 1.14 christos static BOOLEAN
1341 1.14 christos XfValidateCrossReference (
1342 1.14 christos ACPI_PARSE_OBJECT *Op,
1343 1.14 christos const ACPI_OPCODE_INFO *OpInfo,
1344 1.14 christos ACPI_NAMESPACE_NODE *Node)
1345 1.14 christos {
1346 1.14 christos ACPI_PARSE_OBJECT *ReferencingMethodOp;
1347 1.14 christos ACPI_NAMESPACE_NODE *ReferencedMethodNode;
1348 1.14 christos
1349 1.14 christos
1350 1.14 christos /* Ignore actual named (and related) object declarations */
1351 1.14 christos
1352 1.14 christos if (OpInfo->Flags & (AML_NAMED | AML_CREATE | AML_DEFER | AML_HAS_ARGS))
1353 1.14 christos {
1354 1.14 christos return (TRUE);
1355 1.14 christos }
1356 1.14 christos
1357 1.14 christos /*
1358 1.14 christos * 1) Search upwards in parse tree for owner of the referencing object
1359 1.14 christos * 2) Search upwards in namespace to find the owner of the referenced object
1360 1.14 christos */
1361 1.17 christos ReferencingMethodOp = UtGetParentMethodOp (Op);
1362 1.17 christos ReferencedMethodNode = UtGetParentMethodNode (Node);
1363 1.14 christos
1364 1.14 christos if (!ReferencingMethodOp && !ReferencedMethodNode)
1365 1.14 christos {
1366 1.14 christos /*
1367 1.14 christos * 1) Case (0,0): Both Op and Node are not within methods
1368 1.14 christos * --> OK
1369 1.14 christos */
1370 1.14 christos return (TRUE);
1371 1.14 christos }
1372 1.14 christos
1373 1.14 christos if (!ReferencingMethodOp && ReferencedMethodNode)
1374 1.14 christos {
1375 1.14 christos /*
1376 1.14 christos * 2) Case (0,1): Op is not in a method, but Node is within a
1377 1.14 christos * method --> illegal
1378 1.14 christos */
1379 1.14 christos return (FALSE);
1380 1.14 christos }
1381 1.14 christos else if (ReferencingMethodOp && !ReferencedMethodNode)
1382 1.14 christos {
1383 1.14 christos /*
1384 1.14 christos * 3) Case (1,0): Op is within a method, but Node is not
1385 1.14 christos * --> OK
1386 1.14 christos */
1387 1.14 christos return (TRUE);
1388 1.14 christos }
1389 1.14 christos else if (ReferencingMethodOp->Asl.Node == ReferencedMethodNode)
1390 1.14 christos {
1391 1.14 christos /*
1392 1.14 christos * 4) Case (1,1): Both Op and Node are within the same method
1393 1.14 christos * --> OK
1394 1.14 christos */
1395 1.14 christos return (TRUE);
1396 1.14 christos }
1397 1.14 christos else
1398 1.14 christos {
1399 1.14 christos /*
1400 1.14 christos * 5) Case (1,1), Op and Node are in different methods
1401 1.14 christos * --> Illegal
1402 1.14 christos */
1403 1.14 christos return (FALSE);
1404 1.14 christos }
1405 1.14 christos }
1406