VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c@ 109019

Last change on this file since 109019 was 108794, checked in by vboxsync, 4 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1/** @file
2 Xen Hypercall Library implementation for Intel architecture
3
4Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
5SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
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
36/**
37 Check if the Xen Hypercall library is able to make calls to the Xen
38 hypervisor.
39
40 Client code should call further functions in this library only if, and after,
41 this function returns TRUE.
42
43 @retval TRUE Hypercalls are available.
44 @retval FALSE Hypercalls are not available.
45**/
46BOOLEAN
47EFIAPI
48XenHypercallIsAvailable (
49 VOID
50 )
51{
52 return mHypercallAvail;
53}
54
55STATIC
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
82/**
83 Library constructor: Check for Xen leaf in CPUID
84**/
85RETURN_STATUS
86EFIAPI
87XenHypercallLibInit (
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
129/**
130 This function will put the two arguments in the right place (registers) and
131 invoke the hypercall identified by HypercallID.
132
133 @param HypercallID The symbolic ID of the hypercall to be invoked
134 @param Arg1 First argument.
135 @param Arg2 Second argument.
136
137 @return Return 0 if success otherwise it return an errno.
138**/
139INTN
140EFIAPI
141XenHypercall2 (
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}
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