Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

MMInternal.h

Go to the documentation of this file.
/* $Id: MMInternal.h $ */
/** @file
 * MM - Internal header file.
 */

/*
 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
 * Clara, CA 95054 USA or visit http://www.sun.com if you need
 * additional information or have any questions.
 */

#ifndef ___MMInternal_h
#define ___MMInternal_h

#include <VBox/cdefs.h>
#include <VBox/types.h>
#include <VBox/sup.h>
#include <VBox/stam.h>
#include <VBox/pdmcritsect.h>
#include <iprt/avl.h>
#include <iprt/critsect.h>



/** @defgroup grp_mm_int   Internals
 * @internal
 * @ingroup grp_mm
 * @{
 */


/** @name MMR3Heap - VM Ring-3 Heap Internals
 * @{
 */

/** @def MMR3HEAP_SIZE_ALIGNMENT
 * The allocation size alignment of the MMR3Heap.
 */
00049 #define MMR3HEAP_SIZE_ALIGNMENT     16

/** @def MMR3HEAP_WITH_STATISTICS
 * Enable MMR3Heap statistics.
 */
#if !defined(MMR3HEAP_WITH_STATISTICS) && defined(VBOX_WITH_STATISTICS)
# define MMR3HEAP_WITH_STATISTICS
#endif

/**
 * Heap statistics record.
 * There is one global and one per allocation tag.
 */
00062 typedef struct MMHEAPSTAT
{
    /** Core avl node, key is the tag. */
00065     AVLULNODECORE           Core;
    /** Pointer to the heap the memory belongs to. */
00067     struct MMHEAP          *pHeap;
#ifdef MMR3HEAP_WITH_STATISTICS
    /** Number of allocation. */
    uint64_t                cAllocations;
    /** Number of reallocations. */
    uint64_t                cReallocations;
    /** Number of frees. */
    uint64_t                cFrees;
    /** Failures. */
    uint64_t                cFailures;
    /** Number of bytes allocated (sum). */
    uint64_t                cbAllocated;
    /** Number of bytes freed. */
    uint64_t                cbFreed;
    /** Number of bytes currently allocated. */
    size_t                  cbCurAllocated;
#endif
} MMHEAPSTAT;
/** Pointer to heap statistics record. */
00086 typedef MMHEAPSTAT *PMMHEAPSTAT;



/**
 * Additional heap block header for relating allocations to the VM.
 */
00093 typedef struct MMHEAPHDR
{
    /** Pointer to the next record. */
00096     struct MMHEAPHDR       *pNext;
    /** Pointer to the previous record. */
00098     struct MMHEAPHDR       *pPrev;
    /** Pointer to the heap statistics record.
     * (Where the a PVM can be found.) */
00101     PMMHEAPSTAT             pStat;
    /** Size of the allocation (including this header). */
00103     size_t                  cbSize;
} MMHEAPHDR;
/** Pointer to MM heap header. */
00106 typedef MMHEAPHDR *PMMHEAPHDR;


/** MM Heap structure. */
00110 typedef struct MMHEAP
{
    /** Lock protecting the heap. */
00113     RTCRITSECT              Lock;
    /** Heap block list head. */
00115     PMMHEAPHDR              pHead;
    /** Heap block list tail. */
00117     PMMHEAPHDR              pTail;
    /** Heap per tag statistics tree. */
00119     PAVLULNODECORE          pStatTree;
    /** The VM handle. */
00121     PUVM                    pUVM;
    /** Heap global statistics. */
00123     MMHEAPSTAT              Stat;
} MMHEAP;
/** Pointer to MM Heap structure. */
00126 typedef MMHEAP *PMMHEAP;

/** @} */


/** @name MMUkHeap - VM User-kernel Heap Internals
 * @{
 */

/** @def MMUKHEAP_SIZE_ALIGNMENT
 * The allocation size alignment of the MMR3UkHeap.
 */
