]>
git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/PlatformPei/Xen.c
2 Xen Platform PEI support
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 // The package level header files this module uses
23 // The Library classes this module consumes
25 #include <Library/DebugLib.h>
26 #include <Library/HobLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/PcdLib.h>
29 #include <Guid/XenInfo.h>
33 EFI_XEN_INFO mXenInfo
;
37 Connects to the Hypervisor.
39 @param XenLeaf CPUID index used to connect.
54 AsmCpuid (XenLeaf
+ 2, &TransferPages
, &TransferReg
, NULL
, NULL
);
55 mXenInfo
.HyperPages
= AllocatePages (TransferPages
);
56 if (!mXenInfo
.HyperPages
) {
57 return EFI_OUT_OF_RESOURCES
;
60 for (Index
= 0; Index
< TransferPages
; Index
++) {
61 AsmWriteMsr64 (TransferReg
,
62 (UINTN
) mXenInfo
.HyperPages
+
63 (Index
<< EFI_PAGE_SHIFT
) + Index
);
66 AsmCpuid (XenLeaf
+ 1, &XenVersion
, NULL
, NULL
, NULL
);
67 DEBUG ((EFI_D_ERROR
, "Detected Xen version %d.%d\n",
68 XenVersion
>> 16, XenVersion
& 0xFFFF));
69 mXenInfo
.VersionMajor
= (UINT16
)(XenVersion
>> 16);
70 mXenInfo
.VersionMinor
= (UINT16
)(XenVersion
& 0xFFFF);
72 /* TBD: Locate hvm_info and reserve it away. */
73 mXenInfo
.HvmInfo
= NULL
;
85 Figures out if we are running inside Xen HVM.
87 @return UINT32 CPUID index used to connect to HV.
99 for (XenLeaf
= 0x40000000; XenLeaf
< 0x40010000; XenLeaf
+= 0x100) {
100 AsmCpuid (XenLeaf
, NULL
, (UINT32
*) &Signature
[0],
101 (UINT32
*) &Signature
[4],
102 (UINT32
*) &Signature
[8]);
103 Signature
[12] = '\0';
105 if (!AsciiStrCmp ((CHAR8
*) Signature
, "XenVMMXenVMM")) {
114 Perform Xen PEI initialization.
116 @return EFI_SUCCESS Xen initialized successfully
117 @return EFI_NOT_FOUND Not running under Xen
127 XenLeaf
= XenDetect ();
130 return EFI_NOT_FOUND
;
133 DEBUG ((EFI_D_INFO
, "Xen was detected\n"));
135 XenConnect (XenLeaf
);
138 // Reserve away HVMLOADER reserved memory [0xFC000000,0xFD000000).
139 // This needs to match HVMLOADER RESERVED_MEMBASE/RESERVED_MEMSIZE.
141 AddReservedMemoryBaseSizeHob (0xFC000000, 0x1000000);