Skip to content

Commit 0444e65

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 4b37b20 commit 0444e65

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>
@@ -20,6 +21,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
2021
#include <Guid/ImageAuthentication.h>
2122
#include <Guid/TpmInstance.h>
2223

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

4985
#define PERF_ID_TCG2_DXE 0x3120
5086

@@ -2710,6 +2746,106 @@ InstallTcg2 (
27102746
return Status;
27112747
}
27122748

2749+
/**
2750+
Publish TPM2 ACPI table
2751+
2752+
@retval EFI_SUCCESS The TPM2 ACPI table is published successfully.
2753+
@retval Others The TPM2 ACPI table is not published.
2754+
2755+
**/
2756+
EFI_STATUS
2757+
PublishTpm2 (
2758+
VOID
2759+
)
2760+
{
2761+
EFI_STATUS Status;
2762+
EFI_ACPI_TABLE_PROTOCOL *AcpiTable;
2763+
UINTN TableKey;
2764+
UINT64 OemTableId;
2765+
EFI_TPM2_ACPI_CONTROL_AREA *ControlArea;
2766+
TPM2_PTP_INTERFACE_TYPE InterfaceType;
2767+
2768+
//
2769+
// Measure to PCR[0] with event EV_POST_CODE ACPI DATA.
2770+
// The measurement has to be done before any update.
2771+
// Otherwise, the PCR record would be different after event log update
2772+
// or the PCD configuration change.
2773+
//
2774+
TpmMeasureAndLogData(
2775+
0,
2776+
EV_POST_CODE,
2777+
EV_POSTCODE_INFO_ACPI_DATA,
2778+
ACPI_DATA_LEN,
2779+
&mTpm2AcpiTemplate,
2780+
mTpm2AcpiTemplate.Header.Length
2781+
);
2782+
2783+
mTpm2AcpiTemplate.Header.Revision = PcdGet8(PcdTpm2AcpiTableRev);
2784+
DEBUG((DEBUG_INFO, "Tpm2 ACPI table revision is %d\n", mTpm2AcpiTemplate.Header.Revision));
2785+
2786+
//
2787+
// PlatformClass is only valid for version 4 and above
2788+
// BIT0~15: PlatformClass
2789+
// BIT16~31: Reserved
2790+
//
2791+
if (mTpm2AcpiTemplate.Header.Revision >= EFI_TPM2_ACPI_TABLE_REVISION_4) {
2792+
mTpm2AcpiTemplate.Flags = (mTpm2AcpiTemplate.Flags & 0xFFFF0000) | PcdGet8(PcdTpmPlatformClass);
2793+
DEBUG((DEBUG_INFO, "Tpm2 ACPI table PlatformClass is %d\n", (mTpm2AcpiTemplate.Flags & 0x0000FFFF)));
2794+
}
2795+
2796+
mTpm2AcpiTemplate.Laml = PcdGet32(PcdTpm2AcpiTableLaml);
2797+
mTpm2AcpiTemplate.Lasa = PcdGet64(PcdTpm2AcpiTableLasa);
2798+
if ((mTpm2AcpiTemplate.Header.Revision < EFI_TPM2_ACPI_TABLE_REVISION_4) ||
2799+
(mTpm2AcpiTemplate.Laml == 0) || (mTpm2AcpiTemplate.Lasa == 0)) {
2800+
//
2801+
// If version is smaller than 4 or Laml/Lasa is not valid, rollback to original Length.
2802+
//
2803+
mTpm2AcpiTemplate.Header.Length = sizeof(EFI_TPM2_ACPI_TABLE);
2804+
}
2805+
2806+
InterfaceType = PcdGet8(PcdActiveTpmInterfaceType);
2807+
switch (InterfaceType) {
2808+
case Tpm2PtpInterfaceCrb:
2809+
mTpm2AcpiTemplate.StartMethod = EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE;
2810+
mTpm2AcpiTemplate.AddressOfControlArea = PcdGet64 (PcdTpmBaseAddress) + 0x40;
2811+
ControlArea = (EFI_TPM2_ACPI_CONTROL_AREA *)(UINTN)mTpm2AcpiTemplate.AddressOfControlArea;
2812+
ControlArea->CommandSize = 0xF80;
2813+
ControlArea->ResponseSize = 0xF80;
2814+
ControlArea->Command = PcdGet64 (PcdTpmBaseAddress) + 0x80;
2815+
ControlArea->Response = PcdGet64 (PcdTpmBaseAddress) + 0x80;
2816+
break;
2817+
case Tpm2PtpInterfaceFifo:
2818+
case Tpm2PtpInterfaceTis:
2819+
break;
2820+
default:
2821+
DEBUG((EFI_D_ERROR, "TPM2 InterfaceType get error! %d\n", InterfaceType));
2822+
break;
2823+
}
2824+
2825+
CopyMem (mTpm2AcpiTemplate.Header.OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (mTpm2AcpiTemplate.Header.OemId));
2826+
OemTableId = PcdGet64 (PcdAcpiDefaultOemTableId);
2827+
CopyMem (&mTpm2AcpiTemplate.Header.OemTableId, &OemTableId, sizeof (UINT64));
2828+
mTpm2AcpiTemplate.Header.OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
2829+
mTpm2AcpiTemplate.Header.CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
2830+
mTpm2AcpiTemplate.Header.CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
2831+
2832+
//
2833+
// Construct ACPI table
2834+
//
2835+
Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **) &AcpiTable);
2836+
ASSERT_EFI_ERROR (Status);
2837+
2838+
Status = AcpiTable->InstallAcpiTable (
2839+
AcpiTable,
2840+
&mTpm2AcpiTemplate,
2841+
mTpm2AcpiTemplate.Header.Length,
2842+
&TableKey
2843+
);
2844+
ASSERT_EFI_ERROR (Status);
2845+
2846+
return Status;
2847+
}
2848+
27132849
/**
27142850
The driver's entry point. It publishes EFI Tcg2 Protocol.
27152851
@@ -2895,5 +3031,11 @@ DriverEntry (
28953031
Status = InstallTcg2 ();
28963032
DEBUG ((DEBUG_INFO, "InstallTcg2 - %r\n", Status));
28973033

3034+
//
3035+
// Set TPM2 ACPI table
3036+
//
3037+
Status = PublishTpm2 ();
3038+
ASSERT_EFI_ERROR (Status);
3039+
28983040
return Status;
28993041
}

SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,14 @@
9696
gEfiMpServiceProtocolGuid ## SOMETIMES_CONSUMES
9797
gEfiVariableWriteArchProtocolGuid ## NOTIFY
9898
gEfiResetNotificationProtocolGuid ## CONSUMES
99+
gEfiAcpiTableProtocolGuid ## CONSUMES
99100

100101
[Pcd]
102+
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemId ## SOMETIMES_CONSUMES
103+
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId ## SOMETIMES_CONSUMES
104+
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision ## SOMETIMES_CONSUMES
105+
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId ## SOMETIMES_CONSUMES
106+
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision ## SOMETIMES_CONSUMES
101107
gEfiSecurityPkgTokenSpaceGuid.PcdTpmPlatformClass ## SOMETIMES_CONSUMES
102108
gEfiSecurityPkgTokenSpaceGuid.PcdFirmwareDebuggerInitialized ## SOMETIMES_CONSUMES
103109
gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid ## CONSUMES
@@ -110,8 +116,11 @@
110116
gEfiSecurityPkgTokenSpaceGuid.PcdTpm2AcpiTableLaml ## PRODUCES
111117
gEfiSecurityPkgTokenSpaceGuid.PcdTpm2AcpiTableLasa ## PRODUCES
112118
gEfiMdeModulePkgTokenSpaceGuid.PcdTcgPfpMeasurementRevision ## CONSUMES
119+
gEfiSecurityPkgTokenSpaceGuid.PcdActiveTpmInterfaceType ## CONSUMES
120+
gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## CONSUMES
113121

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

0 commit comments

Comments
 (0)