]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c
MdeModulePkg-FPDT(3): Use SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET in FpdtDxe.
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / FirmwarePerformanceDataTableDxe / FirmwarePerformanceDxe.c
index b1801a70f8c46c9c06656f8b4f108f21bc7a2b9b..6f6ea073aa82e0a0338c2620f82a15a5afa1bb7a 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 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 2016, 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
@@ -28,6 +28,7 @@
 #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
@@ -337,6 +338,12 @@ InstallFirmwarePerformanceDataTable (
   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
 \r
   //\r
   // Get AcpiTable Protocol.\r
@@ -351,40 +358,74 @@ InstallFirmwarePerformanceDataTable (
   //\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
     //\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
+    Status = EfiGetSystemConfigurationTable (\r
+              &gEdkiiPiSmmCommunicationRegionTableGuid, \r
+              (VOID **) &SmmCommRegionTable\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
+      }\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
-      // Get all boot records\r
+      // Check enough reserved memory space\r
       //\r
-      SmmCommData->Function       = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA;\r
-      SmmCommData->BootRecordData = AllocateZeroPool(SmmCommData->BootRecordSize);\r
-      ASSERT (SmmCommData->BootRecordData != NULL);\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
-      Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);\r
-      ASSERT_EFI_ERROR (Status);\r
-      ASSERT_EFI_ERROR(SmmCommData->ReturnStatus);\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
     }\r
   }\r
 \r
@@ -394,7 +435,7 @@ InstallFirmwarePerformanceDataTable (
   //\r
   BootPerformanceDataSize = sizeof (BOOT_PERFORMANCE_TABLE) + mBootRecordSize + PcdGet32 (PcdExtFpdtBootRecordPadSize);\r
   if (SmmCommData != NULL) {\r
-    BootPerformanceDataSize += SmmCommData->BootRecordSize;\r
+    BootPerformanceDataSize += SmmBootRecordDataSize;\r
   }\r
 \r
   //\r
@@ -430,14 +471,12 @@ InstallFirmwarePerformanceDataTable (
   DEBUG ((EFI_D_INFO, "FPDT: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));\r
 \r
   if (mAcpiBootPerformanceTable == NULL) {\r
-    if (SmmCommData != NULL && SmmCommData->BootRecordData != NULL) {\r
-      FreePool (SmmCommData->BootRecordData);\r
-    }\r
-    if (SmmBootRecordCommBuffer != NULL) {\r
-      FreePool (SmmBootRecordCommBuffer);\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
     }\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -457,17 +496,14 @@ InstallFirmwarePerformanceDataTable (
   CopyMem (BootPerformanceData, mBootRecordBuffer, mBootRecordSize);\r
   mAcpiBootPerformanceTable->Header.Length += mBootRecordSize;\r
   BootPerformanceData = BootPerformanceData + mBootRecordSize;\r
-  if (SmmCommData != NULL && SmmCommData->BootRecordData != NULL) {\r
+  if (SmmCommData != NULL && SmmBootRecordData != 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
+    CopyMem (BootPerformanceData, SmmBootRecordData, SmmBootRecordDataSize);\r
+    FreePool (SmmBootRecordData);\r
+    mAcpiBootPerformanceTable->Header.Length = (UINT32) (mAcpiBootPerformanceTable->Header.Length + SmmBootRecordDataSize);\r
+    BootPerformanceData = BootPerformanceData + SmmBootRecordDataSize;\r
   }\r
 \r
   //\r
@@ -555,46 +591,6 @@ FpdtReadyToBootEventNotify (
   }\r
 }\r
 \r
-/**\r
-  Notify function for event group EFI_EVENT_LEGACY_BOOT_GUID. This is used to\r
-  record performance data for OsLoaderLoadImageStart in FPDT for legacy boot.\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
-FpdtLegacyBootEventNotify (\r
-  IN EFI_EVENT        Event,\r
-  IN VOID             *Context\r
-  )\r
-{\r
-  if (mAcpiBootPerformanceTable == NULL) {\r
-    //\r
-    // Firmware Performance Data Table not installed, do nothing.\r
-    //\r
-    return ;\r
-  }\r
-\r
-  //\r
-  // Update Firmware Basic Boot Performance Record for legacy boot.\r
-  //\r
-  mAcpiBootPerformanceTable->BasicBoot.OsLoaderLoadImageStart  = 0;\r
-  mAcpiBootPerformanceTable->BasicBoot.OsLoaderStartImageStart = GetTimeInNanoSecond (GetPerformanceCounter ());\r
-  mAcpiBootPerformanceTable->BasicBoot.ExitBootServicesEntry   = 0;\r
-  mAcpiBootPerformanceTable->BasicBoot.ExitBootServicesExit    = 0;\r
-\r
-  //\r
-  // Dump FPDT Boot Performance record.\r
-  //\r
-  DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - ResetEnd                = %ld\n", mAcpiBootPerformanceTable->BasicBoot.ResetEnd));\r
-  DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - OsLoaderLoadImageStart  = 0\n"));\r
-  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
-}\r
-\r
 /**\r
   Report status code listener of FPDT. This is used to collect performance data\r
   for OsLoaderLoadImageStart and OsLoaderStartImageStart in FPDT.\r
@@ -682,6 +678,27 @@ FpdtStatusCodeListenerDxe (
     // Update ExitBootServicesExit for UEFI boot.\r
     //\r
     mAcpiBootPerformanceTable->BasicBoot.ExitBootServicesExit = GetTimeInNanoSecond (GetPerformanceCounter ());\r
+  } else if (Value == (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_LEGACY_BOOT_EVENT)) {\r
+    if (mAcpiBootPerformanceTable == NULL) {\r
+      //\r
+      // Firmware Performance Data Table not installed, do nothing.\r
+      //\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    // Update Firmware Basic Boot Performance Record for legacy boot.\r
+    //\r
+    mAcpiBootPerformanceTable->BasicBoot.OsLoaderStartImageStart = GetTimeInNanoSecond (GetPerformanceCounter ());\r
+\r
+    //\r
+    // Dump FPDT Boot Performance record.\r
+    //\r
+    DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - ResetEnd                = %ld\n", mAcpiBootPerformanceTable->BasicBoot.ResetEnd));\r
+    DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - OsLoaderLoadImageStart  = 0\n"));\r
+    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
@@ -744,7 +761,7 @@ FpdtExitBootServicesEventNotify (
   IN VOID             *Context\r
   )\r
 {\r
-  if (mDxeCoreReportStatusCodeEnable == FALSE) {\r
+  if (!mDxeCoreReportStatusCodeEnable) {\r
     //\r
     // When DxeCore Report Status Code is disabled, \r
     // Unregister boot time report status code listener at ExitBootService Event.\r
@@ -848,19 +865,6 @@ FirmwarePerformanceDxeEntryPoint (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  //\r
-  // Create legacy boot event to log OsLoaderStartImageStart for legacy boot.\r
-  //\r
-  Status = gBS->CreateEventEx (\r
-                  EVT_NOTIFY_SIGNAL,\r
-                  TPL_NOTIFY,\r
-                  FpdtLegacyBootEventNotify,\r
-                  NULL,\r
-                  &gEfiEventLegacyBootGuid,\r
-                  &mLegacyBootEvent\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   //\r
   // Retrieve GUID HOB data that contains the ResetEnd.\r
   //\r