TianoCore EDK2 master
Loading...
Searching...
No Matches
X86XenHypercall.c
Go to the documentation of this file.
1
9#include <PiDxe.h>
10#include <Library/BaseLib.h>
11#include <Library/DebugLib.h>
12#include <Library/CpuLib.h>
13
14static INTN mUseVmmCall = -1;
15static BOOLEAN mHypercallAvail;
16
17//
18// Interface exposed by the ASM implementation of the core hypercall
19//
20INTN
21EFIAPI
22__XenVmmcall2 (
23 IN INTN HypercallNum,
24 IN OUT INTN Arg1,
25 IN OUT INTN Arg2
26 );
27
28INTN
29EFIAPI
30__XenVmcall2 (
31 IN INTN HypercallNum,
32 IN OUT INTN Arg1,
33 IN OUT INTN Arg2
34 );
35
46BOOLEAN
47EFIAPI
49 VOID
50 )
51{
52 return mHypercallAvail;
53}
54
56UINT32
57XenCpuidLeaf (
58 VOID
59 )
60{
61 UINT8 Signature[13];
62 UINT32 XenLeaf;
63
64 Signature[12] = '\0';
65 for (XenLeaf = 0x40000000; XenLeaf < 0x40010000; XenLeaf += 0x100) {
66 AsmCpuid (
67 XenLeaf,
68 NULL,
69 (UINT32 *)&Signature[0],
70 (UINT32 *)&Signature[4],
71 (UINT32 *)&Signature[8]
72 );
73
74 if (!AsciiStrCmp ((CHAR8 *)Signature, "XenVMMXenVMM")) {
75 return XenLeaf;
76 }
77 }
78
79 return 0;
80}
81
85RETURN_STATUS
86EFIAPI
88 VOID
89 )
90{
91 UINT32 XenLeaf;
92 CHAR8 sig[13];
93
94 XenLeaf = XenCpuidLeaf ();
95 if (XenLeaf == 0) {
96 return RETURN_NOT_FOUND;
97 }
98
99 sig[12] = '\0';
100 AsmCpuid (
101 0,
102 NULL,
103 (UINT32 *)&sig[0],
104 (UINT32 *)&sig[8],
105 (UINT32 *)&sig[4]
106 );
107
108 DEBUG ((DEBUG_INFO, "Detected CPU \"%12a\"\n", sig));
109
110 if ((AsciiStrCmp ("AuthenticAMD", sig) == 0) ||
111 (AsciiStrCmp ("HygonGenuine", sig) == 0))
112 {
113 mUseVmmCall = TRUE;
114 } else if ((AsciiStrCmp ("GenuineIntel", sig) == 0) ||
115 (AsciiStrCmp ("CentaurHauls", sig) == 0) ||
116 (AsciiStrCmp (" Shanghai ", sig) == 0))
117 {
118 mUseVmmCall = FALSE;
119 } else {
120 DEBUG ((DEBUG_ERROR, "Unsupported CPU vendor\n"));
121 return RETURN_NOT_FOUND;
122 }
123
124 mHypercallAvail = TRUE;
125
126 return RETURN_SUCCESS;
127}
128
139INTN
140EFIAPI
142 IN UINTN HypercallID,
143 IN OUT INTN Arg1,
144 IN OUT INTN Arg2
145 )
146{
147 if (mUseVmmCall) {
148 return __XenVmmcall2 (HypercallID, Arg1, Arg2);
149 } else {
150 return __XenVmcall2 (HypercallID, Arg1, Arg2);
151 }
152}
UINT64 UINTN
INT64 INTN
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
Definition: String.c:716
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define RETURN_NOT_FOUND
Definition: Base.h:1142
#define RETURN_SUCCESS
Definition: Base.h:1066
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINT32 EFIAPI AsmCpuid(IN UINT32 Index, OUT UINT32 *RegisterEax OPTIONAL, OUT UINT32 *RegisterEbx OPTIONAL, OUT UINT32 *RegisterEcx OPTIONAL, OUT UINT32 *RegisterEdx OPTIONAL)
Definition: CpuId.c:36
RETURN_STATUS EFIAPI XenHypercallLibInit(VOID)
BOOLEAN EFIAPI XenHypercallIsAvailable(VOID)
INTN EFIAPI XenHypercall2(IN UINTN HypercallID, IN OUT INTN Arg1, IN OUT INTN Arg2)