]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c
Handle TPM device error and avoid deadloop in BDS.
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibDTpm / Tpm2Tis.c
index cf85d4c7eeab818bfcaaa7a24ce135b448e6b089..a1862796a5379836055e1085297348ee84263926 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   TIS (TPM Interface Specification) functions used by dTPM2.0 library.\r
   \r
-Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2013 - 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
@@ -223,7 +223,6 @@ TisPcPresenceCheck (
   @retval     EFI_TIMEOUT  The register can't run into the expected status in time.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 TisPcWaitRegisterBits (\r
   IN      UINT8                     *Register,\r
   IN      UINT8                     BitSet,\r
@@ -255,7 +254,6 @@ TisPcWaitRegisterBits (
   @retval     EFI_TIMEOUT           BurstCount can't be got in time.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 TisPcReadBurstCount (\r
   IN      TIS_PC_REGISTERS_PTR      TisReg,\r
      OUT  UINT16                    *BurstCount\r
@@ -299,7 +297,6 @@ TisPcReadBurstCount (
   @retval    EFI_TIMEOUT           TPM chip can't be set to ready state in time.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 TisPcPrepareCommand (\r
   IN      TIS_PC_REGISTERS_PTR      TisReg\r
   )\r
@@ -332,7 +329,6 @@ TisPcPrepareCommand (
   @retval    EFI_TIMEOUT           Can't get the TPM control in time.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 TisPcRequestUseTpm (\r
   IN      TIS_PC_REGISTERS_PTR      TisReg\r
   )\r
@@ -367,7 +363,6 @@ TisPcRequestUseTpm (
   @param[in, out] SizeOut       Size of response data.  \r
  \r
   @retval EFI_SUCCESS           Operation completed successfully.\r
-  @retval EFI_TIMEOUT           The register can't run into the expected status in time.\r
   @retval EFI_BUFFER_TOO_SMALL  Response data buffer is too small.\r
   @retval EFI_DEVICE_ERROR      Unexpected device behavior.\r
   @retval EFI_UNSUPPORTED       Unsupported TPM version\r
@@ -392,7 +387,7 @@ TisTpmCommand (
   DEBUG_CODE (\r
     UINTN  DebugSize;\r
 \r
-    DEBUG ((EFI_D_INFO, "TisTpmCommand Send - "));\r
+    DEBUG ((EFI_D_INFO, "Tpm2TisTpmCommand Send - "));\r
     if (SizeIn > 0x100) {\r
       DebugSize = 0x40;\r
     } else {\r
@@ -413,8 +408,8 @@ TisTpmCommand (
 \r
   Status = TisPcPrepareCommand (TisReg);\r
   if (EFI_ERROR (Status)){\r
-    DEBUG ((DEBUG_ERROR, "Tpm is not ready for command!\n"));\r
-    return Status;\r
+    DEBUG ((DEBUG_ERROR, "Tpm2 is not ready for command!\n"));\r
+    return EFI_DEVICE_ERROR;\r
   }\r
   //\r
   // Send the command data to Tpm\r
@@ -423,7 +418,7 @@ TisTpmCommand (
   while (Index < SizeIn) {\r
     Status = TisPcReadBurstCount (TisReg, &BurstCount);\r
     if (EFI_ERROR (Status)) {\r
-      Status = EFI_TIMEOUT;\r
+      Status = EFI_DEVICE_ERROR;\r
       goto Exit;\r
     }\r
     for (; BurstCount > 0 && Index < SizeIn; BurstCount--) {\r
@@ -441,7 +436,7 @@ TisTpmCommand (
              TIS_TIMEOUT_C\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((DEBUG_ERROR, "The send buffer too small!\n"));\r
+    DEBUG ((DEBUG_ERROR, "Tpm2 The send buffer too small!\n"));\r
     Status = EFI_BUFFER_TOO_SMALL;\r
     goto Exit;\r
   }\r
@@ -460,8 +455,8 @@ TisTpmCommand (
              TIS_TIMEOUT_MAX\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((DEBUG_ERROR, "Wait for Tpm response data time out!!\n"));\r
-    Status = EFI_TIMEOUT;\r
+    DEBUG ((DEBUG_ERROR, "Wait for Tpm2 response data time out!!\n"));\r
+    Status = EFI_DEVICE_ERROR;\r
     goto Exit;\r
   }\r
   //\r
@@ -472,7 +467,7 @@ TisTpmCommand (
   while (Index < sizeof (TPM2_RESPONSE_HEADER)) {\r
     Status = TisPcReadBurstCount (TisReg, &BurstCount);\r
     if (EFI_ERROR (Status)) {\r
-      Status = EFI_TIMEOUT;\r
+      Status = EFI_DEVICE_ERROR;\r
       goto Exit;\r
     }\r
     for (; BurstCount > 0; BurstCount--) {\r
@@ -494,7 +489,7 @@ TisTpmCommand (
   CopyMem (&Data16, BufferOut, sizeof (UINT16));\r
   // TPM2 should not use this RSP_COMMAND\r
   if (SwapBytes16 (Data16) == TPM_ST_RSP_COMMAND) {\r
-    DEBUG ((EFI_D_ERROR, "TPM_ST_RSP error - %x\n", TPM_ST_RSP_COMMAND));\r
+    DEBUG ((EFI_D_ERROR, "TPM2: TPM_ST_RSP error - %x\n", TPM_ST_RSP_COMMAND));\r
     Status = EFI_UNSUPPORTED;\r
     goto Exit;\r
   }\r
@@ -520,13 +515,13 @@ TisTpmCommand (
     }\r
     Status = TisPcReadBurstCount (TisReg, &BurstCount);\r
     if (EFI_ERROR (Status)) {\r
-      Status = EFI_TIMEOUT;\r
+      Status = EFI_DEVICE_ERROR;\r
       goto Exit;\r
     }\r
   }\r
 Exit:\r
   DEBUG_CODE (\r
-    DEBUG ((EFI_D_INFO, "TisTpmCommand Receive - "));\r
+    DEBUG ((EFI_D_INFO, "Tpm2TisTpmCommand Receive - "));\r
     for (Index = 0; Index < TpmOutSize; Index++) {\r
       DEBUG ((EFI_D_INFO, "%02x ", BufferOut[Index]));\r
     }\r