00138 #define MMUKHEAP_SIZE_ALIGNMENT   16

/** @def MMUKHEAP_WITH_STATISTICS
 * Enable MMUkHeap statistics.
 */
#if !defined(MMUKHEAP_WITH_STATISTICS) && defined(VBOX_WITH_STATISTICS)
# define MMUKHEAP_WITH_STATISTICS
#endif


/**
 * Heap statistics record.
 * There is one global and one per allocation tag.
 */
00152 typedef struct MMUKHEAPSTAT
{
    /** Core avl node, key is the tag. */
00155     AVLULNODECORE           Core;
    /** Number of allocation. */
00157     uint64_t                cAllocations;
    /** Number of reallocations. */
00159     uint64_t                cReallocations;
    /** Number of frees. */
00161     uint64_t                cFrees;
    /** Failures. */
00163     uint64_t                cFailures;
    /** Number of bytes allocated (sum). */
00165     uint64_t                cbAllocated;
    /** Number of bytes freed. */
00167     uint64_t                cbFreed;
    /** Number of bytes currently allocated. */
00169     size_t                  cbCurAllocated;
} MMUKHEAPSTAT;
/** Pointer to heap statistics record. */
00172 typedef MMUKHEAPSTAT *PMMUKHEAPSTAT;

/**
 * Sub heap tracking record.
 */
00177 typedef struct MMUKHEAPSUB
{
    /** Pointer to the next sub-heap. */
00180     struct MMUKHEAPSUB     *pNext;
    /** The base address of the sub-heap. */
00182     void                   *pv;
    /** The size of the sub-heap.  */
00184     size_t                  cb;
    /** The handle of the simple block pointer. */
00186     RTHEAPSIMPLE            hSimple;
    /** The ring-0 address corresponding to MMUKHEAPSUB::pv. */
00188     RTR0PTR                 pvR0;
} MMUKHEAPSUB;
/** Pointer to a sub-heap tracking record. */
00191 typedef MMUKHEAPSUB *PMMUKHEAPSUB;


/** MM User-kernel Heap structure. */
00195 typedef struct MMUKHEAP
{
    /** Lock protecting the heap. */
00198     RTCRITSECT              Lock;
    /** Head of the sub-heap LIFO. */
00200     PMMUKHEAPSUB            pSubHeapHead;
    /** Heap per tag statistics tree. */
00202     PAVLULNODECORE          pStatTree;
    /** The VM handle. */
00204     PUVM                    pUVM;
    /** Heap global statistics. */
00206     MMUKHEAPSTAT            Stat;
} MMUKHEAP;
/** Pointer to MM Heap structure. */
00209 typedef MMUKHEAP *PMMUKHEAP;

/** @} */



/** @name Hypervisor Heap Internals
 * @{
 */

/** @def MMHYPER_HEAP_FREE_DELAY
 * If defined, it indicates the number of frees that should be delayed.
 */
#if defined(DOXYGEN_RUNNING)
# define MMHYPER_HEAP_FREE_DELAY            64
#endif

/** @def MMHYPER_HEAP_FREE_POISON
 * If defined, it indicates that freed memory should be poisoned
 * with the value it has.
 */
#if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
# define MMHYPER_HEAP_FREE_POISON           0xcb
#endif

/** @def MMHYPER_HEAP_STRICT
 * Enables a bunch of assertions in the heap code. */
#if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
# define MMHYPER_HEAP_STRICT 1
# if 0 || defined(DOXYGEN_RUNNING)
/** @def MMHYPER_HEAP_STRICT_FENCE
 * Enables tail fence. */
#  define MMHYPER_HEAP_STRICT_FENCE
/** @def MMHYPER_HEAP_STRICT_FENCE_SIZE
 * The fence size in bytes. */
#  define MMHYPER_HEAP_STRICT_FENCE_SIZE    256
/** @def MMHYPER_HEAP_STRICT_FENCE_U32
 * The fence filler. */
