MdeModulePkg/FirmwarePerformanceDataTableDxe: use AllocatePeiAccessiblePages
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 22 May 2018 13:37:58 +0000 (15:37 +0200)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 29 May 2018 08:47:18 +0000 (10:47 +0200)
Replace the call to and implementation of the function
FpdtAllocateReservedMemoryBelow4G() with a call to
AllocatePeiAccessiblePages, which boils down to the same on X64,
but does not crash non-X64 systems that lack memory below 4 GB.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.inf

index e719e9e..ded817f 100644 (file)
@@ -32,6 +32,7 @@
 #include <Library/UefiRuntimeServicesTableLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/DebugLib.h>\r
+#include <Library/DxeServicesLib.h>\r
 #include <Library/TimerLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
@@ -179,46 +180,6 @@ FpdtAcpiTableChecksum (
   Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Size);\r
 }\r
 \r
-/**\r
-  Allocate EfiReservedMemoryType below 4G memory address.\r
-\r
-  This function allocates EfiReservedMemoryType below 4G memory address.\r
-\r
-  @param[in]  Size   Size of memory to allocate.\r
-\r
-  @return Allocated address for output.\r
-\r
-**/\r
-VOID *\r
-FpdtAllocateReservedMemoryBelow4G (\r
-  IN UINTN       Size\r
-  )\r
-{\r
-  UINTN                 Pages;\r
-  EFI_PHYSICAL_ADDRESS  Address;\r
-  EFI_STATUS            Status;\r
-  VOID                  *Buffer;\r
-\r
-  Buffer  = NULL;\r
-  Pages   = EFI_SIZE_TO_PAGES (Size);\r
-  Address = 0xffffffff;\r
-\r
-  Status = gBS->AllocatePages (\r
-                  AllocateMaxAddress,\r
-                  EfiReservedMemoryType,\r
-                  Pages,\r
-                  &Address\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-\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
@@ -287,7 +248,10 @@ FpdtAllocateS3PerformanceTableMemory (
         //\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
+        mAcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) AllocatePeiAccessiblePages (\r
+                                                             EfiReservedMemoryType,\r
+                                                             EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE))\r
+                                                             );\r
       }\r
       DEBUG ((EFI_D_INFO, "FPDT: ACPI S3 Performance Table address = 0x%x\n", mAcpiS3PerformanceTable));\r
       if (mAcpiS3PerformanceTable != NULL) {\r
@@ -368,7 +332,10 @@ InstallFirmwarePerformanceDataTable (
       //\r
       // Fail to allocate at specified address, continue to allocate at any address.\r
       //\r
-      mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) FpdtAllocateReservedMemoryBelow4G (BootPerformanceDataSize);\r
+      mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) AllocatePeiAccessiblePages (\r
+                                                               EfiReservedMemoryType,\r
+                                                               EFI_SIZE_TO_PAGES (BootPerformanceDataSize)\r
+                                                               );\r
     }\r
     DEBUG ((DEBUG_INFO, "FPDT: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));\r
     if (mAcpiBootPerformanceTable == NULL) {\r