]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/PlatformPei/Xen.c
BaseTools/BinToPcd: Fix Python 2.7.x compatibility issue
[mirror_edk2.git] / OvmfPkg / PlatformPei / Xen.c
index a720b91b99bb1ad7ea26c0cf276eecd6ab5979de..ab38f97a67aa4a1334f4bbfd3f381718615a23d9 100644 (file)
@@ -1,7 +1,7 @@
 /**@file\r
   Xen Platform PEI support\r
 \r
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, 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 <Library/MemoryAllocationLib.h>\r
 #include <Library/PcdLib.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 "Xen.h"\r
+\r
+BOOLEAN mXen = FALSE;\r
+\r
+STATIC UINT32 mXenLeaf = 0;\r
 \r
 EFI_XEN_INFO mXenInfo;\r
 \r
+/**\r
+  Returns E820 map provided by Xen\r
+\r
+  @param Entries      Pointer to E820 map\r
+  @param Count        Number of entries\r
+\r
+  @return EFI_STATUS\r
+**/\r
+EFI_STATUS\r
+XenGetE820Map (\r
+  EFI_E820_ENTRY64 **Entries,\r
+  UINT32 *Count\r
+  )\r
+{\r
+  EFI_XEN_OVMF_INFO *Info =\r
+    (EFI_XEN_OVMF_INFO *)(UINTN) OVMF_INFO_PHYSICAL_ADDRESS;\r
+\r
+  if (AsciiStrCmp ((CHAR8 *) Info->Signature, "XenHVMOVMF")) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  ASSERT (Info->E820 < MAX_ADDRESS);\r
+  *Entries = (EFI_E820_ENTRY64 *)(UINTN) Info->E820;\r
+  *Count = Info->E820EntriesCount;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
 \r
 /**\r
   Connects to the Hypervisor.\r
@@ -84,32 +119,85 @@ XenConnect (
 /**\r
   Figures out if we are running inside Xen HVM.\r
 \r
-  @return UINT32     CPUID index used to connect to HV.\r
+  @retval TRUE   Xen was detected\r
+  @retval FALSE  Xen was not detected\r
 \r
 **/\r
-UINT32\r
+BOOLEAN\r
 XenDetect (\r
   VOID\r
   )\r
 {\r
-\r
-  UINT32 XenLeaf;\r
   UINT8 Signature[13];\r
 \r
-  for (XenLeaf = 0x40000000; XenLeaf < 0x40010000; XenLeaf += 0x100) {\r
-    AsmCpuid (XenLeaf, NULL, (UINT32 *) &Signature[0],\r
+  if (mXenLeaf != 0) {\r
+    return TRUE;\r
+  }\r
+\r
+  Signature[12] = '\0';\r
+  for (mXenLeaf = 0x40000000; mXenLeaf < 0x40010000; mXenLeaf += 0x100) {\r
+    AsmCpuid (mXenLeaf,\r
+              NULL,\r
+              (UINT32 *) &Signature[0],\r
               (UINT32 *) &Signature[4],\r
               (UINT32 *) &Signature[8]);\r
-    Signature[12] = '\0';\r
 \r
     if (!AsciiStrCmp ((CHAR8 *) Signature, "XenVMMXenVMM")) {\r
-      return XenLeaf;\r
+      mXen = TRUE;\r
+      return TRUE;\r
     }\r
   }\r
 \r
-  return 0;\r
+  mXenLeaf = 0;\r
+  return FALSE;\r
+}\r
+\r
+\r
+VOID\r
+XenPublishRamRegions (\r
+  VOID\r
+  )\r
+{\r
+  EFI_E820_ENTRY64  *E820Map;\r
+  UINT32            E820EntriesCount;\r
+  EFI_STATUS        Status;\r
+\r
+  if (!mXen) {\r
+    return;\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, "Using memory map provided by Xen\n"));\r
+\r
+  //\r
+  // Parse RAM in E820 map\r
+  //\r
+  E820EntriesCount = 0;\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
+      AddMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);\r
+\r
+      MtrrSetMemoryAttribute (Entry->BaseAddr, Entry->Length, CacheWriteBack);\r
+    }\r
+  }\r
 }\r
 \r
+\r
 /**\r
   Perform Xen PEI initialization.\r
 \r
@@ -122,23 +210,22 @@ InitializeXen (
   VOID\r
   )\r
 {\r
-  UINT32 XenLeaf;\r
-\r
-  XenLeaf = XenDetect ();\r
+  RETURN_STATUS PcdStatus;\r
 \r
-  if (XenLeaf == 0) {\r
+  if (mXenLeaf == 0) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  DEBUG ((EFI_D_INFO, "Xen was detected\n"));\r
-\r
-  XenConnect (XenLeaf);\r
+  XenConnect (mXenLeaf);\r
 \r
   //\r
   // Reserve away HVMLOADER reserved memory [0xFC000000,0xFD000000).\r
   // This needs to match HVMLOADER RESERVED_MEMBASE/RESERVED_MEMSIZE.\r
   //\r
-  AddReservedMemoryBaseSizeHob (0xFC000000, 0x1000000);\r
+  AddReservedMemoryBaseSizeHob (0xFC000000, 0x1000000, FALSE);\r
+\r
+  PcdStatus = PcdSetBoolS (PcdPciDisableBusEnumeration, TRUE);\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
 \r
   return EFI_SUCCESS;\r
 }\r