blob: 25bbc1d78547f1574ecd980dd4a482b2f24a0232 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/******************************************************************************
3 *
4 * Module Name: exstoren - AML Interpreter object store support,
5 * Store to Node (namespace object)
6 *
7 *****************************************************************************/
8
9/*
Bob Moore4a90c7e2006-01-13 16:22:00 -050010 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <acpi/acpi.h>
47#include <acpi/acinterp.h>
48#include <acpi/amlcode.h>
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define _COMPONENT ACPI_EXECUTER
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("exstoren")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_ex_resolve_object
56 *
57 * PARAMETERS: source_desc_ptr - Pointer to the source object
58 * target_type - Current type of the target
59 * walk_state - Current walk state
60 *
61 * RETURN: Status, resolved object in source_desc_ptr.
62 *
63 * DESCRIPTION: Resolve an object. If the object is a reference, dereference
64 * it and return the actual object in the source_desc_ptr.
65 *
66 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070067acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040068acpi_ex_resolve_object(union acpi_operand_object **source_desc_ptr,
69 acpi_object_type target_type,
70 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Len Brown4be44fc2005-08-05 00:44:28 -040072 union acpi_operand_object *source_desc = *source_desc_ptr;
73 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Len Brown4be44fc2005-08-05 00:44:28 -040075 ACPI_FUNCTION_TRACE("ex_resolve_object");
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Robert Moore44f6c012005-04-18 22:49:35 -040077 /* Ensure we have a Target that can be stored to */
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 switch (target_type) {
80 case ACPI_TYPE_BUFFER_FIELD:
81 case ACPI_TYPE_LOCAL_REGION_FIELD:
82 case ACPI_TYPE_LOCAL_BANK_FIELD:
83 case ACPI_TYPE_LOCAL_INDEX_FIELD:
84 /*
85 * These cases all require only Integers or values that
86 * can be converted to Integers (Strings or Buffers)
87 */
88
89 case ACPI_TYPE_INTEGER:
90 case ACPI_TYPE_STRING:
91 case ACPI_TYPE_BUFFER:
92
93 /*
94 * Stores into a Field/Region or into a Integer/Buffer/String
95 * are all essentially the same. This case handles the
96 * "interchangeable" types Integer, String, and Buffer.
97 */
Len Brown4be44fc2005-08-05 00:44:28 -040098 if (ACPI_GET_OBJECT_TYPE(source_desc) ==
99 ACPI_TYPE_LOCAL_REFERENCE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 /* Resolve a reference object first */
101
Len Brown4be44fc2005-08-05 00:44:28 -0400102 status =
103 acpi_ex_resolve_to_value(source_desc_ptr,
104 walk_state);
105 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 break;
107 }
108 }
109
110 /* For copy_object, no further validation necessary */
111
112 if (walk_state->opcode == AML_COPY_OP) {
113 break;
114 }
115
Robert Moore44f6c012005-04-18 22:49:35 -0400116 /* Must have a Integer, Buffer, or String */
117
Len Brown4be44fc2005-08-05 00:44:28 -0400118 if ((ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) &&
119 (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) &&
120 (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) &&
121 !((ACPI_GET_OBJECT_TYPE(source_desc) ==
122 ACPI_TYPE_LOCAL_REFERENCE)
123 && (source_desc->reference.opcode == AML_LOAD_OP))) {
Robert Moore44f6c012005-04-18 22:49:35 -0400124 /* Conversion successful but still not a valid type */
125
Bob Moore4a90c7e2006-01-13 16:22:00 -0500126 ACPI_REPORT_ERROR(("Cannot assign type %s to %s (must be type Int/Str/Buf)\n", acpi_ut_get_object_type_name(source_desc), acpi_ut_get_type_name(target_type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 status = AE_AML_OPERAND_TYPE;
128 }
129 break;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 case ACPI_TYPE_LOCAL_ALIAS:
132 case ACPI_TYPE_LOCAL_METHOD_ALIAS:
133
Robert Moore44f6c012005-04-18 22:49:35 -0400134 /* Aliases are resolved by acpi_ex_prep_operands */
135
Len Brown4be44fc2005-08-05 00:44:28 -0400136 ACPI_REPORT_ERROR(("Store into Alias - should never happen\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 status = AE_AML_INTERNAL;
138 break;
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 case ACPI_TYPE_PACKAGE:
141 default:
142
143 /*
144 * All other types than Alias and the various Fields come here,
145 * including the untyped case - ACPI_TYPE_ANY.
146 */
147 break;
148 }
149
Len Brown4be44fc2005-08-05 00:44:28 -0400150 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153/*******************************************************************************
154 *
155 * FUNCTION: acpi_ex_store_object_to_object
156 *
157 * PARAMETERS: source_desc - Object to store
158 * dest_desc - Object to receive a copy of the source
159 * new_desc - New object if dest_desc is obsoleted
160 * walk_state - Current walk state
161 *
162 * RETURN: Status
163 *
164 * DESCRIPTION: "Store" an object to another object. This may include
165 * converting the source type to the target type (implicit
166 * conversion), and a copy of the value of the source to
167 * the target.
168 *
169 * The Assignment of an object to another (not named) object
170 * is handled here.
171 * The Source passed in will replace the current value (if any)
172 * with the input value.
173 *
174 * When storing into an object the data is converted to the
175 * target object type then stored in the object. This means
176 * that the target object type (for an initialized target) will
177 * not be changed by a store operation.
178 *
179 * This module allows destination types of Number, String,
180 * Buffer, and Package.
181 *
182 * Assumes parameters are already validated. NOTE: source_desc
183 * resolution (from a reference object) must be performed by
184 * the caller if necessary.
185 *
186 ******************************************************************************/
187
188acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400189acpi_ex_store_object_to_object(union acpi_operand_object *source_desc,
190 union acpi_operand_object *dest_desc,
191 union acpi_operand_object **new_desc,
192 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
Len Brown4be44fc2005-08-05 00:44:28 -0400194 union acpi_operand_object *actual_src_desc;
195 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Len Brown4be44fc2005-08-05 00:44:28 -0400197 ACPI_FUNCTION_TRACE_PTR("ex_store_object_to_object", source_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199 actual_src_desc = source_desc;
200 if (!dest_desc) {
201 /*
202 * There is no destination object (An uninitialized node or
203 * package element), so we can simply copy the source object
204 * creating a new destination object
205 */
Len Brown4be44fc2005-08-05 00:44:28 -0400206 status =
207 acpi_ut_copy_iobject_to_iobject(actual_src_desc, new_desc,
208 walk_state);
209 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 }
211
Len Brown4be44fc2005-08-05 00:44:28 -0400212 if (ACPI_GET_OBJECT_TYPE(source_desc) !=
213 ACPI_GET_OBJECT_TYPE(dest_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 /*
215 * The source type does not match the type of the destination.
216 * Perform the "implicit conversion" of the source to the current type
217 * of the target as per the ACPI specification.
218 *
219 * If no conversion performed, actual_src_desc = source_desc.
220 * Otherwise, actual_src_desc is a temporary object to hold the
221 * converted object.
222 */
Len Brown4be44fc2005-08-05 00:44:28 -0400223 status =
224 acpi_ex_convert_to_target_type(ACPI_GET_OBJECT_TYPE
225 (dest_desc), source_desc,
226 &actual_src_desc,
227 walk_state);
228 if (ACPI_FAILURE(status)) {
229 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 }
231
232 if (source_desc == actual_src_desc) {
233 /*
234 * No conversion was performed. Return the source_desc as the
235 * new object.
236 */
237 *new_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400238 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 }
240 }
241
242 /*
243 * We now have two objects of identical types, and we can perform a
244 * copy of the *value* of the source object.
245 */
Len Brown4be44fc2005-08-05 00:44:28 -0400246 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 case ACPI_TYPE_INTEGER:
248
249 dest_desc->integer.value = actual_src_desc->integer.value;
250
251 /* Truncate value if we are executing from a 32-bit ACPI table */
252
Len Brown4be44fc2005-08-05 00:44:28 -0400253 acpi_ex_truncate_for32bit_table(dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 break;
255
256 case ACPI_TYPE_STRING:
257
Len Brown4be44fc2005-08-05 00:44:28 -0400258 status =
259 acpi_ex_store_string_to_string(actual_src_desc, dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 break;
261
262 case ACPI_TYPE_BUFFER:
263
Len Brown4be44fc2005-08-05 00:44:28 -0400264 status =
265 acpi_ex_store_buffer_to_buffer(actual_src_desc, dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 break;
267
268 case ACPI_TYPE_PACKAGE:
269
Len Brown4be44fc2005-08-05 00:44:28 -0400270 status =
271 acpi_ut_copy_iobject_to_iobject(actual_src_desc, &dest_desc,
272 walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 break;
274
275 default:
276 /*
277 * All other types come here.
278 */
Bob Moore4a90c7e2006-01-13 16:22:00 -0500279 ACPI_REPORT_WARNING(("Store into type %s not implemented\n",
280 acpi_ut_get_object_type_name(dest_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282 status = AE_NOT_IMPLEMENTED;
283 break;
284 }
285
286 if (actual_src_desc != source_desc) {
287 /* Delete the intermediate (temporary) source object */
288
Len Brown4be44fc2005-08-05 00:44:28 -0400289 acpi_ut_remove_reference(actual_src_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 }
291
292 *new_desc = dest_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400293 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294}