]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/AcpiTableDxe: use pool allocation for RSDT/XSDT if possible
authorArd Biesheuvel <ard.biesheuvel@arm.com>
Fri, 16 Oct 2020 14:53:53 +0000 (16:53 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 30 Oct 2020 14:50:33 +0000 (14:50 +0000)
If no memory allocation limit is in effect for ACPI tables, prefer
pool allocations over page allocations, to avoid wasting memory on
systems where page based allocations are rounded up to 64 KB, such
as AArch64.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c

index eb79dbadbfc517cf205f8975ac0e4f0d0e748cf1..ae446270faef3dbb8d600391a0a24a1048c17314 100644 (file)
@@ -355,28 +355,39 @@ ReallocateAcpiTableBuffer (
                  NewMaxTableNumber * sizeof (UINT32);\r
   }\r
 \r
-  //\r
-  // Allocate memory in the lower 32 bit of address range for\r
-  // compatibility with ACPI 1.0 OS.\r
-  //\r
-  // This is done because ACPI 1.0 pointers are 32 bit values.\r
-  // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.\r
-  // There is no architectural reason these should be below 4GB, it is purely\r
-  // for convenience of implementation that we force memory below 4GB.\r
-  //\r
-  PageAddress = 0xFFFFFFFF;\r
-  Status = gBS->AllocatePages (\r
-                  mAcpiTableAllocType,\r
-                  EfiACPIReclaimMemory,\r
-                  EFI_SIZE_TO_PAGES (TotalSize),\r
-                  &PageAddress\r
-                  );\r
+  if (mAcpiTableAllocType != AllocateAnyPages) {\r
+    //\r
+    // Allocate memory in the lower 32 bit of address range for\r
+    // compatibility with ACPI 1.0 OS.\r
+    //\r
+    // This is done because ACPI 1.0 pointers are 32 bit values.\r
+    // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.\r
+    // There is no architectural reason these should be below 4GB, it is purely\r
+    // for convenience of implementation that we force memory below 4GB.\r
+    //\r
+    PageAddress = 0xFFFFFFFF;\r
+    Status = gBS->AllocatePages (\r
+                    mAcpiTableAllocType,\r
+                    EfiACPIReclaimMemory,\r
+                    EFI_SIZE_TO_PAGES (TotalSize),\r
+                    &PageAddress\r
+                    );\r
+  } else {\r
+    Status = gBS->AllocatePool (\r
+                    EfiACPIReclaimMemory,\r
+                    TotalSize,\r
+                    (VOID **)&Pointer\r
+                    );\r
+  }\r
 \r
   if (EFI_ERROR (Status)) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  Pointer = (UINT8 *) (UINTN) PageAddress;\r
+  if (mAcpiTableAllocType != AllocateAnyPages) {\r
+    Pointer = (UINT8 *)(UINTN)PageAddress;\r
+  }\r
+\r
   ZeroMem (Pointer, TotalSize);\r
 \r
   AcpiTableInstance->Rsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *) Pointer;\r
@@ -406,21 +417,26 @@ ReallocateAcpiTableBuffer (
   }\r
   CopyMem (AcpiTableInstance->Xsdt, TempPrivateData.Xsdt, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT64)));\r
 \r
-  //\r
-  // Calculate orignal ACPI table buffer size\r
-  //\r
-  TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) +         // for ACPI 2.0/3.0 XSDT\r
-              mEfiAcpiMaxNumTables * sizeof (UINT64);\r
+  if (mAcpiTableAllocType != AllocateAnyPages) {\r
+    //\r
+    // Calculate orignal ACPI table buffer size\r
+    //\r
+    TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) +         // for ACPI 2.0/3.0 XSDT\r
+                mEfiAcpiMaxNumTables * sizeof (UINT64);\r
+\r
+    if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {\r
+      TotalSize += sizeof (EFI_ACPI_DESCRIPTION_HEADER) +         // for ACPI 1.0 RSDT\r
+                   mEfiAcpiMaxNumTables * sizeof (UINT32) +\r
+                   sizeof (EFI_ACPI_DESCRIPTION_HEADER) +         // for ACPI 2.0/3.0 RSDT\r
+                   mEfiAcpiMaxNumTables * sizeof (UINT32);\r
+    }\r
 \r
-  if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {\r
-    TotalSize += sizeof (EFI_ACPI_DESCRIPTION_HEADER) +         // for ACPI 1.0 RSDT\r
-                 mEfiAcpiMaxNumTables * sizeof (UINT32) +\r
-                 sizeof (EFI_ACPI_DESCRIPTION_HEADER) +         // for ACPI 2.0/3.0 RSDT\r
-                 mEfiAcpiMaxNumTables * sizeof (UINT32);\r
+    gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)TempPrivateData.Rsdt1,\r
+           EFI_SIZE_TO_PAGES (TotalSize));\r
+  } else {\r
+    gBS->FreePool (TempPrivateData.Rsdt1);\r
   }\r
 \r
-  gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)TempPrivateData.Rsdt1, EFI_SIZE_TO_PAGES (TotalSize));\r
-\r
   //\r
   // Update the Max ACPI table number\r
   //\r
@@ -1763,29 +1779,39 @@ AcpiTableAcpiTableConstructor (
                  mEfiAcpiMaxNumTables * sizeof (UINT32);\r
   }\r
 \r
-  //\r
-  // Allocate memory in the lower 32 bit of address range for\r
-  // compatibility with ACPI 1.0 OS.\r
-  //\r
-  // This is done because ACPI 1.0 pointers are 32 bit values.\r
-  // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.\r
-  // There is no architectural reason these should be below 4GB, it is purely\r
-  // for convenience of implementation that we force memory below 4GB.\r
-  //\r
-  PageAddress = 0xFFFFFFFF;\r
-  Status = gBS->AllocatePages (\r
-                  mAcpiTableAllocType,\r
-                  EfiACPIReclaimMemory,\r
-                  EFI_SIZE_TO_PAGES (TotalSize),\r
-                  &PageAddress\r
-                  );\r
+  if (mAcpiTableAllocType != AllocateAnyPages) {\r
+    //\r
+    // Allocate memory in the lower 32 bit of address range for\r
+    // compatibility with ACPI 1.0 OS.\r
+    //\r
+    // This is done because ACPI 1.0 pointers are 32 bit values.\r
+    // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.\r
+    // There is no architectural reason these should be below 4GB, it is purely\r
+    // for convenience of implementation that we force memory below 4GB.\r
+    //\r
+    PageAddress = 0xFFFFFFFF;\r
+    Status = gBS->AllocatePages (\r
+                    mAcpiTableAllocType,\r
+                    EfiACPIReclaimMemory,\r
+                    EFI_SIZE_TO_PAGES (TotalSize),\r
+                    &PageAddress\r
+                    );\r
+  } else {\r
+    Status = gBS->AllocatePool (\r
+                    EfiACPIReclaimMemory,\r
+                    TotalSize,\r
+                    (VOID **)&Pointer\r
+                    );\r
+  }\r
 \r
   if (EFI_ERROR (Status)) {\r
     gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)AcpiTableInstance->Rsdp1, EFI_SIZE_TO_PAGES (RsdpTableSize));\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  Pointer = (UINT8 *) (UINTN) PageAddress;\r
+  if (mAcpiTableAllocType != AllocateAnyPages) {\r
+    Pointer = (UINT8 *)(UINTN)PageAddress;\r
+  }\r
   ZeroMem (Pointer, TotalSize);\r
 \r
   AcpiTableInstance->Rsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *) Pointer;\r