]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
SecurityPkg: Cache TPM interface type info
[mirror_edk2.git] / SecurityPkg / Tcg / Tcg2Config / Tcg2ConfigImpl.c
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