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