PGMPhys.cpp revision 5acd506d7f80295c8328715f744117fddb0b3444
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * PGM - Page Manager and Monitor, Physical Memory Addressing.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This file is part of VirtualBox Open Source Edition (OSE), as
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * available from http://www.virtualbox.org. This file is free software;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * you can redistribute it and/or modify it under the terms of the GNU
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * General Public License (GPL) as published by the Free Software
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Foundation, in version 2 as it comes in the "COPYING" file of the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Clara, CA 95054 USA or visit http://www.sun.com if you need
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * additional information or have any questions.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/*******************************************************************************
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* Header Files *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster*******************************************************************************/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/*******************************************************************************
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* Defined Constants And Macros *
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott*******************************************************************************/
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott/** The number of pages to free in one batch. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/*******************************************************************************
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott* Internal Functions *
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott*******************************************************************************/
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottstatic DECLCALLBACK(int) pgmR3PhysRomWriteHandler(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser);
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottstatic int pgmPhysFreePage(PVM pVM, PGMMFREEPAGESREQ pReq, uint32_t *pcPendingPages, PPGMPAGE pPage, RTGCPHYS GCPhys);
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * PGMR3PhysReadU8-64
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott * PGMR3PhysWriteU8-64
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott#define PGMPHYSFN_WRITENAME PGMR3PhysWriteU16
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott#define PGMPHYSFN_WRITENAME PGMR3PhysWriteU64
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott * EMT worker for PGMR3PhysReadExternal.
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottstatic DECLCALLBACK(int) pgmR3PhysReadExternalEMT(PVM pVM, PRTGCPHYS pGCPhys, void *pvBuf, size_t cbRead)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Write to physical memory, external users.
be367fb48c4c5a05214aab48aea9f09703b63a97Craig McDonnell * @returns VBox status code.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @retval VINF_SUCCESS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param pVM VM Handle.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param GCPhys Physical address to write to.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @param pvBuf What to write.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param cbWrite How many bytes to write.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @thread Any but EMTs.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnellVMMR3DECL(int) PGMR3PhysReadExternal(PVM pVM, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell AssertMsgReturn(cbRead > 0, ("don't even think about reading zero bytes!\n"), VINF_SUCCESS);
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell LogFlow(("PGMR3PhysReadExternal: %RGp %d\n", GCPhys, cbRead));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copy loop on ram ranges.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(pRamRanges);
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell /* Find range. */
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell /* Inside range or not? */
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * Must work our way thru this page by page.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * If the page has an ALL access handler, we'll have to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * delegate the job to EMT.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell if (PGM_PAGE_HAS_ACTIVE_ALL_HANDLERS(pPage))
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell return VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)pgmR3PhysReadExternalEMT, 4,
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * Simple stuff, go ahead.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell size_t cb = PAGE_SIZE - (off & PAGE_OFFSET_MASK);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int rc = pgmPhysGCPhys2CCPtrInternalReadOnly(pVM, pPage, pRam->GCPhys + off, &pvSrc);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AssertLogRelMsgFailed(("pgmPhysGCPhys2CCPtrInternalReadOnly failed on %RGp / %R[pgmpage] -> %Rrc\n",
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell /* next page */
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell } /* walk pages in ram range. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogFlow(("PGMPhysRead: Unassigned %RGp size=%u\n", GCPhys, cbRead));
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * Unassigned address space.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell } /* Ram range walk */
d552ef9965b495ec6fa5f89b12ad638ad4cc87f4Tony Bamford * EMT worker for PGMR3PhysWriteExternal.
d552ef9965b495ec6fa5f89b12ad638ad4cc87f4Tony Bamfordstatic DECLCALLBACK(int) pgmR3PhysWriteExternalEMT(PVM pVM, PRTGCPHYS pGCPhys, const void *pvBuf, size_t cbWrite)
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell /** @todo VERR_EM_NO_MEMORY */
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell PGMPhysWrite(pVM, *pGCPhys, pvBuf, cbWrite);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Write to physical memory, external users.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @returns VBox status code.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @retval VINF_SUCCESS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @retval VERR_EM_NO_MEMORY.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @param pVM VM Handle.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @param GCPhys Physical address to write to.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @param pvBuf What to write.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @param cbWrite How many bytes to write.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @param pszWho Who is writing. For tracking down who is writing
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * after we've saved the state.
d552ef9965b495ec6fa5f89b12ad638ad4cc87f4Tony Bamford * @thread Any but EMTs.
d552ef9965b495ec6fa5f89b12ad638ad4cc87f4Tony BamfordVMMDECL(int) PGMR3PhysWriteExternal(PVM pVM, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, const char *pszWho)
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell ("Calling PGMR3PhysWriteExternal after pgmR3Save()! GCPhys=%RGp cbWrite=%#x pszWho=%s\n",
d552ef9965b495ec6fa5f89b12ad638ad4cc87f4Tony Bamford AssertMsgReturn(cbWrite > 0, ("don't even think about writing zero bytes!\n"), VINF_SUCCESS);
d552ef9965b495ec6fa5f89b12ad638ad4cc87f4Tony Bamford LogFlow(("PGMR3PhysWriteExternal: %RGp %d\n", GCPhys, cbWrite));
d552ef9965b495ec6fa5f89b12ad638ad4cc87f4Tony Bamford * Copy loop on ram ranges, stop when we hit something difficult.
d552ef9965b495ec6fa5f89b12ad638ad4cc87f4Tony Bamford PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(pRamRanges);
d552ef9965b495ec6fa5f89b12ad638ad4cc87f4Tony Bamford /* Find range. */
d552ef9965b495ec6fa5f89b12ad638ad4cc87f4Tony Bamford /* Inside range or not? */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Must work our way thru this page by page.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * Is the page problematic, we have to do the work on the EMT.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * Allocating writable pages and access handlers are
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * problematic, write monitored pages are simple and can be
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * dealth with here.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell || PGM_PAGE_GET_STATE(pPage) != PGM_PAGE_STATE_ALLOCATED)
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell if ( PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_WRITE_MONITORED
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell pgmPhysPageMakeWriteMonitoredWritable(pVM, pPage);
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell return VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)pgmR3PhysWriteExternalEMT, 4,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Simple stuff, go ahead.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell size_t cb = PAGE_SIZE - (off & PAGE_OFFSET_MASK);
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell int rc = pgmPhysGCPhys2CCPtrInternal(pVM, pPage, pRam->GCPhys + off, &pvDst);
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell AssertLogRelMsgFailed(("pgmPhysGCPhys2CCPtrInternal failed on %RGp / %R[pgmpage] -> %Rrc\n",
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell /* next page */
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell } /* walk pages in ram range */
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * Unassigned address space, skip it.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell } /* Ram range walk */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * VMR3ReqCall worker for PGMR3PhysGCPhys2CCPtrExternal to make pages writable.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @returns see PGMR3PhysGCPhys2CCPtrExternal
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param pVM The VM handle.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param pGCPhys Pointer to the guest physical address.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param ppv Where to store the mapping address.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @param pLock Where to store the lock.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterstatic DECLCALLBACK(int) pgmR3PhysGCPhys2CCPtrDelegated(PVM pVM, PRTGCPHYS pGCPhys, void **ppv, PPGMPAGEMAPLOCK pLock)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Just hand it to PGMPhysGCPhys2CCPtr and check that it's not a page with
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * an access handler after it succeeds.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster rc = PGMPhysGCPhys2CCPtr(pVM, *pGCPhys, ppv, pLock);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int rc2 = pgmPhysPageQueryTlbe(&pVM->pgm.s, *pGCPhys, &pTlbe);
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell else if ( PGM_PAGE_HAS_ACTIVE_HANDLERS(pPage)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* We *must* flush any corresponding pgm pool page here, otherwise we'll
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * not be informed about writes and keep bogus gst->shw mappings around.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell Assert(!PGM_PAGE_HAS_ACTIVE_HANDLERS(pPage));
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell /** @todo r=bird: return VERR_PGM_PHYS_PAGE_RESERVED here if it still has
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * active handlers, see the PGMR3PhysGCPhys2CCPtrExternal docs. */
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * Requests the mapping of a guest page into ring-3, external threads.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * When you're done with the page, call PGMPhysReleasePageMappingLock() ASAP to
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * release it.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * This API will assume your intention is to write to the page, and will
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * therefore replace shared and zero pages. If you do not intend to modify the
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * page, use the PGMR3PhysGCPhys2CCPtrReadOnlyExternal() API.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @returns VBox status code.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @retval VINF_SUCCESS on success.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * backing or if the page has any active access handlers. The caller
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * must fall back on using PGMR3PhysWriteExternal.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @param pVM The VM handle.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @param GCPhys The guest physical address of the page that should be mapped.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @param ppv Where to store the address corresponding to GCPhys.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @param pLock Where to store the lock information that PGMPhysReleasePageMappingLock needs.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @remark Avoid calling this API from within critical sections (other than the
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * PGM one) because of the deadlock risk when we have to delegating the
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * task to an EMT.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * @thread Any.
786bac66d599daf6355e45e64da84c846a857552Craig McDonnellVMMR3DECL(int) PGMR3PhysGCPhys2CCPtrExternal(PVM pVM, RTGCPHYS GCPhys, void **ppv, PPGMPAGEMAPLOCK pLock)
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell Assert(VM_IS_EMT(pVM) || !PGMIsLockOwner(pVM));
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell * Query the Physical TLB entry for the page (may fail).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster rc = pgmPhysPageQueryTlbe(&pVM->pgm.s, GCPhys, &pTlbe);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If the page is shared, the zero page, or being write monitored
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * it must be converted to an page that's writable if possible.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * We can only deal with write monitored pages here, the rest have
d552ef9965b495ec6fa5f89b12ad638ad4cc87f4Tony Bamford * to be on an EMT.
d552ef9965b495ec6fa5f89b12ad638ad4cc87f4Tony Bamford || PGM_PAGE_GET_STATE(pPage) != PGM_PAGE_STATE_ALLOCATED
d552ef9965b495ec6fa5f89b12ad638ad4cc87f4Tony Bamford if ( PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_WRITE_MONITORED
786bac66d599daf6355e45e64da84c846a857552Craig McDonnell pgmPhysPageMakeWriteMonitoredWritable(pVM, pPage);
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott return VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)pgmR3PhysGCPhys2CCPtrDelegated, 4,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Now, just perform the locking and calculate the return address.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster unsigned cLocks = PGM_PAGE_GET_WRITE_LOCKS(pPage);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (RT_LIKELY(cLocks < PGM_PAGE_MAX_LOCKS - 1))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster else if (cLocks != PGM_PAGE_GET_WRITE_LOCKS(pPage))
if (pMap)
return rc;
VMMR3DECL(int) PGMR3PhysGCPhys2CCPtrReadOnlyExternal(PVM pVM, RTGCPHYS GCPhys, void const **ppv, PPGMPAGEMAPLOCK pLock)
if (pMap)
if (cLocks == 0)
AssertMsgFailed(("%RGp / %R[pgmpage] is entering permanent readonly locked state!\n", GCPhys, pPage));
if (pMap)
return rc;
#ifdef VBOX_STRICT
if (pCur)
if (pPrev)
if (pPrev)
static int pgmR3PhysFreePageRange(PVM pVM, PPGMRAMRANGE pRam, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast, uint8_t uType)
while (cPagesLeft-- > 0)
pPageDst++;
if (cPendingPages)
return rc;
static DECLCALLBACK(VBOXSTRICTRC) pgmR3PhysFreeRamPagesRendezvous(PVM pVM, PVMCPU pVCpu, void *pvUser)
return rc;
for (unsigned i = 0; i < cPages; i++)
Log(("PGMR3PhysFreePageRange: invalid physical page %RGp pPage->u3Type=%d\n", paPhysPage[i], (pPage) ? pPage->uTypeY : 0));
return rc;
if (cPendingPages)
return rc;
return rc;
int rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_ONCE, pgmR3PhysFreeRamPagesRendezvous, (void *)paUser);
return rc;
static void pgmR3PhysInitAndLinkRamRange(PVM pVM, PPGMRAMRANGE pNew, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast,
while (iPage-- > 0)
static DECLCALLBACK(bool) pgmR3PhysRamRangeRelocate(PVM pVM, RTGCPTR GCPtrOld, RTGCPTR GCPtrNew, PGMRELOCATECALL enmMode, void *pvUser)
switch (enmMode)
case PGMRELOCATECALL_SUGGEST:
case PGMRELOCATECALL_RELOCATE:
AssertFailedReturn(false);
? pszDesc
size_t const cChunkPages = RT_ALIGN_Z(RT_UOFFSETOF(PGMRAMRANGE, aPages[cRamPages]), PAGE_SIZE) >> PAGE_SHIFT;
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
NULL,
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
rc = PGMR3MapPT(pVM, GCPtrChunkMap, cbChunk, 0 /*fFlags*/, pgmR3PhysRamRangeRelocate, pNew, pszDescChunk);
return rc;
AssertMsgReturn(GCPhysLast > GCPhys, ("The range wraps! GCPhys=%RGp cb=%RGp\n", GCPhys, cb), VERR_INVALID_PARAMETER);
return rc;
while (cPagesLeft > 0)
rc = pgmR3PhysRegisterHighRamChunk(pVM, GCPhysChunk, cPagesInChunk, cbChunk, iChunk, pszDesc, &pPrev);
iChunk++;
pgmR3PhysInitAndLinkRamRange(pVM, pNew, GCPhys, GCPhysLast, NIL_RTRCPTR, NIL_RTR0PTR, pszDesc, pPrev);
return VINF_SUCCESS;
while (cLeft-- > 0)
case PGM_PAGE_STATE_ZERO:
LogRel(("PGM: RAM Pre-allocation failed at %RGp (in %s) with rc=%Rrc\n", GCPhys, pRam->pszDesc, rc));
return rc;
cPages++;
case PGM_PAGE_STATE_ALLOCATED:
case PGM_PAGE_STATE_SHARED:
pPage++;
return VINF_SUCCESS;
AssertMsg(((RTGCPHYS)iPage << PAGE_SHIFT) == pRam->cb, ("%RGp %RGp\n", (RTGCPHYS)iPage << PAGE_SHIFT, pRam->cb));
while (iPage-- > 0)
case PGMPAGETYPE_RAM:
rc = pgmPhysFreePage(pVM, pReq, &cPendingPages, pPage, pRam->GCPhys + ((RTGCPHYS)iPage << PAGE_SHIFT));
case PGMPAGETYPE_MMIO2:
case PGMPAGETYPE_ROM:
case PGMPAGETYPE_MMIO:
AssertFailed();
while (iPage-- > 0)
case PGMPAGETYPE_RAM:
case PGM_PAGE_STATE_ZERO:
case PGM_PAGE_STATE_SHARED:
case PGM_PAGE_STATE_ALLOCATED:
void *pvPage;
case PGMPAGETYPE_MMIO2:
case PGMPAGETYPE_ROM_SHADOW:
case PGMPAGETYPE_ROM:
case PGMPAGETYPE_MMIO:
AssertFailed();
if (cPendingPages)
return VINF_SUCCESS;
int rc;
bool fRamExists = false;
while (cLeft-- > 0)
pPage++;
fRamExists = true;
if (fRamExists)
Log(("PGMR3PhysMMIORegister: Adding ad hoc MMIO range for %RGp-%RGp %s\n", GCPhys, GCPhysLast, pszDesc));
rc = MMHyperAlloc(pVM, RT_OFFSETOF(PGMRAMRANGE, aPages[cPages]), 16, MM_TAG_PGM_PHYS, (void **)&pNew);
while (iPage-- > 0)
&& !fRamExists)
return rc;
bool fAllMMIO = true;
while (cLeft-- > 0)
fAllMMIO = false;
pPage++;
if (fAllMMIO)
* Range match? It will all be within one range (see PGMAllHandler.cpp).
while (cLeft--)
AssertMsg(PGM_PAGE_IS_MMIO(pPage), ("%RGp %R[pgmpage]\n", pRam->GCPhys + ((RTGCPHYS)iPage << PAGE_SHIFT), pPage));
AssertMsg(PGM_PAGE_IS_ZERO(pPage), ("%RGp %R[pgmpage]\n", pRam->GCPhys + ((RTGCPHYS)iPage << PAGE_SHIFT), pPage));
return rc;
return pCur;
return NULL;
VMMR3DECL(int) PGMR3PhysMMIO2Register(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cb, uint32_t fFlags, void **ppv, const char *pszDesc)
if (!pszDesc)
return VERR_NO_MEMORY;
void *pvPages;
while (iPage-- > 0)
return VINF_SUCCESS;
return rc;
unsigned cFound = 0;
while (pCur)
cFound++;
if (pPrev)
#ifdef VBOX_STRICT
bool fRamExists = false;
fRamExists = true;
if (fRamExists)
while (cPagesLeft-- > 0)
pPage++;
if (fRamExists)
while (cPagesLeft-- > 0)
pPageSrc++;
pPageDst++;
if (cPendingPages)
return VINF_SUCCESS;
bool fInformREM;
while (cPagesLeft-- > 0)
pPageDst++;
fInformREM = false;
fInformREM = true;
if (fInformREM)
return VINF_SUCCESS;
VMMR3DECL(int) PGMR3PhysMMIO2GetHCPhys(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, PRTHCPHYS pHCPhys)
return VINF_SUCCESS;
VMMR3DECL(int) PGMR3PhysMMIO2MapKernel(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
return rc;
Log(("PGMR3PhysRomRegister: pDevIns=%p GCPhys=%RGp(-%RGp) cb=%RGp pvBinary=%p fFlags=%#x pszDesc=%s\n",
AssertReturn(!(fFlags & ~(PGMPHYS_ROM_FLAGS_SHADOWED | PGMPHYS_ROM_FLAGS_PERMANENT_BINARY)), VERR_INVALID_PARAMETER);
bool fRamExists = false;
fRamExists = true;
if (fRamExists)
while (cPagesLeft-- > 0)
pPage++;
if (cExtraBaseCost)
return rc;
return rc;
rc = MMHyperAlloc(pVM, RT_OFFSETOF(PGMROMRANGE, aPages[cPages]), 0, MM_TAG_PGM_PHYS, (void **)&pRomNew);
if (!fRamExists)
rc = MMHyperAlloc(pVM, RT_OFFSETOF(PGMRAMRANGE, aPages[cPages]), sizeof(PGMPAGE), MM_TAG_PGM_PHYS, (void **)&pRamNew);
if (!fRamExists)
void *pvDstPage;
if (pRomPrev)
return VINF_SUCCESS;
if (!fRamExists)
return rc;
static DECLCALLBACK(int) pgmR3PhysRomWriteHandler(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser)
Log5(("pgmR3PhysRomWriteHandler: %d %c %#08RGp %#04zx\n", pRomPage->enmProt, enmAccessType == PGMACCESSTYPE_READ ? 'R' : 'W', GCPhys, cbBuf));
return VINF_PGM_HANDLER_DO_DEFAULT;
return VINF_SUCCESS;
void *pvDstPage;
return rc;
rc = pgmPhysFreePage(pVM, pReq, &cPendingPages, &pRom->aPages[iPage].Shadow, pRom->GCPhys + (iPage << PAGE_SHIFT));
if (cPendingPages)
void *pvDstPage;
#ifdef VBOX_STRICT
void const *pvDstPage;
return VINF_SUCCESS;
if (!cb)
return VINF_SUCCESS;
bool fFlushTLB = false;
bool fChanges = false;
iPage++)
fChanges = true;
if (fChanges)
return rc2;
if (fFlushTLB)
return rc;
RTAvlU32DoWithAll(&pVM->pgm.s.ChunkR3Map.pTree, true /*fFromLeft*/, pgmR3PhysChunkAgeingRolloverCallback, pVM);
RTAvlU32DoWithAll(&pVM->pgm.s.ChunkR3Map.pTree, true /*fFromLeft*/, pgmR3PhysChunkAgeingCallback, pVM);
typedef struct PGMR3PHYSCHUNKUNMAPCB
if (pChunk)
if (pChunk)
/* next with the same age - this version of the AVL API doesn't enumerate the list, so we have to do it. */
} while (pNode);
if (RTAvllU32DoWithAll(&pVM->pgm.s.ChunkR3Map.pAgeTree, true /*fFromLeft*/, pgmR3PhysChunkUnmapCandidateCallback, pVM))
return INT32_MAX;
int rc;
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
PPGMCHUNKR3MAP pChunk = (PPGMCHUNKR3MAP)MMR3HeapAlloc(pVM, MM_TAG_PGM_CHUNK_MAPPING, sizeof(*pChunk));
PPGMCHUNKR3MAP pChunk = (PPGMCHUNKR3MAP)MMR3UkHeapAlloc(pVM, MM_TAG_PGM_CHUNK_MAPPING, sizeof(*pChunk), NULL);
PPGMCHUNKR3MAP pUnmappedChunk = (PPGMCHUNKR3MAP)RTAvlU32Remove(&pVM->pgm.s.ChunkR3Map.pTree, Req.idChunkUnmap);
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
return rc;
int rc;
return rc;
void *pvDummy;
return rc;
* in EM.cpp and shouldn't be propagated outside TRPM, HWACCM, EM and
AssertMsgReturn(iClear <= RT_ELEMENTS(pVM->pgm.s.aHandyPages), ("%d", iClear), VERR_INTERNAL_ERROR);
void *pvChunk;
void *pv;
AssertLogRelMsgBreak(RT_SUCCESS(rc), ("idPage=%#x HCPhysGCPhys=%RHp rc=%Rrc", pPage->idPage, pPage->HCPhysGCPhys, rc));
iClear++;
Log3(("PGMR3PhysAllocateHandyPages: idPage=%#x HCPhys=%RGp\n", pPage->idPage, pPage->HCPhysGCPhys));
pRam;
return rc;
static int pgmPhysFreePage(PVM pVM, PGMMFREEPAGESREQ pReq, uint32_t *pcPendingPages, PPGMPAGE pPage, RTGCPHYS GCPhys)
return VMSetError(pVM, VERR_PGM_PHYS_NOT_RAM, RT_SRC_POS, "GCPhys=%RGp type=%d", GCPhys, PGM_PAGE_GET_TYPE(pPage));
return VINF_SUCCESS;
return VMSetError(pVM, VERR_PGM_PHYS_INVALID_PAGE_ID, RT_SRC_POS, "GCPhys=%RGp idPage=%#x", GCPhys, pPage);
return VINF_SUCCESS;
*pcPendingPages = 0;
return rc;
/** @todo Handle TLB loads of virtual handlers so ./test.sh can be made to work
if (fWritable)
int rc2;
case PGM_PAGE_STATE_ALLOCATED:
case PGM_PAGE_STATE_ZERO:
case PGM_PAGE_STATE_SHARED:
Log6(("PGMR3PhysTlbGCPhys2Ptr: GCPhys=%RGp rc=%Rrc pPage=%R[pgmpage] *ppv=%p\n", GCPhys, rc, pPage, *ppv));
return rc;