VirtualBox

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


Ignore:
Timestamp:
Nov 22, 2010 7:58:14 AM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
67974
Message:

Audio/HDA: some reorganization.

File:
1 edited

Legend:

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

    r34228 r34229  
    12991299}
    13001300
     1301#ifdef LOG_ENABLED
    13011302static void dump_bd(INTELHDLinkState *pState, PHDABDLEDESC pBdle, uint64_t u64BaseDMA)
    13021303{
     
    13261327    }
    13271328}
     1329#endif
     1330
    13281331static void fetch_bd(INTELHDLinkState *pState, PHDABDLEDESC pBdle, uint64_t u64BaseDMA)
    13291332{
     
    13341337    pBdle->u32BdleCviLen = *(uint32_t *)&bdle[8];
    13351338    pBdle->fBdleCviIoc = (*(uint32_t *)&bdle[12]) & 0x1;
     1339#ifdef LOG_ENABLED
    13361340    dump_bd(pState, pBdle, u64BaseDMA);
     1341#endif
     1342}
     1343
     1344static inline uint32_t hdaCalculateDMABufferLength(PHDABDLEDESC pBdle, uint32_t u32SoundBackendBufferBytesAvail, uint32_t u32Fifos, uint32_t u32CblLimit)
     1345{
     1346    uint32_t cb2Copy;
     1347    /*
     1348     * Amounts of bytes depends on current position in buffer (u32BdleCviLen-u32BdleCviPos)
     1349     */
     1350    Assert((pBdle->u32BdleCviLen >= pBdle->u32BdleCviPos)); /* sanity */
     1351    cb2Copy = pBdle->u32BdleCviLen - pBdle->u32BdleCviPos;
     1352    /*
     1353     * we may increase the counter in range of [0, FIFOS + 1]
     1354     */
     1355    cb2Copy = RT_MIN(cb2Copy, u32Fifos + 1);
     1356    Assert((u32SoundBackendBufferBytesAvail > 0));
     1357
     1358    /* sanity check to avoid overriding sound backend buffer */
     1359    cb2Copy = RT_MIN(cb2Copy, u32SoundBackendBufferBytesAvail);
     1360    cb2Copy = RT_MIN(cb2Copy, u32CblLimit);
     1361
     1362    if (cb2Copy <= pBdle->cbUnderFifoW)
     1363        return 0;
     1364    cb2Copy -= pBdle->cbUnderFifoW; /* forcely reserve amount of ureported bytes to copy */
     1365    return cb2Copy;
    13371366}
    13381367
     
    13441373    uint32_t cbBackendCopy = 0;
    13451374
    1346     if (   !pBdle->u32BdleCviLen
    1347         || (*pu32Avail < hdaFifoWToSz(pState, 0)))
     1375    Log(("hda:ra: CVI(pos:%d, len:%d)\n", pBdle->u32BdleCviPos, pBdle->u32BdleCviLen));
     1376
     1377    cb2Copy = hdaCalculateDMABufferLength(pBdle, *pu32Avail, SDFIFOS(pState, 0), u32CblLimit);
     1378    if (!cb2Copy)
    13481379    {
    13491380        *fStop = true;
    1350         goto done;
    1351     }
    1352 
    1353     Log(("hda:ra: CVI(pos:%d, len:%d)\n", pBdle->u32BdleCviPos, pBdle->u32BdleCviLen));
    1354     Assert((pBdle->u32BdleCviLen >= pBdle->u32BdleCviPos)); /* sanity */
    1355     cb2Copy = pBdle->u32BdleCviLen - pBdle->u32BdleCviPos;
    1356     /*
    1357      * we may increase the counter in range of [0, FIFOS(pState, 4) + 1]
    1358      */
    1359     cb2Copy = RT_MIN(cb2Copy, SDFIFOS(pState, 0) + 1);
    1360     Assert((*pu32Avail > 0));
    1361 
    1362     /* sanity check to avoid overriding sound backend buffer */
    1363     cb2Copy = RT_MIN(cb2Copy, *pu32Avail);
    1364     cb2Copy = RT_MIN(cb2Copy, u32CblLimit);
    1365 
    1366     if (cb2Copy <= pBdle->cbUnderFifoW)
    1367     {
    1368         *fStop = true;
    1369         goto done;
    1370     }
    1371     cb2Copy -= pBdle->cbUnderFifoW;
    1372 
     1381        return 0;
     1382    }
     1383       
     1384   
    13731385    /*
    13741386     * read from backend input line
     
    13981410        goto done;
    13991411    }
    1400     Log(("hda:ra: CVI(pos:%d, len:%d)\n", pBdle->u32BdleCviPos, pBdle->u32BdleCviLen));
    14011412    done:
    14021413    Assert((cbTransfered <= (SDFIFOS(pState, 0) + 1)));
    1403     Log(("hda:ra: cbTransfered: %d\n", cbTransfered));
     1414    Log(("hda:ra: CVI(pos:%d, len:%d) cbTransfered: %d\n", pBdle->u32BdleCviPos, pBdle->u32BdleCviLen, cbTransfered));
    14041415    return cbTransfered;
    14051416}
     
    14141425    Log(("hda:wa: CVI(cvi:%d, pos:%d, len:%d)\n", pBdle->u32BdleCvi, pBdle->u32BdleCviPos, pBdle->u32BdleCviLen));
    14151426
    1416     /*
    1417      * Amounts of bytes depends on current position in buffer (u32BdleCviLen-u32BdleCviPos)
    1418      */
    1419     if (pBdle->u32BdleCviLen)
    1420     {
    1421         Assert((pBdle->u32BdleCviLen >= pBdle->u32BdleCviPos)); /* sanity */
    1422         cb2Copy = pBdle->u32BdleCviLen - pBdle->u32BdleCviPos; /* align copy buffer to size of trailing space in BDLE buffer */
    1423         cb2Copy = RT_MIN(cb2Copy, SDFIFOS(pState, 4) + 1); /* we may increase the counter in range of [0, FIFOS(pState, 4) + 1] */
    1424         cb2Copy = RT_MIN(cb2Copy, *pu32Avail); /* align copying buffer size up to size of back end buffer */
    1425         cb2Copy = RT_MIN(cb2Copy, u32CblLimit); /* avoid LCBL overrun */
    1426     }
    1427     if (cb2Copy <= pBdle->cbUnderFifoW)
    1428     {
    1429         Log(("hda:wa: amount of unreported bytes is less than room may be transfered  (cbUnderFifoW:%d < %d)\n", pBdle->cbUnderFifoW, cb2Copy));
    1430         *fStop = true;
    1431         goto done;
    1432     }
    1433     cb2Copy -= pBdle->cbUnderFifoW; /* force reserve "Unreported bits" */
     1427    cb2Copy = hdaCalculateDMABufferLength(pBdle, *pu32Avail, SDFIFOS(pState, 4), u32CblLimit);
    14341428   
    14351429    /*
     
    14391433        PDMDevHlpPhysRead(ICH6_HDASTATE_2_DEVINS(pState), pBdle->u64BdleCviAddr + pBdle->u32BdleCviPos, pBdle->au8HdaBuffer + pBdle->cbUnderFifoW, cb2Copy);
    14401434    /*
    1441      * Write to audio backend.
     1435     * Write to audio backend. we should be sure whether we have enought bytes to copy to Audio backend.
    14421436     */
    14431437    if (cb2Copy + pBdle->cbUnderFifoW >= hdaFifoWToSz(pState, 4))
     
    14661460    else
    14671461    {
     1462        /* Not enough bytes to be processed and reported, check luck on next enterence */
    14681463        Log(("hda:wa: CVI (cbUnderFifoW:%d, pos:%d, len:%d)\n", pBdle->cbUnderFifoW, pBdle->u32BdleCviPos, pBdle->u32BdleCviLen));
    14691464        pBdle->cbUnderFifoW += cb2Copy;
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