Home | History | Annotate | Line # | Download | only in executer
exstore.c revision 1.1.1.6
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3      1.1    jruoho  * Module Name: exstore - AML Interpreter object store support
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7  1.1.1.2    jruoho /*
      8  1.1.1.6  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 "acdispat.h"
     47      1.1    jruoho #include "acinterp.h"
     48      1.1    jruoho #include "amlcode.h"
     49      1.1    jruoho #include "acnamesp.h"
     50      1.1    jruoho 
     51      1.1    jruoho 
     52      1.1    jruoho #define _COMPONENT          ACPI_EXECUTER
     53      1.1    jruoho         ACPI_MODULE_NAME    ("exstore")
     54      1.1    jruoho 
     55      1.1    jruoho /* Local prototypes */
     56      1.1    jruoho 
     57      1.1    jruoho static ACPI_STATUS
     58      1.1    jruoho AcpiExStoreObjectToIndex (
     59      1.1    jruoho     ACPI_OPERAND_OBJECT     *ValDesc,
     60      1.1    jruoho     ACPI_OPERAND_OBJECT     *DestDesc,
     61      1.1    jruoho     ACPI_WALK_STATE         *WalkState);
     62      1.1    jruoho 
     63  1.1.1.3  christos static ACPI_STATUS
     64  1.1.1.3  christos AcpiExStoreDirectToNode (
     65  1.1.1.3  christos     ACPI_OPERAND_OBJECT     *SourceDesc,
     66  1.1.1.3  christos     ACPI_NAMESPACE_NODE     *Node,
     67  1.1.1.3  christos     ACPI_WALK_STATE         *WalkState);
     68  1.1.1.3  christos 
     69      1.1    jruoho 
     70      1.1    jruoho /*******************************************************************************
     71      1.1    jruoho  *
     72      1.1    jruoho  * FUNCTION:    AcpiExStore
     73      1.1    jruoho  *
     74      1.1    jruoho  * PARAMETERS:  *SourceDesc         - Value to be stored
     75  1.1.1.3  christos  *              *DestDesc           - Where to store it. Must be an NS node
     76  1.1.1.3  christos  *                                    or ACPI_OPERAND_OBJECT of type
     77      1.1    jruoho  *                                    Reference;
     78      1.1    jruoho  *              WalkState           - Current walk state
     79      1.1    jruoho  *
     80      1.1    jruoho  * RETURN:      Status
     81      1.1    jruoho  *
     82      1.1    jruoho  * DESCRIPTION: Store the value described by SourceDesc into the location
     83  1.1.1.3  christos  *              described by DestDesc. Called by various interpreter
     84      1.1    jruoho  *              functions to store the result of an operation into
     85      1.1    jruoho  *              the destination operand -- not just simply the actual "Store"
     86      1.1    jruoho  *              ASL operator.
     87      1.1    jruoho  *
     88      1.1    jruoho  ******************************************************************************/
     89      1.1    jruoho 
     90      1.1    jruoho ACPI_STATUS
     91      1.1    jruoho AcpiExStore (
     92      1.1    jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
     93      1.1    jruoho     ACPI_OPERAND_OBJECT     *DestDesc,
     94      1.1    jruoho     ACPI_WALK_STATE         *WalkState)
     95      1.1    jruoho {
     96      1.1    jruoho     ACPI_STATUS             Status = AE_OK;
     97      1.1    jruoho     ACPI_OPERAND_OBJECT     *RefDesc = DestDesc;
     98      1.1    jruoho 
     99      1.1    jruoho 
    100      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (ExStore, DestDesc);
    101      1.1    jruoho 
    102      1.1    jruoho 
    103      1.1    jruoho     /* Validate parameters */
    104      1.1    jruoho 
    105      1.1    jruoho     if (!SourceDesc || !DestDesc)
    106      1.1    jruoho     {
    107      1.1    jruoho         ACPI_ERROR ((AE_INFO, "Null parameter"));
    108      1.1    jruoho         return_ACPI_STATUS (AE_AML_NO_OPERAND);
    109      1.1    jruoho     }
    110      1.1    jruoho 
    111      1.1    jruoho     /* DestDesc can be either a namespace node or an ACPI object */
    112      1.1    jruoho 
    113      1.1    jruoho     if (ACPI_GET_DESCRIPTOR_TYPE (DestDesc) == ACPI_DESC_TYPE_NAMED)
    114      1.1    jruoho     {
    115      1.1    jruoho         /*
    116      1.1    jruoho          * Dest is a namespace node,
    117      1.1    jruoho          * Storing an object into a Named node.
    118      1.1    jruoho          */
    119      1.1    jruoho         Status = AcpiExStoreObjectToNode (SourceDesc,
    120  1.1.1.6  christos             (ACPI_NAMESPACE_NODE *) DestDesc, WalkState,
    121  1.1.1.6  christos             ACPI_IMPLICIT_CONVERSION);
    122      1.1    jruoho 
    123      1.1    jruoho         return_ACPI_STATUS (Status);
    124      1.1    jruoho     }
    125      1.1    jruoho 
    126      1.1    jruoho     /* Destination object must be a Reference or a Constant object */
    127      1.1    jruoho 
    128      1.1    jruoho     switch (DestDesc->Common.Type)
    129      1.1    jruoho     {
    130      1.1    jruoho     case ACPI_TYPE_LOCAL_REFERENCE:
    131  1.1.1.3  christos 
    132      1.1    jruoho         break;
    133      1.1    jruoho 
    134      1.1    jruoho     case ACPI_TYPE_INTEGER:
    135      1.1    jruoho 
    136      1.1    jruoho         /* Allow stores to Constants -- a Noop as per ACPI spec */
    137      1.1    jruoho 
    138      1.1    jruoho         if (DestDesc->Common.Flags & AOPOBJ_AML_CONSTANT)
    139      1.1    jruoho         {
    140      1.1    jruoho             return_ACPI_STATUS (AE_OK);
    141      1.1    jruoho         }
    142      1.1    jruoho 
    143      1.1    jruoho         /*lint -fallthrough */
    144      1.1    jruoho 
    145      1.1    jruoho     default:
    146      1.1    jruoho 
    147      1.1    jruoho         /* Destination is not a Reference object */
    148      1.1    jruoho 
    149      1.1    jruoho         ACPI_ERROR ((AE_INFO,
    150  1.1.1.6  christos             "Target is not a Reference or Constant object - [%s] %p",
    151      1.1    jruoho             AcpiUtGetObjectTypeName (DestDesc), DestDesc));
    152      1.1    jruoho 
    153      1.1    jruoho         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    154      1.1    jruoho     }
    155      1.1    jruoho 
    156      1.1    jruoho     /*
    157      1.1    jruoho      * Examine the Reference class. These cases are handled:
    158      1.1    jruoho      *
    159      1.1    jruoho      * 1) Store to Name (Change the object associated with a name)
    160      1.1    jruoho      * 2) Store to an indexed area of a Buffer or Package
    161      1.1    jruoho      * 3) Store to a Method Local or Arg
    162      1.1    jruoho      * 4) Store to the debug object
    163      1.1    jruoho      */
    164      1.1    jruoho     switch (RefDesc->Reference.Class)
    165      1.1    jruoho     {
    166      1.1    jruoho     case ACPI_REFCLASS_REFOF:
    167      1.1    jruoho 
    168      1.1    jruoho         /* Storing an object into a Name "container" */
    169      1.1    jruoho 
    170      1.1    jruoho         Status = AcpiExStoreObjectToNode (SourceDesc,
    171  1.1.1.6  christos             RefDesc->Reference.Object,
    172  1.1.1.6  christos             WalkState, ACPI_IMPLICIT_CONVERSION);
    173      1.1    jruoho         break;
    174      1.1    jruoho 
    175      1.1    jruoho     case ACPI_REFCLASS_INDEX:
    176      1.1    jruoho 
    177      1.1    jruoho         /* Storing to an Index (pointer into a packager or buffer) */
    178      1.1    jruoho 
    179      1.1    jruoho         Status = AcpiExStoreObjectToIndex (SourceDesc, RefDesc, WalkState);
    180      1.1    jruoho         break;
    181      1.1    jruoho 
    182      1.1    jruoho     case ACPI_REFCLASS_LOCAL:
    183      1.1    jruoho     case ACPI_REFCLASS_ARG:
    184      1.1    jruoho 
    185      1.1    jruoho         /* Store to a method local/arg  */
    186      1.1    jruoho 
    187      1.1    jruoho         Status = AcpiDsStoreObjectToLocal (RefDesc->Reference.Class,
    188  1.1.1.6  christos             RefDesc->Reference.Value, SourceDesc, WalkState);
    189      1.1    jruoho         break;
    190      1.1    jruoho 
    191      1.1    jruoho     case ACPI_REFCLASS_DEBUG:
    192      1.1    jruoho         /*
    193      1.1    jruoho          * Storing to the Debug object causes the value stored to be
    194      1.1    jruoho          * displayed and otherwise has no effect -- see ACPI Specification
    195      1.1    jruoho          */
    196      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    197  1.1.1.6  christos             "**** Write to Debug Object: Object %p [%s] ****:\n\n",
    198      1.1    jruoho             SourceDesc, AcpiUtGetObjectTypeName (SourceDesc)));
    199      1.1    jruoho 
    200      1.1    jruoho         ACPI_DEBUG_OBJECT (SourceDesc, 0, 0);
    201      1.1    jruoho         break;
    202      1.1    jruoho 
    203      1.1    jruoho     default:
    204      1.1    jruoho 
    205      1.1    jruoho         ACPI_ERROR ((AE_INFO, "Unknown Reference Class 0x%2.2X",
    206      1.1    jruoho             RefDesc->Reference.Class));
    207      1.1    jruoho         ACPI_DUMP_ENTRY (RefDesc, ACPI_LV_INFO);
    208      1.1    jruoho 
    209      1.1    jruoho         Status = AE_AML_INTERNAL;
    210      1.1    jruoho         break;
    211      1.1    jruoho     }
    212      1.1    jruoho 
    213      1.1    jruoho     return_ACPI_STATUS (Status);
    214      1.1    jruoho }
    215      1.1    jruoho 
    216      1.1    jruoho 
    217      1.1    jruoho /*******************************************************************************
    218      1.1    jruoho  *
    219      1.1    jruoho  * FUNCTION:    AcpiExStoreObjectToIndex
    220      1.1    jruoho  *
    221      1.1    jruoho  * PARAMETERS:  *SourceDesc             - Value to be stored
    222      1.1    jruoho  *              *DestDesc               - Named object to receive the value
    223      1.1    jruoho  *              WalkState               - Current walk state
    224      1.1    jruoho  *
    225      1.1    jruoho  * RETURN:      Status
    226      1.1    jruoho  *
    227      1.1    jruoho  * DESCRIPTION: Store the object to indexed Buffer or Package element
    228      1.1    jruoho  *
    229      1.1    jruoho  ******************************************************************************/
    230      1.1    jruoho 
    231      1.1    jruoho static ACPI_STATUS
    232      1.1    jruoho AcpiExStoreObjectToIndex (
    233      1.1    jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
    234      1.1    jruoho     ACPI_OPERAND_OBJECT     *IndexDesc,
    235      1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    236      1.1    jruoho {
    237      1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    238      1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    239      1.1    jruoho     ACPI_OPERAND_OBJECT     *NewDesc;
    240      1.1    jruoho     UINT8                   Value = 0;
    241      1.1    jruoho     UINT32                  i;
    242      1.1    jruoho 
    243      1.1    jruoho 
    244      1.1    jruoho     ACPI_FUNCTION_TRACE (ExStoreObjectToIndex);
    245      1.1    jruoho 
    246      1.1    jruoho 
    247      1.1    jruoho     /*
    248      1.1    jruoho      * Destination must be a reference pointer, and
    249      1.1    jruoho      * must point to either a buffer or a package
    250      1.1    jruoho      */
    251      1.1    jruoho     switch (IndexDesc->Reference.TargetType)
    252      1.1    jruoho     {
    253      1.1    jruoho     case ACPI_TYPE_PACKAGE:
    254      1.1    jruoho         /*
    255      1.1    jruoho          * Storing to a package element. Copy the object and replace
    256      1.1    jruoho          * any existing object with the new object. No implicit
    257      1.1    jruoho          * conversion is performed.
    258      1.1    jruoho          *
    259      1.1    jruoho          * The object at *(IndexDesc->Reference.Where) is the
    260      1.1    jruoho          * element within the package that is to be modified.
    261      1.1    jruoho          * The parent package object is at IndexDesc->Reference.Object
    262      1.1    jruoho          */
    263      1.1    jruoho         ObjDesc = *(IndexDesc->Reference.Where);
    264      1.1    jruoho 
    265      1.1    jruoho         if (SourceDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE &&
    266      1.1    jruoho             SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE)
    267      1.1    jruoho         {
    268      1.1    jruoho             /* This is a DDBHandle, just add a reference to it */
    269      1.1    jruoho 
    270      1.1    jruoho             AcpiUtAddReference (SourceDesc);
    271      1.1    jruoho             NewDesc = SourceDesc;
    272      1.1    jruoho         }
    273      1.1    jruoho         else
    274      1.1    jruoho         {
    275      1.1    jruoho             /* Normal object, copy it */
    276      1.1    jruoho 
    277  1.1.1.6  christos             Status = AcpiUtCopyIobjectToIobject (
    278  1.1.1.6  christos                 SourceDesc, &NewDesc, WalkState);
    279      1.1    jruoho             if (ACPI_FAILURE (Status))
    280      1.1    jruoho             {
    281      1.1    jruoho                 return_ACPI_STATUS (Status);
    282      1.1    jruoho             }
    283      1.1    jruoho         }
    284      1.1    jruoho 
    285      1.1    jruoho         if (ObjDesc)
    286      1.1    jruoho         {
    287      1.1    jruoho             /* Decrement reference count by the ref count of the parent package */
    288      1.1    jruoho 
    289      1.1    jruoho             for (i = 0;
    290      1.1    jruoho                  i < ((ACPI_OPERAND_OBJECT *)
    291      1.1    jruoho                         IndexDesc->Reference.Object)->Common.ReferenceCount;
    292      1.1    jruoho                  i++)
    293      1.1    jruoho             {
    294      1.1    jruoho                 AcpiUtRemoveReference (ObjDesc);
    295      1.1    jruoho             }
    296      1.1    jruoho         }
    297      1.1    jruoho 
    298      1.1    jruoho         *(IndexDesc->Reference.Where) = NewDesc;
    299      1.1    jruoho 
    300      1.1    jruoho         /* Increment ref count by the ref count of the parent package-1 */
    301      1.1    jruoho 
    302      1.1    jruoho         for (i = 1;
    303      1.1    jruoho              i < ((ACPI_OPERAND_OBJECT *)
    304      1.1    jruoho                     IndexDesc->Reference.Object)->Common.ReferenceCount;
    305      1.1    jruoho              i++)
    306      1.1    jruoho         {
    307      1.1    jruoho             AcpiUtAddReference (NewDesc);
    308      1.1    jruoho         }
    309      1.1    jruoho 
    310      1.1    jruoho         break;
    311      1.1    jruoho 
    312      1.1    jruoho     case ACPI_TYPE_BUFFER_FIELD:
    313      1.1    jruoho         /*
    314      1.1    jruoho          * Store into a Buffer or String (not actually a real BufferField)
    315      1.1    jruoho          * at a location defined by an Index.
    316      1.1    jruoho          *
    317      1.1    jruoho          * The first 8-bit element of the source object is written to the
    318      1.1    jruoho          * 8-bit Buffer location defined by the Index destination object,
    319      1.1    jruoho          * according to the ACPI 2.0 specification.
    320      1.1    jruoho          */
    321      1.1    jruoho 
    322      1.1    jruoho         /*
    323      1.1    jruoho          * Make sure the target is a Buffer or String. An error should
    324      1.1    jruoho          * not happen here, since the ReferenceObject was constructed
    325      1.1    jruoho          * by the INDEX_OP code.
    326      1.1    jruoho          */
    327      1.1    jruoho         ObjDesc = IndexDesc->Reference.Object;
    328      1.1    jruoho         if ((ObjDesc->Common.Type != ACPI_TYPE_BUFFER) &&
    329      1.1    jruoho             (ObjDesc->Common.Type != ACPI_TYPE_STRING))
    330      1.1    jruoho         {
    331      1.1    jruoho             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    332      1.1    jruoho         }
    333      1.1    jruoho 
    334      1.1    jruoho         /*
    335      1.1    jruoho          * The assignment of the individual elements will be slightly
    336      1.1    jruoho          * different for each source type.
    337      1.1    jruoho          */
    338      1.1    jruoho         switch (SourceDesc->Common.Type)
    339      1.1    jruoho         {
    340      1.1    jruoho         case ACPI_TYPE_INTEGER:
    341      1.1    jruoho 
    342      1.1    jruoho             /* Use the least-significant byte of the integer */
    343      1.1    jruoho 
    344      1.1    jruoho             Value = (UINT8) (SourceDesc->Integer.Value);
    345      1.1    jruoho             break;
    346      1.1    jruoho 
    347      1.1    jruoho         case ACPI_TYPE_BUFFER:
    348      1.1    jruoho         case ACPI_TYPE_STRING:
    349      1.1    jruoho 
    350      1.1    jruoho             /* Note: Takes advantage of common string/buffer fields */
    351      1.1    jruoho 
    352      1.1    jruoho             Value = SourceDesc->Buffer.Pointer[0];
    353      1.1    jruoho             break;
    354      1.1    jruoho 
    355      1.1    jruoho         default:
    356      1.1    jruoho 
    357      1.1    jruoho             /* All other types are invalid */
    358      1.1    jruoho 
    359      1.1    jruoho             ACPI_ERROR ((AE_INFO,
    360  1.1.1.6  christos                 "Source must be type [Integer/Buffer/String], found [%s]",
    361      1.1    jruoho                 AcpiUtGetObjectTypeName (SourceDesc)));
    362      1.1    jruoho             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    363      1.1    jruoho         }
    364      1.1    jruoho 
    365      1.1    jruoho         /* Store the source value into the target buffer byte */
    366      1.1    jruoho 
    367      1.1    jruoho         ObjDesc->Buffer.Pointer[IndexDesc->Reference.Value] = Value;
    368      1.1    jruoho         break;
    369      1.1    jruoho 
    370      1.1    jruoho     default:
    371      1.1    jruoho         ACPI_ERROR ((AE_INFO,
    372  1.1.1.6  christos             "Target is not of type [Package/BufferField]"));
    373  1.1.1.6  christos         Status = AE_AML_TARGET_TYPE;
    374      1.1    jruoho         break;
    375      1.1    jruoho     }
    376      1.1    jruoho 
    377      1.1    jruoho     return_ACPI_STATUS (Status);
    378      1.1    jruoho }
    379      1.1    jruoho 
    380      1.1    jruoho 
    381      1.1    jruoho /*******************************************************************************
    382      1.1    jruoho  *
    383      1.1    jruoho  * FUNCTION:    AcpiExStoreObjectToNode
    384      1.1    jruoho  *
    385      1.1    jruoho  * PARAMETERS:  SourceDesc              - Value to be stored
    386      1.1    jruoho  *              Node                    - Named object to receive the value
    387      1.1    jruoho  *              WalkState               - Current walk state
    388      1.1    jruoho  *              ImplicitConversion      - Perform implicit conversion (yes/no)
    389      1.1    jruoho  *
    390      1.1    jruoho  * RETURN:      Status
    391      1.1    jruoho  *
    392      1.1    jruoho  * DESCRIPTION: Store the object to the named object.
    393      1.1    jruoho  *
    394  1.1.1.6  christos  * The assignment of an object to a named object is handled here.
    395  1.1.1.6  christos  * The value passed in will replace the current value (if any)
    396  1.1.1.6  christos  * with the input value.
    397  1.1.1.6  christos  *
    398  1.1.1.6  christos  * When storing into an object the data is converted to the
    399  1.1.1.6  christos  * target object type then stored in the object. This means
    400  1.1.1.6  christos  * that the target object type (for an initialized target) will
    401  1.1.1.6  christos  * not be changed by a store operation. A CopyObject can change
    402  1.1.1.6  christos  * the target type, however.
    403  1.1.1.3  christos  *
    404  1.1.1.6  christos  * The ImplicitConversion flag is set to NO/FALSE only when
    405  1.1.1.6  christos  * storing to an ArgX -- as per the rules of the ACPI spec.
    406      1.1    jruoho  *
    407  1.1.1.6  christos  * Assumes parameters are already validated.
    408      1.1    jruoho  *
    409      1.1    jruoho  ******************************************************************************/
    410      1.1    jruoho 
    411      1.1    jruoho ACPI_STATUS
    412      1.1    jruoho AcpiExStoreObjectToNode (
    413      1.1    jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
    414      1.1    jruoho     ACPI_NAMESPACE_NODE     *Node,
    415      1.1    jruoho     ACPI_WALK_STATE         *WalkState,
    416      1.1    jruoho     UINT8                   ImplicitConversion)
    417      1.1    jruoho {
    418      1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    419      1.1    jruoho     ACPI_OPERAND_OBJECT     *TargetDesc;
    420      1.1    jruoho     ACPI_OPERAND_OBJECT     *NewDesc;
    421      1.1    jruoho     ACPI_OBJECT_TYPE        TargetType;
    422      1.1    jruoho 
    423      1.1    jruoho 
    424      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToNode, SourceDesc);
    425      1.1    jruoho 
    426      1.1    jruoho 
    427      1.1    jruoho     /* Get current type of the node, and object attached to Node */
    428      1.1    jruoho 
    429      1.1    jruoho     TargetType = AcpiNsGetType (Node);
    430      1.1    jruoho     TargetDesc = AcpiNsGetAttachedObject (Node);
    431      1.1    jruoho 
    432  1.1.1.6  christos     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p [%s] to node %p [%s]\n",
    433      1.1    jruoho         SourceDesc, AcpiUtGetObjectTypeName (SourceDesc),
    434  1.1.1.6  christos         Node, AcpiUtGetTypeName (TargetType)));
    435  1.1.1.6  christos 
    436  1.1.1.6  christos     /* Only limited target types possible for everything except CopyObject */
    437  1.1.1.6  christos 
    438  1.1.1.6  christos     if (WalkState->Opcode != AML_COPY_OP)
    439  1.1.1.6  christos     {
    440  1.1.1.6  christos         /*
    441  1.1.1.6  christos          * Only CopyObject allows all object types to be overwritten. For
    442  1.1.1.6  christos          * TargetRef(s), there are restrictions on the object types that
    443  1.1.1.6  christos          * are allowed.
    444  1.1.1.6  christos          *
    445  1.1.1.6  christos          * Allowable operations/typing for Store:
    446  1.1.1.6  christos          *
    447  1.1.1.6  christos          * 1) Simple Store
    448  1.1.1.6  christos          *      Integer     --> Integer (Named/Local/Arg)
    449  1.1.1.6  christos          *      String      --> String  (Named/Local/Arg)
    450  1.1.1.6  christos          *      Buffer      --> Buffer  (Named/Local/Arg)
    451  1.1.1.6  christos          *      Package     --> Package (Named/Local/Arg)
    452  1.1.1.6  christos          *
    453  1.1.1.6  christos          * 2) Store with implicit conversion
    454  1.1.1.6  christos          *      Integer     --> String or Buffer  (Named)
    455  1.1.1.6  christos          *      String      --> Integer or Buffer (Named)
    456  1.1.1.6  christos          *      Buffer      --> Integer or String (Named)
    457  1.1.1.6  christos          */
    458  1.1.1.6  christos         switch (TargetType)
    459  1.1.1.6  christos         {
    460  1.1.1.6  christos         case ACPI_TYPE_PACKAGE:
    461  1.1.1.6  christos             /*
    462  1.1.1.6  christos              * Here, can only store a package to an existing package.
    463  1.1.1.6  christos              * Storing a package to a Local/Arg is OK, and handled
    464  1.1.1.6  christos              * elsewhere.
    465  1.1.1.6  christos              */
    466  1.1.1.6  christos             if (WalkState->Opcode == AML_STORE_OP)
    467  1.1.1.6  christos             {
    468  1.1.1.6  christos                 if (SourceDesc->Common.Type != ACPI_TYPE_PACKAGE)
    469  1.1.1.6  christos                 {
    470  1.1.1.6  christos                     ACPI_ERROR ((AE_INFO,
    471  1.1.1.6  christos                         "Cannot assign type [%s] to [Package] "
    472  1.1.1.6  christos                         "(source must be type Pkg)",
    473  1.1.1.6  christos                         AcpiUtGetObjectTypeName (SourceDesc)));
    474  1.1.1.6  christos 
    475  1.1.1.6  christos                     return_ACPI_STATUS (AE_AML_TARGET_TYPE);
    476  1.1.1.6  christos                 }
    477  1.1.1.6  christos                 break;
    478  1.1.1.6  christos             }
    479  1.1.1.6  christos 
    480  1.1.1.6  christos         /* Fallthrough */
    481  1.1.1.6  christos 
    482  1.1.1.6  christos         case ACPI_TYPE_DEVICE:
    483  1.1.1.6  christos         case ACPI_TYPE_EVENT:
    484  1.1.1.6  christos         case ACPI_TYPE_MUTEX:
    485  1.1.1.6  christos         case ACPI_TYPE_REGION:
    486  1.1.1.6  christos         case ACPI_TYPE_POWER:
    487  1.1.1.6  christos         case ACPI_TYPE_PROCESSOR:
    488  1.1.1.6  christos         case ACPI_TYPE_THERMAL:
    489  1.1.1.6  christos 
    490  1.1.1.6  christos             ACPI_ERROR ((AE_INFO,
    491  1.1.1.6  christos                 "Target must be [Buffer/Integer/String/Reference]"
    492  1.1.1.6  christos                 ", found [%s] (%4.4s)",
    493  1.1.1.6  christos                 AcpiUtGetTypeName (Node->Type), Node->Name.Ascii));
    494  1.1.1.6  christos 
    495  1.1.1.6  christos             return_ACPI_STATUS (AE_AML_TARGET_TYPE);
    496  1.1.1.6  christos 
    497  1.1.1.6  christos         default:
    498  1.1.1.6  christos             break;
    499  1.1.1.6  christos         }
    500  1.1.1.6  christos     }
    501      1.1    jruoho 
    502      1.1    jruoho     /*
    503      1.1    jruoho      * Resolve the source object to an actual value
    504      1.1    jruoho      * (If it is a reference object)
    505      1.1    jruoho      */
    506      1.1    jruoho     Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState);
    507      1.1    jruoho     if (ACPI_FAILURE (Status))
    508      1.1    jruoho     {
    509      1.1    jruoho         return_ACPI_STATUS (Status);
    510      1.1    jruoho     }
    511      1.1    jruoho 
    512      1.1    jruoho     /* Do the actual store operation */
    513      1.1    jruoho 
    514      1.1    jruoho     switch (TargetType)
    515      1.1    jruoho     {
    516      1.1    jruoho         /*
    517  1.1.1.3  christos          * The simple data types all support implicit source operand
    518  1.1.1.3  christos          * conversion before the store.
    519      1.1    jruoho          */
    520  1.1.1.6  christos     case ACPI_TYPE_INTEGER:
    521  1.1.1.6  christos     case ACPI_TYPE_STRING:
    522  1.1.1.6  christos     case ACPI_TYPE_BUFFER:
    523  1.1.1.3  christos 
    524  1.1.1.3  christos         if ((WalkState->Opcode == AML_COPY_OP) ||
    525  1.1.1.3  christos             !ImplicitConversion)
    526  1.1.1.3  christos         {
    527  1.1.1.3  christos             /*
    528  1.1.1.3  christos              * However, CopyObject and Stores to ArgX do not perform
    529  1.1.1.3  christos              * an implicit conversion, as per the ACPI specification.
    530  1.1.1.3  christos              * A direct store is performed instead.
    531  1.1.1.3  christos              */
    532  1.1.1.6  christos             Status = AcpiExStoreDirectToNode (SourceDesc, Node, WalkState);
    533  1.1.1.3  christos             break;
    534  1.1.1.3  christos         }
    535  1.1.1.3  christos 
    536  1.1.1.3  christos         /* Store with implicit source operand conversion support */
    537  1.1.1.3  christos 
    538      1.1    jruoho         Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc,
    539  1.1.1.3  christos             &NewDesc, WalkState);
    540      1.1    jruoho         if (ACPI_FAILURE (Status))
    541      1.1    jruoho         {
    542      1.1    jruoho             return_ACPI_STATUS (Status);
    543      1.1    jruoho         }
    544      1.1    jruoho 
    545      1.1    jruoho         if (NewDesc != TargetDesc)
    546      1.1    jruoho         {
    547      1.1    jruoho             /*
    548      1.1    jruoho              * Store the new NewDesc as the new value of the Name, and set
    549      1.1    jruoho              * the Name's type to that of the value being stored in it.
    550      1.1    jruoho              * SourceDesc reference count is incremented by AttachObject.
    551      1.1    jruoho              *
    552  1.1.1.3  christos              * Note: This may change the type of the node if an explicit
    553  1.1.1.3  christos              * store has been performed such that the node/object type
    554  1.1.1.3  christos              * has been changed.
    555      1.1    jruoho              */
    556  1.1.1.6  christos             Status = AcpiNsAttachObject (
    557  1.1.1.6  christos                 Node, NewDesc, NewDesc->Common.Type);
    558      1.1    jruoho 
    559      1.1    jruoho             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    560  1.1.1.6  christos                 "Store type [%s] into [%s] via Convert/Attach\n",
    561      1.1    jruoho                 AcpiUtGetObjectTypeName (SourceDesc),
    562      1.1    jruoho                 AcpiUtGetObjectTypeName (NewDesc)));
    563      1.1    jruoho         }
    564      1.1    jruoho         break;
    565      1.1    jruoho 
    566  1.1.1.3  christos     case ACPI_TYPE_BUFFER_FIELD:
    567  1.1.1.3  christos     case ACPI_TYPE_LOCAL_REGION_FIELD:
    568  1.1.1.3  christos     case ACPI_TYPE_LOCAL_BANK_FIELD:
    569  1.1.1.3  christos     case ACPI_TYPE_LOCAL_INDEX_FIELD:
    570  1.1.1.3  christos         /*
    571  1.1.1.3  christos          * For all fields, always write the source data to the target
    572  1.1.1.3  christos          * field. Any required implicit source operand conversion is
    573  1.1.1.3  christos          * performed in the function below as necessary. Note, field
    574  1.1.1.3  christos          * objects must retain their original type permanently.
    575  1.1.1.3  christos          */
    576  1.1.1.3  christos         Status = AcpiExWriteDataToField (SourceDesc, TargetDesc,
    577  1.1.1.3  christos             &WalkState->ResultObj);
    578  1.1.1.3  christos         break;
    579      1.1    jruoho 
    580      1.1    jruoho     default:
    581  1.1.1.3  christos         /*
    582  1.1.1.6  christos          * CopyObject operator: No conversions for all other types.
    583  1.1.1.6  christos          * Instead, directly store a copy of the source object.
    584  1.1.1.3  christos          *
    585  1.1.1.6  christos          * This is the ACPI spec-defined behavior for the CopyObject
    586  1.1.1.6  christos          * operator. (Note, for this default case, all normal
    587  1.1.1.6  christos          * Store/Target operations exited above with an error).
    588  1.1.1.3  christos          */
    589  1.1.1.6  christos         Status = AcpiExStoreDirectToNode (SourceDesc, Node, WalkState);
    590      1.1    jruoho         break;
    591      1.1    jruoho     }
    592      1.1    jruoho 
    593      1.1    jruoho     return_ACPI_STATUS (Status);
    594      1.1    jruoho }
    595      1.1    jruoho 
    596      1.1    jruoho 
    597  1.1.1.3  christos /*******************************************************************************
    598  1.1.1.3  christos  *
    599  1.1.1.3  christos  * FUNCTION:    AcpiExStoreDirectToNode
    600  1.1.1.3  christos  *
    601  1.1.1.3  christos  * PARAMETERS:  SourceDesc              - Value to be stored
    602  1.1.1.3  christos  *              Node                    - Named object to receive the value
    603  1.1.1.3  christos  *              WalkState               - Current walk state
    604  1.1.1.3  christos  *
    605  1.1.1.3  christos  * RETURN:      Status
    606  1.1.1.3  christos  *
    607  1.1.1.3  christos  * DESCRIPTION: "Store" an object directly to a node. This involves a copy
    608  1.1.1.3  christos  *              and an attach.
    609  1.1.1.3  christos  *
    610  1.1.1.3  christos  ******************************************************************************/
    611  1.1.1.3  christos 
    612  1.1.1.3  christos static ACPI_STATUS
    613  1.1.1.3  christos AcpiExStoreDirectToNode (
    614  1.1.1.3  christos     ACPI_OPERAND_OBJECT     *SourceDesc,
    615  1.1.1.3  christos     ACPI_NAMESPACE_NODE     *Node,
    616  1.1.1.3  christos     ACPI_WALK_STATE         *WalkState)
    617  1.1.1.3  christos {
    618  1.1.1.3  christos     ACPI_STATUS             Status;
    619  1.1.1.3  christos     ACPI_OPERAND_OBJECT     *NewDesc;
    620  1.1.1.3  christos 
    621  1.1.1.3  christos 
    622  1.1.1.3  christos     ACPI_FUNCTION_TRACE (ExStoreDirectToNode);
    623  1.1.1.3  christos 
    624  1.1.1.3  christos 
    625  1.1.1.3  christos     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    626  1.1.1.3  christos         "Storing [%s] (%p) directly into node [%s] (%p)"
    627  1.1.1.3  christos         " with no implicit conversion\n",
    628  1.1.1.3  christos         AcpiUtGetObjectTypeName (SourceDesc), SourceDesc,
    629  1.1.1.3  christos         AcpiUtGetTypeName (Node->Type), Node));
    630  1.1.1.3  christos 
    631  1.1.1.3  christos     /* Copy the source object to a new object */
    632  1.1.1.3  christos 
    633  1.1.1.3  christos     Status = AcpiUtCopyIobjectToIobject (SourceDesc, &NewDesc, WalkState);
    634  1.1.1.3  christos     if (ACPI_FAILURE (Status))
    635  1.1.1.3  christos     {
    636  1.1.1.3  christos         return_ACPI_STATUS (Status);
    637  1.1.1.3  christos     }
    638  1.1.1.3  christos 
    639  1.1.1.3  christos     /* Attach the new object to the node */
    640  1.1.1.3  christos 
    641  1.1.1.3  christos     Status = AcpiNsAttachObject (Node, NewDesc, NewDesc->Common.Type);
    642  1.1.1.3  christos     AcpiUtRemoveReference (NewDesc);
    643  1.1.1.3  christos     return_ACPI_STATUS (Status);
    644  1.1.1.3  christos }
    645