Skip to content

Commit

Permalink
MdeModulePkg/AcpiTableDxe: PCD switch to avoid using ACPI reclaim memory
Browse files Browse the repository at this point in the history
UEFI spec defined ACPI Tables at boot time can be contained in memory of
type EfiACPIReclaimMemory or EfiAcpiMemoryNVS, although InstallAcpiTable
with AcpiTableProtocol will only allocate memory with type
EfiACPIReclaimMemory (Except FACS).

This patch provides an optional method controlled by PCD to avoid using
EfiACPIReclaimMemory, by setting the PCD PcdNoACPIReclaimMemory to TRUE,
all ACPI allocated memory will use EfiAcpiMemoryNVS instead.

Cc: Zhiguang Liu <[email protected]>
Cc: Dandan Bi <[email protected]>
Cc: Liming Gao <[email protected]>
Cc: Liu Yun <[email protected]>
Cc: Jiewen Yao <[email protected]>
Cc: Ray Ni <[email protected]>
Cc: Michael D Kinney <[email protected]>
Signed-off-by: Aaron Li <[email protected]>
Reviewed-by: Liming Gao <[email protected]>
Reviewed-by: Zhiguang Liu <[email protected]>
  • Loading branch information
Li-Aaron authored and mergify[bot] committed Apr 9, 2024
1 parent b7f8779 commit 932db9d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
7 changes: 7 additions & 0 deletions MdeModulePkg/MdeModulePkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,13 @@
# @Prompt Exposed ACPI table versions.
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions|0x3E|UINT32|0x0001004c

## Indicates whether ACPI Reclaim memory is not available
# Default is FALSE that means ACPI Reclaim memory is available
# If it is set to TRUE that means ACPI Reclaim memory is not available
# For example ACPI Table protocol will use ACPI NVS memory instead of ACPI Reclaim memory
# @Prompt ACPI Reclaim memory is not available.
gEfiMdeModulePkgTokenSpaceGuid.PcdNoACPIReclaimMemory|FALSE|BOOLEAN|0x0001008b

## This PCD defines the MAX repair count.
# The default value is 0 that means infinite.
# @Prompt MAX repair count
Expand Down
8 changes: 8 additions & 0 deletions MdeModulePkg/MdeModulePkg.uni
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,14 @@
"BIT 4 - EFI_ACPI_TABLE_VERSION_4_0.<BR>\n"
"BIT 5 - EFI_ACPI_TABLE_VERSION_5_0.<BR>"

#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdNoACPIReclaimMemory_PROMPT #language en-US "ACPI Reclaim memory is not available."

#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdNoACPIReclaimMemory_HELP #language en-US "Indicates whether ACPI Reclaim memory is not available\n"
"Default is FALSE that means ACPI Reclaim memory is available\n"
"If it is set to TRUE that means ACPI Reclaim memory is not available\n"
"For example ACPI Table protocol will use ACPI NVS memory instead of ACPI Reclaim memory"


#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdHiiOsRuntimeSupport_PROMPT #language en-US "Enable export HII data and configuration to be used in OS runtime."

#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdHiiOsRuntimeSupport_HELP #language en-US "Indicates if HII data and configuration has been exported.<BR><BR>\n"
Expand Down
1 change: 1 addition & 0 deletions MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdNoACPIReclaimMemory ## CONSUMES

