]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg:Tpm2DeviceLibDTpm: Support TPM command cancel
authorZhang, Chao B <chao.b.zhang@intel.com>
Tue, 23 Jan 2018 07:18:16 +0000 (15:18 +0800)
committerZhang, Chao B <chao.b.zhang@intel.com>
Thu, 25 Jan 2018 14:14:28 +0000 (22:14 +0800)
Support TPM Command cancel if executing command timeouts. Cancel could
happen in long running command case

Cc: Yao Jiewen <jiewen.yao@intel.com>
Cc: Chinnusamy Rajkumar K <rajkumar.k.chinnusamy@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chao Zhang <chao.b.zhang@intel.com>
Reviewed-by: Yao Jiewen <jiewen.yao@intel.com>
MdePkg/Include/IndustryStandard/TpmTis.h
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c

index 519fa794d122eac6e74e929625e14b200aa81cb5..f25ca2559380ef55cffb81f12f780988a76519b5 100644 (file)
@@ -2,7 +2,7 @@
   TPM Interface Specification definition.\r
   It covers both TPM1.2 and TPM2.0.\r
 \r
-Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2016 - 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
@@ -142,6 +142,10 @@ typedef TIS_PC_REGISTERS  *TIS_PC_REGISTERS_PTR;
 ///\r
 #define TIS_PC_ACC_ESTABLISH        BIT0\r
 \r
+///\r
+/// Write a 1 to this bit to notify TPM to cancel currently executing command\r
+///\r
+#define TIS_PC_STS_CANCEL           BIT24\r
 ///\r
 /// This field indicates that STS_DATA and STS_EXPECT are valid\r
 ///\r
@@ -180,4 +184,4 @@ typedef TIS_PC_REGISTERS  *TIS_PC_REGISTERS_PTR;
 #define TIS_TIMEOUT_C               (750  * 1000)  // 750ms\r
 #define TIS_TIMEOUT_D               (750  * 1000)  // 750ms\r
 \r
-#endif
\ No newline at end of file
+#endif\r
index ddd4bd00b474515f32ef2dd2bd3d04afc9547ebe..d9df2646994d0351345c76b423b1467b7279b52e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   PTP (Platform TPM Profile) CRB (Command Response Buffer) interface used by dTPM2.0 library.\r
 \r
-Copyright (c) 2015 - 2016, 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
@@ -240,8 +240,26 @@ PtpCrbTpmCommand (
              PTP_TIMEOUT_MAX\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    Status = EFI_DEVICE_ERROR;\r
-    goto Exit;\r
+    //\r
+    // Command Completion check timeout. Cancel the currently executing command by writing TPM_CRB_CTRL_CANCEL,\r
+    // Expect TPM_RC_CANCELLED or successfully completed response.\r
+    //\r
+    MmioWrite32((UINTN)&CrbReg->CrbControlCancel, PTP_CRB_CONTROL_CANCEL);\r
+    Status = PtpCrbWaitRegisterBits (\r
+               &CrbReg->CrbControlStart,\r
+               0,\r
+               PTP_CRB_CONTROL_START,\r
+               PTP_TIMEOUT_B\r
+               );\r
+    MmioWrite32((UINTN)&CrbReg->CrbControlCancel, 0);\r
+\r
+    if (EFI_ERROR(Status)) {\r
+      //\r
+      // Still in Command Execution state. Try to goIdle, the behavior is agnostic.\r
+      //\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
   }\r
 \r
   //\r
index 6cd7030df2a6c33c24917da8cd3b1183e1aee158..0889162592fd6b488a207c28bd21450aa849f894 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   TIS (TPM Interface Specification) functions used by dTPM2.0 library.\r
   \r
-Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2015 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
@@ -295,10 +295,32 @@ Tpm2TisTpmCommand (
              TIS_TIMEOUT_MAX\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((DEBUG_ERROR, "Wait for Tpm2 response data time out!!\n"));\r
-    Status = EFI_DEVICE_ERROR;\r
-    goto Exit;\r
+    //\r
+    // dataAvail check timeout. Cancel the currently executing command by writing commandCancel,\r
+    // Expect TPM_RC_CANCELLED or successfully completed response.\r
+    //\r
+    DEBUG ((DEBUG_ERROR, "Wait for Tpm2 response data time out. Trying to cancel the command!!\n"));\r
+\r
+    MmioWrite32((UINTN)&TisReg->Status, TIS_PC_STS_CANCEL);\r
+    Status = TisPcWaitRegisterBits (\r
+               &TisReg->Status,\r
+               (UINT8) (TIS_PC_VALID | TIS_PC_STS_DATA),\r
+               0,\r
+               TIS_TIMEOUT_B\r
+               );\r
+    //\r
+    // Do not clear CANCEL bit here bicoz Writes of 0 to this bit are ignored\r
+    //\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Cancel executing command fail to get any response\r
+      // Try to abort the command with write of a 1 to commandReady in Command Execution state\r
+      //\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
   }\r
+\r
   //\r
   // Get response data header\r
   //\r