dsmthdat.c revision 70243
167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: dsmthdat - control method arguments and local variables
470243Smsmith *              $Revision: 37 $
567754Smsmith *
667754Smsmith ******************************************************************************/
767754Smsmith
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
1270243Smsmith * Some or all of this work - Copyright (c) 1999, 2000, 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
12767754Smsmith#define _COMPONENT          DISPATCHER
12867754Smsmith        MODULE_NAME         ("dsmthdat")
12967754Smsmith
13067754Smsmith
13167754Smsmith/*******************************************************************************
13267754Smsmith *
13367754Smsmith * FUNCTION:    AcpiDsMethodDataInit
13467754Smsmith *
13567754Smsmith * PARAMETERS:  *ObjDesc
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
15767754Smsmith     * AcpiCmCallocate().
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 *
19667754Smsmith * PARAMETERS:  None
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
21867754Smsmith    DEBUG_PRINT (ACPI_INFO,
21967754Smsmith        ("MethodDeleteAll: Deleting local variables in %p\n", WalkState));
22067754Smsmith
22167754Smsmith    for (Index = 0; Index < MTH_NUM_LOCALS; Index++)
22267754Smsmith    {
22367754Smsmith        Object = WalkState->LocalVariables[Index].Object;
22467754Smsmith        if (Object)
22567754Smsmith        {
22667754Smsmith            DEBUG_PRINT (TRACE_EXEC,
22767754Smsmith                ("MethodDeleteAll: Deleting Local%d=%p\n", Index, Object));
22867754Smsmith
22967754Smsmith            /* Remove first */
23067754Smsmith
23167754Smsmith            WalkState->LocalVariables[Index].Object = NULL;
23267754Smsmith
23367754Smsmith            /* Was given a ref when stored */
23467754Smsmith
23567754Smsmith            AcpiCmRemoveReference (Object);
23667754Smsmith       }
23767754Smsmith    }
23867754Smsmith
23967754Smsmith
24067754Smsmith    /* Delete the arguments */
24167754Smsmith
24267754Smsmith    DEBUG_PRINT (ACPI_INFO,
24367754Smsmith        ("MethodDeleteAll: Deleting arguments in %p\n", WalkState));
24467754Smsmith
24567754Smsmith    for (Index = 0; Index < MTH_NUM_ARGS; Index++)
24667754Smsmith    {
24767754Smsmith        Object = WalkState->Arguments[Index].Object;
24867754Smsmith        if (Object)
24967754Smsmith        {
25067754Smsmith            DEBUG_PRINT (TRACE_EXEC,
25167754Smsmith                ("MethodDeleteAll: Deleting Arg%d=%p\n", Index, Object));
25267754Smsmith
25367754Smsmith            /* Remove first */
25467754Smsmith
25567754Smsmith            WalkState->Arguments[Index].Object = NULL;
25667754Smsmith
25767754Smsmith             /* Was given a ref when stored */
25867754Smsmith
25967754Smsmith            AcpiCmRemoveReference (Object);
26067754Smsmith        }
26167754Smsmith    }
26267754Smsmith
26367754Smsmith    return_ACPI_STATUS (AE_OK);
26467754Smsmith}
26567754Smsmith
26667754Smsmith
26767754Smsmith/*******************************************************************************
26867754Smsmith *
26967754Smsmith * FUNCTION:    AcpiDsMethodDataInitArgs
27067754Smsmith *
27167754Smsmith * PARAMETERS:  None
27267754Smsmith *
27367754Smsmith * RETURN:      Status
27467754Smsmith *
27567754Smsmith * DESCRIPTION: Initialize arguments for a method
27667754Smsmith *
27767754Smsmith ******************************************************************************/
27867754Smsmith
27967754SmsmithACPI_STATUS
28067754SmsmithAcpiDsMethodDataInitArgs (
28167754Smsmith    ACPI_OPERAND_OBJECT     **Params,
28267754Smsmith    UINT32                  MaxParamCount,
28367754Smsmith    ACPI_WALK_STATE         *WalkState)
28467754Smsmith{
28567754Smsmith    ACPI_STATUS             Status;
28667754Smsmith    UINT32                  Mindex;
28767754Smsmith    UINT32                  Pindex;
28867754Smsmith
28967754Smsmith
29067754Smsmith    FUNCTION_TRACE_PTR ("DsMethodDataInitArgs", Params);
29167754Smsmith
29267754Smsmith
29367754Smsmith    if (!Params)
29467754Smsmith    {
29567754Smsmith        DEBUG_PRINT (TRACE_EXEC,
29667754Smsmith            ("DsMethodDataInitArgs: No param list passed to method\n"));
29767754Smsmith        return_ACPI_STATUS (AE_OK);
29867754Smsmith    }
29967754Smsmith
30067754Smsmith    /* Copy passed parameters into the new method stack frame  */
30167754Smsmith
30267754Smsmith    for (Pindex = Mindex = 0;
30367754Smsmith        (Mindex < MTH_NUM_ARGS) && (Pindex < MaxParamCount);
30467754Smsmith        Mindex++)
30567754Smsmith    {
30667754Smsmith        if (Params[Pindex])
30767754Smsmith        {
30867754Smsmith            /*
30967754Smsmith             * A valid parameter.
31067754Smsmith             * Set the current method argument to the
31167754Smsmith             * Params[Pindex++] argument object descriptor
31267754Smsmith             */
31367754Smsmith            Status = AcpiDsMethodDataSetValue (MTH_TYPE_ARG, Mindex,
31467754Smsmith                                                Params[Pindex], WalkState);
31567754Smsmith            if (ACPI_FAILURE (Status))
31667754Smsmith            {
31767754Smsmith                break;
31867754Smsmith            }
31967754Smsmith
32067754Smsmith            Pindex++;
32167754Smsmith        }
32267754Smsmith
32367754Smsmith        else
32467754Smsmith        {
32567754Smsmith            break;
32667754Smsmith        }
32767754Smsmith    }
32867754Smsmith
32967754Smsmith    DEBUG_PRINT (TRACE_EXEC,
33067754Smsmith        ("DsMethodDataInitArgs: %d args passed to method\n", Pindex));
33167754Smsmith    return_ACPI_STATUS (AE_OK);
33267754Smsmith}
33367754Smsmith
33467754Smsmith
33567754Smsmith/*******************************************************************************
33667754Smsmith *
33767754Smsmith * FUNCTION:    AcpiDsMethodDataGetEntry
33867754Smsmith *
33967754Smsmith * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
34067754Smsmith *              Index               - Which localVar or argument to get
34167754Smsmith *              Entry               - Pointer to where a pointer to the stack
34267754Smsmith *                                    entry is returned.
34367754Smsmith *
34467754Smsmith * RETURN:      Status
34567754Smsmith *
34667754Smsmith * DESCRIPTION: Get the address of the stack entry given by Type:Index
34767754Smsmith *
34867754Smsmith ******************************************************************************/
34967754Smsmith
35067754SmsmithACPI_STATUS
35167754SmsmithAcpiDsMethodDataGetEntry (
35267754Smsmith    UINT32                  Type,
35367754Smsmith    UINT32                  Index,
35467754Smsmith    ACPI_WALK_STATE         *WalkState,
35567754Smsmith    ACPI_OPERAND_OBJECT     ***Entry)
35667754Smsmith{
35767754Smsmith
35867754Smsmith    FUNCTION_TRACE_U32 ("DsMethodDataGetEntry", Index);
35967754Smsmith
36067754Smsmith
36167754Smsmith    /*
36267754Smsmith     * Get the requested object.
36367754Smsmith     * The stack "Type" is either a LocalVariable or an Argument
36467754Smsmith     */
36567754Smsmith
36667754Smsmith    switch (Type)
36767754Smsmith    {
36867754Smsmith
36967754Smsmith    case MTH_TYPE_LOCAL:
37067754Smsmith
37167754Smsmith        if (Index > MTH_MAX_LOCAL)
37267754Smsmith        {
37367754Smsmith            DEBUG_PRINT (ACPI_ERROR,
37467754Smsmith                ("DsMethodDataGetEntry: LocalVar index %d is invalid (max %d)\n",
37567754Smsmith                Index, MTH_MAX_LOCAL));
37667754Smsmith            return_ACPI_STATUS (AE_BAD_PARAMETER);
37767754Smsmith        }
37867754Smsmith
37967754Smsmith        *Entry =
38067754Smsmith            (ACPI_OPERAND_OBJECT  **) &WalkState->LocalVariables[Index].Object;
38167754Smsmith        break;
38267754Smsmith
38367754Smsmith
38467754Smsmith    case MTH_TYPE_ARG:
38567754Smsmith
38667754Smsmith        if (Index > MTH_MAX_ARG)
38767754Smsmith        {
38867754Smsmith            DEBUG_PRINT (ACPI_ERROR,
38967754Smsmith                ("DsMethodDataGetEntry: Argument index %d is invalid (max %d)\n",
39067754Smsmith                Index, MTH_MAX_ARG));
39167754Smsmith            return_ACPI_STATUS (AE_BAD_PARAMETER);
39267754Smsmith        }
39367754Smsmith
39467754Smsmith        *Entry =
39567754Smsmith            (ACPI_OPERAND_OBJECT  **) &WalkState->Arguments[Index].Object;
39667754Smsmith        break;
39767754Smsmith
39867754Smsmith
39967754Smsmith    default:
40067754Smsmith        DEBUG_PRINT (ACPI_ERROR,
40167754Smsmith            ("DsMethodDataGetEntry: Stack type %d is invalid\n",
40267754Smsmith            Type));
40367754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
40467754Smsmith    }
40567754Smsmith
40667754Smsmith
40767754Smsmith    return_ACPI_STATUS (AE_OK);
40867754Smsmith}
40967754Smsmith
41067754Smsmith
41167754Smsmith/*******************************************************************************
41267754Smsmith *
41367754Smsmith * FUNCTION:    AcpiDsMethodDataSetEntry
41467754Smsmith *
41567754Smsmith * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
41667754Smsmith *              Index               - Which localVar or argument to get
41767754Smsmith *              Object              - Object to be inserted into the stack entry
41867754Smsmith *
41967754Smsmith * RETURN:      Status
42067754Smsmith *
42167754Smsmith * DESCRIPTION: Insert an object onto the method stack at entry Type:Index.
42267754Smsmith *
42367754Smsmith ******************************************************************************/
42467754Smsmith
42567754SmsmithACPI_STATUS
42667754SmsmithAcpiDsMethodDataSetEntry (
42767754Smsmith    UINT32                  Type,
42867754Smsmith    UINT32                  Index,
42967754Smsmith    ACPI_OPERAND_OBJECT     *Object,
43067754Smsmith    ACPI_WALK_STATE         *WalkState)
43167754Smsmith{
43267754Smsmith    ACPI_STATUS             Status;
43367754Smsmith    ACPI_OPERAND_OBJECT     **Entry;
43467754Smsmith
43567754Smsmith
43667754Smsmith    FUNCTION_TRACE ("DsMethodDataSetEntry");
43767754Smsmith
43867754Smsmith    /* Get a pointer to the stack entry to set */
43967754Smsmith
44067754Smsmith    Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry);
44167754Smsmith    if (ACPI_FAILURE (Status))
44267754Smsmith    {
44367754Smsmith        return_ACPI_STATUS (Status);
44467754Smsmith    }
44567754Smsmith
44667754Smsmith    /* Increment ref count so object can't be deleted while installed */
44767754Smsmith
44867754Smsmith    AcpiCmAddReference (Object);
44967754Smsmith
45067754Smsmith    /* Install the object into the stack entry */
45167754Smsmith
45267754Smsmith    *Entry = Object;
45367754Smsmith
45467754Smsmith    return_ACPI_STATUS (AE_OK);
45567754Smsmith}
45667754Smsmith
45767754Smsmith
45867754Smsmith/*******************************************************************************
45967754Smsmith *
46067754Smsmith * FUNCTION:    AcpiDsMethodDataGetType
46167754Smsmith *
46267754Smsmith * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
46367754Smsmith *              Index               - Which localVar or argument whose type
46467754Smsmith *                                      to get
46567754Smsmith *
46667754Smsmith * RETURN:      Data type of selected Arg or Local
46767754Smsmith *              Used only in ExecMonadic2()/TypeOp.
46867754Smsmith *
46967754Smsmith ******************************************************************************/
47067754Smsmith
47167754SmsmithOBJECT_TYPE_INTERNAL
47267754SmsmithAcpiDsMethodDataGetType (
47367754Smsmith    UINT32                  Type,
47467754Smsmith    UINT32                  Index,
47567754Smsmith    ACPI_WALK_STATE         *WalkState)
47667754Smsmith{
47767754Smsmith    ACPI_STATUS             Status;
47867754Smsmith    ACPI_OPERAND_OBJECT     **Entry;
47967754Smsmith    ACPI_OPERAND_OBJECT     *Object;
48067754Smsmith
48167754Smsmith
48267754Smsmith    FUNCTION_TRACE ("DsMethodDataGetType");
48367754Smsmith
48467754Smsmith
48567754Smsmith    /* Get a pointer to the requested stack entry */
48667754Smsmith
48767754Smsmith    Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry);
48867754Smsmith    if (ACPI_FAILURE (Status))
48967754Smsmith    {
49067754Smsmith        return_VALUE ((ACPI_TYPE_NOT_FOUND));
49167754Smsmith    }
49267754Smsmith
49367754Smsmith    /* Get the object from the method stack */
49467754Smsmith
49567754Smsmith    Object = *Entry;
49667754Smsmith
49767754Smsmith    /* Get the object type */
49867754Smsmith
49967754Smsmith    if (!Object)
50067754Smsmith    {
50167754Smsmith        /* Any == 0 => "uninitialized" -- see spec 15.2.3.5.2.28 */
50267754Smsmith        return_VALUE (ACPI_TYPE_ANY);
50367754Smsmith    }
50467754Smsmith
50567754Smsmith    return_VALUE (Object->Common.Type);
50667754Smsmith}
50767754Smsmith
50867754Smsmith
50967754Smsmith/*******************************************************************************
51067754Smsmith *
51167754Smsmith * FUNCTION:    AcpiDsMethodDataGetNte
51267754Smsmith *
51367754Smsmith * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
51467754Smsmith *              Index               - Which localVar or argument whose type
51567754Smsmith *                                      to get
51667754Smsmith *
51767754Smsmith * RETURN:      Get the Node associated with a local or arg.
51867754Smsmith *
51967754Smsmith ******************************************************************************/
52067754Smsmith
52167754SmsmithACPI_NAMESPACE_NODE *
52267754SmsmithAcpiDsMethodDataGetNte (
52367754Smsmith    UINT32                  Type,
52467754Smsmith    UINT32                  Index,
52567754Smsmith    ACPI_WALK_STATE         *WalkState)
52667754Smsmith{
52767754Smsmith    ACPI_NAMESPACE_NODE     *Node = NULL;
52867754Smsmith
52967754Smsmith
53067754Smsmith    FUNCTION_TRACE ("DsMethodDataGetNte");
53167754Smsmith
53267754Smsmith
53367754Smsmith    switch (Type)
53467754Smsmith    {
53567754Smsmith
53667754Smsmith    case MTH_TYPE_LOCAL:
53767754Smsmith
53867754Smsmith        if (Index > MTH_MAX_LOCAL)
53967754Smsmith        {
54067754Smsmith            DEBUG_PRINT (ACPI_ERROR,
54167754Smsmith                ("DsMethodDataGetEntry: LocalVar index %d is invalid (max %d)\n",
54267754Smsmith                Index, MTH_MAX_LOCAL));
54367754Smsmith            return_PTR (Node);
54467754Smsmith        }
54567754Smsmith
54667754Smsmith        Node =  &WalkState->LocalVariables[Index];
54767754Smsmith        break;
54867754Smsmith
54967754Smsmith
55067754Smsmith    case MTH_TYPE_ARG:
55167754Smsmith
55267754Smsmith        if (Index > MTH_MAX_ARG)
55367754Smsmith        {
55467754Smsmith            DEBUG_PRINT (ACPI_ERROR,
55567754Smsmith                ("DsMethodDataGetEntry: Argument index %d is invalid (max %d)\n",
55667754Smsmith                Index, MTH_MAX_ARG));
55767754Smsmith            return_PTR (Node);
55867754Smsmith        }
55967754Smsmith
56067754Smsmith        Node = &WalkState->Arguments[Index];
56167754Smsmith        break;
56267754Smsmith
56367754Smsmith
56467754Smsmith    default:
56567754Smsmith        DEBUG_PRINT (ACPI_ERROR,
56667754Smsmith            ("DsMethodDataGetEntry: Stack type %d is invalid\n",
56767754Smsmith            Type));
56867754Smsmith        break;
56967754Smsmith    }
57067754Smsmith
57167754Smsmith
57267754Smsmith    return_PTR (Node);
57367754Smsmith}
57467754Smsmith
57567754Smsmith
57667754Smsmith/*******************************************************************************
57767754Smsmith *
57867754Smsmith * FUNCTION:    AcpiDsMethodDataGetValue
57967754Smsmith *
58067754Smsmith * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
58167754Smsmith *              Index               - Which localVar or argument to get
58267754Smsmith *              *DestDesc            - Descriptor into which selected Arg
58367754Smsmith *                                    or Local value should be copied
58467754Smsmith *
58567754Smsmith * RETURN:      Status
58667754Smsmith *
58767754Smsmith * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame
58867754Smsmith *              at the current top of the method stack.
58967754Smsmith *              Used only in AcpiAmlResolveToValue().
59067754Smsmith *
59167754Smsmith ******************************************************************************/
59267754Smsmith
59367754SmsmithACPI_STATUS
59467754SmsmithAcpiDsMethodDataGetValue (
59567754Smsmith    UINT32                  Type,
59667754Smsmith    UINT32                  Index,
59767754Smsmith    ACPI_WALK_STATE         *WalkState,
59867754Smsmith    ACPI_OPERAND_OBJECT     **DestDesc)
59967754Smsmith{
60067754Smsmith    ACPI_STATUS             Status;
60167754Smsmith    ACPI_OPERAND_OBJECT     **Entry;
60267754Smsmith    ACPI_OPERAND_OBJECT     *Object;
60367754Smsmith
60467754Smsmith
60567754Smsmith    FUNCTION_TRACE ("DsMethodDataGetValue");
60667754Smsmith
60767754Smsmith
60867754Smsmith    /* Validate the object descriptor */
60967754Smsmith
61067754Smsmith    if (!DestDesc)
61167754Smsmith    {
61267754Smsmith        DEBUG_PRINT (ACPI_ERROR,
61367754Smsmith            ("DsMethodDataGetValue: NULL object descriptor pointer\n"));
61467754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
61567754Smsmith    }
61667754Smsmith
61767754Smsmith
61867754Smsmith    /* Get a pointer to the requested method stack entry */
61967754Smsmith
62067754Smsmith    Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry);
62167754Smsmith    if (ACPI_FAILURE (Status))
62267754Smsmith    {
62367754Smsmith        return_ACPI_STATUS (Status);
62467754Smsmith    }
62567754Smsmith
62667754Smsmith    /* Get the object from the method stack */
62767754Smsmith
62867754Smsmith    Object = *Entry;
62967754Smsmith
63067754Smsmith
63167754Smsmith    /* Examine the returned object, it must be valid. */
63267754Smsmith
63367754Smsmith    if (!Object)
63467754Smsmith    {
63567754Smsmith        /*
63667754Smsmith         * Index points to uninitialized object stack value.
63767754Smsmith         * This means that either 1) The expected argument was
63867754Smsmith         * not passed to the method, or 2) A local variable
63967754Smsmith         * was referenced by the method (via the ASL)
64067754Smsmith         * before it was initialized.  Either case is an error.
64167754Smsmith         */
64267754Smsmith
64367754Smsmith        switch (Type)
64467754Smsmith        {
64567754Smsmith        case MTH_TYPE_ARG:
64667754Smsmith            DEBUG_PRINT (ACPI_ERROR,
64769746Smsmith                ("DsMethodDataGetValue: Uninitialized Arg[%d] at entry %p\n",
64867754Smsmith                Index, Entry));
64967754Smsmith            return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
65067754Smsmith            break;
65167754Smsmith
65267754Smsmith        case MTH_TYPE_LOCAL:
65367754Smsmith            DEBUG_PRINT (ACPI_ERROR,
65469746Smsmith                ("DsMethodDataGetValue: Uninitialized Local[%d] at entry %p\n",
65567754Smsmith                Index, Entry));
65667754Smsmith            return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
65767754Smsmith            break;
65867754Smsmith        }
65967754Smsmith    }
66067754Smsmith
66167754Smsmith
66267754Smsmith    /*
66367754Smsmith     * Index points to initialized and valid object stack value.
66467754Smsmith     * Return an additional reference to the object
66567754Smsmith     */
66667754Smsmith
66767754Smsmith    *DestDesc = Object;
66867754Smsmith    AcpiCmAddReference (Object);
66967754Smsmith
67067754Smsmith    return_ACPI_STATUS (AE_OK);
67167754Smsmith}
67267754Smsmith
67367754Smsmith
67467754Smsmith/*******************************************************************************
67567754Smsmith *
67667754Smsmith * FUNCTION:    AcpiDsMethodDataDeleteValue
67767754Smsmith *
67867754Smsmith * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
67967754Smsmith *              Index               - Which localVar or argument to delete
68067754Smsmith *
68167754Smsmith * RETURN:      Status
68267754Smsmith *
68367754Smsmith * DESCRIPTION: Delete the entry at Type:Index on the method stack.  Inserts
68467754Smsmith *              a null into the stack slot after the object is deleted.
68567754Smsmith *
68667754Smsmith ******************************************************************************/
68767754Smsmith
68867754SmsmithACPI_STATUS
68967754SmsmithAcpiDsMethodDataDeleteValue (
69067754Smsmith    UINT32                  Type,
69167754Smsmith    UINT32                  Index,
69267754Smsmith    ACPI_WALK_STATE         *WalkState)
69367754Smsmith{
69467754Smsmith    ACPI_STATUS             Status;
69567754Smsmith    ACPI_OPERAND_OBJECT     **Entry;
69667754Smsmith    ACPI_OPERAND_OBJECT     *Object;
69767754Smsmith
69867754Smsmith
69967754Smsmith    FUNCTION_TRACE ("DsMethodDataDeleteValue");
70067754Smsmith
70167754Smsmith
70267754Smsmith    /* Get a pointer to the requested entry */
70367754Smsmith
70467754Smsmith    Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry);
70567754Smsmith    if (ACPI_FAILURE (Status))
70667754Smsmith    {
70767754Smsmith        return_ACPI_STATUS (Status);
70867754Smsmith    }
70967754Smsmith
71067754Smsmith    /* Get the current entry in this slot k */
71167754Smsmith
71267754Smsmith    Object = *Entry;
71367754Smsmith
71467754Smsmith    /*
71567754Smsmith     * Undefine the Arg or Local by setting its descriptor
71667754Smsmith     * pointer to NULL. Locals/Args can contain both
71767754Smsmith     * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
71867754Smsmith     */
71967754Smsmith    *Entry = NULL;
72067754Smsmith
72167754Smsmith
72267754Smsmith    if ((Object) &&
72367754Smsmith        (VALID_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_INTERNAL)))
72467754Smsmith    {
72567754Smsmith        /*
72667754Smsmith         * There is a valid object in this slot
72767754Smsmith         * Decrement the reference count by one to balance the
72867754Smsmith         * increment when the object was stored in the slot.
72967754Smsmith         */
73067754Smsmith
73167754Smsmith        AcpiCmRemoveReference (Object);
73267754Smsmith    }
73367754Smsmith
73467754Smsmith
73567754Smsmith    return_ACPI_STATUS (AE_OK);
73667754Smsmith}
73767754Smsmith
73867754Smsmith
73967754Smsmith/*******************************************************************************
74067754Smsmith *
74167754Smsmith * FUNCTION:    AcpiDsMethodDataSetValue
74267754Smsmith *
74367754Smsmith * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
74467754Smsmith *              Index               - Which localVar or argument to set
74567754Smsmith *              *SrcDesc            - Value to be stored
74667754Smsmith *              *DestDesc           - Descriptor into which *SrcDesc
74767754Smsmith *                                    can be copied, or NULL if one must
74867754Smsmith *                                    be allocated for the purpose.  If
74967754Smsmith *                                    provided, this descriptor will be
75067754Smsmith *                                    used for the new value.
75167754Smsmith *
75267754Smsmith * RETURN:      Status
75367754Smsmith *
75467754Smsmith * DESCRIPTION: Store a value in an Arg or Local.  The SrcDesc is installed
75567754Smsmith *              as the new value for the Arg or Local and the reference count
75667754Smsmith *              is incremented.
75767754Smsmith *
75867754Smsmith ******************************************************************************/
75967754Smsmith
76067754SmsmithACPI_STATUS
76167754SmsmithAcpiDsMethodDataSetValue (
76267754Smsmith    UINT32                  Type,
76367754Smsmith    UINT32                  Index,
76467754Smsmith    ACPI_OPERAND_OBJECT     *SrcDesc,
76567754Smsmith    ACPI_WALK_STATE         *WalkState)
76667754Smsmith{
76767754Smsmith    ACPI_STATUS             Status;
76867754Smsmith    ACPI_OPERAND_OBJECT     **Entry;
76967754Smsmith
77067754Smsmith
77167754Smsmith    FUNCTION_TRACE ("DsMethodDataSetValue");
77267754Smsmith    DEBUG_PRINT (TRACE_EXEC,
77367754Smsmith        ("DsMethodDataSetValue: Type=%d Idx=%d Obj=%p\n",
77467754Smsmith        Type, Index, SrcDesc));
77567754Smsmith
77667754Smsmith
77767754Smsmith    /* Parameter validation */
77867754Smsmith
77967754Smsmith    if (!SrcDesc)
78067754Smsmith    {
78167754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
78267754Smsmith    }
78367754Smsmith
78467754Smsmith
78567754Smsmith    /* Get a pointer to the requested method stack entry */
78667754Smsmith
78767754Smsmith    Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry);
78867754Smsmith    if (ACPI_FAILURE (Status))
78967754Smsmith    {
79067754Smsmith        goto Cleanup;
79167754Smsmith    }
79267754Smsmith
79367754Smsmith    if (*Entry == SrcDesc)
79467754Smsmith    {
79567754Smsmith        DEBUG_PRINT (TRACE_EXEC,
79667754Smsmith            ("DsMethodDataSetValue: Obj=%p already installed!\n",
79767754Smsmith            SrcDesc));
79867754Smsmith        goto Cleanup;
79967754Smsmith    }
80067754Smsmith
80167754Smsmith
80267754Smsmith    /*
80367754Smsmith     * If there is an object already in this slot, we either
80467754Smsmith     * have to delete it, or if this is an argument and there
80567754Smsmith     * is an object reference stored there, we have to do
80667754Smsmith     * an indirect store!
80767754Smsmith     */
80867754Smsmith
80967754Smsmith    if (*Entry)
81067754Smsmith    {
81167754Smsmith        /*
81267754Smsmith         * Check for an indirect store if an argument
81367754Smsmith         * contains an object reference (stored as an Node).
81467754Smsmith         * We don't allow this automatic dereferencing for
81567754Smsmith         * locals, since a store to a local should overwrite
81667754Smsmith         * anything there, including an object reference.
81767754Smsmith         *
81867754Smsmith         * If both Arg0 and Local0 contain RefOf (Local4):
81967754Smsmith         *
82067754Smsmith         * Store (1, Arg0)             - Causes indirect store to local4
82167754Smsmith         * Store (1, Local0)           - Stores 1 in local0, overwriting
82267754Smsmith         *                                  the reference to local4
82367754Smsmith         * Store (1, DeRefof (Local0)) - Causes indirect store to local4
82467754Smsmith         *
82567754Smsmith         * Weird, but true.
82667754Smsmith         */
82767754Smsmith
82867754Smsmith        if ((Type == MTH_TYPE_ARG) &&
82967754Smsmith            (VALID_DESCRIPTOR_TYPE (*Entry, ACPI_DESC_TYPE_NAMED)))
83067754Smsmith        {
83167754Smsmith            DEBUG_PRINT (TRACE_EXEC,
83267754Smsmith                ("DsMethodDataSetValue: Arg (%p) is an ObjRef(Node), storing in %p\n",
83367754Smsmith                SrcDesc, *Entry));
83467754Smsmith
83567754Smsmith            /* Detach an existing object from the Node */
83667754Smsmith
83767754Smsmith            AcpiNsDetachObject ((ACPI_NAMESPACE_NODE *) *Entry);
83867754Smsmith
83967754Smsmith            /*
84067754Smsmith             * Store this object into the Node
84167754Smsmith             * (do the indirect store)
84267754Smsmith             */
84367754Smsmith
84467754Smsmith            Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) *Entry, SrcDesc,
84567754Smsmith                                            SrcDesc->Common.Type);
84667754Smsmith            return_ACPI_STATUS (Status);
84767754Smsmith        }
84867754Smsmith
84967754Smsmith
85067754Smsmith        /*
85167754Smsmith         * Otherwise, just delete the existing object
85267754Smsmith         * before storing the new one
85367754Smsmith         */
85467754Smsmith
85567754Smsmith        AcpiDsMethodDataDeleteValue (Type, Index, WalkState);
85667754Smsmith    }
85767754Smsmith
85867754Smsmith
85967754Smsmith    /*
86067754Smsmith     * Install the ObjStack descriptor (*SrcDesc) into
86167754Smsmith     * the descriptor for the Arg or Local.
86267754Smsmith     * Install the new object in the stack entry
86367754Smsmith     * (increments the object reference count by one)
86467754Smsmith     */
86567754Smsmith
86667754Smsmith    Status = AcpiDsMethodDataSetEntry (Type, Index, SrcDesc, WalkState);
86767754Smsmith    if (ACPI_FAILURE (Status))
86867754Smsmith    {
86967754Smsmith        goto Cleanup;
87067754Smsmith    }
87167754Smsmith
87267754Smsmith    /* Normal exit */
87367754Smsmith
87467754Smsmith    return_ACPI_STATUS (AE_OK);
87567754Smsmith
87667754Smsmith
87767754Smsmith    /* Error exit */
87867754Smsmith
87967754SmsmithCleanup:
88067754Smsmith
88167754Smsmith    return_ACPI_STATUS (Status);
88267754Smsmith}
88367754Smsmith
884