summaryrefslogtreecommitdiff
path: root/SecurityPkg/Tcg/TrEEConfig/TpmDetection.c
diff options
context:
space:
mode:
Diffstat (limited to 'SecurityPkg/Tcg/TrEEConfig/TpmDetection.c')
-rw-r--r--SecurityPkg/Tcg/TrEEConfig/TpmDetection.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/SecurityPkg/Tcg/TrEEConfig/TpmDetection.c b/SecurityPkg/Tcg/TrEEConfig/TpmDetection.c
index b8aab1ffd..ce7a9a197 100644
--- a/SecurityPkg/Tcg/TrEEConfig/TpmDetection.c
+++ b/SecurityPkg/Tcg/TrEEConfig/TpmDetection.c
@@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <PiPei.h>
+#include <Ppi/ReadOnlyVariable2.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
@@ -64,25 +65,47 @@ DetectTpmDevice (
{
EFI_STATUS Status;
EFI_BOOT_MODE BootMode;
+ TREE_DEVICE_DETECTION TrEEDeviceDetection;
+ EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi;
+ UINTN Size;
+
+ if (PcdGetBool (PcdHideTpmSupport) && PcdGetBool (PcdHideTpm)) {
+ DEBUG ((EFI_D_ERROR, "DetectTpmDevice: Tpm is hide\n"));
+ return TPM_DEVICE_NULL;
+ }
Status = PeiServicesGetBootMode (&BootMode);
ASSERT_EFI_ERROR (Status);
//
- // In S3, we rely on Setup option, because we save to Setup in normal boot.
+ // In S3, we rely on normal boot Detection, because we save to ReadOnly Variable in normal boot.
//
if (BootMode == BOOT_ON_S3_RESUME) {
DEBUG ((EFI_D_ERROR, "DetectTpmDevice: S3 mode\n"));
- return SetupTpmDevice;
- }
- if (PcdGetBool (PcdHideTpmSupport) && PcdGetBool (PcdHideTpm)) {
- DEBUG ((EFI_D_ERROR, "DetectTpmDevice: Tpm is hide\n"));
- return TPM_DEVICE_NULL;
+ Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, (VOID **) &VariablePpi);
+ ASSERT_EFI_ERROR (Status);
+
+ Size = sizeof(TREE_DEVICE_DETECTION);
+ ZeroMem (&TrEEDeviceDetection, sizeof(TrEEDeviceDetection));
+ Status = VariablePpi->GetVariable (
+ VariablePpi,
+ TREE_DEVICE_DETECTION_NAME,
+ &gTrEEConfigFormSetGuid,
+ NULL,
+ &Size,
+ &TrEEDeviceDetection
+ );
+ if (!EFI_ERROR (Status) &&
+ (TrEEDeviceDetection.TpmDeviceDetected >= TPM_DEVICE_MIN) &&
+ (TrEEDeviceDetection.TpmDeviceDetected <= TPM_DEVICE_MAX)) {
+ DEBUG ((EFI_D_ERROR, "TpmDevice from DeviceDetection: %x\n", TrEEDeviceDetection.TpmDeviceDetected));
+ return TrEEDeviceDetection.TpmDeviceDetected;
+ }
}
DEBUG ((EFI_D_ERROR, "DetectTpmDevice:\n"));
- if ((!IsDtpmPresent ()) || (SetupTpmDevice == TPM_DEVICE_NULL)) {
+ if (!IsDtpmPresent ()) {
// dTPM not available
return TPM_DEVICE_NULL;
}
@@ -96,7 +119,11 @@ DetectTpmDevice (
return TPM_DEVICE_2_0_DTPM;
}
- Status = Tpm12Startup (TPM_ST_CLEAR);
+ if (BootMode == BOOT_ON_S3_RESUME) {
+ Status = Tpm12Startup (TPM_ST_STATE);
+ } else {
+ Status = Tpm12Startup (TPM_ST_CLEAR);
+ }
if (EFI_ERROR (Status)) {
return TPM_DEVICE_2_0_DTPM;
}