#  define MMHYPER_HEAP_STRICT_FENCE_U32     UINT32_C(0xdeadbeef)
# endif
#endif

/**
 * Hypervisor heap statistics record.
 * There is one global and one per allocation tag.
 */
00255 typedef struct MMHYPERSTAT
{
    /** Core avl node, key is the tag.
     * @todo The type is wrong! Get your lazy a$$ over and create that offsetted uint32_t version we need here!  */
00259     AVLOGCPHYSNODECORE      Core;
    /** Aligning the 64-bit fields on a 64-bit line. */
00261     uint32_t                u32Padding0;
    /** Indicator for whether these statistics are registered with STAM or not. */
00263     bool                    fRegistered;
    /** Number of allocation. */
00265     uint64_t                cAllocations;
    /** Number of frees. */
00267     uint64_t                cFrees;
    /** Failures. */
00269     uint64_t                cFailures;
    /** Number of bytes allocated (sum). */
00271     uint64_t                cbAllocated;
    /** Number of bytes freed (sum). */
00273     uint64_t                cbFreed;
    /** Number of bytes currently allocated. */
00275     uint32_t                cbCurAllocated;
    /** Max number of bytes allocated. */
00277     uint32_t                cbMaxAllocated;
} MMHYPERSTAT;
/** Pointer to hypervisor heap statistics record. */
00280 typedef MMHYPERSTAT *PMMHYPERSTAT;

/**
 * Hypervisor heap chunk.
 */
00285 typedef struct MMHYPERCHUNK
{
    /** Previous block in the list of all blocks.
     * This is relative to the start of the heap. */
00289     uint32_t                offNext;
    /** Offset to the previous block relative to this one. */
00291     int32_t                 offPrev;
    /** The statistics record this allocation belongs to (self relative). */
00293     int32_t                 offStat;
    /** Offset to the heap block (self relative). */
00295     int32_t                 offHeap;
} MMHYPERCHUNK;
/** Pointer to a hypervisor heap chunk. */
00298 typedef MMHYPERCHUNK *PMMHYPERCHUNK;


/**
 * Hypervisor heap chunk.
 */
00304 typedef struct MMHYPERCHUNKFREE
{
    /** Main list. */
00307     MMHYPERCHUNK            core;
    /** Offset of the next chunk in the list of free nodes. */
00309     uint32_t                offNext;
    /** Offset of the previous chunk in the list of free nodes. */
00311     int32_t                 offPrev;
    /** Size of the block. */
00313     uint32_t                cb;
} MMHYPERCHUNKFREE;
/** Pointer to a free hypervisor heap chunk. */
00316 typedef MMHYPERCHUNKFREE *PMMHYPERCHUNKFREE;


/**
 * The hypervisor heap.
 */