[Protocols]
gEfiAcpiTableProtocolGuid ## PRODUCES
Expand Down
37 changes: 29 additions & 8 deletions MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ ReallocateAcpiTableBuffer (
EFI_ACPI_TABLE_INSTANCE TempPrivateData;
EFI_STATUS Status;
UINT64 CurrentData;
EFI_MEMORY_TYPE AcpiAllocateMemoryType;

CopyMem (&TempPrivateData, AcpiTableInstance, sizeof (EFI_ACPI_TABLE_INSTANCE));
//
Expand All @@ -359,6 +360,12 @@ ReallocateAcpiTableBuffer (
NewMaxTableNumber * sizeof (UINT32);
}

if (PcdGetBool (PcdNoACPIReclaimMemory)) {
AcpiAllocateMemoryType = EfiACPIMemoryNVS;
} else {
AcpiAllocateMemoryType = EfiACPIReclaimMemory;
}

if (mAcpiTableAllocType != AllocateAnyPages) {
//
// Allocate memory in the lower 32 bit of address range for
Expand All @@ -372,13 +379,13 @@ ReallocateAcpiTableBuffer (
PageAddress = 0xFFFFFFFF;
Status = gBS->AllocatePages (
mAcpiTableAllocType,
EfiACPIReclaimMemory,
AcpiAllocateMemoryType,
EFI_SIZE_TO_PAGES (TotalSize),
&PageAddress
);
} else {
Status = gBS->AllocatePool (
EfiACPIReclaimMemory,
AcpiAllocateMemoryType,
TotalSize,
(VOID **)&Pointer
);
Expand Down Expand Up @@ -512,6 +519,7 @@ AddTableToList (
EFI_PHYSICAL_ADDRESS AllocPhysAddress;
UINT64 Buffer64;
BOOLEAN AddToRsdt;
EFI_MEMORY_TYPE AcpiAllocateMemoryType;

//
// Check for invalid input parameters
Expand Down Expand Up @@ -550,6 +558,12 @@ AddTableToList (
CurrentTableList->TableSize = CurrentTableSize;
CurrentTableList->PoolAllocation = FALSE;

if (PcdGetBool (PcdNoACPIReclaimMemory)) {
AcpiAllocateMemoryType = EfiACPIMemoryNVS;
} else {
AcpiAllocateMemoryType = EfiACPIReclaimMemory;
}

//
// Allocation memory type depends on the type of the table
//
Expand Down Expand Up @@ -585,7 +599,7 @@ AddTableToList (
// such as AArch64 that allocate multiples of 64 KB
//
Status = gBS->AllocatePool (
EfiACPIReclaimMemory,
AcpiAllocateMemoryType,
CurrentTableList->TableSize,
(VOID **)&CurrentTableList->Table
);
Expand All @@ -596,7 +610,7 @@ AddTableToList (
//
Status = gBS->AllocatePages (
mAcpiTableAllocType,
EfiACPIReclaimMemory,
AcpiAllocateMemoryType,
EFI_SIZE_TO_PAGES (CurrentTableList->TableSize),
&AllocPhysAddress
);
Expand Down Expand Up @@ -1944,6 +1958,7 @@ AcpiTableAcpiTableConstructor (
UINTN RsdpTableSize;
UINT8 *Pointer;
EFI_PHYSICAL_ADDRESS PageAddress;
EFI_MEMORY_TYPE AcpiAllocateMemoryType;

//
// Check for invalid input parameters
Expand Down Expand Up @@ -1978,17 +1993,23 @@ AcpiTableAcpiTableConstructor (
RsdpTableSize += sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
}

if (PcdGetBool (PcdNoACPIReclaimMemory)) {
AcpiAllocateMemoryType = EfiACPIMemoryNVS;
} else {
AcpiAllocateMemoryType = EfiACPIReclaimMemory;
}

if (mAcpiTableAllocType != AllocateAnyPages) {
PageAddress = 0xFFFFFFFF;
Status = gBS->AllocatePages (
mAcpiTableAllocType,
EfiACPIReclaimMemory,
AcpiAllocateMemoryType,
EFI_SIZE_TO_PAGES (RsdpTableSize),
&PageAddress
);
} else {
Status = gBS->AllocatePool (
EfiACPIReclaimMemory,
AcpiAllocateMemoryType,
RsdpTableSize,
(VOID **)&Pointer
);
Expand Down Expand Up @@ -2037,13 +2058,13 @@ AcpiTableAcpiTableConstructor (
PageAddress = 0xFFFFFFFF;
Status = gBS->AllocatePages (
mAcpiTableAllocType,
EfiACPIReclaimMemory,
AcpiAllocateMemoryType,
EFI_SIZE_TO_PAGES (TotalSize),
&PageAddress
);
} else {
Status = gBS->AllocatePool (
EfiACPIReclaimMemory,
AcpiAllocateMemoryType,
TotalSize,
(VOID **)&Pointer
);
Expand Down

0 comments on commit 932db9d

Please sign in to comment.