exstore.c revision 99679
167754Smsmith
267754Smsmith/******************************************************************************
367754Smsmith *
477424Smsmith * Module Name: exstore - AML Interpreter object store support
599679Siwasaki *              $Revision: 167 $
667754Smsmith *
767754Smsmith *****************************************************************************/
867754Smsmith
967754Smsmith/******************************************************************************
1067754Smsmith *
1167754Smsmith * 1. Copyright Notice
1267754Smsmith *
1391116Smsmith * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
1470243Smsmith * All rights reserved.
1567754Smsmith *
1667754Smsmith * 2. License
1767754Smsmith *
1867754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
1967754Smsmith * rights.  You may have additional license terms from the party that provided
2067754Smsmith * you this software, covering your right to use that party's intellectual
2167754Smsmith * property rights.
2267754Smsmith *
2367754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2467754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2567754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2667754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2767754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2867754Smsmith * Code in any form, with the right to sublicense such rights; and
2967754Smsmith *
3067754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3167754Smsmith * license (with the right to sublicense), under only those claims of Intel
3267754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3367754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3467754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3567754Smsmith * license, and in no event shall the patent license extend to any additions
3667754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3767754Smsmith * is granted directly or by implication, estoppel or otherwise;
3867754Smsmith *
3967754Smsmith * The above copyright and patent license is granted only if the following
4067754Smsmith * conditions are met:
4167754Smsmith *
4267754Smsmith * 3. Conditions
4367754Smsmith *
4467754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4567754Smsmith * Redistribution of source code of any substantial portion of the Covered
4667754Smsmith * Code or modification with rights to further distribute source must include
4767754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4867754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
4967754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
5067754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5167754Smsmith * Code and the date of any change.  Licensee must include in that file the
5267754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5367754Smsmith * must include a prominent statement that the modification is derived,
5467754Smsmith * directly or indirectly, from Original Intel Code.
5567754Smsmith *
5667754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5767754Smsmith * Redistribution of source code of any substantial portion of the Covered
5867754Smsmith * Code or modification without rights to further distribute source must
5967754Smsmith * include the following Disclaimer and Export Compliance provision in the
6067754Smsmith * documentation and/or other materials provided with distribution.  In
6167754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6267754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6367754Smsmith * license from Licensee to its licensee is limited to the intellectual
6467754Smsmith * property embodied in the software Licensee provides to its licensee, and
6567754Smsmith * not to intellectual property embodied in modifications its licensee may
6667754Smsmith * make.
6767754Smsmith *
6867754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
6967754Smsmith * substantial portion of the Covered Code or modification must reproduce the
7067754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7167754Smsmith * provision in the documentation and/or other materials provided with the
7267754Smsmith * distribution.
7367754Smsmith *
7467754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7567754Smsmith * Intel Code.
7667754Smsmith *
7767754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7867754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
7967754Smsmith * other dealings in products derived from or relating to the Covered Code
8067754Smsmith * without prior written authorization from Intel.
8167754Smsmith *
8267754Smsmith * 4. Disclaimer and Export Compliance
8367754Smsmith *
8467754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8567754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8667754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8767754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8867754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8967754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
9067754Smsmith * PARTICULAR PURPOSE.
9167754Smsmith *
9267754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9367754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9467754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9567754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9667754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9767754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9867754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9967754Smsmith * LIMITED REMEDY.
10067754Smsmith *
10167754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10267754Smsmith * software or system incorporating such software without first obtaining any
10367754Smsmith * required license or other approval from the U. S. Department of Commerce or
10467754Smsmith * any other agency or department of the United States Government.  In the
10567754Smsmith * event Licensee exports any such software from the United States or
10667754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10767754Smsmith * ensure that the distribution and export/re-export of the software is in
10867754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10967754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
11067754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11167754Smsmith * software, or service, directly or indirectly, to any country for which the
11267754Smsmith * United States government or any agency thereof requires an export license,
11367754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11467754Smsmith * such license, approval or letter.
11567754Smsmith *
11667754Smsmith *****************************************************************************/
11767754Smsmith
11877424Smsmith#define __EXSTORE_C__
11967754Smsmith
12067754Smsmith#include "acpi.h"
12167754Smsmith#include "acdispat.h"
12267754Smsmith#include "acinterp.h"
12367754Smsmith#include "amlcode.h"
12467754Smsmith#include "acnamesp.h"
12567754Smsmith
12667754Smsmith
12777424Smsmith#define _COMPONENT          ACPI_EXECUTER
12891116Smsmith        ACPI_MODULE_NAME    ("exstore")
12967754Smsmith
13067754Smsmith
13167754Smsmith/*******************************************************************************
13267754Smsmith *
13377424Smsmith * FUNCTION:    AcpiExStore
13467754Smsmith *
13585756Smsmith * PARAMETERS:  *SourceDesc         - Value to be stored
13677424Smsmith *              *DestDesc           - Where to store it.  Must be an NS node
13777424Smsmith *                                    or an ACPI_OPERAND_OBJECT of type
13887031Smsmith *                                    Reference;
13987031Smsmith *              WalkState           - Current walk state
14067754Smsmith *
14167754Smsmith * RETURN:      Status
14267754Smsmith *
14385756Smsmith * DESCRIPTION: Store the value described by SourceDesc into the location
14467754Smsmith *              described by DestDesc.  Called by various interpreter
14567754Smsmith *              functions to store the result of an operation into
14691116Smsmith *              the destination operand -- not just simply the actual "Store"
14787031Smsmith *              ASL operator.
14867754Smsmith *
14967754Smsmith ******************************************************************************/
15067754Smsmith
15167754SmsmithACPI_STATUS
15277424SmsmithAcpiExStore (
15385756Smsmith    ACPI_OPERAND_OBJECT     *SourceDesc,
15467754Smsmith    ACPI_OPERAND_OBJECT     *DestDesc,
15567754Smsmith    ACPI_WALK_STATE         *WalkState)
15667754Smsmith{
15767754Smsmith    ACPI_STATUS             Status = AE_OK;
15871867Smsmith    ACPI_OPERAND_OBJECT     *RefDesc = DestDesc;
15967754Smsmith
16067754Smsmith
16191116Smsmith    ACPI_FUNCTION_TRACE_PTR ("ExStore", DestDesc);
16267754Smsmith
16367754Smsmith
16467754Smsmith    /* Validate parameters */
16567754Smsmith
16685756Smsmith    if (!SourceDesc || !DestDesc)
16767754Smsmith    {
16891116Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null parameter\n"));
16967754Smsmith        return_ACPI_STATUS (AE_AML_NO_OPERAND);
17067754Smsmith    }
17167754Smsmith
17271867Smsmith    /* DestDesc can be either a namespace node or an ACPI object */
17367754Smsmith
17491116Smsmith    if (ACPI_GET_DESCRIPTOR_TYPE (DestDesc) == ACPI_DESC_TYPE_NAMED)
17567754Smsmith    {
17677424Smsmith        /*
17771867Smsmith         * Dest is a namespace node,
17877424Smsmith         * Storing an object into a Name "container"
17971867Smsmith         */
18085756Smsmith        Status = AcpiExStoreObjectToNode (SourceDesc,
18171867Smsmith                    (ACPI_NAMESPACE_NODE *) DestDesc, WalkState);
18267754Smsmith
18371867Smsmith        return_ACPI_STATUS (Status);
18467754Smsmith    }
18567754Smsmith
18699679Siwasaki    /* Destination object must be a Reference or a Constant object */
18767754Smsmith
18899679Siwasaki    switch (ACPI_GET_OBJECT_TYPE (DestDesc))
18999679Siwasaki    {
19099679Siwasaki    case INTERNAL_TYPE_REFERENCE:
19199679Siwasaki        break;
19299679Siwasaki
19399679Siwasaki    case ACPI_TYPE_INTEGER:
19499679Siwasaki
19599679Siwasaki        /* Allow stores to Constants -- a Noop as per ACPI spec */
19699679Siwasaki
19799679Siwasaki        if (DestDesc->Common.Flags & AOPOBJ_AML_CONSTANT)
19899679Siwasaki        {
19999679Siwasaki            return_ACPI_STATUS (AE_OK);
20099679Siwasaki        }
20199679Siwasaki
20299679Siwasaki        /*lint: -fallthrough */
20399679Siwasaki
20499679Siwasaki    default:
20599679Siwasaki
20667754Smsmith        /* Destination is not an Reference */
20767754Smsmith
20882367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
20999679Siwasaki            "Destination is not a Reference or Constant object [%p]\n", DestDesc));
21067754Smsmith
21191116Smsmith        ACPI_DUMP_STACK_ENTRY (SourceDesc);
21291116Smsmith        ACPI_DUMP_STACK_ENTRY (DestDesc);
21391116Smsmith        ACPI_DUMP_OPERANDS (&DestDesc, ACPI_IMODE_EXECUTE, "ExStore",
21499679Siwasaki                        2, "Target is not a Reference or Constant object");
21567754Smsmith
21667754Smsmith        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
21767754Smsmith    }
21867754Smsmith
21977424Smsmith    /*
22071867Smsmith     * Examine the Reference opcode.  These cases are handled:
22171867Smsmith     *
22271867Smsmith     * 1) Store to Name (Change the object associated with a name)
22371867Smsmith     * 2) Store to an indexed area of a Buffer or Package
22471867Smsmith     * 3) Store to a Method Local or Arg
22571867Smsmith     * 4) Store to the debug object
22671867Smsmith     */
22777424Smsmith    switch (RefDesc->Reference.Opcode)
22867754Smsmith    {
22967754Smsmith    case AML_NAME_OP:
23067754Smsmith
23171867Smsmith        /* Storing an object into a Name "container" */
23271867Smsmith
23385756Smsmith        Status = AcpiExStoreObjectToNode (SourceDesc, RefDesc->Reference.Object,
23467754Smsmith                        WalkState);
23571867Smsmith        break;
23667754Smsmith
23767754Smsmith
23867754Smsmith    case AML_INDEX_OP:
23967754Smsmith
24071867Smsmith        /* Storing to an Index (pointer into a packager or buffer) */
24167754Smsmith
24285756Smsmith        Status = AcpiExStoreObjectToIndex (SourceDesc, RefDesc, WalkState);
24371867Smsmith        break;
24471867Smsmith
24571867Smsmith
24671867Smsmith    case AML_LOCAL_OP:
24777424Smsmith    case AML_ARG_OP:
24871867Smsmith
24977424Smsmith        /* Store to a method local/arg  */
25071867Smsmith
25177424Smsmith        Status = AcpiDsStoreObjectToLocal (RefDesc->Reference.Opcode,
25285756Smsmith                        RefDesc->Reference.Offset, SourceDesc, WalkState);
25371867Smsmith        break;
25471867Smsmith
25571867Smsmith
25671867Smsmith    case AML_DEBUG_OP:
25771867Smsmith
25867754Smsmith        /*
25971867Smsmith         * Storing to the Debug object causes the value stored to be
26071867Smsmith         * displayed and otherwise has no effect -- see ACPI Specification
26167754Smsmith         */
26299146Siwasaki        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Write to Debug Object: ****:\n\n"));
26377424Smsmith
26483174Smsmith        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %s: ",
26599679Siwasaki                        AcpiUtGetObjectTypeName (SourceDesc)));
26677424Smsmith
26799679Siwasaki        switch (ACPI_GET_OBJECT_TYPE (SourceDesc))
26871867Smsmith        {
26977424Smsmith        case ACPI_TYPE_INTEGER:
27077424Smsmith
27191116Smsmith            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%8.8X%8.8X\n",
27291116Smsmith                    ACPI_HIWORD (SourceDesc->Integer.Value),
27391116Smsmith                    ACPI_LOWORD (SourceDesc->Integer.Value)));
27477424Smsmith            break;
27577424Smsmith
27677424Smsmith
27777424Smsmith        case ACPI_TYPE_BUFFER:
27877424Smsmith
27991116Smsmith            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "Length %.2X\n",
28091116Smsmith                    (UINT32) SourceDesc->Buffer.Length));
28177424Smsmith            break;
28277424Smsmith
28377424Smsmith
28477424Smsmith        case ACPI_TYPE_STRING:
28577424Smsmith
28685756Smsmith            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%s\n", SourceDesc->String.Pointer));
28777424Smsmith            break;
28877424Smsmith
28977424Smsmith
29077424Smsmith        case ACPI_TYPE_PACKAGE:
29177424Smsmith
29291116Smsmith            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "Elements Ptr - %p\n",
29391116Smsmith                    SourceDesc->Package.Elements));
29477424Smsmith            break;
29577424Smsmith
29677424Smsmith
29777424Smsmith        default:
29877424Smsmith
29991116Smsmith            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "Type %s %p\n",
30099679Siwasaki                    AcpiUtGetObjectTypeName (SourceDesc), SourceDesc));
30177424Smsmith            break;
30271867Smsmith        }
30367754Smsmith
30499146Siwasaki        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
30571867Smsmith        break;
30671867Smsmith
30771867Smsmith
30871867Smsmith    default:
30971867Smsmith
31099679Siwasaki        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Reference opcode %X\n",
31177424Smsmith            RefDesc->Reference.Opcode));
31291116Smsmith        ACPI_DUMP_ENTRY (RefDesc, ACPI_LV_ERROR);
31371867Smsmith
31471867Smsmith        Status = AE_AML_INTERNAL;
31571867Smsmith        break;
31699679Siwasaki    }
31771867Smsmith
31871867Smsmith    return_ACPI_STATUS (Status);
31971867Smsmith}
32071867Smsmith
32171867Smsmith
32271867Smsmith/*******************************************************************************
32371867Smsmith *
32477424Smsmith * FUNCTION:    AcpiExStoreObjectToIndex
32571867Smsmith *
32687031Smsmith * PARAMETERS:  *SourceDesc             - Value to be stored
32787031Smsmith *              *DestDesc               - Named object to receive the value
32887031Smsmith *              WalkState               - Current walk state
32971867Smsmith *
33071867Smsmith * RETURN:      Status
33171867Smsmith *
33287031Smsmith * DESCRIPTION: Store the object to indexed Buffer or Package element
33371867Smsmith *
33471867Smsmith ******************************************************************************/
33571867Smsmith
33671867SmsmithACPI_STATUS
33777424SmsmithAcpiExStoreObjectToIndex (
33885756Smsmith    ACPI_OPERAND_OBJECT     *SourceDesc,
33991116Smsmith    ACPI_OPERAND_OBJECT     *IndexDesc,
34071867Smsmith    ACPI_WALK_STATE         *WalkState)
34171867Smsmith{
34271867Smsmith    ACPI_STATUS             Status = AE_OK;
34371867Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
34491116Smsmith    ACPI_OPERAND_OBJECT     *NewDesc;
34571867Smsmith    UINT8                   Value = 0;
34671867Smsmith
34771867Smsmith
34891116Smsmith    ACPI_FUNCTION_TRACE ("ExStoreObjectToIndex");
34971867Smsmith
35071867Smsmith
35171867Smsmith    /*
35271867Smsmith     * Destination must be a reference pointer, and
35371867Smsmith     * must point to either a buffer or a package
35471867Smsmith     */
35591116Smsmith    switch (IndexDesc->Reference.TargetType)
35671867Smsmith    {
35771867Smsmith    case ACPI_TYPE_PACKAGE:
35871867Smsmith        /*
35971867Smsmith         * Storing to a package element is not simple.  The source must be
36067754Smsmith         * evaluated and converted to the type of the destination and then the
36167754Smsmith         * source is copied into the destination - we can't just point to the
36267754Smsmith         * source object.
36367754Smsmith         */
36491116Smsmith        /*
36591116Smsmith         * The object at *(IndexDesc->Reference.Where) is the
36691116Smsmith         * element within the package that is to be modified.
36791116Smsmith         */
36891116Smsmith        ObjDesc = *(IndexDesc->Reference.Where);
36985756Smsmith
37091116Smsmith        /* Do the conversion/store */
37167754Smsmith
37291116Smsmith        Status = AcpiExStoreObjectToObject (SourceDesc, ObjDesc, &NewDesc,
37391116Smsmith                                                WalkState);
37491116Smsmith        if (ACPI_FAILURE (Status))
37591116Smsmith        {
37691116Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
37791116Smsmith                "Could not store object to indexed package element\n"));
37891116Smsmith            return_ACPI_STATUS (Status);
37991116Smsmith        }
38067754Smsmith
38191116Smsmith        /*
38291116Smsmith         * If a new object was created, we must install it as the new
38391116Smsmith         * package element
38491116Smsmith         */
38591116Smsmith        if (NewDesc != ObjDesc)
38691116Smsmith        {
38791116Smsmith            AcpiUtRemoveReference (ObjDesc);
38891116Smsmith            *(IndexDesc->Reference.Where) = NewDesc;
38967754Smsmith        }
39071867Smsmith        break;
39167754Smsmith
39267754Smsmith
39371867Smsmith    case ACPI_TYPE_BUFFER_FIELD:
39477424Smsmith
39567754Smsmith        /*
39691116Smsmith         * Store into a Buffer (not actually a real BufferField) at a
39787031Smsmith         * location defined by an Index.
39867754Smsmith         *
39987031Smsmith         * The first 8-bit element of the source object is written to the
40087031Smsmith         * 8-bit Buffer location defined by the Index destination object,
40187031Smsmith         * according to the ACPI 2.0 specification.
40267754Smsmith         */
40367754Smsmith
40467754Smsmith        /*
40587031Smsmith         * Make sure the target is a Buffer
40667754Smsmith         */
40791116Smsmith        ObjDesc = IndexDesc->Reference.Object;
40899679Siwasaki        if (ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_BUFFER)
40967754Smsmith        {
41071867Smsmith            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
41167754Smsmith        }
41267754Smsmith
41367754Smsmith        /*
41467754Smsmith         * The assignment of the individual elements will be slightly
41567754Smsmith         * different for each source type.
41667754Smsmith         */
41799679Siwasaki        switch (ACPI_GET_OBJECT_TYPE (SourceDesc))
41867754Smsmith        {
41971867Smsmith        case ACPI_TYPE_INTEGER:
42087031Smsmith
42187031Smsmith            /* Use the least-significant byte of the integer */
42287031Smsmith
42387031Smsmith            Value = (UINT8) (SourceDesc->Integer.Value);
42467754Smsmith            break;
42567754Smsmith
42687031Smsmith        case ACPI_TYPE_BUFFER:
42777424Smsmith
42887031Smsmith            Value = SourceDesc->Buffer.Pointer[0];
42967754Smsmith            break;
43067754Smsmith
43187031Smsmith        case ACPI_TYPE_STRING:
43277424Smsmith
43399679Siwasaki            Value = (UINT8) SourceDesc->String.Pointer[0];
43467754Smsmith            break;
43567754Smsmith
43667754Smsmith        default:
43777424Smsmith
43887031Smsmith            /* All other types are invalid */
43977424Smsmith
44082367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
44187031Smsmith                "Source must be Integer/Buffer/String type, not %s\n",
44299679Siwasaki                AcpiUtGetObjectTypeName (SourceDesc)));
44387031Smsmith            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
44467754Smsmith        }
44587031Smsmith
44687031Smsmith        /* Store the source value into the target buffer byte */
44787031Smsmith
44891116Smsmith        ObjDesc->Buffer.Pointer[IndexDesc->Reference.Offset] = Value;
44971867Smsmith        break;
45067754Smsmith
45167754Smsmith
45271867Smsmith    default:
45391116Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
45487031Smsmith            "Target is not a Package or BufferField\n"));
45571867Smsmith        Status = AE_AML_OPERAND_TYPE;
45667754Smsmith        break;
45771867Smsmith    }
45867754Smsmith
45971867Smsmith    return_ACPI_STATUS (Status);
46071867Smsmith}
46167754Smsmith
46267754Smsmith
46371867Smsmith/*******************************************************************************
46471867Smsmith *
46577424Smsmith * FUNCTION:    AcpiExStoreObjectToNode
46671867Smsmith *
46787031Smsmith * PARAMETERS:  SourceDesc              - Value to be stored
46887031Smsmith *              Node                    - Named object to receive the value
46987031Smsmith *              WalkState               - Current walk state
47071867Smsmith *
47171867Smsmith * RETURN:      Status
47271867Smsmith *
47371867Smsmith * DESCRIPTION: Store the object to the named object.
47471867Smsmith *
47571867Smsmith *              The Assignment of an object to a named object is handled here
47687031Smsmith *              The value passed in will replace the current value (if any)
47771867Smsmith *              with the input value.
47871867Smsmith *
47971867Smsmith *              When storing into an object the data is converted to the
48071867Smsmith *              target object type then stored in the object.  This means
48171867Smsmith *              that the target object type (for an initialized target) will
48271867Smsmith *              not be changed by a store operation.
48371867Smsmith *
48487031Smsmith *              Assumes parameters are already validated.
48571867Smsmith *
48671867Smsmith ******************************************************************************/
48767754Smsmith
48871867SmsmithACPI_STATUS
48977424SmsmithAcpiExStoreObjectToNode (
49071867Smsmith    ACPI_OPERAND_OBJECT     *SourceDesc,
49171867Smsmith    ACPI_NAMESPACE_NODE     *Node,
49271867Smsmith    ACPI_WALK_STATE         *WalkState)
49371867Smsmith{
49471867Smsmith    ACPI_STATUS             Status = AE_OK;
49571867Smsmith    ACPI_OPERAND_OBJECT     *TargetDesc;
49691116Smsmith    ACPI_OPERAND_OBJECT     *NewDesc;
49791116Smsmith    ACPI_OBJECT_TYPE        TargetType;
49867754Smsmith
49971867Smsmith
50091116Smsmith    ACPI_FUNCTION_TRACE_PTR ("ExStoreObjectToNode", SourceDesc);
50171867Smsmith
50283174Smsmith
50371867Smsmith    /*
50471867Smsmith     * Get current type of the node, and object attached to Node
50571867Smsmith     */
50671867Smsmith    TargetType = AcpiNsGetType (Node);
50771867Smsmith    TargetDesc = AcpiNsGetAttachedObject (Node);
50871867Smsmith
50999146Siwasaki    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
51099679Siwasaki        SourceDesc, AcpiUtGetObjectTypeName (SourceDesc),
51191116Smsmith              Node, AcpiUtGetTypeName (TargetType)));
51271867Smsmith
51371867Smsmith    /*
51471867Smsmith     * Resolve the source object to an actual value
51577424Smsmith     * (If it is a reference object)
51671867Smsmith     */
51777424Smsmith    Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState);
51871867Smsmith    if (ACPI_FAILURE (Status))
51971867Smsmith    {
52071867Smsmith        return_ACPI_STATUS (Status);
52171867Smsmith    }
52271867Smsmith
52371867Smsmith    /*
52477424Smsmith     * Do the actual store operation
52571867Smsmith     */
52671867Smsmith    switch (TargetType)
52771867Smsmith    {
52877424Smsmith    case ACPI_TYPE_BUFFER_FIELD:
52977424Smsmith    case INTERNAL_TYPE_REGION_FIELD:
53077424Smsmith    case INTERNAL_TYPE_BANK_FIELD:
53177424Smsmith    case INTERNAL_TYPE_INDEX_FIELD:
53271867Smsmith
53377424Smsmith        /*
53477424Smsmith         * For fields, copy the source data to the target field.
53577424Smsmith         */
53677424Smsmith        Status = AcpiExWriteDataToField (SourceDesc, TargetDesc);
53767754Smsmith        break;
53867754Smsmith
53967754Smsmith
54071867Smsmith    case ACPI_TYPE_INTEGER:
54171867Smsmith    case ACPI_TYPE_STRING:
54271867Smsmith    case ACPI_TYPE_BUFFER:
54367754Smsmith
54477424Smsmith        /*
54571867Smsmith         * These target types are all of type Integer/String/Buffer, and
54671867Smsmith         * therefore support implicit conversion before the store.
54777424Smsmith         *
54877424Smsmith         * Copy and/or convert the source object to a new target object
54967754Smsmith         */
55091116Smsmith        Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc, &NewDesc, WalkState);
55171867Smsmith        if (ACPI_FAILURE (Status))
55267754Smsmith        {
55371867Smsmith            return_ACPI_STATUS (Status);
55467754Smsmith        }
55567754Smsmith
55691116Smsmith        if (NewDesc != TargetDesc)
55791116Smsmith        {
55891116Smsmith            /*
55991116Smsmith             * Store the new NewDesc as the new value of the Name, and set
56091116Smsmith             * the Name's type to that of the value being stored in it.
56191116Smsmith             * SourceDesc reference count is incremented by AttachObject.
56291116Smsmith             */
56391116Smsmith            Status = AcpiNsAttachObject (Node, NewDesc, TargetType);
56485756Smsmith
56599146Siwasaki            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
56691116Smsmith                "Store %s into %s via Convert/Attach\n",
56799679Siwasaki                AcpiUtGetObjectTypeName (SourceDesc),
56899679Siwasaki                AcpiUtGetObjectTypeName (NewDesc)));
56991116Smsmith        }
57067754Smsmith        break;
57167754Smsmith
57277424Smsmith
57367754Smsmith    default:
57467754Smsmith
57599146Siwasaki        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
57684491Smsmith            "Storing %s (%p) directly into node (%p), no implicit conversion\n",
57799679Siwasaki            AcpiUtGetObjectTypeName (SourceDesc), SourceDesc, Node));
57884491Smsmith
57971867Smsmith        /* No conversions for all other types.  Just attach the source object */
58067754Smsmith
58199679Siwasaki        Status = AcpiNsAttachObject (Node, SourceDesc, ACPI_GET_OBJECT_TYPE (SourceDesc));
58271867Smsmith        break;
58371867Smsmith    }
58467754Smsmith
58571867Smsmith    return_ACPI_STATUS (Status);
58671867Smsmith}
58767754Smsmith
58867754Smsmith
589