]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg: Add TPM PTP support in TCG2 SMM.
authorYao, Jiewen <jiewen.yao@intel.com>
Tue, 26 Jan 2016 01:30:17 +0000 (01:30 +0000)
committerjyao1 <jyao1@Edk2>
Tue, 26 Jan 2016 01:30:17 +0000 (01:30 +0000)
TPM2 hardware may support PTP FIFO/TIS interface
or PTP CRB interface. The original ACPI table only
handles PTP FIFO/TIS interface. This patch adds
PTP CRB interface support.
The current logic is that SMM driver will runtime
detect TPM device interface (CRB or FIFO/TIS) and
publish TPM2 table based on result.

It is compatible for old TPM2 FIFO/TIS device and
new TPM2 CRB device.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: "Yao, Jiewen" <jiewen.yao@intel.com>
Reviewed-by: "Zhang, Chao B" <chao.b.zhang@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19741 6f19259b-4bc3-4df7-8a09-765794883524

SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h
SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf
SecurityPkg/Tcg/Tcg2Smm/Tpm.asl

index 503cc18dd98fef8d4f35bedda3560313c3d170d9..dab1f532cc9a68b9d77d32dc2c49cbded6171f42 100644 (file)
@@ -9,7 +9,7 @@
 \r
   PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check.\r
 \r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2016, 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
@@ -22,6 +22,48 @@ 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_CRB) &&\r
+      (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_CRB) &&\r
+      (InterfaceId.Bits.CapCRB != 0)) {\r
+    return PtpInterfaceCrb;\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
+  return PtpInterfaceTis;\r
+}\r
+\r
 EFI_TPM2_ACPI_TABLE  mTpm2AcpiTemplate = {\r
   {\r
     EFI_ACPI_5_0_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE,\r
@@ -288,6 +330,8 @@ PublishTpm2 (
   EFI_ACPI_TABLE_PROTOCOL        *AcpiTable;\r
   UINTN                          TableKey;\r
   UINT64                         OemTableId;\r
+  EFI_TPM2_ACPI_CONTROL_AREA     *ControlArea;\r
+  PTP_INTERFACE_TYPE             InterfaceType;\r
 \r
   //\r
   // Measure to PCR[0] with event EV_POST_CODE ACPI DATA\r
@@ -301,6 +345,24 @@ PublishTpm2 (
     sizeof(mTpm2AcpiTemplate)\r
     );\r
 \r
+  InterfaceType = GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
+  switch (InterfaceType) {\r
+  case PtpInterfaceCrb:\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
+    ControlArea->CommandSize  = 0xF80;\r
+    ControlArea->ResponseSize = 0xF80;\r
+    ControlArea->Command      = PcdGet64 (PcdTpmBaseAddress) + 0x80;\r
+    ControlArea->Response     = PcdGet64 (PcdTpmBaseAddress) + 0x80;\r
+    break;\r
+  case PtpInterfaceFifo:\r
+  case PtpInterfaceTis:\r
+    break;\r
+  default:\r
+    break;\r
+  }\r
+\r
   CopyMem (mTpm2AcpiTemplate.Header.OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (mTpm2AcpiTemplate.Header.OemId));\r
   OemTableId = PcdGet64 (PcdAcpiDefaultOemTableId);\r
   CopyMem (&mTpm2AcpiTemplate.Header.OemTableId, &OemTableId, sizeof (UINT64));\r
index ebd71edb772d2d2442d6b902bddac7c2859cadc7..62374a2ee5354aec55ed3ea320ad163d693745e2 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The header file for Tcg2 SMM driver.\r
   \r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2016, 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
@@ -37,6 +37,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/TpmMeasurementLib.h>\r
 #include <Library/Tpm2DeviceLib.h>\r
 #include <Library/Tcg2PhysicalPresenceLib.h>\r
+#include <Library/IoLib.h>\r
+\r
+#include <IndustryStandard/TpmPtp.h>\r
 \r
 #pragma pack(1)\r
 typedef struct {\r
index ef30ec79e0f3c9cc1dc457b09a901ae313a96879..0cc0cc689d6a3a253d165d3633984a6c6e38f9b0 100644 (file)
@@ -9,7 +9,7 @@
 #  This driver will have external input - variable and ACPINvs data in SMM mode.\r
 #  This external input must be validated carefully to avoid security issue.\r
 #\r
-# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2015 - 2016, 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
@@ -50,6 +50,7 @@
   TpmMeasurementLib\r
   Tpm2DeviceLib\r
   Tcg2PhysicalPresenceLib\r
+  IoLib\r
 \r
 [Guids]\r
   ## SOMETIMES_PRODUCES ## Variable:L"MemoryOverwriteRequestControl"\r
@@ -70,6 +71,7 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision      ## SOMETIMES_CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId        ## SOMETIMES_CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision  ## SOMETIMES_CONSUMES\r
+  gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress               ## CONSUMES\r
 \r
 [Depex]\r
   gEfiAcpiTableProtocolGuid AND\r
index 2abd4af9ef6112496c8121513fc478594f2cce80..776f43e972f91154365f88031df892a82c411c6a 100644 (file)
@@ -2,7 +2,7 @@
   The TPM2 definition block in ACPI table for TCG2 physical presence  \r
   and MemoryClear.\r
 \r
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015, 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