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 | /**
|
---|
78 | * Checks if an interrupt event is currently pending.
|
---|
79 | *
|
---|
80 | * @returns Interrupt event pending state.
|
---|
81 | * @param pVM The VM to operate on.
|
---|
82 | */
|
---|
83 | HWACCMDECL(bool) HWACCMHasPendingIrq(PVM pVM);
|
---|
84 |
|
---|
85 | #ifndef IN_GC
|
---|
86 | /**
|
---|
87 | * Flushes the guest TLB
|
---|
88 | *
|
---|
89 | * @returns VBox status code.
|
---|
90 | * @param pVM The VM to operate on.
|
---|
91 | */
|
---|
92 | HWACCMDECL(int) HWACCMFlushTLB(PVM pVM);
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Invalidates a guest page by physical address
|
---|
96 | *
|
---|
97 | * NOTE: Assumes the current instruction references this physical page though a virtual address!!
|
---|
98 | *
|
---|
99 | * @returns VBox status code.
|
---|
100 | * @param pVM The VM to operate on.
|
---|
101 | * @param GCPhys Page to invalidate
|
---|
102 | */
|
---|
103 | HWACCMDECL(int) HWACCMInvalidatePhysPage(PVM pVM, RTGCPHYS GCPhys);
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Checks if nested paging is enabled
|
---|
107 | *
|
---|
108 | * @returns boolean
|
---|
109 | * @param pVM The VM to operate on.
|
---|
110 | */
|
---|
111 | HWACCMDECL(bool) HWACCMIsNestedPagingActive(PVM pVM);
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Return the shadow paging mode for nested paging/ept
|
---|
115 | *
|
---|
116 | * @returns shadow paging mode
|
---|
117 | * @param pVM The VM to operate on.
|
---|
118 | */
|
---|
119 | HWACCMDECL(PGMMODE) HWACCMGetPagingMode(PVM pVM);
|
---|
120 |
|
---|
121 | #else
|
---|
122 | /* Nop in GC */
|
---|
123 | #define HWACCMFlushTLB(pVM) do { } while (0)
|
---|
124 | #define HWACCMIsNestedPagingActive(pVM) false
|
---|
125 | #endif
|
---|
126 |
|
---|
127 | #ifdef IN_RING0
|
---|
128 | /** @defgroup grp_hwaccm_r0 The VM Hardware Manager API
|
---|
129 | * @ingroup grp_hwaccm
|
---|
130 | * @{
|
---|
131 | */
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Does global Ring-0 HWACCM initialization.
|
---|
135 | *
|
---|
136 | * @returns VBox status code.
|
---|
137 | */
|
---|
138 | HWACCMR0DECL(int) HWACCMR0Init();
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Does global Ring-0 HWACCM termination.
|
---|
142 | *
|
---|
143 | * @returns VBox status code.
|
---|
144 | */
|
---|
145 | HWACCMR0DECL(int) HWACCMR0Term();
|
---|
146 |
|
---|
147 | /**
|
---|
148 | * Does Ring-0 per VM HWACCM initialization.
|
---|
149 | *
|
---|
150 | * This is mainly to check that the Host CPU mode is compatible
|
---|
151 | * with VMX or SVM.
|
---|
152 | *
|
---|
153 | * @returns VBox status code.
|
---|
154 | * @param pVM The VM to operate on.
|
---|
155 | */
|
---|
156 | HWACCMR0DECL(int) HWACCMR0InitVM(PVM pVM);
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * Does Ring-0 per VM HWACCM termination.
|
---|
160 | *
|
---|
161 | * @returns VBox status code.
|
---|
162 | * @param pVM The VM to operate on.
|
---|
163 | */
|
---|
164 | HWACCMR0DECL(int) HWACCMR0TermVM(PVM pVM);
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Sets up HWACCM on all cpus.
|
---|
168 | *
|
---|
169 | * @returns VBox status code.
|
---|
170 | * @param pVM The VM to operate on.
|
---|
171 | * @param enmNewHwAccmState New hwaccm state
|
---|
172 | *
|
---|
173 | */
|
---|
174 | HWACCMR0DECL(int) HWACCMR0EnableAllCpus(PVM pVM, HWACCMSTATE enmNewHwAccmState);
|
---|
175 |
|
---|
176 | /** @} */
|
---|
177 | #endif
|
---|
178 |
|
---|
179 |
|
---|
180 | #ifdef IN_RING3
|
---|
181 | /** @defgroup grp_hwaccm_r3 The VM Hardware Manager API
|
---|
182 | * @ingroup grp_hwaccm
|
---|
183 | * @{
|
---|
184 | */
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Checks if internal events are pending
|
---|
188 | *
|
---|
189 | * @returns boolean
|
---|
190 | * @param pVM The VM to operate on.
|
---|
191 | */
|
---|
192 | HWACCMR3DECL(bool) HWACCMR3IsEventPending(PVM pVM);
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Initializes the HWACCM.
|
---|
196 | *
|
---|
197 | * @returns VBox status code.
|
---|
198 | * @param pVM The VM to operate on.
|
---|
199 | */
|
---|
200 | HWACCMR3DECL(int) HWACCMR3Init(PVM pVM);
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Initialize VT-x or AMD-V
|
---|
204 | *
|
---|
205 | * @returns VBox status code.
|
---|
206 | * @param pVM The VM handle.
|
---|
207 | */
|
---|
208 | HWACCMR3DECL(int) HWACCMR3InitFinalizeR0(PVM pVM);
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * Applies relocations to data and code managed by this
|
---|
212 | * component. This function will be called at init and
|
---|
213 | * whenever the VMM need to relocate it self inside the GC.
|
---|
214 | *
|
---|
215 | * The HWACCM will update the addresses used by the switcher.
|
---|
216 | *
|
---|
217 | * @param pVM The VM.
|
---|
218 | */
|
---|
219 | HWACCMR3DECL(void) HWACCMR3Relocate(PVM pVM);
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Terminates the VMXM.
|
---|
223 | *
|
---|
224 | * Termination means cleaning up and freeing all resources,
|
---|
225 | * the VM it self is at this point powered off or suspended.
|
---|
226 | *
|
---|
227 | * @returns VBox status code.
|
---|
228 | * @param pVM The VM to operate on.
|
---|
229 | */
|
---|
230 | HWACCMR3DECL(int) HWACCMR3Term(PVM pVM);
|
---|
231 |
|
---|
232 | /**
|
---|
233 | * VMXM reset callback.
|
---|
234 | *
|
---|
235 | * @param pVM The VM which is reset.
|
---|
236 | */
|
---|
237 | HWACCMR3DECL(void) HWACCMR3Reset(PVM pVM);
|
---|
238 |
|
---|
239 |
|
---|
240 | /**
|
---|
241 | * Checks if we can currently use hardware accelerated raw mode.
|
---|
242 | *
|
---|
243 | * @returns boolean
|
---|
244 | * @param pVM The VM to operate on.
|
---|
245 | * @param pCtx Partial VM execution context
|
---|
246 | */
|
---|
247 | HWACCMR3DECL(bool) HWACCMR3CanExecuteGuest(PVM pVM, PCPUMCTX pCtx);
|
---|
248 |
|
---|
249 |
|
---|
250 | /**
|
---|
251 | * Checks if we are currently using hardware accelerated raw mode.
|
---|
252 | *
|
---|
253 | * @returns boolean
|
---|
254 | * @param pVM The VM to operate on.
|
---|
255 | */
|
---|
256 | HWACCMR3DECL(bool) HWACCMR3IsActive(PVM pVM);
|
---|
257 |
|
---|
258 | /**
|
---|
259 | * Checks if we are currently using nested paging.
|
---|
260 | *
|
---|
261 | * @returns boolean
|
---|
262 | * @param pVM The VM to operate on.
|
---|
263 | */
|
---|
264 | HWACCMR3DECL(bool) HWACCMR3IsNestedPagingActive(PVM pVM);
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * Checks hardware accelerated raw mode is allowed.
|
---|
268 | *
|
---|
269 | * @returns boolean
|
---|
270 | * @param pVM The VM to operate on.
|
---|
271 | */
|
---|
272 | HWACCMR3DECL(bool) HWACCMR3IsAllowed(PVM pVM);
|
---|
273 |
|
---|
274 | /**
|
---|
275 | * Notification callback which is called whenever there is a chance that a CR3
|
---|
276 | * value might have changed.
|
---|
277 | * This is called by PGM.
|
---|
278 | *
|
---|
279 | * @param pVM The VM to operate on.
|
---|
280 | * @param enmShadowMode New paging mode.
|
---|
281 | */
|
---|
282 | HWACCMR3DECL(void) HWACCMR3PagingModeChanged(PVM pVM, PGMMODE enmShadowMode);
|
---|
283 |
|
---|
284 | /** @} */
|
---|
285 | #endif
|
---|
286 |
|
---|
287 | #ifdef IN_RING0
|
---|
288 | /** @addtogroup grp_hwaccm_r0
|
---|
289 | * @{
|
---|
290 | */
|
---|
291 |
|
---|
292 | /**
|
---|
293 | * Sets up a VT-x or AMD-V session
|
---|
294 | *
|
---|
295 | * @returns VBox status code.
|
---|
296 | * @param pVM The VM to operate on.
|
---|
297 | */
|
---|
298 | HWACCMR0DECL(int) HWACCMR0SetupVM(PVM pVM);
|
---|
299 |
|
---|
300 |
|
---|
301 | /**
|
---|
302 | * Runs guest code in a VMX/SVM VM.
|
---|
303 | *
|
---|
304 | * @returns VBox status code.
|
---|
305 | * @param pVM The VM to operate on.
|
---|
306 | */
|
---|
307 | HWACCMR0DECL(int) HWACCMR0RunGuestCode(PVM pVM);
|
---|
308 |
|
---|
309 | /**
|
---|
310 | * Enters the VT-x or AMD-V session
|
---|
311 | *
|
---|
312 | * @returns VBox status code.
|
---|
313 | * @param pVM The VM to operate on.
|
---|
314 | */
|
---|
315 | HWACCMR0DECL(int) HWACCMR0Enter(PVM pVM);
|
---|
316 |
|
---|
317 |
|
---|
318 | /**
|
---|
319 | * Leaves the VT-x or AMD-V session
|
---|
320 | *
|
---|
321 | * @returns VBox status code.
|
---|
322 | * @param pVM The VM to operate on.
|
---|
323 | */
|
---|
324 | HWACCMR0DECL(int) HWACCMR0Leave(PVM pVM);
|
---|
325 |
|
---|
326 | /**
|
---|
327 | * Invalidates a guest page
|
---|
328 | *
|
---|
329 | * @returns VBox status code.
|
---|
330 | * @param pVM The VM to operate on.
|
---|
331 | * @param GCVirt Page to invalidate
|
---|
332 | */
|
---|
333 | HWACCMR0DECL(int) HWACCMR0InvalidatePage(PVM pVM, RTGCPTR GCVirt);
|
---|
334 |
|
---|
335 | /**
|
---|
336 | * Flushes the guest TLB
|
---|
337 | *
|
---|
338 | * @returns VBox status code.
|
---|
339 | * @param pVM The VM to operate on.
|
---|
340 | */
|
---|
341 | HWACCMR0DECL(int) HWACCMR0FlushTLB(PVM pVM);
|
---|
342 |
|
---|
343 | /** @} */
|
---|
344 | #endif
|
---|
345 |
|
---|
346 |
|
---|
347 | /** @} */
|
---|
348 | __END_DECLS
|
---|
349 |
|
---|
350 |
|
---|
351 | #endif
|
---|
352 |
|
---|