]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / FirmwarePerformanceDataTableSmm / FirmwarePerformanceSmm.c
index 73188fb3dfd7cdee2a53a00b8dfe42d1df0d32e3..711272e073952a1e60af26656b138f7111b90d9c 100644 (file)
@@ -11,7 +11,7 @@
 \r
   FpdtSmiHandler() will receive untrusted input and do basic validation.\r
 \r
-  Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 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
 #include <Library/SynchronizationLib.h>\r
 #include <Library/SmmMemLib.h>\r
 \r
-#define EXTENSION_RECORD_SIZE     0x1000\r
+SMM_BOOT_PERFORMANCE_TABLE    *mSmmBootPerformanceTable = NULL;\r
 \r
 EFI_SMM_RSC_HANDLER_PROTOCOL  *mRscHandlerProtocol    = NULL;\r
 UINT64                        mSuspendStartTime       = 0;\r
 BOOLEAN                       mS3SuspendLockBoxSaved  = FALSE;\r
 UINT32                        mBootRecordSize = 0;\r
-UINT32                        mBootRecordMaxSize = 0;\r
 UINT8                         *mBootRecordBuffer = NULL;\r
 \r
 SPIN_LOCK                     mSmmFpdtLock;\r
@@ -84,7 +83,6 @@ FpdtStatusCodeListenerSmm (
   EFI_STATUS                           Status;\r
   UINT64                               CurrentTime;\r
   EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD  S3SuspendRecord;\r
-  UINT8                                *NewRecordBuffer;\r
 \r
   //\r
   // Check whether status code is what we are interested in.\r
@@ -92,40 +90,27 @@ FpdtStatusCodeListenerSmm (
   if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) != EFI_PROGRESS_CODE) {\r
     return EFI_UNSUPPORTED;\r
   }\r
-  \r
+\r
   //\r
   // Collect one or more Boot records in boot time\r
   //\r
