blob: 8233d40178eed88a5d6863578ff9f78451a7b2ea [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/******************************************************************************
3 *
4 * Module Name: exstorob - AML Interpreter object store support, store to object
5 *
6 *****************************************************************************/
7
8/*
Bob Moore6c9deb72007-02-02 19:48:24 +03009 * Copyright (C) 2000 - 2007, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_EXECUTER
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("exstorob")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
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 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070063acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040064acpi_ex_store_buffer_to_buffer(union acpi_operand_object *source_desc,
65 union acpi_operand_object *target_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Len Brown4be44fc2005-08-05 00:44:28 -040067 u32 length;
68 u8 *buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Bob Mooreb229cf92006-04-21 17:15:00 -040070 ACPI_FUNCTION_TRACE_PTR(ex_store_buffer_to_buffer, source_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72 /* We know that source_desc is a buffer by now */
73
Bob Moorec51a4de2005-11-17 13:07:00 -050074 buffer = ACPI_CAST_PTR(u8, source_desc->buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 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) ||
Len Brown4be44fc2005-08-05 00:44:28 -040082 (target_desc->common.flags & AOPOBJ_STATIC_POINTER)) {
Bob Moore83135242006-10-03 00:00:00 -040083 target_desc->buffer.pointer = ACPI_ALLOCATE(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 if (!target_desc->buffer.pointer) {
Len Brown4be44fc2005-08-05 00:44:28 -040085 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 }
87
88 target_desc->buffer.length = length;
89 }
90
91 /* Copy source buffer to target buffer */
92
93 if (length <= target_desc->buffer.length) {
Bob Moore52fc0b02006-10-02 00:00:00 -040094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 /* Clear existing buffer and copy in the new one */
96
Len Brown4be44fc2005-08-05 00:44:28 -040097 ACPI_MEMSET(target_desc->buffer.pointer, 0,
98 target_desc->buffer.length);
99 ACPI_MEMCPY(target_desc->buffer.pointer, buffer, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101#ifdef ACPI_OBSOLETE_BEHAVIOR
102 /*
103 * NOTE: ACPI versions up to 3.0 specified that the buffer must be
104 * truncated if the string is smaller than the buffer. However, "other"
105 * implementations of ACPI never did this and thus became the defacto
Bob Moore958dd242006-05-12 17:12:00 -0400106 * standard. ACPI 3.0_a changes this behavior such that the buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 * is no longer truncated.
108 */
109
110 /*
111 * OBSOLETE BEHAVIOR:
112 * If the original source was a string, we must truncate the buffer,
113 * according to the ACPI spec. Integer-to-Buffer and Buffer-to-Buffer
114 * copy must not truncate the original buffer.
115 */
116 if (original_src_type == ACPI_TYPE_STRING) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 /* Set the new length of the target */
119
120 target_desc->buffer.length = length;
121 }
122#endif
Len Brown4be44fc2005-08-05 00:44:28 -0400123 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 /* Truncate the source, copy only what will fit */
125
Len Brown4be44fc2005-08-05 00:44:28 -0400126 ACPI_MEMCPY(target_desc->buffer.pointer, buffer,
127 target_desc->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Len Brown4be44fc2005-08-05 00:44:28 -0400129 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
130 "Truncating source buffer from %X to %X\n",
131 length, target_desc->buffer.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 }
133
134 /* Copy flags */
135
136 target_desc->buffer.flags = source_desc->buffer.flags;
137 target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
Len Brown4be44fc2005-08-05 00:44:28 -0400138 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141/*******************************************************************************
142 *
143 * FUNCTION: acpi_ex_store_string_to_string
144 *
145 * PARAMETERS: source_desc - Source object to copy
146 * target_desc - Destination object of the copy
147 *
148 * RETURN: Status
149 *
150 * DESCRIPTION: Copy a String object to another String object
151 *
152 ******************************************************************************/
153
154acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400155acpi_ex_store_string_to_string(union acpi_operand_object *source_desc,
156 union acpi_operand_object *target_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
Len Brown4be44fc2005-08-05 00:44:28 -0400158 u32 length;
159 u8 *buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Bob Mooreb229cf92006-04-21 17:15:00 -0400161 ACPI_FUNCTION_TRACE_PTR(ex_store_string_to_string, source_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 /* We know that source_desc is a string by now */
164
Bob Moorec51a4de2005-11-17 13:07:00 -0500165 buffer = ACPI_CAST_PTR(u8, source_desc->string.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 length = source_desc->string.length;
167
168 /*
169 * Replace existing string value if it will fit and the string
170 * pointer is not a static pointer (part of an ACPI table)
171 */
172 if ((length < target_desc->string.length) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400173 (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 /*
175 * String will fit in existing non-static buffer.
176 * Clear old string and copy in the new one
177 */
Len Brown4be44fc2005-08-05 00:44:28 -0400178 ACPI_MEMSET(target_desc->string.pointer, 0,
179 (acpi_size) target_desc->string.length + 1);
180 ACPI_MEMCPY(target_desc->string.pointer, buffer, length);
181 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 /*
183 * Free the current buffer, then allocate a new buffer
184 * large enough to hold the value
185 */
186 if (target_desc->string.pointer &&
Len Brown4be44fc2005-08-05 00:44:28 -0400187 (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 /* Only free if not a pointer into the DSDT */
190
Bob Moore83135242006-10-03 00:00:00 -0400191 ACPI_FREE(target_desc->string.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 }
193
Bob Moore83135242006-10-03 00:00:00 -0400194 target_desc->string.pointer = ACPI_ALLOCATE_ZEROED((acpi_size)
195 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 if (!target_desc->string.pointer) {
Len Brown4be44fc2005-08-05 00:44:28 -0400197 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 }
199
200 target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
Len Brown4be44fc2005-08-05 00:44:28 -0400201 ACPI_MEMCPY(target_desc->string.pointer, buffer, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
203
204 /* Set the new target length */
205
206 target_desc->string.length = length;
Len Brown4be44fc2005-08-05 00:44:28 -0400207 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208}