VirtualBox

Changeset 18101 in vbox


Ignore:
Timestamp:
Mar 19, 2009 10:39:06 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
44762
Message:

PDM,PGM,DevPcArch,types.h: Added GCPhys2CCPtr conversion methods to PDMDEVHLP and removed some obsolete (or soon to be obsolete) methods.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/pdmdev.h

    r17334 r18101  
    24022402    /**
    24032403     * Read physical memory.
    2404      *
     2404     * 
     2405     * @returns VINF_SUCCESS (for now).
    24052406     * @param   pDevIns         Device instance.
    24062407     * @param   GCPhys          Physical address start reading from.
     
    24092410     * @thread  Any thread, but the call may involve the emulation thread.
    24102411     */
    2411     DECLR3CALLBACKMEMBER(void, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
     2412    DECLR3CALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
    24122413
    24132414    /**
    24142415     * Write to physical memory.
    24152416     *
     2417     * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
    24162418     * @param   pDevIns         Device instance.
    24172419     * @param   GCPhys          Physical address to write to.
     
    24202422     * @thread  Any thread, but the call may involve the emulation thread.
    24212423     */
    2422     DECLR3CALLBACKMEMBER(void, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
     2424    DECLR3CALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
     2425
     2426    /**
     2427     * Requests the mapping of a guest page into ring-3.
     2428     *
     2429     * When you're done with the page, call pfnPhysReleasePageMappingLock() ASAP to
     2430     * release it.
     2431     *
     2432     * This API will assume your intention is to write to the page, and will
     2433     * therefore replace shared and zero pages. If you do not intend to modify the
     2434     * page, use the pfnPhysGCPhys2CCPtrReadOnly() API.
     2435     *
     2436     * @returns VBox status code.
     2437     * @retval  VINF_SUCCESS on success.
     2438     * @retval  VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical
     2439     *          backing or if the page has any active access handlers. The caller
     2440     *          must fall back on using PGMR3PhysWriteExternal.
     2441     * @retval  VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
     2442     *
     2443     * @param   pVM             The VM handle.
     2444     * @param   GCPhys          The guest physical address of the page that should be mapped.
     2445     * @param   fFlags          Flags reserved for future use, MBZ.
     2446     * @param   ppv             Where to store the address corresponding to GCPhys.
     2447     * @param   pLock           Where to store the lock information that
     2448     *                          pfnPhysReleasePageMappingLock needs.
     2449     *
     2450     * @remark  Avoid calling this API from within critical sections (other than the
     2451     *          PGM one) because of the deadlock risk when we have to delegating the
     2452     *          task to an EMT.
     2453     * @thread  Any.
     2454     */
     2455    DECLR3CALLBACKMEMBER(int, pfnPhysGCPhys2CCPtr,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock));
     2456
     2457    /**
     2458     * Requests the mapping of a guest page into ring-3, external threads.
     2459     *
     2460     * When you're done with the page, call pfnPhysReleasePageMappingLock() ASAP to
     2461     * release it.
     2462     *
     2463     * @returns VBox status code.
     2464     * @retval  VINF_SUCCESS on success.
     2465     * @retval  VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical
     2466     *          backing or if the page as an active ALL access handler. The caller
     2467     *          must fall back on using PGMPhysRead.
     2468     * @retval  VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
     2469     *
     2470     * @param   pDevIns         Device instance.
     2471     * @param   GCPhys          The guest physical address of the page that should be mapped.
     2472     * @param   fFlags          Flags reserved for future use, MBZ.
     2473     * @param   ppv             Where to store the address corresponding to GCPhys.
     2474     * @param   pLock           Where to store the lock information that
     2475     *                          pfnPhysReleasePageMappingLock needs.
     2476     *
     2477     * @remark  Avoid calling this API from within critical sections.
     2478     * @thread  Any.
     2479     */
     2480    DECLR3CALLBACKMEMBER(int, pfnPhysGCPhys2CCPtrReadOnly,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void const **ppv, PPGMPAGEMAPLOCK pLock));
     2481
     2482    /**
     2483     * Release the mapping of a guest page.
     2484     *
     2485     * This is the counter part of pfnPhysGCPhys2CCPtr and
     2486     * pfnPhysGCPhys2CCPtrReadOnly.
     2487     *
     2488     * @param   pDevIns         Device instance.
     2489     * @param   pLock           The lock structure initialized by the mapping function.
     2490     */
     2491    DECLR3CALLBACKMEMBER(void, pfnPhysReleasePageMappingLock,(PPDMDEVINS pDevIns, PPGMPAGEMAPLOCK pLock));
    24232492
    24242493    /**
     
    24432512     */
    24442513    DECLR3CALLBACKMEMBER(int, pfnPhysWriteGCVirt,(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb));
    2445 
    2446     /**
    2447      * Reserve physical address space for ROM and MMIO ranges.
    2448      *
    2449      * @returns VBox status code.
    2450      * @param   pDevIns         Device instance.
    2451      * @param   GCPhys          Start physical address.
    2452      * @param   cbRange         The size of the range.
    2453      * @param   pszDesc         Description string.
    2454      * @thread  The emulation thread.
    2455      */
    2456     DECLR3CALLBACKMEMBER(int, pfnPhysReserve,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, const char *pszDesc));
    2457 
    2458     /**
    2459      * Convert a guest physical address to a host virtual address. (OBSOLETE)
    2460      *
    2461      * @returns VBox status code.
    2462      * @param   pDevIns         Device instance.
    2463      * @param   GCPhys          Start physical address.
    2464      * @param   cbRange         The size of the range. Use 0 if you don't care about the range.
    2465      * @param   ppvHC           Where to store the HC pointer corresponding to GCPhys.
    2466      * @thread  The emulation thread.
    2467      *
    2468      * @remark  Careful with page boundraries.
    2469      * @remark  Do not use the mapping after you return to the caller! (it could get invalidated/changed)
    2470      */
    2471     DECLR3CALLBACKMEMBER(int, pfnObsoletePhys2HCVirt,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, PRTHCPTR ppvHC));
    2472 
    2473     /**
    2474      * Convert a guest virtual address to a host virtual address. (OBSOLETE)
    2475      *
    2476      * @returns VBox status code.
    2477      * @param   pDevIns         Device instance.
    2478      * @param   GCPtr           Guest virtual address.
    2479      * @param   pHCPtr          Where to store the HC pointer corresponding to GCPtr.
    2480      * @thread  The emulation thread.
    2481      *
    2482      * @remark  Careful with page boundraries.
    2483      * @remark  Do not use the mapping after you return to the caller! (it could get invalidated/changed)
    2484      */
    2485     DECLR3CALLBACKMEMBER(int, pfnObsoletePhysGCPtr2HCPtr,(PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTHCPTR pHCPtr));
    24862514
    24872515    /**
     
    27432771     *
    27442772     * @return VBox status code.
    2745      * @param   pDevIns     The device owning the MMIO2 memory.
    2746      * @param   iRegion     The region.
    2747      * @param   off         The offset into the region. Will be rounded down to closest page boundrary.
    2748      * @param   cb          The number of bytes to map. Will be rounded up to the closest page boundrary.
    2749      * @param   pszDesc     Mapping description.
    2750      * @param   pRCPtr      Where to store the RC address.
     2773     * @param   pDevIns         The device owning the MMIO2 memory.
     2774     * @param   iRegion         The region.
     2775     * @param   off             The offset into the region. Will be rounded down to closest page boundrary.
     2776     * @param   cb              The number of bytes to map. Will be rounded up to the closest page boundrary.
     2777     * @param   pszDesc         Mapping description.
     2778     * @param   pRCPtr          Where to store the RC address.
    27512779     */
    27522780    DECLR3CALLBACKMEMBER(int, pfnMMHyperMapMMIO2,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
     
    27602788     *
    27612789     * @return VBox status code.
    2762      * @param   pDevIns     The device owning the MMIO2 memory.
    2763      * @param   iRegion     The region.
    2764      * @param   off         The offset into the region. Must be page aligned.
    2765      * @param   cb          The number of bytes to map. Must be page aligned.
    2766      * @param   pszDesc     Mapping description.
    2767      * @param   pR0Ptr      Where to store the R0 address.
     2790     * @param   pDevIns         The device owning the MMIO2 memory.
     2791     * @param   iRegion         The region.
     2792     * @param   off             The offset into the region. Must be page aligned.
     2793     * @param   cb              The number of bytes to map. Must be page aligned.
     2794     * @param   pszDesc         Mapping description.
     2795     * @param   pR0Ptr          Where to store the R0 address.
    27682796     */
    27692797    DECLR3CALLBACKMEMBER(int, pfnMMIO2MapKernel,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
     
    28042832
    28052833/** Current PDMDEVHLP version number. */
    2806 #define PDM_DEVHLP_VERSION  0xf2070000
     2834#define PDM_DEVHLP_VERSION  0xf2080000
    28072835
    28082836
     
    28382866     * Read physical memory.
    28392867     *
     2868     * @returns VINF_SUCCESS (for now).
    28402869     * @param   pDevIns         Device instance.
    28412870     * @param   GCPhys          Physical address start reading from.
     
    28432872     * @param   cbRead          How many bytes to read.
    28442873     */
    2845     DECLRCCALLBACKMEMBER(void, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
     2874    DECLRCCALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
    28462875
    28472876    /**
    28482877     * Write to physical memory.
    28492878     *
     2879     * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
    28502880     * @param   pDevIns         Device instance.
    28512881     * @param   GCPhys          Physical address to write to.
     
    28532883     * @param   cbWrite         How many bytes to write.
    28542884     */
    2855     DECLRCCALLBACKMEMBER(void, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
     2885    DECLRCCALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
    28562886
    28572887    /**
     
    29402970
    29412971/** Current PDMDEVHLP version number. */
    2942 #define PDM_DEVHLPRC_VERSION  0xfb010000
     2972#define PDM_DEVHLPRC_VERSION  0xfb010001
    29432973
    29442974
     
    29743004     * Read physical memory.
    29753005     *
     3006     * @returns VINF_SUCCESS (for now).
    29763007     * @param   pDevIns         Device instance.
    29773008     * @param   GCPhys          Physical address start reading from.
     
    29793010     * @param   cbRead          How many bytes to read.
    29803011     */
    2981     DECLR0CALLBACKMEMBER(void, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
     3012    DECLR0CALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
    29823013
    29833014    /**
    29843015     * Write to physical memory.
    29853016     *
     3017     * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
    29863018     * @param   pDevIns         Device instance.
    29873019     * @param   GCPhys          Physical address to write to.
     
    29893021     * @param   cbWrite         How many bytes to write.
    29903022     */
    2991     DECLR0CALLBACKMEMBER(void, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
     3023    DECLR0CALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
    29923024
    29933025    /**
     
    30843116
    30853117/** Current PDMDEVHLP version number. */
    3086 #define PDM_DEVHLPR0_VERSION  0xfb020000
     3118#define PDM_DEVHLPR0_VERSION  0xfb020001
    30873119
    30883120
     
    35213553}
    35223554
    3523 #ifndef VBOX_WITH_NEW_PHYS_CODE
    3524 /**
    3525  * @copydoc PDMDEVHLPR3::pfnPhysReserve
    3526  */
    3527 DECLINLINE(int) PDMDevHlpPhysReserve(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, const char *pszDesc)
    3528 {
    3529     return pDevIns->pDevHlpR3->pfnPhysReserve(pDevIns, GCPhys, cbRange, pszDesc);
    3530 }
    3531 #endif
    3532 
    35333555/**
    35343556 * @copydoc PDMDEVHLPR3::pfnPhysGCPtr2GCPhys
     
    37153737 * @copydoc PDMDEVHLPR3::pfnPhysRead
    37163738 */
    3717 DECLINLINE(void) PDMDevHlpPhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
    3718 {
    3719     pDevIns->CTX_SUFF(pDevHlp)->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
     3739DECLINLINE(int) PDMDevHlpPhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
     3740{
     3741    return pDevIns->CTX_SUFF(pDevHlp)->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
    37203742}
    37213743
     
    37233745 * @copydoc PDMDEVHLPR3::pfnPhysWrite
    37243746 */
    3725 DECLINLINE(void) PDMDevHlpPhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
    3726 {
    3727     pDevIns->CTX_SUFF(pDevHlp)->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
    3728 }
     3747DECLINLINE(int) PDMDevHlpPhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
     3748{
     3749    return pDevIns->CTX_SUFF(pDevHlp)->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
     3750}
     3751
     3752#ifdef IN_RING3
     3753
     3754/**
     3755 * @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtr
     3756 */
     3757DECLINLINE(int) PDMDevHlpPhysGCPhys2CCPtr(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock)
     3758{
     3759    return pDevIns->CTX_SUFF(pDevHlp)->pfnPhysGCPhys2CCPtr(pDevIns, GCPhys, fFlags, ppv, pLock);
     3760}
     3761
     3762/**
     3763 * @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtrReadOnly
     3764 */
     3765DECLINLINE(int) PDMDevHlpPhysGCPhys2CCPtrReadOnly(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void const **ppv, PPGMPAGEMAPLOCK pLock)
     3766{
     3767    return pDevIns->CTX_SUFF(pDevHlp)->pfnPhysGCPhys2CCPtrReadOnly(pDevIns, GCPhys, fFlags, ppv, pLock);
     3768}
     3769
     3770/**
     3771 * @copydoc PDMDEVHLPR3::pfnPhysReleasePageMappingLock
     3772 */
     3773DECLINLINE(void) PDMDevHlpPhysReleasePageMappingLock(PPDMDEVINS pDevIns, PPGMPAGEMAPLOCK pLock)
     3774{
     3775    pDevIns->CTX_SUFF(pDevHlp)->pfnPhysReleasePageMappingLock(pDevIns, pLock);
     3776}
     3777
     3778#endif /* IN_RING3 */
    37293779
    37303780/**
  • trunk/include/VBox/pgm.h

    r17534 r18101  
    359359VMMDECL(void)       PGMPhysInvalidatePageR3MapTLB(PVM pVM);
    360360
    361 /**
    362  * Page mapping lock.
    363  *
    364  * @remarks This doesn't work in structures shared between
    365  *          ring-3, ring-0 and/or GC.
    366  */
    367 typedef struct PGMPAGEMAPLOCK
    368 {
    369     /** @todo see PGMPhysIsPageMappingLockValid for possibly incorrect assumptions */
    370 #if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
    371     /** Just a dummy for the time being. */
    372     uint32_t    u32Dummy;
    373 #else
    374     /** Pointer to the PGMPAGE. */
    375     void       *pvPage;
    376     /** Pointer to the PGMCHUNKR3MAP. */
    377     void       *pvMap;
    378 #endif
    379 } PGMPAGEMAPLOCK;
    380 /** Pointer to a page mapping lock. */
    381 typedef PGMPAGEMAPLOCK *PPGMPAGEMAPLOCK;
    382 
    383361VMMDECL(int)        PGMPhysGCPhys2CCPtr(PVM pVM, RTGCPHYS GCPhys, void **ppv, PPGMPAGEMAPLOCK pLock);
    384362VMMDECL(int)        PGMPhysGCPhys2CCPtrReadOnly(PVM pVM, RTGCPHYS GCPhys, void const **ppv, PPGMPAGEMAPLOCK pLock);
     
    575553VMMR3DECL(int)      PGMR3PhysReadExternal(PVM pVM, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead);
    576554VMMR3DECL(int)      PGMR3PhysWriteExternal(PVM pVM, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
     555VMMR3DECL(int)      PGMR3PhysGCPhys2CCPtrExternal(PVM pVM, RTGCPHYS GCPhys, void **ppv, PPGMPAGEMAPLOCK pLock);
     556VMMR3DECL(int)      PGMR3PhysGCPhys2CCPtrReadOnlyExternal(PVM pVM, RTGCPHYS GCPhys, void const **ppv, PPGMPAGEMAPLOCK pLock);
    577557VMMR3DECL(int)      PGMR3PhysChunkMap(PVM pVM, uint32_t idChunk);
    578558VMMR3DECL(void)     PGMR3PhysChunkInvalidateTLB(PVM pVM);
  • trunk/include/VBox/types.h

    r17661 r18101  
    574574
    575575
     576/**
     577 * Page mapping lock.
     578 *
     579 * @remarks This doesn't work in structures shared between
     580 *          ring-3, ring-0 and/or GC.
     581 */
     582typedef struct PGMPAGEMAPLOCK
     583{
     584    /** @todo see PGMPhysIsPageMappingLockValid for possibly incorrect assumptions */
     585#if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
     586    /** Just a dummy for the time being. */
     587    uint32_t    u32Dummy;
     588#else
     589    /** Pointer to the PGMPAGE. */
     590    void       *pvPage;
     591    /** Pointer to the PGMCHUNKR3MAP. */
     592    void       *pvMap;
     593#endif
     594} PGMPAGEMAPLOCK;
     595/** Pointer to a page mapping lock. */
     596typedef PGMPAGEMAPLOCK *PPGMPAGEMAPLOCK;
     597
     598
    576599/** @} */
    577600
  • trunk/src/VBox/Devices/PC/DevPcArch.c

    r17251 r18101  
    259259     * Note: This will be removed before long.
    260260     */
    261     rc = PDMDevHlpPhysReserve(pDevIns, 0x000a0000, 0x50000, "Low ROM Region");
     261    rc = MMR3PhysReserve(PDMDevHlpGetVM(pDevIns), 0x000a0000, 0x50000, "Low ROM Region");
    262262    if (RT_FAILURE(rc))
    263263        return rc;
    264     rc = PDMDevHlpPhysReserve(pDevIns, 0xfff80000, 0x80000, "High ROM Region");
     264    rc = MMR3PhysReserve(PDMDevHlpGetVM(pDevIns), 0xfff80000, 0x80000, "High ROM Region");
    265265    if (RT_FAILURE(rc))
    266266        return rc;
  • trunk/src/VBox/VMM/PDMDevHlp.cpp

    r17534 r18101  
    20242024
    20252025/** @copydoc PDMDEVHLPR3::pfnPhysRead */
    2026 static DECLCALLBACK(void) pdmR3DevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
     2026static DECLCALLBACK(int) pdmR3DevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
    20272027{
    20282028    PDMDEV_ASSERT_DEVINS(pDevIns);
     
    20332033    int rc;
    20342034#ifdef VBOX_WITH_NEW_PHYS_CODE
    2035     if (!VM_IS_EMT(pVM))
     2035    if (VM_IS_EMT(pVM))
     2036        rc = PGMPhysRead(pVM, GCPhys, pvBuf, cbRead);
     2037    else
    20362038        rc = PGMR3PhysReadExternal(pVM, GCPhys, pvBuf, cbRead);
    2037     else
    2038         rc = PGMPhysRead(pVM, GCPhys, pvBuf, cbRead);
    20392039#else
    20402040    PGMPhysRead(pVM, GCPhys, pvBuf, cbRead);
     
    20422042#endif
    20432043    Log(("pdmR3DevHlp_PhysRead: caller='%s'/%d: returns %Rrc\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance, rc));
    2044     /** @todo return rc; */ NOREF(rc);
     2044    return rc;
    20452045}
    20462046
    20472047
    20482048/** @copydoc PDMDEVHLPR3::pfnPhysWrite */
    2049 static DECLCALLBACK(void) pdmR3DevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
     2049static DECLCALLBACK(int) pdmR3DevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
    20502050{
    20512051    PDMDEV_ASSERT_DEVINS(pDevIns);
     
    20562056    int rc;
    20572057#ifdef VBOX_WITH_NEW_PHYS_CODE
    2058     if (!VM_IS_EMT(pVM))
     2058    if (VM_IS_EMT(pVM))
     2059        rc = PGMPhysWrite(pVM, GCPhys, pvBuf, cbWrite);
     2060    else
    20592061        rc = PGMR3PhysWriteExternal(pVM, GCPhys, pvBuf, cbWrite);
    2060     else
    2061         rc = PGMPhysWrite(pVM, GCPhys, pvBuf, cbWrite);
    20622062#else
    20632063    PGMPhysWrite(pVM, GCPhys, pvBuf, cbWrite);
     
    20652065#endif
    20662066    Log(("pdmR3DevHlp_PhysWrite: caller='%s'/%d: returns %Rrc\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance, rc));
    2067     /** @todo return rc; */ NOREF(rc);
     2067    return rc;
     2068}
     2069
     2070
     2071/** @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtr */
     2072static DECLCALLBACK(int) pdmR3DevHlp_PhysGCPhys2CCPtr(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock)
     2073{
     2074    PDMDEV_ASSERT_DEVINS(pDevIns);
     2075    PVM pVM = pDevIns->Internal.s.pVMR3;
     2076    LogFlow(("pdmR3DevHlp_PhysGCPhys2CCPtr: caller='%s'/%d: GCPhys=%RGp fFlags=%#x ppv=%p pLock=%p\n",
     2077             pDevIns->pDevReg->szDeviceName, pDevIns->iInstance, GCPhys, fFlags, ppv, pLock));
     2078    AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
     2079
     2080    int rc = PGMR3PhysGCPhys2CCPtrExternal(pVM, GCPhys, ppv, pLock);
     2081
     2082    Log(("pdmR3DevHlp_PhysGCPhys2CCPtr: caller='%s'/%d: returns %Rrc\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance, rc));
     2083    return rc;
     2084}
     2085
     2086
     2087/** @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtrReadOnly */
     2088static DECLCALLBACK(int) pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, const void **ppv, PPGMPAGEMAPLOCK pLock)
     2089{
     2090    PDMDEV_ASSERT_DEVINS(pDevIns);
     2091    PVM pVM = pDevIns->Internal.s.pVMR3;
     2092    LogFlow(("pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly: caller='%s'/%d: GCPhys=%RGp fFlags=%#x ppv=%p pLock=%p\n",
     2093             pDevIns->pDevReg->szDeviceName, pDevIns->iInstance, GCPhys, fFlags, ppv, pLock));
     2094    AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
     2095
     2096    int rc = PGMR3PhysGCPhys2CCPtrReadOnlyExternal(pVM, GCPhys, ppv, pLock);
     2097
     2098    Log(("pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly: caller='%s'/%d: returns %Rrc\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance, rc));
     2099    return rc;
     2100}
     2101
     2102
     2103/** @copydoc PDMDEVHLPR3::pfnPhysReleasePageMappingLock */
     2104static DECLCALLBACK(void) pdmR3DevHlp_PhysReleasePageMappingLock(PPDMDEVINS pDevIns, PPGMPAGEMAPLOCK pLock)
     2105{
     2106    PDMDEV_ASSERT_DEVINS(pDevIns);
     2107    PVM pVM = pDevIns->Internal.s.pVMR3;
     2108    LogFlow(("pdmR3DevHlp_PhysReleasePageMappingLock: caller='%s'/%d: pLock=%p\n",
     2109             pDevIns->pDevReg->szDeviceName, pDevIns->iInstance, pLock));
     2110
     2111    PGMPhysReleasePageMappingLock(pVM, pLock);
     2112
     2113    Log(("pdmR3DevHlp_PhysReleasePageMappingLock: caller='%s'/%d: returns void\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
    20682114}
    20692115
     
    21062152
    21072153    return rc;
    2108 }
    2109 
    2110 
    2111 /** @copydoc PDMDEVHLPR3::pfnPhysReserve */
    2112 static DECLCALLBACK(int) pdmR3DevHlp_PhysReserve(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, const char *pszDesc)
    2113 {
    2114 #ifdef VBOX_WITH_NEW_PHYS_CODE
    2115     AssertFailed();
    2116     return VERR_ACCESS_DENIED;
    2117 #else
    2118     PDMDEV_ASSERT_DEVINS(pDevIns);
    2119     VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
    2120     LogFlow(("pdmR3DevHlp_PhysReserve: caller='%s'/%d: GCPhys=%RGp cbRange=%#x pszDesc=%p:{%s}\n",
    2121              pDevIns->pDevReg->szDeviceName, pDevIns->iInstance, GCPhys, cbRange, pszDesc, pszDesc));
    2122 
    2123     int rc = MMR3PhysReserve(pDevIns->Internal.s.pVMR3, GCPhys, cbRange, pszDesc);
    2124 
    2125     LogFlow(("pdmR3DevHlp_PhysReserve: caller='%s'/%d: returns %Rrc\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance, rc));
    2126 
    2127     return rc;
    2128 #endif
    2129 }
    2130 
    2131 
    2132 /** @copydoc PDMDEVHLPR3::pfnObsoletePhys2HCVirt */
    2133 static DECLCALLBACK(int) pdmR3DevHlp_Obsolete_Phys2HCVirt(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, PRTHCPTR ppvHC)
    2134 {
    2135     PDMDEV_ASSERT_DEVINS(pDevIns);
    2136     AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
    2137     NOREF(GCPhys);
    2138     NOREF(cbRange);
    2139     NOREF(ppvHC);
    2140     return VERR_ACCESS_DENIED;
    2141 }
    2142 
    2143 
    2144 /** @copydoc PDMDEVHLPR3::pfnObsoletePhysGCPtr2HCPtr */
    2145 static DECLCALLBACK(int) pdmR3DevHlp_Obsolete_PhysGCPtr2HCPtr(PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTHCPTR pHCPtr)
    2146 {
    2147     PDMDEV_ASSERT_DEVINS(pDevIns);
    2148     AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
    2149     NOREF(GCPtr);
    2150     NOREF(pHCPtr);
    2151     return VERR_ACCESS_DENIED;
    21522154}
    21532155
     
    27032705    pdmR3DevHlp_PhysRead,
    27042706    pdmR3DevHlp_PhysWrite,
     2707    pdmR3DevHlp_PhysGCPhys2CCPtr,
     2708    pdmR3DevHlp_PhysGCPhys2CCPtrReadOnly,
     2709    pdmR3DevHlp_PhysReleasePageMappingLock,
    27052710    pdmR3DevHlp_PhysReadGCVirt,
    27062711    pdmR3DevHlp_PhysWriteGCVirt,
    2707     pdmR3DevHlp_PhysReserve,
    2708     pdmR3DevHlp_Obsolete_Phys2HCVirt,
    2709     pdmR3DevHlp_Obsolete_PhysGCPtr2HCPtr,
    27102712    pdmR3DevHlp_A20IsEnabled,
    27112713    pdmR3DevHlp_A20Set,
     
    28052807
    28062808/** @copydoc PDMDEVHLPR3::pfnPhysRead */
    2807 static DECLCALLBACK(void) pdmR3DevHlp_Untrusted_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
     2809static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
    28082810{
    28092811    PDMDEV_ASSERT_DEVINS(pDevIns);
     
    28122814    NOREF(pvBuf);
    28132815    NOREF(cbRead);
     2816    return VERR_ACCESS_DENIED;
    28142817}
    28152818
    28162819
    28172820/** @copydoc PDMDEVHLPR3::pfnPhysWrite */
    2818 static DECLCALLBACK(void) pdmR3DevHlp_Untrusted_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
     2821static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
    28192822{
    28202823    PDMDEV_ASSERT_DEVINS(pDevIns);
     
    28232826    NOREF(pvBuf);
    28242827    NOREF(cbWrite);
     2828    return VERR_ACCESS_DENIED;
     2829}
     2830
     2831
     2832/** @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtr */
     2833static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_PhysGCPhys2CCPtr(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock)
     2834{
     2835    PDMDEV_ASSERT_DEVINS(pDevIns);
     2836    AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
     2837    NOREF(GCPhys);
     2838    NOREF(fFlags);
     2839    NOREF(ppv);
     2840    NOREF(pLock);
     2841    return VERR_ACCESS_DENIED;
     2842}
     2843
     2844
     2845/** @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtrReadOnly */
     2846static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_PhysGCPhys2CCPtrReadOnly(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, const void **ppv, PPGMPAGEMAPLOCK pLock)
     2847{
     2848    PDMDEV_ASSERT_DEVINS(pDevIns);
     2849    AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
     2850    NOREF(GCPhys);
     2851    NOREF(fFlags);
     2852    NOREF(ppv);
     2853    NOREF(pLock);
     2854    return VERR_ACCESS_DENIED;
     2855}
     2856
     2857
     2858/** @copydoc PDMDEVHLPR3::pfnPhysReleasePageMappingLock */
     2859static DECLCALLBACK(void) pdmR3DevHlp_Untrusted_PhysReleasePageMappingLock(PPDMDEVINS pDevIns, PPGMPAGEMAPLOCK pLock)
     2860{
     2861    PDMDEV_ASSERT_DEVINS(pDevIns);
     2862    AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
     2863    NOREF(pLock);
    28252864}
    28262865
     
    28462885    NOREF(pvSrc);
    28472886    NOREF(cb);
    2848     return VERR_ACCESS_DENIED;
    2849 }
    2850 
    2851 
    2852 /** @copydoc PDMDEVHLPR3::pfnPhysReserve */
    2853 static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_PhysReserve(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, const char *pszDesc)
    2854 {
    2855     PDMDEV_ASSERT_DEVINS(pDevIns);
    2856     AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
    2857     NOREF(GCPhys);
    2858     NOREF(cbRange);
    2859     return VERR_ACCESS_DENIED;
    2860 }
    2861 
    2862 
    2863 /** @copydoc PDMDEVHLPR3::pfnObsoletePhys2HCVirt */
    2864 static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_Obsolete_Phys2HCVirt(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, PRTHCPTR ppvHC)
    2865 {
    2866     PDMDEV_ASSERT_DEVINS(pDevIns);
    2867     AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
    2868     NOREF(GCPhys);
    2869     NOREF(cbRange);
    2870     NOREF(ppvHC);
    2871     return VERR_ACCESS_DENIED;
    2872 }
    2873 
    2874 
    2875 /** @copydoc PDMDEVHLPR3::pfnObsoletePhysGCPtr2HCPtr */
    2876 static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_Obsolete_PhysGCPtr2HCPtr(PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTHCPTR pHCPtr)
    2877 {
    2878     PDMDEV_ASSERT_DEVINS(pDevIns);
    2879     AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
    2880     NOREF(GCPtr);
    2881     NOREF(pHCPtr);
    28822887    return VERR_ACCESS_DENIED;
    28832888}
     
    31833188    pdmR3DevHlp_Untrusted_PhysRead,
    31843189    pdmR3DevHlp_Untrusted_PhysWrite,
     3190    pdmR3DevHlp_Untrusted_PhysGCPhys2CCPtr,
     3191    pdmR3DevHlp_Untrusted_PhysGCPhys2CCPtrReadOnly,
     3192    pdmR3DevHlp_Untrusted_PhysReleasePageMappingLock,
    31853193    pdmR3DevHlp_Untrusted_PhysReadGCVirt,
    31863194    pdmR3DevHlp_Untrusted_PhysWriteGCVirt,
    3187     pdmR3DevHlp_Untrusted_PhysReserve,
    3188     pdmR3DevHlp_Untrusted_Obsolete_Phys2HCVirt,
    3189     pdmR3DevHlp_Untrusted_Obsolete_PhysGCPtr2HCPtr,
    31903195    pdmR3DevHlp_Untrusted_A20IsEnabled,
    31913196    pdmR3DevHlp_Untrusted_A20Set,
  • trunk/src/VBox/VMM/PGMPhys.cpp

    r18046 r18101  
    345345}
    346346
     347
     348#ifdef VBOX_WITH_NEW_PHYS_CODE
     349/**
     350 * VMR3ReqCall worker for PGMR3PhysGCPhys2CCPtrExternal to make pages writable.
     351 * 
     352 * @returns see PGMR3PhysGCPhys2CCPtrExternal
     353 * @param   pVM         The VM handle.
     354 * @param   pGCPhys     Pointer to the guest physical address.
     355 * @param   ppv         Where to store the mapping address.
     356 * @param   pLock       Where to store the lock.
     357 */
     358static DECLCALLBACK(int) pgmR3PhysGCPhys2CCPtrDelegated(PVM pVM, PRTGCPHYS pGCPhys, void **ppv, PPGMPAGEMAPLOCK pLock)
     359{
     360    /*
     361     * Just hand it to PGMPhysGCPhys2CCPtr and check that it's not a page with
     362     * an access handler after it succeeds.
     363     */
     364    int rc = pgmLock(pVM);
     365    AssertRCReturn(rc, rc);
     366
     367    rc = PGMPhysGCPhys2CCPtr(pVM, *pGCPhys, ppv, pLock);
     368    if (RT_SUCCESS(rc))
     369    {
     370        PPGMPAGEMAPTLBE pTlbe;
     371        int rc2 = pgmPhysPageQueryTlbe(&pVM->pgm.s, *pGCPhys, &pTlbe);
     372        AssertFatalRC(rc2);
     373        PPGMPAGE pPage = pTlbe->pPage;
     374#if 1
     375        if (PGM_PAGE_IS_MMIO(pPage))
     376#else
     377        if (PGM_PAGE_HAS_ACTIVE_HANDLERS(pPage))
     378#endif
     379        {
     380            PGMPhysReleasePageMappingLock(pVM, pLock);
     381            rc = VERR_PGM_PHYS_PAGE_RESERVED;
     382        }
     383    }
     384
     385    pgmUnlock(pVM);
     386    return rc;
     387}
     388#endif /* VBOX_WITH_NEW_PHYS_CODE */
     389
     390
     391/**
     392 * Requests the mapping of a guest page into ring-3, external threads.
     393 *
     394 * When you're done with the page, call PGMPhysReleasePageMappingLock() ASAP to
     395 * release it.
     396 *
     397 * This API will assume your intention is to write to the page, and will
     398 * therefore replace shared and zero pages. If you do not intend to modify the
     399 * page, use the PGMR3PhysGCPhys2CCPtrReadOnlyExternal() API.
     400 *
     401 * @returns VBox status code.
     402 * @retval  VINF_SUCCESS on success.
     403 * @retval  VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical
     404 *          backing or if the page has any active access handlers. The caller
     405 *          must fall back on using PGMR3PhysWriteExternal.
     406 * @retval  VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
     407 *
     408 * @param   pVM         The VM handle.
     409 * @param   GCPhys      The guest physical address of the page that should be mapped.
     410 * @param   ppv         Where to store the address corresponding to GCPhys.
     411 * @param   pLock       Where to store the lock information that PGMPhysReleasePageMappingLock needs.
     412 *
     413 * @remark  Avoid calling this API from within critical sections (other than the
     414 *          PGM one) because of the deadlock risk when we have to delegating the
     415 *          task to an EMT.
     416 * @thread  Any.
     417 */
     418VMMR3DECL(int) PGMR3PhysGCPhys2CCPtrExternal(PVM pVM, RTGCPHYS GCPhys, void **ppv, PPGMPAGEMAPLOCK pLock)
     419{
     420    VM_ASSERT_OTHER_THREAD(pVM);
     421    AssertPtr(ppv);
     422    AssertPtr(pLock);
     423
     424#ifdef VBOX_WITH_NEW_PHYS_CODE
     425    int rc = pgmLock(pVM);
     426    AssertRCReturn(rc, rc);
     427
     428    /*
     429     * Query the Physical TLB entry for the page (may fail).
     430     */
     431    PPGMPAGEMAPTLBE pTlbe;
     432    rc = pgmPhysPageQueryTlbe(&pVM->pgm.s, GCPhys, &pTlbe);
     433    if (RT_SUCCESS(rc))
     434    {
     435        PPGMPAGE pPage = pTlbe->pPage;
     436#if 1
     437        if (PGM_PAGE_IS_MMIO(pPage))
     438            rc = VERR_PGM_PHYS_PAGE_RESERVED;
     439#else
     440        if (PGM_PAGE_HAS_ACTIVE_HANDLERS(pPage))
     441            rc = VERR_PGM_PHYS_PAGE_RESERVED;
     442#endif
     443        else
     444        {
     445            /*
     446             * If the page is shared, the zero page, or being write monitored
     447             * it must be converted to an page that's writable if possible.
     448             * This has to be done on an EMT.
     449             */
     450            if (RT_UNLIKELY(PGM_PAGE_GET_STATE(pPage) != PGM_PAGE_STATE_ALLOCATED))
     451            {
     452                pgmUnlock(pVM);
     453   
     454                PVMREQ pReq = NULL;
     455                rc = VMR3ReqCall(pVM, VMREQDEST_ANY, &pReq, RT_INDEFINITE_WAIT,
     456                                 (PFNRT)pgmR3PhysGCPhys2CCPtrDelegated, 4, pVM, &GCPhys, ppv, pLock);
     457                if (RT_SUCCESS(rc))
     458                {
     459                    rc = pReq->iStatus;
     460                    VMR3ReqFree(pReq);
     461                }
     462                return rc;
     463            }
     464
     465            /*
     466             * Now, just perform the locking and calculate the return address.
     467             */
     468            PPGMPAGEMAP pMap = pTlbe->pMap;
     469            pMap->cRefs++;
     470#if 0 /** @todo implement locking properly */
     471            if (RT_LIKELY(pPage->cLocks != PGM_PAGE_MAX_LOCKS))
     472                if (RT_UNLIKELY(++pPage->cLocks == PGM_PAGE_MAX_LOCKS))
     473                {
     474                    AssertMsgFailed(("%RGp is entering permanent locked state!\n", GCPhys));
     475                    pMap->cRefs++; /* Extra ref to prevent it from going away. */
     476                }
     477#endif
     478            *ppv = (void *)((uintptr_t)pTlbe->pv | (GCPhys & PAGE_OFFSET_MASK));
     479            pLock->pvPage = pPage;
     480            pLock->pvMap = pMap;
     481        }
     482    }
     483
     484    pgmUnlock(pVM);
     485    return rc;
     486
     487#else  /* !VBOX_WITH_NEW_PHYS_CODE */
     488    /*
     489     * Fallback code.
     490     */
     491    return PGMPhysGCPhys2R3Ptr(pVM, GCPhys, 1, (PRTR3PTR)ppv);
     492#endif /* !VBOX_WITH_NEW_PHYS_CODE */
     493}
     494
     495
     496/**
     497 * Requests the mapping of a guest page into ring-3, external threads.
     498 *
     499 * When you're done with the page, call PGMPhysReleasePageMappingLock() ASAP to
     500 * release it.
     501 *
     502 * @returns VBox status code.
     503 * @retval  VINF_SUCCESS on success.
     504 * @retval  VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical
     505 *          backing or if the page as an active ALL access handler. The caller
     506 *          must fall back on using PGMPhysRead.
     507 * @retval  VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
     508 *
     509 * @param   pVM         The VM handle.
     510 * @param   GCPhys      The guest physical address of the page that should be mapped.
     511 * @param   ppv         Where to store the address corresponding to GCPhys.
     512 * @param   pLock       Where to store the lock information that PGMPhysReleasePageMappingLock needs.
     513 *
     514 * @remark  Avoid calling this API from within critical sections (other than
     515 *          the PGM one) because of the deadlock risk.
     516 * @thread  Any.
     517 */
     518VMMR3DECL(int) PGMR3PhysGCPhys2CCPtrReadOnlyExternal(PVM pVM, RTGCPHYS GCPhys, void const **ppv, PPGMPAGEMAPLOCK pLock)
     519{
     520#ifdef VBOX_WITH_NEW_PHYS_CODE
     521    int rc = pgmLock(pVM);
     522    AssertRCReturn(rc, rc);
     523
     524    /*
     525     * Query the Physical TLB entry for the page (may fail).
     526     */
     527    PPGMPAGEMAPTLBE pTlbe;
     528    rc = pgmPhysPageQueryTlbe(&pVM->pgm.s, GCPhys, &pTlbe);
     529    if (RT_SUCCESS(rc))
     530    {
     531        PPGMPAGE pPage = pTlbe->pPage;
     532#if 1
     533        /* MMIO pages doesn't have any readable backing. */
     534        if (PGM_PAGE_IS_MMIO(pPage))
     535            rc = VERR_PGM_PHYS_PAGE_RESERVED;
     536#else
     537        if (PGM_PAGE_HAS_ACTIVE_ALL_HANDLERS(pPage))
     538            rc = VERR_PGM_PHYS_PAGE_RESERVED;
     539#endif
     540        else
     541        {
     542            /*
     543             * Now, just perform the locking and calculate the return address.
     544             */
     545            PPGMPAGEMAP pMap = pTlbe->pMap;
     546            pMap->cRefs++;
     547#if 0 /** @todo implement locking properly */
     548            if (RT_LIKELY(pPage->cLocks != PGM_PAGE_MAX_LOCKS))
     549                if (RT_UNLIKELY(++pPage->cLocks == PGM_PAGE_MAX_LOCKS))
     550                {
     551                    AssertMsgFailed(("%RGp is entering permanent locked state!\n", GCPhys));
     552                    pMap->cRefs++; /* Extra ref to prevent it from going away. */
     553                }
     554#endif
     555            *ppv = (void *)((uintptr_t)pTlbe->pv | (GCPhys & PAGE_OFFSET_MASK));
     556            pLock->pvPage = pPage;
     557            pLock->pvMap = pMap;
     558        }
     559    }
     560
     561    pgmUnlock(pVM);
     562    return rc;
     563
     564#else  /* !VBOX_WITH_NEW_PHYS_CODE */
     565    /*
     566     * Fallback code.
     567     */
     568    return PGMPhysGCPhys2CCPtr(pVM, GCPhys, (void **)ppv, pLock);
     569#endif /* !VBOX_WITH_NEW_PHYS_CODE */
     570}
    347571
    348572
  • trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp

    r18073 r18101  
    939939 * @param   ppv         Where to store the address corresponding to GCPhys.
    940940 * @param   pLock       Where to store the lock information that PGMPhysReleasePageMappingLock needs.
    941  *
    942  * @remark  Avoid calling this API from within critical sections (other than
    943  *          the PGM one) because of the deadlock risk.
     941 * 
     942 * @remarks The caller is responsible for dealing with access handlers.
     943 * @todo    Add an informational return code for pages with access handlers?
     944 * 
     945 * @remark  Avoid calling this API from within critical sections (other than the
     946 *          PGM one) because of the deadlock risk. External threads may need to
     947 *          delegate jobs to the EMTs.
    944948 * @thread  Any thread.
    945949 */
     
    972976    }
    973977
    974 # else
     978# else  /* IN_RING3 || IN_RING0 */
    975979    int rc = pgmLock(pVM);
    976980    AssertRCReturn(rc, rc);
     
    10411045 * This API should only be used for very short term, as it will consume
    10421046 * scarse resources (R0 and GC) in the mapping cache. When you're done
    1043  * with the page, call PGMPhysReleasePageMappingLock() ASAP to release it.
    1044  *
     1047 * with the page, call PGMPhysReleasePageMappingLock() ASAP to release it. 
     1048 * 
    10451049 * @returns VBox status code.
    10461050 * @retval  VINF_SUCCESS on success.
     
    10531057 * @param   pLock       Where to store the lock information that PGMPhysReleasePageMappingLock needs.
    10541058 *
     1059 * @remarks The caller is responsible for dealing with access handlers.
     1060 * @todo    Add an informational return code for pages with access handlers?
     1061 * 
    10551062 * @remark  Avoid calling this API from within critical sections (other than
    10561063 *          the PGM one) because of the deadlock risk.
     
    10591066VMMDECL(int) PGMPhysGCPhys2CCPtrReadOnly(PVM pVM, RTGCPHYS GCPhys, void const **ppv, PPGMPAGEMAPLOCK pLock)
    10601067{
    1061     /** @todo implement this */
     1068#ifdef VBOX_WITH_NEW_PHYS_CODE
     1069# if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
     1070
     1071    /*
     1072     * Find the page and make sure it's readable.
     1073     */
     1074    PPGMPAGE pPage;
     1075    int rc = pgmPhysGetPageEx(&pVM->pgm.s, GCPhys, &pPage);
     1076    if (RT_SUCCESS(rc))
     1077    {
     1078        if (RT_UNLIKELY(PGM_PAGE_IS_MMIO(pPage)))
     1079            rc = VERR_PGM_PHYS_PAGE_RESERVED;
     1080        else
     1081        {
     1082            *ppv = pgmDynMapHCPageOff(&pVM->pgm.s, PGM_PAGE_GET_HCPHYS(pPage) | (GCPhys & PAGE_OFFSET_MASK)); /** @todo add a read only flag? */
     1083#if 0
     1084            pLock->pvMap = 0;
     1085            pLock->pvPage = pPage;
     1086#else
     1087            pLock->u32Dummy = UINT32_MAX;
     1088#endif
     1089            AssertMsg(rc == VINF_SUCCESS || rc == VINF_PGM_SYNC_CR3 /* not returned */, ("%Rrc\n", rc));
     1090            rc = VINF_SUCCESS;
     1091        }
     1092    }
     1093
     1094# else  /* IN_RING3 || IN_RING0 */
     1095    int rc = pgmLock(pVM);
     1096    AssertRCReturn(rc, rc);
     1097
     1098    /*
     1099     * Query the Physical TLB entry for the page (may fail).
     1100     */
     1101    PPGMPAGEMAPTLBE pTlbe;
     1102    rc = pgmPhysPageQueryTlbe(&pVM->pgm.s, GCPhys, &pTlbe);
     1103    if (RT_SUCCESS(rc))
     1104    {
     1105        /* MMIO pages doesn't have any readable backing. */
     1106        PPGMPAGE pPage = pTlbe->pPage;
     1107        if (RT_UNLIKELY(PGM_PAGE_IS_MMIO(pPage)))
     1108            rc = VERR_PGM_PHYS_PAGE_RESERVED;
     1109        else
     1110        {
     1111            /*
     1112             * Now, just perform the locking and calculate the return address.
     1113             */
     1114            PPGMPAGEMAP pMap = pTlbe->pMap;
     1115            pMap->cRefs++;
     1116#if 0 /** @todo implement locking properly */
     1117            if (RT_LIKELY(pPage->cLocks != PGM_PAGE_MAX_LOCKS))
     1118                if (RT_UNLIKELY(++pPage->cLocks == PGM_PAGE_MAX_LOCKS))
     1119                {
     1120                    AssertMsgFailed(("%RGp is entering permanent locked state!\n", GCPhys));
     1121                    pMap->cRefs++; /* Extra ref to prevent it from going away. */
     1122                }
     1123#endif
     1124            *ppv = (void *)((uintptr_t)pTlbe->pv | (GCPhys & PAGE_OFFSET_MASK));
     1125            pLock->pvPage = pPage;
     1126            pLock->pvMap = pMap;
     1127        }
     1128    }
     1129
     1130    pgmUnlock(pVM);
     1131#endif /* IN_RING3 || IN_RING0 */
     1132    return rc;
     1133
     1134#else  /* !VBOX_WITH_NEW_PHYS_CODE */
     1135    /*
     1136     * Fallback code.
     1137     */
    10621138    return PGMPhysGCPhys2CCPtr(pVM, GCPhys, (void **)ppv, pLock);
     1139#endif /* !VBOX_WITH_NEW_PHYS_CODE */
    10631140}
    10641141
  • trunk/src/VBox/VMM/VMMGC/PDMGCDevice.cpp

    r17534 r18101  
    5959static DECLCALLBACK(void) pdmGCDevHlp_PCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
    6060static DECLCALLBACK(void) pdmGCDevHlp_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
    61 static DECLCALLBACK(void) pdmGCDevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead);
    62 static DECLCALLBACK(void) pdmGCDevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
     61static DECLCALLBACK(int) pdmGCDevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead);
     62static DECLCALLBACK(int) pdmGCDevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
    6363static DECLCALLBACK(bool) pdmGCDevHlp_A20IsEnabled(PPDMDEVINS pDevIns);
    6464static DECLCALLBACK(int)  pdmGCDevHlp_VMSetError(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...);
     
    248248
    249249/** @copydoc PDMDEVHLPRC::pfnPhysRead */
    250 static DECLCALLBACK(void) pdmGCDevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
     250static DECLCALLBACK(int) pdmGCDevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
    251251{
    252252    PDMDEV_ASSERT_DEVINS(pDevIns);
     
    259259#else
    260260    PGMPhysRead(pDevIns->Internal.s.pVMRC, GCPhys, pvBuf, cbRead);
     261    int rc = VINF_SUCCESS;
    261262#endif
    262263
    263     Log(("pdmGCDevHlp_PhysRead: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
     264    Log(("pdmGCDevHlp_PhysRead: caller=%p/%d: returns %Rrc\n", pDevIns, pDevIns->iInstance, rc));
     265    return rc;
    264266}
    265267
    266268
    267269/** @copydoc PDMDEVHLPRC::pfnPhysWrite */
    268 static DECLCALLBACK(void) pdmGCDevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
     270static DECLCALLBACK(int) pdmGCDevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
    269271{
    270272    PDMDEV_ASSERT_DEVINS(pDevIns);
     
    277279#else
    278280    PGMPhysWrite(pDevIns->Internal.s.pVMRC, GCPhys, pvBuf, cbWrite);
     281    int rc = VINF_SUCCESS;
    279282#endif
    280283
    281     Log(("pdmGCDevHlp_PhysWrite: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
     284    Log(("pdmGCDevHlp_PhysWrite: caller=%p/%d: returns %Rrc\n", pDevIns, pDevIns->iInstance, rc));
     285    return rc;
    282286}
    283287
  • trunk/src/VBox/VMM/VMMR0/PDMR0Device.cpp

    r17534 r18101  
    6060static DECLCALLBACK(void) pdmR0DevHlp_PCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
    6161static DECLCALLBACK(void) pdmR0DevHlp_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
    62 static DECLCALLBACK(void) pdmR0DevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead);
    63 static DECLCALLBACK(void) pdmR0DevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
     62static DECLCALLBACK(int) pdmR0DevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead);
     63static DECLCALLBACK(int) pdmR0DevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
    6464static DECLCALLBACK(bool) pdmR0DevHlp_A20IsEnabled(PPDMDEVINS pDevIns);
    6565static DECLCALLBACK(int)  pdmR0DevHlp_VMSetError(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...);
     
    251251
    252252/** @copydoc PDMDEVHLPR0::pfnPhysRead */
    253 static DECLCALLBACK(void) pdmR0DevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
     253static DECLCALLBACK(int) pdmR0DevHlp_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
    254254{
    255255    PDMDEV_ASSERT_DEVINS(pDevIns);
     
    262262#else
    263263    PGMPhysRead(pDevIns->Internal.s.pVMR0, GCPhys, pvBuf, cbRead);
     264    int rc = VINF_SUCCESS;
    264265#endif
    265266
    266     Log(("pdmR0DevHlp_PhysRead: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
     267    Log(("pdmR0DevHlp_PhysRead: caller=%p/%d: returns %Rrc\n", pDevIns, pDevIns->iInstance, rc));
     268    return rc;
    267269}
    268270
    269271
    270272/** @copydoc PDMDEVHLPR0::pfnPhysWrite */
    271 static DECLCALLBACK(void) pdmR0DevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
     273static DECLCALLBACK(int) pdmR0DevHlp_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
    272274{
    273275    PDMDEV_ASSERT_DEVINS(pDevIns);
     
    280282#else
    281283    PGMPhysWrite(pDevIns->Internal.s.pVMR0, GCPhys, pvBuf, cbWrite);
     284    int rc = VINF_SUCCESS;
    282285#endif
    283286
    284     Log(("pdmR0DevHlp_PhysWrite: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
     287    Log(("pdmR0DevHlp_PhysWrite: caller=%p/%d: returns %Rrc\n", pDevIns, pDevIns->iInstance, rc));
     288    return rc;
    285289}
    286290
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette