2 Xen Platform PEI support
4 Copyright (c) 2006 - 2016, 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>
30 #include <IndustryStandard/E820.h>
31 #include <Library/ResourcePublicationLib.h>
32 #include <Library/MtrrLib.h>
39 STATIC UINT32 mXenLeaf
= 0;
41 EFI_XEN_INFO mXenInfo
;
44 Returns E820 map provided by Xen
46 @param Entries Pointer to E820 map
47 @param Count Number of entries
53 EFI_E820_ENTRY64
**Entries
,
57 EFI_XEN_OVMF_INFO
*Info
=
58 (EFI_XEN_OVMF_INFO
*)(UINTN
) OVMF_INFO_PHYSICAL_ADDRESS
;
60 if (AsciiStrCmp ((CHAR8
*) Info
->Signature
, "XenHVMOVMF")) {
64 ASSERT (Info
->E820
< MAX_ADDRESS
);
65 *Entries
= (EFI_E820_ENTRY64
*)(UINTN
) Info
->E820
;
66 *Count
= Info
->E820EntriesCount
;
72 Connects to the Hypervisor.
74 @param XenLeaf CPUID index used to connect.
89 AsmCpuid (XenLeaf
+ 2, &TransferPages
, &TransferReg
, NULL
, NULL
);
90 mXenInfo
.HyperPages
= AllocatePages (TransferPages
);
91 if (!mXenInfo
.HyperPages
) {
92 return EFI_OUT_OF_RESOURCES
;
95 for (Index
= 0; Index
< TransferPages
; Index
++) {
96 AsmWriteMsr64 (TransferReg
,
97 (UINTN
) mXenInfo
.HyperPages
+
98 (Index
<< EFI_PAGE_SHIFT
) + Index
);
101 AsmCpuid (XenLeaf
+ 1, &XenVersion
, NULL
, NULL
, NULL
);
102 DEBUG ((EFI_D_ERROR
, "Detected Xen version %d.%d\n",
103 XenVersion
>> 16, XenVersion
& 0xFFFF));
104 mXenInfo
.VersionMajor
= (UINT16
)(XenVersion
>> 16);
105 mXenInfo
.VersionMinor
= (UINT16
)(XenVersion
& 0xFFFF);
107 /* TBD: Locate hvm_info and reserve it away. */
108 mXenInfo
.HvmInfo
= NULL
;
120 Figures out if we are running inside Xen HVM.
122 @retval TRUE Xen was detected
123 @retval FALSE Xen was not detected
137 Signature
[12] = '\0';
138 for (mXenLeaf
= 0x40000000; mXenLeaf
< 0x40010000; mXenLeaf
+= 0x100) {
141 (UINT32
*) &Signature
[0],
142 (UINT32
*) &Signature
[4],
143 (UINT32
*) &Signature
[8]);
145 if (!AsciiStrCmp ((CHAR8
*) Signature
, "XenVMMXenVMM")) {
157 XenPublishRamRegions (
161 EFI_E820_ENTRY64
*E820Map
;
162 UINT32 E820EntriesCount
;
169 DEBUG ((EFI_D_INFO
, "Using memory map provided by Xen\n"));
172 // Parse RAM in E820 map
174 E820EntriesCount
= 0;
175 Status
= XenGetE820Map (&E820Map
, &E820EntriesCount
);
177 ASSERT_EFI_ERROR (Status
);
179 if (E820EntriesCount
> 0) {
180 EFI_E820_ENTRY64
*Entry
;
183 for (Loop
= 0; Loop
< E820EntriesCount
; Loop
++) {
184 Entry
= E820Map
+ Loop
;
187 // Only care about RAM
189 if (Entry
->Type
!= EfiAcpiAddressRangeMemory
) {
193 AddMemoryBaseSizeHob (Entry
->BaseAddr
, Entry
->Length
);
195 MtrrSetMemoryAttribute (Entry
->BaseAddr
, Entry
->Length
, CacheWriteBack
);
202 Perform Xen PEI initialization.
204 @return EFI_SUCCESS Xen initialized successfully
205 @return EFI_NOT_FOUND Not running under Xen
213 RETURN_STATUS PcdStatus
;
216 return EFI_NOT_FOUND
;
219 XenConnect (mXenLeaf
);
222 // Reserve away HVMLOADER reserved memory [0xFC000000,0xFD000000).
223 // This needs to match HVMLOADER RESERVED_MEMBASE/RESERVED_MEMSIZE.
225 AddReservedMemoryBaseSizeHob (0xFC000000, 0x1000000, FALSE
);
227 PcdStatus
= PcdSetBoolS (PcdPciDisableBusEnumeration
, TRUE
);
228 ASSERT_RETURN_ERROR (PcdStatus
);