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