exstorob.c revision 1.1.1.2 1
2 /******************************************************************************
3 *
4 * Module Name: exstorob - AML Interpreter object store support, store to object
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * 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
45 #define __EXSTOROB_C__
46
47 #include "acpi.h"
48 #include "accommon.h"
49 #include "acinterp.h"
50
51
52 #define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exstorob")
54
55
56 /*******************************************************************************
57 *
58 * FUNCTION: AcpiExStoreBufferToBuffer
59 *
60 * PARAMETERS: SourceDesc - Source object to copy
61 * TargetDesc - Destination object of the copy
62 *
63 * RETURN: Status
64 *
65 * DESCRIPTION: Copy a buffer object to another buffer object.
66 *
67 ******************************************************************************/
68
69 ACPI_STATUS
70 AcpiExStoreBufferToBuffer (
71 ACPI_OPERAND_OBJECT *SourceDesc,
72 ACPI_OPERAND_OBJECT *TargetDesc)
73 {
74 UINT32 Length;
75 UINT8 *Buffer;
76
77
78 ACPI_FUNCTION_TRACE_PTR (ExStoreBufferToBuffer, SourceDesc);
79
80
81 /* If Source and Target are the same, just return */
82
83 if (SourceDesc == TargetDesc)
84 {
85 return_ACPI_STATUS (AE_OK);
86 }
87
88 /* We know that SourceDesc is a buffer by now */
89
90 Buffer = ACPI_CAST_PTR (UINT8, SourceDesc->Buffer.Pointer);
91 Length = SourceDesc->Buffer.Length;
92
93 /*
94 * If target is a buffer of length zero or is a static buffer,
95 * allocate a new buffer of the proper length
96 */
97 if ((TargetDesc->Buffer.Length == 0) ||
98 (TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER))
99 {
100 TargetDesc->Buffer.Pointer = ACPI_ALLOCATE (Length);
101 if (!TargetDesc->Buffer.Pointer)
102 {
103 return_ACPI_STATUS (AE_NO_MEMORY);
104 }
105
106 TargetDesc->Buffer.Length = Length;
107 }
108
109 /* Copy source buffer to target buffer */
110
111 if (Length <= TargetDesc->Buffer.Length)
112 {
113 /* Clear existing buffer and copy in the new one */
114
115 ACPI_MEMSET (TargetDesc->Buffer.Pointer, 0, TargetDesc->Buffer.Length);
116 ACPI_MEMCPY (TargetDesc->Buffer.Pointer, Buffer, Length);
117
118 #ifdef ACPI_OBSOLETE_BEHAVIOR
119 /*
120 * NOTE: ACPI versions up to 3.0 specified that the buffer must be
121 * truncated if the string is smaller than the buffer. However, "other"
122 * implementations of ACPI never did this and thus became the defacto
123 * standard. ACPI 3.0A changes this behavior such that the buffer
124 * is no longer truncated.
125 */
126
127 /*
128 * OBSOLETE BEHAVIOR:
129 * If the original source was a string, we must truncate the buffer,
130 * according to the ACPI spec. Integer-to-Buffer and Buffer-to-Buffer
131 * copy must not truncate the original buffer.
132 */
133 if (OriginalSrcType == ACPI_TYPE_STRING)
134 {
135 /* Set the new length of the target */
136
137 TargetDesc->Buffer.Length = Length;
138 }
139 #endif
140 }
141 else
142 {
143 /* Truncate the source, copy only what will fit */
144
145 ACPI_MEMCPY (TargetDesc->Buffer.Pointer, Buffer,
146 TargetDesc->Buffer.Length);
147
148 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
149 "Truncating source buffer from %X to %X\n",
150 Length, TargetDesc->Buffer.Length));
151 }
152
153 /* Copy flags */
154
155 TargetDesc->Buffer.Flags = SourceDesc->Buffer.Flags;
156 TargetDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
157 return_ACPI_STATUS (AE_OK);
158 }
159
160
161 /*******************************************************************************
162 *
163 * FUNCTION: AcpiExStoreStringToString
164 *
165 * PARAMETERS: SourceDesc - Source object to copy
166 * TargetDesc - Destination object of the copy
167 *
168 * RETURN: Status
169 *
170 * DESCRIPTION: Copy a String object to another String object
171 *
172 ******************************************************************************/
173
174 ACPI_STATUS
175 AcpiExStoreStringToString (
176 ACPI_OPERAND_OBJECT *SourceDesc,
177 ACPI_OPERAND_OBJECT *TargetDesc)
178 {
179 UINT32 Length;
180 UINT8 *Buffer;
181
182
183 ACPI_FUNCTION_TRACE_PTR (ExStoreStringToString, SourceDesc);
184
185
186 /* If Source and Target are the same, just return */
187
188 if (SourceDesc == TargetDesc)
189 {
190 return_ACPI_STATUS (AE_OK);
191 }
192
193 /* We know that SourceDesc is a string by now */
194
195 Buffer = ACPI_CAST_PTR (UINT8, SourceDesc->String.Pointer);
196 Length = SourceDesc->String.Length;
197
198 /*
199 * Replace existing string value if it will fit and the string
200 * pointer is not a static pointer (part of an ACPI table)
201 */
202 if ((Length < TargetDesc->String.Length) &&
203 (!(TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
204 {
205 /*
206 * String will fit in existing non-static buffer.
207 * Clear old string and copy in the new one
208 */
209 ACPI_MEMSET (TargetDesc->String.Pointer, 0,
210 (ACPI_SIZE) TargetDesc->String.Length + 1);
211 ACPI_MEMCPY (TargetDesc->String.Pointer, Buffer, Length);
212 }
213 else
214 {
215 /*
216 * Free the current buffer, then allocate a new buffer
217 * large enough to hold the value
218 */
219 if (TargetDesc->String.Pointer &&
220 (!(TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
221 {
222 /* Only free if not a pointer into the DSDT */
223
224 ACPI_FREE (TargetDesc->String.Pointer);
225 }
226
227 TargetDesc->String.Pointer = ACPI_ALLOCATE_ZEROED (
228 (ACPI_SIZE) Length + 1);
229 if (!TargetDesc->String.Pointer)
230 {
231 return_ACPI_STATUS (AE_NO_MEMORY);
232 }
233
234 TargetDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
235 ACPI_MEMCPY (TargetDesc->String.Pointer, Buffer, Length);
236 }
237
238 /* Set the new target length */
239
240 TargetDesc->String.Length = Length;
241 return_ACPI_STATUS (AE_OK);
242 }
243
244
245