VirtualBox

source: vbox/trunk/src/VBox/VMM/include/NEMInternal.h@ 71224

最後變更 在這個檔案從71224是 71224,由 vboxsync 提交於 7 年 前

NEM/w: Optimizations and build fixes for the other configurations. bugref:9044

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 11.2 KB
 
1/* $Id: NEMInternal.h 71224 2018-03-06 01:08:53Z vboxsync $ */
2/** @file
3 * NEM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2018 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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
18#ifndef ___NEMInternal_h
19#define ___NEMInternal_h
20
21#include <VBox/cdefs.h>
22#include <VBox/types.h>
23#include <VBox/vmm/nem.h>
24#include <VBox/vmm/cpum.h> /* For CPUMCPUVENDOR. */
25#include <VBox/vmm/stam.h>
26#include <VBox/vmm/vmapi.h>
27#ifdef RT_OS_WINDOWS
28#include <iprt/nt/hyperv.h>
29#endif
30
31RT_C_DECLS_BEGIN
32
33
34/** @defgroup grp_nem_int Internal
35 * @ingroup grp_nem
36 * @internal
37 * @{
38 */
39
40
41#ifdef RT_OS_WINDOWS
42/*
43 * Windows: Code configuration.
44 */
45# define NEM_WIN_USE_HYPERCALLS_FOR_PAGES
46# define NEM_WIN_USE_HYPERCALLS_FOR_REGISTERS
47# define NEM_WIN_USE_OUR_OWN_RUN_API
48# if defined(NEM_WIN_USE_OUR_OWN_RUN_API) && !defined(NEM_WIN_USE_HYPERCALLS_FOR_REGISTERS)
49# error "NEM_WIN_USE_OUR_OWN_RUN_API requires NEM_WIN_USE_HYPERCALLS_FOR_REGISTERS"
50# endif
51
52/**
53 * Windows VID I/O control information.
54 */
55typedef struct NEMWINIOCTL
56{
57 /** The I/O control function number. */
58 uint32_t uFunction;
59 uint32_t cbInput;
60 uint32_t cbOutput;
61} NEMWINIOCTL;
62
63/** @name Windows: Our two-bit physical page state for PGMPAGE
64 * @{ */
65# define NEM_WIN_PAGE_STATE_NOT_SET 0
66# define NEM_WIN_PAGE_STATE_UNMAPPED 1
67# define NEM_WIN_PAGE_STATE_READABLE 2
68# define NEM_WIN_PAGE_STATE_WRITABLE 3
69/** @} */
70
71/** Windows: Checks if a_GCPhys is subject to the limited A20 gate emulation. */
72# define NEM_WIN_IS_SUBJECT_TO_A20(a_GCPhys) ((RTGCPHYS)((a_GCPhys) - _1M) < (RTGCPHYS)_64K)
73/** Windows: Checks if a_GCPhys is relevant to the limited A20 gate emulation. */
74# define NEM_WIN_IS_RELEVANT_TO_A20(a_GCPhys) \
75 ( ((RTGCPHYS)((a_GCPhys) - _1M) < (RTGCPHYS)_64K) || ((RTGCPHYS)(a_GCPhys) < (RTGCPHYS)_64K) )
76
77/** The CPUMCTX_EXTRN_XXX mask for IEM. */
78# define NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM CPUMCTX_EXTRN_ALL
79
80#endif /* RT_OS_WINDOWS */
81
82
83/** Trick to make slickedit see the static functions in the template. */
84#ifndef IN_SLICKEDIT
85# define NEM_TMPL_STATIC static
86#else
87# define NEM_TMPL_STATIC
88#endif
89
90
91/**
92 * NEM VM Instance data.
93 */
94typedef struct NEM
95{
96 /** NEM_MAGIC. */
97 uint32_t u32Magic;
98
99 /** Set if enabled. */
100 bool fEnabled;
101#ifdef RT_OS_WINDOWS
102 /** Set if we've created the EMTs. */
103 bool fCreatedEmts : 1;
104 /** WHvRunVpExitReasonX64Cpuid is supported. */
105 bool fExtendedMsrExit : 1;
106 /** WHvRunVpExitReasonX64MsrAccess is supported. */
107 bool fExtendedCpuIdExit : 1;
108 /** WHvRunVpExitReasonException is supported. */
109 bool fExtendedXcptExit : 1;
110 /** Set if we've started more than one CPU and cannot mess with A20. */
111 bool fA20Fixed : 1;
112 /** Set if A20 is enabled. */
113 bool fA20Enabled : 1;
114 /** The reported CPU vendor. */
115 CPUMCPUVENDOR enmCpuVendor;
116 /** Cache line flush size as a power of two. */
117 uint8_t cCacheLineFlushShift;
118 /** The result of WHvCapabilityCodeProcessorFeatures. */
119 union
120 {
121 /** 64-bit view. */
122 uint64_t u64;
123# ifdef _WINHVAPIDEFS_H_
124 /** Interpreed features. */
125 WHV_PROCESSOR_FEATURES u;
126# endif
127 } uCpuFeatures;
128
129 /** The partition handle. */
130# ifdef _WINHVAPIDEFS_H_
131 WHV_PARTITION_HANDLE
132# else
133 RTHCUINTPTR
134# endif
135 hPartition;
136 /** The device handle for the partition, for use with Vid APIs or direct I/O
137 * controls. */
138 RTR3PTR hPartitionDevice;
139 /** The Hyper-V partition ID. */
140 uint64_t idHvPartition;
141
142 /** Number of currently mapped pages. */
143 uint32_t volatile cMappedPages;
144
145 /** Info about the VidGetHvPartitionId I/O control interface. */
146 NEMWINIOCTL IoCtlGetHvPartitionId;
147 /** Info about the VidStartVirtualProcessor I/O control interface. */
148 NEMWINIOCTL IoCtlStartVirtualProcessor;
149 /** Info about the VidStopVirtualProcessor I/O control interface. */
150 NEMWINIOCTL IoCtlStopVirtualProcessor;
151 /** Info about the VidStopVirtualProcessor I/O control interface. */
152 NEMWINIOCTL IoCtlMessageSlotHandleAndGetNext;
153
154#endif /* RT_OS_WINDOWS */
155} NEM;
156/** Pointer to NEM VM instance data. */
157typedef NEM *PNEM;
158
159/** NEM::u32Magic value. */
160#define NEM_MAGIC UINT32_C(0x004d454e)
161/** NEM::u32Magic value after termination. */
162#define NEM_MAGIC_DEAD UINT32_C(0xdead1111)
163
164
165/**
166 * NEM VMCPU Instance data.
167 */
168typedef struct NEMCPU
169{
170 /** NEMCPU_MAGIC. */
171 uint32_t u32Magic;
172#ifdef RT_OS_WINDOWS
173# ifdef NEM_WIN_USE_OUR_OWN_RUN_API
174 /** Pending VERR_NEM_CHANGE_PGM_MODE or VERR_NEM_FLUSH_TLB. */
175 int32_t rcPgmPending;
176 /** The VID_MSHAGN_F_XXX flags.
177 * Either VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE or zero. */
178 uint32_t fHandleAndGetFlags;
179 /** What VidMessageSlotMap returns and is used for passing exit info. */
180 RTR3PTR pvMsgSlotMapping;
181# endif
182 /** The windows thread handle. */
183 RTR3PTR hNativeThreadHandle;
184 /** Parameters for making Hyper-V hypercalls. */
185 union
186 {
187 uint8_t ab[64];
188 /** Arguments for NEMR0MapPages (HvCallMapGpaPages). */
189 struct
190 {
191 RTGCPHYS GCPhysSrc;
192 RTGCPHYS GCPhysDst; /**< Same as GCPhysSrc except maybe when the A20 gate is disabled. */
193 uint32_t cPages;
194 HV_MAP_GPA_FLAGS fFlags;
195 } MapPages;
196 /** Arguments for NEMR0UnmapPages (HvCallUnmapGpaPages). */
197 struct
198 {
199 RTGCPHYS GCPhys;
200 uint32_t cPages;
201 } UnmapPages;
202 } Hypercall;
203 /** I/O control buffer, we always use this for I/O controls. */
204 union
205 {
206 uint8_t ab[64];
207 HV_PARTITION_ID idPartition;
208 HV_VP_INDEX idCpu;
209# ifdef VID_MSHAGN_F_GET_NEXT_MESSAGE
210 VID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT MsgSlotHandleAndGetNext;
211# endif
212 } uIoCtlBuf;
213#endif
214} NEMCPU;
215/** Pointer to NEM VMCPU instance data. */
216typedef NEMCPU *PNEMCPU;
217
218/** NEMCPU::u32Magic value. */
219#define NEMCPU_MAGIC UINT32_C(0x4d454e20)
220/** NEMCPU::u32Magic value after termination. */
221#define NEMCPU_MAGIC_DEAD UINT32_C(0xdead2222)
222
223
224#ifdef IN_RING0
225
226/**
227 * NEM GVMCPU instance data.
228 */
229typedef struct NEMR0PERVCPU
230{
231# ifdef RT_OS_WINDOWS
232 /** @name Hypercall input/ouput page.
233 * @{ */
234 /** Host physical address of the hypercall input/output page. */
235 RTHCPHYS HCPhysHypercallData;
236 /** Pointer to the hypercall input/output page. */
237 uint8_t *pbHypercallData;
238 /** Handle to the memory object of the hypercall input/output page. */
239 RTR0MEMOBJ hHypercallDataMemObj;
240 /** @} */
241# else
242 uint32_t uDummy;
243# endif
244} NEMR0PERVCPU;
245
246/**
247 * NEM GVM instance data.
248 */
249typedef struct NEMR0PERVM
250{
251# ifdef RT_OS_WINDOWS
252 /** The partition ID. */
253 uint64_t idHvPartition;
254 /** I/O control context. */
255 PSUPR0IOCTLCTX pIoCtlCtx;
256 /** Delta to add to convert a ring-0 pointer to a ring-3 one. */
257 uintptr_t offRing3ConversionDelta;
258 /** Info about the VidGetHvPartitionId I/O control interface. */
259 NEMWINIOCTL IoCtlGetHvPartitionId;
260 /** Info about the VidStartVirtualProcessor I/O control interface. */
261 NEMWINIOCTL IoCtlStartVirtualProcessor;
262 /** Info about the VidStopVirtualProcessor I/O control interface. */
263 NEMWINIOCTL IoCtlStopVirtualProcessor;
264 /** Info about the VidStopVirtualProcessor I/O control interface. */
265 NEMWINIOCTL IoCtlMessageSlotHandleAndGetNext;
266
267# else
268 uint32_t uDummy;
269# endif
270} NEMR0PERVM;
271
272#endif /* IN_RING*/
273
274
275#ifdef IN_RING3
276int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced);
277int nemR3NativeInitAfterCPUM(PVM pVM);
278int nemR3NativeInitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
279int nemR3NativeTerm(PVM pVM);
280void nemR3NativeReset(PVM pVM);
281void nemR3NativeResetCpu(PVMCPU pVCpu, bool fInitIpi);
282VBOXSTRICTRC nemR3NativeRunGC(PVM pVM, PVMCPU pVCpu);
283bool nemR3NativeCanExecuteGuest(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
284bool nemR3NativeSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
285void nemR3NativeNotifyFF(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
286
287int nemR3NativeNotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb);
288int nemR3NativeNotifyPhysMmioExMap(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, uint32_t fFlags, void *pvMmio2);
289int nemR3NativeNotifyPhysMmioExUnmap(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, uint32_t fFlags);
290int nemR3NativeNotifyPhysRomRegisterEarly(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, uint32_t fFlags);
291int nemR3NativeNotifyPhysRomRegisterLate(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, uint32_t fFlags);
292void nemR3NativeNotifySetA20(PVMCPU pVCpu, bool fEnabled);
293#endif
294
295void nemHCNativeNotifyHandlerPhysicalRegister(PVM pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb);
296void nemHCNativeNotifyHandlerPhysicalDeregister(PVM pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb,
297 int fRestoreAsRAM, bool fRestoreAsRAM2);
298void nemHCNativeNotifyHandlerPhysicalModify(PVM pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhysOld,
299 RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fRestoreAsRAM);
300int nemHCNativeNotifyPhysPageAllocated(PVM pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
301 PGMPAGETYPE enmType, uint8_t *pu2State);
302void nemHCNativeNotifyPhysPageProtChanged(PVM pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
303 PGMPAGETYPE enmType, uint8_t *pu2State);
304void nemHCNativeNotifyPhysPageChanged(PVM pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhysPrev, RTHCPHYS HCPhysNew, uint32_t fPageProt,
305 PGMPAGETYPE enmType, uint8_t *pu2State);
306
307
308#ifdef RT_OS_WINDOWS
309/** Maximum number of pages we can map in a single NEMR0MapPages call. */
310# define NEM_MAX_MAP_PAGES ((PAGE_SIZE - RT_UOFFSETOF(HV_INPUT_MAP_GPA_PAGES, PageList)) / sizeof(HV_SPA_PAGE_NUMBER))
311/** Maximum number of pages we can unmap in a single NEMR0UnmapPages call. */
312# define NEM_MAX_UNMAP_PAGES 4095
313
314#endif
315/** @} */
316
317RT_C_DECLS_END
318
319#endif
320
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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