00322 typedef struct MMHYPERHEAP
{
    /** The typical magic (MMHYPERHEAP_MAGIC). */
00325     uint32_t                u32Magic;
    /** The heap size. (This structure is not included!) */
00327     uint32_t                cbHeap;
    /** Lock protecting the heap. */
00329     PDMCRITSECT             Lock;
    /** The HC ring-3 address of the heap. */
    R3PTRTYPE(uint8_t *)    pbHeapR3;
    /** The HC ring-3 address of the shared VM strcture. */
00333     PVMR3                   pVMR3;
    /** The HC ring-0 address of the heap. */
    R0PTRTYPE(uint8_t *)    pbHeapR0;
    /** The HC ring-0 address of the shared VM strcture. */
00337     PVMR0                   pVMR0;
    /** The RC address of the heap. */
    RCPTRTYPE(uint8_t *)    pbHeapRC;
    /** The RC address of the shared VM strcture. */
00341     PVMRC                   pVMRC;
    /** The amount of free memory in the heap. */
00343     uint32_t                cbFree;
    /** Offset of the first free chunk in the heap.
     * The offset is relative to the start of the heap. */
00346     uint32_t                offFreeHead;
    /** Offset of the last free chunk in the heap.
     * The offset is relative to the start of the heap. */
00349     uint32_t                offFreeTail;
    /** Offset of the first page aligned block in the heap.
     * The offset is equal to cbHeap initially. */
00352     uint32_t                offPageAligned;
    /** Tree of hypervisor heap statistics. */
00354     AVLOGCPHYSTREE          HyperHeapStatTree;
#ifdef MMHYPER_HEAP_FREE_DELAY
    /** Where to insert the next free. */
    uint32_t                iDelayedFree;
    /** Array of delayed frees. Circular. Offsets relative to this structure. */
    struct
    {
        /** The free caller address. */
        RTUINTPTR           uCaller;
        /** The offset of the freed chunk. */
        uint32_t            offChunk;
    } aDelayedFrees[MMHYPER_HEAP_FREE_DELAY];
#else
    /** Padding the structure to a 64-bit aligned size. */
00368     uint32_t                u32Padding0;
#endif
    /** The heap physical pages. */
    R3PTRTYPE(PSUPPAGE)     paPages;
#if HC_ARCH_BITS == 32
    /** Padding the structure to a 64-bit aligned size. */
    uint32_t                u32Padding1;
#endif
} MMHYPERHEAP;
/** Pointer to the hypervisor heap. */
00378 typedef MMHYPERHEAP *PMMHYPERHEAP;

/** Magic value for MMHYPERHEAP. (C. S. Lewis) */
00381 #define MMHYPERHEAP_MAGIC               UINT32_C(0x18981129)


/**
 * Hypervisor heap minimum alignment (16 bytes).
 */
00387 #define MMHYPER_HEAP_ALIGN_MIN          16

/**
 * The aligned size of the the MMHYPERHEAP structure.
 */
00392 #define MMYPERHEAP_HDR_SIZE             RT_ALIGN_Z(sizeof(MMHYPERHEAP), MMHYPER_HEAP_ALIGN_MIN * 4)

/** @name Hypervisor heap chunk flags.
 * The flags are put in the first bits of the MMHYPERCHUNK::offPrev member.
 * These bits aren't used anyway because of the chunk minimal alignment (16 bytes).
 * @{ */
/** The chunk is free. (The code ASSUMES this is 0!) */
00399 #define MMHYPERCHUNK_FLAGS_FREE         0x0
/** The chunk is in use. */
00401 #define MMHYPERCHUNK_FLAGS_USED         0x1
/** The type mask. */
00403 #define MMHYPERCHUNK_FLAGS_TYPE_MASK    0x1
/** The flag mask */
00405 #define MMHYPERCHUNK_FLAGS_MASK         0x1

/** Checks if the chunk is free. */
00408 #define MMHYPERCHUNK_ISFREE(pChunk)                 ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_FREE )
/** Checks if the chunk is used. */
00410 #define MMHYPERCHUNK_ISUSED(pChunk)                 ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_USED )
/** Toggles FREE/USED flag of a chunk. */
00412 #define MMHYPERCHUNK_SET_TYPE(pChunk, type)         do { (pChunk)->offPrev = ((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_TYPE_MASK) | ((type) & MMHYPERCHUNK_FLAGS_TYPE_MASK); } while (0)

/** Gets the prev offset without the flags. */
00415 #define MMHYPERCHUNK_GET_OFFPREV(pChunk)            ((int32_t)((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_MASK))
/** Sets the prev offset without changing the flags. */
00417 #define MMHYPERCHUNK_SET_OFFPREV(pChunk, off)       do { (pChunk)->offPrev = (off) | ((pChunk)->offPrev & MMHYPERCHUNK_FLAGS_MASK); } while (0)
#if 0
/** Clears one or more flags. */
#define MMHYPERCHUNK_FLAGS_OP_CLEAR(pChunk, fFlags) do { ((pChunk)->offPrev) &= ~((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
/** Sets one or more flags. */
#define MMHYPERCHUNK_FLAGS_OP_SET(pChunk, fFlags)   do { ((pChunk)->offPrev) |=  ((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
/** Checks if one is set. */
#define MMHYPERCHUNK_FLAGS_OP_ISSET(pChunk, fFlag)  (!!(((pChunk)->offPrev) & ((fFlag) & MMHYPERCHUNK_FLAGS_MASK)))
#endif
/** @} */

