Skip to content

Commit 14f5e9b

Browse files
sarah-walker-armlgao4
authored andcommitted
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 <[email protected]>
1 parent 7216013 commit 14f5e9b

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,23 @@ ParseAcpiSsdt (
11681168
IN UINT8 AcpiTableRevision
11691169
);
11701170

1171+
/**
1172+
This function parses the ACPI TPM2 table.
1173+
1174+
@param [in] Trace If TRUE, trace the ACPI fields.
1175+
@param [in] Ptr Pointer to the start of the buffer.
1176+
@param [in] AcpiTableLength Length of the ACPI table.
1177+
@param [in] AcpiTableRevision Revision of the ACPI table.
1178+
**/
1179+
VOID
1180+
EFIAPI
1181+
ParseAcpiTpm2 (
1182+
IN BOOLEAN Trace,
1183+
IN UINT8 *Ptr,
1184+
IN UINT32 AcpiTableLength,
1185+
IN UINT8 AcpiTableRevision
1186+
);
1187+
11711188
/**
11721189
This function parses the ACPI WSMT table.
11731190
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/** @file
2+
TPM2 table parser
3+
4+
Copyright (c) 2024, ARM Limited. All rights reserved.
5+
SPDX-License-Identifier: BSD-2-Clause-Patent
6+
7+
@par Reference(s):
8+
- TCG ACPI Specification - Version 1.4, Revision 15, April 3, 2024.
9+
(https://trustedcomputinggroup.org/resource/tcg-acpi-specification/)
10+
**/
11+
12+
#include <IndustryStandard/Acpi.h>
13+
#include <IndustryStandard/Tpm2Acpi.h>
14+
#include <Library/UefiLib.h>
15+
#include "AcpiParser.h"
16+
#include "AcpiTableParser.h"
17+
18+
#define TPM2_ACPI_TABLE_LOG_AREA_SIZE (sizeof(UINT32) + sizeof(UINT64))
19+
20+
// Log area parameter offset is different on ACPI table revision 4 and 5, due to different SMSP max size.
21+
#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)
22+
#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)
23+
24+
// Local variables
25+
STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
26+
STATIC UINT32 *StartMethod;
27+
28+
/**
29+
An ACPI_PARSER array describing the ACPI TPM 2.0 Table.
30+
**/
31+
STATIC CONST ACPI_PARSER Tpm2Parser[] = {
32+
PARSE_ACPI_HEADER (&AcpiHdrInfo),
33+
{ L"Platform Class", 2, 36, L"0x%x", NULL, NULL, NULL, NULL },
34+
{ L"Reserved", 2, 38, L"0x%x", NULL, NULL, NULL, NULL },
35+
{ L"Address of CRB Control Area",8, 40, L"0x%lx", NULL, NULL, NULL, NULL },
36+
{ L"Start Method", 4, 48, L"0x%x", NULL, (VOID **)&StartMethod, NULL, NULL }
37+
};
38+
39+
/**
40+
An ACPI_PARSER array describing the ACPI TPM 2.0 Table Log Area entries.
41+
**/
42+
STATIC CONST ACPI_PARSER Tpm2LogArea[] = {
43+
{ L"Log Area Minimum Length", 4, 0, L"0x%x", NULL, NULL, NULL, NULL },
44+
{ L"Log Area Start Address", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL }
45+
};
46+
47+
/**
48+
An ACPI_PARSER array describing the Start Method Specific Parameters for Arm SMC Start Method table.
49+
**/
50+
STATIC CONST ACPI_PARSER Tpm2StartMethodArmSmc[] = {
51+
{ L"Interrupt", 4, 0, L"0x%x", NULL, NULL, NULL, NULL },
52+
{ L"Flags", 1, 4, L"0x%x", NULL, NULL, NULL, NULL },
53+
{ L"Operation Flags", 1, 5, L"0x%x", NULL, NULL, NULL, NULL },
54+
{ L"Attributes", 1, 6, L"0x%x", NULL, NULL, NULL, NULL },
55+
{ L"Reserved", 1, 7, L"0x%x", NULL, NULL, NULL, NULL },
56+
{ L"SMC/HVC Function ID", 4, 8, L"0x%x", NULL, NULL, NULL, NULL },
57+
};
58+
59+
/**
60+
This function parses the ACPI TPM2 table.
61+
When trace is enabled this function parses the TPM2 table and
62+
traces the ACPI table fields.
63+
64+
This function also performs validation of the ACPI table fields.
65+
66+
@param [in] Trace If TRUE, trace the ACPI fields.
67+
@param [in] Ptr Pointer to the start of the buffer.
68+
@param [in] AcpiTableLength Length of the ACPI table.
69+
@param [in] AcpiTableRevision Revision of the ACPI table.
70+
**/
71+
VOID
72+
EFIAPI
73+
ParseAcpiTpm2 (
74+
IN BOOLEAN Trace,
75+
IN UINT8 *Ptr,
76+
IN UINT32 AcpiTableLength,
77+
IN UINT8 AcpiTableRevision
78+
)
79+
{
80+
UINT32 Offset;
81+
BOOLEAN LogAreaPresent;
82+
83+
if (!Trace) {
84+
return;
85+
}
86+
87+
Offset = ParseAcpi (
88+
TRUE,
89+
0,
90+
"TPM2",
91+
Ptr,
92+
AcpiTableLength,
93+
PARSER_PARAMS (Tpm2Parser)
94+
);
95+
96+
// Log area parameters are optional. Presence is determined by table length.
97+
LogAreaPresent = (*AcpiHdrInfo.Revision == EFI_TPM2_ACPI_TABLE_REVISION_4 && AcpiTableLength == TPM2_ACPI_TABLE_SIZE_WITH_LOG_AREA_REVISION_4) ||
98+
(*AcpiHdrInfo.Revision == EFI_TPM2_ACPI_TABLE_REVISION_5 && AcpiTableLength == TPM2_ACPI_TABLE_SIZE_WITH_LOG_AREA_REVISION_5);
99+
100+
switch (*StartMethod) {
101+
case EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE_WITH_SMC:
102+
ParseAcpi (
103+
TRUE,
104+
0,
105+
"Start Method Specific Parameters for Arm SMC",
106+
Ptr + Offset,
107+
AcpiTableLength - Offset,
108+
PARSER_PARAMS (Tpm2StartMethodArmSmc)
109+
);
110+
break;
111+
112+
default:
113+
Print (
114+
L"WARNING: Start Method %u not supported\n",
115+
*StartMethod
116+
);
117+
break;
118+
}
119+
120+
if (LogAreaPresent) {
121+
Offset += (*AcpiHdrInfo.Revision == EFI_TPM2_ACPI_TABLE_REVISION_4) ?
122+
EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_4 :
123+
EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_5;
124+
125+
ParseAcpi (
126+
TRUE,
127+
0,
128+
"TPM2 Log Area",
129+
Ptr + Offset,
130+
AcpiTableLength - Offset,
131+
PARSER_PARAMS (Tpm2LogArea)
132+
);
133+
}
134+
}

ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ ACPI_TABLE_PARSER ParserList[] = {
7878
{ EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE, ParseAcpiSpcr },
7979
{ EFI_ACPI_6_2_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE, ParseAcpiSrat },
8080
{ EFI_ACPI_6_2_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiSsdt },
81+
{ EFI_ACPI_6_5_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE, ParseAcpiTpm2 },
8182
{ EFI_ACPI_6_5_WINDOWS_SMM_SECURITY_MITIGATION_TABLE_SIGNATURE, ParseAcpiWsmt },
8283
{ EFI_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiXsdt }
8384
};

ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
Parsers/Spcr/SpcrParser.c
5858
Parsers/Srat/SratParser.c
5959
Parsers/Ssdt/SsdtParser.c
60+
Parsers/Tpm2/Tpm2Parser.c
6061
Parsers/Wsmt/WsmtParser.c
6162
Parsers/Xsdt/XsdtParser.c
6263
UefiShellAcpiViewCommandLib.c

0 commit comments

Comments
 (0)