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