]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
SecurityPkg: Cache TPM interface type info
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibDTpm / Tpm2DeviceLibDTpm.c
index 7d10dbbe47dba64e6f42bd925bb169641bb0d2cc..3feb64df7edfde5f1c0ac987f7e69018980818e6 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
-  Ihis library is TPM2 DTPM device lib.\r
+  This library is TPM2 DTPM device lib.\r
   Choosing this library means platform uses and only uses DTPM device as TPM2 engine.\r
 \r
-Copyright (c) 2013, 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
@@ -17,6 +17,19 @@ 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
+/**\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
   This service enables the sending of commands to the TPM2.\r
@@ -114,3 +127,26 @@ Tpm2RegisterTpm2DeviceLib (
 {\r
   return EFI_UNSUPPORTED;\r
 }\r
+\r
+/**\r
+  The function 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
+EFI_STATUS\r
+EFIAPI\r
+Tpm2DeviceLibConstructor (\r
+  VOID\r
+  )\r
+{\r
+  TPM2_PTP_INTERFACE_TYPE  PtpInterface;\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
+  return EFI_SUCCESS;\r
+}\r