VirtualBox

source: vbox/trunk/src/VBox/VMM/HWACCMInternal.h@ 9566

Last change on this file since 9566 was 9457, checked in by vboxsync, 16 years ago

Reapplied fixed 31707.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 14.9 KB
Line 
1/* $Id: HWACCMInternal.h 9457 2008-06-06 09:46:39Z vboxsync $ */
2/** @file
3 * HWACCM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef ___HWACCMInternal_h
23#define ___HWACCMInternal_h
24
25#include <VBox/cdefs.h>
26#include <VBox/types.h>
27#include <VBox/em.h>
28#include <VBox/stam.h>
29#include <VBox/dis.h>
30#include <VBox/hwaccm.h>
31#include <VBox/pgm.h>
32#include <iprt/memobj.h>
33#include <iprt/cpuset.h>
34#include <iprt/mp.h>
35
36/* Uncomment to enable experimental nested paging. */
37//#define VBOX_WITH_NESTED_PAGING
38/* Uncomment to enable 64 bits guest support. */
39//#define VBOX_ENABLE_64_BITS_GUESTS
40
41__BEGIN_DECLS
42
43
44/** @defgroup grp_hwaccm_int Internal
45 * @ingroup grp_hwaccm
46 * @internal
47 * @{
48 */
49
50
51/**
52 * Converts a HWACCM pointer into a VM pointer.
53 * @returns Pointer to the VM structure the EM is part of.
54 * @param pHWACCM Pointer to HWACCM instance data.
55 */
56#define HWACCM2VM(pHWACCM) ( (PVM)((char*)pHWACCM - pHWACCM->offVM) )
57
58/** Maximum number of exit reason statistics counters. */
59#define MAX_EXITREASON_STAT 0x100
60#define MASK_EXITREASON_STAT 0xff
61
62/** @name Changed flags
63 * These flags are used to keep track of which important registers that
64 * have been changed since last they were reset.
65 * @{
66 */
67#define HWACCM_CHANGED_GUEST_FPU RT_BIT(0)
68#define HWACCM_CHANGED_GUEST_CR0 RT_BIT(1)
69#define HWACCM_CHANGED_GUEST_CR3 RT_BIT(2)
70#define HWACCM_CHANGED_GUEST_CR4 RT_BIT(3)
71#define HWACCM_CHANGED_GUEST_GDTR RT_BIT(4)
72#define HWACCM_CHANGED_GUEST_IDTR RT_BIT(5)
73#define HWACCM_CHANGED_GUEST_LDTR RT_BIT(6)
74#define HWACCM_CHANGED_GUEST_TR RT_BIT(7)
75#define HWACCM_CHANGED_GUEST_SYSENTER_MSR RT_BIT(8)
76#define HWACCM_CHANGED_GUEST_SEGMENT_REGS RT_BIT(9)
77#define HWACCM_CHANGED_GUEST_DEBUG RT_BIT(10)
78#define HWACCM_CHANGED_HOST_CONTEXT RT_BIT(11)
79
80#define HWACCM_CHANGED_ALL ( HWACCM_CHANGED_GUEST_SEGMENT_REGS \
81 | HWACCM_CHANGED_GUEST_CR0 \
82 | HWACCM_CHANGED_GUEST_CR3 \
83 | HWACCM_CHANGED_GUEST_CR4 \
84 | HWACCM_CHANGED_GUEST_GDTR \
85 | HWACCM_CHANGED_GUEST_IDTR \
86 | HWACCM_CHANGED_GUEST_LDTR \
87 | HWACCM_CHANGED_GUEST_TR \
88 | HWACCM_CHANGED_GUEST_SYSENTER_MSR \
89 | HWACCM_CHANGED_GUEST_FPU \
90 | HWACCM_CHANGED_GUEST_DEBUG \
91 | HWACCM_CHANGED_HOST_CONTEXT)
92
93#define HWACCM_CHANGED_ALL_GUEST ( HWACCM_CHANGED_GUEST_SEGMENT_REGS \
94 | HWACCM_CHANGED_GUEST_CR0 \
95 | HWACCM_CHANGED_GUEST_CR3 \
96 | HWACCM_CHANGED_GUEST_CR4 \
97 | HWACCM_CHANGED_GUEST_GDTR \
98 | HWACCM_CHANGED_GUEST_IDTR \
99 | HWACCM_CHANGED_GUEST_LDTR \
100 | HWACCM_CHANGED_GUEST_TR \
101 | HWACCM_CHANGED_GUEST_SYSENTER_MSR \
102 | HWACCM_CHANGED_GUEST_DEBUG \
103 | HWACCM_CHANGED_GUEST_FPU)
104
105/** @} */
106
107/** @name Intercepted traps
108 * Traps that need to be intercepted so we can correctly dispatch them to the guest if required.
109 * Currently #NM and #PF only
110 */
111#ifdef VBOX_STRICT
112#define HWACCM_VMX_TRAP_MASK RT_BIT(X86_XCPT_DE) | RT_BIT(X86_XCPT_NM) | RT_BIT(X86_XCPT_PF) | RT_BIT(X86_XCPT_UD) | RT_BIT(X86_XCPT_NP) | RT_BIT(X86_XCPT_SS) | RT_BIT(X86_XCPT_GP) | RT_BIT(X86_XCPT_MF)
113#define HWACCM_SVM_TRAP_MASK HWACCM_VMX_TRAP_MASK
114#else
115#define HWACCM_VMX_TRAP_MASK RT_BIT(X86_XCPT_NM) | RT_BIT(X86_XCPT_PF)
116#define HWACCM_SVM_TRAP_MASK HWACCM_VMX_TRAP_MASK
117#endif
118/** @} */
119
120
121/** Maxium resume loops allowed in ring 0 (safety precaution) */
122#define HWACCM_MAX_RESUME_LOOPS 1024
123
124/** HWACCM SSM version
125 */
126#define HWACCM_SSM_VERSION 3
127
128/* Per-cpu information. */
129typedef struct
130{
131 RTCPUID idCpu;
132
133 RTR0MEMOBJ pMemObj;
134 /* Current ASID (AMD-V only) */
135 uint32_t uCurrentASID;
136 /* TLB flush count */
137 uint32_t cTLBFlushes;
138
139 bool fConfigured;
140} HWACCM_CPUINFO;
141typedef HWACCM_CPUINFO *PHWACCM_CPUINFO;
142
143/**
144 * HWACCM VM Instance data.
145 * Changes to this must checked against the padding of the cfgm union in VM!
146 */
147typedef struct HWACCM
148{
149 /** Offset to the VM structure.
150 * See HWACCM2VM(). */
151 RTUINT offVM;
152
153 /** Set when we've initialized VMX or SVM. */
154 bool fInitialized;
155 /** Set when we're using VMX/SVN at that moment. */
156 bool fActive;
157
158 /** Set when hardware acceleration is allowed. */
159 bool fAllowed;
160
161 /** Set if nested paging is enabled. */
162 bool fNestedPaging;
163
164 /** HWACCM_CHANGED_* flags. */
165 uint32_t fContextUseFlags;
166
167 /** Old style FPU reporting trap mask override performed (optimization) */
168 uint32_t fFPUOldStyleOverride;
169
170 /** And mask for copying register contents. */
171 uint64_t u64RegisterMask;
172 struct
173 {
174 /** Set by the ring-0 driver to indicate VMX is supported by the CPU. */
175 bool fSupported;
176
177 /** Set when we've enabled VMX. */
178 bool fEnabled;
179
180 /** Set if we can use VMXResume to execute guest code. */
181 bool fResumeVM;
182
183 /** R0 memory object for the VM control structure (VMCS). */
184 RTR0MEMOBJ pMemObjVMCS;
185 /** Physical address of the VM control structure (VMCS). */
186 RTHCPHYS pVMCSPhys;
187 /** Virtual address of the VM control structure (VMCS). */
188 R0PTRTYPE(void *) pVMCS;
189
190 /** R0 memory object for the TSS page used for real mode emulation. */
191 RTR0MEMOBJ pMemObjRealModeTSS;
192 /** Physical address of the TSS page used for real mode emulation. */
193 RTHCPHYS pRealModeTSSPhys;
194 /** Virtual address of the TSS page used for real mode emulation. */
195 R0PTRTYPE(PVBOXTSS) pRealModeTSS;
196
197 /** Ring 0 handlers for VT-x. */
198 DECLR0CALLBACKMEMBER(int, pfnStartVM,(RTHCUINT fResume, PCPUMCTX pCtx));
199
200 /** Host CR4 value (set by ring-0 VMX init) */
201 uint64_t hostCR4;
202
203 /** Current VMX_VMCS_CTRL_PROC_EXEC_CONTROLS. */
204 uint64_t proc_ctls;
205
206 /** Current CR0 mask. */
207 uint64_t cr0_mask;
208 /** Current CR4 mask. */
209 uint64_t cr4_mask;
210
211 /** VMX MSR values */
212 struct
213 {
214 uint64_t feature_ctrl;
215 uint64_t vmx_basic_info;
216 uint64_t vmx_pin_ctls;
217 uint64_t vmx_proc_ctls;
218 uint64_t vmx_exit;
219 uint64_t vmx_entry;
220 uint64_t vmx_misc;
221 uint64_t vmx_cr0_fixed0;
222 uint64_t vmx_cr0_fixed1;
223 uint64_t vmx_cr4_fixed0;
224 uint64_t vmx_cr4_fixed1;
225 uint64_t vmx_vmcs_enum;
226 } msr;
227
228 /* Last instruction error */
229 uint32_t ulLastInstrError;
230 } vmx;
231
232 struct
233 {
234 /** Set by the ring-0 driver to indicate SVM is supported by the CPU. */
235 bool fSupported;
236 /** Set when we've enabled SVM. */
237 bool fEnabled;
238 /** Set if we don't have to flush the TLB on VM entry. */
239 bool fResumeVM;
240 /** Set if erratum 170 affects the AMD cpu. */
241 bool fAlwaysFlushTLB;
242 /** Set if we need to flush the TLB during the world switch. */
243 bool fForceTLBFlush;
244
245 /* Id of the last cpu we were executing code on (NIL_RTCPUID for the first time) */
246 RTCPUID idLastCpu;
247
248 /* TLB flush count */
249 uint32_t cTLBFlushes;
250
251 /** R0 memory object for the VM control block (VMCB). */
252 RTR0MEMOBJ pMemObjVMCB;
253 /** Physical address of the VM control block (VMCB). */
254 RTHCPHYS pVMCBPhys;
255 /** Virtual address of the VM control block (VMCB). */
256 R0PTRTYPE(void *) pVMCB;
257
258 /** R0 memory object for the host VM control block (VMCB). */
259 RTR0MEMOBJ pMemObjVMCBHost;
260 /** Physical address of the host VM control block (VMCB). */
261 RTHCPHYS pVMCBHostPhys;
262 /** Virtual address of the host VM control block (VMCB). */
263 R0PTRTYPE(void *) pVMCBHost;
264
265 /** R0 memory object for the IO bitmap (12kb). */
266 RTR0MEMOBJ pMemObjIOBitmap;
267 /** Physical address of the IO bitmap (12kb). */
268 RTHCPHYS pIOBitmapPhys;
269 /** Virtual address of the IO bitmap. */
270 R0PTRTYPE(void *) pIOBitmap;
271
272 /** R0 memory object for the MSR bitmap (8kb). */
273 RTR0MEMOBJ pMemObjMSRBitmap;
274 /** Physical address of the MSR bitmap (8kb). */
275 RTHCPHYS pMSRBitmapPhys;
276 /** Virtual address of the MSR bitmap. */
277 R0PTRTYPE(void *) pMSRBitmap;
278
279 /** SVM revision. */
280 uint32_t u32Rev;
281
282 /** Maximum ASID allowed. */
283 uint32_t u32MaxASID;
284
285 /** SVM feature bits from cpuid 0x8000000a */
286 uint32_t u32Features;
287 } svm;
288
289 struct
290 {
291 uint32_t u32AMDFeatureECX;
292 uint32_t u32AMDFeatureEDX;
293 } cpuid;
294
295 /* Event injection state. */
296 struct
297 {
298 uint32_t fPending;
299 uint32_t errCode;
300 uint64_t intInfo;
301 } Event;
302
303 /** Saved error from detection */
304 int32_t lLastError;
305
306 /** HWACCMR0Init was run */
307 bool fHWACCMR0Init;
308
309 /** Currenty shadow paging mode. */
310 PGMMODE enmShadowMode;
311
312 STAMPROFILEADV StatEntry;
313 STAMPROFILEADV StatExit;
314 STAMPROFILEADV StatInGC;
315
316 STAMCOUNTER StatIntInject;
317
318 STAMCOUNTER StatExitShadowNM;
319 STAMCOUNTER StatExitGuestNM;
320 STAMCOUNTER StatExitShadowPF;
321 STAMCOUNTER StatExitGuestPF;
322 STAMCOUNTER StatExitGuestUD;
323 STAMCOUNTER StatExitGuestSS;
324 STAMCOUNTER StatExitGuestNP;
325 STAMCOUNTER StatExitGuestGP;
326 STAMCOUNTER StatExitGuestDE;
327 STAMCOUNTER StatExitGuestMF;
328 STAMCOUNTER StatExitInvpg;
329 STAMCOUNTER StatExitInvd;
330 STAMCOUNTER StatExitCpuid;
331 STAMCOUNTER StatExitRdtsc;
332 STAMCOUNTER StatExitCRxWrite;
333 STAMCOUNTER StatExitCRxRead;
334 STAMCOUNTER StatExitDRxWrite;
335 STAMCOUNTER StatExitDRxRead;
336 STAMCOUNTER StatExitCLTS;
337 STAMCOUNTER StatExitLMSW;
338 STAMCOUNTER StatExitIOWrite;
339 STAMCOUNTER StatExitIORead;
340 STAMCOUNTER StatExitIOStringWrite;
341 STAMCOUNTER StatExitIOStringRead;
342 STAMCOUNTER StatExitIrqWindow;
343 STAMCOUNTER StatExitMaxResume;
344 STAMCOUNTER StatIntReinject;
345 STAMCOUNTER StatPendingHostIrq;
346
347 STAMCOUNTER StatFlushPageManual;
348 STAMCOUNTER StatFlushPhysPageManual;
349 STAMCOUNTER StatFlushTLBManual;
350 STAMCOUNTER StatFlushPageInvlpg;
351 STAMCOUNTER StatFlushTLBWorldSwitch;
352 STAMCOUNTER StatNoFlushTLBWorldSwitch;
353 STAMCOUNTER StatFlushTLBCRxChange;
354 STAMCOUNTER StatFlushASID;
355
356 STAMCOUNTER StatSwitchGuestIrq;
357 STAMCOUNTER StatSwitchToR3;
358
359 STAMCOUNTER StatTSCOffset;
360 STAMCOUNTER StatTSCIntercept;
361
362 STAMCOUNTER StatExitReasonNPF;
363 R3PTRTYPE(PSTAMCOUNTER) pStatExitReason;
364 R0PTRTYPE(PSTAMCOUNTER) pStatExitReasonR0;
365} HWACCM;
366/** Pointer to HWACCM VM instance data. */
367typedef HWACCM *PHWACCM;
368
369#ifdef IN_RING0
370
371#ifdef VBOX_STRICT
372HWACCMR0DECL(void) HWACCMDumpRegs(PCPUMCTX pCtx);
373HWACCMR0DECL(void) HWACCMR0DumpDescriptor(PX86DESCHC Desc, RTSEL Sel, const char *pszMsg);
374#else
375#define HWACCMDumpRegs(a) do { } while (0)
376#define HWACCMR0DumpDescriptor(a, b, c) do { } while (0)
377#endif
378
379/* Dummy callback handlers. */
380HWACCMR0DECL(int) HWACCMR0DummyEnter(PVM pVM, PHWACCM_CPUINFO pCpu);
381HWACCMR0DECL(int) HWACCMR0DummyLeave(PVM pVM);
382HWACCMR0DECL(int) HWACCMR0DummyEnableCpu(PHWACCM_CPUINFO pCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
383HWACCMR0DECL(int) HWACCMR0DummyDisableCpu(PHWACCM_CPUINFO pCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
384HWACCMR0DECL(int) HWACCMR0DummyInitVM(PVM pVM);
385HWACCMR0DECL(int) HWACCMR0DummyTermVM(PVM pVM);
386HWACCMR0DECL(int) HWACCMR0DummySetupVM(PVM pVM);
387HWACCMR0DECL(int) HWACCMR0DummyRunGuestCode(PVM pVM, CPUMCTX *pCtx, PHWACCM_CPUINFO pCpu);
388HWACCMR0DECL(int) HWACCMR0DummySaveHostState(PVM pVM);
389HWACCMR0DECL(int) HWACCMR0DummyLoadGuestState(PVM pVM, CPUMCTX *pCtx);
390
391#endif
392
393/** @} */
394
395__END_DECLS
396
397#endif
398
Note: See TracBrowser for help on using the repository browser.

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