Changeset 89723 in vbox
- Timestamp:
- Jun 15, 2021 8:13:35 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DevIchAc97.cpp
r89721 r89723 848 848 * @param pStreamCC The AC'97 stream to retrieve size for (ring-3). 849 849 */ 850 static uint32_t ichac97R3StreamGetUsed(PAC97STREAMR3 pStreamCC) 851 { 852 if (!pStreamCC->State.pCircBuf) 853 return 0; 854 855 return (uint32_t)RTCircBufUsed(pStreamCC->State.pCircBuf); 856 } 850 DECLINLINE(uint32_t) ichac97R3StreamGetUsed(PAC97STREAMR3 pStreamCC) 851 { 852 PRTCIRCBUF const pCircBuf = pStreamCC->State.pCircBuf; 853 if (pCircBuf) 854 return (uint32_t)RTCircBufUsed(pCircBuf); 855 return 0; 856 } 857 857 858 858 859 /** … … 862 863 * @param pStreamCC AC'97 stream to retrieve size for (ring-3). 863 864 */ 864 static uint32_t ichac97R3StreamGetFree(PAC97STREAMR3 pStreamCC) 865 { 866 if (!pStreamCC->State.pCircBuf) 867 return 0; 868 869 return (uint32_t)RTCircBufFree(pStreamCC->State.pCircBuf); 870 } 865 DECLINLINE(uint32_t) ichac97R3StreamGetFree(PAC97STREAMR3 pStreamCC) 866 { 867 PRTCIRCBUF const pCircBuf = pStreamCC->State.pCircBuf; 868 if (pCircBuf) 869 return (uint32_t)RTCircBufFree(pCircBuf); 870 return 0; 871 } 872 871 873 872 874 # if 0 /* Unused */ … … 1015 1017 PAC97STREAMR3 pStreamCC, uint32_t cbToProcessMax, bool fWriteSilence, bool fInput) 1016 1018 { 1017 if (!cbToProcessMax) 1019 if (RT_LIKELY(cbToProcessMax > 0)) 1020 Assert(PDMAudioPropsIsSizeAligned(&pStreamCC->State.Cfg.Props, cbToProcessMax)); 1021 else 1018 1022 return VINF_SUCCESS; 1019 1023 1020 #ifdef VBOX_STRICT1021 const unsigned cbFrame = PDMAudioPropsBytesPerFrame(&pStreamCC->State.Cfg.Props);1022 #endif1023 1024 /* Make sure to only process an integer number of audio frames. */1025 Assert(cbToProcessMax % cbFrame == 0);1026 1027 1024 ichac97R3StreamLock(pStreamCC); 1028 1025 1029 1026 PAC97BMREGS pRegs = &pStream->Regs; 1030 1027 1031 if (pRegs->sr & AC97_SR_DCH) /* Controller halted? */ 1028 if (!(pRegs->sr & AC97_SR_DCH)) /* Controller halted? */ 1029 { /* not halted - likely */ } 1030 else 1032 1031 { 1033 1032 if (pRegs->cr & AC97_CR_RPBM) /* Bus master operation starts. */ … … 1049 1048 1050 1049 /* BCIS flag still set? Skip iteration. */ 1051 if (pRegs->sr & AC97_SR_BCIS) 1052 { 1050 /** @todo combine with the above test. */ 1051 if (!(pRegs->sr & AC97_SR_BCIS)) 1052 { /* likely */ } 1053 else 1054 { 1055 /** @todo counter */ 1053 1056 Log3Func(("[SD%RU8] BCIS set\n", pStream->u8SD)); 1054 1057 … … 1619 1622 * @param pStreamCC The AC'97 stream to lock (ring-3). 1620 1623 */ 1621 static voidichac97R3StreamLock(PAC97STREAMR3 pStreamCC)1624 DECLINLINE(void) ichac97R3StreamLock(PAC97STREAMR3 pStreamCC) 1622 1625 { 1623 1626 int rc2 = RTCritSectEnter(&pStreamCC->State.CritSect); … … 1631 1634 * @param pStreamCC The AC'97 stream to unlock (ring-3). 1632 1635 */ 1633 static voidichac97R3StreamUnlock(PAC97STREAMR3 pStreamCC)1636 DECLINLINE(void) ichac97R3StreamUnlock(PAC97STREAMR3 pStreamCC) 1634 1637 { 1635 1638 int rc2 = RTCritSectLeave(&pStreamCC->State.CritSect); … … 1758 1761 static PAC97DRIVERSTREAM ichac97R3MixerGetDrvStream(PAC97DRIVER pDrv, PDMAUDIODIR enmDir, PDMAUDIOPATH enmPath) 1759 1762 { 1760 PAC97DRIVERSTREAM pDrvStream = NULL;1761 1762 1763 if (enmDir == PDMAUDIODIR_IN) 1763 1764 { 1764 1765 LogFunc(("enmRecSource=%d\n", enmPath)); 1765 1766 1766 switch (enmPath) 1767 1767 { 1768 1768 case PDMAUDIOPATH_IN_LINE: 1769 pDrvStream = &pDrv->LineIn; 1770 break; 1769 return &pDrv->LineIn; 1771 1770 case PDMAUDIOPATH_IN_MIC: 1772 pDrvStream = &pDrv->MicIn; 1773 break; 1771 return &pDrv->MicIn; 1774 1772 default: 1775 AssertFailed(); 1776 break; 1773 AssertFailedBreak(); 1777 1774 } 1778 1775 } … … 1780 1777 { 1781 1778 LogFunc(("enmPlaybackDst=%d\n", enmPath)); 1782 1783 1779 switch (enmPath) 1784 1780 { 1785 1781 case PDMAUDIOPATH_OUT_FRONT: 1786 pDrvStream = &pDrv->Out; 1787 break; 1782 return &pDrv->Out; 1788 1783 default: 1789 AssertFailed(); 1790 break; 1784 AssertFailedBreak(); 1791 1785 } 1792 1786 } … … 1794 1788 AssertFailed(); 1795 1789 1796 return pDrvStream;1790 return NULL; 1797 1791 } 1798 1792 … … 1833 1827 rc = AudioMixerSinkAddStream(pMixSink, pMixStrm); 1834 1828 LogFlowFunc(("LUN#%RU8: Added stream \"%s\" to sink, rc=%Rrc\n", pDrv->uLUN, pStreamCfg->szName, rc)); 1835 if (RT_FAILURE(rc)) 1829 if (RT_SUCCESS(rc)) 1830 pDrvStream->pMixStrm = pMixStrm; 1831 else 1836 1832 AudioMixerStreamDestroy(pMixStrm, pDevIns, true /*fImmediate*/); 1837 1833 } 1838 1839 if (RT_SUCCESS(rc))1840 pDrvStream->pMixStrm = pMixStrm;1841 1834 } 1842 1835 else … … 1862 1855 AssertPtrReturn(pMixSink, VERR_INVALID_POINTER); 1863 1856 1864 if (!AudioHlpStreamCfgIsValid(pCfg)) 1865 return VERR_INVALID_PARAMETER; 1866 1867 int rc = AudioMixerSinkSetFormat(pMixSink, &pCfg->Props); 1868 if (RT_FAILURE(rc)) 1869 return rc; 1870 1871 PAC97DRIVER pDrv; 1872 RTListForEach(&pThisCC->lstDrv, pDrv, AC97DRIVER, Node) 1873 { 1874 int rc2 = ichac97R3MixerAddDrvStream(pDevIns, pMixSink, pCfg, pDrv); 1875 if (RT_FAILURE(rc2)) 1876 LogFunc(("Attaching stream failed with %Rrc\n", rc2)); 1877 1878 /* Do not pass failure to rc here, as there might be drivers which aren't 1879 * configured / ready yet. */ 1880 } 1857 int rc; 1858 if (AudioHlpStreamCfgIsValid(pCfg)) 1859 { 1860 rc = AudioMixerSinkSetFormat(pMixSink, &pCfg->Props); 1861 if (RT_SUCCESS(rc)) 1862 { 1863 1864 PAC97DRIVER pDrv; 1865 RTListForEach(&pThisCC->lstDrv, pDrv, AC97DRIVER, Node) 1866 { 1867 int rc2 = ichac97R3MixerAddDrvStream(pDevIns, pMixSink, pCfg, pDrv); 1868 if (RT_FAILURE(rc2)) 1869 LogFunc(("Attaching stream failed with %Rrc\n", rc2)); 1870 1871 /* Do not pass failure to rc here, as there might be drivers which aren't 1872 configured / ready yet. */ 1873 } 1874 } 1875 } 1876 else 1877 rc = VERR_INVALID_PARAMETER; 1881 1878 1882 1879 LogFlowFuncLeaveRC(rc); … … 1886 1883 /** 1887 1884 * Adds a specific AC'97 driver to the driver chain. 1885 * 1886 * Only called from ichac97R3Attach(). 1888 1887 * 1889 1888 * @returns VBox status code. … … 1922 1921 * Removes a specific AC'97 driver from the driver chain and destroys its 1923 1922 * associated streams. 1923 * 1924 * Only called from ichac97R3Detach(). 1924 1925 * 1925 1926 * @param pDevIns The device instance. … … 2277 2278 } 2278 2279 2280 2279 2281 /** 2280 2282 * Closes an AC'97 stream. 2281 2283 * 2282 * @returns VBox status code. 2284 * Empty stub at present, nothing to do here as we reuse streams and only really 2285 * re-open them if parameters changed (seldom). 2286 * 2283 2287 * @param pStream The AC'97 stream to close (shared). 2284 2288 */ 2285 static intichac97R3StreamClose(PAC97STREAM pStream)2289 static void ichac97R3StreamClose(PAC97STREAM pStream) 2286 2290 { 2287 2291 RT_NOREF(pStream); 2288 2292 LogFlowFunc(("[SD%RU8]\n", pStream->u8SD)); 2289 return VINF_SUCCESS; 2290 } 2293 } 2294 2291 2295 2292 2296 /** … … 2311 2315 Assert(pStreamCC - &pThisCC->aStreams[0] == pStream->u8SD); 2312 2316 2313 int rc = ichac97R3StreamClose(pStream); 2314 if (RT_SUCCESS(rc)) 2315 rc = ichac97R3StreamOpen(pDevIns, pThis, pThisCC, pStream, pStreamCC, fForce); 2316 2317 return rc; 2317 ichac97R3StreamClose(pStream); 2318 return ichac97R3StreamOpen(pDevIns, pThis, pThisCC, pStream, pStreamCC, fForce); 2318 2319 } 2319 2320 … … 2383 2384 else 2384 2385 { 2385 rc = ichac97R3StreamClose(pStream); 2386 if (RT_SUCCESS(rc)) 2387 rc = AudioMixerSinkDrainAndStop(pSink, 2388 pStreamCC->State.pCircBuf ? (uint32_t)RTCircBufUsed(pStreamCC->State.pCircBuf) : 0); 2386 rc = AudioMixerSinkDrainAndStop(pSink, pStreamCC->State.pCircBuf ? (uint32_t)RTCircBufUsed(pStreamCC->State.pCircBuf) : 0); 2387 ichac97R3StreamClose(pStream); 2389 2388 } 2390 2389 … … 2929 2928 { 2930 2929 AssertMsgReturnVoid(uMixerIdx + 2U <= sizeof(pThis->mixer_data), 2931 ("Index %RU8 out of bounds (%zu)\n", uMixerIdx, sizeof(pThis->mixer_data))); 2932 2933 LogRel2(("AC97: Setting mixer index #%RU8 to %RU16 (%RU8 %RU8)\n", 2934 uMixerIdx, uVal, RT_HI_U8(uVal), RT_LO_U8(uVal))); 2930 ("Index %RU8 out of bounds (%zu)\n", uMixerIdx, sizeof(pThis->mixer_data))); 2931 2932 LogRel2(("AC97: Setting mixer index #%RU8 to %RU16 (%RU8 %RU8)\n", uMixerIdx, uVal, RT_HI_U8(uVal), RT_LO_U8(uVal))); 2935 2933 2936 2934 pThis->mixer_data[uMixerIdx + 0] = RT_LO_U8(uVal); … … 2981 2979 * master volume controls. 2982 2980 */ 2983 if (index == AC97_Master_Volume_Mute || index == AC97_Headphone_Volume_Mute || index == AC97_Master_Volume_Mono_Mute) 2981 if ( index == AC97_Master_Volume_Mute 2982 || index == AC97_Headphone_Volume_Mute 2983 || index == AC97_Master_Volume_Mono_Mute) 2984 2984 { 2985 2985 if (uVal & RT_BIT(5)) /* D5 bit set? */ … … 3063 3063 * Sets the gain of a specific AC'97 recording control. 3064 3064 * 3065 * NB: gain support is currently not implemented in PDM audio.3065 * @note Gain support is currently not implemented in PDM audio. 3066 3066 * 3067 3067 * @returns VBox status code. … … 3078 3078 * zero being 0dB gain and 15 being +22.5dB gain. 3079 3079 */ 3080 const boolfCtlMuted = (uVal >> AC97_BARS_VOL_MUTE_SHIFT) & 1;3080 bool const fCtlMuted = (uVal >> AC97_BARS_VOL_MUTE_SHIFT) & 1; 3081 3081 uint8_t uCtlGainLeft = (uVal >> 8) & AC97_BARS_GAIN_MASK; 3082 3082 uint8_t uCtlGainRight = uVal & AC97_BARS_GAIN_MASK; … … 3147 3147 } 3148 3148 3149 3149 3150 /** 3150 3151 * Converts an AC'97 recording source index to a PDM audio recording source. … … 3171 3172 } 3172 3173 3174 3173 3175 /** 3174 3176 * Converts a PDM audio recording source to an AC'97 recording source index. … … 3316 3318 { 3317 3319 case 1: 3318 {3319 3320 LogRel2(("AC97: Warning: Unimplemented read (1 byte) offPort=%#x\n", offPort)); 3320 3321 pThis->cas = 0; 3321 3322 *pu32 = UINT32_MAX; 3322 3323 break; 3323 }3324 3324 3325 3325 case 2: 3326 {3327 3326 pThis->cas = 0; 3328 3327 *pu32 = ichac97MixerGet(pThis, offPort); 3329 3328 break; 3330 }3331 3329 3332 3330 case 4: 3333 {3334 3331 LogRel2(("AC97: Warning: Unimplemented read (4 bytes) offPort=%#x\n", offPort)); 3335 3332 pThis->cas = 0; 3336 3333 *pu32 = UINT32_MAX; 3337 3334 break; 3338 }3339 3335 3340 3336 default: 3341 {3342 3337 AssertFailed(); 3343 3338 rc = VERR_IOM_IOPORT_UNUSED; 3344 }3339 break; 3345 3340 } 3346 3341 … … 3367 3362 { 3368 3363 case 1: 3369 {3370 3364 LogRel2(("AC97: Warning: Unimplemented NAMWrite (1 byte) offPort=%#x <- %#x\n", offPort, u32)); 3371 3365 pThis->cas = 0; 3372 3366 break; 3373 }3374 3367 3375 3368 case 2: … … 3563 3556 3564 3557 case 4: 3565 {3566 3558 LogRel2(("AC97: Warning: Unimplemented 4 byte NAMWrite: offPort=%#x <- %#x\n", offPort, u32)); 3567 3559 pThis->cas = 0; 3568 3560 break; 3569 }3570 3561 3571 3562 default: … … 3609 3600 } 3610 3601 3602 3611 3603 /** 3612 3604 * @callback_method_impl{FNSSMDEVSAVEEXEC} … … 3643 3635 return VINF_SUCCESS; 3644 3636 } 3637 3645 3638 3646 3639 /** … … 3669 3662 } 3670 3663 3664 3671 3665 /** 3672 3666 * @callback_method_impl{FNSSMDEVLOADEXEC} … … 3693 3687 for (unsigned i = 0; i < AC97_MAX_STREAMS; i++) 3694 3688 { 3695 int rc 2= ichac97R3LoadStream(pDevIns, pSSM, &pThis->aStreams[i]);3696 AssertRCReturn(rc 2, rc2);3689 int rc = ichac97R3LoadStream(pDevIns, pSSM, &pThis->aStreams[i]); 3690 AssertRCReturn(rc, rc); 3697 3691 } 3698 3692 … … 3721 3715 */ 3722 3716 uint8_t afActiveStrms[AC97SOUNDSOURCE_MAX]; 3723 int rc 2= pHlp->pfnSSMGetMem(pSSM, afActiveStrms, sizeof(afActiveStrms));3724 AssertRCReturn(rc 2, rc2);3717 int rc = pHlp->pfnSSMGetMem(pSSM, afActiveStrms, sizeof(afActiveStrms)); 3718 AssertRCReturn(rc, rc); 3725 3719 3726 3720 for (unsigned i = 0; i < AC97_MAX_STREAMS; i++) … … 3730 3724 const PAC97STREAMR3 pStreamCC = &pThisCC->aStreams[i]; 3731 3725 3732 rc 2= ichac97R3StreamEnable(pDevIns, pThis, pThisCC, pStream, pStreamCC, fEnable);3733 AssertRC(rc 2);3726 rc = ichac97R3StreamEnable(pDevIns, pThis, pThisCC, pStream, pStreamCC, fEnable); 3727 AssertRC(rc); 3734 3728 if ( fEnable 3735 && RT_SUCCESS(rc 2))3729 && RT_SUCCESS(rc)) 3736 3730 { 3737 3731 /* Re-arm the timer for this stream. */ … … 4086 4080 } 4087 4081 4082 4088 4083 /** 4089 4084 * @interface_method_impl{PDMDEVREGR3,pfnAttach} … … 4112 4107 } 4113 4108 4114 /**4115 * Worker for ichac97R3Detach that does all but freeing the pDrv structure.4116 *4117 * This is called to let the device detach from a driver for a specified LUN4118 * at runtime.4119 *4120 * @param pDevIns The device instance.4121 * @param pThisCC The ring-3 AC'97 device state.4122 * @param pDrv Driver to detach from device.4123 */4124 static void ichac97R3DetachInternal(PPDMDEVINS pDevIns, PAC97STATER3 pThisCC, PAC97DRIVER pDrv)4125 {4126 /* Remove the driver from our list and destory it's associated streams.4127 This also will un-set the driver as a recording source (if associated). */4128 ichac97R3MixerRemoveDrv(pDevIns, pThisCC, pDrv);4129 LogFunc(("Detached LUN#%u\n", pDrv->uLUN));4130 }4131 4109 4132 4110 /** … … 4148 4126 if (pDrv->uLUN == iLUN) 4149 4127 { 4150 ichac97R3DetachInternal(pDevIns, pThisCC, pDrv); 4128 /* Remove the driver from our list and destory it's associated streams. 4129 This also will un-set the driver as a recording source (if associated). */ 4130 ichac97R3MixerRemoveDrv(pDevIns, pThisCC, pDrv); 4131 LogFunc(("Detached LUN#%u\n", pDrv->uLUN)); 4132 4133 DEVAC97_UNLOCK(pDevIns, pThis); 4134 4151 4135 RTStrFree(pDrv->pszDesc); 4152 4136 RTMemFree(pDrv); 4153 DEVAC97_UNLOCK(pDevIns, pThis);4154 4137 return; 4155 4138 } … … 4191 4174 return VINF_SUCCESS; 4192 4175 } 4176 4193 4177 4194 4178 /**
Note:
See TracChangeset
for help on using the changeset viewer.