VirtualBox

Ignore:
Timestamp:
Jun 24, 2021 10:37:29 AM (3 years ago)
Author:
vboxsync
Message:

DevHda: Kicked out the disabled bounce buffer stuff from hdaR3StreamDoDmaOutput. The assumption is that we won't need it for misaligned guest buffers either, given that pCircBuf is between us and the more frame oriented audio stack. bugref:9890

File:
1 edited

Legend:

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

    r89879 r89880  
    345345        }
    346346    }
    347     AssertLogRelMsgReturn(cbBorrow == 0, ("HDA: Internal scheduling error on stream #%u: cbBorrow=%#x cbTotal=%#x cbCur=%#x\n",
    348                                           pStreamShared->u8SD, cbBorrow, cbTotal, cbCur),
    349                           VERR_INTERNAL_ERROR_3);
    350347
    351348    /*
     
    414411
    415412        }
    416         Assert(cbBorrow == 0);
    417413    }
    418414    else if (cbCur)
     
    435431        pStreamShared->State.cSchedulePrologue = (uint8_t)cPotentialPrologue;
    436432    }
     433
     434    AssertLogRelMsgReturn(cbBorrow == 0, ("HDA: Internal scheduling error on stream #%u: cbBorrow=%#x cbTotal=%#x cbCur=%#x\n",
     435                                          pStreamShared->u8SD, cbBorrow, cbTotal, cbCur),
     436                          VERR_INTERNAL_ERROR_3);
    437437
    438438    /*
     
    16341634     * The DMA copy loop.
    16351635     *
    1636      */
    1637 # if 0
    1638     uint8_t    abBounce[4096 + 128];    /* Most guest does at most 4KB BDLE. So, 4KB + space for a partial frame to reduce loops. */
    1639     uint32_t   cbBounce = 0;            /* in case of incomplete frames between buffer segments */
    1640 # endif
     1636     * Note! Unaligned BDLEs shouldn't be a problem since the circular buffer
     1637     *       doesn't care about alignment.  Only, we have to write the rest
     1638     *       of the incomplete frame to it ASAP.
     1639     */
    16411640    PRTCIRCBUF pCircBuf = pStreamR3->State.pCircBuf;
    16421641    uint32_t   cbLeft   = cbToProduce;
     
    16581657        RTGCPHYS GCPhys  = hdaStreamDmaBufGet(pStreamShared, &cbChunk);
    16591658
    1660         /* Need to diverge if the BDLEs contain misaligned entries.  */
     1659        if (cbChunk <= cbLeft)
     1660        { /* very likely */ }
     1661        else
     1662            cbChunk = cbLeft;
     1663
     1664        /*
     1665         * Read the guest data directly into the internal DMA buffer.
     1666         */
    16611667        uint32_t cbRead  = 0;
    1662 # if 0
    1663         if (/** @todo pStreamShared->State.fFrameAlignedBuffers */)
     1668        while (cbChunk > 0)
     1669        {
     1670            /* Grab internal DMA buffer space and read into it. */
     1671            void  *pvBufDst;
     1672            size_t cbBufDst;
     1673            RTCircBufAcquireWriteBlock(pCircBuf, cbChunk, &pvBufDst, &cbBufDst);
     1674            AssertBreakStmt(cbBufDst, RTCircBufReleaseWriteBlock(pCircBuf, 0));
     1675
     1676            int rc2 = PDMDevHlpPCIPhysRead(pDevIns, GCPhys, pvBufDst, cbBufDst);
     1677            AssertRC(rc2);
     1678
     1679# ifdef HDA_DEBUG_SILENCE
     1680            fix me if relevant;
    16641681# endif
    1665         {
    1666             if (cbChunk <= cbLeft)
    1667             { /* very likely */ }
     1682            if (RT_LIKELY(!pStreamR3->Dbg.Runtime.fEnabled))
     1683            { /* likely */ }
    16681684            else
    1669                 cbChunk = cbLeft;
    1670 
    1671             /*
    1672              * Read the guest data directly into the internal DMA buffer.
    1673              */
    1674             while (cbChunk > 0)
    1675             {
    1676                 /* Grab internal DMA buffer space and read into it. */
    1677                 void  *pvBufDst;
    1678                 size_t cbBufDst;
    1679                 RTCircBufAcquireWriteBlock(pCircBuf, cbChunk, &pvBufDst, &cbBufDst);
    1680                 AssertBreakStmt(cbBufDst, RTCircBufReleaseWriteBlock(pCircBuf, 0));
    1681 
    1682                 int rc2 = PDMDevHlpPCIPhysRead(pDevIns, GCPhys, pvBufDst, cbBufDst);
    1683                 AssertRC(rc2);
    1684 
    1685 # ifdef HDA_DEBUG_SILENCE
    1686                 fix me if relevant;
     1685                AudioHlpFileWrite(pStreamR3->Dbg.Runtime.pFileDMARaw, pvBufDst, cbBufDst, 0 /* fFlags */);
     1686
     1687# ifdef VBOX_WITH_DTRACE
     1688            VBOXDD_HDA_STREAM_DMA_OUT((uint32_t)uSD, (uint32_t)cbBufDst, pStreamShared->State.offWrite);
    16871689# endif
    1688                 if (RT_LIKELY(!pStreamR3->Dbg.Runtime.fEnabled))
    1689                 { /* likely */ }
    1690                 else
    1691                     AudioHlpFileWrite(pStreamR3->Dbg.Runtime.pFileDMARaw, pvBufDst, cbBufDst, 0 /* fFlags */);
    1692 
    1693 # ifdef VBOX_WITH_DTRACE
    1694                 VBOXDD_HDA_STREAM_DMA_OUT((uint32_t)uSD, (uint32_t)cbBufDst, pStreamShared->State.offWrite);
    1695 # endif
    1696                 pStreamShared->State.offWrite   += cbBufDst;
    1697                 RTCircBufReleaseWriteBlock(pCircBuf, cbBufDst);
    1698                 STAM_COUNTER_ADD(&pThis->StatBytesRead, cbBufDst);
    1699 
    1700                 /* advance */
    1701                 cbChunk                         -= (uint32_t)cbBufDst;
    1702                 cbRead                          += (uint32_t)cbBufDst;
    1703                 GCPhys                          +=           cbBufDst;
    1704                 pStreamShared->State.offCurBdle += (uint32_t)cbBufDst;
    1705             }
    1706         }
    1707 # if 0
    1708         /*
    1709          * Need to map the frame content, so we need to read the guest data
    1710          * into a temporary buffer, though the output can be directly written
    1711          * into the internal buffer as it is assumed to be frame aligned.
    1712          *
    1713          * Note! cbLeft is relative to the output frame size.
    1714          *       cbChunk OTOH is relative to input size.
    1715          */
    1716         else
    1717         {
    1718 /** @todo clean up host/guest props distinction, they're the same now w/o the
    1719  *        mapping done by the mixer rather than us.  */
    1720             PCPDMAUDIOPCMPROPS pGuestProps = &pStreamShared->State.Cfg.Props;
    1721             Assert(PDMAudioPropsIsSizeAligned(&pStreamShared->State.Cfg.Props, cbLeft));
    1722             uint32_t const cbLeftGuest = PDMAudioPropsFramesToBytes(pGuestProps,
    1723                                                                     PDMAudioPropsBytesToFrames(&pStreamShared->State.Cfg.Props,
    1724                                                                                                cbLeft));
    1725             if (cbChunk <= cbLeftGuest)
    1726             { /* very likely */ }
    1727             else
    1728                 cbChunk = cbLeftGuest;
    1729 
    1730             /*
    1731              * Loop till we've covered the chunk.
    1732              */
    1733             Log5Func(("loop0:  GCPhys=%RGp cbChunk=%#x + cbBounce=%#x\n", GCPhys, cbChunk, cbBounce));
    1734             while (cbChunk > 0)
    1735             {
    1736                 /* Read into the bounce buffer. */
    1737                 uint32_t const cbToRead = RT_MIN(cbChunk, sizeof(abBounce) - cbBounce);
    1738                 int rc2 = PDMDevHlpPCIPhysRead(pDevIns, GCPhys, &abBounce[cbBounce], cbToRead);
    1739                 AssertRC(rc2);
    1740                 cbBounce += cbToRead;
    1741 
    1742                 /* Convert the size to whole frames and a remainder. */
    1743                 uint32_t cFrames = PDMAudioPropsBytesToFrames(pGuestProps, cbBounce);
    1744                 uint32_t const cbRemainder = cbBounce - PDMAudioPropsFramesToBytes(pGuestProps, cFrames);
    1745                 Log5Func((" loop1: GCPhys=%RGp cbToRead=%#x cbBounce=%#x cFrames=%#x\n", GCPhys, cbToRead, cbBounce, cFrames));
    1746 
    1747                 /*
    1748                  * Convert from the bounce buffer and into the internal DMA buffer.
    1749                  */
    1750                 uint32_t offBounce = 0;
    1751                 while (cFrames > 0)
    1752                 {
    1753                     void  *pvBufDst;
    1754                     size_t cbBufDst;
    1755                     RTCircBufAcquireWriteBlock(pCircBuf, PDMAudioPropsFramesToBytes(&pStreamShared->State.Cfg.Props, cFrames),
    1756                                                &pvBufDst, &cbBufDst);
    1757 
    1758                     uint32_t const cFramesToConvert = PDMAudioPropsBytesToFrames(&pStreamShared->State.Cfg.Props, (uint32_t)cbBufDst);
    1759                     Assert(PDMAudioPropsFramesToBytes(&pStreamShared->State.Cfg.Props, cFramesToConvert) == cbBufDst);
    1760                     Assert(cFramesToConvert > 0);
    1761                     Assert(cFramesToConvert <= cFrames);
    1762 
    1763                     pStreamR3->State.Mapping.pfnGuestToHost(pvBufDst, &abBounce[offBounce], cFramesToConvert,
    1764                                                             &pStreamR3->State.Mapping);
    1765                     Log5Func(("  loop2: offBounce=%#05x cFramesToConvert=%#05x cbBufDst=%#x%s\n",
    1766                               offBounce, cFramesToConvert, cbBufDst, ASMMemIsZero(pvBufDst, cbBufDst) ? " all zero" : ""));
    1767 
    1768 #  ifdef HDA_DEBUG_SILENCE
    1769                     fix me if relevant;
    1770 #  endif
    1771                     if (RT_LIKELY(!pStreamR3->Dbg.Runtime.fEnabled))
    1772                     { /* likely */ }
    1773                     else
    1774                         AudioHlpFileWrite(pStreamR3->Dbg.Runtime.pFileDMARaw, pvBufDst, cbBufDst, 0 /* fFlags */);
    1775 
    1776                     pStreamR3->State.offWrite += cbBufDst;
    1777                     RTCircBufReleaseWriteBlock(pCircBuf, cbBufDst);
    1778                     STAM_COUNTER_ADD(&pThis->StatBytesRead, cbBufDst);
    1779 
    1780                     /* advance */
    1781                     cbLeft    -= (uint32_t)cbBufDst;
    1782                     cFrames   -= cFramesToConvert;
    1783                     offBounce += PDMAudioPropsFramesToBytes(pGuestProps, cFramesToConvert);
    1784                 }
    1785 
    1786                 /* advance */
    1787                 cbChunk                         -= cbToRead;
    1788                 GCPhys                          += cbToRead;
    1789                 pStreamShared->State.offCurBdle += cbToRead;
    1790                 if (cbRemainder)
    1791                     memmove(&abBounce[0], &abBounce[cbBounce - cbRemainder], cbRemainder);
    1792                 cbBounce = cbRemainder;
    1793             }
    1794             Log5Func(("loop0: GCPhys=%RGp cbBounce=%#x cbLeft=%#x\n", GCPhys, cbBounce, cbLeft));
    1795         }
    1796 # endif
     1690            pStreamShared->State.offWrite   += cbBufDst;
     1691            RTCircBufReleaseWriteBlock(pCircBuf, cbBufDst);
     1692            STAM_COUNTER_ADD(&pThis->StatBytesRead, cbBufDst);
     1693
     1694            /* advance */
     1695            cbChunk                         -= (uint32_t)cbBufDst;
     1696            cbRead                          += (uint32_t)cbBufDst;
     1697            GCPhys                          +=           cbBufDst;
     1698            pStreamShared->State.offCurBdle += (uint32_t)cbBufDst;
     1699        }
    17971700
    17981701        cbLeft -= cbRead;
     
    18131716
    18141717    Assert(cbLeft == 0); /* There shall be no break statements in the above loop, so cbLeft is always zero here! */
    1815 # if 0
    1816     AssertMsg(cbBounce == 0, ("%#x\n", cbBounce));
    1817 # endif
    18181718
    18191719    /*
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