]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c
Remove ASSERT check for SetVariable in FirmwarePerformanceDataTableDxe
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / FirmwarePerformanceDataTableDxe / FirmwarePerformanceDxe.c
index fbd0046513eecceb73d27264f2009587010e312a..caf924ccf8e7a9b04ab32e89b7d7ca6f2d1d9782 100644 (file)
@@ -2,9 +2,10 @@
   This module install ACPI Firmware Performance Data Table (FPDT).\r
 \r
   This module register report status code listener to collect performance data\r
-  for Firmware Basic Boot Performance Record and install FPDT to ACPI table.\r
+  for Firmware Basic Boot Performance Record and other boot performance records, \r
+  and install FPDT to ACPI table.\r
 \r
-  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 2014, 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
 \r
 #include <PiDxe.h>\r
 \r
-#include <IndustryStandard/Acpi50.h>\r
-\r
 #include <Protocol/ReportStatusCodeHandler.h>\r
 #include <Protocol/AcpiTable.h>\r
+#include <Protocol/SmmCommunication.h>\r
+#include <Protocol/LockBox.h>\r
+#include <Protocol/Variable.h>\r
 \r
 #include <Guid/Acpi.h>\r
 #include <Guid/FirmwarePerformance.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/HobLib.h>\r
-#include <Library/PcdLib.h>\r
+#include <Library/LockBoxLib.h>\r
+#include <Library/UefiLib.h>\r
 \r
-//\r
-// ACPI table information used to initialize tables.\r
-//\r
-#define EFI_ACPI_OEM_ID           "INTEL"\r
-#define EFI_ACPI_OEM_TABLE_ID     0x2020204F4E414954ULL // "TIANO   "\r
-#define EFI_ACPI_OEM_REVISION     0x00000001\r
-#define EFI_ACPI_CREATOR_ID       0x5446534D            // TBD "MSFT"\r
-#define EFI_ACPI_CREATOR_REVISION 0x01000013            // TBD\r
+#define EXTENSION_RECORD_SIZE     0x10000\r
+#define SMM_BOOT_RECORD_COMM_SIZE OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE)\r
 \r
 EFI_RSC_HANDLER_PROTOCOL    *mRscHandlerProtocol = NULL;\r
 \r
+BOOLEAN                     mLockBoxReady = FALSE;\r
 EFI_EVENT                   mReadyToBootEvent;\r
 EFI_EVENT                   mLegacyBootEvent;\r
 EFI_EVENT                   mExitBootServicesEvent;\r
 UINTN                       mFirmwarePerformanceTableTemplateKey  = 0;\r
+UINT32                      mBootRecordSize = 0;\r
+UINT32                      mBootRecordMaxSize = 0;\r
+UINT8                       *mBootRecordBuffer = NULL;\r
 \r
-FIRMWARE_PERFORMANCE_RUNTIME_DATA           *mPerformanceRuntimeData   = NULL;\r
 BOOT_PERFORMANCE_TABLE                      *mAcpiBootPerformanceTable = NULL;\r
 S3_PERFORMANCE_TABLE                        *mAcpiS3PerformanceTable   = NULL;\r
 \r
@@ -65,13 +65,13 @@ FIRMWARE_PERFORMANCE_TABLE  mFirmwarePerformanceTableTemplate = {
     EFI_ACPI_5_0_FIRMWARE_PERFORMANCE_DATA_TABLE_REVISION,    // Revision\r
     0x00, // Checksum will be updated at runtime\r
     //\r
-    // It is expected that these values will be updated at runtime.\r
+    // It is expected that these values will be updated at EntryPoint.\r
     //\r
-    EFI_ACPI_OEM_ID,            // OEMID is a 6 bytes long field\r
-    EFI_ACPI_OEM_TABLE_ID,      // OEM table identification(8 bytes long)\r
-    EFI_ACPI_OEM_REVISION,      // OEM revision number\r
-    EFI_ACPI_CREATOR_ID,        // ASL compiler vendor ID\r
-    EFI_ACPI_CREATOR_REVISION,  // ASL compiler revision number\r
+    {0x00},     // OEM ID is a 6 bytes long field\r
+    0x00,       // OEM Table ID(8 bytes long)\r
+    0x00,       // OEM Revision\r
+    0x00,       // Creator ID\r
+    0x00,       // Creator Revision\r
   },\r
   //\r
   // Firmware Basic Boot Performance Table Pointer Record.\r
