mirror of https://github.com/acidanthera/audk.git
MdeModulePkg CapsuleRuntimeDxe: Reduce reserved memory consumption
Reduce reserved memory consumption by page table buffer, then OS can have more available memory to use. Take PhysicalAddressBits = 48 and 2MB page granularity as example, 1:1 Virtual to Physical identity mapping page table buffer needs to be ((512 + 1) * 512 + 1) * 4096 = 1075843072 bytes = 0x40201000 bytes. The code is updated to only allocate 2 pages (1G page enabled) or 6 pages for 4G page table, and 8 extra pages to handles > 4G request by page fault. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18070 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
716087e2be
commit
b2d2a7f3f2
|
@ -4,7 +4,7 @@
|
||||||
# It installs the Capsule Architectural Protocol defined in PI1.0a to signify
|
# It installs the Capsule Architectural Protocol defined in PI1.0a to signify
|
||||||
# the capsule runtime services are ready.
|
# the capsule runtime services are ready.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
|
# Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||||
# This program and the accompanying materials
|
# This program and the accompanying materials
|
||||||
# are licensed and made available under the terms and conditions of the BSD License
|
# are licensed and made available under the terms and conditions of the BSD License
|
||||||
# which accompanies this distribution. The full text of the license may be found at
|
# which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -58,7 +58,6 @@
|
||||||
[LibraryClasses.X64]
|
[LibraryClasses.X64]
|
||||||
UefiLib
|
UefiLib
|
||||||
BaseMemoryLib
|
BaseMemoryLib
|
||||||
HobLib
|
|
||||||
|
|
||||||
[Guids]
|
[Guids]
|
||||||
## SOMETIMES_PRODUCES ## Variable:L"CapsuleUpdateData" # (Process across reset capsule image) for capsule updated data
|
## SOMETIMES_PRODUCES ## Variable:L"CapsuleUpdateData" # (Process across reset capsule image) for capsule updated data
|
||||||
|
@ -85,9 +84,6 @@
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxSizePopulateCapsule || gEfiMdeModulePkgTokenSpaceGuid.PcdSupportUpdateCapsuleReset ## SOMETIMES_CONSUMES # Populate Image requires reset support.
|
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxSizePopulateCapsule || gEfiMdeModulePkgTokenSpaceGuid.PcdSupportUpdateCapsuleReset ## SOMETIMES_CONSUMES # Populate Image requires reset support.
|
||||||
|
|
||||||
[Pcd.X64]
|
[Pcd.X64]
|
||||||
## SOMETIMES_CONSUMES
|
|
||||||
## SOMETIMES_PRODUCES
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdIdentifyMappingPageTablePtr
|
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsulePeiLongModeStackSize ## SOMETIMES_CONSUMES
|
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsulePeiLongModeStackSize ## SOMETIMES_CONSUMES
|
||||||
gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ## SOMETIMES_CONSUMES
|
gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ## SOMETIMES_CONSUMES
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Create the variable to save the base address of page table and stack
|
Create the variable to save the base address of page table and stack
|
||||||
for transferring into long mode in IA32 capsule PEI.
|
for transferring into long mode in IA32 capsule PEI.
|
||||||
|
|
||||||
Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -30,7 +30,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
#include <Library/BaseLib.h>
|
#include <Library/BaseLib.h>
|
||||||
#include <Library/UefiLib.h>
|
#include <Library/UefiLib.h>
|
||||||
#include <Library/BaseMemoryLib.h>
|
#include <Library/BaseMemoryLib.h>
|
||||||
#include <Library/HobLib.h>
|
|
||||||
|
//
|
||||||
|
// 8 extra pages for PF handler.
|
||||||
|
//
|
||||||
|
#define EXTRA_PAGE_TABLE_PAGES 8
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Allocate EfiReservedMemoryType below 4G memory address.
|
Allocate EfiReservedMemoryType below 4G memory address.
|
||||||
|
@ -106,11 +110,11 @@ PrepareContextForCapsulePei (
|
||||||
VOID
|
VOID
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
UINTN ExtraPageTablePages;
|
||||||
UINT32 RegEax;
|
UINT32 RegEax;
|
||||||
UINT32 RegEdx;
|
UINT32 RegEdx;
|
||||||
UINTN TotalPagesNum;
|
UINTN TotalPagesNum;
|
||||||
UINT8 PhysicalAddressBits;
|
UINT8 PhysicalAddressBits;
|
||||||
VOID *Hob;
|
|
||||||
UINT32 NumberOfPml4EntriesNeeded;
|
UINT32 NumberOfPml4EntriesNeeded;
|
||||||
UINT32 NumberOfPdpEntriesNeeded;
|
UINT32 NumberOfPdpEntriesNeeded;
|
||||||
BOOLEAN Page1GSupport;
|
BOOLEAN Page1GSupport;
|
||||||
|
@ -118,11 +122,8 @@ PrepareContextForCapsulePei (
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
VOID *Registration;
|
VOID *Registration;
|
||||||
|
|
||||||
LongModeBuffer.PageTableAddress = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdIdentifyMappingPageTablePtr);
|
|
||||||
|
|
||||||
if (LongModeBuffer.PageTableAddress == 0x0) {
|
|
||||||
//
|
//
|
||||||
// Calculate the size of page table, allocate the memory, and set PcdIdentifyMappingPageTablePtr.
|
// Calculate the size of page table, allocate the memory.
|
||||||
//
|
//
|
||||||
Page1GSupport = FALSE;
|
Page1GSupport = FALSE;
|
||||||
if (PcdGetBool(PcdUse1GPageTable)) {
|
if (PcdGetBool(PcdUse1GPageTable)) {
|
||||||
|
@ -136,28 +137,11 @@ PrepareContextForCapsulePei (
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get physical address bits supported.
|
// Create 4G page table by default,
|
||||||
|
// and let PF handler to handle > 4G request.
|
||||||
//
|
//
|
||||||
Hob = GetFirstHob (EFI_HOB_TYPE_CPU);
|
PhysicalAddressBits = 32;
|
||||||
if (Hob != NULL) {
|
ExtraPageTablePages = EXTRA_PAGE_TABLE_PAGES;
|
||||||
PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;
|
|
||||||
} else {
|
|
||||||
AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
|
|
||||||
if (RegEax >= 0x80000008) {
|
|
||||||
AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
|
|
||||||
PhysicalAddressBits = (UINT8) RegEax;
|
|
||||||
} else {
|
|
||||||
PhysicalAddressBits = 36;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// IA-32e paging translates 48-bit linear addresses to 52-bit physical addresses.
|
|
||||||
//
|
|
||||||
ASSERT (PhysicalAddressBits <= 52);
|
|
||||||
if (PhysicalAddressBits > 48) {
|
|
||||||
PhysicalAddressBits = 48;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Calculate the table entries needed.
|
// Calculate the table entries needed.
|
||||||
|
@ -175,11 +159,11 @@ PrepareContextForCapsulePei (
|
||||||
} else {
|
} else {
|
||||||
TotalPagesNum = NumberOfPml4EntriesNeeded + 1;
|
TotalPagesNum = NumberOfPml4EntriesNeeded + 1;
|
||||||
}
|
}
|
||||||
|
TotalPagesNum += ExtraPageTablePages;
|
||||||
|
DEBUG ((EFI_D_ERROR, "CapsuleRuntimeDxe X64 TotalPagesNum - 0x%x pages\n", TotalPagesNum));
|
||||||
|
|
||||||
LongModeBuffer.PageTableAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateReservedMemoryBelow4G (EFI_PAGES_TO_SIZE (TotalPagesNum));
|
LongModeBuffer.PageTableAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateReservedMemoryBelow4G (EFI_PAGES_TO_SIZE (TotalPagesNum));
|
||||||
ASSERT (LongModeBuffer.PageTableAddress != 0);
|
ASSERT (LongModeBuffer.PageTableAddress != 0);
|
||||||
PcdSet64 (PcdIdentifyMappingPageTablePtr, LongModeBuffer.PageTableAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Allocate stack
|
// Allocate stack
|
||||||
|
|
Loading…
Reference in New Issue