Home | History | Annotate | Line # | Download | only in executer
exstoren.c revision 1.1.1.2
      1      1.1  jruoho 
      2      1.1  jruoho /******************************************************************************
      3      1.1  jruoho  *
      4      1.1  jruoho  * Module Name: exstoren - AML Interpreter object store support,
      5      1.1  jruoho  *                        Store to Node (namespace object)
      6      1.1  jruoho  *
      7      1.1  jruoho  *****************************************************************************/
      8      1.1  jruoho 
      9  1.1.1.2  jruoho /*
     10  1.1.1.2  jruoho  * Copyright (C) 2000 - 2011, Intel Corp.
     11      1.1  jruoho  * All rights reserved.
     12      1.1  jruoho  *
     13  1.1.1.2  jruoho  * Redistribution and use in source and binary forms, with or without
     14  1.1.1.2  jruoho  * modification, are permitted provided that the following conditions
     15  1.1.1.2  jruoho  * are met:
     16  1.1.1.2  jruoho  * 1. Redistributions of source code must retain the above copyright
     17  1.1.1.2  jruoho  *    notice, this list of conditions, and the following disclaimer,
     18  1.1.1.2  jruoho  *    without modification.
     19  1.1.1.2  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     20  1.1.1.2  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     21  1.1.1.2  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     22  1.1.1.2  jruoho  *    including a substantially similar Disclaimer requirement for further
     23  1.1.1.2  jruoho  *    binary redistribution.
     24  1.1.1.2  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     25  1.1.1.2  jruoho  *    of any contributors may be used to endorse or promote products derived
     26  1.1.1.2  jruoho  *    from this software without specific prior written permission.
     27  1.1.1.2  jruoho  *
     28  1.1.1.2  jruoho  * Alternatively, this software may be distributed under the terms of the
     29  1.1.1.2  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     30  1.1.1.2  jruoho  * Software Foundation.
     31  1.1.1.2  jruoho  *
     32  1.1.1.2  jruoho  * NO WARRANTY
     33  1.1.1.2  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     34  1.1.1.2  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     35  1.1.1.2  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     36  1.1.1.2  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     37  1.1.1.2  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     38  1.1.1.2  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     39  1.1.1.2  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     40  1.1.1.2  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     41  1.1.1.2  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     42  1.1.1.2  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     43  1.1.1.2  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     44  1.1.1.2  jruoho  */
     45      1.1  jruoho 
     46      1.1  jruoho #define __EXSTOREN_C__
     47      1.1  jruoho 
     48      1.1  jruoho #include "acpi.h"
     49      1.1  jruoho #include "accommon.h"
     50      1.1  jruoho #include "acinterp.h"
     51      1.1  jruoho #include "amlcode.h"
     52      1.1  jruoho 
     53      1.1  jruoho 
     54      1.1  jruoho #define _COMPONENT          ACPI_EXECUTER
     55      1.1  jruoho         ACPI_MODULE_NAME    ("exstoren")
     56      1.1  jruoho 
     57      1.1  jruoho 
     58      1.1  jruoho /*******************************************************************************
     59      1.1  jruoho  *
     60      1.1  jruoho  * FUNCTION:    AcpiExResolveObject
     61      1.1  jruoho  *
     62      1.1  jruoho  * PARAMETERS:  SourceDescPtr       - Pointer to the source object
     63      1.1  jruoho  *              TargetType          - Current type of the target
     64      1.1  jruoho  *              WalkState           - Current walk state
     65      1.1  jruoho  *
     66      1.1  jruoho  * RETURN:      Status, resolved object in SourceDescPtr.
     67      1.1  jruoho  *
     68      1.1  jruoho  * DESCRIPTION: Resolve an object.  If the object is a reference, dereference
     69      1.1  jruoho  *              it and return the actual object in the SourceDescPtr.
     70      1.1  jruoho  *
     71      1.1  jruoho  ******************************************************************************/
     72      1.1  jruoho 
     73      1.1  jruoho ACPI_STATUS
     74      1.1  jruoho AcpiExResolveObject (
     75      1.1  jruoho     ACPI_OPERAND_OBJECT     **SourceDescPtr,
     76      1.1  jruoho     ACPI_OBJECT_TYPE        TargetType,
     77      1.1  jruoho     ACPI_WALK_STATE         *WalkState)
     78      1.1  jruoho {
     79      1.1  jruoho     ACPI_OPERAND_OBJECT     *SourceDesc = *SourceDescPtr;
     80      1.1  jruoho     ACPI_STATUS             Status = AE_OK;
     81      1.1  jruoho 
     82      1.1  jruoho 
     83      1.1  jruoho     ACPI_FUNCTION_TRACE (ExResolveObject);
     84      1.1  jruoho 
     85      1.1  jruoho 
     86      1.1  jruoho     /* Ensure we have a Target that can be stored to */
     87      1.1  jruoho 
     88      1.1  jruoho     switch (TargetType)
     89      1.1  jruoho     {
     90      1.1  jruoho     case ACPI_TYPE_BUFFER_FIELD:
     91      1.1  jruoho     case ACPI_TYPE_LOCAL_REGION_FIELD:
     92      1.1  jruoho     case ACPI_TYPE_LOCAL_BANK_FIELD:
     93      1.1  jruoho     case ACPI_TYPE_LOCAL_INDEX_FIELD:
     94      1.1  jruoho         /*
     95      1.1  jruoho          * These cases all require only Integers or values that
     96      1.1  jruoho          * can be converted to Integers (Strings or Buffers)
     97      1.1  jruoho          */
     98      1.1  jruoho 
     99      1.1  jruoho     case ACPI_TYPE_INTEGER:
    100      1.1  jruoho     case ACPI_TYPE_STRING:
    101      1.1  jruoho     case ACPI_TYPE_BUFFER:
    102      1.1  jruoho 
    103      1.1  jruoho         /*
    104      1.1  jruoho          * Stores into a Field/Region or into a Integer/Buffer/String
    105      1.1  jruoho          * are all essentially the same.  This case handles the
    106      1.1  jruoho          * "interchangeable" types Integer, String, and Buffer.
    107      1.1  jruoho          */
    108      1.1  jruoho         if (SourceDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
    109      1.1  jruoho         {
    110      1.1  jruoho             /* Resolve a reference object first */
    111      1.1  jruoho 
    112      1.1  jruoho             Status = AcpiExResolveToValue (SourceDescPtr, WalkState);
    113      1.1  jruoho             if (ACPI_FAILURE (Status))
    114      1.1  jruoho             {
    115      1.1  jruoho                 break;
    116      1.1  jruoho             }
    117      1.1  jruoho         }
    118      1.1  jruoho 
    119      1.1  jruoho         /* For CopyObject, no further validation necessary */
    120      1.1  jruoho 
    121      1.1  jruoho         if (WalkState->Opcode == AML_COPY_OP)
    122      1.1  jruoho         {
    123      1.1  jruoho             break;
    124      1.1  jruoho         }
    125      1.1  jruoho 
    126      1.1  jruoho         /* Must have a Integer, Buffer, or String */
    127      1.1  jruoho 
    128      1.1  jruoho         if ((SourceDesc->Common.Type != ACPI_TYPE_INTEGER)    &&
    129      1.1  jruoho             (SourceDesc->Common.Type != ACPI_TYPE_BUFFER)     &&
    130      1.1  jruoho             (SourceDesc->Common.Type != ACPI_TYPE_STRING)     &&
    131      1.1  jruoho             !((SourceDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
    132      1.1  jruoho                     (SourceDesc->Reference.Class== ACPI_REFCLASS_TABLE)))
    133      1.1  jruoho         {
    134      1.1  jruoho             /* Conversion successful but still not a valid type */
    135      1.1  jruoho 
    136      1.1  jruoho             ACPI_ERROR ((AE_INFO,
    137      1.1  jruoho                 "Cannot assign type %s to %s (must be type Int/Str/Buf)",
    138      1.1  jruoho                 AcpiUtGetObjectTypeName (SourceDesc),
    139      1.1  jruoho                 AcpiUtGetTypeName (TargetType)));
    140      1.1  jruoho             Status = AE_AML_OPERAND_TYPE;
    141      1.1  jruoho         }
    142      1.1  jruoho         break;
    143      1.1  jruoho 
    144      1.1  jruoho 
    145      1.1  jruoho     case ACPI_TYPE_LOCAL_ALIAS:
    146      1.1  jruoho     case ACPI_TYPE_LOCAL_METHOD_ALIAS:
    147      1.1  jruoho 
    148      1.1  jruoho         /*
    149      1.1  jruoho          * All aliases should have been resolved earlier, during the
    150      1.1  jruoho          * operand resolution phase.
    151      1.1  jruoho          */
    152      1.1  jruoho         ACPI_ERROR ((AE_INFO, "Store into an unresolved Alias object"));
    153      1.1  jruoho         Status = AE_AML_INTERNAL;
    154      1.1  jruoho         break;
    155      1.1  jruoho 
    156      1.1  jruoho 
    157      1.1  jruoho     case ACPI_TYPE_PACKAGE:
    158      1.1  jruoho     default:
    159      1.1  jruoho 
    160      1.1  jruoho         /*
    161      1.1  jruoho          * All other types than Alias and the various Fields come here,
    162      1.1  jruoho          * including the untyped case - ACPI_TYPE_ANY.
    163      1.1  jruoho          */
    164      1.1  jruoho         break;
    165      1.1  jruoho     }
    166      1.1  jruoho 
    167      1.1  jruoho     return_ACPI_STATUS (Status);
    168      1.1  jruoho }
    169      1.1  jruoho 
    170      1.1  jruoho 
    171      1.1  jruoho /*******************************************************************************
    172      1.1  jruoho  *
    173      1.1  jruoho  * FUNCTION:    AcpiExStoreObjectToObject
    174      1.1  jruoho  *
    175      1.1  jruoho  * PARAMETERS:  SourceDesc          - Object to store
    176      1.1  jruoho  *              DestDesc            - Object to receive a copy of the source
    177      1.1  jruoho  *              NewDesc             - New object if DestDesc is obsoleted
    178      1.1  jruoho  *              WalkState           - Current walk state
    179      1.1  jruoho  *
    180      1.1  jruoho  * RETURN:      Status
    181      1.1  jruoho  *
    182      1.1  jruoho  * DESCRIPTION: "Store" an object to another object.  This may include
    183      1.1  jruoho  *              converting the source type to the target type (implicit
    184      1.1  jruoho  *              conversion), and a copy of the value of the source to
    185      1.1  jruoho  *              the target.
    186      1.1  jruoho  *
    187      1.1  jruoho  *              The Assignment of an object to another (not named) object
    188      1.1  jruoho  *              is handled here.
    189      1.1  jruoho  *              The Source passed in will replace the current value (if any)
    190      1.1  jruoho  *              with the input value.
    191      1.1  jruoho  *
    192      1.1  jruoho  *              When storing into an object the data is converted to the
    193      1.1  jruoho  *              target object type then stored in the object.  This means
    194      1.1  jruoho  *              that the target object type (for an initialized target) will
    195      1.1  jruoho  *              not be changed by a store operation.
    196      1.1  jruoho  *
    197      1.1  jruoho  *              This module allows destination types of Number, String,
    198      1.1  jruoho  *              Buffer, and Package.
    199      1.1  jruoho  *
    200      1.1  jruoho  *              Assumes parameters are already validated.  NOTE: SourceDesc
    201      1.1  jruoho  *              resolution (from a reference object) must be performed by
    202      1.1  jruoho  *              the caller if necessary.
    203      1.1  jruoho  *
    204      1.1  jruoho  ******************************************************************************/
    205      1.1  jruoho 
    206      1.1  jruoho ACPI_STATUS
    207      1.1  jruoho AcpiExStoreObjectToObject (
    208      1.1  jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
    209      1.1  jruoho     ACPI_OPERAND_OBJECT     *DestDesc,
    210      1.1  jruoho     ACPI_OPERAND_OBJECT     **NewDesc,
    211      1.1  jruoho     ACPI_WALK_STATE         *WalkState)
    212      1.1  jruoho {
    213      1.1  jruoho     ACPI_OPERAND_OBJECT     *ActualSrcDesc;
    214      1.1  jruoho     ACPI_STATUS             Status = AE_OK;
    215      1.1  jruoho 
    216      1.1  jruoho 
    217      1.1  jruoho     ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToObject, SourceDesc);
    218      1.1  jruoho 
    219      1.1  jruoho 
    220      1.1  jruoho     ActualSrcDesc = SourceDesc;
    221      1.1  jruoho     if (!DestDesc)
    222      1.1  jruoho     {
    223      1.1  jruoho         /*
    224      1.1  jruoho          * There is no destination object (An uninitialized node or
    225      1.1  jruoho          * package element), so we can simply copy the source object
    226      1.1  jruoho          * creating a new destination object
    227      1.1  jruoho          */
    228      1.1  jruoho         Status = AcpiUtCopyIobjectToIobject (ActualSrcDesc, NewDesc, WalkState);
    229      1.1  jruoho         return_ACPI_STATUS (Status);
    230      1.1  jruoho     }
    231      1.1  jruoho 
    232      1.1  jruoho     if (SourceDesc->Common.Type != DestDesc->Common.Type)
    233      1.1  jruoho     {
    234      1.1  jruoho         /*
    235      1.1  jruoho          * The source type does not match the type of the destination.
    236      1.1  jruoho          * Perform the "implicit conversion" of the source to the current type
    237      1.1  jruoho          * of the target as per the ACPI specification.
    238      1.1  jruoho          *
    239      1.1  jruoho          * If no conversion performed, ActualSrcDesc = SourceDesc.
    240      1.1  jruoho          * Otherwise, ActualSrcDesc is a temporary object to hold the
    241      1.1  jruoho          * converted object.
    242      1.1  jruoho          */
    243      1.1  jruoho         Status = AcpiExConvertToTargetType (DestDesc->Common.Type,
    244      1.1  jruoho                         SourceDesc, &ActualSrcDesc, WalkState);
    245      1.1  jruoho         if (ACPI_FAILURE (Status))
    246      1.1  jruoho         {
    247      1.1  jruoho             return_ACPI_STATUS (Status);
    248      1.1  jruoho         }
    249      1.1  jruoho 
    250      1.1  jruoho         if (SourceDesc == ActualSrcDesc)
    251      1.1  jruoho         {
    252      1.1  jruoho             /*
    253      1.1  jruoho              * No conversion was performed. Return the SourceDesc as the
    254      1.1  jruoho              * new object.
    255      1.1  jruoho              */
    256      1.1  jruoho             *NewDesc = SourceDesc;
    257      1.1  jruoho             return_ACPI_STATUS (AE_OK);
    258      1.1  jruoho         }
    259      1.1  jruoho     }
    260      1.1  jruoho 
    261      1.1  jruoho     /*
    262      1.1  jruoho      * We now have two objects of identical types, and we can perform a
    263      1.1  jruoho      * copy of the *value* of the source object.
    264      1.1  jruoho      */
    265      1.1  jruoho     switch (DestDesc->Common.Type)
    266      1.1  jruoho     {
    267      1.1  jruoho     case ACPI_TYPE_INTEGER:
    268      1.1  jruoho 
    269      1.1  jruoho         DestDesc->Integer.Value = ActualSrcDesc->Integer.Value;
    270      1.1  jruoho 
    271      1.1  jruoho         /* Truncate value if we are executing from a 32-bit ACPI table */
    272      1.1  jruoho 
    273      1.1  jruoho         AcpiExTruncateFor32bitTable (DestDesc);
    274      1.1  jruoho         break;
    275      1.1  jruoho 
    276      1.1  jruoho     case ACPI_TYPE_STRING:
    277      1.1  jruoho 
    278      1.1  jruoho         Status = AcpiExStoreStringToString (ActualSrcDesc, DestDesc);
    279      1.1  jruoho         break;
    280      1.1  jruoho 
    281      1.1  jruoho     case ACPI_TYPE_BUFFER:
    282      1.1  jruoho 
    283      1.1  jruoho         Status = AcpiExStoreBufferToBuffer (ActualSrcDesc, DestDesc);
    284      1.1  jruoho         break;
    285      1.1  jruoho 
    286      1.1  jruoho     case ACPI_TYPE_PACKAGE:
    287      1.1  jruoho 
    288      1.1  jruoho         Status = AcpiUtCopyIobjectToIobject (ActualSrcDesc, &DestDesc,
    289      1.1  jruoho                     WalkState);
    290      1.1  jruoho         break;
    291      1.1  jruoho 
    292      1.1  jruoho     default:
    293      1.1  jruoho         /*
    294      1.1  jruoho          * All other types come here.
    295      1.1  jruoho          */
    296      1.1  jruoho         ACPI_WARNING ((AE_INFO, "Store into type %s not implemented",
    297      1.1  jruoho             AcpiUtGetObjectTypeName (DestDesc)));
    298      1.1  jruoho 
    299      1.1  jruoho         Status = AE_NOT_IMPLEMENTED;
    300      1.1  jruoho         break;
    301      1.1  jruoho     }
    302      1.1  jruoho 
    303      1.1  jruoho     if (ActualSrcDesc != SourceDesc)
    304      1.1  jruoho     {
    305      1.1  jruoho         /* Delete the intermediate (temporary) source object */
    306      1.1  jruoho 
    307      1.1  jruoho         AcpiUtRemoveReference (ActualSrcDesc);
    308      1.1  jruoho     }
    309      1.1  jruoho 
    310      1.1  jruoho     *NewDesc = DestDesc;
    311      1.1  jruoho     return_ACPI_STATUS (Status);
    312      1.1  jruoho }
    313      1.1  jruoho 
    314      1.1  jruoho 
    315