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