Skip to content

Commit

Permalink
Dispatcher: Cleanup ACPI_OPERAND_OBJECT's AML address assignments.
Browse files Browse the repository at this point in the history
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 <lv.zheng@intel.com>
  • Loading branch information
Lv Zheng committed Jun 10, 2015
1 parent 61b3600 commit afb5261
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 54 deletions.
2 changes: 1 addition & 1 deletion source/common/adisasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ AdParseTable (

/* Create the root object */

AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp ();
AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp (AmlStart);
if (!AcpiGbl_ParseOpRoot)
{
return (AE_NO_MEMORY);
Expand Down
2 changes: 1 addition & 1 deletion source/components/debugger/dbmethod.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ AcpiDbDisassembleMethod (

ObjDesc = Method->Object;

Op = AcpiPsCreateScopeOp ();
Op = AcpiPsCreateScopeOp (ObjDesc->Method.AmlStart);
if (!Op)
{
return (AE_NO_MEMORY);
Expand Down
4 changes: 2 additions & 2 deletions source/components/dispatcher/dsargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion source/components/dispatcher/dsmethod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion source/components/dispatcher/dswload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion source/components/dispatcher/dswload2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 20 additions & 24 deletions source/components/namespace/nsparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -164,7 +180,7 @@ AcpiNsOneCompleteParse (

/* Create and init a Root Node */

ParseRoot = AcpiPsCreateScopeOp ();
ParseRoot = AcpiPsCreateScopeOp (AmlStart);
if (!ParseRoot)
{
return_ACPI_STATUS (AE_NO_MEMORY);
Expand All @@ -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 */
Expand All @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions source/components/parser/psargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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++;
Expand All @@ -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);
Expand Down Expand Up @@ -783,7 +782,7 @@ AcpiPsGetNextField (
}
else
{
Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, Aml);
if (!Arg)
{
AcpiPsFreeOp (Field);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions source/components/parser/psloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ AcpiPsGetArguments (

if (Arg)
{
Arg->Common.Aml = WalkState->Aml;
AcpiPsAppendArg (Op, Arg);
}

Expand Down Expand Up @@ -573,8 +572,6 @@ AcpiPsParseLoop (
continue;
}

Op->Common.Aml = WalkState->Aml;

if (WalkState->OpInfo)
{
ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
Expand Down
2 changes: 1 addition & 1 deletion source/components/parser/psobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions source/components/parser/psparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions source/components/parser/psutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
*
Expand All @@ -198,7 +199,8 @@ AcpiPsInitOp (

ACPI_PARSE_OBJECT*
AcpiPsAllocOp (
UINT16 Opcode)
UINT16 Opcode,
UINT8 *Aml)
{
ACPI_PARSE_OBJECT *Op;
const ACPI_OPCODE_INFO *OpInfo;
Expand Down Expand Up @@ -245,6 +247,7 @@ AcpiPsAllocOp (
if (Op)
{
AcpiPsInitOp (Op, Opcode);
Op->Common.Aml = Aml;
Op->Common.Flags = Flags;
}

Expand Down
2 changes: 1 addition & 1 deletion source/components/parser/psxface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions source/include/acparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ AcpiPsDeleteParseTree (
*/
ACPI_PARSE_OBJECT *
AcpiPsCreateScopeOp (
void);
UINT8 *Aml);

void
AcpiPsInitOp (
Expand All @@ -387,7 +387,8 @@ AcpiPsInitOp (

ACPI_PARSE_OBJECT *
AcpiPsAllocOp (
UINT16 opcode);
UINT16 Opcode,
UINT8 *Aml);

void
AcpiPsFreeOp (
Expand Down

0 comments on commit afb5261

Please sign in to comment.