summaryrefslogtreecommitdiff
path: root/IntelFsp2Pkg/Library/BaseFspPlatformLib/FspPlatformMemory.c
diff options
context:
space:
mode:
Diffstat (limited to 'IntelFsp2Pkg/Library/BaseFspPlatformLib/FspPlatformMemory.c')
-rw-r--r--IntelFsp2Pkg/Library/BaseFspPlatformLib/FspPlatformMemory.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/IntelFsp2Pkg/Library/BaseFspPlatformLib/FspPlatformMemory.c b/IntelFsp2Pkg/Library/BaseFspPlatformLib/FspPlatformMemory.c
index 2573e4e..f136b5b 100644
--- a/IntelFsp2Pkg/Library/BaseFspPlatformLib/FspPlatformMemory.c
+++ b/IntelFsp2Pkg/Library/BaseFspPlatformLib/FspPlatformMemory.c
@@ -6,6 +6,7 @@
**/
#include <PiPei.h>
+#include <Register/Intel/Msr.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
@@ -119,3 +120,40 @@ FspGetSystemMemorySize (
Hob.Raw = GET_NEXT_HOB (Hob);
}
}
+
+/**
+ Calculate TemporaryRam Size using Base address.
+
+ @param[in] TemporaryRamBase the address of target memory
+ @param[out] TemporaryRamSize the size of target memory
+**/
+VOID
+EFIAPI
+ReadTemporaryRamSize (
+ IN UINT32 TemporaryRamBase,
+ OUT UINT32 *TemporaryRamSize
+ )
+{
+ MSR_IA32_MTRRCAP_REGISTER Msr;
+ UINT32 MsrNum;
+ UINT32 MsrNumEnd;
+
+ if (TemporaryRamBase == 0) {
+ return;
+ }
+
+ *TemporaryRamSize = 0;
+ Msr.Uint64 = AsmReadMsr64 (MSR_IA32_MTRRCAP);
+ MsrNumEnd = MSR_IA32_MTRR_PHYSBASE0 + (2 * (Msr.Bits.VCNT));
+
+ for (MsrNum = MSR_IA32_MTRR_PHYSBASE0; MsrNum < MsrNumEnd; MsrNum += 2) {
+ if ((AsmReadMsr64 (MsrNum+1) & BIT11) != 0 ) {
+ if (TemporaryRamBase == (AsmReadMsr64 (MsrNum) & 0xFFFFF000)) {
+ *TemporaryRamSize = (~(AsmReadMsr64 (MsrNum + 1) & 0xFFFFF000) + 1);
+ break;
+ }
+ }
+ }
+
+ return;
+}