mm.h revision 37ebf1330e7e4408b384bddec3e47f19ad388ce0
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * MM - The Memory Manager.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * The contents of this file may alternatively be used under the terms
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * of the Common Development and Distribution License Version 1.0
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * VirtualBox OSE distribution, in which case the provisions of the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * CDDL are applicable instead of those of the GPL.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * You may elect to license modified versions of this file under the
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync * terms and conditions of either the GPL or the CDDL or both.
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
b0db50948c349fa76655abf252f7946b515e8204vboxsync * additional information or have any questions.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** @defgroup grp_mm The Memory Manager API
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** @name RAM Page Flags
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Since internal ranges have a byte granularity it's possible for a
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * page be flagged for several uses. The access virtualization in PGM
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * will choose the most restricted one and use EM to emulate access to
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * the less restricted areas of the page.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Bits 0-11 only since they are fitted into the offset part of a physical memory address.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Reserved - Not RAM, ROM nor MMIO2.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * If this bit is cleared the memory is assumed to be some kind of RAM.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Normal MMIO may set it but that depends on whether the RAM range was
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * created specially for the MMIO or not.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @remarks The current implementation will always reserve backing
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * memory for reserved ranges to simplify things.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** ROM - Read Only Memory.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * The page have a HC physical address which contains the BIOS code. All write
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * access is trapped and ignored.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * HACK: Writable shadow ROM is indicated by both ROM and MMIO2 being
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * set. (We're out of bits.)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** MMIO - Memory Mapped I/O.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * All access is trapped and emulated. No physical backing is required, but
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * might for various reasons be present.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync/** MMIO2 - Memory Mapped I/O, variation 2.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * The virtualization is performed using real memory and only catching
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * a few accesses for like keeping track for dirty pages.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @remark Involved in the shadow ROM hack.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Physical backing memory is allocated dynamically. Not set implies a one time static allocation. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** @name MMR3PhysRegisterEx registration type
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsynctypedef enum
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Normal physical region (flags specify exact page type) */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /** Allocate part of a dynamically allocated physical region */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif /* !VBOX_WITH_NEW_PHYS_CODE */
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync * Memory Allocation Tags.
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync * For use with MMHyperAlloc(), MMR3HeapAlloc(), MMR3HeapAllocEx(),
65697a26b524640b83828b715160c798c43a0424vboxsync * MMR3HeapAllocZ() and MMR3HeapAllocZEx().
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @remark Don't forget to update the dump command in MMHeap.cpp!
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync/** @defgroup grp_mm_hyper Hypervisor Memory Management
65697a26b524640b83828b715160c798c43a0424vboxsync * @ingroup grp_mm
65697a26b524640b83828b715160c798c43a0424vboxsyncVMMDECL(RTR3PTR) MMHyperR0ToR3(PVM pVM, RTR0PTR R0Ptr);
65697a26b524640b83828b715160c798c43a0424vboxsyncVMMDECL(RTRCPTR) MMHyperR0ToRC(PVM pVM, RTR0PTR R0Ptr);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncVMMDECL(void *) MMHyperR0ToCC(PVM pVM, RTR0PTR R0Ptr);
65697a26b524640b83828b715160c798c43a0424vboxsyncVMMDECL(RTR0PTR) MMHyperR3ToR0(PVM pVM, RTR3PTR R3Ptr);
65697a26b524640b83828b715160c798c43a0424vboxsyncVMMDECL(RTRCPTR) MMHyperR3ToRC(PVM pVM, RTR3PTR R3Ptr);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncVMMDECL(RTR3PTR) MMHyperRCToR3(PVM pVM, RTRCPTR RCPtr);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncVMMDECL(RTR0PTR) MMHyperRCToR0(PVM pVM, RTRCPTR RCPtr);
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsyncVMMDECL(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr);
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsyncDECLINLINE(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncVMMDECL(void *) MMHyperRCToCC(PVM pVM, RTRCPTR RCPtr);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(void *) MMHyperRCToCC(PVM pVM, RTRCPTR RCPtr)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return (void *)RCPtr;
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsyncDECLINLINE(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv)
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsyncDECLINLINE(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv)
64f58e4154eaa20c47782b429eeaff09070369bfvboxsyncDECLINLINE(RTRCPTR) MMHyperCCToRC(PVM pVM, void *pv)
64f58e4154eaa20c47782b429eeaff09070369bfvboxsyncVMMDECL(int) MMHyperAlloc(PVM pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, void **ppv);
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsyncVMMDECL(RTGCPTR) MMHyperGetArea(PVM pVM, size_t *pcb);
64f58e4154eaa20c47782b429eeaff09070369bfvboxsyncVMMDECL(bool) MMHyperIsInsideArea(PVM pVM, RTGCPTR GCPtr);
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsyncVMMDECL(RTHCPHYS) MMPage2Phys(PVM pVM, void *pvPage);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncVMMDECL(void *) MMPagePhys2Page(PVM pVM, RTHCPHYS HCPhysPage);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncVMMDECL(int) MMPagePhys2PageEx(PVM pVM, RTHCPHYS HCPhysPage, void **ppvPage);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncVMMDECL(int) MMPagePhys2PageTry(PVM pVM, RTHCPHYS HCPhysPage, void **ppvPage);
65697a26b524640b83828b715160c798c43a0424vboxsync/** @def MMHYPER_RC_ASSERT_RCPTR
65697a26b524640b83828b715160c798c43a0424vboxsync * Asserts that an address is either NULL or inside the hypervisor memory area.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * This assertion only works while IN_RC, it's a NOP everywhere else.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @thread The Emulation Thread.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync# define MMHYPER_RC_ASSERT_RCPTR(pVM, RCPtr) Assert(MMHyperIsInsideArea((pVM), (RTRCUINTPTR)(RCPtr)) || !(RCPtr))
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync# define MMHYPER_RC_ASSERT_RCPTR(pVM, RCPtr) do { } while (0)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** @defgroup grp_mm_r3 The MM Host Context Ring-3 API
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @ingroup grp_mm
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncVMMR3DECL(int) MMR3IncreaseBaseReservation(PVM pVM, uint64_t cAddBasePages);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncVMMR3DECL(int) MMR3AdjustFixedReservation(PVM pVM, int32_t cDeltaFixedPages, const char *pszDesc);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncVMMR3DECL(int) MMR3UpdateShadowReservation(PVM pVM, uint32_t cShadowPages);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncVMMR3DECL(int) MMR3HCPhys2HCVirt(PVM pVM, RTHCPHYS HCPhys, void **ppv);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncVMMR3DECL(int) MMR3ReadGCVirt(PVM pVM, void *pvDst, RTGCPTR GCPtr, size_t cb);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncVMMR3DECL(int) MMR3WriteGCVirt(PVM pVM, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync/** @defgroup grp_mm_r3_hyper Hypervisor Memory Manager (HC R3 Portion)
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsync * @ingroup grp_mm_r3
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncVMMDECL(int) MMR3HyperAllocOnceNoRel(PVM pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, void **ppv);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncVMMR3DECL(int) MMR3HyperMapHCPhys(PVM pVM, void *pvR3, RTR0PTR pvR0, RTHCPHYS HCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncVMMR3DECL(int) MMR3HyperMapGCPhys(PVM pVM, RTGCPHYS GCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncVMMR3DECL(int) MMR3HyperMapMMIO2(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb, const char *pszDesc, PRTRCPTR pRCPtr);
f4aad55f8addd816ef005845842a2418bbdc3ea2vboxsyncVMMR3DECL(int) MMR3HyperMapPages(PVM pVM, void *pvR3, RTR0PTR pvR0, size_t cPages, PCSUPPAGE paPages, const char *pszDesc, PRTGCPTR pGCPtr);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncVMMR3DECL(int) MMR3HyperReserve(PVM pVM, unsigned cb, const char *pszDesc, PRTGCPTR pGCPtr);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncVMMR3DECL(RTHCPHYS) MMR3HyperHCVirt2HCPhys(PVM pVM, void *pvHC);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncVMMR3DECL(int) MMR3HyperHCVirt2HCPhysEx(PVM pVM, void *pvHC, PRTHCPHYS pHCPhys);
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsyncVMMR3DECL(void *) MMR3HyperHCPhys2HCVirt(PVM pVM, RTHCPHYS HCPhys);
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsyncVMMR3DECL(int) MMR3HyperHCPhys2HCVirtEx(PVM pVM, RTHCPHYS HCPhys, void **ppv);
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsyncVMMR3DECL(int) MMR3HyperReadGCVirt(PVM pVM, void *pvDst, RTGCPTR GCPtr, size_t cb);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** @defgroup grp_mm_phys Guest Physical Memory Manager
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @ingroup grp_mm_r3
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncVMMR3DECL(int) MMR3PhysRegisterEx(PVM pVM, void *pvRam, RTGCPHYS GCPhys, unsigned cb, unsigned fFlags, MMPHYSREG enmType, const char *pszDesc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncVMMR3DECL(int) MMR3PhysRomRegister(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, const void *pvBinary, bool fShadow, const char *pszDesc);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncVMMR3DECL(int) MMR3PhysRomProtect(PVM pVM, RTGCPHYS GCPhys, RTUINT cbRange);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncVMMR3DECL(int) MMR3PhysReserve(PVM pVM, RTGCPHYS GCPhys, RTUINT cbRange, const char *pszDesc);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** @defgroup grp_mm_page Physical Page Pool
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @ingroup grp_mm_r3
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsyncVMMR3DECL(void) MMR3PageFree(PVM pVM, void *pvPage);
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsyncVMMR3DECL(void) MMR3PageFreeLow(PVM pVM, void *pvPage);
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsyncVMMR3DECL(void) MMR3PageFreeByPhys(PVM pVM, RTHCPHYS HCPhysPage);
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync/** @defgroup grp_mm_heap Heap Manager
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync * @ingroup grp_mm_r3
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsyncVMMR3DECL(void *) MMR3HeapAlloc(PVM pVM, MMTAG enmTag, size_t cbSize);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncVMMR3DECL(void *) MMR3HeapAllocU(PUVM pUVM, MMTAG enmTag, size_t cbSize);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncVMMR3DECL(int) MMR3HeapAllocEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncVMMR3DECL(int) MMR3HeapAllocExU(PUVM pUVM, MMTAG enmTag, size_t cbSize, void **ppv);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncVMMR3DECL(void *) MMR3HeapAllocZ(PVM pVM, MMTAG enmTag, size_t cbSize);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncVMMR3DECL(void *) MMR3HeapAllocZU(PUVM pUVM, MMTAG enmTag, size_t cbSize);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncVMMR3DECL(int) MMR3HeapAllocZEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncVMMR3DECL(int) MMR3HeapAllocZExU(PUVM pUVM, MMTAG enmTag, size_t cbSize, void **ppv);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncVMMR3DECL(void *) MMR3HeapRealloc(void *pv, size_t cbNewSize);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncVMMR3DECL(char *) MMR3HeapStrDup(PVM pVM, MMTAG enmTag, const char *psz);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncVMMR3DECL(char *) MMR3HeapStrDupU(PUVM pUVM, MMTAG enmTag, const char *psz);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncVMMR3DECL(char *) MMR3HeapAPrintf(PVM pVM, MMTAG enmTag, const char *pszFormat, ...);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncVMMR3DECL(char *) MMR3HeapAPrintfU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, ...);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncVMMR3DECL(char *) MMR3HeapAPrintfV(PVM pVM, MMTAG enmTag, const char *pszFormat, va_list va);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncVMMR3DECL(char *) MMR3HeapAPrintfVU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, va_list va);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync#endif /* IN_RING3 */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync/** @defgroup grp_mm_gc The MM Guest Context API
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync * @ingroup grp_mm
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncVMMRCDECL(void) MMGCRamRegisterTrapHandler(PVM pVM);
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsyncVMMRCDECL(void) MMGCRamDeregisterTrapHandler(PVM pVM);
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsyncVMMRCDECL(int) MMGCRamReadNoTrapHandler(void *pDst, void *pSrc, size_t cb);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncVMMRCDECL(int) MMGCRamWriteNoTrapHandler(void *pDst, void *pSrc, size_t cb);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncVMMRCDECL(int) MMGCRamRead(PVM pVM, void *pDst, void *pSrc, size_t cb);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncVMMRCDECL(int) MMGCRamWrite(PVM pVM, void *pDst, void *pSrc, size_t cb);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#endif /* IN_RC */