]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c
MdeModulePkg/FPDT: Add error message for unsupported case
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / FirmwarePerformanceDataTableDxe / FirmwarePerformanceDxe.c
index b004cac95aaef60c7b07a6fb78cde5e3c10d211c..e719e9e482cb2d280ce8852cd3ed298be85ba64c 100644 (file)
@@ -5,7 +5,7 @@
   for Firmware Basic Boot Performance Record and other boot performance records, \r
   and install FPDT to ACPI table.\r
 \r
-  Copyright (c) 2011 - 2017, 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
@@ -20,7 +20,6 @@
 \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
@@ -28,7 +27,6 @@
 #include <Guid/FirmwarePerformance.h>\r
 #include <Guid/EventGroup.h>\r
 #include <Guid/EventLegacyBios.h>\r
-#include <Guid/PiSmmCommunicationRegionTable.h>\r
 \r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/UefiRuntimeServicesTableLib.h>\r
@@ -42,8 +40,7 @@
 #include <Library/LockBoxLib.h>\r
 #include <Library/UefiLib.h>\r
 \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
+#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
@@ -52,12 +49,10 @@ EFI_EVENT                   mReadyToBootEvent;
 EFI_EVENT                   mLegacyBootEvent;\r
 EFI_EVENT                   mExitBootServicesEvent;\r
 UINTN                       mFirmwarePerformanceTableTemplateKey  = 0;\r
-UINT32                      mBootRecordSize = 0;\r
-UINT32                      mBootRecordMaxSize = 0;\r
-UINT8                       *mBootRecordBuffer = NULL;\r
 BOOLEAN                     mDxeCoreReportStatusCodeEnable = FALSE;\r
 \r
 BOOT_PERFORMANCE_TABLE                      *mAcpiBootPerformanceTable = NULL;\r
