39UINT8 mPhysMemAddressWidth;
41STATIC UINT32 mS3AcpiReservedMemoryBase;
42STATIC UINT32 mS3AcpiReservedMemorySize;
44STATIC UINT16 mQ35TsegMbytes;
46BOOLEAN mQ35SmramAtDefaultSmbase =
FALSE;
49Q35TsegMbytesInitialization (
53 UINT16 ExtendedTsegMbytes;
54 RETURN_STATUS PcdStatus;
56 if (mHostBridgeDevId != INTEL_Q35_MCH_DEVICE_ID) {
59 "%a: no TSEG (SMRAM) on host bridge DID=0x%04x; "
60 "only DID=0x%04x (Q35) is supported\n",
63 INTEL_Q35_MCH_DEVICE_ID
85 PciWrite16 (DRAMC_REGISTER_Q35 (MCH_EXT_TSEG_MB), MCH_EXT_TSEG_MB_QUERY);
86 ExtendedTsegMbytes =
PciRead16 (DRAMC_REGISTER_Q35 (MCH_EXT_TSEG_MB));
87 if (ExtendedTsegMbytes == MCH_EXT_TSEG_MB_QUERY) {
88 mQ35TsegMbytes =
PcdGet16 (PcdQ35TsegMbytes);
94 "%a: QEMU offers an extended TSEG (%d MB)\n",
98 PcdStatus =
PcdSet16S (PcdQ35TsegMbytes, ExtendedTsegMbytes);
100 mQ35TsegMbytes = ExtendedTsegMbytes;
104GetSystemMemorySizeBelow4gb (
123 return (UINT32)(((
UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB);
128GetSystemMemorySizeAbove4gb (
143 for (CmosIndex = 0x5d; CmosIndex >= 0x5b; CmosIndex--) {
144 Size = (UINT32)(Size << 8) + (UINT32)
CmosRead8 (CmosIndex);
159 UINT64 FirstNonAddress;
160 UINT64 Pci64Base, Pci64Size;
161 RETURN_STATUS PcdStatus;
163 FirstNonAddress = BASE_4GB + GetSystemMemorySizeAbove4gb ();
172 return FirstNonAddress;
181 Pci64Size =
PcdGet64 (PcdPciMmio64Size);
183 if (Pci64Size == 0) {
184 if (mBootMode != BOOT_ON_S3_RESUME) {
187 "%a: disabling 64-bit PCI host aperture\n",
190 PcdStatus =
PcdSet64S (PcdPciMmio64Size, 0);
199 return FirstNonAddress;
206 Pci64Base =
ALIGN_VALUE (FirstNonAddress, (UINT64)SIZE_1GB);
207 Pci64Size =
ALIGN_VALUE (Pci64Size, (UINT64)SIZE_1GB);
217 if (mBootMode != BOOT_ON_S3_RESUME) {
223 PcdStatus =
PcdSet64S (PcdPciMmio64Base, Pci64Base);
225 PcdStatus =
PcdSet64S (PcdPciMmio64Size, Pci64Size);
230 "%a: Pci64Base=0x%Lx Pci64Size=0x%Lx\n",
240 FirstNonAddress = Pci64Base + Pci64Size;
241 return FirstNonAddress;
252 UINT64 FirstNonAddress;
261 mPhysMemAddressWidth = (UINT8)
HighBitSet64 (FirstNonAddress);
267 if ((FirstNonAddress & (FirstNonAddress - 1)) != 0) {
268 ++mPhysMemAddressWidth;
277 if (mPhysMemAddressWidth <= 36) {
278 mPhysMemAddressWidth = 36;
281 ASSERT (mPhysMemAddressWidth <= 48);
293 BOOLEAN Page1GSupport;
316 Page1GSupport =
FALSE;
319 if (RegEax >= 0x80000001) {
321 if ((RegEdx & BIT26) != 0) {
322 Page1GSupport =
TRUE;
327 if (mPhysMemAddressWidth <= 39) {
329 PdpEntries = 1 << (mPhysMemAddressWidth - 30);
330 ASSERT (PdpEntries <= 0x200);
332 Pml4Entries = 1 << (mPhysMemAddressWidth - 39);
333 ASSERT (Pml4Entries <= 0x200);
337 TotalPages = Page1GSupport ? Pml4Entries + 1 :
338 (PdpEntries + 1) * Pml4Entries + 1;
339 ASSERT (TotalPages <= 0x40201);
363 UINT32 LowerMemorySize;
366 LowerMemorySize = GetSystemMemorySizeBelow4gb ();
371 LowerMemorySize -= mQ35TsegMbytes * SIZE_1MB;
380 mS3AcpiReservedMemorySize = SIZE_512KB +
383 mS3AcpiReservedMemoryBase = LowerMemorySize - mS3AcpiReservedMemorySize;
384 LowerMemorySize = mS3AcpiReservedMemoryBase;
387 if (mBootMode == BOOT_ON_S3_RESUME) {
388 MemoryBase = mS3AcpiReservedMemoryBase;
389 MemorySize = mS3AcpiReservedMemorySize;
394 "%a: mPhysMemAddressWidth=%d PeiMemoryCap=%u KB\n",
396 mPhysMemAddressWidth,
410 MemoryBase = mS3Supported &&
FeaturePcdGet (PcdSmmSmramRequire) ?
411 PcdGet32 (PcdOvmfDecompressionScratchEnd) :
413 MemorySize = LowerMemorySize - MemoryBase;
414 if (MemorySize > PeiMemoryCap) {
415 MemoryBase = LowerMemorySize - PeiMemoryCap;
416 MemorySize = PeiMemoryCap;
439 UINT64 LowerMemorySize;
440 UINT64 UpperMemorySize;
444 DEBUG ((DEBUG_INFO,
"%a called\n", __func__));
449 LowerMemorySize = GetSystemMemorySizeBelow4gb ();
450 UpperMemorySize = GetSystemMemorySizeAbove4gb ();
452 if (mBootMode == BOOT_ON_S3_RESUME) {
483 TsegSize = mQ35TsegMbytes * SIZE_1MB;
485 AddReservedMemoryBaseSizeHob (
486 LowerMemorySize - TsegSize,
494 if (UpperMemorySize != 0) {
495 AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);
516 ASSERT ((MtrrSettings.MtrrDefType & BIT11) != 0);
517 ASSERT ((MtrrSettings.MtrrDefType & BIT10) == 0);
518 ASSERT ((MtrrSettings.MtrrDefType & 0xFF) == MTRR_CACHE_WRITE_BACK);
523 SetMem (&MtrrSettings.Fixed,
sizeof MtrrSettings.Fixed, MTRR_CACHE_WRITE_BACK);
524 ZeroMem (&MtrrSettings.Variables,
sizeof MtrrSettings.Variables);
525 MtrrSettings.MtrrDefType |= BIT10;
532 BASE_512KB + BASE_128KB,
533 BASE_1MB - (BASE_512KB + BASE_128KB),
544 SIZE_4GB - LowerMemorySize,
562 if (mS3Supported && (mBootMode != BOOT_ON_S3_RESUME)) {
567 mS3AcpiReservedMemoryBase,
568 mS3AcpiReservedMemorySize,
578 PcdGet32 (PcdOvmfSecPeiTempRamBase),
579 PcdGet32 (PcdOvmfSecPeiTempRamSize),
587 PcdGet64 (PcdGuidedExtractHandlerTableAddress),
588 PcdGet32 (PcdGuidedExtractHandlerTableSize),
607 if (mBootMode != BOOT_ON_S3_RESUME) {
637 TsegSize = mQ35TsegMbytes * SIZE_1MB;
639 GetSystemMemorySizeBelow4gb () - TsegSize,
VOID EFIAPI BuildMemoryAllocationHob(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN EFI_MEMORY_TYPE MemoryType)
VOID EFIAPI CpuDeadLoop(VOID)
UINT64 EFIAPI GetPowerOfTwo64(IN UINT64 Operand)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
INTN EFIAPI HighBitSet64(IN UINT64 Operand)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define ALIGN_VALUE(Value, Alignment)
#define ASSERT_EFI_ERROR(StatusParameter)
#define ASSERT_RETURN_ERROR(StatusParameter)
#define DEBUG(Expression)
UINT16 EFIAPI PciWrite16(IN UINTN Address, IN UINT16 Value)
UINT16 EFIAPI PciRead16(IN UINTN Address)
UINT32 EFIAPI AsmCpuid(IN UINT32 Index, OUT UINT32 *RegisterEax OPTIONAL, OUT UINT32 *RegisterEbx OPTIONAL, OUT UINT32 *RegisterEcx OPTIONAL, OUT UINT32 *RegisterEdx OPTIONAL)
MTRR_SETTINGS *EFIAPI MtrrSetAllMtrrs(IN MTRR_SETTINGS *MtrrSetting)
BOOLEAN EFIAPI IsMtrrSupported(VOID)
RETURN_STATUS EFIAPI MtrrSetMemoryAttribute(IN PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN MTRR_MEMORY_CACHE_TYPE Attribute)
MTRR_SETTINGS *EFIAPI MtrrGetAllMtrrs(OUT MTRR_SETTINGS *MtrrSetting)
#define PcdGet16(TokenName)
#define PcdGet64(TokenName)
#define PcdGet32(TokenName)
#define PcdGetBool(TokenName)
#define PcdSet64S(TokenName, Value)
#define PcdSet16S(TokenName, Value)
#define FeaturePcdGet(TokenName)
RETURN_STATUS EFIAPI PublishSystemMemory(IN PHYSICAL_ADDRESS MemoryBegin, IN UINT64 MemoryLength)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)