Wei Liu
2013-Nov-19 20:38 UTC
[PATCH RFC v2 7/7] OvmfPkg: introduce XenMemMapInitialization
This function parses Xen OVMF info and arrange memory maps accordingly.
It also sets PcdPciAllowFullEnumeration to false to prevent OVMF from
playing with PCI devices.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
OvmfPkg/OvmfPkgIa32.dsc | 5 ++-
OvmfPkg/OvmfPkgIa32X64.dsc | 5 ++-
OvmfPkg/OvmfPkgX64.dsc | 5 ++-
OvmfPkg/PlatformPei/Platform.c | 81 ++++++++++++++++++++++++++++++++++-
OvmfPkg/PlatformPei/PlatformPei.inf | 1 +
5 files changed, 89 insertions(+), 8 deletions(-)
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 760bd41..4b465fe 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -222,7 +222,7 @@
!else
DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
!endif
- PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
[LibraryClasses.common.DXE_DRIVER]
@@ -320,6 +320,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPciAllowFullEnumeration|TRUE
################################################################################
@@ -342,7 +343,7 @@
MdeModulePkg/Core/Pei/PeiMain.inf
MdeModulePkg/Universal/PCD/Pei/Pcd.inf {
<LibraryClasses>
- PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
}
IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf
MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 268d722..d26145d 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -227,7 +227,7 @@
!else
DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
!endif
- PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
[LibraryClasses.common.DXE_DRIVER]
@@ -326,6 +326,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPciAllowFullEnumeration|TRUE
################################################################################
@@ -348,7 +349,7 @@
MdeModulePkg/Core/Pei/PeiMain.inf
MdeModulePkg/Universal/PCD/Pei/Pcd.inf {
<LibraryClasses>
- PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
}
IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf
MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 53945d0..b2792aa 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -227,7 +227,7 @@
!else
DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
!endif
- PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
[LibraryClasses.common.DXE_DRIVER]
@@ -325,6 +325,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPciAllowFullEnumeration|TRUE
################################################################################
@@ -347,7 +348,7 @@
MdeModulePkg/Core/Pei/PeiMain.inf
MdeModulePkg/Universal/PCD/Pei/Pcd.inf {
<LibraryClasses>
- PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
}
IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf
MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index 9b7828f..f9ffc25 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -34,6 +34,10 @@
#include <Guid/MemoryTypeInformation.h>
#include <Ppi/MasterBootMode.h>
#include <IndustryStandard/Pci22.h>
+#include <Guid/XenInfo.h>
+#include <IndustryStandard/E820.h>
+#include <Library/ResourcePublicationLib.h>
+#include <Library/MtrrLib.h>
#include "Platform.h"
#include "Cmos.h"
@@ -163,6 +167,72 @@ AddUntestedMemoryRangeHob (
AddUntestedMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit -
MemoryBase));
}
+VOID
+XenMemMapInitialization (
+ VOID
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+ EFI_XEN_INFO *Info;
+
+ DEBUG ((EFI_D_ERROR, "Using memory map provided by Xen\n"));
+
+ GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
+
+ ASSERT (GuidHob != NULL);
+
+ Info = GET_GUID_HOB_DATA (GuidHob);
+
+ //
+ // Create Memory Type Information HOB
+ //
+ BuildGuidDataHob (
+ &gEfiMemoryTypeInformationGuid,
+ mDefaultMemoryTypeInformation,
+ sizeof(mDefaultMemoryTypeInformation)
+ );
+
+ //
+ // Add PCI IO Port space available for PCI resource allocations.
+ //
+ BuildResourceDescriptorHob (
+ EFI_RESOURCE_IO,
+ EFI_RESOURCE_ATTRIBUTE_PRESENT |
+ EFI_RESOURCE_ATTRIBUTE_INITIALIZED,
+ 0xC000,
+ 0x4000
+ );
+
+ //
+ // Video memory + Legacy BIOS region
+ //
+ AddIoMemoryRangeHob (0x0A0000, BASE_1MB);
+
+ //
+ // Parse RAM in E820 map
+ //
+ if (Info->E820EntryCount > 0) {
+ EFI_E820_ENTRY64 *E820Map, *Entry;
+ UINT16 Loop;
+
+ E820Map = Info->E820;
+ for (Loop = 0; Loop < Info->E820EntryCount; Loop++) {
+ Entry = E820Map + Loop;
+
+ // only care about RAM
+ if (Entry->Type != EfiAcpiAddressRangeMemory)
+ continue;
+
+ if (Entry->BaseAddr >= BASE_4GB)
+ AddUntestedMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);
+ else
+ AddMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);
+
+ MtrrSetMemoryAttribute (Entry->BaseAddr, Entry->Length,
CacheWriteBack);
+ }
+ }
+}
+
VOID
MemMapInitialization (
@@ -346,7 +416,11 @@ InitializePlatform (
XenLeaf = XenDetect ();
- TopOfMemory = MemDetect ();
+ if (XenLeaf != 0) {
+ PublishPeiMemory ();
+ PcdSetBool (PcdPciAllowFullEnumeration, FALSE);
+ } else
+ TopOfMemory = MemDetect ();
if (XenLeaf != 0) {
DEBUG ((EFI_D_INFO, "Xen was detected\n"));
@@ -357,7 +431,10 @@ InitializePlatform (
PeiFvInitialization ();
- MemMapInitialization (TopOfMemory);
+ if (XenLeaf != 0)
+ XenMemMapInitialization ();
+ else
+ MemMapInitialization (TopOfMemory);
MiscInitialization ();
diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf
b/OvmfPkg/PlatformPei/PlatformPei.inf
index 3d5cbbb..221afb2 100644
--- a/OvmfPkg/PlatformPei/PlatformPei.inf
+++ b/OvmfPkg/PlatformPei/PlatformPei.inf
@@ -65,6 +65,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPciAllowFullEnumeration
gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress
[Ppis]
--
1.7.10.4