VirtualBox

Changeset 5106

Show
Ignore:
Timestamp:
09/28/07 20:31:29 (1 year ago)
Author:
vboxsync
Message:

Hooked up the GMM code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/VBox/gmm.h

    r5086 r5106  
    2121#include <VBox/types.h> 
    2222#include <VBox/gvmm.h> 
     23#include <VBox/sup.h> 
    2324 
    2425__BEGIN_DECLS 
     
    4950/** The shift factor for converting a page id into a chunk id. */ 
    5051#define GMM_CHUNKID_SHIFT               (GMM_CHUNK_SHIFT - PAGE_SHIFT) 
     52/** The last valid Chunk ID value. */ 
     53#define GMM_CHUNK_LAST                  (GMM_PAGEID_LAST >> GMM_CHUNKID_SHIFT) 
     54/** The last valid Page ID value. 
     55 * The current limit is 2^28 - 1, or almost 1TB if you like. 
     56 * The constraints are currently dictated by PGMPAGE. */ 
     57#define GMM_PAGEID_LAST                 (RT_BIT_32(28) - 1) 
    5158/** The NIL Chunk ID value. */ 
    5259#define NIL_GMM_CHUNKID                 0 
     
    201208#define GMM_GCPHYS_UNSHARABLE   (RTHCPHYS)(0xfffffff0) 
    202209 
    203  
    204210GMMR0DECL(int)  GMMR0Init(void); 
    205211GMMR0DECL(void) GMMR0Term(void); 
     
    213219GMMR0DECL(int)  GMMR0FreePages(PVM pVM, uint32_t cPages, PGMMFREEPAGEDESC paPages, GMMACCOUNT enmAccount); 
    214220GMMR0DECL(int)  GMMR0BalloonedPages(PVM pVM, uint32_t cBalloonedPages, uint32_t cPagesToFree, PGMMFREEPAGEDESC paPages); 
     221GMMR0DECL(int)  GMMR0FreeMapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR pvR3); 
     222GMMR0DECL(int)  GMMR0SeedChunk(PVM pVM, RTR3PTR pvR3); 
     223 
     224 
     225/** 
     226 * Request buffer for GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION. 
     227 * @see GMMR0InitialReservation 
     228 */ 
     229typedef struct GMMINITIALRESERVATIONREQ 
     230{ 
     231    /** The header. */ 
     232    SUPVMMR0REQHDR  Hdr; 
     233    uint64_t        cBasePages;         /**< @see GMMR0InitialReservation */ 
     234    uint32_t        cShadowPages;       /**< @see GMMR0InitialReservation */ 
     235    uint32_t        cFixedPages;        /**< @see GMMR0InitialReservation */ 
     236    GMMOCPOLICY     enmPolicy;          /**< @see GMMR0InitialReservation */ 
     237    GMMPRIORITY     enmPriority;        /**< @see GMMR0InitialReservation */ 
     238} GMMINITIALRESERVATIONREQ; 
     239/** Pointer to a GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION request buffer. */ 
     240typedef GMMINITIALRESERVATIONREQ *PGMMINITIALRESERVATIONREQ; 
     241 
     242GMMR0DECL(int)  GMMR0InitialReservationReq(PVM pVM, PGMMINITIALRESERVATIONREQ pReq); 
     243 
     244 
     245/** 
     246 * Request buffer for GMMR0UpdateReservationReq / VMMR0_DO_GMM_UPDATE_RESERVATION. 
     247 * @see GMMR0UpdateReservation 
     248 */ 
     249typedef struct GMMUPDATERESERVATIONREQ 
     250{ 
     251    /** The header. */ 
     252    SUPVMMR0REQHDR  Hdr; 
     253    uint64_t        cBasePages;         /**< @see GMMR0UpdateReservation */ 
     254    uint32_t        cShadowPages;       /**< @see GMMR0UpdateReservation */ 
     255    uint32_t        cFixedPages;        /**< @see GMMR0UpdateReservation */ 
     256} GMMUPDATERESERVATIONREQ; 
     257/** Pointer to a GMMR0InitialReservationReq / VMMR0_DO_GMM_INITIAL_RESERVATION request buffer. */ 
     258typedef GMMUPDATERESERVATIONREQ *PGMMUPDATERESERVATIONREQ; 
     259 
     260GMMR0DECL(int)  GMMR0UpdateReservationReq(PVM pVM, PGMMUPDATERESERVATIONREQ pReq); 
     261 
     262 
     263/** 
     264 * Request buffer for GMMR0AllocatePagesReq / VMMR0_DO_GMM_ALLOCATE_PAGES. 
     265 * @see GMMR0AllocatePages. 
     266 */ 
     267typedef struct GMMALLOCATEPAGESREQ 
     268{ 
     269    /** The header. */ 
     270    SUPVMMR0REQHDR  Hdr; 
     271    /** The account to charge the allocation to. */ 
     272    GMMACCOUNT      enmAccount; 
     273    /** The number of pages to allocate. */ 
     274    uint32_t        cPages; 
     275    /** Array of page descriptors. */ 
     276    GMMPAGEDESC     aPages[1]; 
     277} GMMALLOCATEPAGESREQ; 
     278/** Pointer to a GMMR0AllocatePagesReq / VMMR0_DO_GMM_ALLOCATE_PAGES request buffer. */ 
     279typedef GMMALLOCATEPAGESREQ *PGMMALLOCATEPAGESREQ; 
     280 
     281GMMR0DECL(int)  GMMR0AllocatePagesReq(PVM pVM, PGMMALLOCATEPAGESREQ pReq); 
     282 
     283 
     284/** 
     285 * Request buffer for GMMR0FreePagesReq / VMMR0_DO_GMM_FREE_PAGES. 
     286 * @see GMMR0FreePages. 
     287 */ 
     288typedef struct GMMFREEPAGESREQ 
     289{ 
     290    /** The header. */ 
     291    SUPVMMR0REQHDR  Hdr; 
     292    /** The account this relates to. */ 
     293    GMMACCOUNT      enmAccount; 
     294    /** The number of pages to free. */ 
     295    uint32_t        cPages; 
     296    /** Array of free page descriptors. */ 
     297    GMMFREEPAGEDESC aPages[1]; 
     298} GMMFREEPAGESREQ; 
     299/** Pointer to a GMMR0FreePagesReq / VMMR0_DO_GMM_FREE_PAGES request buffer. */ 
     300typedef GMMFREEPAGESREQ *PGMMFREEPAGESREQ; 
     301 
     302GMMR0DECL(int)  GMMR0FreePagesReq(PVM pVM, PGMMFREEPAGESREQ pReq); 
     303 
     304 
     305/** 
     306 * Request buffer for GMMR0BalloonedPagesReq / VMMR0_DO_GMM_BALLOONED_PAGES. 
     307 * @see GMMR0BalloonedPages. 
     308 */ 
     309typedef struct GMMBALLOONEDPAGESREQ 
     310{ 
     311    /** The header. */ 
     312    SUPVMMR0REQHDR  Hdr; 
     313    /** The number of ballooned pages. */ 
     314    uint32_t        cBalloonedPages; 
     315    /** The number of pages to free. */ 
     316    uint32_t        cPagesToFree; 
     317    /** Array of free page descriptors. */ 
     318    GMMFREEPAGEDESC aPages[1]; 
     319} GMMBALLOONEDPAGESREQ; 
     320/** Pointer to a GMMR0BalloonedPagesReq / VMMR0_DO_GMM_BALLOONED_PAGES request buffer. */ 
     321typedef GMMBALLOONEDPAGESREQ *PGMMBALLOONEDPAGESREQ; 
     322 
     323GMMR0DECL(int)  GMMR0BalloonedPagesReq(PVM pVM, PGMMBALLOONEDPAGESREQ pReq); 
     324 
     325 
     326/** 
     327 * Request buffer for GMMR0FreeMapUnmapChunkReq / VMMR0_DO_GMM_MAP_UNMAP_CHUNK. 
     328 * @see GMMR0FreeMapUnmapChunk 
     329 */ 
     330typedef struct GMMMAPUNMAPCHUNKREQ 
     331{ 
     332    /** The header. */ 
     333    SUPVMMR0REQHDR  Hdr; 
     334    /** The chunk to map, UINT32_MAX if unmap only. (IN) */ 
     335    uint32_t        idChunkMap; 
     336    /** The chunk to unmap, UINT32_MAX if map only. (IN) */ 
     337    uint32_t        idChunkUnmap; 
     338    /** Where the mapping address is returned. (OUT) */ 
     339    RTR3PTR         pvR3; 
     340} GMMMAPUNMAPCHUNKREQ; 
     341/** Pointer to a GMMR0FreeMapUnmapChunkReq / VMMR0_DO_GMM_MAP_UNMAP_CHUNK request buffer. */ 
     342typedef GMMMAPUNMAPCHUNKREQ *PGMMMAPUNMAPCHUNKREQ; 
     343 
     344GMMR0DECL(int)  GMMR0FreeMapUnmapChunkReq(PVM pVM, PGMMMAPUNMAPCHUNKREQ pReq); 
    215345 
    216346 
  • trunk/include/VBox/vmm.h

    r5031 r5106  
    375375    /** Call PGMR0PhysAllocateHandyPages(). */ 
    376376    VMMR0_DO_PGM_ALLOCATE_HANDY_PAGES, 
     377 
     378    /** Call GMMR0InitialReservation(). */ 
     379    VMMR0_DO_GMM_INITIAL_RESERVATION, 
     380    /** Call GMMR0UpdateReservation(). */ 
     381    VMMR0_DO_GMM_UPDATE_RESERVATION, 
    377382    /** Call GMMR0AllocatePages(). */ 
    378383    VMMR0_DO_GMM_ALLOCATE_PAGES, 
    379384    /** Call GMMR0FreePages(). */ 
    380385    VMMR0_DO_GMM_FREE_PAGES, 
     386    /** Call GMMR0BalloonedPages(). */ 
     387    VMMR0_DO_GMM_BALLOONED_PAGES, 
    381388    /** Call GMMR0MapUnmapChunk(). */ 
    382389    VMMR0_DO_GMM_MAP_UNMAP_CHUNK, 
  • trunk/src/VBox/VMM/PGMPhys.cpp

    r5001 r5106  
    783783 
    784784/** 
    785  * Argument package for the VMMR0_DO_GMM_MAP_UNMAP_CHUNK request. 
    786  */ 
    787 typedef struct GMMMAPUNMAPCHUNKREQ 
    788 { 
    789     /** The header. */ 
    790     SUPVMMR0REQHDR  Hdr; 
    791     /** The chunk to map, UINT32_MAX if unmap only. (IN) */ 
    792     uint32_t        idChunkMap; 
    793     /** The chunk to unmap, UINT32_MAX if map only. (IN) */ 
    794     uint32_t        idChunkUnmap; 
    795     /** Where the mapping address is returned. (OUT) */ 
    796     RTR3PTR         pvR3; 
    797 } GMMMAPUNMAPCHUNKREQ; 
    798  
    799  
    800 /** 
    801785 * Maps the given chunk into the ring-3 mapping cache. 
    802786 * 
  • trunk/src/VBox/VMM/VMMR0/GMMR0.cpp

    r5086 r5106  
    147147#include <VBox/log.h> 
    148148#include <VBox/param.h> 
     149#include <VBox/err.h> 
    149150#include <iprt/avl.h> 
    150151#include <iprt/mem.h> 
     
    152153#include <iprt/semaphore.h> 
    153154#include <iprt/string.h> 
     155 
     156/** @def GMM_MAX_GCPHYS 
     157 * The max guest physical address. 
     158 * This must reflect the constraints imposed by the RTGCPHYS type and the guest 
     159 * page frame number used internally in GMMPAGE. */ 
     160#define GMM_MAX_GCPHYS      UINT32_MAX 
    154161 
    155162 
     
    792799 * @param   enmPolicy       The OC policy to use on this VM. 
    793800 * @param   enmPriority     The priority in an out-of-memory situation. 
     801 * 
     802 * @thread  The creator thread / EMT. 
    794803 */ 
    795804GMMR0DECL(int) GMMR0InitialReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages, 
     
    807816    if (!pGVM) 
    808817        return VERR_INVALID_PARAMETER; 
     818    if (pGVM->hEMT != RTThreadNativeSelf()) 
     819        return VERR_NOT_OWNER; 
    809820 
    810821    AssertReturn(cBasePages, VERR_INVALID_PARAMETER); 
     
    851862 
    852863/** 
     864 * VMMR0 request wrapper for GMMR0InitialReservation. 
     865 * 
     866 * @returns see GMMR0InitialReservation. 
     867 * @param   pVM             Pointer to the shared VM structure. 
     868 * @param   pReq            The request packet. 
     869 */ 
     870GMMR0DECL(int) GMMR0InitialReservationReq(PVM pVM, PGMMINITIALRESERVATIONREQ pReq) 
     871{ 
     872    /* 
     873     * Validate input and pass it on. 
     874     */ 
     875    AssertPtrReturn(pVM, VERR_INVALID_POINTER); 
     876    AssertPtrReturn(pReq, VERR_INVALID_POINTER); 
     877    AssertMsgReturn(pReq->Hdr.cbReq != sizeof(*pReq), ("%#x != %#x\n", pReq->Hdr.cbReq, sizeof(*pReq)), VERR_INVALID_PARAMETER); 
     878 
     879    return GMMR0InitialReservation(pVM, pReq->cBasePages, pReq->cShadowPages, pReq->cFixedPages, pReq->enmPolicy, pReq->enmPriority); 
     880} 
     881 
     882 
     883/** 
    853884 * This updates the memory reservation with the additional MMIO2 and ROM pages. 
    854885 * 
     
    864895 * @param   enmPolicy       The OC policy to use on this VM. 
    865896 * @param   enmPriority     The priority in an out-of-memory situation. 
     897 * 
     898 * @thread  EMT. 
    866899 */ 
    867900GMMR0DECL(int) GMMR0UpdateReservation(PVM pVM, uint64_t cBasePages, uint32_t cShadowPages, uint32_t cFixedPages) 
     
    878911    if (!pGVM) 
    879912        return VERR_INVALID_PARAMETER; 
     913    if (pGVM->hEMT != RTThreadNativeSelf()) 
     914        return VERR_NOT_OWNER; 
    880915 
    881916    AssertReturn(cBasePages, VERR_INVALID_PARAMETER); 
     
    919954 
    920955/** 
     956 * VMMR0 request wrapper for GMMR0UpdateReservation. 
     957 * 
     958 * @returns see GMMR0UpdateReservation. 
     959 * @param   pVM             Pointer to the shared VM structure. 
     960 * @param   pReq            The request packet. 
     961 */ 
     962GMMR0DECL(int) GMMR0UpdateReservationReq(PVM pVM, PGMMUPDATERESERVATIONREQ pReq) 
     963{ 
     964    /* 
     965     * Validate input and pass it on. 
     966     */ 
     967    AssertPtrReturn(pVM, VERR_INVALID_POINTER); 
     968    AssertPtrReturn(pReq, VERR_INVALID_POINTER); 
     969    AssertMsgReturn(pReq->Hdr.cbReq != sizeof(*pReq), ("%#x != %#x\n", pReq->Hdr.cbReq, sizeof(*pReq)), VERR_INVALID_PARAMETER); 
     970 
     971    return GMMR0UpdateReservation(pVM, pReq->cBasePages, pReq->cShadowPages, pReq->cFixedPages); 
     972} 
     973 
     974 
     975/** 
     976 * Finds a page. 
     977 * 
     978 * @returns Pointer to the page, NULL if not found. 
     979 * @param   pGMM    Pointer to the GMM instance. 
     980 * @param   idPage  The ID of the page to find. 
     981 */ 
     982DECLINLINE(PGMMPAGE) gmmR0GetPage(PGMM pGMM, uint32_t idPage) 
     983{ 
     984    return NULL; 
     985} 
     986 
     987 
     988 
     989/** 
     990 * Common worker for GMMR0AllocateHandyPages and GMMR0AllocatePages. 
     991 * 
     992 * @returns VBox status code: 
     993 * @retval  xxx 
     994 * 
     995 * @param   pVM                 Pointer to the shared VM structure. 
     996 * @param   cPages              The number of pages to allocate. 
     997 * @param   paPages             Pointer to the page descriptors. 
     998 *                              See GMMPAGEDESC for details on what is expected on input. 
     999 * @param   enmAccount          The account to charge. 
     1000 */ 
     1001static int gmmR0AllocatePages(PGMM pGMM, PGVM pGVM, uint32_t cPages, PGMMPAGEDESC paPages, GMMACCOUNT enmAccount) 
     1002{ 
     1003 
     1004    return VERR_NOT_IMPLEMENTED; 
     1005} 
     1006 
     1007 
     1008/** 
    9211009 * Updates the previous allocations and allocates more pages. 
    9221010 * 
     
    9311019 * @param   paPages             The array of page descriptors. 
    9321020 *                              See GMMPAGEDESC for details on what is expected on input. 
     1021 * @thread  EMT. 
    9331022 */ 
    9341023GMMR0DECL(int) GMMR0AllocateHandyPages(PVM pVM, uint32_t cPagesToUpdate, uint32_t cPagesToAlloc, PGMMPAGEDESC paPages) 
    9351024{ 
    936     return VERR_NOT_IMPLEMENTED; 
     1025    /* 
     1026     * Validate, get basics and take the semaphore. 
     1027     * (This is a relatively busy path, so make predictions where possible.) 
     1028     */ 
     1029    PGMM pGMM; 
     1030    GMM_GET_VALID_INSTANCE(pGMM, VERR_INTERNAL_ERROR); 
     1031    PGVM pGVM = GVMMR0ByVM(pVM); 
     1032    if (RT_UNLIKELY(!pGVM)) 
     1033        return VERR_INVALID_PARAMETER; 
     1034    if (RT_UNLIKELY(pGVM->hEMT != RTThreadNativeSelf())) 
     1035        return VERR_NOT_OWNER; 
     1036 
     1037    AssertPtrReturn(paPages, VERR_INVALID_PARAMETER); 
     1038    AssertMsgReturn(    (cPagesToUpdate && cPagesToUpdate < 1024) 
     1039                    ||  (cPagesToAlloc  && cPagesToAlloc < 1024), 
     1040                    ("cPagesToUpdate=%#x cPagesToAlloc=%#x\n", cPagesToUpdate, cPagesToAlloc), 
     1041                    VERR_INVALID_PARAMETER); 
     1042 
     1043    unsigned iPage = 0; 
     1044    for (; iPage < cPagesToUpdate; iPage++) 
     1045    { 
     1046        AssertMsgReturn(    (    paPages[iPage].HCPhysGCPhys < GMM_MAX_GCPHYS 
     1047                             && !(paPages[iPage].HCPhysGCPhys & PAGE_OFFSET_MASK)) 
     1048                        ||  paPages[iPage].HCPhysGCPhys == NIL_RTHCPHYS 
     1049                        ||  paPages[iPage].HCPhysGCPhys == GMM_GCPHYS_UNSHARABLE, 
     1050                        ("#%#x: %RHp\n", iPage, paPages[iPage].HCPhysGCPhys), 
     1051                        VERR_INVALID_PARAMETER); 
     1052        AssertMsgReturn(    paPages[iPage].idPage <= GMM_PAGEID_LAST 
     1053                        /*||  paPages[iPage].idPage == NIL_GMM_PAGEID*/, 
     1054                        ("#%#x: %#x\n", iPage, paPages[iPage].idPage), VERR_INVALID_PARAMETER); 
     1055        AssertMsgReturn(    paPages[iPage].idPage <= GMM_PAGEID_LAST 
     1056                        /*||  paPages[iPage].idSharedPage == NIL_GMM_PAGEID*/, 
     1057                        ("#%#x: %#x\n", iPage, paPages[iPage].idSharedPage), VERR_INVALID_PARAMETER); 
     1058    } 
     1059 
     1060    for (; iPage < cPagesToAlloc; iPage++) 
     1061    { 
     1062        AssertMsgReturn(paPages[iPage].HCPhysGCPhys == NIL_RTHCPHYS,   ("#%#x: %RHp\n", iPage, paPages[iPage].HCPhysGCPhys), VERR_INVALID_PARAMETER); 
     1063        AssertMsgReturn(paPages[iPage].idPage       == NIL_GMM_PAGEID, ("#%#x: %#x\n", iPage, paPages[iPage].idPage),        VERR_INVALID_PARAMETER); 
     1064        AssertMsgReturn(paPages[iPage].idSharedPage == NIL_GMM_PAGEID, ("#%#x: %#x\n", iPage, paPages[iPage].idSharedPage),  VERR_INVALID_PARAMETER); 
     1065    } 
     1066 
     1067    int rc = RTSemFastMutexRequest(pGMM->Mtx); 
     1068    AssertRC(rc); 
     1069 
     1070    /* No allocations before the initial reservation has been made! */ 
     1071    if (RT_LIKELY(    pGVM->gmm.s.Reserved.cBasePages 
     1072                  &&  pGVM->gmm.s.Reserved.cFixedPages 
     1073                  &&  pGVM->gmm.s.Reserved.cShadowPages)) 
     1074    { 
     1075        /* 
     1076         * Do the updates. 
     1077         */ 
     1078        for (iPage = 0; iPage < cPagesToUpdate; iPage++) 
     1079        { 
     1080            if (paPages[iPage].idPage != NIL_GMM_PAGEID) 
     1081            { 
     1082                PGMMPAGE pPage = gmmR0GetPage(pGMM, paPages[iPage].idPage); 
     1083                if (RT_LIKELY(pPage)) 
     1084                { 
     1085 
     1086                    paPages[iPage].idPage = NIL_GMM_PAGEID; 
     1087                    paPages[iPage].HCPhysGCPhys = NIL_RTHCPHYS; 
     1088                } 
     1089                else 
     1090                    rc = VERR_GMM_PAGE_NOT_FOUND; 
     1091            } 
     1092 
     1093            if (paPages[iPage].idSharedPage != NIL_GMM_PAGEID) 
     1094            { 
     1095                PGMMPAGE pPage = gmmR0GetPage(pGMM, paPages[iPage].idSharedPage); 
     1096                if (RT_LIKELY(pPage)) 
     1097                { 
     1098 
     1099                    paPages[iPage].idSharedPage = NIL_GMM_PAGEID; 
     1100                } 
     1101                else 
     1102                    rc = VERR_GMM_PAGE_NOT_FOUND; 
     1103            } 
     1104        } 
     1105 
     1106        /* 
     1107         * And now do the allocation. 
     1108         */ 
     1109        if (RT_SUCCESS(rc)) 
     1110            rc = gmmR0AllocatePages(pGMM, pGVM, cPagesToAlloc, paPages, GMMACCOUNT_BASE); 
     1111    } 
     1112    else 
     1113        rc = VERR_WRONG_ORDER; 
     1114 
     1115    RTSemFastMutexRelease(pGMM->Mtx); 
     1116    LogFlow(("GMMR0UpdateReservation: returns %Rrc\n", rc)); 
     1117    return rc; 
    9371118} 
    9381119 
     
    9511132 *                              See GMMPAGEDESC for details on what is expected on input. 
    9521133 * @param   enmAccount          The account to charge. 
     1134 * 
     1135 * @thread  EMT. 
    9531136 */ 
    9541137GMMR0DECL(int) GMMR0AllocatePages(PVM pVM, uint32_t cPages, PGMMPAGEDESC paPages, GMMACCOUNT enmAccount) 
    9551138{ 
    956     return VERR_NOT_IMPLEMENTED; 
     1139    LogFlow(("GMMR0AllocatePages: pVM=%p cPages=%#x paPages=%p enmAccount=%d\n", pVM, cPages, paPages, enmAccount)); 
     1140 
     1141    /* 
     1142     * Validate, get basics and take the semaphore. 
     1143     */ 
     1144    PGMM pGMM; 
     1145    GMM_GET_VALID_INSTANCE(pGMM, VERR_INTERNAL_ERROR); 
     1146    PGVM pGVM = GVMMR0ByVM(pVM); 
     1147    if (!pGVM) 
     1148        return VERR_INVALID_PARAMETER; 
     1149    if (pGVM->hEMT != RTThreadNativeSelf()) 
     1150        return VERR_NOT_OWNER; 
     1151 
     1152    AssertPtrReturn(paPages, VERR_INVALID_PARAMETER); 
     1153    AssertMsgReturn(enmAccount > GMMACCOUNT_INVALID && enmAccount < GMMACCOUNT_END, ("%d\n", enmAccount), VERR_INVALID_PARAMETER); 
     1154    AssertMsgReturn(cPages > 0 && cPages < RT_BIT(32 - PAGE_SHIFT), ("%#x\n", cPages), VERR_INVALID_PARAMETER); 
     1155 
     1156    for (unsigned iPage = 0; iPage < cPages; iPage++) 
     1157    { 
     1158        AssertMsgReturn(    paPages[iPage].HCPhysGCPhys == NIL_RTHCPHYS 
     1159                        ||  paPages[iPage].HCPhysGCPhys == GMM_GCPHYS_UNSHARABLE 
     1160                        ||  (    enmAccount == GMMACCOUNT_BASE 
     1161                             &&  paPages[iPage].HCPhysGCPhys < GMM_MAX_GCPHYS 
     1162                             && !(paPages[iPage].HCPhysGCPhys & PAGE_OFFSET_MASK)), 
     1163                        ("#%#x: %RHp enmAccount=%d\n", iPage, paPages[iPage].HCPhysGCPhys, enmAccount), 
     1164                        VERR_INVALID_PARAMETER); 
     1165        AssertMsgReturn(paPages[iPage].idPage == NIL_GMM_PAGEID, ("#%#x: %#x\n", iPage, paPages[iPage].idPage), VERR_INVALID_PARAMETER); 
     1166        AssertMsgReturn(paPages[iPage].idSharedPage == NIL_GMM_PAGEID, ("#%#x: %#x\n", iPage, paPages[iPage].idSharedPage), VERR_INVALID_PARAMETER); 
     1167    } 
     1168 
     1169    int rc = RTSemFastMutexRequest(pGMM->Mtx); 
     1170    AssertRC(rc); 
     1171 
     1172    /* No allocations before the initial reservation has been made! */ 
     1173    if (    pGVM->gmm.s.Reserved.cBasePages 
     1174        &&  pGVM->gmm.s.Reserved.cFixedPages 
     1175        &&  pGVM->gmm.s.Reserved.cShadowPages) 
     1176        rc = gmmR0AllocatePages(pGMM, pGVM, cPages, paPages, enmAccount); 
     1177    else 
     1178        rc = VERR_WRONG_ORDER; 
     1179 
     1180    RTSemFastMutexRelease(pGMM->Mtx); 
     1181    LogFlow(("GMMR0UpdateReservation: returns %Rrc\n", rc)); 
     1182    return rc; 
     1183
     1184 
     1185 
     1186/** 
     1187 * VMMR0 request wrapper for GMMR0AllocatePages. 
     1188 * 
     1189 * @returns see GMMR0AllocatePages. 
     1190 * @param   pVM             Pointer to the shared VM structure. 
     1191 * @param   pReq            The request packet. 
     1192 */ 
     1193GMMR0DECL(int) GMMR0AllocatePagesReq(PVM pVM, PGMMALLOCATEPAGESREQ pReq) 
     1194
     1195    /* 
     1196     * Validate input and pass it on. 
     1197     */ 
     1198    AssertPtrReturn(pVM, VERR_INVALID_POINTER); 
     1199    AssertPtrReturn(pReq, VERR_INVALID_POINTER); 
     1200    AssertMsgReturn(pReq->Hdr.cbReq >= RT_UOFFSETOF(GMMALLOCATEPAGESREQ, aPages[0]), 
     1201                    ("%#x < %#x\n", pReq->Hdr.cbReq, RT_UOFFSETOF(GMMALLOCATEPAGESREQ, aPages[0])), 
     1202                    VERR_INVALID_PARAMETER); 
     1203    AssertMsgReturn(pReq->Hdr.cbReq == RT_UOFFSETOF(GMMALLOCATEPAGESREQ, aPages[pReq->cPages]), 
     1204                    ("%#x != %#x\n", pReq->Hdr.cbReq, RT_UOFFSETOF(GMMALLOCATEPAGESREQ, aPages[pReq->cPages])), 
     1205                    VERR_INVALID_PARAMETER); 
     1206 
     1207    return GMMR0AllocatePages(pVM, pReq->cPages, &pReq->aPages[0], pReq->enmAccount); 
    9571208} 
    9581209 
     
    9701221 * @param   paPages             Pointer to the page descriptors containing the Page IDs for each page. 
    9711222 * @param   enmAccount          The account this relates to. 
     1223 * @thread  EMT. 
    9721224 */ 
    9731225GMMR0DECL(int) GMMR0FreePages(PVM pVM, uint32_t cPages, PGMMFREEPAGEDESC paPages, GMMACCOUNT enmAccount) 
    9741226{ 
    9751227    return VERR_NOT_IMPLEMENTED; 
     1228} 
     1229 
     1230 
     1231/** 
     1232 * VMMR0 request wrapper for GMMR0FreePages. 
     1233 * 
     1234 * @returns see GMMR0FreePages. 
     1235 * @param   pVM             Pointer to the shared VM structure. 
     1236 * @param   pReq            The request packet. 
     1237 */ 
     1238GMMR0DECL(int) GMMR0FreePagesReq(PVM pVM, PGMMFREEPAGESREQ pReq) 
     1239{ 
     1240    /* 
     1241     * Validate input and pass it on. 
     1242     */ 
     1243    AssertPtrReturn(pVM, VERR_INVALID_POINTER); 
     1244    AssertPtrReturn(pReq, VERR_INVALID_POINTER); 
     1245    AssertMsgReturn(pReq->Hdr.cbReq >= RT_UOFFSETOF(GMMFREEPAGESREQ, aPages[0]), 
     1246                    ("%#x < %#x\n", pReq->Hdr.cbReq, RT_UOFFSETOF(GMMFREEPAGESREQ, aPages[0])), 
     1247                    VERR_INVALID_PARAMETER); 
     1248    AssertMsgReturn(pReq->Hdr.cbReq == RT_UOFFSETOF(GMMFREEPAGESREQ, aPages[pReq->cPages]), 
     1249                    ("%#x != %#x\n", pReq->Hdr.cbReq, RT_UOFFSETOF(GMMFREEPAGESREQ, aPages[pReq->cPages])), 
     1250                    VERR_INVALID_PARAMETER); 
     1251 
     1252    return GMMR0FreePages(pVM, pReq->cPages, &pReq->aPages[0], pReq->enmAccount); 
    9761253} 
    9771254 
     
    9891266 * @param   cPagesToFree        The number of pages to be freed. 
    9901267 * @param   paPages             Pointer to the page descriptors for the pages that's to be freed. 
     1268 * @thread  EMT. 
    9911269 */ 
    9921270GMMR0DECL(int) GMMR0BalloonedPages(PVM pVM, uint32_t cBalloonedPages, uint32_t cPagesToFree, PGMMFREEPAGEDESC paPages) 
     
    9961274 
    9971275 
     1276/** 
     1277 * VMMR0 request wrapper for GMMR0BalloonedPages. 
     1278 * 
     1279 * @returns see GMMR0BalloonedPages. 
     1280 * @param   pVM             Pointer to the shared VM structure. 
     1281 * @param   pReq            The request packet. 
     1282 */ 
     1283GMMR0DECL(int) GMMR0BalloonedPagesReq(PVM pVM, PGMMBALLOONEDPAGESREQ pReq) 
     1284{ 
     1285    /* 
     1286     * Validate input and pass it on. 
     1287     */ 
     1288    AssertPtrReturn(pVM, VERR_INVALID_POINTER); 
     1289    AssertPtrReturn(pReq, VERR_INVALID_POINTER); 
     1290    AssertMsgReturn(pReq->Hdr.cbReq >= RT_UOFFSETOF(GMMBALLOONEDPAGESREQ, aPages[0]), 
     1291                    ("%#x < %#x\n", pReq->Hdr.cbReq, RT_UOFFSETOF(GMMBALLOONEDPAGESREQ, aPages[0])), 
     1292                    VERR_INVALID_PARAMETER); 
     1293    AssertMsgReturn(pReq->Hdr.cbReq == RT_UOFFSETOF(GMMBALLOONEDPAGESREQ, aPages[pReq->cPagesToFree]), 
     1294                    ("%#x != %#x\n", pReq->Hdr.cbReq, RT_UOFFSETOF(GMMBALLOONEDPAGESREQ, aPages[pReq->cPagesToFree])), 
     1295                    VERR_INVALID_PARAMETER); 
     1296 
     1297    return GMMR0BalloonedPages(pVM, pReq->cBalloonedPages, pReq->cPagesToFree, &pReq->aPages[0]); 
     1298} 
     1299 
     1300 
     1301GMMR0DECL(int) GMMR0FreeMapUnmapChunk(PVM pVM, uint32_t idChunkMap, uint32_t idChunkUnmap, PRTR3PTR pvR3) 
     1302{ 
     1303    return VERR_NOT_IMPLEMENTED; 
     1304} 
     1305 
     1306 
     1307/** 
     1308 * VMMR0 request wrapper for GMMR0FreeMapUnmapChunk. 
     1309 * 
     1310 * @returns see GMMR0FreeMapUnmapChunk. 
     1311 * @param   pVM             Pointer to the shared VM structure. 
     1312 * @param   pReq            The request packet. 
     1313 */ 
     1314GMMR0DECL(int)  GMMR0FreeMapUnmapChunkReq(PVM pVM, PGMMMAPUNMAPCHUNKREQ pReq) 
     1315{ 
     1316    /* 
     1317     * Validate input and pass it on. 
     1318     */ 
     1319    AssertPtrReturn(pVM, VERR_INVALID_POINTER); 
     1320    AssertPtrReturn(pReq, VERR_INVALID_POINTER); 
     1321    AssertMsgReturn(pReq->Hdr.cbReq == sizeof(*pReq), ("%#x != %#x\n", pReq->Hdr.cbReq, sizeof(*pReq)), VERR_INVALID_PARAMETER); 
     1322 
     1323    return GMMR0FreeMapUnmapChunk(pVM, pReq->idChunkMap, pReq->idChunkUnmap, &pReq->pvR3); 
     1324} 
     1325 
     1326 
     1327GMMR0DECL(int)  GMMR0SeedChunk(PVM pVM, RTR3PTR pvR3) 
     1328{ 
     1329    return VERR_NOT_IMPLEMENTED; 
     1330} 
     1331 
  • trunk/src/VBox/VMM/VMMR0/PGMR0.cpp

    r4738 r5106  
    2828 
    2929 
    30 /**  
     30/** 
    3131 * Worker function for PGMR3PhysAllocateHandyPages and pgmPhysEnsureHandyPage. 
    32  *  
     32 * 
    3333 * @returns The following VBox status codes. 
    3434 * @retval  VINF_SUCCESS on success. FF cleared. 
    3535 * @retval  VINF_EM_NO_MEMORY if we're out of memory. The FF is set in this case. 
    36  *  
     36 * 
    3737 * @param   pVM         The VM handle. 
    38  *  
     38 * 
    3939 * @remarks Must be called from within the PGM critical section. 
    4040 */ 
    4141PGMR0DECL(int) PGMR0PhysAllocateHandyPages(PVM pVM) 
    4242{ 
     43 
    4344    return VERR_NOT_IMPLEMENTED; 
    4445} 
  • trunk/src/VBox/VMM/VMMR0/VMMR0.cpp

    r5031 r5106  
    3030#include <VBox/vm.h> 
    3131#include <VBox/gvmm.h> 
     32#include <VBox/gmm.h> 
    3233#include <VBox/intnet.h> 
    3334#include <VBox/hwaccm.h> 
     35#include <VBox/param.h> 
    3436 
    3537#include <VBox/err.h> 
     
    648650static int vmmR0EntryExWorker(PVM pVM, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReqHdr, uint64_t u64Arg) 
    649651{ 
     652    /* 
     653     * Common VM pointer validation. 
     654     */ 
     655    if (pVM) 
     656    { 
     657        if (RT_UNLIKELY(    !VALID_PTR(pVM) 
     658                        ||  ((uintptr_t)pVM & PAGE_OFFSET_MASK))) 
     659        { 
     660            SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p! (op=%d)\n", pVM, enmOperation); 
     661            return VERR_INVALID_POINTER; 
     662        } 
     663        if (RT_UNLIKELY(    pVM->enmVMState < VMSTATE_CREATING 
     664                        ||  pVM->enmVMState > VMSTATE_TERMINATED 
     665                        ||  pVM->pVMR0 != pVM)) 
     666        { 
     667            SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p:{enmVMState=%d, .pVMR0=%p}! (op=%d)\n", 
     668                        pVM, pVM->enmVMState, pVM->pVMR0, enmOperation); 
     669            return VERR_INVALID_POINTER; 
     670        } 
     671    } 
     672 
    650673    switch (enmOperation) 
    651674    { 
     
    710733            return PGMR0PhysAllocateHandyPages(pVM); 
    711734 
    712 #if 0 
    713         /* 
    714          * GMM wrappers 
    715          */ 
     735        /* 
     736         * GMM wrappers. 
     737         */ 
     738        case VMMR0_DO_GMM_INITIAL_RESERVATION: 
     739            return GMMR0InitialReservationReq(pVM, (PGMMINITIALRESERVATIONREQ)pReqHdr); 
     740        case VMMR0_DO_GMM_UPDATE_RESERVATION: 
     741            return GMMR0UpdateReservationReq(pVM, (PGMMUPDATERESERVATIONREQ)pReqHdr); 
     742 
    716743        case VMMR0_DO_GMM_ALLOCATE_PAGES: 
    717             return GMMR0AllocatePages(pVM, ...); 
     744            return GMMR0AllocatePagesReq(pVM, (PGMMALLOCATEPAGESREQ)pReqHdr); 
    718745        case VMMR0_DO_GMM_FREE_PAGES: 
    719             return GMMR0FreePages(pVM, ...); 
     746            return GMMR0FreePagesReq(pVM, (PGMMFREEPAGESREQ)pReqHdr); 
     747        case VMMR0_DO_GMM_BALLOONED_PAGES: 
     748            return GMMR0BalloonedPagesReq(pVM, (PGMMBALLOONEDPAGESREQ)pReqHdr); 
     749 
    720750        case VMMR0_DO_GMM_MAP_UNMAP_CHUNK: 
    721             return GMMR0FreeMapUnmapChunk(pVM, ...); 
     751            return GMMR0FreeMapUnmapChunkReq(pVM, (PGMMMAPUNMAPCHUNKREQ)pReqHdr); 
    722752        case VMMR0_DO_GMM_SEED_CHUNK: 
    723             return GMMR0SeedChunk(pVM, (RTR3PTR)pvArg); 
    724 #endif 
    725  
     753            return GMMR0SeedChunk(pVM, (RTR3PTR)u64Arg); 
    726754 
    727755 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy