dspkginit.c revision 1.9 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.9 christos /******************************************************************************
8 1.9 christos *
9 1.9 christos * 1. Copyright Notice
10 1.9 christos *
11 1.9 christos * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
12 1.1 christos * All rights reserved.
13 1.1 christos *
14 1.9 christos * 2. License
15 1.9 christos *
16 1.9 christos * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.9 christos * rights. You may have additional license terms from the party that provided
18 1.9 christos * you this software, covering your right to use that party's intellectual
19 1.9 christos * property rights.
20 1.9 christos *
21 1.9 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.9 christos * copy of the source code appearing in this file ("Covered Code") an
23 1.9 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.9 christos * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.9 christos * make derivatives, distribute, use and display any portion of the Covered
26 1.9 christos * Code in any form, with the right to sublicense such rights; and
27 1.9 christos *
28 1.9 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.9 christos * license (with the right to sublicense), under only those claims of Intel
30 1.9 christos * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.9 christos * offer to sell, and import the Covered Code and derivative works thereof
32 1.9 christos * solely to the minimum extent necessary to exercise the above copyright
33 1.9 christos * license, and in no event shall the patent license extend to any additions
34 1.9 christos * to or modifications of the Original Intel Code. No other license or right
35 1.9 christos * is granted directly or by implication, estoppel or otherwise;
36 1.9 christos *
37 1.9 christos * The above copyright and patent license is granted only if the following
38 1.9 christos * conditions are met:
39 1.9 christos *
40 1.9 christos * 3. Conditions
41 1.9 christos *
42 1.9 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.9 christos * Redistribution of source code of any substantial portion of the Covered
44 1.9 christos * Code or modification with rights to further distribute source must include
45 1.9 christos * the above Copyright Notice, the above License, this list of Conditions,
46 1.9 christos * and the following Disclaimer and Export Compliance provision. In addition,
47 1.9 christos * Licensee must cause all Covered Code to which Licensee contributes to
48 1.9 christos * contain a file documenting the changes Licensee made to create that Covered
49 1.9 christos * Code and the date of any change. Licensee must include in that file the
50 1.9 christos * documentation of any changes made by any predecessor Licensee. Licensee
51 1.9 christos * must include a prominent statement that the modification is derived,
52 1.9 christos * directly or indirectly, from Original Intel Code.
53 1.9 christos *
54 1.9 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.9 christos * Redistribution of source code of any substantial portion of the Covered
56 1.9 christos * Code or modification without rights to further distribute source must
57 1.9 christos * include the following Disclaimer and Export Compliance provision in the
58 1.9 christos * documentation and/or other materials provided with distribution. In
59 1.9 christos * addition, Licensee may not authorize further sublicense of source of any
60 1.9 christos * portion of the Covered Code, and must include terms to the effect that the
61 1.9 christos * license from Licensee to its licensee is limited to the intellectual
62 1.9 christos * property embodied in the software Licensee provides to its licensee, and
63 1.9 christos * not to intellectual property embodied in modifications its licensee may
64 1.9 christos * make.
65 1.9 christos *
66 1.9 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.9 christos * substantial portion of the Covered Code or modification must reproduce the
68 1.9 christos * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.9 christos * provision in the documentation and/or other materials provided with the
70 1.9 christos * distribution.
71 1.9 christos *
72 1.9 christos * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.9 christos * Intel Code.
74 1.9 christos *
75 1.9 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.9 christos * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.9 christos * other dealings in products derived from or relating to the Covered Code
78 1.9 christos * without prior written authorization from Intel.
79 1.9 christos *
80 1.9 christos * 4. Disclaimer and Export Compliance
81 1.9 christos *
82 1.9 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.9 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.9 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.9 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.9 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 1.9 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 1.9 christos * PARTICULAR PURPOSE.
89 1.9 christos *
90 1.9 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 1.9 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 1.9 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 1.9 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 1.9 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 1.9 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 1.9 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 1.9 christos * LIMITED REMEDY.
98 1.9 christos *
99 1.9 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 1.9 christos * software or system incorporating such software without first obtaining any
101 1.9 christos * required license or other approval from the U. S. Department of Commerce or
102 1.9 christos * any other agency or department of the United States Government. In the
103 1.9 christos * event Licensee exports any such software from the United States or
104 1.9 christos * re-exports any such software from a foreign destination, Licensee shall
105 1.9 christos * ensure that the distribution and export/re-export of the software is in
106 1.9 christos * compliance with all laws, regulations, orders, or other restrictions of the
107 1.9 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 1.9 christos * any of its subsidiaries will export/re-export any technical data, process,
109 1.9 christos * software, or service, directly or indirectly, to any country for which the
110 1.9 christos * United States government or any agency thereof requires an export license,
111 1.9 christos * other governmental approval, or letter of assurance, without first obtaining
112 1.9 christos * such license, approval or letter.
113 1.9 christos *
114 1.9 christos *****************************************************************************
115 1.9 christos *
116 1.9 christos * Alternatively, you may choose to be licensed under the terms of the
117 1.9 christos * following license:
118 1.9 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.6 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.9 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 1.9 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 1.9 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 1.9 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 1.9 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 1.9 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 1.9 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 1.9 christos *
146 1.9 christos * Alternatively, you may choose to be licensed under the terms of the
147 1.9 christos * GNU General Public License ("GPL") version 2 as published by the Free
148 1.9 christos * Software Foundation.
149 1.9 christos *
150 1.9 christos *****************************************************************************/
151 1.1 christos
152 1.1 christos #include "acpi.h"
153 1.1 christos #include "accommon.h"
154 1.1 christos #include "acnamesp.h"
155 1.1 christos #include "amlcode.h"
156 1.1 christos #include "acdispat.h"
157 1.1 christos #include "acinterp.h"
158 1.2 christos #include "acparser.h"
159 1.1 christos
160 1.1 christos
161 1.1 christos #define _COMPONENT ACPI_NAMESPACE
162 1.1 christos ACPI_MODULE_NAME ("dspkginit")
163 1.1 christos
164 1.1 christos
165 1.1 christos /* Local prototypes */
166 1.1 christos
167 1.1 christos static void
168 1.1 christos AcpiDsResolvePackageElement (
169 1.1 christos ACPI_OPERAND_OBJECT **Element);
170 1.1 christos
171 1.1 christos
172 1.1 christos /*******************************************************************************
173 1.1 christos *
174 1.1 christos * FUNCTION: AcpiDsBuildInternalPackageObj
175 1.1 christos *
176 1.1 christos * PARAMETERS: WalkState - Current walk state
177 1.1 christos * Op - Parser object to be translated
178 1.1 christos * ElementCount - Number of elements in the package - this is
179 1.1 christos * the NumElements argument to Package()
180 1.1 christos * ObjDescPtr - Where the ACPI internal object is returned
181 1.1 christos *
182 1.1 christos * RETURN: Status
183 1.1 christos *
184 1.1 christos * DESCRIPTION: Translate a parser Op package object to the equivalent
185 1.1 christos * namespace object
186 1.1 christos *
187 1.1 christos * NOTE: The number of elements in the package will be always be the NumElements
188 1.1 christos * count, regardless of the number of elements in the package list. If
189 1.1 christos * NumElements is smaller, only that many package list elements are used.
190 1.1 christos * if NumElements is larger, the Package object is padded out with
191 1.1 christos * objects of type Uninitialized (as per ACPI spec.)
192 1.1 christos *
193 1.1 christos * Even though the ASL compilers do not allow NumElements to be smaller
194 1.1 christos * than the Package list length (for the fixed length package opcode), some
195 1.1 christos * BIOS code modifies the AML on the fly to adjust the NumElements, and
196 1.1 christos * this code compensates for that. This also provides compatibility with
197 1.1 christos * other AML interpreters.
198 1.1 christos *
199 1.1 christos ******************************************************************************/
200 1.1 christos
201 1.1 christos ACPI_STATUS
202 1.1 christos AcpiDsBuildInternalPackageObj (
203 1.1 christos ACPI_WALK_STATE *WalkState,
204 1.1 christos ACPI_PARSE_OBJECT *Op,
205 1.1 christos UINT32 ElementCount,
206 1.1 christos ACPI_OPERAND_OBJECT **ObjDescPtr)
207 1.1 christos {
208 1.1 christos ACPI_PARSE_OBJECT *Arg;
209 1.1 christos ACPI_PARSE_OBJECT *Parent;
210 1.1 christos ACPI_OPERAND_OBJECT *ObjDesc = NULL;
211 1.1 christos ACPI_STATUS Status = AE_OK;
212 1.2 christos BOOLEAN ModuleLevelCode = FALSE;
213 1.1 christos UINT16 ReferenceCount;
214 1.1 christos UINT32 Index;
215 1.1 christos UINT32 i;
216 1.1 christos
217 1.1 christos
218 1.1 christos ACPI_FUNCTION_TRACE (DsBuildInternalPackageObj);
219 1.1 christos
220 1.1 christos
221 1.2 christos /* Check if we are executing module level code */
222 1.2 christos
223 1.2 christos if (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL)
224 1.2 christos {
225 1.2 christos ModuleLevelCode = TRUE;
226 1.2 christos }
227 1.2 christos
228 1.1 christos /* Find the parent of a possibly nested package */
229 1.1 christos
230 1.1 christos Parent = Op->Common.Parent;
231 1.1 christos while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
232 1.1 christos (Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
233 1.1 christos {
234 1.1 christos Parent = Parent->Common.Parent;
235 1.1 christos }
236 1.1 christos
237 1.1 christos /*
238 1.1 christos * If we are evaluating a Named package object of the form:
239 1.1 christos * Name (xxxx, Package)
240 1.1 christos * the package object already exists, otherwise it must be created.
241 1.1 christos */
242 1.1 christos ObjDesc = *ObjDescPtr;
243 1.1 christos if (!ObjDesc)
244 1.1 christos {
245 1.1 christos ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
246 1.1 christos *ObjDescPtr = ObjDesc;
247 1.1 christos if (!ObjDesc)
248 1.1 christos {
249 1.1 christos return_ACPI_STATUS (AE_NO_MEMORY);
250 1.1 christos }
251 1.1 christos
252 1.1 christos ObjDesc->Package.Node = Parent->Common.Node;
253 1.1 christos }
254 1.1 christos
255 1.1 christos if (ObjDesc->Package.Flags & AOPOBJ_DATA_VALID) /* Just in case */
256 1.1 christos {
257 1.1 christos return_ACPI_STATUS (AE_OK);
258 1.1 christos }
259 1.1 christos
260 1.1 christos /*
261 1.1 christos * Allocate the element array (array of pointers to the individual
262 1.2 christos * objects) if necessary. the count is based on the NumElements
263 1.2 christos * parameter. Add an extra pointer slot so that the list is always
264 1.2 christos * null terminated.
265 1.1 christos */
266 1.1 christos if (!ObjDesc->Package.Elements)
267 1.1 christos {
268 1.2 christos ObjDesc->Package.Elements = ACPI_ALLOCATE_ZEROED (
269 1.2 christos ((ACPI_SIZE) ElementCount + 1) * sizeof (void *));
270 1.2 christos
271 1.2 christos if (!ObjDesc->Package.Elements)
272 1.2 christos {
273 1.2 christos AcpiUtDeleteObjectDesc (ObjDesc);
274 1.2 christos return_ACPI_STATUS (AE_NO_MEMORY);
275 1.2 christos }
276 1.2 christos
277 1.2 christos ObjDesc->Package.Count = ElementCount;
278 1.1 christos }
279 1.1 christos
280 1.2 christos /* First arg is element count. Second arg begins the initializer list */
281 1.2 christos
282 1.1 christos Arg = Op->Common.Value.Arg;
283 1.1 christos Arg = Arg->Common.Next;
284 1.1 christos
285 1.2 christos /*
286 1.2 christos * If we are executing module-level code, we will defer the
287 1.2 christos * full resolution of the package elements in order to support
288 1.2 christos * forward references from the elements. This provides
289 1.2 christos * compatibility with other ACPI implementations.
290 1.2 christos */
291 1.2 christos if (ModuleLevelCode)
292 1.1 christos {
293 1.2 christos ObjDesc->Package.AmlStart = WalkState->Aml;
294 1.2 christos ObjDesc->Package.AmlLength = 0;
295 1.2 christos
296 1.2 christos ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,
297 1.2 christos "%s: Deferring resolution of Package elements\n",
298 1.2 christos ACPI_GET_FUNCTION_NAME));
299 1.1 christos }
300 1.1 christos
301 1.1 christos /*
302 1.1 christos * Initialize the elements of the package, up to the NumElements count.
303 1.1 christos * Package is automatically padded with uninitialized (NULL) elements
304 1.1 christos * if NumElements is greater than the package list length. Likewise,
305 1.1 christos * Package is truncated if NumElements is less than the list length.
306 1.1 christos */
307 1.1 christos for (i = 0; Arg && (i < ElementCount); i++)
308 1.1 christos {
309 1.1 christos if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
310 1.1 christos {
311 1.3 christos if (!Arg->Common.Node)
312 1.3 christos {
313 1.3 christos /*
314 1.3 christos * This is the case where an expression has returned a value.
315 1.3 christos * The use of expressions (TermArgs) within individual
316 1.3 christos * package elements is not supported by the AML interpreter,
317 1.3 christos * even though the ASL grammar supports it. Example:
318 1.3 christos *
319 1.3 christos * Name (INT1, 0x1234)
320 1.3 christos *
321 1.3 christos * Name (PKG3, Package () {
322 1.3 christos * Add (INT1, 0xAAAA0000)
323 1.3 christos * })
324 1.3 christos *
325 1.3 christos * 1) No known AML interpreter supports this type of construct
326 1.3 christos * 2) This fixes a fault if the construct is encountered
327 1.3 christos */
328 1.3 christos ACPI_EXCEPTION ((AE_INFO, AE_SUPPORT,
329 1.3 christos "Expressions within package elements are not supported"));
330 1.3 christos
331 1.3 christos /* Cleanup the return object, it is not needed */
332 1.3 christos
333 1.3 christos AcpiUtRemoveReference (WalkState->Results->Results.ObjDesc[0]);
334 1.3 christos return_ACPI_STATUS (AE_SUPPORT);
335 1.3 christos }
336 1.3 christos
337 1.1 christos if (Arg->Common.Node->Type == ACPI_TYPE_METHOD)
338 1.1 christos {
339 1.1 christos /*
340 1.1 christos * A method reference "looks" to the parser to be a method
341 1.1 christos * invocation, so we special case it here
342 1.1 christos */
343 1.1 christos Arg->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
344 1.1 christos Status = AcpiDsBuildInternalObject (
345 1.1 christos WalkState, Arg, &ObjDesc->Package.Elements[i]);
346 1.1 christos }
347 1.1 christos else
348 1.1 christos {
349 1.1 christos /* This package element is already built, just get it */
350 1.1 christos
351 1.1 christos ObjDesc->Package.Elements[i] =
352 1.1 christos ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node);
353 1.1 christos }
354 1.1 christos }
355 1.1 christos else
356 1.1 christos {
357 1.1 christos Status = AcpiDsBuildInternalObject (
358 1.1 christos WalkState, Arg, &ObjDesc->Package.Elements[i]);
359 1.1 christos if (Status == AE_NOT_FOUND)
360 1.1 christos {
361 1.1 christos ACPI_ERROR ((AE_INFO, "%-48s", "****DS namepath not found"));
362 1.1 christos }
363 1.1 christos
364 1.2 christos if (!ModuleLevelCode)
365 1.2 christos {
366 1.2 christos /*
367 1.2 christos * Initialize this package element. This function handles the
368 1.2 christos * resolution of named references within the package.
369 1.2 christos * Forward references from module-level code are deferred
370 1.2 christos * until all ACPI tables are loaded.
371 1.2 christos */
372 1.2 christos AcpiDsInitPackageElement (0, ObjDesc->Package.Elements[i],
373 1.2 christos NULL, &ObjDesc->Package.Elements[i]);
374 1.2 christos }
375 1.1 christos }
376 1.1 christos
377 1.1 christos if (*ObjDescPtr)
378 1.1 christos {
379 1.1 christos /* Existing package, get existing reference count */
380 1.1 christos
381 1.1 christos ReferenceCount = (*ObjDescPtr)->Common.ReferenceCount;
382 1.1 christos if (ReferenceCount > 1)
383 1.1 christos {
384 1.1 christos /* Make new element ref count match original ref count */
385 1.1 christos /* TBD: Probably need an AcpiUtAddReferences function */
386 1.1 christos
387 1.1 christos for (Index = 0; Index < ((UINT32) ReferenceCount - 1); Index++)
388 1.1 christos {
389 1.1 christos AcpiUtAddReference ((ObjDesc->Package.Elements[i]));
390 1.1 christos }
391 1.1 christos }
392 1.1 christos }
393 1.1 christos
394 1.1 christos Arg = Arg->Common.Next;
395 1.1 christos }
396 1.1 christos
397 1.1 christos /* Check for match between NumElements and actual length of PackageList */
398 1.1 christos
399 1.1 christos if (Arg)
400 1.1 christos {
401 1.1 christos /*
402 1.1 christos * NumElements was exhausted, but there are remaining elements in
403 1.1 christos * the PackageList. Truncate the package to NumElements.
404 1.1 christos *
405 1.1 christos * Note: technically, this is an error, from ACPI spec: "It is an
406 1.1 christos * error for NumElements to be less than the number of elements in
407 1.1 christos * the PackageList". However, we just print a message and no
408 1.1 christos * exception is returned. This provides compatibility with other
409 1.1 christos * ACPI implementations. Some firmware implementations will alter
410 1.1 christos * the NumElements on the fly, possibly creating this type of
411 1.1 christos * ill-formed package object.
412 1.1 christos */
413 1.1 christos while (Arg)
414 1.1 christos {
415 1.1 christos /*
416 1.1 christos * We must delete any package elements that were created earlier
417 1.1 christos * and are not going to be used because of the package truncation.
418 1.1 christos */
419 1.1 christos if (Arg->Common.Node)
420 1.1 christos {
421 1.1 christos AcpiUtRemoveReference (
422 1.1 christos ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node));
423 1.1 christos Arg->Common.Node = NULL;
424 1.1 christos }
425 1.1 christos
426 1.1 christos /* Find out how many elements there really are */
427 1.1 christos
428 1.1 christos i++;
429 1.1 christos Arg = Arg->Common.Next;
430 1.1 christos }
431 1.1 christos
432 1.1 christos ACPI_INFO ((
433 1.1 christos "Actual Package length (%u) is larger than "
434 1.1 christos "NumElements field (%u), truncated",
435 1.1 christos i, ElementCount));
436 1.1 christos }
437 1.1 christos else if (i < ElementCount)
438 1.1 christos {
439 1.1 christos /*
440 1.1 christos * Arg list (elements) was exhausted, but we did not reach
441 1.1 christos * NumElements count.
442 1.1 christos *
443 1.1 christos * Note: this is not an error, the package is padded out
444 1.2 christos * with NULLs as per the ACPI specification.
445 1.1 christos */
446 1.2 christos ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO,
447 1.2 christos "%s: Package List length (%u) smaller than NumElements "
448 1.1 christos "count (%u), padded with null elements\n",
449 1.2 christos ACPI_GET_FUNCTION_NAME, i, ElementCount));
450 1.2 christos }
451 1.2 christos
452 1.2 christos /* Module-level packages will be resolved later */
453 1.2 christos
454 1.2 christos if (!ModuleLevelCode)
455 1.2 christos {
456 1.2 christos ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
457 1.1 christos }
458 1.1 christos
459 1.1 christos Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
460 1.1 christos return_ACPI_STATUS (Status);
461 1.1 christos }
462 1.1 christos
463 1.1 christos
464 1.1 christos /*******************************************************************************
465 1.1 christos *
466 1.1 christos * FUNCTION: AcpiDsInitPackageElement
467 1.1 christos *
468 1.1 christos * PARAMETERS: ACPI_PKG_CALLBACK
469 1.1 christos *
470 1.1 christos * RETURN: Status
471 1.1 christos *
472 1.1 christos * DESCRIPTION: Resolve a named reference element within a package object
473 1.1 christos *
474 1.1 christos ******************************************************************************/
475 1.1 christos
476 1.1 christos ACPI_STATUS
477 1.1 christos AcpiDsInitPackageElement (
478 1.1 christos UINT8 ObjectType,
479 1.1 christos ACPI_OPERAND_OBJECT *SourceObject,
480 1.1 christos ACPI_GENERIC_STATE *State,
481 1.1 christos void *Context)
482 1.1 christos {
483 1.1 christos ACPI_OPERAND_OBJECT **ElementPtr;
484 1.1 christos
485 1.1 christos
486 1.2 christos ACPI_FUNCTION_TRACE (DsInitPackageElement);
487 1.2 christos
488 1.2 christos
489 1.1 christos if (!SourceObject)
490 1.1 christos {
491 1.2 christos return_ACPI_STATUS (AE_OK);
492 1.1 christos }
493 1.1 christos
494 1.1 christos /*
495 1.1 christos * The following code is a bit of a hack to workaround a (current)
496 1.1 christos * limitation of the ACPI_PKG_CALLBACK interface. We need a pointer
497 1.1 christos * to the location within the element array because a new object
498 1.1 christos * may be created and stored there.
499 1.1 christos */
500 1.1 christos if (Context)
501 1.1 christos {
502 1.1 christos /* A direct call was made to this function */
503 1.1 christos
504 1.1 christos ElementPtr = (ACPI_OPERAND_OBJECT **) Context;
505 1.1 christos }
506 1.1 christos else
507 1.1 christos {
508 1.1 christos /* Call came from AcpiUtWalkPackageTree */
509 1.1 christos
510 1.1 christos ElementPtr = State->Pkg.ThisTargetObj;
511 1.1 christos }
512 1.1 christos
513 1.1 christos /* We are only interested in reference objects/elements */
514 1.1 christos
515 1.1 christos if (SourceObject->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
516 1.1 christos {
517 1.1 christos /* Attempt to resolve the (named) reference to a namespace node */
518 1.1 christos
519 1.1 christos AcpiDsResolvePackageElement (ElementPtr);
520 1.1 christos }
521 1.1 christos else if (SourceObject->Common.Type == ACPI_TYPE_PACKAGE)
522 1.1 christos {
523 1.1 christos SourceObject->Package.Flags |= AOPOBJ_DATA_VALID;
524 1.1 christos }
525 1.1 christos
526 1.2 christos return_ACPI_STATUS (AE_OK);
527 1.1 christos }
528 1.1 christos
529 1.1 christos
530 1.1 christos /*******************************************************************************
531 1.1 christos *
532 1.1 christos * FUNCTION: AcpiDsResolvePackageElement
533 1.1 christos *
534 1.1 christos * PARAMETERS: ElementPtr - Pointer to a reference object
535 1.1 christos *
536 1.1 christos * RETURN: Possible new element is stored to the indirect ElementPtr
537 1.1 christos *
538 1.1 christos * DESCRIPTION: Resolve a package element that is a reference to a named
539 1.1 christos * object.
540 1.1 christos *
541 1.1 christos ******************************************************************************/
542 1.1 christos
543 1.1 christos static void
544 1.1 christos AcpiDsResolvePackageElement (
545 1.1 christos ACPI_OPERAND_OBJECT **ElementPtr)
546 1.1 christos {
547 1.1 christos ACPI_STATUS Status;
548 1.2 christos ACPI_STATUS Status2;
549 1.1 christos ACPI_GENERIC_STATE ScopeInfo;
550 1.1 christos ACPI_OPERAND_OBJECT *Element = *ElementPtr;
551 1.1 christos ACPI_NAMESPACE_NODE *ResolvedNode;
552 1.2 christos ACPI_NAMESPACE_NODE *OriginalNode;
553 1.2 christos char *ExternalPath = __UNCONST("");
554 1.1 christos ACPI_OBJECT_TYPE Type;
555 1.1 christos
556 1.1 christos
557 1.1 christos ACPI_FUNCTION_TRACE (DsResolvePackageElement);
558 1.1 christos
559 1.1 christos
560 1.1 christos /* Check if reference element is already resolved */
561 1.1 christos
562 1.1 christos if (Element->Reference.Resolved)
563 1.1 christos {
564 1.2 christos ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,
565 1.2 christos "%s: Package element is already resolved\n",
566 1.2 christos ACPI_GET_FUNCTION_NAME));
567 1.2 christos
568 1.1 christos return_VOID;
569 1.1 christos }
570 1.1 christos
571 1.1 christos /* Element must be a reference object of correct type */
572 1.1 christos
573 1.1 christos ScopeInfo.Scope.Node = Element->Reference.Node; /* Prefix node */
574 1.1 christos
575 1.2 christos Status = AcpiNsLookup (&ScopeInfo, (char *) Element->Reference.Aml,
576 1.1 christos ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
577 1.1 christos ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
578 1.1 christos NULL, &ResolvedNode);
579 1.1 christos if (ACPI_FAILURE (Status))
580 1.1 christos {
581 1.2 christos if ((Status == AE_NOT_FOUND) && AcpiGbl_IgnorePackageResolutionErrors)
582 1.2 christos {
583 1.2 christos /*
584 1.2 christos * Optionally be silent about the NOT_FOUND case for the referenced
585 1.2 christos * name. Although this is potentially a serious problem,
586 1.2 christos * it can generate a lot of noise/errors on platforms whose
587 1.2 christos * firmware carries around a bunch of unused Package objects.
588 1.2 christos * To disable these errors, set this global to TRUE:
589 1.2 christos * AcpiGbl_IgnorePackageResolutionErrors
590 1.2 christos *
591 1.2 christos * If the AML actually tries to use such a package, the unresolved
592 1.2 christos * element(s) will be replaced with NULL elements.
593 1.2 christos */
594 1.2 christos
595 1.2 christos /* Referenced name not found, set the element to NULL */
596 1.2 christos
597 1.2 christos AcpiUtRemoveReference (*ElementPtr);
598 1.2 christos *ElementPtr = NULL;
599 1.2 christos return_VOID;
600 1.2 christos }
601 1.2 christos
602 1.2 christos Status2 = AcpiNsExternalizeName (ACPI_UINT32_MAX,
603 1.2 christos (char *) Element->Reference.Aml, NULL, &ExternalPath);
604 1.1 christos
605 1.1 christos ACPI_EXCEPTION ((AE_INFO, Status,
606 1.2 christos "While resolving a named reference package element - %s",
607 1.2 christos ExternalPath));
608 1.2 christos if (ACPI_SUCCESS (Status2))
609 1.2 christos {
610 1.2 christos ACPI_FREE (ExternalPath);
611 1.2 christos }
612 1.2 christos
613 1.2 christos /* Could not resolve name, set the element to NULL */
614 1.1 christos
615 1.2 christos AcpiUtRemoveReference (*ElementPtr);
616 1.1 christos *ElementPtr = NULL;
617 1.1 christos return_VOID;
618 1.1 christos }
619 1.1 christos else if (ResolvedNode->Type == ACPI_TYPE_ANY)
620 1.1 christos {
621 1.1 christos /* Named reference not resolved, return a NULL package element */
622 1.1 christos
623 1.1 christos ACPI_ERROR ((AE_INFO,
624 1.1 christos "Could not resolve named package element [%4.4s] in [%4.4s]",
625 1.1 christos ResolvedNode->Name.Ascii, ScopeInfo.Scope.Node->Name.Ascii));
626 1.1 christos *ElementPtr = NULL;
627 1.1 christos return_VOID;
628 1.1 christos }
629 1.1 christos
630 1.1 christos /*
631 1.1 christos * Special handling for Alias objects. We need ResolvedNode to point
632 1.1 christos * to the Alias target. This effectively "resolves" the alias.
633 1.1 christos */
634 1.1 christos if (ResolvedNode->Type == ACPI_TYPE_LOCAL_ALIAS)
635 1.1 christos {
636 1.1 christos ResolvedNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
637 1.1 christos ResolvedNode->Object);
638 1.1 christos }
639 1.1 christos
640 1.1 christos /* Update the reference object */
641 1.1 christos
642 1.1 christos Element->Reference.Resolved = TRUE;
643 1.1 christos Element->Reference.Node = ResolvedNode;
644 1.1 christos Type = Element->Reference.Node->Type;
645 1.1 christos
646 1.1 christos /*
647 1.1 christos * Attempt to resolve the node to a value before we insert it into
648 1.1 christos * the package. If this is a reference to a common data type,
649 1.1 christos * resolve it immediately. According to the ACPI spec, package
650 1.1 christos * elements can only be "data objects" or method references.
651 1.1 christos * Attempt to resolve to an Integer, Buffer, String or Package.
652 1.1 christos * If cannot, return the named reference (for things like Devices,
653 1.1 christos * Methods, etc.) Buffer Fields and Fields will resolve to simple
654 1.1 christos * objects (int/buf/str/pkg).
655 1.1 christos *
656 1.1 christos * NOTE: References to things like Devices, Methods, Mutexes, etc.
657 1.1 christos * will remain as named references. This behavior is not described
658 1.1 christos * in the ACPI spec, but it appears to be an oversight.
659 1.1 christos */
660 1.2 christos OriginalNode = ResolvedNode;
661 1.1 christos Status = AcpiExResolveNodeToValue (&ResolvedNode, NULL);
662 1.1 christos if (ACPI_FAILURE (Status))
663 1.1 christos {
664 1.1 christos return_VOID;
665 1.1 christos }
666 1.1 christos
667 1.1 christos switch (Type)
668 1.1 christos {
669 1.1 christos /*
670 1.1 christos * These object types are a result of named references, so we will
671 1.1 christos * leave them as reference objects. In other words, these types
672 1.1 christos * have no intrinsic "value".
673 1.1 christos */
674 1.1 christos case ACPI_TYPE_DEVICE:
675 1.1 christos case ACPI_TYPE_THERMAL:
676 1.2 christos case ACPI_TYPE_METHOD:
677 1.1 christos break;
678 1.1 christos
679 1.1 christos case ACPI_TYPE_MUTEX:
680 1.1 christos case ACPI_TYPE_POWER:
681 1.1 christos case ACPI_TYPE_PROCESSOR:
682 1.1 christos case ACPI_TYPE_EVENT:
683 1.1 christos case ACPI_TYPE_REGION:
684 1.1 christos
685 1.2 christos /* AcpiExResolveNodeToValue gave these an extra reference */
686 1.2 christos
687 1.2 christos AcpiUtRemoveReference (OriginalNode->Object);
688 1.1 christos break;
689 1.1 christos
690 1.1 christos default:
691 1.1 christos /*
692 1.1 christos * For all other types - the node was resolved to an actual
693 1.2 christos * operand object with a value, return the object. Remove
694 1.2 christos * a reference on the existing object.
695 1.1 christos */
696 1.2 christos AcpiUtRemoveReference (Element);
697 1.1 christos *ElementPtr = (ACPI_OPERAND_OBJECT *) ResolvedNode;
698 1.1 christos break;
699 1.1 christos }
700 1.1 christos
701 1.1 christos return_VOID;
702 1.1 christos }
703