dsmthdat.c revision 91116
167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: dsmthdat - control method arguments and local variables
491116Smsmith *              $Revision: 58 $
567754Smsmith *
667754Smsmith ******************************************************************************/
767754Smsmith
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
1291116Smsmith * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
1370243Smsmith * All rights reserved.
1467754Smsmith *
1567754Smsmith * 2. License
1667754Smsmith *
1767754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
1867754Smsmith * rights.  You may have additional license terms from the party that provided
1967754Smsmith * you this software, covering your right to use that party's intellectual
2067754Smsmith * property rights.
2167754Smsmith *
2267754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2367754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2467754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2567754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2667754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2767754Smsmith * Code in any form, with the right to sublicense such rights; and
2867754Smsmith *
2967754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3067754Smsmith * license (with the right to sublicense), under only those claims of Intel
3167754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3267754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3367754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3467754Smsmith * license, and in no event shall the patent license extend to any additions
3567754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3667754Smsmith * is granted directly or by implication, estoppel or otherwise;
3767754Smsmith *
3867754Smsmith * The above copyright and patent license is granted only if the following
3967754Smsmith * conditions are met:
4067754Smsmith *
4167754Smsmith * 3. Conditions
4267754Smsmith *
4367754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4467754Smsmith * Redistribution of source code of any substantial portion of the Covered
4567754Smsmith * Code or modification with rights to further distribute source must include
4667754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4767754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
4867754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
4967754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5067754Smsmith * Code and the date of any change.  Licensee must include in that file the
5167754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5267754Smsmith * must include a prominent statement that the modification is derived,
5367754Smsmith * directly or indirectly, from Original Intel Code.
5467754Smsmith *
5567754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5667754Smsmith * Redistribution of source code of any substantial portion of the Covered
5767754Smsmith * Code or modification without rights to further distribute source must
5867754Smsmith * include the following Disclaimer and Export Compliance provision in the
5967754Smsmith * documentation and/or other materials provided with distribution.  In
6067754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6167754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6267754Smsmith * license from Licensee to its licensee is limited to the intellectual
6367754Smsmith * property embodied in the software Licensee provides to its licensee, and
6467754Smsmith * not to intellectual property embodied in modifications its licensee may
6567754Smsmith * make.
6667754Smsmith *
6767754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
6867754Smsmith * substantial portion of the Covered Code or modification must reproduce the
6967754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7067754Smsmith * provision in the documentation and/or other materials provided with the
7167754Smsmith * distribution.
7267754Smsmith *
7367754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7467754Smsmith * Intel Code.
7567754Smsmith *
7667754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7767754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
7867754Smsmith * other dealings in products derived from or relating to the Covered Code
7967754Smsmith * without prior written authorization from Intel.
8067754Smsmith *
8167754Smsmith * 4. Disclaimer and Export Compliance
8267754Smsmith *
8367754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8467754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8567754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8667754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8767754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8867754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8967754Smsmith * PARTICULAR PURPOSE.
9067754Smsmith *
9167754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9267754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9367754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9467754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9567754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9667754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9767754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9867754Smsmith * LIMITED REMEDY.
9967754Smsmith *
10067754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10167754Smsmith * software or system incorporating such software without first obtaining any
10267754Smsmith * required license or other approval from the U. S. Department of Commerce or
10367754Smsmith * any other agency or department of the United States Government.  In the
10467754Smsmith * event Licensee exports any such software from the United States or
10567754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10667754Smsmith * ensure that the distribution and export/re-export of the software is in
10767754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10867754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10967754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11067754Smsmith * software, or service, directly or indirectly, to any country for which the
11167754Smsmith * United States government or any agency thereof requires an export license,
11267754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11367754Smsmith * such license, approval or letter.
11467754Smsmith *
11567754Smsmith *****************************************************************************/
11667754Smsmith
11767754Smsmith#define __DSMTHDAT_C__
11867754Smsmith
11967754Smsmith#include "acpi.h"
12067754Smsmith#include "acparser.h"
12167754Smsmith#include "acdispat.h"
12267754Smsmith#include "acinterp.h"
12367754Smsmith#include "amlcode.h"
12467754Smsmith#include "acnamesp.h"
12567754Smsmith
12667754Smsmith
12777424Smsmith#define _COMPONENT          ACPI_DISPATCHER
12891116Smsmith        ACPI_MODULE_NAME    ("dsmthdat")
12967754Smsmith
13067754Smsmith
13167754Smsmith/*******************************************************************************
13267754Smsmith *
13367754Smsmith * FUNCTION:    AcpiDsMethodDataInit
13467754Smsmith *
13571867Smsmith * PARAMETERS:  WalkState           - Current walk state object
13667754Smsmith *
13767754Smsmith * RETURN:      Status
13867754Smsmith *
13967754Smsmith * DESCRIPTION: Initialize the data structures that hold the method's arguments
14067754Smsmith *              and locals.  The data struct is an array of NTEs for each.
14167754Smsmith *              This allows RefOf and DeRefOf to work properly for these
14267754Smsmith *              special data types.
14367754Smsmith *
14487031Smsmith * NOTES:       WalkState fields are initialized to zero by the
14587031Smsmith *              ACPI_MEM_CALLOCATE().
14687031Smsmith *
14787031Smsmith *              A pseudo-Namespace Node is assigned to each argument and local
14887031Smsmith *              so that RefOf() can return a pointer to the Node.
14987031Smsmith *
15067754Smsmith ******************************************************************************/
15167754Smsmith
15267754SmsmithACPI_STATUS
15367754SmsmithAcpiDsMethodDataInit (
15467754Smsmith    ACPI_WALK_STATE         *WalkState)
15567754Smsmith{
15667754Smsmith    UINT32                  i;
15767754Smsmith
15867754Smsmith
15991116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataInit");
16067754Smsmith
16167754Smsmith
16267754Smsmith    /* Init the method arguments */
16367754Smsmith
16467754Smsmith    for (i = 0; i < MTH_NUM_ARGS; i++)
16567754Smsmith    {
16691116Smsmith        ACPI_MOVE_UNALIGNED32_TO_32 (&WalkState->Arguments[i].Name,
16767754Smsmith                                NAMEOF_ARG_NTE);
16891116Smsmith        WalkState->Arguments[i].Name      |= (i << 24);
16991116Smsmith        WalkState->Arguments[i].Descriptor = ACPI_DESC_TYPE_NAMED;
17091116Smsmith        WalkState->Arguments[i].Type       = ACPI_TYPE_ANY;
17191116Smsmith        WalkState->Arguments[i].Flags      = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG;
17267754Smsmith    }
17367754Smsmith
17467754Smsmith    /* Init the method locals */
17567754Smsmith
17667754Smsmith    for (i = 0; i < MTH_NUM_LOCALS; i++)
17767754Smsmith    {
17891116Smsmith        ACPI_MOVE_UNALIGNED32_TO_32 (&WalkState->LocalVariables[i].Name,
17967754Smsmith                                NAMEOF_LOCAL_NTE);
18067754Smsmith
18191116Smsmith        WalkState->LocalVariables[i].Name      |= (i << 24);
18291116Smsmith        WalkState->LocalVariables[i].Descriptor = ACPI_DESC_TYPE_NAMED;
18391116Smsmith        WalkState->LocalVariables[i].Type       = ACPI_TYPE_ANY;
18491116Smsmith        WalkState->LocalVariables[i].Flags      = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL;
18567754Smsmith    }
18667754Smsmith
18767754Smsmith    return_ACPI_STATUS (AE_OK);
18867754Smsmith}
18967754Smsmith
19067754Smsmith
19167754Smsmith/*******************************************************************************
19267754Smsmith *
19367754Smsmith * FUNCTION:    AcpiDsMethodDataDeleteAll
19467754Smsmith *
19571867Smsmith * PARAMETERS:  WalkState           - Current walk state object
19667754Smsmith *
19767754Smsmith * RETURN:      Status
19867754Smsmith *
19967754Smsmith * DESCRIPTION: Delete method locals and arguments.  Arguments are only
20067754Smsmith *              deleted if this method was called from another method.
20167754Smsmith *
20267754Smsmith ******************************************************************************/
20367754Smsmith
20467754SmsmithACPI_STATUS
20567754SmsmithAcpiDsMethodDataDeleteAll (
20667754Smsmith    ACPI_WALK_STATE         *WalkState)
20767754Smsmith{
20867754Smsmith    UINT32                  Index;
20967754Smsmith
21067754Smsmith
21191116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataDeleteAll");
21267754Smsmith
21367754Smsmith
21487031Smsmith    /* Detach the locals */
21567754Smsmith
21667754Smsmith    for (Index = 0; Index < MTH_NUM_LOCALS; Index++)
21767754Smsmith    {
21887031Smsmith        if (WalkState->LocalVariables[Index].Object)
21967754Smsmith        {
22087031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%d=%p\n",
22187031Smsmith                    Index, WalkState->LocalVariables[Index].Object));
22267754Smsmith
22387031Smsmith            /* Detach object (if present) and remove a reference */
22467754Smsmith
22587031Smsmith            AcpiNsDetachObject (&WalkState->LocalVariables[Index]);
22667754Smsmith       }
22767754Smsmith    }
22867754Smsmith
22987031Smsmith    /* Detach the arguments */
23067754Smsmith
23167754Smsmith    for (Index = 0; Index < MTH_NUM_ARGS; Index++)
23267754Smsmith    {
23387031Smsmith        if (WalkState->Arguments[Index].Object)
23467754Smsmith        {
23587031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%d=%p\n",
23687031Smsmith                    Index, WalkState->Arguments[Index].Object));
23767754Smsmith
23887031Smsmith            /* Detach object (if present) and remove a reference */
23967754Smsmith
24087031Smsmith            AcpiNsDetachObject (&WalkState->Arguments[Index]);
24167754Smsmith        }
24267754Smsmith    }
24367754Smsmith
24467754Smsmith    return_ACPI_STATUS (AE_OK);
24567754Smsmith}
24667754Smsmith
24767754Smsmith
24867754Smsmith/*******************************************************************************
24967754Smsmith *
25067754Smsmith * FUNCTION:    AcpiDsMethodDataInitArgs
25167754Smsmith *
25271867Smsmith * PARAMETERS:  *Params         - Pointer to a parameter list for the method
25371867Smsmith *              MaxParamCount   - The arg count for this method
25471867Smsmith *              WalkState       - Current walk state object
25567754Smsmith *
25667754Smsmith * RETURN:      Status
25767754Smsmith *
25887031Smsmith * DESCRIPTION: Initialize arguments for a method.  The parameter list is a list
25987031Smsmith *              of ACPI operand objects, either null terminated or whose length
26087031Smsmith *              is defined by MaxParamCount.
26167754Smsmith *
26267754Smsmith ******************************************************************************/
26367754Smsmith
26467754SmsmithACPI_STATUS
26567754SmsmithAcpiDsMethodDataInitArgs (
26667754Smsmith    ACPI_OPERAND_OBJECT     **Params,
26767754Smsmith    UINT32                  MaxParamCount,
26867754Smsmith    ACPI_WALK_STATE         *WalkState)
26967754Smsmith{
27067754Smsmith    ACPI_STATUS             Status;
27187031Smsmith    UINT32                  Index = 0;
27267754Smsmith
27367754Smsmith
27491116Smsmith    ACPI_FUNCTION_TRACE_PTR ("DsMethodDataInitArgs", Params);
27567754Smsmith
27667754Smsmith
27767754Smsmith    if (!Params)
27867754Smsmith    {
27982367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "No param list passed to method\n"));
28067754Smsmith        return_ACPI_STATUS (AE_OK);
28167754Smsmith    }
28267754Smsmith
28367754Smsmith    /* Copy passed parameters into the new method stack frame  */
28467754Smsmith
28587031Smsmith    while ((Index < MTH_NUM_ARGS) && (Index < MaxParamCount) && Params[Index])
28667754Smsmith    {
28787031Smsmith        /*
28887031Smsmith         * A valid parameter.
28987031Smsmith         * Store the argument in the method/walk descriptor
29087031Smsmith         */
29187031Smsmith        Status = AcpiDsStoreObjectToLocal (AML_ARG_OP, Index, Params[Index],
29287031Smsmith                                            WalkState);
29387031Smsmith        if (ACPI_FAILURE (Status))
29467754Smsmith        {
29587031Smsmith            return_ACPI_STATUS (Status);
29667754Smsmith        }
29767754Smsmith
29887031Smsmith        Index++;
29967754Smsmith    }
30067754Smsmith
30187031Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%d args passed to method\n", Index));
30267754Smsmith    return_ACPI_STATUS (AE_OK);
30367754Smsmith}
30467754Smsmith
30567754Smsmith
30667754Smsmith/*******************************************************************************
30767754Smsmith *
30887031Smsmith * FUNCTION:    AcpiDsMethodDataGetNode
30967754Smsmith *
31077424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
31187031Smsmith *              Index               - Which localVar or argument whose type
31287031Smsmith *                                      to get
31371867Smsmith *              WalkState           - Current walk state object
31467754Smsmith *
31587031Smsmith * RETURN:      Get the Node associated with a local or arg.
31667754Smsmith *
31767754Smsmith ******************************************************************************/
31867754Smsmith
31967754SmsmithACPI_STATUS
32087031SmsmithAcpiDsMethodDataGetNode (
32177424Smsmith    UINT16                  Opcode,
32267754Smsmith    UINT32                  Index,
32367754Smsmith    ACPI_WALK_STATE         *WalkState,
32487031Smsmith    ACPI_NAMESPACE_NODE     **Node)
32567754Smsmith{
32691116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataGetNode");
32767754Smsmith
32867754Smsmith
32967754Smsmith    /*
33087031Smsmith     * Method Locals and Arguments are supported
33167754Smsmith     */
33277424Smsmith    switch (Opcode)
33367754Smsmith    {
33477424Smsmith    case AML_LOCAL_OP:
33567754Smsmith
33667754Smsmith        if (Index > MTH_MAX_LOCAL)
33767754Smsmith        {
33887031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Local index %d is invalid (max %d)\n",
33967754Smsmith                Index, MTH_MAX_LOCAL));
34087031Smsmith            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
34167754Smsmith        }
34267754Smsmith
34387031Smsmith        /* Return a pointer to the pseudo-node */
34487031Smsmith
34587031Smsmith        *Node = &WalkState->LocalVariables[Index];
34667754Smsmith        break;
34767754Smsmith
34877424Smsmith    case AML_ARG_OP:
34967754Smsmith
35067754Smsmith        if (Index > MTH_MAX_ARG)
35167754Smsmith        {
35282367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Arg index %d is invalid (max %d)\n",
35367754Smsmith                Index, MTH_MAX_ARG));
35487031Smsmith            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
35567754Smsmith        }
35667754Smsmith
35787031Smsmith        /* Return a pointer to the pseudo-node */
35887031Smsmith
35987031Smsmith        *Node = &WalkState->Arguments[Index];
36067754Smsmith        break;
36167754Smsmith
36267754Smsmith    default:
36382367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Opcode %d is invalid\n", Opcode));
36487031Smsmith        return_ACPI_STATUS (AE_AML_BAD_OPCODE);
36567754Smsmith    }
36667754Smsmith
36767754Smsmith    return_ACPI_STATUS (AE_OK);
36867754Smsmith}
36967754Smsmith
37067754Smsmith
37167754Smsmith/*******************************************************************************
37267754Smsmith *
37387031Smsmith * FUNCTION:    AcpiDsMethodDataSetValue
37467754Smsmith *
37577424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
37667754Smsmith *              Index               - Which localVar or argument to get
37767754Smsmith *              Object              - Object to be inserted into the stack entry
37871867Smsmith *              WalkState           - Current walk state object
37967754Smsmith *
38067754Smsmith * RETURN:      Status
38167754Smsmith *
38277424Smsmith * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
38367754Smsmith *
38467754Smsmith ******************************************************************************/
38567754Smsmith
38667754SmsmithACPI_STATUS
38787031SmsmithAcpiDsMethodDataSetValue (
38877424Smsmith    UINT16                  Opcode,
38967754Smsmith    UINT32                  Index,
39067754Smsmith    ACPI_OPERAND_OBJECT     *Object,
39167754Smsmith    ACPI_WALK_STATE         *WalkState)
39267754Smsmith{
39367754Smsmith    ACPI_STATUS             Status;
39487031Smsmith    ACPI_NAMESPACE_NODE     *Node;
39567754Smsmith
39667754Smsmith
39791116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataSetValue");
39867754Smsmith
39983174Smsmith
40087031Smsmith    /* Get the namespace node for the arg/local */
40167754Smsmith
40287031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
40367754Smsmith    if (ACPI_FAILURE (Status))
40467754Smsmith    {
40567754Smsmith        return_ACPI_STATUS (Status);
40667754Smsmith    }
40767754Smsmith
40867754Smsmith    /* Increment ref count so object can't be deleted while installed */
40967754Smsmith
41077424Smsmith    AcpiUtAddReference (Object);
41167754Smsmith
41267754Smsmith    /* Install the object into the stack entry */
41367754Smsmith
41487031Smsmith    Node->Object = Object;
41567754Smsmith    return_ACPI_STATUS (AE_OK);
41667754Smsmith}
41767754Smsmith
41867754Smsmith
41967754Smsmith/*******************************************************************************
42067754Smsmith *
42167754Smsmith * FUNCTION:    AcpiDsMethodDataGetType
42267754Smsmith *
42377424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
42467754Smsmith *              Index               - Which localVar or argument whose type
42567754Smsmith *                                      to get
42671867Smsmith *              WalkState           - Current walk state object
42767754Smsmith *
42887031Smsmith * RETURN:      Data type of current value of the selected Arg or Local
42967754Smsmith *
43067754Smsmith ******************************************************************************/
43167754Smsmith
43291116SmsmithACPI_OBJECT_TYPE
43367754SmsmithAcpiDsMethodDataGetType (
43477424Smsmith    UINT16                  Opcode,
43567754Smsmith    UINT32                  Index,
43667754Smsmith    ACPI_WALK_STATE         *WalkState)
43767754Smsmith{
43867754Smsmith    ACPI_STATUS             Status;
43987031Smsmith    ACPI_NAMESPACE_NODE     *Node;
44067754Smsmith    ACPI_OPERAND_OBJECT     *Object;
44167754Smsmith
44267754Smsmith
44391116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataGetType");
44467754Smsmith
44567754Smsmith
44687031Smsmith    /* Get the namespace node for the arg/local */
44767754Smsmith
44887031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
44967754Smsmith    if (ACPI_FAILURE (Status))
45067754Smsmith    {
45167754Smsmith        return_VALUE ((ACPI_TYPE_NOT_FOUND));
45267754Smsmith    }
45367754Smsmith
45487031Smsmith    /* Get the object */
45567754Smsmith
45687031Smsmith    Object = AcpiNsGetAttachedObject (Node);
45767754Smsmith    if (!Object)
45867754Smsmith    {
45987031Smsmith        /* Uninitialized local/arg, return TYPE_ANY */
46087031Smsmith
46167754Smsmith        return_VALUE (ACPI_TYPE_ANY);
46267754Smsmith    }
46367754Smsmith
46487031Smsmith    /* Get the object type */
46587031Smsmith
46667754Smsmith    return_VALUE (Object->Common.Type);
46767754Smsmith}
46867754Smsmith
46967754Smsmith
47067754Smsmith/*******************************************************************************
47167754Smsmith *
47267754Smsmith * FUNCTION:    AcpiDsMethodDataGetValue
47367754Smsmith *
47477424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
47567754Smsmith *              Index               - Which localVar or argument to get
47671867Smsmith *              WalkState           - Current walk state object
47771867Smsmith *              *DestDesc           - Ptr to Descriptor into which selected Arg
47867754Smsmith *                                    or Local value should be copied
47967754Smsmith *
48067754Smsmith * RETURN:      Status
48167754Smsmith *
48267754Smsmith * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame
48367754Smsmith *              at the current top of the method stack.
48477424Smsmith *              Used only in AcpiExResolveToValue().
48567754Smsmith *
48667754Smsmith ******************************************************************************/
48767754Smsmith
48867754SmsmithACPI_STATUS
48967754SmsmithAcpiDsMethodDataGetValue (
49077424Smsmith    UINT16                  Opcode,
49167754Smsmith    UINT32                  Index,
49267754Smsmith    ACPI_WALK_STATE         *WalkState,
49367754Smsmith    ACPI_OPERAND_OBJECT     **DestDesc)
49467754Smsmith{
49567754Smsmith    ACPI_STATUS             Status;
49687031Smsmith    ACPI_NAMESPACE_NODE     *Node;
49767754Smsmith    ACPI_OPERAND_OBJECT     *Object;
49867754Smsmith
49967754Smsmith
50091116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataGetValue");
50167754Smsmith
50267754Smsmith
50367754Smsmith    /* Validate the object descriptor */
50467754Smsmith
50567754Smsmith    if (!DestDesc)
50667754Smsmith    {
50782367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null object descriptor pointer\n"));
50867754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
50967754Smsmith    }
51067754Smsmith
51187031Smsmith    /* Get the namespace node for the arg/local */
51267754Smsmith
51387031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
51467754Smsmith    if (ACPI_FAILURE (Status))
51567754Smsmith    {
51667754Smsmith        return_ACPI_STATUS (Status);
51767754Smsmith    }
51867754Smsmith
51987031Smsmith    /* Get the object from the node */
52067754Smsmith
52187031Smsmith    Object = Node->Object;
52267754Smsmith
52367754Smsmith    /* Examine the returned object, it must be valid. */
52467754Smsmith
52567754Smsmith    if (!Object)
52667754Smsmith    {
52767754Smsmith        /*
52887031Smsmith         * Index points to uninitialized object.
52967754Smsmith         * This means that either 1) The expected argument was
53067754Smsmith         * not passed to the method, or 2) A local variable
53167754Smsmith         * was referenced by the method (via the ASL)
53267754Smsmith         * before it was initialized.  Either case is an error.
53367754Smsmith         */
53477424Smsmith        switch (Opcode)
53567754Smsmith        {
53677424Smsmith        case AML_ARG_OP:
53771867Smsmith
53887031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Arg[%d] at node %p\n",
53987031Smsmith                Index, Node));
54071867Smsmith
54167754Smsmith            return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
54267754Smsmith
54377424Smsmith        case AML_LOCAL_OP:
54471867Smsmith
54587031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Local[%d] at node %p\n",
54687031Smsmith                Index, Node));
54771867Smsmith
54867754Smsmith            return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
54967754Smsmith        }
55067754Smsmith    }
55167754Smsmith
55267754Smsmith    /*
55387031Smsmith     * The Index points to an initialized and valid object.
55467754Smsmith     * Return an additional reference to the object
55567754Smsmith     */
55667754Smsmith    *DestDesc = Object;
55777424Smsmith    AcpiUtAddReference (Object);
55867754Smsmith
55967754Smsmith    return_ACPI_STATUS (AE_OK);
56067754Smsmith}
56167754Smsmith
56267754Smsmith
56367754Smsmith/*******************************************************************************
56467754Smsmith *
56567754Smsmith * FUNCTION:    AcpiDsMethodDataDeleteValue
56667754Smsmith *
56777424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
56867754Smsmith *              Index               - Which localVar or argument to delete
56971867Smsmith *              WalkState           - Current walk state object
57067754Smsmith *
57167754Smsmith * RETURN:      Status
57267754Smsmith *
57377424Smsmith * DESCRIPTION: Delete the entry at Opcode:Index on the method stack.  Inserts
57467754Smsmith *              a null into the stack slot after the object is deleted.
57567754Smsmith *
57667754Smsmith ******************************************************************************/
57767754Smsmith
57867754SmsmithACPI_STATUS
57967754SmsmithAcpiDsMethodDataDeleteValue (
58077424Smsmith    UINT16                  Opcode,
58167754Smsmith    UINT32                  Index,
58267754Smsmith    ACPI_WALK_STATE         *WalkState)
58367754Smsmith{
58467754Smsmith    ACPI_STATUS             Status;
58587031Smsmith    ACPI_NAMESPACE_NODE     *Node;
58667754Smsmith    ACPI_OPERAND_OBJECT     *Object;
58767754Smsmith
58867754Smsmith
58991116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataDeleteValue");
59067754Smsmith
59167754Smsmith
59287031Smsmith    /* Get the namespace node for the arg/local */
59367754Smsmith
59487031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
59567754Smsmith    if (ACPI_FAILURE (Status))
59667754Smsmith    {
59767754Smsmith        return_ACPI_STATUS (Status);
59867754Smsmith    }
59967754Smsmith
60087031Smsmith    /* Get the associated object */
60167754Smsmith
60287031Smsmith    Object = AcpiNsGetAttachedObject (Node);
60367754Smsmith
60467754Smsmith    /*
60567754Smsmith     * Undefine the Arg or Local by setting its descriptor
60667754Smsmith     * pointer to NULL. Locals/Args can contain both
60767754Smsmith     * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
60867754Smsmith     */
60987031Smsmith    Node->Object = NULL;
61067754Smsmith
61167754Smsmith    if ((Object) &&
61291116Smsmith        (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_INTERNAL))
61367754Smsmith    {
61467754Smsmith        /*
61587031Smsmith         * There is a valid object.
61667754Smsmith         * Decrement the reference count by one to balance the
61787031Smsmith         * increment when the object was stored.
61867754Smsmith         */
61977424Smsmith        AcpiUtRemoveReference (Object);
62067754Smsmith    }
62167754Smsmith
62267754Smsmith    return_ACPI_STATUS (AE_OK);
62367754Smsmith}
62467754Smsmith
62567754Smsmith
62667754Smsmith/*******************************************************************************
62767754Smsmith *
62877424Smsmith * FUNCTION:    AcpiDsStoreObjectToLocal
62967754Smsmith *
63077424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
63167754Smsmith *              Index               - Which localVar or argument to set
63287031Smsmith *              ObjDesc             - Value to be stored
63371867Smsmith *              WalkState           - Current walk state
63467754Smsmith *
63567754Smsmith * RETURN:      Status
63667754Smsmith *
63787031Smsmith * DESCRIPTION: Store a value in an Arg or Local.  The ObjDesc is installed
63867754Smsmith *              as the new value for the Arg or Local and the reference count
63987031Smsmith *              for ObjDesc is incremented.
64067754Smsmith *
64167754Smsmith ******************************************************************************/
64267754Smsmith
64367754SmsmithACPI_STATUS
64477424SmsmithAcpiDsStoreObjectToLocal (
64577424Smsmith    UINT16                  Opcode,
64667754Smsmith    UINT32                  Index,
64787031Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc,
64867754Smsmith    ACPI_WALK_STATE         *WalkState)
64967754Smsmith{
65067754Smsmith    ACPI_STATUS             Status;
65187031Smsmith    ACPI_NAMESPACE_NODE     *Node;
65287031Smsmith    ACPI_OPERAND_OBJECT     *CurrentObjDesc;
65367754Smsmith
65467754Smsmith
65591116Smsmith    ACPI_FUNCTION_TRACE ("DsStoreObjectToLocal");
65682367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode=%d Idx=%d Obj=%p\n",
65787031Smsmith        Opcode, Index, ObjDesc));
65867754Smsmith
65967754Smsmith
66067754Smsmith    /* Parameter validation */
66167754Smsmith
66287031Smsmith    if (!ObjDesc)
66367754Smsmith    {
66467754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
66567754Smsmith    }
66667754Smsmith
66787031Smsmith    /* Get the namespace node for the arg/local */
66867754Smsmith
66987031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
67067754Smsmith    if (ACPI_FAILURE (Status))
67167754Smsmith    {
67287031Smsmith        return_ACPI_STATUS (Status);
67367754Smsmith    }
67467754Smsmith
67587031Smsmith    CurrentObjDesc = AcpiNsGetAttachedObject (Node);
67687031Smsmith    if (CurrentObjDesc == ObjDesc)
67767754Smsmith    {
67887031Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n", ObjDesc));
67987031Smsmith        return_ACPI_STATUS (Status);
68067754Smsmith    }
68167754Smsmith
68267754Smsmith    /*
68367754Smsmith     * If there is an object already in this slot, we either
68467754Smsmith     * have to delete it, or if this is an argument and there
68567754Smsmith     * is an object reference stored there, we have to do
68667754Smsmith     * an indirect store!
68767754Smsmith     */
68887031Smsmith    if (CurrentObjDesc)
68967754Smsmith    {
69067754Smsmith        /*
69167754Smsmith         * Check for an indirect store if an argument
69267754Smsmith         * contains an object reference (stored as an Node).
69367754Smsmith         * We don't allow this automatic dereferencing for
69467754Smsmith         * locals, since a store to a local should overwrite
69567754Smsmith         * anything there, including an object reference.
69667754Smsmith         *
69767754Smsmith         * If both Arg0 and Local0 contain RefOf (Local4):
69867754Smsmith         *
69967754Smsmith         * Store (1, Arg0)             - Causes indirect store to local4
70067754Smsmith         * Store (1, Local0)           - Stores 1 in local0, overwriting
70167754Smsmith         *                                  the reference to local4
70267754Smsmith         * Store (1, DeRefof (Local0)) - Causes indirect store to local4
70367754Smsmith         *
70467754Smsmith         * Weird, but true.
70567754Smsmith         */
70677424Smsmith        if ((Opcode == AML_ARG_OP) &&
70791116Smsmith            (ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) == ACPI_DESC_TYPE_NAMED))
70867754Smsmith        {
70982367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
71087031Smsmith                "Arg (%p) is an ObjRef(Node), storing in node %p\n",
71187031Smsmith                ObjDesc, CurrentObjDesc));
71267754Smsmith
71367754Smsmith            /* Detach an existing object from the Node */
71467754Smsmith
71587031Smsmith            AcpiNsDetachObject ((ACPI_NAMESPACE_NODE *) CurrentObjDesc);
71667754Smsmith
71767754Smsmith            /*
71867754Smsmith             * Store this object into the Node
71987031Smsmith             * (perform the indirect store)
72067754Smsmith             */
72191116Smsmith            Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) CurrentObjDesc,
72287031Smsmith                            ObjDesc, ObjDesc->Common.Type);
72367754Smsmith            return_ACPI_STATUS (Status);
72467754Smsmith        }
72567754Smsmith
72667754Smsmith        /*
72771867Smsmith         * Delete the existing object
72867754Smsmith         * before storing the new one
72967754Smsmith         */
73077424Smsmith        AcpiDsMethodDataDeleteValue (Opcode, Index, WalkState);
73167754Smsmith    }
73267754Smsmith
73367754Smsmith    /*
73487031Smsmith     * Install the ObjStack descriptor (*ObjDesc) into
73567754Smsmith     * the descriptor for the Arg or Local.
73667754Smsmith     * Install the new object in the stack entry
73767754Smsmith     * (increments the object reference count by one)
73867754Smsmith     */
73987031Smsmith    Status = AcpiDsMethodDataSetValue (Opcode, Index, ObjDesc, WalkState);
74067754Smsmith    return_ACPI_STATUS (Status);
74167754Smsmith}
74267754Smsmith
74387031Smsmith
744