-  if (Data != NULL && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) {\r
+  if (Data != NULL && CompareGuid (&Data->Type, &gEdkiiFpdtExtendedFirmwarePerformanceGuid)) {\r
     AcquireSpinLock (&mSmmFpdtLock);\r
-    \r
-    if (mBootRecordSize + Data->Size > mBootRecordMaxSize) {\r
-      //\r
-      // Try to allocate big SMRAM data to store Boot record. \r
-      //\r
-      if (mSmramIsOutOfResource) {\r
-        ReleaseSpinLock (&mSmmFpdtLock);\r
-        return EFI_OUT_OF_RESOURCES;\r
-      }\r
-      NewRecordBuffer = ReallocatePool (mBootRecordSize, mBootRecordSize + Data->Size + EXTENSION_RECORD_SIZE, mBootRecordBuffer); \r
-      if (NewRecordBuffer == NULL) {\r
-        ReleaseSpinLock (&mSmmFpdtLock);\r
-        mSmramIsOutOfResource = TRUE;\r
-        return EFI_OUT_OF_RESOURCES;\r
-      }\r
-      mBootRecordBuffer  = NewRecordBuffer;\r
-      mBootRecordMaxSize = mBootRecordSize + Data->Size + EXTENSION_RECORD_SIZE;\r
-    }\r
     //\r
-    // Save boot record into the temp memory space.\r
+    // Get the boot performance data.\r
     //\r
-    CopyMem (mBootRecordBuffer + mBootRecordSize, Data + 1, Data->Size);\r
-    mBootRecordSize += Data->Size;\r
-    \r
+    CopyMem (&mSmmBootPerformanceTable, Data + 1, Data->Size);\r
+    mBootRecordBuffer = ((UINT8 *) (mSmmBootPerformanceTable)) + sizeof (SMM_BOOT_PERFORMANCE_TABLE);\r
+\r
     ReleaseSpinLock (&mSmmFpdtLock);\r
     return EFI_SUCCESS;\r
   }\r
 \r
+  if (Data != NULL && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) {\r
+    DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerSmm: Performance data reported through gEfiFirmwarePerformanceGuid will not be collected by FirmwarePerformanceDataTableSmm\n"));\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   if ((Value != PcdGet32 (PcdProgressCodeS3SuspendStart)) &&\r
       (Value != PcdGet32 (PcdProgressCodeS3SuspendEnd))) {\r
     return EFI_UNSUPPORTED;\r
@@ -178,7 +163,7 @@ FpdtStatusCodeListenerSmm (
 /**\r
   Communication service SMI Handler entry.\r
 \r
-  This SMI handler provides services for report SMM boot records. \r
+  This SMI handler provides services for report SMM boot records.\r
 \r
   Caution: This function may receive untrusted input.\r
   Communicate buffer and buffer size are external input, so this function will do basic validation.\r
@@ -190,11 +175,11 @@ FpdtStatusCodeListenerSmm (
                                  be conveyed from a non-SMM environment into an SMM environment.\r
   @param[in, out] CommBufferSize The size of the CommBuffer.\r
 \r
-  @retval EFI_SUCCESS                         The interrupt was handled and quiesced. No other handlers \r
+  @retval EFI_SUCCESS                         The interrupt was handled and quiesced. No other handlers\r
                                               should still be called.\r
-  @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED  The interrupt has been quiesced but other handlers should \r
+  @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED  The interrupt has been quiesced but other handlers should\r
                                               still be called.\r
-  @retval EFI_WARN_INTERRUPT_SOURCE_PENDING   The interrupt is still pending and other handlers should still \r
+  @retval EFI_WARN_INTERRUPT_SOURCE_PENDING   The interrupt is still pending and other handlers should still\r
                                               be called.\r
   @retval EFI_INTERRUPT_PENDING               The interrupt could not be quiesced.\r
 \r
@@ -210,6 +195,7 @@ FpdtSmiHandler (
 {\r
   EFI_STATUS                   Status;\r
   SMM_BOOT_RECORD_COMMUNICATE  *SmmCommData;\r
+  UINTN                        BootRecordOffset;\r
   UINTN                        BootRecordSize;\r
   VOID                         *BootRecordData;\r
   UINTN                        TempCommBufferSize;\r
@@ -226,7 +212,7 @@ FpdtSmiHandler (
   if(TempCommBufferSize < sizeof (SMM_BOOT_RECORD_COMMUNICATE)) {\r
     return EFI_SUCCESS;\r
   }\r
-  \r
+\r
   if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
     DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM communication data buffer in SMRAM or overflow!\n"));\r
     return EFI_SUCCESS;\r
@@ -238,40 +224,51 @@ FpdtSmiHandler (
 \r
   switch (SmmCommData->Function) {\r
     case SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE :\r
-       SmmCommData->BootRecordSize = mBootRecordSize;\r
-       break;\r
+      if (mSmmBootPerformanceTable != NULL) {\r
+        mBootRecordSize = mSmmBootPerformanceTable->Header.Length - sizeof (SMM_BOOT_PERFORMANCE_TABLE);\r
+      }\r
+      SmmCommData->BootRecordSize = mBootRecordSize;\r
+      break;\r
 \r
     case SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA :\r
-       BootRecordData = SmmCommData->BootRecordData;\r
-       BootRecordSize = SmmCommData->BootRecordSize;\r
-       if (BootRecordData == NULL || BootRecordSize < mBootRecordSize) {\r
-         Status = EFI_INVALID_PARAMETER;\r
-         break;\r
-       } \r
-\r
-       //\r
-       // Sanity check\r
-       //\r
-       SmmCommData->BootRecordSize = mBootRecordSize;\r
-       if (!SmmIsBufferOutsideSmmValid ((UINTN)BootRecordData, mBootRecordSize)) {\r
-         DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM Data buffer in SMRAM or overflow!\n"));\r
-         Status = EFI_ACCESS_DENIED;\r
-         break;\r
-       }\r
-\r
-       CopyMem (\r
-         (UINT8*)BootRecordData, \r
-         mBootRecordBuffer, \r
-         mBootRecordSize\r
-         );\r
-       break;\r
+      Status = EFI_UNSUPPORTED;\r
+      break;\r
+\r
+    case SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET :\r
+      BootRecordOffset = SmmCommData->BootRecordOffset;\r
+      BootRecordData   = SmmCommData->BootRecordData;\r
+      BootRecordSize   = SmmCommData->BootRecordSize;\r
+      if (BootRecordData == NULL || BootRecordOffset >= mBootRecordSize) {\r
+        Status = EFI_INVALID_PARAMETER;\r
+        break;\r
+      }\r
+\r
+      //\r
+      // Sanity check\r
+      //\r
+      if (BootRecordSize > mBootRecordSize - BootRecordOffset) {\r
+        BootRecordSize = mBootRecordSize - BootRecordOffset;\r
+      }\r
+      SmmCommData->BootRecordSize = BootRecordSize;\r
+      if (!SmmIsBufferOutsideSmmValid ((UINTN)BootRecordData, BootRecordSize)) {\r
+        DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM Data buffer in SMRAM or overflow!\n"));\r
+        Status = EFI_ACCESS_DENIED;\r
+        break;\r
+      }\r
+\r
+      CopyMem (\r
+       (UINT8*)BootRecordData,\r
+       mBootRecordBuffer + BootRecordOffset,\r
+       BootRecordSize\r
+       );\r
+      break;\r
 \r
     default:\r
-       Status = EFI_UNSUPPORTED;\r
+      Status = EFI_UNSUPPORTED;\r
   }\r
 \r
   SmmCommData->ReturnStatus = Status;\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -298,8 +295,8 @@ FirmwarePerformanceSmmEntryPoint (
   //\r
   // Initialize spin lock\r
   //\r
-  InitializeSpinLock (&mSmmFpdtLock); \r
-   \r
+  InitializeSpinLock (&mSmmFpdtLock);\r
+\r
   //\r
   // Get SMM Report Status Code Handler Protocol.\r
   //\r