TianoCore EDK2 master
|
#include <IndustryStandard/E820.h>
#include <IndustryStandard/I440FxPiix4.h>
#include <IndustryStandard/Q35MchIch9.h>
#include <IndustryStandard/CloudHv.h>
#include <IndustryStandard/Xen/arch-x86/hvm/start_info.h>
#include <PiPei.h>
#include <Register/Intel/SmramSaveStateMap.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/CcProbeLib.h>
#include <Library/DebugLib.h>
#include <Library/HardwareInfoLib.h>
#include <Library/HobLib.h>
#include <Library/IoLib.h>
#include <Library/MemEncryptSevLib.h>
#include <Library/PcdLib.h>
#include <Library/PciLib.h>
#include <Library/PeimEntryPoint.h>
#include <Library/ResourcePublicationLib.h>
#include <Library/MtrrLib.h>
#include <Library/QemuFwCfgLib.h>
#include <Library/QemuFwCfgSimpleParserLib.h>
#include <Library/TdxLib.h>
#include <Library/PlatformInitLib.h>
#include <Guid/AcpiS3Context.h>
#include <Guid/SmramMemoryReserve.h>
Go to the source code of this file.
Macros | |
#define | MEGABYTE_SHIFT 20 |
Typedefs | |
typedef VOID(* | E820_SCAN_CALLBACK) (EFI_E820_ENTRY64 *E820Entry, EFI_HOB_PLATFORM_INFO *PlatformInfoHob) |
Memory Detection for Virtual Machines.
Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Module Name:
MemDetect.c
Definition in file MemDetect.c.
#define MEGABYTE_SHIFT 20 |
Definition at line 49 of file MemDetect.c.
typedef VOID(* E820_SCAN_CALLBACK) (EFI_E820_ENTRY64 *E820Entry, EFI_HOB_PLATFORM_INFO *PlatformInfoHob) |
Definition at line 105 of file MemDetect.c.
STATIC VOID CreateSmmSmramMemoryHob | ( | IN EFI_PHYSICAL_ADDRESS | StartAddress, |
IN UINT32 | Size | ||
) |
Create gEfiSmmSmramMemoryGuid HOB defined in the PI specification Vol. 3, section 5, which is used to describe the SMRAM memory regions supported by the platform.
[in] | StartAddress | StartAddress of smram. |
[in] | Size | Size of smram. |
Definition at line 1151 of file MemDetect.c.
STATIC UINT64 GetHighestSystemMemoryAddressFromPvhMemmap | ( | BOOLEAN | Below4gb | ) |
Definition at line 404 of file MemDetect.c.
EFI_STATUS GetPvhMemmapEntries | ( | struct hvm_memmap_table_entry ** | Entries, |
UINT32 * | Count | ||
) |
Returns PVH memmap
Entries | Pointer to PVH memmap |
Count | Number of entries |
Definition at line 291 of file MemDetect.c.
STATIC VOID PlatformAddHobCB | ( | IN EFI_E820_ENTRY64 * | E820Entry, |
IN OUT EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ||
) |
Create HOBs for reservations and RAM (except low memory).
Definition at line 197 of file MemDetect.c.
VOID EFIAPI PlatformAddressWidthFromCpuid | ( | IN OUT EFI_HOB_PLATFORM_INFO * | PlatformInfoHob, |
IN BOOLEAN | QemuQuirk | ||
) |
Definition at line 663 of file MemDetect.c.
VOID EFIAPI PlatformAddressWidthInitialization | ( | IN OUT EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ) |
Initialize the PhysMemAddressWidth field in PlatformInfoHob based on guest RAM size.
Definition at line 1045 of file MemDetect.c.
VOID EFIAPI PlatformDynamicMmioWindow | ( | IN OUT EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ) |
Definition at line 789 of file MemDetect.c.
STATIC VOID PlatformGetFirstNonAddress | ( | IN OUT EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ) |
Return the highest address that DXE could possibly use, plus one.
Definition at line 506 of file MemDetect.c.
STATIC VOID PlatformGetFirstNonAddressCB | ( | IN EFI_E820_ENTRY64 * | E820Entry, |
IN OUT EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ||
) |
Store first address not used by e820 RAM entries in PlatformInfoHob->FirstNonAddress
Definition at line 146 of file MemDetect.c.
STATIC VOID PlatformGetLowMemoryCB | ( | IN EFI_E820_ENTRY64 * | E820Entry, |
IN OUT EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ||
) |
Store the low (below 4G) memory size in PlatformInfoHob->LowMemory
Definition at line 170 of file MemDetect.c.
STATIC UINT64 PlatformGetSystemMemorySizeAbove4gb | ( | ) |
Definition at line 479 of file MemDetect.c.
VOID EFIAPI PlatformGetSystemMemorySizeBelow4gb | ( | IN EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ) |
Definition at line 441 of file MemDetect.c.
VOID EFIAPI PlatformQemuInitializeRam | ( | IN EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ) |
Peform Memory Detection for QEMU / KVM
Definition at line 1231 of file MemDetect.c.
VOID EFIAPI PlatformQemuInitializeRamForS3 | ( | IN EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ) |
Definition at line 1358 of file MemDetect.c.
VOID EFIAPI PlatformQemuUc32BaseInitialization | ( | IN OUT EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ) |
Definition at line 53 of file MemDetect.c.
STATIC VOID PlatformReservationConflictCB | ( | IN EFI_E820_ENTRY64 * | E820Entry, |
IN OUT EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ||
) |
Check whenever the 64bit PCI MMIO window overlaps with a reservation from qemu. If so move down the MMIO window to resolve the conflict.
This happens on (virtual) AMD machines with 1TB address space, because the AMD IOMMU uses an address window just below 1TB.
Definition at line 248 of file MemDetect.c.
STATIC EFI_STATUS PlatformScanE820 | ( | IN E820_SCAN_CALLBACK | Callback, |
IN OUT EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ||
) |
Iterate over the entries in QEMU's fw_cfg E820 RAM map, call the passed callback for each entry.
[in] | Callback | The callback function to be called. |
[in,out] | PlatformInfoHob | PlatformInfo struct which is passed through to the callback. |
EFI_SUCCESS | The fw_cfg E820 RAM map was found and processed. |
EFI_PROTOCOL_ERROR | The RAM map was found, but its size wasn't a whole multiple of sizeof(EFI_E820_ENTRY64). No RAM entry was processed. |
Definition at line 365 of file MemDetect.c.
STATIC EFI_STATUS PlatformScanE820Pvh | ( | IN E820_SCAN_CALLBACK | Callback, |
IN OUT EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ||
) |
Definition at line 314 of file MemDetect.c.
STATIC EFI_STATUS PlatformScanE820Tdx | ( | IN E820_SCAN_CALLBACK | Callback, |
IN OUT EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ||
) |
Definition at line 112 of file MemDetect.c.
STATIC EFI_STATUS PlatformScanHostProvided64BitPciMmioEnd | ( | OUT UINT64 * | PciMmioAddressEnd | ) |
Iterate over the PCI host bridges resources information optionally provided in fw-cfg and find the highest address contained in the PCI MMIO windows. If the information is found, return the exclusive end; one past the last usable address.
[out] | PciMmioAddressEnd | Pointer to one-after End Address updated with information extracted from host-provided data or zero if no information available or an error happened |
EFI_SUCCESS | PCI information was read and the output parameter updated with the last valid address in the 64-bit MMIO range. |
EFI_INVALID_PARAMETER | Pointer parameter is invalid |
EFI_INCOMPATIBLE_VERSION | Hardware information found in fw-cfg has an incompatible format |
EFI_UNSUPPORTED | Fw-cfg is not supported, thus host provided information, if any, cannot be read |
EFI_NOT_FOUND | No PCI host bridge information provided by the host. |
Definition at line 840 of file MemDetect.c.
STATIC VOID PlatformSetupPagingLevel | ( | IN OUT EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ) |
Configure x64 paging levels.
The OVMF ResetVector code will enter long mode with 5-level paging if the following conditions are true:
(1) OVMF has been built with PcdUse5LevelPageTable = TRUE, and (2) the CPU supports 5-level paging (aka la57), and (3) the CPU supports gigabyte pages, and (4) the VM is not running in SEV mode.
Condition (4) is a temporary stopgap for BaseMemEncryptSevLib not supporting 5-level paging yet.
This function looks at the virtual machine configuration, then decides whenever it will continue to use 5-level paging or downgrade to 4-level paging for better compatibility with older guest OS versions.
There is a fw_cfg config option to explicitly request 4 or 5-level paging using 'qemu -fw_cfg name=opt/org.tianocode/PagingLevel,string=4|5'. If the option is present the requested paging level will be used.
Should that not be the case the function checks the size of the address space needed, which is the RAM installed plus fw_cfg reservations. The downgrade to 4-level paging will happen for small guests where the address space needed is lower than 1TB.
This function will also log the paging level used and the reason for that.
Definition at line 975 of file MemDetect.c.
STATIC VOID QemuInitializeRamBelow1gb | ( | IN EFI_HOB_PLATFORM_INFO * | PlatformInfoHob | ) |
Definition at line 1201 of file MemDetect.c.