VirtualBox

Changeset 82362 in vbox for trunk/src


Ignore:
Timestamp:
Dec 3, 2019 11:36:38 PM (5 years ago)
Author:
vboxsync
Message:

DevIchAc97: Cleanups. bugref:9218

File:
1 edited

Legend:

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

    r82361 r82362  
    4848
    4949/** Current saved state version. */
    50 #define AC97_SSM_VERSION    1
     50#define AC97_SAVED_STATE_VERSION 1
    5151
    5252/** Default timer frequency (in Hz). */
    53 #define AC97_TIMER_HZ_DEFAULT 100
     53#define AC97_TIMER_HZ_DEFAULT   100
    5454
    5555/** Maximum number of streams we support. */
    56 #define AC97_MAX_STREAMS      3
     56#define AC97_MAX_STREAMS        3
    5757
    5858/** Maximum FIFO size (in bytes). */
    59 #define AC97_FIFO_MAX       256
     59#define AC97_FIFO_MAX           256
    6060
    6161#define AC97_SR_FIFOE           RT_BIT(4)           /**< rwc, FIFO error. */
     
    146146#define AC97_DB_FACTOR          4
    147147
    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 * @{ */
    161163enum
    162164{
     
    195197    AC97_Vendor_ID2                = 0x7e
    196198};
    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 * @{  */
    207203#define AC97_AD_MISC_LOSEL       RT_BIT(5)   /**< Surround (rear) goes to line out outputs. */
    208204#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/** @}   */
    217213
    218214/** @name AC'97 source indices.
     
    513509
    514510
     511/* Codec models. */
     512typedef 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
    515522/**
    516523 * The shared AC'97 device state.
     
    534541    uint16_t                au16Padding1[3];
    535542    uint8_t                 silence[128];
    536     int32_t                 bup_flag;
     543    uint32_t                bup_flag;
    537544    /** Codec model. */
    538     uint32_t                uCodecModel;
     545    AC97CODEC               enmCodecModel;
    539546
    540547    /** PCI region \#0: NAM I/O ports. */
     
    552559} AC97STATE;
    553560AssertCompileMemberAlignment(AC97STATE, aStreams, 8);
     561#ifdef VBOX_WITH_STATISTICS
     562AssertCompileMemberAlignment(AC97STATE, StatTimer,        8);
     563AssertCompileMemberAlignment(AC97STATE, StatBytesRead,    8);
     564AssertCompileMemberAlignment(AC97STATE, StatBytesWritten, 8);
     565#endif
    554566
    555567
     
    634646    PDMDevHlpTimerUnlockClock2((a_pDevIns), (a_pStream)->hTimer, &(a_pThis)->CritSect)
    635647
    636 #ifdef VBOX_WITH_STATISTICS
    637 AssertCompileMemberAlignment(AC97STATE, StatTimer,        8);
    638 AssertCompileMemberAlignment(AC97STATE, StatBytesRead,    8);
    639 AssertCompileMemberAlignment(AC97STATE, StatBytesWritten, 8);
    640 #endif
    641 
    642648#ifndef VBOX_DEVICE_STRUCT_TESTCASE
    643649
     
    17831789 *
    17841790 * @returns IPRT status code.
    1785  * @param   pThis               The shared AC'97 state.
     1791 * @param   pThisCC             The ring-3 AC'97 state.
    17861792 * @param   pMixSink            Mixer sink to add stream to.
    17871793 * @param   pCfg                Stream configuration to use.
     
    18171823 *
    18181824 * @return IPRT status code.
    1819  * @param  pThis                The ring-3 AC'97 device state.
     1825 * @param  pThisCC              The ring-3 AC'97 device state.
    18201826 * @param  pDrv                 The AC'97 driver to add.
    18211827 */
     
    18481854 * associated streams.
    18491855 *
    1850  * @param pThis                 The ring-3 AC'97 device state.
     1856 * @param pThisCC               The ring-3 AC'97 device state.
    18511857 * @param pDrv                  AC'97 driver to remove.
    18521858 */
     
    19091915 * Removes all driver streams from a specific mixer sink.
    19101916 *
    1911  * @param   pThis               The ring-3 AC'97 state.
     1917 * @param   pThisCC             The ring-3 AC'97 state.
    19121918 * @param   pMixSink            Mixer sink to remove audio streams from.
    19131919 * @param   enmDir              Stream direction to remove.
     
    21812187 *
    21822188 * @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).
    21842190 */
    21852191static uint32_t ichac97R3StreamGetFree(PAC97STREAMR3 pStreamCC)
     
    22162222     * master volume controls.
    22172223     */
    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)
    22192225    {
    22202226        if (uVal & RT_BIT(5))  /* D5 bit set? */
     
    25172523    ichac97MixerSet(pThis, AC97_MIC_ADC_Rate            , 0xbb80 /* 48000 Hz by default */);
    25182524
    2519     if (pThis->uCodecModel == AC97_CODEC_AD1980)
     2525    if (pThis->enmCodecModel == AC97CODEC_AD1980)
    25202526    {
    25212527        /* Analog Devices 1980 (AD1980) */
     
    25252531        ichac97MixerSet(pThis, AC97_Headphone_Volume_Mute   , 0x8000);
    25262532    }
    2527     else if (pThis->uCodecModel == AC97_CODEC_AD1981B)
     2533    else if (pThis->enmCodecModel == AC97CODEC_AD1981B)
    25282534    {
    25292535        /* Analog Devices 1981B (AD1981B) */
     
    33203326                    break;
    33213327                case AC97_Master_Volume_Mute:
    3322                     if (pThis->uCodecModel == AC97_CODEC_AD1980)
     3328                    if (pThis->enmCodecModel == AC97CODEC_AD1980)
    33233329                    {
    33243330                        if (ichac97MixerGet(pThis, AC97_AD_Misc) & AC97_AD_MISC_LOSEL)
     
    33323338                    break;
    33333339                case AC97_Headphone_Volume_Mute:
    3334                     if (pThis->uCodecModel == AC97_CODEC_AD1980)
     3340                    if (pThis->enmCodecModel == AC97CODEC_AD1980)
    33353341                    {
    33363342                        if (ichac97MixerGet(pThis, AC97_AD_Misc) & AC97_AD_MISC_HPSEL)
     
    35003506 * Saves (serializes) an AC'97 stream using SSM.
    35013507 *
    3502  * @returns IPRT status code.
    35033508 * @param   pDevIns             Device instance.
    35043509 * @param   pSSM                Saved state manager (SSM) handle to use.
    35053510 * @param   pStream             AC'97 stream to save.
    35063511 */
    3507 static int ichac97R3SaveStream(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, PAC97STREAM pStream)
     3512static void ichac97R3SaveStream(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, PAC97STREAM pStream)
    35083513{
    35093514    PAC97BMREGS   pRegs = &pStream->Regs;
     
    35203525    pHlp->pfnSSMPutU32(pSSM, pRegs->bd.addr);
    35213526    pHlp->pfnSSMPutU32(pSSM, pRegs->bd.ctl_len);
    3522 
    3523     return VINF_SUCCESS;
    35243527}
    35253528
     
    35323535    PAC97STATER3    pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PAC97STATER3);
    35333536    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
    3534 
    35353537    LogFlowFuncEnter();
    35363538
     
    35393541    pHlp->pfnSSMPutU32(pSSM, pThis->cas);
    35403542
     3543    /*
     3544     * The order that the streams are saved here is fixed, so don't change.
     3545     */
    35413546    /** @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. */
    35433547    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]);
    35483549
    35493550    pHlp->pfnSSMPutMem(pSSM, pThis->mixer_data, sizeof(pThis->mixer_data));
    35503551
    3551     uint8_t active[AC97SOUNDSOURCE_MAX];
    3552 
    3553     active[AC97SOUNDSOURCE_PI_INDEX] = ichac97R3StreamIsEnabled(pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_PI_INDEX]) ? 1 : 0;
    3554     active[AC97SOUNDSOURCE_PO_INDEX] = ichac97R3StreamIsEnabled(pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_PO_INDEX]) ? 1 : 0;
    3555     active[AC97SOUNDSOURCE_MC_INDEX] = ichac97R3StreamIsEnabled(pThisCC, &pThis->aStreams[AC97SOUNDSOURCE_MC_INDEX]) ? 1 : 0;
    3556 
    3557     pHlp->pfnSSMPutMem(pSSM, active, 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));
    35583559
    35593560    LogFlowFuncLeaveRC(VINF_SUCCESS);
     
    35973598    LogRel2(("ichac97LoadExec: uVersion=%RU32, uPass=0x%x\n", uVersion, uPass));
    35983599
    3599     AssertMsgReturn (uVersion == AC97_SSM_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);
    36003601    Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
    36013602
     
    36043605    pHlp->pfnSSMGetU32(pSSM, &pThis->cas);
    36053606
    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     */
    36083611    for (unsigned i = 0; i < AC97_MAX_STREAMS; i++)
    36093612    {
     
    36133616
    36143617    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);
    36203618
    36213619    ichac97R3MixerRecordSelect(pThis, ichac97MixerGet(pThis, AC97_Record_Select));
     
    36323630    ichac97R3MixerSetGain(pThis, pThisCC, AC97_Record_Gain_Mute,        PDMAUDIOMIXERCTL_LINE_IN,
    36333631                          ichac97MixerGet(pThis, AC97_Record_Gain_Mute));
    3634     if (pThis->uCodecModel == AC97_CODEC_AD1980)
     3632    if (pThis->enmCodecModel == AC97CODEC_AD1980)
    36353633        if (ichac97MixerGet(pThis, AC97_AD_Misc) & AC97_AD_MISC_HPSEL)
    36363634            ichac97R3MixerSetVolume(pThis, pThisCC, AC97_Headphone_Volume_Mute, PDMAUDIOMIXERCTL_VOLUME_MASTER,
    36373635                                    ichac97MixerGet(pThis, AC97_Headphone_Volume_Mute));
    36383636
    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
    36403644    for (unsigned i = 0; i < AC97_MAX_STREAMS; i++)
    36413645    {
    3642         const bool          fEnable   = RT_BOOL(uaStrmsActive[i]);
     3646        const bool          fEnable   = RT_BOOL(afActiveStrms[i]);
    36433647        const PAC97STREAM   pStream   = &pThis->aStreams[i];
    36443648        const PAC97STREAMR3 pStreamCC = &pThisCC->aStreams[i];
     
    39383942 * @returns VBox status code.
    39393943 * @param   pDevIns     The device instance.
    3940  * @param   pThis       The ring-3 AC'97 device state.
     3944 * @param   pThisCC     The ring-3 AC'97 device state.
    39413945 * @param   iLun        The logical unit which is being replaced.
    39423946 */
     
    40314035     */
    40324036    if (!strcmp(szCodec, "STAC9700"))
    4033         pThis->uCodecModel = AC97_CODEC_STAC9700;
     4037        pThis->enmCodecModel = AC97CODEC_STAC9700;
    40344038    else if (!strcmp(szCodec, "AD1980"))
    4035         pThis->uCodecModel = AC97_CODEC_AD1980;
     4039        pThis->enmCodecModel = AC97CODEC_AD1980;
    40364040    else if (!strcmp(szCodec, "AD1981B"))
    4037         pThis->uCodecModel = AC97_CODEC_AD1981B;
     4041        pThis->enmCodecModel = AC97CODEC_AD1981B;
    40384042    else
    40394043        return PDMDevHlpVMSetError(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, RT_SRC_POS,
     
    40744078    PCIDevSetInterruptPin(pPciDev,          0x01);   /* 3d ro - INTA#. */               Assert(pPciDev->abConfig[0x3d] == 0x01);
    40754079
    4076     if (pThis->uCodecModel == AC97_CODEC_AD1980)
     4080    if (pThis->enmCodecModel == AC97CODEC_AD1980)
    40774081    {
    40784082        PCIDevSetSubSystemVendorId(pPciDev, 0x1028); /* 2c ro - Dell.) */
    40794083        PCIDevSetSubSystemId(pPciDev,       0x0177); /* 2e ro. */
    40804084    }
    4081     else if (pThis->uCodecModel == AC97_CODEC_AD1981B)
     4085    else if (pThis->enmCodecModel == AC97CODEC_AD1981B)
    40824086    {
    40834087        PCIDevSetSubSystemVendorId(pPciDev, 0x1028); /* 2c ro - Dell.) */
     
    41104114     * Saved state.
    41114115     */
    4112     rc = PDMDevHlpSSMRegister(pDevIns, AC97_SSM_VERSION, sizeof(*pThis), ichac97R3SaveExec, ichac97R3LoadExec);
     4116    rc = PDMDevHlpSSMRegister(pDevIns, AC97_SAVED_STATE_VERSION, sizeof(*pThis), ichac97R3SaveExec, ichac97R3LoadExec);
    41134117    if (RT_FAILURE(rc))
    41144118        return rc;
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