dsmthdat.c revision 102550
167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: dsmthdat - control method arguments and local variables
4102550Siwasaki *              $Revision: 63 $
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 "acdispat.h"
12167754Smsmith#include "amlcode.h"
12267754Smsmith#include "acnamesp.h"
12367754Smsmith
12467754Smsmith
12577424Smsmith#define _COMPONENT          ACPI_DISPATCHER
12691116Smsmith        ACPI_MODULE_NAME    ("dsmthdat")
12767754Smsmith
12867754Smsmith
12967754Smsmith/*******************************************************************************
13067754Smsmith *
13167754Smsmith * FUNCTION:    AcpiDsMethodDataInit
13267754Smsmith *
13371867Smsmith * PARAMETERS:  WalkState           - Current walk state object
13467754Smsmith *
13567754Smsmith * RETURN:      Status
13667754Smsmith *
13767754Smsmith * DESCRIPTION: Initialize the data structures that hold the method's arguments
13867754Smsmith *              and locals.  The data struct is an array of NTEs for each.
13967754Smsmith *              This allows RefOf and DeRefOf to work properly for these
14067754Smsmith *              special data types.
14167754Smsmith *
14287031Smsmith * NOTES:       WalkState fields are initialized to zero by the
14387031Smsmith *              ACPI_MEM_CALLOCATE().
14487031Smsmith *
14587031Smsmith *              A pseudo-Namespace Node is assigned to each argument and local
14687031Smsmith *              so that RefOf() can return a pointer to the Node.
14787031Smsmith *
14867754Smsmith ******************************************************************************/
14967754Smsmith
15099679Siwasakivoid
15167754SmsmithAcpiDsMethodDataInit (
15267754Smsmith    ACPI_WALK_STATE         *WalkState)
15367754Smsmith{
15467754Smsmith    UINT32                  i;
15567754Smsmith
15667754Smsmith
15791116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataInit");
15867754Smsmith
15967754Smsmith
16067754Smsmith    /* Init the method arguments */
16167754Smsmith
16267754Smsmith    for (i = 0; i < MTH_NUM_ARGS; i++)
16367754Smsmith    {
16491116Smsmith        ACPI_MOVE_UNALIGNED32_TO_32 (&WalkState->Arguments[i].Name,
16567754Smsmith                                NAMEOF_ARG_NTE);
16699146Siwasaki        WalkState->Arguments[i].Name.Integer |= (i << 24);
16799146Siwasaki        WalkState->Arguments[i].Descriptor    = ACPI_DESC_TYPE_NAMED;
16899146Siwasaki        WalkState->Arguments[i].Type          = ACPI_TYPE_ANY;
16999146Siwasaki        WalkState->Arguments[i].Flags         = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG;
17067754Smsmith    }
17167754Smsmith
17267754Smsmith    /* Init the method locals */
17367754Smsmith
17467754Smsmith    for (i = 0; i < MTH_NUM_LOCALS; i++)
17567754Smsmith    {
17691116Smsmith        ACPI_MOVE_UNALIGNED32_TO_32 (&WalkState->LocalVariables[i].Name,
17767754Smsmith                                NAMEOF_LOCAL_NTE);
17867754Smsmith
17999146Siwasaki        WalkState->LocalVariables[i].Name.Integer |= (i << 24);
18099146Siwasaki        WalkState->LocalVariables[i].Descriptor    = ACPI_DESC_TYPE_NAMED;
18199146Siwasaki        WalkState->LocalVariables[i].Type          = ACPI_TYPE_ANY;
18299146Siwasaki        WalkState->LocalVariables[i].Flags         = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL;
18367754Smsmith    }
18467754Smsmith
18599679Siwasaki    return_VOID;
18667754Smsmith}
18767754Smsmith
18867754Smsmith
18967754Smsmith/*******************************************************************************
19067754Smsmith *
19167754Smsmith * FUNCTION:    AcpiDsMethodDataDeleteAll
19267754Smsmith *
19371867Smsmith * PARAMETERS:  WalkState           - Current walk state object
19467754Smsmith *
19599679Siwasaki * RETURN:      None
19667754Smsmith *
19767754Smsmith * DESCRIPTION: Delete method locals and arguments.  Arguments are only
19867754Smsmith *              deleted if this method was called from another method.
19967754Smsmith *
20067754Smsmith ******************************************************************************/
20167754Smsmith
20299679Siwasakivoid
20367754SmsmithAcpiDsMethodDataDeleteAll (
20467754Smsmith    ACPI_WALK_STATE         *WalkState)
20567754Smsmith{
20667754Smsmith    UINT32                  Index;
20767754Smsmith
20867754Smsmith
20991116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataDeleteAll");
21067754Smsmith
21167754Smsmith
21287031Smsmith    /* Detach the locals */
21367754Smsmith
21467754Smsmith    for (Index = 0; Index < MTH_NUM_LOCALS; Index++)
21567754Smsmith    {
21687031Smsmith        if (WalkState->LocalVariables[Index].Object)
21767754Smsmith        {
21887031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%d=%p\n",
21987031Smsmith                    Index, WalkState->LocalVariables[Index].Object));
22067754Smsmith
22187031Smsmith            /* Detach object (if present) and remove a reference */
22267754Smsmith
22387031Smsmith            AcpiNsDetachObject (&WalkState->LocalVariables[Index]);
22499679Siwasaki        }
22567754Smsmith    }
22667754Smsmith
22787031Smsmith    /* Detach the arguments */
22867754Smsmith
22967754Smsmith    for (Index = 0; Index < MTH_NUM_ARGS; Index++)
23067754Smsmith    {
23187031Smsmith        if (WalkState->Arguments[Index].Object)
23267754Smsmith        {
23387031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%d=%p\n",
23487031Smsmith                    Index, WalkState->Arguments[Index].Object));
23567754Smsmith
23687031Smsmith            /* Detach object (if present) and remove a reference */
23767754Smsmith
23887031Smsmith            AcpiNsDetachObject (&WalkState->Arguments[Index]);
23967754Smsmith        }
24067754Smsmith    }
24167754Smsmith
24299679Siwasaki    return_VOID;
24367754Smsmith}
24467754Smsmith
24567754Smsmith
24667754Smsmith/*******************************************************************************
24767754Smsmith *
24867754Smsmith * FUNCTION:    AcpiDsMethodDataInitArgs
24967754Smsmith *
25071867Smsmith * PARAMETERS:  *Params         - Pointer to a parameter list for the method
25171867Smsmith *              MaxParamCount   - The arg count for this method
25271867Smsmith *              WalkState       - Current walk state object
25367754Smsmith *
25467754Smsmith * RETURN:      Status
25567754Smsmith *
25687031Smsmith * DESCRIPTION: Initialize arguments for a method.  The parameter list is a list
25787031Smsmith *              of ACPI operand objects, either null terminated or whose length
25887031Smsmith *              is defined by MaxParamCount.
25967754Smsmith *
26067754Smsmith ******************************************************************************/
26167754Smsmith
26267754SmsmithACPI_STATUS
26367754SmsmithAcpiDsMethodDataInitArgs (
26467754Smsmith    ACPI_OPERAND_OBJECT     **Params,
26567754Smsmith    UINT32                  MaxParamCount,
26667754Smsmith    ACPI_WALK_STATE         *WalkState)
26767754Smsmith{
26867754Smsmith    ACPI_STATUS             Status;
26987031Smsmith    UINT32                  Index = 0;
27067754Smsmith
27167754Smsmith
27291116Smsmith    ACPI_FUNCTION_TRACE_PTR ("DsMethodDataInitArgs", Params);
27367754Smsmith
27467754Smsmith
27567754Smsmith    if (!Params)
27667754Smsmith    {
27782367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "No param list passed to method\n"));
27867754Smsmith        return_ACPI_STATUS (AE_OK);
27967754Smsmith    }
28067754Smsmith
28167754Smsmith    /* Copy passed parameters into the new method stack frame  */
28267754Smsmith
28387031Smsmith    while ((Index < MTH_NUM_ARGS) && (Index < MaxParamCount) && Params[Index])
28467754Smsmith    {
28587031Smsmith        /*
28687031Smsmith         * A valid parameter.
28787031Smsmith         * Store the argument in the method/walk descriptor
28887031Smsmith         */
28987031Smsmith        Status = AcpiDsStoreObjectToLocal (AML_ARG_OP, Index, Params[Index],
29087031Smsmith                                            WalkState);
29187031Smsmith        if (ACPI_FAILURE (Status))
29267754Smsmith        {
29387031Smsmith            return_ACPI_STATUS (Status);
29467754Smsmith        }
29567754Smsmith
29687031Smsmith        Index++;
29767754Smsmith    }
29867754Smsmith
29987031Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%d args passed to method\n", Index));
30067754Smsmith    return_ACPI_STATUS (AE_OK);
30167754Smsmith}
30267754Smsmith
30367754Smsmith
30467754Smsmith/*******************************************************************************
30567754Smsmith *
30687031Smsmith * FUNCTION:    AcpiDsMethodDataGetNode
30767754Smsmith *
30877424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
30987031Smsmith *              Index               - Which localVar or argument whose type
31087031Smsmith *                                      to get
31171867Smsmith *              WalkState           - Current walk state object
31267754Smsmith *
31387031Smsmith * RETURN:      Get the Node associated with a local or arg.
31467754Smsmith *
31567754Smsmith ******************************************************************************/
31667754Smsmith
31767754SmsmithACPI_STATUS
31887031SmsmithAcpiDsMethodDataGetNode (
31977424Smsmith    UINT16                  Opcode,
32067754Smsmith    UINT32                  Index,
32167754Smsmith    ACPI_WALK_STATE         *WalkState,
32287031Smsmith    ACPI_NAMESPACE_NODE     **Node)
32367754Smsmith{
32491116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataGetNode");
32567754Smsmith
32667754Smsmith
32767754Smsmith    /*
32887031Smsmith     * Method Locals and Arguments are supported
32967754Smsmith     */
33077424Smsmith    switch (Opcode)
33167754Smsmith    {
33277424Smsmith    case AML_LOCAL_OP:
33367754Smsmith
33467754Smsmith        if (Index > MTH_MAX_LOCAL)
33567754Smsmith        {
33687031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Local index %d is invalid (max %d)\n",
33767754Smsmith                Index, MTH_MAX_LOCAL));
33887031Smsmith            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
33967754Smsmith        }
34067754Smsmith
34187031Smsmith        /* Return a pointer to the pseudo-node */
34287031Smsmith
34387031Smsmith        *Node = &WalkState->LocalVariables[Index];
34467754Smsmith        break;
34567754Smsmith
34677424Smsmith    case AML_ARG_OP:
34767754Smsmith
34867754Smsmith        if (Index > MTH_MAX_ARG)
34967754Smsmith        {
35082367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Arg index %d is invalid (max %d)\n",
35167754Smsmith                Index, MTH_MAX_ARG));
35287031Smsmith            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
35367754Smsmith        }
35467754Smsmith
35587031Smsmith        /* Return a pointer to the pseudo-node */
35687031Smsmith
35787031Smsmith        *Node = &WalkState->Arguments[Index];
35867754Smsmith        break;
35967754Smsmith
36067754Smsmith    default:
36182367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Opcode %d is invalid\n", Opcode));
36287031Smsmith        return_ACPI_STATUS (AE_AML_BAD_OPCODE);
36367754Smsmith    }
36467754Smsmith
36567754Smsmith    return_ACPI_STATUS (AE_OK);
36667754Smsmith}
36767754Smsmith
36867754Smsmith
36967754Smsmith/*******************************************************************************
37067754Smsmith *
37187031Smsmith * FUNCTION:    AcpiDsMethodDataSetValue
37267754Smsmith *
37377424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
37467754Smsmith *              Index               - Which localVar or argument to get
37567754Smsmith *              Object              - Object to be inserted into the stack entry
37671867Smsmith *              WalkState           - Current walk state object
37767754Smsmith *
37867754Smsmith * RETURN:      Status
37967754Smsmith *
38077424Smsmith * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
38167754Smsmith *
38267754Smsmith ******************************************************************************/
38367754Smsmith
38467754SmsmithACPI_STATUS
38587031SmsmithAcpiDsMethodDataSetValue (
38677424Smsmith    UINT16                  Opcode,
38767754Smsmith    UINT32                  Index,
38867754Smsmith    ACPI_OPERAND_OBJECT     *Object,
38967754Smsmith    ACPI_WALK_STATE         *WalkState)
39067754Smsmith{
39167754Smsmith    ACPI_STATUS             Status;
39287031Smsmith    ACPI_NAMESPACE_NODE     *Node;
39367754Smsmith
39467754Smsmith
39591116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataSetValue");
39667754Smsmith
39783174Smsmith
39887031Smsmith    /* Get the namespace node for the arg/local */
39967754Smsmith
40087031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
40167754Smsmith    if (ACPI_FAILURE (Status))
40267754Smsmith    {
40367754Smsmith        return_ACPI_STATUS (Status);
40467754Smsmith    }
40567754Smsmith
40667754Smsmith    /* Increment ref count so object can't be deleted while installed */
40767754Smsmith
40877424Smsmith    AcpiUtAddReference (Object);
40967754Smsmith
41067754Smsmith    /* Install the object into the stack entry */
41167754Smsmith
41287031Smsmith    Node->Object = Object;
41367754Smsmith    return_ACPI_STATUS (AE_OK);
41467754Smsmith}
41567754Smsmith
41667754Smsmith
41767754Smsmith/*******************************************************************************
41867754Smsmith *
41967754Smsmith * FUNCTION:    AcpiDsMethodDataGetType
42067754Smsmith *
42177424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
42267754Smsmith *              Index               - Which localVar or argument whose type
42367754Smsmith *                                      to get
42471867Smsmith *              WalkState           - Current walk state object
42567754Smsmith *
42687031Smsmith * RETURN:      Data type of current value of the selected Arg or Local
42767754Smsmith *
42867754Smsmith ******************************************************************************/
42967754Smsmith
43091116SmsmithACPI_OBJECT_TYPE
43167754SmsmithAcpiDsMethodDataGetType (
43277424Smsmith    UINT16                  Opcode,
43367754Smsmith    UINT32                  Index,
43467754Smsmith    ACPI_WALK_STATE         *WalkState)
43567754Smsmith{
43667754Smsmith    ACPI_STATUS             Status;
43787031Smsmith    ACPI_NAMESPACE_NODE     *Node;
43867754Smsmith    ACPI_OPERAND_OBJECT     *Object;
43967754Smsmith
44067754Smsmith
44191116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataGetType");
44267754Smsmith
44367754Smsmith
44487031Smsmith    /* Get the namespace node for the arg/local */
44567754Smsmith
44687031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
44767754Smsmith    if (ACPI_FAILURE (Status))
44867754Smsmith    {
44967754Smsmith        return_VALUE ((ACPI_TYPE_NOT_FOUND));
45067754Smsmith    }
45167754Smsmith
45287031Smsmith    /* Get the object */
45367754Smsmith
45487031Smsmith    Object = AcpiNsGetAttachedObject (Node);
45567754Smsmith    if (!Object)
45667754Smsmith    {
45787031Smsmith        /* Uninitialized local/arg, return TYPE_ANY */
45887031Smsmith
45967754Smsmith        return_VALUE (ACPI_TYPE_ANY);
46067754Smsmith    }
46167754Smsmith
46287031Smsmith    /* Get the object type */
46387031Smsmith
46499679Siwasaki    return_VALUE (ACPI_GET_OBJECT_TYPE (Object));
46567754Smsmith}
46667754Smsmith
46767754Smsmith
46867754Smsmith/*******************************************************************************
46967754Smsmith *
47067754Smsmith * FUNCTION:    AcpiDsMethodDataGetValue
47167754Smsmith *
47277424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
47367754Smsmith *              Index               - Which localVar or argument to get
47471867Smsmith *              WalkState           - Current walk state object
47571867Smsmith *              *DestDesc           - Ptr to Descriptor into which selected Arg
47667754Smsmith *                                    or Local value should be copied
47767754Smsmith *
47867754Smsmith * RETURN:      Status
47967754Smsmith *
48067754Smsmith * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame
48167754Smsmith *              at the current top of the method stack.
48277424Smsmith *              Used only in AcpiExResolveToValue().
48367754Smsmith *
48467754Smsmith ******************************************************************************/
48567754Smsmith
48667754SmsmithACPI_STATUS
48767754SmsmithAcpiDsMethodDataGetValue (
48877424Smsmith    UINT16                  Opcode,
48967754Smsmith    UINT32                  Index,
49067754Smsmith    ACPI_WALK_STATE         *WalkState,
49167754Smsmith    ACPI_OPERAND_OBJECT     **DestDesc)
49267754Smsmith{
49367754Smsmith    ACPI_STATUS             Status;
49487031Smsmith    ACPI_NAMESPACE_NODE     *Node;
49567754Smsmith    ACPI_OPERAND_OBJECT     *Object;
49667754Smsmith
49767754Smsmith
49891116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataGetValue");
49967754Smsmith
50067754Smsmith
50167754Smsmith    /* Validate the object descriptor */
50267754Smsmith
50367754Smsmith    if (!DestDesc)
50467754Smsmith    {
50582367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null object descriptor pointer\n"));
50667754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
50767754Smsmith    }
50867754Smsmith
50987031Smsmith    /* Get the namespace node for the arg/local */
51067754Smsmith
51187031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
51267754Smsmith    if (ACPI_FAILURE (Status))
51367754Smsmith    {
51467754Smsmith        return_ACPI_STATUS (Status);
51567754Smsmith    }
51667754Smsmith
51787031Smsmith    /* Get the object from the node */
51867754Smsmith
51987031Smsmith    Object = Node->Object;
52067754Smsmith
52167754Smsmith    /* Examine the returned object, it must be valid. */
52267754Smsmith
52367754Smsmith    if (!Object)
52467754Smsmith    {
52567754Smsmith        /*
52687031Smsmith         * Index points to uninitialized object.
52767754Smsmith         * This means that either 1) The expected argument was
52867754Smsmith         * not passed to the method, or 2) A local variable
52967754Smsmith         * was referenced by the method (via the ASL)
53067754Smsmith         * before it was initialized.  Either case is an error.
53167754Smsmith         */
53277424Smsmith        switch (Opcode)
53367754Smsmith        {
53477424Smsmith        case AML_ARG_OP:
53571867Smsmith
53687031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Arg[%d] at node %p\n",
53787031Smsmith                Index, Node));
53871867Smsmith
53967754Smsmith            return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
54067754Smsmith
54177424Smsmith        case AML_LOCAL_OP:
54271867Smsmith
54387031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Local[%d] at node %p\n",
54487031Smsmith                Index, Node));
54571867Smsmith
54667754Smsmith            return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
54799679Siwasaki
54899679Siwasaki        default:
54999679Siwasaki            return_ACPI_STATUS (AE_AML_INTERNAL);
55067754Smsmith        }
55167754Smsmith    }
55267754Smsmith
55367754Smsmith    /*
55487031Smsmith     * The Index points to an initialized and valid object.
55567754Smsmith     * Return an additional reference to the object
55667754Smsmith     */
55767754Smsmith    *DestDesc = Object;
55877424Smsmith    AcpiUtAddReference (Object);
55967754Smsmith
56067754Smsmith    return_ACPI_STATUS (AE_OK);
56167754Smsmith}
56267754Smsmith
56367754Smsmith
56467754Smsmith/*******************************************************************************
56567754Smsmith *
56667754Smsmith * FUNCTION:    AcpiDsMethodDataDeleteValue
56767754Smsmith *
56877424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
56967754Smsmith *              Index               - Which localVar or argument to delete
57071867Smsmith *              WalkState           - Current walk state object
57167754Smsmith *
57299679Siwasaki * RETURN:      None
57367754Smsmith *
57477424Smsmith * DESCRIPTION: Delete the entry at Opcode:Index on the method stack.  Inserts
57567754Smsmith *              a null into the stack slot after the object is deleted.
57667754Smsmith *
57767754Smsmith ******************************************************************************/
57867754Smsmith
57999679Siwasakivoid
58067754SmsmithAcpiDsMethodDataDeleteValue (
58177424Smsmith    UINT16                  Opcode,
58267754Smsmith    UINT32                  Index,
58367754Smsmith    ACPI_WALK_STATE         *WalkState)
58467754Smsmith{
58567754Smsmith    ACPI_STATUS             Status;
58687031Smsmith    ACPI_NAMESPACE_NODE     *Node;
58767754Smsmith    ACPI_OPERAND_OBJECT     *Object;
58867754Smsmith
58967754Smsmith
59091116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataDeleteValue");
59167754Smsmith
59267754Smsmith
59387031Smsmith    /* Get the namespace node for the arg/local */
59467754Smsmith
59587031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
59667754Smsmith    if (ACPI_FAILURE (Status))
59767754Smsmith    {
59899679Siwasaki        return_VOID;
59967754Smsmith    }
60067754Smsmith
60187031Smsmith    /* Get the associated object */
60267754Smsmith
60387031Smsmith    Object = AcpiNsGetAttachedObject (Node);
60467754Smsmith
60567754Smsmith    /*
60667754Smsmith     * Undefine the Arg or Local by setting its descriptor
60767754Smsmith     * pointer to NULL. Locals/Args can contain both
60867754Smsmith     * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
60967754Smsmith     */
61087031Smsmith    Node->Object = NULL;
61167754Smsmith
61267754Smsmith    if ((Object) &&
61399679Siwasaki        (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND))
61467754Smsmith    {
61567754Smsmith        /*
61687031Smsmith         * There is a valid object.
61767754Smsmith         * Decrement the reference count by one to balance the
61887031Smsmith         * increment when the object was stored.
61967754Smsmith         */
62077424Smsmith        AcpiUtRemoveReference (Object);
62167754Smsmith    }
62267754Smsmith
62399679Siwasaki    return_VOID;
62467754Smsmith}
62567754Smsmith
62667754Smsmith
62767754Smsmith/*******************************************************************************
62867754Smsmith *
62977424Smsmith * FUNCTION:    AcpiDsStoreObjectToLocal
63067754Smsmith *
63177424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
63267754Smsmith *              Index               - Which localVar or argument to set
63387031Smsmith *              ObjDesc             - Value to be stored
63471867Smsmith *              WalkState           - Current walk state
63567754Smsmith *
63667754Smsmith * RETURN:      Status
63767754Smsmith *
63887031Smsmith * DESCRIPTION: Store a value in an Arg or Local.  The ObjDesc is installed
63967754Smsmith *              as the new value for the Arg or Local and the reference count
64087031Smsmith *              for ObjDesc is incremented.
64167754Smsmith *
64267754Smsmith ******************************************************************************/
64367754Smsmith
64467754SmsmithACPI_STATUS
64577424SmsmithAcpiDsStoreObjectToLocal (
64677424Smsmith    UINT16                  Opcode,
64767754Smsmith    UINT32                  Index,
64887031Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc,
64967754Smsmith    ACPI_WALK_STATE         *WalkState)
65067754Smsmith{
65167754Smsmith    ACPI_STATUS             Status;
65287031Smsmith    ACPI_NAMESPACE_NODE     *Node;
65387031Smsmith    ACPI_OPERAND_OBJECT     *CurrentObjDesc;
65467754Smsmith
65567754Smsmith
65691116Smsmith    ACPI_FUNCTION_TRACE ("DsStoreObjectToLocal");
65782367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode=%d Idx=%d Obj=%p\n",
65887031Smsmith        Opcode, Index, ObjDesc));
65967754Smsmith
66067754Smsmith
66167754Smsmith    /* Parameter validation */
66267754Smsmith
66387031Smsmith    if (!ObjDesc)
66467754Smsmith    {
66567754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
66667754Smsmith    }
66767754Smsmith
66887031Smsmith    /* Get the namespace node for the arg/local */
66967754Smsmith
67087031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
67167754Smsmith    if (ACPI_FAILURE (Status))
67267754Smsmith    {
67387031Smsmith        return_ACPI_STATUS (Status);
67467754Smsmith    }
67567754Smsmith
67687031Smsmith    CurrentObjDesc = AcpiNsGetAttachedObject (Node);
67787031Smsmith    if (CurrentObjDesc == ObjDesc)
67867754Smsmith    {
67987031Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n", ObjDesc));
68087031Smsmith        return_ACPI_STATUS (Status);
68167754Smsmith    }
68267754Smsmith
68367754Smsmith    /*
68467754Smsmith     * If there is an object already in this slot, we either
68567754Smsmith     * have to delete it, or if this is an argument and there
68667754Smsmith     * is an object reference stored there, we have to do
68767754Smsmith     * an indirect store!
68867754Smsmith     */
68987031Smsmith    if (CurrentObjDesc)
69067754Smsmith    {
69167754Smsmith        /*
69267754Smsmith         * Check for an indirect store if an argument
69367754Smsmith         * contains an object reference (stored as an Node).
69467754Smsmith         * We don't allow this automatic dereferencing for
69567754Smsmith         * locals, since a store to a local should overwrite
69667754Smsmith         * anything there, including an object reference.
69767754Smsmith         *
69867754Smsmith         * If both Arg0 and Local0 contain RefOf (Local4):
69967754Smsmith         *
70067754Smsmith         * Store (1, Arg0)             - Causes indirect store to local4
70167754Smsmith         * Store (1, Local0)           - Stores 1 in local0, overwriting
70267754Smsmith         *                                  the reference to local4
70367754Smsmith         * Store (1, DeRefof (Local0)) - Causes indirect store to local4
70467754Smsmith         *
70567754Smsmith         * Weird, but true.
70667754Smsmith         */
707102550Siwasaki        if (Opcode == AML_ARG_OP)
70867754Smsmith        {
709102550Siwasaki            /*
710102550Siwasaki             * Make sure that the object is the correct type.  This may be overkill, but
711102550Siwasaki             * it is here because references were NS nodes in the past.  Now they are
712102550Siwasaki             * operand objects of type Reference.
713102550Siwasaki             */
714102550Siwasaki            if (ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) != ACPI_DESC_TYPE_OPERAND)
715102550Siwasaki            {
716102550Siwasaki                ACPI_REPORT_ERROR (("Invalid descriptor type while storing to method arg: %X\n",
717102550Siwasaki                    CurrentObjDesc->Common.Type));
718102550Siwasaki                return_ACPI_STATUS (AE_AML_INTERNAL);
719102550Siwasaki            }
72067754Smsmith
721102550Siwasaki            /*
722102550Siwasaki             * If we have a valid reference object that came from RefOf(), do the
723102550Siwasaki             * indirect store
724102550Siwasaki             */
725102550Siwasaki            if ((CurrentObjDesc->Common.Type == INTERNAL_TYPE_REFERENCE) &&
726102550Siwasaki                (CurrentObjDesc->Reference.Opcode == AML_REF_OF_OP))
727102550Siwasaki            {
728102550Siwasaki                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
729102550Siwasaki                    "Arg (%p) is an ObjRef(Node), storing in node %p\n",
730102550Siwasaki                    ObjDesc, CurrentObjDesc));
73167754Smsmith
732102550Siwasaki                /* Detach an existing object from the referenced Node */
73367754Smsmith
734102550Siwasaki                AcpiNsDetachObject (CurrentObjDesc->Reference.Object);
735102550Siwasaki
736102550Siwasaki                /*
737102550Siwasaki                 * Store this object into the Node
738102550Siwasaki                 * (perform the indirect store)
739102550Siwasaki                 */
740102550Siwasaki                Status = AcpiNsAttachObject (CurrentObjDesc->Reference.Object,
741102550Siwasaki                                ObjDesc, ACPI_GET_OBJECT_TYPE (ObjDesc));
742102550Siwasaki                return_ACPI_STATUS (Status);
743102550Siwasaki            }
74467754Smsmith        }
74567754Smsmith
74667754Smsmith        /*
74771867Smsmith         * Delete the existing object
74867754Smsmith         * before storing the new one
74967754Smsmith         */
75077424Smsmith        AcpiDsMethodDataDeleteValue (Opcode, Index, WalkState);
75167754Smsmith    }
75267754Smsmith
75367754Smsmith    /*
75487031Smsmith     * Install the ObjStack descriptor (*ObjDesc) into
75567754Smsmith     * the descriptor for the Arg or Local.
75667754Smsmith     * Install the new object in the stack entry
75767754Smsmith     * (increments the object reference count by one)
75867754Smsmith     */
75987031Smsmith    Status = AcpiDsMethodDataSetValue (Opcode, Index, ObjDesc, WalkState);
76067754Smsmith    return_ACPI_STATUS (Status);
76167754Smsmith}
76267754Smsmith
76387031Smsmith
764