IntelFsp2Pkg: FSP can utilize bootloader stack

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1485

Current FSP utilizes pre-allocated temporary memory from
boot loader for both heap and stack. To reduce overall
temporary memory usage FSP may share the same stack with
boot loader and only needs a smaller memory for heap,
no separate memory required for stack.
Setting PcdFspHeapSizePercentage to 0 to enable FSP sharing
stack with boot loader, in this case boot loader stack
has to be large enough for FSP to use. Default is 50
(half memory heap and half memory stack) for backward
compatible with original model.

Test: Verified on internal platform and booting successfully
      with both modes.

Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
This commit is contained in:
Chasel, Chiu
2019-01-23 16:12:38 +08:00
parent 35897da27e
commit 12a0a80b4a
6 changed files with 157 additions and 19 deletions

View File

@ -1,6 +1,6 @@
/** @file
Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
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
@ -83,7 +83,29 @@ SecStartup (
//
InitializeFloatingPointUnits ();
//
// Scenario 1 memory map when running on bootloader stack
//
// |-------------------|---->
// |Idt Table |
// |-------------------|
// |PeiService Pointer |
// |-------------------|
// | |
// | |
// | Heap |
// | |
// | |
// |-------------------|----> TempRamBase
//
//
// |-------------------|
// |Bootloader stack |----> somewhere in memory, FSP will share this stack.
// |-------------------|
//
// Scenario 2 memory map when running FSP on a separate stack
//
// |-------------------|---->
// |Idt Table |
// |-------------------|
@ -135,11 +157,19 @@ SecStartup (
SecCoreData.BootFirmwareVolumeSize = (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)BootFirmwareVolume)->FvLength;
SecCoreData.TemporaryRamBase = (VOID*)(UINTN) TempRamBase;
SecCoreData.TemporaryRamSize = SizeOfRam;
SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;
SecCoreData.PeiTemporaryRamSize = SecCoreData.TemporaryRamSize * PcdGet8 (PcdFspHeapSizePercentage) / 100;
SecCoreData.StackBase = (VOID*)(UINTN)((UINTN)SecCoreData.TemporaryRamBase + SecCoreData.PeiTemporaryRamSize);
SecCoreData.StackSize = SecCoreData.TemporaryRamSize - SecCoreData.PeiTemporaryRamSize;
if (PcdGet8 (PcdFspHeapSizePercentage) == 0) {
SecCoreData.TemporaryRamSize = SizeOfRam; // stack size that is going to be copied to the permanent memory
SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;
SecCoreData.PeiTemporaryRamSize = SecCoreData.TemporaryRamSize;
SecCoreData.StackBase = (VOID *)GetFspEntryStack(); // Share the same boot loader stack
SecCoreData.StackSize = 0;
} else {
SecCoreData.TemporaryRamSize = SizeOfRam;
SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;
SecCoreData.PeiTemporaryRamSize = SecCoreData.TemporaryRamSize * PcdGet8 (PcdFspHeapSizePercentage) / 100;
SecCoreData.StackBase = (VOID*)(UINTN)((UINTN)SecCoreData.TemporaryRamBase + SecCoreData.PeiTemporaryRamSize);
SecCoreData.StackSize = SecCoreData.TemporaryRamSize - SecCoreData.PeiTemporaryRamSize;
}
DEBUG ((DEBUG_INFO, "Fsp BootFirmwareVolumeBase - 0x%x\n", SecCoreData.BootFirmwareVolumeBase));
DEBUG ((DEBUG_INFO, "Fsp BootFirmwareVolumeSize - 0x%x\n", SecCoreData.BootFirmwareVolumeSize));
@ -194,15 +224,37 @@ SecTemporaryRamSupport (
UINTN HeapSize;
UINTN StackSize;
HeapSize = CopySize * PcdGet8 (PcdFspHeapSizePercentage) / 100 ;
StackSize = CopySize - HeapSize;
UINTN CurrentStack;
UINTN FspStackBase;
OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;
NewHeap = (VOID*)((UINTN)PermanentMemoryBase + StackSize);
if (PcdGet8 (PcdFspHeapSizePercentage) == 0) {
OldStack = (VOID*)((UINTN)TemporaryMemoryBase + HeapSize);
NewStack = (VOID*)(UINTN)PermanentMemoryBase;
CurrentStack = AsmReadEsp();
FspStackBase = (UINTN)GetFspEntryStack();
StackSize = FspStackBase - CurrentStack;
HeapSize = CopySize;
OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;
NewHeap = (VOID*)((UINTN)PermanentMemoryBase);
OldStack = (VOID*)CurrentStack;
//
//The old stack is copied at the end of the stack region because stack grows down.
//
NewStack = (VOID*)((UINTN)PermanentMemoryBase - StackSize);
} else {
HeapSize = CopySize * PcdGet8 (PcdFspHeapSizePercentage) / 100 ;
StackSize = CopySize - HeapSize;
OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;
NewHeap = (VOID*)((UINTN)PermanentMemoryBase + StackSize);
OldStack = (VOID*)((UINTN)TemporaryMemoryBase + HeapSize);
NewStack = (VOID*)(UINTN)PermanentMemoryBase;
}
//
// Migrate Heap
//