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