pcmcia: CompactFlash driver for PA Semi Electra boards
[pv_ops_mirror.git] / drivers / acpi / executer / exresnte.c
blob2b3a01cc4929e2bf9b0dbd7c2f22707a89d3fdd2
2 /******************************************************************************
4 * Module Name: exresnte - AML Interpreter object resolution
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2007, 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.
45 #include <acpi/acpi.h>
46 #include <acpi/acdispat.h>
47 #include <acpi/acinterp.h>
48 #include <acpi/acnamesp.h>
49 #include <acpi/acparser.h>
50 #include <acpi/amlcode.h>
52 #define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME("exresnte")
55 /*******************************************************************************
57 * FUNCTION: acpi_ex_resolve_node_to_value
59 * PARAMETERS: object_ptr - Pointer to a location that contains
60 * a pointer to a NS node, and will receive a
61 * pointer to the resolved object.
62 * walk_state - Current state. Valid only if executing AML
63 * code. NULL if simply resolving an object
65 * RETURN: Status
67 * DESCRIPTION: Resolve a Namespace node to a valued object
69 * Note: for some of the data types, the pointer attached to the Node
70 * can be either a pointer to an actual internal object or a pointer into the
71 * AML stream itself. These types are currently:
73 * ACPI_TYPE_INTEGER
74 * ACPI_TYPE_STRING
75 * ACPI_TYPE_BUFFER
76 * ACPI_TYPE_MUTEX
77 * ACPI_TYPE_PACKAGE
79 ******************************************************************************/
80 acpi_status
81 acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
82 struct acpi_walk_state *walk_state)
84 acpi_status status = AE_OK;
85 union acpi_operand_object *source_desc;
86 union acpi_operand_object *obj_desc = NULL;
87 struct acpi_namespace_node *node;
88 acpi_object_type entry_type;
90 ACPI_FUNCTION_TRACE(ex_resolve_node_to_value);
93 * The stack pointer points to a struct acpi_namespace_node (Node). Get the
94 * object that is attached to the Node.
96 node = *object_ptr;
97 source_desc = acpi_ns_get_attached_object(node);
98 entry_type = acpi_ns_get_type((acpi_handle) node);
100 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
101 node, source_desc,
102 acpi_ut_get_type_name(entry_type)));
104 if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
105 (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
107 /* There is always exactly one level of indirection */
109 node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object);
110 source_desc = acpi_ns_get_attached_object(node);
111 entry_type = acpi_ns_get_type((acpi_handle) node);
112 *object_ptr = node;
116 * Several object types require no further processing:
117 * 1) Device/Thermal objects don't have a "real" subobject, return the Node
118 * 2) Method locals and arguments have a pseudo-Node
120 if ((entry_type == ACPI_TYPE_DEVICE) ||
121 (entry_type == ACPI_TYPE_THERMAL) ||
122 (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
123 return_ACPI_STATUS(AE_OK);
126 if (!source_desc) {
127 ACPI_ERROR((AE_INFO, "No object attached to node %p", node));
128 return_ACPI_STATUS(AE_AML_NO_OPERAND);
132 * Action is based on the type of the Node, which indicates the type
133 * of the attached object or pointer
135 switch (entry_type) {
136 case ACPI_TYPE_PACKAGE:
138 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_PACKAGE) {
139 ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
140 acpi_ut_get_object_type_name(source_desc)));
141 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
144 status = acpi_ds_get_package_arguments(source_desc);
145 if (ACPI_SUCCESS(status)) {
147 /* Return an additional reference to the object */
149 obj_desc = source_desc;
150 acpi_ut_add_reference(obj_desc);
152 break;
154 case ACPI_TYPE_BUFFER:
156 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) {
157 ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s",
158 acpi_ut_get_object_type_name(source_desc)));
159 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
162 status = acpi_ds_get_buffer_arguments(source_desc);
163 if (ACPI_SUCCESS(status)) {
165 /* Return an additional reference to the object */
167 obj_desc = source_desc;
168 acpi_ut_add_reference(obj_desc);
170 break;
172 case ACPI_TYPE_STRING:
174 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) {
175 ACPI_ERROR((AE_INFO, "Object not a String, type %s",
176 acpi_ut_get_object_type_name(source_desc)));
177 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
180 /* Return an additional reference to the object */
182 obj_desc = source_desc;
183 acpi_ut_add_reference(obj_desc);
184 break;
186 case ACPI_TYPE_INTEGER:
188 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) {
189 ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
190 acpi_ut_get_object_type_name(source_desc)));
191 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
194 /* Return an additional reference to the object */
196 obj_desc = source_desc;
197 acpi_ut_add_reference(obj_desc);
198 break;
200 case ACPI_TYPE_BUFFER_FIELD:
201 case ACPI_TYPE_LOCAL_REGION_FIELD:
202 case ACPI_TYPE_LOCAL_BANK_FIELD:
203 case ACPI_TYPE_LOCAL_INDEX_FIELD:
205 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
206 "FieldRead Node=%p SourceDesc=%p Type=%X\n",
207 node, source_desc, entry_type));
209 status =
210 acpi_ex_read_data_from_field(walk_state, source_desc,
211 &obj_desc);
212 break;
214 /* For these objects, just return the object attached to the Node */
216 case ACPI_TYPE_MUTEX:
217 case ACPI_TYPE_METHOD:
218 case ACPI_TYPE_POWER:
219 case ACPI_TYPE_PROCESSOR:
220 case ACPI_TYPE_EVENT:
221 case ACPI_TYPE_REGION:
223 /* Return an additional reference to the object */
225 obj_desc = source_desc;
226 acpi_ut_add_reference(obj_desc);
227 break;
229 /* TYPE_ANY is untyped, and thus there is no object associated with it */
231 case ACPI_TYPE_ANY:
233 ACPI_ERROR((AE_INFO,
234 "Untyped entry %p, no attached object!", node));
236 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
238 case ACPI_TYPE_LOCAL_REFERENCE:
240 switch (source_desc->reference.opcode) {
241 case AML_LOAD_OP:
243 /* This is a ddb_handle */
244 /* Return an additional reference to the object */
246 case AML_REF_OF_OP:
248 obj_desc = source_desc;
249 acpi_ut_add_reference(obj_desc);
250 break;
252 default:
253 /* No named references are allowed here */
255 ACPI_ERROR((AE_INFO,
256 "Unsupported Reference opcode %X (%s)",
257 source_desc->reference.opcode,
258 acpi_ps_get_opcode_name(source_desc->
259 reference.opcode)));
261 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
263 break;
265 default:
267 /* Default case is for unknown types */
269 ACPI_ERROR((AE_INFO,
270 "Node %p - Unknown object type %X",
271 node, entry_type));
273 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
275 } /* switch (entry_type) */
277 /* Return the object descriptor */
279 *object_ptr = (void *)obj_desc;
280 return_ACPI_STATUS(status);