VirtualBox

Changeset 81541 in vbox


Ignore:
Timestamp:
Oct 25, 2019 1:30:49 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134274
Message:

DevOHCI: Bumped saved state version and kicked out the dummy end-of-frame timer. bugref:9218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/USB/DevOHCI.cpp

    r81536 r81541  
    113113*********************************************************************************************************************************/
    114114/** The current saved state version. */
    115 #define OHCI_SAVED_STATE_VERSION            5   /* Introduced post-4.3. */
    116 /** The saved state with support of up to 8 ports. */
    117 #define OHCI_SAVED_STATE_VERSION_8PORTS     4   /* Introduced in 3.1 or so. */
     115#define OHCI_SAVED_STATE_VERSION                OHCI_SAVED_STATE_VERSION_NO_EOF_TIMER
     116/** The current saved state version.
     117 * @since 6.1.0beta3/rc1  */
     118#define OHCI_SAVED_STATE_VERSION_NO_EOF_TIMER   6
     119/** The current saved with the start-of-frame timer.
     120 * @since 4.3.x  */
     121#define OHCI_SAVED_STATE_VERSION_EOF_TIMER      5
     122/** The saved state with support of up to 8 ports.
     123 * @since 3.1 or so  */
     124#define OHCI_SAVED_STATE_VERSION_8PORTS         4
    118125
    119126
     
    269276typedef struct OHCI
    270277{
    271     /** The End-Of-Frame timer. */
    272     TMTIMERHANDLE       hEndOfFrameTimer;
    273 
    274278    /** Start of current frame. */
    275279    uint64_t            SofTime;
     
    332336    /** @} */
    333337
     338    /** This member and all the following are not part of saved state. */
     339    uint64_t            SavedStateEnd;
     340
    334341    /** The number of virtual time ticks per frame. */
    335342    uint64_t            cTicksPerFrame;
     
    345352    /** Profiling ohciR3FrameBoundaryTimer. */
    346353    STAMPROFILE         StatTimer;
    347 
    348     /** This member and all the following are not part of saved state. */
    349     uint64_t            SavedStateEnd;
    350354
    351355    /** VM timer frequency used for frame timer calculations. */
     
    423427    /** Pointer to state load data. */
    424428    R3PTRTYPE(POHCILOAD) pLoad;
     429    /** The restored periodic frame rate. */
     430    uint32_t             uRestoredPeriodicFrameRate;
    425431} OHCIR3;
    426432/** Pointer to ring-3 OHCI state. */
     
    44914497            case OHCI_USB_OPERATIONAL:
    44924498                LogRel(("OHCI: USB Operational\n"));
    4493                 ohciR3BusStart(pDevIns, pThis,  pThisCC);
     4499                ohciR3BusStart(pDevIns, pThis, pThisCC);
    44944500                break;
    44954501            case OHCI_USB_SUSPEND:
     
    55955601        }
    55965602    }
    5597 
    5598     /*
    5599      * If the bus was started set the timer. This is ugly but avoids changing the
    5600      * saved state version for now so we can backport the changes to other branches.
    5601      */
    5602     /** @todo Do it properly for 4.4 by changing the saved state. */
    5603     if (VUSBIRhGetPeriodicFrameRate(pThisCC->RootHub.pIRhConn) != 0)
    5604     {
    5605         /* Calculate a new timer expiration so this saved state works with older releases. */
    5606         uint64_t u64Expire = PDMDevHlpTMTimeVirtGet(pDevIns) + pThis->cTicksPerFrame;
    5607 
    5608         LogFlowFunc(("Bus is active, setting timer to %llu\n", u64Expire));
    5609         int rc = PDMDevHlpTimerSet(pDevIns, pThis->hEndOfFrameTimer, u64Expire);
    5610         AssertRC(rc);
    5611     }
    5612 
    56135603    PDMDevHlpCritSectLeave(pDevIns, pDevIns->pCritSectRoR3);
    56145604
     
    56355625static DECLCALLBACK(int) ohciR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    56365626{
    5637     POHCI           pThis = PDMINS_2_DATA(pDevIns, POHCI);
    5638     PCPDMDEVHLPR3   pHlp  = pDevIns->pHlpR3;
    5639     LogFlow(("ohciR3SaveExec: \n"));
    5640 
    5641     int rc = pHlp->pfnSSMPutStructEx(pSSM, pThis, sizeof(*pThis), 0 /*fFlags*/, &g_aOhciFields[0], NULL);
    5642     if (RT_SUCCESS(rc))
    5643         rc = PDMDevHlpTimerSave(pDevIns, pThis->hEndOfFrameTimer, pSSM);
    5644     return rc;
     5627    POHCI   pThis   = PDMINS_2_DATA(pDevIns, POHCI);
     5628    POHCICC pThisCC = PDMINS_2_DATA_CC(pDevIns, POHCICC);
     5629    LogFlow(("ohciR3SaveExec:\n"));
     5630
     5631    int rc = pDevIns->pHlpR3->pfnSSMPutStructEx(pSSM, pThis, sizeof(*pThis), 0 /*fFlags*/, &g_aOhciFields[0], NULL);
     5632    AssertRCReturn(rc, rc);
     5633
     5634    /* Save the periodic frame rate so we can we can tell if the bus was started or not when restoring. */
     5635    return pDevIns->pHlpR3->pfnSSMPutU32(pSSM, VUSBIRhGetPeriodicFrameRate(pThisCC->RootHub.pIRhConn));
    56455636}
    56465637
     
    56645655     */
    56655656    POHCIROOTHUB pRh = &pThis->RootHub;
    5666     OHCIROOTHUB  Rh = *pRh;
     5657    OHCIROOTHUB  Rh  = *pRh;
    56675658    for (unsigned i = 0; i < RT_ELEMENTS(pRh->aPorts); i++)
    56685659    {
     
    57535744static DECLCALLBACK(int) ohciR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
    57545745{
    5755     POHCI           pThis = PDMINS_2_DATA(pDevIns, POHCI);
    5756     PCPDMDEVHLPR3   pHlp  = pDevIns->pHlpR3;
     5746    POHCI           pThis   = PDMINS_2_DATA(pDevIns, POHCI);
     5747    POHCICC         pThisCC = PDMINS_2_DATA_CC(pDevIns, POHCICC);
     5748    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
    57575749    int             rc;
    57585750    LogFlow(("ohciR3LoadExec:\n"));
     5751
    57595752    Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
    57605753
    5761     if (uVersion == OHCI_SAVED_STATE_VERSION)
    5762     {
     5754    if (uVersion >= OHCI_SAVED_STATE_VERSION_EOF_TIMER)
    57635755        rc = pHlp->pfnSSMGetStructEx(pSSM, pThis, sizeof(*pThis), 0 /*fFlags*/, &g_aOhciFields[0], NULL);
    5764         if (RT_FAILURE(rc))
    5765             return rc;
    5766     }
    57675756    else if (uVersion == OHCI_SAVED_STATE_VERSION_8PORTS)
    5768     {
    57695757        rc = pHlp->pfnSSMGetStructEx(pSSM, pThis, sizeof(*pThis), 0 /*fFlags*/, &g_aOhciFields8Ports[0], NULL);
    5770         if (RT_FAILURE(rc))
    5771             return rc;
    5772     }
    57735758    else
    57745759        AssertMsgFailedReturn(("%d\n", uVersion), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);
    5775 
    5776     /*
    5777      * Finally restore the timer.
    5778      */
    5779     return PDMDevHlpTimerLoad(pDevIns, pThis->hEndOfFrameTimer, pSSM);
     5760    AssertRCReturn(rc, rc);
     5761
     5762    /*
     5763     * Get the frame rate / started indicator.
     5764     *
     5765     * For older versions there is a timer saved here.  We'll skip it and deduce
     5766     * the periodic frame rate from the host controller functional state.
     5767     */
     5768    if (uVersion > OHCI_SAVED_STATE_VERSION_EOF_TIMER)
     5769    {
     5770        rc = pHlp->pfnSSMGetU32(pSSM, &pThisCC->uRestoredPeriodicFrameRate);
     5771        AssertRCReturn(rc, rc);
     5772    }
     5773    else
     5774    {
     5775        rc = pHlp->pfnSSMSkipToEndOfUnit(pSSM);
     5776        AssertRCReturn(rc, rc);
     5777
     5778        uint32_t fHcfs = pThis->ctl & OHCI_CTL_HCFS;
     5779        switch (fHcfs)
     5780        {
     5781            case OHCI_USB_OPERATIONAL:
     5782            case OHCI_USB_RESUME:
     5783                pThisCC->uRestoredPeriodicFrameRate = OHCI_DEFAULT_TIMER_FREQ;
     5784                break;
     5785            default:
     5786                pThisCC->uRestoredPeriodicFrameRate = 0;
     5787                break;
     5788        }
     5789    }
     5790
     5791    /** @todo could we restore the frame rate here instead of in ohciR3Resume? */
     5792    return VINF_SUCCESS;
    57805793}
    57815794
     
    58695882static DECLCALLBACK(void) ohciR3Resume(PPDMDEVINS pDevIns)
    58705883{
    5871     POHCI   pThis   = PDMINS_2_DATA(pDevIns, POHCI);
    58725884    POHCICC pThisCC = PDMINS_2_DATA_CC(pDevIns, POHCICC);
    58735885    LogFlowFunc(("\n"));
    58745886
    5875     /* Restart the frame thread if the timer is active. */
    5876     if (PDMDevHlpTimerIsActive(pDevIns, pThis->hEndOfFrameTimer))
    5877     {
    5878         int rc = PDMDevHlpTimerStop(pDevIns, pThis->hEndOfFrameTimer);
    5879         AssertRC(rc);
    5880 
    5881         LogFlowFunc(("Bus was active, enable periodic frame processing\n"));
    5882         rc = pThisCC->RootHub.pIRhConn->pfnSetPeriodicFrameProcessing(pThisCC->RootHub.pIRhConn, OHCI_DEFAULT_TIMER_FREQ);
     5887    /* Restart the frame thread if it was active when the loaded state was saved. */
     5888    uint32_t uRestoredPeriodicFR = pThisCC->uRestoredPeriodicFrameRate;
     5889    pThisCC->uRestoredPeriodicFrameRate = 0;
     5890    if (uRestoredPeriodicFR)
     5891    {
     5892        LogFlowFunc(("Bus was active, enable periodic frame processing (rate: %u)\n", uRestoredPeriodicFR));
     5893        int rc = pThisCC->RootHub.pIRhConn->pfnSetPeriodicFrameProcessing(pThisCC->RootHub.pIRhConn, uRestoredPeriodicFR);
    58835894        AssertRC(rc);
    58845895    }
     
    60856096
    60866097    /*
    6087      * Create the end-of-frame timer.
    6088      */
    6089     rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ohciR3FrameBoundaryTimer, pThis,
    6090                               TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "USB Frame Timer", &pThis->hEndOfFrameTimer);
    6091     AssertRCReturn(rc, rc);
    6092 
    6093     /*
    60946098     * Register the saved state data unit.
    60956099     */
     
    61376141
    61386142    /*
    6139      * Calculate the timer intervals.
    6140      * This assumes that the VM timer doesn't change frequency during the run.
    6141      */
    6142     pThis->u64TimerHz = PDMDevHlpTimerGetFreq(pDevIns, pThis->hEndOfFrameTimer);
     6143     * Take down the virtual clock frequence for use in ohciR3FrameRateChanged().
     6144     * (Used to be a timer, thus the name.)
     6145     */
     6146    pThis->u64TimerHz = PDMDevHlpTMTimeVirtGetFreq(pDevIns);
    61436147
    61446148    /*
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