From 14f5e9b09832da56cf1e5bef2bcd7564e7d864d2 Mon Sep 17 00:00:00 2001 From: Sarah Walker Date: Fri, 3 Jan 2025 10:25:16 +0000 Subject: [PATCH] ShellPkg: AcpiView: TPM2 Parser Add a new parser for the TPM2 Table as specified in the TCG ACPI Specification v1.4 Signed-off-by: Sarah Walker --- .../UefiShellAcpiViewCommandLib/AcpiParser.h | 17 +++ .../Parsers/Tpm2/Tpm2Parser.c | 134 ++++++++++++++++++ .../UefiShellAcpiViewCommandLib.c | 1 + .../UefiShellAcpiViewCommandLib.inf | 1 + 4 files changed, 153 insertions(+) create mode 100644 ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Tpm2/Tpm2Parser.c diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h index ded5657f00..0aece822f6 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h @@ -1168,6 +1168,23 @@ ParseAcpiSsdt ( IN UINT8 AcpiTableRevision ); +/** + This function parses the ACPI TPM2 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 +ParseAcpiTpm2 ( + IN BOOLEAN Trace, + IN UINT8 *Ptr, + IN UINT32 AcpiTableLength, + IN UINT8 AcpiTableRevision + ); + /** This function parses the ACPI WSMT table. diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Tpm2/Tpm2Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Tpm2/Tpm2Parser.c new file mode 100644 index 0000000000..a0be2622a4 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Tpm2/Tpm2Parser.c @@ -0,0 +1,134 @@ +/** @file + TPM2 table parser + + Copyright (c) 2024, ARM Limited. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - TCG ACPI Specification - Version 1.4, Revision 15, April 3, 2024. + (https://trustedcomputinggroup.org/resource/tcg-acpi-specification/) +**/ + +#include +#include +#include +#include "AcpiParser.h" +#include "AcpiTableParser.h" + +#define TPM2_ACPI_TABLE_LOG_AREA_SIZE (sizeof(UINT32) + sizeof(UINT64)) + +// Log area parameter offset is different on ACPI table revision 4 and 5, due to different SMSP max size. +#define TPM2_ACPI_TABLE_SIZE_WITH_LOG_AREA_REVISION_4 (sizeof(EFI_TPM2_ACPI_TABLE) + EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_4 + TPM2_ACPI_TABLE_LOG_AREA_SIZE) +#define TPM2_ACPI_TABLE_SIZE_WITH_LOG_AREA_REVISION_5 (sizeof(EFI_TPM2_ACPI_TABLE) + EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_5 + TPM2_ACPI_TABLE_LOG_AREA_SIZE) + +// Local variables +STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo; +STATIC UINT32 *StartMethod; + +/** + An ACPI_PARSER array describing the ACPI TPM 2.0 Table. +**/ +STATIC CONST ACPI_PARSER Tpm2Parser[] = { + PARSE_ACPI_HEADER (&AcpiHdrInfo), + { L"Platform Class", 2, 36, L"0x%x", NULL, NULL, NULL, NULL }, + { L"Reserved", 2, 38, L"0x%x", NULL, NULL, NULL, NULL }, + { L"Address of CRB Control Area",8, 40, L"0x%lx", NULL, NULL, NULL, NULL }, + { L"Start Method", 4, 48, L"0x%x", NULL, (VOID **)&StartMethod, NULL, NULL } +}; + +/** + An ACPI_PARSER array describing the ACPI TPM 2.0 Table Log Area entries. +**/ +STATIC CONST ACPI_PARSER Tpm2LogArea[] = { + { L"Log Area Minimum Length", 4, 0, L"0x%x", NULL, NULL, NULL, NULL }, + { L"Log Area Start Address", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL } +}; + +/** + An ACPI_PARSER array describing the Start Method Specific Parameters for Arm SMC Start Method table. +**/ +STATIC CONST ACPI_PARSER Tpm2StartMethodArmSmc[] = { + { L"Interrupt", 4, 0, L"0x%x", NULL, NULL, NULL, NULL }, + { L"Flags", 1, 4, L"0x%x", NULL, NULL, NULL, NULL }, + { L"Operation Flags", 1, 5, L"0x%x", NULL, NULL, NULL, NULL }, + { L"Attributes", 1, 6, L"0x%x", NULL, NULL, NULL, NULL }, + { L"Reserved", 1, 7, L"0x%x", NULL, NULL, NULL, NULL }, + { L"SMC/HVC Function ID", 4, 8, L"0x%x", NULL, NULL, NULL, NULL }, +}; + +/** + This function parses the ACPI TPM2 table. + When trace is enabled this function parses the TPM2 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 +ParseAcpiTpm2 ( + IN BOOLEAN Trace, + IN UINT8 *Ptr, + IN UINT32 AcpiTableLength, + IN UINT8 AcpiTableRevision + ) +{ + UINT32 Offset; + BOOLEAN LogAreaPresent; + + if (!Trace) { + return; + } + + Offset = ParseAcpi ( + TRUE, + 0, + "TPM2", + Ptr, + AcpiTableLength, + PARSER_PARAMS (Tpm2Parser) + ); + + // Log area parameters are optional. Presence is determined by table length. + LogAreaPresent = (*AcpiHdrInfo.Revision == EFI_TPM2_ACPI_TABLE_REVISION_4 && AcpiTableLength == TPM2_ACPI_TABLE_SIZE_WITH_LOG_AREA_REVISION_4) || + (*AcpiHdrInfo.Revision == EFI_TPM2_ACPI_TABLE_REVISION_5 && AcpiTableLength == TPM2_ACPI_TABLE_SIZE_WITH_LOG_AREA_REVISION_5); + + switch (*StartMethod) { + case EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE_WITH_SMC: + ParseAcpi ( + TRUE, + 0, + "Start Method Specific Parameters for Arm SMC", + Ptr + Offset, + AcpiTableLength - Offset, + PARSER_PARAMS (Tpm2StartMethodArmSmc) + ); + break; + + default: + Print ( + L"WARNING: Start Method %u not supported\n", + *StartMethod + ); + break; + } + + if (LogAreaPresent) { + Offset += (*AcpiHdrInfo.Revision == EFI_TPM2_ACPI_TABLE_REVISION_4) ? + EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_4 : + EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_5; + + ParseAcpi ( + TRUE, + 0, + "TPM2 Log Area", + Ptr + Offset, + AcpiTableLength - Offset, + PARSER_PARAMS (Tpm2LogArea) + ); + } +} diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c index 7b140a062b..37a122c1d8 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c @@ -78,6 +78,7 @@ ACPI_TABLE_PARSER ParserList[] = { { EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE, ParseAcpiSpcr }, { EFI_ACPI_6_2_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE, ParseAcpiSrat }, { EFI_ACPI_6_2_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiSsdt }, + { EFI_ACPI_6_5_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE, ParseAcpiTpm2 }, { EFI_ACPI_6_5_WINDOWS_SMM_SECURITY_MITIGATION_TABLE_SIGNATURE, ParseAcpiWsmt }, { EFI_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiXsdt } }; diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf index af77856a85..42ce88e171 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf @@ -57,6 +57,7 @@ Parsers/Spcr/SpcrParser.c Parsers/Srat/SratParser.c Parsers/Ssdt/SsdtParser.c + Parsers/Tpm2/Tpm2Parser.c Parsers/Wsmt/WsmtParser.c Parsers/Xsdt/XsdtParser.c UefiShellAcpiViewCommandLib.c