Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/drivers/acpica/exstorob.c need to be fixed.

0001 
0002 /******************************************************************************
0003  *
0004  * Module Name: exstorob - AML Interpreter object store support, store to object
0005  *
0006  *****************************************************************************/
0007 
0008 /******************************************************************************
0009  *
0010  * 1. Copyright Notice
0011  *
0012  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
0013  * All rights reserved.
0014  *
0015  * 2. License
0016  *
0017  * 2.1. This is your license from Intel Corp. under its intellectual property
0018  * rights.  You may have additional license terms from the party that provided
0019  * you this software, covering your right to use that party's intellectual
0020  * property rights.
0021  *
0022  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0023  * copy of the source code appearing in this file ("Covered Code") an
0024  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0025  * base code distributed originally by Intel ("Original Intel Code") to copy,
0026  * make derivatives, distribute, use and display any portion of the Covered
0027  * Code in any form, with the right to sublicense such rights; and
0028  *
0029  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0030  * license (with the right to sublicense), under only those claims of Intel
0031  * patents that are infringed by the Original Intel Code, to make, use, sell,
0032  * offer to sell, and import the Covered Code and derivative works thereof
0033  * solely to the minimum extent necessary to exercise the above copyright
0034  * license, and in no event shall the patent license extend to any additions
0035  * to or modifications of the Original Intel Code.  No other license or right
0036  * is granted directly or by implication, estoppel or otherwise;
0037  *
0038  * The above copyright and patent license is granted only if the following
0039  * conditions are met:
0040  *
0041  * 3. Conditions
0042  *
0043  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0044  * Redistribution of source code of any substantial portion of the Covered
0045  * Code or modification with rights to further distribute source must include
0046  * the above Copyright Notice, the above License, this list of Conditions,
0047  * and the following Disclaimer and Export Compliance provision.  In addition,
0048  * Licensee must cause all Covered Code to which Licensee contributes to
0049  * contain a file documenting the changes Licensee made to create that Covered
0050  * Code and the date of any change.  Licensee must include in that file the
0051  * documentation of any changes made by any predecessor Licensee.  Licensee
0052  * must include a prominent statement that the modification is derived,
0053  * directly or indirectly, from Original Intel Code.
0054  *
0055  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0056  * Redistribution of source code of any substantial portion of the Covered
0057  * Code or modification without rights to further distribute source must
0058  * include the following Disclaimer and Export Compliance provision in the
0059  * documentation and/or other materials provided with distribution.  In
0060  * addition, Licensee may not authorize further sublicense of source of any
0061  * portion of the Covered Code, and must include terms to the effect that the
0062  * license from Licensee to its licensee is limited to the intellectual
0063  * property embodied in the software Licensee provides to its licensee, and
0064  * not to intellectual property embodied in modifications its licensee may
0065  * make.
0066  *
0067  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0068  * substantial portion of the Covered Code or modification must reproduce the
0069  * above Copyright Notice, and the following Disclaimer and Export Compliance
0070  * provision in the documentation and/or other materials provided with the
0071  * distribution.
0072  *
0073  * 3.4. Intel retains all right, title, and interest in and to the Original
0074  * Intel Code.
0075  *
0076  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0077  * Intel shall be used in advertising or otherwise to promote the sale, use or
0078  * other dealings in products derived from or relating to the Covered Code
0079  * without prior written authorization from Intel.
0080  *
0081  * 4. Disclaimer and Export Compliance
0082  *
0083  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0084  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0085  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
0086  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
0087  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
0088  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0089  * PARTICULAR PURPOSE.
0090  *
0091  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0092  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0093  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0094  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0095  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0096  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
0097  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0098  * LIMITED REMEDY.
0099  *
0100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0101  * software or system incorporating such software without first obtaining any
0102  * required license or other approval from the U. S. Department of Commerce or
0103  * any other agency or department of the United States Government.  In the
0104  * event Licensee exports any such software from the United States or
0105  * re-exports any such software from a foreign destination, Licensee shall
0106  * ensure that the distribution and export/re-export of the software is in
0107  * compliance with all laws, regulations, orders, or other restrictions of the
0108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0109  * any of its subsidiaries will export/re-export any technical data, process,
0110  * software, or service, directly or indirectly, to any country for which the
0111  * United States government or any agency thereof requires an export license,
0112  * other governmental approval, or letter of assurance, without first obtaining
0113  * such license, approval or letter.
0114  *
0115  *****************************************************************************/
0116 
0117 #define __EXSTOROB_C__
0118 
0119 #include "acpi.h"
0120 #include "accommon.h"
0121 #include "acinterp.h"
0122 
0123 
0124 #define _COMPONENT          ACPI_EXECUTER
0125         ACPI_MODULE_NAME    ("exstorob")
0126 
0127 
0128 /*******************************************************************************
0129  *
0130  * FUNCTION:    AcpiExStoreBufferToBuffer
0131  *
0132  * PARAMETERS:  SourceDesc          - Source object to copy
0133  *              TargetDesc          - Destination object of the copy
0134  *
0135  * RETURN:      Status
0136  *
0137  * DESCRIPTION: Copy a buffer object to another buffer object.
0138  *
0139  ******************************************************************************/
0140 
0141 ACPI_STATUS
0142 AcpiExStoreBufferToBuffer (
0143     ACPI_OPERAND_OBJECT     *SourceDesc,
0144     ACPI_OPERAND_OBJECT     *TargetDesc)
0145 {
0146     UINT32                  Length;
0147     UINT8                   *Buffer;
0148 
0149 
0150     ACPI_FUNCTION_TRACE_PTR (ExStoreBufferToBuffer, SourceDesc);
0151 
0152 
0153     /* We know that SourceDesc is a buffer by now */
0154 
0155     Buffer = ACPI_CAST_PTR (UINT8, SourceDesc->Buffer.Pointer);
0156     Length = SourceDesc->Buffer.Length;
0157 
0158     /*
0159      * If target is a buffer of length zero or is a static buffer,
0160      * allocate a new buffer of the proper length
0161      */
0162     if ((TargetDesc->Buffer.Length == 0) ||
0163         (TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER))
0164     {
0165         TargetDesc->Buffer.Pointer = ACPI_ALLOCATE (Length);
0166         if (!TargetDesc->Buffer.Pointer)
0167         {
0168             return_ACPI_STATUS (AE_NO_MEMORY);
0169         }
0170 
0171         TargetDesc->Buffer.Length = Length;
0172     }
0173 
0174     /* Copy source buffer to target buffer */
0175 
0176     if (Length <= TargetDesc->Buffer.Length)
0177     {
0178         /* Clear existing buffer and copy in the new one */
0179 
0180         ACPI_MEMSET (TargetDesc->Buffer.Pointer, 0, TargetDesc->Buffer.Length);
0181         ACPI_MEMCPY (TargetDesc->Buffer.Pointer, Buffer, Length);
0182 
0183 #ifdef ACPI_OBSOLETE_BEHAVIOR
0184         /*
0185          * NOTE: ACPI versions up to 3.0 specified that the buffer must be
0186          * truncated if the string is smaller than the buffer.  However, "other"
0187          * implementations of ACPI never did this and thus became the defacto
0188          * standard. ACPI 3.0A changes this behavior such that the buffer
0189          * is no longer truncated.
0190          */
0191 
0192         /*
0193          * OBSOLETE BEHAVIOR:
0194          * If the original source was a string, we must truncate the buffer,
0195          * according to the ACPI spec.  Integer-to-Buffer and Buffer-to-Buffer
0196          * copy must not truncate the original buffer.
0197          */
0198         if (OriginalSrcType == ACPI_TYPE_STRING)
0199         {
0200             /* Set the new length of the target */
0201 
0202             TargetDesc->Buffer.Length = Length;
0203         }
0204 #endif
0205     }
0206     else
0207     {
0208         /* Truncate the source, copy only what will fit */
0209 
0210         ACPI_MEMCPY (TargetDesc->Buffer.Pointer, Buffer,
0211             TargetDesc->Buffer.Length);
0212 
0213         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
0214             "Truncating source buffer from %X to %X\n",
0215             Length, TargetDesc->Buffer.Length));
0216     }
0217 
0218     /* Copy flags */
0219 
0220     TargetDesc->Buffer.Flags = SourceDesc->Buffer.Flags;
0221     TargetDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
0222     return_ACPI_STATUS (AE_OK);
0223 }
0224 
0225 
0226 /*******************************************************************************
0227  *
0228  * FUNCTION:    AcpiExStoreStringToString
0229  *
0230  * PARAMETERS:  SourceDesc          - Source object to copy
0231  *              TargetDesc          - Destination object of the copy
0232  *
0233  * RETURN:      Status
0234  *
0235  * DESCRIPTION: Copy a String object to another String object
0236  *
0237  ******************************************************************************/
0238 
0239 ACPI_STATUS
0240 AcpiExStoreStringToString (
0241     ACPI_OPERAND_OBJECT     *SourceDesc,
0242     ACPI_OPERAND_OBJECT     *TargetDesc)
0243 {
0244     UINT32                  Length;
0245     UINT8                   *Buffer;
0246 
0247 
0248     ACPI_FUNCTION_TRACE_PTR (ExStoreStringToString, SourceDesc);
0249 
0250 
0251     /* We know that SourceDesc is a string by now */
0252 
0253     Buffer = ACPI_CAST_PTR (UINT8, SourceDesc->String.Pointer);
0254     Length = SourceDesc->String.Length;
0255 
0256     /*
0257      * Replace existing string value if it will fit and the string
0258      * pointer is not a static pointer (part of an ACPI table)
0259      */
0260     if ((Length < TargetDesc->String.Length) &&
0261        (!(TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
0262     {
0263         /*
0264          * String will fit in existing non-static buffer.
0265          * Clear old string and copy in the new one
0266          */
0267         ACPI_MEMSET (TargetDesc->String.Pointer, 0,
0268             (ACPI_SIZE) TargetDesc->String.Length + 1);
0269         ACPI_MEMCPY (TargetDesc->String.Pointer, Buffer, Length);
0270     }
0271     else
0272     {
0273         /*
0274          * Free the current buffer, then allocate a new buffer
0275          * large enough to hold the value
0276          */
0277         if (TargetDesc->String.Pointer &&
0278            (!(TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
0279         {
0280             /* Only free if not a pointer into the DSDT */
0281 
0282             ACPI_FREE (TargetDesc->String.Pointer);
0283         }
0284 
0285         TargetDesc->String.Pointer = ACPI_ALLOCATE_ZEROED (
0286                                         (ACPI_SIZE) Length + 1);
0287         if (!TargetDesc->String.Pointer)
0288         {
0289             return_ACPI_STATUS (AE_NO_MEMORY);
0290         }
0291 
0292         TargetDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
0293         ACPI_MEMCPY (TargetDesc->String.Pointer, Buffer, Length);
0294     }
0295 
0296     /* Set the new target length */
0297 
0298     TargetDesc->String.Length = Length;
0299     return_ACPI_STATUS (AE_OK);
0300 }
0301 
0302