]> xenbits.xensource.com Git - people/liuw/ovmf.git/commitdiff
OvmfPkg: introduce XenMemMapInitialization rfc-v2
authorWei Liu <wei.liu2@citrix.com>
Fri, 15 Nov 2013 03:23:35 +0000 (03:23 +0000)
committerWei Liu <wei.liu2@citrix.com>
Tue, 19 Nov 2013 20:30:04 +0000 (20:30 +0000)
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
OvmfPkg/OvmfPkgIa32X64.dsc
OvmfPkg/OvmfPkgX64.dsc
OvmfPkg/PlatformPei/Platform.c
OvmfPkg/PlatformPei/PlatformPei.inf

index 760bd4106947fef83bb22af26d3d262a5ab7ef99..4b465fe96db24758634568095fe6d633b90b1c19 100644 (file)
 !else\r
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf\r
 !endif\r
-  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
 \r
 [LibraryClasses.common.DXE_DRIVER]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPciAllowFullEnumeration|TRUE\r
 \r
 \r
 ################################################################################\r
   MdeModulePkg/Core/Pei/PeiMain.inf\r
   MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {\r
     <LibraryClasses>\r
-      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+      PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf\r
   }\r
   IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf\r
   MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
index 268d722fde4f12ce0f96dcc487cabb4e27d75d2e..d26145d249a60541b9c52488b2980de40dfda3ab 100644 (file)
 !else\r
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf\r
 !endif\r
-  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
 \r
 [LibraryClasses.common.DXE_DRIVER]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPciAllowFullEnumeration|TRUE\r
 \r
 \r
 ################################################################################\r
   MdeModulePkg/Core/Pei/PeiMain.inf\r
   MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {\r
     <LibraryClasses>\r
-      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+      PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf\r
   }\r
   IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf\r
   MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
index 53945d0bb389fb4677ee28b2374e14643507a7a9..b2792aac9f8383ed11e62ac95b5e130231e942d0 100644 (file)
 !else\r
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf\r
 !endif\r
-  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
 \r
 [LibraryClasses.common.DXE_DRIVER]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPciAllowFullEnumeration|TRUE\r
 \r
 \r
 ################################################################################\r
   MdeModulePkg/Core/Pei/PeiMain.inf\r
   MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {\r
     <LibraryClasses>\r
-      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+      PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf\r
   }\r
   IntelFrameworkModulePkg/Universal/StatusCode/Pei/StatusCodePei.inf\r
   MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
index 9b7828f8dccba4a26d8f211f92ec6e1856928a8a..f9ffc250df92c6287549c54d7d9f4b885b514a2a 100644 (file)
 #include <Guid/MemoryTypeInformation.h>\r
 #include <Ppi/MasterBootMode.h>\r
 #include <IndustryStandard/Pci22.h>\r
+#include <Guid/XenInfo.h>\r
+#include <IndustryStandard/E820.h>\r
+#include <Library/ResourcePublicationLib.h>\r
+#include <Library/MtrrLib.h>\r
 \r
 #include "Platform.h"\r
 #include "Cmos.h"\r
@@ -163,6 +167,72 @@ AddUntestedMemoryRangeHob (
   AddUntestedMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));\r
 }\r
 \r
+VOID\r
+XenMemMapInitialization (\r
+  VOID\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE *GuidHob;\r
+  EFI_XEN_INFO *Info;\r
+\r
+  DEBUG ((EFI_D_ERROR, "Using memory map provided by Xen\n"));\r
+\r
+  GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);\r
+\r
+  ASSERT (GuidHob != NULL);\r
+\r
+  Info = GET_GUID_HOB_DATA (GuidHob);\r
+\r
+  //\r
+  // Create Memory Type Information HOB\r
+  //\r
+  BuildGuidDataHob (\r
+    &gEfiMemoryTypeInformationGuid,\r
+    mDefaultMemoryTypeInformation,\r
+    sizeof(mDefaultMemoryTypeInformation)\r
+    );\r
+\r
+  //\r
+  // Add PCI IO Port space available for PCI resource allocations.\r
+  //\r
+  BuildResourceDescriptorHob (\r
+    EFI_RESOURCE_IO,\r
+    EFI_RESOURCE_ATTRIBUTE_PRESENT     |\r
+    EFI_RESOURCE_ATTRIBUTE_INITIALIZED,\r
+    0xC000,\r
+    0x4000\r
+    );\r
+\r
+  //\r
+  // Video memory + Legacy BIOS region\r
+  //\r
+  AddIoMemoryRangeHob (0x0A0000, BASE_1MB);\r
+\r
+  //\r
+  // Parse RAM in E820 map\r
+  //\r
+  if (Info->E820EntryCount > 0) {\r
+    EFI_E820_ENTRY64 *E820Map, *Entry;\r
+    UINT16 Loop;\r
+\r
+    E820Map = Info->E820;\r
+    for (Loop = 0; Loop < Info->E820EntryCount; Loop++) {\r
+      Entry = E820Map + Loop;\r
+\r
+      // only care about RAM\r
+      if (Entry->Type != EfiAcpiAddressRangeMemory)\r
+        continue;\r
+\r
+      if (Entry->BaseAddr >= BASE_4GB)\r
+        AddUntestedMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);\r
+      else\r
+        AddMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);\r
+\r
+      MtrrSetMemoryAttribute (Entry->BaseAddr, Entry->Length, CacheWriteBack);\r
+    }\r
+  }\r
+}\r
+\r
 \r
 VOID\r
 MemMapInitialization (\r
@@ -346,7 +416,11 @@ InitializePlatform (
 \r
   XenLeaf = XenDetect ();\r
 \r
-  TopOfMemory = MemDetect ();\r
+  if (XenLeaf != 0) {\r
+    PublishPeiMemory ();\r
+    PcdSetBool (PcdPciAllowFullEnumeration, FALSE);\r
+  } else\r
+    TopOfMemory = MemDetect ();\r
 \r
   if (XenLeaf != 0) {\r
     DEBUG ((EFI_D_INFO, "Xen was detected\n"));\r
@@ -357,7 +431,10 @@ InitializePlatform (
 \r
   PeiFvInitialization ();\r
 \r
-  MemMapInitialization (TopOfMemory);\r
+  if (XenLeaf != 0)\r
+    XenMemMapInitialization ();\r
+  else\r
+    MemMapInitialization (TopOfMemory);\r
 \r
   MiscInitialization ();\r
 \r
index 3d5cbbbc2b59dd1bcd3629ff89e5378d3cb61156..221afb2303848720945d9e8c1aa434401084a8c5 100644 (file)
@@ -65,6 +65,7 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPciAllowFullEnumeration\r
   gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress\r
 \r
 [Ppis]\r