VirtualBox

Changeset 82324 in vbox


Ignore:
Timestamp:
Dec 2, 2019 2:53:47 PM (5 years ago)
Author:
vboxsync
Message:

DevIchAc97: Converted timers. bugref:9218

Location:
trunk/src/VBox/Devices/Audio
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/DevIchAc97.cpp

    r82323 r82324  
    505505    /** The device timer Hz rate. Defaults to AC97_TIMER_HZ_DEFAULT_DEFAULT. */
    506506    uint16_t                uTimerHz;
    507     /** The timer for pumping data thru the attached LUN drivers - RCPtr. */
    508     PTMTIMERRC              pTimerRC[AC97_MAX_STREAMS];
    509     /** The timer for pumping data thru the attached LUN drivers - R3Ptr. */
    510     PTMTIMERR3              pTimerR3[AC97_MAX_STREAMS];
    511     /** The timer for pumping data thru the attached LUN drivers - R0Ptr. */
    512     PTMTIMERR0              pTimerR0[AC97_MAX_STREAMS];
     507    uint16_t                au16Padding1[3];
     508    /** The timer for pumping data thru the attached LUN drivers. */
     509    TMTIMERHANDLE           ahTimers[AC97_MAX_STREAMS];
    513510    /** List of associated LUN drivers (AC97DRIVER). */
    514511    RTLISTANCHORR3          lstDrv;
     
    581578#define DEVAC97_LOCK_BOTH_RETURN(a_pDevIns, a_pThis, a_SD, a_rcBusy) \
    582579    do { \
    583         int rcLock = TMTimerLock((a_pThis)->DEVAC97_CTX_SUFF_SD(pTimer, a_SD), (a_rcBusy)); \
     580        int rcLock = PDMDevHlpTimerLock((a_pDevIns), RT_SAFE_SUBSCRIPT8((a_pThis)->ahTimers, (a_SD)), (a_rcBusy)); \
    584581        if (rcLock == VINF_SUCCESS) \
    585582        { \
     
    587584            if (rcLock == VINF_SUCCESS) \
    588585                break; \
    589             TMTimerUnlock((a_pThis)->DEVAC97_CTX_SUFF_SD(pTimer, a_SD)); \
     586            PDMDevHlpTimerUnlock((a_pDevIns), RT_SAFE_SUBSCRIPT8((a_pThis)->ahTimers, (a_SD))); \
    590587        } \
    591588        AssertRC(rcLock); \
     
    599596    do { \
    600597        PDMDevHlpCritSectLeave((a_pDevIns), &(a_pThis)->CritSect); \
    601         TMTimerUnlock((a_pThis)->DEVAC97_CTX_SUFF_SD(pTimer, a_SD)); \
     598        PDMDevHlpTimerUnlock((a_pDevIns), RT_SAFE_SUBSCRIPT8((a_pThis)->ahTimers, (a_SD))); \
    602599    } while (0)
    603600
     
    655652# endif
    656653#endif /* IN_RING3 */
    657 bool                      ichac97TimerSet(PAC97STATE pThis, PAC97STREAM pStream, uint64_t tsExpire, bool fForce);
     654static bool               ichac97TimerSet(PPDMDEVINS pDevIns, PAC97STATE pThis, PAC97STREAM pStream, uint64_t tsExpire, bool fForce);
    658655
    659656static void ichac97WarmReset(PAC97STATE pThis)
     
    19221919 *
    19231920 * @returns Calculated ticks
     1921 * @param   pDevIns             The device instance.
    19241922 * @param   pThis               AC'97 device state.
    19251923 * @param   pStream             AC'97 stream to calculate ticks for.
    19261924 * @param   cbBytes             Bytes to calculate ticks for.
    19271925 */
    1928 static uint64_t ichac97R3StreamTransferCalcNext(PAC97STATE pThis, PAC97STREAM pStream, uint32_t cbBytes)
     1926static uint64_t ichac97R3StreamTransferCalcNext(PPDMDEVINS pDevIns, PAC97STATE pThis, PAC97STREAM pStream, uint32_t cbBytes)
    19291927{
    19301928    if (!cbBytes)
     
    19321930
    19331931    const uint64_t usBytes        = DrvAudioHlpBytesToMicro(cbBytes, &pStream->State.Cfg.Props);
    1934     const uint64_t cTransferTicks = TMTimerFromMicro((pThis)->DEVAC97_CTX_SUFF_SD(pTimer, pStream->u8SD), usBytes);
     1932    const uint64_t cTransferTicks = PDMDevHlpTimerFromMicro(pDevIns, RT_SAFE_SUBSCRIPT8(pThis->ahTimers, pStream->u8SD), usBytes);
    19351933
    19361934    Log3Func(("[SD%RU8] Timer %uHz, cbBytes=%RU32 -> usBytes=%RU64, cTransferTicks=%RU64\n",
     
    19431941 * Updates the next transfer based on a specific amount of bytes.
    19441942 *
     1943 * @param   pDevIns             The device instance.
    19451944 * @param   pThis               AC'97 device state.
    19461945 * @param   pStream             AC'97 stream to update.
    19471946 * @param   cbBytes             Bytes to update next transfer for.
    19481947 */
    1949 static void ichac97R3StreamTransferUpdate(PAC97STATE pThis, PAC97STREAM pStream, uint32_t cbBytes)
     1948static void ichac97R3StreamTransferUpdate(PPDMDEVINS pDevIns, PAC97STATE pThis, PAC97STREAM pStream, uint32_t cbBytes)
    19501949{
    19511950    if (!cbBytes)
     
    19571956
    19581957    /* Update the transfer ticks. */
    1959     pStream->State.cTransferTicks = ichac97R3StreamTransferCalcNext(pThis, pStream, pStream->State.cbTransferChunk);
     1958    pStream->State.cTransferTicks = ichac97R3StreamTransferCalcNext(pDevIns, pThis, pStream, pStream->State.cbTransferChunk);
    19601959    Assert(pStream->State.cTransferTicks); /* Paranoia. */
    19611960}
     
    25992598    AssertPtr(pStream);
    26002599    Assert(PDMDevHlpCritSectIsOwner(pDevIns, &pThis->CritSect));
    2601     Assert(TMTimerIsLockOwner((pThis)->DEVAC97_CTX_SUFF_SD(pTimer, pStream->u8SD)));
     2600    Assert(PDMDevHlpTimerIsLockOwner(pDevIns, RT_SAFE_SUBSCRIPT8(pThis->ahTimers, pStream->u8SD)));
    26022601
    26032602    ichac97R3StreamUpdate(pThis, pStream, true /* fInTimer */);
     
    26062605    if (pSink && AudioMixerSinkIsActive(pSink))
    26072606    {
    2608         ichac97R3StreamTransferUpdate(pThis, pStream, pStream->Regs.picb << 1); /** @todo r=andy Assumes 16-bit samples. */
    2609 
    2610         ichac97TimerSet(pThis, pStream,
    2611                         TMTimerGet((pThis)->DEVAC97_CTX_SUFF_SD(pTimer, pStream->u8SD)) + pStream->State.cTransferTicks,
     2607        ichac97R3StreamTransferUpdate(pDevIns, pThis, pStream, pStream->Regs.picb << 1); /** @todo r=andy Assumes 16-bit samples. */
     2608
     2609        ichac97TimerSet(pDevIns, pThis, pStream,
     2610                          PDMDevHlpTimerGet(pDevIns, RT_SAFE_SUBSCRIPT8(pThis->ahTimers, pStream->u8SD))
     2611                        + pStream->State.cTransferTicks,
    26122612                        false /* fForce */);
    26132613    }
     
    26222622 *
    26232623 * @returns Whether the new expiration time was set or not.
     2624 * @param   pDevIns             The device instance.
    26242625 * @param   pThis               AC'97 state.
    26252626 * @param   pStream             AC'97 stream to set timer for.
     
    26362637 *          Forcing a new expiration time will override the above mechanism.
    26372638 */
    2638 bool ichac97TimerSet(PAC97STATE pThis, PAC97STREAM pStream, uint64_t tsExpire, bool fForce)
     2639static bool ichac97TimerSet(PPDMDEVINS pDevIns, PAC97STATE pThis, PAC97STREAM pStream, uint64_t tsExpire, bool fForce)
    26392640{
    26402641    AssertPtrReturn(pThis, false);
     
    26452646    uint64_t tsExpireMin = tsExpire;
    26462647
    2647     AssertPtr((pThis)->DEVAC97_CTX_SUFF_SD(pTimer, pStream->u8SD));
    2648 
    2649     const uint64_t tsNow = TMTimerGet((pThis)->DEVAC97_CTX_SUFF_SD(pTimer, pStream->u8SD));
     2648    TMTIMERHANDLE const hTimer = RT_SAFE_SUBSCRIPT8(pThis->ahTimers, pStream->u8SD);
     2649    /** @todo r=bird: This is rather silly given that all three callers just did
     2650     *        TimerGet + interval. */
     2651    const uint64_t tsNow = PDMDevHlpTimerGet(pDevIns, hTimer);
    26502652
    26512653    /* Make sure to not go backwards in time, as this will assert in TMTimerSet(). */
     
    26532655        tsExpireMin = tsNow;
    26542656
    2655     int rc = TMTimerSet((pThis)->DEVAC97_CTX_SUFF_SD(pTimer, pStream->u8SD), tsExpireMin);
    2656     AssertRC(rc);
    2657 
    2658     return RT_SUCCESS(rc);
     2657    int rc = PDMDevHlpTimerSet(pDevIns, hTimer, tsExpireMin);
     2658    AssertRCReturn(rc, false);
     2659
     2660    return true;
    26592661}
    26602662
     
    31463148
    31473149                            /* Arm the timer for this stream. */
    3148                             int rc2 = ichac97TimerSet(pThis, pStream,
    3149                                                       TMTimerGet((pThis)->DEVAC97_CTX_SUFF_SD(pTimer, pStream->u8SD)) + pStream->State.cTransferTicks,
     3150                            /** @todo r=bird: This function returns bool, not VBox status! */
     3151                            int rc2 = ichac97TimerSet(pDevIns, pThis, pStream,
     3152                                                        PDMDevHlpTimerGet(pDevIns, RT_SAFE_SUBSCRIPT8(pThis->ahTimers,
     3153                                                                                                      pStream->u8SD))
     3154                                                      + pStream->State.cTransferTicks,
    31503155                                                      false /* fForce */);
    31513156                            AssertRC(rc2);
     
    36413646        {
    36423647            /* Re-arm the timer for this stream. */
    3643             rc2 = ichac97TimerSet(pThis, pStream,
    3644                                   TMTimerGet((pThis)->DEVAC97_CTX_SUFF_SD(pTimer, pStream->u8SD)) + pStream->State.cTransferTicks,
     3648            /** @todo r=bird: This function returns bool, not VBox status! */
     3649            rc2 = ichac97TimerSet(pDevIns, pThis, pStream,
     3650                                    PDMDevHlpTimerGet(pDevIns, RT_SAFE_SUBSCRIPT8(pThis->ahTimers, pStream->u8SD))
     3651                                  + pStream->State.cTransferTicks,
    36453652                                  false /* fForce */);
    36463653        }
     
    39493956    PAC97STATE pThis = PDMDEVINS_2_DATA(pDevIns, PAC97STATE);
    39503957    pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
    3951 
    3952     for (unsigned i = 0; i < AC97_MAX_STREAMS; i++)
    3953         pThis->pTimerRC[i] = TMTimerRCPtr(pThis->pTimerR3[i]);
    39543958}
    39553959
     
    42654269    ichac97R3Reset(pDevIns);
    42664270
    4267     static const char * const s_apszNames[] =
    4268     {
    4269         "AC97 PI", "AC97 PO", "AC97 MC"
    4270     };
     4271    /*
     4272     * Create the emulation timers (one per stream).
     4273     *
     4274     * We must the critical section for the timers as the device has a
     4275     * noop section associated with it.
     4276     *
     4277     * Note:  Use TMCLOCK_VIRTUAL_SYNC here, as the guest's AC'97 driver
     4278     *        relies on exact (virtual) DMA timing and uses DMA Position Buffers
     4279     *        instead of the LPIB registers.
     4280     */
     4281    static const char * const s_apszNames[] = { "AC97 PI", "AC97 PO", "AC97 MC" };
    42714282    AssertCompile(RT_ELEMENTS(s_apszNames) == AC97_MAX_STREAMS);
    4272 
     4283    AssertCompile(RT_ELEMENTS(pThis->ahTimers) == AC97_MAX_STREAMS);
    42734284    for (unsigned i = 0; i < AC97_MAX_STREAMS; i++)
    42744285    {
    4275         /* Create the emulation timer (per stream).
    4276          *
    4277          * Note:  Use TMCLOCK_VIRTUAL_SYNC here, as the guest's AC'97 driver
    4278          *        relies on exact (virtual) DMA timing and uses DMA Position Buffers
    4279          *        instead of the LPIB registers.
    4280          */
    4281         rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, ichac97R3Timer, &pThis->aStreams[i],
    4282                                     TMTIMER_FLAGS_NO_CRIT_SECT, s_apszNames[i], &pThis->pTimerR3[i]);
     4286        rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, ichac97R3Timer, &pThis->aStreams[i],
     4287                                  TMTIMER_FLAGS_NO_CRIT_SECT, s_apszNames[i], &pThis->ahTimers[i]);
    42834288        AssertRCReturn(rc, rc);
    4284         pThis->pTimerR0[i] = TMTimerR0Ptr(pThis->pTimerR3[i]);
    4285         pThis->pTimerRC[i] = TMTimerRCPtr(pThis->pTimerR3[i]);
    4286 
    4287         /* Use our own critcal section for the device timer.
    4288          * That way we can control more fine-grained when to lock what. */
    4289         rc = TMR3TimerSetCritSect(pThis->pTimerR3[i], &pThis->CritSect);
     4289
     4290        rc = PDMDevHlpTimerSetCritSect(pDevIns, pThis->ahTimers[i], &pThis->CritSect);
    42904291        AssertRCReturn(rc, rc);
    42914292    }
  • trunk/src/VBox/Devices/Audio/HDAStream.cpp

    r82323 r82324  
    11101110                     *
    11111111                     * I know, the following code is horribly slow, but seems to work for now.
    1112                      ** @todo Optimize channel data extraction! Use some SSE(3) / intrinsics?
    11131112                     */
     1113                    /** @todo Optimize channel data extraction! Use some SSE(3) / intrinsics? */
    11141114                    for (unsigned m = 0; m < pStream->State.Mapping.cMappings; m++)
    11151115                    {
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