dsmthdat.c revision 151937
167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: dsmthdat - control method arguments and local variables
4151937Sjkim *              $Revision: 1.85 $
567754Smsmith *
667754Smsmith ******************************************************************************/
767754Smsmith
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
12151937Sjkim * Some or all of this work - Copyright (c) 1999 - 2005, 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
119151600Sobrien#include <contrib/dev/acpica/acpi.h>
120151600Sobrien#include <contrib/dev/acpica/acdispat.h>
121151600Sobrien#include <contrib/dev/acpica/amlcode.h>
122151600Sobrien#include <contrib/dev/acpica/acnamesp.h>
123151600Sobrien#include <contrib/dev/acpica/acinterp.h>
12467754Smsmith
12567754Smsmith
12677424Smsmith#define _COMPONENT          ACPI_DISPATCHER
12791116Smsmith        ACPI_MODULE_NAME    ("dsmthdat")
12867754Smsmith
129151937Sjkim/* Local prototypes */
13067754Smsmith
131151937Sjkimstatic void
132151937SjkimAcpiDsMethodDataDeleteValue (
133151937Sjkim    UINT16                  Opcode,
134151937Sjkim    UINT32                  Index,
135151937Sjkim    ACPI_WALK_STATE         *WalkState);
136151937Sjkim
137151937Sjkimstatic ACPI_STATUS
138151937SjkimAcpiDsMethodDataSetValue (
139151937Sjkim    UINT16                  Opcode,
140151937Sjkim    UINT32                  Index,
141151937Sjkim    ACPI_OPERAND_OBJECT     *Object,
142151937Sjkim    ACPI_WALK_STATE         *WalkState);
143151937Sjkim
144151937Sjkim#ifdef ACPI_OBSOLETE_FUNCTIONS
145151937SjkimACPI_OBJECT_TYPE
146151937SjkimAcpiDsMethodDataGetType (
147151937Sjkim    UINT16                  Opcode,
148151937Sjkim    UINT32                  Index,
149151937Sjkim    ACPI_WALK_STATE         *WalkState);
150151937Sjkim#endif
151151937Sjkim
152151937Sjkim
15367754Smsmith/*******************************************************************************
15467754Smsmith *
15567754Smsmith * FUNCTION:    AcpiDsMethodDataInit
15667754Smsmith *
15771867Smsmith * PARAMETERS:  WalkState           - Current walk state object
15867754Smsmith *
15967754Smsmith * RETURN:      Status
16067754Smsmith *
16167754Smsmith * DESCRIPTION: Initialize the data structures that hold the method's arguments
162151937Sjkim *              and locals.  The data struct is an array of namespace nodes for
163151937Sjkim *              each - this allows RefOf and DeRefOf to work properly for these
16467754Smsmith *              special data types.
16567754Smsmith *
16687031Smsmith * NOTES:       WalkState fields are initialized to zero by the
16787031Smsmith *              ACPI_MEM_CALLOCATE().
16887031Smsmith *
16987031Smsmith *              A pseudo-Namespace Node is assigned to each argument and local
17087031Smsmith *              so that RefOf() can return a pointer to the Node.
17187031Smsmith *
17267754Smsmith ******************************************************************************/
17367754Smsmith
17499679Siwasakivoid
17567754SmsmithAcpiDsMethodDataInit (
17667754Smsmith    ACPI_WALK_STATE         *WalkState)
17767754Smsmith{
17867754Smsmith    UINT32                  i;
17967754Smsmith
18067754Smsmith
18191116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataInit");
18267754Smsmith
18367754Smsmith
18467754Smsmith    /* Init the method arguments */
18567754Smsmith
186114237Snjl    for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
18767754Smsmith    {
188117521Snjl        ACPI_MOVE_32_TO_32 (&WalkState->Arguments[i].Name,
189117521Snjl                            NAMEOF_ARG_NTE);
19099146Siwasaki        WalkState->Arguments[i].Name.Integer |= (i << 24);
19199146Siwasaki        WalkState->Arguments[i].Descriptor    = ACPI_DESC_TYPE_NAMED;
19299146Siwasaki        WalkState->Arguments[i].Type          = ACPI_TYPE_ANY;
193151937Sjkim        WalkState->Arguments[i].Flags         = ANOBJ_END_OF_PEER_LIST |
194151937Sjkim                                                ANOBJ_METHOD_ARG;
19567754Smsmith    }
19667754Smsmith
19767754Smsmith    /* Init the method locals */
19867754Smsmith
199114237Snjl    for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
20067754Smsmith    {
201117521Snjl        ACPI_MOVE_32_TO_32 (&WalkState->LocalVariables[i].Name,
202117521Snjl                            NAMEOF_LOCAL_NTE);
20367754Smsmith
20499146Siwasaki        WalkState->LocalVariables[i].Name.Integer |= (i << 24);
20599146Siwasaki        WalkState->LocalVariables[i].Descriptor    = ACPI_DESC_TYPE_NAMED;
20699146Siwasaki        WalkState->LocalVariables[i].Type          = ACPI_TYPE_ANY;
207151937Sjkim        WalkState->LocalVariables[i].Flags         = ANOBJ_END_OF_PEER_LIST |
208151937Sjkim                                                     ANOBJ_METHOD_LOCAL;
20967754Smsmith    }
21067754Smsmith
21199679Siwasaki    return_VOID;
21267754Smsmith}
21367754Smsmith
21467754Smsmith
21567754Smsmith/*******************************************************************************
21667754Smsmith *
21767754Smsmith * FUNCTION:    AcpiDsMethodDataDeleteAll
21867754Smsmith *
21971867Smsmith * PARAMETERS:  WalkState           - Current walk state object
22067754Smsmith *
22199679Siwasaki * RETURN:      None
22267754Smsmith *
22367754Smsmith * DESCRIPTION: Delete method locals and arguments.  Arguments are only
22467754Smsmith *              deleted if this method was called from another method.
22567754Smsmith *
22667754Smsmith ******************************************************************************/
22767754Smsmith
22899679Siwasakivoid
22967754SmsmithAcpiDsMethodDataDeleteAll (
23067754Smsmith    ACPI_WALK_STATE         *WalkState)
23167754Smsmith{
23267754Smsmith    UINT32                  Index;
23367754Smsmith
23467754Smsmith
23591116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataDeleteAll");
23667754Smsmith
23767754Smsmith
23887031Smsmith    /* Detach the locals */
23967754Smsmith
240114237Snjl    for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++)
24167754Smsmith    {
24287031Smsmith        if (WalkState->LocalVariables[Index].Object)
24367754Smsmith        {
24487031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%d=%p\n",
24587031Smsmith                    Index, WalkState->LocalVariables[Index].Object));
24667754Smsmith
24787031Smsmith            /* Detach object (if present) and remove a reference */
24867754Smsmith
24987031Smsmith            AcpiNsDetachObject (&WalkState->LocalVariables[Index]);
25099679Siwasaki        }
25167754Smsmith    }
25267754Smsmith
25387031Smsmith    /* Detach the arguments */
25467754Smsmith
255114237Snjl    for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++)
25667754Smsmith    {
25787031Smsmith        if (WalkState->Arguments[Index].Object)
25867754Smsmith        {
25987031Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%d=%p\n",
26087031Smsmith                    Index, WalkState->Arguments[Index].Object));
26167754Smsmith
26287031Smsmith            /* Detach object (if present) and remove a reference */
26367754Smsmith
26487031Smsmith            AcpiNsDetachObject (&WalkState->Arguments[Index]);
26567754Smsmith        }
26667754Smsmith    }
26767754Smsmith
26899679Siwasaki    return_VOID;
26967754Smsmith}
27067754Smsmith
27167754Smsmith
27267754Smsmith/*******************************************************************************
27367754Smsmith *
27467754Smsmith * FUNCTION:    AcpiDsMethodDataInitArgs
27567754Smsmith *
27671867Smsmith * PARAMETERS:  *Params         - Pointer to a parameter list for the method
27771867Smsmith *              MaxParamCount   - The arg count for this method
27871867Smsmith *              WalkState       - Current walk state object
27967754Smsmith *
28067754Smsmith * RETURN:      Status
28167754Smsmith *
28287031Smsmith * DESCRIPTION: Initialize arguments for a method.  The parameter list is a list
28387031Smsmith *              of ACPI operand objects, either null terminated or whose length
28487031Smsmith *              is defined by MaxParamCount.
28567754Smsmith *
28667754Smsmith ******************************************************************************/
28767754Smsmith
28867754SmsmithACPI_STATUS
28967754SmsmithAcpiDsMethodDataInitArgs (
29067754Smsmith    ACPI_OPERAND_OBJECT     **Params,
29167754Smsmith    UINT32                  MaxParamCount,
29267754Smsmith    ACPI_WALK_STATE         *WalkState)
29367754Smsmith{
29467754Smsmith    ACPI_STATUS             Status;
29587031Smsmith    UINT32                  Index = 0;
29667754Smsmith
29767754Smsmith
29891116Smsmith    ACPI_FUNCTION_TRACE_PTR ("DsMethodDataInitArgs", Params);
29967754Smsmith
30067754Smsmith
30167754Smsmith    if (!Params)
30267754Smsmith    {
30382367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "No param list passed to method\n"));
30467754Smsmith        return_ACPI_STATUS (AE_OK);
30567754Smsmith    }
30667754Smsmith
307151937Sjkim    /* Copy passed parameters into the new method stack frame */
30867754Smsmith
309151937Sjkim    while ((Index < ACPI_METHOD_NUM_ARGS) &&
310151937Sjkim           (Index < MaxParamCount)        &&
311151937Sjkim            Params[Index])
31267754Smsmith    {
31387031Smsmith        /*
31487031Smsmith         * A valid parameter.
315126372Snjl         * Store the argument in the method/walk descriptor.
316126372Snjl         * Do not copy the arg in order to implement call by reference
31787031Smsmith         */
318151937Sjkim        Status = AcpiDsMethodDataSetValue (AML_ARG_OP, Index,
319151937Sjkim                    Params[Index], WalkState);
32087031Smsmith        if (ACPI_FAILURE (Status))
32167754Smsmith        {
32287031Smsmith            return_ACPI_STATUS (Status);
32367754Smsmith        }
32467754Smsmith
32587031Smsmith        Index++;
32667754Smsmith    }
32767754Smsmith
32887031Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%d args passed to method\n", Index));
32967754Smsmith    return_ACPI_STATUS (AE_OK);
33067754Smsmith}
33167754Smsmith
33267754Smsmith
33367754Smsmith/*******************************************************************************
33467754Smsmith *
33587031Smsmith * FUNCTION:    AcpiDsMethodDataGetNode
33667754Smsmith *
33777424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
338151937Sjkim *              Index               - Which Local or Arg whose type to get
33971867Smsmith *              WalkState           - Current walk state object
340151937Sjkim *              Node                - Where the node is returned.
34167754Smsmith *
342151937Sjkim * RETURN:      Status and node
34367754Smsmith *
344151937Sjkim * DESCRIPTION: Get the Node associated with a local or arg.
345151937Sjkim *
34667754Smsmith ******************************************************************************/
34767754Smsmith
34867754SmsmithACPI_STATUS
34987031SmsmithAcpiDsMethodDataGetNode (
35077424Smsmith    UINT16                  Opcode,
35167754Smsmith    UINT32                  Index,
35267754Smsmith    ACPI_WALK_STATE         *WalkState,
35387031Smsmith    ACPI_NAMESPACE_NODE     **Node)
35467754Smsmith{
35591116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataGetNode");
35667754Smsmith
35767754Smsmith
35867754Smsmith    /*
35987031Smsmith     * Method Locals and Arguments are supported
36067754Smsmith     */
36177424Smsmith    switch (Opcode)
36267754Smsmith    {
36377424Smsmith    case AML_LOCAL_OP:
36467754Smsmith
365114237Snjl        if (Index > ACPI_METHOD_MAX_LOCAL)
36667754Smsmith        {
367151937Sjkim            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
368151937Sjkim                "Local index %d is invalid (max %d)\n",
369114237Snjl                Index, ACPI_METHOD_MAX_LOCAL));
37087031Smsmith            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
37167754Smsmith        }
37267754Smsmith
37387031Smsmith        /* Return a pointer to the pseudo-node */
37487031Smsmith
37587031Smsmith        *Node = &WalkState->LocalVariables[Index];
37667754Smsmith        break;
37767754Smsmith
37877424Smsmith    case AML_ARG_OP:
37967754Smsmith
380114237Snjl        if (Index > ACPI_METHOD_MAX_ARG)
38167754Smsmith        {
382151937Sjkim            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
383151937Sjkim                "Arg index %d is invalid (max %d)\n",
384114237Snjl                Index, ACPI_METHOD_MAX_ARG));
38587031Smsmith            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
38667754Smsmith        }
38767754Smsmith
38887031Smsmith        /* Return a pointer to the pseudo-node */
38987031Smsmith
39087031Smsmith        *Node = &WalkState->Arguments[Index];
39167754Smsmith        break;
39267754Smsmith
39367754Smsmith    default:
39482367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Opcode %d is invalid\n", Opcode));
39587031Smsmith        return_ACPI_STATUS (AE_AML_BAD_OPCODE);
39667754Smsmith    }
39767754Smsmith
39867754Smsmith    return_ACPI_STATUS (AE_OK);
39967754Smsmith}
40067754Smsmith
40167754Smsmith
40267754Smsmith/*******************************************************************************
40367754Smsmith *
40487031Smsmith * FUNCTION:    AcpiDsMethodDataSetValue
40567754Smsmith *
40677424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
407151937Sjkim *              Index               - Which Local or Arg to get
40867754Smsmith *              Object              - Object to be inserted into the stack entry
40971867Smsmith *              WalkState           - Current walk state object
41067754Smsmith *
41167754Smsmith * RETURN:      Status
41267754Smsmith *
41377424Smsmith * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
414114237Snjl *              Note: There is no "implicit conversion" for locals.
41567754Smsmith *
41667754Smsmith ******************************************************************************/
41767754Smsmith
418151937Sjkimstatic ACPI_STATUS
41987031SmsmithAcpiDsMethodDataSetValue (
42077424Smsmith    UINT16                  Opcode,
42167754Smsmith    UINT32                  Index,
42267754Smsmith    ACPI_OPERAND_OBJECT     *Object,
42367754Smsmith    ACPI_WALK_STATE         *WalkState)
42467754Smsmith{
42567754Smsmith    ACPI_STATUS             Status;
42687031Smsmith    ACPI_NAMESPACE_NODE     *Node;
42767754Smsmith
42867754Smsmith
42991116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataSetValue");
43067754Smsmith
43183174Smsmith
432114237Snjl    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
433138287Smarks        "NewObj %p Opcode %X, Refs=%d [%s]\n", Object,
434114237Snjl        Opcode, Object->Common.ReferenceCount,
435114237Snjl        AcpiUtGetTypeName (Object->Common.Type)));
436114237Snjl
43787031Smsmith    /* Get the namespace node for the arg/local */
43867754Smsmith
43987031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
44067754Smsmith    if (ACPI_FAILURE (Status))
44167754Smsmith    {
44267754Smsmith        return_ACPI_STATUS (Status);
44367754Smsmith    }
44467754Smsmith
445123315Snjl    /*
446122945Snjl     * Increment ref count so object can't be deleted while installed.
447122945Snjl     * NOTE: We do not copy the object in order to preserve the call by
448122945Snjl     * reference semantics of ACPI Control Method invocation.
449122945Snjl     * (See ACPI Specification 2.0C)
450114237Snjl     */
451122945Snjl    AcpiUtAddReference (Object);
45267754Smsmith
453114237Snjl    /* Install the object */
454114237Snjl
455122945Snjl    Node->Object = Object;
456114237Snjl    return_ACPI_STATUS (Status);
45767754Smsmith}
45867754Smsmith
45967754Smsmith
46067754Smsmith/*******************************************************************************
46167754Smsmith *
46267754Smsmith * FUNCTION:    AcpiDsMethodDataGetValue
46367754Smsmith *
46477424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
46567754Smsmith *              Index               - Which localVar or argument to get
46671867Smsmith *              WalkState           - Current walk state object
467151937Sjkim *              DestDesc            - Where Arg or Local value is returned
46867754Smsmith *
46967754Smsmith * RETURN:      Status
47067754Smsmith *
471151937Sjkim * DESCRIPTION: Retrieve value of selected Arg or Local for this method
47277424Smsmith *              Used only in AcpiExResolveToValue().
47367754Smsmith *
47467754Smsmith ******************************************************************************/
47567754Smsmith
47667754SmsmithACPI_STATUS
47767754SmsmithAcpiDsMethodDataGetValue (
47877424Smsmith    UINT16                  Opcode,
47967754Smsmith    UINT32                  Index,
48067754Smsmith    ACPI_WALK_STATE         *WalkState,
48167754Smsmith    ACPI_OPERAND_OBJECT     **DestDesc)
48267754Smsmith{
48367754Smsmith    ACPI_STATUS             Status;
48487031Smsmith    ACPI_NAMESPACE_NODE     *Node;
48567754Smsmith    ACPI_OPERAND_OBJECT     *Object;
48667754Smsmith
48767754Smsmith
48891116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataGetValue");
48967754Smsmith
49067754Smsmith
49167754Smsmith    /* Validate the object descriptor */
49267754Smsmith
49367754Smsmith    if (!DestDesc)
49467754Smsmith    {
49582367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null object descriptor pointer\n"));
49667754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
49767754Smsmith    }
49867754Smsmith
49987031Smsmith    /* Get the namespace node for the arg/local */
50067754Smsmith
50187031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
50267754Smsmith    if (ACPI_FAILURE (Status))
50367754Smsmith    {
50467754Smsmith        return_ACPI_STATUS (Status);
50567754Smsmith    }
50667754Smsmith
50787031Smsmith    /* Get the object from the node */
50867754Smsmith
50987031Smsmith    Object = Node->Object;
51067754Smsmith
51167754Smsmith    /* Examine the returned object, it must be valid. */
51267754Smsmith
51367754Smsmith    if (!Object)
51467754Smsmith    {
51567754Smsmith        /*
51687031Smsmith         * Index points to uninitialized object.
51767754Smsmith         * This means that either 1) The expected argument was
51867754Smsmith         * not passed to the method, or 2) A local variable
51967754Smsmith         * was referenced by the method (via the ASL)
52067754Smsmith         * before it was initialized.  Either case is an error.
52167754Smsmith         */
522138287Smarks
523138287Smarks        /* If slack enabled, init the LocalX/ArgX to an Integer of value zero */
524138287Smarks
525138287Smarks        if (AcpiGbl_EnableInterpreterSlack)
52667754Smsmith        {
527138287Smarks            Object = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
528138287Smarks            if (!Object)
529138287Smarks            {
530138287Smarks                return_ACPI_STATUS (AE_NO_MEMORY);
531138287Smarks            }
532138287Smarks
533138287Smarks            Object->Integer.Value = 0;
534138287Smarks            Node->Object = Object;
535138287Smarks        }
536138287Smarks
537138287Smarks        /* Otherwise, return the error */
538138287Smarks
539138287Smarks        else switch (Opcode)
540138287Smarks        {
54177424Smsmith        case AML_ARG_OP:
54271867Smsmith
543151937Sjkim            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
544151937Sjkim                "Uninitialized Arg[%d] at node %p\n",
54587031Smsmith                Index, Node));
54671867Smsmith
54767754Smsmith            return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
54867754Smsmith
54977424Smsmith        case AML_LOCAL_OP:
55071867Smsmith
551151937Sjkim            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
552151937Sjkim                "Uninitialized Local[%d] at node %p\n",
55387031Smsmith                Index, Node));
55471867Smsmith
55567754Smsmith            return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
55699679Siwasaki
55799679Siwasaki        default:
558126372Snjl            ACPI_REPORT_ERROR (("Not Arg/Local opcode: %X\n", Opcode));
55999679Siwasaki            return_ACPI_STATUS (AE_AML_INTERNAL);
56067754Smsmith        }
56167754Smsmith    }
56267754Smsmith
56367754Smsmith    /*
56487031Smsmith     * The Index points to an initialized and valid object.
56567754Smsmith     * Return an additional reference to the object
56667754Smsmith     */
56767754Smsmith    *DestDesc = Object;
56877424Smsmith    AcpiUtAddReference (Object);
56967754Smsmith
57067754Smsmith    return_ACPI_STATUS (AE_OK);
57167754Smsmith}
57267754Smsmith
57367754Smsmith
57467754Smsmith/*******************************************************************************
57567754Smsmith *
57667754Smsmith * FUNCTION:    AcpiDsMethodDataDeleteValue
57767754Smsmith *
57877424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
57967754Smsmith *              Index               - Which localVar or argument to delete
58071867Smsmith *              WalkState           - Current walk state object
58167754Smsmith *
58299679Siwasaki * RETURN:      None
58367754Smsmith *
584151937Sjkim * DESCRIPTION: Delete the entry at Opcode:Index.  Inserts
58567754Smsmith *              a null into the stack slot after the object is deleted.
58667754Smsmith *
58767754Smsmith ******************************************************************************/
58867754Smsmith
589151937Sjkimstatic void
59067754SmsmithAcpiDsMethodDataDeleteValue (
59177424Smsmith    UINT16                  Opcode,
59267754Smsmith    UINT32                  Index,
59367754Smsmith    ACPI_WALK_STATE         *WalkState)
59467754Smsmith{
59567754Smsmith    ACPI_STATUS             Status;
59687031Smsmith    ACPI_NAMESPACE_NODE     *Node;
59767754Smsmith    ACPI_OPERAND_OBJECT     *Object;
59867754Smsmith
59967754Smsmith
60091116Smsmith    ACPI_FUNCTION_TRACE ("DsMethodDataDeleteValue");
60167754Smsmith
60267754Smsmith
60387031Smsmith    /* Get the namespace node for the arg/local */
60467754Smsmith
60587031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
60667754Smsmith    if (ACPI_FAILURE (Status))
60767754Smsmith    {
60899679Siwasaki        return_VOID;
60967754Smsmith    }
61067754Smsmith
61187031Smsmith    /* Get the associated object */
61267754Smsmith
61387031Smsmith    Object = AcpiNsGetAttachedObject (Node);
61467754Smsmith
61567754Smsmith    /*
61667754Smsmith     * Undefine the Arg or Local by setting its descriptor
61767754Smsmith     * pointer to NULL. Locals/Args can contain both
61867754Smsmith     * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
61967754Smsmith     */
62087031Smsmith    Node->Object = NULL;
62167754Smsmith
62267754Smsmith    if ((Object) &&
62399679Siwasaki        (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND))
62467754Smsmith    {
62567754Smsmith        /*
62687031Smsmith         * There is a valid object.
62767754Smsmith         * Decrement the reference count by one to balance the
62887031Smsmith         * increment when the object was stored.
62967754Smsmith         */
63077424Smsmith        AcpiUtRemoveReference (Object);
63167754Smsmith    }
63267754Smsmith
63399679Siwasaki    return_VOID;
63467754Smsmith}
63567754Smsmith
63667754Smsmith
63767754Smsmith/*******************************************************************************
63867754Smsmith *
63977424Smsmith * FUNCTION:    AcpiDsStoreObjectToLocal
64067754Smsmith *
64177424Smsmith * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
642151937Sjkim *              Index               - Which Local or Arg to set
64387031Smsmith *              ObjDesc             - Value to be stored
64471867Smsmith *              WalkState           - Current walk state
64567754Smsmith *
64667754Smsmith * RETURN:      Status
64767754Smsmith *
64887031Smsmith * DESCRIPTION: Store a value in an Arg or Local.  The ObjDesc is installed
64967754Smsmith *              as the new value for the Arg or Local and the reference count
65087031Smsmith *              for ObjDesc is incremented.
65167754Smsmith *
65267754Smsmith ******************************************************************************/
65367754Smsmith
65467754SmsmithACPI_STATUS
65577424SmsmithAcpiDsStoreObjectToLocal (
65677424Smsmith    UINT16                  Opcode,
65767754Smsmith    UINT32                  Index,
65887031Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc,
65967754Smsmith    ACPI_WALK_STATE         *WalkState)
66067754Smsmith{
66167754Smsmith    ACPI_STATUS             Status;
66287031Smsmith    ACPI_NAMESPACE_NODE     *Node;
66387031Smsmith    ACPI_OPERAND_OBJECT     *CurrentObjDesc;
664123315Snjl    ACPI_OPERAND_OBJECT     *NewObjDesc;
66567754Smsmith
66667754Smsmith
66791116Smsmith    ACPI_FUNCTION_TRACE ("DsStoreObjectToLocal");
668138287Smarks    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode=%X Index=%d Obj=%p\n",
66987031Smsmith        Opcode, Index, ObjDesc));
67067754Smsmith
67167754Smsmith    /* Parameter validation */
67267754Smsmith
67387031Smsmith    if (!ObjDesc)
67467754Smsmith    {
67567754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
67667754Smsmith    }
67767754Smsmith
67887031Smsmith    /* Get the namespace node for the arg/local */
67967754Smsmith
68087031Smsmith    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
68167754Smsmith    if (ACPI_FAILURE (Status))
68267754Smsmith    {
68387031Smsmith        return_ACPI_STATUS (Status);
68467754Smsmith    }
68567754Smsmith
68687031Smsmith    CurrentObjDesc = AcpiNsGetAttachedObject (Node);
68787031Smsmith    if (CurrentObjDesc == ObjDesc)
68867754Smsmith    {
689114237Snjl        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n",
690114237Snjl            ObjDesc));
69187031Smsmith        return_ACPI_STATUS (Status);
69267754Smsmith    }
69367754Smsmith
69467754Smsmith    /*
695123315Snjl     * If the reference count on the object is more than one, we must
696126372Snjl     * take a copy of the object before we store.  A reference count
697126372Snjl     * of exactly 1 means that the object was just created during the
698126372Snjl     * evaluation of an expression, and we can safely use it since it
699126372Snjl     * is not used anywhere else.
700123315Snjl     */
701123315Snjl    NewObjDesc = ObjDesc;
702126372Snjl    if (ObjDesc->Common.ReferenceCount > 1)
703123315Snjl    {
704123315Snjl        Status = AcpiUtCopyIobjectToIobject (ObjDesc, &NewObjDesc, WalkState);
705123315Snjl        if (ACPI_FAILURE (Status))
706123315Snjl        {
707123315Snjl            return_ACPI_STATUS (Status);
708123315Snjl        }
709123315Snjl    }
710123315Snjl
711123315Snjl    /*
71267754Smsmith     * If there is an object already in this slot, we either
71367754Smsmith     * have to delete it, or if this is an argument and there
71467754Smsmith     * is an object reference stored there, we have to do
71567754Smsmith     * an indirect store!
71667754Smsmith     */
71787031Smsmith    if (CurrentObjDesc)
71867754Smsmith    {
71967754Smsmith        /*
72067754Smsmith         * Check for an indirect store if an argument
72167754Smsmith         * contains an object reference (stored as an Node).
72267754Smsmith         * We don't allow this automatic dereferencing for
72367754Smsmith         * locals, since a store to a local should overwrite
72467754Smsmith         * anything there, including an object reference.
72567754Smsmith         *
72667754Smsmith         * If both Arg0 and Local0 contain RefOf (Local4):
72767754Smsmith         *
72867754Smsmith         * Store (1, Arg0)             - Causes indirect store to local4
72967754Smsmith         * Store (1, Local0)           - Stores 1 in local0, overwriting
73067754Smsmith         *                                  the reference to local4
73167754Smsmith         * Store (1, DeRefof (Local0)) - Causes indirect store to local4
73267754Smsmith         *
73367754Smsmith         * Weird, but true.
73467754Smsmith         */
735102550Siwasaki        if (Opcode == AML_ARG_OP)
73667754Smsmith        {
737114237Snjl            /*
738151937Sjkim             * If we have a valid reference object that came from RefOf(),
739151937Sjkim             * do the indirect store
740102550Siwasaki             */
741151937Sjkim            if ((ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) == ACPI_DESC_TYPE_OPERAND) &&
742151937Sjkim                (CurrentObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
743102550Siwasaki                (CurrentObjDesc->Reference.Opcode == AML_REF_OF_OP))
744102550Siwasaki            {
745102550Siwasaki                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
746123315Snjl                        "Arg (%p) is an ObjRef(Node), storing in node %p\n",
747123315Snjl                        NewObjDesc, CurrentObjDesc));
74867754Smsmith
749102550Siwasaki                /*
750128212Snjl                 * Store this object to the Node (perform the indirect store)
751128212Snjl                 * NOTE: No implicit conversion is performed, as per the ACPI
752128212Snjl                 * specification rules on storing to Locals/Args.
753102550Siwasaki                 */
754123315Snjl                Status = AcpiExStoreObjectToNode (NewObjDesc,
755128212Snjl                            CurrentObjDesc->Reference.Object, WalkState,
756128212Snjl                            ACPI_NO_IMPLICIT_CONVERSION);
757123315Snjl
758123315Snjl                /* Remove local reference if we copied the object above */
759123315Snjl
760123315Snjl                if (NewObjDesc != ObjDesc)
761123315Snjl                {
762123315Snjl                    AcpiUtRemoveReference (NewObjDesc);
763123315Snjl                }
764102550Siwasaki                return_ACPI_STATUS (Status);
765102550Siwasaki            }
76667754Smsmith        }
76767754Smsmith
76867754Smsmith        /*
76971867Smsmith         * Delete the existing object
77067754Smsmith         * before storing the new one
77167754Smsmith         */
77277424Smsmith        AcpiDsMethodDataDeleteValue (Opcode, Index, WalkState);
77367754Smsmith    }
77467754Smsmith
77567754Smsmith    /*
776123315Snjl     * Install the Obj descriptor (*NewObjDesc) into
77767754Smsmith     * the descriptor for the Arg or Local.
77867754Smsmith     * (increments the object reference count by one)
77967754Smsmith     */
780123315Snjl    Status = AcpiDsMethodDataSetValue (Opcode, Index, NewObjDesc, WalkState);
781123315Snjl
782123315Snjl    /* Remove local reference if we copied the object above */
783123315Snjl
784123315Snjl    if (NewObjDesc != ObjDesc)
785123315Snjl    {
786123315Snjl        AcpiUtRemoveReference (NewObjDesc);
787123315Snjl    }
788123315Snjl
78967754Smsmith    return_ACPI_STATUS (Status);
79067754Smsmith}
79167754Smsmith
79287031Smsmith
793151937Sjkim#ifdef ACPI_OBSOLETE_FUNCTIONS
794151937Sjkim/*******************************************************************************
795151937Sjkim *
796151937Sjkim * FUNCTION:    AcpiDsMethodDataGetType
797151937Sjkim *
798151937Sjkim * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
799151937Sjkim *              Index               - Which Local or Arg whose type to get
800151937Sjkim *              WalkState           - Current walk state object
801151937Sjkim *
802151937Sjkim * RETURN:      Data type of current value of the selected Arg or Local
803151937Sjkim *
804151937Sjkim * DESCRIPTION: Get the type of the object stored in the Local or Arg
805151937Sjkim *
806151937Sjkim ******************************************************************************/
807151937Sjkim
808151937SjkimACPI_OBJECT_TYPE
809151937SjkimAcpiDsMethodDataGetType (
810151937Sjkim    UINT16                  Opcode,
811151937Sjkim    UINT32                  Index,
812151937Sjkim    ACPI_WALK_STATE         *WalkState)
813151937Sjkim{
814151937Sjkim    ACPI_STATUS             Status;
815151937Sjkim    ACPI_NAMESPACE_NODE     *Node;
816151937Sjkim    ACPI_OPERAND_OBJECT     *Object;
817151937Sjkim
818151937Sjkim
819151937Sjkim    ACPI_FUNCTION_TRACE ("DsMethodDataGetType");
820151937Sjkim
821151937Sjkim
822151937Sjkim    /* Get the namespace node for the arg/local */
823151937Sjkim
824151937Sjkim    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
825151937Sjkim    if (ACPI_FAILURE (Status))
826151937Sjkim    {
827151937Sjkim        return_VALUE ((ACPI_TYPE_NOT_FOUND));
828151937Sjkim    }
829151937Sjkim
830151937Sjkim    /* Get the object */
831151937Sjkim
832151937Sjkim    Object = AcpiNsGetAttachedObject (Node);
833151937Sjkim    if (!Object)
834151937Sjkim    {
835151937Sjkim        /* Uninitialized local/arg, return TYPE_ANY */
836151937Sjkim
837151937Sjkim        return_VALUE (ACPI_TYPE_ANY);
838151937Sjkim    }
839151937Sjkim
840151937Sjkim    /* Get the object type */
841151937Sjkim
842151937Sjkim    return_VALUE (ACPI_GET_OBJECT_TYPE (Object));
843151937Sjkim}
844151937Sjkim#endif
845151937Sjkim
846151937Sjkim
847