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