initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / acpi / executer / exresolv.c
blob504d53f4a7e66b6a31827e456d1870a975b59e59
2 /******************************************************************************
4 * Module Name: exresolv - AML Interpreter object resolution
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2004, 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")
58 /*******************************************************************************
60 * FUNCTION: acpi_ex_resolve_to_value
62 * PARAMETERS: **stack_ptr - Points to entry on obj_stack, which can
63 * be either an (union acpi_operand_object *)
64 * or an acpi_handle.
65 * walk_state - Current method state
67 * RETURN: Status
69 * DESCRIPTION: Convert Reference objects to values
71 ******************************************************************************/
73 acpi_status
74 acpi_ex_resolve_to_value (
75 union acpi_operand_object **stack_ptr,
76 struct acpi_walk_state *walk_state)
78 acpi_status status;
81 ACPI_FUNCTION_TRACE_PTR ("ex_resolve_to_value", stack_ptr);
84 if (!stack_ptr || !*stack_ptr) {
85 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Internal - null pointer\n"));
86 return_ACPI_STATUS (AE_AML_NO_OPERAND);
90 * The entity pointed to by the stack_ptr can be either
91 * 1) A valid union acpi_operand_object, or
92 * 2) A struct acpi_namespace_node (named_obj)
94 if (ACPI_GET_DESCRIPTOR_TYPE (*stack_ptr) == ACPI_DESC_TYPE_OPERAND) {
95 status = acpi_ex_resolve_object_to_value (stack_ptr, walk_state);
96 if (ACPI_FAILURE (status)) {
97 return_ACPI_STATUS (status);
102 * Object on the stack may have changed if acpi_ex_resolve_object_to_value()
103 * was called (i.e., we can't use an _else_ here.)
105 if (ACPI_GET_DESCRIPTOR_TYPE (*stack_ptr) == ACPI_DESC_TYPE_NAMED) {
106 status = acpi_ex_resolve_node_to_value (
107 ACPI_CAST_INDIRECT_PTR (struct acpi_namespace_node, stack_ptr),
108 walk_state);
109 if (ACPI_FAILURE (status)) {
110 return_ACPI_STATUS (status);
114 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Resolved object %p\n", *stack_ptr));
115 return_ACPI_STATUS (AE_OK);
119 /*******************************************************************************
121 * FUNCTION: acpi_ex_resolve_object_to_value
123 * PARAMETERS: stack_ptr - Pointer to a stack location that contains a
124 * ptr to an internal object.
125 * walk_state - Current method state
127 * RETURN: Status
129 * DESCRIPTION: Retrieve the value from an internal object. The Reference type
130 * uses the associated AML opcode to determine the value.
132 ******************************************************************************/
134 acpi_status
135 acpi_ex_resolve_object_to_value (
136 union acpi_operand_object **stack_ptr,
137 struct acpi_walk_state *walk_state)
139 acpi_status status = AE_OK;
140 union acpi_operand_object *stack_desc;
141 void *temp_node;
142 union acpi_operand_object *obj_desc;
143 u16 opcode;
146 ACPI_FUNCTION_TRACE ("ex_resolve_object_to_value");
149 stack_desc = *stack_ptr;
151 /* This is an union acpi_operand_object */
153 switch (ACPI_GET_OBJECT_TYPE (stack_desc)) {
154 case ACPI_TYPE_LOCAL_REFERENCE:
156 opcode = stack_desc->reference.opcode;
158 switch (opcode) {
159 case AML_NAME_OP:
162 * Convert indirect name ptr to a direct name ptr.
163 * Then, acpi_ex_resolve_node_to_value can be used to get the value
165 temp_node = stack_desc->reference.object;
167 /* Delete the Reference Object */
169 acpi_ut_remove_reference (stack_desc);
171 /* Put direct name pointer onto stack and exit */
173 (*stack_ptr) = temp_node;
174 break;
177 case AML_LOCAL_OP:
178 case AML_ARG_OP:
181 * Get the local from the method's state info
182 * Note: this increments the local's object reference count
184 status = acpi_ds_method_data_get_value (opcode,
185 stack_desc->reference.offset, walk_state, &obj_desc);
186 if (ACPI_FAILURE (status)) {
187 return_ACPI_STATUS (status);
190 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Arg/Local %X] value_obj is %p\n",
191 stack_desc->reference.offset, obj_desc));
194 * Now we can delete the original Reference Object and
195 * replace it with the resolved value
197 acpi_ut_remove_reference (stack_desc);
198 *stack_ptr = obj_desc;
199 break;
202 case AML_INDEX_OP:
204 switch (stack_desc->reference.target_type) {
205 case ACPI_TYPE_BUFFER_FIELD:
207 /* Just return - leave the Reference on the stack */
208 break;
211 case ACPI_TYPE_PACKAGE:
213 obj_desc = *stack_desc->reference.where;
214 if (obj_desc) {
216 * Valid obj descriptor, copy pointer to return value
217 * (i.e., dereference the package index)
218 * Delete the ref object, increment the returned object
220 acpi_ut_remove_reference (stack_desc);
221 acpi_ut_add_reference (obj_desc);
222 *stack_ptr = obj_desc;
224 else {
226 * A NULL object descriptor means an unitialized element of
227 * the package, can't dereference it
229 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
230 "Attempt to deref an Index to NULL pkg element Idx=%p\n",
231 stack_desc));
232 status = AE_AML_UNINITIALIZED_ELEMENT;
234 break;
237 default:
239 /* Invalid reference object */
241 ACPI_REPORT_ERROR ((
242 "During resolve, Unknown target_type %X in Index/Reference obj %p\n",
243 stack_desc->reference.target_type, stack_desc));
244 status = AE_AML_INTERNAL;
245 break;
247 break;
250 case AML_REF_OF_OP:
251 case AML_DEBUG_OP:
252 case AML_LOAD_OP:
254 /* Just leave the object as-is */
256 break;
259 default:
261 ACPI_REPORT_ERROR (("During resolve, Unknown Reference opcode %X (%s) in %p\n",
262 opcode, acpi_ps_get_opcode_name (opcode), stack_desc));
263 status = AE_AML_INTERNAL;
264 break;
266 break;
269 case ACPI_TYPE_BUFFER:
271 status = acpi_ds_get_buffer_arguments (stack_desc);
272 break;
275 case ACPI_TYPE_PACKAGE:
277 status = acpi_ds_get_package_arguments (stack_desc);
278 break;
282 * These cases may never happen here, but just in case..
284 case ACPI_TYPE_BUFFER_FIELD:
285 case ACPI_TYPE_LOCAL_REGION_FIELD:
286 case ACPI_TYPE_LOCAL_BANK_FIELD:
287 case ACPI_TYPE_LOCAL_INDEX_FIELD:
289 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "field_read source_desc=%p Type=%X\n",
290 stack_desc, ACPI_GET_OBJECT_TYPE (stack_desc)));
292 status = acpi_ex_read_data_from_field (walk_state, stack_desc, &obj_desc);
293 *stack_ptr = (void *) obj_desc;
294 break;
296 default:
297 break;
300 return_ACPI_STATUS (status);
304 /*******************************************************************************
306 * FUNCTION: acpi_ex_resolve_multiple
308 * PARAMETERS: walk_state - Current state (contains AML opcode)
309 * Operand - Starting point for resolution
310 * return_type - Where the object type is returned
311 * return_desc - Where the resolved object is returned
313 * RETURN: Status
315 * DESCRIPTION: Return the base object and type. Traverse a reference list if
316 * necessary to get to the base object.
318 ******************************************************************************/
320 acpi_status
321 acpi_ex_resolve_multiple (
322 struct acpi_walk_state *walk_state,
323 union acpi_operand_object *operand,
324 acpi_object_type *return_type,
325 union acpi_operand_object **return_desc)
327 union acpi_operand_object *obj_desc = (void *) operand;
328 struct acpi_namespace_node *node;
329 acpi_object_type type;
332 ACPI_FUNCTION_TRACE ("acpi_ex_resolve_multiple");
336 * For reference objects created via the ref_of or Index operators,
337 * we need to get to the base object (as per the ACPI specification
338 * of the object_type and size_of operators). This means traversing
339 * the list of possibly many nested references.
341 while (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_LOCAL_REFERENCE) {
342 switch (obj_desc->reference.opcode) {
343 case AML_REF_OF_OP:
345 /* Dereference the reference pointer */
347 node = obj_desc->reference.object;
349 /* All "References" point to a NS node */
351 if (ACPI_GET_DESCRIPTOR_TYPE (node) != ACPI_DESC_TYPE_NAMED) {
352 ACPI_REPORT_ERROR (("acpi_ex_resolve_multiple: Not a NS node %p [%s]\n",
353 node, acpi_ut_get_descriptor_name (node)));
354 return_ACPI_STATUS (AE_AML_INTERNAL);
357 /* Get the attached object */
359 obj_desc = acpi_ns_get_attached_object (node);
360 if (!obj_desc) {
361 /* No object, use the NS node type */
363 type = acpi_ns_get_type (node);
364 goto exit;
367 /* Check for circular references */
369 if (obj_desc == operand) {
370 return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE);
372 break;
375 case AML_INDEX_OP:
377 /* Get the type of this reference (index into another object) */
379 type = obj_desc->reference.target_type;
380 if (type != ACPI_TYPE_PACKAGE) {
381 goto exit;
385 * The main object is a package, we want to get the type
386 * of the individual package element that is referenced by
387 * the index.
389 * This could of course in turn be another reference object.
391 obj_desc = *(obj_desc->reference.where);
392 break;
395 case AML_INT_NAMEPATH_OP:
397 /* Dereference the reference pointer */
399 node = obj_desc->reference.node;
401 /* All "References" point to a NS node */
403 if (ACPI_GET_DESCRIPTOR_TYPE (node) != ACPI_DESC_TYPE_NAMED) {
404 ACPI_REPORT_ERROR (("acpi_ex_resolve_multiple: Not a NS node %p [%s]\n",
405 node, acpi_ut_get_descriptor_name (node)));
406 return_ACPI_STATUS (AE_AML_INTERNAL);
409 /* Get the attached object */
411 obj_desc = acpi_ns_get_attached_object (node);
412 if (!obj_desc) {
413 /* No object, use the NS node type */
415 type = acpi_ns_get_type (node);
416 goto exit;
419 /* Check for circular references */
421 if (obj_desc == operand) {
422 return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE);
424 break;
427 case AML_DEBUG_OP:
429 /* The Debug Object is of type "debug_object" */
431 type = ACPI_TYPE_DEBUG_OBJECT;
432 goto exit;
435 default:
437 ACPI_REPORT_ERROR (("acpi_ex_resolve_multiple: Unknown Reference subtype %X\n",
438 obj_desc->reference.opcode));
439 return_ACPI_STATUS (AE_AML_INTERNAL);
444 * Now we are guaranteed to have an object that has not been created
445 * via the ref_of or Index operators.
447 type = ACPI_GET_OBJECT_TYPE (obj_desc);
450 exit:
451 /* Convert internal types to external types */
453 switch (type) {
454 case ACPI_TYPE_LOCAL_REGION_FIELD:
455 case ACPI_TYPE_LOCAL_BANK_FIELD:
456 case ACPI_TYPE_LOCAL_INDEX_FIELD:
458 type = ACPI_TYPE_FIELD_UNIT;
459 break;
461 case ACPI_TYPE_LOCAL_SCOPE:
463 /* Per ACPI Specification, Scope is untyped */
465 type = ACPI_TYPE_ANY;
466 break;
468 default:
469 /* No change to Type required */
470 break;
473 *return_type = type;
474 if (return_desc) {
475 *return_desc = obj_desc;
477 return_ACPI_STATUS (AE_OK);