MdeModulePkg-FPDT(3): Use SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET in FpdtDxe.
authorLiming Gao <liming.gao@intel.com>
Fri, 22 Apr 2016 07:31:07 +0000 (15:31 +0800)
committerJiewen Yao <jiewen.yao@intel.com>
Fri, 29 Apr 2016 04:49:20 +0000 (12:49 +0800)
This patch enhance performance data SMM communication by using fixed
SMM communication buffer.

Update FpdtDxe to use fixed SMM communication buffer to get
performance data by SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET API.

This is designed to meet Microsoft WSMT table definition on FIXED_COMM_BUFFERS
requirement.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.inf

index 423e8f227023006df487030aae9f51fbea8d055c..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 - 2015, 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
+        //\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
-      Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);\r
-      ASSERT_EFI_ERROR (Status);\r
-      ASSERT_EFI_ERROR(SmmCommData->ReturnStatus);\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
index d4e6175b9983cedfa48405ca93c1e7f1a5ab0d5e..49d8420ba4a23b8e19a32fd713db9b63d4a0efa2 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
@@ -70,6 +70,7 @@
   ## SOMETIMES_CONSUMES ## UNDEFINED # StatusCode Data\r
   gEfiFirmwarePerformanceGuid\r
   gFirmwarePerformanceS3PointerGuid             ## PRODUCES ## UNDEFINED # SaveLockBox\r
+  gEdkiiPiSmmCommunicationRegionTableGuid       ## SOMETIMES_CONSUMES    ## SystemTable\r
 \r
 [Pcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad    ## CONSUMES\r