From 3dd05ac3e6a047cd0e85f590a9886a8cd4fd7a16 Mon Sep 17 00:00:00 2001 From: "Yao, Jiewen" Date: Wed, 4 Mar 2015 01:15:08 +0000 Subject: [PATCH] Add performance optimization for Tcg/TrEE. Add error check for Tcg/TrEE Pei/Dxe driver to avoid unnecessary hardware check for performance optimization. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: "Yao, Jiewen" Reviewed-by: "Zeng, Star" git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17004 6f19259b-4bc3-4df7-8a09-765794883524 --- SecurityPkg/SecurityPkg.dec | 1 + SecurityPkg/Tcg/TcgDxe/TcgDxe.c | 9 +++++---- SecurityPkg/Tcg/TcgPei/TcgPei.c | 13 +++++++++++++ SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c | 11 ++++++----- SecurityPkg/Tcg/TrEEPei/TrEEPei.c | 13 +++++++++++++ 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/SecurityPkg/SecurityPkg.dec b/SecurityPkg/SecurityPkg.dec index b15cd62401..11c1d84dc7 100644 --- a/SecurityPkg/SecurityPkg.dec +++ b/SecurityPkg/SecurityPkg.dec @@ -192,6 +192,7 @@ # [Error.gEfiSecurityPkgTokenSpaceGuid] # 0x80000001 | Invalid value provided. # 0x80000002 | Reserved bits must be set to zero. +# 0x80000003 | Incorrect progress or error code provided. # [PcdsFixedAtBuild, PcdsPatchableInModule] diff --git a/SecurityPkg/Tcg/TcgDxe/TcgDxe.c b/SecurityPkg/Tcg/TcgDxe/TcgDxe.c index db7951cd9a..f15e94353c 100644 --- a/SecurityPkg/Tcg/TcgDxe/TcgDxe.c +++ b/SecurityPkg/Tcg/TcgDxe/TcgDxe.c @@ -1355,6 +1355,11 @@ DriverEntry ( return EFI_UNSUPPORTED; } + if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) { + DEBUG ((EFI_D_ERROR, "TPM error!\n")); + return EFI_DEVICE_ERROR; + } + mTcgDxeData.TpmHandle = (TIS_TPM_HANDLE)(UINTN)TPM_BASE_ADDRESS; Status = TisPcRequestUseTpm (mTcgDxeData.TpmHandle); if (EFI_ERROR (Status)) { @@ -1362,10 +1367,6 @@ DriverEntry ( return Status; } - if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) { - mTcgDxeData.BsCap.TPMPresentFlag = FALSE; - } - Status = GetTpmStatus (&mTcgDxeData.BsCap.TPMDeactivatedFlag); if (EFI_ERROR (Status)) { DEBUG (( diff --git a/SecurityPkg/Tcg/TcgPei/TcgPei.c b/SecurityPkg/Tcg/TcgPei/TcgPei.c index 466caf66c2..419eacf37d 100644 --- a/SecurityPkg/Tcg/TcgPei/TcgPei.c +++ b/SecurityPkg/Tcg/TcgPei/TcgPei.c @@ -752,6 +752,11 @@ PeimEntryMA ( return EFI_UNSUPPORTED; } + if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) { + DEBUG ((EFI_D_ERROR, "TPM error!\n")); + return EFI_DEVICE_ERROR; + } + // // Initialize TPM device // @@ -808,6 +813,14 @@ PeimEntryMA ( } Done: + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "TPM error! Build Hob\n")); + BuildGuidHob (&gTpmErrorHobGuid,0); + REPORT_STATUS_CODE ( + EFI_ERROR_CODE | EFI_ERROR_MINOR, + (PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR) + ); + } // // Always intall TpmInitializationDonePpi no matter success or fail. // Other driver can know TPM initialization state by TpmInitializedPpi. diff --git a/SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c b/SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c index 58c4aff819..6126bd8761 100644 --- a/SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c +++ b/SecurityPkg/Tcg/TrEEDxe/TrEEDxe.c @@ -1815,16 +1815,17 @@ DriverEntry ( return EFI_UNSUPPORTED; } + if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) { + DEBUG ((EFI_D_ERROR, "TPM2 error!\n")); + return EFI_DEVICE_ERROR; + } + Status = Tpm2RequestUseTpm (); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "TPM not detected!\n")); + DEBUG ((EFI_D_ERROR, "TPM2 not detected!\n")); return Status; } - if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) { - mTcgDxeData.BsCap.TrEEPresentFlag = FALSE; - } - // // Fill information // diff --git a/SecurityPkg/Tcg/TrEEPei/TrEEPei.c b/SecurityPkg/Tcg/TrEEPei/TrEEPei.c index a7bc903436..7a17b0a5da 100644 --- a/SecurityPkg/Tcg/TrEEPei/TrEEPei.c +++ b/SecurityPkg/Tcg/TrEEPei/TrEEPei.c @@ -636,6 +636,11 @@ PeimEntryMA ( return EFI_UNSUPPORTED; } + if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) { + DEBUG ((EFI_D_ERROR, "TPM2 error!\n")); + return EFI_DEVICE_ERROR; + } + Status = PeiServicesGetBootMode (&BootMode); ASSERT_EFI_ERROR (Status); @@ -701,6 +706,14 @@ PeimEntryMA ( } Done: + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "TPM2 error! Build Hob\n")); + BuildGuidHob (&gTpmErrorHobGuid,0); + REPORT_STATUS_CODE ( + EFI_ERROR_CODE | EFI_ERROR_MINOR, + (PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR) + ); + } // // Always intall TpmInitializationDonePpi no matter success or fail. // Other driver can know TPM initialization state by TpmInitializedPpi. -- 2.39.2