VirtualBox

Ignore:
Timestamp:
Oct 9, 2019 12:09:24 PM (5 years ago)
Author:
vboxsync
Message:

Audio/HDA: Added more SD register checks (bugref:9569).

File:
1 edited

Legend:

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

    r80692 r81181  
    2626#include <iprt/semaphore.h>
    2727
     28#include <VBox/AssertGuest.h>
    2829#include <VBox/vmm/pdmdev.h>
    2930#include <VBox/vmm/pdmaudioifs.h>
     
    239240    AssertRCReturn(rc, rc);
    240241
     242    ASSERT_GUEST_LOGREL_MSG_RETURN(u32CBL % pStream->State.Mapping.cbFrameSize == 0,
     243                                   ("CBL for stream #%RU8 does not align to frame size\n", pStream->u8SD),
     244                                   VERR_INVALID_PARAMETER);
     245
    241246    /*
    242247     * Set the stream's timer Hz rate, based on the stream channel count.
     
    344349             pStream->u8SD, pStream->u64BDLBase, pStream->u32CBL, pStream->u16LVI, pStream->u16FIFOS));
    345350
    346     /* Make sure that mandatory parameters are set up correctly. */
    347     AssertStmt(pStream->u32CBL %  pStream->State.Mapping.cbFrameSize == 0, rc = VERR_INVALID_PARAMETER);
    348     AssertStmt(pStream->u16LVI >= 1,                                       rc = VERR_INVALID_PARAMETER);
    349 
    350351    if (RT_SUCCESS(rc))
    351352    {
     
    357358        /* Figure out how many transfer fragments we're going to use for this stream. */
    358359        /** @todo Use a more dynamic fragment size? */
    359         Assert(pStream->u16LVI <= UINT8_MAX - 1);
    360360        uint8_t cFragments = pStream->u16LVI + 1;
    361361        if (cFragments <= 1)
     
    446446        Assert(pStream->State.cbTransferSize);
    447447        Assert(pStream->State.cbTransferSize % pStream->State.Mapping.cbFrameSize == 0);
    448 
    449         /* Calculate the bytes we need to transfer to / from the stream's DMA per iteration.
    450          * This is bound to the device's Hz rate and thus to the (virtual) timing the device expects. */
    451         pStream->State.cbTransferChunk = (pStream->State.Cfg.Props.uHz / pStream->State.uTimerHz) * pStream->State.Mapping.cbFrameSize;
    452         Assert(pStream->State.cbTransferChunk);
    453         Assert(pStream->State.cbTransferChunk % pStream->State.Mapping.cbFrameSize == 0);
    454 
    455         /* Make sure that the transfer chunk does not exceed the overall transfer size. */
    456         if (pStream->State.cbTransferChunk > pStream->State.cbTransferSize)
    457             pStream->State.cbTransferChunk = pStream->State.cbTransferSize;
    458 
    459         const uint64_t cTicksPerHz = TMTimerGetFreq(pStream->pTimer) / pStream->State.uTimerHz;
    460 
    461         /* Calculate the timer ticks per byte for this stream. */
    462         pStream->State.cTicksPerByte = cTicksPerHz / pStream->State.cbTransferChunk;
    463         Assert(pStream->State.cTicksPerByte);
    464 
    465         /* Calculate timer ticks per transfer. */
    466         pStream->State.cTransferTicks     = pStream->State.cbTransferChunk * pStream->State.cTicksPerByte;
    467         Assert(pStream->State.cTransferTicks);
    468 
    469         LogFunc(("[SD%RU8] Timer %uHz (%RU64 ticks per Hz), cTicksPerByte=%RU64, cbTransferChunk=%RU32, cTransferTicks=%RU64, " \
    470                  "cbTransferSize=%RU32\n",
    471                  pStream->u8SD, pStream->State.uTimerHz, cTicksPerHz, pStream->State.cTicksPerByte,
    472                  pStream->State.cbTransferChunk, pStream->State.cTransferTicks, pStream->State.cbTransferSize));
    473 
    474         /* Make sure to also update the stream's DMA counter (based on its current LPIB value). */
    475         hdaR3StreamSetPosition(pStream, HDA_STREAM_REG(pThis, LPIB, pStream->u8SD));
     448        ASSERT_GUEST_LOGREL_MSG_STMT(pStream->State.cbTransferSize,
     449                                     ("Transfer size for stream #%RU8 is invalid\n", pStream->u8SD), rc = VERR_INVALID_PARAMETER);
     450        if (RT_SUCCESS(rc))
     451        {
     452            /* Calculate the bytes we need to transfer to / from the stream's DMA per iteration.
     453             * This is bound to the device's Hz rate and thus to the (virtual) timing the device expects. */
     454            pStream->State.cbTransferChunk = (pStream->State.Cfg.Props.uHz / pStream->State.uTimerHz) * pStream->State.Mapping.cbFrameSize;
     455            Assert(pStream->State.cbTransferChunk);
     456            Assert(pStream->State.cbTransferChunk % pStream->State.Mapping.cbFrameSize == 0);
     457            ASSERT_GUEST_LOGREL_MSG_STMT(pStream->State.cbTransferChunk,
     458                                         ("Transfer chunk for stream #%RU8 is invalid\n", pStream->u8SD),
     459                                         rc = VERR_INVALID_PARAMETER);
     460            if (RT_SUCCESS(rc))
     461            {
     462                /* Make sure that the transfer chunk does not exceed the overall transfer size. */
     463                if (pStream->State.cbTransferChunk > pStream->State.cbTransferSize)
     464                    pStream->State.cbTransferChunk = pStream->State.cbTransferSize;
     465
     466                const uint64_t cTicksPerHz = TMTimerGetFreq(pStream->pTimer) / pStream->State.uTimerHz;
     467
     468                /* Calculate the timer ticks per byte for this stream. */
     469                pStream->State.cTicksPerByte = cTicksPerHz / pStream->State.cbTransferChunk;
     470                Assert(pStream->State.cTicksPerByte);
     471
     472                /* Calculate timer ticks per transfer. */
     473                pStream->State.cTransferTicks = pStream->State.cbTransferChunk * pStream->State.cTicksPerByte;
     474                Assert(pStream->State.cTransferTicks);
     475
     476                LogFunc(("[SD%RU8] Timer %uHz (%RU64 ticks per Hz), cTicksPerByte=%RU64, cbTransferChunk=%RU32, " \
     477                         "cTransferTicks=%RU64, cbTransferSize=%RU32\n",
     478                         pStream->u8SD, pStream->State.uTimerHz, cTicksPerHz, pStream->State.cTicksPerByte,
     479                         pStream->State.cbTransferChunk, pStream->State.cTransferTicks, pStream->State.cbTransferSize));
     480
     481                /* Make sure to also update the stream's DMA counter (based on its current LPIB value). */
     482                hdaR3StreamSetPosition(pStream, HDA_STREAM_REG(pThis, LPIB, pStream->u8SD));
    476483
    477484#ifdef LOG_ENABLED
    478         hdaR3BDLEDumpAll(pThis, pStream->u64BDLBase, pStream->u16LVI + 1);
     485                hdaR3BDLEDumpAll(pThis, pStream->u64BDLBase, pStream->u16LVI + 1);
    479486#endif
     487            }
     488        }
    480489    }
    481490
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