dspkginit.c revision 1.1.1.8 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: dspkginit - Completion of deferred package initialization
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.1.1.8 christos * Copyright (C) 2000 - 2023, 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.1.6 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 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 "acpi.h"
45 1.1 christos #include "accommon.h"
46 1.1 christos #include "acnamesp.h"
47 1.1 christos #include "amlcode.h"
48 1.1 christos #include "acdispat.h"
49 1.1 christos #include "acinterp.h"
50 1.1.1.2 christos #include "acparser.h"
51 1.1 christos
52 1.1 christos
53 1.1 christos #define _COMPONENT ACPI_NAMESPACE
54 1.1 christos ACPI_MODULE_NAME ("dspkginit")
55 1.1 christos
56 1.1 christos
57 1.1 christos /* Local prototypes */
58 1.1 christos
59 1.1 christos static void
60 1.1 christos AcpiDsResolvePackageElement (
61 1.1 christos ACPI_OPERAND_OBJECT **Element);
62 1.1 christos
63 1.1 christos
64 1.1 christos /*******************************************************************************
65 1.1 christos *
66 1.1 christos * FUNCTION: AcpiDsBuildInternalPackageObj
67 1.1 christos *
68 1.1 christos * PARAMETERS: WalkState - Current walk state
69 1.1 christos * Op - Parser object to be translated
70 1.1 christos * ElementCount - Number of elements in the package - this is
71 1.1 christos * the NumElements argument to Package()
72 1.1 christos * ObjDescPtr - Where the ACPI internal object is returned
73 1.1 christos *
74 1.1 christos * RETURN: Status
75 1.1 christos *
76 1.1 christos * DESCRIPTION: Translate a parser Op package object to the equivalent
77 1.1 christos * namespace object
78 1.1 christos *
79 1.1 christos * NOTE: The number of elements in the package will be always be the NumElements
80 1.1 christos * count, regardless of the number of elements in the package list. If
81 1.1 christos * NumElements is smaller, only that many package list elements are used.
82 1.1 christos * if NumElements is larger, the Package object is padded out with
83 1.1 christos * objects of type Uninitialized (as per ACPI spec.)
84 1.1 christos *
85 1.1 christos * Even though the ASL compilers do not allow NumElements to be smaller
86 1.1 christos * than the Package list length (for the fixed length package opcode), some
87 1.1 christos * BIOS code modifies the AML on the fly to adjust the NumElements, and
88 1.1 christos * this code compensates for that. This also provides compatibility with
89 1.1 christos * other AML interpreters.
90 1.1 christos *
91 1.1 christos ******************************************************************************/
92 1.1 christos
93 1.1 christos ACPI_STATUS
94 1.1 christos AcpiDsBuildInternalPackageObj (
95 1.1 christos ACPI_WALK_STATE *WalkState,
96 1.1 christos ACPI_PARSE_OBJECT *Op,
97 1.1 christos UINT32 ElementCount,
98 1.1 christos ACPI_OPERAND_OBJECT **ObjDescPtr)
99 1.1 christos {
100 1.1 christos ACPI_PARSE_OBJECT *Arg;
101 1.1 christos ACPI_PARSE_OBJECT *Parent;
102 1.1 christos ACPI_OPERAND_OBJECT *ObjDesc = NULL;
103 1.1 christos ACPI_STATUS Status = AE_OK;
104 1.1.1.2 christos BOOLEAN ModuleLevelCode = FALSE;
105 1.1 christos UINT16 ReferenceCount;
106 1.1 christos UINT32 Index;
107 1.1 christos UINT32 i;
108 1.1 christos
109 1.1 christos
110 1.1 christos ACPI_FUNCTION_TRACE (DsBuildInternalPackageObj);
111 1.1 christos
112 1.1 christos
113 1.1.1.2 christos /* Check if we are executing module level code */
114 1.1.1.2 christos
115 1.1.1.2 christos if (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL)
116 1.1.1.2 christos {
117 1.1.1.2 christos ModuleLevelCode = TRUE;
118 1.1.1.2 christos }
119 1.1.1.2 christos
120 1.1 christos /* Find the parent of a possibly nested package */
121 1.1 christos
122 1.1 christos Parent = Op->Common.Parent;
123 1.1 christos while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
124 1.1 christos (Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
125 1.1 christos {
126 1.1 christos Parent = Parent->Common.Parent;
127 1.1 christos }
128 1.1 christos
129 1.1 christos /*
130 1.1 christos * If we are evaluating a Named package object of the form:
131 1.1 christos * Name (xxxx, Package)
132 1.1 christos * the package object already exists, otherwise it must be created.
133 1.1 christos */
134 1.1 christos ObjDesc = *ObjDescPtr;
135 1.1 christos if (!ObjDesc)
136 1.1 christos {
137 1.1 christos ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
138 1.1 christos *ObjDescPtr = ObjDesc;
139 1.1 christos if (!ObjDesc)
140 1.1 christos {
141 1.1 christos return_ACPI_STATUS (AE_NO_MEMORY);
142 1.1 christos }
143 1.1 christos
144 1.1 christos ObjDesc->Package.Node = Parent->Common.Node;
145 1.1 christos }
146 1.1 christos
147 1.1 christos if (ObjDesc->Package.Flags & AOPOBJ_DATA_VALID) /* Just in case */
148 1.1 christos {
149 1.1 christos return_ACPI_STATUS (AE_OK);
150 1.1 christos }
151 1.1 christos
152 1.1 christos /*
153 1.1 christos * Allocate the element array (array of pointers to the individual
154 1.1.1.2 christos * objects) if necessary. the count is based on the NumElements
155 1.1.1.2 christos * parameter. Add an extra pointer slot so that the list is always
156 1.1.1.2 christos * null terminated.
157 1.1 christos */
158 1.1 christos if (!ObjDesc->Package.Elements)
159 1.1 christos {
160 1.1.1.2 christos ObjDesc->Package.Elements = ACPI_ALLOCATE_ZEROED (
161 1.1.1.2 christos ((ACPI_SIZE) ElementCount + 1) * sizeof (void *));
162 1.1.1.2 christos
163 1.1.1.2 christos if (!ObjDesc->Package.Elements)
164 1.1.1.2 christos {
165 1.1.1.2 christos AcpiUtDeleteObjectDesc (ObjDesc);
166 1.1.1.2 christos return_ACPI_STATUS (AE_NO_MEMORY);
167 1.1.1.2 christos }
168 1.1.1.2 christos
169 1.1.1.2 christos ObjDesc->Package.Count = ElementCount;
170 1.1 christos }
171 1.1 christos
172 1.1.1.2 christos /* First arg is element count. Second arg begins the initializer list */
173 1.1.1.2 christos
174 1.1 christos Arg = Op->Common.Value.Arg;
175 1.1 christos Arg = Arg->Common.Next;
176 1.1 christos
177 1.1.1.2 christos /*
178 1.1.1.2 christos * If we are executing module-level code, we will defer the
179 1.1.1.2 christos * full resolution of the package elements in order to support
180 1.1.1.2 christos * forward references from the elements. This provides
181 1.1.1.2 christos * compatibility with other ACPI implementations.
182 1.1.1.2 christos */
183 1.1.1.2 christos if (ModuleLevelCode)
184 1.1 christos {
185 1.1.1.2 christos ObjDesc->Package.AmlStart = WalkState->Aml;
186 1.1.1.2 christos ObjDesc->Package.AmlLength = 0;
187 1.1.1.2 christos
188 1.1.1.2 christos ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,
189 1.1.1.2 christos "%s: Deferring resolution of Package elements\n",
190 1.1.1.2 christos ACPI_GET_FUNCTION_NAME));
191 1.1 christos }
192 1.1 christos
193 1.1 christos /*
194 1.1 christos * Initialize the elements of the package, up to the NumElements count.
195 1.1 christos * Package is automatically padded with uninitialized (NULL) elements
196 1.1 christos * if NumElements is greater than the package list length. Likewise,
197 1.1 christos * Package is truncated if NumElements is less than the list length.
198 1.1 christos */
199 1.1 christos for (i = 0; Arg && (i < ElementCount); i++)
200 1.1 christos {
201 1.1 christos if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
202 1.1 christos {
203 1.1.1.3 christos if (!Arg->Common.Node)
204 1.1.1.3 christos {
205 1.1.1.3 christos /*
206 1.1.1.3 christos * This is the case where an expression has returned a value.
207 1.1.1.3 christos * The use of expressions (TermArgs) within individual
208 1.1.1.3 christos * package elements is not supported by the AML interpreter,
209 1.1.1.3 christos * even though the ASL grammar supports it. Example:
210 1.1.1.3 christos *
211 1.1.1.3 christos * Name (INT1, 0x1234)
212 1.1.1.3 christos *
213 1.1.1.3 christos * Name (PKG3, Package () {
214 1.1.1.3 christos * Add (INT1, 0xAAAA0000)
215 1.1.1.3 christos * })
216 1.1.1.3 christos *
217 1.1.1.3 christos * 1) No known AML interpreter supports this type of construct
218 1.1.1.3 christos * 2) This fixes a fault if the construct is encountered
219 1.1.1.3 christos */
220 1.1.1.3 christos ACPI_EXCEPTION ((AE_INFO, AE_SUPPORT,
221 1.1.1.3 christos "Expressions within package elements are not supported"));
222 1.1.1.3 christos
223 1.1.1.3 christos /* Cleanup the return object, it is not needed */
224 1.1.1.3 christos
225 1.1.1.3 christos AcpiUtRemoveReference (WalkState->Results->Results.ObjDesc[0]);
226 1.1.1.3 christos return_ACPI_STATUS (AE_SUPPORT);
227 1.1.1.3 christos }
228 1.1.1.3 christos
229 1.1 christos if (Arg->Common.Node->Type == ACPI_TYPE_METHOD)
230 1.1 christos {
231 1.1 christos /*
232 1.1 christos * A method reference "looks" to the parser to be a method
233 1.1 christos * invocation, so we special case it here
234 1.1 christos */
235 1.1 christos Arg->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
236 1.1 christos Status = AcpiDsBuildInternalObject (
237 1.1 christos WalkState, Arg, &ObjDesc->Package.Elements[i]);
238 1.1 christos }
239 1.1 christos else
240 1.1 christos {
241 1.1 christos /* This package element is already built, just get it */
242 1.1 christos
243 1.1 christos ObjDesc->Package.Elements[i] =
244 1.1 christos ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node);
245 1.1 christos }
246 1.1 christos }
247 1.1 christos else
248 1.1 christos {
249 1.1 christos Status = AcpiDsBuildInternalObject (
250 1.1 christos WalkState, Arg, &ObjDesc->Package.Elements[i]);
251 1.1 christos if (Status == AE_NOT_FOUND)
252 1.1 christos {
253 1.1 christos ACPI_ERROR ((AE_INFO, "%-48s", "****DS namepath not found"));
254 1.1 christos }
255 1.1 christos
256 1.1.1.2 christos if (!ModuleLevelCode)
257 1.1.1.2 christos {
258 1.1.1.2 christos /*
259 1.1.1.2 christos * Initialize this package element. This function handles the
260 1.1.1.2 christos * resolution of named references within the package.
261 1.1.1.2 christos * Forward references from module-level code are deferred
262 1.1.1.2 christos * until all ACPI tables are loaded.
263 1.1.1.2 christos */
264 1.1.1.2 christos AcpiDsInitPackageElement (0, ObjDesc->Package.Elements[i],
265 1.1.1.2 christos NULL, &ObjDesc->Package.Elements[i]);
266 1.1.1.2 christos }
267 1.1 christos }
268 1.1 christos
269 1.1 christos if (*ObjDescPtr)
270 1.1 christos {
271 1.1 christos /* Existing package, get existing reference count */
272 1.1 christos
273 1.1 christos ReferenceCount = (*ObjDescPtr)->Common.ReferenceCount;
274 1.1 christos if (ReferenceCount > 1)
275 1.1 christos {
276 1.1 christos /* Make new element ref count match original ref count */
277 1.1 christos /* TBD: Probably need an AcpiUtAddReferences function */
278 1.1 christos
279 1.1 christos for (Index = 0; Index < ((UINT32) ReferenceCount - 1); Index++)
280 1.1 christos {
281 1.1 christos AcpiUtAddReference ((ObjDesc->Package.Elements[i]));
282 1.1 christos }
283 1.1 christos }
284 1.1 christos }
285 1.1 christos
286 1.1 christos Arg = Arg->Common.Next;
287 1.1 christos }
288 1.1 christos
289 1.1 christos /* Check for match between NumElements and actual length of PackageList */
290 1.1 christos
291 1.1 christos if (Arg)
292 1.1 christos {
293 1.1 christos /*
294 1.1 christos * NumElements was exhausted, but there are remaining elements in
295 1.1 christos * the PackageList. Truncate the package to NumElements.
296 1.1 christos *
297 1.1 christos * Note: technically, this is an error, from ACPI spec: "It is an
298 1.1 christos * error for NumElements to be less than the number of elements in
299 1.1 christos * the PackageList". However, we just print a message and no
300 1.1 christos * exception is returned. This provides compatibility with other
301 1.1 christos * ACPI implementations. Some firmware implementations will alter
302 1.1 christos * the NumElements on the fly, possibly creating this type of
303 1.1 christos * ill-formed package object.
304 1.1 christos */
305 1.1 christos while (Arg)
306 1.1 christos {
307 1.1 christos /*
308 1.1 christos * We must delete any package elements that were created earlier
309 1.1 christos * and are not going to be used because of the package truncation.
310 1.1 christos */
311 1.1 christos if (Arg->Common.Node)
312 1.1 christos {
313 1.1 christos AcpiUtRemoveReference (
314 1.1 christos ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node));
315 1.1 christos Arg->Common.Node = NULL;
316 1.1 christos }
317 1.1 christos
318 1.1 christos /* Find out how many elements there really are */
319 1.1 christos
320 1.1 christos i++;
321 1.1 christos Arg = Arg->Common.Next;
322 1.1 christos }
323 1.1 christos
324 1.1 christos ACPI_INFO ((
325 1.1 christos "Actual Package length (%u) is larger than "
326 1.1 christos "NumElements field (%u), truncated",
327 1.1 christos i, ElementCount));
328 1.1 christos }
329 1.1 christos else if (i < ElementCount)
330 1.1 christos {
331 1.1 christos /*
332 1.1 christos * Arg list (elements) was exhausted, but we did not reach
333 1.1 christos * NumElements count.
334 1.1 christos *
335 1.1 christos * Note: this is not an error, the package is padded out
336 1.1.1.2 christos * with NULLs as per the ACPI specification.
337 1.1 christos */
338 1.1.1.2 christos ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO,
339 1.1.1.2 christos "%s: Package List length (%u) smaller than NumElements "
340 1.1 christos "count (%u), padded with null elements\n",
341 1.1.1.2 christos ACPI_GET_FUNCTION_NAME, i, ElementCount));
342 1.1.1.2 christos }
343 1.1.1.2 christos
344 1.1.1.2 christos /* Module-level packages will be resolved later */
345 1.1.1.2 christos
346 1.1.1.2 christos if (!ModuleLevelCode)
347 1.1.1.2 christos {
348 1.1.1.2 christos ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
349 1.1 christos }
350 1.1 christos
351 1.1 christos Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
352 1.1 christos return_ACPI_STATUS (Status);
353 1.1 christos }
354 1.1 christos
355 1.1 christos
356 1.1 christos /*******************************************************************************
357 1.1 christos *
358 1.1 christos * FUNCTION: AcpiDsInitPackageElement
359 1.1 christos *
360 1.1 christos * PARAMETERS: ACPI_PKG_CALLBACK
361 1.1 christos *
362 1.1 christos * RETURN: Status
363 1.1 christos *
364 1.1 christos * DESCRIPTION: Resolve a named reference element within a package object
365 1.1 christos *
366 1.1 christos ******************************************************************************/
367 1.1 christos
368 1.1 christos ACPI_STATUS
369 1.1 christos AcpiDsInitPackageElement (
370 1.1 christos UINT8 ObjectType,
371 1.1 christos ACPI_OPERAND_OBJECT *SourceObject,
372 1.1 christos ACPI_GENERIC_STATE *State,
373 1.1 christos void *Context)
374 1.1 christos {
375 1.1 christos ACPI_OPERAND_OBJECT **ElementPtr;
376 1.1 christos
377 1.1 christos
378 1.1.1.2 christos ACPI_FUNCTION_TRACE (DsInitPackageElement);
379 1.1.1.2 christos
380 1.1.1.2 christos
381 1.1 christos if (!SourceObject)
382 1.1 christos {
383 1.1.1.2 christos return_ACPI_STATUS (AE_OK);
384 1.1 christos }
385 1.1 christos
386 1.1 christos /*
387 1.1 christos * The following code is a bit of a hack to workaround a (current)
388 1.1 christos * limitation of the ACPI_PKG_CALLBACK interface. We need a pointer
389 1.1 christos * to the location within the element array because a new object
390 1.1 christos * may be created and stored there.
391 1.1 christos */
392 1.1 christos if (Context)
393 1.1 christos {
394 1.1 christos /* A direct call was made to this function */
395 1.1 christos
396 1.1 christos ElementPtr = (ACPI_OPERAND_OBJECT **) Context;
397 1.1 christos }
398 1.1 christos else
399 1.1 christos {
400 1.1 christos /* Call came from AcpiUtWalkPackageTree */
401 1.1 christos
402 1.1 christos ElementPtr = State->Pkg.ThisTargetObj;
403 1.1 christos }
404 1.1 christos
405 1.1 christos /* We are only interested in reference objects/elements */
406 1.1 christos
407 1.1 christos if (SourceObject->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
408 1.1 christos {
409 1.1 christos /* Attempt to resolve the (named) reference to a namespace node */
410 1.1 christos
411 1.1 christos AcpiDsResolvePackageElement (ElementPtr);
412 1.1 christos }
413 1.1 christos else if (SourceObject->Common.Type == ACPI_TYPE_PACKAGE)
414 1.1 christos {
415 1.1 christos SourceObject->Package.Flags |= AOPOBJ_DATA_VALID;
416 1.1 christos }
417 1.1 christos
418 1.1.1.2 christos return_ACPI_STATUS (AE_OK);
419 1.1 christos }
420 1.1 christos
421 1.1 christos
422 1.1 christos /*******************************************************************************
423 1.1 christos *
424 1.1 christos * FUNCTION: AcpiDsResolvePackageElement
425 1.1 christos *
426 1.1 christos * PARAMETERS: ElementPtr - Pointer to a reference object
427 1.1 christos *
428 1.1 christos * RETURN: Possible new element is stored to the indirect ElementPtr
429 1.1 christos *
430 1.1 christos * DESCRIPTION: Resolve a package element that is a reference to a named
431 1.1 christos * object.
432 1.1 christos *
433 1.1 christos ******************************************************************************/
434 1.1 christos
435 1.1 christos static void
436 1.1 christos AcpiDsResolvePackageElement (
437 1.1 christos ACPI_OPERAND_OBJECT **ElementPtr)
438 1.1 christos {
439 1.1 christos ACPI_STATUS Status;
440 1.1.1.2 christos ACPI_STATUS Status2;
441 1.1 christos ACPI_GENERIC_STATE ScopeInfo;
442 1.1 christos ACPI_OPERAND_OBJECT *Element = *ElementPtr;
443 1.1 christos ACPI_NAMESPACE_NODE *ResolvedNode;
444 1.1.1.2 christos ACPI_NAMESPACE_NODE *OriginalNode;
445 1.1.1.2 christos char *ExternalPath = "";
446 1.1 christos ACPI_OBJECT_TYPE Type;
447 1.1 christos
448 1.1 christos
449 1.1 christos ACPI_FUNCTION_TRACE (DsResolvePackageElement);
450 1.1 christos
451 1.1 christos
452 1.1 christos /* Check if reference element is already resolved */
453 1.1 christos
454 1.1 christos if (Element->Reference.Resolved)
455 1.1 christos {
456 1.1.1.2 christos ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,
457 1.1.1.2 christos "%s: Package element is already resolved\n",
458 1.1.1.2 christos ACPI_GET_FUNCTION_NAME));
459 1.1.1.2 christos
460 1.1 christos return_VOID;
461 1.1 christos }
462 1.1 christos
463 1.1 christos /* Element must be a reference object of correct type */
464 1.1 christos
465 1.1 christos ScopeInfo.Scope.Node = Element->Reference.Node; /* Prefix node */
466 1.1 christos
467 1.1.1.2 christos Status = AcpiNsLookup (&ScopeInfo, (char *) Element->Reference.Aml,
468 1.1 christos ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
469 1.1 christos ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
470 1.1 christos NULL, &ResolvedNode);
471 1.1 christos if (ACPI_FAILURE (Status))
472 1.1 christos {
473 1.1.1.2 christos if ((Status == AE_NOT_FOUND) && AcpiGbl_IgnorePackageResolutionErrors)
474 1.1.1.2 christos {
475 1.1.1.2 christos /*
476 1.1.1.2 christos * Optionally be silent about the NOT_FOUND case for the referenced
477 1.1.1.2 christos * name. Although this is potentially a serious problem,
478 1.1.1.2 christos * it can generate a lot of noise/errors on platforms whose
479 1.1.1.2 christos * firmware carries around a bunch of unused Package objects.
480 1.1.1.2 christos * To disable these errors, set this global to TRUE:
481 1.1.1.2 christos * AcpiGbl_IgnorePackageResolutionErrors
482 1.1.1.2 christos *
483 1.1.1.2 christos * If the AML actually tries to use such a package, the unresolved
484 1.1.1.2 christos * element(s) will be replaced with NULL elements.
485 1.1.1.2 christos */
486 1.1.1.2 christos
487 1.1.1.2 christos /* Referenced name not found, set the element to NULL */
488 1.1.1.2 christos
489 1.1.1.2 christos AcpiUtRemoveReference (*ElementPtr);
490 1.1.1.2 christos *ElementPtr = NULL;
491 1.1.1.2 christos return_VOID;
492 1.1.1.2 christos }
493 1.1.1.2 christos
494 1.1.1.2 christos Status2 = AcpiNsExternalizeName (ACPI_UINT32_MAX,
495 1.1.1.2 christos (char *) Element->Reference.Aml, NULL, &ExternalPath);
496 1.1 christos
497 1.1 christos ACPI_EXCEPTION ((AE_INFO, Status,
498 1.1.1.2 christos "While resolving a named reference package element - %s",
499 1.1.1.2 christos ExternalPath));
500 1.1.1.2 christos if (ACPI_SUCCESS (Status2))
501 1.1.1.2 christos {
502 1.1.1.2 christos ACPI_FREE (ExternalPath);
503 1.1.1.2 christos }
504 1.1.1.2 christos
505 1.1.1.2 christos /* Could not resolve name, set the element to NULL */
506 1.1 christos
507 1.1.1.2 christos AcpiUtRemoveReference (*ElementPtr);
508 1.1 christos *ElementPtr = NULL;
509 1.1 christos return_VOID;
510 1.1 christos }
511 1.1 christos else if (ResolvedNode->Type == ACPI_TYPE_ANY)
512 1.1 christos {
513 1.1 christos /* Named reference not resolved, return a NULL package element */
514 1.1 christos
515 1.1 christos ACPI_ERROR ((AE_INFO,
516 1.1 christos "Could not resolve named package element [%4.4s] in [%4.4s]",
517 1.1 christos ResolvedNode->Name.Ascii, ScopeInfo.Scope.Node->Name.Ascii));
518 1.1 christos *ElementPtr = NULL;
519 1.1 christos return_VOID;
520 1.1 christos }
521 1.1 christos
522 1.1 christos /*
523 1.1 christos * Special handling for Alias objects. We need ResolvedNode to point
524 1.1 christos * to the Alias target. This effectively "resolves" the alias.
525 1.1 christos */
526 1.1 christos if (ResolvedNode->Type == ACPI_TYPE_LOCAL_ALIAS)
527 1.1 christos {
528 1.1 christos ResolvedNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
529 1.1 christos ResolvedNode->Object);
530 1.1 christos }
531 1.1 christos
532 1.1 christos /* Update the reference object */
533 1.1 christos
534 1.1 christos Element->Reference.Resolved = TRUE;
535 1.1 christos Element->Reference.Node = ResolvedNode;
536 1.1 christos Type = Element->Reference.Node->Type;
537 1.1 christos
538 1.1 christos /*
539 1.1 christos * Attempt to resolve the node to a value before we insert it into
540 1.1 christos * the package. If this is a reference to a common data type,
541 1.1 christos * resolve it immediately. According to the ACPI spec, package
542 1.1 christos * elements can only be "data objects" or method references.
543 1.1 christos * Attempt to resolve to an Integer, Buffer, String or Package.
544 1.1 christos * If cannot, return the named reference (for things like Devices,
545 1.1 christos * Methods, etc.) Buffer Fields and Fields will resolve to simple
546 1.1 christos * objects (int/buf/str/pkg).
547 1.1 christos *
548 1.1 christos * NOTE: References to things like Devices, Methods, Mutexes, etc.
549 1.1 christos * will remain as named references. This behavior is not described
550 1.1 christos * in the ACPI spec, but it appears to be an oversight.
551 1.1 christos */
552 1.1.1.2 christos OriginalNode = ResolvedNode;
553 1.1 christos Status = AcpiExResolveNodeToValue (&ResolvedNode, NULL);
554 1.1 christos if (ACPI_FAILURE (Status))
555 1.1 christos {
556 1.1 christos return_VOID;
557 1.1 christos }
558 1.1 christos
559 1.1 christos switch (Type)
560 1.1 christos {
561 1.1 christos /*
562 1.1 christos * These object types are a result of named references, so we will
563 1.1 christos * leave them as reference objects. In other words, these types
564 1.1 christos * have no intrinsic "value".
565 1.1 christos */
566 1.1 christos case ACPI_TYPE_DEVICE:
567 1.1 christos case ACPI_TYPE_THERMAL:
568 1.1.1.2 christos case ACPI_TYPE_METHOD:
569 1.1 christos break;
570 1.1 christos
571 1.1 christos case ACPI_TYPE_MUTEX:
572 1.1 christos case ACPI_TYPE_POWER:
573 1.1 christos case ACPI_TYPE_PROCESSOR:
574 1.1 christos case ACPI_TYPE_EVENT:
575 1.1 christos case ACPI_TYPE_REGION:
576 1.1 christos
577 1.1.1.2 christos /* AcpiExResolveNodeToValue gave these an extra reference */
578 1.1.1.2 christos
579 1.1.1.2 christos AcpiUtRemoveReference (OriginalNode->Object);
580 1.1 christos break;
581 1.1 christos
582 1.1 christos default:
583 1.1 christos /*
584 1.1 christos * For all other types - the node was resolved to an actual
585 1.1.1.2 christos * operand object with a value, return the object. Remove
586 1.1.1.2 christos * a reference on the existing object.
587 1.1 christos */
588 1.1.1.2 christos AcpiUtRemoveReference (Element);
589 1.1 christos *ElementPtr = (ACPI_OPERAND_OBJECT *) ResolvedNode;
590 1.1 christos break;
591 1.1 christos }
592 1.1 christos
593 1.1 christos return_VOID;
594 1.1 christos }
595