]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Tis.c
SecurityPkg: Apply uncrustify changes
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibDTpm / Tpm2Tis.c
index a3c84d8ab491ebb6487cecbc223080f8c61b7d23..49539b78d84db7a54d60f4a3db6a43aa35b2c008 100644 (file)
@@ -19,12 +19,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 \r
 #include <IndustryStandard/TpmTis.h>\r
 \r
-#define TIS_TIMEOUT_MAX             (90000 * 1000)  // 90s\r
+#define TIS_TIMEOUT_MAX  (90000 * 1000)             // 90s\r
 \r
 //\r
 // Max TPM command/response length\r
 //\r
-#define TPMCMDBUFLENGTH             0x500\r
+#define TPMCMDBUFLENGTH  0x500\r
 \r
 /**\r
   Check whether TPM chip exist.\r
@@ -36,10 +36,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 **/\r
 BOOLEAN\r
 TisPcPresenceCheck (\r
-  IN      TIS_PC_REGISTERS_PTR      TisReg\r
+  IN      TIS_PC_REGISTERS_PTR  TisReg\r
   )\r
 {\r
-  UINT8                             RegRead;\r
+  UINT8  RegRead;\r
 \r
   RegRead = MmioRead8 ((UINTN)&TisReg->Access);\r
   return (BOOLEAN)(RegRead != (UINT8)-1);\r
@@ -58,21 +58,24 @@ TisPcPresenceCheck (
 **/\r
 EFI_STATUS\r
 TisPcWaitRegisterBits (\r
-  IN      UINT8                     *Register,\r
-  IN      UINT8                     BitSet,\r
-  IN      UINT8                     BitClear,\r
-  IN      UINT32                    TimeOut\r
+  IN      UINT8   *Register,\r
+  IN      UINT8   BitSet,\r
+  IN      UINT8   BitClear,\r
+  IN      UINT32  TimeOut\r
   )\r
 {\r
-  UINT8                             RegRead;\r
-  UINT32                            WaitTime;\r
+  UINT8   RegRead;\r
+  UINT32  WaitTime;\r
 \r
-  for (WaitTime = 0; WaitTime < TimeOut; WaitTime += 30){\r
+  for (WaitTime = 0; WaitTime < TimeOut; WaitTime += 30) {\r
     RegRead = MmioRead8 ((UINTN)Register);\r
-    if ((RegRead & BitSet) == BitSet && (RegRead & BitClear) == 0)\r
+    if (((RegRead & BitSet) == BitSet) && ((RegRead & BitClear) == 0)) {\r
       return EFI_SUCCESS;\r
+    }\r
+\r
     MicroSecondDelay (30);\r
   }\r
+\r
   return EFI_TIMEOUT;\r
 }\r
 \r
@@ -89,15 +92,15 @@ TisPcWaitRegisterBits (
 **/\r
 EFI_STATUS\r
 TisPcReadBurstCount (\r
-  IN      TIS_PC_REGISTERS_PTR      TisReg,\r
-     OUT  UINT16                    *BurstCount\r
+  IN      TIS_PC_REGISTERS_PTR  TisReg,\r
+  OUT  UINT16                   *BurstCount\r
   )\r
 {\r
-  UINT32                            WaitTime;\r
-  UINT8                             DataByte0;\r
-  UINT8                             DataByte1;\r
+  UINT32  WaitTime;\r
+  UINT8   DataByte0;\r
+  UINT8   DataByte1;\r
 \r
-  if (BurstCount == NULL || TisReg == NULL) {\r
+  if ((BurstCount == NULL) || (TisReg == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -113,6 +116,7 @@ TisPcReadBurstCount (
     if (*BurstCount != 0) {\r
       return EFI_SUCCESS;\r
     }\r
+\r
     MicroSecondDelay (30);\r
     WaitTime += 30;\r
   } while (WaitTime < TIS_TIMEOUT_D);\r
@@ -132,16 +136,16 @@ TisPcReadBurstCount (
 **/\r
 EFI_STATUS\r
 TisPcPrepareCommand (\r
-  IN      TIS_PC_REGISTERS_PTR      TisReg\r
+  IN      TIS_PC_REGISTERS_PTR  TisReg\r
   )\r
 {\r
-  EFI_STATUS                        Status;\r
+  EFI_STATUS  Status;\r
 \r
   if (TisReg == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  MmioWrite8((UINTN)&TisReg->Status, TIS_PC_STS_READY);\r
+  MmioWrite8 ((UINTN)&TisReg->Status, TIS_PC_STS_READY);\r
   Status = TisPcWaitRegisterBits (\r
              &TisReg->Status,\r
              TIS_PC_STS_READY,\r
@@ -164,10 +168,10 @@ TisPcPrepareCommand (
 **/\r
 EFI_STATUS\r
 TisPcRequestUseTpm (\r
-  IN      TIS_PC_REGISTERS_PTR      TisReg\r
+  IN      TIS_PC_REGISTERS_PTR  TisReg\r
   )\r
 {\r
-  EFI_STATUS                        Status;\r
+  EFI_STATUS  Status;\r
 \r
   if (TisReg == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -177,7 +181,7 @@ TisPcRequestUseTpm (
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  MmioWrite8((UINTN)&TisReg->Access, TIS_PC_ACC_RQUUSE);\r
+  MmioWrite8 ((UINTN)&TisReg->Access, TIS_PC_ACC_RQUUSE);\r
   Status = TisPcWaitRegisterBits (\r
              &TisReg->Access,\r
              (UINT8)(TIS_PC_ACC_ACTIVE |TIS_PC_VALID),\r
@@ -204,47 +208,51 @@ TisPcRequestUseTpm (
 **/\r
 EFI_STATUS\r
 Tpm2TisTpmCommand (\r
-  IN     TIS_PC_REGISTERS_PTR       TisReg,\r
-  IN     UINT8                      *BufferIn,\r
-  IN     UINT32                     SizeIn,\r
-  IN OUT UINT8                      *BufferOut,\r
-  IN OUT UINT32                     *SizeOut\r
+  IN     TIS_PC_REGISTERS_PTR  TisReg,\r
+  IN     UINT8                 *BufferIn,\r
+  IN     UINT32                SizeIn,\r
+  IN OUT UINT8                 *BufferOut,\r
+  IN OUT UINT32                *SizeOut\r
   )\r
 {\r
-  EFI_STATUS                        Status;\r
-  UINT16                            BurstCount;\r
-  UINT32                            Index;\r
-  UINT32                            TpmOutSize;\r
-  UINT16                            Data16;\r
-  UINT32                            Data32;\r
+  EFI_STATUS  Status;\r
+  UINT16      BurstCount;\r
+  UINT32      Index;\r
+  UINT32      TpmOutSize;\r
+  UINT16      Data16;\r
+  UINT32      Data32;\r
 \r
   DEBUG_CODE_BEGIN ();\r
-    UINTN  DebugSize;\r
+  UINTN  DebugSize;\r
 \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 ((DEBUG_VERBOSE, "Tpm2TisTpmCommand Send - "));\r
+  if (SizeIn > 0x100) {\r
+    DebugSize = 0x40;\r
+  } else {\r
+    DebugSize = SizeIn;\r
+  }\r
+\r
+  for (Index = 0; Index < DebugSize; Index++) {\r
+    DEBUG ((DEBUG_VERBOSE, "%02x ", BufferIn[Index]));\r
+  }\r
+\r
+  if (DebugSize != SizeIn) {\r
+    DEBUG ((DEBUG_VERBOSE, "...... "));\r
+    for (Index = SizeIn - 0x20; Index < SizeIn; Index++) {\r
       DEBUG ((DEBUG_VERBOSE, "%02x ", BufferIn[Index]));\r
     }\r
-    if (DebugSize != SizeIn) {\r
-      DEBUG ((DEBUG_VERBOSE, "...... "));\r
-      for (Index = SizeIn - 0x20; Index < SizeIn; Index++) {\r
-        DEBUG ((DEBUG_VERBOSE, "%02x ", BufferIn[Index]));\r
-      }\r
-    }\r
-    DEBUG ((DEBUG_VERBOSE, "\n"));\r
+  }\r
+\r
+  DEBUG ((DEBUG_VERBOSE, "\n"));\r
   DEBUG_CODE_END ();\r
   TpmOutSize = 0;\r
 \r
   Status = TisPcPrepareCommand (TisReg);\r
-  if (EFI_ERROR (Status)){\r
+  if (EFI_ERROR (Status)) {\r
     DEBUG ((DEBUG_ERROR, "Tpm2 is not ready for command!\n"));\r
     return EFI_DEVICE_ERROR;\r
   }\r
+\r
   //\r
   // Send the command data to Tpm\r
   //\r
@@ -255,17 +263,19 @@ Tpm2TisTpmCommand (
       Status = EFI_DEVICE_ERROR;\r
       goto Exit;\r
     }\r
-    for (; BurstCount > 0 && Index < SizeIn; BurstCount--) {\r
-      MmioWrite8((UINTN)&TisReg->DataFifo, *(BufferIn + Index));\r
+\r
+    for ( ; BurstCount > 0 && Index < SizeIn; BurstCount--) {\r
+      MmioWrite8 ((UINTN)&TisReg->DataFifo, *(BufferIn + Index));\r
       Index++;\r
     }\r
   }\r
+\r
   //\r
   // Check the Tpm status STS_EXPECT change from 1 to 0\r
   //\r
   Status = TisPcWaitRegisterBits (\r
              &TisReg->Status,\r
-             (UINT8) TIS_PC_VALID,\r
+             (UINT8)TIS_PC_VALID,\r
              TIS_PC_STS_EXPECT,\r
              TIS_TIMEOUT_C\r
              );\r
@@ -274,17 +284,18 @@ Tpm2TisTpmCommand (
     Status = EFI_BUFFER_TOO_SMALL;\r
     goto Exit;\r
   }\r
+\r
   //\r
   // Executed the TPM command and waiting for the response data ready\r
   //\r
-  MmioWrite8((UINTN)&TisReg->Status, TIS_PC_STS_GO);\r
+  MmioWrite8 ((UINTN)&TisReg->Status, TIS_PC_STS_GO);\r
 \r
   //\r
   // NOTE: That may take many seconds to minutes for certain commands, such as key generation.\r
   //\r
   Status = TisPcWaitRegisterBits (\r
              &TisReg->Status,\r
-             (UINT8) (TIS_PC_VALID | TIS_PC_STS_DATA),\r
+             (UINT8)(TIS_PC_VALID | TIS_PC_STS_DATA),\r
              0,\r
              TIS_TIMEOUT_MAX\r
              );\r
@@ -295,10 +306,10 @@ Tpm2TisTpmCommand (
     //\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
+    MmioWrite32 ((UINTN)&TisReg->Status, TIS_PC_STS_CANCEL);\r
     Status = TisPcWaitRegisterBits (\r
                &TisReg->Status,\r
-               (UINT8) (TIS_PC_VALID | TIS_PC_STS_DATA),\r
+               (UINT8)(TIS_PC_VALID | TIS_PC_STS_DATA),\r
                0,\r
                TIS_TIMEOUT_B\r
                );\r
@@ -318,7 +329,7 @@ Tpm2TisTpmCommand (
   //\r
   // Get response data header\r
   //\r
-  Index = 0;\r
+  Index      = 0;\r
   BurstCount = 0;\r
   while (Index < sizeof (TPM2_RESPONSE_HEADER)) {\r
     Status = TisPcReadBurstCount (TisReg, &BurstCount);\r
@@ -326,18 +337,23 @@ Tpm2TisTpmCommand (
       Status = EFI_DEVICE_ERROR;\r
       goto Exit;\r
     }\r
-    for (; BurstCount > 0; BurstCount--) {\r
+\r
+    for ( ; BurstCount > 0; BurstCount--) {\r
       *(BufferOut + Index) = MmioRead8 ((UINTN)&TisReg->DataFifo);\r
       Index++;\r
-      if (Index == sizeof (TPM2_RESPONSE_HEADER)) break;\r
+      if (Index == sizeof (TPM2_RESPONSE_HEADER)) {\r
+        break;\r
+      }\r
     }\r
   }\r
+\r
   DEBUG_CODE_BEGIN ();\r
-    DEBUG ((DEBUG_VERBOSE, "Tpm2TisTpmCommand ReceiveHeader - "));\r
-    for (Index = 0; Index < sizeof (TPM2_RESPONSE_HEADER); Index++) {\r
-      DEBUG ((DEBUG_VERBOSE, "%02x ", BufferOut[Index]));\r
-    }\r
-    DEBUG ((DEBUG_VERBOSE, "\n"));\r
+  DEBUG ((DEBUG_VERBOSE, "Tpm2TisTpmCommand ReceiveHeader - "));\r
+  for (Index = 0; Index < sizeof (TPM2_RESPONSE_HEADER); Index++) {\r
+    DEBUG ((DEBUG_VERBOSE, "%02x ", BufferOut[Index]));\r
+  }\r
+\r
+  DEBUG ((DEBUG_VERBOSE, "\n"));\r
   DEBUG_CODE_END ();\r
   //\r
   // Check the response data header (tag,parasize and returncode )\r
@@ -351,17 +367,18 @@ Tpm2TisTpmCommand (
   }\r
 \r
   CopyMem (&Data32, (BufferOut + 2), sizeof (UINT32));\r
-  TpmOutSize  = SwapBytes32 (Data32);\r
+  TpmOutSize = SwapBytes32 (Data32);\r
   if (*SizeOut < TpmOutSize) {\r
     Status = EFI_BUFFER_TOO_SMALL;\r
     goto Exit;\r
   }\r
+\r
   *SizeOut = TpmOutSize;\r
   //\r
   // Continue reading the remaining data\r
   //\r
   while ( Index < TpmOutSize ) {\r
-    for (; BurstCount > 0; BurstCount--) {\r
+    for ( ; BurstCount > 0; BurstCount--) {\r
       *(BufferOut + Index) = MmioRead8 ((UINTN)&TisReg->DataFifo);\r
       Index++;\r
       if (Index == TpmOutSize) {\r
@@ -369,21 +386,24 @@ Tpm2TisTpmCommand (
         goto Exit;\r
       }\r
     }\r
+\r
     Status = TisPcReadBurstCount (TisReg, &BurstCount);\r
     if (EFI_ERROR (Status)) {\r
       Status = EFI_DEVICE_ERROR;\r
       goto Exit;\r
     }\r
   }\r
+\r
 Exit:\r
   DEBUG_CODE_BEGIN ();\r
-    DEBUG ((DEBUG_VERBOSE, "Tpm2TisTpmCommand Receive - "));\r
-    for (Index = 0; Index < TpmOutSize; Index++) {\r
-      DEBUG ((DEBUG_VERBOSE, "%02x ", BufferOut[Index]));\r
-    }\r
-    DEBUG ((DEBUG_VERBOSE, "\n"));\r
+  DEBUG ((DEBUG_VERBOSE, "Tpm2TisTpmCommand Receive - "));\r
+  for (Index = 0; Index < TpmOutSize; Index++) {\r
+    DEBUG ((DEBUG_VERBOSE, "%02x ", BufferOut[Index]));\r
+  }\r
+\r
+  DEBUG ((DEBUG_VERBOSE, "\n"));\r
   DEBUG_CODE_END ();\r
-  MmioWrite8((UINTN)&TisReg->Status, TIS_PC_STS_READY);\r
+  MmioWrite8 ((UINTN)&TisReg->Status, TIS_PC_STS_READY);\r
   return Status;\r
 }\r
 \r
@@ -402,14 +422,14 @@ Exit:
 EFI_STATUS\r
 EFIAPI\r
 DTpm2TisSubmitCommand (\r
-  IN UINT32            InputParameterBlockSize,\r
-  IN UINT8             *InputParameterBlock,\r
-  IN OUT UINT32        *OutputParameterBlockSize,\r
-  IN UINT8             *OutputParameterBlock\r
+  IN UINT32      InputParameterBlockSize,\r
+  IN UINT8       *InputParameterBlock,\r
+  IN OUT UINT32  *OutputParameterBlockSize,\r
+  IN UINT8       *OutputParameterBlock\r
   )\r
 {\r
   return Tpm2TisTpmCommand (\r
-           (TIS_PC_REGISTERS_PTR) (UINTN) PcdGet64 (PcdTpmBaseAddress),\r
+           (TIS_PC_REGISTERS_PTR)(UINTN)PcdGet64 (PcdTpmBaseAddress),\r
            InputParameterBlock,\r
            InputParameterBlockSize,\r
            OutputParameterBlock,\r
@@ -430,5 +450,5 @@ DTpm2TisRequestUseTpm (
   VOID\r
   )\r
 {\r
-  return TisPcRequestUseTpm ((TIS_PC_REGISTERS_PTR) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
+  return TisPcRequestUseTpm ((TIS_PC_REGISTERS_PTR)(UINTN)PcdGet64 (PcdTpmBaseAddress));\r
 }\r