Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cherry-Pick][Rebase & FF] Adding TPM ACPI table shell viewer and FF-A definition #1263

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions MdePkg/Include/IndustryStandard/Tpm2Acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent

#define EFI_TPM2_ACPI_TABLE_REVISION_3 3
#define EFI_TPM2_ACPI_TABLE_REVISION_4 4
#define EFI_TPM2_ACPI_TABLE_REVISION_5 5
#define EFI_TPM2_ACPI_TABLE_REVISION EFI_TPM2_ACPI_TABLE_REVISION_4

#define EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_4 12
#define EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_5 16
#define EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_4

typedef struct {
EFI_ACPI_DESCRIPTION_HEADER Header;
// Flags field is replaced in version 4 and above
Expand All @@ -36,6 +41,7 @@ typedef struct {
#define EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE 7
#define EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE_WITH_ACPI 8
#define EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE_WITH_SMC 11
#define EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE_WITH_FFA 15

typedef struct {
UINT32 Reserved;
Expand Down
17 changes: 17 additions & 0 deletions ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,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.

Expand Down
155 changes: 155 additions & 0 deletions ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Tpm2/Tpm2Parser.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/** @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 <IndustryStandard/Acpi.h>
#include <IndustryStandard/Tpm2Acpi.h>
#include <Library/UefiLib.h>
#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 },
};

/**
An ACPI_PARSER array describing the Start Method Specific Parameters for Arm FF-A table.
**/
STATIC CONST ACPI_PARSER Tpm2StartMethodArmFFA[] = {
{ L"Flags", 1, 0, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Attributes", 1, 1, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Partition ID", 2, 2, L"0x%x", NULL, NULL, NULL, NULL },
{ L"Reserved", 8, 4, L"0x%lx", 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;

case EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE_WITH_FFA:
ParseAcpi (
TRUE,
0,
"Start Method Specific Parameters for Arm FF-A",
Ptr + Offset,
AcpiTableLength - Offset,
PARSER_PARAMS (Tpm2StartMethodArmFFA)
);
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)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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 }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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
Expand Down
Loading