]> 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 ce149e4f979e2c6589fa383ebc2b4232e9df99dc..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
@@ -214,7 +286,7 @@ MemMapInitialization (
 \r
 VOID\r
 MiscInitialization (\r
-  BOOLEAN Xen\r
+  VOID\r
   )\r
 {\r
   //\r
@@ -227,7 +299,12 @@ MiscInitialization (
   //\r
   BuildCpuHob (36, 16);\r
 \r
-  if (!Xen) {\r
+  //\r
+  // If PMREGMISC/PMIOSE is set, assume the ACPI PMBA has been configured (for\r
+  // example by Xen) and skip the setup here. This matches the logic in\r
+  // AcpiTimerLibConstructor ().\r
+  //\r
+  if ((PciRead8 (PCI_LIB_ADDRESS (0, 1, 3, 0x80)) & 0x01) == 0) {\r
     //\r
     // The PEI phase should be exited with fully accessibe PIIX4 IO space:\r
     // 1. set PMBA\r
@@ -282,8 +359,9 @@ ReserveEmuVariableNvStore (
   //\r
   VariableStore =\r
     (EFI_PHYSICAL_ADDRESS)(UINTN)\r
-      AllocateRuntimePool (\r
-        2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)\r
+      AllocateAlignedRuntimePages (\r
+        EFI_SIZE_TO_PAGES (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)),\r
+        PcdGet32 (PcdFlashNvStorageFtwSpareSize)\r
         );\r
   DEBUG ((EFI_D_INFO,\r
           "Reserved variable store memory: 0x%lX; size: %dkb\n",\r
@@ -331,28 +409,43 @@ InitializePlatform (
   IN CONST EFI_PEI_SERVICES     **PeiServices\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
   EFI_PHYSICAL_ADDRESS  TopOfMemory;\r
-  BOOLEAN               Xen;\r
+  UINT32 XenLeaf;\r
+\r
+  TopOfMemory = 0;\r
 \r
   DEBUG ((EFI_D_ERROR, "Platform PEIM Loaded\n"));\r
 \r
   DebugDumpCmos ();\r
 \r
-  TopOfMemory = MemDetect ();\r
+  XenLeaf = XenDetect ();\r
+\r
+  BootModeInitialization ();\r
+\r
+  PublishPeiMemory ();\r
+\r
+  if (XenLeaf != 0) {\r
+    PcdSetBool (PcdPciDisableBusEnumeration, TRUE);\r
+  } else {\r
+    TopOfMemory = MemDetect ();\r
+  }\r
 \r
-  Status = InitializeXen ();\r
-  Xen = EFI_ERROR (Status) ? FALSE : TRUE;\r
+  if (XenLeaf != 0) {\r
+    DEBUG ((EFI_D_INFO, "Xen was detected\n"));\r
+    InitializeXen (XenLeaf);\r
+  }\r
 \r
   ReserveEmuVariableNvStore ();\r
 \r
   PeiFvInitialization ();\r
 \r
-  MemMapInitialization (TopOfMemory);\r
-\r
-  MiscInitialization (Xen);\r
+  if (XenLeaf != 0) {\r
+    XenMemMapInitialization ();\r
+  } else {\r
+    MemMapInitialization (TopOfMemory);\r
+  }\r
 \r
-  BootModeInitialization ();\r
+  MiscInitialization ();\r
 \r
   return EFI_SUCCESS;\r
 }\r