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