#include <Library/Tpm2DeviceLib.h>\r
#include <Library/PcdLib.h>\r
\r
-/**\r
- Return PTP interface type.\r
-\r
- @param[in] Register Pointer to PTP register.\r
-\r
- @return PTP interface type.\r
-**/\r
-TPM2_PTP_INTERFACE_TYPE\r
-Tpm2GetPtpInterface (\r
- IN VOID *Register\r
- );\r
-\r
-/**\r
- Return PTP CRB interface IdleByPass state.\r
-\r
- @param[in] Register Pointer to PTP register.\r
-\r
- @return PTP CRB interface IdleByPass state.\r
-**/\r
-UINT8\r
-Tpm2GetIdleByPass (\r
- IN VOID *Register\r
- );\r
+#include "Tpm2DeviceLibDTpm.h"\r
\r
/**\r
This service enables the sending of commands to the TPM2.\r
VOID\r
)\r
{\r
- TPM2_PTP_INTERFACE_TYPE PtpInterface;\r
- UINT8 IdleByPass;\r
-\r
- //\r
- // Cache current active TpmInterfaceType only when needed\r
- //\r
- if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {\r
- PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
- PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);\r
- }\r
-\r
- if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {\r
- IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
- PcdSet8S(PcdCRBIdleByPass, IdleByPass);\r
- }\r
-\r
- return EFI_SUCCESS;\r
+ return InternalTpm2DeviceLibDTpmCommonConstructor ();\r
}\r
--- /dev/null
+/** @file\r
+ This header file includes common internal fuction prototypes.\r
+\r
+Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) Microsoft Corporation.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef _TPM2_DEVICE_LIB_DTPM_H_\r
+#define _TPM2_DEVICE_LIB_DTPM_H_\r
+\r
+/**\r
+ Return PTP interface type.\r
+\r
+ @param[in] Register Pointer to PTP register.\r
+\r
+ @return PTP interface type.\r
+**/\r
+TPM2_PTP_INTERFACE_TYPE\r
+Tpm2GetPtpInterface (\r
+ IN VOID *Register\r
+ );\r
+\r
+/**\r
+ Return PTP CRB interface IdleByPass state.\r
+\r
+ @param[in] Register Pointer to PTP register.\r
+\r
+ @return PTP CRB interface IdleByPass state.\r
+**/\r
+UINT8\r
+Tpm2GetIdleByPass (\r
+ IN VOID *Register\r
+ );\r
+\r
+/**\r
+ Return cached PTP interface type.\r
+\r
+ @return Cached PTP interface type.\r
+**/\r
+TPM2_PTP_INTERFACE_TYPE\r
+GetCachedPtpInterface (\r
+ VOID\r
+ );\r
+\r
+/**\r
+ Return cached PTP CRB interface IdleByPass state.\r
+\r
+ @return Cached PTP CRB interface IdleByPass state.\r
+**/\r
+UINT8\r
+GetCachedIdleByPass (\r
+ VOID\r
+ );\r
+\r
+/**\r
+ The common function cache current active TpmInterfaceType when needed.\r
+\r
+ @retval EFI_SUCCESS DTPM2.0 instance is registered, or system does not support register DTPM2.0 instance\r
+**/\r
+EFI_STATUS\r
+InternalTpm2DeviceLibDTpmCommonConstructor (\r
+ VOID\r
+ );\r
+\r
+#endif // _TPM2_DEVICE_LIB_DTPM_H_\r
# only uses TPM 2.0 DTPM device.\r
#\r
# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) Microsoft Corporation.\r
# SPDX-License-Identifier: BSD-2-Clause-Patent\r
#\r
##\r
Tpm2Tis.c\r
Tpm2Ptp.c\r
Tpm2DeviceLibDTpm.c\r
+ Tpm2DeviceLibDTpmBase.c\r
+ Tpm2DeviceLibDTpm.h\r
\r
[Packages]\r
MdePkg/MdePkg.dec\r
--- /dev/null
+/** @file\r
+ This file abstract internal interfaces of which implementation differs per library instance.\r
+\r
+Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) Microsoft Corporation.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Library/Tpm2DeviceLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#include "Tpm2DeviceLibDTpm.h"\r
+\r
+/**\r
+ Return cached PTP CRB interface IdleByPass state.\r
+\r
+ @return Cached PTP CRB interface IdleByPass state.\r
+**/\r
+UINT8\r
+GetCachedIdleByPass (\r
+ VOID\r
+ )\r
+{\r
+ return PcdGet8(PcdCRBIdleByPass);\r
+}\r
+\r
+/**\r
+ Return cached PTP interface type.\r
+\r
+ @return Cached PTP interface type.\r
+**/\r
+TPM2_PTP_INTERFACE_TYPE\r
+GetCachedPtpInterface (\r
+ VOID\r
+ )\r
+{\r
+ return PcdGet8(PcdActiveTpmInterfaceType);\r
+}\r
+\r
+/**\r
+ The common function cache current active TpmInterfaceType when needed.\r
+\r
+ @retval EFI_SUCCESS DTPM2.0 instance is registered, or system does not support register DTPM2.0 instance\r
+**/\r
+EFI_STATUS\r
+InternalTpm2DeviceLibDTpmCommonConstructor (\r
+ VOID\r
+ )\r
+{\r
+ TPM2_PTP_INTERFACE_TYPE PtpInterface;\r
+ UINT8 IdleByPass;\r
+\r
+ //\r
+ // Cache current active TpmInterfaceType only when needed\r
+ //\r
+ if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {\r
+ PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
+ PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);\r
+ }\r
+\r
+ if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {\r
+ IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
+ PcdSet8S(PcdCRBIdleByPass, IdleByPass);\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
--- /dev/null
+/** @file\r
+ This file abstract internal interfaces of which implementation differs per library instance.\r
+\r
+Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) Microsoft Corporation.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Library/Tpm2DeviceLib.h>\r
+\r
+#include "Tpm2DeviceLibDTpm.h"\r
+\r
+TPM2_PTP_INTERFACE_TYPE mActiveTpmInterfaceType;\r
+UINT8 mCRBIdleByPass;\r
+\r
+/**\r
+ Return cached PTP CRB interface IdleByPass state.\r
+\r
+ @return Cached PTP CRB interface IdleByPass state.\r
+**/\r
+UINT8\r
+GetCachedIdleByPass (\r
+ VOID\r
+ )\r
+{\r
+ return mCRBIdleByPass;\r
+}\r
+\r
+/**\r
+ Return cached PTP interface type.\r
+\r
+ @return Cached PTP interface type.\r
+**/\r
+TPM2_PTP_INTERFACE_TYPE\r
+GetCachedPtpInterface (\r
+ VOID\r
+ )\r
+{\r
+ return mActiveTpmInterfaceType;\r
+}\r
+\r
+/**\r
+ The common function cache current active TpmInterfaceType when needed.\r
+\r
+ @retval EFI_SUCCESS DTPM2.0 instance is registered, or system does not support register DTPM2.0 instance\r
+**/\r
+EFI_STATUS\r
+InternalTpm2DeviceLibDTpmCommonConstructor (\r
+ VOID\r
+ )\r
+{\r
+ mActiveTpmInterfaceType = 0xFF;\r
+ mCRBIdleByPass = 0xFF;\r
+\r
+ //\r
+ // Always cache current active TpmInterfaceType for StandaloneMm implementation\r
+ //\r
+ mActiveTpmInterfaceType = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
+\r
+ if (mActiveTpmInterfaceType == Tpm2PtpInterfaceCrb) {\r
+ mCRBIdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
--- /dev/null
+## @file\r
+# Provides TPM 2.0 TIS/PTP functions for DTPM\r
+#\r
+# Spec Compliance Info:\r
+# "TCG PC Client Platform TPM Profile(PTP) Specification Family 2.0 Level 00 Revision 00.43"\r
+# "TCG PC Client Specific TPM Interface Specification(TIS) Version 1.3"\r
+#\r
+# This library implements TIS (TPM Interface Specification) and\r
+# PTP (Platform TPM Profile) functions which is\r
+# used for every TPM 2.0 command. Choosing this library means platform uses and\r
+# only uses TPM 2.0 DTPM device.\r
+#\r
+# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) Microsoft Corporation.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = Tpm2DeviceLibDTpmStandaloneMm\r
+ FILE_GUID = 9A5DB21A-FF0B-46D0-8672-B4F83FEF1F0E\r
+ MODULE_TYPE = BASE\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = Tpm2DeviceLib|MM_STANDALONE\r
+ CONSTRUCTOR = Tpm2DeviceLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64\r
+#\r
+\r
+[Sources]\r
+ Tpm2Tis.c\r
+ Tpm2Ptp.c\r
+ Tpm2DeviceLibDTpm.c\r
+ Tpm2DeviceLibDTpmStandaloneMm.c\r
+ Tpm2DeviceLibDTpm.h\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ SecurityPkg/SecurityPkg.dec\r
+\r
+[LibraryClasses]\r
+ BaseLib\r
+ BaseMemoryLib\r
+ IoLib\r
+ TimerLib\r
+ DebugLib\r
+ PcdLib\r
+\r
+[Pcd]\r
+ gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## CONSUMES\r
\r
#include <Guid/TpmInstance.h>\r
\r
-/**\r
- Return PTP interface type.\r
-\r
- @param[in] Register Pointer to PTP register.\r
-\r
- @return PTP interface type.\r
-**/\r
-TPM2_PTP_INTERFACE_TYPE\r
-Tpm2GetPtpInterface (\r
- IN VOID *Register\r
- );\r
-\r
-/**\r
- Return PTP CRB interface IdleByPass state.\r
-\r
- @param[in] Register Pointer to PTP register.\r
-\r
- @return PTP CRB interface IdleByPass state.\r
-**/\r
-UINT8\r
-Tpm2GetIdleByPass (\r
- IN VOID *Register\r
- );\r
+#include "Tpm2DeviceLibDTpm.h"\r
\r
/**\r
Dump PTP register information.\r
)\r
{\r
EFI_STATUS Status;\r
- TPM2_PTP_INTERFACE_TYPE PtpInterface;\r
- UINT8 IdleByPass;\r
\r
Status = Tpm2RegisterTpm2DeviceLib (&mDTpm2InternalTpm2Device);\r
if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {\r
// Unsupported means platform policy does not need this instance enabled.\r
//\r
if (Status == EFI_SUCCESS) {\r
- //\r
- // Cache current active TpmInterfaceType only when needed\r
- //\r
- if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {\r
- PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
- PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);\r
- }\r
-\r
- if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {\r
- IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
- PcdSet8S(PcdCRBIdleByPass, IdleByPass);\r
- }\r
-\r
+ Status = InternalTpm2DeviceLibDTpmCommonConstructor ();\r
DumpPtpInfo ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
}\r
return EFI_SUCCESS;\r
# and PTP (Platform TPM Profile) functions.\r
#\r
# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) Microsoft Corporation\r
# SPDX-License-Identifier: BSD-2-Clause-Patent\r
#\r
##\r
Tpm2Tis.c\r
Tpm2Ptp.c\r
Tpm2InstanceLibDTpm.c\r
+ Tpm2DeviceLibDTpmBase.c\r
+ Tpm2DeviceLibDTpm.h\r
\r
[Packages]\r
MdePkg/MdePkg.dec\r
PTP (Platform TPM Profile) CRB (Command Response Buffer) interface used by dTPM2.0 library.\r
\r
Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c), Microsoft Corporation.\r
SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
#include <IndustryStandard/TpmPtp.h>\r
#include <IndustryStandard/TpmTis.h>\r
\r
+#include "Tpm2DeviceLibDTpm.h"\r
+\r
//\r
// Execution of the command may take from several seconds to minutes for certain\r
// commands, such as key generation.\r
// STEP 0:\r
// if CapCRbIdelByPass == 0, enforce Idle state before sending command\r
//\r
- if (PcdGet8(PcdCRBIdleByPass) == 0 && (MmioRead32((UINTN)&CrbReg->CrbControlStatus) & PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE) == 0){\r
+ if (GetCachedIdleByPass () == 0 && (MmioRead32((UINTN)&CrbReg->CrbControlStatus) & PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE) == 0){\r
Status = PtpCrbWaitRegisterBits (\r
&CrbReg->CrbControlStatus,\r
PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE,\r
// Goto Ready State if command is completed successfully and TPM support IdleBypass\r
// If not supported. flow down to GoIdle\r
//\r
- if (PcdGet8(PcdCRBIdleByPass) == 1) {\r
+ if (GetCachedIdleByPass () == 1) {\r
MmioWrite32((UINTN)&CrbReg->CrbControlRequest, PTP_CRB_CONTROL_AREA_REQUEST_COMMAND_READY);\r
return Status;\r
}\r
// Only enforce Idle state transition if execution fails when CRBIdleBypass==1\r
// Leave regular Idle delay at the beginning of next command execution\r
//\r
- if (PcdGet8(PcdCRBIdleByPass) == 1){\r
+ if (GetCachedIdleByPass () == 1){\r
Status = PtpCrbWaitRegisterBits (\r
&CrbReg->CrbControlStatus,\r
PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE,\r
Vid = 0xFFFF;\r
Did = 0xFFFF;\r
Rid = 0xFF;\r
- PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);\r
+ PtpInterface = GetCachedPtpInterface ();\r
DEBUG ((EFI_D_INFO, "PtpInterface - %x\n", PtpInterface));\r
switch (PtpInterface) {\r
case Tpm2PtpInterfaceCrb:\r
{\r
TPM2_PTP_INTERFACE_TYPE PtpInterface;\r
\r
- PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);\r
+ PtpInterface = GetCachedPtpInterface ();\r
switch (PtpInterface) {\r
case Tpm2PtpInterfaceCrb:\r
return PtpCrbTpmCommand (\r
{\r
TPM2_PTP_INTERFACE_TYPE PtpInterface;\r
\r
- PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);\r
+ PtpInterface = GetCachedPtpInterface ();\r
switch (PtpInterface) {\r
case Tpm2PtpInterfaceCrb:\r
return PtpCrbRequestUseTpm ((PTP_CRB_REGISTERS_PTR) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf\r
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf\r
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf\r
+ SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.inf\r
SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf\r
SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterPei.inf\r
\r