exstore.c revision 138287
167754Smsmith
267754Smsmith/******************************************************************************
367754Smsmith *
477424Smsmith * Module Name: exstore - AML Interpreter object store support
5138287Smarks *              $Revision: 186 $
667754Smsmith *
767754Smsmith *****************************************************************************/
867754Smsmith
967754Smsmith/******************************************************************************
1067754Smsmith *
1167754Smsmith * 1. Copyright Notice
1267754Smsmith *
13126372Snjl * Some or all of this work - Copyright (c) 1999 - 2004, 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,
178107325Siwasaki         * Storing an object into a Named node.
17971867Smsmith         */
18085756Smsmith        Status = AcpiExStoreObjectToNode (SourceDesc,
181128212Snjl                    (ACPI_NAMESPACE_NODE *) DestDesc, WalkState,
182128212Snjl                    ACPI_IMPLICIT_CONVERSION);
18367754Smsmith
18471867Smsmith        return_ACPI_STATUS (Status);
18567754Smsmith    }
18667754Smsmith
18799679Siwasaki    /* Destination object must be a Reference or a Constant object */
18867754Smsmith
18999679Siwasaki    switch (ACPI_GET_OBJECT_TYPE (DestDesc))
190102550Siwasaki    {
191107325Siwasaki    case ACPI_TYPE_LOCAL_REFERENCE:
19299679Siwasaki        break;
19399679Siwasaki
19499679Siwasaki    case ACPI_TYPE_INTEGER:
19599679Siwasaki
19699679Siwasaki        /* Allow stores to Constants -- a Noop as per ACPI spec */
19799679Siwasaki
19899679Siwasaki        if (DestDesc->Common.Flags & AOPOBJ_AML_CONSTANT)
19999679Siwasaki        {
20099679Siwasaki            return_ACPI_STATUS (AE_OK);
20199679Siwasaki        }
20299679Siwasaki
203104470Siwasaki        /*lint -fallthrough */
20499679Siwasaki
20599679Siwasaki    default:
20699679Siwasaki
207126372Snjl        /* Destination is not a Reference object */
20867754Smsmith
20982367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
210138287Smarks            "Target is not a Reference or Constant object - %s [%p]\n",
211138287Smarks            AcpiUtGetObjectTypeName (DestDesc), DestDesc));
21267754Smsmith
21391116Smsmith        ACPI_DUMP_STACK_ENTRY (SourceDesc);
21491116Smsmith        ACPI_DUMP_STACK_ENTRY (DestDesc);
21591116Smsmith        ACPI_DUMP_OPERANDS (&DestDesc, ACPI_IMODE_EXECUTE, "ExStore",
21699679Siwasaki                        2, "Target is not a Reference or Constant object");
21767754Smsmith
21867754Smsmith        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
21967754Smsmith    }
22067754Smsmith
22177424Smsmith    /*
22271867Smsmith     * Examine the Reference opcode.  These cases are handled:
22371867Smsmith     *
22471867Smsmith     * 1) Store to Name (Change the object associated with a name)
22571867Smsmith     * 2) Store to an indexed area of a Buffer or Package
22671867Smsmith     * 3) Store to a Method Local or Arg
22771867Smsmith     * 4) Store to the debug object
22871867Smsmith     */
22977424Smsmith    switch (RefDesc->Reference.Opcode)
23067754Smsmith    {
23167754Smsmith    case AML_NAME_OP:
232100966Siwasaki    case AML_REF_OF_OP:
23367754Smsmith
23471867Smsmith        /* Storing an object into a Name "container" */
23571867Smsmith
23685756Smsmith        Status = AcpiExStoreObjectToNode (SourceDesc, RefDesc->Reference.Object,
237128212Snjl                        WalkState, ACPI_IMPLICIT_CONVERSION);
23871867Smsmith        break;
23967754Smsmith
24067754Smsmith
24167754Smsmith    case AML_INDEX_OP:
24267754Smsmith
24371867Smsmith        /* Storing to an Index (pointer into a packager or buffer) */
24467754Smsmith
24585756Smsmith        Status = AcpiExStoreObjectToIndex (SourceDesc, RefDesc, WalkState);
24671867Smsmith        break;
24771867Smsmith
24871867Smsmith
24971867Smsmith    case AML_LOCAL_OP:
25077424Smsmith    case AML_ARG_OP:
25171867Smsmith
25277424Smsmith        /* Store to a method local/arg  */
25371867Smsmith
25477424Smsmith        Status = AcpiDsStoreObjectToLocal (RefDesc->Reference.Opcode,
25585756Smsmith                        RefDesc->Reference.Offset, SourceDesc, WalkState);
25671867Smsmith        break;
25771867Smsmith
25871867Smsmith
25971867Smsmith    case AML_DEBUG_OP:
26071867Smsmith
26167754Smsmith        /*
26271867Smsmith         * Storing to the Debug object causes the value stored to be
26371867Smsmith         * displayed and otherwise has no effect -- see ACPI Specification
26467754Smsmith         */
265138287Smarks        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
266138287Smarks            "**** Write to Debug Object: Object %p %s ****:\n\n",
267138287Smarks            SourceDesc, AcpiUtGetObjectTypeName (SourceDesc)));
26877424Smsmith
26983174Smsmith        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %s: ",
270138287Smarks            AcpiUtGetObjectTypeName (SourceDesc)));
27177424Smsmith
272138287Smarks        if (!AcpiUtValidInternalObject (SourceDesc))
273138287Smarks        {
274138287Smarks           ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT,
275138287Smarks               "%p, Invalid Internal Object!\n", SourceDesc));
276138287Smarks           break;
277138287Smarks        }
278138287Smarks
27999679Siwasaki        switch (ACPI_GET_OBJECT_TYPE (SourceDesc))
28071867Smsmith        {
28177424Smsmith        case ACPI_TYPE_INTEGER:
28277424Smsmith
283138287Smarks            if (AcpiGbl_IntegerByteWidth == 4)
284138287Smarks            {
285138287Smarks                ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
286138287Smarks                    (UINT32) SourceDesc->Integer.Value));
287138287Smarks            }
288138287Smarks            else
289138287Smarks            {
290138287Smarks                ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X%8.8X\n",
291123315Snjl                    ACPI_FORMAT_UINT64 (SourceDesc->Integer.Value)));
292138287Smarks            }
29377424Smsmith            break;
29477424Smsmith
29577424Smsmith
29677424Smsmith        case ACPI_TYPE_BUFFER:
29777424Smsmith
298138287Smarks            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]",
299138287Smarks                (UINT32) SourceDesc->Buffer.Length));
300129684Snjl            ACPI_DUMP_BUFFER (SourceDesc->Buffer.Pointer,
301126372Snjl                (SourceDesc->Buffer.Length < 32) ? SourceDesc->Buffer.Length : 32);
30277424Smsmith            break;
30377424Smsmith
30477424Smsmith
30577424Smsmith        case ACPI_TYPE_STRING:
30677424Smsmith
307138287Smarks            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
308138287Smarks                SourceDesc->String.Length, SourceDesc->String.Pointer));
30977424Smsmith            break;
31077424Smsmith
31177424Smsmith
31277424Smsmith        case ACPI_TYPE_PACKAGE:
31377424Smsmith
314138287Smarks            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] Elements Ptr - %p\n",
315138287Smarks                SourceDesc->Package.Count, SourceDesc->Package.Elements));
31677424Smsmith            break;
31777424Smsmith
31877424Smsmith
31977424Smsmith        default:
32077424Smsmith
321126372Snjl            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%p\n",
322138287Smarks                SourceDesc));
32377424Smsmith            break;
32471867Smsmith        }
32567754Smsmith
32699146Siwasaki        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
32771867Smsmith        break;
32871867Smsmith
32971867Smsmith
33071867Smsmith    default:
33171867Smsmith
332126372Snjl        ACPI_REPORT_ERROR (("ExStore: Unknown Reference opcode %X\n",
33377424Smsmith            RefDesc->Reference.Opcode));
33491116Smsmith        ACPI_DUMP_ENTRY (RefDesc, ACPI_LV_ERROR);
33571867Smsmith
33671867Smsmith        Status = AE_AML_INTERNAL;
33771867Smsmith        break;
33899679Siwasaki    }
33971867Smsmith
34071867Smsmith    return_ACPI_STATUS (Status);
34171867Smsmith}
34271867Smsmith
34371867Smsmith
34471867Smsmith/*******************************************************************************
34571867Smsmith *
34677424Smsmith * FUNCTION:    AcpiExStoreObjectToIndex
34771867Smsmith *
34887031Smsmith * PARAMETERS:  *SourceDesc             - Value to be stored
34987031Smsmith *              *DestDesc               - Named object to receive the value
35087031Smsmith *              WalkState               - Current walk state
35171867Smsmith *
35271867Smsmith * RETURN:      Status
35371867Smsmith *
35487031Smsmith * DESCRIPTION: Store the object to indexed Buffer or Package element
35571867Smsmith *
35671867Smsmith ******************************************************************************/
35771867Smsmith
35871867SmsmithACPI_STATUS
35977424SmsmithAcpiExStoreObjectToIndex (
36085756Smsmith    ACPI_OPERAND_OBJECT     *SourceDesc,
36191116Smsmith    ACPI_OPERAND_OBJECT     *IndexDesc,
36271867Smsmith    ACPI_WALK_STATE         *WalkState)
36371867Smsmith{
36471867Smsmith    ACPI_STATUS             Status = AE_OK;
36571867Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
36691116Smsmith    ACPI_OPERAND_OBJECT     *NewDesc;
36771867Smsmith    UINT8                   Value = 0;
368126372Snjl    UINT32                  i;
36971867Smsmith
37071867Smsmith
37191116Smsmith    ACPI_FUNCTION_TRACE ("ExStoreObjectToIndex");
37271867Smsmith
37371867Smsmith
37471867Smsmith    /*
37571867Smsmith     * Destination must be a reference pointer, and
37671867Smsmith     * must point to either a buffer or a package
37771867Smsmith     */
37891116Smsmith    switch (IndexDesc->Reference.TargetType)
37971867Smsmith    {
38071867Smsmith    case ACPI_TYPE_PACKAGE:
38171867Smsmith        /*
382138287Smarks         * Storing to a package element. Copy the object and replace
383138287Smarks         * any existing object with the new object. No implicit
384138287Smarks         * conversion is performed.
385138287Smarks         *
38691116Smsmith         * The object at *(IndexDesc->Reference.Where) is the
38791116Smsmith         * element within the package that is to be modified.
388126372Snjl         * The parent package object is at IndexDesc->Reference.Object
38991116Smsmith         */
39091116Smsmith        ObjDesc = *(IndexDesc->Reference.Where);
39185756Smsmith
392138287Smarks        Status = AcpiUtCopyIobjectToIobject (SourceDesc, &NewDesc, WalkState);
39391116Smsmith        if (ACPI_FAILURE (Status))
39491116Smsmith        {
39591116Smsmith            return_ACPI_STATUS (Status);
39691116Smsmith        }
39767754Smsmith
398138287Smarks        if (ObjDesc)
39991116Smsmith        {
400138287Smarks            /* Decrement reference count by the ref count of the parent package */
401104470Siwasaki
402138287Smarks            for (i = 0; i < ((ACPI_OPERAND_OBJECT *) IndexDesc->Reference.Object)->Common.ReferenceCount; i++)
403104470Siwasaki            {
404138287Smarks                AcpiUtRemoveReference (ObjDesc);
405104470Siwasaki            }
406138287Smarks        }
407138287Smarks
408138287Smarks        *(IndexDesc->Reference.Where) = NewDesc;
409126372Snjl
410138287Smarks        /* Increment reference count by the ref count of the parent package -1 */
411126372Snjl
412138287Smarks        for (i = 1; i < ((ACPI_OPERAND_OBJECT *) IndexDesc->Reference.Object)->Common.ReferenceCount; i++)
413138287Smarks        {
414138287Smarks            AcpiUtAddReference (NewDesc);
41567754Smsmith        }
416138287Smarks
41771867Smsmith        break;
41867754Smsmith
41967754Smsmith
42071867Smsmith    case ACPI_TYPE_BUFFER_FIELD:
42177424Smsmith
42267754Smsmith        /*
423138287Smarks         * Store into a Buffer or String (not actually a real BufferField)
424138287Smarks         * at a location defined by an Index.
42567754Smsmith         *
42687031Smsmith         * The first 8-bit element of the source object is written to the
42787031Smsmith         * 8-bit Buffer location defined by the Index destination object,
42887031Smsmith         * according to the ACPI 2.0 specification.
42967754Smsmith         */
43067754Smsmith
43167754Smsmith        /*
432138287Smarks         * Make sure the target is a Buffer or String. An error should
433138287Smarks         * not happen here, since the ReferenceObject was constructed
434138287Smarks         * by the INDEX_OP code.
43567754Smsmith         */
43691116Smsmith        ObjDesc = IndexDesc->Reference.Object;
437138287Smarks        if ((ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_BUFFER) &&
438138287Smarks            (ACPI_GET_OBJECT_TYPE (ObjDesc) != ACPI_TYPE_STRING))
43967754Smsmith        {
44071867Smsmith            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
44167754Smsmith        }
44267754Smsmith
44367754Smsmith        /*
44467754Smsmith         * The assignment of the individual elements will be slightly
44567754Smsmith         * different for each source type.
44667754Smsmith         */
44799679Siwasaki        switch (ACPI_GET_OBJECT_TYPE (SourceDesc))
44867754Smsmith        {
44971867Smsmith        case ACPI_TYPE_INTEGER:
45087031Smsmith
45187031Smsmith            /* Use the least-significant byte of the integer */
45287031Smsmith
45387031Smsmith            Value = (UINT8) (SourceDesc->Integer.Value);
45467754Smsmith            break;
45567754Smsmith
45687031Smsmith        case ACPI_TYPE_BUFFER:
457138287Smarks        case ACPI_TYPE_STRING:
45877424Smsmith
459138287Smarks            /* Note: Takes advantage of common string/buffer fields */
460138287Smarks
46187031Smsmith            Value = SourceDesc->Buffer.Pointer[0];
46267754Smsmith            break;
46367754Smsmith
46467754Smsmith        default:
46577424Smsmith
46687031Smsmith            /* All other types are invalid */
46777424Smsmith
46882367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
46987031Smsmith                "Source must be Integer/Buffer/String type, not %s\n",
47099679Siwasaki                AcpiUtGetObjectTypeName (SourceDesc)));
47187031Smsmith            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
47267754Smsmith        }
47387031Smsmith
47487031Smsmith        /* Store the source value into the target buffer byte */
47587031Smsmith
47691116Smsmith        ObjDesc->Buffer.Pointer[IndexDesc->Reference.Offset] = Value;
47771867Smsmith        break;
47867754Smsmith
47967754Smsmith
48071867Smsmith    default:
48191116Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
48287031Smsmith            "Target is not a Package or BufferField\n"));
48371867Smsmith        Status = AE_AML_OPERAND_TYPE;
48467754Smsmith        break;
48571867Smsmith    }
48667754Smsmith
48771867Smsmith    return_ACPI_STATUS (Status);
48871867Smsmith}
48967754Smsmith
49067754Smsmith
49171867Smsmith/*******************************************************************************
49271867Smsmith *
49377424Smsmith * FUNCTION:    AcpiExStoreObjectToNode
49471867Smsmith *
49587031Smsmith * PARAMETERS:  SourceDesc              - Value to be stored
49687031Smsmith *              Node                    - Named object to receive the value
49787031Smsmith *              WalkState               - Current walk state
498128212Snjl *              ImplicitConversion      - Perform implicit conversion (yes/no)
49971867Smsmith *
50071867Smsmith * RETURN:      Status
50171867Smsmith *
50271867Smsmith * DESCRIPTION: Store the object to the named object.
50371867Smsmith *
50471867Smsmith *              The Assignment of an object to a named object is handled here
50587031Smsmith *              The value passed in will replace the current value (if any)
50671867Smsmith *              with the input value.
50771867Smsmith *
50871867Smsmith *              When storing into an object the data is converted to the
50971867Smsmith *              target object type then stored in the object.  This means
51071867Smsmith *              that the target object type (for an initialized target) will
51171867Smsmith *              not be changed by a store operation.
51271867Smsmith *
51387031Smsmith *              Assumes parameters are already validated.
51471867Smsmith *
51571867Smsmith ******************************************************************************/
51667754Smsmith
51771867SmsmithACPI_STATUS
51877424SmsmithAcpiExStoreObjectToNode (
51971867Smsmith    ACPI_OPERAND_OBJECT     *SourceDesc,
52071867Smsmith    ACPI_NAMESPACE_NODE     *Node,
521128212Snjl    ACPI_WALK_STATE         *WalkState,
522128212Snjl    UINT8                   ImplicitConversion)
52371867Smsmith{
52471867Smsmith    ACPI_STATUS             Status = AE_OK;
52571867Smsmith    ACPI_OPERAND_OBJECT     *TargetDesc;
52691116Smsmith    ACPI_OPERAND_OBJECT     *NewDesc;
52791116Smsmith    ACPI_OBJECT_TYPE        TargetType;
52867754Smsmith
52971867Smsmith
53091116Smsmith    ACPI_FUNCTION_TRACE_PTR ("ExStoreObjectToNode", SourceDesc);
53171867Smsmith
53283174Smsmith
53371867Smsmith    /*
53471867Smsmith     * Get current type of the node, and object attached to Node
53571867Smsmith     */
53671867Smsmith    TargetType = AcpiNsGetType (Node);
53771867Smsmith    TargetDesc = AcpiNsGetAttachedObject (Node);
53871867Smsmith
53999146Siwasaki    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
54099679Siwasaki        SourceDesc, AcpiUtGetObjectTypeName (SourceDesc),
54191116Smsmith              Node, AcpiUtGetTypeName (TargetType)));
54271867Smsmith
54371867Smsmith    /*
54471867Smsmith     * Resolve the source object to an actual value
54577424Smsmith     * (If it is a reference object)
54671867Smsmith     */
54777424Smsmith    Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState);
54871867Smsmith    if (ACPI_FAILURE (Status))
54971867Smsmith    {
55071867Smsmith        return_ACPI_STATUS (Status);
55171867Smsmith    }
55271867Smsmith
553128212Snjl    /* If no implicit conversion, drop into the default case below */
554128212Snjl
555128212Snjl    if (!ImplicitConversion)
556128212Snjl    {
557128212Snjl        /* Force execution of default (no implicit conversion) */
558128212Snjl
559128212Snjl        TargetType = ACPI_TYPE_ANY;
560128212Snjl    }
561128212Snjl
56271867Smsmith    /*
56377424Smsmith     * Do the actual store operation
56471867Smsmith     */
56571867Smsmith    switch (TargetType)
56671867Smsmith    {
56777424Smsmith    case ACPI_TYPE_BUFFER_FIELD:
568107325Siwasaki    case ACPI_TYPE_LOCAL_REGION_FIELD:
569107325Siwasaki    case ACPI_TYPE_LOCAL_BANK_FIELD:
570107325Siwasaki    case ACPI_TYPE_LOCAL_INDEX_FIELD:
57171867Smsmith
57277424Smsmith        /*
57377424Smsmith         * For fields, copy the source data to the target field.
57477424Smsmith         */
575107325Siwasaki        Status = AcpiExWriteDataToField (SourceDesc, TargetDesc, &WalkState->ResultObj);
57667754Smsmith        break;
57767754Smsmith
57867754Smsmith
57971867Smsmith    case ACPI_TYPE_INTEGER:
58071867Smsmith    case ACPI_TYPE_STRING:
58171867Smsmith    case ACPI_TYPE_BUFFER:
58267754Smsmith
58377424Smsmith        /*
58471867Smsmith         * These target types are all of type Integer/String/Buffer, and
58571867Smsmith         * therefore support implicit conversion before the store.
58677424Smsmith         *
58777424Smsmith         * Copy and/or convert the source object to a new target object
58867754Smsmith         */
58991116Smsmith        Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc, &NewDesc, WalkState);
59071867Smsmith        if (ACPI_FAILURE (Status))
59167754Smsmith        {
59271867Smsmith            return_ACPI_STATUS (Status);
59367754Smsmith        }
59467754Smsmith
59591116Smsmith        if (NewDesc != TargetDesc)
59691116Smsmith        {
59791116Smsmith            /*
59891116Smsmith             * Store the new NewDesc as the new value of the Name, and set
59991116Smsmith             * the Name's type to that of the value being stored in it.
60091116Smsmith             * SourceDesc reference count is incremented by AttachObject.
601104470Siwasaki             *
602104470Siwasaki             * Note: This may change the type of the node if an explicit store
603104470Siwasaki             * has been performed such that the node/object type has been
604104470Siwasaki             * changed.
60591116Smsmith             */
606104470Siwasaki            Status = AcpiNsAttachObject (Node, NewDesc, NewDesc->Common.Type);
60785756Smsmith
60899146Siwasaki            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
60991116Smsmith                "Store %s into %s via Convert/Attach\n",
61099679Siwasaki                AcpiUtGetObjectTypeName (SourceDesc),
61199679Siwasaki                AcpiUtGetObjectTypeName (NewDesc)));
61291116Smsmith        }
61367754Smsmith        break;
61467754Smsmith
61577424Smsmith
61667754Smsmith    default:
61767754Smsmith
61899146Siwasaki        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
61984491Smsmith            "Storing %s (%p) directly into node (%p), no implicit conversion\n",
62099679Siwasaki            AcpiUtGetObjectTypeName (SourceDesc), SourceDesc, Node));
62184491Smsmith
62271867Smsmith        /* No conversions for all other types.  Just attach the source object */
62367754Smsmith
62499679Siwasaki        Status = AcpiNsAttachObject (Node, SourceDesc, ACPI_GET_OBJECT_TYPE (SourceDesc));
62571867Smsmith        break;
62671867Smsmith    }
62767754Smsmith
62871867Smsmith    return_ACPI_STATUS (Status);
62971867Smsmith}
63067754Smsmith
63167754Smsmith
632