exstorob.c revision 107325
1210284Sjmallett 2232812Sjmallett/****************************************************************************** 3215990Sjmallett * 4210284Sjmallett * Module Name: exstorob - AML Interpreter object store support, store to object 5210284Sjmallett * $Revision: 46 $ 6215990Sjmallett * 7215990Sjmallett *****************************************************************************/ 8215990Sjmallett 9210284Sjmallett/****************************************************************************** 10215990Sjmallett * 11215990Sjmallett * 1. Copyright Notice 12210284Sjmallett * 13215990Sjmallett * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp. 14215990Sjmallett * All rights reserved. 15215990Sjmallett * 16215990Sjmallett * 2. License 17215990Sjmallett * 18232812Sjmallett * 2.1. This is your license from Intel Corp. under its intellectual property 19215990Sjmallett * rights. You may have additional license terms from the party that provided 20215990Sjmallett * you this software, covering your right to use that party's intellectual 21215990Sjmallett * property rights. 22215990Sjmallett * 23215990Sjmallett * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 24215990Sjmallett * copy of the source code appearing in this file ("Covered Code") an 25215990Sjmallett * irrevocable, perpetual, worldwide license under Intel's copyrights in the 26215990Sjmallett * base code distributed originally by Intel ("Original Intel Code") to copy, 27215990Sjmallett * make derivatives, distribute, use and display any portion of the Covered 28215990Sjmallett * Code in any form, with the right to sublicense such rights; and 29232812Sjmallett * 30215990Sjmallett * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 31215990Sjmallett * license (with the right to sublicense), under only those claims of Intel 32215990Sjmallett * patents that are infringed by the Original Intel Code, to make, use, sell, 33215990Sjmallett * offer to sell, and import the Covered Code and derivative works thereof 34215990Sjmallett * solely to the minimum extent necessary to exercise the above copyright 35215990Sjmallett * license, and in no event shall the patent license extend to any additions 36215990Sjmallett * to or modifications of the Original Intel Code. No other license or right 37215990Sjmallett * is granted directly or by implication, estoppel or otherwise; 38210284Sjmallett * 39210284Sjmallett * The above copyright and patent license is granted only if the following 40210284Sjmallett * conditions are met: 41210284Sjmallett * 42210284Sjmallett * 3. Conditions 43210284Sjmallett * 44215990Sjmallett * 3.1. Redistribution of Source with Rights to Further Distribute Source. 45210284Sjmallett * Redistribution of source code of any substantial portion of the Covered 46210284Sjmallett * Code or modification with rights to further distribute source must include 47210284Sjmallett * the above Copyright Notice, the above License, this list of Conditions, 48210284Sjmallett * and the following Disclaimer and Export Compliance provision. In addition, 49210284Sjmallett * Licensee must cause all Covered Code to which Licensee contributes to 50210284Sjmallett * contain a file documenting the changes Licensee made to create that Covered 51210284Sjmallett * Code and the date of any change. Licensee must include in that file the 52210284Sjmallett * documentation of any changes made by any predecessor Licensee. Licensee 53232812Sjmallett * must include a prominent statement that the modification is derived, 54210284Sjmallett * directly or indirectly, from Original Intel Code. 55210284Sjmallett * 56210284Sjmallett * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 57210284Sjmallett * Redistribution of source code of any substantial portion of the Covered 58210284Sjmallett * Code or modification without rights to further distribute source must 59210284Sjmallett * include the following Disclaimer and Export Compliance provision in the 60210284Sjmallett * documentation and/or other materials provided with distribution. In 61210284Sjmallett * addition, Licensee may not authorize further sublicense of source of any 62210284Sjmallett * portion of the Covered Code, and must include terms to the effect that the 63210284Sjmallett * license from Licensee to its licensee is limited to the intellectual 64210284Sjmallett * property embodied in the software Licensee provides to its licensee, and 65210284Sjmallett * not to intellectual property embodied in modifications its licensee may 66210284Sjmallett * make. 67210284Sjmallett * 68210284Sjmallett * 3.3. Redistribution of Executable. Redistribution in executable form of any 69215990Sjmallett * substantial portion of the Covered Code or modification must reproduce the 70210284Sjmallett * above Copyright Notice, and the following Disclaimer and Export Compliance 71210284Sjmallett * provision in the documentation and/or other materials provided with the 72210284Sjmallett * distribution. 73210284Sjmallett * 74210284Sjmallett * 3.4. Intel retains all right, title, and interest in and to the Original 75210284Sjmallett * Intel Code. 76210284Sjmallett * 77210284Sjmallett * 3.5. Neither the name Intel nor any other trademark owned or controlled by 78210284Sjmallett * Intel shall be used in advertising or otherwise to promote the sale, use or 79210284Sjmallett * other dealings in products derived from or relating to the Covered Code 80210284Sjmallett * without prior written authorization from Intel. 81210284Sjmallett * 82210284Sjmallett * 4. Disclaimer and Export Compliance 83210284Sjmallett * 84210284Sjmallett * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 85210284Sjmallett * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 86210284Sjmallett * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 87210284Sjmallett * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 88210284Sjmallett * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 89210284Sjmallett * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 90210284Sjmallett * PARTICULAR PURPOSE. 91210284Sjmallett * 92210284Sjmallett * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 93210284Sjmallett * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 94210284Sjmallett * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 95210284Sjmallett * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 96210284Sjmallett * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 97210284Sjmallett * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 98210284Sjmallett * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 99210284Sjmallett * LIMITED REMEDY. 100210284Sjmallett * 101210284Sjmallett * 4.3. Licensee shall not export, either directly or indirectly, any of this 102210284Sjmallett * software or system incorporating such software without first obtaining any 103210284Sjmallett * required license or other approval from the U. S. Department of Commerce or 104210284Sjmallett * any other agency or department of the United States Government. In the 105210284Sjmallett * event Licensee exports any such software from the United States or 106210284Sjmallett * re-exports any such software from a foreign destination, Licensee shall 107210284Sjmallett * ensure that the distribution and export/re-export of the software is in 108210284Sjmallett * compliance with all laws, regulations, orders, or other restrictions of the 109210284Sjmallett * U.S. Export Administration Regulations. Licensee agrees that neither it nor 110210284Sjmallett * any of its subsidiaries will export/re-export any technical data, process, 111210284Sjmallett * software, or service, directly or indirectly, to any country for which the 112210284Sjmallett * United States government or any agency thereof requires an export license, 113210284Sjmallett * other governmental approval, or letter of assurance, without first obtaining 114210284Sjmallett * such license, approval or letter. 115210284Sjmallett * 116210284Sjmallett *****************************************************************************/ 117210284Sjmallett 118210284Sjmallett#define __EXSTOROB_C__ 119210284Sjmallett 120210284Sjmallett#include "acpi.h" 121210284Sjmallett#include "acinterp.h" 122210284Sjmallett 123210284Sjmallett 124210284Sjmallett#define _COMPONENT ACPI_EXECUTER 125210284Sjmallett ACPI_MODULE_NAME ("exstorob") 126210284Sjmallett 127210284Sjmallett 128210284Sjmallett/******************************************************************************* 129210284Sjmallett * 130210284Sjmallett * FUNCTION: AcpiExStoreBufferToBuffer 131210284Sjmallett * 132210284Sjmallett * PARAMETERS: SourceDesc - Source object to copy 133210284Sjmallett * TargetDesc - Destination object of the copy 134210284Sjmallett * 135215990Sjmallett * RETURN: Status 136210284Sjmallett * 137210284Sjmallett * DESCRIPTION: Copy a buffer object to another buffer object. 138210284Sjmallett * 139210284Sjmallett ******************************************************************************/ 140210284Sjmallett 141210284SjmallettACPI_STATUS 142210284SjmallettAcpiExStoreBufferToBuffer ( 143210284Sjmallett ACPI_OPERAND_OBJECT *SourceDesc, 144210284Sjmallett ACPI_OPERAND_OBJECT *TargetDesc) 145210284Sjmallett{ 146210284Sjmallett UINT32 Length; 147210284Sjmallett UINT8 *Buffer; 148210284Sjmallett 149210284Sjmallett 150210284Sjmallett ACPI_FUNCTION_NAME ("ExStoreBufferToBuffer"); 151210284Sjmallett 152210284Sjmallett 153210284Sjmallett /* 154210284Sjmallett * We know that SourceDesc is a buffer by now 155210284Sjmallett */ 156210284Sjmallett Buffer = (UINT8 *) SourceDesc->Buffer.Pointer; 157210284Sjmallett Length = SourceDesc->Buffer.Length; 158210284Sjmallett 159210284Sjmallett /* 160210284Sjmallett * If target is a buffer of length zero, allocate a new 161210284Sjmallett * buffer of the proper length 162210284Sjmallett */ 163210284Sjmallett if (TargetDesc->Buffer.Length == 0) 164210284Sjmallett { 165210284Sjmallett TargetDesc->Buffer.Pointer = ACPI_MEM_ALLOCATE (Length); 166215990Sjmallett if (!TargetDesc->Buffer.Pointer) 167210284Sjmallett { 168210284Sjmallett return (AE_NO_MEMORY); 169210284Sjmallett } 170210284Sjmallett 171210284Sjmallett TargetDesc->Buffer.Length = Length; 172210284Sjmallett } 173210284Sjmallett 174210284Sjmallett /* 175210284Sjmallett * Buffer is a static allocation, 176210284Sjmallett * only place what will fit in the buffer. 177210284Sjmallett */ 178210284Sjmallett if (Length <= TargetDesc->Buffer.Length) 179210284Sjmallett { 180210284Sjmallett /* Clear existing buffer and copy in the new one */ 181210284Sjmallett 182210284Sjmallett ACPI_MEMSET (TargetDesc->Buffer.Pointer, 0, TargetDesc->Buffer.Length); 183210284Sjmallett ACPI_MEMCPY (TargetDesc->Buffer.Pointer, Buffer, Length); 184210284Sjmallett } 185210284Sjmallett else 186210284Sjmallett { 187210284Sjmallett /* 188210284Sjmallett * Truncate the source, copy only what will fit 189210284Sjmallett */ 190210284Sjmallett ACPI_MEMCPY (TargetDesc->Buffer.Pointer, Buffer, TargetDesc->Buffer.Length); 191210284Sjmallett 192210284Sjmallett ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 193210284Sjmallett "Truncating src buffer from %X to %X\n", 194210284Sjmallett Length, TargetDesc->Buffer.Length)); 195210284Sjmallett } 196210284Sjmallett 197210284Sjmallett /* Copy flags */ 198210284Sjmallett 199210284Sjmallett TargetDesc->Buffer.Flags = SourceDesc->Buffer.Flags; 200210284Sjmallett return (AE_OK); 201210284Sjmallett} 202210284Sjmallett 203215990Sjmallett 204210284Sjmallett/******************************************************************************* 205210284Sjmallett * 206210284Sjmallett * FUNCTION: AcpiExStoreStringToString 207210284Sjmallett * 208210284Sjmallett * PARAMETERS: SourceDesc - Source object to copy 209210284Sjmallett * TargetDesc - Destination object of the copy 210210284Sjmallett * 211210284Sjmallett * RETURN: Status 212210284Sjmallett * 213210284Sjmallett * DESCRIPTION: Copy a String object to another String object 214210284Sjmallett * 215210284Sjmallett ******************************************************************************/ 216210284Sjmallett 217210284SjmallettACPI_STATUS 218210284SjmallettAcpiExStoreStringToString ( 219210284Sjmallett ACPI_OPERAND_OBJECT *SourceDesc, 220210284Sjmallett ACPI_OPERAND_OBJECT *TargetDesc) 221210284Sjmallett{ 222210284Sjmallett UINT32 Length; 223210284Sjmallett UINT8 *Buffer; 224210284Sjmallett 225210284Sjmallett 226 ACPI_FUNCTION_ENTRY (); 227 228 229 /* 230 * We know that SourceDesc is a string by now. 231 */ 232 Buffer = (UINT8 *) SourceDesc->String.Pointer; 233 Length = SourceDesc->String.Length; 234 235 /* 236 * Setting a string value replaces the old string 237 */ 238 if (Length < TargetDesc->String.Length) 239 { 240 /* 241 * String will fit in existing buffer. 242 * Clear old string and copy in the new one 243 */ 244 ACPI_MEMSET (TargetDesc->String.Pointer, 0, (ACPI_SIZE) TargetDesc->String.Length + 1); 245 ACPI_MEMCPY (TargetDesc->String.Pointer, Buffer, Length); 246 } 247 else 248 { 249 /* 250 * Free the current buffer, then allocate a new buffer 251 * large enough to hold the value 252 */ 253 if (TargetDesc->String.Pointer && 254 (!(TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER))) 255 { 256 /* 257 * Only free if not a pointer into the DSDT 258 */ 259 ACPI_MEM_FREE (TargetDesc->String.Pointer); 260 } 261 262 TargetDesc->String.Pointer = ACPI_MEM_CALLOCATE ((ACPI_SIZE) Length + 1); 263 if (!TargetDesc->String.Pointer) 264 { 265 return (AE_NO_MEMORY); 266 } 267 268 ACPI_MEMCPY (TargetDesc->String.Pointer, Buffer, Length); 269 } 270 271 /* Set the new target length */ 272 273 TargetDesc->String.Length = Length; 274 return (AE_OK); 275} 276 277 278