Linux-2.6.12-rc2
[linux-flexiantxendom0-natty.git] / drivers / acpi / executer / exresnte.c
1
2 /******************************************************************************
3  *
4  * Module Name: exresnte - AML Interpreter object resolution
5  *
6  *****************************************************************************/
7
8 /*
9  * Copyright (C) 2000 - 2005, R. Byron Moore
10  * All rights reserved.
11  *
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.
26  *
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.
30  *
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.
43  */
44
45
46 #include <acpi/acpi.h>
47 #include <acpi/acdispat.h>
48 #include <acpi/acinterp.h>
49 #include <acpi/acnamesp.h>
50 #include <acpi/acparser.h>
51 #include <acpi/amlcode.h>
52
53
54 #define _COMPONENT          ACPI_EXECUTER
55          ACPI_MODULE_NAME    ("exresnte")
56
57
58 /*******************************************************************************
59  *
60  * FUNCTION:    acpi_ex_resolve_node_to_value
61  *
62  * PARAMETERS:  object_ptr      - Pointer to a location that contains
63  *                                a pointer to a NS node, and will receive a
64  *                                pointer to the resolved object.
65  *              walk_state      - Current state.  Valid only if executing AML
66  *                                code.  NULL if simply resolving an object
67  *
68  * RETURN:      Status
69  *
70  * DESCRIPTION: Resolve a Namespace node to a valued object
71  *
72  * Note: for some of the data types, the pointer attached to the Node
73  * can be either a pointer to an actual internal object or a pointer into the
74  * AML stream itself.  These types are currently:
75  *
76  *      ACPI_TYPE_INTEGER
77  *      ACPI_TYPE_STRING
78  *      ACPI_TYPE_BUFFER
79  *      ACPI_TYPE_MUTEX
80  *      ACPI_TYPE_PACKAGE
81  *
82  ******************************************************************************/
83
84 acpi_status
85 acpi_ex_resolve_node_to_value (
86         struct acpi_namespace_node      **object_ptr,
87         struct acpi_walk_state          *walk_state)
88
89 {
90         acpi_status                     status = AE_OK;
91         union acpi_operand_object       *source_desc;
92         union acpi_operand_object       *obj_desc = NULL;
93         struct acpi_namespace_node      *node;
94         acpi_object_type                entry_type;
95
96
97         ACPI_FUNCTION_TRACE ("ex_resolve_node_to_value");
98
99
100         /*
101          * The stack pointer points to a struct acpi_namespace_node (Node).  Get the
102          * object that is attached to the Node.
103          */
104         node       = *object_ptr;
105         source_desc = acpi_ns_get_attached_object (node);
106         entry_type = acpi_ns_get_type ((acpi_handle) node);
107
108         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Entry=%p source_desc=%p [%s]\n",
109                  node, source_desc, acpi_ut_get_type_name (entry_type)));
110
111         if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
112                 (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
113                 /* There is always exactly one level of indirection */
114
115                 node       = ACPI_CAST_PTR (struct acpi_namespace_node, node->object);
116                 source_desc = acpi_ns_get_attached_object (node);
117                 entry_type = acpi_ns_get_type ((acpi_handle) node);
118                 *object_ptr = node;
119         }
120
121         /*
122          * Several object types require no further processing:
123          * 1) Devices rarely have an attached object, return the Node
124          * 2) Method locals and arguments have a pseudo-Node
125          */
126         if (entry_type == ACPI_TYPE_DEVICE ||
127                 (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
128                 return_ACPI_STATUS (AE_OK);
129         }
130
131         if (!source_desc) {
132                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No object attached to node %p\n",
133                         node));
134                 return_ACPI_STATUS (AE_AML_NO_OPERAND);
135         }
136
137         /*
138          * Action is based on the type of the Node, which indicates the type
139          * of the attached object or pointer
140          */
141         switch (entry_type) {
142         case ACPI_TYPE_PACKAGE:
143
144                 if (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_PACKAGE) {
145                         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Object not a Package, type %s\n",
146                                 acpi_ut_get_object_type_name (source_desc)));
147                         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
148                 }
149
150                 status = acpi_ds_get_package_arguments (source_desc);
151                 if (ACPI_SUCCESS (status)) {
152                         /* Return an additional reference to the object */
153
154                         obj_desc = source_desc;
155                         acpi_ut_add_reference (obj_desc);
156                 }
157                 break;
158
159
160         case ACPI_TYPE_BUFFER:
161
162                 if (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_BUFFER) {
163                         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Object not a Buffer, type %s\n",
164                                 acpi_ut_get_object_type_name (source_desc)));
165                         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
166                 }
167
168                 status = acpi_ds_get_buffer_arguments (source_desc);
169                 if (ACPI_SUCCESS (status)) {
170                         /* Return an additional reference to the object */
171
172                         obj_desc = source_desc;
173                         acpi_ut_add_reference (obj_desc);
174                 }
175                 break;
176
177
178         case ACPI_TYPE_STRING:
179
180                 if (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_STRING) {
181                         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Object not a String, type %s\n",
182                                 acpi_ut_get_object_type_name (source_desc)));
183                         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
184                 }
185
186                 /* Return an additional reference to the object */
187
188                 obj_desc = source_desc;
189                 acpi_ut_add_reference (obj_desc);
190                 break;
191
192
193         case ACPI_TYPE_INTEGER:
194
195                 if (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_INTEGER) {
196                         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Object not a Integer, type %s\n",
197                                 acpi_ut_get_object_type_name (source_desc)));
198                         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
199                 }
200
201                 /* Return an additional reference to the object */
202
203                 obj_desc = source_desc;
204                 acpi_ut_add_reference (obj_desc);
205                 break;
206
207
208         case ACPI_TYPE_BUFFER_FIELD:
209         case ACPI_TYPE_LOCAL_REGION_FIELD:
210         case ACPI_TYPE_LOCAL_BANK_FIELD:
211         case ACPI_TYPE_LOCAL_INDEX_FIELD:
212
213                 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "field_read Node=%p source_desc=%p Type=%X\n",
214                         node, source_desc, entry_type));
215
216                 status = acpi_ex_read_data_from_field (walk_state, source_desc, &obj_desc);
217                 break;
218
219         /*
220          * For these objects, just return the object attached to the Node
221          */
222         case ACPI_TYPE_MUTEX:
223         case ACPI_TYPE_METHOD:
224         case ACPI_TYPE_POWER:
225         case ACPI_TYPE_PROCESSOR:
226         case ACPI_TYPE_THERMAL:
227         case ACPI_TYPE_EVENT:
228         case ACPI_TYPE_REGION:
229
230                 /* Return an additional reference to the object */
231
232                 obj_desc = source_desc;
233                 acpi_ut_add_reference (obj_desc);
234                 break;
235
236
237         /* TYPE_ANY is untyped, and thus there is no object associated with it */
238
239         case ACPI_TYPE_ANY:
240
241                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Untyped entry %p, no attached object!\n",
242                         node));
243
244                 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);  /* Cannot be AE_TYPE */
245
246
247         case ACPI_TYPE_LOCAL_REFERENCE:
248
249                 switch (source_desc->reference.opcode) {
250                 case AML_LOAD_OP:
251
252                         /* This is a ddb_handle */
253                         /* Return an additional reference to the object */
254
255                         obj_desc = source_desc;
256                         acpi_ut_add_reference (obj_desc);
257                         break;
258
259                 default:
260                         /* No named references are allowed here */
261
262                         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unsupported Reference opcode %X (%s)\n",
263                                 source_desc->reference.opcode,
264                                 acpi_ps_get_opcode_name (source_desc->reference.opcode)));
265
266                         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
267                 }
268                 break;
269
270
271         /* Default case is for unknown types */
272
273         default:
274
275                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Node %p - Unknown object type %X\n",
276                         node, entry_type));
277
278                 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
279
280         } /* switch (entry_type) */
281
282
283         /* Put the object descriptor on the stack */
284
285         *object_ptr = (void *) obj_desc;
286         return_ACPI_STATUS (status);
287 }
288
289