]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c
SecurityPkg:Tpm2DeviceLibDTpm: Support TPM command cancel
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibDTpm / Tpm2Tis.c
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