VirtualBox

Changeset 36691 in vbox


Ignore:
Timestamp:
Apr 18, 2011 3:03:15 AM (14 years ago)
Author:
vboxsync
Message:

HDA/Audio: Some clean up. Codecs macro definitions splited from implementation.

Location:
trunk/src/VBox/Devices/Audio
Files:
3 edited

Legend:

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

    r35515 r36691  
    279279        case 1:
    280280            pNode->afg.node.name = "AFG";
    281             pNode->node.au32F00_param[8] = CODEC_MAKE_F00_08(CODEC_F00_08_BEEP_GEN, 0xd, 0xd);
     281            pNode->node.au32F00_param[8] = CODEC_MAKE_F00_08(1, 0xd, 0xd);
    282282            pNode->node.au32F00_param[0xC] =   CODEC_MAKE_F00_0C(0x17)
    283283                                             | CODEC_F00_0C_CAP_BALANCED_IO
     
    13331333        pu32Reg = &pState->pNodes[CODEC_NID(cmd)].pcbeep.u32F07_param;
    13341334    else if (   codecIsReservedNode(pState, CODEC_NID(cmd))
    1335              && CODEC_NID(cmd) == 0x1b
    1336              && pState->enmCodec == STAC9220_CODEC)
     1335             && CODEC_NID(cmd) == 0x1b)
    13371336        pu32Reg = &pState->pNodes[CODEC_NID(cmd)].reserved.u32F07_param;
    13381337    Assert((pu32Reg));
     
    21652164}
    21662165
    2167 int codecConstruct(PPDMDEVINS pDevIns, CODECState *pState, ENMCODEC enmCodec)
     2166int codecConstruct(PPDMDEVINS pDevIns, CODECState *pState, PCFGMNODE pCfgHandle)
    21682167{
    21692168    audsettings_t as;
     
    21722171    pState->cVerbs = sizeof(CODECVERBS)/sizeof(CODECVERB);
    21732172    pState->pfnLookup = codecLookup;
    2174     pState->enmCodec = enmCodec;
    2175     switch (enmCodec)
    2176     {
    2177         case STAC9220_CODEC:
    2178             rc = stac9220Construct(pState);
    2179             AssertRC(rc);
    2180             break;
    2181         case ALC885_CODEC:
    2182             rc = alc885Construct(pState);
    2183             AssertRC(rc);
    2184             break;
    2185         default:
    2186             AssertMsgFailed(("Unsupported Codec"));
    2187     }
     2173    rc = stac9220Construct(pState);
     2174    AssertRC(rc);
    21882175    /* common root node initializers */
    21892176    pState->pNodes[0].node.au32F00_param[0] = CODEC_MAKE_F00_00(pState->u16VendorId, pState->u16DeviceId);
     
    21912178    /* common AFG node initializers */
    21922179    pState->pNodes[1].node.au32F00_param[4] = CODEC_MAKE_F00_04(0x2, pState->cTotalNodes - 2);
    2193     pState->pNodes[1].node.au32F00_param[5] = CODEC_MAKE_F00_05(CODEC_F00_05_UNSOL, CODEC_F00_05_AFG);
     2180    pState->pNodes[1].node.au32F00_param[5] = CODEC_MAKE_F00_05(1, CODEC_F00_05_AFG);
    21942181    pState->pNodes[1].afg.u32F20_param = CODEC_MAKE_F20(pState->u16VendorId, pState->u8BSKU, pState->u8AssemblyId);
    21952182
  • trunk/src/VBox/Devices/Audio/DevCodec.h

    r35515 r36691  
    4848#define CODEC_VERB_CMD8(cmd) (CODEC_VERB_CMD((cmd), CODEC_VERB_8BIT_CMD, 8))
    4949#define CODEC_VERB_CMD16(cmd) (CODEC_VERB_CMD((cmd), CODEC_VERB_16BIT_CMD, 16))
     50#define CODEC_VERB_PAYLOAD4(cmd) ((cmd) & CODEC_VERB_4BIT_DATA)
     51#define CODEC_VERB_PAYLOAD8(cmd) ((cmd) & CODEC_VERB_8BIT_DATA)
     52#define CODEC_VERB_PAYLOAD16(cmd) ((cmd) & CODEC_VERB_16BIT_DATA)
    5053
    5154#define CODEC_VERB_GET_AMP_DIRECTION  RT_BIT(15)
     
    7477/* VendorID (7.3.4.1) */
    7578#define CODEC_MAKE_F00_00(vendorID, deviceID) (((vendorID) << 16) | (deviceID))
     79#define CODEC_F00_00_VENDORID(f00_00) (((f00_00) >> 16) & 0xFFFF)
     80#define CODEC_F00_00_DEVICEID(f00_00) ((f00_00) & 0xFFFF)
    7681/* RevisionID (7.3.4.2)*/
    7782#define CODEC_MAKE_F00_02(MajRev, MinRev, RevisionID, SteppingID) (((MajRev) << 20)|((MinRev) << 16)|((RevisionID) << 8)|(SteppingID))
    7883/* Subordinate node count (7.3.4.3)*/
    7984#define CODEC_MAKE_F00_04(startNodeNumber, totalNodeNumber) ((((startNodeNumber) & 0xFF) << 16)|((totalNodeNumber) & 0xFF))
     85#define CODEC_F00_04_TO_START_NODE_NUMBER(f00_04) (((f00_04) >> 16) & 0xFF)
     86#define CODEC_F00_04_TO_NODE_COUNT(f00_04) ((f00_04) & 0xFF)
    8087/*
    8188 * Function Group Type  (7.3.4.4)
     
    8390 * [0x80 - 0xff] are vendor defined function groups
    8491 */
    85 #define CODEC_MAKE_F00_05(UnSol, NodeType) ((UnSol)|(NodeType))
     92#define CODEC_MAKE_F00_05(UnSol, NodeType) (((UnSol) << 8)|(NodeType))
    8693#define CODEC_F00_05_UNSOL  RT_BIT(8)
    8794#define CODEC_F00_05_AFG    (0x1)
    8895#define CODEC_F00_05_MFG    (0x2)
     96#define CODEC_F00_05_IS_UNSOL(f00_05) RT_BOOL((f00_05) & RT_BIT(8))
     97#define CODEC_F00_05_GROUP(f00_05) ((f00_05) & 0xff)
    8998/*  Audio Function Group capabilities (7.3.4.5) */
    90 #define CODEC_MAKE_F00_08(BeepGen, InputDelay, OutputDelay) ((BeepGen)| (((InputDelay) & 0xF) << 8) | ((OutputDelay) & 0xF))
    91 #define CODEC_F00_08_BEEP_GEN RT_BIT(16)
     99#define CODEC_MAKE_F00_08(BeepGen, InputDelay, OutputDelay) ((((BeepGen) & 0x1) << 16)| (((InputDelay) & 0xF) << 8) | ((OutputDelay) & 0xF))
     100#define CODEC_F00_08_BEEP_GEN(f00_08) ((f00_08) & RT_BIT(16)
    92101
    93102/* Widget Capabilities (7.3.4.6) */
     
    120129#define CODEC_F00_09_CAP_IN_AMP_PRESENT     RT_BIT(1)
    121130#define CODEC_F00_09_CAP_LSB                RT_BIT(0)
     131
     132#define CODEC_F00_09_TYPE(f00_09) (((f00_09) >> 20) & 0xF)
     133
     134#define CODEC_F00_09_IS_CAP_CP(f00_09)              RT_BOOL((f00_09) & RT_BIT(12))
     135#define CODEC_F00_09_IS_CAP_L_R_SWAP(f00_09)        RT_BOOL((f00_09) & RT_BIT(11))
     136#define CODEC_F00_09_IS_CAP_POWER_CTRL(f00_09)      RT_BOOL((f00_09) & RT_BIT(10))
     137#define CODEC_F00_09_IS_CAP_DIGITAL(f00_09)         RT_BOOL((f00_09) & RT_BIT(9))
     138#define CODEC_F00_09_IS_CAP_CONNECTION_LIST(f00_09) RT_BOOL((f00_09) & RT_BIT(8))
     139#define CODEC_F00_09_IS_CAP_UNSOL(f00_09)           RT_BOOL((f00_09) & RT_BIT(7))
     140#define CODEC_F00_09_IS_CAP_PROC_WIDGET(f00_09)     RT_BOOL((f00_09) & RT_BIT(6))
     141#define CODEC_F00_09_IS_CAP_STRIPE(f00_09)          RT_BOOL((f00_09) & RT_BIT(5))
     142#define CODEC_F00_09_IS_CAP_FMT_OVERRIDE(f00_09)    RT_BOOL((f00_09) & RT_BIT(4))
     143#define CODEC_F00_09_IS_CAP_AMP_OVERRIDE(f00_09)    RT_BOOL((f00_09) & RT_BIT(3))
     144#define CODEC_F00_09_IS_CAP_OUT_AMP_PRESENT(f00_09) RT_BOOL((f00_09) & RT_BIT(2))
     145#define CODEC_F00_09_IS_CAP_IN_AMP_PRESENT(f00_09)  RT_BOOL((f00_09) & RT_BIT(1))
     146#define CODEC_F00_09_IS_CAP_LSB(f00_09)             RT_BOOL((f00_09) & RT_BIT(0))
    122147
    123148/* Supported PCM size, rates (7.3.4.7) */
     
    164189#define CODEC_F00_0C_CAP_IMPENDANCE_SENSE       RT_BIT(0)
    165190
    166 /* Amplifier capabilities (7.3.4.10) */
     191#define CODEC_F00_0C_IS_CAP_HBR(f00_0c)                    ((f00_0c) & RT_BIT(27))
     192#define CODEC_F00_0C_IS_CAP_DP(f00_0c)                     ((f00_0c) & RT_BIT(24))
     193#define CODEC_F00_0C_IS_CAP_EAPD(f00_0c)                   ((f00_0c) & RT_BIT(16))
     194#define CODEC_F00_0C_IS_CAP_HDMI(f00_0c)                   ((f00_0c) & RT_BIT(7))
     195#define CODEC_F00_0C_IS_CAP_BALANCED_IO(f00_0c)            ((f00_0c) & RT_BIT(6))
     196#define CODEC_F00_0C_IS_CAP_INPUT(f00_0c)                  ((f00_0c) & RT_BIT(5))
     197#define CODEC_F00_0C_IS_CAP_OUTPUT(f00_0c)                 ((f00_0c) & RT_BIT(4))
     198#define CODEC_F00_0C_IS_CAP_HP(f00_0c)                     ((f00_0c) & RT_BIT(3))
     199#define CODEC_F00_0C_IS_CAP_PRESENSE_DETECT(f00_0c)        ((f00_0c) & RT_BIT(2))
     200#define CODEC_F00_0C_IS_CAP_TRIGGER_REQUIRED(f00_0c)       ((f00_0c) & RT_BIT(1))
     201#define CODEC_F00_0C_IS_CAP_IMPENDANCE_SENSE(f00_0c)       ((f00_0c) & RT_BIT(0))
     202
     203/* Input Amplifier capabilities (7.3.4.10) */
    167204#define CODEC_MAKE_F00_0D(mute_cap, step_size, num_steps, offset) \
    168205        (  (((mute_cap) & 0x1) << 31)                             \
     
    171208         | ((offset) & 0xFF))
    172209
     210/* Output Amplifier capabilities (7.3.4.10) */
     211#define CODEC_MAKE_F00_12 CODEC_MAKE_F00_0D
     212
    173213/* Connection list lenght (7.3.4.11) */
    174214#define CODEC_MAKE_F00_0E(long_form, length)    \
    175215    (  (((long_form) & 0x1) << 7)               \
    176216     | ((length) & 0x7F))
     217#define CODEC_F00_0E_IS_LONG(f00_0e) RT_BOOL((f00_0e) & RT_BIT(7))
     218#define CODEC_F00_0E_COUNT(f00_0e) ((f00_0e) & 0x7F)
    177219/* Supported Power States (7.3.4.12) */
    178220#define CODEC_F00_0F_EPSS       RT_BIT(31)
     
    185227#define CODEC_F00_0F_D0         RT_BIT(0)
    186228
     229/* Processing capabilities 7.3.4.13 */
     230#define CODEC_MAKE_F00_10(num, benign) ((((num) & 0xFF) << 8) | ((benign) & 0x1))
     231#define CODEC_F00_10_NUM(f00_10) (((f00_10) & (0xFF << 8)) >> 8)
     232#define CODEC_F00_10_BENING(f00_10) ((f00_10) & 0x1)
     233
    187234/* CP/IO Count (7.3.4.14) */
    188235#define CODEC_MAKE_F00_11(wake, unsol, numgpi, numgpo, numgpio) \
     
    193240     | ((numgpio) & 0xFF))
    194241
     242/* Processing States (7.3.3.4) */
     243#define CODEC_F03_OFF    (0)
     244#define CODEC_F03_ON     RT_BIT(0)
     245#define CODEC_F03_BENING RT_BIT(1)
    195246/* Power States (7.3.3.10) */
    196247#define CODEC_MAKE_F05(reset, stopok, error, act, set)          \
     
    212263#define CODEC_F05_SET(value)        (((value) & 0x7))
    213264
     265#define CODEC_F05_GE(p0, p1) ((p0) <= (p1))
     266#define CODEC_F05_LE(p0, p1) ((p0) >= (p1))
     267
    214268/* Pin Widged Control (7.3.3.13) */
    215269#define CODEC_F07_VREF_HIZ      (0)
     
    222276#define CODEC_F07_OUT_H_ENABLE  RT_BIT(7)
    223277
     278/* Unsolicited enabled (7.3.3.14) */
     279#define CODEC_MAKE_F08(enable, tag) ((((enable) & 1) << 7) | ((tag) & 0x3F))
     280
    224281/* Converter formats (7.3.3.8) and (3.7.1) */
    225282#define CODEC_MAKE_A(fNonPCM, f44_1BaseRate, mult, div, bits, chan) \
     
    260317  | (((fELDValid) & 0x1) << 30))
    261318
     319#define CODEC_MAKE_F0C(lrswap, eapd, btl) ((((lrswap) & 1) << 2) | (((eapd) & 1) << 1) | ((btl) & 1))
     320#define CODEC_FOC_IS_LRSWAP(f0c)    RT_BOOL((f0c) & RT_BIT(2))
     321#define CODEC_FOC_IS_EAPD(f0c)      RT_BOOL((f0c) & RT_BIT(1))
     322#define CODEC_FOC_IS_BTL(f0c)       RT_BOOL((f0c) & RT_BIT(0))
    262323/* HDA spec 7.3.3.31 defines layout of configuration registers/verbs (0xF1C) */
    263324/* Configuration's port connection */
     
    289350#define CODEC_F1C_LOCATION_SPECIAL_0           (0x7)
    290351#define CODEC_F1C_LOCATION_SPECIAL_1           (0x8)
    291 #define CODEC_F1C_LOCATION_SPECIAL_3           (0x9)
     352#define CODEC_F1C_LOCATION_SPECIAL_2           (0x9)
    292353
    293354/* Configuration's devices */
     
    351412#define CODEC_F1C_MISC_MASK                  (0xF)
    352413#define CODEC_F1C_MISC_SHIFT                 (8)
    353 #define CODEC_F1C_MISC_JACK_DETECT           RT_BIT(0)
    354 #define CODEC_F1C_MISC_RESERVED_0            RT_BIT(1)
    355 #define CODEC_F1C_MISC_RESERVED_1            RT_BIT(2)
    356 #define CODEC_F1C_MISC_RESERVED_2            RT_BIT(3)
     414#define CODEC_F1C_MISC_JACK_DETECT           (0)
     415#define CODEC_F1C_MISC_RESERVED_0            (1)
     416#define CODEC_F1C_MISC_RESERVED_1            (2)
     417#define CODEC_F1C_MISC_RESERVED_2            (3)
    357418
    358419/* Configuration's association */
     
    382443
    383444
     445#ifndef VBOX_WITH_HDA_CODEC_EMU
    384446typedef struct CODECVERB
    385447{
     
    389451    PFNCODECVERBPROCESSOR pfn;
    390452} CODECVERB;
    391 
    392 #ifndef VBOX_HDA_CODEC_EMU
     453#endif
     454
     455#ifndef VBOX_WITH_HDA_CODEC_EMU
    393456# define TYPE union
    394457#else
    395458# define TYPE struct
     459typedef struct CODECEMU CODECEMU;
     460typedef CODECEMU *PCODECEMU;
    396461#endif
    397462TYPE CODECNODE;
     
    408473} ENMSOUNDSOURCE;
    409474
    410 typedef enum
    411 {
    412     STAC9220_CODEC,
    413     ALC885_CODEC
    414 } ENMCODEC;
    415475
    416476typedef struct CODECState
     
    421481    uint8_t                 u8BSKU;
    422482    uint8_t                 u8AssemblyId;
     483#ifndef VBOX_WITH_HDA_CODEC_EMU
    423484    CODECVERB               *pVerbs;
    424485    int                     cVerbs;
     486#else
     487    PCODECEMU               pCodecBackend;
     488#endif
    425489    PCODECNODE               pNodes;
    426490    QEMUSoundCard           card;
     
    429493    /** PCM out */
    430494    SWVoiceOut              *SwVoiceOut;
    431     ENMCODEC                enmCodec;
    432495    void                    *pHDAState;
    433496    bool                    fInReset;
     497#ifndef VBOX_WITH_HDA_CODEC_EMU
    434498    const uint8_t           cTotalNodes;
    435499    const uint8_t           *au8Ports;
     
    448512    const uint8_t           u8AdcVolsLineIn;
    449513    const uint8_t           u8DacLineOut;
     514#endif
    450515    DECLR3CALLBACKMEMBER(int, pfnProcess, (struct CODECState *));
     516    DECLR3CALLBACKMEMBER(void, pfnTransfer, (struct CODECState *pState, ENMSOUNDSOURCE, int avail));
     517    /* These callbacks are set by Codec implementation */
    451518    DECLR3CALLBACKMEMBER(int, pfnLookup, (struct CODECState *pState, uint32_t verb, PPFNCODECVERBPROCESSOR));
    452519    DECLR3CALLBACKMEMBER(int, pfnReset, (struct CODECState *pState));
    453     DECLR3CALLBACKMEMBER(void, pfnTransfer, (struct CODECState *pState, ENMSOUNDSOURCE, int avail));
    454520    DECLR3CALLBACKMEMBER(int, pfnCodecNodeReset, (struct CODECState *pState, uint8_t, PCODECNODE));
    455 
    456 } CODECState;
    457 
    458 int codecConstruct(PPDMDEVINS pDevIns, CODECState *pCodecState, ENMCODEC enmCodec);
     521    /* These callbacks are set by codec implementation to answer debugger requests */
     522    DECLR3CALLBACKMEMBER(void, pfnCodecDbgListNodes, (CODECState *pState, PCDBGFINFOHLP pHlp, const char *pszArgs));
     523    DECLR3CALLBACKMEMBER(void, pfnCodecDbgSelector, (CODECState *pState, PCDBGFINFOHLP pHlp, const char *pszArgs));
     524} CODECState, *PCODECState;
     525
     526int codecConstruct(PPDMDEVINS pDevIns, CODECState *pCodecState, PCFGMNODE pCfgHandle);
    459527int codecDestruct(CODECState *pCodecState);
    460528int codecSaveState(CODECState *pCodecState, PSSMHANDLE pSSMHandle);
     
    462530int codecOpenVoice(CODECState *pCodecState, ENMSOUNDSOURCE enmSoundSource, audsettings_t *pAudioSettings);
    463531
     532# ifdef VBOX_WITH_HDA_CODEC_EMU
     533/* */
     534struct CODECEMU
     535{
     536    DECLR3CALLBACKMEMBER(int, pfnCodecEmuConstruct, (PCODECState pState));
     537    DECLR3CALLBACKMEMBER(int, pfnCodecEmuDestruct, (PCODECState pState));
     538    DECLR3CALLBACKMEMBER(int, pfnCodecEmuReset, (PCODECState pState, bool fInit));
     539};
     540# endif
    464541#endif
  • trunk/src/VBox/Devices/Audio/DevIchIntelHDA.cpp

    r35515 r36691  
    5858static DECLCALLBACK(void)  hdaReset (PPDMDEVINS pDevIns);
    5959
     60#define HDA_NREGS 112
    6061/* Registers */
    6162#define HDA_REG_IND_NAME(x) ICH6_HDA_REG_##x
     
    263264#define ICH6_HDA_SDCTL_NUM_MASK   (0xF)
    264265#define ICH6_HDA_SDCTL_NUM_SHIFT  (20)
     266#define ICH6_HDA_SDCTL_DIR_SHIFT  (19)
     267#define ICH6_HDA_SDCTL_TP_SHIFT   (18)
     268#define ICH6_HDA_SDCTL_STRIPE_MASK  (0x3)
     269#define ICH6_HDA_SDCTL_STRIPE_SHIFT (16)
    265270#define ICH6_HDA_SDCTL_DEIE_SHIFT (4)
    266271#define ICH6_HDA_SDCTL_FEIE_SHIFT (3)
     
    373378#define ICH6_HDA_SDFMT_DIV_SHIFT (8)
    374379#define ICH6_HDA_SDFMT_DIV_MASK (0x7)
     380#define ICH6_HDA_SDFMT_BITS_SHIFT (4)
     381#define ICH6_HDA_SDFMT_BITS_MASK (0x7)
    375382#define SDFMT_BASE_RATE(pState, num) ((SDFMT(pState, num) & HDA_REG_FIELD_FLAG_MASK(SDFMT, BASE_RATE)) >> HDA_REG_FIELD_SHIFT(SDFMT, BASE_RATE))
    376383#define SDFMT_MULT(pState, num) ((SDFMT((pState), num) & HDA_REG_FIELD_MASK(SDFMT,MULT)) >> HDA_REG_FIELD_SHIFT(SDFMT, MULT))
     
    435442    PDMIBASE                IBase;
    436443    RTGCPHYS    addrMMReg;
    437     uint32_t     au32Regs[113];
     444    uint32_t     au32Regs[HDA_NREGS];
    438445    HDABDLEDESC  stInBdle;
    439446    HDABDLEDESC  stOutBdle;
     
    522529#endif
    523530
     531
    524532/* see 302349 p 6.2*/
    525533const static struct stIchIntelHDRegMap
     
    541549    /** Full name. */
    542550    const char *name;
    543 } s_ichIntelHDRegMap[] =
     551} s_ichIntelHDRegMap[HDA_NREGS] =
    544552{
    545553    /* offset  size     read mask   write mask         read callback         write callback         abbrev      full name                     */
     
    12491257    }
    12501258    pAudSetting->freq = u32Hz * u32HzMult / u32HzDiv;
    1251     pAudSetting->nchannels = 2;
     1259
     1260    switch (EXTRACT_VALUE(u32SdFmt, ICH6_HDA_SDFMT_BITS_MASK, ICH6_HDA_SDFMT_BITS_SHIFT))
     1261    {
     1262        case 0:
     1263            Log(("hda: %s requested 8 bit\n", __FUNCTION__));
     1264            pAudSetting->fmt = AUD_FMT_S8;
     1265        break;
     1266        case 1:
     1267            Log(("hda: %s requested 16 bit\n", __FUNCTION__));
     1268            pAudSetting->fmt = AUD_FMT_S16;
     1269        break;
     1270        case 2:
     1271            Log(("hda: %s requested 20 bit\n", __FUNCTION__));
     1272        break;
     1273        case 3:
     1274            Log(("hda: %s requested 24 bit\n", __FUNCTION__));
     1275        break;
     1276        case 4:
     1277            Log(("hda: %s requested 32 bit\n", __FUNCTION__));
     1278            pAudSetting->fmt = AUD_FMT_S32;
     1279        break;
     1280        default:
     1281            AssertMsgFailed(("Unsupported"));
     1282    }
     1283    pAudSetting->nchannels = (u32SdFmt & 0xf) + 1;
    12521284    pAudSetting->fmt = AUD_FMT_S16;
    12531285    pAudSetting->endianness = 0;
     
    12571289DECLCALLBACK(int)hdaRegWriteSDFMT(INTELHDLinkState* pState, uint32_t offset, uint32_t index, uint32_t u32Value)
    12581290{
    1259 #if 0
    1260         /* @todo here some more investigations are required. */
    1261         audsettings_t as;
    1262         /* no reason to reopen voice with same settings */
    1263         if (u32Value == HDA_REG_IND(pState, index))
    1264             return VINF_SUCCESS;
    1265         hdaSdFmtToAudSettings(u32Value, &as);
    1266         switch (index)
    1267         {
    1268             case ICH6_HDA_REG_SD0FMT:
    1269                 codecOpenVoice(&pState->Codec, PI_INDEX, &as);
    1270                 break;
    1271             case ICH6_HDA_REG_SD4FMT:
    1272                 codecOpenVoice(&pState->Codec, PO_INDEX, &as);
    1273                 break;
    1274             default:
    1275                 AssertMsgFailed(("unimplemented"));
    1276         }
     1291#ifdef VBOX_WITH_HDA_CODEC_EMU
     1292    /* @todo here some more investigations are required. */
     1293    int rc = 0;
     1294    audsettings_t as;
     1295    /* no reason to reopen voice with same settings */
     1296    if (u32Value == HDA_REG_IND(pState, index))
     1297        return VINF_SUCCESS;
     1298    hdaSdFmtToAudSettings(u32Value, &as);
     1299    switch (index)
     1300    {
     1301        case ICH6_HDA_REG_SD0FMT:
     1302            rc = codecOpenVoice(&pState->Codec, PI_INDEX, &as);
     1303            break;
     1304        case ICH6_HDA_REG_SD4FMT:
     1305            rc = codecOpenVoice(&pState->Codec, PO_INDEX, &as);
     1306            break;
     1307        default:
     1308            Log(("HDA: attempt to change format on %d\n", index));
     1309            rc = 0;
     1310    }
     1311    return hdaRegWriteU16(pState, offset, index, u32Value);
     1312#else
     1313    return hdaRegWriteU16(pState, offset, index, u32Value);
    12771314#endif
    1278         return hdaRegWriteU16(pState, offset, index, u32Value);
    12791315}
    12801316
     
    20612097}
    20622098
     2099static inline int hdaLookUpRegisterByName(INTELHDLinkState *pState, const char *pszArgs)
     2100{
     2101    int iReg = 0;
     2102    for (; iReg < HDA_NREGS; ++iReg)
     2103        if (!RTStrICmp(s_ichIntelHDRegMap[iReg].abbrev, pszArgs))
     2104            return iReg;
     2105    return -1;
     2106}
     2107static inline void hdaDbgPrintRegister(INTELHDLinkState *pState, PCDBGFINFOHLP pHlp, int iHdaIndex)
     2108{
     2109    Assert(   pState
     2110           && iHdaIndex >= 0
     2111           && iHdaIndex < HDA_NREGS);
     2112    pHlp->pfnPrintf(pHlp, "hda: %s: 0x%x\n", s_ichIntelHDRegMap[iHdaIndex].abbrev, pState->au32Regs[iHdaIndex]);
     2113}
     2114static DECLCALLBACK(void) hdaDbgInfo(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
     2115{
     2116    PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
     2117    INTELHDLinkState *hda = &pThis->hda;
     2118    int iHdaRegisterIndex = hdaLookUpRegisterByName(hda, pszArgs);
     2119    if (iHdaRegisterIndex != -1)
     2120        hdaDbgPrintRegister(hda, pHlp, iHdaRegisterIndex);
     2121    else
     2122        for(iHdaRegisterIndex = 0; (unsigned int)iHdaRegisterIndex < HDA_NREGS; ++iHdaRegisterIndex)
     2123            hdaDbgPrintRegister(hda, pHlp, iHdaRegisterIndex);
     2124}
     2125
     2126static inline void hdaDbgPrintStream(INTELHDLinkState *pState, PCDBGFINFOHLP pHlp, int iHdaStrmIndex)
     2127{
     2128    Assert(   pState
     2129           && iHdaStrmIndex >= 0
     2130           && iHdaStrmIndex < 7);
     2131    pHlp->pfnPrintf(pHlp, "Dump of %d Hda Stream:\n", iHdaStrmIndex);
     2132    pHlp->pfnPrintf(pHlp, "SD%dCTL: %R[sdctl]\n", iHdaStrmIndex, HDA_STREAM_REG2(pState, CTL, iHdaStrmIndex));
     2133    pHlp->pfnPrintf(pHlp, "SD%dCTS: %R[sdsts]\n", iHdaStrmIndex, HDA_STREAM_REG2(pState, STS, iHdaStrmIndex));
     2134    pHlp->pfnPrintf(pHlp, "SD%dFIFOS: %R[sdfifos]\n", iHdaStrmIndex, HDA_STREAM_REG2(pState, FIFOS, iHdaStrmIndex));
     2135    pHlp->pfnPrintf(pHlp, "SD%dFIFOW: %R[sdfifow]\n", iHdaStrmIndex, HDA_STREAM_REG2(pState, FIFOW, iHdaStrmIndex));
     2136}
     2137
     2138static inline int hdaLookUpStreamIndex(INTELHDLinkState *pState, const char *pszArgs)
     2139{
     2140    /* todo: add args parsing */
     2141    return -1;
     2142}
     2143static DECLCALLBACK(void) hdaDbgStreamInfo(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
     2144{
     2145    PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
     2146    INTELHDLinkState *hda = &pThis->hda;
     2147    int iHdaStrmIndex = hdaLookUpStreamIndex(hda, pszArgs);
     2148    if (iHdaStrmIndex != -1)
     2149        hdaDbgPrintStream(hda, pHlp, iHdaStrmIndex);
     2150    else
     2151        for(iHdaStrmIndex = 0; iHdaStrmIndex < 7; ++iHdaStrmIndex)
     2152            hdaDbgPrintStream(hda, pHlp, iHdaStrmIndex);
     2153}
     2154
     2155/* Codec debugger interface */
     2156static DECLCALLBACK(void) hdaCodecDbgNodes(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
     2157{
     2158    PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
     2159    INTELHDLinkState *hda = &pThis->hda;
     2160    if (hda->Codec.pfnCodecDbgListNodes)
     2161        hda->Codec.pfnCodecDbgListNodes(&hda->Codec, pHlp, pszArgs);
     2162    else
     2163        pHlp->pfnPrintf(pHlp, "Codec implementation doesn't provide corresponding callback.\n");
     2164}
     2165
     2166static DECLCALLBACK(void) hdaCodecDbgSelector(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
     2167{
     2168    PCIINTELHDLinkState *pThis = PDMINS_2_DATA(pDevIns, PCIINTELHDLinkState *);
     2169    INTELHDLinkState *hda = &pThis->hda;
     2170    if (hda->Codec.pfnCodecDbgSelector)
     2171        hda->Codec.pfnCodecDbgSelector(&hda->Codec, pHlp, pszArgs);
     2172    else
     2173        pHlp->pfnPrintf(pHlp, "Codec implementation doesn't provide corresponding callback.\n");
     2174}
     2175
    20632176//#define HDA_AS_PCI_EXPRESS
     2177/* Misc routines */
     2178static inline bool printHdaIsValid(const char *pszType, const char *pszExpectedFlag)
     2179{
     2180    return (RTStrCmp(pszType, pszExpectedFlag) == 0);
     2181}
     2182static const char *printHdaYesNo(bool fFlag)
     2183{
     2184    return fFlag ? "yes" : "no";
     2185}
     2186static DECLCALLBACK(size_t)
     2187printHdaStrmCtl(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
     2188                 const char *pszType, void const *pvValue,
     2189                 int cchWidth, int cchPrecision, unsigned fFlags,
     2190                 void *pvUser)
     2191{
     2192    uint32_t sdCtl = (uint32_t)(uintptr_t)pvValue;
     2193    size_t cb = 0;
     2194    if (!printHdaIsValid(pszType, "sdctl"))
     2195        return cb;
     2196    cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
     2197                      "SDCTL(raw: %#0x, strm:0x%x, dir:%s, tp:%s strip:%x, deie:%s, ioce:%s, run:%s, srst:%s)",
     2198                      sdCtl,
     2199                      ((sdCtl & HDA_REG_FIELD_MASK(SDCTL, NUM)) >> ICH6_HDA_SDCTL_NUM_SHIFT),
     2200                      printHdaYesNo(RT_BOOL(sdCtl & HDA_REG_FIELD_FLAG_MASK(SDCTL, DIR))),
     2201                      printHdaYesNo(RT_BOOL(sdCtl & HDA_REG_FIELD_FLAG_MASK(SDCTL, TP))),
     2202                      ((sdCtl & HDA_REG_FIELD_MASK(SDCTL, STRIPE)) >> ICH6_HDA_SDCTL_STRIPE_SHIFT),
     2203                      printHdaYesNo(RT_BOOL(sdCtl & HDA_REG_FIELD_FLAG_MASK(SDCTL, DEIE))),
     2204                      printHdaYesNo(RT_BOOL(sdCtl & HDA_REG_FIELD_FLAG_MASK(SDCTL, ICE))),
     2205                      printHdaYesNo(RT_BOOL(sdCtl & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN))),
     2206                      printHdaYesNo(RT_BOOL(sdCtl & HDA_REG_FIELD_FLAG_MASK(SDCTL, SRST))));
     2207    return cb;
     2208}
     2209
     2210static DECLCALLBACK(size_t)
     2211printHdaStrmFifos(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
     2212                 const char *pszType, void const *pvValue,
     2213                 int cchWidth, int cchPrecision, unsigned fFlags,
     2214                 void *pvUser)
     2215{
     2216    uint32_t sdFifos = (uint32_t)(uintptr_t)pvValue;
     2217    uint32_t u32Bytes = 0;
     2218    size_t cb = 0;
     2219    if (!printHdaIsValid(pszType, "sdfifos"))
     2220        return cb;
     2221    switch(sdFifos)
     2222    {
     2223        case HDA_SDONFIFO_16B: u32Bytes = 16; break;
     2224        case HDA_SDONFIFO_32B: u32Bytes = 32; break;
     2225        case HDA_SDONFIFO_64B: u32Bytes = 64; break;
     2226        case HDA_SDONFIFO_128B: u32Bytes = 128; break;
     2227        case HDA_SDONFIFO_192B: u32Bytes = 192; break;
     2228        case HDA_SDONFIFO_256B: u32Bytes = 256; break;
     2229        case HDA_SDINFIFO_120B: u32Bytes = 120; break;
     2230        case HDA_SDINFIFO_160B: u32Bytes = 160; break;
     2231        default:;
     2232    }
     2233    cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
     2234                      "SDFIFOS(raw: %#0x, sdfifos:%d B)",
     2235                      sdFifos,
     2236                      u32Bytes);
     2237    return cb;
     2238}
     2239
     2240static DECLCALLBACK(size_t)
     2241printHdaStrmFifow(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
     2242                 const char *pszType, void const *pvValue,
     2243                 int cchWidth, int cchPrecision, unsigned fFlags,
     2244                 void *pvUser)
     2245{
     2246    uint32_t sdFifow = (uint32_t)(uintptr_t)pvValue;
     2247    uint32_t u32Bytes = 0;
     2248    size_t cb = 0;
     2249    if (!printHdaIsValid(pszType, "sdfifow"))
     2250        return cb;
     2251    switch(sdFifow)
     2252    {
     2253        case HDA_SDFIFOW_8B: u32Bytes = 8; break;
     2254        case HDA_SDFIFOW_16B: u32Bytes = 16; break;
     2255        case HDA_SDFIFOW_32B: u32Bytes = 32; break;
     2256    }
     2257    cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
     2258                      "SDFIFOW(raw: %#0x, sdfifow:%d B)",
     2259                      sdFifow,
     2260                      u32Bytes);
     2261    return cb;
     2262}
     2263
     2264static DECLCALLBACK(size_t)
     2265printHdaStrmSts(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
     2266                 const char *pszType, void const *pvValue,
     2267                 int cchWidth, int cchPrecision, unsigned fFlags,
     2268                 void *pvUser)
     2269{
     2270    uint32_t sdSts = (uint32_t)(uintptr_t)pvValue;
     2271    size_t cb = 0;
     2272    if (!printHdaIsValid(pszType, "sdsts"))
     2273        return cb;
     2274    cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
     2275                      "SDSTS(raw: %#0x, fifordy:%s, dese:%s, fifoe:%s, bcis:%s)",
     2276                      sdSts,
     2277                      printHdaYesNo(RT_BOOL(sdSts & HDA_REG_FIELD_FLAG_MASK(SDSTS, FIFORDY))),
     2278                      printHdaYesNo(RT_BOOL(sdSts & HDA_REG_FIELD_FLAG_MASK(SDSTS, DE))),
     2279                      printHdaYesNo(RT_BOOL(sdSts & HDA_REG_FIELD_FLAG_MASK(SDSTS, FE))),
     2280                      printHdaYesNo(RT_BOOL(sdSts & HDA_REG_FIELD_FLAG_MASK(SDSTS, BCIS))));
     2281    return cb;
     2282}
     2283/**
     2284 * This routine registers debugger info extensions and custom printf formatters
     2285 */
     2286static inline int hdaInitMisc(PPDMDEVINS pDevIns)
     2287{
     2288    int rc;
     2289    PDMDevHlpDBGFInfoRegister(pDevIns, "hda", "HDA info. (hda [register case-insensitive])", hdaDbgInfo);
     2290    PDMDevHlpDBGFInfoRegister(pDevIns, "hdastrm", "HDA stream info. (hdastrm [stream number])", hdaDbgStreamInfo);
     2291    PDMDevHlpDBGFInfoRegister(pDevIns, "hdcnodes", "HDA codec nodes.", hdaCodecDbgNodes);
     2292    PDMDevHlpDBGFInfoRegister(pDevIns, "hdcselector", "HDA codec's selector states [node number].", hdaCodecDbgSelector);
     2293    rc = RTStrFormatTypeRegister("sdctl", printHdaStrmCtl, NULL);
     2294    AssertRC(rc);
     2295    rc = RTStrFormatTypeRegister("sdsts", printHdaStrmSts, NULL);
     2296    AssertRC(rc);
     2297    rc = RTStrFormatTypeRegister("sdfifos", printHdaStrmFifos, NULL);
     2298    AssertRC(rc);
     2299    rc = RTStrFormatTypeRegister("sdfifow", printHdaStrmFifow, NULL);
     2300    AssertRC(rc);
     2301#if 0
     2302    rc = RTStrFormatTypeRegister("sdfmt", printHdaStrmFmt, NULL);
     2303    AssertRC(rc);
     2304#endif
     2305    return rc;
     2306}
    20642307
    20652308/**
     
    22182461
    22192462    pThis->hda.Codec.pHDAState = (void *)&pThis->hda;
    2220     rc = codecConstruct(pDevIns, &pThis->hda.Codec, /* ALC885_CODEC */ STAC9220_CODEC);
     2463    rc = codecConstruct(pDevIns, &pThis->hda.Codec, pCfgHandle);
    22212464    if (RT_FAILURE(rc))
    22222465        AssertRCReturn(rc, rc);
     
    22392482    WAKEEN(&pThis->hda) = 0x0;
    22402483    STATESTS(&pThis->hda) = 0x0;
     2484    hdaInitMisc(pDevIns);
    22412485
    22422486    return VINF_SUCCESS;
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