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