blob: 1cefe777068eef26b2d66851418c7992ede3244a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: exstoren - AML Interpreter object store support,
4 * Store to Node (namespace object)
5 *
6 *****************************************************************************/
7
8/*
Bob Moore25f044e2013-01-25 05:38:56 +00009 * Copyright (C) 2000 - 2013, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050046#include "accommon.h"
47#include "acinterp.h"
48#include "amlcode.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
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 *
Bob Moore73a30902012-10-31 02:26:55 +000063 * DESCRIPTION: Resolve an object. If the object is a reference, dereference
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 * 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
Bob Mooreb229cf92006-04-21 17:15:00 -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
Bob Moore73a30902012-10-31 02:26:55 +000095 * are all essentially the same. This case handles the
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 * "interchangeable" types Integer, String, and Buffer.
97 */
Bob Moore3371c192009-02-18 14:44:03 +080098 if (source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) {
Bob Moore52fc0b02006-10-02 00:00:00 -040099
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
Bob Moore3371c192009-02-18 14:44:03 +0800118 if ((source_desc->common.type != ACPI_TYPE_INTEGER) &&
119 (source_desc->common.type != ACPI_TYPE_BUFFER) &&
120 (source_desc->common.type != ACPI_TYPE_STRING) &&
121 !((source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) &&
122 (source_desc->reference.class == ACPI_REFCLASS_TABLE))) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400123
Robert Moore44f6c012005-04-18 22:49:35 -0400124 /* Conversion successful but still not a valid type */
125
Bob Mooreb8e4d892006-01-27 16:43:00 -0500126 ACPI_ERROR((AE_INFO,
127 "Cannot assign type %s to %s (must be type Int/Str/Buf)",
128 acpi_ut_get_object_type_name(source_desc),
129 acpi_ut_get_type_name(target_type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 status = AE_AML_OPERAND_TYPE;
131 }
132 break;
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 case ACPI_TYPE_LOCAL_ALIAS:
135 case ACPI_TYPE_LOCAL_METHOD_ALIAS:
136
Bob Mooreb8e4d892006-01-27 16:43:00 -0500137 /*
138 * All aliases should have been resolved earlier, during the
139 * operand resolution phase.
140 */
141 ACPI_ERROR((AE_INFO, "Store into an unresolved Alias object"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 status = AE_AML_INTERNAL;
143 break;
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 case ACPI_TYPE_PACKAGE:
146 default:
147
148 /*
149 * All other types than Alias and the various Fields come here,
150 * including the untyped case - ACPI_TYPE_ANY.
151 */
152 break;
153 }
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158/*******************************************************************************
159 *
160 * FUNCTION: acpi_ex_store_object_to_object
161 *
162 * PARAMETERS: source_desc - Object to store
163 * dest_desc - Object to receive a copy of the source
164 * new_desc - New object if dest_desc is obsoleted
165 * walk_state - Current walk state
166 *
167 * RETURN: Status
168 *
Bob Moore73a30902012-10-31 02:26:55 +0000169 * DESCRIPTION: "Store" an object to another object. This may include
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 * converting the source type to the target type (implicit
171 * conversion), and a copy of the value of the source to
172 * the target.
173 *
174 * The Assignment of an object to another (not named) object
175 * is handled here.
176 * The Source passed in will replace the current value (if any)
177 * with the input value.
178 *
179 * When storing into an object the data is converted to the
Bob Moore73a30902012-10-31 02:26:55 +0000180 * target object type then stored in the object. This means
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 * that the target object type (for an initialized target) will
182 * not be changed by a store operation.
183 *
184 * This module allows destination types of Number, String,
185 * Buffer, and Package.
186 *
Bob Moore73a30902012-10-31 02:26:55 +0000187 * Assumes parameters are already validated. NOTE: source_desc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 * resolution (from a reference object) must be performed by
189 * the caller if necessary.
190 *
191 ******************************************************************************/
192
193acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400194acpi_ex_store_object_to_object(union acpi_operand_object *source_desc,
195 union acpi_operand_object *dest_desc,
196 union acpi_operand_object **new_desc,
197 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
Len Brown4be44fc2005-08-05 00:44:28 -0400199 union acpi_operand_object *actual_src_desc;
200 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Bob Mooreb229cf92006-04-21 17:15:00 -0400202 ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_object, source_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 actual_src_desc = source_desc;
205 if (!dest_desc) {
206 /*
207 * There is no destination object (An uninitialized node or
208 * package element), so we can simply copy the source object
209 * creating a new destination object
210 */
Len Brown4be44fc2005-08-05 00:44:28 -0400211 status =
212 acpi_ut_copy_iobject_to_iobject(actual_src_desc, new_desc,
213 walk_state);
214 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216
Bob Moore3371c192009-02-18 14:44:03 +0800217 if (source_desc->common.type != dest_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 /*
219 * The source type does not match the type of the destination.
220 * Perform the "implicit conversion" of the source to the current type
221 * of the target as per the ACPI specification.
222 *
223 * If no conversion performed, actual_src_desc = source_desc.
224 * Otherwise, actual_src_desc is a temporary object to hold the
225 * converted object.
226 */
Bob Moore3371c192009-02-18 14:44:03 +0800227 status = acpi_ex_convert_to_target_type(dest_desc->common.type,
228 source_desc,
229 &actual_src_desc,
230 walk_state);
Len Brown4be44fc2005-08-05 00:44:28 -0400231 if (ACPI_FAILURE(status)) {
232 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 }
234
235 if (source_desc == actual_src_desc) {
236 /*
237 * No conversion was performed. Return the source_desc as the
238 * new object.
239 */
240 *new_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400241 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 }
243 }
244
245 /*
246 * We now have two objects of identical types, and we can perform a
247 * copy of the *value* of the source object.
248 */
Bob Moore3371c192009-02-18 14:44:03 +0800249 switch (dest_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 case ACPI_TYPE_INTEGER:
251
252 dest_desc->integer.value = actual_src_desc->integer.value;
253
254 /* Truncate value if we are executing from a 32-bit ACPI table */
255
Bob Mooreef42e532012-12-31 00:07:18 +0000256 (void)acpi_ex_truncate_for32bit_table(dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 break;
258
259 case ACPI_TYPE_STRING:
260
Len Brown4be44fc2005-08-05 00:44:28 -0400261 status =
262 acpi_ex_store_string_to_string(actual_src_desc, dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 break;
264
265 case ACPI_TYPE_BUFFER:
266
Len Brown4be44fc2005-08-05 00:44:28 -0400267 status =
268 acpi_ex_store_buffer_to_buffer(actual_src_desc, dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 break;
270
271 case ACPI_TYPE_PACKAGE:
272
Len Brown4be44fc2005-08-05 00:44:28 -0400273 status =
274 acpi_ut_copy_iobject_to_iobject(actual_src_desc, &dest_desc,
275 walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 break;
277
278 default:
279 /*
280 * All other types come here.
281 */
Bob Mooreb8e4d892006-01-27 16:43:00 -0500282 ACPI_WARNING((AE_INFO, "Store into type %s not implemented",
283 acpi_ut_get_object_type_name(dest_desc)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 status = AE_NOT_IMPLEMENTED;
286 break;
287 }
288
289 if (actual_src_desc != source_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 /* Delete the intermediate (temporary) source object */
292
Len Brown4be44fc2005-08-05 00:44:28 -0400293 acpi_ut_remove_reference(actual_src_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
295
296 *new_desc = dest_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400297 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}