@@ -202,6 +202,7 @@ FpdtAllocateReservedMemoryBelow4G (
   EFI_STATUS            Status;\r
   VOID                  *Buffer;\r
 \r
+  Buffer  = NULL;\r
   Pages   = EFI_SIZE_TO_PAGES (Size);\r
   Address = 0xffffffff;\r
 \r
@@ -213,12 +214,106 @@ FpdtAllocateReservedMemoryBelow4G (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  Buffer = (VOID *) (UINTN) Address;\r
-  ZeroMem (Buffer, Size);\r
+  if (!EFI_ERROR (Status)) {\r
+    Buffer = (VOID *) (UINTN) Address;\r
+    ZeroMem (Buffer, Size);\r
+  }\r
 \r
   return Buffer;\r
 }\r
 \r
+/**\r
+  Callback function upon VariableArchProtocol and LockBoxProtocol\r
+  to allocate S3 performance table memory and save the pointer to LockBox.\r
+\r
+  @param[in] Event    Event whose notification function is being invoked.\r
+  @param[in] Context  Pointer to the notification function's context.\r
+**/\r
+VOID\r
+EFIAPI\r
+FpdtAllocateS3PerformanceTableMemory (\r
+  IN  EFI_EVENT                             Event,\r
+  IN  VOID                                  *Context\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  VOID                          *Interface;\r
+  FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;\r
+  UINTN                         Size;\r
+  EFI_PHYSICAL_ADDRESS          S3PerformanceTablePointer;\r
+\r
+  if (mLockBoxReady && (mAcpiS3PerformanceTable != NULL)) {\r
+    //\r
+    // The memory for S3 performance table should have been ready,\r
+    // and the pointer should have been saved to LockBox, just return.\r
+    //\r
+    return;\r
+  }\r
+\r
+  if (!mLockBoxReady) {\r
+    Status = gBS->LocateProtocol (&gEfiLockBoxProtocolGuid, NULL, &Interface);\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // LockBox services has been ready.\r
+      //\r
+      mLockBoxReady = TRUE;\r
+    }\r
+  }\r
+\r
+  if (mAcpiS3PerformanceTable == NULL) {\r
+    Status = gBS->LocateProtocol (&gEfiVariableArchProtocolGuid, NULL, &Interface);\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Try to allocate the same runtime buffer as last time boot.\r
+      //\r
+      ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable));\r
+      Size = sizeof (PerformanceVariable);\r
+      Status = gRT->GetVariable (\r
+                      EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,\r
+                      &gEfiFirmwarePerformanceGuid,\r
+                      NULL,\r
+                      &Size,\r
+                      &PerformanceVariable\r
+                      );\r
+      if (!EFI_ERROR (Status)) {\r
+        Status = gBS->AllocatePages (\r
+                        AllocateAddress,\r
+                        EfiReservedMemoryType,\r
+                        EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE)),\r
+                        &PerformanceVariable.S3PerformanceTablePointer\r
+                        );\r
+        if (!EFI_ERROR (Status)) {\r
+          mAcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.S3PerformanceTablePointer;\r
+        }\r
+      }\r
+      if (mAcpiS3PerformanceTable == NULL) {\r
+        //\r
+        // Fail to allocate at specified address, continue to allocate at any address.\r
+        //\r
+        mAcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) FpdtAllocateReservedMemoryBelow4G (sizeof (S3_PERFORMANCE_TABLE));\r
+      }\r
+      DEBUG ((EFI_D_INFO, "FPDT: ACPI S3 Performance Table address = 0x%x\n", mAcpiS3PerformanceTable));\r
+      if (mAcpiS3PerformanceTable != NULL) {\r
+        CopyMem (mAcpiS3PerformanceTable, &mS3PerformanceTableTemplate, sizeof (mS3PerformanceTableTemplate));\r
+      }\r
+    }\r
+  }\r
+\r
+  if (mLockBoxReady && (mAcpiS3PerformanceTable != NULL)) {\r
+    //\r
+    // If LockBox services has been ready and memory for FPDT S3 performance table has been allocated,\r
+    // save the pointer to LockBox for use in S3 resume.\r
+    //\r
+    S3PerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) mAcpiS3PerformanceTable;\r
+    Status = SaveLockBox (\r
+               &gFirmwarePerformanceS3PointerGuid,\r
+               &S3PerformanceTablePointer,\r
+               sizeof (EFI_PHYSICAL_ADDRESS)\r
+               );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+}\r
+\r
 /**\r
   Install ACPI Firmware Performance Data Table (FPDT).\r
 \r
@@ -232,9 +327,15 @@ InstallFirmwarePerformanceDataTable (
 {\r
   EFI_STATUS                    Status;\r
   EFI_ACPI_TABLE_PROTOCOL       *AcpiTableProtocol;\r
-  FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;\r
-  EFI_PHYSICAL_ADDRESS          Address;\r
   UINTN                         Size;\r
+  UINT8                         *SmmBootRecordCommBuffer;\r
+  EFI_SMM_COMMUNICATE_HEADER    *SmmCommBufferHeader;\r
+  SMM_BOOT_RECORD_COMMUNICATE   *SmmCommData;\r
+  UINTN                         CommSize;\r
+  UINTN                         BootPerformanceDataSize;\r
+  UINT8                         *BootPerformanceData; \r
+  EFI_SMM_COMMUNICATION_PROTOCOL  *Communication;\r
+  FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;\r
 \r
   //\r
   // Get AcpiTable Protocol.\r
@@ -245,14 +346,61 @@ InstallFirmwarePerformanceDataTable (
   }\r
 \r
   //\r
-  // Prepare memory for runtime Performance Record.\r
+  // Collect boot records from SMM drivers.\r
   //\r
-  mPerformanceRuntimeData = NULL;\r
-  ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable));\r
+  SmmBootRecordCommBuffer = NULL;\r
+  SmmCommData             = NULL;\r
+  Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &Communication);\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Initialize communicate buffer \r
+    //\r
+    SmmBootRecordCommBuffer = AllocateZeroPool (SMM_BOOT_RECORD_COMM_SIZE);\r
+    ASSERT (SmmBootRecordCommBuffer != NULL);\r
+    SmmCommBufferHeader = (EFI_SMM_COMMUNICATE_HEADER*)SmmBootRecordCommBuffer;\r
+    SmmCommData = (SMM_BOOT_RECORD_COMMUNICATE*)SmmCommBufferHeader->Data;\r
+    ZeroMem((UINT8*)SmmCommData, sizeof(SMM_BOOT_RECORD_COMMUNICATE));\r
+\r
+    CopyGuid (&SmmCommBufferHeader->HeaderGuid, &gEfiFirmwarePerformanceGuid);\r
+    SmmCommBufferHeader->MessageLength = sizeof(SMM_BOOT_RECORD_COMMUNICATE);\r
+    CommSize = SMM_BOOT_RECORD_COMM_SIZE;\r
+  \r
+    //\r
+    // Get the size of boot records.\r
+    //\r
+    SmmCommData->Function       = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE;\r
+    SmmCommData->BootRecordData = NULL;\r
+    Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);\r
+    ASSERT_EFI_ERROR (Status);\r
+  \r
+    if (!EFI_ERROR (SmmCommData->ReturnStatus) && SmmCommData->BootRecordSize != 0) {\r
+      //\r
+      // Get all boot records\r
+      //\r
+      SmmCommData->Function       = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA;\r
+      SmmCommData->BootRecordData = AllocateZeroPool(SmmCommData->BootRecordSize);\r
+      ASSERT (SmmCommData->BootRecordData != NULL);\r
+      \r
+      Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);\r
+      ASSERT_EFI_ERROR (Status);\r
+      ASSERT_EFI_ERROR(SmmCommData->ReturnStatus);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Prepare memory for Boot Performance table.\r
+  // Boot Performance table includes BasicBoot record, and one or more appended Boot Records. \r
+  //\r
+  BootPerformanceDataSize = sizeof (BOOT_PERFORMANCE_TABLE) + mBootRecordSize + PcdGet32 (PcdExtFpdtBootRecordPadSize);\r
+  if (SmmCommData != NULL) {\r
+    BootPerformanceDataSize += SmmCommData->BootRecordSize;\r
+  }\r
+\r
   //\r
   // Try to allocate the same runtime buffer as last time boot.\r
   //\r
-  Size = sizeof (FIRMWARE_PERFORMANCE_VARIABLE);\r
+  ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable));\r
+  Size = sizeof (PerformanceVariable);\r
   Status = gRT->GetVariable (\r
                   EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,\r
                   &gEfiFirmwarePerformanceGuid,\r
@@ -261,36 +409,66 @@ InstallFirmwarePerformanceDataTable (
                   &PerformanceVariable\r
                   );\r
   if (!EFI_ERROR (Status)) {\r
-    Address = PerformanceVariable.BootPerformanceTablePointer;\r
     Status = gBS->AllocatePages (\r
                     AllocateAddress,\r
                     EfiReservedMemoryType,\r
-                    EFI_SIZE_TO_PAGES (sizeof (FIRMWARE_PERFORMANCE_RUNTIME_DATA)),\r
-                    &Address\r
+                    EFI_SIZE_TO_PAGES (BootPerformanceDataSize),\r
+                    &PerformanceVariable.BootPerformanceTablePointer\r
                     );\r
     if (!EFI_ERROR (Status)) {\r
-      mPerformanceRuntimeData = (FIRMWARE_PERFORMANCE_RUNTIME_DATA *) (UINTN) Address;\r
+      mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.BootPerformanceTablePointer;\r
     }\r
   }\r
 \r
-  if (mPerformanceRuntimeData == NULL) {\r
+  if (mAcpiBootPerformanceTable == NULL) {\r
     //\r
     // Fail to allocate at specified address, continue to allocate at any address.\r
     //\r
-    mPerformanceRuntimeData = FpdtAllocateReservedMemoryBelow4G (sizeof (FIRMWARE_PERFORMANCE_RUNTIME_DATA));\r
+    mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) FpdtAllocateReservedMemoryBelow4G (BootPerformanceDataSize);\r
   }\r
-  DEBUG ((EFI_D_INFO, "FPDT: Performance Runtime Data address = 0x%x\n", mPerformanceRuntimeData));\r
+  DEBUG ((EFI_D_INFO, "FPDT: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));\r
 \r
-  if (mPerformanceRuntimeData == NULL) {\r
+  if (mAcpiBootPerformanceTable == NULL) {\r
+    if (SmmCommData != NULL && SmmCommData->BootRecordData != NULL) {\r
+      FreePool (SmmCommData->BootRecordData);\r
+    }\r
+    if (SmmBootRecordCommBuffer != NULL) {\r
+      FreePool (SmmBootRecordCommBuffer);\r
+    }\r
+    if (mAcpiS3PerformanceTable != NULL) {\r
+      FreePages (mAcpiS3PerformanceTable, EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE)));\r
+    }\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
   //\r
   // Prepare Boot Performance Table.\r
   //\r
-  mAcpiBootPerformanceTable = &mPerformanceRuntimeData->BootPerformance;\r
+  BootPerformanceData = (UINT8 *) mAcpiBootPerformanceTable;\r
+  //\r
+  // Fill Basic Boot record to Boot Performance Table.\r
+  //\r
   CopyMem (mAcpiBootPerformanceTable, &mBootPerformanceTableTemplate, sizeof (mBootPerformanceTableTemplate));\r
-  DEBUG ((EFI_D_INFO, "FPDT: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));\r
+  BootPerformanceData = BootPerformanceData + mAcpiBootPerformanceTable->Header.Length;\r
+  //\r
+  // Fill Boot records from boot drivers.\r
+  //\r
+  CopyMem (BootPerformanceData, mBootRecordBuffer, mBootRecordSize);\r
+  mAcpiBootPerformanceTable->Header.Length += mBootRecordSize;\r
+  BootPerformanceData = BootPerformanceData + mBootRecordSize;\r
+  if (SmmCommData != NULL && SmmCommData->BootRecordData != NULL) {\r
+    //\r
+    // Fill Boot records from SMM drivers.\r
+    //\r
+    CopyMem (BootPerformanceData, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);\r
+    FreePool (SmmCommData->BootRecordData);\r
+    mAcpiBootPerformanceTable->Header.Length = (UINT32) (mAcpiBootPerformanceTable->Header.Length + SmmCommData->BootRecordSize);\r
+    BootPerformanceData = BootPerformanceData + SmmCommData->BootRecordSize;\r
+  }\r
+  if (SmmBootRecordCommBuffer != NULL) {\r
+    FreePool (SmmBootRecordCommBuffer);\r
+  }\r
+\r
   //\r
   // Save Boot Performance Table address to Variable for use in S4 resume.\r
   //\r
@@ -300,41 +478,25 @@ InstallFirmwarePerformanceDataTable (
   //\r
   mFirmwarePerformanceTableTemplate.BootPointerRecord.BootPerformanceTablePointer = (UINT64) (UINTN) mAcpiBootPerformanceTable;\r
 \r
-  if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) {\r
-    //\r
-    // Prepare S3 Performance Table.\r
-    //\r
-    mAcpiS3PerformanceTable = &mPerformanceRuntimeData->S3Performance;\r
-    CopyMem (mAcpiS3PerformanceTable, &mS3PerformanceTableTemplate, sizeof (mS3PerformanceTableTemplate));\r
-    DEBUG ((EFI_D_INFO, "FPDT: ACPI S3 Performance Table address = 0x%x\n", mAcpiS3PerformanceTable));\r
-\r
-    //\r
-    // Save S3 Performance Table address to Variable for use in Firmware Performance PEIM.\r
-    //\r
-    PerformanceVariable.S3PerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) mAcpiS3PerformanceTable;\r
-\r
-    //\r
-    // Update S3 Performance Table Pointer in template.\r
-    //\r
-    mFirmwarePerformanceTableTemplate.S3PointerRecord.S3PerformanceTablePointer = (UINT64) PerformanceVariable.S3PerformanceTablePointer;\r
-  } else {\r
-    //\r
-    // Exclude S3 Performance Table Pointer from FPDT table template.\r
-    //\r
-    mFirmwarePerformanceTableTemplate.Header.Length -= sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD);\r
-  }\r
-\r
+  //\r
+  // Save S3 Performance Table address to Variable for use in S4 resume.\r
+  //\r
+  PerformanceVariable.S3PerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) mAcpiS3PerformanceTable;\r
+  //\r
+  // Update S3 Performance Table Pointer in template.\r
+  //\r
+  mFirmwarePerformanceTableTemplate.S3PointerRecord.S3PerformanceTablePointer = (UINT64) (UINTN) mAcpiS3PerformanceTable;\r
   //\r
   // Save Runtime Performance Table pointers to Variable.\r
+  // Don't check SetVariable return status. It doesn't impact FPDT table generation. \r
   //\r
-  Status = gRT->SetVariable (\r
-                  EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,\r
-                  &gEfiFirmwarePerformanceGuid,\r
-                  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-                  sizeof (FIRMWARE_PERFORMANCE_VARIABLE),\r
-                  &PerformanceVariable\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+  gRT->SetVariable (\r
+        EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,\r
+        &gEfiFirmwarePerformanceGuid,\r
+        EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+        sizeof (PerformanceVariable),\r
+        &PerformanceVariable\r
+        );\r
 \r
   //\r
   // Publish Firmware Performance Data Table.\r
@@ -347,12 +509,25 @@ InstallFirmwarePerformanceDataTable (
                                 &mFirmwarePerformanceTableTemplateKey\r
                                 );\r
   if (EFI_ERROR (Status)) {\r
-    FreePool (mPerformanceRuntimeData);\r
+    FreePages (mAcpiBootPerformanceTable, EFI_SIZE_TO_PAGES (BootPerformanceDataSize));\r
+    if (mAcpiS3PerformanceTable != NULL) {\r
+      FreePages (mAcpiS3PerformanceTable, EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE)));\r
+    }\r
     mAcpiBootPerformanceTable = NULL;\r
     mAcpiS3PerformanceTable = NULL;\r
     return Status;\r
   }\r
-\r
+  \r
+  //\r
+  // Free temp Boot record, and update Boot Record to point to Basic Boot performance table.\r
+  //\r
+  if (mBootRecordBuffer != NULL) {\r
+    FreePool (mBootRecordBuffer);\r
+  }\r
+  mBootRecordBuffer  = (UINT8 *) mAcpiBootPerformanceTable;\r
+  mBootRecordSize    = mAcpiBootPerformanceTable->Header.Length;\r
+  mBootRecordMaxSize = mBootRecordSize + PcdGet32 (PcdExtFpdtBootRecordPadSize);\r
+  \r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -538,6 +713,42 @@ FpdtStatusCodeListenerDxe (
     // Unregister boot time report status code listener.\r
     //\r
     mRscHandlerProtocol->Unregister (FpdtStatusCodeListenerDxe);\r
+  } else if (Data != NULL && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) {\r
+    //\r
+    // Append one or more Boot records\r
+    //\r
+    if (mAcpiBootPerformanceTable == NULL) {\r
+      //\r
+      // Append Boot records before FPDT ACPI table is installed. \r
+      //\r
+      if (mBootRecordSize + Data->Size > mBootRecordMaxSize) {\r
+        mBootRecordBuffer = ReallocatePool (mBootRecordSize, mBootRecordSize + Data->Size + EXTENSION_RECORD_SIZE, mBootRecordBuffer);\r
+        ASSERT (mBootRecordBuffer != NULL);\r
+        mBootRecordMaxSize = mBootRecordSize + Data->Size + EXTENSION_RECORD_SIZE;\r
+      }\r
+      //\r
+      // Save boot record into the temp memory space.\r
+      //\r
+      CopyMem (mBootRecordBuffer + mBootRecordSize, Data + 1, Data->Size);\r
+      mBootRecordSize += Data->Size;\r
+    } else {\r
+      //\r
+      // Append Boot records after FPDT ACPI table is installed. \r
+      //\r
+      if (mBootRecordSize + Data->Size > mBootRecordMaxSize) {\r
+        //\r
+        // No enough space to save boot record.\r
+        //\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+      } else {\r
+        //\r
+        // Save boot record into BootPerformance table\r
+        //\r
+        CopyMem (mBootRecordBuffer + mBootRecordSize, Data + 1, Data->Size);\r
+        mBootRecordSize += Data->Size;\r
+        mAcpiBootPerformanceTable->Header.Length = mBootRecordSize;\r
+      }\r
+    }\r
   } else {\r
     //\r
     // Ignore else progress code.\r
@@ -568,6 +779,19 @@ FirmwarePerformanceDxeEntryPoint (
   EFI_STATUS               Status;\r
   EFI_HOB_GUID_TYPE        *GuidHob;\r
   FIRMWARE_SEC_PERFORMANCE *Performance;\r
+  VOID                     *Registration;\r
+  UINT64                   OemTableId;\r
+\r
+  CopyMem (\r
+    mFirmwarePerformanceTableTemplate.Header.OemId,\r
+    PcdGetPtr (PcdAcpiDefaultOemId),\r
+    sizeof (mFirmwarePerformanceTableTemplate.Header.OemId)\r
+    );\r
+  OemTableId = PcdGet64 (PcdAcpiDefaultOemTableId);\r
+  CopyMem (&mFirmwarePerformanceTableTemplate.Header.OemTableId, &OemTableId, sizeof (UINT64));\r
+  mFirmwarePerformanceTableTemplate.Header.OemRevision      = PcdGet32 (PcdAcpiDefaultOemRevision);\r
+  mFirmwarePerformanceTableTemplate.Header.CreatorId        = PcdGet32 (PcdAcpiDefaultCreatorId);\r
+  mFirmwarePerformanceTableTemplate.Header.CreatorRevision  = PcdGet32 (PcdAcpiDefaultCreatorRevision);\r
 \r
   //\r
   // Get Report Status Code Handler Protocol.\r
@@ -634,5 +858,31 @@ FirmwarePerformanceDxeEntryPoint (
     DEBUG ((EFI_D_ERROR, "FPDT: WARNING: SEC Performance Data Hob not found, ResetEnd will be set to 0!\n"));\r
   }\r
 \r
+  if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) {\r
+    //\r
+    // Register callback function upon VariableArchProtocol and LockBoxProtocol\r
+    // to allocate S3 performance table memory and save the pointer to LockBox.\r
+    //\r
+    EfiCreateProtocolNotifyEvent (\r
+      &gEfiVariableArchProtocolGuid,\r
+      TPL_CALLBACK,\r
+      FpdtAllocateS3PerformanceTableMemory,\r
+      NULL,\r
+      &Registration\r
+      );\r
+    EfiCreateProtocolNotifyEvent (\r
+      &gEfiLockBoxProtocolGuid,\r
+      TPL_CALLBACK,\r
+      FpdtAllocateS3PerformanceTableMemory,\r
+      NULL,\r
+      &Registration\r
+      );\r
+  } else {\r
+    //\r
+    // Exclude S3 Performance Table Pointer from FPDT table template.\r
+    //\r
+    mFirmwarePerformanceTableTemplate.Header.Length -= sizeof (EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD);\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 }\r