Home | History | Annotate | Line # | Download | only in executer
exstoren.c revision 1.1.1.8
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3      1.1    jruoho  * Module Name: exstoren - AML Interpreter object store support,
      4      1.1    jruoho  *                        Store to Node (namespace object)
      5      1.1    jruoho  *
      6      1.1    jruoho  *****************************************************************************/
      7      1.1    jruoho 
      8  1.1.1.2    jruoho /*
      9  1.1.1.7  christos  * Copyright (C) 2000 - 2017, 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 #include "acpi.h"
     46      1.1    jruoho #include "accommon.h"
     47      1.1    jruoho #include "acinterp.h"
     48      1.1    jruoho #include "amlcode.h"
     49      1.1    jruoho 
     50      1.1    jruoho 
     51      1.1    jruoho #define _COMPONENT          ACPI_EXECUTER
     52      1.1    jruoho         ACPI_MODULE_NAME    ("exstoren")
     53      1.1    jruoho 
     54      1.1    jruoho 
     55      1.1    jruoho /*******************************************************************************
     56      1.1    jruoho  *
     57      1.1    jruoho  * FUNCTION:    AcpiExResolveObject
     58      1.1    jruoho  *
     59      1.1    jruoho  * PARAMETERS:  SourceDescPtr       - Pointer to the source object
     60      1.1    jruoho  *              TargetType          - Current type of the target
     61      1.1    jruoho  *              WalkState           - Current walk state
     62      1.1    jruoho  *
     63      1.1    jruoho  * RETURN:      Status, resolved object in SourceDescPtr.
     64      1.1    jruoho  *
     65  1.1.1.3  christos  * DESCRIPTION: Resolve an object. If the object is a reference, dereference
     66      1.1    jruoho  *              it and return the actual object in the SourceDescPtr.
     67      1.1    jruoho  *
     68      1.1    jruoho  ******************************************************************************/
     69      1.1    jruoho 
     70      1.1    jruoho ACPI_STATUS
     71      1.1    jruoho AcpiExResolveObject (
     72      1.1    jruoho     ACPI_OPERAND_OBJECT     **SourceDescPtr,
     73      1.1    jruoho     ACPI_OBJECT_TYPE        TargetType,
     74      1.1    jruoho     ACPI_WALK_STATE         *WalkState)
     75      1.1    jruoho {
     76      1.1    jruoho     ACPI_OPERAND_OBJECT     *SourceDesc = *SourceDescPtr;
     77      1.1    jruoho     ACPI_STATUS             Status = AE_OK;
     78      1.1    jruoho 
     79      1.1    jruoho 
     80      1.1    jruoho     ACPI_FUNCTION_TRACE (ExResolveObject);
     81      1.1    jruoho 
     82      1.1    jruoho 
     83      1.1    jruoho     /* Ensure we have a Target that can be stored to */
     84      1.1    jruoho 
     85      1.1    jruoho     switch (TargetType)
     86      1.1    jruoho     {
     87      1.1    jruoho     case ACPI_TYPE_BUFFER_FIELD:
     88      1.1    jruoho     case ACPI_TYPE_LOCAL_REGION_FIELD:
     89      1.1    jruoho     case ACPI_TYPE_LOCAL_BANK_FIELD:
     90      1.1    jruoho     case ACPI_TYPE_LOCAL_INDEX_FIELD:
     91      1.1    jruoho         /*
     92      1.1    jruoho          * These cases all require only Integers or values that
     93      1.1    jruoho          * can be converted to Integers (Strings or Buffers)
     94      1.1    jruoho          */
     95      1.1    jruoho     case ACPI_TYPE_INTEGER:
     96      1.1    jruoho     case ACPI_TYPE_STRING:
     97      1.1    jruoho     case ACPI_TYPE_BUFFER:
     98      1.1    jruoho         /*
     99      1.1    jruoho          * Stores into a Field/Region or into a Integer/Buffer/String
    100  1.1.1.3  christos          * are all essentially the same. This case handles the
    101      1.1    jruoho          * "interchangeable" types Integer, String, and Buffer.
    102      1.1    jruoho          */
    103      1.1    jruoho         if (SourceDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
    104      1.1    jruoho         {
    105      1.1    jruoho             /* Resolve a reference object first */
    106      1.1    jruoho 
    107      1.1    jruoho             Status = AcpiExResolveToValue (SourceDescPtr, WalkState);
    108      1.1    jruoho             if (ACPI_FAILURE (Status))
    109      1.1    jruoho             {
    110      1.1    jruoho                 break;
    111      1.1    jruoho             }
    112      1.1    jruoho         }
    113      1.1    jruoho 
    114      1.1    jruoho         /* For CopyObject, no further validation necessary */
    115      1.1    jruoho 
    116  1.1.1.8  christos         if (WalkState->Opcode == AML_COPY_OBJECT_OP)
    117      1.1    jruoho         {
    118      1.1    jruoho             break;
    119      1.1    jruoho         }
    120      1.1    jruoho 
    121      1.1    jruoho         /* Must have a Integer, Buffer, or String */
    122      1.1    jruoho 
    123      1.1    jruoho         if ((SourceDesc->Common.Type != ACPI_TYPE_INTEGER)    &&
    124      1.1    jruoho             (SourceDesc->Common.Type != ACPI_TYPE_BUFFER)     &&
    125      1.1    jruoho             (SourceDesc->Common.Type != ACPI_TYPE_STRING)     &&
    126      1.1    jruoho             !((SourceDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
    127  1.1.1.6  christos                 (SourceDesc->Reference.Class== ACPI_REFCLASS_TABLE)))
    128      1.1    jruoho         {
    129      1.1    jruoho             /* Conversion successful but still not a valid type */
    130      1.1    jruoho 
    131      1.1    jruoho             ACPI_ERROR ((AE_INFO,
    132  1.1.1.6  christos                 "Cannot assign type [%s] to [%s] (must be type Int/Str/Buf)",
    133      1.1    jruoho                 AcpiUtGetObjectTypeName (SourceDesc),
    134      1.1    jruoho                 AcpiUtGetTypeName (TargetType)));
    135  1.1.1.6  christos 
    136      1.1    jruoho             Status = AE_AML_OPERAND_TYPE;
    137      1.1    jruoho         }
    138      1.1    jruoho         break;
    139      1.1    jruoho 
    140      1.1    jruoho     case ACPI_TYPE_LOCAL_ALIAS:
    141      1.1    jruoho     case ACPI_TYPE_LOCAL_METHOD_ALIAS:
    142      1.1    jruoho         /*
    143      1.1    jruoho          * All aliases should have been resolved earlier, during the
    144      1.1    jruoho          * operand resolution phase.
    145      1.1    jruoho          */
    146      1.1    jruoho         ACPI_ERROR ((AE_INFO, "Store into an unresolved Alias object"));
    147      1.1    jruoho         Status = AE_AML_INTERNAL;
    148      1.1    jruoho         break;
    149      1.1    jruoho 
    150      1.1    jruoho     case ACPI_TYPE_PACKAGE:
    151      1.1    jruoho     default:
    152      1.1    jruoho         /*
    153      1.1    jruoho          * All other types than Alias and the various Fields come here,
    154      1.1    jruoho          * including the untyped case - ACPI_TYPE_ANY.
    155      1.1    jruoho          */
    156      1.1    jruoho         break;
    157      1.1    jruoho     }
    158      1.1    jruoho 
    159      1.1    jruoho     return_ACPI_STATUS (Status);
    160      1.1    jruoho }
    161      1.1    jruoho 
    162      1.1    jruoho 
    163      1.1    jruoho /*******************************************************************************
    164      1.1    jruoho  *
    165      1.1    jruoho  * FUNCTION:    AcpiExStoreObjectToObject
    166      1.1    jruoho  *
    167      1.1    jruoho  * PARAMETERS:  SourceDesc          - Object to store
    168      1.1    jruoho  *              DestDesc            - Object to receive a copy of the source
    169      1.1    jruoho  *              NewDesc             - New object if DestDesc is obsoleted
    170      1.1    jruoho  *              WalkState           - Current walk state
    171      1.1    jruoho  *
    172      1.1    jruoho  * RETURN:      Status
    173      1.1    jruoho  *
    174  1.1.1.3  christos  * DESCRIPTION: "Store" an object to another object. This may include
    175      1.1    jruoho  *              converting the source type to the target type (implicit
    176      1.1    jruoho  *              conversion), and a copy of the value of the source to
    177      1.1    jruoho  *              the target.
    178      1.1    jruoho  *
    179      1.1    jruoho  *              The Assignment of an object to another (not named) object
    180      1.1    jruoho  *              is handled here.
    181      1.1    jruoho  *              The Source passed in will replace the current value (if any)
    182      1.1    jruoho  *              with the input value.
    183      1.1    jruoho  *
    184      1.1    jruoho  *              When storing into an object the data is converted to the
    185  1.1.1.3  christos  *              target object type then stored in the object. This means
    186      1.1    jruoho  *              that the target object type (for an initialized target) will
    187      1.1    jruoho  *              not be changed by a store operation.
    188      1.1    jruoho  *
    189      1.1    jruoho  *              This module allows destination types of Number, String,
    190      1.1    jruoho  *              Buffer, and Package.
    191      1.1    jruoho  *
    192  1.1.1.3  christos  *              Assumes parameters are already validated. NOTE: SourceDesc
    193      1.1    jruoho  *              resolution (from a reference object) must be performed by
    194      1.1    jruoho  *              the caller if necessary.
    195      1.1    jruoho  *
    196      1.1    jruoho  ******************************************************************************/
    197      1.1    jruoho 
    198      1.1    jruoho ACPI_STATUS
    199      1.1    jruoho AcpiExStoreObjectToObject (
    200      1.1    jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
    201      1.1    jruoho     ACPI_OPERAND_OBJECT     *DestDesc,
    202      1.1    jruoho     ACPI_OPERAND_OBJECT     **NewDesc,
    203      1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    204      1.1    jruoho {
    205      1.1    jruoho     ACPI_OPERAND_OBJECT     *ActualSrcDesc;
    206      1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    207      1.1    jruoho 
    208      1.1    jruoho 
    209      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToObject, SourceDesc);
    210      1.1    jruoho 
    211      1.1    jruoho 
    212      1.1    jruoho     ActualSrcDesc = SourceDesc;
    213      1.1    jruoho     if (!DestDesc)
    214      1.1    jruoho     {
    215      1.1    jruoho         /*
    216      1.1    jruoho          * There is no destination object (An uninitialized node or
    217      1.1    jruoho          * package element), so we can simply copy the source object
    218      1.1    jruoho          * creating a new destination object
    219      1.1    jruoho          */
    220      1.1    jruoho         Status = AcpiUtCopyIobjectToIobject (ActualSrcDesc, NewDesc, WalkState);
    221      1.1    jruoho         return_ACPI_STATUS (Status);
    222      1.1    jruoho     }
    223      1.1    jruoho 
    224      1.1    jruoho     if (SourceDesc->Common.Type != DestDesc->Common.Type)
    225      1.1    jruoho     {
    226      1.1    jruoho         /*
    227      1.1    jruoho          * The source type does not match the type of the destination.
    228      1.1    jruoho          * Perform the "implicit conversion" of the source to the current type
    229      1.1    jruoho          * of the target as per the ACPI specification.
    230      1.1    jruoho          *
    231      1.1    jruoho          * If no conversion performed, ActualSrcDesc = SourceDesc.
    232      1.1    jruoho          * Otherwise, ActualSrcDesc is a temporary object to hold the
    233      1.1    jruoho          * converted object.
    234      1.1    jruoho          */
    235      1.1    jruoho         Status = AcpiExConvertToTargetType (DestDesc->Common.Type,
    236  1.1.1.6  christos             SourceDesc, &ActualSrcDesc, WalkState);
    237      1.1    jruoho         if (ACPI_FAILURE (Status))
    238      1.1    jruoho         {
    239      1.1    jruoho             return_ACPI_STATUS (Status);
    240      1.1    jruoho         }
    241      1.1    jruoho 
    242      1.1    jruoho         if (SourceDesc == ActualSrcDesc)
    243      1.1    jruoho         {
    244      1.1    jruoho             /*
    245      1.1    jruoho              * No conversion was performed. Return the SourceDesc as the
    246      1.1    jruoho              * new object.
    247      1.1    jruoho              */
    248      1.1    jruoho             *NewDesc = SourceDesc;
    249      1.1    jruoho             return_ACPI_STATUS (AE_OK);
    250      1.1    jruoho         }
    251      1.1    jruoho     }
    252      1.1    jruoho 
    253      1.1    jruoho     /*
    254      1.1    jruoho      * We now have two objects of identical types, and we can perform a
    255      1.1    jruoho      * copy of the *value* of the source object.
    256      1.1    jruoho      */
    257      1.1    jruoho     switch (DestDesc->Common.Type)
    258      1.1    jruoho     {
    259      1.1    jruoho     case ACPI_TYPE_INTEGER:
    260      1.1    jruoho 
    261      1.1    jruoho         DestDesc->Integer.Value = ActualSrcDesc->Integer.Value;
    262      1.1    jruoho 
    263      1.1    jruoho         /* Truncate value if we are executing from a 32-bit ACPI table */
    264      1.1    jruoho 
    265  1.1.1.3  christos         (void) AcpiExTruncateFor32bitTable (DestDesc);
    266      1.1    jruoho         break;
    267      1.1    jruoho 
    268      1.1    jruoho     case ACPI_TYPE_STRING:
    269      1.1    jruoho 
    270      1.1    jruoho         Status = AcpiExStoreStringToString (ActualSrcDesc, DestDesc);
    271      1.1    jruoho         break;
    272      1.1    jruoho 
    273      1.1    jruoho     case ACPI_TYPE_BUFFER:
    274      1.1    jruoho 
    275      1.1    jruoho         Status = AcpiExStoreBufferToBuffer (ActualSrcDesc, DestDesc);
    276      1.1    jruoho         break;
    277      1.1    jruoho 
    278      1.1    jruoho     case ACPI_TYPE_PACKAGE:
    279      1.1    jruoho 
    280      1.1    jruoho         Status = AcpiUtCopyIobjectToIobject (ActualSrcDesc, &DestDesc,
    281      1.1    jruoho                     WalkState);
    282      1.1    jruoho         break;
    283      1.1    jruoho 
    284      1.1    jruoho     default:
    285      1.1    jruoho         /*
    286      1.1    jruoho          * All other types come here.
    287      1.1    jruoho          */
    288  1.1.1.6  christos         ACPI_WARNING ((AE_INFO, "Store into type [%s] not implemented",
    289      1.1    jruoho             AcpiUtGetObjectTypeName (DestDesc)));
    290      1.1    jruoho 
    291      1.1    jruoho         Status = AE_NOT_IMPLEMENTED;
    292      1.1    jruoho         break;
    293      1.1    jruoho     }
    294      1.1    jruoho 
    295      1.1    jruoho     if (ActualSrcDesc != SourceDesc)
    296      1.1    jruoho     {
    297      1.1    jruoho         /* Delete the intermediate (temporary) source object */
    298      1.1    jruoho 
    299      1.1    jruoho         AcpiUtRemoveReference (ActualSrcDesc);
    300      1.1    jruoho     }
    301      1.1    jruoho 
    302      1.1    jruoho     *NewDesc = DestDesc;
    303      1.1    jruoho     return_ACPI_STATUS (Status);
    304      1.1    jruoho }
    305