dsmthdat.c revision 114237
1169092Sdeischen/*******************************************************************************
2169092Sdeischen *
3169092Sdeischen * Module Name: dsmthdat - control method arguments and local variables
4156608Sdeischen *              $Revision: 69 $
5156608Sdeischen *
6169092Sdeischen ******************************************************************************/
7156608Sdeischen
8156608Sdeischen/******************************************************************************
9156608Sdeischen *
10156608Sdeischen * 1. Copyright Notice
11156608Sdeischen *
12169092Sdeischen * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
13156608Sdeischen * All rights reserved.
14156608Sdeischen *
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 "acdispat.h"
121#include "amlcode.h"
122#include "acnamesp.h"
123#include "acinterp.h"
124
125
126#define _COMPONENT          ACPI_DISPATCHER
127        ACPI_MODULE_NAME    ("dsmthdat")
128
129
130/*******************************************************************************
131 *
132 * FUNCTION:    AcpiDsMethodDataInit
133 *
134 * PARAMETERS:  WalkState           - Current walk state object
135 *
136 * RETURN:      Status
137 *
138 * DESCRIPTION: Initialize the data structures that hold the method's arguments
139 *              and locals.  The data struct is an array of NTEs for each.
140 *              This allows RefOf and DeRefOf to work properly for these
141 *              special data types.
142 *
143 * NOTES:       WalkState fields are initialized to zero by the
144 *              ACPI_MEM_CALLOCATE().
145 *
146 *              A pseudo-Namespace Node is assigned to each argument and local
147 *              so that RefOf() can return a pointer to the Node.
148 *
149 ******************************************************************************/
150
151void
152AcpiDsMethodDataInit (
153    ACPI_WALK_STATE         *WalkState)
154{
155    UINT32                  i;
156
157
158    ACPI_FUNCTION_TRACE ("DsMethodDataInit");
159
160
161    /* Init the method arguments */
162
163    for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
164    {
165        ACPI_MOVE_UNALIGNED32_TO_32 (&WalkState->Arguments[i].Name,
166                                NAMEOF_ARG_NTE);
167        WalkState->Arguments[i].Name.Integer |= (i << 24);
168        WalkState->Arguments[i].Descriptor    = ACPI_DESC_TYPE_NAMED;
169        WalkState->Arguments[i].Type          = ACPI_TYPE_ANY;
170        WalkState->Arguments[i].Flags         = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG;
171    }
172
173    /* Init the method locals */
174
175    for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
176    {
177        ACPI_MOVE_UNALIGNED32_TO_32 (&WalkState->LocalVariables[i].Name,
178                                NAMEOF_LOCAL_NTE);
179
180        WalkState->LocalVariables[i].Name.Integer |= (i << 24);
181        WalkState->LocalVariables[i].Descriptor    = ACPI_DESC_TYPE_NAMED;
182        WalkState->LocalVariables[i].Type          = ACPI_TYPE_ANY;
183        WalkState->LocalVariables[i].Flags         = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL;
184    }
185
186    return_VOID;
187}
188
189
190/*******************************************************************************
191 *
192 * FUNCTION:    AcpiDsMethodDataDeleteAll
193 *
194 * PARAMETERS:  WalkState           - Current walk state object
195 *
196 * RETURN:      None
197 *
198 * DESCRIPTION: Delete method locals and arguments.  Arguments are only
199 *              deleted if this method was called from another method.
200 *
201 ******************************************************************************/
202
203void
204AcpiDsMethodDataDeleteAll (
205    ACPI_WALK_STATE         *WalkState)
206{
207    UINT32                  Index;
208
209
210    ACPI_FUNCTION_TRACE ("DsMethodDataDeleteAll");
211
212
213    /* Detach the locals */
214
215    for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++)
216    {
217        if (WalkState->LocalVariables[Index].Object)
218        {
219            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%d=%p\n",
220                    Index, WalkState->LocalVariables[Index].Object));
221
222            /* Detach object (if present) and remove a reference */
223
224            AcpiNsDetachObject (&WalkState->LocalVariables[Index]);
225        }
226    }
227
228    /* Detach the arguments */
229
230    for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++)
231    {
232        if (WalkState->Arguments[Index].Object)
233        {
234            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%d=%p\n",
235                    Index, WalkState->Arguments[Index].Object));
236
237            /* Detach object (if present) and remove a reference */
238
239            AcpiNsDetachObject (&WalkState->Arguments[Index]);
240        }
241    }
242
243    return_VOID;
244}
245
246
247/*******************************************************************************
248 *
249 * FUNCTION:    AcpiDsMethodDataInitArgs
250 *
251 * PARAMETERS:  *Params         - Pointer to a parameter list for the method
252 *              MaxParamCount   - The arg count for this method
253 *              WalkState       - Current walk state object
254 *
255 * RETURN:      Status
256 *
257 * DESCRIPTION: Initialize arguments for a method.  The parameter list is a list
258 *              of ACPI operand objects, either null terminated or whose length
259 *              is defined by MaxParamCount.
260 *
261 ******************************************************************************/
262
263ACPI_STATUS
264AcpiDsMethodDataInitArgs (
265    ACPI_OPERAND_OBJECT     **Params,
266    UINT32                  MaxParamCount,
267    ACPI_WALK_STATE         *WalkState)
268{
269    ACPI_STATUS             Status;
270    UINT32                  Index = 0;
271
272
273    ACPI_FUNCTION_TRACE_PTR ("DsMethodDataInitArgs", Params);
274
275
276    if (!Params)
277    {
278        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "No param list passed to method\n"));
279        return_ACPI_STATUS (AE_OK);
280    }
281
282    /* Copy passed parameters into the new method stack frame  */
283
284    while ((Index < ACPI_METHOD_NUM_ARGS) && (Index < MaxParamCount) && Params[Index])
285    {
286        /*
287         * A valid parameter.
288         * Store the argument in the method/walk descriptor
289         */
290        Status = AcpiDsStoreObjectToLocal (AML_ARG_OP, Index, Params[Index],
291                                            WalkState);
292        if (ACPI_FAILURE (Status))
293        {
294            return_ACPI_STATUS (Status);
295        }
296
297        Index++;
298    }
299
300    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%d args passed to method\n", Index));
301    return_ACPI_STATUS (AE_OK);
302}
303
304
305/*******************************************************************************
306 *
307 * FUNCTION:    AcpiDsMethodDataGetNode
308 *
309 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
310 *              Index               - Which localVar or argument whose type
311 *                                      to get
312 *              WalkState           - Current walk state object
313 *
314 * RETURN:      Get the Node associated with a local or arg.
315 *
316 ******************************************************************************/
317
318ACPI_STATUS
319AcpiDsMethodDataGetNode (
320    UINT16                  Opcode,
321    UINT32                  Index,
322    ACPI_WALK_STATE         *WalkState,
323    ACPI_NAMESPACE_NODE     **Node)
324{
325    ACPI_FUNCTION_TRACE ("DsMethodDataGetNode");
326
327
328    /*
329     * Method Locals and Arguments are supported
330     */
331    switch (Opcode)
332    {
333    case AML_LOCAL_OP:
334
335        if (Index > ACPI_METHOD_MAX_LOCAL)
336        {
337            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Local index %d is invalid (max %d)\n",
338                Index, ACPI_METHOD_MAX_LOCAL));
339            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
340        }
341
342        /* Return a pointer to the pseudo-node */
343
344        *Node = &WalkState->LocalVariables[Index];
345        break;
346
347    case AML_ARG_OP:
348
349        if (Index > ACPI_METHOD_MAX_ARG)
350        {
351            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Arg index %d is invalid (max %d)\n",
352                Index, ACPI_METHOD_MAX_ARG));
353            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
354        }
355
356        /* Return a pointer to the pseudo-node */
357
358        *Node = &WalkState->Arguments[Index];
359        break;
360
361    default:
362        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Opcode %d is invalid\n", Opcode));
363        return_ACPI_STATUS (AE_AML_BAD_OPCODE);
364    }
365
366    return_ACPI_STATUS (AE_OK);
367}
368
369
370/*******************************************************************************
371 *
372 * FUNCTION:    AcpiDsMethodDataSetValue
373 *
374 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
375 *              Index               - Which localVar or argument to get
376 *              Object              - Object to be inserted into the stack entry
377 *              WalkState           - Current walk state object
378 *
379 * RETURN:      Status
380 *
381 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
382 *              Note: There is no "implicit conversion" for locals.
383 *
384 ******************************************************************************/
385
386ACPI_STATUS
387AcpiDsMethodDataSetValue (
388    UINT16                  Opcode,
389    UINT32                  Index,
390    ACPI_OPERAND_OBJECT     *Object,
391    ACPI_WALK_STATE         *WalkState)
392{
393    ACPI_STATUS             Status;
394    ACPI_NAMESPACE_NODE     *Node;
395    ACPI_OPERAND_OBJECT     *NewDesc = Object;
396
397
398    ACPI_FUNCTION_TRACE ("DsMethodDataSetValue");
399
400
401    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
402        "obj %p op %X, ref count = %d [%s]\n", Object,
403        Opcode, Object->Common.ReferenceCount,
404        AcpiUtGetTypeName (Object->Common.Type)));
405
406    /* Get the namespace node for the arg/local */
407
408    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
409    if (ACPI_FAILURE (Status))
410    {
411        return_ACPI_STATUS (Status);
412    }
413
414    /*
415     * If the object has just been created and is not attached to anything,
416     * (the reference count is 1), then we can just store it directly into
417     * the arg/local.  Otherwise, we must copy it.
418     */
419    if (Object->Common.ReferenceCount > 1)
420    {
421        Status = AcpiUtCopyIobjectToIobject (Object, &NewDesc, WalkState);
422        if (ACPI_FAILURE (Status))
423        {
424            return_ACPI_STATUS (Status);
425        }
426
427       ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object Copied %p, new %p\n",
428           Object, NewDesc));
429    }
430    else
431    {
432        /* Increment ref count so object can't be deleted while installed */
433
434        AcpiUtAddReference (NewDesc);
435    }
436
437    /* Install the object */
438
439    Node->Object = NewDesc;
440    return_ACPI_STATUS (Status);
441}
442
443
444/*******************************************************************************
445 *
446 * FUNCTION:    AcpiDsMethodDataGetType
447 *
448 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
449 *              Index               - Which localVar or argument whose type
450 *                                      to get
451 *              WalkState           - Current walk state object
452 *
453 * RETURN:      Data type of current value of the selected Arg or Local
454 *
455 ******************************************************************************/
456
457ACPI_OBJECT_TYPE
458AcpiDsMethodDataGetType (
459    UINT16                  Opcode,
460    UINT32                  Index,
461    ACPI_WALK_STATE         *WalkState)
462{
463    ACPI_STATUS             Status;
464    ACPI_NAMESPACE_NODE     *Node;
465    ACPI_OPERAND_OBJECT     *Object;
466
467
468    ACPI_FUNCTION_TRACE ("DsMethodDataGetType");
469
470
471    /* Get the namespace node for the arg/local */
472
473    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
474    if (ACPI_FAILURE (Status))
475    {
476        return_VALUE ((ACPI_TYPE_NOT_FOUND));
477    }
478
479    /* Get the object */
480
481    Object = AcpiNsGetAttachedObject (Node);
482    if (!Object)
483    {
484        /* Uninitialized local/arg, return TYPE_ANY */
485
486        return_VALUE (ACPI_TYPE_ANY);
487    }
488
489    /* Get the object type */
490
491    return_VALUE (ACPI_GET_OBJECT_TYPE (Object));
492}
493
494
495/*******************************************************************************
496 *
497 * FUNCTION:    AcpiDsMethodDataGetValue
498 *
499 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
500 *              Index               - Which localVar or argument to get
501 *              WalkState           - Current walk state object
502 *              *DestDesc           - Ptr to Descriptor into which selected Arg
503 *                                    or Local value should be copied
504 *
505 * RETURN:      Status
506 *
507 * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame
508 *              at the current top of the method stack.
509 *              Used only in AcpiExResolveToValue().
510 *
511 ******************************************************************************/
512
513ACPI_STATUS
514AcpiDsMethodDataGetValue (
515    UINT16                  Opcode,
516    UINT32                  Index,
517    ACPI_WALK_STATE         *WalkState,
518    ACPI_OPERAND_OBJECT     **DestDesc)
519{
520    ACPI_STATUS             Status;
521    ACPI_NAMESPACE_NODE     *Node;
522    ACPI_OPERAND_OBJECT     *Object;
523
524
525    ACPI_FUNCTION_TRACE ("DsMethodDataGetValue");
526
527
528    /* Validate the object descriptor */
529
530    if (!DestDesc)
531    {
532        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null object descriptor pointer\n"));
533        return_ACPI_STATUS (AE_BAD_PARAMETER);
534    }
535
536    /* Get the namespace node for the arg/local */
537
538    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
539    if (ACPI_FAILURE (Status))
540    {
541        return_ACPI_STATUS (Status);
542    }
543
544    /* Get the object from the node */
545
546    Object = Node->Object;
547
548    /* Examine the returned object, it must be valid. */
549
550    if (!Object)
551    {
552        /*
553         * Index points to uninitialized object.
554         * This means that either 1) The expected argument was
555         * not passed to the method, or 2) A local variable
556         * was referenced by the method (via the ASL)
557         * before it was initialized.  Either case is an error.
558         */
559        switch (Opcode)
560        {
561        case AML_ARG_OP:
562
563            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Arg[%d] at node %p\n",
564                Index, Node));
565
566            return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
567
568        case AML_LOCAL_OP:
569
570            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Local[%d] at node %p\n",
571                Index, Node));
572
573            return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
574
575        default:
576            return_ACPI_STATUS (AE_AML_INTERNAL);
577        }
578    }
579
580    /*
581     * The Index points to an initialized and valid object.
582     * Return an additional reference to the object
583     */
584    *DestDesc = Object;
585    AcpiUtAddReference (Object);
586
587    return_ACPI_STATUS (AE_OK);
588}
589
590
591/*******************************************************************************
592 *
593 * FUNCTION:    AcpiDsMethodDataDeleteValue
594 *
595 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
596 *              Index               - Which localVar or argument to delete
597 *              WalkState           - Current walk state object
598 *
599 * RETURN:      None
600 *
601 * DESCRIPTION: Delete the entry at Opcode:Index on the method stack.  Inserts
602 *              a null into the stack slot after the object is deleted.
603 *
604 ******************************************************************************/
605
606void
607AcpiDsMethodDataDeleteValue (
608    UINT16                  Opcode,
609    UINT32                  Index,
610    ACPI_WALK_STATE         *WalkState)
611{
612    ACPI_STATUS             Status;
613    ACPI_NAMESPACE_NODE     *Node;
614    ACPI_OPERAND_OBJECT     *Object;
615
616
617    ACPI_FUNCTION_TRACE ("DsMethodDataDeleteValue");
618
619
620    /* Get the namespace node for the arg/local */
621
622    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
623    if (ACPI_FAILURE (Status))
624    {
625        return_VOID;
626    }
627
628    /* Get the associated object */
629
630    Object = AcpiNsGetAttachedObject (Node);
631
632    /*
633     * Undefine the Arg or Local by setting its descriptor
634     * pointer to NULL. Locals/Args can contain both
635     * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
636     */
637    Node->Object = NULL;
638
639    if ((Object) &&
640        (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND))
641    {
642        /*
643         * There is a valid object.
644         * Decrement the reference count by one to balance the
645         * increment when the object was stored.
646         */
647        AcpiUtRemoveReference (Object);
648    }
649
650    return_VOID;
651}
652
653
654/*******************************************************************************
655 *
656 * FUNCTION:    AcpiDsStoreObjectToLocal
657 *
658 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
659 *              Index               - Which localVar or argument to set
660 *              ObjDesc             - Value to be stored
661 *              WalkState           - Current walk state
662 *
663 * RETURN:      Status
664 *
665 * DESCRIPTION: Store a value in an Arg or Local.  The ObjDesc is installed
666 *              as the new value for the Arg or Local and the reference count
667 *              for ObjDesc is incremented.
668 *
669 ******************************************************************************/
670
671ACPI_STATUS
672AcpiDsStoreObjectToLocal (
673    UINT16                  Opcode,
674    UINT32                  Index,
675    ACPI_OPERAND_OBJECT     *ObjDesc,
676    ACPI_WALK_STATE         *WalkState)
677{
678    ACPI_STATUS             Status;
679    ACPI_NAMESPACE_NODE     *Node;
680    ACPI_OPERAND_OBJECT     *CurrentObjDesc;
681
682
683    ACPI_FUNCTION_TRACE ("DsStoreObjectToLocal");
684    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode=%d Idx=%d Obj=%p\n",
685        Opcode, Index, ObjDesc));
686
687
688    /* Parameter validation */
689
690    if (!ObjDesc)
691    {
692        return_ACPI_STATUS (AE_BAD_PARAMETER);
693    }
694
695    /* Get the namespace node for the arg/local */
696
697    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
698    if (ACPI_FAILURE (Status))
699    {
700        return_ACPI_STATUS (Status);
701    }
702
703    CurrentObjDesc = AcpiNsGetAttachedObject (Node);
704    if (CurrentObjDesc == ObjDesc)
705    {
706        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n",
707            ObjDesc));
708        return_ACPI_STATUS (Status);
709    }
710
711    /*
712     * If there is an object already in this slot, we either
713     * have to delete it, or if this is an argument and there
714     * is an object reference stored there, we have to do
715     * an indirect store!
716     */
717    if (CurrentObjDesc)
718    {
719        /*
720         * Check for an indirect store if an argument
721         * contains an object reference (stored as an Node).
722         * We don't allow this automatic dereferencing for
723         * locals, since a store to a local should overwrite
724         * anything there, including an object reference.
725         *
726         * If both Arg0 and Local0 contain RefOf (Local4):
727         *
728         * Store (1, Arg0)             - Causes indirect store to local4
729         * Store (1, Local0)           - Stores 1 in local0, overwriting
730         *                                  the reference to local4
731         * Store (1, DeRefof (Local0)) - Causes indirect store to local4
732         *
733         * Weird, but true.
734         */
735        if (Opcode == AML_ARG_OP)
736        {
737            /*
738             * Make sure that the object is the correct type.  This may be overkill, but
739             * it is here because references were NS nodes in the past.  Now they are
740             * operand objects of type Reference.
741             */
742            if (ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) != ACPI_DESC_TYPE_OPERAND)
743            {
744                ACPI_REPORT_ERROR (("Invalid descriptor type while storing to method arg: %X\n",
745                    CurrentObjDesc->Common.Type));
746                return_ACPI_STATUS (AE_AML_INTERNAL);
747            }
748
749            /*
750             * If we have a valid reference object that came from RefOf(), do the
751             * indirect store
752             */
753            if ((CurrentObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
754                (CurrentObjDesc->Reference.Opcode == AML_REF_OF_OP))
755            {
756                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
757                    "Arg (%p) is an ObjRef(Node), storing in node %p\n",
758                    ObjDesc, CurrentObjDesc));
759
760                /*
761                 * Store this object to the Node
762                 * (perform the indirect store)
763                 */
764                Status = AcpiExStoreObjectToNode (ObjDesc,
765                            CurrentObjDesc->Reference.Object, WalkState);
766                return_ACPI_STATUS (Status);
767            }
768        }
769
770        /*
771         * Delete the existing object
772         * before storing the new one
773         */
774        AcpiDsMethodDataDeleteValue (Opcode, Index, WalkState);
775    }
776
777    /*
778     * Install the ObjStack descriptor (*ObjDesc) into
779     * the descriptor for the Arg or Local.
780     * Install the new object in the stack entry
781     * (increments the object reference count by one)
782     */
783    Status = AcpiDsMethodDataSetValue (Opcode, Index, ObjDesc, WalkState);
784    return_ACPI_STATUS (Status);
785}
786
787
788