/** @} */


/** @name Page Pool Internals
 * @{
 */

/**
 * Page sub pool
 *
 * About the allocation of this structure. To keep the number of heap blocks,
 * the number of heap calls, and fragmentation low we allocate all the data
 * related to a MMPAGESUBPOOL node in one chunk. That means that after the
 * bitmap (which is of variable size) comes the SUPPAGE records and then
 * follows the lookup tree nodes. (The heap in question is the hyper heap.)
 */
00444 typedef struct MMPAGESUBPOOL
{
    /** Pointer to next sub pool. */
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
    R3PTRTYPE(struct MMPAGESUBPOOL *)   pNext;
#else
    R3R0PTRTYPE(struct MMPAGESUBPOOL *) pNext;
#endif
    /** Pointer to next sub pool in the free chain.
     * This is NULL if we're not in the free chain or at the end of it. */
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
    R3PTRTYPE(struct MMPAGESUBPOOL *)   pNextFree;
#else
    R3R0PTRTYPE(struct MMPAGESUBPOOL *) pNextFree;
#endif
    /** Pointer to array of lock ranges.
     * This is allocated together with the MMPAGESUBPOOL and thus needs no freeing.
     * It follows immediately after the bitmap.
     * The reserved field is a pointer to this structure.
     */
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
    R3PTRTYPE(PSUPPAGE)                 paPhysPages;
#else
    R3R0PTRTYPE(PSUPPAGE)               paPhysPages;
#endif
    /** Pointer to the first page. */
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
    R3PTRTYPE(void *)                   pvPages;
#else
    R3R0PTRTYPE(void *)                 pvPages;
#endif
    /** Size of the subpool. */
00476     uint32_t                            cPages;
    /** Number of free pages. */
00478     uint32_t                            cPagesFree;
    /** The allocation bitmap.
     * This may extend beyond the end of the defined array size.
     */
00482     uint32_t                            auBitmap[1];
    /* ... SUPPAGE                      aRanges[1]; */
} MMPAGESUBPOOL;
/** Pointer to page sub pool. */
00486 typedef MMPAGESUBPOOL *PMMPAGESUBPOOL;

/**
 * Page pool.
 */
