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