Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | |
2 | /****************************************************************************** | |
3 | * | |
4 | * Module Name: exresnte - AML Interpreter object resolution | |
5 | * | |
6 | *****************************************************************************/ | |
7 | ||
8 | /* | |
4a90c7e8 | 9 | * Copyright (C) 2000 - 2006, R. Byron Moore |
1da177e4 LT |
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 | ||
1da177e4 LT |
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> | |
51 | ||
1da177e4 | 52 | #define _COMPONENT ACPI_EXECUTER |
4be44fcd | 53 | ACPI_MODULE_NAME("exresnte") |
1da177e4 LT |
54 | |
55 | /******************************************************************************* | |
56 | * | |
57 | * FUNCTION: acpi_ex_resolve_node_to_value | |
58 | * | |
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 | |
64 | * | |
65 | * RETURN: Status | |
66 | * | |
67 | * DESCRIPTION: Resolve a Namespace node to a valued object | |
68 | * | |
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: | |
72 | * | |
73 | * ACPI_TYPE_INTEGER | |
74 | * ACPI_TYPE_STRING | |
75 | * ACPI_TYPE_BUFFER | |
76 | * ACPI_TYPE_MUTEX | |
77 | * ACPI_TYPE_PACKAGE | |
78 | * | |
79 | ******************************************************************************/ | |
1da177e4 | 80 | acpi_status |
4be44fcd LB |
81 | acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr, |
82 | struct acpi_walk_state *walk_state) | |
1da177e4 | 83 | { |
4be44fcd LB |
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; | |
1da177e4 | 89 | |
b229cf92 | 90 | ACPI_FUNCTION_TRACE(ex_resolve_node_to_value); |
1da177e4 LT |
91 | |
92 | /* | |
93 | * The stack pointer points to a struct acpi_namespace_node (Node). Get the | |
94 | * object that is attached to the Node. | |
95 | */ | |
4be44fcd LB |
96 | node = *object_ptr; |
97 | source_desc = acpi_ns_get_attached_object(node); | |
98 | entry_type = acpi_ns_get_type((acpi_handle) node); | |
1da177e4 | 99 | |
b229cf92 | 100 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n", |
4be44fcd LB |
101 | node, source_desc, |
102 | acpi_ut_get_type_name(entry_type))); | |
1da177e4 LT |
103 | |
104 | if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) || | |
4be44fcd | 105 | (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) { |
52fc0b02 | 106 | |
1da177e4 LT |
107 | /* There is always exactly one level of indirection */ |
108 | ||
4be44fcd LB |
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); | |
1da177e4 LT |
112 | *object_ptr = node; |
113 | } | |
114 | ||
115 | /* | |
116 | * Several object types require no further processing: | |
117 | * 1) Devices rarely have an attached object, return the Node | |
118 | * 2) Method locals and arguments have a pseudo-Node | |
119 | */ | |
120 | if (entry_type == ACPI_TYPE_DEVICE || | |
4be44fcd LB |
121 | (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) { |
122 | return_ACPI_STATUS(AE_OK); | |
1da177e4 LT |
123 | } |
124 | ||
125 | if (!source_desc) { | |
b8e4d893 | 126 | ACPI_ERROR((AE_INFO, "No object attached to node %p", node)); |
4be44fcd | 127 | return_ACPI_STATUS(AE_AML_NO_OPERAND); |
1da177e4 LT |
128 | } |
129 | ||
130 | /* | |
131 | * Action is based on the type of the Node, which indicates the type | |
132 | * of the attached object or pointer | |
133 | */ | |
134 | switch (entry_type) { | |
135 | case ACPI_TYPE_PACKAGE: | |
136 | ||
4be44fcd | 137 | if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_PACKAGE) { |
b8e4d893 BM |
138 | ACPI_ERROR((AE_INFO, "Object not a Package, type %s", |
139 | acpi_ut_get_object_type_name(source_desc))); | |
4be44fcd | 140 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 LT |
141 | } |
142 | ||
4be44fcd LB |
143 | status = acpi_ds_get_package_arguments(source_desc); |
144 | if (ACPI_SUCCESS(status)) { | |
52fc0b02 | 145 | |
1da177e4 LT |
146 | /* Return an additional reference to the object */ |
147 | ||
148 | obj_desc = source_desc; | |
4be44fcd | 149 | acpi_ut_add_reference(obj_desc); |
1da177e4 LT |
150 | } |
151 | break; | |
152 | ||
1da177e4 LT |
153 | case ACPI_TYPE_BUFFER: |
154 | ||
4be44fcd | 155 | if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) { |
b8e4d893 BM |
156 | ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s", |
157 | acpi_ut_get_object_type_name(source_desc))); | |
4be44fcd | 158 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 LT |
159 | } |
160 | ||
4be44fcd LB |
161 | status = acpi_ds_get_buffer_arguments(source_desc); |
162 | if (ACPI_SUCCESS(status)) { | |
52fc0b02 | 163 | |
1da177e4 LT |
164 | /* Return an additional reference to the object */ |
165 | ||
166 | obj_desc = source_desc; | |
4be44fcd | 167 | acpi_ut_add_reference(obj_desc); |
1da177e4 LT |
168 | } |
169 | break; | |
170 | ||
1da177e4 LT |
171 | case ACPI_TYPE_STRING: |
172 | ||
4be44fcd | 173 | if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) { |
b8e4d893 BM |
174 | ACPI_ERROR((AE_INFO, "Object not a String, type %s", |
175 | acpi_ut_get_object_type_name(source_desc))); | |
4be44fcd | 176 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 LT |
177 | } |
178 | ||
179 | /* Return an additional reference to the object */ | |
180 | ||
181 | obj_desc = source_desc; | |
4be44fcd | 182 | acpi_ut_add_reference(obj_desc); |
1da177e4 LT |
183 | break; |
184 | ||
1da177e4 LT |
185 | case ACPI_TYPE_INTEGER: |
186 | ||
4be44fcd | 187 | if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) { |
b8e4d893 BM |
188 | ACPI_ERROR((AE_INFO, "Object not a Integer, type %s", |
189 | acpi_ut_get_object_type_name(source_desc))); | |
4be44fcd | 190 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 LT |
191 | } |
192 | ||
193 | /* Return an additional reference to the object */ | |
194 | ||
195 | obj_desc = source_desc; | |
4be44fcd | 196 | acpi_ut_add_reference(obj_desc); |
1da177e4 LT |
197 | break; |
198 | ||
1da177e4 LT |
199 | case ACPI_TYPE_BUFFER_FIELD: |
200 | case ACPI_TYPE_LOCAL_REGION_FIELD: | |
201 | case ACPI_TYPE_LOCAL_BANK_FIELD: | |
202 | case ACPI_TYPE_LOCAL_INDEX_FIELD: | |
203 | ||
4be44fcd | 204 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
b229cf92 | 205 | "FieldRead Node=%p SourceDesc=%p Type=%X\n", |
4be44fcd | 206 | node, source_desc, entry_type)); |
1da177e4 | 207 | |
4be44fcd LB |
208 | status = |
209 | acpi_ex_read_data_from_field(walk_state, source_desc, | |
210 | &obj_desc); | |
1da177e4 LT |
211 | break; |
212 | ||
4be44fcd | 213 | /* For these objects, just return the object attached to the Node */ |
44f6c012 | 214 | |
1da177e4 LT |
215 | case ACPI_TYPE_MUTEX: |
216 | case ACPI_TYPE_METHOD: | |
217 | case ACPI_TYPE_POWER: | |
218 | case ACPI_TYPE_PROCESSOR: | |
219 | case ACPI_TYPE_THERMAL: | |
220 | case ACPI_TYPE_EVENT: | |
221 | case ACPI_TYPE_REGION: | |
222 | ||
223 | /* Return an additional reference to the object */ | |
224 | ||
225 | obj_desc = source_desc; | |
4be44fcd | 226 | acpi_ut_add_reference(obj_desc); |
1da177e4 LT |
227 | break; |
228 | ||
4be44fcd | 229 | /* TYPE_ANY is untyped, and thus there is no object associated with it */ |
1da177e4 LT |
230 | |
231 | case ACPI_TYPE_ANY: | |
232 | ||
b8e4d893 BM |
233 | ACPI_ERROR((AE_INFO, |
234 | "Untyped entry %p, no attached object!", node)); | |
1da177e4 | 235 | |
4be44fcd | 236 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */ |
1da177e4 LT |
237 | |
238 | case ACPI_TYPE_LOCAL_REFERENCE: | |
239 | ||
240 | switch (source_desc->reference.opcode) { | |
241 | case AML_LOAD_OP: | |
242 | ||
243 | /* This is a ddb_handle */ | |
244 | /* Return an additional reference to the object */ | |
245 | ||
52fc0b02 BM |
246 | case AML_REF_OF_OP: |
247 | ||
1da177e4 | 248 | obj_desc = source_desc; |
4be44fcd | 249 | acpi_ut_add_reference(obj_desc); |
1da177e4 LT |
250 | break; |
251 | ||
252 | default: | |
253 | /* No named references are allowed here */ | |
254 | ||
b8e4d893 BM |
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))); | |
1da177e4 | 260 | |
4be44fcd | 261 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 LT |
262 | } |
263 | break; | |
264 | ||
1da177e4 LT |
265 | default: |
266 | ||
44f6c012 RM |
267 | /* Default case is for unknown types */ |
268 | ||
b8e4d893 BM |
269 | ACPI_ERROR((AE_INFO, |
270 | "Node %p - Unknown object type %X", | |
271 | node, entry_type)); | |
1da177e4 | 272 | |
4be44fcd | 273 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
1da177e4 | 274 | |
4be44fcd | 275 | } /* switch (entry_type) */ |
1da177e4 | 276 | |
44f6c012 | 277 | /* Return the object descriptor */ |
1da177e4 | 278 | |
4be44fcd LB |
279 | *object_ptr = (void *)obj_desc; |
280 | return_ACPI_STATUS(status); | |
1da177e4 | 281 | } |