From: "Krzysztof Koch" <krzysztof.koch@arm.com>
To: <devel@edk2.groups.io>
Cc: <ray.ni@intel.com>, <zhichao.gao@intel.com>,
<Sami.Mujawar@arm.com>,
<Laura.Moretta@arm.comMatteo.Carlini@arm.com>, <nd@arm.com>
Subject: [PATCH v1 6/6] ShellPkg: acpiview: Make PPTT parsing logic data driven
Date: Tue, 5 May 2020 16:46:04 +0100 [thread overview]
Message-ID: <20200505154604.9848-7-krzysztof.koch@arm.com> (raw)
In-Reply-To: <20200505154604.9848-1-krzysztof.koch@arm.com>
Replace the switch statement in the main parser loop with a table-driven
approach. Use the ParseAcpiStruct () method to resolve how each
Processor Topology Structure given should be parsed.
Enumerate all structures found in the Processor Properties Topology
Table (PPTT) on a per-type basis.
Consolidate all metadata about each Processor Topology Structure.
Define an array of ACPI_STRUCT_INFO structures to store the name,
instance count, architecture support and handling information. Use this
array to construct the ACPI_STRUCT_DATABASE for PPTT.
Count the number of instances of each Processor Topology Structure type.
Optionally report these counts after PPTT table parsing is finished.
Remove the definition of the DumpCacheTypeStructure and DumpIDStructure
functions. Their only purpose was to call ParseAcpi () and now this
process is streamlined.
Make DumpProcessorHierarchyNodeStructure function signature match that
of ACPI_STRUCT_PARSER_FUNC. This way, the function can be called from
ParseAcpiStruct ().
References:
- ACPI 6.3 Specification - January 2019, Section 5.2.29
Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
---
Notes:
v1:
- Make PPTT parsing logic data driven [Krzysztof]
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c | 152 ++++++++++----------
ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.h | 2 +-
2 files changed, 74 insertions(+), 80 deletions(-)
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
index 0db272c16af0ad8824c8da4c88dd409c8550112a..b62f79b52cab989942f84b020e1d737e8ef65439 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
@@ -21,6 +21,11 @@ STATIC CONST UINT8* ProcessorTopologyStructureLength;
STATIC CONST UINT32* NumberOfPrivateResources;
STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
+/**
+ Handler for each Processor Topology Structure
+**/
+STATIC ACPI_STRUCT_INFO PpttStructs[];
+
/**
This function validates the Cache Type Structure (Type 1) 'Number of sets'
field.
@@ -243,22 +248,34 @@ STATIC CONST ACPI_PARSER IdStructureParser[] = {
@param [in] Ptr Pointer to the start of the Processor Hierarchy Node
Structure data.
@param [in] Length Length of the Processor Hierarchy Node Structure.
+ @param [in] OptArg0 First optional argument (Not used).
+ @param [in] OptArg1 Second optional argument (Not used).
**/
STATIC
VOID
DumpProcessorHierarchyNodeStructure (
- IN UINT8* Ptr,
- IN UINT8 Length
+ IN UINT8* Ptr,
+ IN UINT32 Length,
+ IN CONST VOID* OptArg0 OPTIONAL,
+ IN CONST VOID* OptArg1 OPTIONAL
)
{
UINT32 Offset;
UINT32 Index;
CHAR16 Buffer[OUTPUT_FIELD_COLUMN_WIDTH];
+ CHAR8 AsciiBuffer[80];
+
+ PrintAcpiStructName (
+ PpttStructs[EFI_ACPI_6_3_PPTT_TYPE_PROCESSOR].Name,
+ PpttStructs[EFI_ACPI_6_3_PPTT_TYPE_PROCESSOR].Count,
+ sizeof (AsciiBuffer),
+ AsciiBuffer
+ );
Offset = ParseAcpi (
TRUE,
2,
- "Processor Hierarchy Node Structure",
+ AsciiBuffer,
Ptr,
Length,
PARSER_PARAMS (ProcessorHierarchyNodeStructureParser)
@@ -269,7 +286,8 @@ DumpProcessorHierarchyNodeStructure (
if (NumberOfPrivateResources == NULL) {
IncrementErrorCount ();
Print (
- L"ERROR: Insufficient Processor Hierarchy Node length. Length = %d.\n",
+ L"ERROR: Insufficient %a Structure length. Length = %d.\n",
+ PpttStructs[EFI_ACPI_6_3_PPTT_TYPE_PROCESSOR].Name,
Length
);
return;
@@ -296,7 +314,7 @@ DumpProcessorHierarchyNodeStructure (
UnicodeSPrint (
Buffer,
sizeof (Buffer),
- L"Private resources [%d]",
+ L"Private resource [%d]",
Index
);
@@ -312,50 +330,37 @@ DumpProcessorHierarchyNodeStructure (
}
/**
- This function parses the Cache Type Structure (Type 1).
-
- @param [in] Ptr Pointer to the start of the Cache Type Structure data.
- @param [in] Length Length of the Cache Type Structure.
+ Information about each Processor Topology Structure type.
**/
-STATIC
-VOID
-DumpCacheTypeStructure (
- IN UINT8* Ptr,
- IN UINT8 Length
- )
-{
- ParseAcpi (
- TRUE,
- 2,
- "Cache Type Structure",
- Ptr,
- Length,
- PARSER_PARAMS (CacheTypeStructureParser)
- );
-}
+STATIC ACPI_STRUCT_INFO PpttStructs[] = {
+ ADD_ACPI_STRUCT_INFO_FUNC (
+ "Processor",
+ EFI_ACPI_6_3_PPTT_TYPE_PROCESSOR,
+ ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 | ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64,
+ DumpProcessorHierarchyNodeStructure
+ ),
+ ADD_ACPI_STRUCT_INFO_ARRAY (
+ "Cache",
+ EFI_ACPI_6_3_PPTT_TYPE_CACHE,
+ ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 | ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64,
+ CacheTypeStructureParser
+ ),
+ ADD_ACPI_STRUCT_INFO_ARRAY (
+ "ID",
+ EFI_ACPI_6_3_PPTT_TYPE_ID,
+ ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 | ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64,
+ IdStructureParser
+ )
+};
/**
- This function parses the ID Structure (Type 2).
-
- @param [in] Ptr Pointer to the start of the ID Structure data.
- @param [in] Length Length of the ID Structure.
+ PPTT structure database
**/
-STATIC
-VOID
-DumpIDStructure (
- IN UINT8* Ptr,
- IN UINT8 Length
- )
-{
- ParseAcpi (
- TRUE,
- 2,
- "ID Structure",
- Ptr,
- Length,
- PARSER_PARAMS (IdStructureParser)
- );
-}
+STATIC ACPI_STRUCT_DATABASE PpttDatabase = {
+ "Processor Topology Structure",
+ PpttStructs,
+ ARRAY_SIZE (PpttStructs)
+};
/**
This function parses the ACPI PPTT table.
@@ -390,6 +395,8 @@ ParseAcpiPptt (
return;
}
+ ResetAcpiStructCounts (&PpttDatabase);
+
Offset = ParseAcpi (
TRUE,
0,
@@ -419,7 +426,8 @@ ParseAcpiPptt (
IncrementErrorCount ();
Print (
L"ERROR: Insufficient remaining table buffer length to read the " \
- L"processor topology structure header. Length = %d.\n",
+ L"%a header. Length = %d.\n",
+ PpttDatabase.Name,
AcpiTableLength - Offset
);
return;
@@ -430,8 +438,9 @@ ParseAcpiPptt (
((Offset + (*ProcessorTopologyStructureLength)) > AcpiTableLength)) {
IncrementErrorCount ();
Print (
- L"ERROR: Invalid Processor Topology Structure length. " \
- L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
+ L"ERROR: Invalid %a length. Length = %d. Offset = %d. " \
+ L"AcpiTableLength = %d.\n",
+ PpttDatabase.Name,
*ProcessorTopologyStructureLength,
Offset,
AcpiTableLength
@@ -439,39 +448,24 @@ ParseAcpiPptt (
return;
}
- PrintFieldName (2, L"* Structure Offset *");
- Print (L"0x%x\n", Offset);
-
- switch (*ProcessorTopologyStructureType) {
- case EFI_ACPI_6_2_PPTT_TYPE_PROCESSOR:
- DumpProcessorHierarchyNodeStructure (
- ProcessorTopologyStructurePtr,
- *ProcessorTopologyStructureLength
- );
- break;
- case EFI_ACPI_6_2_PPTT_TYPE_CACHE:
- DumpCacheTypeStructure (
- ProcessorTopologyStructurePtr,
- *ProcessorTopologyStructureLength
- );
- break;
- case EFI_ACPI_6_2_PPTT_TYPE_ID:
- DumpIDStructure (
- ProcessorTopologyStructurePtr,
- *ProcessorTopologyStructureLength
- );
- break;
- default:
- IncrementErrorCount ();
- Print (
- L"ERROR: Unknown processor topology structure:"
- L" Type = %d, Length = %d\n",
- *ProcessorTopologyStructureType,
- *ProcessorTopologyStructureLength
- );
- }
+ // Parse the Processor Topology Structure
+ ParseAcpiStruct (
+ 2,
+ ProcessorTopologyStructurePtr,
+ &PpttDatabase,
+ Offset,
+ *ProcessorTopologyStructureType,
+ *ProcessorTopologyStructureLength,
+ NULL,
+ NULL
+ );
ProcessorTopologyStructurePtr += *ProcessorTopologyStructureLength;
Offset += *ProcessorTopologyStructureLength;
} // while
+
+ // Report and validate processor topology structure counts
+ if (GetConsistencyChecking ()) {
+ ValidateAcpiStructCounts (&PpttDatabase);
+ }
}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.h
index 2a671203fb0035bbc407ff4bb0ca9960706fa588..a0b0622ba00bda63379b670527145359b738bb7d 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.h
@@ -1,7 +1,7 @@
/** @file
Header file for PPTT parser
- Copyright (c) 2019, ARM Limited. All rights reserved.
+ Copyright (c) 2019 - 2020, ARM Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
@par Reference(s):
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
prev parent reply other threads:[~2020-05-05 15:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-05 15:45 [PATCH v1 0/6] ShellPkg: acpiview: Refactor ACPI table parsing loops Krzysztof Koch
2020-05-05 15:45 ` [PATCH v1 1/6] ShellPkg: acpiview: Add interface for data-driven table parsing Krzysztof Koch
2020-06-11 7:42 ` Gao, Zhichao
2020-06-11 11:49 ` [edk2-devel] " Tomas Pilar (tpilar)
2020-05-05 15:46 ` [PATCH v1 2/6] ShellPkg: acpiview: Make MADT parsing logic data driven Krzysztof Koch
2020-05-05 15:46 ` [PATCH v1 3/6] ShellPkg: acpiview: Make SRAT " Krzysztof Koch
2020-05-05 15:46 ` [PATCH v1 4/6] ShellPkg: acpiview: Make GTDT " Krzysztof Koch
2020-06-11 7:46 ` Gao, Zhichao
2020-05-05 15:46 ` [PATCH v1 5/6] ShellPkg: acpiview: Make IORT " Krzysztof Koch
2020-05-05 15:46 ` Krzysztof Koch [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200505154604.9848-7-krzysztof.koch@arm.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox