]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg: Cache TPM interface type info
authorZhang, Chao B <chao.b.zhang@intel.com>
Tue, 8 May 2018 06:51:57 +0000 (14:51 +0800)
committerZhang, Chao B <chao.b.zhang@intel.com>
Mon, 25 Jun 2018 02:55:08 +0000 (10:55 +0800)
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>
13 files changed:
SecurityPkg/Include/Library/Tpm2DeviceLib.h
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
SecurityPkg/SecurityPkg.dec
SecurityPkg/SecurityPkg.uni
SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDxe.inf
SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h
SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf

index 67f158ef039c404a8bdba292cf070bc2b9d21d1f..f072a2492549aa6590a9e5c2070642fa8f64e352 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This library abstract how to access TPM2 hardware device.\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,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Uefi.h>\r
 \r
+//\r
+// Used in PcdActiveTpmInterfaceType to identify TPM interface type\r
+//\r
+typedef enum {\r
+  Tpm2PtpInterfaceTis,\r
+  Tpm2PtpInterfaceFifo,\r
+  Tpm2PtpInterfaceCrb,\r
+  Tpm2PtpInterfaceMax,\r
+} TPM2_PTP_INTERFACE_TYPE;\r
+\r
 /**\r
   This service enables the sending of commands to the TPM2.\r
 \r
index 0b1723e4a1c6b031d2ca294966fdec0e2104ec78..3feb64df7edfde5f1c0ac987f7e69018980818e6 100644 (file)
@@ -2,7 +2,7 @@
   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 - 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
@@ -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
index 3e619b98b73a461b4fb22a1fd04a92761e862140..634bbae847e4999580e764669f6deabb64f8a969 100644 (file)
@@ -10,7 +10,7 @@
 #  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 - 2017, 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
@@ -27,8 +27,8 @@
   FILE_GUID                      = E54A3327-A345-4068-8842-70AC0D519855\r
   MODULE_TYPE                    = BASE\r
   VERSION_STRING                 = 1.0\r
-  LIBRARY_CLASS                  = Tpm2DeviceLib\r
-\r
+  LIBRARY_CLASS                  = Tpm2DeviceLib|PEIM DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER\r
+  Constructor                    = Tpm2DeviceLibConstructor\r
 #\r
 # The following information is for reference only and not required by the build tools.\r
 #\r
@@ -50,6 +50,8 @@
   IoLib\r
   TimerLib\r
   DebugLib\r
+  PcdLib\r
 \r
 [Pcd]\r
   gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress            ## CONSUMES\r
+  gEfiSecurityPkgTokenSpaceGuid.PcdActiveTpmInterfaceType    ## PRODUCES\r
index 3f28f21faa39f3bca68621043ebb173f3dd8d5d0..01f78bf0befbaef8872f7639a28d3f1cc54b0316 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,22 @@ 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
   Dump PTP register information.\r
 \r
@@ -72,7 +85,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 +95,8 @@ Tpm2InstanceLibDTpmConstructor (
   VOID\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS               Status;\r
+  TPM2_PTP_INTERFACE_TYPE  PtpInterface;\r
 \r
   Status = Tpm2RegisterTpm2DeviceLib (&mDTpm2InternalTpm2Device);\r
   if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {\r
@@ -90,6 +104,13 @@ 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
       DumpPtpInfo ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
     }\r
     return EFI_SUCCESS;\r
index 22efb1ef4c9761b2ef6ddb7c257718813b536dfe..876a5a63c49fd46f7e8879b57ae7dc5f4e430c46 100644 (file)
@@ -5,7 +5,7 @@
 #  engine, based on platform setting. It supports both TIS (TPM Interface Specification)\r
 #  and PTP (Platform TPM Profile) functions.\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
@@ -46,6 +46,8 @@
   IoLib\r
   TimerLib\r
   DebugLib\r
+  PcdLib\r
 \r
 [Pcd]\r
-  gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress        ## CONSUMES\r
+  gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress          ## CONSUMES\r
+  gEfiSecurityPkgTokenSpaceGuid.PcdActiveTpmInterfaceType  ## PRODUCES
\ No newline at end of file
index d9df2646994d0351345c76b423b1467b7279b52e..1bc153a2c0d38db2e59e9537068dd7ab2103d677 100644 (file)
@@ -25,13 +25,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <IndustryStandard/TpmPtp.h>\r
 #include <IndustryStandard/TpmTis.h>\r
 \r
-typedef enum {\r
-  PtpInterfaceTis,\r
-  PtpInterfaceFifo,\r
-  PtpInterfaceCrb,\r
-  PtpInterfaceMax,\r
-} PTP_INTERFACE_TYPE;\r
-\r
 //\r
 // Execution of the command may take from several seconds to minutes for certain\r
 // commands, such as key generation.\r
@@ -370,7 +363,7 @@ TisPcRequestUseTpm (
 \r
   @return PTP interface type.\r
 **/\r
-PTP_INTERFACE_TYPE\r
+TPM2_PTP_INTERFACE_TYPE\r
 Tpm2GetPtpInterface (\r
   IN VOID *Register\r
   )\r
@@ -379,7 +372,7 @@ Tpm2GetPtpInterface (
   PTP_FIFO_INTERFACE_CAPABILITY InterfaceCapability;\r
 \r
   if (!Tpm2IsPtpPresence (Register)) {\r
-    return PtpInterfaceMax;\r
+    return Tpm2PtpInterfaceMax;\r
   }\r
   //\r
   // Check interface id\r
@@ -390,15 +383,15 @@ Tpm2GetPtpInterface (
   if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB) &&\r
       (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_CRB) &&\r
       (InterfaceId.Bits.CapCRB != 0)) {\r
-    return PtpInterfaceCrb;\r
+    return Tpm2PtpInterfaceCrb;\r
   }\r
   if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO) &&\r
       (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_FIFO) &&\r
       (InterfaceId.Bits.CapFIFO != 0) &&\r
       (InterfaceCapability.Bits.InterfaceVersion == INTERFACE_CAPABILITY_INTERFACE_VERSION_PTP)) {\r
-    return PtpInterfaceFifo;\r
+    return Tpm2PtpInterfaceFifo;\r
   }\r
-  return PtpInterfaceTis;\r
+  return Tpm2PtpInterfaceTis;\r
 }\r
 \r
 /**\r
@@ -417,7 +410,7 @@ DumpPtpInfo (
   UINT16                        Vid;\r
   UINT16                        Did;\r
   UINT8                         Rid;\r
-  PTP_INTERFACE_TYPE            PtpInterface;\r
+  TPM2_PTP_INTERFACE_TYPE       PtpInterface;\r
 \r
   if (!Tpm2IsPtpPresence (Register)) {\r
     return ;\r
@@ -458,16 +451,16 @@ DumpPtpInfo (
   Vid = 0xFFFF;\r
   Did = 0xFFFF;\r
   Rid = 0xFF;\r
-  PtpInterface = Tpm2GetPtpInterface (Register);\r
+  PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);\r
   DEBUG ((EFI_D_INFO, "PtpInterface - %x\n", PtpInterface));\r
   switch (PtpInterface) {\r
-  case PtpInterfaceCrb:\r
+  case Tpm2PtpInterfaceCrb:\r
     Vid = MmioRead16 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->Vid);\r
     Did = MmioRead16 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->Did);\r
     Rid = (UINT8)InterfaceId.Bits.Rid;\r
     break;\r
-  case PtpInterfaceFifo:\r
-  case PtpInterfaceTis:\r
+  case Tpm2PtpInterfaceFifo:\r
+  case Tpm2PtpInterfaceTis:\r
     Vid = MmioRead16 ((UINTN)&((PTP_FIFO_REGISTERS *)Register)->Vid);\r
     Did = MmioRead16 ((UINTN)&((PTP_FIFO_REGISTERS *)Register)->Did);\r
     Rid = MmioRead8 ((UINTN)&((PTP_FIFO_REGISTERS *)Register)->Rid);\r
@@ -501,11 +494,11 @@ DTpm2SubmitCommand (
   IN UINT8             *OutputParameterBlock\r
   )\r
 {\r
-  PTP_INTERFACE_TYPE  PtpInterface;\r
+  TPM2_PTP_INTERFACE_TYPE  PtpInterface;\r
 \r
-  PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
+  PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);\r
   switch (PtpInterface) {\r
-  case PtpInterfaceCrb:\r
+  case Tpm2PtpInterfaceCrb:\r
     return PtpCrbTpmCommand (\r
            (PTP_CRB_REGISTERS_PTR) (UINTN) PcdGet64 (PcdTpmBaseAddress),\r
            InputParameterBlock,\r
@@ -513,8 +506,8 @@ DTpm2SubmitCommand (
            OutputParameterBlock,\r
            OutputParameterBlockSize\r
            );\r
-  case PtpInterfaceFifo:\r
-  case PtpInterfaceTis:\r
+  case Tpm2PtpInterfaceFifo:\r
+  case Tpm2PtpInterfaceTis:\r
     return Tpm2TisTpmCommand (\r
            (TIS_PC_REGISTERS_PTR) (UINTN) PcdGet64 (PcdTpmBaseAddress),\r
            InputParameterBlock,\r
@@ -540,14 +533,14 @@ DTpm2RequestUseTpm (
   VOID\r
   )\r
 {\r
-  PTP_INTERFACE_TYPE  PtpInterface;\r
+  TPM2_PTP_INTERFACE_TYPE  PtpInterface;\r
 \r
-  PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
+  PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);\r
   switch (PtpInterface) {\r
-  case PtpInterfaceCrb:\r
+  case Tpm2PtpInterfaceCrb:\r
     return PtpCrbRequestUseTpm ((PTP_CRB_REGISTERS_PTR) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
-  case PtpInterfaceFifo:\r
-  case PtpInterfaceTis:\r
+  case Tpm2PtpInterfaceFifo:\r
+  case Tpm2PtpInterfaceTis:\r
     return TisPcRequestUseTpm ((TIS_PC_REGISTERS_PTR) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
   default:\r
     return EFI_NOT_FOUND;\r
index 497354634b9813252d381dcad8c5288833c4c3c7..60f1c0a0e353d8edb1720241f5dde2fa026cf3f4 100644 (file)
   # linked, and the value of this PCD should be got in module entrypoint.\r
   # @Prompt Hash Algorithm bitmap.\r
   gEfiSecurityPkgTokenSpaceGuid.PcdTcg2HashAlgorithmBitmap|0xFFFFFFFF|UINT32|0x00010016\r
-  \r
+\r
+  ## This PCD indicates current active TPM interface type.\r
+  #  Accodingt to TCG PTP spec 1.3, there are 3 types defined in TPM2_PTP_INTERFACE_TYPE.<BR>\r
+  #  0x00 - FIFO interface as defined in TIS 1.3 is active.<BR>\r
+  #  0x01 - FIFO interface as defined in PTP for TPM 2.0 is active.<BR>\r
+  #  0x02 - CRB interface is active.<BR>\r
+  #  0xFF - Contains no current active TPM interface type.<BR>\r
+  #\r
+  # @Prompt current active TPM interface type.\r
+  gEfiSecurityPkgTokenSpaceGuid.PcdActiveTpmInterfaceType|0xFF|UINT8|0x0001001E\r
+\r
 [UserExtensions.TianoCore."ExtraFiles"]\r
   SecurityPkgExtra.uni\r
index aaf77269a311356f41ead247dceead108aad539d..c34250e423ffd0405f8ab8cd88f232e2c9901304 100644 (file)
 #string STR_gEfiSecurityPkgTokenSpaceGuid_PcdTpm2PossibleIrqNumBuf_PROMPT  #language en-US "Possible TPM2 device interrupt number buffer"\r
 \r
 #string STR_gEfiSecurityPkgTokenSpaceGuid_PcdTpm2PossibleIrqNumBuf_HELP  #language en-US "This PCD defines possible TPM2 interrupt number in a platform reported by _PRS control method.\n"\r
-                                                                                         "If PcdTpm2CurrentIrqNum set to 0, _PRS will not report any possible TPM2 interrupt numbers."
\ No newline at end of file
+                                                                                         "If PcdTpm2CurrentIrqNum set to 0, _PRS will not report any possible TPM2 interrupt numbers."\r
+\r
+#string STR_gEfiSecurityPkgTokenSpaceGuid_PcdActiveTpmInterfaceType_PROMPT  #language en-US "Current active TPM interface type"\r
+\r
+#string STR_gEfiSecurityPkgTokenSpaceGuid_PcdActiveTpmInterfaceType_HELP  #language en-US "This PCD indicates current active TPM interface type.\n"\r
+                                                                                          "0x00 - FIFO interface as defined in TIS 1.3 is active.<BR>\n"\r
+                                                                                          "0x01 - FIFO interface as defined in PTP for TPM 2.0 is active.<BR>\n"\r
+                                                                                          "0x02 - CRB interface is active.<BR>\n"\r
+                                                                                          "0xFF - Contains no current active TPM interface type<BR>"
\ No newline at end of file
index 38fa331701092aa44e2ad2cc286b910403b7dc52..a52709669ac64aa915ec2241d8fa0fff01bbf614 100644 (file)
@@ -4,7 +4,7 @@
 #  By this module, user may select TPM device, clear TPM state, etc.\r
 #  NOTE: This module is only for reference only, each platform should have its own setup page.\r
 #\r
-# Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2015 - 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
@@ -79,6 +79,7 @@
   gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress             ## CONSUMES\r
   gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer  ## CONSUMES\r
   gEfiSecurityPkgTokenSpaceGuid.PcdTpm2AcpiTableRev           ## CONSUMES\r
+  gEfiSecurityPkgTokenSpaceGuid.PcdActiveTpmInterfaceType     ## CONSUMES\r
 \r
 [Depex]\r
   gEfiTcg2ProtocolGuid              AND\r
index 4195b6c68f5dc909531686fb4612a95c183c3230..af97628e2cdbf765c38cee15b3d2f3dafca52f9f 100644 (file)
@@ -2,7 +2,7 @@
   HII Config Access protocol implementation of TCG2 configuration module.\r
   NOTE: This module is only for reference only, each platform should have its own setup page.\r
 \r
-Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2018 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials \r
 are licensed and made available under the terms and conditions of the BSD License \r
@@ -17,7 +17,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "Tcg2ConfigImpl.h"\r
 #include <Library/PcdLib.h>\r
 #include <Library/Tpm2CommandLib.h>\r
+#include <Library/Tpm2DeviceLib.h>\r
 #include <Library/IoLib.h>\r
+\r
 #include <Guid/TpmInstance.h>\r
 \r
 #include <IndustryStandard/TpmPtp.h>\r
@@ -60,41 +62,6 @@ HII_VENDOR_DEVICE_PATH          mTcg2HiiVendorDevicePath = {
 \r
 UINT8  mCurrentPpRequest;\r
 \r
-/**\r
-  Return PTP interface type.\r
-\r
-  @param[in] Register                Pointer to PTP register.\r
-\r
-  @return PTP interface type.\r
-**/\r
-UINT8\r
-GetPtpInterface (\r
-  IN VOID *Register\r
-  )\r
-{\r
-  PTP_CRB_INTERFACE_IDENTIFIER  InterfaceId;\r
-  PTP_FIFO_INTERFACE_CAPABILITY InterfaceCapability;\r
-\r
-  //\r
-  // Check interface id\r
-  //\r
-  InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);\r
-  InterfaceCapability.Uint32 = MmioRead32 ((UINTN)&((PTP_FIFO_REGISTERS *)Register)->InterfaceCapability);\r
-\r
-  if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB) &&\r
-      (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_CRB) &&\r
-      (InterfaceId.Bits.CapCRB != 0)) {\r
-    return TPM_DEVICE_INTERFACE_PTP_CRB;\r
-  }\r
-  if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO) &&\r
-      (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_FIFO) &&\r
-      (InterfaceId.Bits.CapFIFO != 0) &&\r
-      (InterfaceCapability.Bits.InterfaceVersion == INTERFACE_CAPABILITY_INTERFACE_VERSION_PTP)) {\r
-    return TPM_DEVICE_INTERFACE_PTP_FIFO;\r
-  }\r
-  return TPM_DEVICE_INTERFACE_TIS;\r
-}\r
-\r
 /**\r
   Return if PTP CRB is supported.\r
 \r
@@ -153,6 +120,7 @@ IsPtpFifoSupported (
 \r
 /**\r
   Set PTP interface type.\r
+  Do not update PcdActiveTpmInterfaceType here because interface change only happens on next _TPM_INIT\r
 \r
   @param[in] Register                Pointer to PTP register.\r
   @param[in] PtpInterface            PTP interface type.\r
@@ -168,12 +136,12 @@ SetPtpInterface (
   IN UINT8                PtpInterface\r
   )\r
 {\r
-  UINT8                         PtpInterfaceCurrent;\r
+  TPM2_PTP_INTERFACE_TYPE       PtpInterfaceCurrent;\r
   PTP_CRB_INTERFACE_IDENTIFIER  InterfaceId;\r
 \r
-  PtpInterfaceCurrent = GetPtpInterface (Register);\r
-  if ((PtpInterfaceCurrent != TPM_DEVICE_INTERFACE_PTP_FIFO) && \r
-      (PtpInterfaceCurrent != TPM_DEVICE_INTERFACE_PTP_CRB)) {\r
+  PtpInterfaceCurrent = PcdGet8(PcdActiveTpmInterfaceType);\r
+  if ((PtpInterfaceCurrent != Tpm2PtpInterfaceFifo) &&\r
+      (PtpInterfaceCurrent != Tpm2PtpInterfaceCrb)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
   InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);\r
@@ -182,14 +150,14 @@ SetPtpInterface (
   }\r
 \r
   switch (PtpInterface) {\r
-  case TPM_DEVICE_INTERFACE_PTP_FIFO:\r
+  case Tpm2PtpInterfaceFifo:\r
     if (InterfaceId.Bits.CapFIFO == 0) {\r
       return EFI_UNSUPPORTED;\r
     }\r
     InterfaceId.Bits.InterfaceSelector = PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_FIFO;\r
     MmioWrite32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId, InterfaceId.Uint32);\r
     return EFI_SUCCESS;\r
-  case TPM_DEVICE_INTERFACE_PTP_CRB:\r
+  case Tpm2PtpInterfaceCrb:\r
     if (InterfaceId.Bits.CapCRB == 0) {\r
       return EFI_UNSUPPORTED;\r
     }\r
@@ -825,7 +793,7 @@ InstallTcg2ConfigForm (
   TPML_PCR_SELECTION              Pcrs;\r
   CHAR16                          TempBuffer[1024];\r
   TCG2_CONFIGURATION_INFO         Tcg2ConfigInfo;\r
-  UINT8                           TpmDeviceInterfaceDetected;\r
+  TPM2_PTP_INTERFACE_TYPE         TpmDeviceInterfaceDetected;\r
 \r
   DriverHandle = NULL;\r
   ConfigAccess = &PrivateData->ConfigAccess;\r
@@ -930,15 +898,15 @@ InstallTcg2ConfigForm (
   // Update TPM device interface type\r
   //\r
   if (PrivateData->TpmDeviceDetected == TPM_DEVICE_2_0_DTPM) {\r
-    TpmDeviceInterfaceDetected = GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
+    TpmDeviceInterfaceDetected = PcdGet8(PcdActiveTpmInterfaceType);\r
     switch (TpmDeviceInterfaceDetected) {\r
-    case TPM_DEVICE_INTERFACE_TIS:\r
+    case Tpm2PtpInterfaceTis:\r
       HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"TIS", NULL);\r
       break;\r
-    case TPM_DEVICE_INTERFACE_PTP_FIFO:\r
+    case Tpm2PtpInterfaceFifo:\r
       HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"PTP FIFO", NULL);\r
       break;\r
-    case TPM_DEVICE_INTERFACE_PTP_CRB:\r
+    case Tpm2PtpInterfaceCrb:\r
       HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"PTP CRB", NULL);\r
       break;\r
      default:\r
@@ -948,13 +916,13 @@ InstallTcg2ConfigForm (
 \r
     Tcg2ConfigInfo.TpmDeviceInterfaceAttempt = TpmDeviceInterfaceDetected;\r
     switch (TpmDeviceInterfaceDetected) {\r
-    case TPM_DEVICE_INTERFACE_TIS:\r
+    case Tpm2PtpInterfaceTis:\r
       Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported = FALSE;\r
       Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported  = FALSE;\r
       HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT), L"TIS", NULL);\r
       break;\r
-    case TPM_DEVICE_INTERFACE_PTP_FIFO:\r
-    case TPM_DEVICE_INTERFACE_PTP_CRB:\r
+    case Tpm2PtpInterfaceFifo:\r
+    case Tpm2PtpInterfaceCrb:\r
       Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported = IsPtpFifoSupported((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
       Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported  = IsPtpCrbSupported((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
       TempBuffer[0] = 0;\r
index f0c92462cf921164a84b730471d5aadc7f1745b1..26f1fbdf8cdb8fcf5eb9f15b648bd4e0a120e495 100644 (file)
@@ -22,56 +22,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "Tcg2Smm.h"\r
 \r
-typedef enum {\r
-  PtpInterfaceTis,\r
-  PtpInterfaceFifo,\r
-  PtpInterfaceCrb,\r
-  PtpInterfaceMax,\r
-} PTP_INTERFACE_TYPE;\r
-\r
-/**\r
-  Return PTP interface type.\r
-\r
-  @param[in] Register                Pointer to PTP register.\r
-\r
-  @return PTP interface type.\r
-**/\r
-PTP_INTERFACE_TYPE\r
-GetPtpInterface (\r
-  IN VOID *Register\r
-  )\r
-{\r
-  PTP_CRB_INTERFACE_IDENTIFIER  InterfaceId;\r
-  PTP_FIFO_INTERFACE_CAPABILITY InterfaceCapability;\r
-\r
-  //\r
-  // Check interface id\r
-  //\r
-  InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);\r
-  InterfaceCapability.Uint32 = MmioRead32 ((UINTN)&((PTP_FIFO_REGISTERS *)Register)->InterfaceCapability);\r
-\r
-  if (InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_TIS) {\r
-    return PtpInterfaceTis;\r
-  }\r
-\r
-  if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB) &&\r
-      (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_CRB) &&\r
-      (InterfaceId.Bits.CapCRB != 0)) {\r
-    return PtpInterfaceCrb;\r
-  }\r
-\r
-  if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO) &&\r
-      (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_FIFO) &&\r
-      (InterfaceId.Bits.CapFIFO != 0) &&\r
-      (InterfaceCapability.Bits.InterfaceVersion == INTERFACE_CAPABILITY_INTERFACE_VERSION_PTP)) {\r
-    return PtpInterfaceFifo;\r
-  }\r
-\r
-  //\r
-  // No Ptp interface available\r
-  //\r
-  return PtpInterfaceMax;\r
-}\r
 \r
 EFI_TPM2_ACPI_TABLE  mTpm2AcpiTemplate = {\r
   {\r
@@ -785,7 +735,7 @@ PublishTpm2 (
   UINTN                          TableKey;\r
   UINT64                         OemTableId;\r
   EFI_TPM2_ACPI_CONTROL_AREA     *ControlArea;\r
-  PTP_INTERFACE_TYPE             InterfaceType;\r
+  TPM2_PTP_INTERFACE_TYPE        InterfaceType;\r
 \r
   mTpm2AcpiTemplate.Header.Revision = PcdGet8(PcdTpm2AcpiTableRev);\r
   DEBUG((DEBUG_INFO, "Tpm2 ACPI table revision is %d\n", mTpm2AcpiTemplate.Header.Revision));\r
@@ -812,9 +762,9 @@ PublishTpm2 (
     sizeof(mTpm2AcpiTemplate)\r
     );\r
 \r
-  InterfaceType = GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
+  InterfaceType = PcdGet8(PcdActiveTpmInterfaceType);\r
   switch (InterfaceType) {\r
-  case PtpInterfaceCrb:\r
+  case Tpm2PtpInterfaceCrb:\r
     mTpm2AcpiTemplate.StartMethod = EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE;\r
     mTpm2AcpiTemplate.AddressOfControlArea = PcdGet64 (PcdTpmBaseAddress) + 0x40;\r
     ControlArea = (EFI_TPM2_ACPI_CONTROL_AREA *)(UINTN)mTpm2AcpiTemplate.AddressOfControlArea;\r
@@ -823,8 +773,8 @@ PublishTpm2 (
     ControlArea->Command      = PcdGet64 (PcdTpmBaseAddress) + 0x80;\r
     ControlArea->Response     = PcdGet64 (PcdTpmBaseAddress) + 0x80;\r
     break;\r
-  case PtpInterfaceFifo:\r
-  case PtpInterfaceTis:\r
+  case Tpm2PtpInterfaceFifo:\r
+  case Tpm2PtpInterfaceTis:\r
     break;\r
   default:\r
     DEBUG((EFI_D_ERROR, "TPM2 InterfaceType get error! %d\n", InterfaceType));\r
index 732452cb35de80e6e2a7d6ef2f2b332d867e9a98..e3a14e8339bc83482a6003d74d344c837ef23654 100644 (file)
@@ -40,6 +40,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/IoLib.h>\r
 #include <Library/PrintLib.h>\r
 #include <Library/PcdLib.h>\r
+#include <Library/Tpm2DeviceLib.h>\r
 \r
 #include <IndustryStandard/TpmPtp.h>\r
 \r
index 81f74959a420ffe60c2ae5f4ba998d208ade5577..168f9779e65138a51a64759cf6f580eb19a62d06 100644 (file)
@@ -85,6 +85,7 @@
   gEfiSecurityPkgTokenSpaceGuid.PcdTpmPlatformClass                 ## SOMETIMES_CONSUMES\r
   gEfiSecurityPkgTokenSpaceGuid.PcdTpm2CurrentIrqNum            ## CONSUMES\r
   gEfiSecurityPkgTokenSpaceGuid.PcdTpm2PossibleIrqNumBuf        ## CONSUMES\r
+  gEfiSecurityPkgTokenSpaceGuid.PcdActiveTpmInterfaceType       ## CONSUMES\r
 \r
 [Depex]\r
   gEfiAcpiTableProtocolGuid AND\r