Changeset 60942 in vbox for trunk/src/VBox/Devices/Audio/DevIchHda.cpp
- Timestamp:
- May 12, 2016 1:18:40 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DevIchHda.cpp
r60941 r60942 906 906 static int hdaRegWriteSDBDPL(PHDASTATE pThis, uint32_t iReg, uint32_t u32Value); 907 907 static int hdaRegWriteSDBDPU(PHDASTATE pThis, uint32_t iReg, uint32_t u32Value); 908 DECLINLINE(int) hdaRegWriteSDLock(PHDASTATE pThis, PHDASTREAM pStr mSt, uint32_t iReg, uint32_t u32Value);909 DECLINLINE(void) hdaRegWriteSDUnlock(PHDASTREAM pStr mSt);908 DECLINLINE(int) hdaRegWriteSDLock(PHDASTATE pThis, PHDASTREAM pStream, uint32_t iReg, uint32_t u32Value); 909 DECLINLINE(void) hdaRegWriteSDUnlock(PHDASTREAM pStream); 910 910 911 911 /* … … 922 922 923 923 #ifdef IN_RING3 924 static void hdaStreamDestroy(PHDASTREAM pStr mSt);924 static void hdaStreamDestroy(PHDASTREAM pStream); 925 925 static int hdaStreamSetActive(PHDASTATE pThis, PHDASTREAM pStream, bool fActive); 926 static int hdaStreamStart(PHDASTREAM pStr mSt);927 static int hdaStreamStop(PHDASTREAM pStr mSt);928 static int hdaStreamWaitForStateChange(PHDASTREAM pStr mSt, RTMSINTERVAL msTimeout);929 static int hdaTransfer(PHDASTATE pThis, PHDASTREAM pStr mSt, uint32_t cbToProcess, uint32_t *pcbProcessed);926 static int hdaStreamStart(PHDASTREAM pStream); 927 static int hdaStreamStop(PHDASTREAM pStream); 928 static int hdaStreamWaitForStateChange(PHDASTREAM pStream, RTMSINTERVAL msTimeout); 929 static int hdaTransfer(PHDASTATE pThis, PHDASTREAM pStream, uint32_t cbToProcess, uint32_t *pcbProcessed); 930 930 #endif 931 931 … … 938 938 #ifdef IN_RING3 939 939 static int hdaBDLEFetch(PHDASTATE pThis, PHDABDLE pBDLE, uint64_t u64BaseDMA, uint16_t u16Entry); 940 DECLINLINE(uint32_t) hdaStreamUpdateLPIB(PHDASTATE pThis, PHDASTREAM pStr mSt, uint32_t u32LPIB);940 DECLINLINE(uint32_t) hdaStreamUpdateLPIB(PHDASTATE pThis, PHDASTREAM pStream, uint32_t u32LPIB); 941 941 # ifdef LOG_ENABLED 942 942 static void hdaBDLEDumpAll(PHDASTATE pThis, uint64_t u64BaseDMA, uint16_t cBDLE); … … 1135 1135 1136 1136 #ifdef IN_RING3 1137 DECLINLINE(uint32_t) hdaStreamUpdateLPIB(PHDASTATE pThis, PHDASTREAM pStr mSt, uint32_t u32LPIB)1137 DECLINLINE(uint32_t) hdaStreamUpdateLPIB(PHDASTATE pThis, PHDASTREAM pStream, uint32_t u32LPIB) 1138 1138 { 1139 1139 AssertPtrReturn(pThis, 0); 1140 AssertPtrReturn(pStr mSt, 0);1141 1142 Assert(u32LPIB <= pStr mSt->u32CBL);1140 AssertPtrReturn(pStream, 0); 1141 1142 Assert(u32LPIB <= pStream->u32CBL); 1143 1143 1144 1144 LogFlowFunc(("[SD%RU8]: LPIB=%RU32 (DMA Position Buffer Enabled: %RTbool)\n", 1145 pStr mSt->u8SD, u32LPIB, pThis->fDMAPosition));1145 pStream->u8SD, u32LPIB, pThis->fDMAPosition)); 1146 1146 1147 1147 /* Update LPIB in any case. */ 1148 HDA_STREAM_REG(pThis, LPIB, pStr mSt->u8SD) = u32LPIB;1148 HDA_STREAM_REG(pThis, LPIB, pStream->u8SD) = u32LPIB; 1149 1149 1150 1150 /* Do we need to tell the current DMA position? */ … … 1152 1152 { 1153 1153 int rc2 = PDMDevHlpPCIPhysWrite(pThis->CTX_SUFF(pDevIns), 1154 (pThis->u64DPBase & DPBASE_ADDR_MASK) + (pStr mSt->u8SD * 2 * sizeof(uint32_t)),1154 (pThis->u64DPBase & DPBASE_ADDR_MASK) + (pStream->u8SD * 2 * sizeof(uint32_t)), 1155 1155 (void *)&u32LPIB, sizeof(uint32_t)); 1156 1156 AssertRC(rc2); … … 1323 1323 * @return Number of bytes accumulated/free in the FIFO. 1324 1324 */ 1325 DECLINLINE(uint8_t) hdaStreamGetFIFOW(PHDASTATE pThis, PHDASTREAM pStr mSt)1325 DECLINLINE(uint8_t) hdaStreamGetFIFOW(PHDASTATE pThis, PHDASTREAM pStream) 1326 1326 { 1327 1327 AssertPtrReturn(pThis, 0); 1328 AssertPtrReturn(pStr mSt, 0);1328 AssertPtrReturn(pStream, 0); 1329 1329 1330 1330 #ifdef VBOX_HDA_WITH_FIFO 1331 return hdaSDFIFOWToBytes(HDA_STREAM_REG(pThis, FIFOW, pStr mSt->u8SD));1331 return hdaSDFIFOWToBytes(HDA_STREAM_REG(pThis, FIFOW, pStream->u8SD)); 1332 1332 #else 1333 1333 return 0; … … 1601 1601 } 1602 1602 1603 static int hdaStreamCreate(PHDASTREAM pStr mSt, uint8_t uSD)1604 { 1605 AssertPtrReturn(pStr mSt, VERR_INVALID_POINTER);1603 static int hdaStreamCreate(PHDASTREAM pStream, uint8_t uSD) 1604 { 1605 AssertPtrReturn(pStream, VERR_INVALID_POINTER); 1606 1606 AssertReturn(uSD <= HDA_MAX_STREAMS, VERR_INVALID_PARAMETER); 1607 1607 1608 int rc = RTSemEventCreate(&pStr mSt->State.hStateChangedEvent);1608 int rc = RTSemEventCreate(&pStream->State.hStateChangedEvent); 1609 1609 if (RT_SUCCESS(rc)) 1610 rc = RTSemMutexCreate(&pStr mSt->State.hMtx);1610 rc = RTSemMutexCreate(&pStream->State.hMtx); 1611 1611 1612 1612 if (RT_SUCCESS(rc)) 1613 1613 { 1614 pStr mSt->u8SD = uSD;1615 pStr mSt->pMixSink = NULL;1616 1617 pStr mSt->State.fActive = false;1618 pStr mSt->State.fInReset = false;1619 pStr mSt->State.fDoStop = false;1614 pStream->u8SD = uSD; 1615 pStream->pMixSink = NULL; 1616 1617 pStream->State.fActive = false; 1618 pStream->State.fInReset = false; 1619 pStream->State.fDoStop = false; 1620 1620 } 1621 1621 … … 1624 1624 } 1625 1625 1626 static void hdaStreamDestroy(PHDASTREAM pStr mSt)1627 { 1628 AssertPtrReturnVoid(pStr mSt);1629 1630 LogFlowFunc(("[SD%RU8]: Destroying ...\n", pStr mSt->u8SD));1631 1632 int rc2 = hdaStreamStop(pStr mSt);1626 static void hdaStreamDestroy(PHDASTREAM pStream) 1627 { 1628 AssertPtrReturnVoid(pStream); 1629 1630 LogFlowFunc(("[SD%RU8]: Destroying ...\n", pStream->u8SD)); 1631 1632 int rc2 = hdaStreamStop(pStream); 1633 1633 AssertRC(rc2); 1634 1634 1635 hdaStreamMapDestroy(&pStr mSt->State.Mapping);1636 1637 if (pStr mSt->State.hMtx != NIL_RTSEMMUTEX)1638 { 1639 rc2 = RTSemMutexDestroy(pStr mSt->State.hMtx);1635 hdaStreamMapDestroy(&pStream->State.Mapping); 1636 1637 if (pStream->State.hMtx != NIL_RTSEMMUTEX) 1638 { 1639 rc2 = RTSemMutexDestroy(pStream->State.hMtx); 1640 1640 AssertRC(rc2); 1641 pStr mSt->State.hMtx = NIL_RTSEMMUTEX;1642 } 1643 1644 if (pStr mSt->State.hStateChangedEvent != NIL_RTSEMEVENT)1645 { 1646 rc2 = RTSemEventDestroy(pStr mSt->State.hStateChangedEvent);1641 pStream->State.hMtx = NIL_RTSEMMUTEX; 1642 } 1643 1644 if (pStream->State.hStateChangedEvent != NIL_RTSEMEVENT) 1645 { 1646 rc2 = RTSemEventDestroy(pStream->State.hStateChangedEvent); 1647 1647 AssertRC(rc2); 1648 pStr mSt->State.hStateChangedEvent = NIL_RTSEMEVENT;1648 pStream->State.hStateChangedEvent = NIL_RTSEMEVENT; 1649 1649 } 1650 1650 … … 1686 1686 } 1687 1687 1688 static void hdaStreamReset(PHDASTATE pThis, PHDASTREAM pStr mSt)1688 static void hdaStreamReset(PHDASTATE pThis, PHDASTREAM pStream) 1689 1689 { 1690 1690 AssertPtrReturnVoid(pThis); 1691 AssertPtrReturnVoid(pStr mSt);1692 1693 const uint8_t uSD = pStr mSt->u8SD;1691 AssertPtrReturnVoid(pStream); 1692 1693 const uint8_t uSD = pStream->u8SD; 1694 1694 1695 1695 #ifdef VBOX_STRICT … … 1703 1703 * Set reset state. 1704 1704 */ 1705 Assert(ASMAtomicReadBool(&pStr mSt->State.fInReset) == false); /* No nested calls. */1706 ASMAtomicXchgBool(&pStr mSt->State.fInReset, true);1705 Assert(ASMAtomicReadBool(&pStream->State.fInReset) == false); /* No nested calls. */ 1706 ASMAtomicXchgBool(&pStream->State.fInReset, true); 1707 1707 1708 1708 /* 1709 1709 * First, reset the internal stream state. 1710 1710 */ 1711 RT_ZERO(pStr mSt->State.BDLE);1712 pStr mSt->State.uCurBDLE = 0;1711 RT_ZERO(pStream->State.BDLE); 1712 pStream->State.uCurBDLE = 0; 1713 1713 1714 1714 /* … … 1732 1732 HDA_STREAM_REG(pThis, BDPL, uSD) = 0; 1733 1733 1734 int rc2 = hdaStreamInit(pThis, pStr mSt, uSD);1734 int rc2 = hdaStreamInit(pThis, pStream, uSD); 1735 1735 AssertRC(rc2); 1736 1736 … … 1739 1739 1740 1740 /* Exit reset state. */ 1741 ASMAtomicXchgBool(&pStr mSt->State.fInReset, false);1741 ASMAtomicXchgBool(&pStream->State.fInReset, false); 1742 1742 } 1743 1743 … … 1778 1778 } 1779 1779 1780 static void hdaStreamAssignToSink(PHDASTREAM pStr mSt, PHDAMIXERSINK pMixSink)1781 { 1782 AssertPtrReturnVoid(pStr mSt);1783 1784 int rc2 = RTSemMutexRequest(pStr mSt->State.hMtx, RT_INDEFINITE_WAIT);1780 static void hdaStreamAssignToSink(PHDASTREAM pStream, PHDAMIXERSINK pMixSink) 1781 { 1782 AssertPtrReturnVoid(pStream); 1783 1784 int rc2 = RTSemMutexRequest(pStream->State.hMtx, RT_INDEFINITE_WAIT); 1785 1785 if (RT_SUCCESS(rc2)) 1786 1786 { 1787 pStr mSt->pMixSink = pMixSink;1788 1789 rc2 = RTSemMutexRelease(pStr mSt->State.hMtx);1787 pStream->pMixSink = pMixSink; 1788 1789 rc2 = RTSemMutexRelease(pStream->State.hMtx); 1790 1790 AssertRC(rc2); 1791 1791 } 1792 1792 } 1793 1793 1794 static int hdaStreamStart(PHDASTREAM pStr mSt)1795 { 1796 AssertPtrReturn(pStr mSt, VERR_INVALID_POINTER);1797 1798 ASMAtomicXchgBool(&pStr mSt->State.fDoStop, false);1799 ASMAtomicXchgBool(&pStr mSt->State.fActive, true);1794 static int hdaStreamStart(PHDASTREAM pStream) 1795 { 1796 AssertPtrReturn(pStream, VERR_INVALID_POINTER); 1797 1798 ASMAtomicXchgBool(&pStream->State.fDoStop, false); 1799 ASMAtomicXchgBool(&pStream->State.fActive, true); 1800 1800 1801 1801 LogFlowFuncLeave(); … … 1803 1803 } 1804 1804 1805 static int hdaStreamStop(PHDASTREAM pStr mSt)1806 { 1807 AssertPtrReturn(pStr mSt, VERR_INVALID_POINTER);1805 static int hdaStreamStop(PHDASTREAM pStream) 1806 { 1807 AssertPtrReturn(pStream, VERR_INVALID_POINTER); 1808 1808 1809 1809 /* Already in stopped state? */ 1810 bool fActive = ASMAtomicReadBool(&pStr mSt->State.fActive);1810 bool fActive = ASMAtomicReadBool(&pStream->State.fActive); 1811 1811 if (!fActive) 1812 1812 return VINF_SUCCESS; … … 1816 1816 * Wait for the stream to stop. 1817 1817 */ 1818 ASMAtomicXchgBool(&pStr mSt->State.fDoStop, true);1819 1820 int rc = hdaStreamWaitForStateChange(pStr mSt, 60 * 1000 /* ms timeout */);1821 fActive = ASMAtomicReadBool(&pStr mSt->State.fActive);1818 ASMAtomicXchgBool(&pStream->State.fDoStop, true); 1819 1820 int rc = hdaStreamWaitForStateChange(pStream, 60 * 1000 /* ms timeout */); 1821 fActive = ASMAtomicReadBool(&pStream->State.fActive); 1822 1822 if ( /* Waiting failed? */ 1823 1823 RT_FAILURE(rc) … … 1827 1827 AssertRC(rc); 1828 1828 LogRel(("HDA: Warning: Unable to stop stream %RU8 (state: %s), rc=%Rrc\n", 1829 pStr mSt->u8Strm, fActive ? "active" : "stopped", rc));1829 pStream->u8Strm, fActive ? "active" : "stopped", rc)); 1830 1830 } 1831 1831 #else … … 1945 1945 } 1946 1946 1947 static int hdaStreamWaitForStateChange(PHDASTREAM pStr mSt, RTMSINTERVAL msTimeout)1948 { 1949 AssertPtrReturn(pStr mSt, VERR_INVALID_POINTER);1950 1951 LogFlowFunc(("[SD%RU8]: msTimeout=%RU32\n", pStr mSt->u8SD, msTimeout));1952 return RTSemEventWait(pStr mSt->State.hStateChangedEvent, msTimeout);1947 static int hdaStreamWaitForStateChange(PHDASTREAM pStream, RTMSINTERVAL msTimeout) 1948 { 1949 AssertPtrReturn(pStream, VERR_INVALID_POINTER); 1950 1951 LogFlowFunc(("[SD%RU8]: msTimeout=%RU32\n", pStream->u8SD, msTimeout)); 1952 return RTSemEventWait(pStream->State.hStateChangedEvent, msTimeout); 1953 1953 } 1954 1954 #endif /* IN_RING3 */ … … 2205 2205 return VINF_SUCCESS; 2206 2206 2207 PHDASTREAM pStr mSt= hdaStreamFromSD(pThis, HDA_SD_NUM_FROM_REG(pThis, CBL, iReg));2208 if (!pStr mSt)2207 PHDASTREAM pStream = hdaStreamFromSD(pThis, HDA_SD_NUM_FROM_REG(pThis, CBL, iReg)); 2208 if (!pStream) 2209 2209 { 2210 2210 LogFunc(("[SD%RU8]: Warning: Changing SDCBL on non-attached stream (0x%x)\n", HDA_SD_NUM_FROM_REG(pThis, CTL, iReg), u32Value)); … … 2212 2212 } 2213 2213 2214 int rc2 = hdaRegWriteSDLock(pThis, pStr mSt, iReg, u32Value);2214 int rc2 = hdaRegWriteSDLock(pThis, pStream, iReg, u32Value); 2215 2215 AssertRC(rc2); 2216 2216 2217 pStr mSt->u32CBL = u32Value;2217 pStream->u32CBL = u32Value; 2218 2218 2219 2219 /* Reset BDLE state. */ 2220 RT_ZERO(pStr mSt->State.BDLE);2221 pStr mSt->State.uCurBDLE = 0;2220 RT_ZERO(pStream->State.BDLE); 2221 pStream->State.uCurBDLE = 0; 2222 2222 2223 2223 rc2 = hdaRegWriteU32(pThis, iReg, u32Value); 2224 2224 AssertRC(rc2); 2225 2225 2226 LogFlowFunc(("[SD%RU8]: CBL=%RU32\n", pStr mSt->u8SD, u32Value));2227 hdaRegWriteSDUnlock(pStr mSt);2226 LogFlowFunc(("[SD%RU8]: CBL=%RU32\n", pStream->u8SD, u32Value)); 2227 hdaRegWriteSDUnlock(pStream); 2228 2228 2229 2229 return VINF_SUCCESS; /* Always return success to the MMIO handler. */ … … 2273 2273 pTag->pStrm = hdaStreamFromSD(pThis, uSD); 2274 2274 2275 PHDASTREAM pStr mSt= pTag->pStrm;2276 AssertPtr(pStr mSt);2275 PHDASTREAM pStream = pTag->pStrm; 2276 AssertPtr(pStream); 2277 2277 2278 2278 /* Note: Do not use hdaRegWriteSDLock() here, as SDnCTL might change the RUN bit. */ 2279 int rc2 = RTSemMutexRequest(pStr mSt->State.hMtx, RT_INDEFINITE_WAIT);2279 int rc2 = RTSemMutexRequest(pStream->State.hMtx, RT_INDEFINITE_WAIT); 2280 2280 AssertRC(rc2); 2281 2281 #endif /* IN_RING3 */ … … 2300 2300 Assert(!fInRun && !fRun); 2301 2301 2302 LogFunc(("[SD%RU8]: Guest initiated enter to stream reset\n", pStr mSt->u8SD));2303 hdaStreamReset(pThis, pStr mSt);2302 LogFunc(("[SD%RU8]: Guest initiated enter to stream reset\n", pStream->u8SD)); 2303 hdaStreamReset(pThis, pStream); 2304 2304 #endif 2305 2305 } … … 2313 2313 { 2314 2314 Assert(!fReset && !fInReset); 2315 LogFunc(("[SD%RU8]: fRun=%RTbool\n", pStr mSt->u8SD, fRun));2316 2317 hdaStreamSetActive(pThis, pStr mSt, fRun);2315 LogFunc(("[SD%RU8]: fRun=%RTbool\n", pStream->u8SD, fRun)); 2316 2317 hdaStreamSetActive(pThis, pStream, fRun); 2318 2318 2319 2319 if (fRun) 2320 2320 { 2321 2321 /* (Re-)Fetch the current BDLE entry. */ 2322 rc2 = hdaBDLEFetch(pThis, &pStr mSt->State.BDLE, pStrmSt->u64BDLBase, pStrmSt->State.uCurBDLE);2322 rc2 = hdaBDLEFetch(pThis, &pStream->State.BDLE, pStream->u64BDLBase, pStream->State.uCurBDLE); 2323 2323 AssertRC(rc2); 2324 2324 } … … 2326 2326 2327 2327 if (!fInRun && !fRun) 2328 hdaStreamInit(pThis, pStr mSt, pStrmSt->u8SD);2328 hdaStreamInit(pThis, pStream, pStream->u8SD); 2329 2329 #endif /* IN_RING3 */ 2330 2330 } … … 2337 2337 AssertRC(rc2); 2338 2338 2339 hdaRegWriteSDUnlock(pStr mSt);2339 hdaRegWriteSDUnlock(pStream); 2340 2340 return VINF_SUCCESS; /* Always return success to the MMIO handler. */ 2341 2341 #else … … 2365 2365 return VINF_SUCCESS; 2366 2366 2367 PHDASTREAM pStr mSt= hdaStreamFromSD(pThis, HDA_SD_NUM_FROM_REG(pThis, LVI, iReg));2368 if (!pStr mSt)2367 PHDASTREAM pStream = hdaStreamFromSD(pThis, HDA_SD_NUM_FROM_REG(pThis, LVI, iReg)); 2368 if (!pStream) 2369 2369 { 2370 2370 LogFunc(("[SD%RU8]: Warning: Changing SDLVI on non-attached stream (0x%x)\n", HDA_SD_NUM_FROM_REG(pThis, CTL, iReg), u32Value)); … … 2372 2372 } 2373 2373 2374 int rc2 = hdaRegWriteSDLock(pThis, pStr mSt, iReg, u32Value);2374 int rc2 = hdaRegWriteSDLock(pThis, pStream, iReg, u32Value); 2375 2375 AssertRC(rc2); 2376 2376 2377 2377 /** @todo Validate LVI. */ 2378 pStr mSt->u16LVI = u32Value;2378 pStream->u16LVI = u32Value; 2379 2379 2380 2380 /* Reset BDLE state. */ 2381 RT_ZERO(pStr mSt->State.BDLE);2382 pStr mSt->State.uCurBDLE = 0;2381 RT_ZERO(pStream->State.BDLE); 2382 pStream->State.uCurBDLE = 0; 2383 2383 2384 2384 rc2 = hdaRegWriteU16(pThis, iReg, u32Value); 2385 2385 AssertRC(rc2); 2386 2386 2387 LogFlowFunc(("[SD%RU8]: LVI=%RU32\n", pStr mSt->u8SD, u32Value));2388 hdaRegWriteSDUnlock(pStr mSt);2387 LogFlowFunc(("[SD%RU8]: LVI=%RU32\n", pStream->u8SD, u32Value)); 2388 hdaRegWriteSDUnlock(pStream); 2389 2389 2390 2390 return VINF_SUCCESS; /* Always return success to the MMIO handler. */ … … 2721 2721 return VINF_SUCCESS; /* Always return success to the MMIO handler. */ 2722 2722 2723 PHDASTREAM pStr mSt= hdaStreamFromSD(pThis, HDA_SD_NUM_FROM_REG(pThis, FMT, iReg));2724 if (!pStr mSt)2723 PHDASTREAM pStream = hdaStreamFromSD(pThis, HDA_SD_NUM_FROM_REG(pThis, FMT, iReg)); 2724 if (!pStream) 2725 2725 { 2726 2726 LogFunc(("[SD%RU8]: Warning: Changing SDFMT on non-attached stream (0x%x)\n", … … 2729 2729 } 2730 2730 2731 rc = hdaRegWriteSDLock(pThis, pStr mSt, iReg, u32Value);2731 rc = hdaRegWriteSDLock(pThis, pStream, iReg, u32Value); 2732 2732 AssertRC(rc); 2733 2733 2734 2734 LogFunc(("[SD%RU8]: Hz=%RU32, Channels=%RU8, enmFmt=%RU32\n", 2735 pStr mSt->u8SD, strmCfg.uHz, strmCfg.cChannels, strmCfg.enmFormat));2735 pStream->u8SD, strmCfg.uHz, strmCfg.cChannels, strmCfg.enmFormat)); 2736 2736 2737 2737 /* Set audio direction. */ 2738 strmCfg.enmDir = hdaGetDirFromSD(pStr mSt->u8SD);2738 strmCfg.enmDir = hdaGetDirFromSD(pStream->u8SD); 2739 2739 2740 2740 /* … … 2746 2746 * number of channels in a single audio stream. 2747 2747 */ 2748 rc = hdaStreamMapInit(&pStr mSt->State.Mapping, &strmCfg);2748 rc = hdaStreamMapInit(&pStream->State.Mapping, &strmCfg); 2749 2749 AssertRC(rc); 2750 2750 … … 2788 2788 } 2789 2789 else 2790 LogFunc(("[SD%RU8]: (Re-)Opening stream failed with rc=%Rrc\n", pStr mSt->u8SD, rc));2791 2792 hdaRegWriteSDUnlock(pStr mSt);2790 LogFunc(("[SD%RU8]: (Re-)Opening stream failed with rc=%Rrc\n", pStream->u8SD, rc)); 2791 2792 hdaRegWriteSDUnlock(pStream); 2793 2793 } 2794 2794 … … 2806 2806 return VINF_SUCCESS; 2807 2807 2808 PHDASTREAM pStr mSt= hdaStreamFromSD(pThis, u8Strm);2809 if (!pStr mSt)2808 PHDASTREAM pStream = hdaStreamFromSD(pThis, u8Strm); 2809 if (!pStream) 2810 2810 { 2811 2811 LogFunc(("[SD%RU8]: Warning: Changing SDBPL/SDBPU on non-attached stream (0x%x)\n", HDA_SD_NUM_FROM_REG(pThis, CTL, iReg), u32Value)); … … 2813 2813 } 2814 2814 2815 int rc2 = hdaRegWriteSDLock(pThis, pStr mSt, iReg, u32Value);2815 int rc2 = hdaRegWriteSDLock(pThis, pStream, iReg, u32Value); 2816 2816 AssertRC(rc2); 2817 2817 … … 2820 2820 2821 2821 /* Update BDL base. */ 2822 pStr mSt->u64BDLBase = RT_MAKE_U64(HDA_STREAM_REG(pThis, BDPL, u8Strm),2822 pStream->u64BDLBase = RT_MAKE_U64(HDA_STREAM_REG(pThis, BDPL, u8Strm), 2823 2823 HDA_STREAM_REG(pThis, BDPU, u8Strm)); 2824 2824 /* Reset BDLE state. */ 2825 RT_ZERO(pStr mSt->State.BDLE);2826 pStr mSt->State.uCurBDLE = 0;2827 2828 LogFlowFunc(("[SD%RU8]: BDLBase=0x%x\n", pStr mSt->u8SD, pStrmSt->u64BDLBase));2829 hdaRegWriteSDUnlock(pStr mSt);2825 RT_ZERO(pStream->State.BDLE); 2826 pStream->State.uCurBDLE = 0; 2827 2828 LogFlowFunc(("[SD%RU8]: BDLBase=0x%x\n", pStream->u8SD, pStream->u64BDLBase)); 2829 hdaRegWriteSDUnlock(pStream); 2830 2830 2831 2831 return VINF_SUCCESS; /* Always return success to the MMIO handler. */ … … 2854 2854 * @param u32Value Value to write. 2855 2855 */ 2856 DECLINLINE(int) hdaRegWriteSDLock(PHDASTATE pThis, PHDASTREAM pStr mSt, uint32_t iReg, uint32_t u32Value)2856 DECLINLINE(int) hdaRegWriteSDLock(PHDASTATE pThis, PHDASTREAM pStream, uint32_t iReg, uint32_t u32Value) 2857 2857 { 2858 2858 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 2859 AssertPtrReturn(pStr mSt, VERR_INVALID_POINTER);2859 AssertPtrReturn(pStream, VERR_INVALID_POINTER); 2860 2860 2861 2861 #ifdef VBOX_STRICT 2862 2862 /* Check if the SD's RUN bit is set. */ 2863 uint32_t u32SDCTL = HDA_STREAM_REG(pThis, CTL, pStr mSt->u8SD);2863 uint32_t u32SDCTL = HDA_STREAM_REG(pThis, CTL, pStream->u8SD); 2864 2864 bool fIsRunning = RT_BOOL(u32SDCTL & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN)); 2865 2865 if (fIsRunning) 2866 2866 { 2867 2867 LogFlowFunc(("[SD%RU8]: Warning: Cannot write to register 0x%x (0x%x) when RUN bit is set (%R[sdctl])\n", 2868 pStr mSt->u8SD, iReg, u32Value, u32SDCTL));2868 pStream->u8SD, iReg, u32Value, u32SDCTL)); 2869 2869 return VERR_ACCESS_DENIED; 2870 2870 } 2871 2871 #endif 2872 2872 2873 return RTSemMutexRequest(pStr mSt->State.hMtx, RT_INDEFINITE_WAIT);2874 } 2875 2876 DECLINLINE(void) hdaRegWriteSDUnlock(PHDASTREAM pStr mSt)2877 { 2878 AssertPtrReturnVoid(pStr mSt);2879 2880 int rc2 = RTSemMutexRelease(pStr mSt->State.hMtx);2873 return RTSemMutexRequest(pStream->State.hMtx, RT_INDEFINITE_WAIT); 2874 } 2875 2876 DECLINLINE(void) hdaRegWriteSDUnlock(PHDASTREAM pStream) 2877 { 2878 AssertPtrReturnVoid(pStream); 2879 2880 int rc2 = RTSemMutexRelease(pStream->State.hMtx); 2881 2881 AssertRC(rc2); 2882 2882 } … … 3098 3098 * @return Number of bytes for the DMA engine to process. 3099 3099 */ 3100 DECLINLINE(uint32_t) hdaStreamGetTransferSize(PHDASTATE pThis, PHDASTREAM pStr mSt, uint32_t cbMax)3100 DECLINLINE(uint32_t) hdaStreamGetTransferSize(PHDASTATE pThis, PHDASTREAM pStream, uint32_t cbMax) 3101 3101 { 3102 3102 AssertPtrReturn(pThis, 0); 3103 AssertPtrReturn(pStr mSt, 0);3103 AssertPtrReturn(pStream, 0); 3104 3104 3105 3105 if (!cbMax) 3106 3106 return 0; 3107 3107 3108 PHDABDLE pBDLE = &pStr mSt->State.BDLE;3109 3110 uint32_t u32LPIB = HDA_STREAM_REG(pThis, LPIB, pStr mSt->u8SD);3111 Assert(u32LPIB <= pStr mSt->u32CBL);3112 3113 uint32_t cbFree = pStr mSt->u32CBL - u32LPIB; /** @todo Convert samples to bytes? */3108 PHDABDLE pBDLE = &pStream->State.BDLE; 3109 3110 uint32_t u32LPIB = HDA_STREAM_REG(pThis, LPIB, pStream->u8SD); 3111 Assert(u32LPIB <= pStream->u32CBL); 3112 3113 uint32_t cbFree = pStream->u32CBL - u32LPIB; /** @todo Convert samples to bytes? */ 3114 3114 if (cbFree) 3115 3115 { … … 3118 3118 3119 3119 /* Make sure we only copy as much as the stream's FIFO can hold (SDFIFOS, 18.2.39). */ 3120 cbFree = RT_MIN(cbFree, pStr mSt->u16FIFOS);3120 cbFree = RT_MIN(cbFree, pStream->u16FIFOS); 3121 3121 3122 3122 /* Make sure we only transfer as many bytes as requested. */ … … 3136 3136 } 3137 3137 3138 LogFlowFunc(("[SD%RU8]: CBL=%RU32, LPIB=%RU32, cbFree=%RU32, %R[bdle]\n", pStr mSt->u8SD,3139 pStr mSt->u32CBL, HDA_STREAM_REG(pThis, LPIB, pStrmSt->u8SD), cbFree, pBDLE));3138 LogFlowFunc(("[SD%RU8]: CBL=%RU32, LPIB=%RU32, cbFree=%RU32, %R[bdle]\n", pStream->u8SD, 3139 pStream->u32CBL, HDA_STREAM_REG(pThis, LPIB, pStream->u8SD), cbFree, pBDLE)); 3140 3140 return cbFree; 3141 3141 } … … 3280 3280 #endif /* IN_RING3 */ 3281 3281 3282 DECLINLINE(bool) hdaStreamNeedsNextBDLE(PHDASTATE pThis, PHDASTREAM pStr mSt)3282 DECLINLINE(bool) hdaStreamNeedsNextBDLE(PHDASTATE pThis, PHDASTREAM pStream) 3283 3283 { 3284 3284 AssertPtrReturn(pThis, false); 3285 AssertPtrReturn(pStr mSt, false);3286 3287 PHDABDLE pBDLE = &pStr mSt->State.BDLE;3288 uint32_t u32LPIB = HDA_STREAM_REG(pThis, LPIB, pStr mSt->u8SD);3285 AssertPtrReturn(pStream, false); 3286 3287 PHDABDLE pBDLE = &pStream->State.BDLE; 3288 uint32_t u32LPIB = HDA_STREAM_REG(pThis, LPIB, pStream->u8SD); 3289 3289 3290 3290 /* Did we reach the CBL (Cyclic Buffer List) limit? */ 3291 bool fCBLLimitReached = u32LPIB >= pStr mSt->u32CBL;3291 bool fCBLLimitReached = u32LPIB >= pStream->u32CBL; 3292 3292 3293 3293 /* Do we need to use the next BDLE entry? Either because we reached … … 3296 3296 || (pBDLE->State.u32BufOff >= pBDLE->u32BufSize)); 3297 3297 3298 Assert(u32LPIB <= pStr mSt->u32CBL);3298 Assert(u32LPIB <= pStream->u32CBL); 3299 3299 Assert(pBDLE->State.u32BufOff <= pBDLE->u32BufSize); 3300 3300 3301 3301 LogFlowFunc(("[SD%RU8]: LPIB=%RU32, CBL=%RU32, fCBLLimitReached=%RTbool, fNeedsNextBDLE=%RTbool, %R[bdle]\n", 3302 pStr mSt->u8SD, u32LPIB, pStrmSt->u32CBL, fCBLLimitReached, fNeedsNextBDLE, pBDLE));3302 pStream->u8SD, u32LPIB, pStream->u32CBL, fCBLLimitReached, fNeedsNextBDLE, pBDLE)); 3303 3303 3304 3304 return fNeedsNextBDLE; 3305 3305 } 3306 3306 3307 DECLINLINE(void) hdaStreamTransferUpdate(PHDASTATE pThis, PHDASTREAM pStr mSt, uint32_t cbInc)3307 DECLINLINE(void) hdaStreamTransferUpdate(PHDASTATE pThis, PHDASTREAM pStream, uint32_t cbInc) 3308 3308 { 3309 3309 AssertPtrReturnVoid(pThis); 3310 AssertPtrReturnVoid(pStr mSt);3311 3312 LogFlowFunc(("[SD%RU8]: cbInc=%RU32\n", pStr mSt->u8SD, cbInc));3313 3314 Assert(cbInc <= pStr mSt->u16FIFOS);3310 AssertPtrReturnVoid(pStream); 3311 3312 LogFlowFunc(("[SD%RU8]: cbInc=%RU32\n", pStream->u8SD, cbInc)); 3313 3314 Assert(cbInc <= pStream->u16FIFOS); 3315 3315 3316 3316 if (!cbInc) /* Nothing to do? Bail out early. */ 3317 3317 return; 3318 3318 3319 PHDABDLE pBDLE = &pStr mSt->State.BDLE;3319 PHDABDLE pBDLE = &pStream->State.BDLE; 3320 3320 3321 3321 /* … … 3326 3326 if (pBDLE->State.cbBelowFIFOW == 0) /* Did we hit (or exceed) the watermark? */ 3327 3327 { 3328 uint32_t u32LPIB = HDA_STREAM_REG(pThis, LPIB, pStr mSt->u8SD);3329 3330 AssertMsg(((u32LPIB + cbInc) <= pStr mSt->u32CBL),3328 uint32_t u32LPIB = HDA_STREAM_REG(pThis, LPIB, pStream->u8SD); 3329 3330 AssertMsg(((u32LPIB + cbInc) <= pStream->u32CBL), 3331 3331 ("[SD%RU8] Increment (%RU32) exceeds CBL (%RU32): LPIB (%RU32)\n", 3332 pStr mSt->u8SD, cbInc, pStrmSt->u32CBL, u32LPIB));3333 3334 u32LPIB = RT_MIN(u32LPIB + cbInc, pStr mSt->u32CBL);3332 pStream->u8SD, cbInc, pStream->u32CBL, u32LPIB)); 3333 3334 u32LPIB = RT_MIN(u32LPIB + cbInc, pStream->u32CBL); 3335 3335 3336 3336 LogFlowFunc(("[SD%RU8]: LPIB: %RU32 -> %RU32, CBL=%RU32\n", 3337 pStr mSt->u8SD,3338 HDA_STREAM_REG(pThis, LPIB, pStr mSt->u8SD), HDA_STREAM_REG(pThis, LPIB, pStrmSt->u8SD) + cbInc,3339 pStr mSt->u32CBL));3340 3341 hdaStreamUpdateLPIB(pThis, pStr mSt, u32LPIB);3337 pStream->u8SD, 3338 HDA_STREAM_REG(pThis, LPIB, pStream->u8SD), HDA_STREAM_REG(pThis, LPIB, pStream->u8SD) + cbInc, 3339 pStream->u32CBL)); 3340 3341 hdaStreamUpdateLPIB(pThis, pStream, u32LPIB); 3342 3342 } 3343 3343 } … … 3392 3392 * but "reports bytes" when all conditions are met (FIFOW). 3393 3393 */ 3394 static int hdaReadAudio(PHDASTATE pThis, PHDASTREAM pStr mSt, uint32_t cbMax, uint32_t *pcbRead)3394 static int hdaReadAudio(PHDASTATE pThis, PHDASTREAM pStream, uint32_t cbMax, uint32_t *pcbRead) 3395 3395 { 3396 3396 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 3397 AssertPtrReturn(pStr mSt, VERR_INVALID_POINTER);3397 AssertPtrReturn(pStream, VERR_INVALID_POINTER); 3398 3398 /* pcbRead is optional. */ 3399 3399 … … 3403 3403 do 3404 3404 { 3405 PHDABDLE pBDLE = &pStr mSt->State.BDLE;3406 3407 uint32_t cbBuf = hdaStreamGetTransferSize(pThis, pStr mSt, cbMax);3405 PHDABDLE pBDLE = &pStream->State.BDLE; 3406 3407 uint32_t cbBuf = hdaStreamGetTransferSize(pThis, pStream, cbMax); 3408 3408 Log3Func(("cbBuf=%RU32, %R[bdle]\n", cbBuf, pBDLE)); 3409 3409 … … 3414 3414 } 3415 3415 3416 AssertPtr(pStr mSt->pMixSink);3417 AssertPtr(pStr mSt->pMixSink->pMixSink);3418 rc = AudioMixerSinkRead(pStr mSt->pMixSink->pMixSink, AUDMIXOP_BLEND, pBDLE->State.au8FIFO, cbBuf, &cbRead);3416 AssertPtr(pStream->pMixSink); 3417 AssertPtr(pStream->pMixSink->pMixSink); 3418 rc = AudioMixerSinkRead(pStream->pMixSink->pMixSink, AUDMIXOP_BLEND, pBDLE->State.au8FIFO, cbBuf, &cbRead); 3419 3419 if (RT_FAILURE(rc)) 3420 3420 break; … … 3429 3429 Assert(cbRead <= cbBuf); 3430 3430 Assert(cbRead <= pBDLE->u32BufSize - pBDLE->State.u32BufOff); 3431 Assert(cbRead <= pStr mSt->u16FIFOS);3431 Assert(cbRead <= pStream->u16FIFOS); 3432 3432 3433 3433 /* … … 3439 3439 AssertRC(rc); 3440 3440 3441 if (pBDLE->State.cbBelowFIFOW + cbRead > hdaStreamGetFIFOW(pThis, pStr mSt))3441 if (pBDLE->State.cbBelowFIFOW + cbRead > hdaStreamGetFIFOW(pThis, pStream)) 3442 3442 { 3443 3443 pBDLE->State.u32BufOff += cbRead; … … 3449 3449 pBDLE->State.u32BufOff += cbRead; 3450 3450 pBDLE->State.cbBelowFIFOW += cbRead; 3451 Assert(pBDLE->State.cbBelowFIFOW <= hdaStreamGetFIFOW(pThis, pStr mSt));3451 Assert(pBDLE->State.cbBelowFIFOW <= hdaStreamGetFIFOW(pThis, pStream)); 3452 3452 //hdaBackendTransferUnreported(pThis, pBDLE, pStreamDesc, cbRead, pcbAvail); 3453 3453 … … 3467 3467 } 3468 3468 3469 static int hdaWriteAudio(PHDASTATE pThis, PHDASTREAM pStr mSt, uint32_t cbMax, uint32_t *pcbWritten)3469 static int hdaWriteAudio(PHDASTATE pThis, PHDASTREAM pStream, uint32_t cbMax, uint32_t *pcbWritten) 3470 3470 { 3471 3471 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 3472 AssertPtrReturn(pStr mSt, VERR_INVALID_POINTER);3472 AssertPtrReturn(pStream, VERR_INVALID_POINTER); 3473 3473 AssertPtrReturn(pcbWritten, VERR_INVALID_POINTER); 3474 3474 /* pcbWritten is optional. */ 3475 3475 3476 PHDABDLE pBDLE = &pStr mSt->State.BDLE;3476 PHDABDLE pBDLE = &pStream->State.BDLE; 3477 3477 3478 3478 uint32_t cbWritten = 0; 3479 uint32_t cbToWrite = hdaStreamGetTransferSize(pThis, pStr mSt, cbMax);3479 uint32_t cbToWrite = hdaStreamGetTransferSize(pThis, pStream, cbMax); 3480 3480 3481 3481 Log3Func(("cbToWrite=%RU32, %R[bdle]\n", cbToWrite, pBDLE)); … … 3517 3517 * Write to audio backend. We should ensure that we have enough bytes to copy to the backend. 3518 3518 */ 3519 if (cbBuf >= hdaStreamGetFIFOW(pThis, pStr mSt))3519 if (cbBuf >= hdaStreamGetFIFOW(pThis, pStream)) 3520 3520 { 3521 PHDASTREAMMAPPING pMapping = &pStr mSt->State.Mapping;3521 PHDASTREAMMAPPING pMapping = &pStream->State.Mapping; 3522 3522 3523 3523 /** @todo Which channel is which? */ … … 3594 3594 pBDLE->State.u32BufOff += cbWritten; 3595 3595 pBDLE->State.cbBelowFIFOW += cbWritten; 3596 Assert(pBDLE->State.cbBelowFIFOW <= hdaStreamGetFIFOW(pThis, pStr mSt));3596 Assert(pBDLE->State.cbBelowFIFOW <= hdaStreamGetFIFOW(pThis, pStream)); 3597 3597 3598 3598 /* Not enough bytes to be processed and reported, we'll try our luck next time around. */ … … 3602 3602 } 3603 3603 3604 Assert(cbWritten <= pStr mSt->u16FIFOS);3604 Assert(cbWritten <= pStream->u16FIFOS); 3605 3605 3606 3606 if (RT_SUCCESS(rc)) … … 4113 4113 #if 0 4114 4114 Log3Func(("[SD%RU8] fProceed=%RTbool, fRun=%RTbool, cbToProcess=%RU32\n", 4115 pStr mSt->u8SD, fProceed, HDA_STREAM_REG(pThis, CTL, pStrmSt->u8SD) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN),4115 pStream->u8SD, fProceed, HDA_STREAM_REG(pThis, CTL, pStream->u8SD) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN), 4116 4116 cbToProcess)); 4117 4117 #endif
Note:
See TracChangeset
for help on using the changeset viewer.