From afb52611dbe7403551f93504d3798534f5c343f4 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Wed, 18 Mar 2015 16:25:43 +0800 Subject: [PATCH] Dispatcher: Cleanup ACPI_OPERAND_OBJECT's AML address assignments. This patch cleans up the code of assigning the AML address to the ACPI_OPERAND_OBJECT. The idea behind this cleanup is: The AML address of the ACPI_OPERAND_OBJECT should always be determined at the point where the object is encountered. It should be started from the first byte of the object. For example, the opcode of the object, the name string of the UserTerm object, or the first byte of the packaged object (where a PkgLength is prefixed). So it's not cleaner to have it assigned here and there in the entire ACPICA source tree. There are some special cases for the internal opcodes, before cleaning up the internal opcodes, we should also determine the rules for the AML addresses of the internal opcodes: 1. INT_NAMEPATH_OP: the address of the first byte for the NameString. 2. INT_METHODCALL_OP: the address of the first byte for the NameString. 3. INT_BYTELIST_OP: the address of the first byte for the ByteData list. 4. INT_EVAL_SUBTREE_OP: the address of the first byte for the Region/Package/Buffer/BankField/Field arguments. 5. INT_NAMEDFIELD_OP: the address to the NameSeg. 6. INT_RESERVEDFIELD_OP: the address to the 0x00 prefix. 7. INT_ACCESSFIELD_OP: the address to the 0x01 prefix. 8. INT_CONNECTION_OP: the address to the 0x02 prefix. 9: INT_EXTACCESSFIELD_OP: the address to the 0x03 prefix. 10.INT_RETURN_VALUE_OP: the address of the replaced operand. 11.ComputationalData: the address to the Byte/Word/Dword/Qword/StringPrefix. Before cleaning up the internal root scope of the AmlWalk, turning it into the TermList, we need to remember the AmlStart address as the "Aml" attribute for the ACPI_OPERAND_OBJECT created by AcpiPsCreateScopeOp(). Finally, we can delete some redundant AML address assignment in psloop.c. Signed-off-by: Lv Zheng --- source/common/adisasm.c | 2 +- source/components/debugger/dbmethod.c | 2 +- source/components/dispatcher/dsargs.c | 4 +-- source/components/dispatcher/dsmethod.c | 2 +- source/components/dispatcher/dswload.c | 2 +- source/components/dispatcher/dswload2.c | 2 +- source/components/namespace/nsparse.c | 44 +++++++++++-------------- source/components/parser/psargs.c | 18 +++++----- source/components/parser/psloop.c | 3 -- source/components/parser/psobject.c | 2 +- source/components/parser/psparse.c | 12 ++++--- source/components/parser/psutils.c | 9 +++-- source/components/parser/psxface.c | 2 +- source/include/acparser.h | 5 +-- 14 files changed, 55 insertions(+), 54 deletions(-) diff --git a/source/common/adisasm.c b/source/common/adisasm.c index d4f0fe657a..7e7dbd4779 100644 --- a/source/common/adisasm.c +++ b/source/common/adisasm.c @@ -964,7 +964,7 @@ AdParseTable ( /* Create the root object */ - AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp (); + AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp (AmlStart); if (!AcpiGbl_ParseOpRoot) { return (AE_NO_MEMORY); diff --git a/source/components/debugger/dbmethod.c b/source/components/debugger/dbmethod.c index 7e44b3f8d7..5e20ada01d 100644 --- a/source/components/debugger/dbmethod.c +++ b/source/components/debugger/dbmethod.c @@ -425,7 +425,7 @@ AcpiDbDisassembleMethod ( ObjDesc = Method->Object; - Op = AcpiPsCreateScopeOp (); + Op = AcpiPsCreateScopeOp (ObjDesc->Method.AmlStart); if (!Op) { return (AE_NO_MEMORY); diff --git a/source/components/dispatcher/dsargs.c b/source/components/dispatcher/dsargs.c index 8acb5dc75c..344e55ec35 100644 --- a/source/components/dispatcher/dsargs.c +++ b/source/components/dispatcher/dsargs.c @@ -166,7 +166,7 @@ AcpiDsExecuteArguments ( /* Allocate a new parser op to be the root of the parsed tree */ - Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP); + Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP, AmlStart); if (!Op) { return_ACPI_STATUS (AE_NO_MEMORY); @@ -213,7 +213,7 @@ AcpiDsExecuteArguments ( /* Evaluate the deferred arguments */ - Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP); + Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP, AmlStart); if (!Op) { return_ACPI_STATUS (AE_NO_MEMORY); diff --git a/source/components/dispatcher/dsmethod.c b/source/components/dispatcher/dsmethod.c index 9a1b36925d..fecfd3f361 100644 --- a/source/components/dispatcher/dsmethod.c +++ b/source/components/dispatcher/dsmethod.c @@ -181,7 +181,7 @@ AcpiDsAutoSerializeMethod ( /* Create/Init a root op for the method parse tree */ - Op = AcpiPsAllocOp (AML_METHOD_OP); + Op = AcpiPsAllocOp (AML_METHOD_OP, ObjDesc->Method.AmlStart); if (!Op) { return_ACPI_STATUS (AE_NO_MEMORY); diff --git a/source/components/dispatcher/dswload.c b/source/components/dispatcher/dswload.c index a1327ba933..a9840755de 100644 --- a/source/components/dispatcher/dswload.c +++ b/source/components/dispatcher/dswload.c @@ -470,7 +470,7 @@ AcpiDsLoad1BeginOp ( { /* Create a new op */ - Op = AcpiPsAllocOp (WalkState->Opcode); + Op = AcpiPsAllocOp (WalkState->Opcode, WalkState->Aml); if (!Op) { return_ACPI_STATUS (AE_NO_MEMORY); diff --git a/source/components/dispatcher/dswload2.c b/source/components/dispatcher/dswload2.c index 312b2cd0ca..d5f9b1c17d 100644 --- a/source/components/dispatcher/dswload2.c +++ b/source/components/dispatcher/dswload2.c @@ -416,7 +416,7 @@ AcpiDsLoad2BeginOp ( { /* Create a new op */ - Op = AcpiPsAllocOp (WalkState->Opcode); + Op = AcpiPsAllocOp (WalkState->Opcode, WalkState->Aml); if (!Op) { return_ACPI_STATUS (AE_NO_MEMORY); diff --git a/source/components/namespace/nsparse.c b/source/components/namespace/nsparse.c index 481e7c358b..26dd9f3467 100644 --- a/source/components/namespace/nsparse.c +++ b/source/components/namespace/nsparse.c @@ -156,6 +156,22 @@ AcpiNsOneCompleteParse ( ACPI_FUNCTION_TRACE (NsOneCompleteParse); + 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)) { @@ -164,7 +180,7 @@ AcpiNsOneCompleteParse ( /* Create and init a Root Node */ - ParseRoot = AcpiPsCreateScopeOp (); + ParseRoot = AcpiPsCreateScopeOp (AmlStart); if (!ParseRoot) { return_ACPI_STATUS (AE_NO_MEMORY); @@ -179,26 +195,12 @@ AcpiNsOneCompleteParse ( return_ACPI_STATUS (AE_NO_MEMORY); } - Status = AcpiGetTableByIndex (TableIndex, &Table); + Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL, + AmlStart, AmlLength, NULL, (UINT8) PassNumber); if (ACPI_FAILURE (Status)) { AcpiDsDeleteWalkState (WalkState); - AcpiPsFreeOp (ParseRoot); - return_ACPI_STATUS (Status); - } - - /* Table must consist of at least a complete header */ - - if (Table->Length < sizeof (ACPI_TABLE_HEADER)) - { - Status = AE_BAD_HEADER; - } - else - { - AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER); - AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER); - Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL, - AmlStart, AmlLength, NULL, (UINT8) PassNumber); + goto Cleanup; } /* Found OSDT table, enable the namespace override feature */ @@ -209,12 +211,6 @@ AcpiNsOneCompleteParse ( WalkState->NamespaceOverride = TRUE; } - if (ACPI_FAILURE (Status)) - { - AcpiDsDeleteWalkState (WalkState); - goto Cleanup; - } - /* StartNode is the default location to load the table */ if (StartNode && StartNode != AcpiGbl_RootNode) diff --git a/source/components/parser/psargs.c b/source/components/parser/psargs.c index 84cec22e13..cbb24a9f89 100644 --- a/source/components/parser/psargs.c +++ b/source/components/parser/psargs.c @@ -388,7 +388,7 @@ AcpiPsGetNextNamepath ( ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Control Method - %p Desc %p Path=%p\n", Node, MethodDesc, Path)); - NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP); + NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, Start); if (!NameOp) { return_ACPI_STATUS (AE_NO_MEMORY); @@ -650,14 +650,12 @@ AcpiPsGetNextField ( /* Allocate a new field op */ - Field = AcpiPsAllocOp (Opcode); + Field = AcpiPsAllocOp (Opcode, Aml); if (!Field) { return_PTR (NULL); } - Field->Common.Aml = Aml; - /* Decode the field type */ switch (Opcode) @@ -721,6 +719,7 @@ AcpiPsGetNextField ( * Argument for Connection operator can be either a Buffer * (resource descriptor), or a NameString. */ + Aml = ParserState->Aml; if (ACPI_GET8 (ParserState->Aml) == AML_BUFFER_OP) { ParserState->Aml++; @@ -733,7 +732,7 @@ AcpiPsGetNextField ( { /* Non-empty list */ - Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP); + Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP, Aml); if (!Arg) { AcpiPsFreeOp (Field); @@ -783,7 +782,7 @@ AcpiPsGetNextField ( } else { - Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP); + Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, Aml); if (!Arg) { AcpiPsFreeOp (Field); @@ -855,7 +854,7 @@ AcpiPsGetNextArg ( /* Constants, strings, and namestrings are all the same size */ - Arg = AcpiPsAllocOp (AML_BYTE_OP); + Arg = AcpiPsAllocOp (AML_BYTE_OP, ParserState->Aml); if (!Arg) { return_ACPI_STATUS (AE_NO_MEMORY); @@ -907,7 +906,8 @@ AcpiPsGetNextArg ( { /* Non-empty list */ - Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP); + Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP, + ParserState->Aml); if (!Arg) { return_ACPI_STATUS (AE_NO_MEMORY); @@ -937,7 +937,7 @@ AcpiPsGetNextArg ( { /* NullName or NameString */ - Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP); + Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, ParserState->Aml); if (!Arg) { return_ACPI_STATUS (AE_NO_MEMORY); diff --git a/source/components/parser/psloop.c b/source/components/parser/psloop.c index f67710dc39..9acad077fc 100644 --- a/source/components/parser/psloop.c +++ b/source/components/parser/psloop.c @@ -217,7 +217,6 @@ AcpiPsGetArguments ( if (Arg) { - Arg->Common.Aml = WalkState->Aml; AcpiPsAppendArg (Op, Arg); } @@ -573,8 +572,6 @@ AcpiPsParseLoop ( continue; } - Op->Common.Aml = WalkState->Aml; - if (WalkState->OpInfo) { ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, diff --git a/source/components/parser/psobject.c b/source/components/parser/psobject.c index 990c4441c5..77e94345a8 100644 --- a/source/components/parser/psobject.c +++ b/source/components/parser/psobject.c @@ -389,7 +389,7 @@ AcpiPsCreateOp ( /* Create Op structure and append to parent's argument list */ WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode); - Op = AcpiPsAllocOp (WalkState->Opcode); + Op = AcpiPsAllocOp (WalkState->Opcode, AmlOpStart); if (!Op) { return_ACPI_STATUS (AE_NO_MEMORY); diff --git a/source/components/parser/psparse.c b/source/components/parser/psparse.c index 71c3fa057f..44d70b58d9 100644 --- a/source/components/parser/psparse.c +++ b/source/components/parser/psparse.c @@ -270,7 +270,8 @@ AcpiPsCompleteThisOp ( * These opcodes contain TermArg operands. The current * op must be replaced by a placeholder return op */ - ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP); + ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP, + Op->Common.Aml); if (!ReplacementOp) { Status = AE_NO_MEMORY; @@ -289,7 +290,8 @@ AcpiPsCompleteThisOp ( (Op->Common.Parent->Common.AmlOpcode == AML_BANK_FIELD_OP) || (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)) { - ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP); + ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP, + Op->Common.Aml); if (!ReplacementOp) { Status = AE_NO_MEMORY; @@ -302,7 +304,8 @@ AcpiPsCompleteThisOp ( (Op->Common.AmlOpcode == AML_PACKAGE_OP) || (Op->Common.AmlOpcode == AML_VAR_PACKAGE_OP)) { - ReplacementOp = AcpiPsAllocOp (Op->Common.AmlOpcode); + ReplacementOp = AcpiPsAllocOp (Op->Common.AmlOpcode, + Op->Common.Aml); if (!ReplacementOp) { Status = AE_NO_MEMORY; @@ -318,7 +321,8 @@ AcpiPsCompleteThisOp ( default: - ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP); + ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP, + Op->Common.Aml); if (!ReplacementOp) { Status = AE_NO_MEMORY; diff --git a/source/components/parser/psutils.c b/source/components/parser/psutils.c index a36a3f3a28..3aa4954ae1 100644 --- a/source/components/parser/psutils.c +++ b/source/components/parser/psutils.c @@ -136,12 +136,12 @@ ACPI_PARSE_OBJECT * AcpiPsCreateScopeOp ( - void) + UINT8 *Aml) { ACPI_PARSE_OBJECT *ScopeOp; - ScopeOp = AcpiPsAllocOp (AML_SCOPE_OP); + ScopeOp = AcpiPsAllocOp (AML_SCOPE_OP, Aml); if (!ScopeOp) { return (NULL); @@ -187,6 +187,7 @@ AcpiPsInitOp ( * FUNCTION: AcpiPsAllocOp * * PARAMETERS: Opcode - Opcode that will be stored in the new Op + * Aml - Address of the opcode * * RETURN: Pointer to the new Op, null on failure * @@ -198,7 +199,8 @@ AcpiPsInitOp ( ACPI_PARSE_OBJECT* AcpiPsAllocOp ( - UINT16 Opcode) + UINT16 Opcode, + UINT8 *Aml) { ACPI_PARSE_OBJECT *Op; const ACPI_OPCODE_INFO *OpInfo; @@ -245,6 +247,7 @@ AcpiPsAllocOp ( if (Op) { AcpiPsInitOp (Op, Opcode); + Op->Common.Aml = Aml; Op->Common.Flags = Flags; } diff --git a/source/components/parser/psxface.c b/source/components/parser/psxface.c index 09833b6264..c1b3a8ff56 100644 --- a/source/components/parser/psxface.c +++ b/source/components/parser/psxface.c @@ -369,7 +369,7 @@ AcpiPsExecuteMethod ( /* Create and init a Root Node */ - Op = AcpiPsCreateScopeOp (); + Op = AcpiPsCreateScopeOp (Info->ObjDesc->Method.AmlStart); if (!Op) { Status = AE_NO_MEMORY; diff --git a/source/include/acparser.h b/source/include/acparser.h index e4fc0c7992..c525dd33cf 100644 --- a/source/include/acparser.h +++ b/source/include/acparser.h @@ -378,7 +378,7 @@ AcpiPsDeleteParseTree ( */ ACPI_PARSE_OBJECT * AcpiPsCreateScopeOp ( - void); + UINT8 *Aml); void AcpiPsInitOp ( @@ -387,7 +387,8 @@ AcpiPsInitOp ( ACPI_PARSE_OBJECT * AcpiPsAllocOp ( - UINT16 opcode); + UINT16 Opcode, + UINT8 *Aml); void AcpiPsFreeOp (