]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/acpi/acpica/exstorob.c
Merge branches 'for-4.11/upstream-fixes', 'for-4.12/accutouch', 'for-4.12/cp2112...
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / acpica / exstorob.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
1fad8738 3 * Module Name: exstorob - AML object store support, store to object
1da177e4
LT
4 *
5 *****************************************************************************/
6
7/*
7735ca0e 8 * Copyright (C) 2000 - 2017, Intel Corp.
1da177e4
LT
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
1da177e4 44#include <acpi/acpi.h>
e2f7a777
LB
45#include "accommon.h"
46#include "acinterp.h"
1da177e4 47
1da177e4 48#define _COMPONENT ACPI_EXECUTER
4be44fcd 49ACPI_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 63acpi_status
4be44fcd
LB
64acpi_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
b229cf92 70 ACPI_FUNCTION_TRACE_PTR(ex_store_buffer_to_buffer, source_desc);
1da177e4 71
b0de22bd
LM
72 /* If Source and Target are the same, just return */
73
74 if (source_desc == target_desc) {
75 return_ACPI_STATUS(AE_OK);
76 }
77
1da177e4
LT
78 /* We know that source_desc is a buffer by now */
79
c51a4de8 80 buffer = ACPI_CAST_PTR(u8, source_desc->buffer.pointer);
1da177e4
LT
81 length = source_desc->buffer.length;
82
83 /*
84 * If target is a buffer of length zero or is a static buffer,
85 * allocate a new buffer of the proper length
86 */
87 if ((target_desc->buffer.length == 0) ||
4be44fcd 88 (target_desc->common.flags & AOPOBJ_STATIC_POINTER)) {
8313524a 89 target_desc->buffer.pointer = ACPI_ALLOCATE(length);
1da177e4 90 if (!target_desc->buffer.pointer) {
4be44fcd 91 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
92 }
93
94 target_desc->buffer.length = length;
95 }
96
97 /* Copy source buffer to target buffer */
98
99 if (length <= target_desc->buffer.length) {
52fc0b02 100
1da177e4
LT
101 /* Clear existing buffer and copy in the new one */
102
4fa4616e
BM
103 memset(target_desc->buffer.pointer, 0,
104 target_desc->buffer.length);
105 memcpy(target_desc->buffer.pointer, buffer, length);
1da177e4
LT
106
107#ifdef ACPI_OBSOLETE_BEHAVIOR
108 /*
109 * NOTE: ACPI versions up to 3.0 specified that the buffer must be
73a3090a 110 * truncated if the string is smaller than the buffer. However, "other"
1da177e4 111 * implementations of ACPI never did this and thus became the defacto
ba494bee 112 * standard. ACPI 3.0A changes this behavior such that the buffer
1da177e4
LT
113 * is no longer truncated.
114 */
115
116 /*
117 * OBSOLETE BEHAVIOR:
118 * If the original source was a string, we must truncate the buffer,
73a3090a 119 * according to the ACPI spec. Integer-to-Buffer and Buffer-to-Buffer
1da177e4
LT
120 * copy must not truncate the original buffer.
121 */
122 if (original_src_type == ACPI_TYPE_STRING) {
52fc0b02 123
1da177e4
LT
124 /* Set the new length of the target */
125
126 target_desc->buffer.length = length;
127 }
128#endif
4be44fcd 129 } else {
1da177e4
LT
130 /* Truncate the source, copy only what will fit */
131
4fa4616e
BM
132 memcpy(target_desc->buffer.pointer, buffer,
133 target_desc->buffer.length);
1da177e4 134
4be44fcd
LB
135 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
136 "Truncating source buffer from %X to %X\n",
137 length, target_desc->buffer.length));
1da177e4
LT
138 }
139
140 /* Copy flags */
141
142 target_desc->buffer.flags = source_desc->buffer.flags;
143 target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
4be44fcd 144 return_ACPI_STATUS(AE_OK);
1da177e4
LT
145}
146
1da177e4
LT
147/*******************************************************************************
148 *
149 * FUNCTION: acpi_ex_store_string_to_string
150 *
151 * PARAMETERS: source_desc - Source object to copy
152 * target_desc - Destination object of the copy
153 *
154 * RETURN: Status
155 *
156 * DESCRIPTION: Copy a String object to another String object
157 *
158 ******************************************************************************/
159
160acpi_status
4be44fcd
LB
161acpi_ex_store_string_to_string(union acpi_operand_object *source_desc,
162 union acpi_operand_object *target_desc)
1da177e4 163{
4be44fcd
LB
164 u32 length;
165 u8 *buffer;
1da177e4 166
b229cf92 167 ACPI_FUNCTION_TRACE_PTR(ex_store_string_to_string, source_desc);
1da177e4 168
b0de22bd
LM
169 /* If Source and Target are the same, just return */
170
171 if (source_desc == target_desc) {
172 return_ACPI_STATUS(AE_OK);
173 }
174
1da177e4
LT
175 /* We know that source_desc is a string by now */
176
c51a4de8 177 buffer = ACPI_CAST_PTR(u8, source_desc->string.pointer);
1da177e4
LT
178 length = source_desc->string.length;
179
180 /*
181 * Replace existing string value if it will fit and the string
182 * pointer is not a static pointer (part of an ACPI table)
183 */
184 if ((length < target_desc->string.length) &&
4be44fcd 185 (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
1da177e4
LT
186 /*
187 * String will fit in existing non-static buffer.
188 * Clear old string and copy in the new one
189 */
4fa4616e 190 memset(target_desc->string.pointer, 0,
f5c1e1c5 191 (acpi_size)target_desc->string.length + 1);
4fa4616e 192 memcpy(target_desc->string.pointer, buffer, length);
4be44fcd 193 } else {
1da177e4
LT
194 /*
195 * Free the current buffer, then allocate a new buffer
196 * large enough to hold the value
197 */
198 if (target_desc->string.pointer &&
4be44fcd 199 (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
52fc0b02 200
1da177e4
LT
201 /* Only free if not a pointer into the DSDT */
202
8313524a 203 ACPI_FREE(target_desc->string.pointer);
1da177e4
LT
204 }
205
1fad8738 206 target_desc->string.pointer =
f5c1e1c5 207 ACPI_ALLOCATE_ZEROED((acpi_size)length + 1);
1fad8738 208
1da177e4 209 if (!target_desc->string.pointer) {
4be44fcd 210 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
211 }
212
213 target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
4fa4616e 214 memcpy(target_desc->string.pointer, buffer, length);
1da177e4
LT
215 }
216
217 /* Set the new target length */
218
219 target_desc->string.length = length;
4be44fcd 220 return_ACPI_STATUS(AE_OK);
1da177e4 221}