VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/OvmfPkg/PlatformPei/Xen.c@ 51572

Last change on this file since 51572 was 48674, checked in by vboxsync, 12 years ago

EFI: Export newly imported tinaocore UEFI sources to OSE.

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1/**@file
2 Xen Platform PEI support
3
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2011, Andrei Warkentin <[email protected]>
6
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
11
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.
14
15**/
16
17//
18// The package level header files this module uses
19//
20#include <PiPei.h>
21
22//
23// The Library classes this module consumes
24//
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
31#include "Platform.h"
32
33EFI_XEN_INFO mXenInfo;
34
35
36/**
37 Connects to the Hypervisor.
38
39 @param XenLeaf CPUID index used to connect.
40
41 @return EFI_STATUS
42
43**/
44EFI_STATUS
45XenConnect (
46 UINT32 XenLeaf
47 )
48{
49 UINT32 Index;
50 UINT32 TransferReg;
51 UINT32 TransferPages;
52 UINT32 XenVersion;
53
54 AsmCpuid (XenLeaf + 2, &TransferPages, &TransferReg, NULL, NULL);
55 mXenInfo.HyperPages = AllocatePages (TransferPages);
56 if (!mXenInfo.HyperPages) {
57 return EFI_OUT_OF_RESOURCES;
58 }
59
60 for (Index = 0; Index < TransferPages; Index++) {
61 AsmWriteMsr64 (TransferReg,
62 (UINTN) mXenInfo.HyperPages +
63 (Index << EFI_PAGE_SHIFT) + Index);
64 }
65
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);
71
72 /* TBD: Locate hvm_info and reserve it away. */
73 mXenInfo.HvmInfo = NULL;
74
75 BuildGuidDataHob (
76 &gEfiXenInfoGuid,
77 &mXenInfo,
78 sizeof(mXenInfo)
79 );
80
81 return EFI_SUCCESS;
82}
83
84/**
85 Figures out if we are running inside Xen HVM.
86
87 @return UINT32 CPUID index used to connect to HV.
88
89**/
90UINT32
91XenDetect (
92 VOID
93 )
94{
95
96 UINT32 XenLeaf;
97 UINT8 Signature[13];
98
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';
104
105 if (!AsciiStrCmp ((CHAR8 *) Signature, "XenVMMXenVMM")) {
106 return XenLeaf;
107 }
108 }
109
110 return 0;
111}
112
113/**
114 Perform Xen PEI initialization.
115
116 @return EFI_SUCCESS Xen initialized successfully
117 @return EFI_NOT_FOUND Not running under Xen
118
119**/
120EFI_STATUS
121InitializeXen (
122 VOID
123 )
124{
125 UINT32 XenLeaf;
126
127 XenLeaf = XenDetect ();
128
129 if (XenLeaf == 0) {
130 return EFI_NOT_FOUND;
131 }
132
133 DEBUG ((EFI_D_INFO, "Xen was detected\n"));
134
135 XenConnect (XenLeaf);
136
137 //
138 // Reserve away HVMLOADER reserved memory [0xFC000000,0xFD000000).
139 // This needs to match HVMLOADER RESERVED_MEMBASE/RESERVED_MEMSIZE.
140 //
141 AddReservedMemoryBaseSizeHob (0xFC000000, 0x1000000);
142
143 return EFI_SUCCESS;
144}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette