2 /******************************************************************************
4 * Module Name: exstorob - AML Interpreter object store support, store to object
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
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.
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.
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.
45 #define __EXSTOROB_C__
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acinterp.h>
52 #define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exstorob")
56 /*******************************************************************************
58 * FUNCTION: AcpiExStoreBufferToBuffer
60 * PARAMETERS: SourceDesc - Source object to copy
61 * TargetDesc - Destination object of the copy
65 * DESCRIPTION: Copy a buffer object to another buffer object.
67 ******************************************************************************/
70 AcpiExStoreBufferToBuffer (
71 ACPI_OPERAND_OBJECT *SourceDesc,
72 ACPI_OPERAND_OBJECT *TargetDesc)
78 ACPI_FUNCTION_TRACE_PTR (ExStoreBufferToBuffer, SourceDesc);
81 /* If Source and Target are the same, just return */
83 if (SourceDesc == TargetDesc)
85 return_ACPI_STATUS (AE_OK);
88 /* We know that SourceDesc is a buffer by now */
90 Buffer = ACPI_CAST_PTR (UINT8, SourceDesc->Buffer.Pointer);
91 Length = SourceDesc->Buffer.Length;
94 * If target is a buffer of length zero or is a static buffer,
95 * allocate a new buffer of the proper length
97 if ((TargetDesc->Buffer.Length == 0) ||
98 (TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER))
100 TargetDesc->Buffer.Pointer = ACPI_ALLOCATE (Length);
101 if (!TargetDesc->Buffer.Pointer)
103 return_ACPI_STATUS (AE_NO_MEMORY);
106 TargetDesc->Buffer.Length = Length;
109 /* Copy source buffer to target buffer */
111 if (Length <= TargetDesc->Buffer.Length)
113 /* Clear existing buffer and copy in the new one */
115 ACPI_MEMSET (TargetDesc->Buffer.Pointer, 0, TargetDesc->Buffer.Length);
116 ACPI_MEMCPY (TargetDesc->Buffer.Pointer, Buffer, Length);
118 #ifdef ACPI_OBSOLETE_BEHAVIOR
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.
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.
133 if (OriginalSrcType == ACPI_TYPE_STRING)
135 /* Set the new length of the target */
137 TargetDesc->Buffer.Length = Length;
143 /* Truncate the source, copy only what will fit */
145 ACPI_MEMCPY (TargetDesc->Buffer.Pointer, Buffer,
146 TargetDesc->Buffer.Length);
148 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
149 "Truncating source buffer from %X to %X\n",
150 Length, TargetDesc->Buffer.Length));
155 TargetDesc->Buffer.Flags = SourceDesc->Buffer.Flags;
156 TargetDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
157 return_ACPI_STATUS (AE_OK);
161 /*******************************************************************************
163 * FUNCTION: AcpiExStoreStringToString
165 * PARAMETERS: SourceDesc - Source object to copy
166 * TargetDesc - Destination object of the copy
170 * DESCRIPTION: Copy a String object to another String object
172 ******************************************************************************/
175 AcpiExStoreStringToString (
176 ACPI_OPERAND_OBJECT *SourceDesc,
177 ACPI_OPERAND_OBJECT *TargetDesc)
183 ACPI_FUNCTION_TRACE_PTR (ExStoreStringToString, SourceDesc);
186 /* If Source and Target are the same, just return */
188 if (SourceDesc == TargetDesc)
190 return_ACPI_STATUS (AE_OK);
193 /* We know that SourceDesc is a string by now */
195 Buffer = ACPI_CAST_PTR (UINT8, SourceDesc->String.Pointer);
196 Length = SourceDesc->String.Length;
199 * Replace existing string value if it will fit and the string
200 * pointer is not a static pointer (part of an ACPI table)
202 if ((Length < TargetDesc->String.Length) &&
203 (!(TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
206 * String will fit in existing non-static buffer.
207 * Clear old string and copy in the new one
209 ACPI_MEMSET (TargetDesc->String.Pointer, 0,
210 (ACPI_SIZE) TargetDesc->String.Length + 1);
211 ACPI_MEMCPY (TargetDesc->String.Pointer, Buffer, Length);
216 * Free the current buffer, then allocate a new buffer
217 * large enough to hold the value
219 if (TargetDesc->String.Pointer &&
220 (!(TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
222 /* Only free if not a pointer into the DSDT */
224 ACPI_FREE (TargetDesc->String.Pointer);
227 TargetDesc->String.Pointer = ACPI_ALLOCATE_ZEROED (
228 (ACPI_SIZE) Length + 1);
229 if (!TargetDesc->String.Pointer)
231 return_ACPI_STATUS (AE_NO_MEMORY);
234 TargetDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
235 ACPI_MEMCPY (TargetDesc->String.Pointer, Buffer, Length);
238 /* Set the new target length */
240 TargetDesc->String.Length = Length;
241 return_ACPI_STATUS (AE_OK);