summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLv Zheng <lv.zheng@intel.com>2016-06-22 09:28:54 +0800
committerLv Zheng <lv.zheng@intel.com>2016-06-22 09:28:54 +0800
commitf3a77b60fbf953953a1a062215d52eeb2f95ff2d (patch)
tree6201b079de4da42a8260771a2e68700039fdbce2
parent5590b7aee04373f9a104625327cfb5243fce2ec9 (diff)
downloadacpica-f3a77b60fbf953953a1a062215d52eeb2f95ff2d.tar.gz
Interpreter: Fix MLC issues by switching to new TermList grammar for table loading
The MLC (Module Level Code) is an ACPICA terminology describing the AML code out of any control method, its support is an indication of the interpreter behavior during the table loading. The original implementation of MLC in ACPICA had several issues: 1. Out of any control method, besides of the object creating opcodes, only the code blocks wrapped by "If/Else/While" opcodes were supported. 2. The supported MLC code blocks were executed after loading the table rather than being executed right in place. ============================================================ The demo of this order issue is as follows: Name (OBJ1, 1) If (CND1 == 1) { Name (OBJ2, 2) } Name (OBJ3, 3) The original MLC support created OBJ2 after OBJ3's creation. ============================================================ Other than these limitations, MLC support in ACPICA looks correct. And supporting this should be easy/natural for ACPICA, but enabling of this was blocked by some ACPICA internal and OSPM specific initialization order issues we've fixed recently. The wrong support started from the following false bug fixing commit: Commit: 80d7951177315f70b5ffd8663985fbf725d07799 Subject: Add support for module-level executable AML code. We can confirm Windows interpreter behavior via reverse engineering means. It can be proven that not only If/Else/While wrapped code blocks, all opcodes can be executed at the module level, including operation region accesses. And it can be proven that the MLC should be executed right in place, not in such a deferred way executed after loading the table. And the above facts indeed reflect the spec words around ACPI definition block tables (DSDT/SSDT/...), the entire table and the Scope object is defined by the AML specification in BNF style as: AMLCode := DefBlockHeader TermList DefScope := ScopeOp PkgLength NameString TermList The bodies of the scope opening terms (AMLCode/Scope) are all TermList, thus the table loading should be no difference than the control method evaluations as the body of the Method is also defined by the AML specification as TermList: DefMethod := MethodOp PkgLength NameString MethodFlags TermList The only difference is: after evaluating control method, created named objects may be freed due to no reference, while named objects created by the table loading should only be freed after unloading the table. So this patch follows the spec and the de-facto standard behavior, enables the new grammar (TermList) for the table loading. By doing so, beyond the fixes to the above issues, we can see additional differences comparing to the old grammar based table loading: 1. Originally, beyond the scope opening terms (AMLCode/Scope), If/Else/While wrapped code blocks under the scope creating terms (Device/PowerResource/Processor/ThermalZone) are also supported as deferred MLC, which violates the spec defined grammar where ObjectList is enforced. With MLC support improved as non-deferred, the interpreter parses such scope creating terms as TermList rather ObjectList like the scope opening terms. After probing the Windows behavior and proving that it also parses these terms as TermList, we submitted an ECR (Engineering Change Request) to the ASWG (ACPI Specification Working Group) to clarify this. The ECR is titled as "ASL Grammar Clarification for Executable AML Opcodes" and has been accepted by the ASWG. The new grammar will appear in ACPI specification 6.2. 2. Originally, Buffer/Package/OperationRegion/CreateXXXField/BankField arguments are evaluated in a deferred way after loading the table. With MLC support improved, they are also parsed right in place during the table loading. This is also Windows compliant and the only difference is the removal of the debugging messages implemented before AcpiDsExecuteArguments(), see Link 1 for the details. A previous commit should have ensured that AcpiCheckAddressRange() won't regress. Note that enabling this feature may cause regressions due to long term Linux ACPI support on top of the wrong grammar. So this patch also prepares a global option to be used to roll back to the old grammar during the period between a regression is reported and the regression is root-cause-fixed. Lv Zheng. Link 1: https://bugzilla.kernel.org/show_bug.cgi?id=112911 Tested-by: Chris Bainbridge <chris.bainbridge@gmail.com> Signed-off-by: Lv Zheng <lv.zheng@intel.com>
-rw-r--r--source/compiler/aslstubs.c8
-rw-r--r--source/components/events/evrgnini.c3
-rw-r--r--source/components/executer/exconfig.c2
-rw-r--r--source/components/namespace/nsload.c2
-rw-r--r--source/components/namespace/nsparse.c180
-rw-r--r--source/components/parser/psparse.c3
-rw-r--r--source/components/parser/psxface.c80
-rw-r--r--source/components/tables/tbxfload.c2
-rw-r--r--source/components/utilities/utxfinit.c2
-rw-r--r--source/include/acnamesp.h5
-rw-r--r--source/include/acparser.h4
-rw-r--r--source/include/acpixf.h6
12 files changed, 260 insertions, 37 deletions
diff --git a/source/compiler/aslstubs.c b/source/compiler/aslstubs.c
index 1ae9e2a32..d0ccdba69 100644
--- a/source/compiler/aslstubs.c
+++ b/source/compiler/aslstubs.c
@@ -119,6 +119,7 @@
#include "acevents.h"
#include "acinterp.h"
#include "acnamesp.h"
+#include "acparser.h"
#define _COMPONENT ACPI_COMPILER
ACPI_MODULE_NAME ("aslstubs")
@@ -143,6 +144,13 @@ AcpiNsInitializeObjects (
}
ACPI_STATUS
+AcpiPsExecuteTable (
+ ACPI_EVALUATE_INFO *Info)
+{
+ return (AE_OK);
+}
+
+ACPI_STATUS
AcpiHwReadPort (
ACPI_IO_ADDRESS Address,
UINT32 *Value,
diff --git a/source/components/events/evrgnini.c b/source/components/events/evrgnini.c
index 7880d04b7..2e6315c3f 100644
--- a/source/components/events/evrgnini.c
+++ b/source/components/events/evrgnini.c
@@ -690,7 +690,8 @@ AcpiEvInitializeRegion (
*
* See AcpiNsExecModuleCode
*/
- if (ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL)
+ if (!AcpiGbl_ParseTableAsTermList &&
+ ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL)
{
HandlerObj = ObjDesc->Method.Dispatch.Handler;
}
diff --git a/source/components/executer/exconfig.c b/source/components/executer/exconfig.c
index 9e8528833..94a833de5 100644
--- a/source/components/executer/exconfig.c
+++ b/source/components/executer/exconfig.c
@@ -204,7 +204,7 @@ AcpiExAddTable (
/* Execute any module-level code that was found in the table */
AcpiExExitInterpreter ();
- if (AcpiGbl_GroupModuleLevelCode)
+ if (!AcpiGbl_ParseTableAsTermList && AcpiGbl_GroupModuleLevelCode)
{
AcpiNsExecModuleCodeList ();
}
diff --git a/source/components/namespace/nsload.c b/source/components/namespace/nsload.c
index c3869aa04..6efb8ff76 100644
--- a/source/components/namespace/nsload.c
+++ b/source/components/namespace/nsload.c
@@ -252,7 +252,7 @@ Unlock:
* other ACPI implementations. Optionally, the execution can be deferred
* until later, see AcpiInitializeObjects.
*/
- if (!AcpiGbl_GroupModuleLevelCode)
+ if (!AcpiGbl_ParseTableAsTermList && !AcpiGbl_GroupModuleLevelCode)
{
AcpiNsExecModuleCodeList ();
}
diff --git a/source/components/namespace/nsparse.c b/source/components/namespace/nsparse.c
index 692d83760..331998941 100644
--- a/source/components/namespace/nsparse.c
+++ b/source/components/namespace/nsparse.c
@@ -128,6 +128,111 @@
/*******************************************************************************
*
+ * FUNCTION: NsExecuteTable
+ *
+ * PARAMETERS: TableDesc - An ACPI table descriptor for table to parse
+ * StartNode - Where to enter the table into the namespace
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Load ACPI/AML table by executing the entire table as a
+ * TermList.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiNsExecuteTable (
+ UINT32 TableIndex,
+ ACPI_NAMESPACE_NODE *StartNode)
+{
+ ACPI_STATUS Status;
+ ACPI_TABLE_HEADER *Table;
+ ACPI_OWNER_ID OwnerId;
+ ACPI_EVALUATE_INFO *Info = NULL;
+ UINT32 AmlLength;
+ UINT8 *AmlStart;
+ ACPI_OPERAND_OBJECT *MethodObj = NULL;
+
+
+ ACPI_FUNCTION_TRACE (NsExecuteTable);
+
+
+ Status = AcpiGetTableByIndex (TableIndex, &Table);
+ if (ACPI_FAILURE (Status))
+ {
+ return_ACPI_STATUS (Status);
+ }
+
+ /* Table must consist of at least a complete header */
+
+ if (Table->Length < sizeof (ACPI_TABLE_HEADER))
+ {
+ return_ACPI_STATUS (AE_BAD_HEADER);
+ }
+
+ AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
+ AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
+
+ Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
+ if (ACPI_FAILURE (Status))
+ {
+ return_ACPI_STATUS (Status);
+ }
+
+ /* Create, initialize, and link a new temporary method object */
+
+ MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
+ if (!MethodObj)
+ {
+ return_ACPI_STATUS (AE_NO_MEMORY);
+ }
+
+ /* Allocate the evaluation information block */
+
+ Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
+ if (!Info)
+ {
+ Status = AE_NO_MEMORY;
+ goto Cleanup;
+ }
+
+ ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
+ "Create table code block: %p\n", MethodObj));
+
+ MethodObj->Method.AmlStart = AmlStart;
+ MethodObj->Method.AmlLength = AmlLength;
+ MethodObj->Method.OwnerId = OwnerId;
+ MethodObj->Method.InfoFlags |= ACPI_METHOD_MODULE_LEVEL;
+
+ Info->PassNumber = ACPI_IMODE_EXECUTE;
+ Info->Node = StartNode;
+ Info->ObjDesc = MethodObj;
+ Info->NodeFlags = Info->Node->Flags;
+ Info->FullPathname = AcpiNsGetNormalizedPathname (Info->Node, TRUE);
+ if (!Info->FullPathname)
+ {
+ Status = AE_NO_MEMORY;
+ goto Cleanup;
+ }
+
+ (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
+ Status = AcpiPsExecuteTable (Info);
+ (void) AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
+
+Cleanup:
+ if (Info)
+ {
+ ACPI_FREE (Info->FullPathname);
+ Info->FullPathname = NULL;
+ }
+ ACPI_FREE (Info);
+ AcpiUtRemoveReference (MethodObj);
+ return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
* FUNCTION: NsOneCompleteParse
*
* PARAMETERS: PassNumber - 1 or 2
@@ -263,40 +368,53 @@ AcpiNsParseTable (
AcpiExEnterInterpreter ();
- /*
- * AML Parse, pass 1
- *
- * In this pass, we load most of the namespace. Control methods
- * are not parsed until later. A parse tree is not created. Instead,
- * each Parser Op subtree is deleted when it is finished. This saves
- * a great deal of memory, and allows a small cache of parse objects
- * to service the entire parse. The second pass of the parse then
- * performs another complete parse of the AML.
- */
- ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 1\n"));
-
- Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS1,
- TableIndex, StartNode);
- if (ACPI_FAILURE (Status))
+ if (AcpiGbl_ParseTableAsTermList)
{
- goto ErrorExit;
- }
+ ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start load pass\n"));
- /*
- * AML Parse, pass 2
- *
- * In this pass, we resolve forward references and other things
- * that could not be completed during the first pass.
- * Another complete parse of the AML is performed, but the
- * overhead of this is compensated for by the fact that the
- * parse objects are all cached.
- */
- ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 2\n"));
- Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2,
- TableIndex, StartNode);
- if (ACPI_FAILURE (Status))
+ Status = AcpiNsExecuteTable (TableIndex, StartNode);
+ if (ACPI_FAILURE (Status))
+ {
+ goto ErrorExit;
+ }
+ }
+ else
{
- goto ErrorExit;
+ /*
+ * AML Parse, pass 1
+ *
+ * In this pass, we load most of the namespace. Control methods
+ * are not parsed until later. A parse tree is not created.
+ * Instead, each Parser Op subtree is deleted when it is finished.
+ * This saves a great deal of memory, and allows a small cache of
+ * parse objects to service the entire parse. The second pass of
+ * the parse then performs another complete parse of the AML.
+ */
+ ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 1\n"));
+
+ Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS1,
+ TableIndex, StartNode);
+ if (ACPI_FAILURE (Status))
+ {
+ goto ErrorExit;
+ }
+
+ /*
+ * AML Parse, pass 2
+ *
+ * In this pass, we resolve forward references and other things
+ * that could not be completed during the first pass.
+ * Another complete parse of the AML is performed, but the
+ * overhead of this is compensated for by the fact that the
+ * parse objects are all cached.
+ */
+ ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 2\n"));
+ Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2,
+ TableIndex, StartNode);
+ if (ACPI_FAILURE (Status))
+ {
+ goto ErrorExit;
+ }
}
ErrorExit:
diff --git a/source/components/parser/psparse.c b/source/components/parser/psparse.c
index 68281bd5a..22182a94b 100644
--- a/source/components/parser/psparse.c
+++ b/source/components/parser/psparse.c
@@ -661,7 +661,8 @@ AcpiPsParseAml (
* cleanup to do
*/
if (((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) ==
- ACPI_PARSE_EXECUTE) ||
+ ACPI_PARSE_EXECUTE &&
+ !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL)) ||
(ACPI_FAILURE (Status)))
{
AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
diff --git a/source/components/parser/psxface.c b/source/components/parser/psxface.c
index 5c690a42a..6774c3f57 100644
--- a/source/components/parser/psxface.c
+++ b/source/components/parser/psxface.c
@@ -347,6 +347,86 @@ Cleanup:
/*******************************************************************************
*
+ * FUNCTION: AcpiPsExecuteTable
+ *
+ * PARAMETERS: Info - Method info block, contains:
+ * Node - Node to where the is entered into the
+ * namespace
+ * ObjDesc - Pseudo method object describing the AML
+ * code of the entire table
+ * PassNumber - Parse or execute pass
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Execute a table
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiPsExecuteTable (
+ ACPI_EVALUATE_INFO *Info)
+{
+ ACPI_STATUS Status;
+ ACPI_PARSE_OBJECT *Op = NULL;
+ ACPI_WALK_STATE *WalkState = NULL;
+
+
+ ACPI_FUNCTION_TRACE (PsExecuteTable);
+
+
+ /* Create and init a Root Node */
+
+ Op = AcpiPsCreateScopeOp (Info->ObjDesc->Method.AmlStart);
+ if (!Op)
+ {
+ Status = AE_NO_MEMORY;
+ goto Cleanup;
+ }
+
+ /* Create and initialize a new walk state */
+
+ WalkState = AcpiDsCreateWalkState (
+ Info->ObjDesc->Method.OwnerId, NULL, NULL, NULL);
+ if (!WalkState)
+ {
+ Status = AE_NO_MEMORY;
+ goto Cleanup;
+ }
+
+ Status = AcpiDsInitAmlWalk (WalkState, Op, Info->Node,
+ Info->ObjDesc->Method.AmlStart,
+ Info->ObjDesc->Method.AmlLength, Info, Info->PassNumber);
+ if (ACPI_FAILURE (Status))
+ {
+ goto Cleanup;
+ }
+
+ if (Info->ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL)
+ {
+ WalkState->ParseFlags |= ACPI_PARSE_MODULE_LEVEL;
+ }
+
+ /*
+ * Parse the AML, WalkState will be deleted by ParseAml
+ */
+ Status = AcpiPsParseAml (WalkState);
+ WalkState = NULL;
+
+Cleanup:
+ if (Op)
+ {
+ AcpiPsDeleteParseTree (Op);
+ }
+ if (WalkState)
+ {
+ AcpiDsDeleteWalkState (WalkState);
+ }
+ return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
* FUNCTION: AcpiPsUpdateParameterList
*
* PARAMETERS: Info - See ACPI_EVALUATE_INFO
diff --git a/source/components/tables/tbxfload.c b/source/components/tables/tbxfload.c
index 6ffc3ccba..8c6f5e5d9 100644
--- a/source/components/tables/tbxfload.c
+++ b/source/components/tables/tbxfload.c
@@ -183,7 +183,7 @@ AcpiLoadTables (
"While loading namespace from ACPI tables"));
}
- if (!AcpiGbl_GroupModuleLevelCode)
+ if (AcpiGbl_ParseTableAsTermList || !AcpiGbl_GroupModuleLevelCode)
{
/*
* Initialize the objects that remain uninitialized. This
diff --git a/source/components/utilities/utxfinit.c b/source/components/utilities/utxfinit.c
index c6f875c23..9104d9d9f 100644
--- a/source/components/utilities/utxfinit.c
+++ b/source/components/utilities/utxfinit.c
@@ -365,7 +365,7 @@ AcpiInitializeObjects (
* all of the tables have been loaded. It is a legacy option and is
* not compatible with other ACPI implementations. See AcpiNsLoadTable.
*/
- if (AcpiGbl_GroupModuleLevelCode)
+ if (!AcpiGbl_ParseTableAsTermList && AcpiGbl_GroupModuleLevelCode)
{
AcpiNsExecModuleCodeList ();
diff --git a/source/include/acnamesp.h b/source/include/acnamesp.h
index 2c4348699..2869bd13c 100644
--- a/source/include/acnamesp.h
+++ b/source/include/acnamesp.h
@@ -216,6 +216,11 @@ AcpiNsParseTable (
ACPI_NAMESPACE_NODE *StartNode);
ACPI_STATUS
+AcpiNsExecuteTable (
+ UINT32 TableIndex,
+ ACPI_NAMESPACE_NODE *StartNode);
+
+ACPI_STATUS
AcpiNsOneCompleteParse (
UINT32 PassNumber,
UINT32 TableIndex,
diff --git a/source/include/acparser.h b/source/include/acparser.h
index 406b0f37c..35f1ab707 100644
--- a/source/include/acparser.h
+++ b/source/include/acparser.h
@@ -155,6 +155,10 @@ ACPI_STATUS
AcpiPsExecuteMethod (
ACPI_EVALUATE_INFO *Info);
+ACPI_STATUS
+AcpiPsExecuteTable (
+ ACPI_EVALUATE_INFO *Info);
+
/*
* psargs - Parse AML opcode arguments
diff --git a/source/include/acpixf.h b/source/include/acpixf.h
index f2278dcfd..293791ff4 100644
--- a/source/include/acpixf.h
+++ b/source/include/acpixf.h
@@ -269,6 +269,12 @@ ACPI_INIT_GLOBAL (UINT8, AcpiGbl_DoNotUseXsdt, FALSE);
ACPI_INIT_GLOBAL (UINT8, AcpiGbl_GroupModuleLevelCode, FALSE);
/*
+ * Optionally support module level code by parsing the entire table as
+ * a TermList. Default is TRUE, do execute entire table.
+ */
+ACPI_INIT_GLOBAL (UINT8, AcpiGbl_ParseTableAsTermList, TRUE);
+
+/*
* Optionally use 32-bit FADT addresses if and when there is a conflict
* (address mismatch) between the 32-bit and 64-bit versions of the
* address. Although ACPICA adheres to the ACPI specification which