public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
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 3/6] ShellPkg: acpiview: Make SRAT parsing logic data driven
Date: Tue, 5 May 2020 16:46:01 +0100	[thread overview]
Message-ID: <20200505154604.9848-4-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
Static Resource Allocation Structure given should be parsed.

Print the offset of each Static Resource Allocation Structure from the
start of the table.

Consolidate all metadata about each Static Resource Allocation
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 the System
Resource Affinity Table (SRAT).

Count the number of instances of each Static Resource Allocation
Structure type. Optionally report these counts after SRAT table parsing
is finished and validate that Advanced Programmable Interrupt Controller
(APIC) structures are not present on Arm-based platforms.

References:
- ACPI 6.3 Specification - January 2019, Section 5.2.16

Signed-off-by: Krzysztof Koch <krzysztof.koch@arm.com>
---

Notes:
    v1:
    - Make SRAT parsing logic data driven [Krzysztof]

 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c | 204 ++++++++------------
 1 file changed, 77 insertions(+), 127 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
index 6f66be68cc0bed14811a0432c61a79fd47c54890..8ec233a52861b039979bb8291b3c90193acd86fa 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
@@ -13,6 +13,7 @@
 #include <Library/UefiLib.h>
 #include "AcpiParser.h"
 #include "AcpiTableParser.h"
+#include "AcpiView.h"
 
 // Local Variables
 STATIC CONST UINT8* SratRAType;
@@ -330,6 +331,57 @@ STATIC CONST ACPI_PARSER SratX2ApciAffinityParser[] = {
   {L"Reserved", 4, 20, L"0x%x", NULL, NULL, NULL, NULL}
 };
 
