dsmthdat.c revision 82367
167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: dsmthdat - control method arguments and local variables
482367Smsmith *              $Revision: 48 $
567754Smsmith *
667754Smsmith ******************************************************************************/
767754Smsmith
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
1271867Smsmith * Some or all of this work - Copyright (c) 1999, 2000, 2001, 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
12867754Smsmith        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 *
14467754Smsmith ******************************************************************************/
14567754Smsmith
14667754SmsmithACPI_STATUS
14767754SmsmithAcpiDsMethodDataInit (
14867754Smsmith    ACPI_WALK_STATE         *WalkState)
14967754Smsmith{
15067754Smsmith    UINT32                  i;
15167754Smsmith
15267754Smsmith
15367754Smsmith    FUNCTION_TRACE ("DsMethodDataInit");
15467754Smsmith
15567754Smsmith    /*
15667754Smsmith     * WalkState fields are initialized to zero by the
15780062Smsmith     * ACPI_MEM_CALLOCATE().
15867754Smsmith     *
15967754Smsmith     * An Node is assigned to each argument and local so
16067754Smsmith     * that RefOf() can return a pointer to the Node.
16167754Smsmith     */
16267754Smsmith
16367754Smsmith    /* Init the method arguments */
16467754Smsmith
16567754Smsmith    for (i = 0; i < MTH_NUM_ARGS; i++)
16667754Smsmith    {
16767754Smsmith        MOVE_UNALIGNED32_TO_32 (&WalkState->Arguments[i].Name,
16867754Smsmith                                NAMEOF_ARG_NTE);
16967754Smsmith        WalkState->Arguments[i].Name       |= (i << 24);
17067754Smsmith        WalkState->Arguments[i].DataType    = ACPI_DESC_TYPE_NAMED;
17169746Smsmith        WalkState->Arguments[i].Type        = ACPI_TYPE_ANY;
17269746Smsmith        WalkState->Arguments[i].Flags       = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG;
17367754Smsmith    }
17467754Smsmith
17567754Smsmith    /* Init the method locals */
17667754Smsmith
17767754Smsmith    for (i = 0; i < MTH_NUM_LOCALS; i++)
17867754Smsmith    {
17967754Smsmith        MOVE_UNALIGNED32_TO_32 (&WalkState->LocalVariables[i].Name,
18067754Smsmith                                NAMEOF_LOCAL_NTE);
18167754Smsmith
18267754Smsmith        WalkState->LocalVariables[i].Name    |= (i << 24);
18367754Smsmith        WalkState->LocalVariables[i].DataType = ACPI_DESC_TYPE_NAMED;
18469746Smsmith        WalkState->LocalVariables[i].Type     = ACPI_TYPE_ANY;
18569746Smsmith        WalkState->LocalVariables[i].Flags    = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL;
18667754Smsmith    }
18767754Smsmith
18867754Smsmith    return_ACPI_STATUS (AE_OK);
18967754Smsmith}
19067754Smsmith
19167754Smsmith
19267754Smsmith/*******************************************************************************
19367754Smsmith *
19467754Smsmith * FUNCTION:    AcpiDsMethodDataDeleteAll
19567754Smsmith *
19671867Smsmith * PARAMETERS:  WalkState           - Current walk state object
19767754Smsmith *
19867754Smsmith * RETURN:      Status
19967754Smsmith *
20067754Smsmith * DESCRIPTION: Delete method locals and arguments.  Arguments are only
20167754Smsmith *              deleted if this method was called from another method.
20267754Smsmith *
20367754Smsmith ******************************************************************************/
20467754Smsmith
20567754SmsmithACPI_STATUS
20667754SmsmithAcpiDsMethodDataDeleteAll (
20767754Smsmith    ACPI_WALK_STATE         *WalkState)
20867754Smsmith{
20967754Smsmith    UINT32                  Index;
21067754Smsmith    ACPI_OPERAND_OBJECT     *Object;
21167754Smsmith
21267754Smsmith
21367754Smsmith    FUNCTION_TRACE ("DsMethodDataDeleteAll");
21467754Smsmith
21567754Smsmith
21667754Smsmith    /* Delete the locals */
21767754Smsmith
21882367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Deleting local variables in %p\n", WalkState));
21967754Smsmith
22067754Smsmith    for (Index = 0; Index < MTH_NUM_LOCALS; Index++)
22167754Smsmith    {
22267754Smsmith        Object = WalkState->LocalVariables[Index].Object;
22367754Smsmith        if (Object)
22467754Smsmith        {
22582367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%d=%p\n", Index, Object));
22667754Smsmith
22767754Smsmith            /* Remove first */
22867754Smsmith
22967754Smsmith            WalkState->LocalVariables[Index].Object = NULL;
23067754Smsmith
23167754Smsmith            /* Was given a ref when stored */
23267754Smsmith
23377424Smsmith            AcpiUtRemoveReference (Object);
23467754Smsmith       }
23567754Smsmith    }
23667754Smsmith
23767754Smsmith
23867754Smsmith    /* Delete the arguments */
23967754Smsmith
24082367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Deleting arguments in %p\n", WalkState));
24167754Smsmith
24267754Smsmith    for (Index = 0; Index < MTH_NUM_ARGS; Index++)
24367754Smsmith    {
24467754Smsmith        Object = WalkState->Arguments[Index].Object;
24567754Smsmith        if (Object)
24667754Smsmith        {
24782367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%d=%p\n", Index, Object));
24867754Smsmith
24967754Smsmith            /* Remove first */
25067754Smsmith
25167754Smsmith            WalkState->Arguments[Index].Object = NULL;
25267754Smsmith
25367754Smsmith             /* Was given a ref when stored */
25467754Smsmith
25577424Smsmith            AcpiUtRemoveReference (Object);
25667754Smsmith        }
25767754Smsmith    }
25867754Smsmith
25967754Smsmith    return_ACPI_STATUS (AE_OK);
26067754Smsmith}
26167754Smsmith
26267754Smsmith
26367754Smsmith/*******************************************************************************
26467754Smsmith *
26567754Smsmith * FUNCTION:    AcpiDsMethodDataInitArgs
26667754Smsmith *
26771867Smsmith * PARAMETERS:  *Params         - Pointer to a parameter list for the method
26871867Smsmith *              MaxParamCount   - The arg count for this method
26971867Smsmith *              WalkState       - Current walk state object
27067754Smsmith *
27167754Smsmith * RETURN:      Status
27267754Smsmith *
27367754Smsmith * DESCRIPTION: Initialize arguments for a method
27467754Smsmith *
27567754Smsmith ******************************************************************************/
27667754Smsmith
27767754SmsmithACPI_STATUS
27867754SmsmithAcpiDsMethodDataInitArgs (
27967754Smsmith    ACPI_OPERAND_OBJECT     **Params,
28067754Smsmith    UINT32                  MaxParamCount,
28167754Smsmith    ACPI_WALK_STATE         *WalkState)
28267754Smsmith{
28367754Smsmith    ACPI_STATUS             Status;
28467754Smsmith    UINT32                  Mindex;
28567754Smsmith    UINT32                  Pindex;
28667754Smsmith
28767754Smsmith
28867754Smsmith    FUNCTION_TRACE_PTR ("DsMethodDataInitArgs", Params);
28967754Smsmith
29067754Smsmith
29167754Smsmith    if (!Params)
29267754Smsmith    {
29382367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "No param list passed to method\n"));
29467754Smsmith        return_ACPI_STATUS (AE_OK);
29567754Smsmith    }
29667754Smsmith
29767754Smsmith    /* Copy passed parameters into the new method stack frame  */
29867754Smsmith
29967754Smsmith    for (Pindex = Mindex = 0;
30067754Smsmith        (Mindex < MTH_NUM_ARGS) && (Pindex < MaxParamCount);
30167754Smsmith        Mindex++)
30267754Smsmith    {
30367754Smsmith        if (Params[Pindex])
30467754Smsmith        {
30567754Smsmith            /*
30667754Smsmith             * A valid parameter.
30767754Smsmith             * Set the current method argument to the
30867754Smsmith             * Params[Pindex++] argument object descriptor
30967754Smsmith             */
31077424Smsmith            Status = AcpiDsStoreObjectToLocal (AML_ARG_OP, Mindex,
31177424Smsmith                            Params[Pindex], WalkState);
31267754Smsmith            if (ACPI_FAILURE (Status))
31367754Smsmith            {
31467754Smsmith                break;
31567754Smsmith            }
31667754Smsmith
31767754Smsmith            Pindex++;
31867754Smsmith        }
31967754Smsmith
32067754Smsmith        else
32167754Smsmith        {
32267754Smsmith            break;
32367754Smsmith        }
32467754Smsmith    }
32567754Smsmith
32682367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%d args passed to method\n", Pindex));
32767754Smsmith    return_ACPI_STATUS (AE_OK);
32867754Smsmith}
32967754Smsmith
33067754Smsmith
33167754Smsmith/*******************************************************************************
33267754Smsmith *
33367754Smsmith * FUNCTION:    AcpiDsMethodDataGetEntry
33467754Smsmith *
33577424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
33667754Smsmith *              Index               - Which localVar or argument to get
33767754Smsmith *              Entry               - Pointer to where a pointer to the stack
33867754Smsmith *                                    entry is returned.
33971867Smsmith *              WalkState           - Current walk state object
34067754Smsmith *
34167754Smsmith * RETURN:      Status
34267754Smsmith *
34377424Smsmith * DESCRIPTION: Get the address of the object entry given by Opcode:Index
34467754Smsmith *
34567754Smsmith ******************************************************************************/
34667754Smsmith
34767754SmsmithACPI_STATUS
34867754SmsmithAcpiDsMethodDataGetEntry (
34977424Smsmith    UINT16                  Opcode,
35067754Smsmith    UINT32                  Index,
35167754Smsmith    ACPI_WALK_STATE         *WalkState,
35267754Smsmith    ACPI_OPERAND_OBJECT     ***Entry)
35367754Smsmith{
35467754Smsmith
35567754Smsmith    FUNCTION_TRACE_U32 ("DsMethodDataGetEntry", Index);
35667754Smsmith
35767754Smsmith
35867754Smsmith    /*
35967754Smsmith     * Get the requested object.
36077424Smsmith     * The stack "Opcode" is either a LocalVariable or an Argument
36167754Smsmith     */
36267754Smsmith
36377424Smsmith    switch (Opcode)
36467754Smsmith    {
36567754Smsmith
36677424Smsmith    case AML_LOCAL_OP:
36767754Smsmith
36867754Smsmith        if (Index > MTH_MAX_LOCAL)
36967754Smsmith        {
37082367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "LocalVar index %d is invalid (max %d)\n",
37167754Smsmith                Index, MTH_MAX_LOCAL));
37267754Smsmith            return_ACPI_STATUS (AE_BAD_PARAMETER);
37367754Smsmith        }
37467754Smsmith
37577424Smsmith        *Entry = (ACPI_OPERAND_OBJECT  **)
37677424Smsmith                    &WalkState->LocalVariables[Index].Object;
37767754Smsmith        break;
37867754Smsmith
37967754Smsmith
38077424Smsmith    case AML_ARG_OP:
38167754Smsmith
38267754Smsmith        if (Index > MTH_MAX_ARG)
38367754Smsmith        {
38482367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Arg index %d is invalid (max %d)\n",
38567754Smsmith                Index, MTH_MAX_ARG));
38667754Smsmith            return_ACPI_STATUS (AE_BAD_PARAMETER);
38767754Smsmith        }
38867754Smsmith
38977424Smsmith        *Entry = (ACPI_OPERAND_OBJECT  **)
39077424Smsmith                    &WalkState->Arguments[Index].Object;
39167754Smsmith        break;
39267754Smsmith
39367754Smsmith
39467754Smsmith    default:
39582367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Opcode %d is invalid\n", Opcode));
39667754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
39767754Smsmith    }
39867754Smsmith
39967754Smsmith
40067754Smsmith    return_ACPI_STATUS (AE_OK);
40167754Smsmith}
40267754Smsmith
40367754Smsmith
40467754Smsmith/*******************************************************************************
40567754Smsmith *
40667754Smsmith * FUNCTION:    AcpiDsMethodDataSetEntry
40767754Smsmith *
40877424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
40967754Smsmith *              Index               - Which localVar or argument to get
41067754Smsmith *              Object              - Object to be inserted into the stack entry
41171867Smsmith *              WalkState           - Current walk state object
41267754Smsmith *
41367754Smsmith * RETURN:      Status
41467754Smsmith *
41577424Smsmith * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
41667754Smsmith *
41767754Smsmith ******************************************************************************/
41867754Smsmith
41967754SmsmithACPI_STATUS
42067754SmsmithAcpiDsMethodDataSetEntry (
42177424Smsmith    UINT16                  Opcode,
42267754Smsmith    UINT32                  Index,
42367754Smsmith    ACPI_OPERAND_OBJECT     *Object,
42467754Smsmith    ACPI_WALK_STATE         *WalkState)
42567754Smsmith{
42667754Smsmith    ACPI_STATUS             Status;
42767754Smsmith    ACPI_OPERAND_OBJECT     **Entry;
42867754Smsmith
42967754Smsmith
43067754Smsmith    FUNCTION_TRACE ("DsMethodDataSetEntry");
43167754Smsmith
43267754Smsmith    /* Get a pointer to the stack entry to set */
43367754Smsmith
43477424Smsmith    Status = AcpiDsMethodDataGetEntry (Opcode, Index, WalkState, &Entry);
43567754Smsmith    if (ACPI_FAILURE (Status))
43667754Smsmith    {
43767754Smsmith        return_ACPI_STATUS (Status);
43867754Smsmith    }
43967754Smsmith
44067754Smsmith    /* Increment ref count so object can't be deleted while installed */
44167754Smsmith
44277424Smsmith    AcpiUtAddReference (Object);
44367754Smsmith
44467754Smsmith    /* Install the object into the stack entry */
44567754Smsmith
44667754Smsmith    *Entry = Object;
44767754Smsmith
44867754Smsmith    return_ACPI_STATUS (AE_OK);
44967754Smsmith}
45067754Smsmith
45167754Smsmith
45267754Smsmith/*******************************************************************************
45367754Smsmith *
45467754Smsmith * FUNCTION:    AcpiDsMethodDataGetType
45567754Smsmith *
45677424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
45767754Smsmith *              Index               - Which localVar or argument whose type
45867754Smsmith *                                      to get
45971867Smsmith *              WalkState           - Current walk state object
46067754Smsmith *
46167754Smsmith * RETURN:      Data type of selected Arg or Local
46267754Smsmith *              Used only in ExecMonadic2()/TypeOp.
46367754Smsmith *
46467754Smsmith ******************************************************************************/
46567754Smsmith
46677424SmsmithACPI_OBJECT_TYPE8
46767754SmsmithAcpiDsMethodDataGetType (
46877424Smsmith    UINT16                  Opcode,
46967754Smsmith    UINT32                  Index,
47067754Smsmith    ACPI_WALK_STATE         *WalkState)
47167754Smsmith{
47267754Smsmith    ACPI_STATUS             Status;
47367754Smsmith    ACPI_OPERAND_OBJECT     **Entry;
47467754Smsmith    ACPI_OPERAND_OBJECT     *Object;
47567754Smsmith
47667754Smsmith
47767754Smsmith    FUNCTION_TRACE ("DsMethodDataGetType");
47867754Smsmith
47967754Smsmith
48067754Smsmith    /* Get a pointer to the requested stack entry */
48167754Smsmith
48277424Smsmith    Status = AcpiDsMethodDataGetEntry (Opcode, Index, WalkState, &Entry);
48367754Smsmith    if (ACPI_FAILURE (Status))
48467754Smsmith    {
48567754Smsmith        return_VALUE ((ACPI_TYPE_NOT_FOUND));
48667754Smsmith    }
48767754Smsmith
48867754Smsmith    /* Get the object from the method stack */
48967754Smsmith
49067754Smsmith    Object = *Entry;
49167754Smsmith
49267754Smsmith    /* Get the object type */
49367754Smsmith
49467754Smsmith    if (!Object)
49567754Smsmith    {
49667754Smsmith        /* Any == 0 => "uninitialized" -- see spec 15.2.3.5.2.28 */
49767754Smsmith        return_VALUE (ACPI_TYPE_ANY);
49867754Smsmith    }
49967754Smsmith
50067754Smsmith    return_VALUE (Object->Common.Type);
50167754Smsmith}
50267754Smsmith
50367754Smsmith
50467754Smsmith/*******************************************************************************
50567754Smsmith *
50677424Smsmith * FUNCTION:    AcpiDsMethodDataGetNode
50767754Smsmith *
50877424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
50967754Smsmith *              Index               - Which localVar or argument whose type
51067754Smsmith *                                      to get
51171867Smsmith *              WalkState           - Current walk state object
51267754Smsmith *
51367754Smsmith * RETURN:      Get the Node associated with a local or arg.
51467754Smsmith *
51567754Smsmith ******************************************************************************/
51667754Smsmith
51767754SmsmithACPI_NAMESPACE_NODE *
51877424SmsmithAcpiDsMethodDataGetNode (
51977424Smsmith    UINT16                  Opcode,
52067754Smsmith    UINT32                  Index,
52167754Smsmith    ACPI_WALK_STATE         *WalkState)
52267754Smsmith{
52367754Smsmith    ACPI_NAMESPACE_NODE     *Node = NULL;
52467754Smsmith
52567754Smsmith
52677424Smsmith    FUNCTION_TRACE ("DsMethodDataGetNode");
52767754Smsmith
52867754Smsmith
52977424Smsmith    switch (Opcode)
53067754Smsmith    {
53167754Smsmith
53277424Smsmith    case AML_LOCAL_OP:
53367754Smsmith
53467754Smsmith        if (Index > MTH_MAX_LOCAL)
53567754Smsmith        {
53682367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Local index %d is invalid (max %d)\n",
53767754Smsmith                Index, MTH_MAX_LOCAL));
53867754Smsmith            return_PTR (Node);
53967754Smsmith        }
54067754Smsmith
54167754Smsmith        Node =  &WalkState->LocalVariables[Index];
54267754Smsmith        break;
54367754Smsmith
54467754Smsmith
54577424Smsmith    case AML_ARG_OP:
54667754Smsmith
54767754Smsmith        if (Index > MTH_MAX_ARG)
54867754Smsmith        {
54982367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Arg index %d is invalid (max %d)\n",
55067754Smsmith                Index, MTH_MAX_ARG));
55167754Smsmith            return_PTR (Node);
55267754Smsmith        }
55367754Smsmith
55467754Smsmith        Node = &WalkState->Arguments[Index];
55567754Smsmith        break;
55667754Smsmith
55767754Smsmith
55867754Smsmith    default:
55982367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Opcode %d is invalid\n", Opcode));
56067754Smsmith        break;
56167754Smsmith    }
56267754Smsmith
56367754Smsmith
56467754Smsmith    return_PTR (Node);
56567754Smsmith}
56667754Smsmith
56767754Smsmith
56867754Smsmith/*******************************************************************************
56967754Smsmith *
57067754Smsmith * FUNCTION:    AcpiDsMethodDataGetValue
57167754Smsmith *
57277424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
57367754Smsmith *              Index               - Which localVar or argument to get
57471867Smsmith *              WalkState           - Current walk state object
57571867Smsmith *              *DestDesc           - Ptr to Descriptor into which selected Arg
57667754Smsmith *                                    or Local value should be copied
57767754Smsmith *
57867754Smsmith * RETURN:      Status
57967754Smsmith *
58067754Smsmith * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame
58167754Smsmith *              at the current top of the method stack.
58277424Smsmith *              Used only in AcpiExResolveToValue().
58367754Smsmith *
58467754Smsmith ******************************************************************************/
58567754Smsmith
58667754SmsmithACPI_STATUS
58767754SmsmithAcpiDsMethodDataGetValue (
58877424Smsmith    UINT16                  Opcode,
58967754Smsmith    UINT32                  Index,
59067754Smsmith    ACPI_WALK_STATE         *WalkState,
59167754Smsmith    ACPI_OPERAND_OBJECT     **DestDesc)
59267754Smsmith{
59367754Smsmith    ACPI_STATUS             Status;
59467754Smsmith    ACPI_OPERAND_OBJECT     **Entry;
59567754Smsmith    ACPI_OPERAND_OBJECT     *Object;
59667754Smsmith
59767754Smsmith
59867754Smsmith    FUNCTION_TRACE ("DsMethodDataGetValue");
59967754Smsmith
60067754Smsmith
60167754Smsmith    /* Validate the object descriptor */
60267754Smsmith
60367754Smsmith    if (!DestDesc)
60467754Smsmith    {
60582367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null object descriptor pointer\n"));
60667754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
60767754Smsmith    }
60867754Smsmith
60967754Smsmith
61067754Smsmith    /* Get a pointer to the requested method stack entry */
61167754Smsmith
61277424Smsmith    Status = AcpiDsMethodDataGetEntry (Opcode, Index, WalkState, &Entry);
61367754Smsmith    if (ACPI_FAILURE (Status))
61467754Smsmith    {
61567754Smsmith        return_ACPI_STATUS (Status);
61667754Smsmith    }
61767754Smsmith
61867754Smsmith    /* Get the object from the method stack */
61967754Smsmith
62067754Smsmith    Object = *Entry;
62167754Smsmith
62267754Smsmith
62367754Smsmith    /* Examine the returned object, it must be valid. */
62467754Smsmith
62567754Smsmith    if (!Object)
62667754Smsmith    {
62767754Smsmith        /*
62867754Smsmith         * Index points to uninitialized object stack value.
62967754Smsmith         * This means that either 1) The expected argument was
63067754Smsmith         * not passed to the method, or 2) A local variable
63167754Smsmith         * was referenced by the method (via the ASL)
63267754Smsmith         * before it was initialized.  Either case is an error.
63367754Smsmith         */
63467754Smsmith
63577424Smsmith        switch (Opcode)
63667754Smsmith        {
63777424Smsmith        case AML_ARG_OP:
63871867Smsmith
63982367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Arg[%d] at entry %p\n",
64067754Smsmith                Index, Entry));
64171867Smsmith
64267754Smsmith            return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
64367754Smsmith            break;
64467754Smsmith
64577424Smsmith        case AML_LOCAL_OP:
64671867Smsmith
64782367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Local[%d] at entry %p\n",
64867754Smsmith                Index, Entry));
64971867Smsmith
65067754Smsmith            return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
65167754Smsmith            break;
65267754Smsmith        }
65367754Smsmith    }
65467754Smsmith
65567754Smsmith
65667754Smsmith    /*
65767754Smsmith     * Index points to initialized and valid object stack value.
65867754Smsmith     * Return an additional reference to the object
65967754Smsmith     */
66067754Smsmith
66167754Smsmith    *DestDesc = Object;
66277424Smsmith    AcpiUtAddReference (Object);
66367754Smsmith
66467754Smsmith    return_ACPI_STATUS (AE_OK);
66567754Smsmith}
66667754Smsmith
66767754Smsmith
66867754Smsmith/*******************************************************************************
66967754Smsmith *
67067754Smsmith * FUNCTION:    AcpiDsMethodDataDeleteValue
67167754Smsmith *
67277424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
67367754Smsmith *              Index               - Which localVar or argument to delete
67471867Smsmith *              WalkState           - Current walk state object
67567754Smsmith *
67667754Smsmith * RETURN:      Status
67767754Smsmith *
67877424Smsmith * DESCRIPTION: Delete the entry at Opcode:Index on the method stack.  Inserts
67967754Smsmith *              a null into the stack slot after the object is deleted.
68067754Smsmith *
68167754Smsmith ******************************************************************************/
68267754Smsmith
68367754SmsmithACPI_STATUS
68467754SmsmithAcpiDsMethodDataDeleteValue (
68577424Smsmith    UINT16                  Opcode,
68667754Smsmith    UINT32                  Index,
68767754Smsmith    ACPI_WALK_STATE         *WalkState)
68867754Smsmith{
68967754Smsmith    ACPI_STATUS             Status;
69067754Smsmith    ACPI_OPERAND_OBJECT     **Entry;
69167754Smsmith    ACPI_OPERAND_OBJECT     *Object;
69267754Smsmith
69367754Smsmith
69467754Smsmith    FUNCTION_TRACE ("DsMethodDataDeleteValue");
69567754Smsmith
69667754Smsmith
69767754Smsmith    /* Get a pointer to the requested entry */
69867754Smsmith
69977424Smsmith    Status = AcpiDsMethodDataGetEntry (Opcode, Index, WalkState, &Entry);
70067754Smsmith    if (ACPI_FAILURE (Status))
70167754Smsmith    {
70267754Smsmith        return_ACPI_STATUS (Status);
70367754Smsmith    }
70467754Smsmith
70567754Smsmith    /* Get the current entry in this slot k */
70667754Smsmith
70767754Smsmith    Object = *Entry;
70867754Smsmith
70967754Smsmith    /*
71067754Smsmith     * Undefine the Arg or Local by setting its descriptor
71167754Smsmith     * pointer to NULL. Locals/Args can contain both
71267754Smsmith     * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
71367754Smsmith     */
71467754Smsmith    *Entry = NULL;
71567754Smsmith
71667754Smsmith
71767754Smsmith    if ((Object) &&
71867754Smsmith        (VALID_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_INTERNAL)))
71967754Smsmith    {
72067754Smsmith        /*
72167754Smsmith         * There is a valid object in this slot
72267754Smsmith         * Decrement the reference count by one to balance the
72367754Smsmith         * increment when the object was stored in the slot.
72467754Smsmith         */
72577424Smsmith        AcpiUtRemoveReference (Object);
72667754Smsmith    }
72767754Smsmith
72867754Smsmith
72967754Smsmith    return_ACPI_STATUS (AE_OK);
73067754Smsmith}
73167754Smsmith
73267754Smsmith
73367754Smsmith/*******************************************************************************
73467754Smsmith *
73577424Smsmith * FUNCTION:    AcpiDsStoreObjectToLocal
73667754Smsmith *
73777424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
73867754Smsmith *              Index               - Which localVar or argument to set
73971867Smsmith *              SrcDesc             - Value to be stored
74071867Smsmith *              WalkState           - Current walk state
74167754Smsmith *
74267754Smsmith * RETURN:      Status
74367754Smsmith *
74467754Smsmith * DESCRIPTION: Store a value in an Arg or Local.  The SrcDesc is installed
74567754Smsmith *              as the new value for the Arg or Local and the reference count
74671867Smsmith *              for SrcDesc is incremented.
74767754Smsmith *
74867754Smsmith ******************************************************************************/
74967754Smsmith
75067754SmsmithACPI_STATUS
75177424SmsmithAcpiDsStoreObjectToLocal (
75277424Smsmith    UINT16                  Opcode,
75367754Smsmith    UINT32                  Index,
75467754Smsmith    ACPI_OPERAND_OBJECT     *SrcDesc,
75567754Smsmith    ACPI_WALK_STATE         *WalkState)
75667754Smsmith{
75767754Smsmith    ACPI_STATUS             Status;
75867754Smsmith    ACPI_OPERAND_OBJECT     **Entry;
75967754Smsmith
76067754Smsmith
76167754Smsmith    FUNCTION_TRACE ("DsMethodDataSetValue");
76282367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode=%d Idx=%d Obj=%p\n",
76377424Smsmith        Opcode, Index, SrcDesc));
76467754Smsmith
76567754Smsmith
76667754Smsmith    /* Parameter validation */
76767754Smsmith
76867754Smsmith    if (!SrcDesc)
76967754Smsmith    {
77067754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
77167754Smsmith    }
77267754Smsmith
77367754Smsmith
77467754Smsmith    /* Get a pointer to the requested method stack entry */
77567754Smsmith
77677424Smsmith    Status = AcpiDsMethodDataGetEntry (Opcode, Index, WalkState, &Entry);
77767754Smsmith    if (ACPI_FAILURE (Status))
77867754Smsmith    {
77967754Smsmith        goto Cleanup;
78067754Smsmith    }
78167754Smsmith
78267754Smsmith    if (*Entry == SrcDesc)
78367754Smsmith    {
78482367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n", SrcDesc));
78567754Smsmith        goto Cleanup;
78667754Smsmith    }
78767754Smsmith
78867754Smsmith
78967754Smsmith    /*
79067754Smsmith     * If there is an object already in this slot, we either
79167754Smsmith     * have to delete it, or if this is an argument and there
79267754Smsmith     * is an object reference stored there, we have to do
79367754Smsmith     * an indirect store!
79467754Smsmith     */
79567754Smsmith
79667754Smsmith    if (*Entry)
79767754Smsmith    {
79867754Smsmith        /*
79967754Smsmith         * Check for an indirect store if an argument
80067754Smsmith         * contains an object reference (stored as an Node).
80167754Smsmith         * We don't allow this automatic dereferencing for
80267754Smsmith         * locals, since a store to a local should overwrite
80367754Smsmith         * anything there, including an object reference.
80467754Smsmith         *
80567754Smsmith         * If both Arg0 and Local0 contain RefOf (Local4):
80667754Smsmith         *
80767754Smsmith         * Store (1, Arg0)             - Causes indirect store to local4
80867754Smsmith         * Store (1, Local0)           - Stores 1 in local0, overwriting
80967754Smsmith         *                                  the reference to local4
81067754Smsmith         * Store (1, DeRefof (Local0)) - Causes indirect store to local4
81167754Smsmith         *
81267754Smsmith         * Weird, but true.
81367754Smsmith         */
81467754Smsmith
81577424Smsmith        if ((Opcode == AML_ARG_OP) &&
81667754Smsmith            (VALID_DESCRIPTOR_TYPE (*Entry, ACPI_DESC_TYPE_NAMED)))
81767754Smsmith        {
81882367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
81982367Smsmith                "Arg (%p) is an ObjRef(Node), storing in %p\n",
82067754Smsmith                SrcDesc, *Entry));
82167754Smsmith
82267754Smsmith            /* Detach an existing object from the Node */
82367754Smsmith
82467754Smsmith            AcpiNsDetachObject ((ACPI_NAMESPACE_NODE *) *Entry);
82567754Smsmith
82667754Smsmith            /*
82767754Smsmith             * Store this object into the Node
82867754Smsmith             * (do the indirect store)
82967754Smsmith             */
83067754Smsmith            Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) *Entry, SrcDesc,
83167754Smsmith                                            SrcDesc->Common.Type);
83267754Smsmith            return_ACPI_STATUS (Status);
83367754Smsmith        }
83467754Smsmith
83567754Smsmith
83677424Smsmith#ifdef ACPI_ENABLE_IMPLICIT_CONVERSION
83767754Smsmith        /*
83871867Smsmith         * Perform "Implicit conversion" of the new object to the type of the
83971867Smsmith         * existing object
84071867Smsmith         */
84177424Smsmith        Status = AcpiExConvertToTargetType ((*Entry)->Common.Type, &SrcDesc, WalkState);
84271867Smsmith        if (ACPI_FAILURE (Status))
84371867Smsmith        {
84471867Smsmith            goto Cleanup;
84571867Smsmith        }
84677424Smsmith#endif
84771867Smsmith
84871867Smsmith        /*
84971867Smsmith         * Delete the existing object
85067754Smsmith         * before storing the new one
85167754Smsmith         */
85277424Smsmith        AcpiDsMethodDataDeleteValue (Opcode, Index, WalkState);
85367754Smsmith    }
85467754Smsmith
85567754Smsmith
85667754Smsmith    /*
85767754Smsmith     * Install the ObjStack descriptor (*SrcDesc) into
85867754Smsmith     * the descriptor for the Arg or Local.
85967754Smsmith     * Install the new object in the stack entry
86067754Smsmith     * (increments the object reference count by one)
86167754Smsmith     */
86277424Smsmith    Status = AcpiDsMethodDataSetEntry (Opcode, Index, SrcDesc, WalkState);
86367754Smsmith    if (ACPI_FAILURE (Status))
86467754Smsmith    {
86567754Smsmith        goto Cleanup;
86667754Smsmith    }
86767754Smsmith
86867754Smsmith    /* Normal exit */
86967754Smsmith
87067754Smsmith    return_ACPI_STATUS (AE_OK);
87167754Smsmith
87267754Smsmith
87367754Smsmith    /* Error exit */
87467754Smsmith
87567754SmsmithCleanup:
87667754Smsmith
87767754Smsmith    return_ACPI_STATUS (Status);
87867754Smsmith}
87967754Smsmith
880