Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: exresnte - AML Interpreter object resolution | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
77848130 | 8 | * Copyright (C) 2000 - 2012, Intel Corp. |
1da177e4 LT |
9 | * All rights reserved. |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions, and the following disclaimer, | |
16 | * without modification. | |
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
18 | * substantially similar to the "NO WARRANTY" disclaimer below | |
19 | * ("Disclaimer") and any redistribution must be conditioned upon | |
20 | * including a substantially similar Disclaimer requirement for further | |
21 | * binary redistribution. | |
22 | * 3. Neither the names of the above-listed copyright holders nor the names | |
23 | * of any contributors may be used to endorse or promote products derived | |
24 | * from this software without specific prior written permission. | |
25 | * | |
26 | * Alternatively, this software may be distributed under the terms of the | |
27 | * GNU General Public License ("GPL") version 2 as published by the Free | |
28 | * Software Foundation. | |
29 | * | |
30 | * NO WARRANTY | |
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
41 | * POSSIBILITY OF SUCH DAMAGES. | |
42 | */ | |
43 | ||
1da177e4 | 44 | #include <acpi/acpi.h> |
e2f7a777 LB |
45 | #include "accommon.h" |
46 | #include "acdispat.h" | |
47 | #include "acinterp.h" | |
48 | #include "acnamesp.h" | |
1da177e4 | 49 | |
1da177e4 | 50 | #define _COMPONENT ACPI_EXECUTER |
4be44fcd | 51 | ACPI_MODULE_NAME("exresnte") |
1da177e4 LT |
52 | |
53 | /******************************************************************************* | |
54 | * | |
55 | * FUNCTION: acpi_ex_resolve_node_to_value | |
56 | * | |
57 | * PARAMETERS: object_ptr - Pointer to a location that contains | |
58 | * a pointer to a NS node, and will receive a | |
59 | * pointer to the resolved object. | |
73a3090a BM |
60 | * walk_state - Current state. Valid only if executing AML |
61 | * code. NULL if simply resolving an object | |
1da177e4 LT |
62 | * |
63 | * RETURN: Status | |
64 | * | |
65 | * DESCRIPTION: Resolve a Namespace node to a valued object | |
66 | * | |
67 | * Note: for some of the data types, the pointer attached to the Node | |
68 | * can be either a pointer to an actual internal object or a pointer into the | |
73a3090a | 69 | * AML stream itself. These types are currently: |
1da177e4 LT |
70 | * |
71 | * ACPI_TYPE_INTEGER | |
72 | * ACPI_TYPE_STRING | |
73 | * ACPI_TYPE_BUFFER | |
74 | * ACPI_TYPE_MUTEX | |
75 | * ACPI_TYPE_PACKAGE | |
76 | * | |
77 | ******************************************************************************/ | |
1da177e4 | 78 | acpi_status |
4be44fcd LB |
79 | acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr, |
80 | struct acpi_walk_state *walk_state) | |
1da177e4 | 81 | { |
4be44fcd LB |
82 | acpi_status status = AE_OK; |
83 | union acpi_operand_object *source_desc; | |
84 | union acpi_operand_object *obj_desc = NULL; | |
85 | struct acpi_namespace_node *node; | |
86 | acpi_object_type entry_type; | |
1da177e4 | 87 | |
b229cf92 | 88 | ACPI_FUNCTION_TRACE(ex_resolve_node_to_value); |
1da177e4 LT |
89 | |
90 | /* | |
73a3090a | 91 | * The stack pointer points to a struct acpi_namespace_node (Node). Get the |
1da177e4 LT |
92 | * object that is attached to the Node. |
93 | */ | |
4be44fcd LB |
94 | node = *object_ptr; |
95 | source_desc = acpi_ns_get_attached_object(node); | |
96 | entry_type = acpi_ns_get_type((acpi_handle) node); | |
1da177e4 | 97 | |
b229cf92 | 98 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n", |
4be44fcd LB |
99 | node, source_desc, |
100 | acpi_ut_get_type_name(entry_type))); | |
1da177e4 LT |
101 | |
102 | if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) || | |
4be44fcd | 103 | (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) { |
52fc0b02 | 104 | |
1da177e4 LT |
105 | /* There is always exactly one level of indirection */ |
106 | ||
4be44fcd LB |
107 | node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object); |
108 | source_desc = acpi_ns_get_attached_object(node); | |
109 | entry_type = acpi_ns_get_type((acpi_handle) node); | |
1da177e4 LT |
110 | *object_ptr = node; |
111 | } | |
112 | ||
113 | /* | |
114 | * Several object types require no further processing: | |
4c90ece2 | 115 | * 1) Device/Thermal objects don't have a "real" subobject, return the Node |
1da177e4 | 116 | * 2) Method locals and arguments have a pseudo-Node |
b160987d | 117 | * 3) 10/2007: Added method type to assist with Package construction. |
1da177e4 | 118 | */ |
4c90ece2 BM |
119 | if ((entry_type == ACPI_TYPE_DEVICE) || |
120 | (entry_type == ACPI_TYPE_THERMAL) || | |
b160987d | 121 | (entry_type == ACPI_TYPE_METHOD) || |
4be44fcd LB |
122 | (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) { |
123 | return_ACPI_STATUS(AE_OK); | |
1da177e4 LT |
124 | } |
125 | ||
126 | if (!source_desc) { | |
b8e4d893 | 127 | ACPI_ERROR((AE_INFO, "No object attached to node %p", node)); |
4be44fcd | 128 | return_ACPI_STATUS(AE_AML_NO_OPERAND); |
1da177e4 LT |
129 | } |
130 | ||
131 | /* | |
132 | * Action is based on the type of the Node, which indicates the type | |
133 | * of the attached object or pointer | |
134 | */ | |
135 | switch (entry_type) { | |
136 | case ACPI_TYPE_PACKAGE: | |
137 | ||
3371c19c | 138 | if (source_desc->common.type != ACPI_TYPE_PACKAGE) { |
b8e4d893 BM |
139 | ACPI_ERROR((AE_INFO, "Object not a Package, type %s", |
140 | acpi_ut_get_object_type_name(source_desc))); | |
4be44fcd | 141 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 LT |
142 | } |
143 | ||
4be44fcd LB |
144 | status = acpi_ds_get_package_arguments(source_desc); |
145 | if (ACPI_SUCCESS(status)) { | |
52fc0b02 | 146 | |
1da177e4 LT |
147 | /* Return an additional reference to the object */ |
148 | ||
149 | obj_desc = source_desc; | |
4be44fcd | 150 | acpi_ut_add_reference(obj_desc); |
1da177e4 LT |
151 | } |
152 | break; | |
153 | ||
1da177e4 LT |
154 | case ACPI_TYPE_BUFFER: |
155 | ||
3371c19c | 156 | if (source_desc->common.type != ACPI_TYPE_BUFFER) { |
b8e4d893 BM |
157 | ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s", |
158 | acpi_ut_get_object_type_name(source_desc))); | |
4be44fcd | 159 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 LT |
160 | } |
161 | ||
4be44fcd LB |
162 | status = acpi_ds_get_buffer_arguments(source_desc); |
163 | if (ACPI_SUCCESS(status)) { | |
52fc0b02 | 164 | |
1da177e4 LT |
165 | /* Return an additional reference to the object */ |
166 | ||
167 | obj_desc = source_desc; | |
4be44fcd | 168 | acpi_ut_add_reference(obj_desc); |
1da177e4 LT |
169 | } |
170 | break; | |
171 | ||
1da177e4 LT |
172 | case ACPI_TYPE_STRING: |
173 | ||
3371c19c | 174 | if (source_desc->common.type != ACPI_TYPE_STRING) { |
b8e4d893 BM |
175 | ACPI_ERROR((AE_INFO, "Object not a String, type %s", |
176 | acpi_ut_get_object_type_name(source_desc))); | |
4be44fcd | 177 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 LT |
178 | } |
179 | ||
180 | /* Return an additional reference to the object */ | |
181 | ||
182 | obj_desc = source_desc; | |
4be44fcd | 183 | acpi_ut_add_reference(obj_desc); |
1da177e4 LT |
184 | break; |
185 | ||
1da177e4 LT |
186 | case ACPI_TYPE_INTEGER: |
187 | ||
3371c19c | 188 | if (source_desc->common.type != ACPI_TYPE_INTEGER) { |
b8e4d893 BM |
189 | ACPI_ERROR((AE_INFO, "Object not a Integer, type %s", |
190 | acpi_ut_get_object_type_name(source_desc))); | |
4be44fcd | 191 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 LT |
192 | } |
193 | ||
194 | /* Return an additional reference to the object */ | |
195 | ||
196 | obj_desc = source_desc; | |
4be44fcd | 197 | acpi_ut_add_reference(obj_desc); |
1da177e4 LT |
198 | break; |
199 | ||
1da177e4 LT |
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: | |
204 | ||
4be44fcd | 205 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
b229cf92 | 206 | "FieldRead Node=%p SourceDesc=%p Type=%X\n", |
4be44fcd | 207 | node, source_desc, entry_type)); |
1da177e4 | 208 | |
4be44fcd LB |
209 | status = |
210 | acpi_ex_read_data_from_field(walk_state, source_desc, | |
211 | &obj_desc); | |
1da177e4 LT |
212 | break; |
213 | ||
4be44fcd | 214 | /* For these objects, just return the object attached to the Node */ |
44f6c012 | 215 | |
1da177e4 | 216 | case ACPI_TYPE_MUTEX: |
1da177e4 LT |
217 | case ACPI_TYPE_POWER: |
218 | case ACPI_TYPE_PROCESSOR: | |
1da177e4 LT |
219 | case ACPI_TYPE_EVENT: |
220 | case ACPI_TYPE_REGION: | |
221 | ||
222 | /* Return an additional reference to the object */ | |
223 | ||
224 | obj_desc = source_desc; | |
4be44fcd | 225 | acpi_ut_add_reference(obj_desc); |
1da177e4 LT |
226 | break; |
227 | ||
4be44fcd | 228 | /* TYPE_ANY is untyped, and thus there is no object associated with it */ |
1da177e4 LT |
229 | |
230 | case ACPI_TYPE_ANY: | |
231 | ||
b8e4d893 BM |
232 | ACPI_ERROR((AE_INFO, |
233 | "Untyped entry %p, no attached object!", node)); | |
1da177e4 | 234 | |
4be44fcd | 235 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */ |
1da177e4 LT |
236 | |
237 | case ACPI_TYPE_LOCAL_REFERENCE: | |
238 | ||
1044f1f6 BM |
239 | switch (source_desc->reference.class) { |
240 | case ACPI_REFCLASS_TABLE: /* This is a ddb_handle */ | |
241 | case ACPI_REFCLASS_REFOF: | |
242 | case ACPI_REFCLASS_INDEX: | |
1da177e4 | 243 | |
1da177e4 LT |
244 | /* Return an additional reference to the object */ |
245 | ||
246 | obj_desc = source_desc; | |
4be44fcd | 247 | acpi_ut_add_reference(obj_desc); |
1da177e4 LT |
248 | break; |
249 | ||
250 | default: | |
251 | /* No named references are allowed here */ | |
252 | ||
b8e4d893 | 253 | ACPI_ERROR((AE_INFO, |
f6a22b0b | 254 | "Unsupported Reference type 0x%X", |
1044f1f6 | 255 | source_desc->reference.class)); |
1da177e4 | 256 | |
4be44fcd | 257 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 LT |
258 | } |
259 | break; | |
260 | ||
1da177e4 LT |
261 | default: |
262 | ||
44f6c012 RM |
263 | /* Default case is for unknown types */ |
264 | ||
b8e4d893 | 265 | ACPI_ERROR((AE_INFO, |
f6a22b0b | 266 | "Node %p - Unknown object type 0x%X", |
b8e4d893 | 267 | node, entry_type)); |
1da177e4 | 268 | |
4be44fcd | 269 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 | 270 | |
4be44fcd | 271 | } /* switch (entry_type) */ |
1da177e4 | 272 | |
44f6c012 | 273 | /* Return the object descriptor */ |
1da177e4 | 274 | |
4be44fcd LB |
275 | *object_ptr = (void *)obj_desc; |
276 | return_ACPI_STATUS(status); | |
1da177e4 | 277 | } |