Skip to content

Commit 83a276f

Browse files
jyao1jyao1
authored andcommitted
Add TpmInitializationDonePpi to TPM PEI module.
This PPI will always be installed to notify other drivers that TPM initialization action is done. TPM initialization may success or fail, or even not present. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: "Yao, Jiewen" <jiewen.yao@intel.com> Reviewed-by: "Dong, Guo" <guo.dong@intel.com> Reviewed-by: "Chiu, Chasel" <chasel.chiu@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16638 6f19259b-4bc3-4df7-8a09-765794883524
1 parent 57ce74a commit 83a276f

File tree

8 files changed

+90
-25
lines changed

8 files changed

+90
-25
lines changed

SecurityPkg/Include/Ppi/TpmInitialized.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
initialized. PEIMs that must execute after TPM hardware initialization
44
may use this GUID in their dependency expressions.
55
6-
Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
6+
Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.<BR>
77
This program and the accompanying materials
88
are licensed and made available under the terms and conditions of the BSD License
99
which accompanies this distribution. The full text of the license may be found at
@@ -27,4 +27,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
2727

2828
extern EFI_GUID gPeiTpmInitializedPpiGuid;
2929

30+
///
31+
/// Global ID for the PEI_TPM_INITIALIZATION_DONE_PPI which always uses a NULL interface.
32+
///
33+
#define PEI_TPM_INITIALIZATION_DONE_PPI_GUID \
34+
{ \
35+
0xa030d115, 0x54dd, 0x447b, { 0x90, 0x64, 0xf2, 0x6, 0x88, 0x3d, 0x7c, 0xcc \
36+
}
37+
38+
extern EFI_GUID gPeiTpmInitializationDonePpiGuid;
39+
3040
#endif

SecurityPkg/SecurityPkg.dec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@
181181
# Include/Ppi/TpmInitialized.h
182182
gPeiTpmInitializedPpiGuid = { 0xe9db0d58, 0xd48d, 0x47f6, { 0x9c, 0x6e, 0x6f, 0x40, 0xe8, 0x6c, 0x7b, 0x41 }}
183183

184+
## The PPI GUID for that TPM initialization is done. TPM initialization may be success or fail.
185+
# Include/Ppi/TpmInitialized.h
186+
gPeiTpmInitializationDonePpiGuid = { 0xa030d115, 0x54dd, 0x447b, { 0x90, 0x64, 0xf2, 0x6, 0x88, 0x3d, 0x7c, 0xcc }}
187+
184188
## Include/Ppi/FirmwareVolumeInfoMeasurementExcluded.h
185189
gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid = { 0x6e056ff9, 0xc695, 0x4364, { 0x9e, 0x2c, 0x61, 0x26, 0xf5, 0xce, 0xea, 0xae } }
186190

SecurityPkg/Tcg/TcgPei/TcgPei.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ EFI_PEI_PPI_DESCRIPTOR mTpmInitializedPpiList = {
5050
NULL
5151
};
5252

53+
EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {
54+
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
55+
&gPeiTpmInitializationDonePpiGuid,
56+
NULL
57+
};
58+
5359
EFI_PLATFORM_FIRMWARE_BLOB *mMeasuredBaseFvInfo;
5460
UINT32 mMeasuredBaseFvIndex = 0;
5561

@@ -737,6 +743,7 @@ PeimEntryMA (
737743
)
738744
{
739745
EFI_STATUS Status;
746+
EFI_STATUS Status2;
740747
EFI_BOOT_MODE BootMode;
741748
TIS_TPM_HANDLE TpmHandle;
742749

@@ -768,13 +775,13 @@ PeimEntryMA (
768775
Status = TisPcRequestUseTpm ((TIS_PC_REGISTERS_PTR)TpmHandle);
769776
if (EFI_ERROR (Status)) {
770777
DEBUG ((DEBUG_ERROR, "TPM not detected!\n"));
771-
return Status;
778+
goto Done;
772779
}
773780

774781
if (PcdGet8 (PcdTpmInitializationPolicy) == 1) {
775782
Status = TpmCommStartup ((EFI_PEI_SERVICES**)PeiServices, TpmHandle, BootMode);
776783
if (EFI_ERROR (Status) ) {
777-
return Status;
784+
goto Done;
778785
}
779786
}
780787

@@ -784,20 +791,29 @@ PeimEntryMA (
784791
if (BootMode != BOOT_ON_S3_RESUME) {
785792
Status = TpmCommContinueSelfTest ((EFI_PEI_SERVICES**)PeiServices, TpmHandle);
786793
if (EFI_ERROR (Status)) {
787-
return Status;
794+
goto Done;
788795
}
789796
}
790797

798+
//
799+
// Only intall TpmInitializedPpi on success
800+
//
791801
Status = PeiServicesInstallPpi (&mTpmInitializedPpiList);
792802
ASSERT_EFI_ERROR (Status);
793803
}
794804

795805
if (mImageInMemory) {
796806
Status = PeimEntryMP ((EFI_PEI_SERVICES**)PeiServices);
797-
if (EFI_ERROR (Status)) {
798-
return Status;
799-
}
807+
return Status;
800808
}
801809

810+
Done:
811+
//
812+
// Always intall TpmInitializationDonePpi no matter success or fail.
813+
// Other driver can know TPM initialization state by TpmInitializedPpi.
814+
//
815+
Status2 = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);
816+
ASSERT_EFI_ERROR (Status2);
817+
802818
return Status;
803819
}

SecurityPkg/Tcg/TcgPei/TcgPei.inf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
gEfiPeiFirmwareVolumeInfoPpiGuid ## SOMETIMES_CONSUMES ## NOTIFY
7070
gEfiPeiFirmwareVolumeInfo2PpiGuid ## SOMETIMES_CONSUMES ## NOTIFY
7171
gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid ## SOMETIMES_CONSUMES
72-
gPeiTpmInitializedPpiGuid ## PRODUCES
72+
gPeiTpmInitializedPpiGuid ## SOMETIMES_PRODUCES
73+
gPeiTpmInitializationDonePpiGuid ## PRODUCES
7374
gEfiEndOfPeiSignalPpiGuid ## SOMETIMES_CONSUMES ## NOTIFY
7475

7576
[Pcd]

SecurityPkg/Tcg/TrEEConfig/TrEEConfigPei.inf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This module initializes TPM device type based on variable and detection.
55
# NOTE: This module is only for reference only, each platform should have its own setup page.
66
#
7-
# Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
7+
# Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>
88
# This program and the accompanying materials
99
# are licensed and made available under the terms and conditions of the BSD License
1010
# which accompanies this distribution. The full text of the license may be found at
@@ -58,9 +58,11 @@
5858
## SOMETIMES_CONSUMES ## Variable:L"TREE_DEVICE_DETECTION"
5959
gTrEEConfigFormSetGuid
6060
gEfiTpmDeviceSelectedGuid ## PRODUCES ## GUID # Used as a PPI GUID
61+
gEfiTpmDeviceInstanceNoneGuid ## SOMETIMES_CONSUMES ## GUID # TPM device identifier
6162

6263
[Ppis]
6364
gEfiPeiReadOnlyVariable2PpiGuid ## CONSUMES
65+
gPeiTpmInitializationDonePpiGuid ## SOMETIMES_PRODUCES
6466

6567
[Pcd]
6668
gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid ## PRODUCES

SecurityPkg/Tcg/TrEEConfig/TrEEConfigPeim.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @file
22
The module entry point for TrEE configuration module.
33
4-
Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
4+
Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>
55
This program and the accompanying materials
66
are licensed and made available under the terms and conditions of the BSD License
77
which accompanies this distribution. The full text of the license may be found at
@@ -25,6 +25,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
2525
#include <Library/PcdLib.h>
2626

2727
#include <Ppi/ReadOnlyVariable2.h>
28+
#include <Ppi/TpmInitialized.h>
2829
#include <Protocol/TrEEProtocol.h>
2930

3031
#include "TrEEConfigNvData.h"
@@ -37,6 +38,12 @@ CONST EFI_PEI_PPI_DESCRIPTOR gTpmSelectedPpi = {
3738
NULL
3839
};
3940

41+
EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {
42+
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
43+
&gPeiTpmInitializationDonePpiGuid,
44+
NULL
45+
};
46+
4047
/**
4148
This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration.
4249
@@ -67,6 +74,7 @@ TrEEConfigPeimEntryPoint (
6774
{
6875
UINTN Size;
6976
EFI_STATUS Status;
77+
EFI_STATUS Status2;
7078
EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi;
7179
TREE_CONFIGURATION TrEEConfiguration;
7280
UINTN Index;
@@ -136,5 +144,15 @@ TrEEConfigPeimEntryPoint (
136144
Status = PeiServicesInstallPpi (&gTpmSelectedPpi);
137145
ASSERT_EFI_ERROR (Status);
138146

147+
//
148+
// Even if no TPM is selected or detected, we still need intall TpmInitializationDonePpi.
149+
// Because TcgPei or TrEEPei will not run, but we still need a way to notify other driver.
150+
// Other driver can know TPM initialization state by TpmInitializedPpi.
151+
//
152+
if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceNoneGuid)) {
153+
Status2 = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);
154+
ASSERT_EFI_ERROR (Status2);
155+
}
156+
139157
return Status;
140158
}

SecurityPkg/Tcg/TrEEPei/TrEEPei.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ EFI_PEI_PPI_DESCRIPTOR mTpmInitializedPpiList = {
6262
NULL
6363
};
6464

65+
EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {
66+
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
67+
&gPeiTpmInitializationDonePpiGuid,
68+
NULL
69+
};
70+
6571
EFI_PLATFORM_FIRMWARE_BLOB *mMeasuredBaseFvInfo;
6672
UINT32 mMeasuredBaseFvIndex = 0;
6773

@@ -621,6 +627,7 @@ PeimEntryMA (
621627
)
622628
{
623629
EFI_STATUS Status;
630+
EFI_STATUS Status2;
624631
EFI_BOOT_MODE BootMode;
625632

626633
if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceNoneGuid) ||
@@ -629,15 +636,6 @@ PeimEntryMA (
629636
return EFI_UNSUPPORTED;
630637
}
631638

632-
//
633-
// Update for Performance optimization
634-
//
635-
Status = Tpm2RequestUseTpm ();
636-
if (EFI_ERROR (Status)) {
637-
DEBUG ((DEBUG_ERROR, "TPM not detected!\n"));
638-
return Status;
639-
}
640-
641639
Status = PeiServicesGetBootMode (&BootMode);
642640
ASSERT_EFI_ERROR (Status);
643641

@@ -658,6 +656,12 @@ PeimEntryMA (
658656
//
659657
// Initialize TPM device
660658
//
659+
Status = Tpm2RequestUseTpm ();
660+
if (EFI_ERROR (Status)) {
661+
DEBUG ((DEBUG_ERROR, "TPM2 not detected!\n"));
662+
goto Done;
663+
}
664+
661665
if (PcdGet8 (PcdTpm2InitializationPolicy) == 1) {
662666
if (BootMode == BOOT_ON_S3_RESUME) {
663667
Status = Tpm2Startup (TPM_SU_STATE);
@@ -668,7 +672,7 @@ PeimEntryMA (
668672
Status = Tpm2Startup (TPM_SU_CLEAR);
669673
}
670674
if (EFI_ERROR (Status) ) {
671-
return Status;
675+
goto Done;
672676
}
673677
}
674678

@@ -679,21 +683,30 @@ PeimEntryMA (
679683
if (PcdGet8 (PcdTpm2SelfTestPolicy) == 1) {
680684
Status = Tpm2SelfTest (NO);
681685
if (EFI_ERROR (Status)) {
682-
return Status;
686+
goto Done;
683687
}
684688
}
685689
}
686690

691+
//
692+
// Only intall TpmInitializedPpi on success
693+
//
687694
Status = PeiServicesInstallPpi (&mTpmInitializedPpiList);
688695
ASSERT_EFI_ERROR (Status);
689696
}
690697

691698
if (mImageInMemory) {
692699
Status = PeimEntryMP ((EFI_PEI_SERVICES**)PeiServices);
693-
if (EFI_ERROR (Status)) {
694-
return Status;
695-
}
700+
return Status;
696701
}
697702

703+
Done:
704+
//
705+
// Always intall TpmInitializationDonePpi no matter success or fail.
706+
// Other driver can know TPM initialization state by TpmInitializedPpi.
707+
//
708+
Status2 = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);
709+
ASSERT_EFI_ERROR (Status2);
710+
698711
return Status;
699712
}

SecurityPkg/Tcg/TrEEPei/TrEEPei.inf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
gEfiPeiFirmwareVolumeInfoPpiGuid ## SOMETIMES_CONSUMES ## NOTIFY
6565
gEfiPeiFirmwareVolumeInfo2PpiGuid ## SOMETIMES_CONSUMES ## NOTIFY
6666
gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid ## SOMETIMES_CONSUMES
67-
gPeiTpmInitializedPpiGuid ## PRODUCES
67+
gPeiTpmInitializedPpiGuid ## SOMETIMES_PRODUCES
68+
gPeiTpmInitializationDonePpiGuid ## PRODUCES
6869
gEfiEndOfPeiSignalPpiGuid ## SOMETIMES_CONSUMES ## NOTIFY
6970

7071
[Pcd]

0 commit comments

Comments
 (0)