Skip to content

Commit 2707989

Browse files
committed
SecurityPkg: publish TPM2 event log in ACPI
Basically a copy&paste from Tcg2Smm. Intentionally not making any changes (like dropping use of PCDs to pass data) beyond what's necessary to make it work. No need for an analogous change for TPM1 because TcgDxe already publishes the log. Signed-off-by: Sergii Dmytruk <[email protected]>
1 parent f22d8c4 commit 2707989

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
1111
#include <IndustryStandard/Acpi.h>
1212
#include <IndustryStandard/PeImage.h>
1313
#include <IndustryStandard/TcpaAcpi.h>
14+
#include <IndustryStandard/Tpm2Acpi.h>
1415

1516
#include <Guid/GlobalVariable.h>
1617
#include <Guid/HobList.h>
@@ -21,6 +22,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
2122
#include <Guid/TpmInstance.h>
2223
#include <Guid/DeviceAuthentication.h>
2324

25+
#include <Protocol/AcpiTable.h>
2426
#include <Protocol/DevicePath.h>
2527
#include <Protocol/MpService.h>
2628
#include <Protocol/VariableWrite.h>
@@ -46,6 +48,40 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
4648
#include <Library/ReportStatusCodeLib.h>
4749
#include <Library/Tcg2PhysicalPresenceLib.h>
4850
#include <Library/DasharoVariablesLib.h>
51+
#include <Library/TpmMeasurementLib.h>
52+
53+
#pragma pack(1)
54+
55+
typedef struct {
56+
EFI_ACPI_DESCRIPTION_HEADER Header;
57+
// Flags field is replaced in version 4 and above
58+
// BIT0~15: PlatformClass This field is only valid for version 4 and above
59+
// BIT16~31: Reserved
60+
UINT32 Flags;
61+
UINT64 AddressOfControlArea;
62+
UINT32 StartMethod;
63+
UINT8 PlatformSpecificParameters[12]; // size up to 12
64+
UINT32 Laml; // Optional
65+
UINT64 Lasa; // Optional
66+
} EFI_TPM2_ACPI_TABLE_V4;
67+
68+
EFI_TPM2_ACPI_TABLE_V4 mTpm2AcpiTemplate = {
69+
{
70+
EFI_ACPI_5_0_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE,
71+
sizeof (mTpm2AcpiTemplate),
72+
EFI_TPM2_ACPI_TABLE_REVISION,
73+
//
74+
// Compiler initializes the remaining bytes to 0
75+
// These fields should be filled in in production
76+
//
77+
},
78+
0, // BIT0~15: PlatformClass
79+
// BIT16~31: Reserved
80+
0, // Control Area
81+
EFI_TPM2_ACPI_TABLE_START_METHOD_TIS, // StartMethod
82+
};
83+
84+
#pragma pack()
4985

5086
#define PERF_ID_TCG2_DXE 0x3120
5187

@@ -2773,6 +2809,106 @@ InstallTcg2 (
27732809
return Status;
27742810
}
27752811

