dsmthdat.c revision 77424
1/*******************************************************************************
2 *
3 * Module Name: dsmthdat - control method arguments and local variables
4 *              $Revision: 46 $
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights.  You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code.  No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision.  In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change.  Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee.  Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution.  In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government.  In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117#define __DSMTHDAT_C__
118
119#include "acpi.h"
120#include "acparser.h"
121#include "acdispat.h"
122#include "acinterp.h"
123#include "amlcode.h"
124#include "acnamesp.h"
125
126
127#define _COMPONENT          ACPI_DISPATCHER
128        MODULE_NAME         ("dsmthdat")
129
130
131/*******************************************************************************
132 *
133 * FUNCTION:    AcpiDsMethodDataInit
134 *
135 * PARAMETERS:  WalkState           - Current walk state object
136 *
137 * RETURN:      Status
138 *
139 * DESCRIPTION: Initialize the data structures that hold the method's arguments
140 *              and locals.  The data struct is an array of NTEs for each.
141 *              This allows RefOf and DeRefOf to work properly for these
142 *              special data types.
143 *
144 ******************************************************************************/
145
146ACPI_STATUS
147AcpiDsMethodDataInit (
148    ACPI_WALK_STATE         *WalkState)
149{
150    UINT32                  i;
151
152
153    FUNCTION_TRACE ("DsMethodDataInit");
154
155    /*
156     * WalkState fields are initialized to zero by the
157     * AcpiUtCallocate().
158     *
159     * An Node is assigned to each argument and local so
160     * that RefOf() can return a pointer to the Node.
161     */
162
163    /* Init the method arguments */
164
165    for (i = 0; i < MTH_NUM_ARGS; i++)
166    {
167        MOVE_UNALIGNED32_TO_32 (&WalkState->Arguments[i].Name,
168                                NAMEOF_ARG_NTE);
169        WalkState->Arguments[i].Name       |= (i << 24);
170        WalkState->Arguments[i].DataType    = ACPI_DESC_TYPE_NAMED;
171        WalkState->Arguments[i].Type        = ACPI_TYPE_ANY;
172        WalkState->Arguments[i].Flags       = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG;
173    }
174
175    /* Init the method locals */
176
177    for (i = 0; i < MTH_NUM_LOCALS; i++)
178    {
179        MOVE_UNALIGNED32_TO_32 (&WalkState->LocalVariables[i].Name,
180                                NAMEOF_LOCAL_NTE);
181
182        WalkState->LocalVariables[i].Name    |= (i << 24);
183        WalkState->LocalVariables[i].DataType = ACPI_DESC_TYPE_NAMED;
184        WalkState->LocalVariables[i].Type     = ACPI_TYPE_ANY;
185        WalkState->LocalVariables[i].Flags    = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL;
186    }
187
188    return_ACPI_STATUS (AE_OK);
189}
190
191
192/*******************************************************************************
193 *
194 * FUNCTION:    AcpiDsMethodDataDeleteAll
195 *
196 * PARAMETERS:  WalkState           - Current walk state object
197 *
198 * RETURN:      Status
199 *
200 * DESCRIPTION: Delete method locals and arguments.  Arguments are only
201 *              deleted if this method was called from another method.
202 *
203 ******************************************************************************/
204
205ACPI_STATUS
206AcpiDsMethodDataDeleteAll (
207    ACPI_WALK_STATE         *WalkState)
208{
209    UINT32                  Index;
210    ACPI_OPERAND_OBJECT     *Object;
211
212
213    FUNCTION_TRACE ("DsMethodDataDeleteAll");
214
215
216    /* Delete the locals */
217
218    DEBUG_PRINTP (ACPI_INFO, ("Deleting local variables in %p\n", WalkState));
219
220    for (Index = 0; Index < MTH_NUM_LOCALS; Index++)
221    {
222        Object = WalkState->LocalVariables[Index].Object;
223        if (Object)
224        {
225            DEBUG_PRINTP (TRACE_EXEC, ("Deleting Local%d=%p\n", Index, Object));
226
227            /* Remove first */
228
229            WalkState->LocalVariables[Index].Object = NULL;
230
231            /* Was given a ref when stored */
232
233            AcpiUtRemoveReference (Object);
234       }
235    }
236
237
238    /* Delete the arguments */
239
240    DEBUG_PRINTP (ACPI_INFO, ("Deleting arguments in %p\n", WalkState));
241
242    for (Index = 0; Index < MTH_NUM_ARGS; Index++)
243    {
244        Object = WalkState->Arguments[Index].Object;
245        if (Object)
246        {
247            DEBUG_PRINTP (TRACE_EXEC, ("Deleting Arg%d=%p\n", Index, Object));
248
249            /* Remove first */
250
251            WalkState->Arguments[Index].Object = NULL;
252
253             /* Was given a ref when stored */
254
255            AcpiUtRemoveReference (Object);
256        }
257    }
258
259    return_ACPI_STATUS (AE_OK);
260}
261
262
263/*******************************************************************************
264 *
265 * FUNCTION:    AcpiDsMethodDataInitArgs
266 *
267 * PARAMETERS:  *Params         - Pointer to a parameter list for the method
268 *              MaxParamCount   - The arg count for this method
269 *              WalkState       - Current walk state object
270 *
271 * RETURN:      Status
272 *
273 * DESCRIPTION: Initialize arguments for a method
274 *
275 ******************************************************************************/
276
277ACPI_STATUS
278AcpiDsMethodDataInitArgs (
279    ACPI_OPERAND_OBJECT     **Params,
280    UINT32                  MaxParamCount,
281    ACPI_WALK_STATE         *WalkState)
282{
283    ACPI_STATUS             Status;
284    UINT32                  Mindex;
285    UINT32                  Pindex;
286
287
288    FUNCTION_TRACE_PTR ("DsMethodDataInitArgs", Params);
289
290
291    if (!Params)
292    {
293        DEBUG_PRINTP (TRACE_EXEC, ("No param list passed to method\n"));
294        return_ACPI_STATUS (AE_OK);
295    }
296
297    /* Copy passed parameters into the new method stack frame  */
298
299    for (Pindex = Mindex = 0;
300        (Mindex < MTH_NUM_ARGS) && (Pindex < MaxParamCount);
301        Mindex++)
302    {
303        if (Params[Pindex])
304        {
305            /*
306             * A valid parameter.
307             * Set the current method argument to the
308             * Params[Pindex++] argument object descriptor
309             */
310            Status = AcpiDsStoreObjectToLocal (AML_ARG_OP, Mindex,
311                            Params[Pindex], WalkState);
312            if (ACPI_FAILURE (Status))
313            {
314                break;
315            }
316
317            Pindex++;
318        }
319
320        else
321        {
322            break;
323        }
324    }
325
326    DEBUG_PRINTP (TRACE_EXEC, ("%d args passed to method\n", Pindex));
327    return_ACPI_STATUS (AE_OK);
328}
329
330
331/*******************************************************************************
332 *
333 * FUNCTION:    AcpiDsMethodDataGetEntry
334 *
335 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
336 *              Index               - Which localVar or argument to get
337 *              Entry               - Pointer to where a pointer to the stack
338 *                                    entry is returned.
339 *              WalkState           - Current walk state object
340 *
341 * RETURN:      Status
342 *
343 * DESCRIPTION: Get the address of the object entry given by Opcode:Index
344 *
345 ******************************************************************************/
346
347ACPI_STATUS
348AcpiDsMethodDataGetEntry (
349    UINT16                  Opcode,
350    UINT32                  Index,
351    ACPI_WALK_STATE         *WalkState,
352    ACPI_OPERAND_OBJECT     ***Entry)
353{
354
355    FUNCTION_TRACE_U32 ("DsMethodDataGetEntry", Index);
356
357
358    /*
359     * Get the requested object.
360     * The stack "Opcode" is either a LocalVariable or an Argument
361     */
362
363    switch (Opcode)
364    {
365
366    case AML_LOCAL_OP:
367
368        if (Index > MTH_MAX_LOCAL)
369        {
370            DEBUG_PRINTP (ACPI_ERROR, ("LocalVar index %d is invalid (max %d)\n",
371                Index, MTH_MAX_LOCAL));
372            return_ACPI_STATUS (AE_BAD_PARAMETER);
373        }
374
375        *Entry = (ACPI_OPERAND_OBJECT  **)
376                    &WalkState->LocalVariables[Index].Object;
377        break;
378
379
380    case AML_ARG_OP:
381
382        if (Index > MTH_MAX_ARG)
383        {
384            DEBUG_PRINTP (ACPI_ERROR, ("Arg index %d is invalid (max %d)\n",
385                Index, MTH_MAX_ARG));
386            return_ACPI_STATUS (AE_BAD_PARAMETER);
387        }
388
389        *Entry = (ACPI_OPERAND_OBJECT  **)
390                    &WalkState->Arguments[Index].Object;
391        break;
392
393
394    default:
395        DEBUG_PRINTP (ACPI_ERROR, ("Opcode %d is invalid\n", Opcode));
396        return_ACPI_STATUS (AE_BAD_PARAMETER);
397    }
398
399
400    return_ACPI_STATUS (AE_OK);
401}
402
403
404/*******************************************************************************
405 *
406 * FUNCTION:    AcpiDsMethodDataSetEntry
407 *
408 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
409 *              Index               - Which localVar or argument to get
410 *              Object              - Object to be inserted into the stack entry
411 *              WalkState           - Current walk state object
412 *
413 * RETURN:      Status
414 *
415 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
416 *
417 ******************************************************************************/
418
419ACPI_STATUS
420AcpiDsMethodDataSetEntry (
421    UINT16                  Opcode,
422    UINT32                  Index,
423    ACPI_OPERAND_OBJECT     *Object,
424    ACPI_WALK_STATE         *WalkState)
425{
426    ACPI_STATUS             Status;
427    ACPI_OPERAND_OBJECT     **Entry;
428
429
430    FUNCTION_TRACE ("DsMethodDataSetEntry");
431
432    /* Get a pointer to the stack entry to set */
433
434    Status = AcpiDsMethodDataGetEntry (Opcode, Index, WalkState, &Entry);
435    if (ACPI_FAILURE (Status))
436    {
437        return_ACPI_STATUS (Status);
438    }
439
440    /* Increment ref count so object can't be deleted while installed */
441
442    AcpiUtAddReference (Object);
443
444    /* Install the object into the stack entry */
445
446    *Entry = Object;
447
448    return_ACPI_STATUS (AE_OK);
449}
450
451
452/*******************************************************************************
453 *
454 * FUNCTION:    AcpiDsMethodDataGetType
455 *
456 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
457 *              Index               - Which localVar or argument whose type
458 *                                      to get
459 *              WalkState           - Current walk state object
460 *
461 * RETURN:      Data type of selected Arg or Local
462 *              Used only in ExecMonadic2()/TypeOp.
463 *
464 ******************************************************************************/
465
466ACPI_OBJECT_TYPE8
467AcpiDsMethodDataGetType (
468    UINT16                  Opcode,
469    UINT32                  Index,
470    ACPI_WALK_STATE         *WalkState)
471{
472    ACPI_STATUS             Status;
473    ACPI_OPERAND_OBJECT     **Entry;
474    ACPI_OPERAND_OBJECT     *Object;
475
476
477    FUNCTION_TRACE ("DsMethodDataGetType");
478
479
480    /* Get a pointer to the requested stack entry */
481
482    Status = AcpiDsMethodDataGetEntry (Opcode, Index, WalkState, &Entry);
483    if (ACPI_FAILURE (Status))
484    {
485        return_VALUE ((ACPI_TYPE_NOT_FOUND));
486    }
487
488    /* Get the object from the method stack */
489
490    Object = *Entry;
491
492    /* Get the object type */
493
494    if (!Object)
495    {
496        /* Any == 0 => "uninitialized" -- see spec 15.2.3.5.2.28 */
497        return_VALUE (ACPI_TYPE_ANY);
498    }
499
500    return_VALUE (Object->Common.Type);
501}
502
503
504/*******************************************************************************
505 *
506 * FUNCTION:    AcpiDsMethodDataGetNode
507 *
508 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
509 *              Index               - Which localVar or argument whose type
510 *                                      to get
511 *              WalkState           - Current walk state object
512 *
513 * RETURN:      Get the Node associated with a local or arg.
514 *
515 ******************************************************************************/
516
517ACPI_NAMESPACE_NODE *
518AcpiDsMethodDataGetNode (
519    UINT16                  Opcode,
520    UINT32                  Index,
521    ACPI_WALK_STATE         *WalkState)
522{
523    ACPI_NAMESPACE_NODE     *Node = NULL;
524
525
526    FUNCTION_TRACE ("DsMethodDataGetNode");
527
528
529    switch (Opcode)
530    {
531
532    case AML_LOCAL_OP:
533
534        if (Index > MTH_MAX_LOCAL)
535        {
536            DEBUG_PRINTP (ACPI_ERROR, ("Local index %d is invalid (max %d)\n",
537                Index, MTH_MAX_LOCAL));
538            return_PTR (Node);
539        }
540
541        Node =  &WalkState->LocalVariables[Index];
542        break;
543
544
545    case AML_ARG_OP:
546
547        if (Index > MTH_MAX_ARG)
548        {
549            DEBUG_PRINTP (ACPI_ERROR, ("Arg index %d is invalid (max %d)\n",
550                Index, MTH_MAX_ARG));
551            return_PTR (Node);
552        }
553
554        Node = &WalkState->Arguments[Index];
555        break;
556
557
558    default:
559        DEBUG_PRINTP (ACPI_ERROR, ("Opcode %d is invalid\n", Opcode));
560        break;
561    }
562
563
564    return_PTR (Node);
565}
566
567
568/*******************************************************************************
569 *
570 * FUNCTION:    AcpiDsMethodDataGetValue
571 *
572 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
573 *              Index               - Which localVar or argument to get
574 *              WalkState           - Current walk state object
575 *              *DestDesc           - Ptr to Descriptor into which selected Arg
576 *                                    or Local value should be copied
577 *
578 * RETURN:      Status
579 *
580 * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame
581 *              at the current top of the method stack.
582 *              Used only in AcpiExResolveToValue().
583 *
584 ******************************************************************************/
585
586ACPI_STATUS
587AcpiDsMethodDataGetValue (
588    UINT16                  Opcode,
589    UINT32                  Index,
590    ACPI_WALK_STATE         *WalkState,
591    ACPI_OPERAND_OBJECT     **DestDesc)
592{
593    ACPI_STATUS             Status;
594    ACPI_OPERAND_OBJECT     **Entry;
595    ACPI_OPERAND_OBJECT     *Object;
596
597
598    FUNCTION_TRACE ("DsMethodDataGetValue");
599
600
601    /* Validate the object descriptor */
602
603    if (!DestDesc)
604    {
605        DEBUG_PRINTP (ACPI_ERROR, ("Null object descriptor pointer\n"));
606        return_ACPI_STATUS (AE_BAD_PARAMETER);
607    }
608
609
610    /* Get a pointer to the requested method stack entry */
611
612    Status = AcpiDsMethodDataGetEntry (Opcode, Index, WalkState, &Entry);
613    if (ACPI_FAILURE (Status))
614    {
615        return_ACPI_STATUS (Status);
616    }
617
618    /* Get the object from the method stack */
619
620    Object = *Entry;
621
622
623    /* Examine the returned object, it must be valid. */
624
625    if (!Object)
626    {
627        /*
628         * Index points to uninitialized object stack value.
629         * This means that either 1) The expected argument was
630         * not passed to the method, or 2) A local variable
631         * was referenced by the method (via the ASL)
632         * before it was initialized.  Either case is an error.
633         */
634
635        switch (Opcode)
636        {
637        case AML_ARG_OP:
638
639            DEBUG_PRINTP (ACPI_ERROR, ("Uninitialized Arg[%d] at entry %p\n",
640                Index, Entry));
641
642            return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
643            break;
644
645        case AML_LOCAL_OP:
646
647            DEBUG_PRINTP (ACPI_ERROR, ("Uninitialized Local[%d] at entry %p\n",
648                Index, Entry));
649
650            return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
651            break;
652        }
653    }
654
655
656    /*
657     * Index points to initialized and valid object stack value.
658     * Return an additional reference to the object
659     */
660
661    *DestDesc = Object;
662    AcpiUtAddReference (Object);
663
664    return_ACPI_STATUS (AE_OK);
665}
666
667
668/*******************************************************************************
669 *
670 * FUNCTION:    AcpiDsMethodDataDeleteValue
671 *
672 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
673 *              Index               - Which localVar or argument to delete
674 *              WalkState           - Current walk state object
675 *
676 * RETURN:      Status
677 *
678 * DESCRIPTION: Delete the entry at Opcode:Index on the method stack.  Inserts
679 *              a null into the stack slot after the object is deleted.
680 *
681 ******************************************************************************/
682
683ACPI_STATUS
684AcpiDsMethodDataDeleteValue (
685    UINT16                  Opcode,
686    UINT32                  Index,
687    ACPI_WALK_STATE         *WalkState)
688{
689    ACPI_STATUS             Status;
690    ACPI_OPERAND_OBJECT     **Entry;
691    ACPI_OPERAND_OBJECT     *Object;
692
693
694    FUNCTION_TRACE ("DsMethodDataDeleteValue");
695
696
697    /* Get a pointer to the requested entry */
698
699    Status = AcpiDsMethodDataGetEntry (Opcode, Index, WalkState, &Entry);
700    if (ACPI_FAILURE (Status))
701    {
702        return_ACPI_STATUS (Status);
703    }
704
705    /* Get the current entry in this slot k */
706
707    Object = *Entry;
708
709    /*
710     * Undefine the Arg or Local by setting its descriptor
711     * pointer to NULL. Locals/Args can contain both
712     * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
713     */
714    *Entry = NULL;
715
716
717    if ((Object) &&
718        (VALID_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_INTERNAL)))
719    {
720        /*
721         * There is a valid object in this slot
722         * Decrement the reference count by one to balance the
723         * increment when the object was stored in the slot.
724         */
725        AcpiUtRemoveReference (Object);
726    }
727
728
729    return_ACPI_STATUS (AE_OK);
730}
731
732
733/*******************************************************************************
734 *
735 * FUNCTION:    AcpiDsStoreObjectToLocal
736 *
737 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
738 *              Index               - Which localVar or argument to set
739 *              SrcDesc             - Value to be stored
740 *              WalkState           - Current walk state
741 *
742 * RETURN:      Status
743 *
744 * DESCRIPTION: Store a value in an Arg or Local.  The SrcDesc is installed
745 *              as the new value for the Arg or Local and the reference count
746 *              for SrcDesc is incremented.
747 *
748 ******************************************************************************/
749
750ACPI_STATUS
751AcpiDsStoreObjectToLocal (
752    UINT16                  Opcode,
753    UINT32                  Index,
754    ACPI_OPERAND_OBJECT     *SrcDesc,
755    ACPI_WALK_STATE         *WalkState)
756{
757    ACPI_STATUS             Status;
758    ACPI_OPERAND_OBJECT     **Entry;
759
760
761    FUNCTION_TRACE ("DsMethodDataSetValue");
762    DEBUG_PRINTP (TRACE_EXEC, ("Opcode=%d Idx=%d Obj=%p\n",
763        Opcode, Index, SrcDesc));
764
765
766    /* Parameter validation */
767
768    if (!SrcDesc)
769    {
770        return_ACPI_STATUS (AE_BAD_PARAMETER);
771    }
772
773
774    /* Get a pointer to the requested method stack entry */
775
776    Status = AcpiDsMethodDataGetEntry (Opcode, Index, WalkState, &Entry);
777    if (ACPI_FAILURE (Status))
778    {
779        goto Cleanup;
780    }
781
782    if (*Entry == SrcDesc)
783    {
784        DEBUG_PRINTP (TRACE_EXEC, ("Obj=%p already installed!\n", SrcDesc));
785        goto Cleanup;
786    }
787
788
789    /*
790     * If there is an object already in this slot, we either
791     * have to delete it, or if this is an argument and there
792     * is an object reference stored there, we have to do
793     * an indirect store!
794     */
795
796    if (*Entry)
797    {
798        /*
799         * Check for an indirect store if an argument
800         * contains an object reference (stored as an Node).
801         * We don't allow this automatic dereferencing for
802         * locals, since a store to a local should overwrite
803         * anything there, including an object reference.
804         *
805         * If both Arg0 and Local0 contain RefOf (Local4):
806         *
807         * Store (1, Arg0)             - Causes indirect store to local4
808         * Store (1, Local0)           - Stores 1 in local0, overwriting
809         *                                  the reference to local4
810         * Store (1, DeRefof (Local0)) - Causes indirect store to local4
811         *
812         * Weird, but true.
813         */
814
815        if ((Opcode == AML_ARG_OP) &&
816            (VALID_DESCRIPTOR_TYPE (*Entry, ACPI_DESC_TYPE_NAMED)))
817        {
818            DEBUG_PRINTP (TRACE_EXEC,
819                ("Arg (%p) is an ObjRef(Node), storing in %p\n",
820                SrcDesc, *Entry));
821
822            /* Detach an existing object from the Node */
823
824            AcpiNsDetachObject ((ACPI_NAMESPACE_NODE *) *Entry);
825
826            /*
827             * Store this object into the Node
828             * (do the indirect store)
829             */
830            Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) *Entry, SrcDesc,
831                                            SrcDesc->Common.Type);
832            return_ACPI_STATUS (Status);
833        }
834
835
836#ifdef ACPI_ENABLE_IMPLICIT_CONVERSION
837        /*
838         * Perform "Implicit conversion" of the new object to the type of the
839         * existing object
840         */
841        Status = AcpiExConvertToTargetType ((*Entry)->Common.Type, &SrcDesc, WalkState);
842        if (ACPI_FAILURE (Status))
843        {
844            goto Cleanup;
845        }
846#endif
847
848        /*
849         * Delete the existing object
850         * before storing the new one
851         */
852        AcpiDsMethodDataDeleteValue (Opcode, Index, WalkState);
853    }
854
855
856    /*
857     * Install the ObjStack descriptor (*SrcDesc) into
858     * the descriptor for the Arg or Local.
859     * Install the new object in the stack entry
860     * (increments the object reference count by one)
861     */
862    Status = AcpiDsMethodDataSetEntry (Opcode, Index, SrcDesc, WalkState);
863    if (ACPI_FAILURE (Status))
864    {
865        goto Cleanup;
866    }
867
868    /* Normal exit */
869
870    return_ACPI_STATUS (AE_OK);
871
872
873    /* Error exit */
874
875Cleanup:
876
877    return_ACPI_STATUS (Status);
878}
879
880