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