dsmthdat.c revision 167802
122347Spst/*******************************************************************************
222347Spst *
322347Spst * Module Name: dsmthdat - control method arguments and local variables
429964Sache *              $Revision: 1.92 $
529964Sache *
622347Spst ******************************************************************************/
722347Spst
822347Spst/******************************************************************************
922347Spst *
1022347Spst * 1. Copyright Notice
1122347Spst *
1222347Spst * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
1322347Spst * All rights reserved.
1422347Spst *
1522347Spst * 2. License
1622347Spst *
1722347Spst * 2.1. This is your license from Intel Corp. under its intellectual property
1822347Spst * rights.  You may have additional license terms from the party that provided
1922347Spst * you this software, covering your right to use that party's intellectual
2022347Spst * property rights.
2122347Spst *
2222347Spst * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2322347Spst * copy of the source code appearing in this file ("Covered Code") an
2422347Spst * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2522347Spst * base code distributed originally by Intel ("Original Intel Code") to copy,
2622347Spst * make derivatives, distribute, use and display any portion of the Covered
2722347Spst * Code in any form, with the right to sublicense such rights; and
2822347Spst *
2922347Spst * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3022347Spst * license (with the right to sublicense), under only those claims of Intel
3122347Spst * patents that are infringed by the Original Intel Code, to make, use, sell,
3222347Spst * offer to sell, and import the Covered Code and derivative works thereof
3322347Spst * solely to the minimum extent necessary to exercise the above copyright
3422347Spst * license, and in no event shall the patent license extend to any additions
3522347Spst * to or modifications of the Original Intel Code.  No other license or right
3622347Spst * is granted directly or by implication, estoppel or otherwise;
3722347Spst *
3822347Spst * The above copyright and patent license is granted only if the following
3922347Spst * conditions are met:
4022347Spst *
4122347Spst * 3. Conditions
4222347Spst *
4322347Spst * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4422347Spst * Redistribution of source code of any substantial portion of the Covered
4522347Spst * Code or modification with rights to further distribute source must include
4622347Spst * the above Copyright Notice, the above License, this list of Conditions,
4722347Spst * and the following Disclaimer and Export Compliance provision.  In addition,
4822347Spst * Licensee must cause all Covered Code to which Licensee contributes to
4922347Spst * contain a file documenting the changes Licensee made to create that Covered
5022347Spst * Code and the date of any change.  Licensee must include in that file the
5122347Spst * documentation of any changes made by any predecessor Licensee.  Licensee
5222347Spst * must include a prominent statement that the modification is derived,
5322347Spst * directly or indirectly, from Original Intel Code.
5422347Spst *
5522347Spst * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5622347Spst * Redistribution of source code of any substantial portion of the Covered
5722347Spst * Code or modification without rights to further distribute source must
5822347Spst * include the following Disclaimer and Export Compliance provision in the
5922347Spst * documentation and/or other materials provided with distribution.  In
6022347Spst * addition, Licensee may not authorize further sublicense of source of any
6122347Spst * portion of the Covered Code, and must include terms to the effect that the
6222347Spst * license from Licensee to its licensee is limited to the intellectual
6322347Spst * property embodied in the software Licensee provides to its licensee, and
6422347Spst * not to intellectual property embodied in modifications its licensee may
6522347Spst * make.
6622347Spst *
6722347Spst * 3.3. Redistribution of Executable. Redistribution in executable form of any
6822347Spst * substantial portion of the Covered Code or modification must reproduce the
6922347Spst * above Copyright Notice, and the following Disclaimer and Export Compliance
7022347Spst * provision in the documentation and/or other materials provided with the
7122347Spst * distribution.
7222347Spst *
7322347Spst * 3.4. Intel retains all right, title, and interest in and to the Original
7422347Spst * Intel Code.
7522347Spst *
7622347Spst * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7722347Spst * Intel shall be used in advertising or otherwise to promote the sale, use or
7822347Spst * other dealings in products derived from or relating to the Covered Code
7922347Spst * without prior written authorization from Intel.
8022347Spst *
8122347Spst * 4. Disclaimer and Export Compliance
8222347Spst *
8322347Spst * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8422347Spst * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8522347Spst * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8622347Spst * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8722347Spst * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8822347Spst * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8922347Spst * PARTICULAR PURPOSE.
9022347Spst *
9122347Spst * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9222347Spst * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9322347Spst * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9422347Spst * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9522347Spst * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9622347Spst * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9722347Spst * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9822347Spst * LIMITED REMEDY.
9922347Spst *
10022347Spst * 4.3. Licensee shall not export, either directly or indirectly, any of this
10122347Spst * software or system incorporating such software without first obtaining any
10222347Spst * required license or other approval from the U. S. Department of Commerce or
10322347Spst * any other agency or department of the United States Government.  In the
10422347Spst * event Licensee exports any such software from the United States or
10522347Spst * re-exports any such software from a foreign destination, Licensee shall
10622347Spst * ensure that the distribution and export/re-export of the software is in
10722347Spst * compliance with all laws, regulations, orders, or other restrictions of the
10822347Spst * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10922347Spst * any of its subsidiaries will export/re-export any technical data, process,
11022347Spst * software, or service, directly or indirectly, to any country for which the
11122347Spst * United States government or any agency thereof requires an export license,
11222347Spst * other governmental approval, or letter of assurance, without first obtaining
11322347Spst * such license, approval or letter.
11422347Spst *
11522347Spst *****************************************************************************/
11622347Spst
11722347Spst#define __DSMTHDAT_C__
11822347Spst
11922347Spst#include <contrib/dev/acpica/acpi.h>
12022347Spst#include <contrib/dev/acpica/acdispat.h>
12122347Spst#include <contrib/dev/acpica/amlcode.h>
12222347Spst#include <contrib/dev/acpica/acnamesp.h>
12322347Spst#include <contrib/dev/acpica/acinterp.h>
12422347Spst
12522347Spst
12622347Spst#define _COMPONENT          ACPI_DISPATCHER
12722347Spst        ACPI_MODULE_NAME    ("dsmthdat")
12822347Spst
12922347Spst/* Local prototypes */
13022347Spst
13122347Spststatic void
13222347SpstAcpiDsMethodDataDeleteValue (
13322347Spst    UINT16                  Opcode,
13422347Spst    UINT32                  Index,
13522347Spst    ACPI_WALK_STATE         *WalkState);
13622347Spst
13722347Spststatic ACPI_STATUS
13822347SpstAcpiDsMethodDataSetValue (
13922347Spst    UINT16                  Opcode,
14022347Spst    UINT32                  Index,
14122347Spst    ACPI_OPERAND_OBJECT     *Object,
14222347Spst    ACPI_WALK_STATE         *WalkState);
14322347Spst
14422347Spst#ifdef ACPI_OBSOLETE_FUNCTIONS
14522347SpstACPI_OBJECT_TYPE
14622347SpstAcpiDsMethodDataGetType (
14722347Spst    UINT16                  Opcode,
14822347Spst    UINT32                  Index,
14922347Spst    ACPI_WALK_STATE         *WalkState);
15022347Spst#endif
15122347Spst
15222347Spst
15322347Spst/*******************************************************************************
15422347Spst *
15522347Spst * FUNCTION:    AcpiDsMethodDataInit
15622347Spst *
15722347Spst * PARAMETERS:  WalkState           - Current walk state object
15822347Spst *
15922347Spst * RETURN:      Status
16022347Spst *
16122347Spst * DESCRIPTION: Initialize the data structures that hold the method's arguments
16222347Spst *              and locals.  The data struct is an array of namespace nodes for
16322347Spst *              each - this allows RefOf and DeRefOf to work properly for these
16422347Spst *              special data types.
16522347Spst *
16622347Spst * NOTES:       WalkState fields are initialized to zero by the
16722347Spst *              ACPI_ALLOCATE_ZEROED().
16822347Spst *
16922347Spst *              A pseudo-Namespace Node is assigned to each argument and local
17022347Spst *              so that RefOf() can return a pointer to the Node.
17122347Spst *
17222347Spst ******************************************************************************/
17322347Spst
17422347Spstvoid
17522347SpstAcpiDsMethodDataInit (
17622347Spst    ACPI_WALK_STATE         *WalkState)
17722347Spst{
17822347Spst    UINT32                  i;
17922347Spst
18022347Spst
18122347Spst    ACPI_FUNCTION_TRACE (DsMethodDataInit);
18222347Spst
18322347Spst
18422347Spst    /* Init the method arguments */
18522347Spst
18622347Spst    for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
18722347Spst    {
18822347Spst        ACPI_MOVE_32_TO_32 (&WalkState->Arguments[i].Name, NAMEOF_ARG_NTE);
18922347Spst        WalkState->Arguments[i].Name.Integer |= (i << 24);
19022347Spst        WalkState->Arguments[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
19122347Spst        WalkState->Arguments[i].Type = ACPI_TYPE_ANY;
19222347Spst        WalkState->Arguments[i].Flags =
19322347Spst            ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG;
19422347Spst    }
19522347Spst
19622347Spst    /* Init the method locals */
19722347Spst
19822347Spst    for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
19922347Spst    {
20022347Spst        ACPI_MOVE_32_TO_32 (&WalkState->LocalVariables[i].Name, NAMEOF_LOCAL_NTE);
20122347Spst
20222347Spst        WalkState->LocalVariables[i].Name.Integer |= (i << 24);
20322347Spst        WalkState->LocalVariables[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
20422347Spst        WalkState->LocalVariables[i].Type = ACPI_TYPE_ANY;
20522347Spst        WalkState->LocalVariables[i].Flags =
20622347Spst            ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL;
20722347Spst    }
20822347Spst
20922347Spst    return_VOID;
21022347Spst}
21122347Spst
21222347Spst
21322347Spst/*******************************************************************************
21422347Spst *
21522347Spst * FUNCTION:    AcpiDsMethodDataDeleteAll
21622347Spst *
21722347Spst * PARAMETERS:  WalkState           - Current walk state object
21822347Spst *
21922347Spst * RETURN:      None
22022347Spst *
22122347Spst * DESCRIPTION: Delete method locals and arguments.  Arguments are only
22222347Spst *              deleted if this method was called from another method.
22322347Spst *
22422347Spst ******************************************************************************/
22522347Spst
22622347Spstvoid
22722347SpstAcpiDsMethodDataDeleteAll (
22822347Spst    ACPI_WALK_STATE         *WalkState)
22922347Spst{
23022347Spst    UINT32                  Index;
23122347Spst
23222347Spst
23322347Spst    ACPI_FUNCTION_TRACE (DsMethodDataDeleteAll);
23422347Spst
23522347Spst
23622347Spst    /* Detach the locals */
23722347Spst
23822347Spst    for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++)
23922347Spst    {
24022347Spst        if (WalkState->LocalVariables[Index].Object)
24122347Spst        {
24222347Spst            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%d=%p\n",
24322347Spst                    Index, WalkState->LocalVariables[Index].Object));
24422347Spst
24522347Spst            /* Detach object (if present) and remove a reference */
24622347Spst
24722347Spst            AcpiNsDetachObject (&WalkState->LocalVariables[Index]);
24822347Spst        }
24922347Spst    }
25022347Spst
25122347Spst    /* Detach the arguments */
25222347Spst
25322347Spst    for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++)
25422347Spst    {
25522347Spst        if (WalkState->Arguments[Index].Object)
25622347Spst        {
25722347Spst            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%d=%p\n",
25822347Spst                    Index, WalkState->Arguments[Index].Object));
25922347Spst
26022347Spst            /* Detach object (if present) and remove a reference */
26122347Spst
26222347Spst            AcpiNsDetachObject (&WalkState->Arguments[Index]);
26322347Spst        }
26422347Spst    }
26522347Spst
26622347Spst    return_VOID;
26722347Spst}
26822347Spst
26922347Spst
27022347Spst/*******************************************************************************
27122347Spst *
27222347Spst * FUNCTION:    AcpiDsMethodDataInitArgs
27322347Spst *
27422347Spst * PARAMETERS:  *Params         - Pointer to a parameter list for the method
27522347Spst *              MaxParamCount   - The arg count for this method
27622347Spst *              WalkState       - Current walk state object
27722347Spst *
27822347Spst * RETURN:      Status
27922347Spst *
28022347Spst * DESCRIPTION: Initialize arguments for a method.  The parameter list is a list
28122347Spst *              of ACPI operand objects, either null terminated or whose length
28222347Spst *              is defined by MaxParamCount.
28322347Spst *
28422347Spst ******************************************************************************/
28522347Spst
28622347SpstACPI_STATUS
28722347SpstAcpiDsMethodDataInitArgs (
28822347Spst    ACPI_OPERAND_OBJECT     **Params,
28922347Spst    UINT32                  MaxParamCount,
29022347Spst    ACPI_WALK_STATE         *WalkState)
29122347Spst{
29222347Spst    ACPI_STATUS             Status;
29322347Spst    UINT32                  Index = 0;
29422347Spst
29522347Spst
29622347Spst    ACPI_FUNCTION_TRACE_PTR (DsMethodDataInitArgs, Params);
29722347Spst
29822347Spst
29922347Spst    if (!Params)
30022347Spst    {
30122347Spst        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "No param list passed to method\n"));
30222347Spst        return_ACPI_STATUS (AE_OK);
30322347Spst    }
30422347Spst
305    /* Copy passed parameters into the new method stack frame */
306
307    while ((Index < ACPI_METHOD_NUM_ARGS) &&
308           (Index < MaxParamCount)        &&
309            Params[Index])
310    {
311        /*
312         * A valid parameter.
313         * Store the argument in the method/walk descriptor.
314         * Do not copy the arg in order to implement call by reference
315         */
316        Status = AcpiDsMethodDataSetValue (AML_ARG_OP, Index,
317                    Params[Index], WalkState);
318        if (ACPI_FAILURE (Status))
319        {
320            return_ACPI_STATUS (Status);
321        }
322
323        Index++;
324    }
325
326    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%d args passed to method\n", Index));
327    return_ACPI_STATUS (AE_OK);
328}
329
330
331/*******************************************************************************
332 *
333 * FUNCTION:    AcpiDsMethodDataGetNode
334 *
335 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
336 *              Index               - Which Local or Arg whose type to get
337 *              WalkState           - Current walk state object
338 *              Node                - Where the node is returned.
339 *
340 * RETURN:      Status and node
341 *
342 * DESCRIPTION: Get the Node associated with a local or arg.
343 *
344 ******************************************************************************/
345
346ACPI_STATUS
347AcpiDsMethodDataGetNode (
348    UINT16                  Opcode,
349    UINT32                  Index,
350    ACPI_WALK_STATE         *WalkState,
351    ACPI_NAMESPACE_NODE     **Node)
352{
353    ACPI_FUNCTION_TRACE (DsMethodDataGetNode);
354
355
356    /*
357     * Method Locals and Arguments are supported
358     */
359    switch (Opcode)
360    {
361    case AML_LOCAL_OP:
362
363        if (Index > ACPI_METHOD_MAX_LOCAL)
364        {
365            ACPI_ERROR ((AE_INFO,
366                "Local index %d is invalid (max %d)",
367                Index, ACPI_METHOD_MAX_LOCAL));
368            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
369        }
370
371        /* Return a pointer to the pseudo-node */
372
373        *Node = &WalkState->LocalVariables[Index];
374        break;
375
376    case AML_ARG_OP:
377
378        if (Index > ACPI_METHOD_MAX_ARG)
379        {
380            ACPI_ERROR ((AE_INFO,
381                "Arg index %d is invalid (max %d)",
382                Index, ACPI_METHOD_MAX_ARG));
383            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
384        }
385
386        /* Return a pointer to the pseudo-node */
387
388        *Node = &WalkState->Arguments[Index];
389        break;
390
391    default:
392        ACPI_ERROR ((AE_INFO, "Opcode %d is invalid", Opcode));
393        return_ACPI_STATUS (AE_AML_BAD_OPCODE);
394    }
395
396    return_ACPI_STATUS (AE_OK);
397}
398
399
400/*******************************************************************************
401 *
402 * FUNCTION:    AcpiDsMethodDataSetValue
403 *
404 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
405 *              Index               - Which Local or Arg to get
406 *              Object              - Object to be inserted into the stack entry
407 *              WalkState           - Current walk state object
408 *
409 * RETURN:      Status
410 *
411 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
412 *              Note: There is no "implicit conversion" for locals.
413 *
414 ******************************************************************************/
415
416static ACPI_STATUS
417AcpiDsMethodDataSetValue (
418    UINT16                  Opcode,
419    UINT32                  Index,
420    ACPI_OPERAND_OBJECT     *Object,
421    ACPI_WALK_STATE         *WalkState)
422{
423    ACPI_STATUS             Status;
424    ACPI_NAMESPACE_NODE     *Node;
425
426
427    ACPI_FUNCTION_TRACE (DsMethodDataSetValue);
428
429
430    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
431        "NewObj %p Opcode %X, Refs=%d [%s]\n", Object,
432        Opcode, Object->Common.ReferenceCount,
433        AcpiUtGetTypeName (Object->Common.Type)));
434
435    /* Get the namespace node for the arg/local */
436
437    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
438    if (ACPI_FAILURE (Status))
439    {
440        return_ACPI_STATUS (Status);
441    }
442
443    /*
444     * Increment ref count so object can't be deleted while installed.
445     * NOTE: We do not copy the object in order to preserve the call by
446     * reference semantics of ACPI Control Method invocation.
447     * (See ACPI Specification 2.0C)
448     */
449    AcpiUtAddReference (Object);
450
451    /* Install the object */
452
453    Node->Object = Object;
454    return_ACPI_STATUS (Status);
455}
456
457
458/*******************************************************************************
459 *
460 * FUNCTION:    AcpiDsMethodDataGetValue
461 *
462 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
463 *              Index               - Which localVar or argument to get
464 *              WalkState           - Current walk state object
465 *              DestDesc            - Where Arg or Local value is returned
466 *
467 * RETURN:      Status
468 *
469 * DESCRIPTION: Retrieve value of selected Arg or Local for this method
470 *              Used only in AcpiExResolveToValue().
471 *
472 ******************************************************************************/
473
474ACPI_STATUS
475AcpiDsMethodDataGetValue (
476    UINT16                  Opcode,
477    UINT32                  Index,
478    ACPI_WALK_STATE         *WalkState,
479    ACPI_OPERAND_OBJECT     **DestDesc)
480{
481    ACPI_STATUS             Status;
482    ACPI_NAMESPACE_NODE     *Node;
483    ACPI_OPERAND_OBJECT     *Object;
484
485
486    ACPI_FUNCTION_TRACE (DsMethodDataGetValue);
487
488
489    /* Validate the object descriptor */
490
491    if (!DestDesc)
492    {
493        ACPI_ERROR ((AE_INFO, "Null object descriptor pointer"));
494        return_ACPI_STATUS (AE_BAD_PARAMETER);
495    }
496
497    /* Get the namespace node for the arg/local */
498
499    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
500    if (ACPI_FAILURE (Status))
501    {
502        return_ACPI_STATUS (Status);
503    }
504
505    /* Get the object from the node */
506
507    Object = Node->Object;
508
509    /* Examine the returned object, it must be valid. */
510
511    if (!Object)
512    {
513        /*
514         * Index points to uninitialized object.
515         * This means that either 1) The expected argument was
516         * not passed to the method, or 2) A local variable
517         * was referenced by the method (via the ASL)
518         * before it was initialized.  Either case is an error.
519         */
520
521        /* If slack enabled, init the LocalX/ArgX to an Integer of value zero */
522
523        if (AcpiGbl_EnableInterpreterSlack)
524        {
525            Object = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
526            if (!Object)
527            {
528                return_ACPI_STATUS (AE_NO_MEMORY);
529            }
530
531            Object->Integer.Value = 0;
532            Node->Object = Object;
533        }
534
535        /* Otherwise, return the error */
536
537        else switch (Opcode)
538        {
539        case AML_ARG_OP:
540
541            ACPI_ERROR ((AE_INFO,
542                "Uninitialized Arg[%d] at node %p",
543                Index, Node));
544
545            return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
546
547        case AML_LOCAL_OP:
548
549            ACPI_ERROR ((AE_INFO,
550                "Uninitialized Local[%d] at node %p",
551                Index, Node));
552
553            return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
554
555        default:
556            ACPI_ERROR ((AE_INFO, "Not a Arg/Local opcode: %X", Opcode));
557            return_ACPI_STATUS (AE_AML_INTERNAL);
558        }
559    }
560
561    /*
562     * The Index points to an initialized and valid object.
563     * Return an additional reference to the object
564     */
565    *DestDesc = Object;
566    AcpiUtAddReference (Object);
567
568    return_ACPI_STATUS (AE_OK);
569}
570
571
572/*******************************************************************************
573 *
574 * FUNCTION:    AcpiDsMethodDataDeleteValue
575 *
576 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
577 *              Index               - Which localVar or argument to delete
578 *              WalkState           - Current walk state object
579 *
580 * RETURN:      None
581 *
582 * DESCRIPTION: Delete the entry at Opcode:Index.  Inserts
583 *              a null into the stack slot after the object is deleted.
584 *
585 ******************************************************************************/
586
587static void
588AcpiDsMethodDataDeleteValue (
589    UINT16                  Opcode,
590    UINT32                  Index,
591    ACPI_WALK_STATE         *WalkState)
592{
593    ACPI_STATUS             Status;
594    ACPI_NAMESPACE_NODE     *Node;
595    ACPI_OPERAND_OBJECT     *Object;
596
597
598    ACPI_FUNCTION_TRACE (DsMethodDataDeleteValue);
599
600
601    /* Get the namespace node for the arg/local */
602
603    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
604    if (ACPI_FAILURE (Status))
605    {
606        return_VOID;
607    }
608
609    /* Get the associated object */
610
611    Object = AcpiNsGetAttachedObject (Node);
612
613    /*
614     * Undefine the Arg or Local by setting its descriptor
615     * pointer to NULL. Locals/Args can contain both
616     * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
617     */
618    Node->Object = NULL;
619
620    if ((Object) &&
621        (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND))
622    {
623        /*
624         * There is a valid object.
625         * Decrement the reference count by one to balance the
626         * increment when the object was stored.
627         */
628        AcpiUtRemoveReference (Object);
629    }
630
631    return_VOID;
632}
633
634
635/*******************************************************************************
636 *
637 * FUNCTION:    AcpiDsStoreObjectToLocal
638 *
639 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
640 *              Index               - Which Local or Arg to set
641 *              ObjDesc             - Value to be stored
642 *              WalkState           - Current walk state
643 *
644 * RETURN:      Status
645 *
646 * DESCRIPTION: Store a value in an Arg or Local.  The ObjDesc is installed
647 *              as the new value for the Arg or Local and the reference count
648 *              for ObjDesc is incremented.
649 *
650 ******************************************************************************/
651
652ACPI_STATUS
653AcpiDsStoreObjectToLocal (
654    UINT16                  Opcode,
655    UINT32                  Index,
656    ACPI_OPERAND_OBJECT     *ObjDesc,
657    ACPI_WALK_STATE         *WalkState)
658{
659    ACPI_STATUS             Status;
660    ACPI_NAMESPACE_NODE     *Node;
661    ACPI_OPERAND_OBJECT     *CurrentObjDesc;
662    ACPI_OPERAND_OBJECT     *NewObjDesc;
663
664
665    ACPI_FUNCTION_TRACE (DsStoreObjectToLocal);
666    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode=%X Index=%d Obj=%p\n",
667        Opcode, Index, ObjDesc));
668
669    /* Parameter validation */
670
671    if (!ObjDesc)
672    {
673        return_ACPI_STATUS (AE_BAD_PARAMETER);
674    }
675
676    /* Get the namespace node for the arg/local */
677
678    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
679    if (ACPI_FAILURE (Status))
680    {
681        return_ACPI_STATUS (Status);
682    }
683
684    CurrentObjDesc = AcpiNsGetAttachedObject (Node);
685    if (CurrentObjDesc == ObjDesc)
686    {
687        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n",
688            ObjDesc));
689        return_ACPI_STATUS (Status);
690    }
691
692    /*
693     * If the reference count on the object is more than one, we must
694     * take a copy of the object before we store.  A reference count
695     * of exactly 1 means that the object was just created during the
696     * evaluation of an expression, and we can safely use it since it
697     * is not used anywhere else.
698     */
699    NewObjDesc = ObjDesc;
700    if (ObjDesc->Common.ReferenceCount > 1)
701    {
702        Status = AcpiUtCopyIobjectToIobject (ObjDesc, &NewObjDesc, WalkState);
703        if (ACPI_FAILURE (Status))
704        {
705            return_ACPI_STATUS (Status);
706        }
707    }
708
709    /*
710     * If there is an object already in this slot, we either
711     * have to delete it, or if this is an argument and there
712     * is an object reference stored there, we have to do
713     * an indirect store!
714     */
715    if (CurrentObjDesc)
716    {
717        /*
718         * Check for an indirect store if an argument
719         * contains an object reference (stored as an Node).
720         * We don't allow this automatic dereferencing for
721         * locals, since a store to a local should overwrite
722         * anything there, including an object reference.
723         *
724         * If both Arg0 and Local0 contain RefOf (Local4):
725         *
726         * Store (1, Arg0)             - Causes indirect store to local4
727         * Store (1, Local0)           - Stores 1 in local0, overwriting
728         *                                  the reference to local4
729         * Store (1, DeRefof (Local0)) - Causes indirect store to local4
730         *
731         * Weird, but true.
732         */
733        if (Opcode == AML_ARG_OP)
734        {
735            /*
736             * If we have a valid reference object that came from RefOf(),
737             * do the indirect store
738             */
739            if ((ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) == ACPI_DESC_TYPE_OPERAND) &&
740                (CurrentObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
741                (CurrentObjDesc->Reference.Opcode == AML_REF_OF_OP))
742            {
743                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
744                        "Arg (%p) is an ObjRef(Node), storing in node %p\n",
745                        NewObjDesc, CurrentObjDesc));
746
747                /*
748                 * Store this object to the Node (perform the indirect store)
749                 * NOTE: No implicit conversion is performed, as per the ACPI
750                 * specification rules on storing to Locals/Args.
751                 */
752                Status = AcpiExStoreObjectToNode (NewObjDesc,
753                            CurrentObjDesc->Reference.Object, WalkState,
754                            ACPI_NO_IMPLICIT_CONVERSION);
755
756                /* Remove local reference if we copied the object above */
757
758                if (NewObjDesc != ObjDesc)
759                {
760                    AcpiUtRemoveReference (NewObjDesc);
761                }
762                return_ACPI_STATUS (Status);
763            }
764        }
765
766        /*
767         * Delete the existing object
768         * before storing the new one
769         */
770        AcpiDsMethodDataDeleteValue (Opcode, Index, WalkState);
771    }
772
773    /*
774     * Install the Obj descriptor (*NewObjDesc) into
775     * the descriptor for the Arg or Local.
776     * (increments the object reference count by one)
777     */
778    Status = AcpiDsMethodDataSetValue (Opcode, Index, NewObjDesc, WalkState);
779
780    /* Remove local reference if we copied the object above */
781
782    if (NewObjDesc != ObjDesc)
783    {
784        AcpiUtRemoveReference (NewObjDesc);
785    }
786
787    return_ACPI_STATUS (Status);
788}
789
790
791#ifdef ACPI_OBSOLETE_FUNCTIONS
792/*******************************************************************************
793 *
794 * FUNCTION:    AcpiDsMethodDataGetType
795 *
796 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
797 *              Index               - Which Local or Arg whose type to get
798 *              WalkState           - Current walk state object
799 *
800 * RETURN:      Data type of current value of the selected Arg or Local
801 *
802 * DESCRIPTION: Get the type of the object stored in the Local or Arg
803 *
804 ******************************************************************************/
805
806ACPI_OBJECT_TYPE
807AcpiDsMethodDataGetType (
808    UINT16                  Opcode,
809    UINT32                  Index,
810    ACPI_WALK_STATE         *WalkState)
811{
812    ACPI_STATUS             Status;
813    ACPI_NAMESPACE_NODE     *Node;
814    ACPI_OPERAND_OBJECT     *Object;
815
816
817    ACPI_FUNCTION_TRACE (DsMethodDataGetType);
818
819
820    /* Get the namespace node for the arg/local */
821
822    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
823    if (ACPI_FAILURE (Status))
824    {
825        return_VALUE ((ACPI_TYPE_NOT_FOUND));
826    }
827
828    /* Get the object */
829
830    Object = AcpiNsGetAttachedObject (Node);
831    if (!Object)
832    {
833        /* Uninitialized local/arg, return TYPE_ANY */
834
835        return_VALUE (ACPI_TYPE_ANY);
836    }
837
838    /* Get the object type */
839
840    return_VALUE (ACPI_GET_OBJECT_TYPE (Object));
841}
842#endif
843
844
845