@@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
11
11
#include <IndustryStandard/Acpi.h>
12
12
#include <IndustryStandard/PeImage.h>
13
13
#include <IndustryStandard/TcpaAcpi.h>
14
+ #include <IndustryStandard/Tpm2Acpi.h>
14
15
15
16
#include <Guid/GlobalVariable.h>
16
17
#include <Guid/HobList.h>
@@ -21,6 +22,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
21
22
#include <Guid/TpmInstance.h>
22
23
#include <Guid/DeviceAuthentication.h>
23
24
25
+ #include <Protocol/AcpiTable.h>
24
26
#include <Protocol/DevicePath.h>
25
27
#include <Protocol/MpService.h>
26
28
#include <Protocol/VariableWrite.h>
@@ -46,6 +48,40 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
46
48
#include <Library/ReportStatusCodeLib.h>
47
49
#include <Library/Tcg2PhysicalPresenceLib.h>
48
50
#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()
49
85
50
86
#define PERF_ID_TCG2_DXE 0x3120
51
87
@@ -2773,6 +2809,106 @@ InstallTcg2 (
2773
2809
return Status ;
2774
2810
}
2775
2811
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
+
2776
2912
/**
2777
2913
The driver's entry point. It publishes EFI Tcg2 Protocol.
2778
2914
@@ -2958,5 +3094,11 @@ DriverEntry (
2958
3094
Status = InstallTcg2 ();
2959
3095
DEBUG ((DEBUG_INFO , "InstallTcg2 - %r\n" , Status ));
2960
3096
3097
+ //
3098
+ // Set TPM2 ACPI table
3099
+ //
3100
+ Status = PublishTpm2 ();
3101
+ ASSERT_EFI_ERROR (Status );
3102
+
2961
3103
return Status ;
2962
3104
}
0 commit comments