Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | |
2 | /****************************************************************************** | |
3 | * | |
4 | * Module Name: exstoren - AML Interpreter object store support, | |
5 | * Store to Node (namespace object) | |
6 | * | |
7 | *****************************************************************************/ | |
8 | ||
9 | /* | |
75a44ce0 | 10 | * Copyright (C) 2000 - 2008, Intel Corp. |
1da177e4 LT |
11 | * All rights reserved. |
12 | * | |
13 | * Redistribution and use in source and binary forms, with or without | |
14 | * modification, are permitted provided that the following conditions | |
15 | * are met: | |
16 | * 1. Redistributions of source code must retain the above copyright | |
17 | * notice, this list of conditions, and the following disclaimer, | |
18 | * without modification. | |
19 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
20 | * substantially similar to the "NO WARRANTY" disclaimer below | |
21 | * ("Disclaimer") and any redistribution must be conditioned upon | |
22 | * including a substantially similar Disclaimer requirement for further | |
23 | * binary redistribution. | |
24 | * 3. Neither the names of the above-listed copyright holders nor the names | |
25 | * of any contributors may be used to endorse or promote products derived | |
26 | * from this software without specific prior written permission. | |
27 | * | |
28 | * Alternatively, this software may be distributed under the terms of the | |
29 | * GNU General Public License ("GPL") version 2 as published by the Free | |
30 | * Software Foundation. | |
31 | * | |
32 | * NO WARRANTY | |
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
37 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
38 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
39 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
40 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
41 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
42 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
43 | * POSSIBILITY OF SUCH DAMAGES. | |
44 | */ | |
45 | ||
1da177e4 | 46 | #include <acpi/acpi.h> |
e2f7a777 LB |
47 | #include "accommon.h" |
48 | #include "acinterp.h" | |
49 | #include "amlcode.h" | |
1da177e4 | 50 | |
1da177e4 | 51 | #define _COMPONENT ACPI_EXECUTER |
4be44fcd | 52 | ACPI_MODULE_NAME("exstoren") |
1da177e4 LT |
53 | |
54 | /******************************************************************************* | |
55 | * | |
56 | * FUNCTION: acpi_ex_resolve_object | |
57 | * | |
58 | * PARAMETERS: source_desc_ptr - Pointer to the source object | |
59 | * target_type - Current type of the target | |
60 | * walk_state - Current walk state | |
61 | * | |
62 | * RETURN: Status, resolved object in source_desc_ptr. | |
63 | * | |
64 | * DESCRIPTION: Resolve an object. If the object is a reference, dereference | |
65 | * it and return the actual object in the source_desc_ptr. | |
66 | * | |
67 | ******************************************************************************/ | |
1da177e4 | 68 | acpi_status |
4be44fcd LB |
69 | acpi_ex_resolve_object(union acpi_operand_object **source_desc_ptr, |
70 | acpi_object_type target_type, | |
71 | struct acpi_walk_state *walk_state) | |
1da177e4 | 72 | { |
4be44fcd LB |
73 | union acpi_operand_object *source_desc = *source_desc_ptr; |
74 | acpi_status status = AE_OK; | |
1da177e4 | 75 | |
b229cf92 | 76 | ACPI_FUNCTION_TRACE(ex_resolve_object); |
1da177e4 | 77 | |
44f6c012 RM |
78 | /* Ensure we have a Target that can be stored to */ |
79 | ||
1da177e4 LT |
80 | switch (target_type) { |
81 | case ACPI_TYPE_BUFFER_FIELD: | |
82 | case ACPI_TYPE_LOCAL_REGION_FIELD: | |
83 | case ACPI_TYPE_LOCAL_BANK_FIELD: | |
84 | case ACPI_TYPE_LOCAL_INDEX_FIELD: | |
85 | /* | |
86 | * These cases all require only Integers or values that | |
87 | * can be converted to Integers (Strings or Buffers) | |
88 | */ | |
89 | ||
90 | case ACPI_TYPE_INTEGER: | |
91 | case ACPI_TYPE_STRING: | |
92 | case ACPI_TYPE_BUFFER: | |
93 | ||
94 | /* | |
95 | * Stores into a Field/Region or into a Integer/Buffer/String | |
96 | * are all essentially the same. This case handles the | |
97 | * "interchangeable" types Integer, String, and Buffer. | |
98 | */ | |
4be44fcd LB |
99 | if (ACPI_GET_OBJECT_TYPE(source_desc) == |
100 | ACPI_TYPE_LOCAL_REFERENCE) { | |
52fc0b02 | 101 | |
1da177e4 LT |
102 | /* Resolve a reference object first */ |
103 | ||
4be44fcd LB |
104 | status = |
105 | acpi_ex_resolve_to_value(source_desc_ptr, | |
106 | walk_state); | |
107 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
108 | break; |
109 | } | |
110 | } | |
111 | ||
112 | /* For copy_object, no further validation necessary */ | |
113 | ||
114 | if (walk_state->opcode == AML_COPY_OP) { | |
115 | break; | |
116 | } | |
117 | ||
44f6c012 RM |
118 | /* Must have a Integer, Buffer, or String */ |
119 | ||
4be44fcd LB |
120 | if ((ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) && |
121 | (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) && | |
122 | (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) && | |
123 | !((ACPI_GET_OBJECT_TYPE(source_desc) == | |
124 | ACPI_TYPE_LOCAL_REFERENCE) | |
1044f1f6 BM |
125 | && (source_desc->reference.class == |
126 | ACPI_REFCLASS_TABLE))) { | |
52fc0b02 | 127 | |
44f6c012 RM |
128 | /* Conversion successful but still not a valid type */ |
129 | ||
b8e4d893 BM |
130 | ACPI_ERROR((AE_INFO, |
131 | "Cannot assign type %s to %s (must be type Int/Str/Buf)", | |
132 | acpi_ut_get_object_type_name(source_desc), | |
133 | acpi_ut_get_type_name(target_type))); | |
1da177e4 LT |
134 | status = AE_AML_OPERAND_TYPE; |
135 | } | |
136 | break; | |
137 | ||
1da177e4 LT |
138 | case ACPI_TYPE_LOCAL_ALIAS: |
139 | case ACPI_TYPE_LOCAL_METHOD_ALIAS: | |
140 | ||
b8e4d893 BM |
141 | /* |
142 | * All aliases should have been resolved earlier, during the | |
143 | * operand resolution phase. | |
144 | */ | |
145 | ACPI_ERROR((AE_INFO, "Store into an unresolved Alias object")); | |
1da177e4 LT |
146 | status = AE_AML_INTERNAL; |
147 | break; | |
148 | ||
1da177e4 LT |
149 | case ACPI_TYPE_PACKAGE: |
150 | default: | |
151 | ||
152 | /* | |
153 | * All other types than Alias and the various Fields come here, | |
154 | * including the untyped case - ACPI_TYPE_ANY. | |
155 | */ | |
156 | break; | |
157 | } | |
158 | ||
4be44fcd | 159 | return_ACPI_STATUS(status); |
1da177e4 LT |
160 | } |
161 | ||
1da177e4 LT |
162 | /******************************************************************************* |
163 | * | |
164 | * FUNCTION: acpi_ex_store_object_to_object | |
165 | * | |
166 | * PARAMETERS: source_desc - Object to store | |
167 | * dest_desc - Object to receive a copy of the source | |
168 | * new_desc - New object if dest_desc is obsoleted | |
169 | * walk_state - Current walk state | |
170 | * | |
171 | * RETURN: Status | |
172 | * | |
173 | * DESCRIPTION: "Store" an object to another object. This may include | |
174 | * converting the source type to the target type (implicit | |
175 | * conversion), and a copy of the value of the source to | |
176 | * the target. | |
177 | * | |
178 | * The Assignment of an object to another (not named) object | |
179 | * is handled here. | |
180 | * The Source passed in will replace the current value (if any) | |
181 | * with the input value. | |
182 | * | |
183 | * When storing into an object the data is converted to the | |
184 | * target object type then stored in the object. This means | |
185 | * that the target object type (for an initialized target) will | |
186 | * not be changed by a store operation. | |
187 | * | |
188 | * This module allows destination types of Number, String, | |
189 | * Buffer, and Package. | |
190 | * | |
191 | * Assumes parameters are already validated. NOTE: source_desc | |
192 | * resolution (from a reference object) must be performed by | |
193 | * the caller if necessary. | |
194 | * | |
195 | ******************************************************************************/ | |
196 | ||
197 | acpi_status | |
4be44fcd LB |
198 | acpi_ex_store_object_to_object(union acpi_operand_object *source_desc, |
199 | union acpi_operand_object *dest_desc, | |
200 | union acpi_operand_object **new_desc, | |
201 | struct acpi_walk_state *walk_state) | |
1da177e4 | 202 | { |
4be44fcd LB |
203 | union acpi_operand_object *actual_src_desc; |
204 | acpi_status status = AE_OK; | |
1da177e4 | 205 | |
b229cf92 | 206 | ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_object, source_desc); |
1da177e4 LT |
207 | |
208 | actual_src_desc = source_desc; | |
209 | if (!dest_desc) { | |
210 | /* | |
211 | * There is no destination object (An uninitialized node or | |
212 | * package element), so we can simply copy the source object | |
213 | * creating a new destination object | |
214 | */ | |
4be44fcd LB |
215 | status = |
216 | acpi_ut_copy_iobject_to_iobject(actual_src_desc, new_desc, | |
217 | walk_state); | |
218 | return_ACPI_STATUS(status); | |
1da177e4 LT |
219 | } |
220 | ||
4be44fcd LB |
221 | if (ACPI_GET_OBJECT_TYPE(source_desc) != |
222 | ACPI_GET_OBJECT_TYPE(dest_desc)) { | |
1da177e4 LT |
223 | /* |
224 | * The source type does not match the type of the destination. | |
225 | * Perform the "implicit conversion" of the source to the current type | |
226 | * of the target as per the ACPI specification. | |
227 | * | |
228 | * If no conversion performed, actual_src_desc = source_desc. | |
229 | * Otherwise, actual_src_desc is a temporary object to hold the | |
230 | * converted object. | |
231 | */ | |
4be44fcd LB |
232 | status = |
233 | acpi_ex_convert_to_target_type(ACPI_GET_OBJECT_TYPE | |
234 | (dest_desc), source_desc, | |
235 | &actual_src_desc, | |
236 | walk_state); | |
237 | if (ACPI_FAILURE(status)) { | |
238 | return_ACPI_STATUS(status); | |
1da177e4 LT |
239 | } |
240 | ||
241 | if (source_desc == actual_src_desc) { | |
242 | /* | |
243 | * No conversion was performed. Return the source_desc as the | |
244 | * new object. | |
245 | */ | |
246 | *new_desc = source_desc; | |
4be44fcd | 247 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
248 | } |
249 | } | |
250 | ||
251 | /* | |
252 | * We now have two objects of identical types, and we can perform a | |
253 | * copy of the *value* of the source object. | |
254 | */ | |
4be44fcd | 255 | switch (ACPI_GET_OBJECT_TYPE(dest_desc)) { |
1da177e4 LT |
256 | case ACPI_TYPE_INTEGER: |
257 | ||
258 | dest_desc->integer.value = actual_src_desc->integer.value; | |
259 | ||
260 | /* Truncate value if we are executing from a 32-bit ACPI table */ | |
261 | ||
4be44fcd | 262 | acpi_ex_truncate_for32bit_table(dest_desc); |
1da177e4 LT |
263 | break; |
264 | ||
265 | case ACPI_TYPE_STRING: | |
266 | ||
4be44fcd LB |
267 | status = |
268 | acpi_ex_store_string_to_string(actual_src_desc, dest_desc); | |
1da177e4 LT |
269 | break; |
270 | ||
271 | case ACPI_TYPE_BUFFER: | |
272 | ||
4be44fcd LB |
273 | status = |
274 | acpi_ex_store_buffer_to_buffer(actual_src_desc, dest_desc); | |
1da177e4 LT |
275 | break; |
276 | ||
277 | case ACPI_TYPE_PACKAGE: | |
278 | ||
4be44fcd LB |
279 | status = |
280 | acpi_ut_copy_iobject_to_iobject(actual_src_desc, &dest_desc, | |
281 | walk_state); | |
1da177e4 LT |
282 | break; |
283 | ||
284 | default: | |
285 | /* | |
286 | * All other types come here. | |
287 | */ | |
b8e4d893 BM |
288 | ACPI_WARNING((AE_INFO, "Store into type %s not implemented", |
289 | acpi_ut_get_object_type_name(dest_desc))); | |
1da177e4 LT |
290 | |
291 | status = AE_NOT_IMPLEMENTED; | |
292 | break; | |
293 | } | |
294 | ||
295 | if (actual_src_desc != source_desc) { | |
52fc0b02 | 296 | |
1da177e4 LT |
297 | /* Delete the intermediate (temporary) source object */ |
298 | ||
4be44fcd | 299 | acpi_ut_remove_reference(actual_src_desc); |
1da177e4 LT |
300 | } |
301 | ||
302 | *new_desc = dest_desc; | |
4be44fcd | 303 | return_ACPI_STATUS(status); |
1da177e4 | 304 | } |