diff options
author | Ruiyu Ni <ruiyu.ni@intel.com> | 2018-04-20 16:08:22 +0800 |
---|---|---|
committer | Ruiyu Ni <ruiyu.ni@intel.com> | 2018-04-23 17:52:44 +0800 |
commit | ee4dc24f57c32a445e7c747396c9bfbd8b221568 (patch) | |
tree | a332a4c461762cf555bc62b4eb9930f1bb4888fa /ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers | |
parent | 8b5c80e0296c7050348a6a89f2cef66190c6141d (diff) | |
download | edk2-ee4dc24f57c32a445e7c747396c9bfbd8b221568.zip edk2-ee4dc24f57c32a445e7c747396c9bfbd8b221568.tar.gz edk2-ee4dc24f57c32a445e7c747396c9bfbd8b221568.tar.bz2 |
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')
14 files changed, 3028 insertions, 0 deletions
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Bgrt/BgrtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Bgrt/BgrtParser.c new file mode 100644 index 0000000..0b3f9a7 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Bgrt/BgrtParser.c @@ -0,0 +1,69 @@ +/**
+ BGRT table parser
+
+ Copyright (c) 2017 - 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/UefiLib.h>
+#include "AcpiParser.h"
+#include "AcpiTableParser.h"
+
+// Local variables
+STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
+
+/** An ACPI_PARSER array describing the ACPI BDRT Table.
+*/
+STATIC CONST ACPI_PARSER BgrtParser[] = {
+ PARSE_ACPI_HEADER (&AcpiHdrInfo),
+ {L"Version", 2, 36, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Status", 1, 38, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Image Type", 1, 39, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Image Address", 8, 40, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Image Offset X", 4, 48, L"%d", NULL, NULL, NULL, NULL},
+ {L"Image Offset Y", 4, 52, L"%d", NULL, NULL, NULL, NULL}
+};
+
+/** This function parses the ACPI BGRT table.
+ When trace is enabled this function parses the BGRT table and
+ traces the ACPI table fields.
+
+ 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
+ParseAcpiBgrt (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ if (!Trace) {
+ return;
+ }
+
+ ParseAcpi (
+ Trace,
+ 0,
+ "BGRT",
+ Ptr,
+ AcpiTableLength,
+ PARSER_PARAMS (BgrtParser)
+ );
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c new file mode 100644 index 0000000..f70a132 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c @@ -0,0 +1,242 @@ +/**
+ DBG2 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):
+ - Microsoft Debug Port Table 2 (DBG2) Specification - December 10, 2015.
+**/
+
+#include <IndustryStandard/DebugPort2Table.h>
+#include <Library/UefiLib.h>
+#include "AcpiParser.h"
+#include "AcpiTableParser.h"
+
+// Local variables pointing to the table fields
+STATIC CONST UINT32* OffsetDbgDeviceInfo;
+STATIC CONST UINT32* NumberDbgDeviceInfo;
+STATIC CONST UINT16* DbgDevInfoLen;
+STATIC CONST UINT8* GasCount;
+STATIC CONST UINT16* NameSpaceStringLength;
+STATIC CONST UINT16* NameSpaceStringOffset;
+STATIC CONST UINT16* OEMDataLength;
+STATIC CONST UINT16* OEMDataOffset;
+STATIC CONST UINT16* BaseAddrRegOffset;
+STATIC CONST UINT16* AddrSizeOffset;
+STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
+
+/** This function Validates the NameSpace string length.
+
+ @param [in] Ptr Pointer to the start of the buffer.
+ @param [in] Context Pointer to context specific information e.g. this
+ could be a pointer to the ACPI table header.
+*/
+STATIC
+VOID
+EFIAPI
+ValidateNameSpaceStrLen (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ );
+
+/** This function parses the debug device information structure.
+
+ @param [in] Ptr Pointer to the start of the buffer.
+ @param [out] Length Pointer in which the length of the debug
+ device information is returned.
+*/
+STATIC
+VOID
+EFIAPI
+DumpDbgDeviceInfo (
+ IN UINT8* Ptr,
+ OUT UINT32* Length
+ );
+
+/// An ACPI_PARSER array describing the ACPI DBG2 table.
+STATIC CONST ACPI_PARSER Dbg2Parser[] = {
+ PARSE_ACPI_HEADER (&AcpiHdrInfo),
+ {L"OffsetDbgDeviceInfo", 4, 36, L"0x%x", NULL,
+ (VOID**)&OffsetDbgDeviceInfo, NULL, NULL},
+ {L"NumberDbgDeviceInfo", 4, 40, L"%d", NULL,
+ (VOID**)&NumberDbgDeviceInfo, NULL, NULL}
+};
+
+/// An ACPI_PARSER array describing the debug device information.
+STATIC CONST ACPI_PARSER DbgDevInfoParser[] = {
+ {L"Revision", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Length", 2, 1, L"%d", NULL, (VOID**)&DbgDevInfoLen, NULL, NULL},
+
+ {L"Generic Address Registers Count", 1, 3, L"0x%x", NULL,
+ (VOID**)&GasCount, NULL, NULL},
+ {L"NameSpace String Length", 2, 4, L"%d", NULL,
+ (VOID**)&NameSpaceStringLength, ValidateNameSpaceStrLen, NULL},
+ {L"NameSpace String Offset", 2, 6, L"0x%x", NULL,
+ (VOID**)&NameSpaceStringOffset, NULL, NULL},
+ {L"OEM Data Length", 2, 8, L"%d", NULL, (VOID**)&OEMDataLength,
+ NULL, NULL},
+ {L"OEM Data Offset", 2, 10, L"0x%x", NULL, (VOID**)&OEMDataOffset,
+ NULL, NULL},
+
+ {L"Port Type", 2, 12, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Port SubType", 2, 14, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Reserved", 2, 16, L"%x", NULL, NULL, NULL, NULL},
+
+ {L"Base Address Register Offset", 2, 18, L"0x%x", NULL,
+ (VOID**)&BaseAddrRegOffset, NULL, NULL},
+ {L"Address Size Offset", 2, 20, L"0x%x", NULL,
+ (VOID**)&AddrSizeOffset, NULL, NULL}
+};
+
+/** This function validates the NameSpace string length.
+
+ @param [in] Ptr Pointer to the start of the buffer.
+ @param [in] Context Pointer to context specific information e.g. this
+ could be a pointer to the ACPI table header.
+*/
+STATIC
+VOID
+EFIAPI
+ValidateNameSpaceStrLen (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ )
+{
+ UINT16 NameSpaceStrLen = *(UINT16*)Ptr;
+ if (NameSpaceStrLen < 2) {
+ IncrementErrorCount ();
+ Print (
+ L"\nERROR: NamespaceString Length = %d. If no Namespace device exists,\n"
+ " then NamespaceString[] must contain a period '.'",
+ NameSpaceStrLen
+ );
+ }
+}
+
+/** This function parses the debug device information structure.
+
+ @param [in] Ptr Pointer to the start of the buffer.
+ @param [out] Ptr Pointer in which the length of the debug
+ device information is returned.
+*/
+STATIC
+VOID
+EFIAPI
+DumpDbgDeviceInfo (
+ IN UINT8* Ptr,
+ OUT UINT32* Length
+ )
+{
+ UINT16 Index;
+ UINT8* DataPtr;
+ UINT32* AddrSize;
+
+ // Parse the debug device info to get the Length
+ ParseAcpi (
+ FALSE,
+ 0,
+ "Debug Device Info",
+ Ptr,
+ 3, // Length is 2 bytes starting at offset 1
+ PARSER_PARAMS (DbgDevInfoParser)
+ );
+
+ ParseAcpi (
+ TRUE,
+ 2,
+ "Debug Device Info",
+ Ptr,
+ *DbgDevInfoLen,
+ PARSER_PARAMS (DbgDevInfoParser)
+ );
+
+ // GAS and Address Size
+ Index = 0;
+ DataPtr = Ptr + (*BaseAddrRegOffset);
+ AddrSize = (UINT32*)(Ptr + (*AddrSizeOffset));
+ while (Index < (*GasCount)) {
+ PrintFieldName (4, L"BaseAddressRegister");
+ DumpGasStruct (DataPtr, 4);
+ PrintFieldName (4, L"Address Size");
+ Print (L"0x%x\n", AddrSize[Index]);
+ DataPtr += GAS_LENGTH;
+ Index++;
+ }
+
+ // NameSpace String
+ Index = 0;
+ DataPtr = Ptr + (*NameSpaceStringOffset);
+ PrintFieldName (4, L"NameSpace String");
+ while (Index < (*NameSpaceStringLength)) {
+ Print (L"%c", DataPtr[Index++]);
+ }
+ Print (L"\n");
+
+ // OEM Data
+ Index = 0;
+ DataPtr = Ptr + (*OEMDataOffset);
+ PrintFieldName (4, L"OEM Data");
+ while (Index < (*OEMDataLength)) {
+ Print (L"%x ", DataPtr[Index++]);
+ if ((Index & 7) == 0) {
+ Print (L"\n%-*s ", OUTPUT_FIELD_COLUMN_WIDTH, L"");
+ }
+ }
+
+ *Length = *DbgDevInfoLen;
+}
+
+/** This function parses the ACPI DBG2 table.
+ When trace is enabled this function parses the DBG2 table and
+ traces the ACPI table fields.
+
+ 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
+ParseAcpiDbg2 (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ UINT32 Offset;
+ UINT32 DbgDeviceInfoLength;
+ UINT8* DevInfoPtr;
+
+ if (!Trace) {
+ return;
+ }
+
+ Offset = ParseAcpi (
+ TRUE,
+ 0,
+ "DBG2",
+ Ptr,
+ AcpiTableLength,
+ PARSER_PARAMS (Dbg2Parser)
+ );
+ DevInfoPtr = Ptr + Offset;
+
+ while (Offset < AcpiTableLength) {
+ DumpDbgDeviceInfo (
+ DevInfoPtr,
+ &DbgDeviceInfoLength
+ );
+ Offset += DbgDeviceInfoLength;
+ DevInfoPtr += DbgDeviceInfoLength;
+ }
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dsdt/DsdtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dsdt/DsdtParser.c new file mode 100644 index 0000000..ef459a1 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dsdt/DsdtParser.c @@ -0,0 +1,47 @@ +/**
+ DSDT 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/UefiLib.h>
+#include "AcpiParser.h"
+#include "AcpiTableParser.h"
+
+/** This function parses the ACPI DSDT table.
+ When trace is enabled this function parses the DSDT table and
+ traces the ACPI table fields.
+ For the DSDT table only the ACPI header fields are parsed and
+ traced.
+
+ @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
+ParseAcpiDsdt (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ if (!Trace) {
+ return;
+ }
+
+ DumpAcpiHeader (Ptr);
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c new file mode 100644 index 0000000..fdccb2a --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Fadt/FadtParser.c @@ -0,0 +1,261 @@ +/**
+ FADT 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/UefiLib.h>
+#include "AcpiParser.h"
+#include "AcpiTableParser.h"
+
+// Local variables
+STATIC CONST UINT32* DsdtAddress;
+STATIC CONST UINT64* X_DsdtAddress;
+STATIC CONST UINT8* FadtMinorRevision;
+STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
+
+/** A macro defining the Hardware reduced ACPI flag
+*/
+#define HW_REDUCED_ACPI BIT20
+
+// Forward declarations
+CONST ACPI_DESCRIPTION_HEADER_INFO* CONST
+EFIAPI
+GetAcpiXsdtHeaderInfo (
+ VOID
+);
+
+STATIC
+VOID
+EFIAPI
+ValidateFirmwareCtrl (
+ IN UINT8* Ptr,
+ IN VOID* Context
+);
+
+STATIC
+VOID
+EFIAPI
+ValidateXFirmwareCtrl (
+ IN UINT8* Ptr,
+ IN VOID* Context
+);
+
+STATIC
+VOID
+EFIAPI
+ValidateFlags (
+ IN UINT8* Ptr,
+ IN VOID* Context
+);
+
+/** An ACPI_PARSER array describing the ACPI FADT Table.
+*/
+STATIC CONST ACPI_PARSER FadtParser[] = {
+ PARSE_ACPI_HEADER (&AcpiHdrInfo),
+ {L"FIRMWARE_CTRL", 4, 36, L"0x%x", NULL, NULL, ValidateFirmwareCtrl, NULL},
+ {L"DSDT", 4, 40, L"0x%x", NULL, (VOID**)&DsdtAddress, NULL, NULL},
+ {L"Reserved", 1, 44, L"%x", NULL, NULL, NULL, NULL},
+ {L"Preferred_PM_Profile", 1, 45, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"SCI_INT", 2, 46, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"SMI_CMD", 4, 48, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"ACPI_ENABLE", 1, 52, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"ACPI_DISABLE", 1, 53, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"S4BIOS_REQ", 1, 54, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PSTATE_CNT", 1, 55, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PM1a_EVT_BLK", 4, 56, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PM1b_EVT_BLK", 4, 60, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PM1a_CNT_BLK", 4, 64, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PM1b_CNT_BLK", 4, 68, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PM2_CNT_BLK", 4, 72, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PM_TMR_BLK", 4, 76, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"GPE0_BLK", 4, 80, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"GPE1_BLK", 4, 84, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PM1_EVT_LEN", 1, 88, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PM1_CNT_LEN", 1, 89, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PM2_CNT_LEN", 1, 90, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PM_TMR_LEN", 1, 91, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"GPE0_BLK_LEN", 1, 92, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"GPE1_BLK_LEN", 1, 93, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"GPE1_BASE", 1, 94, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"CST_CNT", 1, 95, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"P_LVL2_LAT", 2, 96, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"P_LVL3_LAT", 2, 98, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"FLUSH_SIZE", 2, 100, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"FLUSH_STRIDE", 2, 102, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"DUTY_OFFSET", 1, 104, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"DUTY_WIDTH", 1, 105, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"DAY_ALRM", 1, 106, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"MON_ALRM", 1, 107, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"CENTURY", 1, 108, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"IAPC_BOOT_ARCH", 2, 109, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Reserved", 1, 111, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Flags", 4, 112, L"0x%x", NULL, NULL, ValidateFlags, NULL},
+ {L"RESET_REG", 12, 116, NULL, DumpGas, NULL, NULL, NULL},
+ {L"RESET_VALUE", 1, 128, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"ARM_BOOT_ARCH", 2, 129, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"FADT Minor Version", 1, 131, L"0x%x", NULL, (VOID**)&FadtMinorRevision,
+ NULL, NULL},
+ {L"X_FIRMWARE_CTRL", 8, 132, L"0x%lx", NULL, NULL,
+ ValidateXFirmwareCtrl, NULL},
+ {L"X_DSDT", 8, 140, L"0x%lx", NULL, (VOID**)&X_DsdtAddress, NULL, NULL},
+ {L"X_PM1a_EVT_BLK", 12, 148, NULL, DumpGas, NULL, NULL, NULL},
+ {L"X_PM1b_EVT_BLK", 12, 160, NULL, DumpGas, NULL, NULL, NULL},
+ {L"X_PM1a_CNT_BLK", 12, 172, NULL, DumpGas, NULL, NULL, NULL},
+ {L"X_PM1b_CNT_BLK", 12, 184, NULL, DumpGas, NULL, NULL, NULL},
+ {L"X_PM2_CNT_BLK", 12, 196, NULL, DumpGas, NULL, NULL, NULL},
+ {L"X_PM_TMR_BLK", 12, 208, NULL, DumpGas, NULL, NULL, NULL},
+ {L"X_GPE0_BLK", 12, 220, NULL, DumpGas, NULL, NULL, NULL},
+ {L"X_GPE1_BLK", 12, 232, NULL, DumpGas, NULL, NULL, NULL},
+ {L"SLEEP_CONTROL_REG", 12, 244, NULL, DumpGas, NULL, NULL, NULL},
+ {L"SLEEP_STATUS_REG", 12, 256, NULL, DumpGas, NULL, NULL, NULL},
+ {L"Hypervisor VendorIdentity", 8, 268, L"%lx", NULL, NULL, NULL, NULL}
+};
+
+/** This function validates the Firmware Control Field.
+
+ @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
+ValidateFirmwareCtrl (
+ IN UINT8* Ptr,
+ IN VOID* Context
+)
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+ if (*(UINT32*)Ptr != 0) {
+ IncrementErrorCount ();
+ Print (
+ L"\nERROR: Firmware Control must be zero for ARM platforms."
+ );
+ }
+#endif
+}
+
+/** This function validates the X_Firmware Control Field.
+
+ @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
+ValidateXFirmwareCtrl (
+ IN UINT8* Ptr,
+ IN VOID* Context
+)
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+ if (*(UINT64*)Ptr != 0) {
+ IncrementErrorCount ();
+ Print (
+ L"\nERROR: X Firmware Control must be zero for ARM platforms."
+ );
+ }
+#endif
+}
+
+/** This function validates the flags.
+
+ @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
+ValidateFlags (
+ IN UINT8* Ptr,
+ IN VOID* Context
+)
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+ if (((*(UINT32*)Ptr) & HW_REDUCED_ACPI) == 0) {
+ IncrementErrorCount ();
+ Print (
+ L"\nERROR: HW_REDUCED_ACPI flag must be set for ARM platforms."
+ );
+ }
+#endif
+}
+
+/** This function parses the ACPI FADT table.
+ This function parses the FADT table and optionally traces the ACPI
+ table fields.
+
+ 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
+ParseAcpiFadt (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ UINT8* DsdtPtr;
+
+ ParseAcpi (
+ Trace,
+ 0,
+ "FADT",
+ Ptr,
+ AcpiTableLength,
+ PARSER_PARAMS (FadtParser)
+ );
+
+ if (Trace) {
+ Print (L"\nSummary:\n");
+ PrintFieldName (2, L"FADT Version");
+ Print (L"%d.%d\n", *AcpiHdrInfo.Revision, *FadtMinorRevision);
+
+ if (*GetAcpiXsdtHeaderInfo ()->OemTableId != *AcpiHdrInfo.OemTableId) {
+ IncrementErrorCount ();
+ Print (L"ERROR: OEM Table Id does not match with RSDT/XSDT.\n");
+ }
+ }
+
+ // If X_DSDT is not zero then use X_DSDT and ignore DSDT,
+ // else use DSDT.
+ if (*X_DsdtAddress != 0) {
+ DsdtPtr = (UINT8*)(UINTN)(*X_DsdtAddress);
+ } else if (*DsdtAddress != 0) {
+ DsdtPtr = (UINT8*)(UINTN)(*DsdtAddress);
+ } else {
+ // Both DSDT and X_DSDT cannot be zero.
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+ if (Trace) {
+ // The DSDT Table is mandatory for ARM systems
+ // as the CPU information MUST be presented in
+ // the DSDT.
+ IncrementErrorCount ();
+ Print (L"ERROR: Both X_DSDT and DSDT are NULL.\n");
+ }
+#endif
+ return;
+ }
+
+ ProcessAcpiTable (DsdtPtr);
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c new file mode 100644 index 0000000..ce96604 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c @@ -0,0 +1,293 @@ +/**
+ GTDT 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/UefiLib.h>
+#include "AcpiParser.h"
+#include "AcpiTableParser.h"
+
+// Local variables
+STATIC CONST UINT32* GtdtPlatformTimerCount;
+STATIC CONST UINT32* GtdtPlatformTimerOffset;
+STATIC CONST UINT8* PlatformTimerType;
+STATIC CONST UINT16* PlatformTimerLength;
+STATIC CONST UINT32* GtBlockTimerCount;
+STATIC CONST UINT32* GtBlockTimerOffset;
+STATIC CONST UINT16* GtBlockLength;
+STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
+
+/** This function validates the GT Block timer count.
+
+ @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
+ValidateGtBlockTimerCount (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ );
+
+/** An ACPI_PARSER array describing the ACPI GTDT Table.
+*/
+STATIC CONST ACPI_PARSER GtdtParser[] = {
+ PARSE_ACPI_HEADER (&AcpiHdrInfo),
+ {L"CntControlBase Physical Address", 8, 36, L"0x%lx", NULL, NULL,
+ NULL, NULL},
+ {L"Reserved", 4, 44, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Secure EL1 timer GSIV", 4, 48, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Secure EL1 timer FLAGS", 4, 52, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"Non-Secure EL1 timer GSIV", 4, 56, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Non-Secure EL1 timer FLAGS", 4, 60, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"Virtual timer GSIV", 4, 64, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Virtual timer FLAGS", 4, 68, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"Non-Secure EL2 timer GSIV", 4, 72, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Non-Secure EL2 timer FLAGS", 4, 76, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"CntReadBase Physical address", 8, 80, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Platform Timer Count", 4, 88, L"%d", NULL,
+ (VOID**)&GtdtPlatformTimerCount, NULL, NULL},
+ {L"Platform Timer Offset", 4, 92, L"0x%x", NULL,
+ (VOID**)&GtdtPlatformTimerOffset, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the Platform timer header.
+*/
+STATIC CONST ACPI_PARSER GtPlatformTimerHeaderParser[] = {
+ {L"Type", 1, 0, NULL, NULL, (VOID**)&PlatformTimerType, NULL, NULL},
+ {L"Length", 2, 1, NULL, NULL, (VOID**)&PlatformTimerLength, NULL, NULL},
+ {L"Reserved", 1, 3, NULL, NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the Platform GT Block.
+*/
+STATIC CONST ACPI_PARSER GtBlockParser[] = {
+ {L"Type", 1, 0, L"%d", NULL, NULL, NULL, NULL},
+ {L"Length", 2, 1, L"%d", NULL, (VOID**)&GtBlockLength, NULL, NULL},
+ {L"Reserved", 1, 3, L"%x", NULL, NULL, NULL, NULL},
+ {L"Physical address (CntCtlBase)", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Timer Count", 4, 12, L"%d", NULL, (VOID**)&GtBlockTimerCount,
+ ValidateGtBlockTimerCount, NULL},
+ {L"Timer Offset", 4, 16, L"%d", NULL, (VOID**)&GtBlockTimerOffset, NULL,
+ NULL}
+};
+
+/** An ACPI_PARSER array describing the GT Block timer.
+*/
+STATIC CONST ACPI_PARSER GtBlockTimerParser[] = {
+ {L"Frame Number", 1, 0, L"%d", NULL, NULL, NULL, NULL},
+ {L"Reserved", 3, 1, L"%x %x %x", Dump3Chars, NULL, NULL, NULL},
+ {L"Physical address (CntBaseX)", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Physical address (CntEL0BaseX)", 8, 12, L"0x%lx", NULL, NULL, NULL,
+ NULL},
+ {L"Physical Timer GSIV", 4, 20, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Physical Timer Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Virtual Timer GSIV", 4, 28, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Virtual Timer Flags", 4, 32, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Common Flags", 4, 36, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the Platform Watchdog.
+*/
+STATIC CONST ACPI_PARSER SBSAGenericWatchdogParser[] = {
+ {L"Type", 1, 0, L"%d", NULL, NULL, NULL, NULL},
+ {L"Length", 2, 1, L"%d", NULL, NULL, NULL, NULL},
+ {L"Reserved", 1, 3, L"%x", NULL, NULL, NULL, NULL},
+ {L"RefreshFrame Physical address", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"ControlFrame Physical address", 8, 12, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Watchdog Timer GSIV", 4, 20, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Watchdog Timer Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** This function validates the GT Block timer count.
+
+ @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
+ValidateGtBlockTimerCount (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ )
+{
+ UINT32 BlockTimerCount = *(UINT32*)Ptr;
+ if (BlockTimerCount > 8) {
+ IncrementErrorCount ();
+ Print (
+ L"\nERROR: Timer Count = %d. Max Timer Count is 8.",
+ BlockTimerCount
+ );
+ }
+}
+
+/** This function parses the Platform GT Block.
+
+ @param [in] Ptr Pointer to the start of the GT Block data.
+ @param [in] Length Length of the GT Block structure.
+*/
+STATIC
+VOID
+DumpGTBlock (
+ IN UINT8* Ptr,
+ IN UINT16 Length
+ )
+{
+ UINT32 Index;
+ UINT32 Offset;
+ UINT16 GTBlockTimerLength;
+
+ Offset = ParseAcpi (
+ TRUE,
+ 2,
+ "GT Block",
+ Ptr,
+ Length,
+ PARSER_PARAMS (GtBlockParser)
+ );
+ GTBlockTimerLength = (*GtBlockLength - Offset) / (*GtBlockTimerCount);
+ Length -= Offset;
+
+ if (*GtBlockTimerCount != 0) {
+ Ptr += (*GtBlockTimerOffset);
+ Index = 0;
+ while ((Index < (*GtBlockTimerCount)) && (Length >= GTBlockTimerLength)) {
+ Offset = ParseAcpi (
+ TRUE,
+ 2,
+ "GT Block Timer",
+ Ptr,
+ GTBlockTimerLength,
+ PARSER_PARAMS (GtBlockTimerParser)
+ );
+ // Increment by GT Block Timer structure size
+ Ptr += Offset;
+ Length -= Offset;
+ Index++;
+ }
+
+ if (Length != 0) {
+ IncrementErrorCount ();
+ Print (
+ L"ERROR:GT Block Timer length mismatch. Unparsed %d bytes.\n",
+ Length
+ );
+ }
+ }
+}
+
+/** This function parses the Platform Watchdog timer.
+
+ @param [in] Ptr Pointer to the start of the watchdog timer data.
+ @param [in] Length Length of the watchdog timer structure.
+*/
+STATIC
+VOID
+DumpWatchdogTimer (
+ IN UINT8* Ptr,
+ IN UINT16 Length
+ )
+{
+ ParseAcpi (
+ TRUE,
+ 2,
+ "SBSA Generic Watchdog",
+ Ptr,
+ Length,
+ PARSER_PARAMS (SBSAGenericWatchdogParser)
+ );
+}
+
+/** This function parses the ACPI GTDT table.
+ When trace is enabled this function parses the GTDT table and
+ traces the ACPI table fields.
+
+ This function also parses the following platform timer structures:
+ - GT Block timer
+ - Watchdog timer
+
+ 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
+ParseAcpiGtdt (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ UINT32 Index;
+ UINT8* TimerPtr;
+
+ if (!Trace) {
+ return;
+ }
+
+ ParseAcpi (
+ TRUE,
+ 0,
+ "GTDT",
+ Ptr,
+ AcpiTableLength,
+ PARSER_PARAMS (GtdtParser)
+ );
+
+ if (*GtdtPlatformTimerCount != 0) {
+ TimerPtr = Ptr + (*GtdtPlatformTimerOffset);
+ Index = 0;
+ do {
+ // Parse the Platform Timer Header
+ ParseAcpi (
+ FALSE,
+ 0,
+ NULL,
+ TimerPtr,
+ 4, // GT Platform Timer structure header length.
+ PARSER_PARAMS (GtPlatformTimerHeaderParser)
+ );
+ switch (*PlatformTimerType) {
+ case EFI_ACPI_6_2_GTDT_GT_BLOCK:
+ DumpGTBlock (TimerPtr, *PlatformTimerLength);
+ break;
+ case EFI_ACPI_6_2_GTDT_SBSA_GENERIC_WATCHDOG:
+ DumpWatchdogTimer (TimerPtr, *PlatformTimerLength);
+ break;
+ default:
+ IncrementErrorCount ();
+ Print (
+ L"ERROR: INVALID Platform Timer Type = %d\n",
+ *PlatformTimerType
+ );
+ break;
+ } // switch
+ TimerPtr += (*PlatformTimerLength);
+ Index++;
+ } while (Index < *GtdtPlatformTimerCount);
+ }
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c new file mode 100644 index 0000000..503a745 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c @@ -0,0 +1,700 @@ +/**
+ IORT 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):
+ - IO Remapping Table, Platform Design Document, Revision C, 15 May 2017
+**/
+
+#include <IndustryStandard/IoRemappingTable.h>
+#include <Library/PrintLib.h>
+#include <Library/UefiLib.h>
+#include "AcpiParser.h"
+#include "AcpiTableParser.h"
+
+// Local variables
+STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
+
+/** The EIORT_NODE enum describes the IORT Node types.
+*/
+typedef enum IortNode {
+ EIORT_NODE_ITS_GROUP, ///< ITS Group node
+ EIORT_NODE_NAMED_COMPONENT, ///< Named Component node
+ EIORT_NODE_ROOT_COMPLEX, ///< Root Complex node
+ EIORT_NODE_SMMUV1_V2, ///< SMMU v1/v2 node
+ EIORT_NODE_SMMUV3, ///< SMMU v3 node
+ EIORT_NODE_PMCG, ///< PMC group node
+ EIORT_NODE_MAX
+} EIORT_NODE;
+
+// Local Variables
+STATIC CONST UINT32* IortNodeCount;
+STATIC CONST UINT32* IortNodeOffset;
+
+STATIC CONST UINT8* IortNodeType;
+STATIC CONST UINT16* IortNodeLength;
+STATIC CONST UINT32* IortIdMappingCount;
+STATIC CONST UINT32* IortIdMappingOffset;
+
+STATIC CONST UINT32* InterruptContextCount;
+STATIC CONST UINT32* InterruptContextOffset;
+STATIC CONST UINT32* PmuInterruptCount;
+STATIC CONST UINT32* PmuInterruptOffset;
+
+STATIC CONST UINT32* ItsCount;
+
+/** This function validates the ID Mapping array count for the ITS node.
+
+ @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
+ValidateItsIdMappingCount (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ );
+
+/** This function validates the ID Mapping array offset for the ITS node.
+
+ @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
+ValidateItsIdArrayReference (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ );
+
+/** Helper Macro for populating the IORT Node header in the ACPI_PARSER
+ array.
+
+ @param [out] ValidateIdMappingCount Optional pointer to a function for
+ validating the ID Mapping count.
+ @param [out] ValidateIdArrayReference Optional pointer to a function for
+ validating the ID Array reference.
+*/
+#define PARSE_IORT_NODE_HEADER(ValidateIdMappingCount, \
+ ValidateIdArrayReference) \
+ { L"Type", 1, 0, L"%d", NULL, (VOID**)&IortNodeType, NULL, NULL }, \
+ { L"Length", 2, 1, L"%d", NULL, (VOID**)&IortNodeLength, NULL, NULL }, \
+ { L"Revision", 1, 3, L"%d", NULL, NULL, NULL, NULL }, \
+ { L"Reserved", 4, 4, L"0x%x", NULL, NULL, NULL, NULL }, \
+ { L"Number of ID mappings", 4, 8, L"%d", NULL, \
+ (VOID**)&IortIdMappingCount, ValidateIdMappingCount, NULL }, \
+ { L"Reference to ID Array", 4, 12, L"0x%x", NULL, \
+ (VOID**)&IortIdMappingOffset, ValidateIdArrayReference, NULL }
+
+/** An ACPI_PARSER array describing the ACPI IORT Table
+*/
+STATIC CONST ACPI_PARSER IortParser[] = {
+ PARSE_ACPI_HEADER (&AcpiHdrInfo),
+ {L"Number of IORT Nodes", 4, 36, L"%d", NULL,
+ (VOID**)&IortNodeCount, NULL, NULL},
+ {L"Offset to Array of IORT Nodes", 4, 40, L"0x%x", NULL,
+ (VOID**)&IortNodeOffset, NULL, NULL},
+ {L"Reserved", 4, 44, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the IORT node header structure.
+*/
+STATIC CONST ACPI_PARSER IortNodeHeaderParser[] = {
+ PARSE_IORT_NODE_HEADER (NULL, NULL)
+};
+
+/** An ACPI_PARSER array describing the IORT SMMUv1/2 node.
+*/
+STATIC CONST ACPI_PARSER IortNodeSmmuV1V2Parser[] = {
+ PARSE_IORT_NODE_HEADER (NULL, NULL),
+ {L"Base Address", 8, 16, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Span", 8, 24, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Model", 4, 32, L"%d", NULL, NULL, NULL, NULL},
+ {L"Flags", 4, 36, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Reference to Global Interrupt Array", 4, 40, L"0x%x", NULL, NULL, NULL,
+ NULL},
+ {L"Number of context interrupts", 4, 44, L"%d", NULL,
+ (VOID**)&InterruptContextCount, NULL, NULL},
+ {L"Reference to Context Interrupt Array", 4, 48, L"0x%x", NULL,
+ (VOID**)&InterruptContextOffset, NULL, NULL},
+ {L"Number of PMU Interrupts", 4, 52, L"%d", NULL,
+ (VOID**)&PmuInterruptCount, NULL, NULL},
+ {L"Reference to PMU Interrupt Array", 4, 56, L"0x%x", NULL,
+ (VOID**)&PmuInterruptOffset, NULL, NULL},
+
+ // Interrupt Array
+ {L"SMMU_NSgIrpt", 4, 60, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"SMMU_NSgIrpt interrupt flags", 4, 64, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"SMMU_NSgCfgIrpt", 4, 68, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"SMMU_NSgCfgIrpt interrupt flags", 4, 72, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the SMMUv1/2 Node Interrupt Array.
+*/
+STATIC CONST ACPI_PARSER InterruptArrayParser[] = {
+ {L" Interrupt GSIV", 4, 0, L"0x%x", NULL, NULL, NULL, NULL},
+ {L" Flags", 4, 4, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the IORT ID Mapping.
+*/
+STATIC CONST ACPI_PARSER IortNodeIdMappingParser[] = {
+ {L" Input base", 4, 0, L"0x%x", NULL, NULL, NULL, NULL},
+ {L" Number of IDs", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
+ {L" Output base", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},
+ {L" Output reference", 4, 12, L"0x%x", NULL, NULL, NULL, NULL},
+ {L" Flags", 4, 16, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the IORT SMMUv3 node.
+*/
+STATIC CONST ACPI_PARSER IortNodeSmmuV3Parser[] = {
+ PARSE_IORT_NODE_HEADER (NULL, NULL),
+ {L"Base Address", 8, 16, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Reserved", 4, 28, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"VATOS Address", 8, 32, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Model", 4, 40, L"%d", NULL, NULL, NULL, NULL},
+ {L"Event", 4, 44, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PRI", 4, 48, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"GERR", 4, 52, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Sync", 4, 56, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the IORT ITS node.
+*/
+STATIC CONST ACPI_PARSER IortNodeItsParser[] = {
+ PARSE_IORT_NODE_HEADER (
+ ValidateItsIdMappingCount,
+ ValidateItsIdArrayReference
+ ),
+ {L" Number of ITSs", 4, 16, L"%d", NULL, (VOID**)&ItsCount, NULL}
+};
+
+/** An ACPI_PARSER array describing the ITS ID.
+*/
+STATIC CONST ACPI_PARSER ItsIdParser[] = {
+ { L" GIC ITS Identifier", 4, 0, L"%d", NULL, NULL, NULL }
+};
+
+/** An ACPI_PARSER array describing the IORT Names Component node.
+*/
+STATIC CONST ACPI_PARSER IortNodeNamedComponentParser[] = {
+ PARSE_IORT_NODE_HEADER (NULL, NULL),
+ {L"Node Flags", 4, 16, L"%d", NULL, NULL, NULL, NULL},
+ {L"Memory access properties", 8, 20, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Device memory address size limit", 1, 28, L"%d", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the IORT Root Complex node.
+*/
+STATIC CONST ACPI_PARSER IortNodeRootComplexParser[] = {
+ PARSE_IORT_NODE_HEADER (NULL, NULL),
+ {L"Memory access properties", 8, 16, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"ATS Attribute", 4, 24, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PCI Segment number", 4, 28, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the IORT PMCG node.
+*/
+STATIC CONST ACPI_PARSER IortNodePmcgParser[] = {
+ PARSE_IORT_NODE_HEADER (NULL, NULL),
+ {L"Base Address", 8, 16, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Overflow interrupt GSIV", 4, 24, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Node reference", 4, 28, L"0x%x", NULL, NULL, NULL, NULL},
+};
+
+/** This function validates the ID Mapping array count for the ITS node.
+
+ @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
+ValidateItsIdMappingCount (
+ IN UINT8* Ptr,
+ VOID* Context
+ )
+{
+ if (*(UINT32*)Ptr != 0) {
+ IncrementErrorCount ();
+ Print (L"\nERROR: IORT ID Mapping count must be zero.");
+ }
+}
+
+/** This function validates the ID Mapping array offset for the ITS node.
+
+ @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
+ValidateItsIdArrayReference (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ )
+{
+ if (*(UINT32*)Ptr != 0) {
+ IncrementErrorCount ();
+ Print (L"\nERROR: IORT ID Mapping offset must be zero.");
+ }
+}
+
+/** This function parses the IORT Node Id Mapping array.
+
+ @param [in] Ptr Pointer to the start of the IORT Table.
+ @param [in] MappingCount The ID Mapping count.
+ @param [in] MappingOffset The offset of the ID Mapping array
+ from the start of the IORT table.
+*/
+STATIC
+VOID
+DumpIortNodeIdMappings (
+ IN UINT8* Ptr,
+ IN UINT32 MappingCount,
+ IN UINT32 MappingOffset
+ )
+{
+ UINT8* IdMappingPtr;
+ UINT32 Index;
+ UINT32 Offset;
+ CHAR8 Buffer[40]; // Used for AsciiName param of ParseAcpi
+
+ IdMappingPtr = Ptr + MappingOffset;
+ Index = 0;
+ while (Index < MappingCount) {
+ AsciiSPrint (
+ Buffer,
+ sizeof (Buffer),
+ "ID Mapping [%d]",
+ Index
+ );
+ Offset = ParseAcpi (
+ TRUE,
+ 4,
+ Buffer,
+ IdMappingPtr,
+ 20,
+ PARSER_PARAMS (IortNodeIdMappingParser)
+ );
+ IdMappingPtr += Offset;
+ Index++;
+ }
+}
+
+/** This function parses the IORT SMMUv1/2 node.
+
+ @param [in] Ptr Pointer to the start of the buffer.
+ @param [in] Length Length of the buffer.
+ @param [in] MappingCount The ID Mapping count.
+ @param [in] MappingOffset The offset of the ID Mapping array
+ from the start of the IORT table.
+*/
+STATIC
+VOID
+DumpIortNodeSmmuV1V2 (
+ IN UINT8* Ptr,
+ IN UINT16 Length,
+ IN UINT32 MappingCount,
+ IN UINT32 MappingOffset
+ )
+{
+ UINT32 Index;
+ UINT32 Offset;
+ CHAR8 Buffer[50]; // Used for AsciiName param of ParseAcpi
+
+ UINT8* ArrayPtr;
+
+ ParseAcpi (
+ TRUE,
+ 2,
+ "SMMUv1 or SMMUv2 Node",
+ Ptr,
+ Length,
+ PARSER_PARAMS (IortNodeSmmuV1V2Parser)
+ );
+
+ ArrayPtr = Ptr + *InterruptContextOffset;
+ Index = 0;
+ while (Index < *InterruptContextCount) {
+ AsciiSPrint (
+ Buffer,
+ sizeof (Buffer),
+ "Context Interrupts Array [%d]",
+ Index
+ );
+ Offset = ParseAcpi (
+ TRUE,
+ 4,
+ Buffer,
+ ArrayPtr,
+ 8,
+ PARSER_PARAMS (InterruptArrayParser)
+ );
+ ArrayPtr += Offset;
+ Index++;
+ }
+
+ ArrayPtr = Ptr + *PmuInterruptOffset;
+ Index = 0;
+ while (Index < *PmuInterruptCount) {
+ AsciiSPrint (
+ Buffer,
+ sizeof (Buffer),
+ "PMU Interrupts Array [%d]",
+ Index
+ );
+ Offset = ParseAcpi (
+ TRUE,
+ 4,
+ Buffer,
+ ArrayPtr,
+ 8,
+ PARSER_PARAMS (InterruptArrayParser)
+ );
+ ArrayPtr += Offset;
+ Index++;
+ }
+
+ if (*IortIdMappingCount != 0) {
+ DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset);
+ }
+}
+
+/** This function parses the IORT SMMUv3 node.
+
+ @param [in] Ptr Pointer to the start of the buffer.
+ @param [in] Length Length of the buffer.
+ @param [in] MappingCount The ID Mapping count.
+ @param [in] MappingOffset The offset of the ID Mapping array
+ from the start of the IORT table.
+*/
+STATIC
+VOID
+DumpIortNodeSmmuV3 (
+ IN UINT8* Ptr,
+ IN UINT16 Length,
+ IN UINT32 MappingCount,
+ IN UINT32 MappingOffset
+ )
+{
+ ParseAcpi (
+ TRUE,
+ 2,
+ "SMMUV3 Node",
+ Ptr,
+ Length,
+ PARSER_PARAMS (IortNodeSmmuV3Parser)
+ );
+
+ if (*IortIdMappingCount != 0) {
+ DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset);
+ }
+}
+
+/** This function parses the IORT ITS node.
+
+ @param [in] Ptr Pointer to the start of the buffer.
+ @param [in] Length Length of the buffer.
+*/
+STATIC
+VOID
+DumpIortNodeIts (
+ IN UINT8* Ptr,
+ IN UINT16 Length
+ )
+{
+ UINT32 Offset;
+ UINT32 Index;
+ UINT8* ItsIdPtr;
+ CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi
+
+ Offset = ParseAcpi (
+ TRUE,
+ 2,
+ "ITS Node",
+ Ptr,
+ Length,
+ PARSER_PARAMS (IortNodeItsParser)
+ );
+
+ ItsIdPtr = Ptr + Offset;
+ Index = 0;
+ while (Index < *ItsCount) {
+ AsciiSPrint (
+ Buffer,
+ sizeof (Buffer),
+ "GIC ITS Identifier Array [%d]",
+ Index
+ );
+ Offset = ParseAcpi (
+ TRUE,
+ 4,
+ Buffer,
+ ItsIdPtr,
+ 4,
+ PARSER_PARAMS (ItsIdParser)
+ );
+ ItsIdPtr += Offset;
+ Index++;
+ }
+
+ // Note: ITS does not have the ID Mappings Array
+}
+
+/** This function parses the IORT Named Component node.
+
+ @param [in] Ptr Pointer to the start of the buffer.
+ @param [in] Length Length of the buffer.
+ @param [in] MappingCount The ID Mapping count.
+ @param [in] MappingOffset The offset of the ID Mapping array
+ from the start of the IORT table.
+*/
+STATIC
+VOID
+DumpIortNodeNamedComponent (
+ IN UINT8* Ptr,
+ IN UINT16 Length,
+ IN UINT32 MappingCount,
+ IN UINT32 MappingOffset
+ )
+{
+ UINT32 Offset;
+ UINT32 Index;
+ UINT8* DeviceNamePtr;
+ UINT32 DeviceNameLength;
+
+ Offset = ParseAcpi (
+ TRUE,
+ 2,
+ "Named Component Node",
+ Ptr,
+ Length,
+ PARSER_PARAMS (IortNodeNamedComponentParser)
+ );
+
+ DeviceNamePtr = Ptr + Offset;
+ // Estimate the Device Name length
+ DeviceNameLength = Length - Offset - (MappingCount * 20);
+ PrintFieldName (2, L"Device Object Name");
+ Index = 0;
+ while ((Index < DeviceNameLength) && (DeviceNamePtr[Index] != 0)) {
+ Print (L"%c", DeviceNamePtr[Index++]);
+ }
+ Print (L"\n");
+
+ if (*IortIdMappingCount != 0) {
+ DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset);
+ }
+}
+
+/** This function parses the IORT Root Complex node.
+
+ @param [in] Ptr Pointer to the start of the buffer.
+ @param [in] Length Length of the buffer.
+ @param [in] MappingCount The ID Mapping count.
+ @param [in] MappingOffset The offset of the ID Mapping array
+ from the start of the IORT table.
+*/
+STATIC
+VOID
+DumpIortNodeRootComplex (
+ IN UINT8* Ptr,
+ IN UINT16 Length,
+ IN UINT32 MappingCount,
+ IN UINT32 MappingOffset
+ )
+{
+ ParseAcpi (
+ TRUE,
+ 2,
+ "Root Complex Node",
+ Ptr,
+ Length,
+ PARSER_PARAMS (IortNodeRootComplexParser)
+ );
+
+ if (*IortIdMappingCount != 0) {
+ DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset);
+ }
+}
+
+/** This function parses the IORT PMCG node.
+
+ @param [in] Ptr Pointer to the start of the buffer.
+ @param [in] Length Length of the buffer.
+ @param [in] MappingCount The ID Mapping count.
+ @param [in] MappingOffset The offset of the ID Mapping array
+ from the start of the IORT table.
+*/
+STATIC
+VOID
+DumpIortNodePmcg (
+ IN UINT8* Ptr,
+ IN UINT16 Length,
+ IN UINT32 MappingCount,
+ IN UINT32 MappingOffset
+)
+{
+ ParseAcpi (
+ TRUE,
+ 2,
+ "PMCG Node",
+ Ptr,
+ Length,
+ PARSER_PARAMS (IortNodePmcgParser)
+ );
+
+ if (*IortIdMappingCount != 0) {
+ DumpIortNodeIdMappings (Ptr, MappingCount, MappingOffset);
+ }
+
+ if (*IortIdMappingCount > 1) {
+ IncrementErrorCount ();
+ Print (
+ L"ERROR: ID mapping must not be greater than 1. Id Mapping Count =%d\n",
+ *IortIdMappingCount
+ );
+ }
+}
+
+/** This function parses the ACPI IORT table.
+ When trace is enabled this function parses the IORT table and
+ traces the ACPI fields.
+
+ This function also parses the following nodes:
+ - ITS Group
+ - Named Component
+ - Root Complex
+ - SMMUv1/2
+ - SMMUv3
+ - PMCG
+
+ 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
+ParseAcpiIort (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ UINT32 Offset;
+ UINT32 Index;
+ UINT8* NodePtr;
+
+ if (!Trace) {
+ return;
+ }
+
+ ParseAcpi (
+ TRUE,
+ 0,
+ "IORT",
+ Ptr,
+ AcpiTableLength,
+ PARSER_PARAMS (IortParser)
+ );
+ Offset = *IortNodeOffset;
+ NodePtr = Ptr + Offset;
+ Index = 0;
+
+ while ((Index < *IortNodeCount) && (Offset < AcpiTableLength)) {
+ // Parse the IORT Node Header
+ ParseAcpi (
+ FALSE,
+ 0,
+ "IORT Node Header",
+ NodePtr,
+ 16,
+ PARSER_PARAMS (IortNodeHeaderParser)
+ );
+ if (*IortNodeLength == 0) {
+ IncrementErrorCount ();
+ Print (L"ERROR: Parser error. Invalid table data.\n");
+ return;
+ }
+
+ PrintFieldName (2, L"* Node Offset *");
+ Print (L"0x%x\n", Offset);
+
+ switch (*IortNodeType) {
+ case EIORT_NODE_ITS_GROUP:
+ DumpIortNodeIts (
+ NodePtr,
+ *IortNodeLength
+ );
+ break;
+ case EIORT_NODE_NAMED_COMPONENT:
+ DumpIortNodeNamedComponent (
+ NodePtr,
+ *IortNodeLength,
+ *IortIdMappingCount,
+ *IortIdMappingOffset
+ );
+ break;
+ case EIORT_NODE_ROOT_COMPLEX:
+ DumpIortNodeRootComplex (
+ NodePtr,
+ *IortNodeLength,
+ *IortIdMappingCount,
+ *IortIdMappingOffset
+ );
+ break;
+ case EIORT_NODE_SMMUV1_V2:
+ DumpIortNodeSmmuV1V2 (
+ NodePtr,
+ *IortNodeLength,
+ *IortIdMappingCount,
+ *IortIdMappingOffset
+ );
+ break;
+ case EIORT_NODE_SMMUV3:
+ DumpIortNodeSmmuV3 (
+ NodePtr,
+ *IortNodeLength,
+ *IortIdMappingCount,
+ *IortIdMappingOffset
+ );
+ break;
+ case EIORT_NODE_PMCG:
+ DumpIortNodePmcg (
+ NodePtr,
+ *IortNodeLength,
+ *IortIdMappingCount,
+ *IortIdMappingOffset
+ );
+ break;
+
+ default:
+ IncrementErrorCount ();
+ Print (L"ERROR: Unsupported IORT Node type = %d\n", *IortNodeType);
+ } // switch
+
+ NodePtr += (*IortNodeLength);
+ Offset += (*IortNodeLength);
+ } // while
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c new file mode 100644 index 0000000..2ccbb7b --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c @@ -0,0 +1,313 @@ +/**
+ MADT 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/UefiLib.h>
+#include "AcpiParser.h"
+#include "AcpiTableParser.h"
+
+// Local Variables
+STATIC CONST UINT8* MadtInterruptControllerType;
+STATIC CONST UINT8* MadtInterruptControllerLength;
+STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
+
+// Forward declarations
+STATIC
+VOID
+EFIAPI
+ValidateGICDSystemVectorBase (
+ IN UINT8* Ptr,
+ IN VOID* Context
+);
+
+/** An ACPI_PARSER array describing the GICC Interrupt
+ Controller Structure.
+*/
+STATIC CONST ACPI_PARSER GicCParser[] = {
+ {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
+ {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"CPU Interface Number", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"ACPI Processor UID", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Flags", 4, 12, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Parking Protocol Version", 4, 16, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"Performance Interrupt GSIV", 4, 20, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Parked Address", 8, 24, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Physical Base Address", 8, 32, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"GICV", 8, 40, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"GICH", 8, 48, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"VGIC Maintenance interrupt", 4, 56, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"GICR Base Address", 8, 60, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"MPIDR", 8, 68, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Processor Power Efficiency Class", 1, 76, L"0x%x", NULL, NULL, NULL,
+ NULL},
+ {L"Reserved", 3, 77, L"%x %x %x", Dump3Chars, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the GICD Interrupt
+ Controller Structure.
+*/
+STATIC CONST ACPI_PARSER GicDParser[] = {
+ {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
+ {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"GIC ID", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Physical Base Address", 8, 8, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"System Vector Base", 4, 16, L"0x%x", NULL, NULL,
+ ValidateGICDSystemVectorBase, NULL},
+ {L"GIC Version", 1, 20, L"%d", NULL, NULL, NULL, NULL},
+ {L"Reserved", 3, 21, L"%x %x %x", Dump3Chars, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the MSI Frame Interrupt
+ Controller Structure.
+*/
+STATIC CONST ACPI_PARSER GicMSIFrameParser[] = {
+ {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
+ {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"MSI Frame ID", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Physical Base Address", 8, 8, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Flags", 4, 16, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"SPI Count", 2, 20, L"%d", NULL, NULL, NULL, NULL},
+ {L"SPI Base", 2, 22, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the GICR Interrupt
+ Controller Structure.
+*/
+STATIC CONST ACPI_PARSER GicRParser[] = {
+ {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
+ {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"Discovery Range Base Address", 8, 4, L"0x%lx", NULL, NULL, NULL,
+ NULL},
+ {L"Discovery Range Length", 4, 12, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the GIC ITS Interrupt
+ Controller Structure.
+*/
+STATIC CONST ACPI_PARSER GicITSParser[] = {
+ {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
+ {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
+
+ {L"GIC ITS ID", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Physical Base Address", 8, 8, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"Reserved", 4, 16, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the ACPI MADT Table.
+*/
+STATIC CONST ACPI_PARSER MadtParser[] = {
+ PARSE_ACPI_HEADER (&AcpiHdrInfo),
+ {L"Local Interrupt Controller Address", 4, 36, L"0x%x", NULL, NULL, NULL,
+ NULL},
+ {L"Flags", 4, 40, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** An ACPI_PARSER array describing the MADT Interrupt
+ Controller Structure Header Structure.
+*/
+STATIC CONST ACPI_PARSER MadtInterruptControllerHeaderParser[] = {
+ {NULL, 1, 0, NULL, NULL, (VOID**)&MadtInterruptControllerType, NULL, NULL},
+ {L"Length", 1, 1, NULL, NULL, (VOID**)&MadtInterruptControllerLength, NULL,
+ NULL},
+ {L"Reserved", 2, 2, NULL, NULL, NULL, NULL, NULL}
+};
+
+/** This function validates the System Vector Base in the GICD.
+
+ @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
+ValidateGICDSystemVectorBase (
+ IN UINT8* Ptr,
+ IN VOID* Context
+)
+{
+ if (*(UINT32*)Ptr != 0) {
+ IncrementErrorCount ();
+ Print (
+ L"\nERROR: System Vector Base must be zero."
+ );
+ }
+}
+
+/** This function parses the ACPI MADT table.
+ When trace is enabled this function parses the MADT table and
+ traces the ACPI table fields.
+
+ This function currently parses the following Interrupt Controller
+ Structures:
+ - GICC
+ - GICD
+ - GIC MSI Frame
+ - GICR
+ - GIC ITS
+
+ 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
+ParseAcpiMadt (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ UINT32 Offset;
+ UINT8* InterruptContollerPtr;
+ UINT32 GICDCount = 0;
+
+ if (!Trace) {
+ return;
+ }
+
+ Offset = ParseAcpi (
+ TRUE,
+ 0,
+ "MADT",
+ Ptr,
+ AcpiTableLength,
+ PARSER_PARAMS (MadtParser)
+ );
+ InterruptContollerPtr = Ptr + Offset;
+
+ while (Offset < AcpiTableLength) {
+ // Parse Interrupt Controller Structure to obtain Length.
+ ParseAcpi (
+ FALSE,
+ 0,
+ NULL,
+ InterruptContollerPtr,
+ 2, // Length is 1 byte at offset 1
+ PARSER_PARAMS (MadtInterruptControllerHeaderParser)
+ );
+
+ if (((Offset + (*MadtInterruptControllerLength)) > AcpiTableLength) ||
+ (*MadtInterruptControllerLength < 4)) {
+ IncrementErrorCount ();
+ Print (
+ L"ERROR: Invalid Interrupt Controller Length,"
+ " Type = %d, Length = %d\n",
+ *MadtInterruptControllerType,
+ *MadtInterruptControllerLength
+ );
+ break;
+ }
+
+ switch (*MadtInterruptControllerType) {
+ case EFI_ACPI_6_2_GIC: {
+ ParseAcpi (
+ TRUE,
+ 2,
+ "GICC",
+ InterruptContollerPtr,
+ *MadtInterruptControllerLength,
+ PARSER_PARAMS (GicCParser)
+ );
+ break;
+ }
+
+ case EFI_ACPI_6_2_GICD: {
+ if (++GICDCount > 1) {
+ IncrementErrorCount ();
+ Print (
+ L"ERROR: Only one GICD must be present,"
+ " GICDCount = %d\n",
+ GICDCount
+ );
+ }
+ ParseAcpi (
+ TRUE,
+ 2,
+ "GICD",
+ InterruptContollerPtr,
+ *MadtInterruptControllerLength,
+ PARSER_PARAMS (GicDParser)
+ );
+ break;
+ }
+
+ case EFI_ACPI_6_2_GIC_MSI_FRAME: {
+ ParseAcpi (
+ TRUE,
+ 2,
+ "GIC MSI Frame",
+ InterruptContollerPtr,
+ *MadtInterruptControllerLength,
+ PARSER_PARAMS (GicMSIFrameParser)
+ );
+ break;
+ }
+
+ case EFI_ACPI_6_2_GICR: {
+ ParseAcpi (
+ TRUE,
+ 2,
+ "GICR",
+ InterruptContollerPtr,
+ *MadtInterruptControllerLength,
+ PARSER_PARAMS (GicRParser)
+ );
+ break;
+ }
+
+ case EFI_ACPI_6_2_GIC_ITS: {
+ ParseAcpi (
+ TRUE,
+ 2,
+ "GIC ITS",
+ InterruptContollerPtr,
+ *MadtInterruptControllerLength,
+ PARSER_PARAMS (GicITSParser)
+ );
+ break;
+ }
+
+ default: {
+ IncrementErrorCount ();
+ Print (
+ L"ERROR: Unknown Interrupt Controller Structure,"
+ " Type = %d, Length = %d\n",
+ *MadtInterruptControllerType,
+ *MadtInterruptControllerLength
+ );
+ }
+ } // switch
+
+ InterruptContollerPtr += *MadtInterruptControllerLength;
+ Offset += *MadtInterruptControllerLength;
+ } // while
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Mcfg/McfgParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Mcfg/McfgParser.c new file mode 100644 index 0000000..a21b30d --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Mcfg/McfgParser.c @@ -0,0 +1,94 @@ +/**
+ MCFG 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):
+ - PCI Firmware Specification - Revision 3.2, January 26, 2015.
+**/
+
+#include <IndustryStandard/Acpi.h>
+#include <Library/UefiLib.h>
+#include "AcpiParser.h"
+#include "AcpiTableParser.h"
+
+// Local variables
+STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
+
+/** An ACPI_PARSER array describing the ACPI MCFG Table.
+*/
+STATIC CONST ACPI_PARSER McfgParser[] = {
+ PARSE_ACPI_HEADER (&AcpiHdrInfo),
+ {L"Reserved", 8, 36, L"0x%lx", NULL, NULL, NULL, NULL},
+};
+
+/** An ACPI_PARSER array describing the PCI configuration Space
+ Base Address structure.
+*/
+STATIC CONST ACPI_PARSER PciCfgSpaceBaseAddrParser[] = {
+ {L"Base Address", 8, 0, L"0x%lx", NULL, NULL, NULL, NULL},
+ {L"PCI Segment Group No.", 2, 8, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Start Bus No.", 1, 10, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"End Bus No.", 1, 11, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Reserved", 4, 12, L"0x%x", NULL, NULL, NULL, NULL}
+};
+
+/** This function parses the ACPI MCFG table.
+ When trace is enabled this function parses the MCFG table and
+ traces the ACPI table fields.
+
+ 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
+ParseAcpiMcfg (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ UINT32 Offset;
+ UINT32 PciCfgOffset;
+ UINT8* PciCfgSpacePtr;
+
+ if (!Trace) {
+ return;
+ }
+
+ Offset = ParseAcpi (
+ TRUE,
+ 0,
+ "MCFG",
+ Ptr,
+ AcpiTableLength,
+ PARSER_PARAMS (McfgParser)
+ );
+
+ PciCfgSpacePtr = Ptr + Offset;
+
+ while (Offset < AcpiTableLength) {
+ PciCfgOffset = ParseAcpi (
+ TRUE,
+ 2,
+ "PCI Configuration Space",
+ PciCfgSpacePtr,
+ (AcpiTableLength - Offset),
+ PARSER_PARAMS (PciCfgSpaceBaseAddrParser)
+ );
+ PciCfgSpacePtr += PciCfgOffset;
+ Offset += PciCfgOffset;
+ }
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c new file mode 100644 index 0000000..c7acdce --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Rsdp/RsdpParser.c @@ -0,0 +1,169 @@ +/**
+ RSDP 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 <Library/UefiLib.h>
+#include "AcpiParser.h"
+#include "AcpiTableParser.h"
+
+// Local Variables
+STATIC CONST UINT64* XsdtAddress;
+
+/** This function validates the RSDT Address.
+
+ @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
+ValidateRsdtAddress (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ );
+
+/** This function validates the XSDT Address.
+
+ @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
+ValidateXsdtAddress (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ );
+
+/** An array describing the ACPI RSDP Table.
+*/
+STATIC CONST ACPI_PARSER RsdpParser[] = {
+ {L"Signature", 8, 0, NULL, Dump8Chars, NULL, NULL, NULL},
+ {L"Checksum", 1, 8, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Oem ID", 6, 9, NULL, Dump6Chars, NULL, NULL, NULL},
+ {L"Revision", 1, 15, L"%d", NULL, NULL, NULL, NULL},
+ {L"RSDT Address", 4, 16, L"0x%x", NULL, NULL, ValidateRsdtAddress, NULL},
+ {L"Length", 4, 20, L"%d", NULL, NULL, NULL, NULL},
+ {L"XSDT Address", 8, 24, L"0x%lx", NULL, (VOID**)&XsdtAddress,
+ ValidateXsdtAddress, NULL},
+ {L"Extended Checksum", 1, 32, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Reserved", 3, 33, L"%x %x %x", Dump3Chars, NULL, NULL, NULL}
+};
+
+/** This function validates the RSDT Address.
+
+ @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
+ValidateRsdtAddress (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ )
+{
+#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+ // Reference: Server Base Boot Requirements System Software on ARM Platforms
+ // Section: 4.2.1.1 RSDP
+ // Root System Description Pointer (RSDP), ACPI ? 5.2.5.
+ // - Within the RSDP, the RsdtAddress field must be null (zero) and the
+ // XsdtAddresss MUST be a valid, non-null, 64-bit value.
+ UINT32 RsdtAddr = *(UINT32*)Ptr;
+ if (RsdtAddr != 0) {
+ IncrementErrorCount ();
+ Print (
+ L"\nERROR: Rsdt Address = 0x%p. This must be NULL on ARM Platforms.",
+ RsdtAddr
+ );
+ }
+#endif
+}
+
+/** This function validates the XSDT Address.
+
+ @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
+ValidateXsdtAddress (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ )
+{
+#if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+ // Reference: Server Base Boot Requirements System Software on ARM Platforms
+ // Section: 4.2.1.1 RSDP
+ // Root System Description Pointer (RSDP), ACPI ? 5.2.5.
+ // - Within the RSDP, the RsdtAddress field must be null (zero) and the
+ // XsdtAddresss MUST be a valid, non-null, 64-bit value.
+ UINT64 XsdtAddr = *(UINT64*)Ptr;
+ if (XsdtAddr == 0) {
+ IncrementErrorCount ();
+ Print (
+ L"\nERROR: Xsdt Address = 0x%p. This must not be NULL on ARM Platforms.",
+ XsdtAddr
+ );
+ }
+#endif
+}
+
+/** This function parses the ACPI RSDP table.
+
+ This function invokes the parser for the XSDT table.
+ * Note - This function does not support parsing of RSDT table.
+
+ This function also performs a RAW dump of the ACPI table and
+ validates the checksum.
+
+ @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
+ParseAcpiRsdp (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ if (Trace) {
+ DumpRaw (Ptr, AcpiTableLength);
+ VerifyChecksum (TRUE, Ptr, AcpiTableLength);
+ }
+
+ ParseAcpi (Trace, 0, "RSDP", Ptr, AcpiTableLength, PARSER_PARAMS (RsdpParser));
+
+ // This code currently supports parsing of XSDT table only
+ // and does not parse the RSDT table. Platforms provide the
+ // RSDT to enable compatibility with ACPI 1.0 operating systems.
+ // Therefore the RSDT should not be used on ARM platforms.
+ if ((*XsdtAddress) == 0) {
+ IncrementErrorCount ();
+ Print (L"ERROR: XSDT Pointer is not set.\n");
+ return;
+ }
+
+ ProcessAcpiTable ((UINT8*)(UINTN)(*XsdtAddress));
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c new file mode 100644 index 0000000..5f99fd4 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Slit/SlitParser.c @@ -0,0 +1,142 @@ +/**
+ SLIT 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 UINT64* SlitSystemLocalityCount;
+STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
+
+/** An ACPI_PARSER array describing the ACPI SLIT table.
+*/
+STATIC CONST ACPI_PARSER SlitParser[] = {
+ PARSE_ACPI_HEADER (&AcpiHdrInfo),
+ {L"Number of System Localities", 8, 36, L"0x%lx", NULL,
+ (VOID**)&SlitSystemLocalityCount, NULL, NULL}
+};
+
+/** Macro to get the value of a System Locality
+*/
+#define SLIT_ELEMENT(Ptr, i, j) *(Ptr + (i * LocalityCount) + j)
+
+/** This function parses the ACPI SLIT table.
+ When trace is enabled this function parses the SLIT table and
+ traces the ACPI table fields.
+
+ This function also validates System Localities for the following:
+ - Diagonal elements have a normalized value of 10
+ - Relative distance from System Locality at i*N+j is same as
+ j*N+i
+
+ @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
+ParseAcpiSlit (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ UINT32 Offset;
+ UINT64 i;
+ UINT64 j;
+ UINT64 LocalityCount;
+ UINT8* LocalityPtr;
+ CHAR16 Buffer[80]; // Used for AsciiName param of ParseAcpi
+
+ if (!Trace) {
+ return;
+ }
+
+ Offset = ParseAcpi (
+ TRUE,
+ 0,
+ "SLIT",
+ Ptr,
+ AcpiTableLength,
+ PARSER_PARAMS (SlitParser)
+ );
+ LocalityPtr = Ptr + Offset;
+
+ LocalityCount = *SlitSystemLocalityCount;
+ // We only print the Localities if the count is less than 16
+ // If the locality count is more than 16 then refer to the
+ // raw data dump.
+ if (LocalityCount < 16) {
+ UnicodeSPrint (
+ Buffer,
+ sizeof (Buffer),
+ L"Entry[0x%lx][0x%lx]",
+ LocalityCount,
+ LocalityCount
+ );
+ PrintFieldName (0, Buffer);
+ Print (L"\n");
+ Print (L" ");
+ for (j = 0; j < LocalityCount; j++) {
+ Print (L" (%3d) ", j);
+ }
+ Print (L"\n");
+ for (i = 0; i < LocalityCount; i++) {
+ Print (L" (%3d) ", i);
+ for (j = 0; j < LocalityCount; j++) {
+ Print (L" %3d ", SLIT_ELEMENT (LocalityPtr, i, j));
+ }
+ Print (L"\n");
+ }
+ }
+
+ // Validate
+ for (i = 0; i < LocalityCount; i++) {
+ for (j = 0; j < LocalityCount; j++) {
+ // Element[x][x] must be equal to 10
+ if ((i == j) && (SLIT_ELEMENT (LocalityPtr, i, j) != 10)) {
+ IncrementErrorCount ();
+ Print (
+ L"ERROR: Diagonal Element[0x%lx][0x%lx] (%3d)."
+ " Normalized Value is not 10\n",
+ i,
+ j,
+ SLIT_ELEMENT (LocalityPtr, i, j)
+ );
+ }
+ // Element[i][j] must be equal to Element[j][i]
+ if (SLIT_ELEMENT (LocalityPtr, i, j) !=
+ SLIT_ELEMENT (LocalityPtr, j, i)) {
+ IncrementErrorCount ();
+ Print (
+ L"ERROR: Relative distances for Element[0x%lx][0x%lx] (%3d) and \n"
+ "Element[0x%lx][0x%lx] (%3d) do not match.\n",
+ i,
+ j,
+ SLIT_ELEMENT (LocalityPtr, i, j),
+ j,
+ i,
+ SLIT_ELEMENT (LocalityPtr, j, i)
+ );
+ }
+ }
+ }
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c new file mode 100644 index 0000000..841a27f --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Spcr/SpcrParser.c @@ -0,0 +1,168 @@ +/**
+ SPCR 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):
+ - Microsoft Serial Port Console Redirection Table
+ Specification - Version 1.03 - August 10, 2015.
+**/
+
+#include <IndustryStandard/Acpi.h>
+#include <IndustryStandard/SerialPortConsoleRedirectionTable.h>
+#include <Library/UefiLib.h>
+#include "AcpiParser.h"
+#include "AcpiTableParser.h"
+
+// Local variables
+STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
+
+/** This function validates the Interrupt Type.
+
+ @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
+ValidateInterruptType (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ );
+
+/** This function validates the Irq.
+
+ @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
+ValidateIrq (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ );
+
+/** An ACPI_PARSER array describing the ACPI SPCR Table.
+*/
+STATIC CONST ACPI_PARSER SpcrParser[] = {
+ PARSE_ACPI_HEADER (&AcpiHdrInfo),
+ {L"Interface Type", 1, 36, L"%d", NULL, NULL, NULL, NULL},
+ {L"Reserved", 3, 37, L"%x %x %x", Dump3Chars, NULL, NULL, NULL},
+ {L"Base Address", 12, 40, NULL, DumpGas, NULL, NULL, NULL},
+ {L"Interrupt Type", 1, 52, L"%d", NULL, NULL, ValidateInterruptType, NULL},
+ {L"IRQ", 1, 53, L"%d", NULL, NULL, ValidateIrq, NULL},
+ {L"Global System Interrupt", 4, 54, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Baud Rate", 1, 58, L"%d", NULL, NULL, NULL, NULL},
+ {L"Parity", 1, 59, L"%d", NULL, NULL, NULL, NULL},
+ {L"Stop Bits", 1, 60, L"%d", NULL, NULL, NULL, NULL},
+ {L"Flow Control", 1, 61, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Terminal Type", 1, 62, L"%d", NULL, NULL, NULL, NULL},
+ {L"Reserved", 1, 63, L"%x", NULL, NULL, NULL, NULL},
+
+ {L"PCI Device ID", 2, 64, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PCI Vendor ID", 2, 66, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PCI Bus Number", 1, 68, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PCI Device Number", 1, 69, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PCI Function Number", 1, 70, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PCI Flags", 4, 71, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"PCI Segment", 1, 75, L"0x%x", NULL, NULL, NULL, NULL},
+ {L"Reserved", 4, 76, L"%x", NULL, NULL, NULL, NULL}
+};
+
+/** This function validates the Interrupt Type.
+
+ @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
+ValidateInterruptType (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ )
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+ UINT8 InterruptType = *Ptr;
+ if (InterruptType !=
+ EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERRUPT_TYPE_GIC) {
+ IncrementErrorCount ();
+ Print (
+ L"\nERROR: InterruptType = %d. This must be 8 on ARM Platforms",
+ InterruptType
+ );
+ }
+#endif
+}
+
+/** This function validates the Irq.
+
+ @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
+ValidateIrq (
+ IN UINT8* Ptr,
+ IN VOID* Context
+ )
+{
+#if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
+ UINT8 Irq = *Ptr;
+ if (Irq != 0) {
+ IncrementErrorCount ();
+ Print (
+ L"\nERROR: Irq = %d. This must be zero on ARM Platforms\n",
+ Irq
+ );
+ }
+#endif
+}
+
+/** This function parses the ACPI SPCR table.
+ When trace is enabled this function parses the SPCR table and
+ traces the ACPI table fields.
+
+ This function also performs validations 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
+ParseAcpiSpcr (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ if (!Trace) {
+ return;
+ }
+
+ // Dump the SPCR
+ ParseAcpi (
+ TRUE,
+ 0,
+ "SPCR",
+ Ptr,
+ AcpiTableLength,
+ PARSER_PARAMS (SpcrParser)
+ );
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c new file mode 100644 index 0000000..86da559 --- /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);
+ }
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Ssdt/SsdtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Ssdt/SsdtParser.c new file mode 100644 index 0000000..a77ccbe --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Ssdt/SsdtParser.c @@ -0,0 +1,47 @@ +/**
+ SSDT 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/UefiLib.h>
+#include "AcpiParser.h"
+#include "AcpiTableParser.h"
+
+/** This function parses the ACPI SSDT table.
+ When trace is enabled this function parses the SSDT table and
+ traces the ACPI table fields.
+ For the SSDT table only the ACPI header fields are
+ parsed and traced.
+
+ @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
+ParseAcpiSsdt (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ if (!Trace) {
+ return;
+ }
+
+ DumpAcpiHeader (Ptr);
+}
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c new file mode 100644 index 0000000..0ed65d2 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c @@ -0,0 +1,153 @@ +/**
+ XSDT 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/UefiLib.h>
+#include <Library/PrintLib.h>
+#include "AcpiParser.h"
+#include "AcpiTableParser.h"
+
+// Local variables
+STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
+
+/** An ACPI_PARSER array describing the ACPI XSDT table.
+*/
+STATIC CONST ACPI_PARSER XsdtParser[] = {
+ PARSE_ACPI_HEADER (&AcpiHdrInfo)
+};
+
+CONST ACPI_DESCRIPTION_HEADER_INFO* CONST
+EFIAPI
+GetAcpiXsdtHeaderInfo (
+ VOID
+)
+{
+ return &AcpiHdrInfo;
+}
+
+/** This function parses the ACPI XSDT table
+ and optionally traces the ACPI table fields.
+
+ This function also performs validation of the XSDT table.
+
+ @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
+ParseAcpiXsdt (
+ IN BOOLEAN Trace,
+ IN UINT8* Ptr,
+ IN UINT32 AcpiTableLength,
+ IN UINT8 AcpiTableRevision
+ )
+{
+ UINT32 Offset;
+ UINT32 TableOffset;
+ UINT64* TablePointer;
+ UINTN EntryIndex;
+ CHAR16 Buffer[32];
+
+ // Parse the ACPI header to get the length
+ ParseAcpi (
+ FALSE,
+ 0,
+ "XSDT",
+ Ptr,
+ ACPI_DESCRIPTION_HEADER_LENGTH,
+ PARSER_PARAMS (XsdtParser)
+ );
+
+ Offset = ParseAcpi (
+ Trace,
+ 0,
+ "XSDT",
+ Ptr,
+ *AcpiHdrInfo.Length,
+ PARSER_PARAMS (XsdtParser)
+ );
+
+ TableOffset = Offset;
+
+ if (Trace) {
+ EntryIndex = 0;
+ TablePointer = (UINT64*)(Ptr + TableOffset);
+ while (Offset < (*AcpiHdrInfo.Length)) {
+ CONST UINT32* Signature;
+ CONST UINT32* Length;
+ CONST UINT8* Revision;
+
+ if ((UINT64*)(UINTN)(*TablePointer) != NULL) {
+ UINT8* Ptr;
+
+ ParseAcpiHeader (
+ (UINT8*)(UINTN)(*TablePointer),
+ &Signature,
+ &Length,
+ &Revision
+ );
+
+ Ptr = (UINT8*)Signature;
+
+ UnicodeSPrint (
+ Buffer,
+ sizeof (Buffer),
+ L"Entry[%d] - %c%c%c%c",
+ EntryIndex++,
+ Ptr[0],
+ Ptr[1],
+ Ptr[2],
+ Ptr[3]
+ );
+ } else {
+ UnicodeSPrint (
+ Buffer,
+ sizeof (Buffer),
+ L"Entry[%d]",
+ EntryIndex++
+ );
+ }
+
+ PrintFieldName (2, Buffer);
+ Print (L"0x%lx\n", *TablePointer);
+
+ // Validate the table pointers are not NULL
+ if ((UINT64*)(UINTN)(*TablePointer) == NULL) {
+ IncrementErrorCount ();
+ Print (
+ L"ERROR: Invalid table entry at 0x%lx, table address is 0x%lx\n",
+ TablePointer,
+ *TablePointer
+ );
+ }
+ Offset += sizeof (UINT64);
+ TablePointer++;
+ } // while
+ }
+
+ // Process the tables
+ Offset = TableOffset;
+ TablePointer = (UINT64*)(Ptr + TableOffset);
+ while (Offset < (*AcpiHdrInfo.Length)) {
+ if ((UINT64*)(UINTN)(*TablePointer) != NULL) {
+ ProcessAcpiTable ((UINT8*)(UINTN)(*TablePointer));
+ }
+ Offset += sizeof (UINT64);
+ TablePointer++;
+ } // while
+}
|