+/**
+  Information about each Static Resource Allocation Structure type.
+**/
+STATIC ACPI_STRUCT_INFO SratStructs[] = {
+  ADD_ACPI_STRUCT_INFO_ARRAY (
+    "Processor Local APIC/SAPIC Affinity",
+    EFI_ACPI_6_3_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY,
+    ARCH_COMPAT_IA32 | ARCH_COMPAT_X64,
+    SratApciSapicAffinityParser
+    ),
+  ADD_ACPI_STRUCT_INFO_ARRAY (
+    "Memory Affinity",
+    EFI_ACPI_6_3_MEMORY_AFFINITY,
+    ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 | ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64,
+    SratMemAffinityParser
+    ),
+  ADD_ACPI_STRUCT_INFO_ARRAY (
+    "Processor Local x2APIC Affinity",
+    EFI_ACPI_6_3_PROCESSOR_LOCAL_X2APIC_AFFINITY,
+    ARCH_COMPAT_IA32 | ARCH_COMPAT_X64,
+    SratX2ApciAffinityParser
+    ),
+  ADD_ACPI_STRUCT_INFO_ARRAY (
+    "GICC Affinity Structure",
+    EFI_ACPI_6_3_GICC_AFFINITY,
+    ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64,
+    SratGicCAffinityParser
+    ),
+  ADD_ACPI_STRUCT_INFO_ARRAY (
+    "GIC ITS Affinity",
+    EFI_ACPI_6_3_GIC_ITS_AFFINITY,
+    ARCH_COMPAT_ARM | ARCH_COMPAT_AARCH64,
+    SratGicITSAffinityParser
+    ),
+  ADD_ACPI_STRUCT_INFO_ARRAY (
+    "Generic Initiator Affinity",
+    EFI_ACPI_6_3_GENERIC_INITIATOR_AFFINITY,
+    ARCH_COMPAT_IA32 | ARCH_COMPAT_X64 | ARCH_COMPAT_ARM |ARCH_COMPAT_AARCH64,
+    SratGenericInitiatorAffinityParser
+    )
+};
+
+/**
+  SRAT structure database
+**/
+STATIC ACPI_STRUCT_DATABASE SratDatabase = {
+  "Static Resource Allocation Structure",
+  SratStructs,
+  ARRAY_SIZE (SratStructs)
+};
+
 /**
   This function parses the ACPI SRAT table.
   When trace is enabled this function parses the SRAT table and
@@ -357,27 +409,15 @@ ParseAcpiSrat (
   IN UINT8   AcpiTableRevision
   )
 {
-  UINT32 Offset;
-  UINT8* ResourcePtr;
-  UINT32 GicCAffinityIndex;
-  UINT32 GicITSAffinityIndex;
-  UINT32 GenericInitiatorAffinityIndex;
-  UINT32 MemoryAffinityIndex;
-  UINT32 ApicSapicAffinityIndex;
-  UINT32 X2ApicAffinityIndex;
-  CHAR8  Buffer[80];  // Used for AsciiName param of ParseAcpi
-
-  GicCAffinityIndex = 0;
-  GicITSAffinityIndex = 0;
-  GenericInitiatorAffinityIndex = 0;
-  MemoryAffinityIndex = 0;
-  ApicSapicAffinityIndex = 0;
-  X2ApicAffinityIndex = 0;
+  UINT32                      Offset;
+  UINT8*                      ResourcePtr;
 
   if (!Trace) {
     return;
   }
 
+  ResetAcpiStructCounts (&SratDatabase);
+
   Offset = ParseAcpi (
              TRUE,
              0,
@@ -406,7 +446,8 @@ ParseAcpiSrat (
       IncrementErrorCount ();
       Print (
         L"ERROR: Insufficient remaining table buffer length to read the " \
-          L"Static Resource Allocation structure header. Length = %d.\n",
+          L"%a header. Length = %d.\n",
+        SratDatabase.Name,
         AcpiTableLength - Offset
         );
       return;
@@ -417,8 +458,9 @@ ParseAcpiSrat (
         ((Offset + (*SratRALength)) > AcpiTableLength)) {
       IncrementErrorCount ();
       Print (
-        L"ERROR: Invalid Static Resource Allocation Structure length. " \
-          L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
+        L"ERROR: Invalid %a length. Length = %d. Offset = %d. " \
+          L"AcpiTableLength = %d.\n",
+        SratDatabase.Name,
         *SratRALength,
         Offset,
         AcpiTableLength
@@ -426,116 +468,24 @@ ParseAcpiSrat (
       return;
     }
 
-    switch (*SratRAType) {
-      case EFI_ACPI_6_3_GICC_AFFINITY:
-        AsciiSPrint (
-          Buffer,
-          sizeof (Buffer),
-          "GICC Affinity Structure [%d]",
-          GicCAffinityIndex++
-          );
-        ParseAcpi (
-          TRUE,
-          2,
-          Buffer,
-          ResourcePtr,
-          *SratRALength,
-          PARSER_PARAMS (SratGicCAffinityParser)
-          );
-        break;
-
-      case EFI_ACPI_6_3_GIC_ITS_AFFINITY:
-        AsciiSPrint (
-          Buffer,
-          sizeof (Buffer),
-          "GIC ITS Affinity Structure [%d]",
-          GicITSAffinityIndex++
-        );
-        ParseAcpi (
-          TRUE,
-          2,
-          Buffer,
-          ResourcePtr,
-          *SratRALength,
-          PARSER_PARAMS (SratGicITSAffinityParser)
-          );
-        break;
-
-      case EFI_ACPI_6_3_GENERIC_INITIATOR_AFFINITY:
-        AsciiSPrint (
-          Buffer,
-          sizeof (Buffer),
-          "Generic Initiator Affinity Structure [%d]",
-          GenericInitiatorAffinityIndex++
-        );
-        ParseAcpi (
-          TRUE,
-          2,
-          Buffer,
-          ResourcePtr,
-          *SratRALength,
-          PARSER_PARAMS (SratGenericInitiatorAffinityParser)
-        );
-        break;
-
-      case EFI_ACPI_6_3_MEMORY_AFFINITY:
-        AsciiSPrint (
-          Buffer,
-          sizeof (Buffer),
-          "Memory Affinity Structure [%d]",
-          MemoryAffinityIndex++
-          );
-        ParseAcpi (
-          TRUE,
-          2,
-          Buffer,
-          ResourcePtr,
-          *SratRALength,
-          PARSER_PARAMS (SratMemAffinityParser)
-          );
-        break;
-
-      case EFI_ACPI_6_3_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY:
-        AsciiSPrint (
-          Buffer,
-          sizeof (Buffer),
-          "APIC/SAPIC Affinity Structure [%d]",
-          ApicSapicAffinityIndex++
-          );
-        ParseAcpi (
-          TRUE,
-          2,
-          Buffer,
-          ResourcePtr,
-          *SratRALength,
-          PARSER_PARAMS (SratApciSapicAffinityParser)
-          );
-        break;
-
-      case EFI_ACPI_6_3_PROCESSOR_LOCAL_X2APIC_AFFINITY:
-        AsciiSPrint (
-          Buffer,
-          sizeof (Buffer),
-          "X2APIC Affinity Structure [%d]",
-          X2ApicAffinityIndex++
-          );
-        ParseAcpi (
-          TRUE,
-          2,
-          Buffer,
-          ResourcePtr,
-          *SratRALength,
-          PARSER_PARAMS (SratX2ApciAffinityParser)
-          );
-        break;
-
-      default:
-        IncrementErrorCount ();
-        Print (L"ERROR: Unknown SRAT Affinity type = 0x%x\n", *SratRAType);
-        break;
-    }
+    // Parse the Static Resource Allocation Structure
+    ParseAcpiStruct (
+      2,
+      ResourcePtr,
+      &SratDatabase,
+      Offset,
+      *SratRAType,
+      *SratRALength,
+      NULL,
+      NULL
+      );
 
     ResourcePtr += (*SratRALength);
     Offset += (*SratRALength);
   }
+
+  // Report and validate Static Resource Allocation Structure counts
+  if (GetConsistencyChecking ()) {
+    ValidateAcpiStructCounts (&SratDatabase);
+  }
 }
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


  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 ` Krzysztof Koch [this message]
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 ` [PATCH v1 6/6] ShellPkg: acpiview: Make PPTT " Krzysztof Koch

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-4-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