Revert "[PATCH] ACPI: fix vendor resource length computation"
[deliverable/linux.git] / drivers / acpi / executer / exstoren.c
CommitLineData
1da177e4
LT
1
2/******************************************************************************
3 *
4 * Module Name: exstoren - AML Interpreter object store support,
5 * Store to Node (namespace object)
6 *
7 *****************************************************************************/
8
9/*
4a90c7e8 10 * Copyright (C) 2000 - 2006, R. Byron Moore
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
LT
46#include <acpi/acpi.h>
47#include <acpi/acinterp.h>
48#include <acpi/amlcode.h>
49
1da177e4 50#define _COMPONENT ACPI_EXECUTER
4be44fcd 51ACPI_MODULE_NAME("exstoren")
1da177e4
LT
52
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 ******************************************************************************/
1da177e4 67acpi_status
4be44fcd
LB
68acpi_ex_resolve_object(union acpi_operand_object **source_desc_ptr,
69 acpi_object_type target_type,
70 struct acpi_walk_state *walk_state)
1da177e4 71{
4be44fcd
LB
72 union acpi_operand_object *source_desc = *source_desc_ptr;
73 acpi_status status = AE_OK;
1da177e4 74
4be44fcd 75 ACPI_FUNCTION_TRACE("ex_resolve_object");
1da177e4 76
44f6c012
RM
77 /* Ensure we have a Target that can be stored to */
78
1da177e4
LT
79 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 */
4be44fcd
LB
98 if (ACPI_GET_OBJECT_TYPE(source_desc) ==
99 ACPI_TYPE_LOCAL_REFERENCE) {
1da177e4
LT
100 /* Resolve a reference object first */
101
4be44fcd
LB
102 status =
103 acpi_ex_resolve_to_value(source_desc_ptr,
104 walk_state);
105 if (ACPI_FAILURE(status)) {
1da177e4
LT
106 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
44f6c012
RM
116 /* Must have a Integer, Buffer, or String */
117
4be44fcd
LB
118 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))) {
44f6c012
RM
124 /* Conversion successful but still not a valid type */
125
b8e4d893
BM
126 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)));
1da177e4
LT
130 status = AE_AML_OPERAND_TYPE;
131 }
132 break;
133
1da177e4
LT
134 case ACPI_TYPE_LOCAL_ALIAS:
135 case ACPI_TYPE_LOCAL_METHOD_ALIAS:
136
b8e4d893
BM
137 /*
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"));
1da177e4
LT
142 status = AE_AML_INTERNAL;
143 break;
144
1da177e4
LT
145 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
4be44fcd 155 return_ACPI_STATUS(status);
1da177e4
LT
156}
157
1da177e4
LT
158/*******************************************************************************
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 *
169 * DESCRIPTION: "Store" an object to another object. This may include
170 * 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
180 * target object type then stored in the object. This means
181 * 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 *
187 * Assumes parameters are already validated. NOTE: source_desc
188 * resolution (from a reference object) must be performed by
189 * the caller if necessary.
190 *
191 ******************************************************************************/
192
193acpi_status
4be44fcd
LB
194acpi_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)
1da177e4 198{
4be44fcd
LB
199 union acpi_operand_object *actual_src_desc;
200 acpi_status status = AE_OK;
1da177e4 201
4be44fcd 202 ACPI_FUNCTION_TRACE_PTR("ex_store_object_to_object", source_desc);
1da177e4
LT
203
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 */
4be44fcd
LB
211 status =
212 acpi_ut_copy_iobject_to_iobject(actual_src_desc, new_desc,
213 walk_state);
214 return_ACPI_STATUS(status);
1da177e4
LT
215 }
216
4be44fcd
LB
217 if (ACPI_GET_OBJECT_TYPE(source_desc) !=
218 ACPI_GET_OBJECT_TYPE(dest_desc)) {
1da177e4
LT
219 /*
220 * The source type does not match the type of the destination.
221 * Perform the "implicit conversion" of the source to the current type
222 * of the target as per the ACPI specification.
223 *
224 * If no conversion performed, actual_src_desc = source_desc.
225 * Otherwise, actual_src_desc is a temporary object to hold the
226 * converted object.
227 */
4be44fcd
LB
228 status =
229 acpi_ex_convert_to_target_type(ACPI_GET_OBJECT_TYPE
230 (dest_desc), source_desc,
231 &actual_src_desc,
232 walk_state);
233 if (ACPI_FAILURE(status)) {
234 return_ACPI_STATUS(status);
1da177e4
LT
235 }
236
237 if (source_desc == actual_src_desc) {
238 /*
239 * No conversion was performed. Return the source_desc as the
240 * new object.
241 */
242 *new_desc = source_desc;
4be44fcd 243 return_ACPI_STATUS(AE_OK);
1da177e4
LT
244 }
245 }
246
247 /*
248 * We now have two objects of identical types, and we can perform a
249 * copy of the *value* of the source object.
250 */
4be44fcd 251 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) {
1da177e4
LT
252 case ACPI_TYPE_INTEGER:
253
254 dest_desc->integer.value = actual_src_desc->integer.value;
255
256 /* Truncate value if we are executing from a 32-bit ACPI table */
257
4be44fcd 258 acpi_ex_truncate_for32bit_table(dest_desc);
1da177e4
LT
259 break;
260
261 case ACPI_TYPE_STRING:
262
4be44fcd
LB
263 status =
264 acpi_ex_store_string_to_string(actual_src_desc, dest_desc);
1da177e4
LT
265 break;
266
267 case ACPI_TYPE_BUFFER:
268
4be44fcd
LB
269 status =
270 acpi_ex_store_buffer_to_buffer(actual_src_desc, dest_desc);
1da177e4
LT
271 break;
272
273 case ACPI_TYPE_PACKAGE:
274
4be44fcd
LB
275 status =
276 acpi_ut_copy_iobject_to_iobject(actual_src_desc, &dest_desc,
277 walk_state);
1da177e4
LT
278 break;
279
280 default:
281 /*
282 * All other types come here.
283 */
b8e4d893
BM
284 ACPI_WARNING((AE_INFO, "Store into type %s not implemented",
285 acpi_ut_get_object_type_name(dest_desc)));
1da177e4
LT
286
287 status = AE_NOT_IMPLEMENTED;
288 break;
289 }
290
291 if (actual_src_desc != source_desc) {
292 /* Delete the intermediate (temporary) source object */
293
4be44fcd 294 acpi_ut_remove_reference(actual_src_desc);
1da177e4
LT
295 }
296
297 *new_desc = dest_desc;
4be44fcd 298 return_ACPI_STATUS(status);
1da177e4 299}
This page took 0.089744 seconds and 5 git commands to generate.