]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/PlatformPei: Add Xen support
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 5 Aug 2011 15:43:05 +0000 (15:43 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 5 Aug 2011 15:43:05 +0000 (15:43 +0000)
* Make PlatformPei aware of Xen
* Fix assigned PIO and MMIO ranges to be compatible with Xen
* Reserve Xen HVM address range
* Publish XenInfo HOB
* Don't program PIIX4 PMBA for Xen

Signed-off-by: Andrei Warkentin <andreiw@motorola.com>
Reviewed-by: gavinguan
Signed-off-by: jljusten
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12091 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/PlatformPei/Platform.c
OvmfPkg/PlatformPei/Platform.h
OvmfPkg/PlatformPei/PlatformPei.inf
OvmfPkg/PlatformPei/Xen.c [new file with mode: 0644]

index 5479b76f4ad37d8fc9c445d5b95e3ae865c32702..d395bc191ad1db81e9db55701a1d8f1eaa92ac0d 100644 (file)
@@ -1,7 +1,9 @@
 /**@file\r
   Platform PEI driver\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>\r
+\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -73,6 +75,22 @@ AddIoMemoryBaseSizeHob (
     );\r
 }\r
 \r
+VOID\r
+AddReservedMemoryBaseSizeHob (\r
+  EFI_PHYSICAL_ADDRESS        MemoryBase,\r
+  UINT64                      MemorySize\r
+  )\r
+{\r
+  BuildResourceDescriptorHob (\r
+    EFI_RESOURCE_MEMORY_RESERVED,\r
+      EFI_RESOURCE_ATTRIBUTE_PRESENT     |\r
+      EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
+      EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
+      EFI_RESOURCE_ATTRIBUTE_TESTED,\r
+    MemoryBase,\r
+    MemorySize\r
+    );\r
+}\r
 \r
 VOID\r
 AddIoMemoryRangeHob (\r
@@ -164,19 +182,19 @@ MemMapInitialization (
   //\r
   BuildResourceDescriptorHob (\r
     EFI_RESOURCE_IO,\r
-      EFI_RESOURCE_ATTRIBUTE_PRESENT     |\r
-      EFI_RESOURCE_ATTRIBUTE_INITIALIZED,\r
-    0x1000,\r
-    0xF000\r
+    EFI_RESOURCE_ATTRIBUTE_PRESENT     |\r
+    EFI_RESOURCE_ATTRIBUTE_INITIALIZED,\r
+    0xC000,\r
+    0x4000\r
     );\r
 \r
   //\r
   // Add PCI MMIO space available to PCI resource allocations\r
   //\r
   if (TopOfMemory < BASE_2GB) {\r
-    AddIoMemoryBaseSizeHob (BASE_2GB, 0xFEC00000 - BASE_2GB);\r
+    AddIoMemoryBaseSizeHob (BASE_2GB, 0xFC000000 - BASE_2GB);\r
   } else {\r
-    AddIoMemoryBaseSizeHob (TopOfMemory, 0xFEC00000 - TopOfMemory);\r
+    AddIoMemoryBaseSizeHob (TopOfMemory, 0xFC000000 - TopOfMemory);\r
   }\r
 \r
   //\r
@@ -198,6 +216,7 @@ MemMapInitialization (
 \r
 VOID\r
 MiscInitialization (\r
+  BOOLEAN Xen\r
   )\r
 {\r
   //\r
@@ -210,10 +229,12 @@ MiscInitialization (
   //\r
   BuildCpuHob (36, 16);\r
 \r
-  //\r
-  // Set the PM I/O base address to 0x400\r
-  //\r
-  PciAndThenOr32 (PCI_LIB_ADDRESS (0, 1, 3, 0x40), (UINT32) ~0xfc0, 0x400);\r
+  if (!Xen) {\r
+    //\r
+    // Set the PM I/O base address to 0x400\r
+    //\r
+    PciAndThenOr32 (PCI_LIB_ADDRESS (0, 1, 3, 0x40), (UINT32) ~0xfc0, 0x400);\r
+  }\r
 }\r
 \r
 \r
@@ -294,7 +315,9 @@ InitializePlatform (
   IN CONST EFI_PEI_SERVICES     **PeiServices\r
   )\r
 {\r
+  EFI_STATUS            Status;\r
   EFI_PHYSICAL_ADDRESS  TopOfMemory;\r
+  BOOLEAN               Xen;\r
 \r
   DEBUG ((EFI_D_ERROR, "Platform PEIM Loaded\n"));\r
 \r
@@ -302,13 +325,16 @@ InitializePlatform (
 \r
   TopOfMemory = MemDetect ();\r
 \r
+  Status = InitializeXen ();\r
+  Xen = EFI_ERROR (Status) ? FALSE : TRUE;\r
+\r
   ReserveEmuVariableNvStore ();\r
 \r
   PeiFvInitialization ();\r
 \r
   MemMapInitialization (TopOfMemory);\r
 \r
-  MiscInitialization ();\r
+  MiscInitialization (Xen);\r
 \r
   BootModeInitialization ();\r
 \r
index 3e5dca2ce7002604fdde1bad691cb6f886377ac7..383e6a43646b0d1e79b81496f23ba35a184fb705 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Platform PEI module include file.\r
 \r
-  Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -45,6 +45,12 @@ AddUntestedMemoryBaseSizeHob (
   UINT64                      MemorySize\r
   );\r
 \r
+VOID\r
+AddReservedMemoryBaseSizeHob (\r
+  EFI_PHYSICAL_ADDRESS        MemoryBase,\r
+  UINT64                      MemorySize\r
+  );\r
+\r
 VOID\r
 AddUntestedMemoryRangeHob (\r
   EFI_PHYSICAL_ADDRESS        MemoryBase,\r
@@ -61,4 +67,9 @@ PeiFvInitialization (
   VOID\r
   );\r
 \r
+EFI_STATUS\r
+InitializeXen (\r
+  VOID\r
+  );\r
+\r
 #endif // _PLATFORM_PEI_H_INCLUDED_\r
index 2926553f5f71fad9609f3837d4a60d3b43aba343..3ef7f0d7ed060f7446bad558d2b47c861a8d5b64 100644 (file)
@@ -2,7 +2,7 @@
 #  Platform PEI driver\r
 #\r
 #  This module provides platform specific function to detect boot mode.\r
-#  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -33,6 +33,7 @@
   Fv.c\r
   MemDetect.c\r
   Platform.c\r
+  Xen.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
@@ -41,6 +42,7 @@
 \r
 [Guids]\r
   gEfiMemoryTypeInformationGuid\r
+  gEfiXenInfoGuid\r
 \r
 [LibraryClasses]\r
   DebugLib\r
diff --git a/OvmfPkg/PlatformPei/Xen.c b/OvmfPkg/PlatformPei/Xen.c
new file mode 100644 (file)
index 0000000..1bb6b50
--- /dev/null
@@ -0,0 +1,144 @@
+/**@file\r
+  Xen Platform PEI support\r
+\r
+  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Guid/XenInfo.h>\r
+\r
+#include "Platform.h"\r
+\r
+EFI_XEN_INFO mXenInfo;\r
+\r
+\r
+/**\r
+  Connects to the Hypervisor.\r
\r
+  @param  XenLeaf     CPUID index used to connect.\r
+\r
+  @return EFI_STATUS\r
+\r
+**/\r
+EFI_STATUS\r
+XenConnect (\r
+  UINT32 XenLeaf\r
+  )\r
+{\r
+  UINT32 Index;\r
+  UINT32 TransferReg;\r
+  UINT32 TransferPages;\r
+  UINT32 XenVersion;\r
+\r
+  AsmCpuid (XenLeaf + 2, &TransferPages, &TransferReg, NULL, NULL);\r
+  mXenInfo.HyperPages = AllocatePages (TransferPages);\r
+  if (!mXenInfo.HyperPages) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  for (Index = 0; Index < TransferPages; Index++) {\r
+    AsmWriteMsr64 (TransferReg,\r
+                   (UINTN) mXenInfo.HyperPages +\r
+                   (Index << EFI_PAGE_SHIFT) + Index);\r
+  }\r
+\r
+  AsmCpuid (XenLeaf + 1, &XenVersion, NULL, NULL, NULL);\r
+  DEBUG ((EFI_D_ERROR, "Detected Xen version %d.%d\n",\r
+          XenVersion >> 16, XenVersion & 0xFFFF));\r
+  mXenInfo.VersionMajor = XenVersion >> 16;\r
+  mXenInfo.VersionMinor = XenVersion & 0xFFFF;\r
+\r
+  /* TBD: Locate hvm_info and reserve it away. */\r
+  mXenInfo.HvmInfo = NULL;\r
+\r
+  BuildGuidDataHob (\r
+    &gEfiXenInfoGuid,\r
+    &mXenInfo,\r
+    sizeof(mXenInfo)\r
+    );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Figures out if we are running inside Xen HVM.\r
+\r
+  @return UINT32     CPUID index used to connect to HV.\r
+\r
+**/\r
+UINT32\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
+              (UINT32 *) &Signature[4],\r
+              (UINT32 *) &Signature[8]);\r
+    Signature[12] = '\0';\r
+\r
+    if (!AsciiStrCmp ((CHAR8 *) Signature, "XenVMMXenVMM")) {\r
+      return XenLeaf;\r
+    }\r
+  }\r
+\r
+  return 0;\r
+}\r
+\r
+/**\r
+  Perform Xen PEI initialization.\r
+\r
+  @return EFI_SUCCESS     Xen initialized successfully\r
+  @return EFI_NOT_FOUND   Not running under Xen\r
+\r
+**/\r
+EFI_STATUS\r
+InitializeXen (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 XenLeaf;\r
+\r
+  XenLeaf = XenDetect ();\r
+\r
+  if (XenLeaf == 0) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, "Xen was detected\n"));\r
+\r
+  XenConnect (XenLeaf);\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
+\r
+  return EFI_SUCCESS;\r
+}\r