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