VirtualBox

Changeset 81952 in vbox


Ignore:
Timestamp:
Nov 18, 2019 4:54:34 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134749
Message:

DevHPET: Use device helpers for CFGM and SSM. Nits. bugref:9218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/DevHPET.cpp

    r81591 r81952  
    241241} HPETTIMER;
    242242AssertCompileMemberAlignment(HPETTIMER, u64Config, sizeof(uint64_t));
     243/** Pointer to the shared state of an HPET timer. */
     244typedef HPETTIMER *PHPETTIMER;
     245/** Const pointer to the shared state of an HPET timer. */
     246typedef HPETTIMER const *PCHPETTIMER;
     247
    243248
    244249/**
     
    290295    uint8_t                     abPadding0[7];
    291296} HPET;
     297/** Pointer to the shared HPET device state. */
     298typedef HPET *PHPET;
     299/** Const pointer to the shared HPET device state. */
     300typedef const HPET *PCHPET;
    292301
    293302
     
    295304
    296305
    297 DECLINLINE(bool) hpet32bitTimer(HPETTIMER *pHpetTimer)
     306DECLINLINE(bool) hpet32bitTimer(PHPETTIMER pHpetTimer)
    298307{
    299308    uint64_t u64Cfg = pHpetTimer->u64Config;
     
    302311}
    303312
    304 DECLINLINE(uint64_t) hpetInvalidValue(HPETTIMER *pHpetTimer)
     313DECLINLINE(uint64_t) hpetInvalidValue(PHPETTIMER pHpetTimer)
    305314{
    306315    return hpet32bitTimer(pHpetTimer) ? UINT32_MAX : UINT64_MAX;
    307316}
    308317
    309 DECLINLINE(uint64_t) hpetTicksToNs(HPET *pThis, uint64_t value)
     318DECLINLINE(uint64_t) hpetTicksToNs(PHPET pThis, uint64_t value)
    310319{
    311320    return ASMMultU64ByU32DivByU32(value,  pThis->u32Period, FS_PER_NS);
    312321}
    313322
    314 DECLINLINE(uint64_t) nsToHpetTicks(HPET const *pThis, uint64_t u64Value)
     323DECLINLINE(uint64_t) nsToHpetTicks(PCHPET pThis, uint64_t u64Value)
    315324{
    316325    return ASMMultU64ByU32DivByU32(u64Value, FS_PER_NS, pThis->u32Period);
    317326}
    318327
    319 DECLINLINE(uint64_t) hpetGetTicks(HPET const *pThis)
     328DECLINLINE(uint64_t) hpetGetTicks(PCHPET pThis)
    320329{
    321330    /*
     
    347356}
    348357
    349 DECLINLINE(uint64_t) hpetComputeDiff(HPETTIMER *pHpetTimer, uint64_t u64Now)
     358DECLINLINE(uint64_t) hpetComputeDiff(PHPETTIMER pHpetTimer, uint64_t u64Now)
    350359{
    351360
     
    369378
    370379
    371 static void hpetAdjustComparator(HPETTIMER *pHpetTimer, uint64_t u64Now)
     380static void hpetAdjustComparator(PHPETTIMER pHpetTimer, uint64_t u64Now)
    372381{
    373382    uint64_t    u64Period = pHpetTimer->u64Period;
     
    388397 * @param   pHpetTimer  The timer.
    389398 */
    390 DECLINLINE(void) hpetTimerSetFrequencyHint(HPET *pThis, HPETTIMER *pHpetTimer)
     399DECLINLINE(void) hpetTimerSetFrequencyHint(PHPET pThis, PHPETTIMER pHpetTimer)
    391400{
    392401    if (pHpetTimer->u64Config & HPET_TN_PERIODIC)
     
    400409
    401410
    402 static void hpetProgramTimer(HPET *pThis, HPETTIMER *pHpetTimer)
     411static void hpetProgramTimer(PHPET pThis, PHPETTIMER pHpetTimer)
    403412{
    404413    /* no wrapping on new timers */
     
    463472 * @remarks ASSUMES the caller holds the HPET lock.
    464473 */
    465 static int hpetTimerRegRead32(HPET const *pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t *pu32Value)
     474static int hpetTimerRegRead32(PCHPET pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t *pu32Value)
    466475{
    467476    Assert(PDMCritSectIsOwner(&pThis->CritSect));
     
    475484    }
    476485
    477     HPETTIMER const *pHpetTimer = &pThis->aTimers[iTimerNo];
     486    PCHPETTIMER pHpetTimer = &pThis->aTimers[iTimerNo];
    478487    uint32_t u32Value;
    479488    switch (iTimerReg)
     
    529538 *          the TM lock.
    530539 */
    531 static int hpetTimerRegWrite32(HPET *pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t u32NewValue)
     540static int hpetTimerRegWrite32(PHPET pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t u32NewValue)
    532541{
    533542    Assert(!PDMCritSectIsOwner(&pThis->CritSect) || TMTimerIsLockOwner(pThis->aTimers[0].CTX_SUFF(pTimer)));
     
    539548        return VINF_SUCCESS;
    540549    }
    541     HPETTIMER *pHpetTimer = &pThis->aTimers[iTimerNo];
     550    PHPETTIMER pHpetTimer = &pThis->aTimers[iTimerNo];
    542551
    543552    switch (iTimerReg)
     
    647656 * @remarks The caller must not own the device lock if HPET_COUNTER is read.
    648657 */
    649 static int hpetConfigRegRead32(HPET *pThis, uint32_t idxReg, uint32_t *pu32Value)
     658static int hpetConfigRegRead32(PHPET pThis, uint32_t idxReg, uint32_t *pu32Value)
    650659{
    651660    Assert(!PDMCritSectIsOwner(&pThis->CritSect) || (idxReg != HPET_COUNTER && idxReg != HPET_COUNTER + 4));
     
    732741 *          the TM lock.
    733742 */
    734 static int hpetConfigRegWrite32(HPET *pThis, uint32_t idxReg, uint32_t u32NewValue)
     743static int hpetConfigRegWrite32(PHPET pThis, uint32_t idxReg, uint32_t u32NewValue)
    735744{
    736745    Assert(!PDMCritSectIsOwner(&pThis->CritSect) || TMTimerIsLockOwner(pThis->aTimers[0].CTX_SUFF(pTimer)));
     
    10021011 * @param   pHpetTimer          The HPET timer.
    10031012 */
    1004 static uint32_t hpetR3TimerGetIrq(struct HPETTIMER const *pHpetTimer)
     1013static uint32_t hpetR3TimerGetIrq(PCHPETTIMER pHpetTimer)
    10051014{
    10061015    /*
     
    10261035 * @param   pHpetTimer          The HPET timer.
    10271036 */
    1028 static void hpetR3TimerUpdateIrq(HPET *pThis, struct HPETTIMER *pHpetTimer)
     1037static void hpetR3TimerUpdateIrq(PHPET pThis, PHPETTIMER pHpetTimer)
    10291038{
    10301039    /** @todo is it correct? */
     
    10581067static DECLCALLBACK(void) hpetR3Timer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    10591068{
    1060     HPET *pThis      = PDMDEVINS_2_DATA(pDevIns, HPET *);
    1061     HPETTIMER *pHpetTimer = (HPETTIMER *)pvUser;
     1069    PHPET pThis      = PDMDEVINS_2_DATA(pDevIns, PHPET);
     1070    PHPETTIMER pHpetTimer = (HPETTIMER *)pvUser;
    10621071    uint64_t   u64Period  = pHpetTimer->u64Period;
    10631072    uint64_t   u64CurTick = hpetGetTicks(pThis);
     
    11071116static DECLCALLBACK(void) hpetR3Info(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
    11081117{
    1109     HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
     1118    PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET);
    11101119    NOREF(pszArgs);
    11111120
     
    11401149static DECLCALLBACK(int) hpetR3LiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
    11411150{
    1142     HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
     1151    PHPET           pThis   = PDMDEVINS_2_DATA(pDevIns, PHPET);
     1152    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
    11431153    NOREF(uPass);
    11441154
    1145     SSMR3PutU8(pSSM, HPET_CAP_GET_TIMERS(pThis->u32Capabilities));
     1155    pHlp->pfnSSMPutU8(pSSM, HPET_CAP_GET_TIMERS(pThis->u32Capabilities));
    11461156
    11471157    return VINF_SSM_DONT_CALL_AGAIN;
     
    11541164static DECLCALLBACK(int) hpetR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    11551165{
    1156     HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
     1166    PHPET           pThis   = PDMDEVINS_2_DATA(pDevIns, PHPET);
     1167    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
    11571168
    11581169    /*
     
    11671178    for (uint32_t iTimer = 0; iTimer < cTimers; iTimer++)
    11681179    {
    1169         HPETTIMER *pHpetTimer = &pThis->aTimers[iTimer];
     1180        PHPETTIMER pHpetTimer = &pThis->aTimers[iTimer];
    11701181        TMR3TimerSave(pHpetTimer->pTimerR3, pSSM);
    1171         SSMR3PutU8(pSSM,  pHpetTimer->u8Wrap);
    1172         SSMR3PutU64(pSSM, pHpetTimer->u64Config);
    1173         SSMR3PutU64(pSSM, pHpetTimer->u64Cmp);
    1174         SSMR3PutU64(pSSM, pHpetTimer->u64Fsb);
    1175         SSMR3PutU64(pSSM, pHpetTimer->u64Period);
    1176     }
    1177 
    1178     SSMR3PutU64(pSSM, pThis->u64HpetOffset);
     1182        pHlp->pfnSSMPutU8(pSSM,  pHpetTimer->u8Wrap);
     1183        pHlp->pfnSSMPutU64(pSSM, pHpetTimer->u64Config);
     1184        pHlp->pfnSSMPutU64(pSSM, pHpetTimer->u64Cmp);
     1185        pHlp->pfnSSMPutU64(pSSM, pHpetTimer->u64Fsb);
     1186        pHlp->pfnSSMPutU64(pSSM, pHpetTimer->u64Period);
     1187    }
     1188
     1189    pHlp->pfnSSMPutU64(pSSM, pThis->u64HpetOffset);
    11791190    uint64_t u64CapPer = RT_MAKE_U64(pThis->u32Capabilities, pThis->u32Period);
    1180     SSMR3PutU64(pSSM, u64CapPer);
    1181     SSMR3PutU64(pSSM, pThis->u64HpetConfig);
    1182     SSMR3PutU64(pSSM, pThis->u64Isr);
    1183     return SSMR3PutU64(pSSM, pThis->u64HpetCounter);
     1191    pHlp->pfnSSMPutU64(pSSM, u64CapPer);
     1192    pHlp->pfnSSMPutU64(pSSM, pThis->u64HpetConfig);
     1193    pHlp->pfnSSMPutU64(pSSM, pThis->u64Isr);
     1194    return pHlp->pfnSSMPutU64(pSSM, pThis->u64HpetCounter);
    11841195}
    11851196
     
    11901201static DECLCALLBACK(int) hpetR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
    11911202{
    1192     HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
     1203    PHPET           pThis   = PDMDEVINS_2_DATA(pDevIns, PHPET);
     1204    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
    11931205
    11941206    /*
     
    12041216     */
    12051217    uint8_t cTimers;
    1206     int rc = SSMR3GetU8(pSSM, &cTimers);
     1218    int rc = pHlp->pfnSSMGetU8(pSSM, &cTimers);
    12071219    AssertRCReturn(rc, rc);
    12081220    if (cTimers > RT_ELEMENTS(pThis->aTimers))
    1209         return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - too many timers: saved=%#x config=%#x"),
    1210                                 cTimers, RT_ELEMENTS(pThis->aTimers));
     1221        return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - too many timers: saved=%#x config=%#x"),
     1222                                       cTimers, RT_ELEMENTS(pThis->aTimers));
    12111223
    12121224    if (uPass != SSM_PASS_FINAL)
     
    12181230    for (uint32_t iTimer = 0; iTimer < cTimers; iTimer++)
    12191231    {
    1220         HPETTIMER *pHpetTimer = &pThis->aTimers[iTimer];
     1232        PHPETTIMER pHpetTimer = &pThis->aTimers[iTimer];
    12211233        TMR3TimerLoad(pHpetTimer->pTimerR3, pSSM);
    1222         SSMR3GetU8(pSSM,  &pHpetTimer->u8Wrap);
    1223         SSMR3GetU64(pSSM, &pHpetTimer->u64Config);
    1224         SSMR3GetU64(pSSM, &pHpetTimer->u64Cmp);
    1225         SSMR3GetU64(pSSM, &pHpetTimer->u64Fsb);
    1226         SSMR3GetU64(pSSM, &pHpetTimer->u64Period);
    1227     }
    1228 
    1229     SSMR3GetU64(pSSM, &pThis->u64HpetOffset);
     1234        pHlp->pfnSSMGetU8(pSSM,  &pHpetTimer->u8Wrap);
     1235        pHlp->pfnSSMGetU64(pSSM, &pHpetTimer->u64Config);
     1236        pHlp->pfnSSMGetU64(pSSM, &pHpetTimer->u64Cmp);
     1237        pHlp->pfnSSMGetU64(pSSM, &pHpetTimer->u64Fsb);
     1238        pHlp->pfnSSMGetU64(pSSM, &pHpetTimer->u64Period);
     1239    }
     1240
     1241    pHlp->pfnSSMGetU64(pSSM, &pThis->u64HpetOffset);
    12301242    uint64_t u64CapPer;
    1231     SSMR3GetU64(pSSM, &u64CapPer);
    1232     SSMR3GetU64(pSSM, &pThis->u64HpetConfig);
    1233     SSMR3GetU64(pSSM, &pThis->u64Isr);
    1234     rc = SSMR3GetU64(pSSM, &pThis->u64HpetCounter);
     1243    pHlp->pfnSSMGetU64(pSSM, &u64CapPer);
     1244    pHlp->pfnSSMGetU64(pSSM, &pThis->u64HpetConfig);
     1245    pHlp->pfnSSMGetU64(pSSM, &pThis->u64Isr);
     1246    rc = pHlp->pfnSSMGetU64(pSSM, &pThis->u64HpetCounter);
    12351247    if (RT_FAILURE(rc))
    12361248        return rc;
    12371249    if (HPET_CAP_GET_TIMERS(RT_LO_U32(u64CapPer)) != cTimers)
    1238         return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Capabilities does not match timer count: cTimers=%#x caps=%#x"),
    1239                                 cTimers, (unsigned)HPET_CAP_GET_TIMERS(u64CapPer));
     1250        return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Capabilities does not match timer count: cTimers=%#x caps=%#x"),
     1251                                       cTimers, (unsigned)HPET_CAP_GET_TIMERS(u64CapPer));
    12401252    pThis->u32Capabilities  = RT_LO_U32(u64CapPer);
    12411253    pThis->u32Period        = RT_HI_U32(u64CapPer);
     
    12471259    for (uint32_t iTimer = 0; iTimer < cTimers; iTimer++)
    12481260    {
    1249         HPETTIMER *pHpetTimer = &pThis->aTimers[iTimer];
     1261        PHPETTIMER pHpetTimer = &pThis->aTimers[iTimer];
    12501262        if (TMTimerIsActive(pHpetTimer->CTX_SUFF(pTimer)))
    12511263            hpetTimerSetFrequencyHint(pThis, pHpetTimer);
     
    12641276static DECLCALLBACK(void) hpetR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
    12651277{
    1266     HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
     1278    PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET);
    12671279    LogFlow(("hpetR3Relocate:\n"));
    12681280    NOREF(offDelta);
     
    12731285    for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++)
    12741286    {
    1275         HPETTIMER *pTm = &pThis->aTimers[i];
     1287        PHPETTIMER pTm = &pThis->aTimers[i];
    12761288        if (pTm->pTimerR3)
    12771289            pTm->pTimerRC = TMTimerRCPtr(pTm->pTimerR3);
     
    12861298static DECLCALLBACK(void) hpetR3Reset(PPDMDEVINS pDevIns)
    12871299{
    1288     HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
     1300    PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET);
    12891301    LogFlow(("hpetR3Reset:\n"));
    12901302
     
    12951307    for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++)
    12961308    {
    1297         HPETTIMER *pHpetTimer = &pThis->aTimers[i];
     1309        PHPETTIMER pHpetTimer = &pThis->aTimers[i];
    12981310        Assert(pHpetTimer->idxTimer == i);
    12991311        TMTimerStop(pHpetTimer->pTimerR3);
     
    13511363{
    13521364    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    1353     HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
     1365    PHPET           pThis   = PDMDEVINS_2_DATA(pDevIns, PHPET);
     1366    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
    13541367
    13551368    /* Only one HPET device now, as we use fixed MMIO region. */
     
    13661379    for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++)
    13671380    {
    1368         HPETTIMER *pHpetTimer = &pThis->aTimers[i];
     1381        PHPETTIMER pHpetTimer = &pThis->aTimers[i];
    13691382
    13701383        pHpetTimer->idxTimer = i;
     
    13771390     * Validate and read the configuration.
    13781391     */
    1379     PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "GCEnabled|R0Enabled|ICH9", "");
    1380 
    1381     bool fRCEnabled;
    1382     int rc = CFGMR3QueryBoolDef(pCfg, "GCEnabled", &fRCEnabled, true);
     1392    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "ICH9", "");
     1393
     1394    int rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "ICH9", &pThis->fIch9, false);
    13831395    if (RT_FAILURE(rc))
    1384         return PDMDEV_SET_ERROR(pDevIns, rc,
    1385                                 N_("Configuration error: Querying \"GCEnabled\" as a bool failed"));
    1386 
    1387     bool fR0Enabled;
    1388     rc = CFGMR3QueryBoolDef(pCfg, "R0Enabled", &fR0Enabled, true);
    1389     if (RT_FAILURE(rc))
    1390         return PDMDEV_SET_ERROR(pDevIns, rc,
    1391                                 N_("Configuration error: failed to read R0Enabled as boolean"));
    1392 
    1393     rc = CFGMR3QueryBoolDef(pCfg, "ICH9", &pThis->fIch9, false);
    1394     if (RT_FAILURE(rc))
    1395         return PDMDEV_SET_ERROR(pDevIns, rc,
    1396                                 N_("Configuration error: failed to read ICH9 as boolean"));
     1396        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: failed to read ICH9 as boolean"));
    13971397
    13981398
     
    14101410    for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++)
    14111411    {
    1412         HPETTIMER *pHpetTimer = &pThis->aTimers[i];
     1412        PHPETTIMER pHpetTimer = &pThis->aTimers[i];
    14131413
    14141414        rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, hpetR3Timer, pHpetTimer,
     
    14441444    AssertRCReturn(rc, rc);
    14451445
    1446     if (fRCEnabled)
     1446    if (pDevIns->fRCEnabled)
    14471447    {
    14481448        rc = PDMDevHlpMMIORegisterRC(pDevIns, HPET_BASE, HPET_BAR_SIZE, NIL_RTRCPTR /*pvUser*/, "hpetMMIOWrite", "hpetMMIORead");
     
    14521452    }
    14531453
    1454     if (fR0Enabled)
    1455     {
    1456         rc = PDMDevHlpMMIORegisterR0(pDevIns, HPET_BASE, HPET_BAR_SIZE, NIL_RTR0PTR /*pvUser*/,
    1457                                      "hpetMMIOWrite", "hpetMMIORead");
     1454    if (pDevIns->fR0Enabled)
     1455    {
     1456        rc = PDMDevHlpMMIORegisterR0(pDevIns, HPET_BASE, HPET_BAR_SIZE, NIL_RTR0PTR /*pvUser*/, "hpetMMIOWrite", "hpetMMIORead");
    14581457        AssertRCReturn(rc, rc);
    14591458
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