00491 typedef struct MMPAGEPOOL
{
    /** List of subpools. */
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
    R3PTRTYPE(PMMPAGESUBPOOL)           pHead;
#else
    R3R0PTRTYPE(PMMPAGESUBPOOL)         pHead;
#endif
    /** Head of subpools with free pages. */
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
    R3PTRTYPE(PMMPAGESUBPOOL)           pHeadFree;
#else
    R3R0PTRTYPE(PMMPAGESUBPOOL)         pHeadFree;
#endif
    /** AVLPV tree for looking up HC virtual addresses.
     * The tree contains MMLOOKUPVIRTPP records.
     */
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
    R3PTRTYPE(PAVLPVNODECORE)           pLookupVirt;
#else
    R3R0PTRTYPE(PAVLPVNODECORE)         pLookupVirt;
#endif
    /** Tree for looking up HC physical addresses.
     * The tree contains MMLOOKUPPHYSHC records.
     */
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
    R3PTRTYPE(AVLHCPHYSTREE)            pLookupPhys;
#else
    R3R0PTRTYPE(AVLHCPHYSTREE)          pLookupPhys;
#endif
    /** Pointer to the VM this pool belongs. */
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
    PVMR3                               pVM;
#else
    R3R0PTRTYPE(PVM)                    pVM;
#endif
    /** Flag indicating the allocation method.
     * Set: SUPR3LowAlloc().
     * Clear: SUPR3PageAllocEx(). */
00530     bool                                fLow;
    /** Number of subpools. */
00532     uint32_t                            cSubPools;
    /** Number of pages in pool. */
00534     uint32_t                            cPages;
#ifdef VBOX_WITH_STATISTICS
    /** Number of free pages in pool. */
    uint32_t                            cFreePages;
    /** Number of alloc calls. */
    STAMCOUNTER                         cAllocCalls;
    /** Number of free calls. */
    STAMCOUNTER                         cFreeCalls;
    /** Number of to phys conversions. */
    STAMCOUNTER                         cToPhysCalls;
    /** Number of to virtual conversions. */
    STAMCOUNTER                         cToVirtCalls;
    /** Number of real errors. */
    STAMCOUNTER                         cErrors;
#endif
} MMPAGEPOOL;
/** Pointer to page pool. */
00551 typedef MMPAGEPOOL *PMMPAGEPOOL;

/**
 * Lookup record for HC virtual memory in the page pool.
 */
00556 typedef struct MMPPLOOKUPHCPTR
{
    /** The key is virtual address. */
00559     AVLPVNODECORE           Core;
    /** Pointer to subpool if lookup record for a pool. */
00561     struct MMPAGESUBPOOL   *pSubPool;
} MMPPLOOKUPHCPTR;
/** Pointer to virtual memory lookup record. */
00564 typedef MMPPLOOKUPHCPTR *PMMPPLOOKUPHCPTR;

/**
 * Lookup record for HC physical memory.
 */
00569 typedef struct MMPPLOOKUPHCPHYS
{
    /** The key is physical address. */
00572     AVLHCPHYSNODECORE       Core;
    /** Pointer to SUPPAGE record for this physical address. */
00574     PSUPPAGE                pPhysPage;
} MMPPLOOKUPHCPHYS;
/** Pointer to physical memory lookup record. */
00577 typedef MMPPLOOKUPHCPHYS *PMMPPLOOKUPHCPHYS;

/** @} */


/**
 * Hypervisor memory mapping type.
 */
00585 typedef enum MMLOOKUPHYPERTYPE
{
    /** Invalid record. This is used for record which are incomplete. */
00588     MMLOOKUPHYPERTYPE_INVALID = 0,
    /** Mapping of locked memory. */
00590     MMLOOKUPHYPERTYPE_LOCKED,
    /** Mapping of contiguous HC physical memory. */
00592     MMLOOKUPHYPERTYPE_HCPHYS,
    /** Mapping of contiguous GC physical memory. */
00594     MMLOOKUPHYPERTYPE_GCPHYS,
    /** Mapping of MMIO2 memory. */
00596     MMLOOKUPHYPERTYPE_MMIO2,
    /** Dynamic mapping area (MMR3HyperReserve).
     * A conversion will require to check what's in the page table for the pages. */
00599     MMLOOKUPHYPERTYPE_DYNAMIC
} MMLOOKUPHYPERTYPE;

/**
 * Lookup record for the hypervisor memory area.
 */
