VirtualBox

source: vbox/trunk/include/VBox/vmm/pgm.h@ 104910

Last change on this file since 104910 was 104910, checked in by vboxsync, 9 months ago

VMM/PGM: bugref:10703 Add PGM API for retreiving boot zeroed RAM ranges for Hyper-V paravirt provider.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 59.3 KB
Line 
1/** @file
2 * PGM - Page Monitor / Monitor.
3 */
4
5/*
6 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef VBOX_INCLUDED_vmm_pgm_h
37#define VBOX_INCLUDED_vmm_pgm_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <VBox/types.h>
43#include <VBox/sup.h>
44#include <VBox/vmm/vmapi.h>
45#include <VBox/vmm/gmm.h> /* for PGMMREGISTERSHAREDMODULEREQ */
46#include <VBox/vmm/hm_vmx.h>
47#include <iprt/x86.h>
48#include <VBox/param.h>
49
50RT_C_DECLS_BEGIN
51
52/** @defgroup grp_pgm The Page Monitor / Manager API
53 * @ingroup grp_vmm
54 * @{
55 */
56
57/**
58 * FNPGMRELOCATE callback mode.
59 */
60typedef enum PGMRELOCATECALL
61{
62 /** The callback is for checking if the suggested address is suitable. */
63 PGMRELOCATECALL_SUGGEST = 1,
64 /** The callback is for executing the relocation. */
65 PGMRELOCATECALL_RELOCATE
66} PGMRELOCATECALL;
67
68
69/**
70 * Callback function which will be called when PGM is trying to find
71 * a new location for the mapping.
72 *
73 * The callback is called in two modes, 1) the check mode and 2) the relocate mode.
74 * In 1) the callback should say if it objects to a suggested new location. If it
75 * accepts the new location, it is called again for doing it's relocation.
76 *
77 *
78 * @returns true if the location is ok.
79 * @returns false if another location should be found.
80 * @param pVM The cross context VM structure.
81 * @param GCPtrOld The old virtual address.
82 * @param GCPtrNew The new virtual address.
83 * @param enmMode Used to indicate the callback mode.
84 * @param pvUser User argument.
85 * @remark The return value is no a failure indicator, it's an acceptance
86 * indicator. Relocation can not fail!
87 */
88typedef DECLCALLBACKTYPE(bool, FNPGMRELOCATE,(PVM pVM, RTGCPTR GCPtrOld, RTGCPTR GCPtrNew, PGMRELOCATECALL enmMode, void *pvUser));
89/** Pointer to a relocation callback function. */
90typedef FNPGMRELOCATE *PFNPGMRELOCATE;
91
92
93/**
94 * Memory access origin.
95 */
96typedef enum PGMACCESSORIGIN
97{
98 /** Invalid zero value. */
99 PGMACCESSORIGIN_INVALID = 0,
100 /** IEM is access memory. */
101 PGMACCESSORIGIN_IEM,
102 /** HM is access memory. */
103 PGMACCESSORIGIN_HM,
104 /** Some device is access memory. */
105 PGMACCESSORIGIN_DEVICE,
106 /** Someone debugging is access memory. */
107 PGMACCESSORIGIN_DEBUGGER,
108 /** SELM is access memory. */
109 PGMACCESSORIGIN_SELM,
110 /** FTM is access memory. */
111 PGMACCESSORIGIN_FTM,
112 /** REM is access memory. */
113 PGMACCESSORIGIN_REM,
114 /** IOM is access memory. */
115 PGMACCESSORIGIN_IOM,
116 /** End of valid values. */
117 PGMACCESSORIGIN_END,
118 /** Type size hack. */
119 PGMACCESSORIGIN_32BIT_HACK = 0x7fffffff
120} PGMACCESSORIGIN;
121
122
123/**
124 * Physical page access handler kind.
125 */
126typedef enum PGMPHYSHANDLERKIND
127{
128 /** Invalid zero value. */
129 PGMPHYSHANDLERKIND_INVALID = 0,
130 /** MMIO range. Pages are not present, all access is done in interpreter or recompiler. */
131 PGMPHYSHANDLERKIND_MMIO,
132 /** Handler all write access to a physical page range. */
133 PGMPHYSHANDLERKIND_WRITE,
134 /** Handler all access to a physical page range. */
135 PGMPHYSHANDLERKIND_ALL,
136 /** End of the valid values. */
137 PGMPHYSHANDLERKIND_END,
138 /** Type size hack. */
139 PGMPHYSHANDLERKIND_32BIT_HACK = 0x7fffffff
140} PGMPHYSHANDLERKIND;
141
142/**
143 * Guest Access type
144 */
145typedef enum PGMACCESSTYPE
146{
147 /** Read access. */
148 PGMACCESSTYPE_READ = 1,
149 /** Write access. */
150 PGMACCESSTYPE_WRITE
151} PGMACCESSTYPE;
152
153
154/** @def PGM_ALL_CB_DECL
155 * Macro for declaring a handler callback for all contexts. The handler
156 * callback is static in ring-3, and exported in RC and R0.
157 * @sa PGM_ALL_CB2_DECL.
158 */
159#if defined(IN_RC) || defined(IN_RING0)
160# ifdef __cplusplus
161# define PGM_ALL_CB_DECL(type) extern "C" DECLCALLBACK(DECLEXPORT(type))
162# else
163# define PGM_ALL_CB_DECL(type) DECLCALLBACK(DECLEXPORT(type))
164# endif
165#else
166# define PGM_ALL_CB_DECL(type) static DECLCALLBACK(type)
167#endif
168
169/** @def PGM_ALL_CB2_DECL
170 * Macro for declaring a handler callback for all contexts. The handler
171 * callback is hidden in ring-3, and exported in RC and R0.
172 * @sa PGM_ALL_CB2_DECL.
173 */
174#if defined(IN_RC) || defined(IN_RING0)
175# ifdef __cplusplus
176# define PGM_ALL_CB2_DECL(type) extern "C" DECLCALLBACK(DECLEXPORT(type))
177# else
178# define PGM_ALL_CB2_DECL(type) DECLCALLBACK(DECLEXPORT(type))
179# endif
180#else
181# define PGM_ALL_CB2_DECL(type) DECL_HIDDEN_CALLBACK(type)
182#endif
183
184/** @def PGM_ALL_CB2_PROTO
185 * Macro for declaring a handler callback for all contexts. The handler
186 * callback is hidden in ring-3, and exported in RC and R0.
187 * @param fnType The callback function type.
188 * @sa PGM_ALL_CB2_DECL.
189 */
190#if defined(IN_RC) || defined(IN_RING0)
191# ifdef __cplusplus
192# define PGM_ALL_CB2_PROTO(fnType) extern "C" DECLEXPORT(fnType)
193# else
194# define PGM_ALL_CB2_PROTO(fnType) DECLEXPORT(fnType)
195# endif
196#else
197# define PGM_ALL_CB2_PROTO(fnType) DECLHIDDEN(fnType)
198#endif
199
200
201/**
202 * \#PF Handler callback for physical access handler ranges in RC and R0.
203 *
204 * @returns Strict VBox status code (appropriate for ring-0 and raw-mode).
205 * @param pVM The cross context VM structure.
206 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
207 * @param uErrorCode CPU Error code.
208 * @param pCtx Pointer to the register context for the CPU.
209 * @param pvFault The fault address (cr2).
210 * @param GCPhysFault The GC physical address corresponding to pvFault.
211 * @param uUser User argument (not a pointer).
212 * @thread EMT(pVCpu)
213 */
214typedef DECLCALLBACKTYPE(VBOXSTRICTRC, FNPGMRZPHYSPFHANDLER,(PVMCC pVM, PVMCPUCC pVCpu, RTGCUINT uErrorCode, PCPUMCTX pCtx,
215 RTGCPTR pvFault, RTGCPHYS GCPhysFault, uint64_t uUser));
216/** Pointer to PGM access callback. */
217typedef FNPGMRZPHYSPFHANDLER *PFNPGMRZPHYSPFHANDLER;
218
219
220/**
221 * Access handler callback for physical access handler ranges.
222 *
223 * The handler can not raise any faults, it's mainly for monitoring write access
224 * to certain pages (like MMIO).
225 *
226 * @returns Strict VBox status code in ring-0 and raw-mode context, in ring-3
227 * the only supported informational status code is
228 * VINF_PGM_HANDLER_DO_DEFAULT.
229 * @retval VINF_SUCCESS if the handler have carried out the operation.
230 * @retval VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the
231 * access operation.
232 * @retval VINF_EM_XXX in ring-0 and raw-mode context.
233 *
234 * @param pVM The cross context VM structure.
235 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
236 * @param GCPhys The physical address the guest is writing to.
237 * @param pvPhys The HC mapping of that address.
238 * @param pvBuf What the guest is reading/writing.
239 * @param cbBuf How much it's reading/writing.
240 * @param enmAccessType The access type.
241 * @param enmOrigin The origin of this call.
242 * @param uUser User argument (not a pointer).
243 * @thread EMT(pVCpu)
244 */
245typedef DECLCALLBACKTYPE(VBOXSTRICTRC, FNPGMPHYSHANDLER,(PVMCC pVM, PVMCPUCC pVCpu, RTGCPHYS GCPhys, void *pvPhys,
246 void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType,
247 PGMACCESSORIGIN enmOrigin, uint64_t uUser));
248/** Pointer to PGM access callback. */
249typedef FNPGMPHYSHANDLER *PFNPGMPHYSHANDLER;
250
251
252/**
253 * Paging mode.
254 *
255 * @note Part of saved state. Change with extreme care.
256 */
257typedef enum PGMMODE
258{
259 /** The usual invalid value. */
260 PGMMODE_INVALID = 0,
261 /** Real mode. */
262 PGMMODE_REAL,
263 /** Protected mode, no paging. */
264 PGMMODE_PROTECTED,
265 /** 32-bit paging. */
266 PGMMODE_32_BIT,
267 /** PAE paging. */
268 PGMMODE_PAE,
269 /** PAE paging with NX enabled. */
270 PGMMODE_PAE_NX,
271 /** 64-bit AMD paging (long mode). */
272 PGMMODE_AMD64,
273 /** 64-bit AMD paging (long mode) with NX enabled. */
274 PGMMODE_AMD64_NX,
275 /** 32-bit nested paging mode (shadow only; guest physical to host physical). */
276 PGMMODE_NESTED_32BIT,
277 /** PAE nested paging mode (shadow only; guest physical to host physical). */
278 PGMMODE_NESTED_PAE,
279 /** AMD64 nested paging mode (shadow only; guest physical to host physical). */
280 PGMMODE_NESTED_AMD64,
281 /** Extended paging (Intel) mode. */
282 PGMMODE_EPT,
283 /** Special mode used by NEM to indicate no shadow paging necessary. */
284 PGMMODE_NONE,
285 /** The max number of modes */
286 PGMMODE_MAX,
287 /** 32bit hackishness. */
288 PGMMODE_32BIT_HACK = 0x7fffffff
289} PGMMODE;
290
291/**
292 * Second level address translation (SLAT) mode.
293 */
294typedef enum PGMSLAT
295{
296 /** The usual invalid value. */
297 PGMSLAT_INVALID = 0,
298 /** No second level translation. */
299 PGMSLAT_DIRECT,
300 /** Intel Extended Page Tables (EPT). */
301 PGMSLAT_EPT,
302 /** AMD-V Nested Paging 32-bit. */
303 PGMSLAT_32BIT,
304 /** AMD-V Nested Paging PAE. */
305 PGMSLAT_PAE,
306 /** AMD-V Nested Paging 64-bit. */
307 PGMSLAT_AMD64,
308 /** 32bit hackishness. */
309 PGMSLAT_32BIT_HACK = 0x7fffffff
310} PGMSLAT;
311
312
313/** @name PGMPTWALK::fFailed flags.
314 * These flags indicate the type of a page-walk failure.
315 * @{
316 */
317typedef uint32_t PGMWALKFAIL;
318/** Regular page fault (MBZ since guest Walk code don't set these explicitly). */
319#define PGM_WALKFAIL_PAGE_FAULT UINT32_C(0)
320/** EPT violation - Intel. */
321#define PGM_WALKFAIL_EPT_VIOLATION RT_BIT_32(0)
322/** EPT violation, convertible to \#VE exception - Intel. */
323#define PGM_WALKFAIL_EPT_VIOLATION_CONVERTIBLE RT_BIT_32(1)
324/** EPT misconfiguration - Intel. */
325#define PGM_WALKFAIL_EPT_MISCONFIG RT_BIT_32(2)
326
327/** Mask of all EPT induced page-walk failures - Intel. */
328#define PGM_WALKFAIL_EPT ( PGM_WALKFAIL_EPT_VIOLATION \
329 | PGM_WALKFAIL_EPT_VIOLATION_CONVERTIBLE \
330 | PGM_WALKFAIL_EPT_MISCONFIG)
331/** @} */
332
333
334/** @name PGMPTATTRS - PGM page-table attributes.
335 *
336 * This is VirtualBox's combined page table attributes. It combines regular page
337 * table and Intel EPT attributes. It's 64-bit in size so there's ample room for
338 * bits added in the future to EPT or regular page tables (for e.g. Protection Key).
339 *
340 * The following bits map 1:1 (shifted by PGM_PTATTRS_EPT_SHIFT) to the Intel EPT
341 * attributes as these are unique to EPT and fit within 64-bits despite the shift:
342 * - EPT_R : Read access.
343 * - EPT_W : Write access.
344 * - EPT_X_SUPER : Execute or execute for supervisor-mode linear addr access.
345 * - EPT_MEMTYPE : EPT memory type.
346 * - EPT_IGNORE_PAT: Ignore PAT memory type.
347 * - EPT_X_USER : Execute access for user-mode linear addresses.
348 *
349 * For regular page tables, the R bit is always 1 (same as P bit).
350 * For Intel EPT, the EPT_R and EPT_W bits are copied to R and W bits respectively.
351 *
352 * The following EPT attributes are mapped to the following positions because they
353 * exist in the regular page tables at these positions OR are exclusive to EPT and
354 * have been mapped to arbitrarily chosen positions:
355 * - EPT_A : Accessed (EPT bit 8 maps to bit 5).
356 * - EPT_D : Dirty (EPT bit 9 maps to bit 6).
357 * - EPT_SUPER_SHW_STACK : Supervisor Shadow Stack (EPT bit 60 maps to bit 24).
358 * - EPT_SUPPRESS_VE_XCPT: Suppress \#VE exception (EPT bit 63 maps to bit 25).
359 *
360 * Bits 12, 11:9 and 43 are deliberately kept unused (correspond to bit PS and bits
361 * 11:9 in the regular page-table structures and to bit 11 in the EPT structures
362 * respectively) as bit 12 is the page-size bit and bits 11:9 are reserved for
363 * use by software and we may want to use/preserve them in the future.
364 *
365 * @{ */
366typedef uint64_t PGMPTATTRS;
367/** Pointer to a PGMPTATTRS type. */
368typedef PGMPTATTRS *PPGMPTATTRS;
369
370/** Read bit (always 1 for regular PT, copy of EPT_R for EPT). */
371#define PGM_PTATTRS_R_SHIFT 0
372#define PGM_PTATTRS_R_MASK RT_BIT_64(PGM_PTATTRS_R_SHIFT)
373/** Write access bit (aka read/write bit for regular PT). */
374#define PGM_PTATTRS_W_SHIFT 1
375#define PGM_PTATTRS_W_MASK RT_BIT_64(PGM_PTATTRS_W_SHIFT)
376/** User-mode access bit. */
377#define PGM_PTATTRS_US_SHIFT 2
378#define PGM_PTATTRS_US_MASK RT_BIT_64(PGM_PTATTRS_US_SHIFT)
379/** Write through cache bit. */
380#define PGM_PTATTRS_PWT_SHIFT 3
381#define PGM_PTATTRS_PWT_MASK RT_BIT_64(PGM_PTATTRS_PWT_SHIFT)
382/** Cache disabled bit. */
383#define PGM_PTATTRS_PCD_SHIFT 4
384#define PGM_PTATTRS_PCD_MASK RT_BIT_64(PGM_PTATTRS_PCD_SHIFT)
385/** Accessed bit. */
386#define PGM_PTATTRS_A_SHIFT 5
387#define PGM_PTATTRS_A_MASK RT_BIT_64(PGM_PTATTRS_A_SHIFT)
388/** Dirty bit. */
389#define PGM_PTATTRS_D_SHIFT 6
390#define PGM_PTATTRS_D_MASK RT_BIT_64(PGM_PTATTRS_D_SHIFT)
391/** The PAT bit. */
392#define PGM_PTATTRS_PAT_SHIFT 7
393#define PGM_PTATTRS_PAT_MASK RT_BIT_64(PGM_PTATTRS_PAT_SHIFT)
394/** The global bit. */
395#define PGM_PTATTRS_G_SHIFT 8
396#define PGM_PTATTRS_G_MASK RT_BIT_64(PGM_PTATTRS_G_SHIFT)
397/** Reserved (bits 12:9) unused. */
398#define PGM_PTATTRS_RSVD_12_9_SHIFT 9
399#define PGM_PTATTRS_RSVD_12_9_MASK UINT64_C(0x0000000000001e00)
400/** Read access bit - EPT only. */
401#define PGM_PTATTRS_EPT_R_SHIFT 13
402#define PGM_PTATTRS_EPT_R_MASK RT_BIT_64(PGM_PTATTRS_EPT_R_SHIFT)
403/** Write access bit - EPT only. */
404#define PGM_PTATTRS_EPT_W_SHIFT 14
405#define PGM_PTATTRS_EPT_W_MASK RT_BIT_64(PGM_PTATTRS_EPT_W_SHIFT)
406/** Execute or execute access for supervisor-mode linear addresses - EPT only. */
407#define PGM_PTATTRS_EPT_X_SUPER_SHIFT 15
408#define PGM_PTATTRS_EPT_X_SUPER_MASK RT_BIT_64(PGM_PTATTRS_EPT_X_SUPER_SHIFT)
409/** EPT memory type - EPT only. */
410#define PGM_PTATTRS_EPT_MEMTYPE_SHIFT 16
411#define PGM_PTATTRS_EPT_MEMTYPE_MASK UINT64_C(0x0000000000070000)
412/** Ignore PAT memory type - EPT only. */
413#define PGM_PTATTRS_EPT_IGNORE_PAT_SHIFT 19
414#define PGM_PTATTRS_EPT_IGNORE_PAT_MASK RT_BIT_64(PGM_PTATTRS_EPT_IGNORE_PAT_SHIFT)
415/** Leaf paging entry (big or regular) - EPT only. */
416#define PGM_PTATTRS_EPT_LEAF_SHIFT 20
417#define PGM_PTATTRS_EPT_LEAF_MASK RT_BIT_64(PGM_PTATTRS_EPT_LEAF_SHIFT)
418/** Accessed bit - EPT only. */
419#define PGM_PTATTRS_EPT_A_SHIFT 21
420#define PGM_PTATTRS_EPT_A_MASK RT_BIT_64(PGM_PTATTRS_EPT_A_SHIFT)
421/** Dirty bit - EPT only. */
422#define PGM_PTATTRS_EPT_D_SHIFT 22
423#define PGM_PTATTRS_EPT_D_MASK RT_BIT_64(PGM_PTATTRS_EPT_D_SHIFT)
424/** Execute access for user-mode linear addresses - EPT only. */
425#define PGM_PTATTRS_EPT_X_USER_SHIFT 23
426#define PGM_PTATTRS_EPT_X_USER_MASK RT_BIT_64(PGM_PTATTRS_EPT_X_USER_SHIFT)
427/** Reserved (bits 29:24) - unused. */
428#define PGM_PTATTRS_RSVD_29_24_SHIFT 24
429#define PGM_PTATTRS_RSVD_29_24_MASK UINT64_C(0x000000003f000000)
430/** Verify Guest Paging - EPT only. */
431#define PGM_PTATTRS_EPT_VGP_SHIFT 30
432#define PGM_PTATTRS_EPT_VGP_MASK RT_BIT_64(PGM_PTATTRS_EPT_VGP_SHIFT)
433/** Paging-write - EPT only. */
434#define PGM_PTATTRS_EPT_PW_SHIFT 31
435#define PGM_PTATTRS_EPT_PW_MASK RT_BIT_64(PGM_PTATTRS_EPT_PW_SHIFT)
436/** Reserved (bit 32) - unused. */
437#define PGM_PTATTRS_RSVD_32_SHIFT 32
438#define PGM_PTATTRS_RSVD_32_MASK UINT64_C(0x0000000100000000)
439/** Supervisor shadow stack - EPT only. */
440#define PGM_PTATTRS_EPT_SSS_SHIFT 33
441#define PGM_PTATTRS_EPT_SSS_MASK RT_BIT_64(PGM_PTATTRS_EPT_SSS_SHIFT)
442/** Sub-page write permission - EPT only. */
443#define PGM_PTATTRS_EPT_SPP_SHIFT 34
444#define PGM_PTATTRS_EPT_SPP_MASK RT_BIT_64(PGM_PTATTRS_EPT_SPP_SHIFT)
445/** Reserved (bit 35) - unused. */
446#define PGM_PTATTRS_RSVD_35_SHIFT 35
447#define PGM_PTATTRS_RSVD_35_MASK UINT64_C(0x0000000800000000)
448/** Suppress \#VE exception - EPT only. */
449#define PGM_PTATTRS_EPT_SVE_SHIFT 36
450#define PGM_PTATTRS_EPT_SVE_MASK RT_BIT_64(PGM_PTATTRS_EPT_SVE_SHIFT)
451/** Reserved (bits 62:37) - unused. */
452#define PGM_PTATTRS_RSVD_62_37_SHIFT 37
453#define PGM_PTATTRS_RSVD_62_37_MASK UINT64_C(0x7fffffe000000000)
454/** No-execute bit. */
455#define PGM_PTATTRS_NX_SHIFT 63
456#define PGM_PTATTRS_NX_MASK RT_BIT_64(PGM_PTATTRS_NX_SHIFT)
457
458RT_BF_ASSERT_COMPILE_CHECKS(PGM_PTATTRS_, UINT64_C(0), UINT64_MAX,
459 (R, W, US, PWT, PCD, A, D, PAT, G, RSVD_12_9, EPT_R, EPT_W, EPT_X_SUPER, EPT_MEMTYPE, EPT_IGNORE_PAT,
460 EPT_LEAF, EPT_A, EPT_D, EPT_X_USER, RSVD_29_24, EPT_VGP, EPT_PW, RSVD_32, EPT_SSS, EPT_SPP,
461 RSVD_35, EPT_SVE, RSVD_62_37, NX));
462
463/** The bit position where the EPT specific attributes begin. */
464#define PGM_PTATTRS_EPT_SHIFT PGM_PTATTRS_EPT_R_SHIFT
465/** The mask of EPT bits (bits 36:ATTR_SHIFT). In the future we might choose to
466 * use higher unused bits for something else, in that case adjust this mask. */
467#define PGM_PTATTRS_EPT_MASK UINT64_C(0x0000001fffffe000)
468
469/** The mask of all PGM page attribute bits for regular page-tables. */
470#define PGM_PTATTRS_PT_VALID_MASK ( PGM_PTATTRS_R_MASK \
471 | PGM_PTATTRS_W_MASK \
472 | PGM_PTATTRS_US_MASK \
473 | PGM_PTATTRS_PWT_MASK \
474 | PGM_PTATTRS_PCD_MASK \
475 | PGM_PTATTRS_A_MASK \
476 | PGM_PTATTRS_D_MASK \
477 | PGM_PTATTRS_PAT_MASK \
478 | PGM_PTATTRS_G_MASK \
479 | PGM_PTATTRS_NX_MASK)
480
481/** The mask of all PGM page attribute bits for EPT. */
482#define PGM_PTATTRS_EPT_VALID_MASK ( PGM_PTATTRS_EPT_R_MASK \
483 | PGM_PTATTRS_EPT_W_MASK \
484 | PGM_PTATTRS_EPT_X_SUPER_MASK \
485 | PGM_PTATTRS_EPT_MEMTYPE_MASK \
486 | PGM_PTATTRS_EPT_IGNORE_PAT_MASK \
487 | PGM_PTATTRS_EPT_LEAF_MASK \
488 | PGM_PTATTRS_EPT_A_MASK \
489 | PGM_PTATTRS_EPT_D_MASK \
490 | PGM_PTATTRS_EPT_X_USER_MASK \
491 | PGM_PTATTRS_EPT_VGP_MASK \
492 | PGM_PTATTRS_EPT_PW_MASK \
493 | PGM_PTATTRS_EPT_SSS_MASK \
494 | PGM_PTATTRS_EPT_SPP_MASK \
495 | PGM_PTATTRS_EPT_SVE_MASK)
496
497/* The mask of all PGM page attribute bits (combined). */
498#define PGM_PTATTRS_VALID_MASK (PGM_PTATTRS_PT_VALID_MASK | PGM_PTATTRS_EPT_VALID_MASK)
499
500/* Verify bits match the regular PT bits. */
501AssertCompile(PGM_PTATTRS_W_SHIFT == X86_PTE_BIT_RW);
502AssertCompile(PGM_PTATTRS_US_SHIFT == X86_PTE_BIT_US);
503AssertCompile(PGM_PTATTRS_PWT_SHIFT == X86_PTE_BIT_PWT);
504AssertCompile(PGM_PTATTRS_PCD_SHIFT == X86_PTE_BIT_PCD);
505AssertCompile(PGM_PTATTRS_A_SHIFT == X86_PTE_BIT_A);
506AssertCompile(PGM_PTATTRS_D_SHIFT == X86_PTE_BIT_D);
507AssertCompile(PGM_PTATTRS_PAT_SHIFT == X86_PTE_BIT_PAT);
508AssertCompile(PGM_PTATTRS_G_SHIFT == X86_PTE_BIT_G);
509AssertCompile(PGM_PTATTRS_W_MASK == X86_PTE_RW);
510AssertCompile(PGM_PTATTRS_US_MASK == X86_PTE_US);
511AssertCompile(PGM_PTATTRS_PWT_MASK == X86_PTE_PWT);
512AssertCompile(PGM_PTATTRS_PCD_MASK == X86_PTE_PCD);
513AssertCompile(PGM_PTATTRS_A_MASK == X86_PTE_A);
514AssertCompile(PGM_PTATTRS_D_MASK == X86_PTE_D);
515AssertCompile(PGM_PTATTRS_PAT_MASK == X86_PTE_PAT);
516AssertCompile(PGM_PTATTRS_G_MASK == X86_PTE_G);
517AssertCompile(PGM_PTATTRS_NX_MASK == X86_PTE_PAE_NX);
518
519/* Verify those EPT bits that must map 1:1 (after shifting). */
520AssertCompile(PGM_PTATTRS_EPT_R_SHIFT - PGM_PTATTRS_EPT_SHIFT == EPT_E_BIT_READ);
521AssertCompile(PGM_PTATTRS_EPT_W_SHIFT - PGM_PTATTRS_EPT_SHIFT == EPT_E_BIT_WRITE);
522AssertCompile(PGM_PTATTRS_EPT_X_SUPER_SHIFT - PGM_PTATTRS_EPT_SHIFT == EPT_E_BIT_EXECUTE);
523AssertCompile(PGM_PTATTRS_EPT_IGNORE_PAT_SHIFT - PGM_PTATTRS_EPT_SHIFT == EPT_E_BIT_IGNORE_PAT);
524AssertCompile(PGM_PTATTRS_EPT_X_USER_SHIFT - PGM_PTATTRS_EPT_SHIFT == EPT_E_BIT_USER_EXECUTE);
525/** @} */
526
527
528/**
529 * Page table walk information.
530 *
531 * This provides extensive information regarding page faults (or EPT
532 * violations/misconfigurations) while traversing page tables.
533 */
534typedef struct PGMPTWALK
535{
536 /** The linear address that is being resolved (input). */
537 RTGCPTR GCPtr;
538
539 /** The second-level physical address (input/output).
540 * @remarks only valid if fIsSlat is set. */
541 RTGCPHYS GCPhysNested;
542
543 /** The physical address that is the result of the walk (output). */
544 RTGCPHYS GCPhys;
545
546 /** Set if the walk succeeded. */
547 bool fSucceeded;
548 /** Whether this is a second-level address translation. */
549 bool fIsSlat;
550 /** Whether the linear address (GCPtr) caused the second-level
551 * address translation. */
552 bool fIsLinearAddrValid;
553 /** The level problem arrised at.
554 * PTE is level 1, PDE is level 2, PDPE is level 3, PML4 is level 4, CR3 is
555 * level 8. This is 0 on success. */
556 uint8_t uLevel;
557 /** Set if the page isn't present. */
558 bool fNotPresent;
559 /** Encountered a bad physical address. */
560 bool fBadPhysAddr;
561 /** Set if there was reserved bit violations. */
562 bool fRsvdError;
563 /** Set if it involves a big page (2/4 MB). */
564 bool fBigPage;
565 /** Set if it involves a gigantic page (1 GB). */
566 bool fGigantPage;
567 bool afPadding[3];
568 /** Page-walk failure type, PGM_WALKFAIL_XXX. */
569 PGMWALKFAIL fFailed;
570
571 /** The effective page-table attributes, PGM_PTATTRS_XXX. */
572 PGMPTATTRS fEffective;
573} PGMPTWALK;
574/** Pointer to page walk information. */
575typedef PGMPTWALK *PPGMPTWALK;
576/** Pointer to const page walk information. */
577typedef PGMPTWALK const *PCPGMPTWALK;
578
579
580/** Macro for checking if the guest is using paging.
581 * @param enmMode PGMMODE_*.
582 * @remark ASSUMES certain order of the PGMMODE_* values.
583 */
584#define PGMMODE_WITH_PAGING(enmMode) ((enmMode) >= PGMMODE_32_BIT)
585
586/** Macro for checking if it's one of the long mode modes.
587 * @param enmMode PGMMODE_*.
588 */
589#define PGMMODE_IS_LONG_MODE(enmMode) ((enmMode) == PGMMODE_AMD64_NX || (enmMode) == PGMMODE_AMD64)
590
591/** Macro for checking if it's one of the AMD64 nested modes.
592 * @param enmMode PGMMODE_*.
593 */
594#define PGMMODE_IS_NESTED(enmMode) ( (enmMode) == PGMMODE_NESTED_32BIT \
595 || (enmMode) == PGMMODE_NESTED_PAE \
596 || (enmMode) == PGMMODE_NESTED_AMD64)
597
598/** Macro for checking if it's one of the PAE modes.
599 * @param enmMode PGMMODE_*.
600 */
601#define PGMMODE_IS_PAE(enmMode) ( (enmMode) == PGMMODE_PAE \
602 || (enmMode) == PGMMODE_PAE_NX)
603
604/**
605 * Is the ROM mapped (true) or is the shadow RAM mapped (false).
606 *
607 * @returns boolean.
608 * @param enmProt The PGMROMPROT value, must be valid.
609 */
610#define PGMROMPROT_IS_ROM(enmProt) \
611 ( (enmProt) == PGMROMPROT_READ_ROM_WRITE_IGNORE \
612 || (enmProt) == PGMROMPROT_READ_ROM_WRITE_RAM )
613
614
615VMMDECL(bool) PGMIsLockOwner(PVMCC pVM);
616
617VMMDECL(int) PGMRegisterStringFormatTypes(void);
618VMMDECL(void) PGMDeregisterStringFormatTypes(void);
619VMMDECL(RTHCPHYS) PGMGetHyperCR3(PVMCPU pVCpu);
620VMMDECL(int) PGMTrap0eHandler(PVMCPUCC pVCpu, RTGCUINT uErr, PCPUMCTX pCtx, RTGCPTR pvFault);
621VMMDECL(int) PGMPrefetchPage(PVMCPUCC pVCpu, RTGCPTR GCPtrPage);
622VMMDECL(VBOXSTRICTRC) PGMInterpretInstruction(PVMCPUCC pVCpu, RTGCPTR pvFault);
623VMMDECL(int) PGMShwGetPage(PVMCPUCC pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTHCPHYS pHCPhys);
624VMMDECL(int) PGMShwMakePageReadonly(PVMCPUCC pVCpu, RTGCPTR GCPtr, uint32_t fFlags);
625VMMDECL(int) PGMShwMakePageWritable(PVMCPUCC pVCpu, RTGCPTR GCPtr, uint32_t fFlags);
626VMMDECL(int) PGMShwMakePageNotPresent(PVMCPUCC pVCpu, RTGCPTR GCPtr, uint32_t fFlags);
627/** @name Flags for PGMShwMakePageReadonly, PGMShwMakePageWritable and
628 * PGMShwMakePageNotPresent
629 * @{ */
630/** The call is from an access handler for dealing with the a faulting write
631 * operation. The virtual address is within the same page. */
632#define PGM_MK_PG_IS_WRITE_FAULT RT_BIT(0)
633/** The page is an MMIO2. */
634#define PGM_MK_PG_IS_MMIO2 RT_BIT(1)
635/** @}*/
636VMMDECL(int) PGMGstGetPage(PVMCPUCC pVCpu, RTGCPTR GCPtr, PPGMPTWALK pWalk);
637VMMDECL(int) PGMGstModifyPage(PVMCPUCC pVCpu, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
638VMM_INT_DECL(bool) PGMGstArePaePdpesValid(PVMCPUCC pVCpu, PCX86PDPE paPaePdpes);
639VMM_INT_DECL(int) PGMGstMapPaePdpes(PVMCPUCC pVCpu, PCX86PDPE paPaePdpes);
640VMM_INT_DECL(int) PGMGstMapPaePdpesAtCr3(PVMCPUCC pVCpu, uint64_t cr3);
641
642VMMDECL(int) PGMInvalidatePage(PVMCPUCC pVCpu, RTGCPTR GCPtrPage);
643VMMDECL(int) PGMFlushTLB(PVMCPUCC pVCpu, uint64_t cr3, bool fGlobal);
644VMMDECL(int) PGMSyncCR3(PVMCPUCC pVCpu, uint64_t cr0, uint64_t cr3, uint64_t cr4, bool fGlobal);
645VMMDECL(int) PGMUpdateCR3(PVMCPUCC pVCpu, uint64_t cr3);
646VMMDECL(int) PGMChangeMode(PVMCPUCC pVCpu, uint64_t cr0, uint64_t cr4, uint64_t efer, bool fForce);
647VMM_INT_DECL(int) PGMHCChangeMode(PVMCC pVM, PVMCPUCC pVCpu, PGMMODE enmGuestMode, bool fForce);
648VMMDECL(void) PGMCr0WpEnabled(PVMCPUCC pVCpu);
649VMMDECL(PGMMODE) PGMGetGuestMode(PVMCPU pVCpu);
650VMMDECL(PGMMODE) PGMGetShadowMode(PVMCPU pVCpu);
651VMMDECL(PGMMODE) PGMGetHostMode(PVM pVM);
652VMMDECL(const char *) PGMGetModeName(PGMMODE enmMode);
653#ifdef VBOX_WITH_NESTED_HWVIRT_VMX_EPT
654VMM_INT_DECL(const char *) PGMGetSlatModeName(PGMSLAT enmSlatMode);
655#endif
656VMM_INT_DECL(RTGCPHYS) PGMGetGuestCR3Phys(PVMCPU pVCpu);
657VMM_INT_DECL(void) PGMNotifyNxeChanged(PVMCPU pVCpu, bool fNxe);
658VMMDECL(bool) PGMHasDirtyPages(PVM pVM);
659VMM_INT_DECL(void) PGMSetGuestEptPtr(PVMCPUCC pVCpu, uint64_t uEptPtr);
660
661/** PGM physical access handler type registration handle (heap offset, valid
662 * cross contexts without needing fixing up). Callbacks and handler type is
663 * associated with this and it is shared by all handler registrations. */
664typedef uint64_t PGMPHYSHANDLERTYPE;
665/** Pointer to a PGM physical handler type registration handle. */
666typedef PGMPHYSHANDLERTYPE *PPGMPHYSHANDLERTYPE;
667/** NIL value for PGM physical access handler type handle. */
668#define NIL_PGMPHYSHANDLERTYPE UINT64_MAX
669VMMDECL(int) PGMHandlerPhysicalRegister(PVMCC pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast, PGMPHYSHANDLERTYPE hType,
670 uint64_t uUser, R3PTRTYPE(const char *) pszDesc);
671VMMDECL(int) PGMHandlerPhysicalRegisterVmxApicAccessPage(PVMCC pVM, RTGCPHYS GCPhys, PGMPHYSHANDLERTYPE hType);
672VMMDECL(int) PGMHandlerPhysicalModify(PVMCC pVM, RTGCPHYS GCPhysCurrent, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast);
673VMMDECL(int) PGMHandlerPhysicalDeregister(PVMCC pVM, RTGCPHYS GCPhys);
674VMMDECL(int) PGMHandlerPhysicalChangeUserArg(PVMCC pVM, RTGCPHYS GCPhys, uint64_t uUser);
675VMMDECL(int) PGMHandlerPhysicalSplit(PVMCC pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysSplit);
676VMMDECL(int) PGMHandlerPhysicalJoin(PVMCC pVM, RTGCPHYS GCPhys1, RTGCPHYS GCPhys2);
677VMMDECL(int) PGMHandlerPhysicalPageTempOff(PVMCC pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage);
678VMMDECL(int) PGMHandlerPhysicalPageAliasMmio2(PVMCC pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage,
679 PPDMDEVINS pDevIns, PGMMMIO2HANDLE hMmio2, RTGCPHYS offMMio2PageRemap);
680VMMDECL(int) PGMHandlerPhysicalPageAliasHC(PVMCC pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage, RTHCPHYS HCPhysPageRemap);
681VMMDECL(int) PGMHandlerPhysicalReset(PVMCC pVM, RTGCPHYS GCPhys);
682VMMDECL(bool) PGMHandlerPhysicalIsRegistered(PVMCC pVM, RTGCPHYS GCPhys);
683
684/** @name PGMPHYSHANDLER_F_XXX - flags for PGMR3HandlerPhysicalTypeRegister and PGMR0HandlerPhysicalTypeRegister
685 * @{ */
686/** Whether to hold the PGM lock while calling the handler or not.
687 * Mainly an optimization for PGM callers. */
688#define PGMPHYSHANDLER_F_KEEP_PGM_LOCK RT_BIT_32(0)
689/** The uUser value is a ring-0 device instance index that needs translating
690 * into a PDMDEVINS pointer before calling the handler. This is a hack to make
691 * it possible to use access handlers in devices. */
692#define PGMPHYSHANDLER_F_R0_DEVINS_IDX RT_BIT_32(1)
693/** Don't apply the access handler to VT-x and AMD-V. Only works with full pages.
694 * This is a trick for the VT-x APIC access page in nested VT-x setups. */
695#define PGMPHYSHANDLER_F_NOT_IN_HM RT_BIT_32(2)
696/** Mask of valid bits. */
697#define PGMPHYSHANDLER_F_VALID_MASK UINT32_C(7)
698/** @} */
699
700
701/**
702 * Page type.
703 *
704 * @remarks This enum has to fit in a 3-bit field (see PGMPAGE::u3Type).
705 * @remarks This is used in the saved state, so changes to it requires bumping
706 * the saved state version.
707 * @todo So, convert to \#defines!
708 */
709typedef enum PGMPAGETYPE
710{
711 /** The usual invalid zero entry. */
712 PGMPAGETYPE_INVALID = 0,
713 /** RAM page. (RWX) */
714 PGMPAGETYPE_RAM,
715 /** MMIO2 page. (RWX) */
716 PGMPAGETYPE_MMIO2,
717 /** MMIO2 page aliased over an MMIO page. (RWX)
718 * See PGMHandlerPhysicalPageAlias(). */
719 PGMPAGETYPE_MMIO2_ALIAS_MMIO,
720 /** Special page aliased over an MMIO page. (RWX)
721 * See PGMHandlerPhysicalPageAliasHC(), but this is generally only used for
722 * VT-x's APIC access page at the moment. Treated as MMIO by everyone except
723 * the shadow paging code. */
724 PGMPAGETYPE_SPECIAL_ALIAS_MMIO,
725 /** Shadowed ROM. (RWX) */
726 PGMPAGETYPE_ROM_SHADOW,
727 /** ROM page. (R-X) */
728 PGMPAGETYPE_ROM,
729 /** MMIO page. (---) */
730 PGMPAGETYPE_MMIO,
731 /** End of valid entries. */
732 PGMPAGETYPE_END
733} PGMPAGETYPE;
734AssertCompile(PGMPAGETYPE_END == 8);
735
736/** @name PGM page type predicates.
737 * @{ */
738#define PGMPAGETYPE_IS_READABLE(a_enmType) ( (a_enmType) <= PGMPAGETYPE_ROM )
739#define PGMPAGETYPE_IS_WRITEABLE(a_enmType) ( (a_enmType) <= PGMPAGETYPE_ROM_SHADOW )
740#define PGMPAGETYPE_IS_RWX(a_enmType) ( (a_enmType) <= PGMPAGETYPE_ROM_SHADOW )
741#define PGMPAGETYPE_IS_ROX(a_enmType) ( (a_enmType) == PGMPAGETYPE_ROM )
742#define PGMPAGETYPE_IS_NP(a_enmType) ( (a_enmType) == PGMPAGETYPE_MMIO )
743/** @} */
744
745/**
746 * A physical memory range.
747 *
748 * @note This layout adheres to to GIM Hyper-V specs (asserted while compiling
749 * GIM Hyper-V that uses the PGM API).
750 */
751typedef struct PGMPHYSRANGE
752{
753 /** The first address in the range. */
754 RTGCPHYS GCPhysStart;
755 /** The number of pages in the range. */
756 uint64_t cPages;
757} PGMPHYSRANGE;
758AssertCompileSize(PGMPHYSRANGE, 16);
759
760/**
761 * A list of physical memory ranges.
762 *
763 * @note This layout adheres to to GIM Hyper-V specs (asserted while compiling
764 * GIM Hyper-V that uses the PGM API).
765 */
766typedef struct PGMPHYSRANGES
767{
768 /** The number of ranges in the list. */
769 uint64_t cRanges;
770 /** Array of physical memory ranges. */
771 RT_FLEXIBLE_ARRAY_EXTENSION
772 PGMPHYSRANGE aRanges[RT_FLEXIBLE_ARRAY];
773} PGMPHYSRANGES;
774/** Pointer to a list of physical memory ranges. */
775typedef PGMPHYSRANGES *PPGMPHYSRANGES;
776/** Pointer to a const list of physical memory ranges. */
777typedef PGMPHYSRANGES const *PCPGMPHYSRANGES;
778
779
780VMM_INT_DECL(PGMPAGETYPE) PGMPhysGetPageType(PVMCC pVM, RTGCPHYS GCPhys);
781
782VMM_INT_DECL(int) PGMPhysGCPhys2HCPhys(PVMCC pVM, RTGCPHYS GCPhys, PRTHCPHYS pHCPhys);
783VMM_INT_DECL(int) PGMPhysGCPtr2HCPhys(PVMCPUCC pVCpu, RTGCPTR GCPtr, PRTHCPHYS pHCPhys);
784VMM_INT_DECL(int) PGMPhysGCPhys2CCPtr(PVMCC pVM, RTGCPHYS GCPhys, void **ppv, PPGMPAGEMAPLOCK pLock);
785VMM_INT_DECL(int) PGMPhysGCPhys2CCPtrReadOnly(PVMCC pVM, RTGCPHYS GCPhys, void const **ppv, PPGMPAGEMAPLOCK pLock);
786VMM_INT_DECL(int) PGMPhysGCPtr2CCPtr(PVMCPUCC pVCpu, RTGCPTR GCPtr, void **ppv, PPGMPAGEMAPLOCK pLock);
787VMM_INT_DECL(int) PGMPhysGCPtr2CCPtrReadOnly(PVMCPUCC pVCpu, RTGCPTR GCPtr, void const **ppv, PPGMPAGEMAPLOCK pLock);
788
789VMMDECL(bool) PGMPhysIsA20Enabled(PVMCPU pVCpu);
790VMMDECL(bool) PGMPhysIsGCPhysValid(PVMCC pVM, RTGCPHYS GCPhys);
791VMMDECL(bool) PGMPhysIsGCPhysNormal(PVMCC pVM, RTGCPHYS GCPhys);
792VMMDECL(int) PGMPhysGCPtr2GCPhys(PVMCPUCC pVCpu, RTGCPTR GCPtr, PRTGCPHYS pGCPhys);
793VMMDECL(void) PGMPhysReleasePageMappingLock(PVMCC pVM, PPGMPAGEMAPLOCK pLock);
794VMMDECL(void) PGMPhysBulkReleasePageMappingLocks(PVMCC pVM, uint32_t cPages, PPGMPAGEMAPLOCK paLock);
795
796/** @def PGM_PHYS_RW_IS_SUCCESS
797 * Check whether a PGMPhysRead, PGMPhysWrite, PGMPhysReadGCPtr or
798 * PGMPhysWriteGCPtr call completed the given task.
799 *
800 * @returns true if completed, false if not.
801 * @param a_rcStrict The status code.
802 * @sa IOM_SUCCESS
803 */
804#ifdef IN_RING3
805# define PGM_PHYS_RW_IS_SUCCESS(a_rcStrict) \
806 ( (a_rcStrict) == VINF_SUCCESS \
807 || (a_rcStrict) == VINF_EM_DBG_STOP \
808 || (a_rcStrict) == VINF_EM_DBG_EVENT \
809 || (a_rcStrict) == VINF_EM_DBG_BREAKPOINT \
810 )
811#elif defined(IN_RING0)
812# define PGM_PHYS_RW_IS_SUCCESS(a_rcStrict) \
813 ( (a_rcStrict) == VINF_SUCCESS \
814 || (a_rcStrict) == VINF_IOM_R3_MMIO_COMMIT_WRITE \
815 || (a_rcStrict) == VINF_EM_OFF \
816 || (a_rcStrict) == VINF_EM_SUSPEND \
817 || (a_rcStrict) == VINF_EM_RESET \
818 || (a_rcStrict) == VINF_EM_HALT \
819 || (a_rcStrict) == VINF_EM_DBG_STOP \
820 || (a_rcStrict) == VINF_EM_DBG_EVENT \
821 || (a_rcStrict) == VINF_EM_DBG_BREAKPOINT \
822 )
823#elif defined(IN_RC)
824# define PGM_PHYS_RW_IS_SUCCESS(a_rcStrict) \
825 ( (a_rcStrict) == VINF_SUCCESS \
826 || (a_rcStrict) == VINF_IOM_R3_MMIO_COMMIT_WRITE \
827 || (a_rcStrict) == VINF_EM_OFF \
828 || (a_rcStrict) == VINF_EM_SUSPEND \
829 || (a_rcStrict) == VINF_EM_RESET \
830 || (a_rcStrict) == VINF_EM_HALT \
831 || (a_rcStrict) == VINF_SELM_SYNC_GDT \
832 || (a_rcStrict) == VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT \
833 || (a_rcStrict) == VINF_EM_DBG_STOP \
834 || (a_rcStrict) == VINF_EM_DBG_EVENT \
835 || (a_rcStrict) == VINF_EM_DBG_BREAKPOINT \
836 )
837#endif
838/** @def PGM_PHYS_RW_DO_UPDATE_STRICT_RC
839 * Updates the return code with a new result.
840 *
841 * Both status codes must be successes according to PGM_PHYS_RW_IS_SUCCESS.
842 *
843 * @param a_rcStrict The current return code, to be updated.
844 * @param a_rcStrict2 The new return code to merge in.
845 */
846#ifdef IN_RING3
847# define PGM_PHYS_RW_DO_UPDATE_STRICT_RC(a_rcStrict, a_rcStrict2) \
848 do { \
849 Assert(rcStrict == VINF_SUCCESS); \
850 Assert(rcStrict2 == VINF_SUCCESS); \
851 } while (0)
852#elif defined(IN_RING0)
853# define PGM_PHYS_RW_DO_UPDATE_STRICT_RC(a_rcStrict, a_rcStrict2) \
854 do { \
855 Assert(PGM_PHYS_RW_IS_SUCCESS(rcStrict)); \
856 Assert(PGM_PHYS_RW_IS_SUCCESS(rcStrict2)); \
857 AssertCompile(VINF_IOM_R3_MMIO_COMMIT_WRITE > VINF_EM_LAST); \
858 if ((a_rcStrict2) == VINF_SUCCESS || (a_rcStrict) == (a_rcStrict2)) \
859 { /* likely */ } \
860 else if ( (a_rcStrict) == VINF_SUCCESS \
861 || (a_rcStrict) > (a_rcStrict2)) \
862 (a_rcStrict) = (a_rcStrict2); \
863 } while (0)
864#elif defined(IN_RC)
865# define PGM_PHYS_RW_DO_UPDATE_STRICT_RC(a_rcStrict, a_rcStrict2) \
866 do { \
867 Assert(PGM_PHYS_RW_IS_SUCCESS(rcStrict)); \
868 Assert(PGM_PHYS_RW_IS_SUCCESS(rcStrict2)); \
869 AssertCompile(VINF_SELM_SYNC_GDT > VINF_EM_LAST); \
870 AssertCompile(VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT > VINF_EM_LAST); \
871 AssertCompile(VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT < VINF_SELM_SYNC_GDT); \
872 AssertCompile(VINF_IOM_R3_MMIO_COMMIT_WRITE > VINF_EM_LAST); \
873 AssertCompile(VINF_IOM_R3_MMIO_COMMIT_WRITE > VINF_SELM_SYNC_GDT); \
874 AssertCompile(VINF_IOM_R3_MMIO_COMMIT_WRITE > VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT); \
875 if ((a_rcStrict2) == VINF_SUCCESS || (a_rcStrict) == (a_rcStrict2)) \
876 { /* likely */ } \
877 else if ((a_rcStrict) == VINF_SUCCESS) \
878 (a_rcStrict) = (a_rcStrict2); \
879 else if ( ( (a_rcStrict) > (a_rcStrict2) \
880 && ( (a_rcStrict2) <= VINF_EM_RESET \
881 || (a_rcStrict) != VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT) ) \
882 || ( (a_rcStrict2) == VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT \
883 && (a_rcStrict) > VINF_EM_RESET) ) \
884 (a_rcStrict) = (a_rcStrict2); \
885 } while (0)
886#endif
887
888VMMDECL(VBOXSTRICTRC) PGMPhysRead(PVMCC pVM, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, PGMACCESSORIGIN enmOrigin);
889VMMDECL(VBOXSTRICTRC) PGMPhysWrite(PVMCC pVM, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, PGMACCESSORIGIN enmOrigin);
890VMMDECL(VBOXSTRICTRC) PGMPhysReadGCPtr(PVMCPUCC pVCpu, void *pvDst, RTGCPTR GCPtrSrc, size_t cb, PGMACCESSORIGIN enmOrigin);
891VMMDECL(VBOXSTRICTRC) PGMPhysWriteGCPtr(PVMCPUCC pVCpu, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb, PGMACCESSORIGIN enmOrigin);
892
893VMMDECL(int) PGMPhysSimpleReadGCPhys(PVMCC pVM, void *pvDst, RTGCPHYS GCPhysSrc, size_t cb);
894VMMDECL(int) PGMPhysSimpleWriteGCPhys(PVMCC pVM, RTGCPHYS GCPhysDst, const void *pvSrc, size_t cb);
895VMMDECL(int) PGMPhysSimpleReadGCPtr(PVMCPUCC pVCpu, void *pvDst, RTGCPTR GCPtrSrc, size_t cb);
896VMMDECL(int) PGMPhysSimpleWriteGCPtr(PVMCPUCC pVCpu, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
897VMMDECL(int) PGMPhysSimpleDirtyWriteGCPtr(PVMCPUCC pVCpu, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
898
899VMM_INT_DECL(int) PGMPhysIemGCPhys2Ptr(PVMCC pVM, PVMCPUCC pVCpu, RTGCPHYS GCPhys, bool fWritable, bool fByPassHandlers, void **ppv, PPGMPAGEMAPLOCK pLock);
900VMM_INT_DECL(int) PGMPhysIemQueryAccess(PVMCC pVM, RTGCPHYS GCPhys, bool fWritable, bool fByPassHandlers);
901VMM_INT_DECL(int) PGMPhysIemGCPhys2PtrNoLock(PVMCC pVM, PVMCPUCC pVCpu, RTGCPHYS GCPhys, uint64_t const volatile *puTlbPhysRev,
902 R3R0PTRTYPE(uint8_t *) *ppb, uint64_t *pfTlb);
903/** @name Flags returned by PGMPhysIemGCPhys2PtrNoLock
904 * @{ */
905#define PGMIEMGCPHYS2PTR_F_NO_WRITE RT_BIT_32(3) /**< Not writable (IEMTLBE_F_PG_NO_WRITE). */
906#define PGMIEMGCPHYS2PTR_F_NO_READ RT_BIT_32(4) /**< Not readable (IEMTLBE_F_PG_NO_READ). */
907#define PGMIEMGCPHYS2PTR_F_NO_MAPPINGR3 RT_BIT_32(7) /**< No ring-3 mapping (IEMTLBE_F_NO_MAPPINGR3). */
908#define PGMIEMGCPHYS2PTR_F_UNASSIGNED RT_BIT_32(8) /**< Unassgined memory (IEMTLBE_F_PG_UNASSIGNED). */
909#define PGMIEMGCPHYS2PTR_F_CODE_PAGE RT_BIT_32(9) /**< Write monitored IEM code page (IEMTLBE_F_PG_CODE_PAGE). */
910/** @} */
911
912/** Information returned by PGMPhysNemQueryPageInfo. */
913typedef struct PGMPHYSNEMPAGEINFO
914{
915 /** The host physical address of the page, NIL_HCPHYS if invalid page. */
916 RTHCPHYS HCPhys;
917 /** The NEM access mode for the page, NEM_PAGE_PROT_XXX */
918 uint32_t fNemProt : 8;
919 /** The NEM state associated with the PAGE. */
920 uint32_t u2NemState : 2;
921 /** The NEM state associated with the PAGE before pgmPhysPageMakeWritable was called. */
922 uint32_t u2OldNemState : 2;
923 /** Set if the page has handler. */
924 uint32_t fHasHandlers : 1;
925 /** Set if is the zero page backing it. */
926 uint32_t fZeroPage : 1;
927 /** Set if the page has handler. */
928 PGMPAGETYPE enmType;
929} PGMPHYSNEMPAGEINFO;
930/** Pointer to page information for NEM. */
931typedef PGMPHYSNEMPAGEINFO *PPGMPHYSNEMPAGEINFO;
932/**
933 * Callback for checking that the page is in sync while under the PGM lock.
934 *
935 * NEM passes this callback to PGMPhysNemQueryPageInfo to check that the page is
936 * in-sync between PGM and the native hypervisor API in an atomic fashion.
937 *
938 * @returns VBox status code.
939 * @param pVM The cross context VM structure.
940 * @param pVCpu The cross context per virtual CPU structure. Optional,
941 * see PGMPhysNemQueryPageInfo.
942 * @param GCPhys The guest physical address (not A20 masked).
943 * @param pInfo The page info structure. This function updates the
944 * u2NemState memory and the caller will update the PGMPAGE
945 * copy accordingly.
946 * @param pvUser Callback user argument.
947 */
948typedef DECLCALLBACKTYPE(int, FNPGMPHYSNEMCHECKPAGE,(PVMCC pVM, PVMCPUCC pVCpu, RTGCPHYS GCPhys, PPGMPHYSNEMPAGEINFO pInfo, void *pvUser));
949/** Pointer to a FNPGMPHYSNEMCHECKPAGE function. */
950typedef FNPGMPHYSNEMCHECKPAGE *PFNPGMPHYSNEMCHECKPAGE;
951
952VMM_INT_DECL(int) PGMPhysNemPageInfoChecker(PVMCC pVM, PVMCPUCC pVCpu, RTGCPHYS GCPhys, bool fMakeWritable,
953 PPGMPHYSNEMPAGEINFO pInfo, PFNPGMPHYSNEMCHECKPAGE pfnChecker, void *pvUser);
954
955/**
956 * Callback for use with PGMPhysNemEnumPagesByState.
957 * @returns VBox status code.
958 * Failure status will stop enumeration immediately and return.
959 * @param pVM The cross context VM structure.
960 * @param pVCpu The cross context per virtual CPU structure. Optional,
961 * see PGMPhysNemEnumPagesByState.
962 * @param GCPhys The guest physical address (not A20 masked).
963 * @param pu2NemState Pointer to variable with the NEM state. This can be
964 * update.
965 * @param pvUser The user argument.
966 */
967typedef DECLCALLBACKTYPE(int, FNPGMPHYSNEMENUMCALLBACK,(PVMCC pVM, PVMCPUCC pVCpu, RTGCPHYS GCPhys,
968 uint8_t *pu2NemState, void *pvUser));
969/** Pointer to a FNPGMPHYSNEMENUMCALLBACK function. */
970typedef FNPGMPHYSNEMENUMCALLBACK *PFNPGMPHYSNEMENUMCALLBACK;
971VMM_INT_DECL(int) PGMPhysNemEnumPagesByState(PVMCC pVM, PVMCPUCC VCpu, uint8_t uMinState,
972 PFNPGMPHYSNEMENUMCALLBACK pfnCallback, void *pvUser);
973
974
975#ifdef VBOX_STRICT
976VMMDECL(unsigned) PGMAssertHandlerAndFlagsInSync(PVMCC pVM);
977VMMDECL(unsigned) PGMAssertNoMappingConflicts(PVM pVM);
978VMMDECL(unsigned) PGMAssertCR3(PVMCC pVM, PVMCPUCC pVCpu, uint64_t cr3, uint64_t cr4);
979#endif /* VBOX_STRICT */
980
981VMMDECL(int) PGMSetLargePageUsage(PVMCC pVM, bool fUseLargePages);
982
983/**
984 * Query large page usage state
985 *
986 * @returns 0 - disabled, 1 - enabled
987 * @param pVM The cross context VM structure.
988 */
989#define PGMIsUsingLargePages(pVM) ((pVM)->pgm.s.fUseLargePages)
990
991
992/** @defgroup grp_pgm_r0 The PGM Host Context Ring-0 API
993 * @{
994 */
995#ifdef IN_RING0
996VMMR0_INT_DECL(int) PGMR0InitPerVMData(PGVM pGVM, RTR0MEMOBJ hMemObj);
997VMMR0_INT_DECL(int) PGMR0InitVM(PGVM pGVM);
998VMMR0_INT_DECL(void) PGMR0DoneInitVM(PGVM pGVM);
999VMMR0_INT_DECL(void) PGMR0CleanupVM(PGVM pGVM);
1000VMMR0_INT_DECL(int) PGMR0PhysAllocateHandyPages(PGVM pGVM, VMCPUID idCpu);
1001VMMR0_INT_DECL(int) PGMR0PhysFlushHandyPages(PGVM pGVM, VMCPUID idCpu);
1002VMMR0_INT_DECL(int) PGMR0PhysAllocateLargePage(PGVM pGVM, VMCPUID idCpu, RTGCPHYS GCPhys);
1003VMMR0_INT_DECL(int) PGMR0PhysMMIO2MapKernel(PGVM pGVM, PPDMDEVINS pDevIns, PGMMMIO2HANDLE hMmio2,
1004 size_t offSub, size_t cbSub, void **ppvMapping);
1005VMMR0_INT_DECL(int) PGMR0PhysSetupIoMmu(PGVM pGVM);
1006VMMR0_INT_DECL(int) PGMR0PhysHandlerInitReqHandler(PGVM pGVM, uint32_t cEntries);
1007
1008VMMR0_INT_DECL(int) PGMR0HandlerPhysicalTypeSetUpContext(PGVM pGVM, PGMPHYSHANDLERKIND enmKind, uint32_t fFlags,
1009 PFNPGMPHYSHANDLER pfnHandler, PFNPGMRZPHYSPFHANDLER pfnPfHandler,
1010 const char *pszDesc, PGMPHYSHANDLERTYPE hType);
1011
1012VMMR0DECL(int) PGMR0SharedModuleCheck(PVMCC pVM, PGVM pGVM, VMCPUID idCpu, PGMMSHAREDMODULE pModule,
1013 PCRTGCPTR64 paRegionsGCPtrs);
1014VMMR0DECL(int) PGMR0Trap0eHandlerNestedPaging(PGVM pGVM, PGVMCPU pGVCpu, PGMMODE enmShwPagingMode, RTGCUINT uErr,
1015 PCPUMCTX pCtx, RTGCPHYS pvFault);
1016VMMR0DECL(VBOXSTRICTRC) PGMR0Trap0eHandlerNPMisconfig(PGVM pGVM, PGVMCPU pGVCpu, PGMMODE enmShwPagingMode,
1017 PCPUMCTX pCtx, RTGCPHYS GCPhysFault, uint32_t uErr);
1018VMMR0_INT_DECL(int) PGMR0PoolGrow(PGVM pGVM, VMCPUID idCpu);
1019
1020# ifdef VBOX_WITH_NESTED_HWVIRT_VMX_EPT
1021VMMR0DECL(VBOXSTRICTRC) PGMR0NestedTrap0eHandlerNestedPaging(PGVMCPU pGVCpu, PGMMODE enmShwPagingMode, RTGCUINT uErr,
1022 PCPUMCTX pCtx, RTGCPHYS GCPhysNestedFault,
1023 bool fIsLinearAddrValid, RTGCPTR GCPtrNestedFault, PPGMPTWALK pWalk);
1024# endif
1025#endif /* IN_RING0 */
1026
1027/**
1028 * Request buffer for PGMR0PhysAllocateRamRangeReq / VMMR0_DO_PGM_PHYS_ALLOCATE_RAM_RANGE
1029 */
1030typedef struct PGMPHYSALLOCATERAMRANGEREQ
1031{
1032 /** The header. */
1033 SUPVMMR0REQHDR Hdr;
1034 /** Input: the GUEST_PAGE_SIZE value (for validation). */
1035 uint32_t cbGuestPage;
1036 /** Input: Number of guest pages in the range. */
1037 uint32_t cGuestPages;
1038 /** Input: The RAM range flags (PGM_RAM_RANGE_FLAGS_XXX). */
1039 uint32_t fFlags;
1040 /** Output: The range identifier. */
1041 uint32_t idNewRange;
1042} PGMPHYSALLOCATERAMRANGEREQ;
1043/** Pointer to a PGMR0PhysAllocateRamRangeReq / VMMR0_DO_PGM_PHYS_ALLOCATE_RAM_RANGE request buffer. */
1044typedef PGMPHYSALLOCATERAMRANGEREQ *PPGMPHYSALLOCATERAMRANGEREQ;
1045
1046VMMR0_INT_DECL(int) PGMR0PhysAllocateRamRangeReq(PGVM pGVM, PPGMPHYSALLOCATERAMRANGEREQ pReq);
1047
1048
1049/**
1050 * Request buffer for PGMR0PhysMmio2RegisterReq / VMMR0_DO_PGM_PHYS_MMIO2_REGISTER
1051 */
1052typedef struct PGMPHYSMMIO2REGISTERREQ
1053{
1054 /** The header. */
1055 SUPVMMR0REQHDR Hdr;
1056 /** Input: the GUEST_PAGE_SIZE value (for validation). */
1057 uint32_t cbGuestPage;
1058 /** Input: Number of guest pages in the MMIO2 range. */
1059 uint32_t cGuestPages;
1060 /** Input: The MMIO2 ID of the first chunk. */
1061 uint8_t idMmio2;
1062 /** Input: The number of MMIO2 chunks needed. */
1063 uint8_t cChunks;
1064 /** Input: The sub-device number. */
1065 uint8_t iSubDev;
1066 /** Input: The device region number. */
1067 uint8_t iRegion;
1068 /** Input: Flags (PGMPHYS_MMIO2_FLAGS_XXX). */
1069 uint32_t fFlags;
1070 /** Input: The owner device key. */
1071 PPDMDEVINSR3 pDevIns;
1072} PGMPHYSMMIO2REGISTERREQ;
1073/** Pointer to a PGMR0PhysAllocateRamRangeReq / VMMR0_DO_PGM_PHYS_MMIO2_REGISTER request buffer. */
1074typedef PGMPHYSMMIO2REGISTERREQ *PPGMPHYSMMIO2REGISTERREQ;
1075
1076VMMR0_INT_DECL(int) PGMR0PhysMmio2RegisterReq(PGVM pGVM, PPGMPHYSMMIO2REGISTERREQ pReq);
1077
1078
1079/*
1080 * Request buffer for PGMR0PhysMmio2DeregisterReq / VMMR0_DO_PGM_PHYS_MMIO2_DEREGISTER
1081 */
1082typedef struct PGMPHYSMMIO2DEREGISTERREQ
1083{
1084 /** The header. */
1085 SUPVMMR0REQHDR Hdr;
1086 /** Input: The MMIO2 ID of the first chunk. */
1087 uint8_t idMmio2;
1088 /** Input: The number of MMIO2 chunks to free. */
1089 uint8_t cChunks;
1090 /** Input: Reserved and must be zero. */
1091 uint8_t abReserved[6];
1092 /** Input: The owner device key. */
1093 PPDMDEVINSR3 pDevIns;
1094} PGMPHYSMMIO2DEREGISTERREQ;
1095/** Pointer to a PGMR0PhysMmio2DeregisterReq / VMMR0_DO_PGM_PHYS_MMIO2_DEREGISTER request buffer. */
1096typedef PGMPHYSMMIO2DEREGISTERREQ *PPGMPHYSMMIO2DEREGISTERREQ;
1097
1098VMMR0_INT_DECL(int) PGMR0PhysMmio2DeregisterReq(PGVM pGVM, PPGMPHYSMMIO2DEREGISTERREQ pReq);
1099
1100/*
1101 * Request buffer for PGMR0PhysRomAllocateRangeReq / VMMR0_DO_PGM_PHYS_ROM_ALLOCATE_RANGE
1102 */
1103typedef struct PGMPHYSROMALLOCATERANGEREQ
1104{
1105 /** The header. */
1106 SUPVMMR0REQHDR Hdr;
1107 /** Input: the GUEST_PAGE_SIZE value (for validation). */
1108 uint32_t cbGuestPage;
1109 /** Input: Number of guest pages in the range. */
1110 uint32_t cGuestPages;
1111 /** Input: The ROM range ID (index) to be allocated. */
1112 uint32_t idRomRange;
1113 /** Input: The ROM range flags (PGMPHYS_ROM_FLAGS_XXX). */
1114 uint32_t fFlags;
1115} PGMPHYSROMALLOCATERANGEREQ;
1116/* Pointer to a PGMR0PhysRomAllocateRangeReq / VMMR0_DO_PGM_PHYS_ROM_ALLOCATE_RANGE request buffer. */
1117typedef PGMPHYSROMALLOCATERANGEREQ *PPGMPHYSROMALLOCATERANGEREQ;
1118
1119VMMR0_INT_DECL(int) PGMR0PhysRomAllocateRangeReq(PGVM pGVM, PPGMPHYSROMALLOCATERANGEREQ pReq);
1120
1121
1122/** @} */
1123
1124
1125
1126/** @defgroup grp_pgm_r3 The PGM Host Context Ring-3 API
1127 * @{
1128 */
1129#ifdef IN_RING3
1130VMMR3_INT_DECL(void) PGMR3EnableNemMode(PVM pVM);
1131VMMR3_INT_DECL(bool) PGMR3IsNemModeEnabled(PVM pVM);
1132VMMR3DECL(int) PGMR3Init(PVM pVM);
1133VMMR3DECL(int) PGMR3InitFinalize(PVM pVM);
1134VMMR3_INT_DECL(int) PGMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
1135VMMR3DECL(void) PGMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
1136VMMR3DECL(void) PGMR3ResetCpu(PVM pVM, PVMCPU pVCpu);
1137VMMR3_INT_DECL(void) PGMR3Reset(PVM pVM);
1138VMMR3_INT_DECL(void) PGMR3ResetNoMorePhysWritesFlag(PVM pVM);
1139VMMR3_INT_DECL(void) PGMR3MemSetup(PVM pVM, bool fReset);
1140VMMR3DECL(int) PGMR3Term(PVM pVM);
1141
1142VMMR3DECL(int) PGMR3PhysRegisterRam(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, const char *pszDesc);
1143VMMR3DECL(int) PGMR3PhysChangeMemBalloon(PVM pVM, bool fInflate, unsigned cPages, RTGCPHYS *paPhysPage);
1144VMMR3DECL(int) PGMR3PhysWriteProtectRAM(PVM pVM);
1145VMMR3DECL(uint32_t) PGMR3PhysGetRamRangeCount(PVM pVM);
1146VMMR3DECL(int) PGMR3PhysGetRange(PVM pVM, uint32_t iRange, PRTGCPHYS pGCPhysStart, PRTGCPHYS pGCPhysLast,
1147 const char **ppszDesc, bool *pfIsMmio);
1148VMMR3_INT_DECL(int) PGMR3PhysGetRamBootZeroedRanges(PVM pVM, PPGMPHYSRANGES pRanges, uint32_t cMaxRanges);
1149VMMR3DECL(int) PGMR3QueryMemoryStats(PUVM pUVM, uint64_t *pcbTotalMem, uint64_t *pcbPrivateMem, uint64_t *pcbSharedMem, uint64_t *pcbZeroMem);
1150VMMR3DECL(int) PGMR3QueryGlobalMemoryStats(PUVM pUVM, uint64_t *pcbAllocMem, uint64_t *pcbFreeMem, uint64_t *pcbBallonedMem, uint64_t *pcbSharedMem);
1151
1152VMMR3_INT_DECL(int) PGMR3PhysMmioRegister(PVM pVM, PVMCPU pVCpu, RTGCPHYS cb, const char *pszDesc, uint16_t *pidRamRange);
1153VMMR3_INT_DECL(int) PGMR3PhysMmioMap(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, RTGCPHYS cb, uint16_t idRamRange,
1154 PGMPHYSHANDLERTYPE hType, uint64_t uUser);
1155VMMR3_INT_DECL(int) PGMR3PhysMmioUnmap(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, RTGCPHYS cb, uint16_t idRamRange);
1156#endif /* IN_RING3 */
1157
1158/** @name PGMPHYS_MMIO2_FLAGS_XXX - MMIO2 registration flags.
1159 * @see PGMR3PhysMmio2Register, PDMDevHlpMmio2Create
1160 * @{ */
1161/** Track dirty pages.
1162 * @see PGMR3PhysMmio2QueryAndResetDirtyBitmap(), PGMR3PhysMmio2ControlDirtyPageTracking(). */
1163#define PGMPHYS_MMIO2_FLAGS_TRACK_DIRTY_PAGES RT_BIT_32(0)
1164/** Valid flags. */
1165#define PGMPHYS_MMIO2_FLAGS_VALID_MASK UINT32_C(0x00000001)
1166/** @} */
1167
1168#ifdef IN_RING3
1169VMMR3_INT_DECL(int) PGMR3PhysMmio2Register(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS cb,
1170 uint32_t fFlags, const char *pszDesc, void **ppv, PGMMMIO2HANDLE *phRegion);
1171VMMR3_INT_DECL(int) PGMR3PhysMmio2Deregister(PVM pVM, PPDMDEVINS pDevIns, PGMMMIO2HANDLE hMmio2);
1172VMMR3_INT_DECL(int) PGMR3PhysMmio2Map(PVM pVM, PPDMDEVINS pDevIns, PGMMMIO2HANDLE hMmio2, RTGCPHYS GCPhys);
1173VMMR3_INT_DECL(int) PGMR3PhysMmio2Unmap(PVM pVM, PPDMDEVINS pDevIns, PGMMMIO2HANDLE hMmio2, RTGCPHYS GCPhys);
1174VMMR3_INT_DECL(int) PGMR3PhysMmio2Reduce(PVM pVM, PPDMDEVINS pDevIns, PGMMMIO2HANDLE hMmio2, RTGCPHYS cbRegion);
1175VMMR3_INT_DECL(int) PGMR3PhysMmio2ValidateHandle(PVM pVM, PPDMDEVINS pDevIns, PGMMMIO2HANDLE hMmio2);
1176VMMR3_INT_DECL(RTGCPHYS) PGMR3PhysMmio2GetMappingAddress(PVM pVM, PPDMDEVINS pDevIns, PGMMMIO2HANDLE hMmio2);
1177VMMR3_INT_DECL(int) PGMR3PhysMmio2ChangeRegionNo(PVM pVM, PPDMDEVINS pDevIns, PGMMMIO2HANDLE hMmio2, uint32_t iNewRegion);
1178VMMR3_INT_DECL(int) PGMR3PhysMmio2QueryAndResetDirtyBitmap(PVM pVM, PPDMDEVINS pDevIns, PGMMMIO2HANDLE hMmio2,
1179 void *pvBitmap, size_t cbBitmap);
1180VMMR3_INT_DECL(int) PGMR3PhysMmio2ControlDirtyPageTracking(PVM pVM, PPDMDEVINS pDevIns, PGMMMIO2HANDLE hMmio2, bool fEnabled);
1181#endif /* IN_RING3 */
1182
1183/** @name PGMPHYS_ROM_FLAGS_XXX - ROM registration flags.
1184 * @see PGMR3PhysRegisterRom, PDMDevHlpROMRegister
1185 * @{ */
1186/** Inidicates that ROM shadowing should be enabled. */
1187#define PGMPHYS_ROM_FLAGS_SHADOWED UINT8_C(0x01)
1188/** Indicates that what pvBinary points to won't go away
1189 * and can be used for strictness checks. */
1190#define PGMPHYS_ROM_FLAGS_PERMANENT_BINARY UINT8_C(0x02)
1191/** Indicates that the ROM is allowed to be missing from saved state.
1192 * @note This is a hack for EFI, see @bugref{6940} */
1193#define PGMPHYS_ROM_FLAGS_MAYBE_MISSING_FROM_STATE UINT8_C(0x04)
1194/** Valid flags. */
1195#define PGMPHYS_ROM_FLAGS_VALID_MASK UINT8_C(0x07)
1196/** @} */
1197
1198#ifdef IN_RING3
1199VMMR3DECL(int) PGMR3PhysRomRegister(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPHYS cb,
1200 const void *pvBinary, uint32_t cbBinary, uint8_t fFlags, const char *pszDesc);
1201VMMR3DECL(int) PGMR3PhysRomProtect(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, PGMROMPROT enmProt);
1202VMMDECL(void) PGMR3PhysSetA20(PVMCPU pVCpu, bool fEnable);
1203
1204VMMR3_INT_DECL(int) PGMR3HandlerPhysicalTypeRegister(PVM pVM, PGMPHYSHANDLERKIND enmKind, uint32_t fFlags,
1205 PFNPGMPHYSHANDLER pfnHandlerR3, const char *pszDesc,
1206 PPGMPHYSHANDLERTYPE phType);
1207
1208VMMR3_INT_DECL(int) PGMR3PoolGrow(PVM pVM, PVMCPU pVCpu);
1209
1210VMMR3DECL(int) PGMR3PhysTlbGCPhys2Ptr(PVM pVM, RTGCPHYS GCPhys, bool fWritable, void **ppv);
1211VMMR3DECL(uint8_t) PGMR3PhysReadU8(PVM pVM, RTGCPHYS GCPhys, PGMACCESSORIGIN enmOrigin);
1212VMMR3DECL(uint16_t) PGMR3PhysReadU16(PVM pVM, RTGCPHYS GCPhys, PGMACCESSORIGIN enmOrigin);
1213VMMR3DECL(uint32_t) PGMR3PhysReadU32(PVM pVM, RTGCPHYS GCPhys, PGMACCESSORIGIN enmOrigin);
1214VMMR3DECL(uint64_t) PGMR3PhysReadU64(PVM pVM, RTGCPHYS GCPhys, PGMACCESSORIGIN enmOrigin);
1215VMMR3DECL(void) PGMR3PhysWriteU8(PVM pVM, RTGCPHYS GCPhys, uint8_t Value, PGMACCESSORIGIN enmOrigin);
1216VMMR3DECL(void) PGMR3PhysWriteU16(PVM pVM, RTGCPHYS GCPhys, uint16_t Value, PGMACCESSORIGIN enmOrigin);
1217VMMR3DECL(void) PGMR3PhysWriteU32(PVM pVM, RTGCPHYS GCPhys, uint32_t Value, PGMACCESSORIGIN enmOrigin);
1218VMMR3DECL(void) PGMR3PhysWriteU64(PVM pVM, RTGCPHYS GCPhys, uint64_t Value, PGMACCESSORIGIN enmOrigin);
1219VMMR3DECL(int) PGMR3PhysReadExternal(PVM pVM, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, PGMACCESSORIGIN enmOrigin);
1220VMMR3DECL(int) PGMR3PhysWriteExternal(PVM pVM, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, PGMACCESSORIGIN enmOrigin);
1221VMMR3DECL(int) PGMR3PhysGCPhys2CCPtrExternal(PVM pVM, RTGCPHYS GCPhys, void **ppv, PPGMPAGEMAPLOCK pLock);
1222VMMR3DECL(int) PGMR3PhysGCPhys2CCPtrReadOnlyExternal(PVM pVM, RTGCPHYS GCPhys, void const **ppv, PPGMPAGEMAPLOCK pLock);
1223VMMR3DECL(int) PGMR3PhysBulkGCPhys2CCPtrExternal(PVM pVM, uint32_t cPages, PCRTGCPHYS paGCPhysPages,
1224 void **papvPages, PPGMPAGEMAPLOCK paLocks);
1225VMMR3DECL(int) PGMR3PhysBulkGCPhys2CCPtrReadOnlyExternal(PVM pVM, uint32_t cPages, PCRTGCPHYS paGCPhysPages,
1226 void const **papvPages, PPGMPAGEMAPLOCK paLocks);
1227VMMR3DECL(int) PGMR3PhysAllocateHandyPages(PVM pVM);
1228
1229VMMR3DECL(int) PGMR3CheckIntegrity(PVM pVM);
1230
1231VMMR3DECL(int) PGMR3DbgR3Ptr2GCPhys(PUVM pUVM, RTR3PTR R3Ptr, PRTGCPHYS pGCPhys);
1232VMMR3DECL(int) PGMR3DbgR3Ptr2HCPhys(PUVM pUVM, RTR3PTR R3Ptr, PRTHCPHYS pHCPhys);
1233VMMR3DECL(int) PGMR3DbgHCPhys2GCPhys(PUVM pUVM, RTHCPHYS HCPhys, PRTGCPHYS pGCPhys);
1234VMMR3_INT_DECL(int) PGMR3DbgReadGCPhys(PVM pVM, void *pvDst, RTGCPHYS GCPhysSrc, size_t cb, uint32_t fFlags, size_t *pcbRead);
1235VMMR3_INT_DECL(int) PGMR3DbgWriteGCPhys(PVM pVM, RTGCPHYS GCPhysDst, const void *pvSrc, size_t cb, uint32_t fFlags, size_t *pcbWritten);
1236VMMR3_INT_DECL(int) PGMR3DbgReadGCPtr(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb, uint32_t fFlags, size_t *pcbRead);
1237VMMR3_INT_DECL(int) PGMR3DbgWriteGCPtr(PVM pVM, RTGCPTR GCPtrDst, void const *pvSrc, size_t cb, uint32_t fFlags, size_t *pcbWritten);
1238VMMR3_INT_DECL(int) PGMR3DbgScanPhysical(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cbRange, RTGCPHYS GCPhysAlign, const uint8_t *pabNeedle, size_t cbNeedle, PRTGCPHYS pGCPhysHit);
1239VMMR3_INT_DECL(int) PGMR3DbgScanVirtual(PVM pVM, PVMCPU pVCpu, RTGCPTR GCPtr, RTGCPTR cbRange, RTGCPTR GCPtrAlign, const uint8_t *pabNeedle, size_t cbNeedle, PRTGCUINTPTR pGCPhysHit);
1240VMMR3_INT_DECL(int) PGMR3DumpHierarchyShw(PVM pVM, uint64_t cr3, uint32_t fFlags, uint64_t u64FirstAddr, uint64_t u64LastAddr, uint32_t cMaxDepth, PCDBGFINFOHLP pHlp);
1241VMMR3_INT_DECL(int) PGMR3DumpHierarchyGst(PVM pVM, uint64_t cr3, uint32_t fFlags, RTGCPTR FirstAddr, RTGCPTR LastAddr, uint32_t cMaxDepth, PCDBGFINFOHLP pHlp);
1242#endif /* IN_RING3 */
1243
1244/** @name Page sharing
1245 * @{ */
1246#ifdef IN_RING3
1247VMMR3DECL(int) PGMR3SharedModuleRegister(PVM pVM, VBOXOSFAMILY enmGuestOS, char *pszModuleName, char *pszVersion,
1248 RTGCPTR GCBaseAddr, uint32_t cbModule,
1249 uint32_t cRegions, VMMDEVSHAREDREGIONDESC const *paRegions);
1250VMMR3DECL(int) PGMR3SharedModuleUnregister(PVM pVM, char *pszModuleName, char *pszVersion,
1251 RTGCPTR GCBaseAddr, uint32_t cbModule);
1252VMMR3DECL(int) PGMR3SharedModuleCheckAll(PVM pVM);
1253VMMR3DECL(int) PGMR3SharedModuleGetPageState(PVM pVM, RTGCPTR GCPtrPage, bool *pfShared, uint64_t *pfPageFlags);
1254#endif /* IN_RING3 */
1255/** @} */
1256
1257/** @} */
1258
1259RT_C_DECLS_END
1260
1261/** @} */
1262#endif /* !VBOX_INCLUDED_vmm_pgm_h */
1263
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