]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c
SecurityPkg: Change complex DEBUG_CODE() to DEBUG_CODE_BEGIN/END()
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibDTpm / Tpm2Tis.c
index 0889162592fd6b488a207c28bd21450aa849f894..a3c84d8ab491ebb6487cecbc223080f8c61b7d23 100644 (file)
@@ -1,15 +1,9 @@
 /** @file\r
   TIS (TPM Interface Specification) functions used by dTPM2.0 library.\r
-  \r
+\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
-which accompanies this distribution.  The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -28,7 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define TIS_TIMEOUT_MAX             (90000 * 1000)  // 90s\r
 \r
 //\r
-// Max TPM command/reponse length\r
+// Max TPM command/response length\r
 //\r
 #define TPMCMDBUFLENGTH             0x500\r
 \r
@@ -46,7 +40,7 @@ TisPcPresenceCheck (
   )\r
 {\r
   UINT8                             RegRead;\r
-  \r
+\r
   RegRead = MmioRead8 ((UINTN)&TisReg->Access);\r
   return (BOOLEAN)(RegRead != (UINT8)-1);\r
 }\r
@@ -83,11 +77,11 @@ TisPcWaitRegisterBits (
 }\r
 \r
 /**\r
-  Get BurstCount by reading the burstCount field of a TIS regiger \r
+  Get BurstCount by reading the burstCount field of a TIS register\r
   in the time of default TIS_TIMEOUT_D.\r
 \r
   @param[in]  TisReg                Pointer to TIS register.\r
-  @param[out] BurstCount            Pointer to a buffer to store the got BurstConut.\r
+  @param[out] BurstCount            Pointer to a buffer to store the got BurstCount.\r
 \r
   @retval     EFI_SUCCESS           Get BurstCount.\r
   @retval     EFI_INVALID_PARAMETER TisReg is NULL or BurstCount is NULL.\r
@@ -127,7 +121,7 @@ TisPcReadBurstCount (
 }\r
 \r
 /**\r
-  Set TPM chip to ready state by sending ready command TIS_PC_STS_READY \r
+  Set TPM chip to ready state by sending ready command TIS_PC_STS_READY\r
   to Status Register in time.\r
 \r
   @param[in] TisReg                Pointer to TIS register.\r
@@ -158,7 +152,7 @@ TisPcPrepareCommand (
 }\r
 \r
 /**\r
-  Get the control of TPM chip by sending requestUse command TIS_PC_ACC_RQUUSE \r
+  Get the control of TPM chip by sending requestUse command TIS_PC_ACC_RQUUSE\r
   to ACCESS Register in the time of default TIS_TIMEOUT_A.\r
 \r
   @param[in] TisReg                Pointer to TIS register.\r
@@ -174,11 +168,11 @@ TisPcRequestUseTpm (
   )\r
 {\r
   EFI_STATUS                        Status;\r
-  \r
+\r
   if (TisReg == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   if (!TisPcPresenceCheck (TisReg)) {\r
     return EFI_NOT_FOUND;\r
   }\r
@@ -196,12 +190,12 @@ TisPcRequestUseTpm (
 /**\r
   Send a command to TPM for execution and return response data.\r
 \r
-  @param[in]      TisReg        TPM register space base address.  \r
-  @param[in]      BufferIn      Buffer for command data.  \r
-  @param[in]      SizeIn        Size of command data.  \r
-  @param[in, out] BufferOut     Buffer for response data.  \r
-  @param[in, out] SizeOut       Size of response data.  \r
\r
+  @param[in]      TisReg        TPM register space base address.\r
+  @param[in]      BufferIn      Buffer for command data.\r
+  @param[in]      SizeIn        Size of command data.\r
+  @param[in, out] BufferOut     Buffer for response data.\r
+  @param[in, out] SizeOut       Size of response data.\r
+\r
   @retval EFI_SUCCESS           Operation completed successfully.\r
   @retval EFI_BUFFER_TOO_SMALL  Response data buffer is too small.\r
   @retval EFI_DEVICE_ERROR      Unexpected device behavior.\r
@@ -224,26 +218,26 @@ Tpm2TisTpmCommand (
   UINT16                            Data16;\r
   UINT32                            Data32;\r
 \r
-  DEBUG_CODE (\r
+  DEBUG_CODE_BEGIN ();\r
     UINTN  DebugSize;\r
 \r
-    DEBUG ((EFI_D_VERBOSE, "Tpm2TisTpmCommand Send - "));\r
+    DEBUG ((DEBUG_VERBOSE, "Tpm2TisTpmCommand Send - "));\r
     if (SizeIn > 0x100) {\r
       DebugSize = 0x40;\r
     } else {\r
       DebugSize = SizeIn;\r
     }\r
     for (Index = 0; Index < DebugSize; Index++) {\r
-      DEBUG ((EFI_D_VERBOSE, "%02x ", BufferIn[Index]));\r
+      DEBUG ((DEBUG_VERBOSE, "%02x ", BufferIn[Index]));\r
     }\r
     if (DebugSize != SizeIn) {\r
-      DEBUG ((EFI_D_VERBOSE, "...... "));\r
+      DEBUG ((DEBUG_VERBOSE, "...... "));\r
       for (Index = SizeIn - 0x20; Index < SizeIn; Index++) {\r
-        DEBUG ((EFI_D_VERBOSE, "%02x ", BufferIn[Index]));\r
+        DEBUG ((DEBUG_VERBOSE, "%02x ", BufferIn[Index]));\r
       }\r
     }\r
-    DEBUG ((EFI_D_VERBOSE, "\n"));\r
-  );\r
+    DEBUG ((DEBUG_VERBOSE, "\n"));\r
+  DEBUG_CODE_END ();\r
   TpmOutSize = 0;\r
 \r
   Status = TisPcPrepareCommand (TisReg);\r
@@ -309,7 +303,7 @@ Tpm2TisTpmCommand (
                TIS_TIMEOUT_B\r
                );\r
     //\r
-    // Do not clear CANCEL bit here bicoz Writes of 0 to this bit are ignored\r
+    // Do not clear CANCEL bit here because Writes of 0 to this bit are ignored\r
     //\r
     if (EFI_ERROR (Status)) {\r
       //\r
@@ -338,20 +332,20 @@ Tpm2TisTpmCommand (
       if (Index == sizeof (TPM2_RESPONSE_HEADER)) break;\r
     }\r
   }\r
-  DEBUG_CODE (\r
-    DEBUG ((EFI_D_VERBOSE, "Tpm2TisTpmCommand ReceiveHeader - "));\r
+  DEBUG_CODE_BEGIN ();\r
+    DEBUG ((DEBUG_VERBOSE, "Tpm2TisTpmCommand ReceiveHeader - "));\r
     for (Index = 0; Index < sizeof (TPM2_RESPONSE_HEADER); Index++) {\r
-      DEBUG ((EFI_D_VERBOSE, "%02x ", BufferOut[Index]));\r
+      DEBUG ((DEBUG_VERBOSE, "%02x ", BufferOut[Index]));\r
     }\r
-    DEBUG ((EFI_D_VERBOSE, "\n"));\r
-  );\r
+    DEBUG ((DEBUG_VERBOSE, "\n"));\r
+  DEBUG_CODE_END ();\r
   //\r
-  // Check the reponse data header (tag,parasize and returncode )\r
+  // Check the response data header (tag,parasize and returncode )\r
   //\r
   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, "TPM2: TPM_ST_RSP error - %x\n", TPM_ST_RSP_COMMAND));\r
+    DEBUG ((DEBUG_ERROR, "TPM2: TPM_ST_RSP error - %x\n", TPM_ST_RSP_COMMAND));\r
     Status = EFI_UNSUPPORTED;\r
     goto Exit;\r
   }\r
@@ -382,13 +376,13 @@ Tpm2TisTpmCommand (
     }\r
   }\r
 Exit:\r
-  DEBUG_CODE (\r
-    DEBUG ((EFI_D_VERBOSE, "Tpm2TisTpmCommand Receive - "));\r
+  DEBUG_CODE_BEGIN ();\r
+    DEBUG ((DEBUG_VERBOSE, "Tpm2TisTpmCommand Receive - "));\r
     for (Index = 0; Index < TpmOutSize; Index++) {\r
-      DEBUG ((EFI_D_VERBOSE, "%02x ", BufferOut[Index]));\r
+      DEBUG ((DEBUG_VERBOSE, "%02x ", BufferOut[Index]));\r
     }\r
-    DEBUG ((EFI_D_VERBOSE, "\n"));\r
-  );\r
+    DEBUG ((DEBUG_VERBOSE, "\n"));\r
+  DEBUG_CODE_END ();\r
   MmioWrite8((UINTN)&TisReg->Status, TIS_PC_STS_READY);\r
   return Status;\r
 }\r
@@ -403,7 +397,7 @@ Exit:
 \r
   @retval EFI_SUCCESS            The command byte stream was successfully sent to the device and a response was successfully received.\r
   @retval EFI_DEVICE_ERROR       The command was not successfully sent to the device or a response was not successfully received from the device.\r
-  @retval EFI_BUFFER_TOO_SMALL   The output parameter block is too small. \r
+  @retval EFI_BUFFER_TOO_SMALL   The output parameter block is too small.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r