00605 typedef struct MMLOOKUPHYPER
{
    /** Byte offset from the start of this record to the next.
     * If the value is NIL_OFFSET the chain is terminated. */
00609     int32_t                 offNext;
    /** Offset into the hypvervisor memory area. */
00611     uint32_t                off;
    /** Size of this part. */
00613     uint32_t                cb;
    /** Locking type. */
00615     MMLOOKUPHYPERTYPE       enmType;
    /** Type specific data */
    union
    {
        /** Locked memory. */
        struct
        {
            /** Host context ring-3 pointer. */
            R3PTRTYPE(void *)       pvR3;
            /** Host context ring-0 pointer. Optional. */
00625             RTR0PTR                 pvR0;
            /** Pointer to an array containing the physical address of each page. */
            R3PTRTYPE(PRTHCPHYS)    paHCPhysPages;
        } Locked;

        /** Contiguous physical memory. */
        struct
        {
            /** Host context ring-3 pointer. */
            R3PTRTYPE(void *)       pvR3;
            /** Host context ring-0 pointer. Optional. */
            RTR0PTR                 pvR0;
            /** HC physical address corresponding to pvR3/pvR0. */
00638             RTHCPHYS                HCPhys;
        } HCPhys;

        /** Contiguous guest physical memory. */
        struct
        {
            /** The memory address (Guest Context). */
00645             RTGCPHYS                GCPhys;
        } GCPhys;

        /** MMIO2 memory. */
        struct
        {
            /** The device instance owning the MMIO2 region. */
00652             PPDMDEVINSR3            pDevIns;
            /** The region number. */
00654             uint32_t                iRegion;
            /** The offset into the MMIO2 region. */
00656             RTGCPHYS                off;
        } MMIO2;
    } u;
    /** Description. */
    R3PTRTYPE(const char *) pszDesc;
} MMLOOKUPHYPER;
/** Pointer to a hypervisor memory lookup record. */
00663 typedef MMLOOKUPHYPER *PMMLOOKUPHYPER;


/**
 * Converts a MM pointer into a VM pointer.
 * @returns Pointer to the VM structure the MM is part of.
 * @param   pMM   Pointer to MM instance data.
 */
00671 #define MM2VM(pMM)  ( (PVM)((uint8_t *)pMM - pMM->offVM) )


/**
 * MM Data (part of VM)
 */
00677 typedef struct MM
{
    /** Offset to the VM structure.
     * See MM2VM(). */
00681     RTINT                       offVM;

    /** Set if MMR3InitPaging has been called. */
00684     bool                        fDoneMMR3InitPaging;
    /** Set if PGM has been initialized and we can safely call PGMR3Map(). */
00686     bool                        fPGMInitialized;
#if GC_ARCH_BITS == 64 || HC_ARCH_BITS == 64
    uint32_t                    u32Padding1; /**< alignment padding. */
#endif

    /** Lookup list for the Hypervisor Memory Area.
     * The offset is relative to the start of the heap.
     * Use pHyperHeapR3, pHyperHeapR0 or pHypeRHeapRC to calculate the address.
     */
00695     RTUINT                      offLookupHyper;

    /** The offset of the next static mapping in the Hypervisor Memory Area. */
00698     RTUINT                      offHyperNextStatic;
    /** The size of the HMA.
     * Starts at 12MB and will be fixed late in the init process. */
00701     RTUINT                      cbHyperArea;

    /** Guest address of the Hypervisor Memory Area.
     * @remarks It's still a bit open whether this should be change to RTRCPTR or
     *          remain a RTGCPTR. */
00706     RTGCPTR                     pvHyperAreaGC;

    /** The hypervisor heap (GC Ptr). */
    RCPTRTYPE(PMMHYPERHEAP)     pHyperHeapRC;
#if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 64
    uint32_t                    u32Padding2;
#endif

    /** The hypervisor heap (R0 Ptr). */
    R0PTRTYPE(PMMHYPERHEAP)     pHyperHeapR0;
#ifndef VBOX_WITH_2X_4GB_ADDR_SPACE
    /** Page pool - R0 Ptr. */
    R0PTRTYPE(PMMPAGEPOOL)      pPagePoolR0;
    /** Page pool pages in low memory R0 Ptr. */
    R0PTRTYPE(PMMPAGEPOOL)      pPagePoolLowR0;
#endif /* !VBOX_WITH_2X_4GB_ADDR_SPACE */

    /** The hypervisor heap (R3 Ptr). */
    R3PTRTYPE(PMMHYPERHEAP)     pHyperHeapR3;
    /** Page pool - R3 Ptr. */
    R3PTRTYPE(PMMPAGEPOOL)      pPagePoolR3;
    /** Page pool pages in low memory R3 Ptr. */
    R3PTRTYPE(PMMPAGEPOOL)      pPagePoolLowR3;

    /** Pointer to the dummy page.
     * The dummy page is a paranoia thingy used for instance for pure MMIO RAM ranges
     * to make sure any bugs will not harm whatever the system stores in the first
     * physical page. */
    R3PTRTYPE(void *)           pvDummyPage;
    /** Physical address of the dummy page. */
00736     RTHCPHYS                    HCPhysDummyPage;

    /** Size of the base RAM in bytes. (The CFGM RamSize value.) */
00739     uint64_t                    cbRamBase;
    /** The number of base RAM pages that PGM has reserved (GMM).
     * @remarks Shadow ROMs will be counted twice (RAM+ROM), so it won't be 1:1 with
     *          what the guest sees. */
00743     uint64_t                    cBasePages;
    /** The number of handy pages that PGM has reserved (GMM).
     * These are kept out of cBasePages and thus out of the saved state. */
00746     uint32_t                    cHandyPages;
    /** The number of shadow pages PGM has reserved (GMM). */
00748     uint32_t                    cShadowPages;
    /** The number of fixed pages we've reserved (GMM). */
00750     uint32_t                    cFixedPages;
    /** Padding. */
00752     uint32_t                    u32Padding0;
} MM;
/** Pointer to MM Data (part of VM). */
00755 typedef MM *PMM;


