VirtualBox

Changeset 81954 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Nov 18, 2019 5:18:45 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134751
Message:

DevHPET: Converted timers to handles and device helpers. bugref:9218

File:
1 edited

Legend:

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

    r81953 r81954  
    156156    do { \
    157157        int rcLock = PDMDevHlpCritSectEnter((a_pDevIns), &(a_pThis)->CritSect, (a_rcBusy)); \
    158         if (rcLock == VINF_SUCCESS) \
     158        if (RT_LIKELY(rcLock == VINF_SUCCESS)) \
    159159        { /* likely */ } \
    160160        else \
     
    171171/**
    172172 * Acquires the TM lock and HPET lock, returns on failure.
     173 * @todo r=bird: Aren't the timers using the same critsect?!?
    173174 */
    174175#define DEVHPET_LOCK_BOTH_RETURN(a_pDevIns, a_pThis, a_rcBusy)  \
    175176    do { \
    176         int rcLock = TMTimerLock((a_pThis)->aTimers[0].CTX_SUFF(pTimer), (a_rcBusy)); \
    177         if (rcLock == VINF_SUCCESS) \
     177        int rcLock = PDMDevHlpTimerLock((a_pDevIns), (a_pThis)->aTimers[0].hTimer, (a_rcBusy)); \
     178        if (RT_LIKELY(rcLock == VINF_SUCCESS)) \
    178179        { \
    179180            rcLock = PDMDevHlpCritSectEnter((a_pDevIns), &(a_pThis)->CritSect, (a_rcBusy)); \
    180             if (rcLock == VINF_SUCCESS) \
     181            if (RT_LIKELY(rcLock == VINF_SUCCESS)) \
    181182                break; /* likely */ \
    182             TMTimerUnlock((a_pThis)->aTimers[0].CTX_SUFF(pTimer)); \
     183            PDMDevHlpTimerUnlock((a_pDevIns), (a_pThis)->aTimers[0].hTimer); \
    183184        } \
    184185        return rcLock; \
     
    192193    do { \
    193194        PDMDevHlpCritSectLeave((a_pDevIns), &(a_pThis)->CritSect); \
    194         TMTimerUnlock((a_pThis)->aTimers[0].CTX_SUFF(pTimer)); \
     195        PDMDevHlpTimerUnlock((a_pDevIns), (a_pThis)->aTimers[0].hTimer); \
    195196    } while (0)
    196197
     
    204205typedef struct HPETTIMER
    205206{
    206     /** The HPET timer - R3 Ptr. */
    207     PTMTIMERR3                  pTimerR3;
     207    /** The HPET timer. */
     208    TMTIMERHANDLE               hTimer;
     209
    208210    /** Pointer to the instance data - R3 Ptr. */
    209211    R3PTRTYPE(struct HPET *)    pHpetR3;
    210 
    211     /** The HPET timer - R0 Ptr. */
    212     PTMTIMERR0                  pTimerR0;
    213212    /** Pointer to the instance data - R0 Ptr. */
    214213    R0PTRTYPE(struct HPET *)    pHpetR0;
    215 
    216     /** The HPET timer - RC Ptr. */
    217     PTMTIMERRC                  pTimerRC;
    218214    /** Pointer to the instance data - RC Ptr. */
    219215    RCPTRTYPE(struct HPET *)    pHpetRC;
     
    223219    /** Wrap. */
    224220    uint8_t                     u8Wrap;
    225     /** Alignment. */
    226     uint32_t                    alignment0;
     221    /** Explicit padding. */
     222    uint8_t                     abPadding[2];
    227223
    228224    /** @name Memory-mapped, software visible timer registers.
     
    328324}
    329325
    330 DECLINLINE(uint64_t) hpetGetTicks(PCHPET pThis)
    331 {
    332     /*
    333      * We can use any timer to get current time, they all go
    334      * with the same speed.
    335      */
    336     return nsToHpetTicks(pThis,
    337                            TMTimerGet(pThis->aTimers[0].CTX_SUFF(pTimer))
    338                          + pThis->u64HpetOffset);
     326DECLINLINE(uint64_t) hpetGetTicks(PPDMDEVINS pDevIns, PCHPET pThis)
     327{
     328    /*
     329     * We can use any timer to get current time, they all go with the same speed.
     330     */
     331    return nsToHpetTicks(pThis, PDMDevHlpTimerGet(pDevIns, pThis->aTimers[0].hTimer) + pThis->u64HpetOffset);
    339332}
    340333
     
    396389 * Sets the frequency hint if it's a periodic timer.
    397390 *
     391 * @param   pDevIns     The device instance.
    398392 * @param   pThis       The shared HPET state.
    399393 * @param   pHpetTimer  The timer.
    400394 */
    401 DECLINLINE(void) hpetTimerSetFrequencyHint(PHPET pThis, PHPETTIMER pHpetTimer)
     395DECLINLINE(void) hpetTimerSetFrequencyHint(PPDMDEVINS pDevIns, PHPET pThis, PHPETTIMER pHpetTimer)
    402396{
    403397    if (pHpetTimer->u64Config & HPET_TN_PERIODIC)
     
    406400        uint32_t const u32Freq   = pThis->u32Period;
    407401        if (u64Period > 0 && u64Period < u32Freq)
    408             TMTimerSetFrequencyHint(pHpetTimer->CTX_SUFF(pTimer), u32Freq / (uint32_t)u64Period);
    409     }
    410 }
    411 
    412 
    413 static void hpetProgramTimer(PHPET pThis, PHPETTIMER pHpetTimer)
     402            PDMDevHlpTimerSetFrequencyHint(pDevIns, pHpetTimer->hTimer, u32Freq / (uint32_t)u64Period);
     403    }
     404}
     405
     406
     407static void hpetProgramTimer(PPDMDEVINS pDevIns, PHPET pThis, PHPETTIMER pHpetTimer)
    414408{
    415409    /* no wrapping on new timers */
    416410    pHpetTimer->u8Wrap = 0;
    417411
    418     uint64_t u64Ticks = hpetGetTicks(pHpetTimer->CTX_SUFF(pHpet));
     412    uint64_t u64Ticks = hpetGetTicks(pDevIns, pHpetTimer->CTX_SUFF(pHpet));
    419413    hpetAdjustComparator(pHpetTimer, u64Ticks);
    420414
     
    450444    {
    451445        Log4(("HPET: next IRQ in %lld ticks (%lld ns)\n", u64Diff, hpetTicksToNs(pHpetTimer->CTX_SUFF(pHpet), u64Diff)));
    452         TMTimerSetNano(pHpetTimer->CTX_SUFF(pTimer), hpetTicksToNs(pHpetTimer->CTX_SUFF(pHpet), u64Diff));
     446        PDMDevHlpTimerSetNano(pDevIns, pHpetTimer->hTimer, hpetTicksToNs(pHpetTimer->CTX_SUFF(pHpet), u64Diff));
    453447    }
    454448    else
     
    456450        LogRelMax(10, ("HPET: Not scheduling an interrupt more than 100 years in the future.\n"));
    457451    }
    458     hpetTimerSetFrequencyHint(pHpetTimer->CTX_SUFF(pHpet), pHpetTimer);
     452    hpetTimerSetFrequencyHint(pDevIns, pThis, pHpetTimer);
    459453}
    460454
     
    545539static int hpetTimerRegWrite32(PPDMDEVINS pDevIns, PHPET pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t u32NewValue)
    546540{
    547     Assert(!PDMDevHlpCritSectIsOwner(pDevIns, &pThis->CritSect) || TMTimerIsLockOwner(pThis->aTimers[0].CTX_SUFF(pTimer)));
     541    Assert(!PDMDevHlpCritSectIsOwner(pDevIns, &pThis->CritSect) || PDMDevHlpTimerIsLockOwner(pDevIns, pThis->aTimers[0].hTimer));
    548542
    549543    if (   iTimerNo >= HPET_CAP_GET_TIMERS(pThis->u32Capabilities)
     
    605599
    606600            if (pThis->u64HpetConfig & HPET_CFG_ENABLE)
    607                 hpetProgramTimer(pThis, pHpetTimer);
     601                hpetProgramTimer(pDevIns, pThis, pHpetTimer);
    608602            DEVHPET_UNLOCK_BOTH(pDevIns, pThis);
    609603            break;
     
    625619
    626620                if (pThis->u64HpetConfig & HPET_CFG_ENABLE)
    627                     hpetProgramTimer(pThis, pHpetTimer);
     621                    hpetProgramTimer(pDevIns, pThis, pHpetTimer);
    628622            }
    629623            DEVHPET_UNLOCK_BOTH(pDevIns, pThis);
     
    704698            uint64_t u64Ticks;
    705699            if (pThis->u64HpetConfig & HPET_CFG_ENABLE)
    706                 u64Ticks = hpetGetTicks(pThis);
     700                u64Ticks = hpetGetTicks(pDevIns, pThis);
    707701            else
    708702                u64Ticks = pThis->u64HpetCounter;
     
    750744static int hpetConfigRegWrite32(PPDMDEVINS pDevIns, PHPET pThis, uint32_t idxReg, uint32_t u32NewValue)
    751745{
    752     Assert(!PDMDevHlpCritSectIsOwner(pDevIns, &pThis->CritSect) || TMTimerIsLockOwner(pThis->aTimers[0].CTX_SUFF(pTimer)));
     746    Assert(!PDMDevHlpCritSectIsOwner(pDevIns, &pThis->CritSect) || PDMDevHlpTimerIsLockOwner(pDevIns, pThis->aTimers[0].hTimer));
    753747
    754748    int rc = VINF_SUCCESS;
     
    798792                {
    799793                    pThis->u64HpetOffset = hpetTicksToNs(pThis, pThis->u64HpetCounter)
    800                                          - TMTimerGet(pThis->aTimers[0].CTX_SUFF(pTimer));
     794                                         - PDMDevHlpTimerGet(pDevIns, pThis->aTimers[0].hTimer);
    801795                }
    802796                else
     
    804798                    LogRelMax(10, ("HPET: Counter set more than 100 years in the future, reducing.\n"));
    805799                    pThis->u64HpetOffset = 1000000LL * 60 * 60 * 24 * 365 * 100
    806                                          - TMTimerGet(pThis->aTimers[0].CTX_SUFF(pTimer));
     800                                         - PDMDevHlpTimerGet(pDevIns, pThis->aTimers[0].hTimer);
    807801                }
    808802                for (uint32_t i = 0; i < cTimers; i++)
    809803                    if (pThis->aTimers[i].u64Cmp != hpetInvalidValue(&pThis->aTimers[i]))
    810                         hpetProgramTimer(pThis, &pThis->aTimers[i]);
     804                        hpetProgramTimer(pDevIns, pThis, &pThis->aTimers[i]);
    811805            }
    812806            else if (hpetBitJustCleared(iOldValue, u32NewValue, HPET_CFG_ENABLE))
    813807            {
    814808                /* Halt main counter and disable interrupt generation. */
    815                 pThis->u64HpetCounter = hpetGetTicks(pThis);
     809                pThis->u64HpetCounter = hpetGetTicks(pDevIns, pThis);
    816810                for (uint32_t i = 0; i < cTimers; i++)
    817                     TMTimerStop(pThis->aTimers[i].CTX_SUFF(pTimer));
     811                    PDMDevHlpTimerStop(pDevIns, pThis->aTimers[i].hTimer);
    818812            }
    819813
     
    924918            DEVHPET_LOCK_BOTH_RETURN(pDevIns, pThis, VINF_IOM_R3_MMIO_READ);
    925919            if (pThis->u64HpetConfig & HPET_CFG_ENABLE)
    926                 pValue->u = hpetGetTicks(pThis);
     920                pValue->u = hpetGetTicks(pDevIns, pThis);
    927921            else
    928922                pValue->u = pThis->u64HpetCounter;
     
    10741068static DECLCALLBACK(void) hpetR3Timer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    10751069{
    1076     PHPET pThis      = PDMDEVINS_2_DATA(pDevIns, PHPET);
    1077     PHPETTIMER pHpetTimer = (HPETTIMER *)pvUser;
    1078     uint64_t   u64Period  = pHpetTimer->u64Period;
    1079     uint64_t   u64CurTick = hpetGetTicks(pThis);
    1080     uint64_t   u64Diff;
     1070    PHPET       pThis      = PDMDEVINS_2_DATA(pDevIns, PHPET);
     1071    PHPETTIMER  pHpetTimer = (HPETTIMER *)pvUser;
     1072    uint64_t    u64Period  = pHpetTimer->u64Period;
     1073    uint64_t    u64CurTick = hpetGetTicks(pDevIns, pThis);
     1074    uint64_t    u64Diff;
     1075    RT_NOREF(pTimer);
    10811076
    10821077    if (pHpetTimer->u64Config & HPET_TN_PERIODIC)
    10831078    {
    1084         if (u64Period) {
     1079        if (u64Period)
     1080        {
    10851081            hpetAdjustComparator(pHpetTimer, u64CurTick);
    10861082
     
    10911087            {
    10921088                Log4(("HPET: periodic: next in %llu\n", hpetTicksToNs(pThis, u64Diff)));
    1093                 TMTimerSetNano(pTimer, hpetTicksToNs(pThis, u64Diff));
     1089                PDMDevHlpTimerSetNano(pDevIns, pHpetTimer->hTimer, hpetTicksToNs(pThis, u64Diff));
    10941090            }
    10951091            else
     
    11051101        {
    11061102            u64Diff = hpetComputeDiff(pHpetTimer, u64CurTick);
    1107             TMTimerSetNano(pTimer, hpetTicksToNs(pThis, u64Diff));
     1103            PDMDevHlpTimerSetNano(pDevIns, pHpetTimer->hTimer, hpetTicksToNs(pThis, u64Diff));
    11081104            pHpetTimer->u8Wrap = 0;
    11091105        }
     
    11861182    {
    11871183        PHPETTIMER pHpetTimer = &pThis->aTimers[iTimer];
    1188         TMR3TimerSave(pHpetTimer->pTimerR3, pSSM);
     1184        PDMDevHlpTimerSave(pDevIns, pHpetTimer->hTimer, pSSM);
    11891185        pHlp->pfnSSMPutU8(pSSM,  pHpetTimer->u8Wrap);
    11901186        pHlp->pfnSSMPutU64(pSSM, pHpetTimer->u64Config);
     
    12381234    {
    12391235        PHPETTIMER pHpetTimer = &pThis->aTimers[iTimer];
    1240         TMR3TimerLoad(pHpetTimer->pTimerR3, pSSM);
     1236        PDMDevHlpTimerLoad(pDevIns, pHpetTimer->hTimer, pSSM);
    12411237        pHlp->pfnSSMGetU8(pSSM,  &pHpetTimer->u8Wrap);
    12421238        pHlp->pfnSSMGetU64(pSSM, &pHpetTimer->u64Config);
     
    12671263    {
    12681264        PHPETTIMER pHpetTimer = &pThis->aTimers[iTimer];
    1269         if (TMTimerIsActive(pHpetTimer->CTX_SUFF(pTimer)))
    1270             hpetTimerSetFrequencyHint(pThis, pHpetTimer);
     1265        if (PDMDevHlpTimerIsActive(pDevIns, pHpetTimer->hTimer))
     1266            hpetTimerSetFrequencyHint(pDevIns, pThis, pHpetTimer);
    12711267    }
    12721268    PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
     
    12931289    {
    12941290        PHPETTIMER pTm = &pThis->aTimers[i];
    1295         if (pTm->pTimerR3)
    1296             pTm->pTimerRC = TMTimerRCPtr(pTm->pTimerR3);
    12971291        pTm->pHpetRC = PDMINS_2_DATA_RCPTR(pDevIns);
    12981292    }
     
    13111305     * The timers first.
    13121306     */
    1313     TMTimerLock(pThis->aTimers[0].pTimerR3, VERR_IGNORED);
     1307    PDMDevHlpTimerLock(pDevIns, pThis->aTimers[0].hTimer, VERR_IGNORED);
    13141308    for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++)
    13151309    {
    13161310        PHPETTIMER pHpetTimer = &pThis->aTimers[i];
    13171311        Assert(pHpetTimer->idxTimer == i);
    1318         TMTimerStop(pHpetTimer->pTimerR3);
     1312        PDMDevHlpTimerStop(pDevIns, pHpetTimer->hTimer);
    13191313
    13201314        /* capable of periodic operations and 64-bits */
     
    13331327        pHpetTimer->u64Cmp     = hpetInvalidValue(pHpetTimer);
    13341328    }
    1335     TMTimerUnlock(pThis->aTimers[0].pTimerR3);
     1329    PDMDevHlpTimerUnlock(pDevIns, pThis->aTimers[0].hTimer);
    13361330
    13371331    /*
     
    14191413        PHPETTIMER pHpetTimer = &pThis->aTimers[i];
    14201414
    1421         rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, hpetR3Timer, pHpetTimer,
    1422                                     TMTIMER_FLAGS_NO_CRIT_SECT, "HPET Timer",
    1423                                     &pThis->aTimers[i].pTimerR3);
     1415        rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, hpetR3Timer, pHpetTimer,
     1416                                  TMTIMER_FLAGS_NO_CRIT_SECT, "HPET Timer", &pThis->aTimers[i].hTimer);
    14241417        AssertRCReturn(rc, rc);
    1425         pThis->aTimers[i].pTimerRC = TMTimerRCPtr(pThis->aTimers[i].pTimerR3);
    1426         pThis->aTimers[i].pTimerR0 = TMTimerR0Ptr(pThis->aTimers[i].pTimerR3);
    1427         rc = TMR3TimerSetCritSect(pThis->aTimers[i].pTimerR3, &pThis->CritSect);
     1418        /** @todo r=bird: This is TOTALLY MESSED UP!  Why do we need
     1419         *        DEVHPET_LOCK_BOTH_RETURN() when the timers use the same critsect as
     1420         *        we do?!? */
     1421        rc = PDMDevHlpTimerSetCritSect(pDevIns, pThis->aTimers[i].hTimer, &pThis->CritSect);
    14281422        AssertRCReturn(rc, rc);
    14291423    }
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