dsmthdat.c revision 128212
167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: dsmthdat - control method arguments and local variables
4128212Snjl *              $Revision: 78 $
567754Smsmith *
667754Smsmith ******************************************************************************/
767754Smsmith
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
12126372Snjl * Some or all of this work - Copyright (c) 1999 - 2004, 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"
123114237Snjl#include "acinterp.h"
12467754Smsmith
12567754Smsmith
12677424Smsmith#define _COMPONENT          ACPI_DISPATCHER
12791116Smsmith        ACPI_MODULE_NAME    ("dsmthdat")
12867754Smsmith
12967754Smsmith
13067754Smsmith/*******************************************************************************
13167754Smsmith *
13267754Smsmith * FUNCTION:    AcpiDsMethodDataInit
13367754Smsmith *
13471867Smsmith * PARAMETERS:  WalkState           - Current walk state object
13567754Smsmith *
13667754Smsmith * RETURN:      Status
13767754Smsmith *
13867754Smsmith * DESCRIPTION: Initialize the data structures that hold the method's arguments
13967754Smsmith *              and locals.  The data struct is an array of NTEs for each.
14067754Smsmith *              This allows RefOf and DeRefOf to work properly for these
14167754Smsmith *              special data types.
14267754Smsmith *
14387031Smsmith * NOTES:       WalkState fields are initialized to zero by the
14487031Smsmith *              ACPI_MEM_CALLOCATE().
14587031Smsmith *
14687031Smsmith *              A pseudo-Namespace Node is assigned to each argument and local
14787031Smsmith *              so that RefOf() can return a pointer to the Node.
14887031Smsmith *
14967754Smsmith ******************************************************************************/
15067754Smsmith
15199679Siwasakivoid
15267754SmsmithAcpiDsMethodDataInit (
15367754Smsmith    ACPI_WALK_STATE         *WalkState)
15467754Smsmith{
15567754Smsmith    UINT32                  i;
15667754Smsmith
15767754Smsmith
15891116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataInit");
15967754Smsmith
16067754Smsmith
16167754Smsmith    /* Init the method arguments */
16267754Smsmith
163114237Snjl    for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
16467754Smsmith    {
165117521Snjl        ACPI_MOVE_32_TO_32 (&WalkState->Arguments[i].Name,
166117521Snjl                            NAMEOF_ARG_NTE);
16799146Siwasaki        WalkState->Arguments[i].Name.Integer |= (i << 24);
16899146Siwasaki        WalkState->Arguments[i].Descriptor    = ACPI_DESC_TYPE_NAMED;
16999146Siwasaki        WalkState->Arguments[i].Type          = ACPI_TYPE_ANY;
17099146Siwasaki        WalkState->Arguments[i].Flags         = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG;
17167754Smsmith    }
17267754Smsmith
17367754Smsmith    /* Init the method locals */
17467754Smsmith
175114237Snjl    for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
17667754Smsmith    {
177117521Snjl        ACPI_MOVE_32_TO_32 (&WalkState->LocalVariables[i].Name,
178117521Snjl                            NAMEOF_LOCAL_NTE);
17967754Smsmith
18099146Siwasaki        WalkState->LocalVariables[i].Name.Integer |= (i << 24);
18199146Siwasaki        WalkState->LocalVariables[i].Descriptor    = ACPI_DESC_TYPE_NAMED;
18299146Siwasaki        WalkState->LocalVariables[i].Type          = ACPI_TYPE_ANY;
18399146Siwasaki        WalkState->LocalVariables[i].Flags         = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL;
18467754Smsmith    }
18567754Smsmith
18699679Siwasaki    return_VOID;
18767754Smsmith}
18867754Smsmith
18967754Smsmith
19067754Smsmith/*******************************************************************************
19167754Smsmith *
19267754Smsmith * FUNCTION:    AcpiDsMethodDataDeleteAll
19367754Smsmith *
19471867Smsmith * PARAMETERS:  WalkState           - Current walk state object
19567754Smsmith *
19699679Siwasaki * RETURN:      None
19767754Smsmith *
19867754Smsmith * DESCRIPTION: Delete method locals and arguments.  Arguments are only
19967754Smsmith *              deleted if this method was called from another method.
20067754Smsmith *
20167754Smsmith ******************************************************************************/
20267754Smsmith
20399679Siwasakivoid
20467754SmsmithAcpiDsMethodDataDeleteAll (
20567754Smsmith    ACPI_WALK_STATE         *WalkState)
20667754Smsmith{
20767754Smsmith    UINT32                  Index;
20867754Smsmith
20967754Smsmith
21091116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataDeleteAll");
21167754Smsmith
21267754Smsmith
21387031Smsmith    /* Detach the locals */
21467754Smsmith
215114237Snjl    for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++)
21667754Smsmith    {
21787031Smsmith        if (WalkState->LocalVariables[Index].Object)
21867754Smsmith        {
21987031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%d=%p\n",
22087031Smsmith                    Index, WalkState->LocalVariables[Index].Object));
22167754Smsmith
22287031Smsmith            /* Detach object (if present) and remove a reference */
22367754Smsmith
22487031Smsmith            AcpiNsDetachObject (&WalkState->LocalVariables[Index]);
22599679Siwasaki        }
22667754Smsmith    }
22767754Smsmith
22887031Smsmith    /* Detach the arguments */
22967754Smsmith
230114237Snjl    for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++)
23167754Smsmith    {
23287031Smsmith        if (WalkState->Arguments[Index].Object)
23367754Smsmith        {
23487031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%d=%p\n",
23587031Smsmith                    Index, WalkState->Arguments[Index].Object));
23667754Smsmith
23787031Smsmith            /* Detach object (if present) and remove a reference */
23867754Smsmith
23987031Smsmith            AcpiNsDetachObject (&WalkState->Arguments[Index]);
24067754Smsmith        }
24167754Smsmith    }
24267754Smsmith
24399679Siwasaki    return_VOID;
24467754Smsmith}
24567754Smsmith
24667754Smsmith
24767754Smsmith/*******************************************************************************
24867754Smsmith *
24967754Smsmith * FUNCTION:    AcpiDsMethodDataInitArgs
25067754Smsmith *
25171867Smsmith * PARAMETERS:  *Params         - Pointer to a parameter list for the method
25271867Smsmith *              MaxParamCount   - The arg count for this method
25371867Smsmith *              WalkState       - Current walk state object
25467754Smsmith *
25567754Smsmith * RETURN:      Status
25667754Smsmith *
25787031Smsmith * DESCRIPTION: Initialize arguments for a method.  The parameter list is a list
25887031Smsmith *              of ACPI operand objects, either null terminated or whose length
25987031Smsmith *              is defined by MaxParamCount.
26067754Smsmith *
26167754Smsmith ******************************************************************************/
26267754Smsmith
26367754SmsmithACPI_STATUS
26467754SmsmithAcpiDsMethodDataInitArgs (
26567754Smsmith    ACPI_OPERAND_OBJECT     **Params,
26667754Smsmith    UINT32                  MaxParamCount,
26767754Smsmith    ACPI_WALK_STATE         *WalkState)
26867754Smsmith{
26967754Smsmith    ACPI_STATUS             Status;
27087031Smsmith    UINT32                  Index = 0;
27167754Smsmith
27267754Smsmith
27391116Smsmith    ACPI_FUNCTION_TRACE_PTR ("DsMethodDataInitArgs", Params);
27467754Smsmith
27567754Smsmith
27667754Smsmith    if (!Params)
27767754Smsmith    {
27882367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "No param list passed to method\n"));
27967754Smsmith        return_ACPI_STATUS (AE_OK);
28067754Smsmith    }
28167754Smsmith
28267754Smsmith    /* Copy passed parameters into the new method stack frame  */
28367754Smsmith
284114237Snjl    while ((Index < ACPI_METHOD_NUM_ARGS) && (Index < MaxParamCount) && Params[Index])
28567754Smsmith    {
28687031Smsmith        /*
28787031Smsmith         * A valid parameter.
288126372Snjl         * Store the argument in the method/walk descriptor.
289126372Snjl         * Do not copy the arg in order to implement call by reference
29087031Smsmith         */
291126372Snjl        Status = AcpiDsMethodDataSetValue (AML_ARG_OP, Index, Params[Index], WalkState);
29287031Smsmith        if (ACPI_FAILURE (Status))
29367754Smsmith        {
29487031Smsmith            return_ACPI_STATUS (Status);
29567754Smsmith        }
29667754Smsmith
29787031Smsmith        Index++;
29867754Smsmith    }
29967754Smsmith
30087031Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%d args passed to method\n", Index));
30167754Smsmith    return_ACPI_STATUS (AE_OK);
30267754Smsmith}
30367754Smsmith
30467754Smsmith
30567754Smsmith/*******************************************************************************
30667754Smsmith *
30787031Smsmith * FUNCTION:    AcpiDsMethodDataGetNode
30867754Smsmith *
30977424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
31087031Smsmith *              Index               - Which localVar or argument whose type
31187031Smsmith *                                      to get
31271867Smsmith *              WalkState           - Current walk state object
31367754Smsmith *
31487031Smsmith * RETURN:      Get the Node associated with a local or arg.
31567754Smsmith *
31667754Smsmith ******************************************************************************/
31767754Smsmith
31867754SmsmithACPI_STATUS
31987031SmsmithAcpiDsMethodDataGetNode (
32077424Smsmith    UINT16                  Opcode,
32167754Smsmith    UINT32                  Index,
32267754Smsmith    ACPI_WALK_STATE         *WalkState,
32387031Smsmith    ACPI_NAMESPACE_NODE     **Node)
32467754Smsmith{
32591116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataGetNode");
32667754Smsmith
32767754Smsmith
32867754Smsmith    /*
32987031Smsmith     * Method Locals and Arguments are supported
33067754Smsmith     */
33177424Smsmith    switch (Opcode)
33267754Smsmith    {
33377424Smsmith    case AML_LOCAL_OP:
33467754Smsmith
335114237Snjl        if (Index > ACPI_METHOD_MAX_LOCAL)
33667754Smsmith        {
33787031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Local index %d is invalid (max %d)\n",
338114237Snjl                Index, ACPI_METHOD_MAX_LOCAL));
33987031Smsmith            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
34067754Smsmith        }
34167754Smsmith
34287031Smsmith        /* Return a pointer to the pseudo-node */
34387031Smsmith
34487031Smsmith        *Node = &WalkState->LocalVariables[Index];
34567754Smsmith        break;
34667754Smsmith
34777424Smsmith    case AML_ARG_OP:
34867754Smsmith
349114237Snjl        if (Index > ACPI_METHOD_MAX_ARG)
35067754Smsmith        {
35182367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Arg index %d is invalid (max %d)\n",
352114237Snjl                Index, ACPI_METHOD_MAX_ARG));
35387031Smsmith            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
35467754Smsmith        }
35567754Smsmith
35687031Smsmith        /* Return a pointer to the pseudo-node */
35787031Smsmith
35887031Smsmith        *Node = &WalkState->Arguments[Index];
35967754Smsmith        break;
36067754Smsmith
36167754Smsmith    default:
36282367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Opcode %d is invalid\n", Opcode));
36387031Smsmith        return_ACPI_STATUS (AE_AML_BAD_OPCODE);
36467754Smsmith    }
36567754Smsmith
36667754Smsmith    return_ACPI_STATUS (AE_OK);
36767754Smsmith}
36867754Smsmith
36967754Smsmith
37067754Smsmith/*******************************************************************************
37167754Smsmith *
37287031Smsmith * FUNCTION:    AcpiDsMethodDataSetValue
37367754Smsmith *
37477424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
37567754Smsmith *              Index               - Which localVar or argument to get
37667754Smsmith *              Object              - Object to be inserted into the stack entry
37771867Smsmith *              WalkState           - Current walk state object
37867754Smsmith *
37967754Smsmith * RETURN:      Status
38067754Smsmith *
38177424Smsmith * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
382114237Snjl *              Note: There is no "implicit conversion" for locals.
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
400114237Snjl    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
401114237Snjl        "obj %p op %X, ref count = %d [%s]\n", Object,
402114237Snjl        Opcode, Object->Common.ReferenceCount,
403114237Snjl        AcpiUtGetTypeName (Object->Common.Type)));
404114237Snjl
40587031Smsmith    /* Get the namespace node for the arg/local */
40667754Smsmith
40787031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
40867754Smsmith    if (ACPI_FAILURE (Status))
40967754Smsmith    {
41067754Smsmith        return_ACPI_STATUS (Status);
41167754Smsmith    }
41267754Smsmith
413123315Snjl    /*
414122945Snjl     * Increment ref count so object can't be deleted while installed.
415122945Snjl     * NOTE: We do not copy the object in order to preserve the call by
416122945Snjl     * reference semantics of ACPI Control Method invocation.
417122945Snjl     * (See ACPI Specification 2.0C)
418114237Snjl     */
419122945Snjl    AcpiUtAddReference (Object);
42067754Smsmith
421114237Snjl    /* Install the object */
422114237Snjl
423122945Snjl    Node->Object = Object;
424114237Snjl    return_ACPI_STATUS (Status);
42567754Smsmith}
42667754Smsmith
42767754Smsmith
42867754Smsmith/*******************************************************************************
42967754Smsmith *
43067754Smsmith * FUNCTION:    AcpiDsMethodDataGetType
43167754Smsmith *
43277424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
43367754Smsmith *              Index               - Which localVar or argument whose type
43467754Smsmith *                                      to get
43571867Smsmith *              WalkState           - Current walk state object
43667754Smsmith *
43787031Smsmith * RETURN:      Data type of current value of the selected Arg or Local
43867754Smsmith *
43967754Smsmith ******************************************************************************/
44067754Smsmith
44191116SmsmithACPI_OBJECT_TYPE
44267754SmsmithAcpiDsMethodDataGetType (
44377424Smsmith    UINT16                  Opcode,
44467754Smsmith    UINT32                  Index,
44567754Smsmith    ACPI_WALK_STATE         *WalkState)
44667754Smsmith{
44767754Smsmith    ACPI_STATUS             Status;
44887031Smsmith    ACPI_NAMESPACE_NODE     *Node;
44967754Smsmith    ACPI_OPERAND_OBJECT     *Object;
45067754Smsmith
45167754Smsmith
45291116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataGetType");
45367754Smsmith
45467754Smsmith
45587031Smsmith    /* Get the namespace node for the arg/local */
45667754Smsmith
45787031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
45867754Smsmith    if (ACPI_FAILURE (Status))
45967754Smsmith    {
46067754Smsmith        return_VALUE ((ACPI_TYPE_NOT_FOUND));
46167754Smsmith    }
46267754Smsmith
46387031Smsmith    /* Get the object */
46467754Smsmith
46587031Smsmith    Object = AcpiNsGetAttachedObject (Node);
46667754Smsmith    if (!Object)
46767754Smsmith    {
46887031Smsmith        /* Uninitialized local/arg, return TYPE_ANY */
46987031Smsmith
47067754Smsmith        return_VALUE (ACPI_TYPE_ANY);
47167754Smsmith    }
47267754Smsmith
47387031Smsmith    /* Get the object type */
47487031Smsmith
47599679Siwasaki    return_VALUE (ACPI_GET_OBJECT_TYPE (Object));
47667754Smsmith}
47767754Smsmith
47867754Smsmith
47967754Smsmith/*******************************************************************************
48067754Smsmith *
48167754Smsmith * FUNCTION:    AcpiDsMethodDataGetValue
48267754Smsmith *
48377424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
48467754Smsmith *              Index               - Which localVar or argument to get
48571867Smsmith *              WalkState           - Current walk state object
48671867Smsmith *              *DestDesc           - Ptr to Descriptor into which selected Arg
48767754Smsmith *                                    or Local value should be copied
48867754Smsmith *
48967754Smsmith * RETURN:      Status
49067754Smsmith *
49167754Smsmith * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame
49267754Smsmith *              at the current top of the method stack.
49377424Smsmith *              Used only in AcpiExResolveToValue().
49467754Smsmith *
49567754Smsmith ******************************************************************************/
49667754Smsmith
49767754SmsmithACPI_STATUS
49867754SmsmithAcpiDsMethodDataGetValue (
49977424Smsmith    UINT16                  Opcode,
50067754Smsmith    UINT32                  Index,
50167754Smsmith    ACPI_WALK_STATE         *WalkState,
50267754Smsmith    ACPI_OPERAND_OBJECT     **DestDesc)
50367754Smsmith{
50467754Smsmith    ACPI_STATUS             Status;
50587031Smsmith    ACPI_NAMESPACE_NODE     *Node;
50667754Smsmith    ACPI_OPERAND_OBJECT     *Object;
50767754Smsmith
50867754Smsmith
50991116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataGetValue");
51067754Smsmith
51167754Smsmith
51267754Smsmith    /* Validate the object descriptor */
51367754Smsmith
51467754Smsmith    if (!DestDesc)
51567754Smsmith    {
51682367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null object descriptor pointer\n"));
51767754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
51867754Smsmith    }
51967754Smsmith
52087031Smsmith    /* Get the namespace node for the arg/local */
52167754Smsmith
52287031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
52367754Smsmith    if (ACPI_FAILURE (Status))
52467754Smsmith    {
52567754Smsmith        return_ACPI_STATUS (Status);
52667754Smsmith    }
52767754Smsmith
52887031Smsmith    /* Get the object from the node */
52967754Smsmith
53087031Smsmith    Object = Node->Object;
53167754Smsmith
53267754Smsmith    /* Examine the returned object, it must be valid. */
53367754Smsmith
53467754Smsmith    if (!Object)
53567754Smsmith    {
53667754Smsmith        /*
53787031Smsmith         * Index points to uninitialized object.
53867754Smsmith         * This means that either 1) The expected argument was
53967754Smsmith         * not passed to the method, or 2) A local variable
54067754Smsmith         * was referenced by the method (via the ASL)
54167754Smsmith         * before it was initialized.  Either case is an error.
54267754Smsmith         */
54377424Smsmith        switch (Opcode)
54467754Smsmith        {
54577424Smsmith        case AML_ARG_OP:
54671867Smsmith
54787031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Arg[%d] at node %p\n",
54887031Smsmith                Index, Node));
54971867Smsmith
55067754Smsmith            return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
55167754Smsmith
55277424Smsmith        case AML_LOCAL_OP:
55371867Smsmith
55487031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Local[%d] at node %p\n",
55587031Smsmith                Index, Node));
55671867Smsmith
55767754Smsmith            return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
55899679Siwasaki
55999679Siwasaki        default:
560126372Snjl            ACPI_REPORT_ERROR (("Not Arg/Local opcode: %X\n", Opcode));
56199679Siwasaki            return_ACPI_STATUS (AE_AML_INTERNAL);
56267754Smsmith        }
56367754Smsmith    }
56467754Smsmith
56567754Smsmith    /*
56687031Smsmith     * The Index points to an initialized and valid object.
56767754Smsmith     * Return an additional reference to the object
56867754Smsmith     */
56967754Smsmith    *DestDesc = Object;
57077424Smsmith    AcpiUtAddReference (Object);
57167754Smsmith
57267754Smsmith    return_ACPI_STATUS (AE_OK);
57367754Smsmith}
57467754Smsmith
57567754Smsmith
57667754Smsmith/*******************************************************************************
57767754Smsmith *
57867754Smsmith * FUNCTION:    AcpiDsMethodDataDeleteValue
57967754Smsmith *
58077424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
58167754Smsmith *              Index               - Which localVar or argument to delete
58271867Smsmith *              WalkState           - Current walk state object
58367754Smsmith *
58499679Siwasaki * RETURN:      None
58567754Smsmith *
58677424Smsmith * DESCRIPTION: Delete the entry at Opcode:Index on the method stack.  Inserts
58767754Smsmith *              a null into the stack slot after the object is deleted.
58867754Smsmith *
58967754Smsmith ******************************************************************************/
59067754Smsmith
59199679Siwasakivoid
59267754SmsmithAcpiDsMethodDataDeleteValue (
59377424Smsmith    UINT16                  Opcode,
59467754Smsmith    UINT32                  Index,
59567754Smsmith    ACPI_WALK_STATE         *WalkState)
59667754Smsmith{
59767754Smsmith    ACPI_STATUS             Status;
59887031Smsmith    ACPI_NAMESPACE_NODE     *Node;
59967754Smsmith    ACPI_OPERAND_OBJECT     *Object;
60067754Smsmith
60167754Smsmith
60291116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataDeleteValue");
60367754Smsmith
60467754Smsmith
60587031Smsmith    /* Get the namespace node for the arg/local */
60667754Smsmith
60787031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
60867754Smsmith    if (ACPI_FAILURE (Status))
60967754Smsmith    {
61099679Siwasaki        return_VOID;
61167754Smsmith    }
61267754Smsmith
61387031Smsmith    /* Get the associated object */
61467754Smsmith
61587031Smsmith    Object = AcpiNsGetAttachedObject (Node);
61667754Smsmith
61767754Smsmith    /*
61867754Smsmith     * Undefine the Arg or Local by setting its descriptor
61967754Smsmith     * pointer to NULL. Locals/Args can contain both
62067754Smsmith     * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
62167754Smsmith     */
62287031Smsmith    Node->Object = NULL;
62367754Smsmith
62467754Smsmith    if ((Object) &&
62599679Siwasaki        (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND))
62667754Smsmith    {
62767754Smsmith        /*
62887031Smsmith         * There is a valid object.
62967754Smsmith         * Decrement the reference count by one to balance the
63087031Smsmith         * increment when the object was stored.
63167754Smsmith         */
63277424Smsmith        AcpiUtRemoveReference (Object);
63367754Smsmith    }
63467754Smsmith
63599679Siwasaki    return_VOID;
63667754Smsmith}
63767754Smsmith
63867754Smsmith
63967754Smsmith/*******************************************************************************
64067754Smsmith *
64177424Smsmith * FUNCTION:    AcpiDsStoreObjectToLocal
64267754Smsmith *
64377424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
64467754Smsmith *              Index               - Which localVar or argument to set
64587031Smsmith *              ObjDesc             - Value to be stored
64671867Smsmith *              WalkState           - Current walk state
64767754Smsmith *
64867754Smsmith * RETURN:      Status
64967754Smsmith *
65087031Smsmith * DESCRIPTION: Store a value in an Arg or Local.  The ObjDesc is installed
65167754Smsmith *              as the new value for the Arg or Local and the reference count
65287031Smsmith *              for ObjDesc is incremented.
65367754Smsmith *
65467754Smsmith ******************************************************************************/
65567754Smsmith
65667754SmsmithACPI_STATUS
65777424SmsmithAcpiDsStoreObjectToLocal (
65877424Smsmith    UINT16                  Opcode,
65967754Smsmith    UINT32                  Index,
66087031Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc,
66167754Smsmith    ACPI_WALK_STATE         *WalkState)
66267754Smsmith{
66367754Smsmith    ACPI_STATUS             Status;
66487031Smsmith    ACPI_NAMESPACE_NODE     *Node;
66587031Smsmith    ACPI_OPERAND_OBJECT     *CurrentObjDesc;
666123315Snjl    ACPI_OPERAND_OBJECT     *NewObjDesc;
66767754Smsmith
66867754Smsmith
66991116Smsmith    ACPI_FUNCTION_TRACE ("DsStoreObjectToLocal");
67082367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode=%d Idx=%d Obj=%p\n",
67187031Smsmith        Opcode, Index, ObjDesc));
67267754Smsmith
67367754Smsmith    /* Parameter validation */
67467754Smsmith
67587031Smsmith    if (!ObjDesc)
67667754Smsmith    {
67767754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
67867754Smsmith    }
67967754Smsmith
68087031Smsmith    /* Get the namespace node for the arg/local */
68167754Smsmith
68287031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
68367754Smsmith    if (ACPI_FAILURE (Status))
68467754Smsmith    {
68587031Smsmith        return_ACPI_STATUS (Status);
68667754Smsmith    }
68767754Smsmith
68887031Smsmith    CurrentObjDesc = AcpiNsGetAttachedObject (Node);
68987031Smsmith    if (CurrentObjDesc == ObjDesc)
69067754Smsmith    {
691114237Snjl        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n",
692114237Snjl            ObjDesc));
69387031Smsmith        return_ACPI_STATUS (Status);
69467754Smsmith    }
69567754Smsmith
69667754Smsmith    /*
697123315Snjl     * If the reference count on the object is more than one, we must
698126372Snjl     * take a copy of the object before we store.  A reference count
699126372Snjl     * of exactly 1 means that the object was just created during the
700126372Snjl     * evaluation of an expression, and we can safely use it since it
701126372Snjl     * is not used anywhere else.
702123315Snjl     */
703123315Snjl    NewObjDesc = ObjDesc;
704126372Snjl    if (ObjDesc->Common.ReferenceCount > 1)
705123315Snjl    {
706123315Snjl        Status = AcpiUtCopyIobjectToIobject (ObjDesc, &NewObjDesc, WalkState);
707123315Snjl        if (ACPI_FAILURE (Status))
708123315Snjl        {
709123315Snjl            return_ACPI_STATUS (Status);
710123315Snjl        }
711123315Snjl    }
712123315Snjl
713123315Snjl    /*
71467754Smsmith     * If there is an object already in this slot, we either
71567754Smsmith     * have to delete it, or if this is an argument and there
71667754Smsmith     * is an object reference stored there, we have to do
71767754Smsmith     * an indirect store!
71867754Smsmith     */
71987031Smsmith    if (CurrentObjDesc)
72067754Smsmith    {
72167754Smsmith        /*
72267754Smsmith         * Check for an indirect store if an argument
72367754Smsmith         * contains an object reference (stored as an Node).
72467754Smsmith         * We don't allow this automatic dereferencing for
72567754Smsmith         * locals, since a store to a local should overwrite
72667754Smsmith         * anything there, including an object reference.
72767754Smsmith         *
72867754Smsmith         * If both Arg0 and Local0 contain RefOf (Local4):
72967754Smsmith         *
73067754Smsmith         * Store (1, Arg0)             - Causes indirect store to local4
73167754Smsmith         * Store (1, Local0)           - Stores 1 in local0, overwriting
73267754Smsmith         *                                  the reference to local4
73367754Smsmith         * Store (1, DeRefof (Local0)) - Causes indirect store to local4
73467754Smsmith         *
73567754Smsmith         * Weird, but true.
73667754Smsmith         */
737102550Siwasaki        if (Opcode == AML_ARG_OP)
73867754Smsmith        {
739114237Snjl            /*
740102550Siwasaki             * Make sure that the object is the correct type.  This may be overkill, but
741102550Siwasaki             * it is here because references were NS nodes in the past.  Now they are
742102550Siwasaki             * operand objects of type Reference.
743102550Siwasaki             */
744102550Siwasaki            if (ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) != ACPI_DESC_TYPE_OPERAND)
745102550Siwasaki            {
746123315Snjl                ACPI_REPORT_ERROR (("Invalid descriptor type while storing to method arg: [%s]\n",
747123315Snjl                        AcpiUtGetDescriptorName (CurrentObjDesc)));
748102550Siwasaki                return_ACPI_STATUS (AE_AML_INTERNAL);
749102550Siwasaki            }
75067754Smsmith
751114237Snjl            /*
752102550Siwasaki             * If we have a valid reference object that came from RefOf(), do the
753102550Siwasaki             * indirect store
754102550Siwasaki             */
755107325Siwasaki            if ((CurrentObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
756102550Siwasaki                (CurrentObjDesc->Reference.Opcode == AML_REF_OF_OP))
757102550Siwasaki            {
758102550Siwasaki                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
759123315Snjl                        "Arg (%p) is an ObjRef(Node), storing in node %p\n",
760123315Snjl                        NewObjDesc, CurrentObjDesc));
76167754Smsmith
762102550Siwasaki                /*
763128212Snjl                 * Store this object to the Node (perform the indirect store)
764128212Snjl                 * NOTE: No implicit conversion is performed, as per the ACPI
765128212Snjl                 * specification rules on storing to Locals/Args.
766102550Siwasaki                 */
767123315Snjl                Status = AcpiExStoreObjectToNode (NewObjDesc,
768128212Snjl                            CurrentObjDesc->Reference.Object, WalkState,
769128212Snjl                            ACPI_NO_IMPLICIT_CONVERSION);
770123315Snjl
771123315Snjl                /* Remove local reference if we copied the object above */
772123315Snjl
773123315Snjl                if (NewObjDesc != ObjDesc)
774123315Snjl                {
775123315Snjl                    AcpiUtRemoveReference (NewObjDesc);
776123315Snjl                }
777102550Siwasaki                return_ACPI_STATUS (Status);
778102550Siwasaki            }
77967754Smsmith        }
78067754Smsmith
78167754Smsmith        /*
78271867Smsmith         * Delete the existing object
78367754Smsmith         * before storing the new one
78467754Smsmith         */
78577424Smsmith        AcpiDsMethodDataDeleteValue (Opcode, Index, WalkState);
78667754Smsmith    }
78767754Smsmith
78867754Smsmith    /*
789123315Snjl     * Install the Obj descriptor (*NewObjDesc) into
79067754Smsmith     * the descriptor for the Arg or Local.
79167754Smsmith     * (increments the object reference count by one)
79267754Smsmith     */
793123315Snjl    Status = AcpiDsMethodDataSetValue (Opcode, Index, NewObjDesc, WalkState);
794123315Snjl
795123315Snjl    /* Remove local reference if we copied the object above */
796123315Snjl
797123315Snjl    if (NewObjDesc != ObjDesc)
798123315Snjl    {
799123315Snjl        AcpiUtRemoveReference (NewObjDesc);
800123315Snjl    }
801123315Snjl
80267754Smsmith    return_ACPI_STATUS (Status);
80367754Smsmith}
80467754Smsmith
80587031Smsmith
806