VirtualBox

Changeset 24087 in vbox for trunk/src/VBox/Devices/PC


Ignore:
Timestamp:
Oct 26, 2009 3:48:03 PM (15 years ago)
Author:
vboxsync
Message:

DevPit-i8254: Save and verify config. Saved state version changed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/DevPit-i8254.cpp

    r24085 r24087  
    6969#define RW_STATE_WORD1 4
    7070
    71 /** The version of the saved state. */
    72 #define PIT_SAVED_STATE_VERSION 2
     71/** The current saved state version. */
     72#define PIT_SAVED_STATE_VERSION             3
     73/** The saved state version used by VirtualBox 3.0 and earlier.
     74 * This did not include the config part. */
     75#define PIT_SAVED_STATE_VERSION_VBOX_30     2
    7376
    7477/** @def FAKE_REFRESH_CLOCK
     
    140143    uint32_t                Alignment1;
    141144#endif
     145    /** Config: I/O port base. */
     146    RTIOPORT                IOPortBaseCfg;
     147    /** Config: Speaker enabled. */
     148    bool                    fSpeakerCfg;
     149    bool                    afAlignment0[HC_ARCH_BITS == 32 ? 1 : 5];
    142150    /** Pointer to the device instance. */
    143151    PPDMDEVINSR3            pDevIns;
    144 #if HC_ARCH_BITS == 32
    145     uint32_t                Alignment0;
    146 #endif
    147152    /** Number of IRQs that's been raised. */
    148153    STAMCOUNTER             StatPITIrq;
     
    710715
    711716/**
    712  * Saves a state of the programmable interval timer device.
    713  *
    714  * @returns VBox status code.
    715  * @param   pDevIns     The device instance.
    716  * @param   pSSMHandle  The handle to save the state to.
    717  */
    718 static DECLCALLBACK(int) pitSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
     717 * @copydoc FNSSMDEVLIVEEXEC
     718 */
     719static DECLCALLBACK(int) pitLiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
     720{
     721    PITState *pThis = PDMINS_2_DATA(pDevIns, PITState *);
     722    SSMR3PutIOPort(pSSM, pThis->IOPortBaseCfg);
     723    SSMR3PutU8(    pSSM, pThis->channels[0].irq);
     724    SSMR3PutBool(  pSSM, pThis->fSpeakerCfg);
     725    return VINF_SSM_DONT_CALL_AGAIN;
     726}
     727
     728
     729/**
     730 * @copydoc FNSSMDEVSAVEEXEC
     731 */
     732static DECLCALLBACK(int) pitSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    719733{
    720734    PITState *pThis = PDMINS_2_DATA(pDevIns, PITState *);
    721735    unsigned i;
    722736
     737    /* The config. */
     738    pitLiveExec(pDevIns, pSSM, SSM_PASS_FINAL);
     739
     740    /* The state. */
    723741    for (i = 0; i < RT_ELEMENTS(pThis->channels); i++)
    724742    {
    725743        PITChannelState *s = &pThis->channels[i];
    726         SSMR3PutU32(pSSMHandle, s->count);
    727         SSMR3PutU16(pSSMHandle, s->latched_count);
    728         SSMR3PutU8(pSSMHandle, s->count_latched);
    729         SSMR3PutU8(pSSMHandle, s->status_latched);
    730         SSMR3PutU8(pSSMHandle, s->status);
    731         SSMR3PutU8(pSSMHandle, s->read_state);
    732         SSMR3PutU8(pSSMHandle, s->write_state);
    733         SSMR3PutU8(pSSMHandle, s->write_latch);
    734         SSMR3PutU8(pSSMHandle, s->rw_mode);
    735         SSMR3PutU8(pSSMHandle, s->mode);
    736         SSMR3PutU8(pSSMHandle, s->bcd);
    737         SSMR3PutU8(pSSMHandle, s->gate);
    738         SSMR3PutU64(pSSMHandle, s->count_load_time);
    739         SSMR3PutU64(pSSMHandle, s->u64NextTS);
    740         SSMR3PutU64(pSSMHandle, s->u64ReloadTS);
    741         SSMR3PutS64(pSSMHandle, s->next_transition_time);
     744        SSMR3PutU32(pSSM, s->count);
     745        SSMR3PutU16(pSSM, s->latched_count);
     746        SSMR3PutU8(pSSM, s->count_latched);
     747        SSMR3PutU8(pSSM, s->status_latched);
     748        SSMR3PutU8(pSSM, s->status);
     749        SSMR3PutU8(pSSM, s->read_state);
     750        SSMR3PutU8(pSSM, s->write_state);
     751        SSMR3PutU8(pSSM, s->write_latch);
     752        SSMR3PutU8(pSSM, s->rw_mode);
     753        SSMR3PutU8(pSSM, s->mode);
     754        SSMR3PutU8(pSSM, s->bcd);
     755        SSMR3PutU8(pSSM, s->gate);
     756        SSMR3PutU64(pSSM, s->count_load_time);
     757        SSMR3PutU64(pSSM, s->u64NextTS);
     758        SSMR3PutU64(pSSM, s->u64ReloadTS);
     759        SSMR3PutS64(pSSM, s->next_transition_time);
    742760        if (s->CTX_SUFF(pTimer))
    743             TMR3TimerSave(s->CTX_SUFF(pTimer), pSSMHandle);
    744     }
    745 
    746     SSMR3PutS32(pSSMHandle, pThis->speaker_data_on);
     761            TMR3TimerSave(s->CTX_SUFF(pTimer), pSSM);
     762    }
     763
     764    SSMR3PutS32(pSSM, pThis->speaker_data_on);
    747765#ifdef FAKE_REFRESH_CLOCK
    748     return SSMR3PutS32(pSSMHandle, pThis->dummy_refresh_clock);
     766    return SSMR3PutS32(pSSM, pThis->dummy_refresh_clock);
    749767#else
    750     return SSMR3PutS32(pSSMHandle, 0);
     768    return SSMR3PutS32(pSSM, 0);
    751769#endif
    752770}
     
    754772
    755773/**
    756  * Loads a saved programmable interval timer device state.
    757  *
    758  * @returns VBox status code.
    759  * @param   pDevIns     The device instance.
    760  * @param   pSSMHandle  The handle to the saved state.
    761  * @param   uVersion    The data unit version number.
    762  * @param   uPass       The data pass.
    763  */
    764 static DECLCALLBACK(int) pitLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, uint32_t uVersion, uint32_t uPass)
    765 {
    766     PITState *pThis = PDMINS_2_DATA(pDevIns, PITState *);
    767 
    768     if (uVersion != PIT_SAVED_STATE_VERSION)
     774 * @copydoc FNSSMDEVLOADEXEC
     775 */
     776static DECLCALLBACK(int) pitLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
     777{
     778    PITState   *pThis = PDMINS_2_DATA(pDevIns, PITState *);
     779    int         rc;
     780
     781    if (    uVersion != PIT_SAVED_STATE_VERSION
     782        &&  uVersion != PIT_SAVED_STATE_VERSION_VBOX_30)
    769783        return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
    770     Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
    771 
     784
     785    /* The config. */
     786    if (uVersion > PIT_SAVED_STATE_VERSION_VBOX_30)
     787    {
     788        RTIOPORT IOPortBaseCfg;
     789        rc = SSMR3GetIOPort(pSSM, &IOPortBaseCfg); AssertRCReturn(rc, rc);
     790        if (IOPortBaseCfg != pThis->IOPortBaseCfg)
     791        {
     792            LogRel(("PIT: Config mismatch - IOPortBaseCfg: saved=%RTiop config=%RTiop\n", IOPortBaseCfg, pThis->IOPortBaseCfg));
     793            return VERR_SSM_LOAD_CONFIG_MISMATCH;
     794        }
     795
     796        uint8_t u8Irq;
     797        rc = SSMR3GetU8(pSSM, &u8Irq); AssertRCReturn(rc, rc);
     798        if (u8Irq != pThis->channels[0].irq)
     799        {
     800            LogRel(("PIT: Config mismatch - u8Irq: saved=%#x config=%#x\n", u8Irq, pThis->channels[0].irq));
     801            return VERR_SSM_LOAD_CONFIG_MISMATCH;
     802        }
     803
     804        bool fSpeakerCfg;
     805        rc = SSMR3GetBool(pSSM, &fSpeakerCfg); AssertRCReturn(rc, rc);
     806        if (fSpeakerCfg != pThis->fSpeakerCfg)
     807        {
     808            LogRel(("PIT: Config mismatch - fSpeakerCfg: saved=%RTbool config=%RTbool\n", fSpeakerCfg, pThis->fSpeakerCfg));
     809            return VERR_SSM_LOAD_CONFIG_MISMATCH;
     810        }
     811    }
     812
     813    if (uPass != SSM_PASS_FINAL)
     814        return VINF_SUCCESS;
     815
     816    /* The state. */
    772817    for (unsigned i = 0; i < RT_ELEMENTS(pThis->channels); i++)
    773818    {
    774819        PITChannelState *s = &pThis->channels[i];
    775         SSMR3GetU32(pSSMHandle, &s->count);
    776         SSMR3GetU16(pSSMHandle, &s->latched_count);
    777         SSMR3GetU8(pSSMHandle, &s->count_latched);
    778         SSMR3GetU8(pSSMHandle, &s->status_latched);
    779         SSMR3GetU8(pSSMHandle, &s->status);
    780         SSMR3GetU8(pSSMHandle, &s->read_state);
    781         SSMR3GetU8(pSSMHandle, &s->write_state);
    782         SSMR3GetU8(pSSMHandle, &s->write_latch);
    783         SSMR3GetU8(pSSMHandle, &s->rw_mode);
    784         SSMR3GetU8(pSSMHandle, &s->mode);
    785         SSMR3GetU8(pSSMHandle, &s->bcd);
    786         SSMR3GetU8(pSSMHandle, &s->gate);
    787         SSMR3GetU64(pSSMHandle, &s->count_load_time);
    788         SSMR3GetU64(pSSMHandle, &s->u64NextTS);
    789         SSMR3GetU64(pSSMHandle, &s->u64ReloadTS);
    790         SSMR3GetS64(pSSMHandle, &s->next_transition_time);
     820        SSMR3GetU32(pSSM, &s->count);
     821        SSMR3GetU16(pSSM, &s->latched_count);
     822        SSMR3GetU8(pSSM, &s->count_latched);
     823        SSMR3GetU8(pSSM, &s->status_latched);
     824        SSMR3GetU8(pSSM, &s->status);
     825        SSMR3GetU8(pSSM, &s->read_state);
     826        SSMR3GetU8(pSSM, &s->write_state);
     827        SSMR3GetU8(pSSM, &s->write_latch);
     828        SSMR3GetU8(pSSM, &s->rw_mode);
     829        SSMR3GetU8(pSSM, &s->mode);
     830        SSMR3GetU8(pSSM, &s->bcd);
     831        SSMR3GetU8(pSSM, &s->gate);
     832        SSMR3GetU64(pSSM, &s->count_load_time);
     833        SSMR3GetU64(pSSM, &s->u64NextTS);
     834        SSMR3GetU64(pSSM, &s->u64ReloadTS);
     835        SSMR3GetS64(pSSM, &s->next_transition_time);
    791836        if (s->CTX_SUFF(pTimer))
    792837        {
    793             TMR3TimerLoad(s->CTX_SUFF(pTimer), pSSMHandle);
     838            TMR3TimerLoad(s->CTX_SUFF(pTimer), pSSM);
    794839            LogRel(("PIT: mode=%d count=%#x (%u) - %d.%02d Hz (ch=%d) (restore)\n",
    795840                    s->mode, s->count, s->count, PIT_FREQ / s->count, (PIT_FREQ * 100 / s->count) % 100, i));
     
    798843    }
    799844
    800     SSMR3GetS32(pSSMHandle, &pThis->speaker_data_on);
     845    SSMR3GetS32(pSSM, &pThis->speaker_data_on);
    801846#ifdef FAKE_REFRESH_CLOCK
    802     return SSMR3GetS32(pSSMHandle, &pThis->dummy_refresh_clock);
     847    return SSMR3GetS32(pSSM, &pThis->dummy_refresh_clock);
    803848#else
    804849    int32_t u32Dummy;
    805     return SSMR3GetS32(pSSMHandle, &u32Dummy);
     850    return SSMR3GetS32(pSSM, &u32Dummy);
    806851#endif
    807852}
     
    9861031                                N_("Configuration error: failed to read R0Enabled as boolean"));
    9871032
    988     pThis->pDevIns = pDevIns;
     1033    pThis->pDevIns         = pDevIns;
     1034    pThis->IOPortBaseCfg   = u16Base;
     1035    pThis->fSpeakerCfg     = fSpeaker;
    9891036    pThis->channels[0].irq = u8Irq;
    9901037    for (i = 0; i < RT_ELEMENTS(pThis->channels); i++)
     
    10351082    }
    10361083
    1037     rc = PDMDevHlpSSMRegister(pDevIns, PIT_SAVED_STATE_VERSION, sizeof(*pThis), pitSaveExec, pitLoadExec);
     1084    rc = PDMDevHlpSSMRegister3(pDevIns, PIT_SAVED_STATE_VERSION, sizeof(*pThis), pitLiveExec, pitSaveExec, pitLoadExec);
    10381085    if (RT_FAILURE(rc))
    10391086        return rc;
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