Home | History | Annotate | Line # | Download | only in executer
exstore.c revision 1.1
      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  jruoho /******************************************************************************
      8  1.1  jruoho  *
      9  1.1  jruoho  * 1. Copyright Notice
     10  1.1  jruoho  *
     11  1.1  jruoho  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
     12  1.1  jruoho  * All rights reserved.
     13  1.1  jruoho  *
     14  1.1  jruoho  * 2. License
     15  1.1  jruoho  *
     16  1.1  jruoho  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.1  jruoho  * rights.  You may have additional license terms from the party that provided
     18  1.1  jruoho  * you this software, covering your right to use that party's intellectual
     19  1.1  jruoho  * property rights.
     20  1.1  jruoho  *
     21  1.1  jruoho  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.1  jruoho  * copy of the source code appearing in this file ("Covered Code") an
     23  1.1  jruoho  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.1  jruoho  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.1  jruoho  * make derivatives, distribute, use and display any portion of the Covered
     26  1.1  jruoho  * Code in any form, with the right to sublicense such rights; and
     27  1.1  jruoho  *
     28  1.1  jruoho  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.1  jruoho  * license (with the right to sublicense), under only those claims of Intel
     30  1.1  jruoho  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.1  jruoho  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.1  jruoho  * solely to the minimum extent necessary to exercise the above copyright
     33  1.1  jruoho  * license, and in no event shall the patent license extend to any additions
     34  1.1  jruoho  * to or modifications of the Original Intel Code.  No other license or right
     35  1.1  jruoho  * is granted directly or by implication, estoppel or otherwise;
     36  1.1  jruoho  *
     37  1.1  jruoho  * The above copyright and patent license is granted only if the following
     38  1.1  jruoho  * conditions are met:
     39  1.1  jruoho  *
     40  1.1  jruoho  * 3. Conditions
     41  1.1  jruoho  *
     42  1.1  jruoho  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     44  1.1  jruoho  * Code or modification with rights to further distribute source must include
     45  1.1  jruoho  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.1  jruoho  * and the following Disclaimer and Export Compliance provision.  In addition,
     47  1.1  jruoho  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.1  jruoho  * contain a file documenting the changes Licensee made to create that Covered
     49  1.1  jruoho  * Code and the date of any change.  Licensee must include in that file the
     50  1.1  jruoho  * documentation of any changes made by any predecessor Licensee.  Licensee
     51  1.1  jruoho  * must include a prominent statement that the modification is derived,
     52  1.1  jruoho  * directly or indirectly, from Original Intel Code.
     53  1.1  jruoho  *
     54  1.1  jruoho  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     56  1.1  jruoho  * Code or modification without rights to further distribute source must
     57  1.1  jruoho  * include the following Disclaimer and Export Compliance provision in the
     58  1.1  jruoho  * documentation and/or other materials provided with distribution.  In
     59  1.1  jruoho  * addition, Licensee may not authorize further sublicense of source of any
     60  1.1  jruoho  * portion of the Covered Code, and must include terms to the effect that the
     61  1.1  jruoho  * license from Licensee to its licensee is limited to the intellectual
     62  1.1  jruoho  * property embodied in the software Licensee provides to its licensee, and
     63  1.1  jruoho  * not to intellectual property embodied in modifications its licensee may
     64  1.1  jruoho  * make.
     65  1.1  jruoho  *
     66  1.1  jruoho  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.1  jruoho  * substantial portion of the Covered Code or modification must reproduce the
     68  1.1  jruoho  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.1  jruoho  * provision in the documentation and/or other materials provided with the
     70  1.1  jruoho  * distribution.
     71  1.1  jruoho  *
     72  1.1  jruoho  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.1  jruoho  * Intel Code.
     74  1.1  jruoho  *
     75  1.1  jruoho  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.1  jruoho  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.1  jruoho  * other dealings in products derived from or relating to the Covered Code
     78  1.1  jruoho  * without prior written authorization from Intel.
     79  1.1  jruoho  *
     80  1.1  jruoho  * 4. Disclaimer and Export Compliance
     81  1.1  jruoho  *
     82  1.1  jruoho  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.1  jruoho  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.1  jruoho  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
     85  1.1  jruoho  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
     86  1.1  jruoho  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.1  jruoho  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.1  jruoho  * PARTICULAR PURPOSE.
     89  1.1  jruoho  *
     90  1.1  jruoho  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.1  jruoho  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.1  jruoho  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.1  jruoho  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.1  jruoho  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.1  jruoho  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
     96  1.1  jruoho  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.1  jruoho  * LIMITED REMEDY.
     98  1.1  jruoho  *
     99  1.1  jruoho  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.1  jruoho  * software or system incorporating such software without first obtaining any
    101  1.1  jruoho  * required license or other approval from the U. S. Department of Commerce or
    102  1.1  jruoho  * any other agency or department of the United States Government.  In the
    103  1.1  jruoho  * event Licensee exports any such software from the United States or
    104  1.1  jruoho  * re-exports any such software from a foreign destination, Licensee shall
    105  1.1  jruoho  * ensure that the distribution and export/re-export of the software is in
    106  1.1  jruoho  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.1  jruoho  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.1  jruoho  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.1  jruoho  * software, or service, directly or indirectly, to any country for which the
    110  1.1  jruoho  * United States government or any agency thereof requires an export license,
    111  1.1  jruoho  * other governmental approval, or letter of assurance, without first obtaining
    112  1.1  jruoho  * such license, approval or letter.
    113  1.1  jruoho  *
    114  1.1  jruoho  *****************************************************************************/
    115  1.1  jruoho 
    116  1.1  jruoho #define __EXSTORE_C__
    117  1.1  jruoho 
    118  1.1  jruoho #include "acpi.h"
    119  1.1  jruoho #include "accommon.h"
    120  1.1  jruoho #include "acdispat.h"
    121  1.1  jruoho #include "acinterp.h"
    122  1.1  jruoho #include "amlcode.h"
    123  1.1  jruoho #include "acnamesp.h"
    124  1.1  jruoho 
    125  1.1  jruoho 
    126  1.1  jruoho #define _COMPONENT          ACPI_EXECUTER
    127  1.1  jruoho         ACPI_MODULE_NAME    ("exstore")
    128  1.1  jruoho 
    129  1.1  jruoho /* Local prototypes */
    130  1.1  jruoho 
    131  1.1  jruoho static ACPI_STATUS
    132  1.1  jruoho AcpiExStoreObjectToIndex (
    133  1.1  jruoho     ACPI_OPERAND_OBJECT     *ValDesc,
    134  1.1  jruoho     ACPI_OPERAND_OBJECT     *DestDesc,
    135  1.1  jruoho     ACPI_WALK_STATE         *WalkState);
    136  1.1  jruoho 
    137  1.1  jruoho 
    138  1.1  jruoho /*******************************************************************************
    139  1.1  jruoho  *
    140  1.1  jruoho  * FUNCTION:    AcpiExStore
    141  1.1  jruoho  *
    142  1.1  jruoho  * PARAMETERS:  *SourceDesc         - Value to be stored
    143  1.1  jruoho  *              *DestDesc           - Where to store it.  Must be an NS node
    144  1.1  jruoho  *                                    or an ACPI_OPERAND_OBJECT of type
    145  1.1  jruoho  *                                    Reference;
    146  1.1  jruoho  *              WalkState           - Current walk state
    147  1.1  jruoho  *
    148  1.1  jruoho  * RETURN:      Status
    149  1.1  jruoho  *
    150  1.1  jruoho  * DESCRIPTION: Store the value described by SourceDesc into the location
    151  1.1  jruoho  *              described by DestDesc.  Called by various interpreter
    152  1.1  jruoho  *              functions to store the result of an operation into
    153  1.1  jruoho  *              the destination operand -- not just simply the actual "Store"
    154  1.1  jruoho  *              ASL operator.
    155  1.1  jruoho  *
    156  1.1  jruoho  ******************************************************************************/
    157  1.1  jruoho 
    158  1.1  jruoho ACPI_STATUS
    159  1.1  jruoho AcpiExStore (
    160  1.1  jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
    161  1.1  jruoho     ACPI_OPERAND_OBJECT     *DestDesc,
    162  1.1  jruoho     ACPI_WALK_STATE         *WalkState)
    163  1.1  jruoho {
    164  1.1  jruoho     ACPI_STATUS             Status = AE_OK;
    165  1.1  jruoho     ACPI_OPERAND_OBJECT     *RefDesc = DestDesc;
    166  1.1  jruoho 
    167  1.1  jruoho 
    168  1.1  jruoho     ACPI_FUNCTION_TRACE_PTR (ExStore, DestDesc);
    169  1.1  jruoho 
    170  1.1  jruoho 
    171  1.1  jruoho     /* Validate parameters */
    172  1.1  jruoho 
    173  1.1  jruoho     if (!SourceDesc || !DestDesc)
    174  1.1  jruoho     {
    175  1.1  jruoho         ACPI_ERROR ((AE_INFO, "Null parameter"));
    176  1.1  jruoho         return_ACPI_STATUS (AE_AML_NO_OPERAND);
    177  1.1  jruoho     }
    178  1.1  jruoho 
    179  1.1  jruoho     /* DestDesc can be either a namespace node or an ACPI object */
    180  1.1  jruoho 
    181  1.1  jruoho     if (ACPI_GET_DESCRIPTOR_TYPE (DestDesc) == ACPI_DESC_TYPE_NAMED)
    182  1.1  jruoho     {
    183  1.1  jruoho         /*
    184  1.1  jruoho          * Dest is a namespace node,
    185  1.1  jruoho          * Storing an object into a Named node.
    186  1.1  jruoho          */
    187  1.1  jruoho         Status = AcpiExStoreObjectToNode (SourceDesc,
    188  1.1  jruoho                     (ACPI_NAMESPACE_NODE *) DestDesc, WalkState,
    189  1.1  jruoho                     ACPI_IMPLICIT_CONVERSION);
    190  1.1  jruoho 
    191  1.1  jruoho         return_ACPI_STATUS (Status);
    192  1.1  jruoho     }
    193  1.1  jruoho 
    194  1.1  jruoho     /* Destination object must be a Reference or a Constant object */
    195  1.1  jruoho 
    196  1.1  jruoho     switch (DestDesc->Common.Type)
    197  1.1  jruoho     {
    198  1.1  jruoho     case ACPI_TYPE_LOCAL_REFERENCE:
    199  1.1  jruoho         break;
    200  1.1  jruoho 
    201  1.1  jruoho     case ACPI_TYPE_INTEGER:
    202  1.1  jruoho 
    203  1.1  jruoho         /* Allow stores to Constants -- a Noop as per ACPI spec */
    204  1.1  jruoho 
    205  1.1  jruoho         if (DestDesc->Common.Flags & AOPOBJ_AML_CONSTANT)
    206  1.1  jruoho         {
    207  1.1  jruoho             return_ACPI_STATUS (AE_OK);
    208  1.1  jruoho         }
    209  1.1  jruoho 
    210  1.1  jruoho         /*lint -fallthrough */
    211  1.1  jruoho 
    212  1.1  jruoho     default:
    213  1.1  jruoho 
    214  1.1  jruoho         /* Destination is not a Reference object */
    215  1.1  jruoho 
    216  1.1  jruoho         ACPI_ERROR ((AE_INFO,
    217  1.1  jruoho             "Target is not a Reference or Constant object - %s [%p]",
    218  1.1  jruoho             AcpiUtGetObjectTypeName (DestDesc), DestDesc));
    219  1.1  jruoho 
    220  1.1  jruoho         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    221  1.1  jruoho     }
    222  1.1  jruoho 
    223  1.1  jruoho     /*
    224  1.1  jruoho      * Examine the Reference class. These cases are handled:
    225  1.1  jruoho      *
    226  1.1  jruoho      * 1) Store to Name (Change the object associated with a name)
    227  1.1  jruoho      * 2) Store to an indexed area of a Buffer or Package
    228  1.1  jruoho      * 3) Store to a Method Local or Arg
    229  1.1  jruoho      * 4) Store to the debug object
    230  1.1  jruoho      */
    231  1.1  jruoho     switch (RefDesc->Reference.Class)
    232  1.1  jruoho     {
    233  1.1  jruoho     case ACPI_REFCLASS_REFOF:
    234  1.1  jruoho 
    235  1.1  jruoho         /* Storing an object into a Name "container" */
    236  1.1  jruoho 
    237  1.1  jruoho         Status = AcpiExStoreObjectToNode (SourceDesc,
    238  1.1  jruoho                     RefDesc->Reference.Object,
    239  1.1  jruoho                     WalkState, ACPI_IMPLICIT_CONVERSION);
    240  1.1  jruoho         break;
    241  1.1  jruoho 
    242  1.1  jruoho 
    243  1.1  jruoho     case ACPI_REFCLASS_INDEX:
    244  1.1  jruoho 
    245  1.1  jruoho         /* Storing to an Index (pointer into a packager or buffer) */
    246  1.1  jruoho 
    247  1.1  jruoho         Status = AcpiExStoreObjectToIndex (SourceDesc, RefDesc, WalkState);
    248  1.1  jruoho         break;
    249  1.1  jruoho 
    250  1.1  jruoho 
    251  1.1  jruoho     case ACPI_REFCLASS_LOCAL:
    252  1.1  jruoho     case ACPI_REFCLASS_ARG:
    253  1.1  jruoho 
    254  1.1  jruoho         /* Store to a method local/arg  */
    255  1.1  jruoho 
    256  1.1  jruoho         Status = AcpiDsStoreObjectToLocal (RefDesc->Reference.Class,
    257  1.1  jruoho                     RefDesc->Reference.Value, SourceDesc, WalkState);
    258  1.1  jruoho         break;
    259  1.1  jruoho 
    260  1.1  jruoho 
    261  1.1  jruoho     case ACPI_REFCLASS_DEBUG:
    262  1.1  jruoho 
    263  1.1  jruoho         /*
    264  1.1  jruoho          * Storing to the Debug object causes the value stored to be
    265  1.1  jruoho          * displayed and otherwise has no effect -- see ACPI Specification
    266  1.1  jruoho          */
    267  1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    268  1.1  jruoho             "**** Write to Debug Object: Object %p %s ****:\n\n",
    269  1.1  jruoho             SourceDesc, AcpiUtGetObjectTypeName (SourceDesc)));
    270  1.1  jruoho 
    271  1.1  jruoho         ACPI_DEBUG_OBJECT (SourceDesc, 0, 0);
    272  1.1  jruoho         break;
    273  1.1  jruoho 
    274  1.1  jruoho 
    275  1.1  jruoho     default:
    276  1.1  jruoho 
    277  1.1  jruoho         ACPI_ERROR ((AE_INFO, "Unknown Reference Class 0x%2.2X",
    278  1.1  jruoho             RefDesc->Reference.Class));
    279  1.1  jruoho         ACPI_DUMP_ENTRY (RefDesc, ACPI_LV_INFO);
    280  1.1  jruoho 
    281  1.1  jruoho         Status = AE_AML_INTERNAL;
    282  1.1  jruoho         break;
    283  1.1  jruoho     }
    284  1.1  jruoho 
    285  1.1  jruoho     return_ACPI_STATUS (Status);
    286  1.1  jruoho }
    287  1.1  jruoho 
    288  1.1  jruoho 
    289  1.1  jruoho /*******************************************************************************
    290  1.1  jruoho  *
    291  1.1  jruoho  * FUNCTION:    AcpiExStoreObjectToIndex
    292  1.1  jruoho  *
    293  1.1  jruoho  * PARAMETERS:  *SourceDesc             - Value to be stored
    294  1.1  jruoho  *              *DestDesc               - Named object to receive the value
    295  1.1  jruoho  *              WalkState               - Current walk state
    296  1.1  jruoho  *
    297  1.1  jruoho  * RETURN:      Status
    298  1.1  jruoho  *
    299  1.1  jruoho  * DESCRIPTION: Store the object to indexed Buffer or Package element
    300  1.1  jruoho  *
    301  1.1  jruoho  ******************************************************************************/
    302  1.1  jruoho 
    303  1.1  jruoho static ACPI_STATUS
    304  1.1  jruoho AcpiExStoreObjectToIndex (
    305  1.1  jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
    306  1.1  jruoho     ACPI_OPERAND_OBJECT     *IndexDesc,
    307  1.1  jruoho     ACPI_WALK_STATE         *WalkState)
    308  1.1  jruoho {
    309  1.1  jruoho     ACPI_STATUS             Status = AE_OK;
    310  1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    311  1.1  jruoho     ACPI_OPERAND_OBJECT     *NewDesc;
    312  1.1  jruoho     UINT8                   Value = 0;
    313  1.1  jruoho     UINT32                  i;
    314  1.1  jruoho 
    315  1.1  jruoho 
    316  1.1  jruoho     ACPI_FUNCTION_TRACE (ExStoreObjectToIndex);
    317  1.1  jruoho 
    318  1.1  jruoho 
    319  1.1  jruoho     /*
    320  1.1  jruoho      * Destination must be a reference pointer, and
    321  1.1  jruoho      * must point to either a buffer or a package
    322  1.1  jruoho      */
    323  1.1  jruoho     switch (IndexDesc->Reference.TargetType)
    324  1.1  jruoho     {
    325  1.1  jruoho     case ACPI_TYPE_PACKAGE:
    326  1.1  jruoho         /*
    327  1.1  jruoho          * Storing to a package element. Copy the object and replace
    328  1.1  jruoho          * any existing object with the new object. No implicit
    329  1.1  jruoho          * conversion is performed.
    330  1.1  jruoho          *
    331  1.1  jruoho          * The object at *(IndexDesc->Reference.Where) is the
    332  1.1  jruoho          * element within the package that is to be modified.
    333  1.1  jruoho          * The parent package object is at IndexDesc->Reference.Object
    334  1.1  jruoho          */
    335  1.1  jruoho         ObjDesc = *(IndexDesc->Reference.Where);
    336  1.1  jruoho 
    337  1.1  jruoho         if (SourceDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE &&
    338  1.1  jruoho             SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE)
    339  1.1  jruoho         {
    340  1.1  jruoho             /* This is a DDBHandle, just add a reference to it */
    341  1.1  jruoho 
    342  1.1  jruoho             AcpiUtAddReference (SourceDesc);
    343  1.1  jruoho             NewDesc = SourceDesc;
    344  1.1  jruoho         }
    345  1.1  jruoho         else
    346  1.1  jruoho         {
    347  1.1  jruoho             /* Normal object, copy it */
    348  1.1  jruoho 
    349  1.1  jruoho             Status = AcpiUtCopyIobjectToIobject (SourceDesc, &NewDesc, WalkState);
    350  1.1  jruoho             if (ACPI_FAILURE (Status))
    351  1.1  jruoho             {
    352  1.1  jruoho                 return_ACPI_STATUS (Status);
    353  1.1  jruoho             }
    354  1.1  jruoho         }
    355  1.1  jruoho 
    356  1.1  jruoho         if (ObjDesc)
    357  1.1  jruoho         {
    358  1.1  jruoho             /* Decrement reference count by the ref count of the parent package */
    359  1.1  jruoho 
    360  1.1  jruoho             for (i = 0;
    361  1.1  jruoho                  i < ((ACPI_OPERAND_OBJECT *)
    362  1.1  jruoho                         IndexDesc->Reference.Object)->Common.ReferenceCount;
    363  1.1  jruoho                  i++)
    364  1.1  jruoho             {
    365  1.1  jruoho                 AcpiUtRemoveReference (ObjDesc);
    366  1.1  jruoho             }
    367  1.1  jruoho         }
    368  1.1  jruoho 
    369  1.1  jruoho         *(IndexDesc->Reference.Where) = NewDesc;
    370  1.1  jruoho 
    371  1.1  jruoho         /* Increment ref count by the ref count of the parent package-1 */
    372  1.1  jruoho 
    373  1.1  jruoho         for (i = 1;
    374  1.1  jruoho              i < ((ACPI_OPERAND_OBJECT *)
    375  1.1  jruoho                     IndexDesc->Reference.Object)->Common.ReferenceCount;
    376  1.1  jruoho              i++)
    377  1.1  jruoho         {
    378  1.1  jruoho             AcpiUtAddReference (NewDesc);
    379  1.1  jruoho         }
    380  1.1  jruoho 
    381  1.1  jruoho         break;
    382  1.1  jruoho 
    383  1.1  jruoho 
    384  1.1  jruoho     case ACPI_TYPE_BUFFER_FIELD:
    385  1.1  jruoho 
    386  1.1  jruoho         /*
    387  1.1  jruoho          * Store into a Buffer or String (not actually a real BufferField)
    388  1.1  jruoho          * at a location defined by an Index.
    389  1.1  jruoho          *
    390  1.1  jruoho          * The first 8-bit element of the source object is written to the
    391  1.1  jruoho          * 8-bit Buffer location defined by the Index destination object,
    392  1.1  jruoho          * according to the ACPI 2.0 specification.
    393  1.1  jruoho          */
    394  1.1  jruoho 
    395  1.1  jruoho         /*
    396  1.1  jruoho          * Make sure the target is a Buffer or String. An error should
    397  1.1  jruoho          * not happen here, since the ReferenceObject was constructed
    398  1.1  jruoho          * by the INDEX_OP code.
    399  1.1  jruoho          */
    400  1.1  jruoho         ObjDesc = IndexDesc->Reference.Object;
    401  1.1  jruoho         if ((ObjDesc->Common.Type != ACPI_TYPE_BUFFER) &&
    402  1.1  jruoho             (ObjDesc->Common.Type != ACPI_TYPE_STRING))
    403  1.1  jruoho         {
    404  1.1  jruoho             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    405  1.1  jruoho         }
    406  1.1  jruoho 
    407  1.1  jruoho         /*
    408  1.1  jruoho          * The assignment of the individual elements will be slightly
    409  1.1  jruoho          * different for each source type.
    410  1.1  jruoho          */
    411  1.1  jruoho         switch (SourceDesc->Common.Type)
    412  1.1  jruoho         {
    413  1.1  jruoho         case ACPI_TYPE_INTEGER:
    414  1.1  jruoho 
    415  1.1  jruoho             /* Use the least-significant byte of the integer */
    416  1.1  jruoho 
    417  1.1  jruoho             Value = (UINT8) (SourceDesc->Integer.Value);
    418  1.1  jruoho             break;
    419  1.1  jruoho 
    420  1.1  jruoho         case ACPI_TYPE_BUFFER:
    421  1.1  jruoho         case ACPI_TYPE_STRING:
    422  1.1  jruoho 
    423  1.1  jruoho             /* Note: Takes advantage of common string/buffer fields */
    424  1.1  jruoho 
    425  1.1  jruoho             Value = SourceDesc->Buffer.Pointer[0];
    426  1.1  jruoho             break;
    427  1.1  jruoho 
    428  1.1  jruoho         default:
    429  1.1  jruoho 
    430  1.1  jruoho             /* All other types are invalid */
    431  1.1  jruoho 
    432  1.1  jruoho             ACPI_ERROR ((AE_INFO,
    433  1.1  jruoho                 "Source must be Integer/Buffer/String type, not %s",
    434  1.1  jruoho                 AcpiUtGetObjectTypeName (SourceDesc)));
    435  1.1  jruoho             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    436  1.1  jruoho         }
    437  1.1  jruoho 
    438  1.1  jruoho         /* Store the source value into the target buffer byte */
    439  1.1  jruoho 
    440  1.1  jruoho         ObjDesc->Buffer.Pointer[IndexDesc->Reference.Value] = Value;
    441  1.1  jruoho         break;
    442  1.1  jruoho 
    443  1.1  jruoho 
    444  1.1  jruoho     default:
    445  1.1  jruoho         ACPI_ERROR ((AE_INFO,
    446  1.1  jruoho             "Target is not a Package or BufferField"));
    447  1.1  jruoho         Status = AE_AML_OPERAND_TYPE;
    448  1.1  jruoho         break;
    449  1.1  jruoho     }
    450  1.1  jruoho 
    451  1.1  jruoho     return_ACPI_STATUS (Status);
    452  1.1  jruoho }
    453  1.1  jruoho 
    454  1.1  jruoho 
    455  1.1  jruoho /*******************************************************************************
    456  1.1  jruoho  *
    457  1.1  jruoho  * FUNCTION:    AcpiExStoreObjectToNode
    458  1.1  jruoho  *
    459  1.1  jruoho  * PARAMETERS:  SourceDesc              - Value to be stored
    460  1.1  jruoho  *              Node                    - Named object to receive the value
    461  1.1  jruoho  *              WalkState               - Current walk state
    462  1.1  jruoho  *              ImplicitConversion      - Perform implicit conversion (yes/no)
    463  1.1  jruoho  *
    464  1.1  jruoho  * RETURN:      Status
    465  1.1  jruoho  *
    466  1.1  jruoho  * DESCRIPTION: Store the object to the named object.
    467  1.1  jruoho  *
    468  1.1  jruoho  *              The Assignment of an object to a named object is handled here
    469  1.1  jruoho  *              The value passed in will replace the current value (if any)
    470  1.1  jruoho  *              with the input value.
    471  1.1  jruoho  *
    472  1.1  jruoho  *              When storing into an object the data is converted to the
    473  1.1  jruoho  *              target object type then stored in the object.  This means
    474  1.1  jruoho  *              that the target object type (for an initialized target) will
    475  1.1  jruoho  *              not be changed by a store operation.
    476  1.1  jruoho  *
    477  1.1  jruoho  *              Assumes parameters are already validated.
    478  1.1  jruoho  *
    479  1.1  jruoho  ******************************************************************************/
    480  1.1  jruoho 
    481  1.1  jruoho ACPI_STATUS
    482  1.1  jruoho AcpiExStoreObjectToNode (
    483  1.1  jruoho     ACPI_OPERAND_OBJECT     *SourceDesc,
    484  1.1  jruoho     ACPI_NAMESPACE_NODE     *Node,
    485  1.1  jruoho     ACPI_WALK_STATE         *WalkState,
    486  1.1  jruoho     UINT8                   ImplicitConversion)
    487  1.1  jruoho {
    488  1.1  jruoho     ACPI_STATUS             Status = AE_OK;
    489  1.1  jruoho     ACPI_OPERAND_OBJECT     *TargetDesc;
    490  1.1  jruoho     ACPI_OPERAND_OBJECT     *NewDesc;
    491  1.1  jruoho     ACPI_OBJECT_TYPE        TargetType;
    492  1.1  jruoho 
    493  1.1  jruoho 
    494  1.1  jruoho     ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToNode, SourceDesc);
    495  1.1  jruoho 
    496  1.1  jruoho 
    497  1.1  jruoho     /* Get current type of the node, and object attached to Node */
    498  1.1  jruoho 
    499  1.1  jruoho     TargetType = AcpiNsGetType (Node);
    500  1.1  jruoho     TargetDesc = AcpiNsGetAttachedObject (Node);
    501  1.1  jruoho 
    502  1.1  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
    503  1.1  jruoho         SourceDesc, AcpiUtGetObjectTypeName (SourceDesc),
    504  1.1  jruoho               Node, AcpiUtGetTypeName (TargetType)));
    505  1.1  jruoho 
    506  1.1  jruoho     /*
    507  1.1  jruoho      * Resolve the source object to an actual value
    508  1.1  jruoho      * (If it is a reference object)
    509  1.1  jruoho      */
    510  1.1  jruoho     Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState);
    511  1.1  jruoho     if (ACPI_FAILURE (Status))
    512  1.1  jruoho     {
    513  1.1  jruoho         return_ACPI_STATUS (Status);
    514  1.1  jruoho     }
    515  1.1  jruoho 
    516  1.1  jruoho     /* If no implicit conversion, drop into the default case below */
    517  1.1  jruoho 
    518  1.1  jruoho     if ((!ImplicitConversion) ||
    519  1.1  jruoho           ((WalkState->Opcode == AML_COPY_OP) &&
    520  1.1  jruoho            (TargetType != ACPI_TYPE_LOCAL_REGION_FIELD) &&
    521  1.1  jruoho            (TargetType != ACPI_TYPE_LOCAL_BANK_FIELD) &&
    522  1.1  jruoho            (TargetType != ACPI_TYPE_LOCAL_INDEX_FIELD)))
    523  1.1  jruoho     {
    524  1.1  jruoho         /*
    525  1.1  jruoho          * Force execution of default (no implicit conversion). Note:
    526  1.1  jruoho          * CopyObject does not perform an implicit conversion, as per the ACPI
    527  1.1  jruoho          * spec -- except in case of region/bank/index fields -- because these
    528  1.1  jruoho          * objects must retain their original type permanently.
    529  1.1  jruoho          */
    530  1.1  jruoho         TargetType = ACPI_TYPE_ANY;
    531  1.1  jruoho     }
    532  1.1  jruoho 
    533  1.1  jruoho     /* Do the actual store operation */
    534  1.1  jruoho 
    535  1.1  jruoho     switch (TargetType)
    536  1.1  jruoho     {
    537  1.1  jruoho     case ACPI_TYPE_BUFFER_FIELD:
    538  1.1  jruoho     case ACPI_TYPE_LOCAL_REGION_FIELD:
    539  1.1  jruoho     case ACPI_TYPE_LOCAL_BANK_FIELD:
    540  1.1  jruoho     case ACPI_TYPE_LOCAL_INDEX_FIELD:
    541  1.1  jruoho 
    542  1.1  jruoho         /* For fields, copy the source data to the target field. */
    543  1.1  jruoho 
    544  1.1  jruoho         Status = AcpiExWriteDataToField (SourceDesc, TargetDesc,
    545  1.1  jruoho                     &WalkState->ResultObj);
    546  1.1  jruoho         break;
    547  1.1  jruoho 
    548  1.1  jruoho 
    549  1.1  jruoho     case ACPI_TYPE_INTEGER:
    550  1.1  jruoho     case ACPI_TYPE_STRING:
    551  1.1  jruoho     case ACPI_TYPE_BUFFER:
    552  1.1  jruoho 
    553  1.1  jruoho         /*
    554  1.1  jruoho          * These target types are all of type Integer/String/Buffer, and
    555  1.1  jruoho          * therefore support implicit conversion before the store.
    556  1.1  jruoho          *
    557  1.1  jruoho          * Copy and/or convert the source object to a new target object
    558  1.1  jruoho          */
    559  1.1  jruoho         Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc,
    560  1.1  jruoho                     &NewDesc, WalkState);
    561  1.1  jruoho         if (ACPI_FAILURE (Status))
    562  1.1  jruoho         {
    563  1.1  jruoho             return_ACPI_STATUS (Status);
    564  1.1  jruoho         }
    565  1.1  jruoho 
    566  1.1  jruoho         if (NewDesc != TargetDesc)
    567  1.1  jruoho         {
    568  1.1  jruoho             /*
    569  1.1  jruoho              * Store the new NewDesc as the new value of the Name, and set
    570  1.1  jruoho              * the Name's type to that of the value being stored in it.
    571  1.1  jruoho              * SourceDesc reference count is incremented by AttachObject.
    572  1.1  jruoho              *
    573  1.1  jruoho              * Note: This may change the type of the node if an explicit store
    574  1.1  jruoho              * has been performed such that the node/object type has been
    575  1.1  jruoho              * changed.
    576  1.1  jruoho              */
    577  1.1  jruoho             Status = AcpiNsAttachObject (Node, NewDesc, NewDesc->Common.Type);
    578  1.1  jruoho 
    579  1.1  jruoho             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    580  1.1  jruoho                 "Store %s into %s via Convert/Attach\n",
    581  1.1  jruoho                 AcpiUtGetObjectTypeName (SourceDesc),
    582  1.1  jruoho                 AcpiUtGetObjectTypeName (NewDesc)));
    583  1.1  jruoho         }
    584  1.1  jruoho         break;
    585  1.1  jruoho 
    586  1.1  jruoho 
    587  1.1  jruoho     default:
    588  1.1  jruoho 
    589  1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    590  1.1  jruoho             "Storing %s (%p) directly into node (%p) with no implicit conversion\n",
    591  1.1  jruoho             AcpiUtGetObjectTypeName (SourceDesc), SourceDesc, Node));
    592  1.1  jruoho 
    593  1.1  jruoho         /* No conversions for all other types.  Just attach the source object */
    594  1.1  jruoho 
    595  1.1  jruoho         Status = AcpiNsAttachObject (Node, SourceDesc,
    596  1.1  jruoho                     SourceDesc->Common.Type);
    597  1.1  jruoho         break;
    598  1.1  jruoho     }
    599  1.1  jruoho 
    600  1.1  jruoho     return_ACPI_STATUS (Status);
    601  1.1  jruoho }
    602  1.1  jruoho 
    603  1.1  jruoho 
    604