1 /******************************************************************************
3 * Module Name: dswexec - Dispatcher method execution callbacks;
4 * dispatch to interpreter.
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2015, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acparser.h>
48 #include <contrib/dev/acpica/include/amlcode.h>
49 #include <contrib/dev/acpica/include/acdispat.h>
50 #include <contrib/dev/acpica/include/acinterp.h>
51 #include <contrib/dev/acpica/include/acnamesp.h>
52 #include <contrib/dev/acpica/include/acdebug.h>
55 #define _COMPONENT ACPI_DISPATCHER
56 ACPI_MODULE_NAME ("dswexec")
59 * Dispatch table for opcode classes
61 static ACPI_EXECUTE_OP AcpiGbl_OpTypeDispatch [] =
63 AcpiExOpcode_0A_0T_1R,
64 AcpiExOpcode_1A_0T_0R,
65 AcpiExOpcode_1A_0T_1R,
66 AcpiExOpcode_1A_1T_0R,
67 AcpiExOpcode_1A_1T_1R,
68 AcpiExOpcode_2A_0T_0R,
69 AcpiExOpcode_2A_0T_1R,
70 AcpiExOpcode_2A_1T_1R,
71 AcpiExOpcode_2A_2T_1R,
72 AcpiExOpcode_3A_0T_0R,
73 AcpiExOpcode_3A_1T_1R,
78 /*****************************************************************************
80 * FUNCTION: AcpiDsGetPredicateValue
82 * PARAMETERS: WalkState - Current state of the parse tree walk
83 * ResultObj - if non-zero, pop result from result stack
87 * DESCRIPTION: Get the result of a predicate evaluation
89 ****************************************************************************/
92 AcpiDsGetPredicateValue (
93 ACPI_WALK_STATE *WalkState,
94 ACPI_OPERAND_OBJECT *ResultObj)
96 ACPI_STATUS Status = AE_OK;
97 ACPI_OPERAND_OBJECT *ObjDesc;
98 ACPI_OPERAND_OBJECT *LocalObjDesc = NULL;
101 ACPI_FUNCTION_TRACE_PTR (DsGetPredicateValue, WalkState);
104 WalkState->ControlState->Common.State = 0;
108 Status = AcpiDsResultPop (&ObjDesc, WalkState);
109 if (ACPI_FAILURE (Status))
111 ACPI_EXCEPTION ((AE_INFO, Status,
112 "Could not get result from predicate evaluation"));
114 return_ACPI_STATUS (Status);
119 Status = AcpiDsCreateOperand (WalkState, WalkState->Op, 0);
120 if (ACPI_FAILURE (Status))
122 return_ACPI_STATUS (Status);
125 Status = AcpiExResolveToValue (&WalkState->Operands [0], WalkState);
126 if (ACPI_FAILURE (Status))
128 return_ACPI_STATUS (Status);
131 ObjDesc = WalkState->Operands [0];
136 ACPI_ERROR ((AE_INFO,
137 "No predicate ObjDesc=%p State=%p",
138 ObjDesc, WalkState));
140 return_ACPI_STATUS (AE_AML_NO_OPERAND);
144 * Result of predicate evaluation must be an Integer
145 * object. Implicitly convert the argument if necessary.
147 Status = AcpiExConvertToInteger (ObjDesc, &LocalObjDesc, 16);
148 if (ACPI_FAILURE (Status))
153 if (LocalObjDesc->Common.Type != ACPI_TYPE_INTEGER)
155 ACPI_ERROR ((AE_INFO,
156 "Bad predicate (not an integer) ObjDesc=%p State=%p Type=0x%X",
157 ObjDesc, WalkState, ObjDesc->Common.Type));
159 Status = AE_AML_OPERAND_TYPE;
163 /* Truncate the predicate to 32-bits if necessary */
165 (void) AcpiExTruncateFor32bitTable (LocalObjDesc);
168 * Save the result of the predicate evaluation on
171 if (LocalObjDesc->Integer.Value)
173 WalkState->ControlState->Common.Value = TRUE;
178 * Predicate is FALSE, we will just toss the
179 * rest of the package
181 WalkState->ControlState->Common.Value = FALSE;
182 Status = AE_CTRL_FALSE;
185 /* Predicate can be used for an implicit return value */
187 (void) AcpiDsDoImplicitReturn (LocalObjDesc, WalkState, TRUE);
192 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Completed a predicate eval=%X Op=%p\n",
193 WalkState->ControlState->Common.Value, WalkState->Op));
195 /* Break to debugger to display result */
197 ACPI_DEBUGGER_EXEC (AcpiDbDisplayResultObject (LocalObjDesc, WalkState));
200 * Delete the predicate result object (we know that
201 * we don't need it anymore)
203 if (LocalObjDesc != ObjDesc)
205 AcpiUtRemoveReference (LocalObjDesc);
207 AcpiUtRemoveReference (ObjDesc);
209 WalkState->ControlState->Common.State = ACPI_CONTROL_NORMAL;
210 return_ACPI_STATUS (Status);
214 /*****************************************************************************
216 * FUNCTION: AcpiDsExecBeginOp
218 * PARAMETERS: WalkState - Current state of the parse tree walk
219 * OutOp - Where to return op if a new one is created
223 * DESCRIPTION: Descending callback used during the execution of control
224 * methods. This is where most operators and operands are
225 * dispatched to the interpreter.
227 ****************************************************************************/
231 ACPI_WALK_STATE *WalkState,
232 ACPI_PARSE_OBJECT **OutOp)
234 ACPI_PARSE_OBJECT *Op;
235 ACPI_STATUS Status = AE_OK;
239 ACPI_FUNCTION_TRACE_PTR (DsExecBeginOp, WalkState);
245 Status = AcpiDsLoad2BeginOp (WalkState, OutOp);
246 if (ACPI_FAILURE (Status))
253 WalkState->Opcode = Op->Common.AmlOpcode;
254 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
256 if (AcpiNsOpensScope (WalkState->OpInfo->ObjectType))
258 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
259 "(%s) Popping scope for Op %p\n",
260 AcpiUtGetTypeName (WalkState->OpInfo->ObjectType), Op));
262 Status = AcpiDsScopeStackPop (WalkState);
263 if (ACPI_FAILURE (Status))
270 if (Op == WalkState->Origin)
277 return_ACPI_STATUS (AE_OK);
281 * If the previous opcode was a conditional, this opcode
282 * must be the beginning of the associated predicate.
283 * Save this knowledge in the current scope descriptor
285 if ((WalkState->ControlState) &&
286 (WalkState->ControlState->Common.State ==
287 ACPI_CONTROL_CONDITIONAL_EXECUTING))
289 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Exec predicate Op=%p State=%p\n",
292 WalkState->ControlState->Common.State = ACPI_CONTROL_PREDICATE_EXECUTING;
294 /* Save start of predicate */
296 WalkState->ControlState->Control.PredicateOp = Op;
300 OpcodeClass = WalkState->OpInfo->Class;
302 /* We want to send namepaths to the load code */
304 if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
306 OpcodeClass = AML_CLASS_NAMED_OBJECT;
310 * Handle the opcode based upon the opcode type
314 case AML_CLASS_CONTROL:
316 Status = AcpiDsExecBeginControlOp (WalkState, Op);
319 case AML_CLASS_NAMED_OBJECT:
321 if (WalkState->WalkType & ACPI_WALK_METHOD)
324 * Found a named object declaration during method execution;
325 * we must enter this object into the namespace. The created
326 * object is temporary and will be deleted upon completion of
327 * the execution of this method.
329 * Note 10/2010: Except for the Scope() op. This opcode does
330 * not actually create a new object, it refers to an existing
331 * object. However, for Scope(), we want to indeed open a
334 if (Op->Common.AmlOpcode != AML_SCOPE_OP)
336 Status = AcpiDsLoad2BeginOp (WalkState, NULL);
340 Status = AcpiDsScopeStackPush (Op->Named.Node,
341 Op->Named.Node->Type, WalkState);
342 if (ACPI_FAILURE (Status))
344 return_ACPI_STATUS (Status);
350 case AML_CLASS_EXECUTE:
351 case AML_CLASS_CREATE:
360 /* Nothing to do here during method execution */
362 return_ACPI_STATUS (Status);
366 Status = AcpiDsMethodError (Status, WalkState);
367 return_ACPI_STATUS (Status);
371 /*****************************************************************************
373 * FUNCTION: AcpiDsExecEndOp
375 * PARAMETERS: WalkState - Current state of the parse tree walk
379 * DESCRIPTION: Ascending callback used during the execution of control
380 * methods. The only thing we really need to do here is to
381 * notice the beginning of IF, ELSE, and WHILE blocks.
383 ****************************************************************************/
387 ACPI_WALK_STATE *WalkState)
389 ACPI_PARSE_OBJECT *Op;
390 ACPI_STATUS Status = AE_OK;
393 ACPI_PARSE_OBJECT *NextOp;
394 ACPI_PARSE_OBJECT *FirstArg;
397 ACPI_FUNCTION_TRACE_PTR (DsExecEndOp, WalkState);
401 OpType = WalkState->OpInfo->Type;
402 OpClass = WalkState->OpInfo->Class;
404 if (OpClass == AML_CLASS_UNKNOWN)
406 ACPI_ERROR ((AE_INFO, "Unknown opcode 0x%X", Op->Common.AmlOpcode));
407 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
410 FirstArg = Op->Common.Value.Arg;
412 /* Init the walk state */
414 WalkState->NumOperands = 0;
415 WalkState->OperandIndex = 0;
416 WalkState->ReturnDesc = NULL;
417 WalkState->ResultObj = NULL;
419 /* Call debugger for single step support (DEBUG build only) */
421 ACPI_DEBUGGER_EXEC (Status = AcpiDbSingleStep (WalkState, Op, OpClass));
422 ACPI_DEBUGGER_EXEC (if (ACPI_FAILURE (Status)) {return_ACPI_STATUS (Status);});
424 /* Decode the Opcode Class */
428 case AML_CLASS_ARGUMENT: /* Constants, literals, etc. */
430 if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
432 Status = AcpiDsEvaluateNamePath (WalkState);
433 if (ACPI_FAILURE (Status))
440 case AML_CLASS_EXECUTE: /* Most operators with arguments */
442 /* Build resolved operand stack */
444 Status = AcpiDsCreateOperands (WalkState, FirstArg);
445 if (ACPI_FAILURE (Status))
451 * All opcodes require operand resolution, with the only exceptions
452 * being the ObjectType and SizeOf operators.
454 if (!(WalkState->OpInfo->Flags & AML_NO_OPERAND_RESOLVE))
456 /* Resolve all operands */
458 Status = AcpiExResolveOperands (WalkState->Opcode,
459 &(WalkState->Operands [WalkState->NumOperands -1]),
463 if (ACPI_SUCCESS (Status))
466 * Dispatch the request to the appropriate interpreter handler
467 * routine. There is one routine per opcode "type" based upon the
468 * number of opcode arguments and return type.
470 Status = AcpiGbl_OpTypeDispatch[OpType] (WalkState);
475 * Treat constructs of the form "Store(LocalX,LocalX)" as noops when the
476 * Local is uninitialized.
478 if ((Status == AE_AML_UNINITIALIZED_LOCAL) &&
479 (WalkState->Opcode == AML_STORE_OP) &&
480 (WalkState->Operands[0]->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
481 (WalkState->Operands[1]->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
482 (WalkState->Operands[0]->Reference.Class ==
483 WalkState->Operands[1]->Reference.Class) &&
484 (WalkState->Operands[0]->Reference.Value ==
485 WalkState->Operands[1]->Reference.Value))
491 ACPI_EXCEPTION ((AE_INFO, Status,
492 "While resolving operands for [%s]",
493 AcpiPsGetOpcodeName (WalkState->Opcode)));
497 /* Always delete the argument objects and clear the operand stack */
499 AcpiDsClearOperands (WalkState);
502 * If a result object was returned from above, push it on the
503 * current result stack
505 if (ACPI_SUCCESS (Status) &&
506 WalkState->ResultObj)
508 Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
516 case AML_TYPE_CONTROL: /* Type 1 opcode, IF/ELSE/WHILE/NOOP */
518 /* 1 Operand, 0 ExternalResult, 0 InternalResult */
520 Status = AcpiDsExecEndControlOp (WalkState, Op);
524 case AML_TYPE_METHOD_CALL:
526 * If the method is referenced from within a package
527 * declaration, it is not a invocation of the method, just
530 if ((Op->Asl.Parent) &&
531 ((Op->Asl.Parent->Asl.AmlOpcode == AML_PACKAGE_OP) ||
532 (Op->Asl.Parent->Asl.AmlOpcode == AML_VAR_PACKAGE_OP)))
534 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
535 "Method Reference in a Package, Op=%p\n", Op));
537 Op->Common.Node = (ACPI_NAMESPACE_NODE *) Op->Asl.Value.Arg->Asl.Node;
538 AcpiUtAddReference (Op->Asl.Value.Arg->Asl.Node->Object);
539 return_ACPI_STATUS (AE_OK);
542 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
543 "Method invocation, Op=%p\n", Op));
546 * (AML_METHODCALL) Op->Asl.Value.Arg->Asl.Node contains
547 * the method Node pointer
549 /* NextOp points to the op that holds the method name */
553 /* NextOp points to first argument op */
555 NextOp = NextOp->Common.Next;
558 * Get the method's arguments and put them on the operand stack
560 Status = AcpiDsCreateOperands (WalkState, NextOp);
561 if (ACPI_FAILURE (Status))
567 * Since the operands will be passed to another control method,
568 * we must resolve all local references here (Local variables,
569 * arguments to *this* method, etc.)
571 Status = AcpiDsResolveOperands (WalkState);
572 if (ACPI_FAILURE (Status))
574 /* On error, clear all resolved operands */
576 AcpiDsClearOperands (WalkState);
581 * Tell the walk loop to preempt this running method and
582 * execute the new method
584 Status = AE_CTRL_TRANSFER;
587 * Return now; we don't want to disturb anything,
588 * especially the operand count!
590 return_ACPI_STATUS (Status);
592 case AML_TYPE_CREATE_FIELD:
594 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
595 "Executing CreateField Buffer/Index Op=%p\n", Op));
597 Status = AcpiDsLoad2EndOp (WalkState);
598 if (ACPI_FAILURE (Status))
603 Status = AcpiDsEvalBufferFieldOperands (WalkState, Op);
607 case AML_TYPE_CREATE_OBJECT:
609 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
610 "Executing CreateObject (Buffer/Package) Op=%p\n", Op));
612 switch (Op->Common.Parent->Common.AmlOpcode)
616 * Put the Node on the object stack (Contains the ACPI Name
619 WalkState->Operands[0] = (void *) Op->Common.Parent->Common.Node;
620 WalkState->NumOperands = 1;
622 Status = AcpiDsCreateNode (WalkState,
623 Op->Common.Parent->Common.Node,
625 if (ACPI_FAILURE (Status))
631 /*lint -fallthrough */
633 case AML_INT_EVAL_SUBTREE_OP:
635 Status = AcpiDsEvalDataObjectOperands (WalkState, Op,
636 AcpiNsGetAttachedObject (Op->Common.Parent->Common.Node));
641 Status = AcpiDsEvalDataObjectOperands (WalkState, Op, NULL);
646 * If a result object was returned from above, push it on the
647 * current result stack
649 if (WalkState->ResultObj)
651 Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
655 case AML_TYPE_NAMED_FIELD:
656 case AML_TYPE_NAMED_COMPLEX:
657 case AML_TYPE_NAMED_SIMPLE:
658 case AML_TYPE_NAMED_NO_OBJ:
660 Status = AcpiDsLoad2EndOp (WalkState);
661 if (ACPI_FAILURE (Status))
666 if (Op->Common.AmlOpcode == AML_REGION_OP)
668 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
669 "Executing OpRegion Address/Length Op=%p\n", Op));
671 Status = AcpiDsEvalRegionOperands (WalkState, Op);
672 if (ACPI_FAILURE (Status))
677 else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
679 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
680 "Executing DataTableRegion Strings Op=%p\n", Op));
682 Status = AcpiDsEvalTableRegionOperands (WalkState, Op);
683 if (ACPI_FAILURE (Status))
688 else if (Op->Common.AmlOpcode == AML_BANK_FIELD_OP)
690 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
691 "Executing BankField Op=%p\n", Op));
693 Status = AcpiDsEvalBankFieldOperands (WalkState, Op);
694 if (ACPI_FAILURE (Status))
701 case AML_TYPE_UNDEFINED:
703 ACPI_ERROR ((AE_INFO,
704 "Undefined opcode type Op=%p", Op));
705 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
709 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
710 "Internal opcode=%X type Op=%p\n",
711 WalkState->Opcode, Op));
716 ACPI_ERROR ((AE_INFO,
717 "Unimplemented opcode, class=0x%X type=0x%X Opcode=0x%X Op=%p",
718 OpClass, OpType, Op->Common.AmlOpcode, Op));
720 Status = AE_NOT_IMPLEMENTED;
726 * ACPI 2.0 support for 64-bit integers: Truncate numeric
727 * result value if we are executing from a 32-bit ACPI table
729 (void) AcpiExTruncateFor32bitTable (WalkState->ResultObj);
732 * Check if we just completed the evaluation of a
733 * conditional predicate
735 if ((ACPI_SUCCESS (Status)) &&
736 (WalkState->ControlState) &&
737 (WalkState->ControlState->Common.State ==
738 ACPI_CONTROL_PREDICATE_EXECUTING) &&
739 (WalkState->ControlState->Control.PredicateOp == Op))
741 Status = AcpiDsGetPredicateValue (WalkState, WalkState->ResultObj);
742 WalkState->ResultObj = NULL;
748 if (WalkState->ResultObj)
750 /* Break to debugger to display result */
752 ACPI_DEBUGGER_EXEC (AcpiDbDisplayResultObject (WalkState->ResultObj,
756 * Delete the result op if and only if:
757 * Parent will not use the result -- such as any
758 * non-nested type2 op in a method (parent will be method)
760 AcpiDsDeleteResultIfNotUsed (Op, WalkState->ResultObj, WalkState);
763 #ifdef _UNDER_DEVELOPMENT
765 if (WalkState->ParserState.Aml == WalkState->ParserState.AmlEnd)
767 AcpiDbMethodEnd (WalkState);
771 /* Invoke exception handler on error */
773 if (ACPI_FAILURE (Status))
775 Status = AcpiDsMethodError (Status, WalkState);
778 /* Always clear the object stack */
780 WalkState->NumOperands = 0;
781 return_ACPI_STATUS (Status);