VirtualBox

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

Last change on this file since 76886 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 46.8 KB
Line 
1/** @file
2 * PGM - Page Monitor / Monitor.
3 */
4
5/*
6 * Copyright (C) 2006-2019 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef VBOX_INCLUDED_vmm_pgm_h
27#define VBOX_INCLUDED_vmm_pgm_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <VBox/types.h>
33#include <VBox/sup.h>
34#include <VBox/vmm/vmapi.h>
35#include <VBox/vmm/gmm.h> /* for PGMMREGISTERSHAREDMODULEREQ */
36#include <iprt/x86.h>
37#include <VBox/param.h>
38
39RT_C_DECLS_BEGIN
40
41/** @defgroup grp_pgm The Page Monitor / Manager API
42 * @ingroup grp_vmm
43 * @{
44 */
45
46/**
47 * FNPGMRELOCATE callback mode.
48 */
49typedef enum PGMRELOCATECALL
50{
51 /** The callback is for checking if the suggested address is suitable. */
52 PGMRELOCATECALL_SUGGEST = 1,
53 /** The callback is for executing the relocation. */
54 PGMRELOCATECALL_RELOCATE
55} PGMRELOCATECALL;
56
57
58/**
59 * Callback function which will be called when PGM is trying to find
60 * a new location for the mapping.
61 *
62 * The callback is called in two modes, 1) the check mode and 2) the relocate mode.
63 * In 1) the callback should say if it objects to a suggested new location. If it
64 * accepts the new location, it is called again for doing it's relocation.
65 *
66 *
67 * @returns true if the location is ok.
68 * @returns false if another location should be found.
69 * @param pVM The cross context VM structure.
70 * @param GCPtrOld The old virtual address.
71 * @param GCPtrNew The new virtual address.
72 * @param enmMode Used to indicate the callback mode.
73 * @param pvUser User argument.
74 * @remark The return value is no a failure indicator, it's an acceptance
75 * indicator. Relocation can not fail!
76 */
77typedef DECLCALLBACK(bool) FNPGMRELOCATE(PVM pVM, RTGCPTR GCPtrOld, RTGCPTR GCPtrNew, PGMRELOCATECALL enmMode, void *pvUser);
78/** Pointer to a relocation callback function. */
79typedef FNPGMRELOCATE *PFNPGMRELOCATE;
80
81
82/**
83 * Memory access origin.
84 */
85typedef enum PGMACCESSORIGIN
86{
87 /** Invalid zero value. */
88 PGMACCESSORIGIN_INVALID = 0,
89 /** IEM is access memory. */
90 PGMACCESSORIGIN_IEM,
91 /** HM is access memory. */
92 PGMACCESSORIGIN_HM,
93 /** Some device is access memory. */
94 PGMACCESSORIGIN_DEVICE,
95 /** Someone debugging is access memory. */
96 PGMACCESSORIGIN_DEBUGGER,
97 /** SELM is access memory. */
98 PGMACCESSORIGIN_SELM,
99 /** FTM is access memory. */
100 PGMACCESSORIGIN_FTM,
101 /** REM is access memory. */
102 PGMACCESSORIGIN_REM,
103 /** IOM is access memory. */
104 PGMACCESSORIGIN_IOM,
105 /** End of valid values. */
106 PGMACCESSORIGIN_END,
107 /** Type size hack. */
108 PGMACCESSORIGIN_32BIT_HACK = 0x7fffffff
109} PGMACCESSORIGIN;
110
111
112/**
113 * Physical page access handler kind.
114 */
115typedef enum PGMPHYSHANDLERKIND
116{
117 /** MMIO range. Pages are not present, all access is done in interpreter or recompiler. */
118 PGMPHYSHANDLERKIND_MMIO = 1,
119 /** Handler all write access to a physical page range. */
120 PGMPHYSHANDLERKIND_WRITE,
121 /** Handler all access to a physical page range. */
122 PGMPHYSHANDLERKIND_ALL
123
124} PGMPHYSHANDLERKIND;
125
126/**
127 * Guest Access type
128 */
129typedef enum PGMACCESSTYPE
130{
131 /** Read access. */
132 PGMACCESSTYPE_READ = 1,
133 /** Write access. */
134 PGMACCESSTYPE_WRITE
135} PGMACCESSTYPE;
136
137
138/** @def PGM_ALL_CB_DECL
139 * Macro for declaring a handler callback for all contexts. The handler
140 * callback is static in ring-3, and exported in RC and R0.
141 * @sa PGM_ALL_CB2_DECL.
142 */
143#if defined(IN_RC) || defined(IN_RING0)
144# ifdef __cplusplus
145# define PGM_ALL_CB_DECL(type) extern "C" DECLCALLBACK(DECLEXPORT(type))
146# else
147# define PGM_ALL_CB_DECL(type) DECLCALLBACK(DECLEXPORT(type))
148# endif
149#else
150# define PGM_ALL_CB_DECL(type) static DECLCALLBACK(type)
151#endif
152
153/** @def PGM_ALL_CB2_DECL
154 * Macro for declaring a handler callback for all contexts. The handler
155 * callback is hidden in ring-3, and exported in RC and R0.
156 * @sa PGM_ALL_CB2_DECL.
157 */
158#if defined(IN_RC) || defined(IN_RING0)
159# ifdef __cplusplus
160# define PGM_ALL_CB2_DECL(type) extern "C" DECLCALLBACK(DECLEXPORT(type))
161# else
162# define PGM_ALL_CB2_DECL(type) DECLCALLBACK(DECLEXPORT(type))
163# endif
164#else
165# define PGM_ALL_CB2_DECL(type) DECLCALLBACK(DECLHIDDEN(type))
166#endif
167
168/** @def PGM_ALL_CB2_PROTO
169 * Macro for declaring a handler callback for all contexts. The handler
170 * callback is hidden in ring-3, and exported in RC and R0.
171 * @param fnType The callback function type.
172 * @sa PGM_ALL_CB2_DECL.
173 */
174#if defined(IN_RC) || defined(IN_RING0)
175# ifdef __cplusplus
176# define PGM_ALL_CB2_PROTO(fnType) extern "C" DECLEXPORT(fnType)
177# else
178# define PGM_ALL_CB2_PROTO(fnType) DECLEXPORT(fnType)
179# endif
180#else
181# define PGM_ALL_CB2_PROTO(fnType) DECLHIDDEN(fnType)
182#endif
183
184
185/**
186 * \#PF Handler callback for physical access handler ranges in RC and R0.
187 *
188 * @returns Strict VBox status code (appropriate for ring-0 and raw-mode).
189 * @param pVM The cross context VM structure.
190 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
191 * @param uErrorCode CPU Error code.
192 * @param pRegFrame Trap register frame.
193 * NULL on DMA and other non CPU access.
194 * @param pvFault The fault address (cr2).
195 * @param GCPhysFault The GC physical address corresponding to pvFault.
196 * @param pvUser User argument.
197 * @thread EMT(pVCpu)
198 */
199typedef DECLCALLBACK(VBOXSTRICTRC) FNPGMRZPHYSPFHANDLER(PVM pVM, PVMCPU pVCpu, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame,
200 RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
201/** Pointer to PGM access callback. */
202typedef FNPGMRZPHYSPFHANDLER *PFNPGMRZPHYSPFHANDLER;
203
204
205/**
206 * Access handler callback for physical access handler ranges.
207 *
208 * The handler can not raise any faults, it's mainly for monitoring write access
209 * to certain pages (like MMIO).
210 *
211 * @returns Strict VBox status code in ring-0 and raw-mode context, in ring-3
212 * the only supported informational status code is
213 * VINF_PGM_HANDLER_DO_DEFAULT.
214 * @retval VINF_SUCCESS if the handler have carried out the operation.
215 * @retval VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the
216 * access operation.
217 * @retval VINF_EM_XXX in ring-0 and raw-mode context.
218 *
219 * @param pVM The cross context VM structure.
220 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
221 * @param GCPhys The physical address the guest is writing to.
222 * @param pvPhys The HC mapping of that address.
223 * @param pvBuf What the guest is reading/writing.
224 * @param cbBuf How much it's reading/writing.
225 * @param enmAccessType The access type.
226 * @param enmOrigin The origin of this call.
227 * @param pvUser User argument.
228 * @thread EMT(pVCpu)
229 */
230typedef DECLCALLBACK(VBOXSTRICTRC) FNPGMPHYSHANDLER(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf,
231 PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, void *pvUser);
232/** Pointer to PGM access callback. */
233typedef FNPGMPHYSHANDLER *PFNPGMPHYSHANDLER;
234
235
236/**
237 * Virtual access handler type.
238 */
239typedef enum PGMVIRTHANDLERKIND
240{
241 /** Write access handled. */
242 PGMVIRTHANDLERKIND_WRITE = 1,
243 /** All access handled. */
244 PGMVIRTHANDLERKIND_ALL,
245 /** Hypervisor write access handled.
246 * This is used to catch the guest trying to write to LDT, TSS and any other
247 * system structure which the brain dead intel guys let unprivilegde code find. */
248 PGMVIRTHANDLERKIND_HYPERVISOR
249} PGMVIRTHANDLERKIND;
250
251/**
252 * \#PF handler callback for virtual access handler ranges, RC.
253 *
254 * Important to realize that a physical page in a range can have aliases, and
255 * for ALL and WRITE handlers these will also trigger.
256 *
257 * @returns Strict VBox status code (appropriate for raw-mode).
258 * @param pVM The cross context VM structure.
259 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
260 * @param uErrorCode CPU Error code (X86_TRAP_PF_XXX).
261 * @param pRegFrame Trap register frame.
262 * @param pvFault The fault address (cr2).
263 * @param pvRange The base address of the handled virtual range.
264 * @param offRange The offset of the access into this range.
265 * (If it's a EIP range this is the EIP, if not it's pvFault.)
266 * @param pvUser User argument.
267 * @thread EMT(pVCpu)
268 */
269typedef DECLCALLBACK(VBOXSTRICTRC) FNPGMRCVIRTPFHANDLER(PVM pVM, PVMCPU pVCpu, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame,
270 RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange, void *pvUser);
271/** Pointer to PGM access callback. */
272typedef FNPGMRCVIRTPFHANDLER *PFNPGMRCVIRTPFHANDLER;
273
274/**
275 * Access handler callback for virtual access handler ranges.
276 *
277 * Important to realize that a physical page in a range can have aliases, and
278 * for ALL and WRITE handlers these will also trigger.
279 *
280 * @returns VINF_SUCCESS if the handler have carried out the operation.
281 * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
282 * @param pVM The cross context VM structure.
283 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
284 * @param GCPtr The virtual address the guest is writing to. This
285 * is the registered address corresponding to the
286 * access, so no aliasing trouble here.
287 * @param pvPtr The HC mapping of that address.
288 * @param pvBuf What the guest is reading/writing.
289 * @param cbBuf How much it's reading/writing.
290 * @param enmAccessType The access type.
291 * @param enmOrigin Who is calling.
292 * @param pvUser User argument.
293 * @thread EMT(pVCpu)
294 */
295typedef DECLCALLBACK(VBOXSTRICTRC) FNPGMVIRTHANDLER(PVM pVM, PVMCPU pVCpu, RTGCPTR GCPtr, void *pvPtr, void *pvBuf, size_t cbBuf,
296 PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, void *pvUser);
297/** Pointer to PGM access callback. */
298typedef FNPGMVIRTHANDLER *PFNPGMVIRTHANDLER;
299
300/**
301 * \#PF Handler callback for invalidation of virtual access handler ranges.
302 *
303 * @param pVM The cross context VM structure.
304 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
305 * @param GCPtr The virtual address the guest has changed.
306 * @param pvUser User argument.
307 * @thread EMT(pVCpu)
308 *
309 * @todo FNPGMR3VIRTINVALIDATE will not actually be called! It was introduced
310 * in r13179 (1.1) and stopped working with r13806 (PGMPool merge,
311 * v1.2), exactly a month later.
312 */
313typedef DECLCALLBACK(int) FNPGMR3VIRTINVALIDATE(PVM pVM, PVMCPU pVCpu, RTGCPTR GCPtr, void *pvUser);
314/** Pointer to PGM invalidation callback. */
315typedef FNPGMR3VIRTINVALIDATE *PFNPGMR3VIRTINVALIDATE;
316
317
318/**
319 * PGMR3PhysEnumDirtyFTPages callback for syncing dirty physical pages
320 *
321 * @param pVM The cross context VM structure.
322 * @param GCPhys GC physical address
323 * @param pRange HC virtual address of the page(s)
324 * @param cbRange Size of the dirty range in bytes.
325 * @param pvUser User argument.
326 */
327typedef DECLCALLBACK(int) FNPGMENUMDIRTYFTPAGES(PVM pVM, RTGCPHYS GCPhys, uint8_t *pRange, unsigned cbRange, void *pvUser);
328/** Pointer to PGMR3PhysEnumDirtyFTPages callback. */
329typedef FNPGMENUMDIRTYFTPAGES *PFNPGMENUMDIRTYFTPAGES;
330
331
332/**
333 * Paging mode.
334 *
335 * @note Part of saved state. Change with extreme care.
336 */
337typedef enum PGMMODE
338{
339 /** The usual invalid value. */
340 PGMMODE_INVALID = 0,
341 /** Real mode. */
342 PGMMODE_REAL,
343 /** Protected mode, no paging. */
344 PGMMODE_PROTECTED,
345 /** 32-bit paging. */
346 PGMMODE_32_BIT,
347 /** PAE paging. */
348 PGMMODE_PAE,
349 /** PAE paging with NX enabled. */
350 PGMMODE_PAE_NX,
351 /** 64-bit AMD paging (long mode). */
352 PGMMODE_AMD64,
353 /** 64-bit AMD paging (long mode) with NX enabled. */
354 PGMMODE_AMD64_NX,
355 /** 32-bit nested paging mode (shadow only; guest physical to host physical). */
356 PGMMODE_NESTED_32BIT,
357 /** PAE nested paging mode (shadow only; guest physical to host physical). */
358 PGMMODE_NESTED_PAE,
359 /** AMD64 nested paging mode (shadow only; guest physical to host physical). */
360 PGMMODE_NESTED_AMD64,
361 /** Extended paging (Intel) mode. */
362 PGMMODE_EPT,
363 /** Special mode used by NEM to indicate no shadow paging necessary. */
364 PGMMODE_NONE,
365 /** The max number of modes */
366 PGMMODE_MAX,
367 /** 32bit hackishness. */
368 PGMMODE_32BIT_HACK = 0x7fffffff
369} PGMMODE;
370
371/** Macro for checking if the guest is using paging.
372 * @param enmMode PGMMODE_*.
373 * @remark ASSUMES certain order of the PGMMODE_* values.
374 */
375#define PGMMODE_WITH_PAGING(enmMode) ((enmMode) >= PGMMODE_32_BIT)
376
377/** Macro for checking if it's one of the long mode modes.
378 * @param enmMode PGMMODE_*.
379 */
380#define PGMMODE_IS_LONG_MODE(enmMode) ((enmMode) == PGMMODE_AMD64_NX || (enmMode) == PGMMODE_AMD64)
381
382/** Macro for checking if it's one of the AMD64 nested modes.
383 * @param enmMode PGMMODE_*.
384 */
385#define PGMMODE_IS_NESTED(enmMode) ( (enmMode) == PGMMODE_NESTED_32BIT \
386 || (enmMode) == PGMMODE_NESTED_PAE \
387 || (enmMode) == PGMMODE_NESTED_AMD64)
388
389/**
390 * Is the ROM mapped (true) or is the shadow RAM mapped (false).
391 *
392 * @returns boolean.
393 * @param enmProt The PGMROMPROT value, must be valid.
394 */
395#define PGMROMPROT_IS_ROM(enmProt) \
396 ( (enmProt) == PGMROMPROT_READ_ROM_WRITE_IGNORE \
397 || (enmProt) == PGMROMPROT_READ_ROM_WRITE_RAM )
398
399
400VMMDECL(bool) PGMIsLockOwner(PVM pVM);
401
402VMMDECL(int) PGMRegisterStringFormatTypes(void);
403VMMDECL(void) PGMDeregisterStringFormatTypes(void);
404VMMDECL(RTHCPHYS) PGMGetHyperCR3(PVMCPU pVCpu);
405VMMDECL(RTHCPHYS) PGMGetNestedCR3(PVMCPU pVCpu, PGMMODE enmShadowMode);
406VMMDECL(RTHCPHYS) PGMGetInterHCCR3(PVM pVM);
407VMMDECL(RTHCPHYS) PGMGetInterRCCR3(PVM pVM, PVMCPU pVCpu);
408VMMDECL(RTHCPHYS) PGMGetInter32BitCR3(PVM pVM);
409VMMDECL(RTHCPHYS) PGMGetInterPaeCR3(PVM pVM);
410VMMDECL(RTHCPHYS) PGMGetInterAmd64CR3(PVM pVM);
411VMMDECL(int) PGMTrap0eHandler(PVMCPU pVCpu, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault);
412VMMDECL(int) PGMPrefetchPage(PVMCPU pVCpu, RTGCPTR GCPtrPage);
413VMMDECL(int) PGMVerifyAccess(PVMCPU pVCpu, RTGCPTR Addr, uint32_t cbSize, uint32_t fAccess);
414VMMDECL(int) PGMIsValidAccess(PVMCPU pVCpu, RTGCPTR Addr, uint32_t cbSize, uint32_t fAccess);
415VMMDECL(VBOXSTRICTRC) PGMInterpretInstruction(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault);
416VMMDECL(int) PGMMap(PVM pVM, RTGCPTR GCPtr, RTHCPHYS HCPhys, uint32_t cbPages, unsigned fFlags);
417VMMDECL(int) PGMMapGetPage(PVM pVM, RTGCPTR GCPtr, uint64_t *pfFlags, PRTHCPHYS pHCPhys);
418VMMDECL(int) PGMMapSetPage(PVM pVM, RTGCPTR GCPtr, uint64_t cb, uint64_t fFlags);
419VMMDECL(int) PGMMapModifyPage(PVM pVM, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
420#ifndef IN_RING0
421VMMDECL(bool) PGMMapHasConflicts(PVM pVM);
422#endif
423#ifdef VBOX_STRICT
424VMMDECL(void) PGMMapCheck(PVM pVM);
425#endif
426VMMDECL(int) PGMShwGetPage(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTHCPHYS pHCPhys);
427VMMDECL(int) PGMShwMakePageReadonly(PVMCPU pVCpu, RTGCPTR GCPtr, uint32_t fFlags);
428VMMDECL(int) PGMShwMakePageWritable(PVMCPU pVCpu, RTGCPTR GCPtr, uint32_t fFlags);
429VMMDECL(int) PGMShwMakePageNotPresent(PVMCPU pVCpu, RTGCPTR GCPtr, uint32_t fFlags);
430/** @name Flags for PGMShwMakePageReadonly, PGMShwMakePageWritable and
431 * PGMShwMakePageNotPresent
432 * @{ */
433/** The call is from an access handler for dealing with the a faulting write
434 * operation. The virtual address is within the same page. */
435#define PGM_MK_PG_IS_WRITE_FAULT RT_BIT(0)
436/** The page is an MMIO2. */
437#define PGM_MK_PG_IS_MMIO2 RT_BIT(1)
438/** @}*/
439VMMDECL(int) PGMGstGetPage(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTGCPHYS pGCPhys);
440VMMDECL(bool) PGMGstIsPagePresent(PVMCPU pVCpu, RTGCPTR GCPtr);
441VMMDECL(int) PGMGstSetPage(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cb, uint64_t fFlags);
442VMMDECL(int) PGMGstModifyPage(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
443VMM_INT_DECL(int) PGMGstGetPaePdpes(PVMCPU pVCpu, PX86PDPE paPdpes);
444VMM_INT_DECL(void) PGMGstUpdatePaePdpes(PVMCPU pVCpu, PCX86PDPE paPdpes);
445
446VMMDECL(int) PGMInvalidatePage(PVMCPU pVCpu, RTGCPTR GCPtrPage);
447VMMDECL(int) PGMFlushTLB(PVMCPU pVCpu, uint64_t cr3, bool fGlobal);
448VMMDECL(int) PGMSyncCR3(PVMCPU pVCpu, uint64_t cr0, uint64_t cr3, uint64_t cr4, bool fGlobal);
449VMMDECL(int) PGMUpdateCR3(PVMCPU pVCpu, uint64_t cr3);
450VMMDECL(int) PGMChangeMode(PVMCPU pVCpu, uint64_t cr0, uint64_t cr4, uint64_t efer);
451VMM_INT_DECL(int) PGMHCChangeMode(PVM pVM, PVMCPU pVCpu, PGMMODE enmGuestMode);
452VMMDECL(void) PGMCr0WpEnabled(PVMCPU pVCpu);
453VMMDECL(PGMMODE) PGMGetGuestMode(PVMCPU pVCpu);
454VMMDECL(PGMMODE) PGMGetShadowMode(PVMCPU pVCpu);
455VMMDECL(PGMMODE) PGMGetHostMode(PVM pVM);
456VMMDECL(const char *) PGMGetModeName(PGMMODE enmMode);
457VMM_INT_DECL(RTGCPHYS) PGMGetGuestCR3Phys(PVMCPU pVCpu);
458VMM_INT_DECL(void) PGMNotifyNxeChanged(PVMCPU pVCpu, bool fNxe);
459VMMDECL(bool) PGMHasDirtyPages(PVM pVM);
460
461/** PGM physical access handler type registration handle (heap offset, valid
462 * cross contexts without needing fixing up). Callbacks and handler type is
463 * associated with this and it is shared by all handler registrations. */
464typedef uint32_t PGMPHYSHANDLERTYPE;
465/** Pointer to a PGM physical handler type registration handle. */
466typedef PGMPHYSHANDLERTYPE *PPGMPHYSHANDLERTYPE;
467/** NIL value for PGM physical access handler type handle. */
468#define NIL_PGMPHYSHANDLERTYPE UINT32_MAX
469VMMDECL(uint32_t) PGMHandlerPhysicalTypeRelease(PVM pVM, PGMPHYSHANDLERTYPE hType);
470VMMDECL(uint32_t) PGMHandlerPhysicalTypeRetain(PVM pVM, PGMPHYSHANDLERTYPE hType);
471
472VMMDECL(int) PGMHandlerPhysicalRegister(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast, PGMPHYSHANDLERTYPE hType,
473 RTR3PTR pvUserR3, RTR0PTR pvUserR0, RTRCPTR pvUserRC,
474 R3PTRTYPE(const char *) pszDesc);
475VMMDECL(int) PGMHandlerPhysicalModify(PVM pVM, RTGCPHYS GCPhysCurrent, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast);
476VMMDECL(int) PGMHandlerPhysicalDeregister(PVM pVM, RTGCPHYS GCPhys);
477VMMDECL(int) PGMHandlerPhysicalChangeUserArgs(PVM pVM, RTGCPHYS GCPhys, RTR3PTR pvUserR3, RTR0PTR pvUserR0, RTRCPTR pvUserRC);
478VMMDECL(int) PGMHandlerPhysicalSplit(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysSplit);
479VMMDECL(int) PGMHandlerPhysicalJoin(PVM pVM, RTGCPHYS GCPhys1, RTGCPHYS GCPhys2);
480VMMDECL(int) PGMHandlerPhysicalPageTempOff(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage);
481VMMDECL(int) PGMHandlerPhysicalPageAlias(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage, RTGCPHYS GCPhysPageRemap);
482VMMDECL(int) PGMHandlerPhysicalPageAliasHC(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage, RTHCPHYS HCPhysPageRemap);
483VMMDECL(int) PGMHandlerPhysicalReset(PVM pVM, RTGCPHYS GCPhys);
484VMMDECL(bool) PGMHandlerPhysicalIsRegistered(PVM pVM, RTGCPHYS GCPhys);
485
486/** PGM virtual access handler type registration handle (heap offset, valid
487 * cross contexts without needing fixing up). Callbacks and handler type is
488 * associated with this and it is shared by all handler registrations. */
489typedef uint32_t PGMVIRTHANDLERTYPE;
490/** Pointer to a PGM virtual handler type registration handle. */
491typedef PGMVIRTHANDLERTYPE *PPGMVIRTHANDLERTYPE;
492/** NIL value for PGM virtual access handler type handle. */
493#define NIL_PGMVIRTHANDLERTYPE UINT32_MAX
494#ifdef VBOX_WITH_RAW_MODE
495VMM_INT_DECL(uint32_t) PGMHandlerVirtualTypeRelease(PVM pVM, PGMVIRTHANDLERTYPE hType);
496VMM_INT_DECL(uint32_t) PGMHandlerVirtualTypeRetain(PVM pVM, PGMVIRTHANDLERTYPE hType);
497VMM_INT_DECL(bool) PGMHandlerVirtualIsRegistered(PVM pVM, RTGCPTR GCPtr);
498#endif
499
500
501/**
502 * Page type.
503 *
504 * @remarks This enum has to fit in a 3-bit field (see PGMPAGE::u3Type).
505 * @remarks This is used in the saved state, so changes to it requires bumping
506 * the saved state version.
507 * @todo So, convert to \#defines!
508 */
509typedef enum PGMPAGETYPE
510{
511 /** The usual invalid zero entry. */
512 PGMPAGETYPE_INVALID = 0,
513 /** RAM page. (RWX) */
514 PGMPAGETYPE_RAM,
515 /** MMIO2 page. (RWX) */
516 PGMPAGETYPE_MMIO2,
517 /** MMIO2 page aliased over an MMIO page. (RWX)
518 * See PGMHandlerPhysicalPageAlias(). */
519 PGMPAGETYPE_MMIO2_ALIAS_MMIO,
520 /** Special page aliased over an MMIO page. (RWX)
521 * See PGMHandlerPhysicalPageAliasHC(), but this is generally only used for
522 * VT-x's APIC access page at the moment. Treated as MMIO by everyone except
523 * the shadow paging code. */
524 PGMPAGETYPE_SPECIAL_ALIAS_MMIO,
525 /** Shadowed ROM. (RWX) */
526 PGMPAGETYPE_ROM_SHADOW,
527 /** ROM page. (R-X) */
528 PGMPAGETYPE_ROM,
529 /** MMIO page. (---) */
530 PGMPAGETYPE_MMIO,
531 /** End of valid entries. */
532 PGMPAGETYPE_END
533} PGMPAGETYPE;
534AssertCompile(PGMPAGETYPE_END == 8);
535
536/** @name PGM page type predicates.
537 * @{ */
538#define PGMPAGETYPE_IS_READABLE(a_enmType) ( (a_enmType) <= PGMPAGETYPE_ROM )
539#define PGMPAGETYPE_IS_WRITEABLE(a_enmType) ( (a_enmType) <= PGMPAGETYPE_ROM_SHADOW )
540#define PGMPAGETYPE_IS_RWX(a_enmType) ( (a_enmType) <= PGMPAGETYPE_ROM_SHADOW )
541#define PGMPAGETYPE_IS_ROX(a_enmType) ( (a_enmType) == PGMPAGETYPE_ROM )
542#define PGMPAGETYPE_IS_NP(a_enmType) ( (a_enmType) == PGMPAGETYPE_MMIO )
543/** @} */
544
545
546VMM_INT_DECL(PGMPAGETYPE) PGMPhysGetPageType(PVM pVM, RTGCPHYS GCPhys);
547
548VMM_INT_DECL(int) PGMPhysGCPhys2HCPhys(PVM pVM, RTGCPHYS GCPhys, PRTHCPHYS pHCPhys);
549VMM_INT_DECL(int) PGMPhysGCPtr2HCPhys(PVMCPU pVCpu, RTGCPTR GCPtr, PRTHCPHYS pHCPhys);
550VMM_INT_DECL(int) PGMPhysGCPhys2CCPtr(PVM pVM, RTGCPHYS GCPhys, void **ppv, PPGMPAGEMAPLOCK pLock);
551VMM_INT_DECL(int) PGMPhysGCPhys2CCPtrReadOnly(PVM pVM, RTGCPHYS GCPhys, void const **ppv, PPGMPAGEMAPLOCK pLock);
552VMM_INT_DECL(int) PGMPhysGCPtr2CCPtr(PVMCPU pVCpu, RTGCPTR GCPtr, void **ppv, PPGMPAGEMAPLOCK pLock);
553VMM_INT_DECL(int) PGMPhysGCPtr2CCPtrReadOnly(PVMCPU pVCpu, RTGCPTR GCPtr, void const **ppv, PPGMPAGEMAPLOCK pLock);
554
555VMMDECL(bool) PGMPhysIsA20Enabled(PVMCPU pVCpu);
556VMMDECL(bool) PGMPhysIsGCPhysValid(PVM pVM, RTGCPHYS GCPhys);
557VMMDECL(bool) PGMPhysIsGCPhysNormal(PVM pVM, RTGCPHYS GCPhys);
558VMMDECL(int) PGMPhysGCPtr2GCPhys(PVMCPU pVCpu, RTGCPTR GCPtr, PRTGCPHYS pGCPhys);
559VMMDECL(void) PGMPhysReleasePageMappingLock(PVM pVM, PPGMPAGEMAPLOCK pLock);
560
561/** @def PGM_PHYS_RW_IS_SUCCESS
562 * Check whether a PGMPhysRead, PGMPhysWrite, PGMPhysReadGCPtr or
563 * PGMPhysWriteGCPtr call completed the given task.
564 *
565 * @returns true if completed, false if not.
566 * @param a_rcStrict The status code.
567 * @sa IOM_SUCCESS
568 */
569#ifdef IN_RING3
570# define PGM_PHYS_RW_IS_SUCCESS(a_rcStrict) \
571 ( (a_rcStrict) == VINF_SUCCESS \
572 || (a_rcStrict) == VINF_EM_DBG_STOP \
573 || (a_rcStrict) == VINF_EM_DBG_EVENT \
574 || (a_rcStrict) == VINF_EM_DBG_BREAKPOINT \
575 )
576#elif defined(IN_RING0)
577# define PGM_PHYS_RW_IS_SUCCESS(a_rcStrict) \
578 ( (a_rcStrict) == VINF_SUCCESS \
579 || (a_rcStrict) == VINF_IOM_R3_MMIO_COMMIT_WRITE \
580 || (a_rcStrict) == VINF_EM_OFF \
581 || (a_rcStrict) == VINF_EM_SUSPEND \
582 || (a_rcStrict) == VINF_EM_RESET \
583 || (a_rcStrict) == VINF_EM_HALT \
584 || (a_rcStrict) == VINF_EM_DBG_STOP \
585 || (a_rcStrict) == VINF_EM_DBG_EVENT \
586 || (a_rcStrict) == VINF_EM_DBG_BREAKPOINT \
587 )
588#elif defined(IN_RC)
589# define PGM_PHYS_RW_IS_SUCCESS(a_rcStrict) \
590 ( (a_rcStrict) == VINF_SUCCESS \
591 || (a_rcStrict) == VINF_IOM_R3_MMIO_COMMIT_WRITE \
592 || (a_rcStrict) == VINF_EM_OFF \
593 || (a_rcStrict) == VINF_EM_SUSPEND \
594 || (a_rcStrict) == VINF_EM_RESET \
595 || (a_rcStrict) == VINF_EM_HALT \
596 || (a_rcStrict) == VINF_SELM_SYNC_GDT \
597 || (a_rcStrict) == VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT \
598 || (a_rcStrict) == VINF_EM_DBG_STOP \
599 || (a_rcStrict) == VINF_EM_DBG_EVENT \
600 || (a_rcStrict) == VINF_EM_DBG_BREAKPOINT \
601 )
602#endif
603/** @def PGM_PHYS_RW_DO_UPDATE_STRICT_RC
604 * Updates the return code with a new result.
605 *
606 * Both status codes must be successes according to PGM_PHYS_RW_IS_SUCCESS.
607 *
608 * @param a_rcStrict The current return code, to be updated.
609 * @param a_rcStrict2 The new return code to merge in.
610 */
611#ifdef IN_RING3
612# define PGM_PHYS_RW_DO_UPDATE_STRICT_RC(a_rcStrict, a_rcStrict2) \
613 do { \
614 Assert(rcStrict == VINF_SUCCESS); \
615 Assert(rcStrict2 == VINF_SUCCESS); \
616 } while (0)
617#elif defined(IN_RING0)
618# define PGM_PHYS_RW_DO_UPDATE_STRICT_RC(a_rcStrict, a_rcStrict2) \
619 do { \
620 Assert(PGM_PHYS_RW_IS_SUCCESS(rcStrict)); \
621 Assert(PGM_PHYS_RW_IS_SUCCESS(rcStrict2)); \
622 AssertCompile(VINF_IOM_R3_MMIO_COMMIT_WRITE > VINF_EM_LAST); \
623 if ((a_rcStrict2) == VINF_SUCCESS || (a_rcStrict) == (a_rcStrict2)) \
624 { /* likely */ } \
625 else if ( (a_rcStrict) == VINF_SUCCESS \
626 || (a_rcStrict) > (a_rcStrict2)) \
627 (a_rcStrict) = (a_rcStrict2); \
628 } while (0)
629#elif defined(IN_RC)
630# define PGM_PHYS_RW_DO_UPDATE_STRICT_RC(a_rcStrict, a_rcStrict2) \
631 do { \
632 Assert(PGM_PHYS_RW_IS_SUCCESS(rcStrict)); \
633 Assert(PGM_PHYS_RW_IS_SUCCESS(rcStrict2)); \
634 AssertCompile(VINF_SELM_SYNC_GDT > VINF_EM_LAST); \
635 AssertCompile(VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT > VINF_EM_LAST); \
636 AssertCompile(VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT < VINF_SELM_SYNC_GDT); \
637 AssertCompile(VINF_IOM_R3_MMIO_COMMIT_WRITE > VINF_EM_LAST); \
638 AssertCompile(VINF_IOM_R3_MMIO_COMMIT_WRITE > VINF_SELM_SYNC_GDT); \
639 AssertCompile(VINF_IOM_R3_MMIO_COMMIT_WRITE > VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT); \
640 if ((a_rcStrict2) == VINF_SUCCESS || (a_rcStrict) == (a_rcStrict2)) \
641 { /* likely */ } \
642 else if ((a_rcStrict) == VINF_SUCCESS) \
643 (a_rcStrict) = (a_rcStrict2); \
644 else if ( ( (a_rcStrict) > (a_rcStrict2) \
645 && ( (a_rcStrict2) <= VINF_EM_RESET \
646 || (a_rcStrict) != VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT) ) \
647 || ( (a_rcStrict2) == VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT \
648 && (a_rcStrict) > VINF_EM_RESET) ) \
649 (a_rcStrict) = (a_rcStrict2); \
650 } while (0)
651#endif
652
653VMMDECL(VBOXSTRICTRC) PGMPhysRead(PVM pVM, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, PGMACCESSORIGIN enmOrigin);
654VMMDECL(VBOXSTRICTRC) PGMPhysWrite(PVM pVM, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, PGMACCESSORIGIN enmOrigin);
655VMMDECL(VBOXSTRICTRC) PGMPhysReadGCPtr(PVMCPU pVCpu, void *pvDst, RTGCPTR GCPtrSrc, size_t cb, PGMACCESSORIGIN enmOrigin);
656VMMDECL(VBOXSTRICTRC) PGMPhysWriteGCPtr(PVMCPU pVCpu, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb, PGMACCESSORIGIN enmOrigin);
657
658VMMDECL(int) PGMPhysSimpleReadGCPhys(PVM pVM, void *pvDst, RTGCPHYS GCPhysSrc, size_t cb);
659VMMDECL(int) PGMPhysSimpleWriteGCPhys(PVM pVM, RTGCPHYS GCPhysDst, const void *pvSrc, size_t cb);
660VMMDECL(int) PGMPhysSimpleReadGCPtr(PVMCPU pVCpu, void *pvDst, RTGCPTR GCPtrSrc, size_t cb);
661VMMDECL(int) PGMPhysSimpleWriteGCPtr(PVMCPU pVCpu, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
662VMMDECL(int) PGMPhysSimpleDirtyWriteGCPtr(PVMCPU pVCpu, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
663VMMDECL(int) PGMPhysInterpretedRead(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, void *pvDst, RTGCPTR GCPtrSrc, size_t cb);
664VMMDECL(int) PGMPhysInterpretedReadNoHandlers(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, void *pvDst, RTGCUINTPTR GCPtrSrc, size_t cb, bool fRaiseTrap);
665VMMDECL(int) PGMPhysInterpretedWriteNoHandlers(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, RTGCPTR GCPtrDst, void const *pvSrc, size_t cb, bool fRaiseTrap);
666
667VMM_INT_DECL(int) PGMPhysIemGCPhys2Ptr(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, bool fWritable, bool fByPassHandlers, void **ppv, PPGMPAGEMAPLOCK pLock);
668VMM_INT_DECL(int) PGMPhysIemQueryAccess(PVM pVM, RTGCPHYS GCPhys, bool fWritable, bool fByPassHandlers);
669VMM_INT_DECL(int) PGMPhysIemGCPhys2PtrNoLock(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, uint64_t const volatile *puTlbPhysRev,
670#if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
671 R3PTRTYPE(uint8_t *) *ppb,
672#else
673 R3R0PTRTYPE(uint8_t *) *ppb,
674#endif
675 uint64_t *pfTlb);
676/** @name Flags returned by PGMPhysIemGCPhys2PtrNoLock
677 * @{ */
678#define PGMIEMGCPHYS2PTR_F_NO_WRITE RT_BIT_32(3) /**< Not writable (IEMTLBE_F_PG_NO_WRITE). */
679#define PGMIEMGCPHYS2PTR_F_NO_READ RT_BIT_32(4) /**< Not readable (IEMTLBE_F_PG_NO_READ). */
680#define PGMIEMGCPHYS2PTR_F_NO_MAPPINGR3 RT_BIT_32(7) /**< No ring-3 mapping (IEMTLBE_F_NO_MAPPINGR3). */
681/** @} */
682
683/** Information returned by PGMPhysNemQueryPageInfo. */
684typedef struct PGMPHYSNEMPAGEINFO
685{
686 /** The host physical address of the page, NIL_HCPHYS if invalid page. */
687 RTHCPHYS HCPhys;
688 /** The NEM access mode for the page, NEM_PAGE_PROT_XXX */
689 uint32_t fNemProt : 8;
690 /** The NEM state associated with the PAGE. */
691 uint32_t u2NemState : 2;
692 /** The NEM state associated with the PAGE before pgmPhysPageMakeWritable was called. */
693 uint32_t u2OldNemState : 2;
694 /** Set if the page has handler. */
695 uint32_t fHasHandlers : 1;
696 /** Set if is the zero page backing it. */
697 uint32_t fZeroPage : 1;
698 /** Set if the page has handler. */
699 PGMPAGETYPE enmType;
700} PGMPHYSNEMPAGEINFO;
701/** Pointer to page information for NEM. */
702typedef PGMPHYSNEMPAGEINFO *PPGMPHYSNEMPAGEINFO;
703/**
704 * Callback for checking that the page is in sync while under the PGM lock.
705 *
706 * NEM passes this callback to PGMPhysNemQueryPageInfo to check that the page is
707 * in-sync between PGM and the native hypervisor API in an atomic fashion.
708 *
709 * @returns VBox status code.
710 * @param pVM The cross context VM structure.
711 * @param pVCpu The cross context per virtual CPU structure. Optional,
712 * see PGMPhysNemQueryPageInfo.
713 * @param GCPhys The guest physical address (not A20 masked).
714 * @param pInfo The page info structure. This function updates the
715 * u2NemState memory and the caller will update the PGMPAGE
716 * copy accordingly.
717 * @param pvUser Callback user argument.
718 */
719typedef DECLCALLBACK(int) FNPGMPHYSNEMCHECKPAGE(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, PPGMPHYSNEMPAGEINFO pInfo, void *pvUser);
720/** Pointer to a FNPGMPHYSNEMCHECKPAGE function. */
721typedef FNPGMPHYSNEMCHECKPAGE *PFNPGMPHYSNEMCHECKPAGE;
722
723VMM_INT_DECL(int) PGMPhysNemPageInfoChecker(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, bool fMakeWritable,
724 PPGMPHYSNEMPAGEINFO pInfo, PFNPGMPHYSNEMCHECKPAGE pfnChecker, void *pvUser);
725
726/**
727 * Callback for use with PGMPhysNemEnumPagesByState.
728 * @returns VBox status code.
729 * Failure status will stop enumeration immediately and return.
730 * @param pVM The cross context VM structure.
731 * @param pVCpu The cross context per virtual CPU structure. Optional,
732 * see PGMPhysNemEnumPagesByState.
733 * @param GCPhys The guest physical address (not A20 masked).
734 * @param pu2NemState Pointer to variable with the NEM state. This can be
735 * update.
736 * @param pvUser The user argument.
737 */
738typedef DECLCALLBACK(int) FNPGMPHYSNEMENUMCALLBACK(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, uint8_t *pu2NemState, void *pvUser);
739/** Pointer to a FNPGMPHYSNEMENUMCALLBACK function. */
740typedef FNPGMPHYSNEMENUMCALLBACK *PFNPGMPHYSNEMENUMCALLBACK;
741VMM_INT_DECL(int) PGMPhysNemEnumPagesByState(PVM pVM, PVMCPU VCpu, uint8_t uMinState,
742 PFNPGMPHYSNEMENUMCALLBACK pfnCallback, void *pvUser);
743
744
745#ifdef VBOX_STRICT
746VMMDECL(unsigned) PGMAssertHandlerAndFlagsInSync(PVM pVM);
747VMMDECL(unsigned) PGMAssertNoMappingConflicts(PVM pVM);
748VMMDECL(unsigned) PGMAssertCR3(PVM pVM, PVMCPU pVCpu, uint64_t cr3, uint64_t cr4);
749#endif /* VBOX_STRICT */
750
751#if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE)
752VMMDECL(void) PGMRZDynMapStartAutoSet(PVMCPU pVCpu);
753VMMDECL(void) PGMRZDynMapReleaseAutoSet(PVMCPU pVCpu);
754VMMDECL(void) PGMRZDynMapFlushAutoSet(PVMCPU pVCpu);
755VMMDECL(uint32_t) PGMRZDynMapPushAutoSubset(PVMCPU pVCpu);
756VMMDECL(void) PGMRZDynMapPopAutoSubset(PVMCPU pVCpu, uint32_t iPrevSubset);
757#endif
758
759VMMDECL(int) PGMSetLargePageUsage(PVM pVM, bool fUseLargePages);
760
761/**
762 * Query large page usage state
763 *
764 * @returns 0 - disabled, 1 - enabled
765 * @param pVM The cross context VM structure.
766 */
767#define PGMIsUsingLargePages(pVM) ((pVM)->fUseLargePages)
768
769
770#ifdef IN_RC
771/** @defgroup grp_pgm_gc The PGM Guest Context API
772 * @{
773 */
774VMMRCDECL(int) PGMRCDynMapInit(PVM pVM);
775/** @} */
776#endif /* IN_RC */
777
778
779#ifdef IN_RING0
780/** @defgroup grp_pgm_r0 The PGM Host Context Ring-0 API
781 * @{
782 */
783VMMR0_INT_DECL(int) PGMR0PhysAllocateHandyPages(PGVM pGVM, PVM pVM, VMCPUID idCpu);
784VMMR0_INT_DECL(int) PGMR0PhysFlushHandyPages(PGVM pGVM, PVM pVM, VMCPUID idCpu);
785VMMR0_INT_DECL(int) PGMR0PhysAllocateLargeHandyPage(PGVM pGVM, PVM pVM, VMCPUID idCpu);
786VMMR0_INT_DECL(int) PGMR0PhysSetupIoMmu(PGVM pGVM, PVM pVM);
787VMMR0DECL(int) PGMR0SharedModuleCheck(PVM pVM, PGVM pGVM, VMCPUID idCpu, PGMMSHAREDMODULE pModule, PCRTGCPTR64 paRegionsGCPtrs);
788VMMR0DECL(int) PGMR0Trap0eHandlerNestedPaging(PVM pVM, PVMCPU pVCpu, PGMMODE enmShwPagingMode, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPHYS pvFault);
789VMMR0DECL(VBOXSTRICTRC) PGMR0Trap0eHandlerNPMisconfig(PVM pVM, PVMCPU pVCpu, PGMMODE enmShwPagingMode, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, uint32_t uErr);
790# ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
791VMMR0DECL(int) PGMR0DynMapInit(void);
792VMMR0DECL(void) PGMR0DynMapTerm(void);
793VMMR0DECL(int) PGMR0DynMapInitVM(PVM pVM);
794VMMR0DECL(void) PGMR0DynMapTermVM(PVM pVM);
795VMMR0DECL(int) PGMR0DynMapAssertIntegrity(void);
796VMMR0DECL(bool) PGMR0DynMapStartOrMigrateAutoSet(PVMCPU pVCpu);
797VMMR0DECL(void) PGMR0DynMapMigrateAutoSet(PVMCPU pVCpu);
798# endif
799/** @} */
800#endif /* IN_RING0 */
801
802
803
804#ifdef IN_RING3
805/** @defgroup grp_pgm_r3 The PGM Host Context Ring-3 API
806 * @{
807 */
808VMMR3DECL(int) PGMR3Init(PVM pVM);
809VMMR3DECL(int) PGMR3InitDynMap(PVM pVM);
810VMMR3DECL(int) PGMR3InitFinalize(PVM pVM);
811VMMR3_INT_DECL(int) PGMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
812VMMR3DECL(void) PGMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
813VMMR3DECL(void) PGMR3ResetCpu(PVM pVM, PVMCPU pVCpu);
814VMMR3_INT_DECL(void) PGMR3Reset(PVM pVM);
815VMMR3_INT_DECL(void) PGMR3ResetNoMorePhysWritesFlag(PVM pVM);
816VMMR3_INT_DECL(void) PGMR3MemSetup(PVM pVM, bool fReset);
817VMMR3DECL(int) PGMR3Term(PVM pVM);
818VMMR3DECL(int) PGMR3LockCall(PVM pVM);
819
820VMMR3DECL(int) PGMR3PhysRegisterRam(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, const char *pszDesc);
821VMMR3DECL(int) PGMR3PhysChangeMemBalloon(PVM pVM, bool fInflate, unsigned cPages, RTGCPHYS *paPhysPage);
822VMMR3DECL(int) PGMR3PhysWriteProtectRAM(PVM pVM);
823VMMR3DECL(int) PGMR3PhysEnumDirtyFTPages(PVM pVM, PFNPGMENUMDIRTYFTPAGES pfnEnum, void *pvUser);
824VMMR3DECL(uint32_t) PGMR3PhysGetRamRangeCount(PVM pVM);
825VMMR3DECL(int) PGMR3PhysGetRange(PVM pVM, uint32_t iRange, PRTGCPHYS pGCPhysStart, PRTGCPHYS pGCPhysLast,
826 const char **ppszDesc, bool *pfIsMmio);
827VMMR3DECL(int) PGMR3QueryMemoryStats(PUVM pUVM, uint64_t *pcbTotalMem, uint64_t *pcbPrivateMem, uint64_t *pcbSharedMem, uint64_t *pcbZeroMem);
828VMMR3DECL(int) PGMR3QueryGlobalMemoryStats(PUVM pUVM, uint64_t *pcbAllocMem, uint64_t *pcbFreeMem, uint64_t *pcbBallonedMem, uint64_t *pcbSharedMem);
829
830VMMR3DECL(int) PGMR3PhysMMIORegister(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, PGMPHYSHANDLERTYPE hType,
831 RTR3PTR pvUserR3, RTR0PTR pvUserR0, RTRCPTR pvUserRC, const char *pszDesc);
832VMMR3DECL(int) PGMR3PhysMMIODeregister(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb);
833VMMR3DECL(int) PGMR3PhysMMIO2Register(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS cb, uint32_t fFlags, void **ppv, const char *pszDesc);
834VMMR3DECL(int) PGMR3PhysMMIOExPreRegister(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS cbRegion, PGMPHYSHANDLERTYPE hType,
835 RTR3PTR pvUserR3, RTR0PTR pvUserR0, RTRCPTR pvUserRC, const char *pszDesc);
836VMMR3DECL(int) PGMR3PhysMMIOExDeregister(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion);
837VMMR3DECL(int) PGMR3PhysMMIOExMap(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS GCPhys);
838VMMR3DECL(int) PGMR3PhysMMIOExUnmap(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS GCPhys);
839VMMR3_INT_DECL(int) PGMR3PhysMMIOExReduce(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS cbRegion);
840VMMR3DECL(bool) PGMR3PhysMMIOExIsBase(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhys);
841VMMR3_INT_DECL(int) PGMR3PhysMMIO2GetHCPhys(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS off, PRTHCPHYS pHCPhys);
842VMMR3_INT_DECL(int) PGMR3PhysMMIO2MapKernel(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb, const char *pszDesc, PRTR0PTR pR0Ptr);
843
844/** @name PGMR3PhysRegisterRom flags.
845 * @{ */
846/** Inidicates that ROM shadowing should be enabled. */
847#define PGMPHYS_ROM_FLAGS_SHADOWED RT_BIT_32(0)
848/** Indicates that what pvBinary points to won't go away
849 * and can be used for strictness checks. */
850#define PGMPHYS_ROM_FLAGS_PERMANENT_BINARY RT_BIT_32(1)
851/** @} */
852
853VMMR3DECL(int) PGMR3PhysRomRegister(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPHYS cb,
854 const void *pvBinary, uint32_t cbBinary, uint32_t fFlags, const char *pszDesc);
855VMMR3DECL(int) PGMR3PhysRomProtect(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, PGMROMPROT enmProt);
856VMMR3DECL(int) PGMR3PhysRegister(PVM pVM, void *pvRam, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, const SUPPAGE *paPages, const char *pszDesc);
857VMMDECL(void) PGMR3PhysSetA20(PVMCPU pVCpu, bool fEnable);
858/** @name PGMR3MapPT flags.
859 * @{ */
860/** The mapping may be unmapped later. The default is permanent mappings. */
861#define PGMR3MAPPT_FLAGS_UNMAPPABLE RT_BIT(0)
862/** @} */
863VMMR3DECL(int) PGMR3MapPT(PVM pVM, RTGCPTR GCPtr, uint32_t cb, uint32_t fFlags, PFNPGMRELOCATE pfnRelocate, void *pvUser, const char *pszDesc);
864VMMR3DECL(int) PGMR3UnmapPT(PVM pVM, RTGCPTR GCPtr);
865VMMR3DECL(int) PGMR3FinalizeMappings(PVM pVM);
866VMMR3DECL(int) PGMR3MappingsSize(PVM pVM, uint32_t *pcb);
867VMMR3DECL(int) PGMR3MappingsFix(PVM pVM, RTGCPTR GCPtrBase, uint32_t cb);
868VMMR3DECL(int) PGMR3MappingsUnfix(PVM pVM);
869VMMR3DECL(bool) PGMR3MappingsNeedReFixing(PVM pVM);
870#if defined(VBOX_WITH_RAW_MODE) || HC_ARCH_BITS == 32 /* (latter for 64-bit guests on 32-bit hosts) */
871VMMR3DECL(int) PGMR3MapIntermediate(PVM pVM, RTUINTPTR Addr, RTHCPHYS HCPhys, unsigned cbPages);
872#endif
873VMMR3DECL(int) PGMR3MapRead(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb);
874
875VMMR3_INT_DECL(int) PGMR3HandlerPhysicalTypeRegisterEx(PVM pVM, PGMPHYSHANDLERKIND enmKind,
876 PFNPGMPHYSHANDLER pfnHandlerR3,
877 R0PTRTYPE(PFNPGMPHYSHANDLER) pfnHandlerR0,
878 R0PTRTYPE(PFNPGMRZPHYSPFHANDLER) pfnPfHandlerR0,
879 RCPTRTYPE(PFNPGMPHYSHANDLER) pfnHandlerRC,
880 RCPTRTYPE(PFNPGMRZPHYSPFHANDLER) pfnPfHandlerRC,
881 const char *pszDesc, PPGMPHYSHANDLERTYPE phType);
882VMMR3DECL(int) PGMR3HandlerPhysicalTypeRegister(PVM pVM, PGMPHYSHANDLERKIND enmKind,
883 R3PTRTYPE(PFNPGMPHYSHANDLER) pfnHandlerR3,
884 const char *pszModR0, const char *pszHandlerR0, const char *pszPfHandlerR0,
885 const char *pszModRC, const char *pszHandlerRC, const char *pszPfHandlerRC,
886 const char *pszDesc,
887 PPGMPHYSHANDLERTYPE phType);
888#ifdef VBOX_WITH_RAW_MODE
889VMMR3_INT_DECL(int) PGMR3HandlerVirtualTypeRegisterEx(PVM pVM, PGMVIRTHANDLERKIND enmKind, bool fRelocUserRC,
890 PFNPGMR3VIRTINVALIDATE pfnInvalidateR3,
891 PFNPGMVIRTHANDLER pfnHandlerR3,
892 RCPTRTYPE(FNPGMVIRTHANDLER) pfnHandlerRC,
893 RCPTRTYPE(FNPGMRCVIRTPFHANDLER) pfnPfHandlerRC,
894 const char *pszDesc, PPGMVIRTHANDLERTYPE phType);
895VMMR3_INT_DECL(int) PGMR3HandlerVirtualTypeRegister(PVM pVM, PGMVIRTHANDLERKIND enmKind, bool fRelocUserRC,
896 PFNPGMR3VIRTINVALIDATE pfnInvalidateR3,
897 PFNPGMVIRTHANDLER pfnHandlerR3,
898 const char *pszHandlerRC, const char *pszPfHandlerRC, const char *pszDesc,
899 PPGMVIRTHANDLERTYPE phType);
900VMMR3_INT_DECL(int) PGMR3HandlerVirtualRegister(PVM pVM, PVMCPU pVCpu, PGMVIRTHANDLERTYPE hType, RTGCPTR GCPtr,
901 RTGCPTR GCPtrLast, void *pvUserR3, RTRCPTR pvUserRC, const char *pszDesc);
902VMMR3_INT_DECL(int) PGMHandlerVirtualChangeType(PVM pVM, RTGCPTR GCPtr, PGMVIRTHANDLERTYPE hNewType);
903VMMR3_INT_DECL(int) PGMHandlerVirtualDeregister(PVM pVM, PVMCPU pVCpu, RTGCPTR GCPtr, bool fHypervisor);
904#endif
905VMMR3DECL(int) PGMR3PoolGrow(PVM pVM);
906
907VMMR3DECL(int) PGMR3PhysTlbGCPhys2Ptr(PVM pVM, RTGCPHYS GCPhys, bool fWritable, void **ppv);
908VMMR3DECL(uint8_t) PGMR3PhysReadU8(PVM pVM, RTGCPHYS GCPhys, PGMACCESSORIGIN enmOrigin);
909VMMR3DECL(uint16_t) PGMR3PhysReadU16(PVM pVM, RTGCPHYS GCPhys, PGMACCESSORIGIN enmOrigin);
910VMMR3DECL(uint32_t) PGMR3PhysReadU32(PVM pVM, RTGCPHYS GCPhys, PGMACCESSORIGIN enmOrigin);
911VMMR3DECL(uint64_t) PGMR3PhysReadU64(PVM pVM, RTGCPHYS GCPhys, PGMACCESSORIGIN enmOrigin);
912VMMR3DECL(void) PGMR3PhysWriteU8(PVM pVM, RTGCPHYS GCPhys, uint8_t Value, PGMACCESSORIGIN enmOrigin);
913VMMR3DECL(void) PGMR3PhysWriteU16(PVM pVM, RTGCPHYS GCPhys, uint16_t Value, PGMACCESSORIGIN enmOrigin);
914VMMR3DECL(void) PGMR3PhysWriteU32(PVM pVM, RTGCPHYS GCPhys, uint32_t Value, PGMACCESSORIGIN enmOrigin);
915VMMR3DECL(void) PGMR3PhysWriteU64(PVM pVM, RTGCPHYS GCPhys, uint64_t Value, PGMACCESSORIGIN enmOrigin);
916VMMR3DECL(int) PGMR3PhysReadExternal(PVM pVM, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, PGMACCESSORIGIN enmOrigin);
917VMMR3DECL(int) PGMR3PhysWriteExternal(PVM pVM, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, PGMACCESSORIGIN enmOrigin);
918VMMR3DECL(int) PGMR3PhysGCPhys2CCPtrExternal(PVM pVM, RTGCPHYS GCPhys, void **ppv, PPGMPAGEMAPLOCK pLock);
919VMMR3DECL(int) PGMR3PhysGCPhys2CCPtrReadOnlyExternal(PVM pVM, RTGCPHYS GCPhys, void const **ppv, PPGMPAGEMAPLOCK pLock);
920VMMR3DECL(int) PGMR3PhysChunkMap(PVM pVM, uint32_t idChunk);
921VMMR3DECL(void) PGMR3PhysChunkInvalidateTLB(PVM pVM);
922VMMR3DECL(int) PGMR3PhysAllocateHandyPages(PVM pVM);
923VMMR3DECL(int) PGMR3PhysAllocateLargeHandyPage(PVM pVM, RTGCPHYS GCPhys);
924
925VMMR3DECL(int) PGMR3CheckIntegrity(PVM pVM);
926
927VMMR3DECL(int) PGMR3DbgR3Ptr2GCPhys(PUVM pUVM, RTR3PTR R3Ptr, PRTGCPHYS pGCPhys);
928VMMR3DECL(int) PGMR3DbgR3Ptr2HCPhys(PUVM pUVM, RTR3PTR R3Ptr, PRTHCPHYS pHCPhys);
929VMMR3DECL(int) PGMR3DbgHCPhys2GCPhys(PUVM pUVM, RTHCPHYS HCPhys, PRTGCPHYS pGCPhys);
930VMMR3_INT_DECL(int) PGMR3DbgReadGCPhys(PVM pVM, void *pvDst, RTGCPHYS GCPhysSrc, size_t cb, uint32_t fFlags, size_t *pcbRead);
931VMMR3_INT_DECL(int) PGMR3DbgWriteGCPhys(PVM pVM, RTGCPHYS GCPhysDst, const void *pvSrc, size_t cb, uint32_t fFlags, size_t *pcbWritten);
932VMMR3_INT_DECL(int) PGMR3DbgReadGCPtr(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb, uint32_t fFlags, size_t *pcbRead);
933VMMR3_INT_DECL(int) PGMR3DbgWriteGCPtr(PVM pVM, RTGCPTR GCPtrDst, void const *pvSrc, size_t cb, uint32_t fFlags, size_t *pcbWritten);
934VMMR3_INT_DECL(int) PGMR3DbgScanPhysical(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cbRange, RTGCPHYS GCPhysAlign, const uint8_t *pabNeedle, size_t cbNeedle, PRTGCPHYS pGCPhysHit);
935VMMR3_INT_DECL(int) PGMR3DbgScanVirtual(PVM pVM, PVMCPU pVCpu, RTGCPTR GCPtr, RTGCPTR cbRange, RTGCPTR GCPtrAlign, const uint8_t *pabNeedle, size_t cbNeedle, PRTGCUINTPTR pGCPhysHit);
936VMMR3_INT_DECL(int) PGMR3DumpHierarchyShw(PVM pVM, uint64_t cr3, uint32_t fFlags, uint64_t u64FirstAddr, uint64_t u64LastAddr, uint32_t cMaxDepth, PCDBGFINFOHLP pHlp);
937VMMR3_INT_DECL(int) PGMR3DumpHierarchyGst(PVM pVM, uint64_t cr3, uint32_t fFlags, RTGCPTR FirstAddr, RTGCPTR LastAddr, uint32_t cMaxDepth, PCDBGFINFOHLP pHlp);
938
939
940/** @name Page sharing
941 * @{ */
942VMMR3DECL(int) PGMR3SharedModuleRegister(PVM pVM, VBOXOSFAMILY enmGuestOS, char *pszModuleName, char *pszVersion,
943 RTGCPTR GCBaseAddr, uint32_t cbModule,
944 uint32_t cRegions, VMMDEVSHAREDREGIONDESC const *paRegions);
945VMMR3DECL(int) PGMR3SharedModuleUnregister(PVM pVM, char *pszModuleName, char *pszVersion,
946 RTGCPTR GCBaseAddr, uint32_t cbModule);
947VMMR3DECL(int) PGMR3SharedModuleCheckAll(PVM pVM);
948VMMR3DECL(int) PGMR3SharedModuleGetPageState(PVM pVM, RTGCPTR GCPtrPage, bool *pfShared, uint64_t *pfPageFlags);
949/** @} */
950
951/** @} */
952#endif /* IN_RING3 */
953
954RT_C_DECLS_END
955
956/** @} */
957#endif /* !VBOX_INCLUDED_vmm_pgm_h */
958
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