SecurityPkg: Cache TPM interface type info

Cache TPM interface type info to avoid excessive interface ID register read

Cc: Long Qin <qin.long@intel.com>
Cc: Yao Jiewen <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chao Zhang <chao.b.zhang@intel.com>
Reviewed-by: Long Qin <qin.long@intel.com>
This commit is contained in:
Zhang, Chao B
2018-05-08 14:51:57 +08:00
parent 796ef9da06
commit f15cb995bb
13 changed files with 148 additions and 145 deletions

View File

@@ -3,7 +3,7 @@
It can be registered to Tpm2 Device router, to be active TPM2 engine,
based on platform setting.
Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>
Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -18,9 +18,22 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/Tpm2DeviceLib.h>
#include <Library/PcdLib.h>
#include <Guid/TpmInstance.h>
/**
Return PTP interface type.
@param[in] Register Pointer to PTP register.
@return PTP interface type.
**/
TPM2_PTP_INTERFACE_TYPE
Tpm2GetPtpInterface (
IN VOID *Register
);
/**
Dump PTP register information.
@@ -72,7 +85,7 @@ TPM2_DEVICE_INTERFACE mDTpm2InternalTpm2Device = {
};
/**
The function register DTPM2.0 instance.
The function register DTPM2.0 instance and caches current active TPM interface type.
@retval EFI_SUCCESS DTPM2.0 instance is registered, or system dose not surpport registr DTPM2.0 instance
**/
@@ -82,7 +95,8 @@ Tpm2InstanceLibDTpmConstructor (
VOID
)
{
EFI_STATUS Status;
EFI_STATUS Status;
TPM2_PTP_INTERFACE_TYPE PtpInterface;
Status = Tpm2RegisterTpm2DeviceLib (&mDTpm2InternalTpm2Device);
if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {
@@ -90,6 +104,13 @@ Tpm2InstanceLibDTpmConstructor (
// Unsupported means platform policy does not need this instance enabled.
//
if (Status == EFI_SUCCESS) {
//
// Cache current active TpmInterfaceType only when needed
//
if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {
PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);
}
DumpPtpInfo ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
}
return EFI_SUCCESS;