VirtualBox

Ignore:
Timestamp:
Nov 16, 2019 4:59:23 PM (5 years ago)
Author:
vboxsync
Message:

DevPit-i8254: Do CFGM, SSM and critsects thru the device helpers. bugref:9218

File:
1 edited

Legend:

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

    r81591 r81898  
    105105 * Acquires the PIT lock or returns.
    106106 */
    107 #define DEVPIT_LOCK_RETURN(a_pThis, a_rcBusy)  \
     107#define DEVPIT_LOCK_RETURN(a_pDevIns, a_pThis, a_rcBusy)  \
    108108    do { \
    109         int rcLock = PDMCritSectEnter(&(a_pThis)->CritSect, (a_rcBusy)); \
     109        int rcLock = PDMDevHlpCritSectEnter((a_pDevIns), &(a_pThis)->CritSect, (a_rcBusy)); \
    110110        if (rcLock != VINF_SUCCESS) \
    111111            return rcLock; \
     
    115115 * Releases the PIT lock.
    116116 */
    117 #define DEVPIT_UNLOCK(a_pThis) \
    118     do { PDMCritSectLeave(&(a_pThis)->CritSect); } while (0)
     117#define DEVPIT_UNLOCK(a_pDevIns, a_pThis) \
     118    do { PDMDevHlpCritSectLeave((a_pDevIns), &(a_pThis)->CritSect); } while (0)
    119119
    120120
     
    122122 * Acquires the TM lock and PIT lock, returns on failure.
    123123 */
    124 #define DEVPIT_LOCK_BOTH_RETURN(a_pThis, a_rcBusy)  \
     124#define DEVPIT_LOCK_BOTH_RETURN(a_pDevIns, a_pThis, a_rcBusy)  \
    125125    do { \
    126126        int rcLock = TMTimerLock((a_pThis)->channels[0].CTX_SUFF(pTimer), (a_rcBusy)); \
    127127        if (rcLock != VINF_SUCCESS) \
    128128            return rcLock; \
    129         rcLock = PDMCritSectEnter(&(a_pThis)->CritSect, (a_rcBusy)); \
     129        rcLock = PDMDevHlpCritSectEnter((a_pDevIns), &(a_pThis)->CritSect, (a_rcBusy)); \
    130130        if (rcLock != VINF_SUCCESS) \
    131131        { \
     
    139139 * Acquires the TM lock and PIT lock, ignores failures.
    140140 */
    141 # define DEVPIT_R3_LOCK_BOTH(a_pThis)  \
     141# define DEVPIT_R3_LOCK_BOTH(a_pDevIns, a_pThis)  \
    142142    do { \
    143143        TMTimerLock((a_pThis)->channels[0].CTX_SUFF(pTimer), VERR_IGNORED); \
    144         PDMCritSectEnter(&(a_pThis)->CritSect, VERR_IGNORED); \
     144        PDMDevHlpCritSectEnter((a_pDevIns), &(a_pThis)->CritSect, VERR_IGNORED); \
    145145    } while (0)
    146146#endif /* IN_RING3 */
     
    149149 * Releases the PIT lock and TM lock.
    150150 */
    151 #define DEVPIT_UNLOCK_BOTH(a_pThis) \
     151#define DEVPIT_UNLOCK_BOTH(a_pDevIns, a_pThis) \
    152152    do { \
    153         PDMCritSectLeave(&(a_pThis)->CritSect); \
     153        PDMDevHlpCritSectLeave((a_pDevIns), &(a_pThis)->CritSect); \
    154154        TMTimerUnlock((a_pThis)->channels[0].CTX_SUFF(pTimer)); \
    155155    } while (0)
     
    665665    int ret;
    666666
    667     DEVPIT_LOCK_RETURN(pThis, VINF_IOM_R3_IOPORT_READ);
     667    DEVPIT_LOCK_RETURN(pDevIns, pThis, VINF_IOM_R3_IOPORT_READ);
    668668    if (pChan->status_latched)
    669669    {
    670670        pChan->status_latched = 0;
    671671        ret = pChan->status;
    672         DEVPIT_UNLOCK(pThis);
     672        DEVPIT_UNLOCK(pDevIns, pThis);
    673673    }
    674674    else if (pChan->count_latched)
     
    690690                break;
    691691        }
    692         DEVPIT_UNLOCK(pThis);
     692        DEVPIT_UNLOCK(pDevIns, pThis);
    693693    }
    694694    else
    695695    {
    696         DEVPIT_UNLOCK(pThis);
    697         DEVPIT_LOCK_BOTH_RETURN(pThis, VINF_IOM_R3_IOPORT_READ);
     696        DEVPIT_UNLOCK(pDevIns, pThis);
     697        DEVPIT_LOCK_BOTH_RETURN(pDevIns, pThis, VINF_IOM_R3_IOPORT_READ);
    698698        int count;
    699699        switch (pChan->read_state)
     
    719719                break;
    720720        }
    721         DEVPIT_UNLOCK_BOTH(pThis);
     721        DEVPIT_UNLOCK_BOTH(pDevIns, pThis);
    722722    }
    723723
     
    766766        {
    767767            /* read-back command */
    768             DEVPIT_LOCK_BOTH_RETURN(pThis, VINF_IOM_R3_IOPORT_WRITE);
     768            DEVPIT_LOCK_BOTH_RETURN(pDevIns, pThis, VINF_IOM_R3_IOPORT_WRITE);
    769769            for (channel = 0; channel < RT_ELEMENTS(pThis->channels); channel++)
    770770            {
     
    787787                }
    788788            }
    789             DEVPIT_UNLOCK_BOTH(pThis);
     789            DEVPIT_UNLOCK_BOTH(pDevIns, pThis);
    790790        }
    791791        else
     
    795795            if (access == 0)
    796796            {
    797                 DEVPIT_LOCK_BOTH_RETURN(pThis, VINF_IOM_R3_IOPORT_WRITE);
     797                DEVPIT_LOCK_BOTH_RETURN(pDevIns, pThis, VINF_IOM_R3_IOPORT_WRITE);
    798798                pit_latch_count(pChan);
    799                 DEVPIT_UNLOCK_BOTH(pThis);
     799                DEVPIT_UNLOCK_BOTH(pDevIns, pThis);
    800800            }
    801801            else
    802802            {
    803                 DEVPIT_LOCK_RETURN(pThis, VINF_IOM_R3_IOPORT_WRITE);
     803                DEVPIT_LOCK_RETURN(pDevIns, pThis, VINF_IOM_R3_IOPORT_WRITE);
    804804                pChan->rw_mode = access;
    805805                pChan->read_state = access;
     
    809809                pChan->bcd = u32 & 1;
    810810                /* XXX: update irq timer ? */
    811                 DEVPIT_UNLOCK(pThis);
     811                DEVPIT_UNLOCK(pDevIns, pThis);
    812812            }
    813813        }
     
    825825        RT_UNTRUSTED_VALIDATED_FENCE(); /* paranoia */
    826826        PPITCHANNEL pChan = &pThis->channels[uPort];
    827         DEVPIT_LOCK_BOTH_RETURN(pThis, VINF_IOM_R3_IOPORT_WRITE);
     827        DEVPIT_LOCK_BOTH_RETURN(pDevIns, pThis, VINF_IOM_R3_IOPORT_WRITE);
    828828        switch (pChan->write_state)
    829829        {
     
    844844                break;
    845845        }
    846         DEVPIT_UNLOCK_BOTH(pThis);
     846        DEVPIT_UNLOCK_BOTH(pDevIns, pThis);
    847847#endif /* !IN_RING3 */
    848848    }
     
    856856PDMBOTHCBDECL(int) pitIOPortSpeakerRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t *pu32, unsigned cb)
    857857{
    858     RT_NOREF2(pvUser, uPort);
     858    RT_NOREF(pvUser, uPort);
    859859    if (cb == 1)
    860860    {
    861861        PPITSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
    862         DEVPIT_LOCK_BOTH_RETURN(pThis, VINF_IOM_R3_IOPORT_READ);
     862        DEVPIT_LOCK_BOTH_RETURN(pDevIns, pThis, VINF_IOM_R3_IOPORT_READ);
    863863
    864864        const uint64_t u64Now = TMTimerGet(pThis->channels[0].CTX_SUFF(pTimer));
     
    882882        const int fTimer2GateStatus = pit_get_gate(pThis, 2);
    883883
    884         DEVPIT_UNLOCK_BOTH(pThis);
     884        DEVPIT_UNLOCK_BOTH(pDevIns, pThis);
    885885
    886886        *pu32 = fTimer2GateStatus
     
    902902PDMBOTHCBDECL(int) pitIOPortSpeakerWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t u32, unsigned cb)
    903903{
    904     RT_NOREF2(pvUser, uPort);
     904    RT_NOREF(pvUser, uPort);
    905905    if (cb == 1)
    906906    {
    907907        PPITSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
    908         DEVPIT_LOCK_BOTH_RETURN(pThis, VERR_IGNORED);
     908        DEVPIT_LOCK_BOTH_RETURN(pDevIns, pThis, VERR_IGNORED);
    909909
    910910        pThis->speaker_data_on = (u32 >> 1) & 1;
     
    914914         * abstract the details, and if necessary create a thread to minimize
    915915         * impact on VM execution. */
    916 #ifdef RT_OS_LINUX
     916# ifdef RT_OS_LINUX
    917917        if (pThis->enmSpeakerEmu != PIT_SPEAKER_EMU_NONE)
    918918        {
     
    992992            }
    993993        }
    994 #endif
    995 
    996         DEVPIT_UNLOCK_BOTH(pThis);
     994# endif /* RT_OS_LINUX */
     995
     996        DEVPIT_UNLOCK_BOTH(pDevIns, pThis);
    997997    }
    998998    Log(("pitIOPortSpeakerWrite: uPort=%#x cb=%x u32=%#x\n", uPort, cb, u32));
     
    10081008static DECLCALLBACK(int) pitLiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
    10091009{
    1010     RT_NOREF1(uPass);
    1011     PPITSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
    1012     SSMR3PutIOPort(pSSM, pThis->IOPortBaseCfg);
    1013     SSMR3PutU8(    pSSM, pThis->channels[0].irq);
    1014     SSMR3PutBool(  pSSM, pThis->fSpeakerCfg);
     1010    PPITSTATE     pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
     1011    PCPDMDEVHLPR3 pHlp  = pDevIns->pHlpR3;
     1012    RT_NOREF(uPass);
     1013    pHlp->pfnSSMPutIOPort(pSSM, pThis->IOPortBaseCfg);
     1014    pHlp->pfnSSMPutU8(    pSSM, pThis->channels[0].irq);
     1015    pHlp->pfnSSMPutBool(  pSSM, pThis->fSpeakerCfg);
    10151016    return VINF_SSM_DONT_CALL_AGAIN;
    10161017}
     
    10221023static DECLCALLBACK(int) pitSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    10231024{
    1024     PPITSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
    1025     PDMCritSectEnter(&pThis->CritSect, VERR_IGNORED);
     1025    PPITSTATE     pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
     1026    PCPDMDEVHLPR3 pHlp  = pDevIns->pHlpR3;
     1027    PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
    10261028
    10271029    /* The config. */
     
    10321034    {
    10331035        PPITCHANNEL pChan = &pThis->channels[i];
    1034         SSMR3PutU32(pSSM, pChan->count);
    1035         SSMR3PutU16(pSSM, pChan->latched_count);
    1036         SSMR3PutU8(pSSM, pChan->count_latched);
    1037         SSMR3PutU8(pSSM, pChan->status_latched);
    1038         SSMR3PutU8(pSSM, pChan->status);
    1039         SSMR3PutU8(pSSM, pChan->read_state);
    1040         SSMR3PutU8(pSSM, pChan->write_state);
    1041         SSMR3PutU8(pSSM, pChan->write_latch);
    1042         SSMR3PutU8(pSSM, pChan->rw_mode);
    1043         SSMR3PutU8(pSSM, pChan->mode);
    1044         SSMR3PutU8(pSSM, pChan->bcd);
    1045         SSMR3PutU8(pSSM, pChan->gate);
    1046         SSMR3PutU64(pSSM, pChan->count_load_time);
    1047         SSMR3PutU64(pSSM, pChan->u64NextTS);
    1048         SSMR3PutU64(pSSM, pChan->u64ReloadTS);
    1049         SSMR3PutS64(pSSM, pChan->next_transition_time);
     1036        pHlp->pfnSSMPutU32(pSSM, pChan->count);
     1037        pHlp->pfnSSMPutU16(pSSM, pChan->latched_count);
     1038        pHlp->pfnSSMPutU8(pSSM, pChan->count_latched);
     1039        pHlp->pfnSSMPutU8(pSSM, pChan->status_latched);
     1040        pHlp->pfnSSMPutU8(pSSM, pChan->status);
     1041        pHlp->pfnSSMPutU8(pSSM, pChan->read_state);
     1042        pHlp->pfnSSMPutU8(pSSM, pChan->write_state);
     1043        pHlp->pfnSSMPutU8(pSSM, pChan->write_latch);
     1044        pHlp->pfnSSMPutU8(pSSM, pChan->rw_mode);
     1045        pHlp->pfnSSMPutU8(pSSM, pChan->mode);
     1046        pHlp->pfnSSMPutU8(pSSM, pChan->bcd);
     1047        pHlp->pfnSSMPutU8(pSSM, pChan->gate);
     1048        pHlp->pfnSSMPutU64(pSSM, pChan->count_load_time);
     1049        pHlp->pfnSSMPutU64(pSSM, pChan->u64NextTS);
     1050        pHlp->pfnSSMPutU64(pSSM, pChan->u64ReloadTS);
     1051        pHlp->pfnSSMPutS64(pSSM, pChan->next_transition_time);
    10501052        if (pChan->CTX_SUFF(pTimer))
    10511053            TMR3TimerSave(pChan->CTX_SUFF(pTimer), pSSM);
    10521054    }
    10531055
    1054     SSMR3PutS32(pSSM, pThis->speaker_data_on);
     1056    pHlp->pfnSSMPutS32(pSSM, pThis->speaker_data_on);
    10551057#ifdef FAKE_REFRESH_CLOCK
    1056     SSMR3PutS32(pSSM, pThis->dummy_refresh_clock);
     1058    pHlp->pfnSSMPutS32(pSSM, pThis->dummy_refresh_clock);
    10571059#else
    1058     SSMR3PutS32(pSSM, 0);
     1060    pHlp->pfnSSMPutS32(pSSM, 0);
    10591061#endif
    10601062
    1061     SSMR3PutBool(pSSM, pThis->fDisabledByHpet);
    1062 
    1063     PDMCritSectLeave(&pThis->CritSect);
     1063    pHlp->pfnSSMPutBool(pSSM, pThis->fDisabledByHpet);
     1064
     1065    PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
    10641066    return VINF_SUCCESS;
    10651067}
     
    10711073static DECLCALLBACK(int) pitLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
    10721074{
    1073     PPITSTATE   pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
    1074     int         rc;
     1075    PPITSTATE     pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
     1076    PCPDMDEVHLPR3 pHlp  = pDevIns->pHlpR3;
     1077    int           rc;
    10751078
    10761079    if (    uVersion != PIT_SAVED_STATE_VERSION
     
    10831086    {
    10841087        RTIOPORT IOPortBaseCfg;
    1085         rc = SSMR3GetIOPort(pSSM, &IOPortBaseCfg); AssertRCReturn(rc, rc);
     1088        rc = pHlp->pfnSSMGetIOPort(pSSM, &IOPortBaseCfg); AssertRCReturn(rc, rc);
    10861089        if (IOPortBaseCfg != pThis->IOPortBaseCfg)
    1087             return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - IOPortBaseCfg: saved=%RTiop config=%RTiop"),
     1090            return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - IOPortBaseCfg: saved=%RTiop config=%RTiop"),
    10881091                                    IOPortBaseCfg, pThis->IOPortBaseCfg);
    10891092
    10901093        uint8_t u8Irq;
    1091         rc = SSMR3GetU8(pSSM, &u8Irq); AssertRCReturn(rc, rc);
     1094        rc = pHlp->pfnSSMGetU8(pSSM, &u8Irq); AssertRCReturn(rc, rc);
    10921095        if (u8Irq != pThis->channels[0].irq)
    1093             return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - u8Irq: saved=%#x config=%#x"),
     1096            return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - u8Irq: saved=%#x config=%#x"),
    10941097                                    u8Irq, pThis->channels[0].irq);
    10951098
    10961099        bool fSpeakerCfg;
    1097         rc = SSMR3GetBool(pSSM, &fSpeakerCfg); AssertRCReturn(rc, rc);
     1100        rc = pHlp->pfnSSMGetBool(pSSM, &fSpeakerCfg); AssertRCReturn(rc, rc);
    10981101        if (fSpeakerCfg != pThis->fSpeakerCfg)
    1099             return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fSpeakerCfg: saved=%RTbool config=%RTbool"),
     1102            return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fSpeakerCfg: saved=%RTbool config=%RTbool"),
    11001103                                    fSpeakerCfg, pThis->fSpeakerCfg);
    11011104    }
     
    11081111    {
    11091112        PPITCHANNEL pChan = &pThis->channels[i];
    1110         SSMR3GetU32(pSSM, &pChan->count);
    1111         SSMR3GetU16(pSSM, &pChan->latched_count);
    1112         SSMR3GetU8(pSSM, &pChan->count_latched);
    1113         SSMR3GetU8(pSSM, &pChan->status_latched);
    1114         SSMR3GetU8(pSSM, &pChan->status);
    1115         SSMR3GetU8(pSSM, &pChan->read_state);
    1116         SSMR3GetU8(pSSM, &pChan->write_state);
    1117         SSMR3GetU8(pSSM, &pChan->write_latch);
    1118         SSMR3GetU8(pSSM, &pChan->rw_mode);
    1119         SSMR3GetU8(pSSM, &pChan->mode);
    1120         SSMR3GetU8(pSSM, &pChan->bcd);
    1121         SSMR3GetU8(pSSM, &pChan->gate);
    1122         SSMR3GetU64(pSSM, &pChan->count_load_time);
    1123         SSMR3GetU64(pSSM, &pChan->u64NextTS);
    1124         SSMR3GetU64(pSSM, &pChan->u64ReloadTS);
    1125         SSMR3GetS64(pSSM, &pChan->next_transition_time);
     1113        pHlp->pfnSSMGetU32(pSSM, &pChan->count);
     1114        pHlp->pfnSSMGetU16(pSSM, &pChan->latched_count);
     1115        pHlp->pfnSSMGetU8(pSSM, &pChan->count_latched);
     1116        pHlp->pfnSSMGetU8(pSSM, &pChan->status_latched);
     1117        pHlp->pfnSSMGetU8(pSSM, &pChan->status);
     1118        pHlp->pfnSSMGetU8(pSSM, &pChan->read_state);
     1119        pHlp->pfnSSMGetU8(pSSM, &pChan->write_state);
     1120        pHlp->pfnSSMGetU8(pSSM, &pChan->write_latch);
     1121        pHlp->pfnSSMGetU8(pSSM, &pChan->rw_mode);
     1122        pHlp->pfnSSMGetU8(pSSM, &pChan->mode);
     1123        pHlp->pfnSSMGetU8(pSSM, &pChan->bcd);
     1124        pHlp->pfnSSMGetU8(pSSM, &pChan->gate);
     1125        pHlp->pfnSSMGetU64(pSSM, &pChan->count_load_time);
     1126        pHlp->pfnSSMGetU64(pSSM, &pChan->u64NextTS);
     1127        pHlp->pfnSSMGetU64(pSSM, &pChan->u64ReloadTS);
     1128        pHlp->pfnSSMGetS64(pSSM, &pChan->next_transition_time);
    11261129        if (pChan->CTX_SUFF(pTimer))
    11271130        {
     
    11291132            LogRel(("PIT: mode=%d count=%#x (%u) - %d.%02d Hz (ch=%d) (restore)\n",
    11301133                    pChan->mode, pChan->count, pChan->count, PIT_FREQ / pChan->count, (PIT_FREQ * 100 / pChan->count) % 100, i));
    1131             PDMCritSectEnter(&pThis->CritSect, VERR_IGNORED);
     1134            PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
    11321135            TMTimerSetFrequencyHint(pChan->CTX_SUFF(pTimer), PIT_FREQ / pChan->count);
    1133             PDMCritSectLeave(&pThis->CritSect);
     1136            PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
    11341137        }
    11351138        pThis->channels[i].cRelLogEntries = 0;
    11361139    }
    11371140
    1138     SSMR3GetS32(pSSM, &pThis->speaker_data_on);
     1141    pHlp->pfnSSMGetS32(pSSM, &pThis->speaker_data_on);
    11391142#ifdef FAKE_REFRESH_CLOCK
    1140     SSMR3GetS32(pSSM, &pThis->dummy_refresh_clock);
     1143    pHlp->pfnSSMGetS32(pSSM, &pThis->dummy_refresh_clock);
    11411144#else
    11421145    int32_t u32Dummy;
    1143     SSMR3GetS32(pSSM, &u32Dummy);
     1146    pHlp->pfnSSMGetS32(pSSM, &u32Dummy);
    11441147#endif
    11451148    if (uVersion > PIT_SAVED_STATE_VERSION_VBOX_31)
    1146         SSMR3GetBool(pSSM, &pThis->fDisabledByHpet);
     1149        pHlp->pfnSSMGetBool(pSSM, &pThis->fDisabledByHpet);
    11471150
    11481151    return VINF_SUCCESS;
     
    11581161static DECLCALLBACK(void) pitTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    11591162{
    1160     RT_NOREF1(pDevIns);
     1163    RT_NOREF(pDevIns);
    11611164    PPITCHANNEL pChan = (PPITCHANNEL)pvUser;
    11621165    STAM_PROFILE_ADV_START(&pChan->CTX_SUFF(pPit)->StatPITHandler, a);
    11631166
    11641167    Log(("pitTimer\n"));
    1165     Assert(PDMCritSectIsOwner(&PDMDEVINS_2_DATA(pDevIns, PPITSTATE)->CritSect));
     1168    Assert(PDMDevHlpCritSectIsOwner(pDevIns, &PDMDEVINS_2_DATA(pDevIns, PPITSTATE)->CritSect));
    11661169    Assert(TMTimerIsLockOwner(pTimer));
    11671170
     
    11791182static DECLCALLBACK(void) pitInfo(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
    11801183{
    1181     RT_NOREF1(pszArgs);
     1184    RT_NOREF(pszArgs);
    11821185    PPITSTATE   pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
    11831186    unsigned    i;
     
    12211224static DECLCALLBACK(void) pitNotifyHpetLegacyNotify_ModeChanged(PPDMIHPETLEGACYNOTIFY pInterface, bool fActivated)
    12221225{
    1223     PPITSTATE pThis = RT_FROM_MEMBER(pInterface, PITSTATE, IHpetLegacyNotify);
    1224     PDMCritSectEnter(&pThis->CritSect, VERR_IGNORED);
     1226    PPITSTATE  pThis   = RT_FROM_MEMBER(pInterface, PITSTATE, IHpetLegacyNotify);
     1227    PPDMDEVINS pDevIns = pThis->pDevIns;
     1228    PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
    12251229
    12261230    pThis->fDisabledByHpet = fActivated;
    12271231
    1228     PDMCritSectLeave(&pThis->CritSect);
     1232    PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
    12291233}
    12301234
     
    12521256static DECLCALLBACK(void) pitRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
    12531257{
    1254     RT_NOREF1(offDelta);
     1258    RT_NOREF(offDelta);
    12551259    PPITSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
    12561260    LogFlow(("pitRelocate: \n"));
     
    12741278    LogFlow(("pitReset: \n"));
    12751279
    1276     DEVPIT_R3_LOCK_BOTH(pThis);
     1280    DEVPIT_R3_LOCK_BOTH(pDevIns, pThis);
    12771281
    12781282    pThis->fDisabledByHpet = false;
     
    13001304    }
    13011305
    1302     DEVPIT_UNLOCK_BOTH(pThis);
     1306    DEVPIT_UNLOCK_BOTH(pDevIns, pThis);
    13031307}
    13041308
     
    13101314{
    13111315    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    1312     PPITSTATE   pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
    1313     int         rc;
    1314     uint8_t     u8Irq;
    1315     uint16_t    u16Base;
    1316     bool        fSpeaker;
    1317     bool        fGCEnabled;
    1318     bool        fR0Enabled;
    1319     unsigned    i;
     1316    PPITSTATE       pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
     1317    PCPDMDEVHLPR3   pHlp  = pDevIns->pHlpR3;
     1318    int             rc;
     1319    uint8_t         u8Irq;
     1320    uint16_t        u16Base;
     1321    bool            fSpeaker;
     1322    unsigned        i;
    13201323    Assert(iInstance == 0);
    13211324
    13221325    /*
    1323      * Validate configuration.
     1326     * Validate and read the configuration.
    13241327     */
    1325     if (!CFGMR3AreValuesValid(pCfg, "Irq\0" "Base\0"
    1326                                     "SpeakerEnabled\0" "PassthroughSpeaker\0" "PassthroughSpeakerDevice\0"
    1327                                     "R0Enabled\0" "GCEnabled\0"))
    1328         return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
     1328    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "Irq|Base|SpeakerEnabled|PassthroughSpeaker|PassthroughSpeakerDevice", "");
     1329
     1330    rc = pHlp->pfnCFGMQueryU8Def(pCfg, "Irq", &u8Irq, 0);
     1331    if (RT_FAILURE(rc))
     1332        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Querying \"Irq\" as a uint8_t failed"));
     1333
     1334    rc = pHlp->pfnCFGMQueryU16Def(pCfg, "Base", &u16Base, 0x40);
     1335    if (RT_FAILURE(rc))
     1336        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Querying \"Base\" as a uint16_t failed"));
     1337
     1338    rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "SpeakerEnabled", &fSpeaker, true);
     1339    if (RT_FAILURE(rc))
     1340        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Querying \"SpeakerEnabled\" as a bool failed"));
     1341
     1342    uint8_t uPassthroughSpeaker;
     1343    char *pszPassthroughSpeakerDevice = NULL;
     1344    rc = pHlp->pfnCFGMQueryU8Def(pCfg, "PassthroughSpeaker", &uPassthroughSpeaker, 0);
     1345    if (RT_FAILURE(rc))
     1346        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: failed to read PassthroughSpeaker as uint8_t"));
     1347    if (uPassthroughSpeaker)
     1348    {
     1349        rc = pHlp->pfnCFGMQueryStringAllocDef(pCfg, "PassthroughSpeakerDevice", &pszPassthroughSpeakerDevice, NULL);
     1350        if (RT_FAILURE(rc))
     1351            return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: failed to read PassthroughSpeakerDevice as string"));
     1352    }
    13291353
    13301354    /*
    13311355     * Init the data.
    13321356     */
    1333     rc = CFGMR3QueryU8Def(pCfg, "Irq", &u8Irq, 0);
    1334     if (RT_FAILURE(rc))
    1335         return PDMDEV_SET_ERROR(pDevIns, rc,
    1336                                 N_("Configuration error: Querying \"Irq\" as a uint8_t failed"));
    1337 
    1338     rc = CFGMR3QueryU16Def(pCfg, "Base", &u16Base, 0x40);
    1339     if (RT_FAILURE(rc))
    1340         return PDMDEV_SET_ERROR(pDevIns, rc,
    1341                                 N_("Configuration error: Querying \"Base\" as a uint16_t failed"));
    1342 
    1343     rc = CFGMR3QueryBoolDef(pCfg, "SpeakerEnabled", &fSpeaker, true);
    1344     if (RT_FAILURE(rc))
    1345         return PDMDEV_SET_ERROR(pDevIns, rc,
    1346                                 N_("Configuration error: Querying \"SpeakerEnabled\" as a bool failed"));
    1347 
    1348     uint8_t uPassthroughSpeaker;
    1349     char *pszPassthroughSpeakerDevice = NULL;
    1350     rc = CFGMR3QueryU8Def(pCfg, "PassthroughSpeaker", &uPassthroughSpeaker, 0);
    1351     if (RT_FAILURE(rc))
    1352         return PDMDEV_SET_ERROR(pDevIns, rc,
    1353                                 N_("Configuration error: failed to read PassthroughSpeaker as uint8_t"));
    1354     if (uPassthroughSpeaker)
    1355     {
    1356         rc = CFGMR3QueryStringAllocDef(pCfg, "PassthroughSpeakerDevice", &pszPassthroughSpeakerDevice, NULL);
    1357         if (RT_FAILURE(rc))
    1358             return PDMDEV_SET_ERROR(pDevIns, rc,
    1359                                     N_("Configuration error: failed to read PassthroughSpeakerDevice as string"));
    1360     }
    1361 
    1362     rc = CFGMR3QueryBoolDef(pCfg, "GCEnabled", &fGCEnabled, true);
    1363     if (RT_FAILURE(rc))
    1364         return PDMDEV_SET_ERROR(pDevIns, rc,
    1365                                 N_("Configuration error: Querying \"GCEnabled\" as a bool failed"));
    1366 
    1367     rc = CFGMR3QueryBoolDef(pCfg, "R0Enabled", &fR0Enabled, true);
    1368     if (RT_FAILURE(rc))
    1369         return PDMDEV_SET_ERROR(pDevIns, rc,
    1370                                 N_("Configuration error: failed to read R0Enabled as boolean"));
    1371 
    13721357    pThis->pDevIns         = pDevIns;
    13731358    pThis->IOPortBaseCfg   = u16Base;
     
    14251410        if (pszPassthroughSpeakerDevice)
    14261411        {
    1427             MMR3HeapFree(pszPassthroughSpeakerDevice);
     1412            PDMDevHlpMMHeapFree(pDevIns, pszPassthroughSpeakerDevice);
    14281413            pszPassthroughSpeakerDevice = NULL;
    14291414        }
     
    14731458    if (RT_FAILURE(rc))
    14741459        return rc;
    1475     if (fGCEnabled)
     1460    if (pDevIns->fRCEnabled)
    14761461    {
    14771462        rc = PDMDevHlpIOPortRegisterRC(pDevIns, u16Base, 4, 0, "pitIOPortWrite", "pitIOPortRead", NULL, NULL, "i8254 Programmable Interval Timer");
     
    14791464            return rc;
    14801465    }
    1481     if (fR0Enabled)
     1466    if (pDevIns->fR0Enabled)
    14821467    {
    14831468        rc = PDMDevHlpIOPortRegisterR0(pDevIns, u16Base, 4, 0, "pitIOPortWrite", "pitIOPortRead", NULL, NULL, "i8254 Programmable Interval Timer");
     
    14911476        if (RT_FAILURE(rc))
    14921477            return rc;
    1493         if (fGCEnabled)
     1478        if (pDevIns->fRCEnabled)
    14941479        {
    14951480            rc = PDMDevHlpIOPortRegisterRC(pDevIns, 0x61, 1, 0, NULL, "pitIOPortSpeakerRead", NULL, NULL, "PC Speaker");
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