]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/PlatformPei/Platform.c
OvmfPkg/PlatformPei: Move BootMode detection before mem-init
[mirror_edk2.git] / OvmfPkg / PlatformPei / Platform.c
index 9b7828f8dccba4a26d8f211f92ec6e1856928a8a..01460639b1d399d15bce5c485d54e2256a0dfb4d 100644 (file)
@@ -1,7 +1,7 @@
 /**@file\r
   Platform PEI driver\r
 \r
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
   Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>\r
 \r
   This program and the accompanying materials\r
 #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,74 @@ AddUntestedMemoryRangeHob (
   AddUntestedMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));\r
 }\r
 \r
+VOID\r
+XenMemMapInitialization (\r
+  VOID\r
+  )\r
+{\r
+  EFI_E820_ENTRY64 *E820Map;\r
+  UINT32 E820EntriesCount;\r
+  EFI_STATUS Status;\r
+\r
+  DEBUG ((EFI_D_INFO, "Using memory map provided by Xen\n"));\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
+  Status = XenGetE820Map(&E820Map, &E820EntriesCount);\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  if (E820EntriesCount > 0) {\r
+    EFI_E820_ENTRY64 *Entry;\r
+    UINT32 Loop;\r
+\r
+    for (Loop = 0; Loop < E820EntriesCount; Loop++) {\r
+      Entry = E820Map + Loop;\r
+\r
+      //\r
+      // Only care about RAM\r
+      //\r
+      if (Entry->Type != EfiAcpiAddressRangeMemory) {\r
+        continue;\r
+      }\r
+\r
+      if (Entry->BaseAddr >= BASE_4GB) {\r
+        AddUntestedMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);\r
+      } else {\r
+        AddMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);\r
+      }\r
+\r
+      MtrrSetMemoryAttribute (Entry->BaseAddr, Entry->Length, CacheWriteBack);\r
+    }\r
+  }\r
+}\r
+\r
 \r
 VOID\r
 MemMapInitialization (\r
@@ -340,13 +412,23 @@ InitializePlatform (
   EFI_PHYSICAL_ADDRESS  TopOfMemory;\r
   UINT32 XenLeaf;\r
 \r
+  TopOfMemory = 0;\r
+\r
   DEBUG ((EFI_D_ERROR, "Platform PEIM Loaded\n"));\r
 \r
   DebugDumpCmos ();\r
 \r
   XenLeaf = XenDetect ();\r
 \r
-  TopOfMemory = MemDetect ();\r
+  BootModeInitialization ();\r
+\r
+  PublishPeiMemory ();\r
+\r
+  if (XenLeaf != 0) {\r
+    PcdSetBool (PcdPciDisableBusEnumeration, TRUE);\r
+  } else {\r
+    TopOfMemory = MemDetect ();\r
+  }\r
 \r
   if (XenLeaf != 0) {\r
     DEBUG ((EFI_D_INFO, "Xen was detected\n"));\r
@@ -357,11 +439,13 @@ InitializePlatform (
 \r
   PeiFvInitialization ();\r
 \r
-  MemMapInitialization (TopOfMemory);\r
+  if (XenLeaf != 0) {\r
+    XenMemMapInitialization ();\r
+  } else {\r
+    MemMapInitialization (TopOfMemory);\r
+  }\r
 \r
   MiscInitialization ();\r
 \r
-  BootModeInitialization ();\r
-\r
   return EFI_SUCCESS;\r
 }\r