Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | |
2 | /****************************************************************************** | |
3 | * | |
4 | * Module Name: exstorob - AML Interpreter object store support, store to object | |
5 | * | |
6 | *****************************************************************************/ | |
7 | ||
8 | /* | |
4a90c7e8 | 9 | * Copyright (C) 2000 - 2006, R. Byron Moore |
1da177e4 LT |
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 | ||
1da177e4 LT |
45 | #include <acpi/acpi.h> |
46 | #include <acpi/acinterp.h> | |
47 | ||
1da177e4 | 48 | #define _COMPONENT ACPI_EXECUTER |
4be44fcd | 49 | ACPI_MODULE_NAME("exstorob") |
1da177e4 LT |
50 | |
51 | /******************************************************************************* | |
52 | * | |
53 | * FUNCTION: acpi_ex_store_buffer_to_buffer | |
54 | * | |
55 | * PARAMETERS: source_desc - Source object to copy | |
56 | * target_desc - Destination object of the copy | |
57 | * | |
58 | * RETURN: Status | |
59 | * | |
60 | * DESCRIPTION: Copy a buffer object to another buffer object. | |
61 | * | |
62 | ******************************************************************************/ | |
1da177e4 | 63 | acpi_status |
4be44fcd LB |
64 | acpi_ex_store_buffer_to_buffer(union acpi_operand_object *source_desc, |
65 | union acpi_operand_object *target_desc) | |
1da177e4 | 66 | { |
4be44fcd LB |
67 | u32 length; |
68 | u8 *buffer; | |
1da177e4 | 69 | |
4be44fcd | 70 | ACPI_FUNCTION_TRACE_PTR("ex_store_buffer_to_buffer", source_desc); |
1da177e4 LT |
71 | |
72 | /* We know that source_desc is a buffer by now */ | |
73 | ||
c51a4de8 | 74 | buffer = ACPI_CAST_PTR(u8, source_desc->buffer.pointer); |
1da177e4 LT |
75 | length = source_desc->buffer.length; |
76 | ||
77 | /* | |
78 | * If target is a buffer of length zero or is a static buffer, | |
79 | * allocate a new buffer of the proper length | |
80 | */ | |
81 | if ((target_desc->buffer.length == 0) || | |
4be44fcd LB |
82 | (target_desc->common.flags & AOPOBJ_STATIC_POINTER)) { |
83 | target_desc->buffer.pointer = ACPI_MEM_ALLOCATE(length); | |
1da177e4 | 84 | if (!target_desc->buffer.pointer) { |
4be44fcd | 85 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
86 | } |
87 | ||
88 | target_desc->buffer.length = length; | |
89 | } | |
90 | ||
91 | /* Copy source buffer to target buffer */ | |
92 | ||
93 | if (length <= target_desc->buffer.length) { | |
94 | /* Clear existing buffer and copy in the new one */ | |
95 | ||
4be44fcd LB |
96 | ACPI_MEMSET(target_desc->buffer.pointer, 0, |
97 | target_desc->buffer.length); | |
98 | ACPI_MEMCPY(target_desc->buffer.pointer, buffer, length); | |
1da177e4 LT |
99 | |
100 | #ifdef ACPI_OBSOLETE_BEHAVIOR | |
101 | /* | |
102 | * NOTE: ACPI versions up to 3.0 specified that the buffer must be | |
103 | * truncated if the string is smaller than the buffer. However, "other" | |
104 | * implementations of ACPI never did this and thus became the defacto | |
105 | * standard. ACPi 3.0_a changes this behavior such that the buffer | |
106 | * is no longer truncated. | |
107 | */ | |
108 | ||
109 | /* | |
110 | * OBSOLETE BEHAVIOR: | |
111 | * If the original source was a string, we must truncate the buffer, | |
112 | * according to the ACPI spec. Integer-to-Buffer and Buffer-to-Buffer | |
113 | * copy must not truncate the original buffer. | |
114 | */ | |
115 | if (original_src_type == ACPI_TYPE_STRING) { | |
116 | /* Set the new length of the target */ | |
117 | ||
118 | target_desc->buffer.length = length; | |
119 | } | |
120 | #endif | |
4be44fcd | 121 | } else { |
1da177e4 LT |
122 | /* Truncate the source, copy only what will fit */ |
123 | ||
4be44fcd LB |
124 | ACPI_MEMCPY(target_desc->buffer.pointer, buffer, |
125 | target_desc->buffer.length); | |
1da177e4 | 126 | |
4be44fcd LB |
127 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
128 | "Truncating source buffer from %X to %X\n", | |
129 | length, target_desc->buffer.length)); | |
1da177e4 LT |
130 | } |
131 | ||
132 | /* Copy flags */ | |
133 | ||
134 | target_desc->buffer.flags = source_desc->buffer.flags; | |
135 | target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER; | |
4be44fcd | 136 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
137 | } |
138 | ||
1da177e4 LT |
139 | /******************************************************************************* |
140 | * | |
141 | * FUNCTION: acpi_ex_store_string_to_string | |
142 | * | |
143 | * PARAMETERS: source_desc - Source object to copy | |
144 | * target_desc - Destination object of the copy | |
145 | * | |
146 | * RETURN: Status | |
147 | * | |
148 | * DESCRIPTION: Copy a String object to another String object | |
149 | * | |
150 | ******************************************************************************/ | |
151 | ||
152 | acpi_status | |
4be44fcd LB |
153 | acpi_ex_store_string_to_string(union acpi_operand_object *source_desc, |
154 | union acpi_operand_object *target_desc) | |
1da177e4 | 155 | { |
4be44fcd LB |
156 | u32 length; |
157 | u8 *buffer; | |
1da177e4 | 158 | |
4be44fcd | 159 | ACPI_FUNCTION_TRACE_PTR("ex_store_string_to_string", source_desc); |
1da177e4 LT |
160 | |
161 | /* We know that source_desc is a string by now */ | |
162 | ||
c51a4de8 | 163 | buffer = ACPI_CAST_PTR(u8, source_desc->string.pointer); |
1da177e4 LT |
164 | length = source_desc->string.length; |
165 | ||
166 | /* | |
167 | * Replace existing string value if it will fit and the string | |
168 | * pointer is not a static pointer (part of an ACPI table) | |
169 | */ | |
170 | if ((length < target_desc->string.length) && | |
4be44fcd | 171 | (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) { |
1da177e4 LT |
172 | /* |
173 | * String will fit in existing non-static buffer. | |
174 | * Clear old string and copy in the new one | |
175 | */ | |
4be44fcd LB |
176 | ACPI_MEMSET(target_desc->string.pointer, 0, |
177 | (acpi_size) target_desc->string.length + 1); | |
178 | ACPI_MEMCPY(target_desc->string.pointer, buffer, length); | |
179 | } else { | |
1da177e4 LT |
180 | /* |
181 | * Free the current buffer, then allocate a new buffer | |
182 | * large enough to hold the value | |
183 | */ | |
184 | if (target_desc->string.pointer && | |
4be44fcd | 185 | (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) { |
1da177e4 LT |
186 | /* Only free if not a pointer into the DSDT */ |
187 | ||
4be44fcd | 188 | ACPI_MEM_FREE(target_desc->string.pointer); |
1da177e4 LT |
189 | } |
190 | ||
4be44fcd LB |
191 | target_desc->string.pointer = ACPI_MEM_CALLOCATE((acpi_size) |
192 | length + 1); | |
1da177e4 | 193 | if (!target_desc->string.pointer) { |
4be44fcd | 194 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
195 | } |
196 | ||
197 | target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER; | |
4be44fcd | 198 | ACPI_MEMCPY(target_desc->string.pointer, buffer, length); |
1da177e4 LT |
199 | } |
200 | ||
201 | /* Set the new target length */ | |
202 | ||
203 | target_desc->string.length = length; | |
4be44fcd | 204 | return_ACPI_STATUS(AE_OK); |
1da177e4 | 205 | } |