/**
 * MM data kept in the UVM.
 */
00761 typedef struct MMUSERPERVM
{
    /** Pointer to the MM R3 Heap. */
    R3PTRTYPE(PMMHEAP)          pHeap;
    /** Pointer to the MM Uk Heap. */
    R3PTRTYPE(PMMUKHEAP)        pUkHeap;
} MMUSERPERVM;
/** Pointer to the MM data kept in the UVM. */
00769 typedef MMUSERPERVM *PMMUSERPERVM;


RT_C_DECLS_BEGIN


int  mmR3UpdateReservation(PVM pVM);

int  mmR3PagePoolInit(PVM pVM);
void mmR3PagePoolTerm(PVM pVM);

int  mmR3HeapCreateU(PUVM pUVM, PMMHEAP *ppHeap);
void mmR3HeapDestroy(PMMHEAP pHeap);

void mmR3UkHeapDestroy(PMMUKHEAP pHeap);
int  mmR3UkHeapCreateU(PUVM pUVM, PMMUKHEAP *ppHeap);


int  mmR3HyperInit(PVM pVM);
int  mmR3HyperTerm(PVM pVM);
int  mmR3HyperInitPaging(PVM pVM);

const char *mmGetTagName(MMTAG enmTag);

/**
 * Converts a pool address to a physical address.
 * The specified allocation type must match with the address.
 *
 * @returns Physical address.
 * @returns NIL_RTHCPHYS if not found or eType is not matching.
 * @param   pPool   Pointer to the page pool.
 * @param   pv      The address to convert.
 * @thread  The Emulation Thread.
 */
RTHCPHYS mmPagePoolPtr2Phys(PMMPAGEPOOL pPool, void *pv);

/**
 * Converts a pool physical address to a linear address.
 * The specified allocation type must match with the address.
 *
 * @returns Physical address.
 * @returns NULL if not found or eType is not matching.
 * @param   pPool       Pointer to the page pool.
 * @param   HCPhys      The address to convert.
 * @thread  The Emulation Thread.
 */
void *mmPagePoolPhys2Ptr(PMMPAGEPOOL pPool, RTHCPHYS HCPhys);

RT_C_DECLS_END

/** @} */

#endif


Generated by  Doxygen 1.6.0   Back to index