VirtualBox

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

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

SUPDrv,VMM/NEM/win: Abstracted kernel I/O control work in SUPDrv, currently only implemented & needed on windows. Made first I/O control call to VID from ring-0. bugref:9044

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

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