MMHyper.cpp revision 4b9dfb569f4f1db12f2edcab743d6b251c0a65c1
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/* $Id$ */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** @file
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * MM - Memory Manager - Hypervisor Memory Area.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/*
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * available from http://www.virtualbox.org. This file is free software;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * General Public License (GPL) as published by the Free Software
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * additional information or have any questions.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/*******************************************************************************
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync* Header Files *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync*******************************************************************************/
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define LOG_GROUP LOG_GROUP_MM_HYPER
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/pgm.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/mm.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/dbgf.h>
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#include "MMInternal.h"
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/vm.h>
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync#include <VBox/err.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/param.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/log.h>
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync#include <iprt/alloc.h>
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync#include <iprt/assert.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/string.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/*******************************************************************************
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync* Internal Functions *
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync*******************************************************************************/
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsyncstatic DECLCALLBACK(bool) mmR3HyperRelocateCallback(PVM pVM, RTGCPTR GCPtrOld, RTGCPTR GCPtrNew, PGMRELOCATECALL enmMode, void *pvUser);
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsyncstatic int mmR3HyperMap(PVM pVM, const size_t cb, const char *pszDesc, PRTGCPTR pGCPtr, PMMLOOKUPHYPER *ppLookup);
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsyncstatic int mmR3HyperHeapCreate(PVM pVM, const size_t cb, PMMHYPERHEAP *ppHeap);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int mmR3HyperHeapMap(PVM pVM, PMMHYPERHEAP pHeap, PRTGCPTR ppHeapGC);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic DECLCALLBACK(void) mmR3HyperInfoHma(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Initializes the hypvervisor related MM stuff without
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * calling down to PGM.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * PGM is not initialized at this point, PGM relies on
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * the heap to initialize.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @returns VBox status.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncint mmR3HyperInit(PVM pVM)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync LogFlow(("mmR3HyperInit:\n"));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Decide Hypervisor mapping in the guest context
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * And setup various hypervisor area and heap parameters.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pVM->mm.s.pvHyperAreaGC = (RTGCPTR)MM_HYPER_AREA_ADDRESS;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pVM->mm.s.cbHyperArea = MM_HYPER_AREA_MAX_SIZE;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertRelease(RT_ALIGN_T(pVM->mm.s.pvHyperAreaGC, 1 << X86_PD_SHIFT, RTGCPTR) == pVM->mm.s.pvHyperAreaGC);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync Assert(pVM->mm.s.pvHyperAreaGC < 0xff000000);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** @todo @bugref{1865}, @bugref{3202}: Change the cbHyperHeap default
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * depending on whether VT-x/AMD-V is enabled or not! Don't waste
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * precious kernel space on heap for the PATM. */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync uint32_t cbHyperHeap;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int rc = CFGMR3QueryU32(CFGMR3GetChild(CFGMR3GetRoot(pVM), "MM"), "cbHyperHeap", &cbHyperHeap);
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync if (rc == VERR_CFGM_NO_PARENT || rc == VERR_CFGM_VALUE_NOT_FOUND)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync cbHyperHeap = 1280*_1K;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (VBOX_FAILURE(rc))
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync {
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync LogRel(("MM/cbHyperHeap query -> %Vrc\n", rc));
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync AssertRCReturn(rc, rc);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync }
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync cbHyperHeap = RT_ALIGN_32(cbHyperHeap, PAGE_SIZE);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Allocate the hypervisor heap.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * (This must be done before we start adding memory to the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * hypervisor static area because lookup records are allocated from it.)
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync rc = mmR3HyperHeapCreate(pVM, cbHyperHeap, &pVM->mm.s.pHyperHeapR3);
0c4004948fca34f2db87e7b38013137e9472c306vboxsync if (VBOX_SUCCESS(rc))
0c4004948fca34f2db87e7b38013137e9472c306vboxsync {
0c4004948fca34f2db87e7b38013137e9472c306vboxsync pVM->mm.s.pHyperHeapR0 = (uintptr_t)pVM->mm.s.pHyperHeapR3; /** @todo #1865: map into ring-0 / whatever. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Make a small head fence to fend of accidental sequential access.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync MMR3HyperReserve(pVM, PAGE_SIZE, "fence", NULL);
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Map the VM structure into the hypervisor space.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertRelease(pVM->cbSelf == RT_OFFSETOF(VM, aCpus[pVM->cCPUs]));
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync RTGCPTR GCPtr;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = MMR3HyperMapPages(pVM, pVM, pVM->pVMR0, RT_ALIGN_Z(pVM->cbSelf, PAGE_SIZE) >> PAGE_SHIFT, pVM->paVMPagesR3, "VM", &GCPtr);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync if (VBOX_SUCCESS(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync pVM->pVMRC = (RTGCPTR32)GCPtr;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync pVM->pVMGC = pVM->pVMRC;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (uint32_t i = 0; i < pVM->cCPUs; i++)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync pVM->aCpus[i].pVMRC = pVM->pVMRC;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /* Reserve a page for fencing. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync MMR3HyperReserve(pVM, PAGE_SIZE, "fence", NULL);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /*
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Map the heap into the hypervisor space.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync rc = mmR3HyperHeapMap(pVM, pVM->mm.s.pHyperHeapR3, &GCPtr);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync if (VBOX_SUCCESS(rc))
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync {
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync pVM->mm.s.pHyperHeapRC = (RTRCPTR)GCPtr;
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync Assert(pVM->mm.s.pHyperHeapRC == GCPtr);
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync /*
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync * Register info handlers.
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync DBGFR3InfoRegisterInternal(pVM, "hma", "Show the layout of the Hypervisor Memory Area.", mmR3HyperInfoHma);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync LogFlow(("mmR3HyperInit: returns VINF_SUCCESS\n"));
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync return VINF_SUCCESS;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /* Caller will do proper cleanup. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync }
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync LogFlow(("mmR3HyperInit: returns %Vrc\n", rc));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return rc;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync}
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/**
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Finalizes the HMA mapping.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * This is called later during init, most (all) HMA allocations should be done
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * by the time this function is called.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @returns VBox status.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncVMMR3DECL(int) MMR3HyperInitFinalize(PVM pVM)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync{
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync LogFlow(("MMR3HyperInitFinalize:\n"));
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /*
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Adjust and create the HMA mapping.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync while ((RTINT)pVM->mm.s.offHyperNextStatic + 64*_1K < (RTINT)pVM->mm.s.cbHyperArea - _4M)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync pVM->mm.s.cbHyperArea -= _4M;
93f91841f87620d1cb6d0238b3d0d5e52cd3b9a4vboxsync int rc = PGMR3MapPT(pVM, pVM->mm.s.pvHyperAreaGC, pVM->mm.s.cbHyperArea,
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync mmR3HyperRelocateCallback, NULL, "Hypervisor Memory Area");
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync if (VBOX_FAILURE(rc))
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync return rc;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync pVM->mm.s.fPGMInitialized = true;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Do all the delayed mappings.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((uintptr_t)pVM->mm.s.pHyperHeapR3 + pVM->mm.s.offLookupHyper);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync for (;;)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync {
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync RTGCPTR GCPtr = pVM->mm.s.pvHyperAreaGC + pLookup->off;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync unsigned cPages = pLookup->cb >> PAGE_SHIFT;
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync switch (pLookup->enmType)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync case MMLOOKUPHYPERTYPE_LOCKED:
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync rc = mmR3MapLocked(pVM, pLookup->u.Locked.pLockedMem, GCPtr, 0, cPages, 0);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync case MMLOOKUPHYPERTYPE_HCPHYS:
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = PGMMap(pVM, GCPtr, pLookup->u.HCPhys.HCPhys, pLookup->cb, 0);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync case MMLOOKUPHYPERTYPE_GCPHYS:
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync const RTGCPHYS GCPhys = pLookup->u.GCPhys.GCPhys;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync const size_t cb = pLookup->cb;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (unsigned off = 0; off < cb; off += PAGE_SIZE)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTHCPHYS HCPhys;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync rc = PGMPhysGCPhys2HCPhys(pVM, GCPhys + off, &HCPhys);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync if (VBOX_FAILURE(rc))
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync break;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync rc = PGMMap(pVM, GCPtr + off, HCPhys, PAGE_SIZE, 0);
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync if (VBOX_FAILURE(rc))
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync break;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync }
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync break;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync }
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync case MMLOOKUPHYPERTYPE_MMIO2:
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync const RTGCPHYS offEnd = pLookup->u.MMIO2.off + pLookup->cb;
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync for (RTGCPHYS offCur = pLookup->u.MMIO2.off; offCur < offEnd; offCur += PAGE_SIZE)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTHCPHYS HCPhys;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync rc = PGMR3PhysMMIO2GetHCPhys(pVM, pLookup->u.MMIO2.pDevIns, pLookup->u.MMIO2.iRegion, offCur, &HCPhys);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (RT_FAILURE(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync rc = PGMMap(pVM, GCPtr + (offCur - pLookup->u.MMIO2.off), HCPhys, PAGE_SIZE, 0);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync if (RT_FAILURE(rc))
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync break;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync case MMLOOKUPHYPERTYPE_DYNAMIC:
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync /* do nothing here since these are either fences or managed by someone else using PGM. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync default:
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync break;
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync }
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync if (VBOX_FAILURE(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync AssertMsgFailed(("rc=%Vrc cb=%d GCPtr=%VGv enmType=%d pszDesc=%s\n",
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync rc, pLookup->cb, pLookup->enmType, pLookup->pszDesc));
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync return rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /* next */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync if (pLookup->offNext == (int32_t)NIL_OFFSET)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync break;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup = (PMMLOOKUPHYPER)((uintptr_t)pLookup + pLookup->offNext);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync }
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync LogFlow(("MMR3HyperInitFinalize: returns VINF_SUCCESS\n"));
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync return VINF_SUCCESS;
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync}
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Callback function which will be called when PGM is trying to find
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * a new location for the mapping.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * The callback is called in two modes, 1) the check mode and 2) the relocate mode.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * In 1) the callback should say if it objects to a suggested new location. If it
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * accepts the new location, it is called again for doing it's relocation.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @returns true if the location is ok.
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync * @returns false if another location should be found.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pVM The VM handle.
d5ea45cc92d7f1d3ade8189944531f665bfe8ed5vboxsync * @param GCPtrOld The old virtual address.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param GCPtrNew The new virtual address.
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync * @param enmMode Used to indicate the callback mode.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pvUser User argument. Ignored.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @remark The return value is no a failure indicator, it's an acceptance
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * indicator. Relocation can not fail!
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncstatic DECLCALLBACK(bool) mmR3HyperRelocateCallback(PVM pVM, RTGCPTR GCPtrOld, RTGCPTR GCPtrNew, PGMRELOCATECALL enmMode, void *pvUser)
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync{
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync switch (enmMode)
d5ea45cc92d7f1d3ade8189944531f665bfe8ed5vboxsync {
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /*
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync * Verify location - all locations are good for us.
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync */
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync case PGMRELOCATECALL_SUGGEST:
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync return true;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /*
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Execute the relocation.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync case PGMRELOCATECALL_RELOCATE:
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync {
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /*
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync * Accepted!
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync AssertMsg(GCPtrOld == pVM->mm.s.pvHyperAreaGC, ("GCPtrOld=%VGv pVM->mm.s.pvHyperAreaGC=%VGv\n", GCPtrOld, pVM->mm.s.pvHyperAreaGC));
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync Log(("Relocating the hypervisor from %VGv to %VGv\n", GCPtrOld, GCPtrNew));
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /*
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync * Relocate the VM structure and ourselves.
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync RTGCINTPTR offDelta = GCPtrNew - GCPtrOld;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync pVM->pVMRC += offDelta;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync pVM->pVMGC = pVM->pVMRC;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync for (uint32_t i = 0; i < pVM->cCPUs; i++)
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync pVM->aCpus[i].pVMRC = pVM->pVMRC;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync pVM->mm.s.pvHyperAreaGC += offDelta;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync Assert(pVM->mm.s.pvHyperAreaGC < _4G);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync pVM->mm.s.pHyperHeapRC += offDelta;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync pVM->mm.s.pHyperHeapR3->pbHeapRC += offDelta;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync pVM->mm.s.pHyperHeapR3->pVMRC = pVM->pVMRC;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /*
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync * Relocate the rest.
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync VMR3Relocate(pVM, offDelta);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync return true;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync default:
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync AssertMsgFailed(("Invalid relocation mode %d\n", enmMode));
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync }
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync return false;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Maps contiguous HC physical memory into the hypervisor region in the GC.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @return VBox status code.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pVM VM handle.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pvR3 Host context address of the memory. Must be page
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * aligned!
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param HCPhys Host context physical address of the memory to be
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * mapped. Must be page aligned!
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param cb Size of the memory. Will be rounded up to nearest page.
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync * @param pszDesc Description.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * @param pGCPtr Where to store the GC address.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync */
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsyncVMMR3DECL(int) MMR3HyperMapHCPhys(PVM pVM, void *pvR3, RTHCPHYS HCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync{
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync LogFlow(("MMR3HyperMapHCPhys: pvR3=%p HCPhys=%RHp cb=%d pszDesc=%p:{%s} pGCPtr=%p\n", pvR3, HCPhys, (int)cb, pszDesc, pszDesc, pGCPtr));
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /*
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync * Validate input.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync AssertReturn(RT_ALIGN_P(pvR3, PAGE_SIZE) == pvR3, VERR_INVALID_PARAMETER);
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync AssertReturn(RT_ALIGN_T(HCPhys, PAGE_SIZE, RTHCPHYS) == HCPhys, VERR_INVALID_PARAMETER);
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync AssertReturn(pszDesc && *pszDesc, VERR_INVALID_PARAMETER);
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Add the memory to the hypervisor area.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync uint32_t cbAligned = RT_ALIGN_32(cb, PAGE_SIZE);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertReturn(cbAligned >= cb, VERR_INVALID_PARAMETER);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTGCPTR GCPtr;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync PMMLOOKUPHYPER pLookup;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int rc = mmR3HyperMap(pVM, cbAligned, pszDesc, &GCPtr, &pLookup);
0c4004948fca34f2db87e7b38013137e9472c306vboxsync if (VBOX_SUCCESS(rc))
0c4004948fca34f2db87e7b38013137e9472c306vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup->enmType = MMLOOKUPHYPERTYPE_HCPHYS;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup->u.HCPhys.pvR3 = pvR3;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup->u.HCPhys.HCPhys = HCPhys;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Update the page table.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync if (pVM->mm.s.fPGMInitialized)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = PGMMap(pVM, GCPtr, HCPhys, cbAligned, 0);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (VBOX_SUCCESS(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *pGCPtr = GCPtr;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Maps contiguous GC physical memory into the hypervisor region in the GC.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @return VBox status code.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pVM VM handle.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param GCPhys Guest context physical address of the memory to be mapped. Must be page aligned!
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param cb Size of the memory. Will be rounded up to nearest page.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pszDesc Mapping description.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pGCPtr Where to store the GC address.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncVMMR3DECL(int) MMR3HyperMapGCPhys(PVM pVM, RTGCPHYS GCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync LogFlow(("MMR3HyperMapGCPhys: GCPhys=%VGp cb=%d pszDesc=%p:{%s} pGCPtr=%p\n", GCPhys, (int)cb, pszDesc, pszDesc, pGCPtr));
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /*
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * Validate input.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync AssertReturn(RT_ALIGN_T(GCPhys, PAGE_SIZE, RTGCPHYS) == GCPhys, VERR_INVALID_PARAMETER);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync AssertReturn(pszDesc && *pszDesc, VERR_INVALID_PARAMETER);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /*
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * Add the memory to the hypervisor area.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync */
8a339f91959bb7a3315b51a23461b68c7b0cb50evboxsync cb = RT_ALIGN_Z(cb, PAGE_SIZE);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync RTGCPTR GCPtr;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync PMMLOOKUPHYPER pLookup;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync int rc = mmR3HyperMap(pVM, cb, pszDesc, &GCPtr, &pLookup);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync if (VBOX_SUCCESS(rc))
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync {
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync pLookup->enmType = MMLOOKUPHYPERTYPE_GCPHYS;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync pLookup->u.GCPhys.GCPhys = GCPhys;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Update the page table.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (unsigned off = 0; off < cb; off += PAGE_SIZE)
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTHCPHYS HCPhys;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = PGMPhysGCPhys2HCPhys(pVM, GCPhys + off, &HCPhys);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertRC(rc);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync if (VBOX_FAILURE(rc))
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync {
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync AssertMsgFailed(("rc=%Vrc GCPhys=%VGv off=%#x %s\n", rc, GCPhys, off, pszDesc));
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync break;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync }
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync if (pVM->mm.s.fPGMInitialized)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync {
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync rc = PGMMap(pVM, GCPtr + off, HCPhys, PAGE_SIZE, 0);
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync AssertRC(rc);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync if (VBOX_FAILURE(rc))
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync {
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync AssertMsgFailed(("rc=%Vrc GCPhys=%VGv off=%#x %s\n", rc, GCPhys, off, pszDesc));
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync break;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (VBOX_SUCCESS(rc) && pGCPtr)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *pGCPtr = GCPtr;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Maps a portion of an MMIO2 region into the hypervisor region.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Callers of this API must never deregister the MMIO2 region before the
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * VM is powered off. If this becomes a requirement MMR3HyperUnmapMMIO2
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * API will be needed to perform cleanups.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @return VBox status code.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pVM Pointer to the shared VM structure.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pDevIns The device owning the MMIO2 memory.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param iRegion The region.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param off The offset into the region. Will be rounded down to closest page boundrary.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param cb The number of bytes to map. Will be rounded up to the closest page boundrary.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pszDesc Mapping description.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pRCPtr Where to store the RC address.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncVMMR3DECL(int) MMR3HyperMapMMIO2(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync const char *pszDesc, PRTRCPTR pRCPtr)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync LogFlow(("MMR3HyperMapMMIO2: pDevIns=%p iRegion=%#x off=%VGp cb=%VGp pszDesc=%p:{%s} pRCPtr=%p\n",
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pDevIns, iRegion, off, cb, pszDesc, pszDesc, pRCPtr));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int rc;
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync /*
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * Validate input.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertReturn(pszDesc && *pszDesc, VERR_INVALID_PARAMETER);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertReturn(off + cb > off, VERR_INVALID_PARAMETER);
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync uint32_t const offPage = off & PAGE_OFFSET_MASK;
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync off &= ~(RTGCPHYS)PAGE_OFFSET_MASK;
a39ea3668b7019c23a68936259545f9b71bce1aavboxsync cb += offPage;
0db6a029780d9f9b347500e117320a8d5661efe5vboxsync cb = RT_ALIGN_Z(cb, PAGE_SIZE);
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync const RTGCPHYS offEnd = off + cb;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync AssertReturn(offEnd > off, VERR_INVALID_PARAMETER);
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync for (RTGCPHYS offCur = off; offCur < offEnd; offCur += PAGE_SIZE)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTHCPHYS HCPhys;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync rc = PGMR3PhysMMIO2GetHCPhys(pVM, pDevIns, iRegion, offCur, &HCPhys);
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync AssertMsgRCReturn(rc, ("rc=%Rrc - iRegion=%d off=%RGp\n", rc, iRegion, off), rc);
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync }
0c4004948fca34f2db87e7b38013137e9472c306vboxsync
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /*
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * Add the memory to the hypervisor area.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync RTGCPTR GCPtr;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync PMMLOOKUPHYPER pLookup;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync rc = mmR3HyperMap(pVM, cb, pszDesc, &GCPtr, &pLookup);
0c4004948fca34f2db87e7b38013137e9472c306vboxsync if (VBOX_SUCCESS(rc))
0c4004948fca34f2db87e7b38013137e9472c306vboxsync {
0c4004948fca34f2db87e7b38013137e9472c306vboxsync pLookup->enmType = MMLOOKUPHYPERTYPE_MMIO2;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync pLookup->u.MMIO2.pDevIns = pDevIns;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync pLookup->u.MMIO2.iRegion = iRegion;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync pLookup->u.MMIO2.off = off;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /*
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * Update the page table.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync if (pVM->mm.s.fPGMInitialized)
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync {
0c4004948fca34f2db87e7b38013137e9472c306vboxsync for (RTGCPHYS offCur = off; offCur < offEnd; offCur += PAGE_SIZE)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync {
0c4004948fca34f2db87e7b38013137e9472c306vboxsync RTHCPHYS HCPhys;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync rc = PGMR3PhysMMIO2GetHCPhys(pVM, pDevIns, iRegion, offCur, &HCPhys);
0c4004948fca34f2db87e7b38013137e9472c306vboxsync AssertRCReturn(rc, VERR_INTERNAL_ERROR);
0c4004948fca34f2db87e7b38013137e9472c306vboxsync rc = PGMMap(pVM, GCPtr + (offCur - off), HCPhys, PAGE_SIZE, 0);
0c4004948fca34f2db87e7b38013137e9472c306vboxsync if (VBOX_FAILURE(rc))
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync {
0c4004948fca34f2db87e7b38013137e9472c306vboxsync AssertMsgFailed(("rc=%Vrc offCur=%RGp %s\n", rc, offCur, pszDesc));
0c4004948fca34f2db87e7b38013137e9472c306vboxsync break;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync }
0c4004948fca34f2db87e7b38013137e9472c306vboxsync }
0c4004948fca34f2db87e7b38013137e9472c306vboxsync }
0c4004948fca34f2db87e7b38013137e9472c306vboxsync
0c4004948fca34f2db87e7b38013137e9472c306vboxsync if (VBOX_SUCCESS(rc))
0c4004948fca34f2db87e7b38013137e9472c306vboxsync {
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync GCPtr |= offPage;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync *pRCPtr = GCPtr;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync AssertLogRelReturn(*pRCPtr == GCPtr, VERR_INTERNAL_ERROR);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync }
0c4004948fca34f2db87e7b38013137e9472c306vboxsync }
0c4004948fca34f2db87e7b38013137e9472c306vboxsync return rc;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync}
0c4004948fca34f2db87e7b38013137e9472c306vboxsync
0c4004948fca34f2db87e7b38013137e9472c306vboxsync
0c4004948fca34f2db87e7b38013137e9472c306vboxsync/**
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * Locks and Maps HC virtual memory into the hypervisor region in the GC.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync *
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @return VBox status code.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync *
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * @param pVM VM handle.
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * @param pvR3 Host context address of the memory (may be not page
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * aligned).
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * @param cb Size of the memory. Will be rounded up to nearest page.
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * @param fFree Set this if MM is responsible for freeing the memory
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * using SUPPageFree.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param pszDesc Mapping description.
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * @param pGCPtr Where to store the GC address corresponding to pvR3.
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync */
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsyncVMMR3DECL(int) MMR3HyperMapHCRam(PVM pVM, void *pvR3, size_t cb, bool fFree, const char *pszDesc, PRTGCPTR pGCPtr)
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync{
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync LogFlow(("MMR3HyperMapHCRam: pvR3=%p cb=%d fFree=%d pszDesc=%p:{%s} pGCPtr=%p\n", pvR3, (int)cb, fFree, pszDesc, pszDesc, pGCPtr));
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /*
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * Validate input.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync if ( !pvR3
0c4004948fca34f2db87e7b38013137e9472c306vboxsync || cb <= 0
0c4004948fca34f2db87e7b38013137e9472c306vboxsync || !pszDesc
0c4004948fca34f2db87e7b38013137e9472c306vboxsync || !*pszDesc)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync {
0c4004948fca34f2db87e7b38013137e9472c306vboxsync AssertMsgFailed(("Invalid parameter\n"));
0c4004948fca34f2db87e7b38013137e9472c306vboxsync return VERR_INVALID_PARAMETER;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync }
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync /*
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * Page align address and size.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync void *pvR3Page = (void *)((uintptr_t)pvR3 & PAGE_BASE_HC_MASK);
0c4004948fca34f2db87e7b38013137e9472c306vboxsync cb += (uintptr_t)pvR3 & PAGE_OFFSET_MASK;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync cb = RT_ALIGN_Z(cb, PAGE_SIZE);
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync /*
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * Add the memory to the hypervisor area.
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync */
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync RTGCPTR GCPtr;
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync PMMLOOKUPHYPER pLookup;
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync int rc = mmR3HyperMap(pVM, cb, pszDesc, &GCPtr, &pLookup);
0c4004948fca34f2db87e7b38013137e9472c306vboxsync if (VBOX_SUCCESS(rc))
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync {
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Lock the heap memory and tell PGM about the locked pages.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PMMLOCKEDMEM pLockedMem;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = mmR3LockMem(pVM, pvR3Page, cb, fFree ? MM_LOCKED_TYPE_HYPER : MM_LOCKED_TYPE_HYPER_NOFREE, &pLockedMem, false /* fSilentFailure */);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (VBOX_SUCCESS(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* map the stuff into guest address space. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (pVM->mm.s.fPGMInitialized)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = mmR3MapLocked(pVM, pLockedMem, GCPtr, 0, ~(size_t)0, 0);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (VBOX_SUCCESS(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync pLookup->enmType = MMLOOKUPHYPERTYPE_LOCKED;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup->u.Locked.pvR3 = pvR3;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup->u.Locked.pvR0 = NIL_RTR0PTR;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup->u.Locked.pLockedMem = pLockedMem;
8cd2f2e64725096acb682f34a5568b7fb816eda7vboxsync
8cd2f2e64725096acb682f34a5568b7fb816eda7vboxsync /* done. */
8cd2f2e64725096acb682f34a5568b7fb816eda7vboxsync GCPtr |= (uintptr_t)pvR3 & PAGE_OFFSET_MASK;
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync *pGCPtr = GCPtr;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync /* Don't care about failure clean, we're screwed if this fails anyway. */
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync }
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync }
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync return rc;
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync}
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync/**
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync * Maps locked R3 virtual memory into the hypervisor region in the GC.
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @return VBox status code.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pVM VM handle.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pvR3 The ring-3 address of the memory, must be page aligned.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pvR0 The ring-0 address of the memory, must be page aligned. (optional)
cba6719bd64ec749967bbe931230452664109857vboxsync * @param cPages The number of pages.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param paPages The page descriptors.
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync * @param pszDesc Mapping description.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pGCPtr Where to store the GC address corresponding to pvR3.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsyncVMMR3DECL(int) MMR3HyperMapPages(PVM pVM, void *pvR3, RTR0PTR pvR0, size_t cPages, PCSUPPAGE paPages, const char *pszDesc, PRTGCPTR pGCPtr)
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync LogFlow(("MMR3HyperMapPages: pvR3=%p pvR0=%p cPages=%zu paPages=%p pszDesc=%p:{%s} pGCPtr=%p\n",
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pvR3, pvR0, cPages, paPages, pszDesc, pszDesc, pGCPtr));
a8139954a84d6e9090dd3a8371aa788351d45bc3vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
a8139954a84d6e9090dd3a8371aa788351d45bc3vboxsync * Validate input.
a8139954a84d6e9090dd3a8371aa788351d45bc3vboxsync */
a8139954a84d6e9090dd3a8371aa788351d45bc3vboxsync AssertPtrReturn(pvR3, VERR_INVALID_POINTER);
a8139954a84d6e9090dd3a8371aa788351d45bc3vboxsync AssertPtrReturn(paPages, VERR_INVALID_POINTER);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertReturn(cPages > 0, VERR_INVALID_PARAMETER);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync AssertReturn(cPages < 1024, VERR_INVALID_PARAMETER);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync AssertPtrReturn(pszDesc, VERR_INVALID_POINTER);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertReturn(*pszDesc, VERR_INVALID_PARAMETER);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertPtrReturn(pGCPtr, VERR_INVALID_PARAMETER);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
cba6719bd64ec749967bbe931230452664109857vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Add the memory to the hypervisor area.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync RTGCPTR GCPtr;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PMMLOOKUPHYPER pLookup;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int rc = mmR3HyperMap(pVM, cPages << PAGE_SHIFT, pszDesc, &GCPtr, &pLookup);
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync if (VBOX_SUCCESS(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Create a locked memory record and tell PGM about this.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PMMLOCKEDMEM pLockedMem = (PMMLOCKEDMEM)MMR3HeapAlloc(pVM, MM_TAG_MM, RT_OFFSETOF(MMLOCKEDMEM, aPhysPages[cPages]));
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync if (pLockedMem)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLockedMem->pv = pvR3;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLockedMem->cb = cPages << PAGE_SHIFT;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLockedMem->eType = MM_LOCKED_TYPE_HYPER_PAGES;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync memset(&pLockedMem->u, 0, sizeof(pLockedMem->u));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (size_t i = 0; i < cPages; i++)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
0db6a029780d9f9b347500e117320a8d5661efe5vboxsync AssertReleaseReturn(paPages[i].Phys != 0 && paPages[i].Phys != NIL_RTHCPHYS && !(paPages[i].Phys & PAGE_OFFSET_MASK), VERR_INTERNAL_ERROR);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLockedMem->aPhysPages[i].Phys = paPages[i].Phys;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLockedMem->aPhysPages[i].uReserved = (RTHCUINTPTR)pLockedMem;
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* map the stuff into guest address space. */
0db6a029780d9f9b347500e117320a8d5661efe5vboxsync if (pVM->mm.s.fPGMInitialized)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = mmR3MapLocked(pVM, pLockedMem, GCPtr, 0, ~(size_t)0, 0);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (VBOX_SUCCESS(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup->enmType = MMLOOKUPHYPERTYPE_LOCKED;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup->u.Locked.pvR3 = pvR3;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup->u.Locked.pvR0 = pvR0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup->u.Locked.pLockedMem = pLockedMem;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* done. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *pGCPtr = GCPtr;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return rc;
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Don't care about failure clean, we're screwed if this fails anyway. */
cba6719bd64ec749967bbe931230452664109857vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync return rc;
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync}
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/**
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Reserves a hypervisor memory area.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Most frequent usage is fence pages and dynamically mappings like the guest PD and PDPT.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @return VBox status code.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pVM VM handle.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param cb Size of the memory. Will be rounded up to nearest page.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pszDesc Mapping description.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pGCPtr Where to store the assigned GC address. Optional.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncVMMR3DECL(int) MMR3HyperReserve(PVM pVM, unsigned cb, const char *pszDesc, PRTGCPTR pGCPtr)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync LogFlow(("MMR3HyperMapHCRam: cb=%d pszDesc=%p:{%s} pGCPtr=%p\n", (int)cb, pszDesc, pszDesc, pGCPtr));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync * Validate input.
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync */
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync if ( cb <= 0
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync || !pszDesc
c91345f92b829d3fba05ce7a97206d83c5183ce0vboxsync || !*pszDesc)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
c91345f92b829d3fba05ce7a97206d83c5183ce0vboxsync AssertMsgFailed(("Invalid parameter\n"));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return VERR_INVALID_PARAMETER;
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync }
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync /*
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync * Add the memory to the hypervisor area.
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync */
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync RTGCPTR GCPtr;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PMMLOOKUPHYPER pLookup;
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync int rc = mmR3HyperMap(pVM, cb, pszDesc, &GCPtr, &pLookup);
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync if (VBOX_SUCCESS(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup->enmType = MMLOOKUPHYPERTYPE_DYNAMIC;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (pGCPtr)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *pGCPtr = GCPtr;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return VINF_SUCCESS;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Adds memory to the hypervisor memory arena.
5b465a7c1237993faf8bb50120d247f3f0319adavboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @return VBox status code.
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync * @param pVM The VM handle.
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync * @param cb Size of the memory. Will be rounded up to neares page.
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync * @param pszDesc The description of the memory.
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync * @param pGCPtr Where to store the GC address.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param ppLookup Where to store the pointer to the lookup record.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @remark We assume the threading structure of VBox imposes natural
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * serialization of most functions, this one included.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int mmR3HyperMap(PVM pVM, const size_t cb, const char *pszDesc, PRTGCPTR pGCPtr, PMMLOOKUPHYPER *ppLookup)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Validate input.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync const uint32_t cbAligned = RT_ALIGN(cb, PAGE_SIZE);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertReturn(cbAligned >= cb, VERR_INVALID_PARAMETER);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (pVM->mm.s.offHyperNextStatic + cbAligned >= pVM->mm.s.cbHyperArea) /* don't use the last page, it's a fence. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgFailed(("Out of static mapping space in the HMA! offHyperAreaGC=%x cbAligned=%x\n",
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync pVM->mm.s.offHyperNextStatic, cbAligned));
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync return VERR_NO_MEMORY;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Allocate lookup record.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync PMMLOOKUPHYPER pLookup;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int rc = MMHyperAlloc(pVM, sizeof(*pLookup), 1, MM_TAG_MM, (void **)&pLookup);
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync if (VBOX_SUCCESS(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /*
cba6719bd64ec749967bbe931230452664109857vboxsync * Initialize it and insert it.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
cba6719bd64ec749967bbe931230452664109857vboxsync pLookup->offNext = pVM->mm.s.offLookupHyper;
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync pLookup->cb = cbAligned;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup->off = pVM->mm.s.offHyperNextStatic;
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync pVM->mm.s.offLookupHyper = (uint8_t *)pLookup - (uint8_t *)pVM->mm.s.pHyperHeapR3;
cba6719bd64ec749967bbe931230452664109857vboxsync if (pLookup->offNext != (int32_t)NIL_OFFSET)
cba6719bd64ec749967bbe931230452664109857vboxsync pLookup->offNext -= pVM->mm.s.offLookupHyper;
cba6719bd64ec749967bbe931230452664109857vboxsync pLookup->enmType = MMLOOKUPHYPERTYPE_INVALID;
cba6719bd64ec749967bbe931230452664109857vboxsync memset(&pLookup->u, 0xff, sizeof(pLookup->u));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pLookup->pszDesc = pszDesc;
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync
/* Mapping. */
*pGCPtr = pVM->mm.s.pvHyperAreaGC + pVM->mm.s.offHyperNextStatic;
pVM->mm.s.offHyperNextStatic += cbAligned;
/* Return pointer. */
*ppLookup = pLookup;
}
AssertRC(rc);
LogFlow(("mmR3HyperMap: returns %Vrc *pGCPtr=%VGv\n", rc, *pGCPtr));
return rc;
}
/**
* Allocates a new heap.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param cb The size of the new heap.
* @param ppHeap Where to store the heap pointer on successful return.
*/
static int mmR3HyperHeapCreate(PVM pVM, const size_t cb, PMMHYPERHEAP *ppHeap)
{
/*
* Allocate the hypervisor heap.
*/
const uint32_t cbAligned = RT_ALIGN_Z(cb, PAGE_SIZE);
AssertReturn(cbAligned >= cb, VERR_INVALID_PARAMETER);
void *pv;
int rc = SUPPageAlloc(cbAligned >> PAGE_SHIFT, &pv); /** @todo #1865: heap allocation must be changed for osx (only). */
if (VBOX_SUCCESS(rc))
{
/*
* Initialize the heap and first free chunk.
*/
PMMHYPERHEAP pHeap = (PMMHYPERHEAP)pv;
pHeap->u32Magic = MMHYPERHEAP_MAGIC;
pHeap->pbHeapR3 = (uint8_t *)pHeap + MMYPERHEAP_HDR_SIZE;
pHeap->pbHeapR0 = (uintptr_t)pHeap->pbHeapR3; /** @todo #1865: Map heap into ring-0 on darwin. */
//pHeap->pbHeapGC = 0; // set by mmR3HyperHeapMap()
pHeap->pVMR3 = pVM;
pHeap->pVMR0 = pVM->pVMR0;
pHeap->pVMRC = pVM->pVMRC;
pHeap->cbHeap = cbAligned - MMYPERHEAP_HDR_SIZE;
pHeap->cbFree = pHeap->cbHeap - sizeof(MMHYPERCHUNK);
//pHeap->offFreeHead = 0;
//pHeap->offFreeTail = 0;
pHeap->offPageAligned = pHeap->cbHeap;
//pHeap->HyperHeapStatTree = 0;
PMMHYPERCHUNKFREE pFree = (PMMHYPERCHUNKFREE)pHeap->pbHeapR3;
pFree->cb = pHeap->cbFree;
//pFree->core.offNext = 0;
MMHYPERCHUNK_SET_TYPE(&pFree->core, MMHYPERCHUNK_FLAGS_FREE);
pFree->core.offHeap = -(int32_t)MMYPERHEAP_HDR_SIZE;
//pFree->offNext = 0;
//pFree->offPrev = 0;
STAMR3Register(pVM, &pHeap->cbHeap, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, "/MM/HyperHeap/cbHeap", STAMUNIT_BYTES, "The heap size.");
STAMR3Register(pVM, &pHeap->cbFree, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, "/MM/HyperHeap/cbFree", STAMUNIT_BYTES, "The free space.");
*ppHeap = pHeap;
return VINF_SUCCESS;
}
AssertMsgFailed(("SUPPageAlloc(%d,) -> %Vrc\n", cbAligned >> PAGE_SHIFT, rc));
*ppHeap = NULL;
return rc;
}
/**
* Allocates a new heap.
*/
static int mmR3HyperHeapMap(PVM pVM, PMMHYPERHEAP pHeap, PRTGCPTR ppHeapGC)
{
int rc = MMR3HyperMapHCRam(pVM, pHeap, pHeap->cbHeap + MMYPERHEAP_HDR_SIZE, true, "Heap", ppHeapGC);
if (VBOX_SUCCESS(rc))
{
pHeap->pVMRC = pVM->pVMRC;
pHeap->pbHeapRC = *ppHeapGC + MMYPERHEAP_HDR_SIZE;
/* Reserve a page for fencing. */
MMR3HyperReserve(pVM, PAGE_SIZE, "fence", NULL);
}
return rc;
}
#if 0
/**
* Destroys a heap.
*/
static int mmR3HyperHeapDestroy(PVM pVM, PMMHYPERHEAP pHeap)
{
/* all this is dealt with when unlocking and freeing locked memory. */
}
#endif
/**
* Allocates memory in the Hypervisor (GC VMM) area which never will
* be freed and doesn't have any offset based relation to other heap blocks.
*
* The latter means that two blocks allocated by this API will not have the
* same relative position to each other in GC and HC. In short, never use
* this API for allocating nodes for an offset based AVL tree!
*
* The returned memory is of course zeroed.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
* @param cb Number of bytes to allocate.
* @param uAlignment Required memory alignment in bytes.
* Values are 0,8,16,32 and PAGE_SIZE.
* 0 -> default alignment, i.e. 8 bytes.
* @param enmTag The statistics tag.
* @param ppv Where to store the address to the allocated
* memory.
* @remark This is assumed not to be used at times when serialization is required.
*/
VMMDECL(int) MMR3HyperAllocOnceNoRel(PVM pVM, size_t cb, unsigned uAlignment, MMTAG enmTag, void **ppv)
{
AssertMsg(cb >= 8, ("Hey! Do you really mean to allocate less than 8 bytes?! cb=%d\n", cb));
/*
* Choose between allocating a new chunk of HMA memory
* and the heap. We will only do BIG allocations from HMA.
*/
if ( cb < _64K
&& ( uAlignment != PAGE_SIZE
|| cb < 48*_1K))
{
int rc = MMHyperAlloc(pVM, cb, uAlignment, enmTag, ppv);
if ( rc != VERR_MM_HYPER_NO_MEMORY
|| cb <= 8*_1K)
{
Log2(("MMR3HyperAllocOnceNoRel: cb=%#zx uAlignment=%#x returns %Rrc and *ppv=%p\n",
cb, uAlignment, rc, *ppv));
return rc;
}
}
/*
* Validate alignment.
*/
switch (uAlignment)
{
case 0:
case 8:
case 16:
case 32:
case PAGE_SIZE:
break;
default:
AssertMsgFailed(("Invalid alignment %u\n", uAlignment));
return VERR_INVALID_PARAMETER;
}
/*
* Allocate the pages and the HMA space.
*/
cb = RT_ALIGN(cb, PAGE_SIZE);
void *pvPages;
int rc = SUPPageAlloc(cb >> PAGE_SHIFT, &pvPages);
if (VBOX_SUCCESS(rc))
{
RTGCPTR GCPtr;
rc = MMR3HyperMapHCRam(pVM, pvPages, cb, true,
MMR3HeapAPrintf(pVM, MM_TAG_MM, "alloc once (%s)", mmR3GetTagName(enmTag)),
&GCPtr);
if (VBOX_SUCCESS(rc))
{
*ppv = pvPages;
Log2(("MMR3HyperAllocOnceNoRel: cb=%#x uAlignment=%#x returns VINF_SUCCESS and *ppv=%p\n",
cb, uAlignment, *ppv));
return rc;
}
AssertMsgFailed(("Failed to allocate %zd bytes! %Rrc\n", cb, rc));
SUPPageFree(pvPages, cb >> PAGE_SHIFT);
/*
* HACK ALERT! Try allocate it off the heap so that we don't freak
* out during vga/vmmdev mmio2 allocation with certain ram sizes.
*/
/** @todo make a proper fix for this so we will never end up in this kind of situation! */
Log(("MMR3HyperAllocOnceNoRel: MMR3HyperMapHCRam failed with rc=%Rrc, try MMHyperAlloc(,%#d,,) instead\n", rc, cb));
int rc2 = MMHyperAlloc(pVM, cb, uAlignment, enmTag, ppv);
if (RT_SUCCESS(rc2))
{
Log2(("MMR3HyperAllocOnceNoRel: cb=%#x uAlignment=%#x returns %Rrc and *ppv=%p\n",
cb, uAlignment, rc, *ppv));
return rc;
}
}
else
AssertMsgFailed(("Failed to allocate %zd bytes! %Rrc\n", cb, rc));
if (rc == VERR_NO_MEMORY)
rc = VERR_MM_HYPER_NO_MEMORY;
LogRel(("MMR3HyperAllocOnceNoRel: cb=%#zx uAlignment=%#x returns %Rrc\n", cb, uAlignment, rc));
return rc;
}
/**
* Convert hypervisor HC virtual address to HC physical address.
*
* @returns HC physical address.
* @param pVM VM Handle
* @param pvR3 Host context virtual address.
*/
VMMR3DECL(RTHCPHYS) MMR3HyperHCVirt2HCPhys(PVM pVM, void *pvR3)
{
PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((uint8_t *)pVM->mm.s.pHyperHeapR3 + pVM->mm.s.offLookupHyper);
for (;;)
{
switch (pLookup->enmType)
{
case MMLOOKUPHYPERTYPE_LOCKED:
{
unsigned off = (uint8_t *)pvR3 - (uint8_t *)pLookup->u.Locked.pvR3;
if (off < pLookup->cb)
return (pLookup->u.Locked.pLockedMem->aPhysPages[off >> PAGE_SHIFT].Phys & X86_PTE_PAE_PG_MASK) | (off & PAGE_OFFSET_MASK);
break;
}
case MMLOOKUPHYPERTYPE_HCPHYS:
{
unsigned off = (uint8_t *)pvR3 - (uint8_t *)pLookup->u.HCPhys.pvR3;
if (off < pLookup->cb)
return pLookup->u.HCPhys.HCPhys + off;
break;
}
case MMLOOKUPHYPERTYPE_GCPHYS:
case MMLOOKUPHYPERTYPE_MMIO2:
case MMLOOKUPHYPERTYPE_DYNAMIC:
/* can (or don't want to) convert these kind of records. */
break;
default:
AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
break;
}
/* next */
if ((unsigned)pLookup->offNext == NIL_OFFSET)
break;
pLookup = (PMMLOOKUPHYPER)((uint8_t *)pLookup + pLookup->offNext);
}
AssertMsgFailed(("pvR3=%p is not inside the hypervisor memory area!\n", pvR3));
return NIL_RTHCPHYS;
}
#if 0 /* unused, not implemented */
/**
* Convert hypervisor HC physical address to HC virtual address.
*
* @returns HC virtual address.
* @param pVM VM Handle
* @param HCPhys Host context physical address.
*/
VMMR3DECL(void *) MMR3HyperHCPhys2HCVirt(PVM pVM, RTHCPHYS HCPhys)
{
void *pv;
int rc = MMR3HyperHCPhys2HCVirtEx(pVM, HCPhys, &pv);
if (VBOX_SUCCESS(rc))
return pv;
AssertMsgFailed(("Invalid address HCPhys=%x rc=%d\n", HCPhys, rc));
return NULL;
}
/**
* Convert hypervisor HC physical address to HC virtual address.
*
* @returns VBox status.
* @param pVM VM Handle
* @param HCPhys Host context physical address.
* @param ppv Where to store the HC virtual address.
*/
VMMR3DECL(int) MMR3HyperHCPhys2HCVirtEx(PVM pVM, RTHCPHYS HCPhys, void **ppv)
{
/*
* Linear search.
*/
/** @todo implement when actually used. */
return VERR_INVALID_POINTER;
}
#endif /* unused, not implemented */
/**
* Read hypervisor memory from GC virtual address.
*
* @returns VBox status.
* @param pVM VM handle.
* @param pvDst Destination address (HC of course).
* @param GCPtr GC virtual address.
* @param cb Number of bytes to read.
*
* @remarks For DBGF only.
*/
VMMR3DECL(int) MMR3HyperReadGCVirt(PVM pVM, void *pvDst, RTGCPTR GCPtr, size_t cb)
{
if (GCPtr - pVM->mm.s.pvHyperAreaGC >= pVM->mm.s.cbHyperArea)
return VERR_INVALID_PARAMETER;
return PGMR3MapRead(pVM, pvDst, GCPtr, cb);
}
/**
* Info handler for 'hma', it dumps the list of lookup records for the hypervisor memory area.
*
* @param pVM The VM handle.
* @param pHlp Callback functions for doing output.
* @param pszArgs Argument string. Optional and specific to the handler.
*/
static DECLCALLBACK(void) mmR3HyperInfoHma(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
{
pHlp->pfnPrintf(pHlp, "Hypervisor Memory Area (HMA) Layout: Base %VGv, 0x%08x bytes\n",
pVM->mm.s.pvHyperAreaGC, pVM->mm.s.cbHyperArea);
PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((uint8_t *)pVM->mm.s.pHyperHeapR3 + pVM->mm.s.offLookupHyper);
for (;;)
{
switch (pLookup->enmType)
{
case MMLOOKUPHYPERTYPE_LOCKED:
pHlp->pfnPrintf(pHlp, "%VGv-%VGv %RHv LOCKED %-*s %s\n",
pLookup->off + pVM->mm.s.pvHyperAreaGC,
pLookup->off + pVM->mm.s.pvHyperAreaGC + pLookup->cb,
pLookup->u.Locked.pvR3,
sizeof(RTHCPTR) * 2,
pLookup->u.Locked.pLockedMem->eType == MM_LOCKED_TYPE_HYPER_NOFREE ? "nofree"
: pLookup->u.Locked.pLockedMem->eType == MM_LOCKED_TYPE_HYPER ? "autofree"
: pLookup->u.Locked.pLockedMem->eType == MM_LOCKED_TYPE_HYPER_PAGES ? "pages"
: pLookup->u.Locked.pLockedMem->eType == MM_LOCKED_TYPE_PHYS ? "gstphys"
: "??",
pLookup->pszDesc);
break;
case MMLOOKUPHYPERTYPE_HCPHYS:
pHlp->pfnPrintf(pHlp, "%VGv-%VGv %RHv HCPHYS %VHp %s\n",
pLookup->off + pVM->mm.s.pvHyperAreaGC,
pLookup->off + pVM->mm.s.pvHyperAreaGC + pLookup->cb,
pLookup->u.HCPhys.pvR3, pLookup->u.HCPhys.HCPhys,
pLookup->pszDesc);
break;
case MMLOOKUPHYPERTYPE_GCPHYS:
pHlp->pfnPrintf(pHlp, "%VGv-%VGv %*s GCPHYS %VGp%*s %s\n",
pLookup->off + pVM->mm.s.pvHyperAreaGC,
pLookup->off + pVM->mm.s.pvHyperAreaGC + pLookup->cb,
sizeof(RTHCPTR) * 2, "",
pLookup->u.GCPhys.GCPhys, RT_ABS((int)(sizeof(RTHCPHYS) - sizeof(RTGCPHYS))) * 2, "",
pLookup->pszDesc);
break;
case MMLOOKUPHYPERTYPE_MMIO2:
pHlp->pfnPrintf(pHlp, "%VGv-%VGv %*s MMIO2 %VGp%*s %s\n",
pLookup->off + pVM->mm.s.pvHyperAreaGC,
pLookup->off + pVM->mm.s.pvHyperAreaGC + pLookup->cb,
sizeof(RTHCPTR) * 2, "",
pLookup->u.MMIO2.off, RT_ABS((int)(sizeof(RTHCPHYS) - sizeof(RTGCPHYS))) * 2, "",
pLookup->pszDesc);
break;
case MMLOOKUPHYPERTYPE_DYNAMIC:
pHlp->pfnPrintf(pHlp, "%VGv-%VGv %*s DYNAMIC %*s %s\n",
pLookup->off + pVM->mm.s.pvHyperAreaGC,
pLookup->off + pVM->mm.s.pvHyperAreaGC + pLookup->cb,
sizeof(RTHCPTR) * 2, "",
sizeof(RTHCPTR) * 2, "",
pLookup->pszDesc);
break;
default:
AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
break;
}
/* next */
if ((unsigned)pLookup->offNext == NIL_OFFSET)
break;
pLookup = (PMMLOOKUPHYPER)((uint8_t *)pLookup + pLookup->offNext);
}
}