1 /******************************************************************************
3 * Module Name: dspkginit - Completion of deferred package initialization
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2018, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
51 #define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME("dspkginit")
54 /* Local prototypes */
56 acpi_ds_resolve_package_element(union acpi_operand_object
**element
);
58 /*******************************************************************************
60 * FUNCTION: acpi_ds_build_internal_package_obj
62 * PARAMETERS: walk_state - Current walk state
63 * op - Parser object to be translated
64 * element_count - Number of elements in the package - this is
65 * the num_elements argument to Package()
66 * obj_desc_ptr - Where the ACPI internal object is returned
70 * DESCRIPTION: Translate a parser Op package object to the equivalent
73 * NOTE: The number of elements in the package will be always be the num_elements
74 * count, regardless of the number of elements in the package list. If
75 * num_elements is smaller, only that many package list elements are used.
76 * if num_elements is larger, the Package object is padded out with
77 * objects of type Uninitialized (as per ACPI spec.)
79 * Even though the ASL compilers do not allow num_elements to be smaller
80 * than the Package list length (for the fixed length package opcode), some
81 * BIOS code modifies the AML on the fly to adjust the num_elements, and
82 * this code compensates for that. This also provides compatibility with
83 * other AML interpreters.
85 ******************************************************************************/
88 acpi_ds_build_internal_package_obj(struct acpi_walk_state
*walk_state
,
89 union acpi_parse_object
*op
,
91 union acpi_operand_object
**obj_desc_ptr
)
93 union acpi_parse_object
*arg
;
94 union acpi_parse_object
*parent
;
95 union acpi_operand_object
*obj_desc
= NULL
;
96 acpi_status status
= AE_OK
;
101 ACPI_FUNCTION_TRACE(ds_build_internal_package_obj
);
103 /* Find the parent of a possibly nested package */
105 parent
= op
->common
.parent
;
106 while ((parent
->common
.aml_opcode
== AML_PACKAGE_OP
) ||
107 (parent
->common
.aml_opcode
== AML_VARIABLE_PACKAGE_OP
)) {
108 parent
= parent
->common
.parent
;
112 * If we are evaluating a Named package object of the form:
113 * Name (xxxx, Package)
114 * the package object already exists, otherwise it must be created.
116 obj_desc
= *obj_desc_ptr
;
118 obj_desc
= acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE
);
119 *obj_desc_ptr
= obj_desc
;
121 return_ACPI_STATUS(AE_NO_MEMORY
);
124 obj_desc
->package
.node
= parent
->common
.node
;
127 if (obj_desc
->package
.flags
& AOPOBJ_DATA_VALID
) { /* Just in case */
128 return_ACPI_STATUS(AE_OK
);
132 * Allocate the element array (array of pointers to the individual
133 * objects) based on the num_elements parameter. Add an extra pointer slot
134 * so that the list is always null terminated.
136 obj_desc
->package
.elements
= ACPI_ALLOCATE_ZEROED(((acpi_size
)
138 1) * sizeof(void *));
140 if (!obj_desc
->package
.elements
) {
141 acpi_ut_delete_object_desc(obj_desc
);
142 return_ACPI_STATUS(AE_NO_MEMORY
);
145 obj_desc
->package
.count
= element_count
;
146 arg
= op
->common
.value
.arg
;
147 arg
= arg
->common
.next
;
150 obj_desc
->package
.flags
|= AOPOBJ_DATA_VALID
;
154 * Initialize the elements of the package, up to the num_elements count.
155 * Package is automatically padded with uninitialized (NULL) elements
156 * if num_elements is greater than the package list length. Likewise,
157 * Package is truncated if num_elements is less than the list length.
159 for (i
= 0; arg
&& (i
< element_count
); i
++) {
160 if (arg
->common
.aml_opcode
== AML_INT_RETURN_VALUE_OP
) {
161 if (arg
->common
.node
->type
== ACPI_TYPE_METHOD
) {
163 * A method reference "looks" to the parser to be a method
164 * invocation, so we special case it here
166 arg
->common
.aml_opcode
= AML_INT_NAMEPATH_OP
;
168 acpi_ds_build_internal_object(walk_state
,
174 /* This package element is already built, just get it */
176 obj_desc
->package
.elements
[i
] =
177 ACPI_CAST_PTR(union acpi_operand_object
,
182 acpi_ds_build_internal_object(walk_state
, arg
,
185 if (status
== AE_NOT_FOUND
) {
186 ACPI_ERROR((AE_INFO
, "%-48s",
187 "****DS namepath not found"));
191 * Initialize this package element. This function handles the
192 * resolution of named references within the package.
194 acpi_ds_init_package_element(0,
203 /* Existing package, get existing reference count */
206 (*obj_desc_ptr
)->common
.reference_count
;
207 if (reference_count
> 1) {
209 /* Make new element ref count match original ref count */
210 /* TBD: Probably need an acpi_ut_add_references function */
213 index
< ((u32
)reference_count
- 1);
215 acpi_ut_add_reference((obj_desc
->
222 arg
= arg
->common
.next
;
225 /* Check for match between num_elements and actual length of package_list */
229 * num_elements was exhausted, but there are remaining elements in
230 * the package_list. Truncate the package to num_elements.
232 * Note: technically, this is an error, from ACPI spec: "It is an
233 * error for NumElements to be less than the number of elements in
234 * the PackageList". However, we just print a message and no
235 * exception is returned. This provides compatibility with other
236 * ACPI implementations. Some firmware implementations will alter
237 * the num_elements on the fly, possibly creating this type of
238 * ill-formed package object.
242 * We must delete any package elements that were created earlier
243 * and are not going to be used because of the package truncation.
245 if (arg
->common
.node
) {
246 acpi_ut_remove_reference(ACPI_CAST_PTR
250 arg
->common
.node
= NULL
;
253 /* Find out how many elements there really are */
256 arg
= arg
->common
.next
;
259 ACPI_INFO(("Actual Package length (%u) is larger than "
260 "NumElements field (%u), truncated",
262 } else if (i
< element_count
) {
264 * Arg list (elements) was exhausted, but we did not reach
265 * num_elements count.
267 * Note: this is not an error, the package is padded out
270 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
271 "Package List length (%u) smaller than NumElements "
272 "count (%u), padded with null elements\n",
276 obj_desc
->package
.flags
|= AOPOBJ_DATA_VALID
;
277 op
->common
.node
= ACPI_CAST_PTR(struct acpi_namespace_node
, obj_desc
);
278 return_ACPI_STATUS(status
);
281 /*******************************************************************************
283 * FUNCTION: acpi_ds_init_package_element
285 * PARAMETERS: acpi_pkg_callback
289 * DESCRIPTION: Resolve a named reference element within a package object
291 ******************************************************************************/
294 acpi_ds_init_package_element(u8 object_type
,
295 union acpi_operand_object
*source_object
,
296 union acpi_generic_state
*state
, void *context
)
298 union acpi_operand_object
**element_ptr
;
300 ACPI_FUNCTION_TRACE(ds_init_package_element
);
302 if (!source_object
) {
303 return_ACPI_STATUS(AE_OK
);
307 * The following code is a bit of a hack to workaround a (current)
308 * limitation of the acpi_pkg_callback interface. We need a pointer
309 * to the location within the element array because a new object
310 * may be created and stored there.
314 /* A direct call was made to this function */
316 element_ptr
= (union acpi_operand_object
**)context
;
318 /* Call came from acpi_ut_walk_package_tree */
320 element_ptr
= state
->pkg
.this_target_obj
;
323 /* We are only interested in reference objects/elements */
325 if (source_object
->common
.type
== ACPI_TYPE_LOCAL_REFERENCE
) {
327 /* Attempt to resolve the (named) reference to a namespace node */
329 acpi_ds_resolve_package_element(element_ptr
);
330 } else if (source_object
->common
.type
== ACPI_TYPE_PACKAGE
) {
331 source_object
->package
.flags
|= AOPOBJ_DATA_VALID
;
334 return_ACPI_STATUS(AE_OK
);
337 /*******************************************************************************
339 * FUNCTION: acpi_ds_resolve_package_element
341 * PARAMETERS: element_ptr - Pointer to a reference object
343 * RETURN: Possible new element is stored to the indirect element_ptr
345 * DESCRIPTION: Resolve a package element that is a reference to a named
348 ******************************************************************************/
351 acpi_ds_resolve_package_element(union acpi_operand_object
**element_ptr
)
354 union acpi_generic_state scope_info
;
355 union acpi_operand_object
*element
= *element_ptr
;
356 struct acpi_namespace_node
*resolved_node
;
357 struct acpi_namespace_node
*original_node
;
358 char *external_path
= NULL
;
359 acpi_object_type type
;
361 ACPI_FUNCTION_TRACE(ds_resolve_package_element
);
363 /* Check if reference element is already resolved */
365 if (element
->reference
.resolved
) {
369 /* Element must be a reference object of correct type */
371 scope_info
.scope
.node
= element
->reference
.node
; /* Prefix node */
373 status
= acpi_ns_lookup(&scope_info
, (char *)element
->reference
.aml
, /* Pointer to AML path */
374 ACPI_TYPE_ANY
, ACPI_IMODE_EXECUTE
,
375 ACPI_NS_SEARCH_PARENT
| ACPI_NS_DONT_OPEN_SCOPE
,
376 NULL
, &resolved_node
);
377 if (ACPI_FAILURE(status
)) {
378 status
= acpi_ns_externalize_name(ACPI_UINT32_MAX
,
379 (char *)element
->reference
.
380 aml
, NULL
, &external_path
);
382 ACPI_EXCEPTION((AE_INFO
, status
,
383 "Could not find/resolve named package element: %s",
386 ACPI_FREE(external_path
);
389 } else if (resolved_node
->type
== ACPI_TYPE_ANY
) {
391 /* Named reference not resolved, return a NULL package element */
394 "Could not resolve named package element [%4.4s] in [%4.4s]",
395 resolved_node
->name
.ascii
,
396 scope_info
.scope
.node
->name
.ascii
));
401 else if (resolved_node
->flags
& ANOBJ_TEMPORARY
) {
403 * A temporary node found here indicates that the reference is
404 * to a node that was created within this method. We are not
405 * going to allow it (especially if the package is returned
406 * from the method) -- the temporary node will be deleted out
407 * from under the method. (05/2017).
410 "Package element refers to a temporary name [%4.4s], "
411 "inserting a NULL element",
412 resolved_node
->name
.ascii
));
419 * Special handling for Alias objects. We need resolved_node to point
420 * to the Alias target. This effectively "resolves" the alias.
422 if (resolved_node
->type
== ACPI_TYPE_LOCAL_ALIAS
) {
423 resolved_node
= ACPI_CAST_PTR(struct acpi_namespace_node
,
424 resolved_node
->object
);
427 /* Update the reference object */
429 element
->reference
.resolved
= TRUE
;
430 element
->reference
.node
= resolved_node
;
431 type
= element
->reference
.node
->type
;
434 * Attempt to resolve the node to a value before we insert it into
435 * the package. If this is a reference to a common data type,
436 * resolve it immediately. According to the ACPI spec, package
437 * elements can only be "data objects" or method references.
438 * Attempt to resolve to an Integer, Buffer, String or Package.
439 * If cannot, return the named reference (for things like Devices,
440 * Methods, etc.) Buffer Fields and Fields will resolve to simple
441 * objects (int/buf/str/pkg).
443 * NOTE: References to things like Devices, Methods, Mutexes, etc.
444 * will remain as named references. This behavior is not described
445 * in the ACPI spec, but it appears to be an oversight.
447 original_node
= resolved_node
;
448 status
= acpi_ex_resolve_node_to_value(&resolved_node
, NULL
);
449 if (ACPI_FAILURE(status
)) {
453 /* TBD - alias support */
455 * Special handling for Alias objects. We need to setup the type
456 * and the Op->Common.Node to point to the Alias target. Note,
457 * Alias has at most one level of indirection internally.
459 type
= op
->common
.node
->type
;
460 if (type
== ACPI_TYPE_LOCAL_ALIAS
) {
461 type
= obj_desc
->common
.type
;
462 op
->common
.node
= ACPI_CAST_PTR(struct acpi_namespace_node
,
463 op
->common
.node
->object
);
469 * These object types are a result of named references, so we will
470 * leave them as reference objects. In other words, these types
471 * have no intrinsic "value".
473 case ACPI_TYPE_DEVICE
:
474 case ACPI_TYPE_THERMAL
:
475 case ACPI_TYPE_METHOD
:
478 case ACPI_TYPE_MUTEX
:
479 case ACPI_TYPE_POWER
:
480 case ACPI_TYPE_PROCESSOR
:
481 case ACPI_TYPE_EVENT
:
482 case ACPI_TYPE_REGION
:
484 /* acpi_ex_resolve_node_to_value gave these an extra reference */
486 acpi_ut_remove_reference(original_node
->object
);
491 * For all other types - the node was resolved to an actual
492 * operand object with a value, return the object. Remove
493 * a reference on the existing object.
495 acpi_ut_remove_reference(element
);
496 *element_ptr
= (union acpi_operand_object
*)resolved_node
;