2 /******************************************************************************
4 * Module Name: exresolv - AML Interpreter object resolution
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2005, R. Byron Moore
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
46 #include <acpi/acpi.h>
47 #include <acpi/amlcode.h>
48 #include <acpi/acdispat.h>
49 #include <acpi/acinterp.h>
50 #include <acpi/acnamesp.h>
51 #include <acpi/acparser.h>
54 #define _COMPONENT ACPI_EXECUTER
55 ACPI_MODULE_NAME ("exresolv")
57 /* Local prototypes */
60 acpi_ex_resolve_object_to_value (
61 union acpi_operand_object
**stack_ptr
,
62 struct acpi_walk_state
*walk_state
);
65 /*******************************************************************************
67 * FUNCTION: acpi_ex_resolve_to_value
69 * PARAMETERS: **stack_ptr - Points to entry on obj_stack, which can
70 * be either an (union acpi_operand_object *)
72 * walk_state - Current method state
76 * DESCRIPTION: Convert Reference objects to values
78 ******************************************************************************/
81 acpi_ex_resolve_to_value (
82 union acpi_operand_object
**stack_ptr
,
83 struct acpi_walk_state
*walk_state
)
88 ACPI_FUNCTION_TRACE_PTR ("ex_resolve_to_value", stack_ptr
);
91 if (!stack_ptr
|| !*stack_ptr
) {
92 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Internal - null pointer\n"));
93 return_ACPI_STATUS (AE_AML_NO_OPERAND
);
97 * The entity pointed to by the stack_ptr can be either
98 * 1) A valid union acpi_operand_object, or
99 * 2) A struct acpi_namespace_node (named_obj)
101 if (ACPI_GET_DESCRIPTOR_TYPE (*stack_ptr
) == ACPI_DESC_TYPE_OPERAND
) {
102 status
= acpi_ex_resolve_object_to_value (stack_ptr
, walk_state
);
103 if (ACPI_FAILURE (status
)) {
104 return_ACPI_STATUS (status
);
108 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Internal - null pointer\n"));
109 return_ACPI_STATUS (AE_AML_NO_OPERAND
);
114 * Object on the stack may have changed if acpi_ex_resolve_object_to_value()
115 * was called (i.e., we can't use an _else_ here.)
117 if (ACPI_GET_DESCRIPTOR_TYPE (*stack_ptr
) == ACPI_DESC_TYPE_NAMED
) {
118 status
= acpi_ex_resolve_node_to_value (
119 ACPI_CAST_INDIRECT_PTR (struct acpi_namespace_node
, stack_ptr
),
121 if (ACPI_FAILURE (status
)) {
122 return_ACPI_STATUS (status
);
126 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Resolved object %p\n", *stack_ptr
));
127 return_ACPI_STATUS (AE_OK
);
131 /*******************************************************************************
133 * FUNCTION: acpi_ex_resolve_object_to_value
135 * PARAMETERS: stack_ptr - Pointer to an internal object
136 * walk_state - Current method state
140 * DESCRIPTION: Retrieve the value from an internal object. The Reference type
141 * uses the associated AML opcode to determine the value.
143 ******************************************************************************/
146 acpi_ex_resolve_object_to_value (
147 union acpi_operand_object
**stack_ptr
,
148 struct acpi_walk_state
*walk_state
)
150 acpi_status status
= AE_OK
;
151 union acpi_operand_object
*stack_desc
;
153 union acpi_operand_object
*obj_desc
;
157 ACPI_FUNCTION_TRACE ("ex_resolve_object_to_value");
160 stack_desc
= *stack_ptr
;
162 /* This is an union acpi_operand_object */
164 switch (ACPI_GET_OBJECT_TYPE (stack_desc
)) {
165 case ACPI_TYPE_LOCAL_REFERENCE
:
167 opcode
= stack_desc
->reference
.opcode
;
173 * Convert name reference to a namespace node
174 * Then, acpi_ex_resolve_node_to_value can be used to get the value
176 temp_node
= stack_desc
->reference
.object
;
178 /* Delete the Reference Object */
180 acpi_ut_remove_reference (stack_desc
);
182 /* Return the namespace node */
184 (*stack_ptr
) = temp_node
;
192 * Get the local from the method's state info
193 * Note: this increments the local's object reference count
195 status
= acpi_ds_method_data_get_value (opcode
,
196 stack_desc
->reference
.offset
, walk_state
, &obj_desc
);
197 if (ACPI_FAILURE (status
)) {
198 return_ACPI_STATUS (status
);
201 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "[Arg/Local %X] value_obj is %p\n",
202 stack_desc
->reference
.offset
, obj_desc
));
205 * Now we can delete the original Reference Object and
206 * replace it with the resolved value
208 acpi_ut_remove_reference (stack_desc
);
209 *stack_ptr
= obj_desc
;
215 switch (stack_desc
->reference
.target_type
) {
216 case ACPI_TYPE_BUFFER_FIELD
:
218 /* Just return - leave the Reference on the stack */
222 case ACPI_TYPE_PACKAGE
:
224 obj_desc
= *stack_desc
->reference
.where
;
227 * Valid obj descriptor, copy pointer to return value
228 * (i.e., dereference the package index)
229 * Delete the ref object, increment the returned object
231 acpi_ut_remove_reference (stack_desc
);
232 acpi_ut_add_reference (obj_desc
);
233 *stack_ptr
= obj_desc
;
237 * A NULL object descriptor means an unitialized element of
238 * the package, can't dereference it
240 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
241 "Attempt to deref an Index to NULL pkg element Idx=%p\n",
243 status
= AE_AML_UNINITIALIZED_ELEMENT
;
250 /* Invalid reference object */
253 "During resolve, Unknown target_type %X in Index/Reference obj %p\n",
254 stack_desc
->reference
.target_type
, stack_desc
));
255 status
= AE_AML_INTERNAL
;
265 /* Just leave the object as-is */
269 case AML_INT_NAMEPATH_OP
: /* Reference to a named object */
271 /* Get the object pointed to by the namespace node */
273 *stack_ptr
= (stack_desc
->reference
.node
)->object
;
274 acpi_ut_add_reference (*stack_ptr
);
275 acpi_ut_remove_reference (stack_desc
);
281 "During resolve, Unknown Reference opcode %X (%s) in %p\n",
282 opcode
, acpi_ps_get_opcode_name (opcode
), stack_desc
));
283 status
= AE_AML_INTERNAL
;
289 case ACPI_TYPE_BUFFER
:
291 status
= acpi_ds_get_buffer_arguments (stack_desc
);
295 case ACPI_TYPE_PACKAGE
:
297 status
= acpi_ds_get_package_arguments (stack_desc
);
301 /* These cases may never happen here, but just in case.. */
303 case ACPI_TYPE_BUFFER_FIELD
:
304 case ACPI_TYPE_LOCAL_REGION_FIELD
:
305 case ACPI_TYPE_LOCAL_BANK_FIELD
:
306 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
308 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "field_read source_desc=%p Type=%X\n",
309 stack_desc
, ACPI_GET_OBJECT_TYPE (stack_desc
)));
311 status
= acpi_ex_read_data_from_field (walk_state
, stack_desc
, &obj_desc
);
312 *stack_ptr
= (void *) obj_desc
;
319 return_ACPI_STATUS (status
);
323 /*******************************************************************************
325 * FUNCTION: acpi_ex_resolve_multiple
327 * PARAMETERS: walk_state - Current state (contains AML opcode)
328 * Operand - Starting point for resolution
329 * return_type - Where the object type is returned
330 * return_desc - Where the resolved object is returned
334 * DESCRIPTION: Return the base object and type. Traverse a reference list if
335 * necessary to get to the base object.
337 ******************************************************************************/
340 acpi_ex_resolve_multiple (
341 struct acpi_walk_state
*walk_state
,
342 union acpi_operand_object
*operand
,
343 acpi_object_type
*return_type
,
344 union acpi_operand_object
**return_desc
)
346 union acpi_operand_object
*obj_desc
= (void *) operand
;
347 struct acpi_namespace_node
*node
;
348 acpi_object_type type
;
352 ACPI_FUNCTION_TRACE ("acpi_ex_resolve_multiple");
355 /* Operand can be either a namespace node or an operand descriptor */
357 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc
)) {
358 case ACPI_DESC_TYPE_OPERAND
:
359 type
= obj_desc
->common
.type
;
362 case ACPI_DESC_TYPE_NAMED
:
363 type
= ((struct acpi_namespace_node
*) obj_desc
)->type
;
364 obj_desc
= acpi_ns_get_attached_object ((struct acpi_namespace_node
*) obj_desc
);
366 /* If we had an Alias node, use the attached object for type info */
368 if (type
== ACPI_TYPE_LOCAL_ALIAS
) {
369 type
= ((struct acpi_namespace_node
*) obj_desc
)->type
;
370 obj_desc
= acpi_ns_get_attached_object ((struct acpi_namespace_node
*) obj_desc
);
375 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
378 /* If type is anything other than a reference, we are done */
380 if (type
!= ACPI_TYPE_LOCAL_REFERENCE
) {
385 * For reference objects created via the ref_of or Index operators,
386 * we need to get to the base object (as per the ACPI specification
387 * of the object_type and size_of operators). This means traversing
388 * the list of possibly many nested references.
390 while (ACPI_GET_OBJECT_TYPE (obj_desc
) == ACPI_TYPE_LOCAL_REFERENCE
) {
391 switch (obj_desc
->reference
.opcode
) {
394 /* Dereference the reference pointer */
396 node
= obj_desc
->reference
.object
;
398 /* All "References" point to a NS node */
400 if (ACPI_GET_DESCRIPTOR_TYPE (node
) != ACPI_DESC_TYPE_NAMED
) {
402 "acpi_ex_resolve_multiple: Not a NS node %p [%s]\n",
403 node
, acpi_ut_get_descriptor_name (node
)));
404 return_ACPI_STATUS (AE_AML_INTERNAL
);
407 /* Get the attached object */
409 obj_desc
= acpi_ns_get_attached_object (node
);
411 /* No object, use the NS node type */
413 type
= acpi_ns_get_type (node
);
417 /* Check for circular references */
419 if (obj_desc
== operand
) {
420 return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE
);
427 /* Get the type of this reference (index into another object) */
429 type
= obj_desc
->reference
.target_type
;
430 if (type
!= ACPI_TYPE_PACKAGE
) {
435 * The main object is a package, we want to get the type
436 * of the individual package element that is referenced by
439 * This could of course in turn be another reference object.
441 obj_desc
= *(obj_desc
->reference
.where
);
443 /* NULL package elements are allowed */
445 type
= 0; /* Uninitialized */
451 case AML_INT_NAMEPATH_OP
:
453 /* Dereference the reference pointer */
455 node
= obj_desc
->reference
.node
;
457 /* All "References" point to a NS node */
459 if (ACPI_GET_DESCRIPTOR_TYPE (node
) != ACPI_DESC_TYPE_NAMED
) {
461 "acpi_ex_resolve_multiple: Not a NS node %p [%s]\n",
462 node
, acpi_ut_get_descriptor_name (node
)));
463 return_ACPI_STATUS (AE_AML_INTERNAL
);
466 /* Get the attached object */
468 obj_desc
= acpi_ns_get_attached_object (node
);
470 /* No object, use the NS node type */
472 type
= acpi_ns_get_type (node
);
476 /* Check for circular references */
478 if (obj_desc
== operand
) {
479 return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE
);
488 status
= acpi_ds_method_data_get_value (obj_desc
->reference
.opcode
,
489 obj_desc
->reference
.offset
, walk_state
, &obj_desc
);
490 if (ACPI_FAILURE (status
)) {
491 return_ACPI_STATUS (status
);
493 acpi_ut_remove_reference (obj_desc
);
496 status
= acpi_ds_method_data_get_node (obj_desc
->reference
.opcode
,
497 obj_desc
->reference
.offset
, walk_state
, &node
);
498 if (ACPI_FAILURE (status
)) {
499 return_ACPI_STATUS (status
);
502 obj_desc
= acpi_ns_get_attached_object (node
);
504 type
= ACPI_TYPE_ANY
;
513 /* The Debug Object is of type "debug_object" */
515 type
= ACPI_TYPE_DEBUG_OBJECT
;
522 "acpi_ex_resolve_multiple: Unknown Reference subtype %X\n",
523 obj_desc
->reference
.opcode
));
524 return_ACPI_STATUS (AE_AML_INTERNAL
);
529 * Now we are guaranteed to have an object that has not been created
530 * via the ref_of or Index operators.
532 type
= ACPI_GET_OBJECT_TYPE (obj_desc
);
536 /* Convert internal types to external types */
539 case ACPI_TYPE_LOCAL_REGION_FIELD
:
540 case ACPI_TYPE_LOCAL_BANK_FIELD
:
541 case ACPI_TYPE_LOCAL_INDEX_FIELD
:
543 type
= ACPI_TYPE_FIELD_UNIT
;
546 case ACPI_TYPE_LOCAL_SCOPE
:
548 /* Per ACPI Specification, Scope is untyped */
550 type
= ACPI_TYPE_ANY
;
554 /* No change to Type required */
560 *return_desc
= obj_desc
;
562 return_ACPI_STATUS (AE_OK
);