- Timestamp:
- Dec 3, 2019 11:36:38 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DevIchAc97.cpp
r82361 r82362 48 48 49 49 /** Current saved state version. */ 50 #define AC97_S SM_VERSION150 #define AC97_SAVED_STATE_VERSION 1 51 51 52 52 /** Default timer frequency (in Hz). */ 53 #define AC97_TIMER_HZ_DEFAULT 10053 #define AC97_TIMER_HZ_DEFAULT 100 54 54 55 55 /** Maximum number of streams we support. */ 56 #define AC97_MAX_STREAMS 356 #define AC97_MAX_STREAMS 3 57 57 58 58 /** Maximum FIFO size (in bytes). */ 59 #define AC97_FIFO_MAX 25659 #define AC97_FIFO_MAX 256 60 60 61 61 #define AC97_SR_FIFOE RT_BIT(4) /**< rwc, FIFO error. */ … … 146 146 #define AC97_DB_FACTOR 4 147 147 148 #define AC97_REC_MASK 7 149 enum 150 { 151 AC97_REC_MIC = 0, 152 AC97_REC_CD, 153 AC97_REC_VIDEO, 154 AC97_REC_AUX, 155 AC97_REC_LINE_IN, 156 AC97_REC_STEREO_MIX, 157 AC97_REC_MONO_MIX, 158 AC97_REC_PHONE 159 }; 160 148 /** @name Recording inputs? 149 * @{ */ 150 #define AC97_REC_MIC UINT8_C(0) 151 #define AC97_REC_CD UINT8_C(1) 152 #define AC97_REC_VIDEO UINT8_C(2) 153 #define AC97_REC_AUX UINT8_C(3) 154 #define AC97_REC_LINE_IN UINT8_C(4) 155 #define AC97_REC_STEREO_MIX UINT8_C(5) 156 #define AC97_REC_MONO_MIX UINT8_C(6) 157 #define AC97_REC_PHONE UINT8_C(7) 158 #define AC97_REC_MASK UINT8_C(7) 159 /** @} */ 160 161 /** @name Mixer registers / NAM BAR registers? 162 * @{ */ 161 163 enum 162 164 { … … 195 197 AC97_Vendor_ID2 = 0x7e 196 198 }; 197 198 /* Codec models. */ 199 typedef enum 200 { 201 AC97_CODEC_STAC9700 = 1, /**< SigmaTel STAC9700 */ 202 AC97_CODEC_AD1980, /**< Analog Devices AD1980 */ 203 AC97_CODEC_AD1981B /**< Analog Devices AD1981B */ 204 } AC97CODEC; 205 206 /* Analog Devices miscellaneous regiter bits used in AD1980. */ 199 /** @} */ 200 201 /** @name Analog Devices miscellaneous regiter bits used in AD1980. 202 * @{ */ 207 203 #define AC97_AD_MISC_LOSEL RT_BIT(5) /**< Surround (rear) goes to line out outputs. */ 208 204 #define AC97_AD_MISC_HPSEL RT_BIT(10) /**< PCM (front) goes to headphone outputs. */ 209 210 #define ICHAC97STATE_2_DEVINS(a_pAC97) ((a_pAC97)->CTX_SUFF(pDevIns)) 211 212 enum 213 { 214 BUP_SET = RT_BIT(0), 215 BUP_LAST = RT_BIT(1)216 }; 205 /** @} */ 206 207 208 /** @name BUP flag values. 209 * @{ */ 210 #define BUP_SET RT_BIT_32(0) 211 #define BUP_LAST RT_BIT_32(1) 212 /** @} */ 217 213 218 214 /** @name AC'97 source indices. … … 513 509 514 510 511 /* Codec models. */ 512 typedef enum AC97CODEC 513 { 514 AC97CODEC_INVALID = 0, /**< Customary illegal zero value. */ 515 AC97CODEC_STAC9700, /**< SigmaTel STAC9700 */ 516 AC97CODEC_AD1980, /**< Analog Devices AD1980 */ 517 AC97CODEC_AD1981B, /**< Analog Devices AD1981B */ 518 AC97CODEC_32BIT_HACK = 0x7fffffff 519 } AC97CODEC; 520 521 515 522 /** 516 523 * The shared AC'97 device state. … … 534 541 uint16_t au16Padding1[3]; 535 542 uint8_t silence[128]; 536 int32_tbup_flag;543 uint32_t bup_flag; 537 544 /** Codec model. */ 538 uint32_t uCodecModel;545 AC97CODEC enmCodecModel; 539 546 540 547 /** PCI region \#0: NAM I/O ports. */ … … 552 559 } AC97STATE; 553 560 AssertCompileMemberAlignment(AC97STATE, aStreams, 8); 561 #ifdef VBOX_WITH_STATISTICS 562 AssertCompileMemberAlignment(AC97STATE, StatTimer, 8); 563 AssertCompileMemberAlignment(AC97STATE, StatBytesRead, 8); 564 AssertCompileMemberAlignment(AC97STATE, StatBytesWritten, 8); 565 #endif 554 566 555 567 … … 634 646 PDMDevHlpTimerUnlockClock2((a_pDevIns), (a_pStream)->hTimer, &(a_pThis)->CritSect) 635 647 636 #ifdef VBOX_WITH_STATISTICS637 AssertCompileMemberAlignment(AC97STATE, StatTimer, 8);638 AssertCompileMemberAlignment(AC97STATE, StatBytesRead, 8);639 AssertCompileMemberAlignment(AC97STATE, StatBytesWritten, 8);640 #endif641 642 648 #ifndef VBOX_DEVICE_STRUCT_TESTCASE 643 649 … … 1783 1789 * 1784 1790 * @returns IPRT status code. 1785 * @param pThis The sharedAC'97 state.1791 * @param pThisCC The ring-3 AC'97 state. 1786 1792 * @param pMixSink Mixer sink to add stream to. 1787 1793 * @param pCfg Stream configuration to use. … … 1817 1823 * 1818 1824 * @return IPRT status code. 1819 * @param pThis 1825 * @param pThisCC The ring-3 AC'97 device state. 1820 1826 * @param pDrv The AC'97 driver to add. 1821 1827 */ … … 1848 1854 * associated streams. 1849 1855 * 1850 * @param pThis 1856 * @param pThisCC The ring-3 AC'97 device state. 1851 1857 * @param pDrv AC'97 driver to remove. 1852 1858 */ … … 1909 1915 * Removes all driver streams from a specific mixer sink. 1910 1916 * 1911 * @param pThis 1917 * @param pThisCC The ring-3 AC'97 state. 1912 1918 * @param pMixSink Mixer sink to remove audio streams from. 1913 1919 * @param enmDir Stream direction to remove. … … 2181 2187 * 2182 2188 * @returns Free data (in bytes). 2183 * @param pStream AC'97 stream to retrieve size for.2189 * @param pStreamCC AC'97 stream to retrieve size for (ring-3). 2184 2190 */ 2185 2191 static uint32_t ichac97R3StreamGetFree(PAC97STREAMR3 pStreamCC) … … 2216 2222 * master volume controls. 2217 2223 */ 2218 if ( (index == AC97_Master_Volume_Mute) || (index == AC97_Headphone_Volume_Mute) || (index == AC97_Master_Volume_Mono_Mute))2224 if (index == AC97_Master_Volume_Mute || index == AC97_Headphone_Volume_Mute || index == AC97_Master_Volume_Mono_Mute) 2219 2225 { 2220 2226 if (uVal & RT_BIT(5)) /* D5 bit set? */ … … 2517 2523 ichac97MixerSet(pThis, AC97_MIC_ADC_Rate , 0xbb80 /* 48000 Hz by default */); 2518 2524 2519 if (pThis-> uCodecModel == AC97_CODEC_AD1980)2525 if (pThis->enmCodecModel == AC97CODEC_AD1980) 2520 2526 { 2521 2527 /* Analog Devices 1980 (AD1980) */ … … 2525 2531 ichac97MixerSet(pThis, AC97_Headphone_Volume_Mute , 0x8000); 2526 2532 } 2527 else if (pThis-> uCodecModel == AC97_CODEC_AD1981B)2533 else if (pThis->enmCodecModel == AC97CODEC_AD1981B) 2528 2534 { 2529 2535 /* Analog Devices 1981B (AD1981B) */ … … 3320 3326 break; 3321 3327 case AC97_Master_Volume_Mute: 3322 if (pThis-> uCodecModel == AC97_CODEC_AD1980)3328 if (pThis->enmCodecModel == AC97CODEC_AD1980) 3323 3329 { 3324 3330 if (ichac97MixerGet(pThis, AC97_AD_Misc) & AC97_AD_MISC_LOSEL) … … 3332 3338 break; 3333 3339 case AC97_Headphone_Volume_Mute: 3334 if (pThis-> uCodecModel == AC97_CODEC_AD1980)3340 if (pThis->enmCodecModel == AC97CODEC_AD1980) 3335 3341 { 3336 3342 if (ichac97MixerGet(pThis, AC97_AD_Misc) & AC97_AD_MISC_HPSEL) … … 3500 3506 * Saves (serializes) an AC'97 stream using SSM. 3501 3507 * 3502 * @returns IPRT status code.3503 3508 * @param pDevIns Device instance. 3504 3509 * @param pSSM Saved state manager (SSM) handle to use. 3505 3510 * @param pStream AC'97 stream to save. 3506 3511 */ 3507 static intichac97R3SaveStream(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, PAC97STREAM pStream)3512 static void ichac97R3SaveStream(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, PAC97STREAM pStream) 3508 3513 { 3509 3514 PAC97BMREGS pRegs = &pStream->Regs; … … 3520 3525 pHlp->pfnSSMPutU32(pSSM, pRegs->bd.addr); 3521 3526 pHlp->pfnSSMPutU32(pSSM, pRegs->bd.ctl_len); 3522 3523 return VINF_SUCCESS;3524 3527 } 3525 3528 … … 3532 3535 PAC97STATER3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PAC97STATER3); 3533 3536 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3; 3534 3535 3537 LogFlowFuncEnter(); 3536 3538 … … 3539 3541 pHlp->pfnSSMPutU32(pSSM, pThis->cas); 3540 3542 3543 /* 3544 * The order that the streams are saved here is fixed, so don't change. 3545 */ 3541 3546 /** @todo r=andy For the next saved state version, add unique stream identifiers and a stream count. */ 3542 /* Note: The order the streams are loaded here is critical, so don't touch. */3543 3547 for (unsigned i = 0; i < AC97_MAX_STREAMS; i++) 3544 { 3545 int rc2 = ichac97R3SaveStream(pDevIns, pSSM, &pThis->aStreams[i]); 3546 AssertRC(rc2); 3547 } 3548 ichac97R3SaveStream(pDevIns, pSSM, &pThis->aStreams[i]); 3548 3549 3549 3550 pHlp->pfnSSMPutMem(pSSM, pThis->mixer_data, sizeof(pThis->mixer_data)); 3550 3551 3551 uint8_t active[AC97SOUNDSOURCE_MAX];3552 3553 a ctive[AC97SOUNDSOURCE_PI_INDEX] = ichac97R3StreamIsEnabled(pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_PI_INDEX]) ? 1 : 0;3554 a ctive[AC97SOUNDSOURCE_PO_INDEX] = ichac97R3StreamIsEnabled(pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_PO_INDEX]) ? 1 : 0;3555 a ctive[AC97SOUNDSOURCE_MC_INDEX] = ichac97R3StreamIsEnabled(pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_MC_INDEX]) ? 1 : 0;3556 3557 pHlp->pfnSSMPutMem(pSSM, a ctive, sizeof(active));3552 /* The stream order is against fixed and set in stone. */ 3553 uint8_t afActiveStrms[AC97SOUNDSOURCE_MAX]; 3554 afActiveStrms[AC97SOUNDSOURCE_PI_INDEX] = ichac97R3StreamIsEnabled(pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_PI_INDEX]); 3555 afActiveStrms[AC97SOUNDSOURCE_PO_INDEX] = ichac97R3StreamIsEnabled(pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_PO_INDEX]); 3556 afActiveStrms[AC97SOUNDSOURCE_MC_INDEX] = ichac97R3StreamIsEnabled(pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_MC_INDEX]); 3557 AssertCompile(RT_ELEMENTS(afActiveStrms) == 3); 3558 pHlp->pfnSSMPutMem(pSSM, afActiveStrms, sizeof(afActiveStrms)); 3558 3559 3559 3560 LogFlowFuncLeaveRC(VINF_SUCCESS); … … 3597 3598 LogRel2(("ichac97LoadExec: uVersion=%RU32, uPass=0x%x\n", uVersion, uPass)); 3598 3599 3599 AssertMsgReturn (uVersion == AC97_S SM_VERSION, ("%RU32\n", uVersion), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);3600 AssertMsgReturn (uVersion == AC97_SAVED_STATE_VERSION, ("%RU32\n", uVersion), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION); 3600 3601 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass); 3601 3602 … … 3604 3605 pHlp->pfnSSMGetU32(pSSM, &pThis->cas); 3605 3606 3606 /** @todo r=andy For the next saved state version, add unique stream identifiers and a stream count. */ 3607 /* Note: The order the streams are loaded here is critical, so don't touch. */ 3607 /* 3608 * The order the streams are loaded here is critical (defined by 3609 * AC97SOUNDSOURCE_XX_INDEX), so don't touch! 3610 */ 3608 3611 for (unsigned i = 0; i < AC97_MAX_STREAMS; i++) 3609 3612 { … … 3613 3616 3614 3617 pHlp->pfnSSMGetMem(pSSM, pThis->mixer_data, sizeof(pThis->mixer_data)); 3615 3616 /** @todo r=andy Stream IDs are hardcoded to certain streams. */3617 uint8_t uaStrmsActive[AC97SOUNDSOURCE_MAX];3618 int rc2 = pHlp->pfnSSMGetMem(pSSM, uaStrmsActive, sizeof(uaStrmsActive));3619 AssertRCReturn(rc2, rc2);3620 3618 3621 3619 ichac97R3MixerRecordSelect(pThis, ichac97MixerGet(pThis, AC97_Record_Select)); … … 3632 3630 ichac97R3MixerSetGain(pThis, pThisCC, AC97_Record_Gain_Mute, PDMAUDIOMIXERCTL_LINE_IN, 3633 3631 ichac97MixerGet(pThis, AC97_Record_Gain_Mute)); 3634 if (pThis-> uCodecModel == AC97_CODEC_AD1980)3632 if (pThis->enmCodecModel == AC97CODEC_AD1980) 3635 3633 if (ichac97MixerGet(pThis, AC97_AD_Misc) & AC97_AD_MISC_HPSEL) 3636 3634 ichac97R3MixerSetVolume(pThis, pThisCC, AC97_Headphone_Volume_Mute, PDMAUDIOMIXERCTL_VOLUME_MASTER, 3637 3635 ichac97MixerGet(pThis, AC97_Headphone_Volume_Mute)); 3638 3636 3639 /** @todo r=andy Stream IDs are hardcoded to certain streams. */ 3637 /* 3638 * Again the stream order is set is stone. 3639 */ 3640 uint8_t afActiveStrms[AC97SOUNDSOURCE_MAX]; 3641 int rc2 = pHlp->pfnSSMGetMem(pSSM, afActiveStrms, sizeof(afActiveStrms)); 3642 AssertRCReturn(rc2, rc2); 3643 3640 3644 for (unsigned i = 0; i < AC97_MAX_STREAMS; i++) 3641 3645 { 3642 const bool fEnable = RT_BOOL( uaStrmsActive[i]);3646 const bool fEnable = RT_BOOL(afActiveStrms[i]); 3643 3647 const PAC97STREAM pStream = &pThis->aStreams[i]; 3644 3648 const PAC97STREAMR3 pStreamCC = &pThisCC->aStreams[i]; … … 3938 3942 * @returns VBox status code. 3939 3943 * @param pDevIns The device instance. 3940 * @param pThis 3944 * @param pThisCC The ring-3 AC'97 device state. 3941 3945 * @param iLun The logical unit which is being replaced. 3942 3946 */ … … 4031 4035 */ 4032 4036 if (!strcmp(szCodec, "STAC9700")) 4033 pThis-> uCodecModel = AC97_CODEC_STAC9700;4037 pThis->enmCodecModel = AC97CODEC_STAC9700; 4034 4038 else if (!strcmp(szCodec, "AD1980")) 4035 pThis-> uCodecModel = AC97_CODEC_AD1980;4039 pThis->enmCodecModel = AC97CODEC_AD1980; 4036 4040 else if (!strcmp(szCodec, "AD1981B")) 4037 pThis-> uCodecModel = AC97_CODEC_AD1981B;4041 pThis->enmCodecModel = AC97CODEC_AD1981B; 4038 4042 else 4039 4043 return PDMDevHlpVMSetError(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, RT_SRC_POS, … … 4074 4078 PCIDevSetInterruptPin(pPciDev, 0x01); /* 3d ro - INTA#. */ Assert(pPciDev->abConfig[0x3d] == 0x01); 4075 4079 4076 if (pThis-> uCodecModel == AC97_CODEC_AD1980)4080 if (pThis->enmCodecModel == AC97CODEC_AD1980) 4077 4081 { 4078 4082 PCIDevSetSubSystemVendorId(pPciDev, 0x1028); /* 2c ro - Dell.) */ 4079 4083 PCIDevSetSubSystemId(pPciDev, 0x0177); /* 2e ro. */ 4080 4084 } 4081 else if (pThis-> uCodecModel == AC97_CODEC_AD1981B)4085 else if (pThis->enmCodecModel == AC97CODEC_AD1981B) 4082 4086 { 4083 4087 PCIDevSetSubSystemVendorId(pPciDev, 0x1028); /* 2c ro - Dell.) */ … … 4110 4114 * Saved state. 4111 4115 */ 4112 rc = PDMDevHlpSSMRegister(pDevIns, AC97_S SM_VERSION, sizeof(*pThis), ichac97R3SaveExec, ichac97R3LoadExec);4116 rc = PDMDevHlpSSMRegister(pDevIns, AC97_SAVED_STATE_VERSION, sizeof(*pThis), ichac97R3SaveExec, ichac97R3LoadExec); 4113 4117 if (RT_FAILURE(rc)) 4114 4118 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.