2812+
/**
2813+
Publish TPM2 ACPI table
2814+
2815+
@retval EFI_SUCCESS The TPM2 ACPI table is published successfully.
2816+
@retval Others The TPM2 ACPI table is not published.
2817+
2818+
**/
2819+
EFI_STATUS
2820+
PublishTpm2 (
2821+
VOID
2822+
)
2823+
{
2824+
EFI_STATUS Status;
2825+
EFI_ACPI_TABLE_PROTOCOL *AcpiTable;
2826+
UINTN TableKey;
2827+
UINT64 OemTableId;
2828+
EFI_TPM2_ACPI_CONTROL_AREA *ControlArea;
2829+
TPM2_PTP_INTERFACE_TYPE InterfaceType;
2830+
2831+
//
2832+
// Measure to PCR[0] with event EV_POST_CODE ACPI DATA.
2833+
// The measurement has to be done before any update.
2834+
// Otherwise, the PCR record would be different after event log update
2835+
// or the PCD configuration change.
2836+
//
2837+
TpmMeasureAndLogData(
2838+
0,
2839+
EV_POST_CODE,
2840+
EV_POSTCODE_INFO_ACPI_DATA,
2841+
ACPI_DATA_LEN,
2842+
&mTpm2AcpiTemplate,
2843+
mTpm2AcpiTemplate.Header.Length
2844+
);
2845+
2846+
mTpm2AcpiTemplate.Header.Revision = PcdGet8(PcdTpm2AcpiTableRev);
2847+
DEBUG((DEBUG_INFO, "Tpm2 ACPI table revision is %d\n", mTpm2AcpiTemplate.Header.Revision));
2848+
2849+
//
2850+
// PlatformClass is only valid for version 4 and above
2851+
// BIT0~15: PlatformClass
2852+
// BIT16~31: Reserved
2853+
//
2854+
if (mTpm2AcpiTemplate.Header.Revision >= EFI_TPM2_ACPI_TABLE_REVISION_4) {
2855+
mTpm2AcpiTemplate.Flags = (mTpm2AcpiTemplate.Flags & 0xFFFF0000) | PcdGet8(PcdTpmPlatformClass);
2856+
DEBUG((DEBUG_INFO, "Tpm2 ACPI table PlatformClass is %d\n", (mTpm2AcpiTemplate.Flags & 0x0000FFFF)));
2857+
}
2858+
2859+
mTpm2AcpiTemplate.Laml = PcdGet32(PcdTpm2AcpiTableLaml);
2860+
mTpm2AcpiTemplate.Lasa = PcdGet64(PcdTpm2AcpiTableLasa);
2861+
if ((mTpm2AcpiTemplate.Header.Revision < EFI_TPM2_ACPI_TABLE_REVISION_4) ||
2862+
(mTpm2AcpiTemplate.Laml == 0) || (mTpm2AcpiTemplate.Lasa == 0)) {
2863+
//
2864+
// If version is smaller than 4 or Laml/Lasa is not valid, rollback to original Length.
2865+
//
2866+
mTpm2AcpiTemplate.Header.Length = sizeof(EFI_TPM2_ACPI_TABLE);
2867+
}
2868+
2869+
InterfaceType = PcdGet8(PcdActiveTpmInterfaceType);
2870+
switch (InterfaceType) {
2871+
case Tpm2PtpInterfaceCrb:
2872+
mTpm2AcpiTemplate.StartMethod = EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE;
2873+
mTpm2AcpiTemplate.AddressOfControlArea = PcdGet64 (PcdTpmBaseAddress) + 0x40;
2874+
ControlArea = (EFI_TPM2_ACPI_CONTROL_AREA *)(UINTN)mTpm2AcpiTemplate.AddressOfControlArea;
2875+
ControlArea->CommandSize = 0xF80;
2876+
ControlArea->ResponseSize = 0xF80;
2877+
ControlArea->Command = PcdGet64 (PcdTpmBaseAddress) + 0x80;
2878+
ControlArea->Response = PcdGet64 (PcdTpmBaseAddress) + 0x80;
2879+
break;
2880+
case Tpm2PtpInterfaceFifo:
2881+
case Tpm2PtpInterfaceTis:
2882+
break;
2883+
default:
2884+
DEBUG((EFI_D_ERROR, "TPM2 InterfaceType get error! %d\n", InterfaceType));
2885+
break;
2886+
}
2887+
2888+
CopyMem (mTpm2AcpiTemplate.Header.OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (mTpm2AcpiTemplate.Header.OemId));
2889+
OemTableId = PcdGet64 (PcdAcpiDefaultOemTableId);
2890+
CopyMem (&mTpm2AcpiTemplate.Header.OemTableId, &OemTableId, sizeof (UINT64));
2891+
mTpm2AcpiTemplate.Header.OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
2892+
mTpm2AcpiTemplate.Header.CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
2893+
mTpm2AcpiTemplate.Header.CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
2894+
2895+
//
2896+
// Construct ACPI table
2897+
//
2898+
Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **) &AcpiTable);
2899+
ASSERT_EFI_ERROR (Status);
2900+
2901+
Status = AcpiTable->InstallAcpiTable (
2902+
AcpiTable,
2903+
&mTpm2AcpiTemplate,
2904+
mTpm2AcpiTemplate.Header.Length,
2905+
&TableKey
2906+
);
2907+
ASSERT_EFI_ERROR (Status);
2908+
2909+
return Status;
2910+
}
2911+
27762912
/**
27772913
The driver's entry point. It publishes EFI Tcg2 Protocol.
27782914
@@ -2958,5 +3094,11 @@ DriverEntry (
29583094
Status = InstallTcg2 ();
29593095
DEBUG ((DEBUG_INFO, "InstallTcg2 - %r\n", Status));
29603096

3097+
//
3098+
// Set TPM2 ACPI table
3099+
//
3100+
Status = PublishTpm2 ();
3101+
ASSERT_EFI_ERROR (Status);
3102+
29613103
return Status;
29623104
}

SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,14 @@
9797
gEfiMpServiceProtocolGuid ## SOMETIMES_CONSUMES
9898
gEfiVariableWriteArchProtocolGuid ## NOTIFY
9999
gEfiResetNotificationProtocolGuid ## CONSUMES
100+
gEfiAcpiTableProtocolGuid ## CONSUMES
100101

101102
[Pcd]
103+
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemId ## SOMETIMES_CONSUMES
104+
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId ## SOMETIMES_CONSUMES
105+
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision ## SOMETIMES_CONSUMES
106+
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId ## SOMETIMES_CONSUMES
107+
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision ## SOMETIMES_CONSUMES
102108
gEfiSecurityPkgTokenSpaceGuid.PcdTpmPlatformClass ## SOMETIMES_CONSUMES
103109
gEfiSecurityPkgTokenSpaceGuid.PcdFirmwareDebuggerInitialized ## SOMETIMES_CONSUMES
104110
gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid ## CONSUMES
@@ -112,8 +118,11 @@
112118
gEfiSecurityPkgTokenSpaceGuid.PcdTpm2AcpiTableLasa ## PRODUCES
113119
gEfiMdeModulePkgTokenSpaceGuid.PcdTcgPfpMeasurementRevision ## CONSUMES
114120
gEfiMdeModulePkgTokenSpaceGuid.PcdEnableSpdmDeviceAuthentication ## CONSUMES
121+
gEfiSecurityPkgTokenSpaceGuid.PcdActiveTpmInterfaceType ## CONSUMES
122+
gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## CONSUMES
115123

116124
[Depex]
125+
gEfiAcpiTableProtocolGuid AND
117126
# According to PcdTpm2AcpiTableRev definition in SecurityPkg.dec
118127
# This PCD should be configured at DynamicHii or DynamicHiiEx.
119128
# So, this PCD read operation depends on GetVariable service.

0 commit comments

Comments
 (0)