]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/PlatformPei/Platform.c
OvmfPkg: detect Xen earlier
[mirror_edk2.git] / OvmfPkg / PlatformPei / Platform.c
index d91f113693f73fc55bf6a12e73ab301c4f3ea93a..9b7828f8dccba4a26d8f211f92ec6e1856928a8a 100644 (file)
@@ -33,6 +33,7 @@
 #include <Library/ResourcePublicationLib.h>\r
 #include <Guid/MemoryTypeInformation.h>\r
 #include <Ppi/MasterBootMode.h>\r
+#include <IndustryStandard/Pci22.h>\r
 \r
 #include "Platform.h"\r
 #include "Cmos.h"\r
@@ -213,7 +214,7 @@ MemMapInitialization (
 \r
 VOID\r
 MiscInitialization (\r
-  BOOLEAN Xen\r
+  VOID\r
   )\r
 {\r
   //\r
@@ -226,11 +227,34 @@ 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
+    //\r
+    PciAndThenOr32 (\r
+      PCI_LIB_ADDRESS (0, 1, 3, 0x40),\r
+      (UINT32) ~0xFFC0,\r
+      PcdGet16 (PcdAcpiPmBaseAddress)\r
+      );\r
+\r
     //\r
-    // Set the PM I/O base address to 0x400\r
+    // 2. set PCICMD/IOSE\r
     //\r
-    PciAndThenOr32 (PCI_LIB_ADDRESS (0, 1, 3, 0x40), (UINT32) ~0xfc0, 0x400);\r
+    PciOr8 (\r
+      PCI_LIB_ADDRESS (0, 1, 3, PCI_COMMAND_OFFSET),\r
+      EFI_PCI_COMMAND_IO_SPACE\r
+      );\r
+\r
+    //\r
+    // 3. set PMREGMISC/PMIOSE\r
+    //\r
+    PciOr8 (PCI_LIB_ADDRESS (0, 1, 3, 0x80), 0x01);\r
   }\r
 }\r
 \r
@@ -263,8 +287,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
@@ -312,18 +337,21 @@ 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
   DEBUG ((EFI_D_ERROR, "Platform PEIM Loaded\n"));\r
 \r
   DebugDumpCmos ();\r
 \r
+  XenLeaf = XenDetect ();\r
+\r
   TopOfMemory = MemDetect ();\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
@@ -331,7 +359,7 @@ InitializePlatform (
 \r
   MemMapInitialization (TopOfMemory);\r
 \r
-  MiscInitialization (Xen);\r
+  MiscInitialization ();\r
 \r
   BootModeInitialization ();\r
 \r