1 | /** @file
|
---|
2 | * HWACCM - Intel/AMD VM Hardware Support Manager
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | *
|
---|
25 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
26 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
27 | * additional information or have any questions.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef ___VBox_hwaccm_h
|
---|
31 | #define ___VBox_hwaccm_h
|
---|
32 |
|
---|
33 | #include <VBox/cdefs.h>
|
---|
34 | #include <VBox/types.h>
|
---|
35 | #include <VBox/pgm.h>
|
---|
36 | #include <iprt/mp.h>
|
---|
37 |
|
---|
38 |
|
---|
39 | /** @defgroup grp_hwaccm The VM Hardware Manager API
|
---|
40 | * @{
|
---|
41 | */
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * HWACCM state
|
---|
45 | */
|
---|
46 | typedef enum HWACCMSTATE
|
---|
47 | {
|
---|
48 | /* Not yet set */
|
---|
49 | HWACCMSTATE_UNINITIALIZED = 0,
|
---|
50 | /* Enabled */
|
---|
51 | HWACCMSTATE_ENABLED,
|
---|
52 | /* Disabled */
|
---|
53 | HWACCMSTATE_DISABLED,
|
---|
54 | /** The usual 32-bit hack. */
|
---|
55 | HWACCMSTATE_32BIT_HACK = 0x7fffffff
|
---|
56 | } HWACCMSTATE;
|
---|
57 |
|
---|
58 | __BEGIN_DECLS
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Query HWACCM state (enabled/disabled)
|
---|
62 | *
|
---|
63 | * @returns 0 - disabled, 1 - enabled
|
---|
64 | * @param pVM The VM to operate on.
|
---|
65 | */
|
---|
66 | #define HWACCMIsEnabled(a) (a->fHWACCMEnabled)
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Invalidates a guest page
|
---|
70 | *
|
---|
71 | * @returns VBox status code.
|
---|
72 | * @param pVM The VM to operate on.
|
---|
73 | * @param GCVirt Page to invalidate
|
---|
74 | */
|
---|
75 | HWACCMDECL(int) HWACCMInvalidatePage(PVM pVM, RTGCPTR GCVirt);
|
---|
76 |
|
---|
77 | #ifndef IN_GC
|
---|
78 | /**
|
---|
79 | * Flushes the guest TLB
|
---|
80 | *
|
---|
81 | * @returns VBox status code.
|
---|
82 | * @param pVM The VM to operate on.
|
---|
83 | */
|
---|
84 | HWACCMDECL(int) HWACCMFlushTLB(PVM pVM);
|
---|
85 | #else
|
---|
86 | /* Nop in GC */
|
---|
87 | #define HWACCMFlushTLB(pVM) do { } while (0)
|
---|
88 | #endif
|
---|
89 |
|
---|
90 | #ifdef IN_RING0
|
---|
91 | /** @defgroup grp_hwaccm_r0 The VM Hardware Manager API
|
---|
92 | * @ingroup grp_hwaccm
|
---|
93 | * @{
|
---|
94 | */
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Does global Ring-0 HWACCM initialization.
|
---|
98 | *
|
---|
99 | * @returns VBox status code.
|
---|
100 | */
|
---|
101 | HWACCMR0DECL(int) HWACCMR0Init();
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Does global Ring-0 HWACCM termination.
|
---|
105 | *
|
---|
106 | * @returns VBox status code.
|
---|
107 | */
|
---|
108 | HWACCMR0DECL(int) HWACCMR0Term();
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Does Ring-0 per VM HWACCM initialization.
|
---|
112 | *
|
---|
113 | * This is mainly to check that the Host CPU mode is compatible
|
---|
114 | * with VMX or SVM.
|
---|
115 | *
|
---|
116 | * @returns VBox status code.
|
---|
117 | * @param pVM The VM to operate on.
|
---|
118 | */
|
---|
119 | HWACCMR0DECL(int) HWACCMR0InitVM(PVM pVM);
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Does Ring-0 per VM HWACCM termination.
|
---|
123 | *
|
---|
124 | * @returns VBox status code.
|
---|
125 | * @param pVM The VM to operate on.
|
---|
126 | */
|
---|
127 | HWACCMR0DECL(int) HWACCMR0TermVM(PVM pVM);
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Sets up HWACCM on all cpus.
|
---|
131 | *
|
---|
132 | * @returns VBox status code.
|
---|
133 | * @param pVM The VM to operate on.
|
---|
134 | * @param enmNewHwAccmState New hwaccm state
|
---|
135 | *
|
---|
136 | */
|
---|
137 | HWACCMR0DECL(int) HWACCMR0EnableAllCpus(PVM pVM, HWACCMSTATE enmNewHwAccmState);
|
---|
138 |
|
---|
139 | /** @} */
|
---|
140 | #endif
|
---|
141 |
|
---|
142 |
|
---|
143 | #ifdef IN_RING3
|
---|
144 | /** @defgroup grp_hwaccm_r3 The VM Hardware Manager API
|
---|
145 | * @ingroup grp_hwaccm
|
---|
146 | * @{
|
---|
147 | */
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * Checks if internal events are pending
|
---|
151 | *
|
---|
152 | * @returns boolean
|
---|
153 | * @param pVM The VM to operate on.
|
---|
154 | */
|
---|
155 | HWACCMR3DECL(bool) HWACCMR3IsEventPending(PVM pVM);
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * Initializes the HWACCM.
|
---|
159 | *
|
---|
160 | * @returns VBox status code.
|
---|
161 | * @param pVM The VM to operate on.
|
---|
162 | */
|
---|
163 | HWACCMR3DECL(int) HWACCMR3Init(PVM pVM);
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Initialize VT-x or AMD-V
|
---|
167 | *
|
---|
168 | * @returns VBox status code.
|
---|
169 | * @param pVM The VM handle.
|
---|
170 | */
|
---|
171 | HWACCMR3DECL(int) HWACCMR3InitFinalizeR0(PVM pVM);
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * Applies relocations to data and code managed by this
|
---|
175 | * component. This function will be called at init and
|
---|
176 | * whenever the VMM need to relocate it self inside the GC.
|
---|
177 | *
|
---|
178 | * The HWACCM will update the addresses used by the switcher.
|
---|
179 | *
|
---|
180 | * @param pVM The VM.
|
---|
181 | */
|
---|
182 | HWACCMR3DECL(void) HWACCMR3Relocate(PVM pVM);
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Terminates the VMXM.
|
---|
186 | *
|
---|
187 | * Termination means cleaning up and freeing all resources,
|
---|
188 | * the VM it self is at this point powered off or suspended.
|
---|
189 | *
|
---|
190 | * @returns VBox status code.
|
---|
191 | * @param pVM The VM to operate on.
|
---|
192 | */
|
---|
193 | HWACCMR3DECL(int) HWACCMR3Term(PVM pVM);
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * VMXM reset callback.
|
---|
197 | *
|
---|
198 | * @param pVM The VM which is reset.
|
---|
199 | */
|
---|
200 | HWACCMR3DECL(void) HWACCMR3Reset(PVM pVM);
|
---|
201 |
|
---|
202 |
|
---|
203 | /**
|
---|
204 | * Checks if we can currently use hardware accelerated raw mode.
|
---|
205 | *
|
---|
206 | * @returns boolean
|
---|
207 | * @param pVM The VM to operate on.
|
---|
208 | * @param pCtx Partial VM execution context
|
---|
209 | */
|
---|
210 | HWACCMR3DECL(bool) HWACCMR3CanExecuteGuest(PVM pVM, PCPUMCTX pCtx);
|
---|
211 |
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * Checks if we are currently using hardware accelerated raw mode.
|
---|
215 | *
|
---|
216 | * @returns boolean
|
---|
217 | * @param pVM The VM to operate on.
|
---|
218 | */
|
---|
219 | HWACCMR3DECL(bool) HWACCMR3IsActive(PVM pVM);
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Checks hardware accelerated raw mode is allowed.
|
---|
223 | *
|
---|
224 | * @returns boolean
|
---|
225 | * @param pVM The VM to operate on.
|
---|
226 | */
|
---|
227 | HWACCMR3DECL(bool) HWACCMR3IsAllowed(PVM pVM);
|
---|
228 |
|
---|
229 | /**
|
---|
230 | * Notification callback which is called whenever there is a chance that a CR3
|
---|
231 | * value might have changed.
|
---|
232 | * This is called by PGM.
|
---|
233 | *
|
---|
234 | * @param pVM The VM to operate on.
|
---|
235 | * @param enmShadowMode New paging mode.
|
---|
236 | */
|
---|
237 | HWACCMR3DECL(void) HWACCMR3PagingModeChanged(PVM pVM, PGMMODE enmShadowMode);
|
---|
238 |
|
---|
239 | /** @} */
|
---|
240 | #endif
|
---|
241 |
|
---|
242 | #ifdef IN_RING0
|
---|
243 | /** @addtogroup grp_hwaccm_r0
|
---|
244 | * @{
|
---|
245 | */
|
---|
246 |
|
---|
247 | /**
|
---|
248 | * Sets up a VT-x or AMD-V session
|
---|
249 | *
|
---|
250 | * @returns VBox status code.
|
---|
251 | * @param pVM The VM to operate on.
|
---|
252 | */
|
---|
253 | HWACCMR0DECL(int) HWACCMR0SetupVM(PVM pVM);
|
---|
254 |
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * Runs guest code in a VMX/SVM VM.
|
---|
258 | *
|
---|
259 | * @returns VBox status code.
|
---|
260 | * @param pVM The VM to operate on.
|
---|
261 | */
|
---|
262 | HWACCMR0DECL(int) HWACCMR0RunGuestCode(PVM pVM);
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * Enters the VT-x or AMD-V session
|
---|
266 | *
|
---|
267 | * @returns VBox status code.
|
---|
268 | * @param pVM The VM to operate on.
|
---|
269 | */
|
---|
270 | HWACCMR0DECL(int) HWACCMR0Enter(PVM pVM);
|
---|
271 |
|
---|
272 |
|
---|
273 | /**
|
---|
274 | * Leaves the VT-x or AMD-V session
|
---|
275 | *
|
---|
276 | * @returns VBox status code.
|
---|
277 | * @param pVM The VM to operate on.
|
---|
278 | */
|
---|
279 | HWACCMR0DECL(int) HWACCMR0Leave(PVM pVM);
|
---|
280 |
|
---|
281 | /**
|
---|
282 | * Invalidates a guest page
|
---|
283 | *
|
---|
284 | * @returns VBox status code.
|
---|
285 | * @param pVM The VM to operate on.
|
---|
286 | * @param GCVirt Page to invalidate
|
---|
287 | */
|
---|
288 | HWACCMR0DECL(int) HWACCMR0InvalidatePage(PVM pVM, RTGCPTR GCVirt);
|
---|
289 |
|
---|
290 | /**
|
---|
291 | * Flushes the guest TLB
|
---|
292 | *
|
---|
293 | * @returns VBox status code.
|
---|
294 | * @param pVM The VM to operate on.
|
---|
295 | */
|
---|
296 | HWACCMR0DECL(int) HWACCMR0FlushTLB(PVM pVM);
|
---|
297 |
|
---|
298 | /** @} */
|
---|
299 | #endif
|
---|
300 |
|
---|
301 |
|
---|
302 | /** @} */
|
---|
303 | __END_DECLS
|
---|
304 |
|
---|
305 |
|
---|
306 | #endif
|
---|
307 |
|
---|