]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
SecurityPkg: Apply uncrustify changes
[mirror_edk2.git] / SecurityPkg / Tcg / Tcg2Smm / Tcg2Smm.c
index 9f5111552b82309fbaddeb0f38058751f8120cfe..498fb626bd9c956b57f412a1cba0d7e9cb4c31eb 100644 (file)
@@ -18,10 +18,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include "Tcg2Smm.h"\r
 \r
 EFI_SMM_VARIABLE_PROTOCOL  *mSmmVariable = NULL;\r
-TCG_NVS                    *mTcgNvs = NULL;\r
-UINTN                       mPpSoftwareSmi;\r
-UINTN                       mMcSoftwareSmi;\r
-EFI_HANDLE                  mReadyToLockHandle;\r
+TCG_NVS                    *mTcgNvs      = NULL;\r
+UINTN                      mPpSoftwareSmi;\r
+UINTN                      mMcSoftwareSmi;\r
+EFI_HANDLE                 mReadyToLockHandle;\r
 \r
 /**\r
   Communication service SMI Handler entry.\r
@@ -47,32 +47,33 @@ EFI_HANDLE                  mReadyToLockHandle;
 EFI_STATUS\r
 EFIAPI\r
 TpmNvsCommunciate (\r
-  IN     EFI_HANDLE                   DispatchHandle,\r
-  IN     CONST VOID                   *RegisterContext,\r
-  IN OUT VOID                         *CommBuffer,\r
-  IN OUT UINTN                        *CommBufferSize\r
+  IN     EFI_HANDLE  DispatchHandle,\r
+  IN     CONST VOID  *RegisterContext,\r
+  IN OUT VOID        *CommBuffer,\r
+  IN OUT UINTN       *CommBufferSize\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
-  UINTN                     TempCommBufferSize;\r
-  TPM_NVS_MM_COMM_BUFFER    *CommParams;\r
+  EFI_STATUS              Status;\r
+  UINTN                   TempCommBufferSize;\r
+  TPM_NVS_MM_COMM_BUFFER  *CommParams;\r
 \r
   DEBUG ((DEBUG_VERBOSE, "%a()\n", __FUNCTION__));\r
 \r
   //\r
   // If input is invalid, stop processing this SMI\r
   //\r
-  if (CommBuffer == NULL || CommBufferSize == NULL) {\r
+  if ((CommBuffer == NULL) || (CommBufferSize == NULL)) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
   TempCommBufferSize = *CommBufferSize;\r
 \r
-  if(TempCommBufferSize != sizeof (TPM_NVS_MM_COMM_BUFFER)) {\r
+  if (TempCommBufferSize != sizeof (TPM_NVS_MM_COMM_BUFFER)) {\r
     DEBUG ((DEBUG_ERROR, "[%a] MM Communication buffer size is invalid for this handler!\n", __FUNCTION__));\r
     return EFI_ACCESS_DENIED;\r
   }\r
-  if (!IsBufferOutsideMmValid ((UINTN) CommBuffer, TempCommBufferSize)) {\r
+\r
+  if (!IsBufferOutsideMmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
     DEBUG ((DEBUG_ERROR, "[%a] - MM Communication buffer in invalid location!\n", __FUNCTION__));\r
     return EFI_ACCESS_DENIED;\r
   }\r
@@ -80,14 +81,14 @@ TpmNvsCommunciate (
   //\r
   // Farm out the job to individual functions based on what was requested.\r
   //\r
-  CommParams = (TPM_NVS_MM_COMM_BUFFER*) CommBuffer;\r
-  Status = EFI_SUCCESS;\r
+  CommParams = (TPM_NVS_MM_COMM_BUFFER *)CommBuffer;\r
+  Status     = EFI_SUCCESS;\r
   switch (CommParams->Function) {\r
     case TpmNvsMmExchangeInfo:\r
       DEBUG ((DEBUG_VERBOSE, "[%a] - Function requested: MM_EXCHANGE_NVS_INFO\n", __FUNCTION__));\r
       CommParams->RegisteredPpSwiValue = mPpSoftwareSmi;\r
       CommParams->RegisteredMcSwiValue = mMcSoftwareSmi;\r
-      mTcgNvs = (TCG_NVS*) (UINTN) CommParams->TargetAddress;\r
+      mTcgNvs                          = (TCG_NVS *)(UINTN)CommParams->TargetAddress;\r
       break;\r
 \r
     default:\r
@@ -96,7 +97,7 @@ TpmNvsCommunciate (
       break;\r
   }\r
 \r
-  CommParams->ReturnStatus = (UINT64) Status;\r
+  CommParams->ReturnStatus = (UINT64)Status;\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -120,17 +121,16 @@ TpmNvsCommunciate (
 EFI_STATUS\r
 EFIAPI\r
 PhysicalPresenceCallback (\r
-  IN EFI_HANDLE                  DispatchHandle,\r
-  IN CONST VOID                  *Context,\r
-  IN OUT VOID                    *CommBuffer,\r
-  IN OUT UINTN                   *CommBufferSize\r
+  IN EFI_HANDLE  DispatchHandle,\r
+  IN CONST VOID  *Context,\r
+  IN OUT VOID    *CommBuffer,\r
+  IN OUT UINTN   *CommBufferSize\r
   )\r
 {\r
-  UINT32                MostRecentRequest;\r
-  UINT32                Response;\r
-  UINT32                OperationRequest;\r
-  UINT32                RequestParameter;\r
-\r
+  UINT32  MostRecentRequest;\r
+  UINT32  Response;\r
+  UINT32  OperationRequest;\r
+  UINT32  RequestParameter;\r
 \r
   if (mTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_RETURN_REQUEST_RESPONSE_TO_OS) {\r
     mTcgNvs->PhysicalPresence.ReturnCode = Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (\r
@@ -138,18 +138,18 @@ PhysicalPresenceCallback (
                                              &Response\r
                                              );\r
     mTcgNvs->PhysicalPresence.LastRequest = MostRecentRequest;\r
-    mTcgNvs->PhysicalPresence.Response = Response;\r
+    mTcgNvs->PhysicalPresence.Response    = Response;\r
     return EFI_SUCCESS;\r
-  } else if ((mTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS)\r
-          || (mTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS_2)) {\r
-\r
-    OperationRequest = mTcgNvs->PhysicalPresence.Request;\r
-    RequestParameter = mTcgNvs->PhysicalPresence.RequestParameter;\r
+  } else if (  (mTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS)\r
+            || (mTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS_2))\r
+  {\r
+    OperationRequest                     = mTcgNvs->PhysicalPresence.Request;\r
+    RequestParameter                     = mTcgNvs->PhysicalPresence.RequestParameter;\r
     mTcgNvs->PhysicalPresence.ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (\r
                                              &OperationRequest,\r
                                              &RequestParameter\r
                                              );\r
-    mTcgNvs->PhysicalPresence.Request = OperationRequest;\r
+    mTcgNvs->PhysicalPresence.Request          = OperationRequest;\r
     mTcgNvs->PhysicalPresence.RequestParameter = RequestParameter;\r
   } else if (mTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_GET_USER_CONFIRMATION_STATUS_FOR_REQUEST) {\r
     mTcgNvs->PhysicalPresence.ReturnCode = Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (mTcgNvs->PPRequestUserConfirm);\r
@@ -158,7 +158,6 @@ PhysicalPresenceCallback (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Software SMI callback for MemoryClear which is called from ACPI method.\r
 \r
@@ -179,28 +178,28 @@ PhysicalPresenceCallback (
 EFI_STATUS\r
 EFIAPI\r
 MemoryClearCallback (\r
-  IN EFI_HANDLE                  DispatchHandle,\r
-  IN CONST VOID                  *Context,\r
-  IN OUT VOID                    *CommBuffer,\r
-  IN OUT UINTN                   *CommBufferSize\r
+  IN EFI_HANDLE  DispatchHandle,\r
+  IN CONST VOID  *Context,\r
+  IN OUT VOID    *CommBuffer,\r
+  IN OUT UINTN   *CommBufferSize\r
   )\r
 {\r
-  EFI_STATUS                     Status;\r
-  UINTN                          DataSize;\r
-  UINT8                          MorControl;\r
+  EFI_STATUS  Status;\r
+  UINTN       DataSize;\r
+  UINT8       MorControl;\r
 \r
   mTcgNvs->MemoryClear.ReturnCode = MOR_REQUEST_SUCCESS;\r
   if (mTcgNvs->MemoryClear.Parameter == ACPI_FUNCTION_DSM_MEMORY_CLEAR_INTERFACE) {\r
-    MorControl = (UINT8) mTcgNvs->MemoryClear.Request;\r
+    MorControl = (UINT8)mTcgNvs->MemoryClear.Request;\r
   } else if (mTcgNvs->MemoryClear.Parameter == ACPI_FUNCTION_PTS_CLEAR_MOR_BIT) {\r
     DataSize = sizeof (UINT8);\r
-    Status = mSmmVariable->SmmGetVariable (\r
-                             MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,\r
-                             &gEfiMemoryOverwriteControlDataGuid,\r
-                             NULL,\r
-                             &DataSize,\r
-                             &MorControl\r
-                             );\r
+    Status   = mSmmVariable->SmmGetVariable (\r
+                               MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,\r
+                               &gEfiMemoryOverwriteControlDataGuid,\r
+                               NULL,\r
+                               &DataSize,\r
+                               &MorControl\r
+                               );\r
     if (EFI_ERROR (Status)) {\r
       mTcgNvs->MemoryClear.ReturnCode = MOR_REQUEST_GENERAL_FAILURE;\r
       DEBUG ((DEBUG_ERROR, "[TPM] Get MOR variable failure! Status = %r\n", Status));\r
@@ -210,6 +209,7 @@ MemoryClearCallback (
     if (MOR_CLEAR_MEMORY_VALUE (MorControl) == 0x0) {\r
       return EFI_SUCCESS;\r
     }\r
+\r
     MorControl &= ~MOR_CLEAR_MEMORY_BIT_MASK;\r
   } else {\r
     mTcgNvs->MemoryClear.ReturnCode = MOR_REQUEST_GENERAL_FAILURE;\r
@@ -218,13 +218,13 @@ MemoryClearCallback (
   }\r
 \r
   DataSize = sizeof (UINT8);\r
-  Status = mSmmVariable->SmmSetVariable (\r
-                           MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,\r
-                           &gEfiMemoryOverwriteControlDataGuid,\r
-                           EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-                           DataSize,\r
-                           &MorControl\r
-                           );\r
+  Status   = mSmmVariable->SmmSetVariable (\r
+                             MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,\r
+                             &gEfiMemoryOverwriteControlDataGuid,\r
+                             EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+                             DataSize,\r
+                             &MorControl\r
+                             );\r
   if (EFI_ERROR (Status)) {\r
     mTcgNvs->MemoryClear.ReturnCode = MOR_REQUEST_GENERAL_FAILURE;\r
     DEBUG ((DEBUG_ERROR, "[TPM] Set MOR variable failure! Status = %r\n", Status));\r
@@ -249,16 +249,17 @@ TcgMmReadyToLock (
   IN CONST EFI_GUID  *Protocol,\r
   IN VOID            *Interface,\r
   IN EFI_HANDLE      Handle\r
-)\r
+  )\r
 {\r
-  EFI_STATUS Status;\r
+  EFI_STATUS  Status;\r
 \r
   Status = EFI_SUCCESS;\r
 \r
   if (mReadyToLockHandle != NULL) {\r
-    Status = gMmst->MmiHandlerUnRegister (mReadyToLockHandle);\r
+    Status             = gMmst->MmiHandlerUnRegister (mReadyToLockHandle);\r
     mReadyToLockHandle = NULL;\r
   }\r
+\r
   return Status;\r
 }\r
 \r
@@ -284,17 +285,17 @@ InitializeTcgCommon (
   EFI_HANDLE                     McSwHandle;\r
   EFI_HANDLE                     NotifyHandle;\r
 \r
-  if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm20DtpmGuid)){\r
+  if (!CompareGuid (PcdGetPtr (PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm20DtpmGuid)) {\r
     DEBUG ((DEBUG_ERROR, "No TPM2 DTPM instance required!\n"));\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
   // Initialize variables first\r
   mReadyToLockHandle = NULL;\r
-  SwDispatch = NULL;\r
-  PpSwHandle = NULL;\r
-  McSwHandle = NULL;\r
-  NotifyHandle = NULL;\r
+  SwDispatch         = NULL;\r
+  PpSwHandle         = NULL;\r
+  McSwHandle         = NULL;\r
+  NotifyHandle       = NULL;\r
 \r
   // Register a root handler to communicate the NVS region and SMI channel between MM and DXE\r
   Status = gMmst->MmiHandlerRegister (TpmNvsCommunciate, &gTpmNvsMmGuid, &mReadyToLockHandle);\r
@@ -307,35 +308,37 @@ InitializeTcgCommon (
   //\r
   // Get the Sw dispatch protocol and register SMI callback functions.\r
   //\r
-  Status = gMmst->MmLocateProtocol (&gEfiSmmSwDispatch2ProtocolGuid, NULL, (VOID**)&SwDispatch);\r
+  Status = gMmst->MmLocateProtocol (&gEfiSmmSwDispatch2ProtocolGuid, NULL, (VOID **)&SwDispatch);\r
   ASSERT_EFI_ERROR (Status);\r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((DEBUG_ERROR, "[%a] Failed to locate Sw dispatch protocol - %r!\n", __FUNCTION__, Status));\r
     goto Cleanup;\r
   }\r
 \r
-  SwContext.SwSmiInputValue = (UINTN) -1;\r
-  Status = SwDispatch->Register (SwDispatch, PhysicalPresenceCallback, &SwContext, &PpSwHandle);\r
+  SwContext.SwSmiInputValue = (UINTN)-1;\r
+  Status                    = SwDispatch->Register (SwDispatch, PhysicalPresenceCallback, &SwContext, &PpSwHandle);\r
   ASSERT_EFI_ERROR (Status);\r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((DEBUG_ERROR, "[%a] Failed to register PP callback as SW MM handler - %r!\n", __FUNCTION__, Status));\r
     goto Cleanup;\r
   }\r
+\r
   mPpSoftwareSmi = SwContext.SwSmiInputValue;\r
 \r
-  SwContext.SwSmiInputValue = (UINTN) -1;\r
-  Status = SwDispatch->Register (SwDispatch, MemoryClearCallback, &SwContext, &McSwHandle);\r
+  SwContext.SwSmiInputValue = (UINTN)-1;\r
+  Status                    = SwDispatch->Register (SwDispatch, MemoryClearCallback, &SwContext, &McSwHandle);\r
   ASSERT_EFI_ERROR (Status);\r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((DEBUG_ERROR, "[%a] Failed to register MC callback as SW MM handler - %r!\n", __FUNCTION__, Status));\r
     goto Cleanup;\r
   }\r
+\r
   mMcSoftwareSmi = SwContext.SwSmiInputValue;\r
 \r
   //\r
   // Locate SmmVariableProtocol.\r
   //\r
-  Status = gMmst->MmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID**)&mSmmVariable);\r
+  Status = gMmst->MmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **)&mSmmVariable);\r
   ASSERT_EFI_ERROR (Status);\r
   if (EFI_ERROR (Status)) {\r
     // Should not happen\r
@@ -359,12 +362,15 @@ Cleanup:
     if (NotifyHandle != NULL) {\r
       gMmst->MmRegisterProtocolNotify (&gEfiMmReadyToLockProtocolGuid, NULL, &NotifyHandle);\r
     }\r
-    if (McSwHandle != NULL && SwDispatch != NULL) {\r
+\r
+    if ((McSwHandle != NULL) && (SwDispatch != NULL)) {\r
       SwDispatch->UnRegister (SwDispatch, McSwHandle);\r
     }\r
-    if (PpSwHandle != NULL && SwDispatch != NULL) {\r
+\r
+    if ((PpSwHandle != NULL) && (SwDispatch != NULL)) {\r
       SwDispatch->UnRegister (SwDispatch, PpSwHandle);\r
     }\r
+\r
     if (mReadyToLockHandle != NULL) {\r
       gMmst->MmiHandlerUnRegister (mReadyToLockHandle);\r
     }\r