Home | History | Annotate | Line # | Download | only in executer
exstorob.c revision 1.1.1.2
      1      1.1  jruoho 
      2      1.1  jruoho /******************************************************************************
      3      1.1  jruoho  *
      4      1.1  jruoho  * Module Name: exstorob - AML Interpreter object store support, store to object
      5      1.1  jruoho  *
      6      1.1  jruoho  *****************************************************************************/
      7      1.1  jruoho 
      8  1.1.1.2  jruoho /*
      9  1.1.1.2  jruoho  * Copyright (C) 2000 - 2011, Intel Corp.
     10      1.1  jruoho  * All rights reserved.
     11      1.1  jruoho  *
     12  1.1.1.2  jruoho  * Redistribution and use in source and binary forms, with or without
     13  1.1.1.2  jruoho  * modification, are permitted provided that the following conditions
     14  1.1.1.2  jruoho  * are met:
     15  1.1.1.2  jruoho  * 1. Redistributions of source code must retain the above copyright
     16  1.1.1.2  jruoho  *    notice, this list of conditions, and the following disclaimer,
     17  1.1.1.2  jruoho  *    without modification.
     18  1.1.1.2  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19  1.1.1.2  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     20  1.1.1.2  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     21  1.1.1.2  jruoho  *    including a substantially similar Disclaimer requirement for further
     22  1.1.1.2  jruoho  *    binary redistribution.
     23  1.1.1.2  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     24  1.1.1.2  jruoho  *    of any contributors may be used to endorse or promote products derived
     25  1.1.1.2  jruoho  *    from this software without specific prior written permission.
     26  1.1.1.2  jruoho  *
     27  1.1.1.2  jruoho  * Alternatively, this software may be distributed under the terms of the
     28  1.1.1.2  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     29  1.1.1.2  jruoho  * Software Foundation.
     30  1.1.1.2  jruoho  *
     31  1.1.1.2  jruoho  * NO WARRANTY
     32  1.1.1.2  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33  1.1.1.2  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34  1.1.1.2  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     35  1.1.1.2  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36  1.1.1.2  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  1.1.1.2  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  1.1.1.2  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  1.1.1.2  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40  1.1.1.2  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41  1.1.1.2  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42  1.1.1.2  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     43  1.1.1.2  jruoho  */
     44      1.1  jruoho 
     45      1.1  jruoho #define __EXSTOROB_C__
     46      1.1  jruoho 
     47      1.1  jruoho #include "acpi.h"
     48      1.1  jruoho #include "accommon.h"
     49      1.1  jruoho #include "acinterp.h"
     50      1.1  jruoho 
     51      1.1  jruoho 
     52      1.1  jruoho #define _COMPONENT          ACPI_EXECUTER
     53      1.1  jruoho         ACPI_MODULE_NAME    ("exstorob")
     54      1.1  jruoho 
     55      1.1  jruoho 
     56      1.1  jruoho /*******************************************************************************
     57      1.1  jruoho  *
     58      1.1  jruoho  * FUNCTION:    AcpiExStoreBufferToBuffer
     59      1.1  jruoho  *
     60      1.1  jruoho  * PARAMETERS:  SourceDesc          - Source object to copy
     61      1.1  jruoho  *              TargetDesc          - Destination object of the copy
     62      1.1  jruoho  *
     63      1.1  jruoho  * RETURN:      Status
     64      1.1  jruoho  *
     65      1.1  jruoho  * DESCRIPTION: Copy a buffer object to another buffer object.
     66      1.1  jruoho  *
     67      1.1  jruoho  ******************************************************************************/
     68      1.1  jruoho 
     69      1.1  jruoho ACPI_STATUS
     70      1.1  jruoho AcpiExStoreBufferToBuffer (
     71      1.1  jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
     72      1.1  jruoho     ACPI_OPERAND_OBJECT     *TargetDesc)
     73      1.1  jruoho {
     74      1.1  jruoho     UINT32                  Length;
     75      1.1  jruoho     UINT8                   *Buffer;
     76      1.1  jruoho 
     77      1.1  jruoho 
     78      1.1  jruoho     ACPI_FUNCTION_TRACE_PTR (ExStoreBufferToBuffer, SourceDesc);
     79      1.1  jruoho 
     80      1.1  jruoho 
     81      1.1  jruoho     /* If Source and Target are the same, just return */
     82      1.1  jruoho 
     83      1.1  jruoho     if (SourceDesc == TargetDesc)
     84      1.1  jruoho     {
     85      1.1  jruoho         return_ACPI_STATUS (AE_OK);
     86      1.1  jruoho     }
     87      1.1  jruoho 
     88      1.1  jruoho     /* We know that SourceDesc is a buffer by now */
     89      1.1  jruoho 
     90      1.1  jruoho     Buffer = ACPI_CAST_PTR (UINT8, SourceDesc->Buffer.Pointer);
     91      1.1  jruoho     Length = SourceDesc->Buffer.Length;
     92      1.1  jruoho 
     93      1.1  jruoho     /*
     94      1.1  jruoho      * If target is a buffer of length zero or is a static buffer,
     95      1.1  jruoho      * allocate a new buffer of the proper length
     96      1.1  jruoho      */
     97      1.1  jruoho     if ((TargetDesc->Buffer.Length == 0) ||
     98      1.1  jruoho         (TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER))
     99      1.1  jruoho     {
    100      1.1  jruoho         TargetDesc->Buffer.Pointer = ACPI_ALLOCATE (Length);
    101      1.1  jruoho         if (!TargetDesc->Buffer.Pointer)
    102      1.1  jruoho         {
    103      1.1  jruoho             return_ACPI_STATUS (AE_NO_MEMORY);
    104      1.1  jruoho         }
    105      1.1  jruoho 
    106      1.1  jruoho         TargetDesc->Buffer.Length = Length;
    107      1.1  jruoho     }
    108      1.1  jruoho 
    109      1.1  jruoho     /* Copy source buffer to target buffer */
    110      1.1  jruoho 
    111      1.1  jruoho     if (Length <= TargetDesc->Buffer.Length)
    112      1.1  jruoho     {
    113      1.1  jruoho         /* Clear existing buffer and copy in the new one */
    114      1.1  jruoho 
    115      1.1  jruoho         ACPI_MEMSET (TargetDesc->Buffer.Pointer, 0, TargetDesc->Buffer.Length);
    116      1.1  jruoho         ACPI_MEMCPY (TargetDesc->Buffer.Pointer, Buffer, Length);
    117      1.1  jruoho 
    118      1.1  jruoho #ifdef ACPI_OBSOLETE_BEHAVIOR
    119      1.1  jruoho         /*
    120      1.1  jruoho          * NOTE: ACPI versions up to 3.0 specified that the buffer must be
    121      1.1  jruoho          * truncated if the string is smaller than the buffer.  However, "other"
    122      1.1  jruoho          * implementations of ACPI never did this and thus became the defacto
    123      1.1  jruoho          * standard. ACPI 3.0A changes this behavior such that the buffer
    124      1.1  jruoho          * is no longer truncated.
    125      1.1  jruoho          */
    126      1.1  jruoho 
    127      1.1  jruoho         /*
    128      1.1  jruoho          * OBSOLETE BEHAVIOR:
    129      1.1  jruoho          * If the original source was a string, we must truncate the buffer,
    130      1.1  jruoho          * according to the ACPI spec.  Integer-to-Buffer and Buffer-to-Buffer
    131      1.1  jruoho          * copy must not truncate the original buffer.
    132      1.1  jruoho          */
    133      1.1  jruoho         if (OriginalSrcType == ACPI_TYPE_STRING)
    134      1.1  jruoho         {
    135      1.1  jruoho             /* Set the new length of the target */
    136      1.1  jruoho 
    137      1.1  jruoho             TargetDesc->Buffer.Length = Length;
    138      1.1  jruoho         }
    139      1.1  jruoho #endif
    140      1.1  jruoho     }
    141      1.1  jruoho     else
    142      1.1  jruoho     {
    143      1.1  jruoho         /* Truncate the source, copy only what will fit */
    144      1.1  jruoho 
    145      1.1  jruoho         ACPI_MEMCPY (TargetDesc->Buffer.Pointer, Buffer,
    146      1.1  jruoho             TargetDesc->Buffer.Length);
    147      1.1  jruoho 
    148      1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    149      1.1  jruoho             "Truncating source buffer from %X to %X\n",
    150      1.1  jruoho             Length, TargetDesc->Buffer.Length));
    151      1.1  jruoho     }
    152      1.1  jruoho 
    153      1.1  jruoho     /* Copy flags */
    154      1.1  jruoho 
    155      1.1  jruoho     TargetDesc->Buffer.Flags = SourceDesc->Buffer.Flags;
    156      1.1  jruoho     TargetDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
    157      1.1  jruoho     return_ACPI_STATUS (AE_OK);
    158      1.1  jruoho }
    159      1.1  jruoho 
    160      1.1  jruoho 
    161      1.1  jruoho /*******************************************************************************
    162      1.1  jruoho  *
    163      1.1  jruoho  * FUNCTION:    AcpiExStoreStringToString
    164      1.1  jruoho  *
    165      1.1  jruoho  * PARAMETERS:  SourceDesc          - Source object to copy
    166      1.1  jruoho  *              TargetDesc          - Destination object of the copy
    167      1.1  jruoho  *
    168      1.1  jruoho  * RETURN:      Status
    169      1.1  jruoho  *
    170      1.1  jruoho  * DESCRIPTION: Copy a String object to another String object
    171      1.1  jruoho  *
    172      1.1  jruoho  ******************************************************************************/
    173      1.1  jruoho 
    174      1.1  jruoho ACPI_STATUS
    175      1.1  jruoho AcpiExStoreStringToString (
    176      1.1  jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
    177      1.1  jruoho     ACPI_OPERAND_OBJECT     *TargetDesc)
    178      1.1  jruoho {
    179      1.1  jruoho     UINT32                  Length;
    180      1.1  jruoho     UINT8                   *Buffer;
    181      1.1  jruoho 
    182      1.1  jruoho 
    183      1.1  jruoho     ACPI_FUNCTION_TRACE_PTR (ExStoreStringToString, SourceDesc);
    184      1.1  jruoho 
    185      1.1  jruoho 
    186      1.1  jruoho     /* If Source and Target are the same, just return */
    187      1.1  jruoho 
    188      1.1  jruoho     if (SourceDesc == TargetDesc)
    189      1.1  jruoho     {
    190      1.1  jruoho         return_ACPI_STATUS (AE_OK);
    191      1.1  jruoho     }
    192      1.1  jruoho 
    193      1.1  jruoho     /* We know that SourceDesc is a string by now */
    194      1.1  jruoho 
    195      1.1  jruoho     Buffer = ACPI_CAST_PTR (UINT8, SourceDesc->String.Pointer);
    196      1.1  jruoho     Length = SourceDesc->String.Length;
    197      1.1  jruoho 
    198      1.1  jruoho     /*
    199      1.1  jruoho      * Replace existing string value if it will fit and the string
    200      1.1  jruoho      * pointer is not a static pointer (part of an ACPI table)
    201      1.1  jruoho      */
    202      1.1  jruoho     if ((Length < TargetDesc->String.Length) &&
    203      1.1  jruoho        (!(TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
    204      1.1  jruoho     {
    205      1.1  jruoho         /*
    206      1.1  jruoho          * String will fit in existing non-static buffer.
    207      1.1  jruoho          * Clear old string and copy in the new one
    208      1.1  jruoho          */
    209      1.1  jruoho         ACPI_MEMSET (TargetDesc->String.Pointer, 0,
    210      1.1  jruoho             (ACPI_SIZE) TargetDesc->String.Length + 1);
    211      1.1  jruoho         ACPI_MEMCPY (TargetDesc->String.Pointer, Buffer, Length);
    212      1.1  jruoho     }
    213      1.1  jruoho     else
    214      1.1  jruoho     {
    215      1.1  jruoho         /*
    216      1.1  jruoho          * Free the current buffer, then allocate a new buffer
    217      1.1  jruoho          * large enough to hold the value
    218      1.1  jruoho          */
    219      1.1  jruoho         if (TargetDesc->String.Pointer &&
    220      1.1  jruoho            (!(TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
    221      1.1  jruoho         {
    222      1.1  jruoho             /* Only free if not a pointer into the DSDT */
    223      1.1  jruoho 
    224      1.1  jruoho             ACPI_FREE (TargetDesc->String.Pointer);
    225      1.1  jruoho         }
    226      1.1  jruoho 
    227      1.1  jruoho         TargetDesc->String.Pointer = ACPI_ALLOCATE_ZEROED (
    228      1.1  jruoho                                         (ACPI_SIZE) Length + 1);
    229      1.1  jruoho         if (!TargetDesc->String.Pointer)
    230      1.1  jruoho         {
    231      1.1  jruoho             return_ACPI_STATUS (AE_NO_MEMORY);
    232      1.1  jruoho         }
    233      1.1  jruoho 
    234      1.1  jruoho         TargetDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
    235      1.1  jruoho         ACPI_MEMCPY (TargetDesc->String.Pointer, Buffer, Length);
    236      1.1  jruoho     }
    237      1.1  jruoho 
    238      1.1  jruoho     /* Set the new target length */
    239      1.1  jruoho 
    240      1.1  jruoho     TargetDesc->String.Length = Length;
    241      1.1  jruoho     return_ACPI_STATUS (AE_OK);
    242      1.1  jruoho }
    243      1.1  jruoho 
    244      1.1  jruoho 
    245