summaryrefslogtreecommitdiffstats
path: root/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2018-04-20 16:08:22 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2018-04-23 17:52:44 +0800
commitee4dc24f57c32a445e7c747396c9bfbd8b221568 (patch)
treea332a4c461762cf555bc62b4eb9930f1bb4888fa /ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
parent8b5c80e0296c7050348a6a89f2cef66190c6141d (diff)
downloadedk2-ee4dc24f57c32a445e7c747396c9bfbd8b221568.tar.gz
edk2-ee4dc24f57c32a445e7c747396c9bfbd8b221568.tar.bz2
edk2-ee4dc24f57c32a445e7c747396c9bfbd8b221568.zip
ShellPkg: Add acpiview tool to dump ACPI tables
This program is provided to allow examination of ACPI table contents from the UEFI Shell. This can help with investigations, especially at that stage where the tables are not enabling an OS to boot. The program is not exhaustive, and only encapsulates detailed knowledge of a limited number of table types. Default behaviour is to display the content of all tables installed. 'Known' table types will be parsed and displayed with descriptions and field values. Where appropriate a degree of consistency checking is done and errors may be reported in the output. Other table types will be displayed as an array of Hexadecimal bytes. To facilitate debugging, the -s and -d options can be used to generate a binary file image of a table that can be copied elsewhere for investigation using tools such as those provided by acpica.org. This is especially relevant for AML type tables like DSDT and SSDT. The inspiration for this is the existing smbiosview Debug1 Shell command. Many tables are not explicitly handled, in part because no examples are available for our testing. The program is designed to be extended to new tables with minimal effort, and contributions are invited. Change-Id: Ifa23dc80ab8ab042c56e88424847e796a8122a7c Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Signed-off-by: Evan Lloyd <evan.lloyd@arm.com> Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Signed-off-by: Evan Lloyd <evan.lloyd@arm.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com> Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Diffstat (limited to 'ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c')
-rw-r--r--ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c330
1 files changed, 330 insertions, 0 deletions
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
new file mode 100644
index 0000000000..86da55935c
--- /dev/null
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
@@ -0,0 +1,330 @@
+/**
+ SRAT table parser
+
+ Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ @par Reference(s):
+ - ACPI 6.2 Specification - Errata A, September 2017
+**/
+
+#include <IndustryStandard/Acpi.h>
+#include <Library/PrintLib.h>
+#include <Library/UefiLib.h>
+#include "AcpiParser.h"
+#include "AcpiTableParser.h"
+
+// Local Variables
+STATIC CONST UINT8* SratRAType;
+STATIC CONST UINT8* SratRALength;
+STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
+
+/** This function validates the Reserved field in the SRAT table header.
+
+ @param [in] Ptr Pointer to the start of the field data.
+ @param [in] Context Pointer to context specific information e.g. this
+ could be a pointer to the ACPI table header.
+*/
+STATIC
+VOID
+EFIAPI
+ValidateSratReserved (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ );
+
+/** This function traces the APIC Proximity Domain field.
+
+ @param [in] Format Format string for tracing the data.
+ @param [in] Ptr Pointer to the start of the buffer.
+*/
+STATIC
+VOID
+DumpSratApicProximity (
+ IN CONST CHAR16* Format,
+ IN UINT8* Ptr
+ );
+
+/** An ACPI_PARSER array describing the SRAT Table.
+*/
+STATIC CONST ACPI_PARSER SratParser[] = {
+ PARSE_ACPI_HEADER (&AcpiHdrInfo),
+ {L"Reserved", 4, 36, L"0x%x", NULL, NULL, ValidateSratReserved, NULL},
+ {L"Reserved", 8, 40, L"0x%lx", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the Resource Allocation
+ structure header.
+*/
+STATIC CONST ACPI_PARSER SratResourceAllocationParser[] = {
+ {L"Type", 1, 0, NULL, NULL, (VOID**)&SratRAType, NULL, NULL},
+ {L"Length", 1, 1, NULL, NULL, (VOID**)&SratRALength, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the GICC Affinity structure.
+*/
+STATIC CONST ACPI_PARSER SratGicCAffinityParser[] = {
+ {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"Proximity Domain", 4, 2, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"ACPI Processor UID", 4, 6, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Flags", 4, 10, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Clock Domain", 4, 14, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the GIC ITS Affinity structure.
+*/
+STATIC CONST ACPI_PARSER SratGicITSAffinityParser[] = {
+ {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"Proximity Domain", 4, 2, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Reserved", 2, 6, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"ITS Id", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},
+};
+
+/** An ACPI_PARSER array describing the Memory Affinity structure.
+*/
+STATIC CONST ACPI_PARSER SratMemAffinityParser[] = {
+ {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"Proximity Domain", 4, 2, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Reserved", 2, 6, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Base Address Low", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Base Address High", 4, 12, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Length Low", 4, 16, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Length High", 4, 20, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Reserved", 4, 24, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Flags", 4, 28, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Reserved", 8, 32, L"0x%lx", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the APIC/SAPIC Affinity structure.
+*/
+STATIC CONST ACPI_PARSER SratApciSapicAffinityParser[] = {
+ {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"Proximity Domain [7:0]", 1, 2, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"APIC ID", 1, 3, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Flags", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Local SAPIC EID", 1, 8, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Proximity Domain [31:8]", 3, 9, L"0x%x", DumpSratApicProximity,
+ NULL, NULL, NULL},
+ {L"Clock Domain", 4, 12, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the Processor Local x2APIC
+ Affinity structure.
+*/
+STATIC CONST ACPI_PARSER SratX2ApciAffinityParser[] = {
+ {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Proximity Domain", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"X2APIC ID", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Flags", 4, 12, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Clock Domain", 4, 16, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Reserved", 4, 20, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** This function validates the Reserved field in the SRAT table header.
+
+ @param [in] Ptr Pointer to the start of the field data.
+ @param [in] Context Pointer to context specific information e.g. this
+ could be a pointer to the ACPI table header.
+*/
+STATIC
+VOID
+EFIAPI
+ValidateSratReserved (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ )
+{
+ if (*(UINT32*)Ptr != 1) {
+ IncrementErrorCount ();
+ Print (L"\nERROR: Reserved should be 1 for backward compatibility.\n");
+ }
+}
+
+/** This function traces the APIC Proximity Domain field.
+
+ @param [in] Format Format string for tracing the data.
+ @param [in] Ptr Pointer to the start of the buffer.
+*/
+STATIC
+VOID
+DumpSratApicProximity (
+ IN CONST CHAR16* Format,
+ IN UINT8* Ptr
+ )
+{
+ UINT32 ProximityDomain = Ptr[0] | (Ptr[1] << 8) | (Ptr[2] << 16);
+ Print (Format, ProximityDomain);
+}
+
+/** This function parses the ACPI SRAT table.
+ When trace is enabled this function parses the SRAT table and
+ traces the ACPI table fields.
+
+ This function parses the following Resource Allocation Structures:
+ - Processor Local APIC/SAPIC Affinity Structure
+ - Memory Affinity Structure
+ - Processor Local x2APIC Affinity Structure
+ - GICC Affinity Structure
+
+ This function also performs validation of the ACPI table fields.
+
+ @param [in] Trace If TRUE, trace the ACPI fields.
+ @param [in] Ptr Pointer to the start of the buffer.
+ @param [in] AcpiTableLength Length of the ACPI table.
+ @param [in] AcpiTableRevision Revision of the ACPI table.
+*/
+VOID
+EFIAPI
+ParseAcpiSrat (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ UINT32 Offset;
+ UINT8* ResourcePtr;
+ UINT32 GicCAffinityIndex = 0;
+ UINT32 GicITSAffinityIndex = 0;
+ UINT32 MemoryAffinityIndex = 0;
+ UINT32 ApicSapicAffinityIndex = 0;
+ UINT32 X2ApicAffinityIndex = 0;
+ CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi
+
+ if (!Trace) {
+ return;
+ }
+
+ Offset = ParseAcpi (
+ TRUE,
+ 0,
+ "SRAT",
+ Ptr,
+ AcpiTableLength,
+ PARSER_PARAMS (SratParser)
+ );
+ ResourcePtr = Ptr + Offset;
+
+ while (Offset < AcpiTableLength) {
+ ParseAcpi (
+ FALSE,
+ 0,
+ NULL,
+ ResourcePtr,
+ 2, // The length is 1 byte at offset 1
+ PARSER_PARAMS (SratResourceAllocationParser)
+ );
+
+ switch (*SratRAType) {
+ case EFI_ACPI_6_2_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_2_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_2_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_2_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_2_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;
+ }
+
+ ResourcePtr += (*SratRALength);
+ Offset += (*SratRALength);
+ }
+}