VirtualBox

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

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

CPUM,NEM: Introduced CPUMCTX field for tracking state that's not in the structure. Made NEM/win only get/set the register it needs. New NEM runloop based on low level messages, skipping translations. bugref:9044

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 10.8 KB
 
1/* $Id: NEMInternal.h 71184 2018-03-03 15:01:59Z 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#endif /* RT_OS_WINDOWS */
78
79
80/** Trick to make slickedit see the static functions in the template. */
81#ifndef IN_SLICKEDIT
82# define NEM_TMPL_STATIC static
83#else
84# define NEM_TMPL_STATIC
85#endif
86
87
88/**
89 * NEM VM Instance data.
90 */
91typedef struct NEM
92{
93 /** NEM_MAGIC. */
94 uint32_t u32Magic;
95
96 /** Set if enabled. */
97 bool fEnabled;
98#ifdef RT_OS_WINDOWS
99 /** Set if we've created the EMTs. */
100 bool fCreatedEmts : 1;
101 /** WHvRunVpExitReasonX64Cpuid is supported. */
102 bool fExtendedMsrExit : 1;
103 /** WHvRunVpExitReasonX64MsrAccess is supported. */
104 bool fExtendedCpuIdExit : 1;
105 /** WHvRunVpExitReasonException is supported. */
106 bool fExtendedXcptExit : 1;
107 /** Set if we've started more than one CPU and cannot mess with A20. */
108 bool fA20Fixed : 1;
109 /** Set if A20 is enabled. */
110 bool fA20Enabled : 1;
111 /** The reported CPU vendor. */
112 CPUMCPUVENDOR enmCpuVendor;
113 /** Cache line flush size as a power of two. */
114 uint8_t cCacheLineFlushShift;
115 /** The result of WHvCapabilityCodeProcessorFeatures. */
116 union
117 {
118 /** 64-bit view. */
119 uint64_t u64;
120# ifdef _WINHVAPIDEFS_H_
121 /** Interpreed features. */
122 WHV_PROCESSOR_FEATURES u;
123# endif
124 } uCpuFeatures;
125
126 /** The partition handle. */
127# ifdef _WINHVAPIDEFS_H_
128 WHV_PARTITION_HANDLE
129# else
130 RTHCUINTPTR
131# endif
132 hPartition;
133 /** The device handle for the partition, for use with Vid APIs or direct I/O
134 * controls. */
135 RTR3PTR hPartitionDevice;
136 /** The Hyper-V partition ID. */
137 uint64_t idHvPartition;
138
139 /** Number of currently mapped pages. */
140 uint32_t volatile cMappedPages;
141
142 /** Info about the VidGetHvPartitionId I/O control interface. */
143 NEMWINIOCTL IoCtlGetHvPartitionId;
144 /** Info about the VidStartVirtualProcessor I/O control interface. */
145 NEMWINIOCTL IoCtlStartVirtualProcessor;
146 /** Info about the VidStopVirtualProcessor I/O control interface. */
147 NEMWINIOCTL IoCtlStopVirtualProcessor;
148 /** Info about the VidStopVirtualProcessor I/O control interface. */
149 NEMWINIOCTL IoCtlMessageSlotHandleAndGetNext;
150
151#endif /* RT_OS_WINDOWS */
152} NEM;
153/** Pointer to NEM VM instance data. */
154typedef NEM *PNEM;
155
156/** NEM::u32Magic value. */
157#define NEM_MAGIC UINT32_C(0x004d454e)
158/** NEM::u32Magic value after termination. */
159#define NEM_MAGIC_DEAD UINT32_C(0xdead1111)
160
161
162/**
163 * NEM VMCPU Instance data.
164 */
165typedef struct NEMCPU
166{
167 /** NEMCPU_MAGIC. */
168 uint32_t u32Magic;
169#ifdef RT_OS_WINDOWS
170# ifdef NEM_WIN_USE_OUR_OWN_RUN_API
171 /** The VID_MSHAGN_F_XXX flags.
172 * Either VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE or zero. */
173 uint32_t fHandleAndGetFlags;
174 /** What VidMessageSlotMap returns and is used for passing exit info. */
175 RTR3PTR pvMsgSlotMapping;
176# endif
177 /** The windows thread handle. */
178 RTR3PTR hNativeThreadHandle;
179 /** Parameters for making Hyper-V hypercalls. */
180 union
181 {
182 uint8_t ab[64];
183 /** Arguments for NEMR0MapPages (HvCallMapGpaPages). */
184 struct
185 {
186 RTGCPHYS GCPhysSrc;
187 RTGCPHYS GCPhysDst; /**< Same as GCPhysSrc except maybe when the A20 gate is disabled. */
188 uint32_t cPages;
189 HV_MAP_GPA_FLAGS fFlags;
190 } MapPages;
191 /** Arguments for NEMR0UnmapPages (HvCallUnmapGpaPages). */
192 struct
193 {
194 RTGCPHYS GCPhys;
195 uint32_t cPages;
196 } UnmapPages;
197 } Hypercall;
198 /** I/O control buffer, we always use this for I/O controls. */
199 union
200 {
201 uint8_t ab[64];
202 HV_PARTITION_ID idPartition;
203 } uIoCtlBuf;
204#endif
205} NEMCPU;
206/** Pointer to NEM VMCPU instance data. */
207typedef NEMCPU *PNEMCPU;
208
209/** NEMCPU::u32Magic value. */
210#define NEMCPU_MAGIC UINT32_C(0x4d454e20)
211/** NEMCPU::u32Magic value after termination. */
212#define NEMCPU_MAGIC_DEAD UINT32_C(0xdead2222)
213
214
215#ifdef IN_RING0
216
217/**
218 * NEM GVMCPU instance data.
219 */
220typedef struct NEMR0PERVCPU
221{
222# ifdef RT_OS_WINDOWS
223 /** @name Hypercall input/ouput page.
224 * @{ */
225 /** Host physical address of the hypercall input/output page. */
226 RTHCPHYS HCPhysHypercallData;
227 /** Pointer to the hypercall input/output page. */
228 uint8_t *pbHypercallData;
229 /** Handle to the memory object of the hypercall input/output page. */
230 RTR0MEMOBJ hHypercallDataMemObj;
231 /** @} */
232# else
233 uint32_t uDummy;
234# endif
235} NEMR0PERVCPU;
236
237/**
238 * NEM GVM instance data.
239 */
240typedef struct NEMR0PERVM
241{
242# ifdef RT_OS_WINDOWS
243 /** The partition ID. */
244 uint64_t idHvPartition;
245 /** I/O control context. */
246 PSUPR0IOCTLCTX pIoCtlCtx;
247 /** Delta to add to convert a ring-0 pointer to a ring-3 one. */
248 uintptr_t offRing3ConversionDelta;
249 /** Info about the VidGetHvPartitionId I/O control interface. */
250 NEMWINIOCTL IoCtlGetHvPartitionId;
251 /** Info about the VidStartVirtualProcessor I/O control interface. */
252 NEMWINIOCTL IoCtlStartVirtualProcessor;
253 /** Info about the VidStopVirtualProcessor I/O control interface. */
254 NEMWINIOCTL IoCtlStopVirtualProcessor;
255 /** Info about the VidStopVirtualProcessor I/O control interface. */
256 NEMWINIOCTL IoCtlMessageSlotHandleAndGetNext;
257
258# else
259 uint32_t uDummy;
260# endif
261} NEMR0PERVM;
262
263#endif /* IN_RING*/
264
265
266#ifdef IN_RING3
267int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced);
268int nemR3NativeInitAfterCPUM(PVM pVM);
269int nemR3NativeInitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
270int nemR3NativeTerm(PVM pVM);
271void nemR3NativeReset(PVM pVM);
272void nemR3NativeResetCpu(PVMCPU pVCpu, bool fInitIpi);
273VBOXSTRICTRC nemR3NativeRunGC(PVM pVM, PVMCPU pVCpu);
274bool nemR3NativeCanExecuteGuest(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
275bool nemR3NativeSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
276void nemR3NativeNotifyFF(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
277
278int nemR3NativeNotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb);
279int nemR3NativeNotifyPhysMmioExMap(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, uint32_t fFlags, void *pvMmio2);
280int nemR3NativeNotifyPhysMmioExUnmap(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, uint32_t fFlags);
281int nemR3NativeNotifyPhysRomRegisterEarly(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, uint32_t fFlags);
282int nemR3NativeNotifyPhysRomRegisterLate(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, uint32_t fFlags);
283void nemR3NativeNotifySetA20(PVMCPU pVCpu, bool fEnabled);
284#endif
285
286void nemHCNativeNotifyHandlerPhysicalRegister(PVM pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb);
287void nemHCNativeNotifyHandlerPhysicalDeregister(PVM pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb,
288 int fRestoreAsRAM, bool fRestoreAsRAM2);
289void nemHCNativeNotifyHandlerPhysicalModify(PVM pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhysOld,
290 RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fRestoreAsRAM);
291int nemHCNativeNotifyPhysPageAllocated(PVM pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
292 PGMPAGETYPE enmType, uint8_t *pu2State);
293void nemHCNativeNotifyPhysPageProtChanged(PVM pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
294 PGMPAGETYPE enmType, uint8_t *pu2State);
295void nemHCNativeNotifyPhysPageChanged(PVM pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhysPrev, RTHCPHYS HCPhysNew, uint32_t fPageProt,
296 PGMPAGETYPE enmType, uint8_t *pu2State);
297
298
299#ifdef RT_OS_WINDOWS
300/** Maximum number of pages we can map in a single NEMR0MapPages call. */
301# define NEM_MAX_MAP_PAGES ((PAGE_SIZE - RT_UOFFSETOF(HV_INPUT_MAP_GPA_PAGES, PageList)) / sizeof(HV_SPA_PAGE_NUMBER))
302/** Maximum number of pages we can unmap in a single NEMR0UnmapPages call. */
303# define NEM_MAX_UNMAP_PAGES 4095
304
305#endif
306/** @} */
307
308RT_C_DECLS_END
309
310#endif
311
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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