17851SDana.Myers@Sun.COM
27851SDana.Myers@Sun.COM /******************************************************************************
37851SDana.Myers@Sun.COM *
47851SDana.Myers@Sun.COM * Module Name: exstorob - AML Interpreter object store support, store to object
57851SDana.Myers@Sun.COM *
67851SDana.Myers@Sun.COM *****************************************************************************/
77851SDana.Myers@Sun.COM
87851SDana.Myers@Sun.COM /******************************************************************************
97851SDana.Myers@Sun.COM *
107851SDana.Myers@Sun.COM * 1. Copyright Notice
117851SDana.Myers@Sun.COM *
129980SDana.Myers@Sun.COM * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
137851SDana.Myers@Sun.COM * All rights reserved.
147851SDana.Myers@Sun.COM *
157851SDana.Myers@Sun.COM * 2. License
167851SDana.Myers@Sun.COM *
177851SDana.Myers@Sun.COM * 2.1. This is your license from Intel Corp. under its intellectual property
187851SDana.Myers@Sun.COM * rights. You may have additional license terms from the party that provided
197851SDana.Myers@Sun.COM * you this software, covering your right to use that party's intellectual
207851SDana.Myers@Sun.COM * property rights.
217851SDana.Myers@Sun.COM *
227851SDana.Myers@Sun.COM * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
237851SDana.Myers@Sun.COM * copy of the source code appearing in this file ("Covered Code") an
247851SDana.Myers@Sun.COM * irrevocable, perpetual, worldwide license under Intel's copyrights in the
257851SDana.Myers@Sun.COM * base code distributed originally by Intel ("Original Intel Code") to copy,
267851SDana.Myers@Sun.COM * make derivatives, distribute, use and display any portion of the Covered
277851SDana.Myers@Sun.COM * Code in any form, with the right to sublicense such rights; and
287851SDana.Myers@Sun.COM *
297851SDana.Myers@Sun.COM * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
307851SDana.Myers@Sun.COM * license (with the right to sublicense), under only those claims of Intel
317851SDana.Myers@Sun.COM * patents that are infringed by the Original Intel Code, to make, use, sell,
327851SDana.Myers@Sun.COM * offer to sell, and import the Covered Code and derivative works thereof
337851SDana.Myers@Sun.COM * solely to the minimum extent necessary to exercise the above copyright
347851SDana.Myers@Sun.COM * license, and in no event shall the patent license extend to any additions
357851SDana.Myers@Sun.COM * to or modifications of the Original Intel Code. No other license or right
367851SDana.Myers@Sun.COM * is granted directly or by implication, estoppel or otherwise;
377851SDana.Myers@Sun.COM *
387851SDana.Myers@Sun.COM * The above copyright and patent license is granted only if the following
397851SDana.Myers@Sun.COM * conditions are met:
407851SDana.Myers@Sun.COM *
417851SDana.Myers@Sun.COM * 3. Conditions
427851SDana.Myers@Sun.COM *
437851SDana.Myers@Sun.COM * 3.1. Redistribution of Source with Rights to Further Distribute Source.
447851SDana.Myers@Sun.COM * Redistribution of source code of any substantial portion of the Covered
457851SDana.Myers@Sun.COM * Code or modification with rights to further distribute source must include
467851SDana.Myers@Sun.COM * the above Copyright Notice, the above License, this list of Conditions,
477851SDana.Myers@Sun.COM * and the following Disclaimer and Export Compliance provision. In addition,
487851SDana.Myers@Sun.COM * Licensee must cause all Covered Code to which Licensee contributes to
497851SDana.Myers@Sun.COM * contain a file documenting the changes Licensee made to create that Covered
507851SDana.Myers@Sun.COM * Code and the date of any change. Licensee must include in that file the
517851SDana.Myers@Sun.COM * documentation of any changes made by any predecessor Licensee. Licensee
527851SDana.Myers@Sun.COM * must include a prominent statement that the modification is derived,
537851SDana.Myers@Sun.COM * directly or indirectly, from Original Intel Code.
547851SDana.Myers@Sun.COM *
557851SDana.Myers@Sun.COM * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
567851SDana.Myers@Sun.COM * Redistribution of source code of any substantial portion of the Covered
577851SDana.Myers@Sun.COM * Code or modification without rights to further distribute source must
587851SDana.Myers@Sun.COM * include the following Disclaimer and Export Compliance provision in the
597851SDana.Myers@Sun.COM * documentation and/or other materials provided with distribution. In
607851SDana.Myers@Sun.COM * addition, Licensee may not authorize further sublicense of source of any
617851SDana.Myers@Sun.COM * portion of the Covered Code, and must include terms to the effect that the
627851SDana.Myers@Sun.COM * license from Licensee to its licensee is limited to the intellectual
637851SDana.Myers@Sun.COM * property embodied in the software Licensee provides to its licensee, and
647851SDana.Myers@Sun.COM * not to intellectual property embodied in modifications its licensee may
657851SDana.Myers@Sun.COM * make.
667851SDana.Myers@Sun.COM *
677851SDana.Myers@Sun.COM * 3.3. Redistribution of Executable. Redistribution in executable form of any
687851SDana.Myers@Sun.COM * substantial portion of the Covered Code or modification must reproduce the
697851SDana.Myers@Sun.COM * above Copyright Notice, and the following Disclaimer and Export Compliance
707851SDana.Myers@Sun.COM * provision in the documentation and/or other materials provided with the
717851SDana.Myers@Sun.COM * distribution.
727851SDana.Myers@Sun.COM *
737851SDana.Myers@Sun.COM * 3.4. Intel retains all right, title, and interest in and to the Original
747851SDana.Myers@Sun.COM * Intel Code.
757851SDana.Myers@Sun.COM *
767851SDana.Myers@Sun.COM * 3.5. Neither the name Intel nor any other trademark owned or controlled by
777851SDana.Myers@Sun.COM * Intel shall be used in advertising or otherwise to promote the sale, use or
787851SDana.Myers@Sun.COM * other dealings in products derived from or relating to the Covered Code
797851SDana.Myers@Sun.COM * without prior written authorization from Intel.
807851SDana.Myers@Sun.COM *
817851SDana.Myers@Sun.COM * 4. Disclaimer and Export Compliance
827851SDana.Myers@Sun.COM *
837851SDana.Myers@Sun.COM * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
847851SDana.Myers@Sun.COM * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
857851SDana.Myers@Sun.COM * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
867851SDana.Myers@Sun.COM * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
877851SDana.Myers@Sun.COM * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
887851SDana.Myers@Sun.COM * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
897851SDana.Myers@Sun.COM * PARTICULAR PURPOSE.
907851SDana.Myers@Sun.COM *
917851SDana.Myers@Sun.COM * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
927851SDana.Myers@Sun.COM * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
937851SDana.Myers@Sun.COM * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
947851SDana.Myers@Sun.COM * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
957851SDana.Myers@Sun.COM * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
967851SDana.Myers@Sun.COM * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
977851SDana.Myers@Sun.COM * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
987851SDana.Myers@Sun.COM * LIMITED REMEDY.
997851SDana.Myers@Sun.COM *
1007851SDana.Myers@Sun.COM * 4.3. Licensee shall not export, either directly or indirectly, any of this
1017851SDana.Myers@Sun.COM * software or system incorporating such software without first obtaining any
1027851SDana.Myers@Sun.COM * required license or other approval from the U. S. Department of Commerce or
1037851SDana.Myers@Sun.COM * any other agency or department of the United States Government. In the
1047851SDana.Myers@Sun.COM * event Licensee exports any such software from the United States or
1057851SDana.Myers@Sun.COM * re-exports any such software from a foreign destination, Licensee shall
1067851SDana.Myers@Sun.COM * ensure that the distribution and export/re-export of the software is in
1077851SDana.Myers@Sun.COM * compliance with all laws, regulations, orders, or other restrictions of the
1087851SDana.Myers@Sun.COM * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1097851SDana.Myers@Sun.COM * any of its subsidiaries will export/re-export any technical data, process,
1107851SDana.Myers@Sun.COM * software, or service, directly or indirectly, to any country for which the
1117851SDana.Myers@Sun.COM * United States government or any agency thereof requires an export license,
1127851SDana.Myers@Sun.COM * other governmental approval, or letter of assurance, without first obtaining
1137851SDana.Myers@Sun.COM * such license, approval or letter.
1147851SDana.Myers@Sun.COM *
1157851SDana.Myers@Sun.COM *****************************************************************************/
1167851SDana.Myers@Sun.COM
1177851SDana.Myers@Sun.COM #define __EXSTOROB_C__
1187851SDana.Myers@Sun.COM
1197851SDana.Myers@Sun.COM #include "acpi.h"
1209980SDana.Myers@Sun.COM #include "accommon.h"
1217851SDana.Myers@Sun.COM #include "acinterp.h"
1227851SDana.Myers@Sun.COM
1237851SDana.Myers@Sun.COM
1247851SDana.Myers@Sun.COM #define _COMPONENT ACPI_EXECUTER
1257851SDana.Myers@Sun.COM ACPI_MODULE_NAME ("exstorob")
1267851SDana.Myers@Sun.COM
1277851SDana.Myers@Sun.COM
1287851SDana.Myers@Sun.COM /*******************************************************************************
1297851SDana.Myers@Sun.COM *
1307851SDana.Myers@Sun.COM * FUNCTION: AcpiExStoreBufferToBuffer
1317851SDana.Myers@Sun.COM *
1327851SDana.Myers@Sun.COM * PARAMETERS: SourceDesc - Source object to copy
1337851SDana.Myers@Sun.COM * TargetDesc - Destination object of the copy
1347851SDana.Myers@Sun.COM *
1357851SDana.Myers@Sun.COM * RETURN: Status
1367851SDana.Myers@Sun.COM *
1377851SDana.Myers@Sun.COM * DESCRIPTION: Copy a buffer object to another buffer object.
1387851SDana.Myers@Sun.COM *
1397851SDana.Myers@Sun.COM ******************************************************************************/
1407851SDana.Myers@Sun.COM
1417851SDana.Myers@Sun.COM ACPI_STATUS
AcpiExStoreBufferToBuffer(ACPI_OPERAND_OBJECT * SourceDesc,ACPI_OPERAND_OBJECT * TargetDesc)1427851SDana.Myers@Sun.COM AcpiExStoreBufferToBuffer (
1437851SDana.Myers@Sun.COM ACPI_OPERAND_OBJECT *SourceDesc,
1447851SDana.Myers@Sun.COM ACPI_OPERAND_OBJECT *TargetDesc)
1457851SDana.Myers@Sun.COM {
1467851SDana.Myers@Sun.COM UINT32 Length;
1477851SDana.Myers@Sun.COM UINT8 *Buffer;
1487851SDana.Myers@Sun.COM
1497851SDana.Myers@Sun.COM
1507851SDana.Myers@Sun.COM ACPI_FUNCTION_TRACE_PTR (ExStoreBufferToBuffer, SourceDesc);
1517851SDana.Myers@Sun.COM
1527851SDana.Myers@Sun.COM
153*11225SDana.Myers@Sun.COM /* If Source and Target are the same, just return */
154*11225SDana.Myers@Sun.COM
155*11225SDana.Myers@Sun.COM if (SourceDesc == TargetDesc)
156*11225SDana.Myers@Sun.COM {
157*11225SDana.Myers@Sun.COM return_ACPI_STATUS (AE_OK);
158*11225SDana.Myers@Sun.COM }
159*11225SDana.Myers@Sun.COM
1607851SDana.Myers@Sun.COM /* We know that SourceDesc is a buffer by now */
1617851SDana.Myers@Sun.COM
1627851SDana.Myers@Sun.COM Buffer = ACPI_CAST_PTR (UINT8, SourceDesc->Buffer.Pointer);
1637851SDana.Myers@Sun.COM Length = SourceDesc->Buffer.Length;
1647851SDana.Myers@Sun.COM
1657851SDana.Myers@Sun.COM /*
1667851SDana.Myers@Sun.COM * If target is a buffer of length zero or is a static buffer,
1677851SDana.Myers@Sun.COM * allocate a new buffer of the proper length
1687851SDana.Myers@Sun.COM */
1697851SDana.Myers@Sun.COM if ((TargetDesc->Buffer.Length == 0) ||
1707851SDana.Myers@Sun.COM (TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER))
1717851SDana.Myers@Sun.COM {
1727851SDana.Myers@Sun.COM TargetDesc->Buffer.Pointer = ACPI_ALLOCATE (Length);
1737851SDana.Myers@Sun.COM if (!TargetDesc->Buffer.Pointer)
1747851SDana.Myers@Sun.COM {
1757851SDana.Myers@Sun.COM return_ACPI_STATUS (AE_NO_MEMORY);
1767851SDana.Myers@Sun.COM }
1777851SDana.Myers@Sun.COM
1787851SDana.Myers@Sun.COM TargetDesc->Buffer.Length = Length;
1797851SDana.Myers@Sun.COM }
1807851SDana.Myers@Sun.COM
1817851SDana.Myers@Sun.COM /* Copy source buffer to target buffer */
1827851SDana.Myers@Sun.COM
1837851SDana.Myers@Sun.COM if (Length <= TargetDesc->Buffer.Length)
1847851SDana.Myers@Sun.COM {
1857851SDana.Myers@Sun.COM /* Clear existing buffer and copy in the new one */
1867851SDana.Myers@Sun.COM
1877851SDana.Myers@Sun.COM ACPI_MEMSET (TargetDesc->Buffer.Pointer, 0, TargetDesc->Buffer.Length);
1887851SDana.Myers@Sun.COM ACPI_MEMCPY (TargetDesc->Buffer.Pointer, Buffer, Length);
1897851SDana.Myers@Sun.COM
1907851SDana.Myers@Sun.COM #ifdef ACPI_OBSOLETE_BEHAVIOR
1917851SDana.Myers@Sun.COM /*
1927851SDana.Myers@Sun.COM * NOTE: ACPI versions up to 3.0 specified that the buffer must be
1937851SDana.Myers@Sun.COM * truncated if the string is smaller than the buffer. However, "other"
1947851SDana.Myers@Sun.COM * implementations of ACPI never did this and thus became the defacto
1957851SDana.Myers@Sun.COM * standard. ACPI 3.0A changes this behavior such that the buffer
1967851SDana.Myers@Sun.COM * is no longer truncated.
1977851SDana.Myers@Sun.COM */
1987851SDana.Myers@Sun.COM
1997851SDana.Myers@Sun.COM /*
2007851SDana.Myers@Sun.COM * OBSOLETE BEHAVIOR:
2017851SDana.Myers@Sun.COM * If the original source was a string, we must truncate the buffer,
2027851SDana.Myers@Sun.COM * according to the ACPI spec. Integer-to-Buffer and Buffer-to-Buffer
2037851SDana.Myers@Sun.COM * copy must not truncate the original buffer.
2047851SDana.Myers@Sun.COM */
2057851SDana.Myers@Sun.COM if (OriginalSrcType == ACPI_TYPE_STRING)
2067851SDana.Myers@Sun.COM {
2077851SDana.Myers@Sun.COM /* Set the new length of the target */
2087851SDana.Myers@Sun.COM
2097851SDana.Myers@Sun.COM TargetDesc->Buffer.Length = Length;
2107851SDana.Myers@Sun.COM }
2117851SDana.Myers@Sun.COM #endif
2127851SDana.Myers@Sun.COM }
2137851SDana.Myers@Sun.COM else
2147851SDana.Myers@Sun.COM {
2157851SDana.Myers@Sun.COM /* Truncate the source, copy only what will fit */
2167851SDana.Myers@Sun.COM
2177851SDana.Myers@Sun.COM ACPI_MEMCPY (TargetDesc->Buffer.Pointer, Buffer,
2187851SDana.Myers@Sun.COM TargetDesc->Buffer.Length);
2197851SDana.Myers@Sun.COM
2207851SDana.Myers@Sun.COM ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
2217851SDana.Myers@Sun.COM "Truncating source buffer from %X to %X\n",
2227851SDana.Myers@Sun.COM Length, TargetDesc->Buffer.Length));
2237851SDana.Myers@Sun.COM }
2247851SDana.Myers@Sun.COM
2257851SDana.Myers@Sun.COM /* Copy flags */
2267851SDana.Myers@Sun.COM
2277851SDana.Myers@Sun.COM TargetDesc->Buffer.Flags = SourceDesc->Buffer.Flags;
2287851SDana.Myers@Sun.COM TargetDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
2297851SDana.Myers@Sun.COM return_ACPI_STATUS (AE_OK);
2307851SDana.Myers@Sun.COM }
2317851SDana.Myers@Sun.COM
2327851SDana.Myers@Sun.COM
2337851SDana.Myers@Sun.COM /*******************************************************************************
2347851SDana.Myers@Sun.COM *
2357851SDana.Myers@Sun.COM * FUNCTION: AcpiExStoreStringToString
2367851SDana.Myers@Sun.COM *
2377851SDana.Myers@Sun.COM * PARAMETERS: SourceDesc - Source object to copy
2387851SDana.Myers@Sun.COM * TargetDesc - Destination object of the copy
2397851SDana.Myers@Sun.COM *
2407851SDana.Myers@Sun.COM * RETURN: Status
2417851SDana.Myers@Sun.COM *
2427851SDana.Myers@Sun.COM * DESCRIPTION: Copy a String object to another String object
2437851SDana.Myers@Sun.COM *
2447851SDana.Myers@Sun.COM ******************************************************************************/
2457851SDana.Myers@Sun.COM
2467851SDana.Myers@Sun.COM ACPI_STATUS
AcpiExStoreStringToString(ACPI_OPERAND_OBJECT * SourceDesc,ACPI_OPERAND_OBJECT * TargetDesc)2477851SDana.Myers@Sun.COM AcpiExStoreStringToString (
2487851SDana.Myers@Sun.COM ACPI_OPERAND_OBJECT *SourceDesc,
2497851SDana.Myers@Sun.COM ACPI_OPERAND_OBJECT *TargetDesc)
2507851SDana.Myers@Sun.COM {
2517851SDana.Myers@Sun.COM UINT32 Length;
2527851SDana.Myers@Sun.COM UINT8 *Buffer;
2537851SDana.Myers@Sun.COM
2547851SDana.Myers@Sun.COM
2557851SDana.Myers@Sun.COM ACPI_FUNCTION_TRACE_PTR (ExStoreStringToString, SourceDesc);
2567851SDana.Myers@Sun.COM
2577851SDana.Myers@Sun.COM
258*11225SDana.Myers@Sun.COM /* If Source and Target are the same, just return */
259*11225SDana.Myers@Sun.COM
260*11225SDana.Myers@Sun.COM if (SourceDesc == TargetDesc)
261*11225SDana.Myers@Sun.COM {
262*11225SDana.Myers@Sun.COM return_ACPI_STATUS (AE_OK);
263*11225SDana.Myers@Sun.COM }
264*11225SDana.Myers@Sun.COM
2657851SDana.Myers@Sun.COM /* We know that SourceDesc is a string by now */
2667851SDana.Myers@Sun.COM
2677851SDana.Myers@Sun.COM Buffer = ACPI_CAST_PTR (UINT8, SourceDesc->String.Pointer);
2687851SDana.Myers@Sun.COM Length = SourceDesc->String.Length;
2697851SDana.Myers@Sun.COM
2707851SDana.Myers@Sun.COM /*
2717851SDana.Myers@Sun.COM * Replace existing string value if it will fit and the string
2727851SDana.Myers@Sun.COM * pointer is not a static pointer (part of an ACPI table)
2737851SDana.Myers@Sun.COM */
2747851SDana.Myers@Sun.COM if ((Length < TargetDesc->String.Length) &&
2757851SDana.Myers@Sun.COM (!(TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
2767851SDana.Myers@Sun.COM {
2777851SDana.Myers@Sun.COM /*
2787851SDana.Myers@Sun.COM * String will fit in existing non-static buffer.
2797851SDana.Myers@Sun.COM * Clear old string and copy in the new one
2807851SDana.Myers@Sun.COM */
2817851SDana.Myers@Sun.COM ACPI_MEMSET (TargetDesc->String.Pointer, 0,
2827851SDana.Myers@Sun.COM (ACPI_SIZE) TargetDesc->String.Length + 1);
2837851SDana.Myers@Sun.COM ACPI_MEMCPY (TargetDesc->String.Pointer, Buffer, Length);
2847851SDana.Myers@Sun.COM }
2857851SDana.Myers@Sun.COM else
2867851SDana.Myers@Sun.COM {
2877851SDana.Myers@Sun.COM /*
2887851SDana.Myers@Sun.COM * Free the current buffer, then allocate a new buffer
2897851SDana.Myers@Sun.COM * large enough to hold the value
2907851SDana.Myers@Sun.COM */
2917851SDana.Myers@Sun.COM if (TargetDesc->String.Pointer &&
2927851SDana.Myers@Sun.COM (!(TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
2937851SDana.Myers@Sun.COM {
2947851SDana.Myers@Sun.COM /* Only free if not a pointer into the DSDT */
2957851SDana.Myers@Sun.COM
2967851SDana.Myers@Sun.COM ACPI_FREE (TargetDesc->String.Pointer);
2977851SDana.Myers@Sun.COM }
2987851SDana.Myers@Sun.COM
2997851SDana.Myers@Sun.COM TargetDesc->String.Pointer = ACPI_ALLOCATE_ZEROED (
3007851SDana.Myers@Sun.COM (ACPI_SIZE) Length + 1);
3017851SDana.Myers@Sun.COM if (!TargetDesc->String.Pointer)
3027851SDana.Myers@Sun.COM {
3037851SDana.Myers@Sun.COM return_ACPI_STATUS (AE_NO_MEMORY);
3047851SDana.Myers@Sun.COM }
3057851SDana.Myers@Sun.COM
3067851SDana.Myers@Sun.COM TargetDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
3077851SDana.Myers@Sun.COM ACPI_MEMCPY (TargetDesc->String.Pointer, Buffer, Length);
3087851SDana.Myers@Sun.COM }
3097851SDana.Myers@Sun.COM
3107851SDana.Myers@Sun.COM /* Set the new target length */
3117851SDana.Myers@Sun.COM
3127851SDana.Myers@Sun.COM TargetDesc->String.Length = Length;
3137851SDana.Myers@Sun.COM return_ACPI_STATUS (AE_OK);
3147851SDana.Myers@Sun.COM }
3157851SDana.Myers@Sun.COM
3167851SDana.Myers@Sun.COM
317