VirtualBox

Changeset 46272 in vbox for trunk/src/VBox/Devices/Audio


Ignore:
Timestamp:
May 26, 2013 6:02:48 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
86011
Message:

Audio/DevIchHda: Implement support for R0 and RC

File:
1 edited

Legend:

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

    r45654 r46272  
    2828
    2929#include <iprt/assert.h>
    30 #include <iprt/uuid.h>
    31 #include <iprt/string.h>
    32 #include <iprt/mem.h>
    3330#include <iprt/asm.h>
    3431#include <iprt/asm-math.h>
     32#ifdef IN_RING3
     33# include <iprt/uuid.h>
     34# include <iprt/string.h>
     35# include <iprt/mem.h>
     36#endif
    3537
    3638#include "VBoxDD.h"
     
    5153/* HP Pavilion dv4t-1300 */
    5254# define HDA_PCI_VENDOR_ID 0x103c
    53 # define HDA_PCI_DEICE_ID 0x30f7
     55# define HDA_PCI_DEVICE_ID 0x30f7
    5456#elif defined(VBOX_WITH_INTEL_HDA)
    5557/* Intel HDA controller */
    5658# define HDA_PCI_VENDOR_ID 0x8086
    57 # define HDA_PCI_DEICE_ID 0x2668
     59# define HDA_PCI_DEVICE_ID 0x2668
    5860#elif defined(VBOX_WITH_NVIDIA_HDA)
    5961/* nVidia HDA controller */
    6062# define HDA_PCI_VENDOR_ID 0x10de
    61 # define HDA_PCI_DEICE_ID 0x0ac0
     63# define HDA_PCI_DEVICE_ID 0x0ac0
    6264#else
    6365# error "Please specify your HDA device vendor/device IDs"
     
    453455{
    454456    /** The PCI device structure. */
    455     PCIDevice               PciDev;
    456     /** Pointer to the device instance. */
    457     PPDMDEVINSR3            pDevIns;
     457    PCIDevice                          PciDev;
     458    /** R3 Pointer to the device instance. */
     459    PPDMDEVINSR3                       pDevInsR3;
     460    /** R0 Pointer to the device instance. */
     461    PPDMDEVINSR0                       pDevInsR0;
     462    /** R0 Pointer to the device instance. */
     463    PPDMDEVINSRC                       pDevInsRC;
     464
     465    uint32_t                           u32Padding;
     466
    458467    /** Pointer to the connector of the attached audio driver. */
    459     PPDMIAUDIOCONNECTOR     pDrv;
     468    R3PTRTYPE(PPDMIAUDIOCONNECTOR)     pDrv;
    460469    /** Pointer to the attached audio driver. */
    461     PPDMIBASE               pDrvBase;
     470    R3PTRTYPE(PPDMIBASE)               pDrvBase;
    462471    /** The base interface for LUN\#0. */
    463     PDMIBASE                IBase;
    464     RTGCPHYS                MMIOBaseAddr;
    465     uint32_t                au32Regs[HDA_NREGS];
    466     HDABDLEDESC             StInBdle;
    467     HDABDLEDESC             StOutBdle;
    468     HDABDLEDESC             StMicBdle;
     472    PDMIBASE                           IBase;
     473    RTGCPHYS                           MMIOBaseAddr;
     474    uint32_t                           au32Regs[HDA_NREGS];
     475    HDABDLEDESC                        StInBdle;
     476    HDABDLEDESC                        StOutBdle;
     477    HDABDLEDESC                        StMicBdle;
     478    uint64_t                           u64CORBBase;
     479    uint64_t                           u64RIRBBase;
     480    uint64_t                           u64DPBase;
     481    /** pointer to CORB buf */
     482    R3PTRTYPE(uint32_t *)              pu32CorbBuf;
     483    /** size in bytes of CORB buf */
     484    uint32_t                           cbCorbBuf;
     485    uint32_t                           u32Padding2;
     486    /** pointer on RIRB buf */
     487    R3PTRTYPE(uint64_t *)              pu64RirbBuf;
     488    /** size in bytes of RIRB buf */
     489    uint32_t                           cbRirbBuf;
     490    /** indicates if HDA in reset. */
     491    bool                               fInReset;
    469492    /** Interrupt on completion */
    470     bool                    fCviIoc;
    471     uint64_t                u64CORBBase;
    472     uint64_t                u64RIRBBase;
    473     uint64_t                u64DPBase;
    474     /** pointer to CORB buf */
    475     uint32_t               *pu32CorbBuf;
    476     /** size in bytes of CORB buf */
    477     uint32_t                cbCorbBuf;
    478     /** pointer on RIRB buf */
    479     uint64_t               *pu64RirbBuf;
    480     /** size in bytes of RIRB buf */
    481     uint32_t                cbRirbBuf;
    482     /** indicates if HDA in reset. */
    483     bool                    fInReset;
     493    bool                               fCviIoc;
     494    /** Flag whether the R0 part is enabled. */
     495    bool                               fR0Enabled;
     496    /** Flag whether the RC part is enabled. */
     497    bool                               fRCEnabled;
    484498    /** The HDA codec state. */
    485     HDACODEC                Codec;
     499    R3PTRTYPE(PHDACODEC)               pCodec;
     500    uint64_t                           u64BaseTS;
    486501    /** 1.2.3.4.5.6.7. - someone please tell me what I'm counting! - .8.9.10... */
    487     uint8_t                 u8Counter;
    488     uint64_t                u64BaseTS;
     502    uint8_t                            u8Counter;
     503    uint8_t                            au8Padding[7];
    489504} HDASTATE;
    490505/** Pointer to the ICH Intel HD Audio Controller state. */
     
    492507
    493508#define ISD0FMT_TO_AUDIO_SELECTOR(pThis) \
    494     ( AUDIO_FORMAT_SELECTOR(&(pThis)->Codec, In, SDFMT_BASE_RATE(pThis, 0), SDFMT_MULT(pThis, 0), SDFMT_DIV(pThis, 0)) )
     509    ( AUDIO_FORMAT_SELECTOR((pThis)->pCodec, In, SDFMT_BASE_RATE(pThis, 0), SDFMT_MULT(pThis, 0), SDFMT_DIV(pThis, 0)) )
    495510#define OSD0FMT_TO_AUDIO_SELECTOR(pThis) \
    496     ( AUDIO_FORMAT_SELECTOR(&(pThis)->Codec, Out, SDFMT_BASE_RATE(pThis, 4), SDFMT_MULT(pThis, 4), SDFMT_DIV(pThis, 4)) )
     511    ( AUDIO_FORMAT_SELECTOR((pThis)->pCodec, Out, SDFMT_BASE_RATE(pThis, 4), SDFMT_MULT(pThis, 4), SDFMT_DIV(pThis, 4)) )
    497512
    498513
     
    500515*   Internal Functions                                                         *
    501516*******************************************************************************/
     517#ifndef VBOX_DEVICE_STRUCT_TESTCASE
    502518static FNPDMDEVRESET hdaReset;
    503519
     
    540556static int hdaRegWriteU8(PHDASTATE pThis, uint32_t iReg, uint32_t pu32Value);
    541557
     558#ifdef IN_RING3
    542559DECLINLINE(void) hdaInitTransferDescriptor(PHDASTATE pThis, PHDABDLEDESC pBdle, uint8_t u8Strm,
    543560                                           PHDASTREAMTRANSFERDESC pStreamDesc);
     
    545562#ifdef LOG_ENABLED
    546563static void dump_bd(PHDASTATE pThis, PHDABDLEDESC pBdle, uint64_t u64BaseDMA);
     564#endif
    547565#endif
    548566
     
    727745};
    728746
    729 
     747#ifdef IN_RING3
    730748/** HDABDLEDESC field descriptors the v3+ saved state. */
    731749static SSMFIELD const g_aHdaBDLEDescFields[] =
     
    756774    SSMFIELD_ENTRY_TERM()
    757775};
     776#endif
    758777
    759778/**
     
    765784};
    766785
    767 
     786#ifdef IN_RING3
    768787DECLINLINE(void) hdaUpdatePosBuf(PHDASTATE pThis, PHDASTREAMTRANSFERDESC pStreamDesc)
    769788{
    770789    if (pThis->u64DPBase & DPBASE_ENABLED)
    771         PDMDevHlpPCIPhysWrite(pThis->pDevIns,
     790        PDMDevHlpPCIPhysWrite(pThis->CTX_SUFF(pDevIns),
    772791                              (pThis->u64DPBase & DPBASE_ADDR_MASK) + pStreamDesc->u8Strm * 8,
    773792                              pStreamDesc->pu32Lpib, sizeof(uint32_t));
    774793}
     794#endif
     795
    775796DECLINLINE(uint32_t) hdaFifoWToSz(PHDASTATE pThis, PHDASTREAMTRANSFERDESC pStreamDesc)
    776797{
     
    807828    {
    808829        Log(("hda: irq %s\n", fIrq ? "asserted" : "deasserted"));
    809         PDMDevHlpPCISetIrq(pThis->pDevIns, 0 , fIrq);
     830        PDMDevHlpPCISetIrq(pThis->CTX_SUFF(pDevIns), 0 , fIrq);
    810831    }
    811832    return VINF_SUCCESS;
     
    919940}
    920941
    921 
     942#ifdef IN_RING3
    922943static int hdaCmdSync(PHDASTATE pThis, bool fLocal)
    923944{
     
    926947    {
    927948        Assert((HDA_REG_FLAG_VALUE(pThis, CORBCTL, DMA)));
    928         rc = PDMDevHlpPhysRead(pThis->pDevIns, pThis->u64CORBBase, pThis->pu32CorbBuf, pThis->cbCorbBuf);
     949        rc = PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), pThis->u64CORBBase, pThis->pu32CorbBuf, pThis->cbCorbBuf);
    929950        if (RT_FAILURE(rc))
    930951            AssertRCReturn(rc, rc);
     
    955976    {
    956977        Assert((HDA_REG_FLAG_VALUE(pThis, RIRBCTL, DMA)));
    957         rc = PDMDevHlpPCIPhysWrite(pThis->pDevIns, pThis->u64RIRBBase, pThis->pu64RirbBuf, pThis->cbRirbBuf);
     978        rc = PDMDevHlpPCIPhysWrite(pThis->CTX_SUFF(pDevIns), pThis->u64RIRBBase, pThis->pu64RirbBuf, pThis->cbRirbBuf);
    958979        if (RT_FAILURE(rc))
    959980            AssertRCReturn(rc, rc);
     
    10031024        corbRp++;
    10041025        cmd = pThis->pu32CorbBuf[corbRp];
    1005         rc = pThis->Codec.pfnLookup(&pThis->Codec, cmd, &pfn);
     1026        rc = pThis->pCodec->pfnLookup(pThis->pCodec, cmd, &pfn);
    10061027        if (RT_FAILURE(rc))
    10071028            AssertRCReturn(rc, rc);
     
    10101031
    10111032        if (RT_LIKELY(pfn))
    1012             rc = pfn(&pThis->Codec, cmd, &resp);
     1033            rc = pfn(pThis->pCodec, cmd, &resp);
    10131034        else
    10141035            rc = VERR_INVALID_FUNCTION;
     
    10431064    return rc;
    10441065}
     1066#endif
    10451067
    10461068static void hdaStreamReset(PHDASTATE pThis, PHDABDLEDESC pBdle, PHDASTREAMTRANSFERDESC pStreamDesc, uint8_t u8Strm)
     
    10691091}
    10701092
    1071 
    10721093/* Register access handlers. */
    10731094
     
    11511172    else
    11521173    {
     1174#ifdef IN_RING3
    11531175        /* enter reset state*/
    11541176        if (   HDA_REG_FLAG_VALUE(pThis, CORBCTL, DMA)
     
    11591181                HDA_REG_FLAG_VALUE(pThis, RIRBCTL, DMA) ? "on" : "off"));
    11601182        }
    1161         hdaReset(pThis->pDevIns);
     1183        hdaReset(pThis->CTX_SUFF(pDevIns));
    11621184        GCTL(pThis) &= ~HDA_REG_FIELD_FLAG_MASK(GCTL, RST);
    11631185        pThis->fInReset = true;
     1186#else
     1187        return VINF_IOM_R3_MMIO_WRITE;
     1188#endif
    11641189    }
    11651190    if (u32Value & HDA_REG_FIELD_FLAG_MASK(GCTL, FSH))
     
    12091234{
    12101235    /* HDA spec (1a): 3.3.16 WALCLK counter ticks with 24Mhz bitclock rate. */
    1211     *pu32Value = (uint32_t)ASMMultU64ByU32DivByU32(PDMDevHlpTMTimeVirtGetNano(pThis->pDevIns)
     1236    *pu32Value = (uint32_t)ASMMultU64ByU32DivByU32(PDMDevHlpTMTimeVirtGetNano(pThis->CTX_SUFF(pDevIns))
    12121237                                                   - pThis->u64BaseTS, 24, 1000);
    12131238    return VINF_SUCCESS;
     
    12321257static int hdaRegWriteCORBCTL(PHDASTATE pThis, uint32_t iReg, uint32_t u32Value)
    12331258{
     1259#ifdef IN_RING3
    12341260    int rc = hdaRegWriteU8(pThis, iReg, u32Value);
    12351261    AssertRC(rc);
     
    12381264        return hdaCORBCmdProcess(pThis);
    12391265    return rc;
     1266#else
     1267    return VINF_IOM_R3_MMIO_WRITE;
     1268#endif
    12401269}
    12411270
     
    12491278static int hdaRegWriteCORBWP(PHDASTATE pThis, uint32_t iReg, uint32_t u32Value)
    12501279{
     1280#ifdef IN_RING3
    12511281    int rc;
    12521282    rc = hdaRegWriteU16(pThis, iReg, u32Value);
     
    12591289    rc = hdaCORBCmdProcess(pThis);
    12601290    return rc;
     1291#else
     1292    return VINF_IOM_R3_MMIO_WRITE;
     1293#endif
    12611294}
    12621295
     
    12841317    else if (fReset)
    12851318    {
     1319#ifdef IN_RING3
    12861320        /*
    12871321         * Assert!!! ICH6 datasheet 18.2.33 says that RUN bit should be cleared before initiation of reset.
     
    13081342        hdaInitTransferDescriptor(pThis, pBdle, u8Strm, &StreamDesc);
    13091343        hdaStreamReset(pThis, pBdle, &StreamDesc, u8Strm);
     1344#else
     1345        return VINF_IOM_R3_MMIO_WRITE;
     1346#endif
    13101347    }
    13111348    else
    13121349    {
     1350#ifdef IN_RING3
    13131351        /* we enter here to change DMA states only */
    13141352        if (   (fInRun && !fRun)
     
    13191357            {
    13201358                case ICH6_HDA_REG_SD0CTL:
    1321                     AUD_set_active_in(pThis->Codec.SwVoiceIn, fRun);
     1359                    AUD_set_active_in(pThis->pCodec->SwVoiceIn, fRun);
    13221360                    break;
    13231361                case ICH6_HDA_REG_SD4CTL:
    1324                     AUD_set_active_out(pThis->Codec.SwVoiceOut, fRun);
     1362                    AUD_set_active_out(pThis->pCodec->SwVoiceOut, fRun);
    13251363                    break;
    13261364                default:
     
    13291367            }
    13301368        }
     1369#else
     1370        return VINF_IOM_R3_MMIO_WRITE;
     1371#endif
    13311372    }
    13321373
     
    14061447}
    14071448
     1449#ifdef IN_RING3
    14081450static void hdaSdFmtToAudSettings(uint32_t u32SdFmt, audsettings_t *pAudSetting)
    14091451{
     
    14631505#undef EXTRACT_VALUE
    14641506}
     1507#endif
    14651508
    14661509static int hdaRegWriteSDFMT(PHDASTATE pThis, uint32_t iReg, uint32_t u32Value)
    14671510{
    1468 #ifdef VBOX_WITH_HDA_CODEC_EMU
     1511#ifdef IN_RING3
     1512# ifdef VBOX_WITH_HDA_CODEC_EMU
    14691513    /** @todo a bit more investigation is required here. */
    14701514    int rc = 0;
     
    14771521    {
    14781522        case ICH6_HDA_REG_SD0FMT:
    1479             rc = hdaCodecOpenVoice(&pThis->Codec, PI_INDEX, &as);
     1523            rc = hdaCodecOpenVoice(pThis->pCodec, PI_INDEX, &as);
    14801524            break;
    14811525        case ICH6_HDA_REG_SD4FMT:
    1482             rc = hdaCodecOpenVoice(&pThis->Codec, PO_INDEX, &as);
     1526            rc = hdaCodecOpenVoice(pThis->pCodec, PO_INDEX, &as);
    14831527            break;
    14841528        default:
     
    14871531    }
    14881532    return hdaRegWriteU16(pThis, iReg, u32Value);
     1533# else
     1534    return hdaRegWriteU16(pThis, iReg, u32Value);
     1535# endif
    14891536#else
    1490     return hdaRegWriteU16(pThis, iReg, u32Value);
     1537    return VINF_IOM_R3_MMIO_WRITE;
    14911538#endif
    14921539}
     
    15231570{
    15241571    int                         rc  = VINF_SUCCESS;
    1525     PFNHDACODECVERBPROCESSOR    pfn = NULL;
    1526     uint64_t                    resp;
    15271572
    15281573    /*
     
    15331578        && !IRS_ICB(pThis))
    15341579    {
     1580#ifdef IN_RING3
     1581        PFNHDACODECVERBPROCESSOR    pfn = NULL;
     1582        uint64_t                    resp;
    15351583        uint32_t cmd = IC(pThis);
    15361584        if (CORBWP(pThis) != CORBRP(pThis))
     
    15441592        IRS(pThis) = HDA_REG_FIELD_FLAG_MASK(IRS, ICB);  /* busy */
    15451593        Log(("hda: IC:%x\n", cmd));
    1546         rc = pThis->Codec.pfnLookup(&pThis->Codec, cmd, &pfn);
     1594        rc = pThis->pCodec->pfnLookup(pThis->pCodec, cmd, &pfn);
    15471595        if (RT_FAILURE(rc))
    15481596            AssertRCReturn(rc, rc);
    1549         rc = pfn(&pThis->Codec, cmd, &resp);
     1597        rc = pfn(pThis->pCodec, cmd, &resp);
    15501598        if (RT_FAILURE(rc))
    15511599            AssertRCReturn(rc, rc);
     
    15541602        IRS(pThis) = HDA_REG_FIELD_FLAG_MASK(IRS, IRV);  /* result is ready  */
    15551603        IRS(pThis) &= ~HDA_REG_FIELD_FLAG_MASK(IRS, ICB); /* busy is clear */
     1604#else
     1605        rc = VINF_IOM_R3_MMIO_WRITE;
     1606#endif
    15561607        return rc;
    15571608    }
     
    16221673}
    16231674
     1675#ifdef IN_RING3
    16241676#ifdef LOG_ENABLED
    16251677static void dump_bd(PHDASTATE pThis, PHDABDLEDESC pBdle, uint64_t u64BaseDMA)
     
    16361688    for (i = 0; i <= pBdle->u32BdleMaxCvi; ++i)
    16371689    {
    1638         PDMDevHlpPhysRead(pThis->pDevIns, u64BaseDMA + i*16, bdle, 16);
     1690        PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), u64BaseDMA + i*16, bdle, 16);
    16391691        addr = *(uint64_t *)bdle;
    16401692        len = *(uint32_t *)&bdle[8];
     
    16461698    for (i = 0; i < 8; ++i)
    16471699    {
    1648         PDMDevHlpPhysRead(pThis->pDevIns, (pThis->u64DPBase & DPBASE_ADDR_MASK) + i*8, &counter, sizeof(&counter));
     1700        PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), (pThis->u64DPBase & DPBASE_ADDR_MASK) + i*8, &counter, sizeof(&counter));
    16491701        Log(("hda: %s stream[%d] counter=%x\n", i == SDCTL_NUM(pThis, 4) || i == SDCTL_NUM(pThis, 0)? "[C]": "   ",
    16501702             i , counter));
     
    16601712            && pBdle
    16611713            && pBdle->u32BdleMaxCvi));
    1662     PDMDevHlpPhysRead(pThis->pDevIns, pStreamDesc->u64BaseDMA + pBdle->u32BdleCvi*16, bdle, 16);
     1714    PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), pStreamDesc->u64BaseDMA + pBdle->u32BdleCvi*16, bdle, 16);
    16631715    pBdle->u64BdleCviAddr = *(uint64_t *)bdle;
    16641716    pBdle->u32BdleCviLen = *(uint32_t *)&bdle[8];
     
    18441896         * read from backend input line to the last unreported position or at the begining.
    18451897         */
    1846         cbBackendCopy = AUD_read(pThis->Codec.SwVoiceIn, pBdle->au8HdaBuffer, cb2Copy);
     1898        cbBackendCopy = AUD_read(pThis->pCodec->SwVoiceIn, pBdle->au8HdaBuffer, cb2Copy);
    18471899        /*
    18481900         * write the HDA DMA buffer
    18491901         */
    1850         PDMDevHlpPCIPhysWrite(pThis->pDevIns, pBdle->u64BdleCviAddr + pBdle->u32BdleCviPos, pBdle->au8HdaBuffer, cbBackendCopy);
     1902        PDMDevHlpPCIPhysWrite(pThis->CTX_SUFF(pDevIns), pBdle->u64BdleCviAddr + pBdle->u32BdleCviPos, pBdle->au8HdaBuffer, cbBackendCopy);
    18511903
    18521904        /* Don't see any reason why cb2Copy would differ from cbBackendCopy */
     
    18861938    else
    18871939    {
    1888         PDMDevHlpPhysRead(pThis->pDevIns, pBdle->u64BdleCviAddr + pBdle->u32BdleCviPos, pBdle->au8HdaBuffer + pBdle->cbUnderFifoW, cb2Copy);
     1940        PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), pBdle->u64BdleCviAddr + pBdle->u32BdleCviPos, pBdle->au8HdaBuffer + pBdle->cbUnderFifoW, cb2Copy);
    18891941        /*
    18901942         * Write to audio backend. we should ensure that we have enough bytes to copy to the backend.
     
    18951947             * Feed the newly fetched samples, including unreported ones, to the backend.
    18961948             */
    1897             cbBackendCopy = AUD_write (pThis->Codec.SwVoiceOut, pBdle->au8HdaBuffer, cb2Copy + pBdle->cbUnderFifoW);
     1949            cbBackendCopy = AUD_write (pThis->pCodec->SwVoiceOut, pBdle->au8HdaBuffer, cb2Copy + pBdle->cbUnderFifoW);
    18981950            hdaBackendWriteTransferReported(pBdle, cb2Copy, cbBackendCopy, &cbTransferred, pu32Avail);
    18991951        }
     
    20172069    }
    20182070}
    2019 
     2071#endif
    20202072
    20212073/* MMIO callbacks */
     
    22722324                cbReg = 1;
    22732325            }
     2326            if (rc != VINF_SUCCESS)
     2327                break;
    22742328            if (cbReg >= cb)
    22752329                break;
     
    23512405/* PCI callback. */
    23522406
     2407#ifdef IN_RING3
    23532408/**
    23542409 * @callback_method_impl{FNPCIIOREGIONMAP}
     
    23692424     */
    23702425    Assert(enmType == PCI_ADDRESS_SPACE_MEM);
    2371     rc = PDMDevHlpMMIORegister(pPciDev->pDevIns, GCPhysAddress, cb, NULL /*pvUser*/,
     2426    rc = PDMDevHlpMMIORegister(pDevIns, GCPhysAddress, cb, NULL /*pvUser*/,
    23722427#ifdef NEW_READ_CODE
    23732428                               IOMMMIO_FLAGS_READ_DWORD |
     
    23812436        return rc;
    23822437
     2438    if (pThis->fR0Enabled)
     2439    {
     2440        rc = PDMDevHlpMMIORegisterR0(pDevIns, GCPhysAddress, cb, NIL_RTR0PTR /*pvUser*/,
     2441                                     "hdaMMIOWrite", "hdaMMIORead");
     2442        if (RT_FAILURE(rc))
     2443            return rc;
     2444    }
     2445
     2446    if (pThis->fRCEnabled)
     2447    {
     2448        rc = PDMDevHlpMMIORegisterRC(pDevIns, GCPhysAddress, cb, NIL_RTRCPTR /*pvUser*/,
     2449                                     "hdaMMIOWrite", "hdaMMIORead");
     2450        if (RT_FAILURE(rc))
     2451            return rc;
     2452    }
     2453
    23832454    pThis->MMIOBaseAddr = GCPhysAddress;
    23842455    return VINF_SUCCESS;
     
    23952466    PHDASTATE pThis = PDMINS_2_DATA(pDevIns, PHDASTATE);
    23962467    /* Save Codec nodes states */
    2397     hdaCodecSaveState(&pThis->Codec, pSSM);
     2468    hdaCodecSaveState(pThis->pCodec, pSSM);
    23982469
    23992470    /* Save MMIO registers */
     
    24222493     * Load Codec nodes states.
    24232494     */
    2424     int rc = hdaCodecLoadState(&pThis->Codec, pSSM, uVersion);
     2495    int rc = hdaCodecLoadState(pThis->pCodec, pSSM, uVersion);
    24252496    if (RT_FAILURE(rc))
    24262497        return rc;
     
    24882559     * Update stuff after the state changes.
    24892560     */
    2490     AUD_set_active_in(pThis->Codec.SwVoiceIn, SDCTL(pThis, 0) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN));
    2491     AUD_set_active_out(pThis->Codec.SwVoiceOut, SDCTL(pThis, 4) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN));
     2561    AUD_set_active_in(pThis->pCodec->SwVoiceIn, SDCTL(pThis, 0) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN));
     2562    AUD_set_active_out(pThis->pCodec->SwVoiceOut, SDCTL(pThis, 4) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN));
    24922563
    24932564    pThis->u64CORBBase = RT_MAKE_U64(CORBLBASE(pThis), CORBUBASE(pThis));
     
    26642735{
    26652736    PHDASTATE pThis = PDMINS_2_DATA(pDevIns, PHDASTATE);
    2666     if (pThis->Codec.pfnCodecDbgListNodes)
    2667         pThis->Codec.pfnCodecDbgListNodes(&pThis->Codec, pHlp, pszArgs);
     2737    if (pThis->pCodec->pfnCodecDbgListNodes)
     2738        pThis->pCodec->pfnCodecDbgListNodes(pThis->pCodec, pHlp, pszArgs);
    26682739    else
    26692740        pHlp->pfnPrintf(pHlp, "Codec implementation doesn't provide corresponding callback.\n");
     
    26772748{
    26782749    PHDASTATE pThis = PDMINS_2_DATA(pDevIns, PHDASTATE);
    2679     if (pThis->Codec.pfnCodecDbgSelector)
    2680         pThis->Codec.pfnCodecDbgSelector(&pThis->Codec, pHlp, pszArgs);
     2750    if (pThis->pCodec->pfnCodecDbgSelector)
     2751        pThis->pCodec->pfnCodecDbgSelector(pThis->pCodec, pHlp, pszArgs);
    26812752    else
    26822753        pHlp->pfnPrintf(pHlp, "Codec implementation doesn't provide corresponding callback.\n");
     
    27742845    PHDASTATE pThis = PDMINS_2_DATA(pDevIns, PHDASTATE);
    27752846
    2776     int rc = hdaCodecDestruct(&pThis->Codec);
    2777     AssertRC(rc);
     2847    if (pThis->pCodec)
     2848    {
     2849        int rc = hdaCodecDestruct(pThis->pCodec);
     2850        AssertRC(rc);
     2851
     2852        RTMemFree(pThis->pCodec);
     2853        pThis->pCodec = NULL;
     2854    }
    27782855
    27792856    RTMemFree(pThis->pu32CorbBuf);
     
    28002877     * Validations.
    28012878     */
    2802     if (!CFGMR3AreValuesValid(pCfgHandle, "\0"))
     2879    if (!CFGMR3AreValuesValid(pCfgHandle, "R0Enabled\0"
     2880                                          "RCEnabled\0"))
    28032881        return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    28042882                                N_ ("Invalid configuration for the Intel HDA device"));
    28052883
    2806     /// @todo r=michaln: This device may need R0/RC enabling, especially if guests
    2807     /// poll some register(pThis).
     2884    rc = CFGMR3QueryBoolDef(pCfgHandle, "RCEnabled", &pThis->fRCEnabled, false);
     2885    if (RT_FAILURE(rc))
     2886        return PDMDEV_SET_ERROR(pDevIns, rc,
     2887                                N_("HDA configuration error: failed to read RCEnabled as boolean"));
     2888    rc = CFGMR3QueryBoolDef(pCfgHandle, "R0Enabled", &pThis->fR0Enabled, false);
     2889    if (RT_FAILURE(rc))
     2890        return PDMDEV_SET_ERROR(pDevIns, rc,
     2891                                N_("HDA configuration error: failed to read R0Enabled as boolean"));
    28082892
    28092893    /*
    28102894     * Initialize data (most of it anyway).
    28112895     */
    2812     pThis->pDevIns                  = pDevIns;
     2896    pThis->pDevInsR3                = pDevIns;
     2897    pThis->pDevInsR0                = PDMDEVINS_2_R0PTR(pDevIns);
     2898    pThis->pDevInsRC                = PDMDEVINS_2_RCPTR(pDevIns);
    28132899    /* IBase */
    28142900    pThis->IBase.pfnQueryInterface  = hdaQueryInterface;
     
    28162902    /* PCI Device */
    28172903    PCIDevSetVendorId           (&pThis->PciDev, HDA_PCI_VENDOR_ID); /* nVidia */
    2818     PCIDevSetDeviceId           (&pThis->PciDev, HDA_PCI_DEICE_ID); /* HDA */
     2904    PCIDevSetDeviceId           (&pThis->PciDev, HDA_PCI_DEVICE_ID); /* HDA */
    28192905
    28202906    PCIDevSetCommand            (&pThis->PciDev, 0x0000); /* 04 rw,ro - pcicmd. */
     
    29323018    }
    29333019
    2934     pThis->Codec.pvHDAState = pThis;
    2935     rc = hdaCodecConstruct(pDevIns, &pThis->Codec, pCfgHandle);
     3020    /* Construct codec state. */
     3021    pThis->pCodec = (PHDACODEC)RTMemAllocZ(sizeof(HDACODEC));
     3022    if (!pThis->pCodec)
     3023        return PDMDEV_SET_ERROR(pDevIns, VERR_NO_MEMORY, N_("HDA: Out of memory allocating codec state"));
     3024
     3025    pThis->pCodec->pvHDAState = pThis;
     3026    rc = hdaCodecConstruct(pDevIns, pThis->pCodec, pCfgHandle);
    29363027    if (RT_FAILURE(rc))
    29373028        AssertRCReturn(rc, rc);
     
    29393030    /* ICH6 datasheet defines 0 values for SVID and SID (18.1.14-15), which together with values returned for
    29403031       verb F20 should provide device/codec recognition. */
    2941     Assert(pThis->Codec.u16VendorId);
    2942     Assert(pThis->Codec.u16DeviceId);
    2943     PCIDevSetSubSystemVendorId(&pThis->PciDev, pThis->Codec.u16VendorId); /* 2c ro - intel.) */
    2944     PCIDevSetSubSystemId(      &pThis->PciDev, pThis->Codec.u16DeviceId); /* 2e ro. */
     3032    Assert(pThis->pCodec->u16VendorId);
     3033    Assert(pThis->pCodec->u16DeviceId);
     3034    PCIDevSetSubSystemVendorId(&pThis->PciDev, pThis->pCodec->u16VendorId); /* 2c ro - intel.) */
     3035    PCIDevSetSubSystemId(      &pThis->PciDev, pThis->pCodec->u16DeviceId); /* 2e ro. */
    29453036
    29463037    hdaReset(pDevIns);
    2947     pThis->Codec.id = 0;
    2948     pThis->Codec.pfnTransfer = hdaTransfer;
    2949     pThis->Codec.pfnReset = hdaCodecReset;
     3038    pThis->pCodec->id = 0;
     3039    pThis->pCodec->pfnTransfer = hdaTransfer;
     3040    pThis->pCodec->pfnReset = hdaCodecReset;
    29503041
    29513042    /*
     
    30373128    "hda",
    30383129    /* szRCMod */
    3039     "",
     3130    "VBoxDDGC.gc",
    30403131    /* szR0Mod */
    3041     "",
     3132    "VBoxDDR0.r0",
    30423133    /* pszDescription */
    30433134    "Intel HD Audio Controller",
    30443135    /* fFlags */
    3045     PDM_DEVREG_FLAGS_DEFAULT_BITS,
     3136    PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0,
    30463137    /* fClass */
    30473138    PDM_DEVREG_CLASS_AUDIO,
     
    30813172    PDM_DEVREG_VERSION
    30823173};
     3174
     3175#endif /* IN_RING3 */
     3176#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette