1 /*******************************************************************************
3 * Module Name: dsutils - Dispatcher utilities
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, 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 MODULE_NAME ("dsutils")
131 /*******************************************************************************
133 * FUNCTION: AcpiDsIsResultUsed
141 * DESCRIPTION: Check if a result object will be used by the parent
143 ******************************************************************************/
147 ACPI_PARSE_OBJECT *Op,
148 ACPI_WALK_STATE *WalkState)
150 ACPI_OPCODE_INFO *ParentInfo;
153 FUNCTION_TRACE_PTR ("DsIsResultUsed", Op);
156 /* Must have both an Op and a Result Object */
160 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Op\n"));
166 * If there is no parent, the result can't possibly be used!
167 * (An executing method typically has no parent, since each
168 * method is parsed separately) However, a method that is
169 * invoked from another method has a parent.
173 return_VALUE (FALSE);
178 * Get info on the parent. The root Op is AML_SCOPE
181 ParentInfo = AcpiPsGetOpcodeInfo (Op->Parent->Opcode);
182 if (ACPI_GET_OP_TYPE (ParentInfo) != ACPI_OP_TYPE_OPCODE)
184 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown parent opcode. Op=%X\n", Op));
185 return_VALUE (FALSE);
190 * Decide what to do with the result based on the parent. If
191 * the parent opcode will not use the result, delete the object.
192 * Otherwise leave it as is, it will be deleted when it is used
193 * as an operand later.
196 switch (ACPI_GET_OP_CLASS (ParentInfo))
199 * In these cases, the parent will never use the return object
201 case OPTYPE_CONTROL: /* IF, ELSE, WHILE only */
203 switch (Op->Parent->Opcode)
207 /* Never delete the return value associated with a return opcode */
209 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
210 "Result used, [RETURN] opcode=%X Op=%X\n", Op->Opcode, Op));
218 * If we are executing the predicate AND this is the predicate op,
219 * we will use the return value!
222 if ((WalkState->ControlState->Common.State == CONTROL_PREDICATE_EXECUTING) &&
223 (WalkState->ControlState->Control.PredicateOp == Op))
225 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
226 "Result used as a predicate, [IF/WHILE] opcode=%X Op=%X\n",
235 /* Fall through to not used case below */
238 case OPTYPE_NAMED_OBJECT: /* Scope, method, etc. */
241 * These opcodes allow TermArg(s) as operands and therefore
242 * method calls. The result is used.
244 if ((Op->Parent->Opcode == AML_REGION_OP) ||
245 (Op->Parent->Opcode == AML_CREATE_FIELD_OP) ||
246 (Op->Parent->Opcode == AML_CREATE_BIT_FIELD_OP) ||
247 (Op->Parent->Opcode == AML_CREATE_BYTE_FIELD_OP) ||
248 (Op->Parent->Opcode == AML_CREATE_WORD_FIELD_OP) ||
249 (Op->Parent->Opcode == AML_CREATE_DWORD_FIELD_OP) ||
250 (Op->Parent->Opcode == AML_CREATE_QWORD_FIELD_OP))
252 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
253 "Result used, [Region or CreateField] opcode=%X Op=%X\n",
258 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
259 "Result not used, Parent opcode=%X Op=%X\n", Op->Opcode, Op));
261 return_VALUE (FALSE);
265 * In all other cases. the parent will actually use the return
266 * object, so keep it.
276 /*******************************************************************************
278 * FUNCTION: AcpiDsDeleteResultIfNotUsed
286 * DESCRIPTION: Used after interpretation of an opcode. If there is an internal
287 * result descriptor, check if the parent opcode will actually use
288 * this result. If not, delete the result now so that it will
289 * not become orphaned.
291 ******************************************************************************/
294 AcpiDsDeleteResultIfNotUsed (
295 ACPI_PARSE_OBJECT *Op,
296 ACPI_OPERAND_OBJECT *ResultObj,
297 ACPI_WALK_STATE *WalkState)
299 ACPI_OPERAND_OBJECT *ObjDesc;
303 FUNCTION_TRACE_PTR ("DsDeleteResultIfNotUsed", ResultObj);
308 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Op\n"));
318 if (!AcpiDsIsResultUsed (Op, WalkState))
321 * Must pop the result stack (ObjDesc should be equal to ResultObj)
323 Status = AcpiDsResultPop (&ObjDesc, WalkState);
324 if (ACPI_SUCCESS (Status))
326 AcpiUtRemoveReference (ResultObj);
334 /*******************************************************************************
336 * FUNCTION: AcpiDsCreateOperand
338 * PARAMETERS: WalkState
343 * DESCRIPTION: Translate a parse tree object that is an argument to an AML
344 * opcode to the equivalent interpreter object. This may include
345 * looking up a name or entering a new name into the internal
348 ******************************************************************************/
351 AcpiDsCreateOperand (
352 ACPI_WALK_STATE *WalkState,
353 ACPI_PARSE_OBJECT *Arg,
356 ACPI_STATUS Status = AE_OK;
357 NATIVE_CHAR *NameString;
359 ACPI_OBJECT_TYPE8 DataType;
360 ACPI_OPERAND_OBJECT *ObjDesc;
361 ACPI_PARSE_OBJECT *ParentOp;
364 OPERATING_MODE InterpreterMode;
367 FUNCTION_TRACE_PTR ("DsCreateOperand", Arg);
370 /* A valid name must be looked up in the namespace */
372 if ((Arg->Opcode == AML_INT_NAMEPATH_OP) &&
375 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n", Arg));
377 /* Get the entire name string from the AML stream */
379 Status = AcpiExGetNameString (ACPI_TYPE_ANY, Arg->Value.Buffer,
380 &NameString, &NameLength);
382 if (ACPI_FAILURE (Status))
384 return_ACPI_STATUS (Status);
388 * All prefixes have been handled, and the name is
393 * Differentiate between a namespace "create" operation
394 * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
395 * IMODE_EXECUTE) in order to support the creation of
396 * namespace objects during the execution of control methods.
398 ParentOp = Arg->Parent;
399 if ((AcpiPsIsNodeOp (ParentOp->Opcode)) &&
400 (ParentOp->Opcode != AML_INT_METHODCALL_OP) &&
401 (ParentOp->Opcode != AML_REGION_OP) &&
402 (ParentOp->Opcode != AML_INT_NAMEPATH_OP))
404 /* Enter name into namespace if not found */
406 InterpreterMode = IMODE_LOAD_PASS2;
411 /* Return a failure if name not found */
413 InterpreterMode = IMODE_EXECUTE;
416 Status = AcpiNsLookup (WalkState->ScopeInfo, NameString,
417 ACPI_TYPE_ANY, InterpreterMode,
418 NS_SEARCH_PARENT | NS_DONT_OPEN_SCOPE,
420 (ACPI_NAMESPACE_NODE **) &ObjDesc);
422 /* Free the namestring created above */
424 ACPI_MEM_FREE (NameString);
427 * The only case where we pass through (ignore) a NOT_FOUND
428 * error is for the CondRefOf opcode.
431 if (Status == AE_NOT_FOUND)
433 if (ParentOp->Opcode == AML_COND_REF_OF_OP)
436 * For the Conditional Reference op, it's OK if
437 * the name is not found; We just need a way to
438 * indicate this to the interpreter, set the
441 ObjDesc = (ACPI_OPERAND_OBJECT *) AcpiGbl_RootNode;
448 * We just plain didn't find it -- which is a
449 * very serious error at this point
451 Status = AE_AML_NAME_NOT_FOUND;
455 /* Check status from the lookup */
457 if (ACPI_FAILURE (Status))
459 return_ACPI_STATUS (Status);
462 /* Put the resulting object onto the current object stack */
464 Status = AcpiDsObjStackPush (ObjDesc, WalkState);
465 if (ACPI_FAILURE (Status))
467 return_ACPI_STATUS (Status);
469 DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (ObjDesc, WalkState));
475 /* Check for null name case */
477 if (Arg->Opcode == AML_INT_NAMEPATH_OP)
480 * If the name is null, this means that this is an
481 * optional result parameter that was not specified
482 * in the original ASL. Create an Reference for a
485 Opcode = AML_ZERO_OP; /* Has no arguments! */
487 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Null namepath: Arg=%p\n", Arg));
490 * TBD: [Investigate] anything else needed for the
497 Opcode = Arg->Opcode;
501 /* Get the data type of the argument */
503 DataType = AcpiDsMapOpcodeToDataType (Opcode, &Flags);
504 if (DataType == INTERNAL_TYPE_INVALID)
506 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
509 if (Flags & OP_HAS_RETURN_VALUE)
511 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
512 "Argument previously created, already stacked \n"));
514 DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (WalkState->Operands [WalkState->NumOperands - 1], WalkState));
517 * Use value that was already previously returned
518 * by the evaluation of this argument
520 Status = AcpiDsResultPopFromBottom (&ObjDesc, WalkState);
521 if (ACPI_FAILURE (Status))
524 * Only error is underflow, and this indicates
525 * a missing or null operand!
527 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Missing or null operand, %s\n",
528 AcpiFormatException (Status)));
529 return_ACPI_STATUS (Status);
536 /* Create an ACPI_INTERNAL_OBJECT for the argument */
538 ObjDesc = AcpiUtCreateInternalObject (DataType);
541 return_ACPI_STATUS (AE_NO_MEMORY);
544 /* Initialize the new object */
546 Status = AcpiDsInitObjectFromOp (WalkState, Arg,
548 if (ACPI_FAILURE (Status))
550 AcpiUtDeleteObjectDesc (ObjDesc);
551 return_ACPI_STATUS (Status);
555 /* Put the operand object on the object stack */
557 Status = AcpiDsObjStackPush (ObjDesc, WalkState);
558 if (ACPI_FAILURE (Status))
560 return_ACPI_STATUS (Status);
563 DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (ObjDesc, WalkState));
566 return_ACPI_STATUS (AE_OK);
570 /*******************************************************************************
572 * FUNCTION: AcpiDsCreateOperands
574 * PARAMETERS: FirstArg - First argument of a parser argument tree
578 * DESCRIPTION: Convert an operator's arguments from a parse tree format to
579 * namespace objects and place those argument object on the object
580 * stack in preparation for evaluation by the interpreter.
582 ******************************************************************************/
585 AcpiDsCreateOperands (
586 ACPI_WALK_STATE *WalkState,
587 ACPI_PARSE_OBJECT *FirstArg)
589 ACPI_STATUS Status = AE_OK;
590 ACPI_PARSE_OBJECT *Arg;
594 FUNCTION_TRACE_PTR ("DsCreateOperands", FirstArg);
596 /* For all arguments in the list... */
601 Status = AcpiDsCreateOperand (WalkState, Arg, ArgCount);
602 if (ACPI_FAILURE (Status))
607 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Arg #%d (%p) done, Arg1=%p\n",
608 ArgCount, Arg, FirstArg));
610 /* Move on to next argument, if any */
616 return_ACPI_STATUS (Status);
621 * We must undo everything done above; meaning that we must
622 * pop everything off of the operand stack and delete those
626 AcpiDsObjStackPopAndDelete (ArgCount, WalkState);
628 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "While creating Arg %d - %s\n",
629 (ArgCount + 1), AcpiFormatException (Status)));
630 return_ACPI_STATUS (Status);
634 /*******************************************************************************
636 * FUNCTION: AcpiDsResolveOperands
638 * PARAMETERS: WalkState - Current walk state with operands on stack
642 * DESCRIPTION: Resolve all operands to their values. Used to prepare
643 * arguments to a control method invocation (a call from one
644 * method to another.)
646 ******************************************************************************/
649 AcpiDsResolveOperands (
650 ACPI_WALK_STATE *WalkState)
653 ACPI_STATUS Status = AE_OK;
656 FUNCTION_TRACE_PTR ("DsResolveOperands", WalkState);
660 * Attempt to resolve each of the valid operands
661 * Method arguments are passed by value, not by reference
665 * TBD: [Investigate] Note from previous parser:
666 * RefOf problem with AcpiExResolveToValue() conversion.
669 for (i = 0; i < WalkState->NumOperands; i++)
671 Status = AcpiExResolveToValue (&WalkState->Operands[i], WalkState);
672 if (ACPI_FAILURE (Status))
678 return_ACPI_STATUS (Status);
682 /*******************************************************************************
684 * FUNCTION: AcpiDsMapOpcodeToDataType
686 * PARAMETERS: Opcode - AML opcode to map
687 * OutFlags - Additional info about the opcode
689 * RETURN: The ACPI type associated with the opcode
691 * DESCRIPTION: Convert a raw AML opcode to the associated ACPI data type,
692 * if any. If the opcode returns a value as part of the
693 * intepreter execution, a flag is returned in OutFlags.
695 ******************************************************************************/
698 AcpiDsMapOpcodeToDataType (
702 ACPI_OBJECT_TYPE8 DataType = INTERNAL_TYPE_INVALID;
703 ACPI_OPCODE_INFO *OpInfo;
707 PROC_NAME ("DsMapOpcodeToDataType");
710 OpInfo = AcpiPsGetOpcodeInfo (Opcode);
711 if (ACPI_GET_OP_TYPE (OpInfo) != ACPI_OP_TYPE_OPCODE)
715 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown AML opcode: %x\n", Opcode));
719 switch (ACPI_GET_OP_CLASS (OpInfo))
731 DataType = ACPI_TYPE_INTEGER;
737 DataType = ACPI_TYPE_STRING;
740 case AML_INT_NAMEPATH_OP:
741 DataType = INTERNAL_TYPE_REFERENCE;
745 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
746 "Unknown (type LITERAL) AML opcode: %x\n", Opcode));
752 case OPTYPE_DATA_TERM:
758 DataType = ACPI_TYPE_BUFFER;
762 case AML_VAR_PACKAGE_OP:
764 DataType = ACPI_TYPE_PACKAGE;
768 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
769 "Unknown (type DATA_TERM) AML opcode: %x\n", Opcode));
775 case OPTYPE_CONSTANT:
776 case OPTYPE_METHOD_ARGUMENT:
777 case OPTYPE_LOCAL_VARIABLE:
779 DataType = INTERNAL_TYPE_REFERENCE;
783 case OPTYPE_MONADIC2:
784 case OPTYPE_MONADIC2R:
786 case OPTYPE_DYADIC2R:
787 case OPTYPE_DYADIC2S:
789 case OPTYPE_QUADRADIC:
793 Flags = OP_HAS_RETURN_VALUE;
794 DataType = ACPI_TYPE_ANY;
798 case OPTYPE_METHOD_CALL:
800 Flags = OP_HAS_RETURN_VALUE;
801 DataType = ACPI_TYPE_METHOD;
805 case OPTYPE_NAMED_OBJECT:
807 DataType = AcpiDsMapNamedOpcodeToDataType (Opcode);
814 /* No mapping needed at this time */
821 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
822 "Unimplemented data type opcode: %x\n", Opcode));
826 /* Return flags to caller if requested */
837 /*******************************************************************************
839 * FUNCTION: AcpiDsMapNamedOpcodeToDataType
841 * PARAMETERS: Opcode - The Named AML opcode to map
843 * RETURN: The ACPI type associated with the named opcode
845 * DESCRIPTION: Convert a raw Named AML opcode to the associated data type.
846 * Named opcodes are a subsystem of the AML opcodes.
848 ******************************************************************************/
851 AcpiDsMapNamedOpcodeToDataType (
854 ACPI_OBJECT_TYPE8 DataType;
862 DataType = INTERNAL_TYPE_SCOPE;
866 DataType = ACPI_TYPE_DEVICE;
869 case AML_THERMAL_ZONE_OP:
870 DataType = ACPI_TYPE_THERMAL;
874 DataType = ACPI_TYPE_METHOD;
877 case AML_POWER_RES_OP:
878 DataType = ACPI_TYPE_POWER;
881 case AML_PROCESSOR_OP:
882 DataType = ACPI_TYPE_PROCESSOR;
885 case AML_FIELD_OP: /* FieldOp */
886 DataType = INTERNAL_TYPE_FIELD_DEFN;
889 case AML_INDEX_FIELD_OP: /* IndexFieldOp */
890 DataType = INTERNAL_TYPE_INDEX_FIELD_DEFN;
893 case AML_BANK_FIELD_OP: /* BankFieldOp */
894 DataType = INTERNAL_TYPE_BANK_FIELD_DEFN;
897 case AML_INT_NAMEDFIELD_OP: /* NO CASE IN ORIGINAL */
898 DataType = ACPI_TYPE_ANY;
901 case AML_NAME_OP: /* NameOp - special code in original */
902 case AML_INT_NAMEPATH_OP:
903 DataType = ACPI_TYPE_ANY;
907 DataType = INTERNAL_TYPE_ALIAS;
911 DataType = ACPI_TYPE_MUTEX;
915 DataType = ACPI_TYPE_EVENT;
919 DataType = ACPI_TYPE_REGION;
924 DataType = ACPI_TYPE_ANY;