Home | History | Annotate | Line # | Download | only in executer
exstorob.c revision 1.1.1.7
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3  1.1.1.7  christos  * Module Name: exstorob - AML 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.7  christos  * Copyright (C) 2000 - 2016, 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 #include "acpi.h"
     45      1.1    jruoho #include "accommon.h"
     46      1.1    jruoho #include "acinterp.h"
     47      1.1    jruoho 
     48      1.1    jruoho 
     49      1.1    jruoho #define _COMPONENT          ACPI_EXECUTER
     50      1.1    jruoho         ACPI_MODULE_NAME    ("exstorob")
     51      1.1    jruoho 
     52      1.1    jruoho 
     53      1.1    jruoho /*******************************************************************************
     54      1.1    jruoho  *
     55      1.1    jruoho  * FUNCTION:    AcpiExStoreBufferToBuffer
     56      1.1    jruoho  *
     57      1.1    jruoho  * PARAMETERS:  SourceDesc          - Source object to copy
     58      1.1    jruoho  *              TargetDesc          - Destination object of the copy
     59      1.1    jruoho  *
     60      1.1    jruoho  * RETURN:      Status
     61      1.1    jruoho  *
     62      1.1    jruoho  * DESCRIPTION: Copy a buffer object to another buffer object.
     63      1.1    jruoho  *
     64      1.1    jruoho  ******************************************************************************/
     65      1.1    jruoho 
     66      1.1    jruoho ACPI_STATUS
     67      1.1    jruoho AcpiExStoreBufferToBuffer (
     68      1.1    jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
     69      1.1    jruoho     ACPI_OPERAND_OBJECT     *TargetDesc)
     70      1.1    jruoho {
     71      1.1    jruoho     UINT32                  Length;
     72      1.1    jruoho     UINT8                   *Buffer;
     73      1.1    jruoho 
     74      1.1    jruoho 
     75      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (ExStoreBufferToBuffer, SourceDesc);
     76      1.1    jruoho 
     77      1.1    jruoho 
     78      1.1    jruoho     /* If Source and Target are the same, just return */
     79      1.1    jruoho 
     80      1.1    jruoho     if (SourceDesc == TargetDesc)
     81      1.1    jruoho     {
     82      1.1    jruoho         return_ACPI_STATUS (AE_OK);
     83      1.1    jruoho     }
     84      1.1    jruoho 
     85      1.1    jruoho     /* We know that SourceDesc is a buffer by now */
     86      1.1    jruoho 
     87      1.1    jruoho     Buffer = ACPI_CAST_PTR (UINT8, SourceDesc->Buffer.Pointer);
     88      1.1    jruoho     Length = SourceDesc->Buffer.Length;
     89      1.1    jruoho 
     90      1.1    jruoho     /*
     91      1.1    jruoho      * If target is a buffer of length zero or is a static buffer,
     92      1.1    jruoho      * allocate a new buffer of the proper length
     93      1.1    jruoho      */
     94      1.1    jruoho     if ((TargetDesc->Buffer.Length == 0) ||
     95      1.1    jruoho         (TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER))
     96      1.1    jruoho     {
     97      1.1    jruoho         TargetDesc->Buffer.Pointer = ACPI_ALLOCATE (Length);
     98      1.1    jruoho         if (!TargetDesc->Buffer.Pointer)
     99      1.1    jruoho         {
    100      1.1    jruoho             return_ACPI_STATUS (AE_NO_MEMORY);
    101      1.1    jruoho         }
    102      1.1    jruoho 
    103      1.1    jruoho         TargetDesc->Buffer.Length = Length;
    104      1.1    jruoho     }
    105      1.1    jruoho 
    106      1.1    jruoho     /* Copy source buffer to target buffer */
    107      1.1    jruoho 
    108      1.1    jruoho     if (Length <= TargetDesc->Buffer.Length)
    109      1.1    jruoho     {
    110      1.1    jruoho         /* Clear existing buffer and copy in the new one */
    111      1.1    jruoho 
    112  1.1.1.6  christos         memset (TargetDesc->Buffer.Pointer, 0, TargetDesc->Buffer.Length);
    113  1.1.1.6  christos         memcpy (TargetDesc->Buffer.Pointer, Buffer, Length);
    114      1.1    jruoho 
    115      1.1    jruoho #ifdef ACPI_OBSOLETE_BEHAVIOR
    116      1.1    jruoho         /*
    117      1.1    jruoho          * NOTE: ACPI versions up to 3.0 specified that the buffer must be
    118  1.1.1.3  christos          * truncated if the string is smaller than the buffer. However, "other"
    119      1.1    jruoho          * implementations of ACPI never did this and thus became the defacto
    120      1.1    jruoho          * standard. ACPI 3.0A changes this behavior such that the buffer
    121      1.1    jruoho          * is no longer truncated.
    122      1.1    jruoho          */
    123      1.1    jruoho 
    124      1.1    jruoho         /*
    125      1.1    jruoho          * OBSOLETE BEHAVIOR:
    126      1.1    jruoho          * If the original source was a string, we must truncate the buffer,
    127  1.1.1.3  christos          * according to the ACPI spec. Integer-to-Buffer and Buffer-to-Buffer
    128      1.1    jruoho          * copy must not truncate the original buffer.
    129      1.1    jruoho          */
    130      1.1    jruoho         if (OriginalSrcType == ACPI_TYPE_STRING)
    131      1.1    jruoho         {
    132      1.1    jruoho             /* Set the new length of the target */
    133      1.1    jruoho 
    134      1.1    jruoho             TargetDesc->Buffer.Length = Length;
    135      1.1    jruoho         }
    136      1.1    jruoho #endif
    137      1.1    jruoho     }
    138      1.1    jruoho     else
    139      1.1    jruoho     {
    140      1.1    jruoho         /* Truncate the source, copy only what will fit */
    141      1.1    jruoho 
    142  1.1.1.6  christos         memcpy (TargetDesc->Buffer.Pointer, Buffer,
    143      1.1    jruoho             TargetDesc->Buffer.Length);
    144      1.1    jruoho 
    145      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    146      1.1    jruoho             "Truncating source buffer from %X to %X\n",
    147      1.1    jruoho             Length, TargetDesc->Buffer.Length));
    148      1.1    jruoho     }
    149      1.1    jruoho 
    150      1.1    jruoho     /* Copy flags */
    151      1.1    jruoho 
    152      1.1    jruoho     TargetDesc->Buffer.Flags = SourceDesc->Buffer.Flags;
    153      1.1    jruoho     TargetDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
    154      1.1    jruoho     return_ACPI_STATUS (AE_OK);
    155      1.1    jruoho }
    156      1.1    jruoho 
    157      1.1    jruoho 
    158      1.1    jruoho /*******************************************************************************
    159      1.1    jruoho  *
    160      1.1    jruoho  * FUNCTION:    AcpiExStoreStringToString
    161      1.1    jruoho  *
    162      1.1    jruoho  * PARAMETERS:  SourceDesc          - Source object to copy
    163      1.1    jruoho  *              TargetDesc          - Destination object of the copy
    164      1.1    jruoho  *
    165      1.1    jruoho  * RETURN:      Status
    166      1.1    jruoho  *
    167      1.1    jruoho  * DESCRIPTION: Copy a String object to another String object
    168      1.1    jruoho  *
    169      1.1    jruoho  ******************************************************************************/
    170      1.1    jruoho 
    171      1.1    jruoho ACPI_STATUS
    172      1.1    jruoho AcpiExStoreStringToString (
    173      1.1    jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
    174      1.1    jruoho     ACPI_OPERAND_OBJECT     *TargetDesc)
    175      1.1    jruoho {
    176      1.1    jruoho     UINT32                  Length;
    177      1.1    jruoho     UINT8                   *Buffer;
    178      1.1    jruoho 
    179      1.1    jruoho 
    180      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (ExStoreStringToString, SourceDesc);
    181      1.1    jruoho 
    182      1.1    jruoho 
    183      1.1    jruoho     /* If Source and Target are the same, just return */
    184      1.1    jruoho 
    185      1.1    jruoho     if (SourceDesc == TargetDesc)
    186      1.1    jruoho     {
    187      1.1    jruoho         return_ACPI_STATUS (AE_OK);
    188      1.1    jruoho     }
    189      1.1    jruoho 
    190      1.1    jruoho     /* We know that SourceDesc is a string by now */
    191      1.1    jruoho 
    192      1.1    jruoho     Buffer = ACPI_CAST_PTR (UINT8, SourceDesc->String.Pointer);
    193      1.1    jruoho     Length = SourceDesc->String.Length;
    194      1.1    jruoho 
    195      1.1    jruoho     /*
    196      1.1    jruoho      * Replace existing string value if it will fit and the string
    197      1.1    jruoho      * pointer is not a static pointer (part of an ACPI table)
    198      1.1    jruoho      */
    199      1.1    jruoho     if ((Length < TargetDesc->String.Length) &&
    200      1.1    jruoho        (!(TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
    201      1.1    jruoho     {
    202      1.1    jruoho         /*
    203      1.1    jruoho          * String will fit in existing non-static buffer.
    204      1.1    jruoho          * Clear old string and copy in the new one
    205      1.1    jruoho          */
    206  1.1.1.6  christos         memset (TargetDesc->String.Pointer, 0,
    207      1.1    jruoho             (ACPI_SIZE) TargetDesc->String.Length + 1);
    208  1.1.1.6  christos         memcpy (TargetDesc->String.Pointer, Buffer, Length);
    209      1.1    jruoho     }
    210      1.1    jruoho     else
    211      1.1    jruoho     {
    212      1.1    jruoho         /*
    213      1.1    jruoho          * Free the current buffer, then allocate a new buffer
    214      1.1    jruoho          * large enough to hold the value
    215      1.1    jruoho          */
    216      1.1    jruoho         if (TargetDesc->String.Pointer &&
    217      1.1    jruoho            (!(TargetDesc->Common.Flags & AOPOBJ_STATIC_POINTER)))
    218      1.1    jruoho         {
    219      1.1    jruoho             /* Only free if not a pointer into the DSDT */
    220      1.1    jruoho 
    221      1.1    jruoho             ACPI_FREE (TargetDesc->String.Pointer);
    222      1.1    jruoho         }
    223      1.1    jruoho 
    224  1.1.1.7  christos         TargetDesc->String.Pointer =
    225  1.1.1.7  christos             ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) Length + 1);
    226  1.1.1.7  christos 
    227      1.1    jruoho         if (!TargetDesc->String.Pointer)
    228      1.1    jruoho         {
    229      1.1    jruoho             return_ACPI_STATUS (AE_NO_MEMORY);
    230      1.1    jruoho         }
    231      1.1    jruoho 
    232      1.1    jruoho         TargetDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
    233  1.1.1.6  christos         memcpy (TargetDesc->String.Pointer, Buffer, Length);
    234      1.1    jruoho     }
    235      1.1    jruoho 
    236      1.1    jruoho     /* Set the new target length */
    237      1.1    jruoho 
    238      1.1    jruoho     TargetDesc->String.Length = Length;
    239      1.1    jruoho     return_ACPI_STATUS (AE_OK);
    240      1.1    jruoho }
    241