1 /*******************************************************************************
3 * Module Name: dsutils - Dispatcher utilities
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
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
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
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;
38 * The above copyright and patent license is granted only if the following
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.
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
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
73 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
81 * 4. Disclaimer and Export Compliance
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
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
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.
115 *****************************************************************************/
117 #define __DSUTILS_C__
120 #include "acparser.h"
122 #include "acdispat.h"
123 #include "acinterp.h"
124 #include "acnamesp.h"
127 #define _COMPONENT ACPI_DISPATCHER
128 ACPI_MODULE_NAME ("dsutils")
131 #ifndef ACPI_NO_METHOD_EXECUTION
133 /*******************************************************************************
135 * FUNCTION: AcpiDsIsResultUsed
137 * PARAMETERS: Op - Current Op
138 * WalkState - Current State
140 * RETURN: TRUE if result is used, FALSE otherwise
142 * DESCRIPTION: Check if a result object will be used by the parent
144 ******************************************************************************/
148 ACPI_PARSE_OBJECT
*Op
,
149 ACPI_WALK_STATE
*WalkState
)
151 const ACPI_OPCODE_INFO
*ParentInfo
;
154 ACPI_FUNCTION_TRACE_PTR ("DsIsResultUsed", Op
);
157 /* Must have both an Op and a Result Object */
161 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Null Op\n"));
166 * If there is no parent, or the parent is a ScopeOp, we are executing
167 * at the method level. An executing method typically has no parent,
168 * since each method is parsed separately. A method invoked externally
169 * via ExecuteControlMethod has a ScopeOp as the parent.
171 if ((!Op
->Common
.Parent
) ||
172 (Op
->Common
.Parent
->Common
.AmlOpcode
== AML_SCOPE_OP
))
175 * If this is the last statement in the method, we know it is not a
176 * Return() operator (would not come here.) The following code is the
177 * optional support for a so-called "implicit return". Some AML code
178 * assumes that the last value of the method is "implicitly" returned
179 * to the caller. Just save the last result as the return value.
180 * NOTE: this is optional because the ASL language does not actually
181 * support this behavior.
183 if ((AcpiGbl_EnableInterpreterSlack
) &&
184 (WalkState
->ParserState
.Aml
>= WalkState
->ParserState
.AmlEnd
))
186 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
187 "Result of [%s] will be implicitly returned\n",
188 AcpiPsGetOpcodeName (Op
->Common
.AmlOpcode
)));
190 /* Use the top of the result stack as the implicit return value */
192 WalkState
->ReturnDesc
= WalkState
->Results
->Results
.ObjDesc
[0];
196 /* No parent, the return value cannot possibly be used */
198 return_VALUE (FALSE
);
201 /* Get info on the parent. The RootOp is AML_SCOPE */
203 ParentInfo
= AcpiPsGetOpcodeInfo (Op
->Common
.Parent
->Common
.AmlOpcode
);
204 if (ParentInfo
->Class
== AML_CLASS_UNKNOWN
)
206 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Unknown parent opcode. Op=%p\n", Op
));
207 return_VALUE (FALSE
);
211 * Decide what to do with the result based on the parent. If
212 * the parent opcode will not use the result, delete the object.
213 * Otherwise leave it as is, it will be deleted when it is used
214 * as an operand later.
216 switch (ParentInfo
->Class
)
218 case AML_CLASS_CONTROL
:
220 switch (Op
->Common
.Parent
->Common
.AmlOpcode
)
224 /* Never delete the return value associated with a return opcode */
232 * If we are executing the predicate AND this is the predicate op,
233 * we will use the return value
235 if ((WalkState
->ControlState
->Common
.State
== ACPI_CONTROL_PREDICATE_EXECUTING
) &&
236 (WalkState
->ControlState
->Control
.PredicateOp
== Op
))
243 /* Ignore other control opcodes */
247 /* The general control opcode returns no result */
252 case AML_CLASS_CREATE
:
255 * These opcodes allow TermArg(s) as operands and therefore
256 * the operands can be method calls. The result is used.
261 case AML_CLASS_NAMED_OBJECT
:
263 if ((Op
->Common
.Parent
->Common
.AmlOpcode
== AML_REGION_OP
) ||
264 (Op
->Common
.Parent
->Common
.AmlOpcode
== AML_DATA_REGION_OP
) ||
265 (Op
->Common
.Parent
->Common
.AmlOpcode
== AML_PACKAGE_OP
) ||
266 (Op
->Common
.Parent
->Common
.AmlOpcode
== AML_VAR_PACKAGE_OP
) ||
267 (Op
->Common
.Parent
->Common
.AmlOpcode
== AML_BUFFER_OP
) ||
268 (Op
->Common
.Parent
->Common
.AmlOpcode
== AML_INT_EVAL_SUBTREE_OP
))
271 * These opcodes allow TermArg(s) as operands and therefore
272 * the operands can be method calls. The result is used.
283 * In all other cases. the parent will actually use the return
284 * object, so keep it.
291 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "Result of [%s] used by Parent [%s] Op=%p\n",
292 AcpiPsGetOpcodeName (Op
->Common
.AmlOpcode
),
293 AcpiPsGetOpcodeName (Op
->Common
.Parent
->Common
.AmlOpcode
), Op
));
299 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "Result of [%s] not used by Parent [%s] Op=%p\n",
300 AcpiPsGetOpcodeName (Op
->Common
.AmlOpcode
),
301 AcpiPsGetOpcodeName (Op
->Common
.Parent
->Common
.AmlOpcode
), Op
));
303 return_VALUE (FALSE
);
307 /*******************************************************************************
309 * FUNCTION: AcpiDsDeleteResultIfNotUsed
311 * PARAMETERS: Op - Current parse Op
312 * ResultObj - Result of the operation
313 * WalkState - Current state
317 * DESCRIPTION: Used after interpretation of an opcode. If there is an internal
318 * result descriptor, check if the parent opcode will actually use
319 * this result. If not, delete the result now so that it will
320 * not become orphaned.
322 ******************************************************************************/
325 AcpiDsDeleteResultIfNotUsed (
326 ACPI_PARSE_OBJECT
*Op
,
327 ACPI_OPERAND_OBJECT
*ResultObj
,
328 ACPI_WALK_STATE
*WalkState
)
330 ACPI_OPERAND_OBJECT
*ObjDesc
;
334 ACPI_FUNCTION_TRACE_PTR ("DsDeleteResultIfNotUsed", ResultObj
);
339 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Null Op\n"));
348 if (!AcpiDsIsResultUsed (Op
, WalkState
))
351 * Must pop the result stack (ObjDesc should be equal to ResultObj)
353 Status
= AcpiDsResultPop (&ObjDesc
, WalkState
);
354 if (ACPI_SUCCESS (Status
))
356 AcpiUtRemoveReference (ResultObj
);
364 /*******************************************************************************
366 * FUNCTION: AcpiDsResolveOperands
368 * PARAMETERS: WalkState - Current walk state with operands on stack
372 * DESCRIPTION: Resolve all operands to their values. Used to prepare
373 * arguments to a control method invocation (a call from one
374 * method to another.)
376 ******************************************************************************/
379 AcpiDsResolveOperands (
380 ACPI_WALK_STATE
*WalkState
)
383 ACPI_STATUS Status
= AE_OK
;
386 ACPI_FUNCTION_TRACE_PTR ("DsResolveOperands", WalkState
);
390 * Attempt to resolve each of the valid operands
391 * Method arguments are passed by reference, not by value. This means
392 * that the actual objects are passed, not copies of the objects.
394 for (i
= 0; i
< WalkState
->NumOperands
; i
++)
396 Status
= AcpiExResolveToValue (&WalkState
->Operands
[i
], WalkState
);
397 if (ACPI_FAILURE (Status
))
403 return_ACPI_STATUS (Status
);
407 /*******************************************************************************
409 * FUNCTION: AcpiDsClearOperands
411 * PARAMETERS: WalkState - Current walk state with operands on stack
415 * DESCRIPTION: Clear all operands on the current walk state operand stack.
417 ******************************************************************************/
420 AcpiDsClearOperands (
421 ACPI_WALK_STATE
*WalkState
)
426 ACPI_FUNCTION_TRACE_PTR ("DsClearOperands", WalkState
);
430 * Remove a reference on each operand on the stack
432 for (i
= 0; i
< WalkState
->NumOperands
; i
++)
435 * Remove a reference to all operands, including both
436 * "Arguments" and "Targets".
438 AcpiUtRemoveReference (WalkState
->Operands
[i
]);
439 WalkState
->Operands
[i
] = NULL
;
442 WalkState
->NumOperands
= 0;
448 /*******************************************************************************
450 * FUNCTION: AcpiDsCreateOperand
452 * PARAMETERS: WalkState - Current walk state
453 * Arg - Parse object for the argument
454 * ArgIndex - Which argument (zero based)
458 * DESCRIPTION: Translate a parse tree object that is an argument to an AML
459 * opcode to the equivalent interpreter object. This may include
460 * looking up a name or entering a new name into the internal
463 ******************************************************************************/
466 AcpiDsCreateOperand (
467 ACPI_WALK_STATE
*WalkState
,
468 ACPI_PARSE_OBJECT
*Arg
,
471 ACPI_STATUS Status
= AE_OK
;
474 ACPI_OPERAND_OBJECT
*ObjDesc
;
475 ACPI_PARSE_OBJECT
*ParentOp
;
477 ACPI_INTERPRETER_MODE InterpreterMode
;
478 const ACPI_OPCODE_INFO
*OpInfo
;
481 ACPI_FUNCTION_TRACE_PTR ("DsCreateOperand", Arg
);
484 /* A valid name must be looked up in the namespace */
486 if ((Arg
->Common
.AmlOpcode
== AML_INT_NAMEPATH_OP
) &&
487 (Arg
->Common
.Value
.String
))
489 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "Getting a name: Arg=%p\n", Arg
));
491 /* Get the entire name string from the AML stream */
493 Status
= AcpiExGetNameString (ACPI_TYPE_ANY
, Arg
->Common
.Value
.Buffer
,
494 &NameString
, &NameLength
);
496 if (ACPI_FAILURE (Status
))
498 return_ACPI_STATUS (Status
);
502 * All prefixes have been handled, and the name is
508 * Special handling for BufferField declarations. This is a deferred
509 * opcode that unfortunately defines the field name as the last
510 * parameter instead of the first. We get here when we are performing
511 * the deferred execution, so the actual name of the field is already
512 * in the namespace. We don't want to attempt to look it up again
513 * because we may be executing in a different scope than where the
514 * actual opcode exists.
516 if ((WalkState
->DeferredNode
) &&
517 (WalkState
->DeferredNode
->Type
== ACPI_TYPE_BUFFER_FIELD
) &&
520 ObjDesc
= ACPI_CAST_PTR (ACPI_OPERAND_OBJECT
, WalkState
->DeferredNode
);
523 else /* All other opcodes */
526 * Differentiate between a namespace "create" operation
527 * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
528 * IMODE_EXECUTE) in order to support the creation of
529 * namespace objects during the execution of control methods.
531 ParentOp
= Arg
->Common
.Parent
;
532 OpInfo
= AcpiPsGetOpcodeInfo (ParentOp
->Common
.AmlOpcode
);
533 if ((OpInfo
->Flags
& AML_NSNODE
) &&
534 (ParentOp
->Common
.AmlOpcode
!= AML_INT_METHODCALL_OP
) &&
535 (ParentOp
->Common
.AmlOpcode
!= AML_REGION_OP
) &&
536 (ParentOp
->Common
.AmlOpcode
!= AML_INT_NAMEPATH_OP
))
538 /* Enter name into namespace if not found */
540 InterpreterMode
= ACPI_IMODE_LOAD_PASS2
;
544 /* Return a failure if name not found */
546 InterpreterMode
= ACPI_IMODE_EXECUTE
;
549 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, NameString
,
550 ACPI_TYPE_ANY
, InterpreterMode
,
551 ACPI_NS_SEARCH_PARENT
| ACPI_NS_DONT_OPEN_SCOPE
,
553 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE
, &ObjDesc
));
555 * The only case where we pass through (ignore) a NOT_FOUND
556 * error is for the CondRefOf opcode.
558 if (Status
== AE_NOT_FOUND
)
560 if (ParentOp
->Common
.AmlOpcode
== AML_COND_REF_OF_OP
)
563 * For the Conditional Reference op, it's OK if
564 * the name is not found; We just need a way to
565 * indicate this to the interpreter, set the
568 ObjDesc
= ACPI_CAST_PTR (ACPI_OPERAND_OBJECT
, AcpiGbl_RootNode
);
574 * We just plain didn't find it -- which is a
575 * very serious error at this point
577 Status
= AE_AML_NAME_NOT_FOUND
;
581 if (ACPI_FAILURE (Status
))
583 ACPI_REPORT_NSERROR (NameString
, Status
);
587 /* Free the namestring created above */
589 ACPI_MEM_FREE (NameString
);
591 /* Check status from the lookup */
593 if (ACPI_FAILURE (Status
))
595 return_ACPI_STATUS (Status
);
598 /* Put the resulting object onto the current object stack */
600 Status
= AcpiDsObjStackPush (ObjDesc
, WalkState
);
601 if (ACPI_FAILURE (Status
))
603 return_ACPI_STATUS (Status
);
605 ACPI_DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (ObjDesc
, WalkState
));
609 /* Check for null name case */
611 if (Arg
->Common
.AmlOpcode
== AML_INT_NAMEPATH_OP
)
614 * If the name is null, this means that this is an
615 * optional result parameter that was not specified
616 * in the original ASL. Create a Zero Constant for a
617 * placeholder. (Store to a constant is a Noop.)
619 Opcode
= AML_ZERO_OP
; /* Has no arguments! */
621 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "Null namepath: Arg=%p\n", Arg
));
625 Opcode
= Arg
->Common
.AmlOpcode
;
628 /* Get the object type of the argument */
630 OpInfo
= AcpiPsGetOpcodeInfo (Opcode
);
631 if (OpInfo
->ObjectType
== ACPI_TYPE_INVALID
)
633 return_ACPI_STATUS (AE_NOT_IMPLEMENTED
);
636 if (OpInfo
->Flags
& AML_HAS_RETVAL
)
638 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
639 "Argument previously created, already stacked \n"));
641 ACPI_DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (
642 WalkState
->Operands
[WalkState
->NumOperands
- 1], WalkState
));
645 * Use value that was already previously returned
646 * by the evaluation of this argument
648 Status
= AcpiDsResultPopFromBottom (&ObjDesc
, WalkState
);
649 if (ACPI_FAILURE (Status
))
652 * Only error is underflow, and this indicates
653 * a missing or null operand!
655 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Missing or null operand, %s\n",
656 AcpiFormatException (Status
)));
657 return_ACPI_STATUS (Status
);
662 /* Create an ACPI_INTERNAL_OBJECT for the argument */
664 ObjDesc
= AcpiUtCreateInternalObject (OpInfo
->ObjectType
);
667 return_ACPI_STATUS (AE_NO_MEMORY
);
670 /* Initialize the new object */
672 Status
= AcpiDsInitObjectFromOp (WalkState
, Arg
,
674 if (ACPI_FAILURE (Status
))
676 AcpiUtDeleteObjectDesc (ObjDesc
);
677 return_ACPI_STATUS (Status
);
681 /* Put the operand object on the object stack */
683 Status
= AcpiDsObjStackPush (ObjDesc
, WalkState
);
684 if (ACPI_FAILURE (Status
))
686 return_ACPI_STATUS (Status
);
689 ACPI_DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (ObjDesc
, WalkState
));
692 return_ACPI_STATUS (AE_OK
);
696 /*******************************************************************************
698 * FUNCTION: AcpiDsCreateOperands
700 * PARAMETERS: FirstArg - First argument of a parser argument tree
704 * DESCRIPTION: Convert an operator's arguments from a parse tree format to
705 * namespace objects and place those argument object on the object
706 * stack in preparation for evaluation by the interpreter.
708 ******************************************************************************/
711 AcpiDsCreateOperands (
712 ACPI_WALK_STATE
*WalkState
,
713 ACPI_PARSE_OBJECT
*FirstArg
)
715 ACPI_STATUS Status
= AE_OK
;
716 ACPI_PARSE_OBJECT
*Arg
;
720 ACPI_FUNCTION_TRACE_PTR ("DsCreateOperands", FirstArg
);
723 /* For all arguments in the list... */
728 Status
= AcpiDsCreateOperand (WalkState
, Arg
, ArgCount
);
729 if (ACPI_FAILURE (Status
))
734 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "Arg #%d (%p) done, Arg1=%p\n",
735 ArgCount
, Arg
, FirstArg
));
737 /* Move on to next argument, if any */
739 Arg
= Arg
->Common
.Next
;
743 return_ACPI_STATUS (Status
);
748 * We must undo everything done above; meaning that we must
749 * pop everything off of the operand stack and delete those
752 (void) AcpiDsObjStackPopAndDelete (ArgCount
, WalkState
);
754 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "While creating Arg %d - %s\n",
755 (ArgCount
+ 1), AcpiFormatException (Status
)));
756 return_ACPI_STATUS (Status
);