ACPICA 20050408 from Bob Moore
[linux-2.6.git] / drivers / acpi / executer / exresolv.c
blob3de45672379a301cfab377b35cd46cf928187058
2 /******************************************************************************
4 * Module Name: exresolv - AML Interpreter object resolution
6 *****************************************************************************/
8 /*
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
14 * are met:
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.
31 * NO WARRANTY
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 */
59 static acpi_status
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 *)
71 * or an acpi_handle.
72 * walk_state - Current method state
74 * RETURN: Status
76 * DESCRIPTION: Convert Reference objects to values
78 ******************************************************************************/
80 acpi_status
81 acpi_ex_resolve_to_value (
82 union acpi_operand_object **stack_ptr,
83 struct acpi_walk_state *walk_state)
85 acpi_status status;
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);
107 if (!*stack_ptr) {
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),
120 walk_state);
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
138 * RETURN: Status
140 * DESCRIPTION: Retrieve the value from an internal object. The Reference type
141 * uses the associated AML opcode to determine the value.
143 ******************************************************************************/
145 static acpi_status
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;
152 void *temp_node;
153 union acpi_operand_object *obj_desc;
154 u16 opcode;
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;
169 switch (opcode) {
170 case AML_NAME_OP:
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;
185 break;
188 case AML_LOCAL_OP:
189 case AML_ARG_OP:
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;
210 break;
213 case AML_INDEX_OP:
215 switch (stack_desc->reference.target_type) {
216 case ACPI_TYPE_BUFFER_FIELD:
218 /* Just return - leave the Reference on the stack */
219 break;
222 case ACPI_TYPE_PACKAGE:
224 obj_desc = *stack_desc->reference.where;
225 if (obj_desc) {
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;
235 else {
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",
242 stack_desc));
243 status = AE_AML_UNINITIALIZED_ELEMENT;
245 break;
248 default:
250 /* Invalid reference object */
252 ACPI_REPORT_ERROR ((
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;
256 break;
258 break;
261 case AML_REF_OF_OP:
262 case AML_DEBUG_OP:
263 case AML_LOAD_OP:
265 /* Just leave the object as-is */
267 break;
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);
276 break;
278 default:
280 ACPI_REPORT_ERROR ((
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;
284 break;
286 break;
289 case ACPI_TYPE_BUFFER:
291 status = acpi_ds_get_buffer_arguments (stack_desc);
292 break;
295 case ACPI_TYPE_PACKAGE:
297 status = acpi_ds_get_package_arguments (stack_desc);
298 break;
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;
313 break;
315 default:
316 break;
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
332 * RETURN: Status
334 * DESCRIPTION: Return the base object and type. Traverse a reference list if
335 * necessary to get to the base object.
337 ******************************************************************************/
339 acpi_status
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;
349 acpi_status status;
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;
360 break;
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);
372 break;
374 default:
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) {
381 goto exit;
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) {
392 case AML_REF_OF_OP:
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) {
401 ACPI_REPORT_ERROR ((
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);
410 if (!obj_desc) {
411 /* No object, use the NS node type */
413 type = acpi_ns_get_type (node);
414 goto exit;
417 /* Check for circular references */
419 if (obj_desc == operand) {
420 return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE);
422 break;
425 case AML_INDEX_OP:
427 /* Get the type of this reference (index into another object) */
429 type = obj_desc->reference.target_type;
430 if (type != ACPI_TYPE_PACKAGE) {
431 goto exit;
435 * The main object is a package, we want to get the type
436 * of the individual package element that is referenced by
437 * the index.
439 * This could of course in turn be another reference object.
441 obj_desc = *(obj_desc->reference.where);
442 if (!obj_desc) {
443 /* NULL package elements are allowed */
445 type = 0; /* Uninitialized */
446 goto exit;
448 break;
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) {
460 ACPI_REPORT_ERROR ((
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);
469 if (!obj_desc) {
470 /* No object, use the NS node type */
472 type = acpi_ns_get_type (node);
473 goto exit;
476 /* Check for circular references */
478 if (obj_desc == operand) {
479 return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE);
481 break;
484 case AML_LOCAL_OP:
485 case AML_ARG_OP:
487 if (return_desc) {
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);
495 else {
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);
503 if (!obj_desc) {
504 type = ACPI_TYPE_ANY;
505 goto exit;
508 break;
511 case AML_DEBUG_OP:
513 /* The Debug Object is of type "debug_object" */
515 type = ACPI_TYPE_DEBUG_OBJECT;
516 goto exit;
519 default:
521 ACPI_REPORT_ERROR ((
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);
535 exit:
536 /* Convert internal types to external types */
538 switch (type) {
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;
544 break;
546 case ACPI_TYPE_LOCAL_SCOPE:
548 /* Per ACPI Specification, Scope is untyped */
550 type = ACPI_TYPE_ANY;
551 break;
553 default:
554 /* No change to Type required */
555 break;
558 *return_type = type;
559 if (return_desc) {
560 *return_desc = obj_desc;
562 return_ACPI_STATUS (AE_OK);