+BOOT_PERFORMANCE_TABLE                      *mReceivedAcpiBootPerformanceTable = NULL;\r
 S3_PERFORMANCE_TABLE                        *mAcpiS3PerformanceTable   = NULL;\r
 \r
 FIRMWARE_PERFORMANCE_TABLE  mFirmwarePerformanceTableTemplate = {\r
@@ -329,21 +324,9 @@ InstallFirmwarePerformanceDataTable (
 {\r
   EFI_STATUS                    Status;\r
   EFI_ACPI_TABLE_PROTOCOL       *AcpiTableProtocol;\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
-  EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *SmmCommRegionTable;\r
-  EFI_MEMORY_DESCRIPTOR         *SmmCommMemRegion;\r
-  UINTN                         Index;\r
-  VOID                          *SmmBootRecordData;\r
-  UINTN                         SmmBootRecordDataSize;\r
-  UINTN                         ReservedMemSize;\r
+  UINTN                         Size;\r
 \r
   //\r
   // Get AcpiTable Protocol.\r
@@ -353,158 +336,50 @@ InstallFirmwarePerformanceDataTable (
     return Status;\r
   }\r
 \r
-  //\r
-  // Collect boot records from SMM drivers.\r
-  //\r
-  SmmBootRecordCommBuffer = NULL;\r
-  SmmCommData             = NULL;\r
-  SmmBootRecordData       = NULL;\r
-  SmmBootRecordDataSize   = 0;\r
-  ReservedMemSize         = 0;\r
-  Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &Communication);\r
-  if (!EFI_ERROR (Status)) {\r
-    //\r
-    // Initialize communicate buffer \r
-    // Get the prepared Reserved Memory Range\r
+  if (mReceivedAcpiBootPerformanceTable != NULL) {\r
+    mAcpiBootPerformanceTable = mReceivedAcpiBootPerformanceTable;\r
+    mAcpiBootPerformanceTable->BasicBoot.ResetEnd = mBootPerformanceTableTemplate.BasicBoot.ResetEnd;\r
+  } else {\r
     //\r
-    Status = EfiGetSystemConfigurationTable (\r
-              &gEdkiiPiSmmCommunicationRegionTableGuid, \r
-              (VOID **) &SmmCommRegionTable\r
-              );\r
+    // Try to allocate the same runtime buffer as last time boot.\r
+    //\r
+    BootPerformanceDataSize = sizeof (BOOT_PERFORMANCE_TABLE);\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
-      ASSERT (SmmCommRegionTable != NULL);\r
-      SmmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *) (SmmCommRegionTable + 1);\r
-      for (Index = 0; Index < SmmCommRegionTable->NumberOfEntries; Index ++) {\r
-        if (SmmCommMemRegion->Type == EfiConventionalMemory) {\r
-          break;\r
-        }\r
-        SmmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) SmmCommMemRegion + SmmCommRegionTable->DescriptorSize);\r
+      Status = gBS->AllocatePages (\r
+                      AllocateAddress,\r
+                      EfiReservedMemoryType,\r
+                      EFI_SIZE_TO_PAGES (BootPerformanceDataSize),\r
+                      &PerformanceVariable.BootPerformanceTablePointer\r
+                      );\r
+      if (!EFI_ERROR (Status)) {\r
+         mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.BootPerformanceTablePointer;\r
       }\r
-      ASSERT (Index < SmmCommRegionTable->NumberOfEntries);\r
-      ASSERT (SmmCommMemRegion->PhysicalStart > 0);\r
-      ASSERT (SmmCommMemRegion->NumberOfPages > 0);\r
-      ReservedMemSize = (UINTN) SmmCommMemRegion->NumberOfPages * EFI_PAGE_SIZE;\r
-    \r
+    }\r
+    if (mAcpiBootPerformanceTable == NULL) {\r
       //\r
-      // Check enough reserved memory space\r
+      // Fail to allocate at specified address, continue to allocate at any address.\r
       //\r
-      if (ReservedMemSize > SMM_BOOT_RECORD_COMM_SIZE) {\r
-        SmmBootRecordCommBuffer = (VOID *) (UINTN) SmmCommMemRegion->PhysicalStart;\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_BY_OFFSET;\r
-          SmmBootRecordDataSize       = SmmCommData->BootRecordSize;\r
-          SmmBootRecordData           = AllocateZeroPool(SmmBootRecordDataSize);\r
-          ASSERT (SmmBootRecordData  != NULL);\r
-          SmmCommData->BootRecordOffset = 0;\r
-          SmmCommData->BootRecordData   = (VOID *) ((UINTN) SmmCommMemRegion->PhysicalStart + SMM_BOOT_RECORD_COMM_SIZE);\r
-          SmmCommData->BootRecordSize   = ReservedMemSize - SMM_BOOT_RECORD_COMM_SIZE;\r
-          while (SmmCommData->BootRecordOffset < SmmBootRecordDataSize) {\r
-            Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);\r
-            ASSERT_EFI_ERROR (Status);\r
-            ASSERT_EFI_ERROR(SmmCommData->ReturnStatus);\r
-            CopyMem ((UINT8 *) SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);\r
-            SmmCommData->BootRecordOffset = SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize;\r
-          }\r
-        }\r
-      }\r
+      mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) FpdtAllocateReservedMemoryBelow4G (BootPerformanceDataSize);\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 += SmmBootRecordDataSize;\r
-  }\r
-\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 (BootPerformanceDataSize),\r
-                    &PerformanceVariable.BootPerformanceTablePointer\r
-                    );\r
-    if (!EFI_ERROR (Status)) {\r
-      mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.BootPerformanceTablePointer;\r
-    }\r
-  }\r
-\r
-  if (mAcpiBootPerformanceTable == NULL) {\r
-    //\r
-    // Fail to allocate at specified address, continue to allocate at any address.\r
-    //\r
-    mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) FpdtAllocateReservedMemoryBelow4G (BootPerformanceDataSize);\r
-  }\r
-  DEBUG ((EFI_D_INFO, "FPDT: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));\r
-\r
-  if (mAcpiBootPerformanceTable == NULL) {\r
-    if (SmmCommData != NULL && SmmBootRecordData != NULL) {\r
-      FreePool (SmmBootRecordData);\r
-    }\r
-    if (mAcpiS3PerformanceTable != NULL) {\r
-      FreePages (mAcpiS3PerformanceTable, EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE)));\r
-      mAcpiS3PerformanceTable = NULL;\r
+    DEBUG ((DEBUG_INFO, "FPDT: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));\r
+    if (mAcpiBootPerformanceTable == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
     }\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  //\r
-  // Prepare Boot Performance Table.\r
-  //\r
-  BootPerformanceData = (UINT8 *) mAcpiBootPerformanceTable;\r
-  //\r
-  // Fill Basic Boot record to Boot Performance Table.\r
-  //\r
-  CopyMem (mAcpiBootPerformanceTable, &mBootPerformanceTableTemplate, sizeof (mBootPerformanceTableTemplate));\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 && SmmBootRecordData != NULL) {\r
     //\r
-    // Fill Boot records from SMM drivers.\r
+    // Fill Basic Boot record to Boot Performance Table.\r
     //\r
-    CopyMem (BootPerformanceData, SmmBootRecordData, SmmBootRecordDataSize);\r
-    FreePool (SmmBootRecordData);\r
-    mAcpiBootPerformanceTable->Header.Length = (UINT32) (mAcpiBootPerformanceTable->Header.Length + SmmBootRecordDataSize);\r
-    BootPerformanceData = BootPerformanceData + SmmBootRecordDataSize;\r
+    CopyMem (mAcpiBootPerformanceTable, &mBootPerformanceTableTemplate, sizeof (mBootPerformanceTableTemplate));\r
   }\r
+  BootPerformanceDataSize   = mAcpiBootPerformanceTable->Header.Length;\r
 \r
   //\r
   // Save Boot Performance Table address to Variable for use in S4 resume.\r
@@ -525,7 +400,7 @@ InstallFirmwarePerformanceDataTable (
   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
+  // Don't check SetVariable return status. It doesn't impact FPDT table generation.\r
   //\r
   gRT->SetVariable (\r
         EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,\r
@@ -546,7 +421,9 @@ InstallFirmwarePerformanceDataTable (
                                 &mFirmwarePerformanceTableTemplateKey\r
                                 );\r
   if (EFI_ERROR (Status)) {\r
-    FreePages (mAcpiBootPerformanceTable, EFI_SIZE_TO_PAGES (BootPerformanceDataSize));\r
+    if (mAcpiBootPerformanceTable != NULL) {\r
+      FreePages (mAcpiBootPerformanceTable, EFI_SIZE_TO_PAGES (BootPerformanceDataSize));\r
+    }\r
     if (mAcpiS3PerformanceTable != NULL) {\r
       FreePages (mAcpiS3PerformanceTable, EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE)));\r
     }\r
@@ -554,43 +431,9 @@ InstallFirmwarePerformanceDataTable (
     mAcpiS3PerformanceTable = NULL;\r
     return Status;\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
-/**\r
-  Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This is used to\r
-  install the Firmware Performance Data Table.\r
-\r
-  @param[in]  Event   The Event that is being processed.\r
-  @param[in]  Context The Event Context.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-FpdtReadyToBootEventNotify (\r
-  IN EFI_EVENT        Event,\r
-  IN VOID             *Context\r
-  )\r
-{\r
-  if (mAcpiBootPerformanceTable == NULL) {\r
-    //\r
-    // ACPI Firmware Performance Data Table not installed yet, install it now.\r
-    //\r
-    InstallFirmwarePerformanceDataTable ();\r
-  }\r
-}\r
-\r
 /**\r
   Report status code listener of FPDT. This is used to collect performance data\r
   for OsLoaderLoadImageStart and OsLoaderStartImageStart in FPDT.\r
@@ -699,42 +542,21 @@ FpdtStatusCodeListenerDxe (
     DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - OsLoaderStartImageStart = %ld\n", mAcpiBootPerformanceTable->BasicBoot.OsLoaderStartImageStart));\r
     DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - ExitBootServicesEntry   = 0\n"));\r
     DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - ExitBootServicesExit    = 0\n"));\r
-  } else if (Data != NULL && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) {\r
-    //\r
-    // Append one or more Boot records\r
-    //\r
+  } else if (Value == (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT)) {\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
+      // ACPI Firmware Performance Data Table not installed yet, install it now.\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
+      InstallFirmwarePerformanceDataTable ();\r
     }\r
+  } else if (Data != NULL && CompareGuid (&Data->Type, &gEdkiiFpdtExtendedFirmwarePerformanceGuid)) {\r
+    //\r
+    // Get the Boot performance table and then install it to ACPI table.\r
+    //\r
+    CopyMem (&mReceivedAcpiBootPerformanceTable, Data + 1, Data->Size);\r
+  } else if (Data != NULL && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) {\r
+    DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerDxe: Performance data reported through gEfiFirmwarePerformanceGuid will not be collected by FirmwarePerformanceDataTableDxe\n"));\r
+    Status = EFI_UNSUPPORTED;\r
   } else {\r
     //\r
     // Ignore else progress code.\r
@@ -852,19 +674,6 @@ FirmwarePerformanceDxeEntryPoint (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  //\r
-  // Create ready to boot event to install ACPI FPDT table.\r
-  //\r
-  Status = gBS->CreateEventEx (\r
-                  EVT_NOTIFY_SIGNAL,\r
-                  TPL_NOTIFY,\r
-                  FpdtReadyToBootEventNotify,\r
-                  NULL,\r
-                  &gEfiEventReadyToBootGuid,\r
-                  &mReadyToBootEvent\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   //\r
   // Retrieve GUID HOB data that contains the ResetEnd.\r
   //\r