From: jljusten Date: Tue, 31 Jul 2012 18:18:01 +0000 (+0000) Subject: OvmfPkg: scan memory space map and populate FWDT (32-bit fields only) X-Git-Tag: edk2-stable201903~13206 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=57c0beb609a75349c067075b45cdafce1a1b77f8;p=mirror_edk2.git OvmfPkg: scan memory space map and populate FWDT (32-bit fields only) Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Reviewed-by: Jordan Justen [jordan.l.justen@intel.com: minor cleanup] Signed-off-by: Jordan Justen git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13574 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf index b43b8ac403..04eb495cac 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf @@ -48,6 +48,7 @@ QemuFwCfgLib MemoryAllocationLib BaseLib + DxeServicesTableLib [Protocols] gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED diff --git a/OvmfPkg/AcpiPlatformDxe/Qemu.c b/OvmfPkg/AcpiPlatformDxe/Qemu.c index 7088733905..051449d72a 100644 --- a/OvmfPkg/AcpiPlatformDxe/Qemu.c +++ b/OvmfPkg/AcpiPlatformDxe/Qemu.c @@ -16,6 +16,7 @@ #include #include #include +#include BOOLEAN @@ -121,7 +122,92 @@ PopulateFwData( OUT FIRMWARE_DATA *FwData ) { - return EFI_SUCCESS; + EFI_STATUS Status; + UINTN NumDesc; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR *AllDesc; + + Status = gDS->GetMemorySpaceMap (&NumDesc, &AllDesc); + if (Status == EFI_SUCCESS) { + UINT64 NonMmio32MaxExclTop; + UINT64 Mmio32MinBase; + UINT64 Mmio32MaxExclTop; + UINTN CurDesc; + + Status = EFI_UNSUPPORTED; + + NonMmio32MaxExclTop = 0; + Mmio32MinBase = BASE_4GB; + Mmio32MaxExclTop = 0; + + for (CurDesc = 0; CurDesc < NumDesc; ++CurDesc) { + CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Desc; + UINT64 ExclTop; + + Desc = &AllDesc[CurDesc]; + ExclTop = Desc->BaseAddress + Desc->Length; + + if (ExclTop <= BASE_4GB) { + switch (Desc->GcdMemoryType) { + case EfiGcdMemoryTypeNonExistent: + break; + + case EfiGcdMemoryTypeReserved: + case EfiGcdMemoryTypeSystemMemory: + if (NonMmio32MaxExclTop < ExclTop) { + NonMmio32MaxExclTop = ExclTop; + } + break; + + case EfiGcdMemoryTypeMemoryMappedIo: + if (Mmio32MinBase > Desc->BaseAddress) { + Mmio32MinBase = Desc->BaseAddress; + } + if (Mmio32MaxExclTop < ExclTop) { + Mmio32MaxExclTop = ExclTop; + } + break; + + default: + ASSERT(0); + } + } + } + + if (Mmio32MinBase < NonMmio32MaxExclTop) { + Mmio32MinBase = NonMmio32MaxExclTop; + } + + if (Mmio32MinBase < Mmio32MaxExclTop) { + FwData->PciWindow32.Base = Mmio32MinBase; + FwData->PciWindow32.End = Mmio32MaxExclTop - 1; + FwData->PciWindow32.Length = Mmio32MaxExclTop - Mmio32MinBase; + + FwData->PciWindow64.Base = 0; + FwData->PciWindow64.End = 0; + FwData->PciWindow64.Length = 0; + + Status = EFI_SUCCESS; + } + + FreePool (AllDesc); + } + + DEBUG (( + DEBUG_INFO, + "ACPI PciWindow32: Base=0x%08lx End=0x%08lx Length=0x%08lx\n", + FwData->PciWindow32.Base, + FwData->PciWindow32.End, + FwData->PciWindow32.Length + )); + DEBUG (( + DEBUG_INFO, + "ACPI PciWindow64: Base=0x%08lx End=0x%08lx Length=0x%08lx\n", + FwData->PciWindow64.Base, + FwData->PciWindow64.End, + FwData->PciWindow64.Length + )); + + return Status; }