]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
SecurityPkg Tpm2DeviceLibDTpm: Update enum type name to match the one in lib
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibDTpm / Tpm2InstanceLibDTpm.c
index 3f28f21faa39f3bca68621043ebb173f3dd8d5d0..5f6e163c0f2ecddc4b4b81a2f2b35c03c7f81641 100644 (file)
@@ -3,7 +3,7 @@
   It can be registered to Tpm2 Device router, to be active TPM2 engine,\r
   based on platform setting.\r
 \r
-Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -18,9 +18,34 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/Tpm2DeviceLib.h>\r
+#include <Library/PcdLib.h>\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
+\r
 /**\r
   Dump PTP register information.\r
 \r
@@ -72,7 +97,7 @@ TPM2_DEVICE_INTERFACE  mDTpm2InternalTpm2Device = {
 };\r
 \r
 /**\r
-  The function register DTPM2.0 instance.\r
+  The function register DTPM2.0 instance and caches current active TPM interface type.\r
   \r
   @retval EFI_SUCCESS   DTPM2.0 instance is registered, or system dose not surpport registr DTPM2.0 instance\r
 **/\r
@@ -82,7 +107,9 @@ Tpm2InstanceLibDTpmConstructor (
   VOID\r
   )\r
 {\r
-  EFI_STATUS  Status;\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
@@ -90,6 +117,19 @@ Tpm2InstanceLibDTpmConstructor (
     // 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
       DumpPtpInfo ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
     }\r
     return EFI_SUCCESS;\r