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