dsmthdat.c revision 70243
1/*******************************************************************************
2 *
3 * Module Name: dsmthdat - control method arguments and local variables
4 *              $Revision: 37 $
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 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          DISPATCHER
128        MODULE_NAME         ("dsmthdat")
129
130
131/*******************************************************************************
132 *
133 * FUNCTION:    AcpiDsMethodDataInit
134 *
135 * PARAMETERS:  *ObjDesc
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     * AcpiCmCallocate().
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:  None
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_PRINT (ACPI_INFO,
219        ("MethodDeleteAll: Deleting local variables in %p\n", WalkState));
220
221    for (Index = 0; Index < MTH_NUM_LOCALS; Index++)
222    {
223        Object = WalkState->LocalVariables[Index].Object;
224        if (Object)
225        {
226            DEBUG_PRINT (TRACE_EXEC,
227                ("MethodDeleteAll: Deleting Local%d=%p\n", Index, Object));
228
229            /* Remove first */
230
231            WalkState->LocalVariables[Index].Object = NULL;
232
233            /* Was given a ref when stored */
234
235            AcpiCmRemoveReference (Object);
236       }
237    }
238
239
240    /* Delete the arguments */
241
242    DEBUG_PRINT (ACPI_INFO,
243        ("MethodDeleteAll: Deleting arguments in %p\n", WalkState));
244
245    for (Index = 0; Index < MTH_NUM_ARGS; Index++)
246    {
247        Object = WalkState->Arguments[Index].Object;
248        if (Object)
249        {
250            DEBUG_PRINT (TRACE_EXEC,
251                ("MethodDeleteAll: Deleting Arg%d=%p\n", Index, Object));
252
253            /* Remove first */
254
255            WalkState->Arguments[Index].Object = NULL;
256
257             /* Was given a ref when stored */
258
259            AcpiCmRemoveReference (Object);
260        }
261    }
262
263    return_ACPI_STATUS (AE_OK);
264}
265
266
267/*******************************************************************************
268 *
269 * FUNCTION:    AcpiDsMethodDataInitArgs
270 *
271 * PARAMETERS:  None
272 *
273 * RETURN:      Status
274 *
275 * DESCRIPTION: Initialize arguments for a method
276 *
277 ******************************************************************************/
278
279ACPI_STATUS
280AcpiDsMethodDataInitArgs (
281    ACPI_OPERAND_OBJECT     **Params,
282    UINT32                  MaxParamCount,
283    ACPI_WALK_STATE         *WalkState)
284{
285    ACPI_STATUS             Status;
286    UINT32                  Mindex;
287    UINT32                  Pindex;
288
289
290    FUNCTION_TRACE_PTR ("DsMethodDataInitArgs", Params);
291
292
293    if (!Params)
294    {
295        DEBUG_PRINT (TRACE_EXEC,
296            ("DsMethodDataInitArgs: No param list passed to method\n"));
297        return_ACPI_STATUS (AE_OK);
298    }
299
300    /* Copy passed parameters into the new method stack frame  */
301
302    for (Pindex = Mindex = 0;
303        (Mindex < MTH_NUM_ARGS) && (Pindex < MaxParamCount);
304        Mindex++)
305    {
306        if (Params[Pindex])
307        {
308            /*
309             * A valid parameter.
310             * Set the current method argument to the
311             * Params[Pindex++] argument object descriptor
312             */
313            Status = AcpiDsMethodDataSetValue (MTH_TYPE_ARG, Mindex,
314                                                Params[Pindex], WalkState);
315            if (ACPI_FAILURE (Status))
316            {
317                break;
318            }
319
320            Pindex++;
321        }
322
323        else
324        {
325            break;
326        }
327    }
328
329    DEBUG_PRINT (TRACE_EXEC,
330        ("DsMethodDataInitArgs: %d args passed to method\n", Pindex));
331    return_ACPI_STATUS (AE_OK);
332}
333
334
335/*******************************************************************************
336 *
337 * FUNCTION:    AcpiDsMethodDataGetEntry
338 *
339 * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
340 *              Index               - Which localVar or argument to get
341 *              Entry               - Pointer to where a pointer to the stack
342 *                                    entry is returned.
343 *
344 * RETURN:      Status
345 *
346 * DESCRIPTION: Get the address of the stack entry given by Type:Index
347 *
348 ******************************************************************************/
349
350ACPI_STATUS
351AcpiDsMethodDataGetEntry (
352    UINT32                  Type,
353    UINT32                  Index,
354    ACPI_WALK_STATE         *WalkState,
355    ACPI_OPERAND_OBJECT     ***Entry)
356{
357
358    FUNCTION_TRACE_U32 ("DsMethodDataGetEntry", Index);
359
360
361    /*
362     * Get the requested object.
363     * The stack "Type" is either a LocalVariable or an Argument
364     */
365
366    switch (Type)
367    {
368
369    case MTH_TYPE_LOCAL:
370
371        if (Index > MTH_MAX_LOCAL)
372        {
373            DEBUG_PRINT (ACPI_ERROR,
374                ("DsMethodDataGetEntry: LocalVar index %d is invalid (max %d)\n",
375                Index, MTH_MAX_LOCAL));
376            return_ACPI_STATUS (AE_BAD_PARAMETER);
377        }
378
379        *Entry =
380            (ACPI_OPERAND_OBJECT  **) &WalkState->LocalVariables[Index].Object;
381        break;
382
383
384    case MTH_TYPE_ARG:
385
386        if (Index > MTH_MAX_ARG)
387        {
388            DEBUG_PRINT (ACPI_ERROR,
389                ("DsMethodDataGetEntry: Argument index %d is invalid (max %d)\n",
390                Index, MTH_MAX_ARG));
391            return_ACPI_STATUS (AE_BAD_PARAMETER);
392        }
393
394        *Entry =
395            (ACPI_OPERAND_OBJECT  **) &WalkState->Arguments[Index].Object;
396        break;
397
398
399    default:
400        DEBUG_PRINT (ACPI_ERROR,
401            ("DsMethodDataGetEntry: Stack type %d is invalid\n",
402            Type));
403        return_ACPI_STATUS (AE_BAD_PARAMETER);
404    }
405
406
407    return_ACPI_STATUS (AE_OK);
408}
409
410
411/*******************************************************************************
412 *
413 * FUNCTION:    AcpiDsMethodDataSetEntry
414 *
415 * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
416 *              Index               - Which localVar or argument to get
417 *              Object              - Object to be inserted into the stack entry
418 *
419 * RETURN:      Status
420 *
421 * DESCRIPTION: Insert an object onto the method stack at entry Type:Index.
422 *
423 ******************************************************************************/
424
425ACPI_STATUS
426AcpiDsMethodDataSetEntry (
427    UINT32                  Type,
428    UINT32                  Index,
429    ACPI_OPERAND_OBJECT     *Object,
430    ACPI_WALK_STATE         *WalkState)
431{
432    ACPI_STATUS             Status;
433    ACPI_OPERAND_OBJECT     **Entry;
434
435
436    FUNCTION_TRACE ("DsMethodDataSetEntry");
437
438    /* Get a pointer to the stack entry to set */
439
440    Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry);
441    if (ACPI_FAILURE (Status))
442    {
443        return_ACPI_STATUS (Status);
444    }
445
446    /* Increment ref count so object can't be deleted while installed */
447
448    AcpiCmAddReference (Object);
449
450    /* Install the object into the stack entry */
451
452    *Entry = Object;
453
454    return_ACPI_STATUS (AE_OK);
455}
456
457
458/*******************************************************************************
459 *
460 * FUNCTION:    AcpiDsMethodDataGetType
461 *
462 * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
463 *              Index               - Which localVar or argument whose type
464 *                                      to get
465 *
466 * RETURN:      Data type of selected Arg or Local
467 *              Used only in ExecMonadic2()/TypeOp.
468 *
469 ******************************************************************************/
470
471OBJECT_TYPE_INTERNAL
472AcpiDsMethodDataGetType (
473    UINT32                  Type,
474    UINT32                  Index,
475    ACPI_WALK_STATE         *WalkState)
476{
477    ACPI_STATUS             Status;
478    ACPI_OPERAND_OBJECT     **Entry;
479    ACPI_OPERAND_OBJECT     *Object;
480
481
482    FUNCTION_TRACE ("DsMethodDataGetType");
483
484
485    /* Get a pointer to the requested stack entry */
486
487    Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry);
488    if (ACPI_FAILURE (Status))
489    {
490        return_VALUE ((ACPI_TYPE_NOT_FOUND));
491    }
492
493    /* Get the object from the method stack */
494
495    Object = *Entry;
496
497    /* Get the object type */
498
499    if (!Object)
500    {
501        /* Any == 0 => "uninitialized" -- see spec 15.2.3.5.2.28 */
502        return_VALUE (ACPI_TYPE_ANY);
503    }
504
505    return_VALUE (Object->Common.Type);
506}
507
508
509/*******************************************************************************
510 *
511 * FUNCTION:    AcpiDsMethodDataGetNte
512 *
513 * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
514 *              Index               - Which localVar or argument whose type
515 *                                      to get
516 *
517 * RETURN:      Get the Node associated with a local or arg.
518 *
519 ******************************************************************************/
520
521ACPI_NAMESPACE_NODE *
522AcpiDsMethodDataGetNte (
523    UINT32                  Type,
524    UINT32                  Index,
525    ACPI_WALK_STATE         *WalkState)
526{
527    ACPI_NAMESPACE_NODE     *Node = NULL;
528
529
530    FUNCTION_TRACE ("DsMethodDataGetNte");
531
532
533    switch (Type)
534    {
535
536    case MTH_TYPE_LOCAL:
537
538        if (Index > MTH_MAX_LOCAL)
539        {
540            DEBUG_PRINT (ACPI_ERROR,
541                ("DsMethodDataGetEntry: LocalVar index %d is invalid (max %d)\n",
542                Index, MTH_MAX_LOCAL));
543            return_PTR (Node);
544        }
545
546        Node =  &WalkState->LocalVariables[Index];
547        break;
548
549
550    case MTH_TYPE_ARG:
551
552        if (Index > MTH_MAX_ARG)
553        {
554            DEBUG_PRINT (ACPI_ERROR,
555                ("DsMethodDataGetEntry: Argument index %d is invalid (max %d)\n",
556                Index, MTH_MAX_ARG));
557            return_PTR (Node);
558        }
559
560        Node = &WalkState->Arguments[Index];
561        break;
562
563
564    default:
565        DEBUG_PRINT (ACPI_ERROR,
566            ("DsMethodDataGetEntry: Stack type %d is invalid\n",
567            Type));
568        break;
569    }
570
571
572    return_PTR (Node);
573}
574
575
576/*******************************************************************************
577 *
578 * FUNCTION:    AcpiDsMethodDataGetValue
579 *
580 * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
581 *              Index               - Which localVar or argument to get
582 *              *DestDesc            - Descriptor into which selected Arg
583 *                                    or Local value should be copied
584 *
585 * RETURN:      Status
586 *
587 * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame
588 *              at the current top of the method stack.
589 *              Used only in AcpiAmlResolveToValue().
590 *
591 ******************************************************************************/
592
593ACPI_STATUS
594AcpiDsMethodDataGetValue (
595    UINT32                  Type,
596    UINT32                  Index,
597    ACPI_WALK_STATE         *WalkState,
598    ACPI_OPERAND_OBJECT     **DestDesc)
599{
600    ACPI_STATUS             Status;
601    ACPI_OPERAND_OBJECT     **Entry;
602    ACPI_OPERAND_OBJECT     *Object;
603
604
605    FUNCTION_TRACE ("DsMethodDataGetValue");
606
607
608    /* Validate the object descriptor */
609
610    if (!DestDesc)
611    {
612        DEBUG_PRINT (ACPI_ERROR,
613            ("DsMethodDataGetValue: NULL object descriptor pointer\n"));
614        return_ACPI_STATUS (AE_BAD_PARAMETER);
615    }
616
617
618    /* Get a pointer to the requested method stack entry */
619
620    Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry);
621    if (ACPI_FAILURE (Status))
622    {
623        return_ACPI_STATUS (Status);
624    }
625
626    /* Get the object from the method stack */
627
628    Object = *Entry;
629
630
631    /* Examine the returned object, it must be valid. */
632
633    if (!Object)
634    {
635        /*
636         * Index points to uninitialized object stack value.
637         * This means that either 1) The expected argument was
638         * not passed to the method, or 2) A local variable
639         * was referenced by the method (via the ASL)
640         * before it was initialized.  Either case is an error.
641         */
642
643        switch (Type)
644        {
645        case MTH_TYPE_ARG:
646            DEBUG_PRINT (ACPI_ERROR,
647                ("DsMethodDataGetValue: Uninitialized Arg[%d] at entry %p\n",
648                Index, Entry));
649            return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
650            break;
651
652        case MTH_TYPE_LOCAL:
653            DEBUG_PRINT (ACPI_ERROR,
654                ("DsMethodDataGetValue: Uninitialized Local[%d] at entry %p\n",
655                Index, Entry));
656            return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
657            break;
658        }
659    }
660
661
662    /*
663     * Index points to initialized and valid object stack value.
664     * Return an additional reference to the object
665     */
666
667    *DestDesc = Object;
668    AcpiCmAddReference (Object);
669
670    return_ACPI_STATUS (AE_OK);
671}
672
673
674/*******************************************************************************
675 *
676 * FUNCTION:    AcpiDsMethodDataDeleteValue
677 *
678 * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
679 *              Index               - Which localVar or argument to delete
680 *
681 * RETURN:      Status
682 *
683 * DESCRIPTION: Delete the entry at Type:Index on the method stack.  Inserts
684 *              a null into the stack slot after the object is deleted.
685 *
686 ******************************************************************************/
687
688ACPI_STATUS
689AcpiDsMethodDataDeleteValue (
690    UINT32                  Type,
691    UINT32                  Index,
692    ACPI_WALK_STATE         *WalkState)
693{
694    ACPI_STATUS             Status;
695    ACPI_OPERAND_OBJECT     **Entry;
696    ACPI_OPERAND_OBJECT     *Object;
697
698
699    FUNCTION_TRACE ("DsMethodDataDeleteValue");
700
701
702    /* Get a pointer to the requested entry */
703
704    Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry);
705    if (ACPI_FAILURE (Status))
706    {
707        return_ACPI_STATUS (Status);
708    }
709
710    /* Get the current entry in this slot k */
711
712    Object = *Entry;
713
714    /*
715     * Undefine the Arg or Local by setting its descriptor
716     * pointer to NULL. Locals/Args can contain both
717     * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
718     */
719    *Entry = NULL;
720
721
722    if ((Object) &&
723        (VALID_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_INTERNAL)))
724    {
725        /*
726         * There is a valid object in this slot
727         * Decrement the reference count by one to balance the
728         * increment when the object was stored in the slot.
729         */
730
731        AcpiCmRemoveReference (Object);
732    }
733
734
735    return_ACPI_STATUS (AE_OK);
736}
737
738
739/*******************************************************************************
740 *
741 * FUNCTION:    AcpiDsMethodDataSetValue
742 *
743 * PARAMETERS:  Type                - Either MTH_TYPE_LOCAL or MTH_TYPE_ARG
744 *              Index               - Which localVar or argument to set
745 *              *SrcDesc            - Value to be stored
746 *              *DestDesc           - Descriptor into which *SrcDesc
747 *                                    can be copied, or NULL if one must
748 *                                    be allocated for the purpose.  If
749 *                                    provided, this descriptor will be
750 *                                    used for the new value.
751 *
752 * RETURN:      Status
753 *
754 * DESCRIPTION: Store a value in an Arg or Local.  The SrcDesc is installed
755 *              as the new value for the Arg or Local and the reference count
756 *              is incremented.
757 *
758 ******************************************************************************/
759
760ACPI_STATUS
761AcpiDsMethodDataSetValue (
762    UINT32                  Type,
763    UINT32                  Index,
764    ACPI_OPERAND_OBJECT     *SrcDesc,
765    ACPI_WALK_STATE         *WalkState)
766{
767    ACPI_STATUS             Status;
768    ACPI_OPERAND_OBJECT     **Entry;
769
770
771    FUNCTION_TRACE ("DsMethodDataSetValue");
772    DEBUG_PRINT (TRACE_EXEC,
773        ("DsMethodDataSetValue: Type=%d Idx=%d Obj=%p\n",
774        Type, Index, SrcDesc));
775
776
777    /* Parameter validation */
778
779    if (!SrcDesc)
780    {
781        return_ACPI_STATUS (AE_BAD_PARAMETER);
782    }
783
784
785    /* Get a pointer to the requested method stack entry */
786
787    Status = AcpiDsMethodDataGetEntry (Type, Index, WalkState, &Entry);
788    if (ACPI_FAILURE (Status))
789    {
790        goto Cleanup;
791    }
792
793    if (*Entry == SrcDesc)
794    {
795        DEBUG_PRINT (TRACE_EXEC,
796            ("DsMethodDataSetValue: Obj=%p already installed!\n",
797            SrcDesc));
798        goto Cleanup;
799    }
800
801
802    /*
803     * If there is an object already in this slot, we either
804     * have to delete it, or if this is an argument and there
805     * is an object reference stored there, we have to do
806     * an indirect store!
807     */
808
809    if (*Entry)
810    {
811        /*
812         * Check for an indirect store if an argument
813         * contains an object reference (stored as an Node).
814         * We don't allow this automatic dereferencing for
815         * locals, since a store to a local should overwrite
816         * anything there, including an object reference.
817         *
818         * If both Arg0 and Local0 contain RefOf (Local4):
819         *
820         * Store (1, Arg0)             - Causes indirect store to local4
821         * Store (1, Local0)           - Stores 1 in local0, overwriting
822         *                                  the reference to local4
823         * Store (1, DeRefof (Local0)) - Causes indirect store to local4
824         *
825         * Weird, but true.
826         */
827
828        if ((Type == MTH_TYPE_ARG) &&
829            (VALID_DESCRIPTOR_TYPE (*Entry, ACPI_DESC_TYPE_NAMED)))
830        {
831            DEBUG_PRINT (TRACE_EXEC,
832                ("DsMethodDataSetValue: Arg (%p) is an ObjRef(Node), storing in %p\n",
833                SrcDesc, *Entry));
834
835            /* Detach an existing object from the Node */
836
837            AcpiNsDetachObject ((ACPI_NAMESPACE_NODE *) *Entry);
838
839            /*
840             * Store this object into the Node
841             * (do the indirect store)
842             */
843
844            Status = AcpiNsAttachObject ((ACPI_NAMESPACE_NODE *) *Entry, SrcDesc,
845                                            SrcDesc->Common.Type);
846            return_ACPI_STATUS (Status);
847        }
848
849
850        /*
851         * Otherwise, just delete the existing object
852         * before storing the new one
853         */
854
855        AcpiDsMethodDataDeleteValue (Type, Index, WalkState);
856    }
857
858
859    /*
860     * Install the ObjStack descriptor (*SrcDesc) into
861     * the descriptor for the Arg or Local.
862     * Install the new object in the stack entry
863     * (increments the object reference count by one)
864     */
865
866    Status = AcpiDsMethodDataSetEntry (Type, Index, SrcDesc, WalkState);
867    if (ACPI_FAILURE (Status))
868    {
869        goto Cleanup;
870    }
871
872    /* Normal exit */
873
874    return_ACPI_STATUS (AE_OK);
875
876
877    /* Error exit */
878
879Cleanup:
880
881    return_ACPI_STATUS (Status);
882}
883
884