VirtualBox

Changeset 65299 in vbox


Ignore:
Timestamp:
Jan 15, 2017 5:50:11 PM (8 years ago)
Author:
vboxsync
Message:

PGM,PDM: Added API for reducing the size a MMIO2 or pre-registered MMIO region when loading saved state.

Location:
trunk
Files:
5 edited

Legend:

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

    r64327 r65299  
    17201720/** The display connector is resizing. */
    17211721#define VINF_VGA_RESIZE_IN_PROGRESS                 (3501)
     1722/** Unexpected PCI region change during VGA saved state loading. */
     1723#define VERR_VGA_UNEXPECTED_PCI_REGION_LOAD_CHANGE  (-3502)
    17221724/** @} */
    17231725
  • trunk/include/VBox/vmm/pdmdev.h

    r65101 r65299  
    18761876
    18771877/** Current PDMDEVHLPR3 version number.
    1878  * @todo Next major revision should add piBus to pfnPCIBusRegister.  */
    1879 #define PDM_DEVHLPR3_VERSION                    PDM_VERSION_MAKE_PP(0xffe7, 19, 1)
     1878 * @todo Next major revision should add piBus to pfnPCIBusRegister, and move
     1879 *       pfnMMIOExReduce up to after pfnMMIOExUnmap. */
     1880#define PDM_DEVHLPR3_VERSION                    PDM_VERSION_MAKE_PP(0xffe7, 19, 2)
    18801881//#define PDM_DEVHLPR3_VERSION                    PDM_VERSION_MAKE_PP(0xffe7, 20, 0)
    18811882
     
    32653266    DECLR3CALLBACKMEMBER(VMRESUMEREASON, pfnVMGetResumeReason,(PPDMDEVINS pDevIns));
    32663267
     3268    /**
     3269     * Reduces the length of a MMIO2 or pre-registered MMIO range.
     3270     *
     3271     * This is for implementations of PDMPCIDEV::pfnRegionLoadChangeHookR3 and will
     3272     * only work during saved state restore.  It will not call the PCI bus code, as
     3273     * that is expected to restore the saved resource configuration.
     3274     *
     3275     * It just adjusts the mapping length of the region so that when pfnMMIOExMap is
     3276     * called it will only map @a cbRegion bytes and not the value set during
     3277     * registration.
     3278     *
     3279     * @return VBox status code.
     3280     * @param   pDevIns             The device owning the range.
     3281     * @param   pPciDev             The PCI device the region is associated with, or
     3282     *                              NULL if not associated with any.
     3283     * @param   iRegion             The region.
     3284     * @param   cbRegion            The new size, must be smaller.
     3285     */
     3286    DECLR3CALLBACKMEMBER(int, pfnMMIOExReduce,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS cbRegion));
     3287
    32673288    /** Space reserved for future members.
    32683289     * @{ */
    3269     DECLR3CALLBACKMEMBER(void, pfnReserved1,(void));
    32703290    DECLR3CALLBACKMEMBER(void, pfnReserved2,(void));
    32713291    DECLR3CALLBACKMEMBER(void, pfnReserved3,(void));
     
    43844404{
    43854405    return pDevIns->pHlpR3->pfnMMIOExUnmap(pDevIns, pPciDev, iRegion, GCPhys);
     4406}
     4407
     4408/**
     4409 * @copydoc PDMDEVHLPR3::pfnMMIOExReduce
     4410 */
     4411DECLINLINE(int) PDMDevHlpMMIOExReduce(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS cbRegion)
     4412{
     4413    return pDevIns->pHlpR3->pfnMMIOExReduce(pDevIns, pPciDev, iRegion, cbRegion);
    43864414}
    43874415
  • trunk/include/VBox/vmm/pgm.h

    r64373 r65299  
    747747VMMR3DECL(int)      PGMR3PhysMMIOExMap(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS GCPhys);
    748748VMMR3DECL(int)      PGMR3PhysMMIOExUnmap(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS GCPhys);
     749VMMR3_INT_DECL(int) PGMR3PhysMMIOExReduce(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS cbRegion);
    749750VMMR3DECL(bool)     PGMR3PhysMMIOExIsBase(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhys);
    750751VMMR3_INT_DECL(int) PGMR3PhysMMIO2GetHCPhys(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS off, PRTHCPHYS pHCPhys);
  • trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp

    r64844 r65299  
    591591
    592592    LogFlow(("pdmR3DevHlp_MMIOExUnmap: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
     593    return rc;
     594}
     595
     596
     597/**
     598 * @copydoc PDMDEVHLPR3::pfnMMIOExReduce
     599 */
     600static DECLCALLBACK(int) pdmR3DevHlp_MMIOExReduce(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS cbRegion)
     601{
     602    PDMDEV_ASSERT_DEVINS(pDevIns);
     603    VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
     604    LogFlow(("pdmR3DevHlp_MMIOExReduce: caller='%s'/%d: pPciDev=%p:{%#x} iRegion=%#x cbRegion=%RGp\n",
     605             pDevIns->pReg->szName, pDevIns->iInstance, pPciDev, pPciDev ? pPciDev->uDevFn : UINT32_MAX, iRegion, cbRegion));
     606    AssertReturn(!pPciDev || pPciDev->Int.s.pDevInsR3 != NULL, VERR_INVALID_PARAMETER);
     607
     608    int rc = PGMR3PhysMMIOExReduce(pDevIns->Internal.s.pVMR3, pDevIns, pPciDev ? pPciDev->Int.s.idxDevCfg : 254, iRegion, cbRegion);
     609
     610    LogFlow(("pdmR3DevHlp_MMIOExReduce: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
    593611    return rc;
    594612}
     
    36783696    pdmR3DevHlp_VMGetSuspendReason,
    36793697    pdmR3DevHlp_VMGetResumeReason,
    3680     0,
     3698    pdmR3DevHlp_MMIOExReduce,
    36813699    0,
    36823700    0,
     
    39353953    pdmR3DevHlp_VMGetSuspendReason,
    39363954    pdmR3DevHlp_VMGetResumeReason,
    3937     0,
     3955    pdmR3DevHlp_MMIOExReduce,
    39383956    0,
    39393957    0,
  • trunk/src/VBox/VMM/VMMR3/PGMPhys.cpp

    r64911 r65299  
    26982698        pNew->RamRange.GCPhysLast   = NIL_RTGCPHYS;
    26992699        pNew->RamRange.pszDesc      = pszDesc;
    2700         pNew->RamRange.cb           = (RTGCPHYS)cPagesTrackedByChunk << X86_PAGE_SHIFT;
     2700        pNew->RamRange.cb           = pNew->cbReal = (RTGCPHYS)cPagesTrackedByChunk << X86_PAGE_SHIFT;
    27012701        pNew->RamRange.fFlags      |= PGM_RAM_RANGE_FLAGS_AD_HOC_MMIO_EX;
    27022702        //pNew->RamRange.pvR3       = NULL;
     
    31633163             * Free the memory.
    31643164             */
    3165             uint32_t const cPages = pCur->RamRange.cb >> PAGE_SHIFT;
     3165            uint32_t const cPages = pCur->cbReal >> PAGE_SHIFT;
    31663166            if (pCur->fFlags & PGMREGMMIORANGE_F_MMIO2)
    31673167            {
     
    36743674
    36753675    return VINF_SUCCESS;
     3676}
     3677
     3678
     3679/**
     3680 * Reduces the mapping size of a MMIO2 or pre-registered MMIO region.
     3681 *
     3682 * This is mainly for dealing with old saved states after changing the default
     3683 * size of a mapping region.  See PGMDevHlpMMIOExReduce and
     3684 * PDMPCIDEV::pfnRegionLoadChangeHookR3.
     3685 *
     3686 * The region must not currently be mapped when making this call.  The VM state
     3687 * must be state restore or VM construction.
     3688 *
     3689 * @returns VBox status code.
     3690 * @param   pVM             The cross context VM structure.
     3691 * @param   pDevIns         The device instance owning the region.
     3692 * @param   iSubDev         The sub-device number of the registered region.
     3693 * @param   iRegion         The index of the registered region.
     3694 * @param   cbRegion        The new mapping size.
     3695 */
     3696VMMR3_INT_DECL(int) PGMR3PhysMMIOExReduce(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS cbRegion)
     3697{
     3698    /*
     3699     * Validate input
     3700     */
     3701    VM_ASSERT_EMT_RETURN(pVM, VERR_VM_THREAD_NOT_EMT);
     3702    AssertPtrReturn(pDevIns, VERR_INVALID_PARAMETER);
     3703    AssertReturn(iSubDev <= UINT8_MAX, VERR_INVALID_PARAMETER);
     3704    AssertReturn(iRegion <= UINT8_MAX, VERR_INVALID_PARAMETER);
     3705    AssertReturn(cbRegion >= X86_PAGE_SIZE, VERR_INVALID_PARAMETER);
     3706    AssertReturn(!(cbRegion & X86_PAGE_OFFSET_MASK), VERR_UNSUPPORTED_ALIGNMENT);
     3707    VMSTATE enmVmState = VMR3GetState(pVM);
     3708    AssertLogRelMsgReturn(   enmVmState == VMSTATE_CREATING
     3709                          || enmVmState == VMSTATE_LOADING,
     3710                          ("enmVmState=%d (%s)\n", enmVmState, VMR3GetStateName(enmVmState)),
     3711                          VERR_VM_INVALID_VM_STATE);
     3712
     3713    int rc = pgmLock(pVM);
     3714    AssertRCReturn(rc, rc);
     3715
     3716    PPGMREGMMIORANGE pFirstMmio = pgmR3PhysMMIOExFind(pVM, pDevIns, iSubDev, iRegion);
     3717    if (pFirstMmio)
     3718    {
     3719        Assert(pFirstMmio->fFlags & PGMREGMMIORANGE_F_FIRST_CHUNK);
     3720        if (!(pFirstMmio->fFlags & PGMREGMMIORANGE_F_MAPPED))
     3721        {
     3722            /*
     3723             * NOTE! Current implementation does not support multiple ranges.
     3724             *       Implement when there is a real world need and thus a testcase.
     3725             */
     3726            AssertLogRelMsgStmt(pFirstMmio->fFlags & PGMREGMMIORANGE_F_LAST_CHUNK,
     3727                                ("%s: %#x\n", pFirstMmio->RamRange.pszDesc, pFirstMmio->fFlags),
     3728                                rc = VERR_NOT_SUPPORTED);
     3729            if (RT_SUCCESS(rc))
     3730            {
     3731                /*
     3732                 * Make the change.
     3733                 */
     3734                Log(("PGMR3PhysMMIOExReduce: %s changes from %RGp bytes (%RGp) to %RGp bytes.\n",
     3735                     pFirstMmio->RamRange.pszDesc, pFirstMmio->RamRange.cb, pFirstMmio->cbReal, cbRegion));
     3736
     3737                AssertLogRelMsgStmt(cbRegion <= pFirstMmio->cbReal,
     3738                                    ("%s: cbRegion=%#RGp cbReal=%#RGp\n", pFirstMmio->RamRange.pszDesc, cbRegion, pFirstMmio->cbReal),
     3739                                    rc = VERR_OUT_OF_RANGE);
     3740                if (RT_SUCCESS(rc))
     3741                {
     3742                    pFirstMmio->RamRange.cb = cbRegion;
     3743                }
     3744            }
     3745        }
     3746        else
     3747            rc = VERR_WRONG_ORDER;
     3748    }
     3749    else
     3750        rc = VERR_NOT_FOUND;
     3751
     3752    pgmUnlock(pVM);
     3753    return rc;
    36763754}
    36773755
Note: See TracChangeset for help on using the changeset viewer.

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