VirtualBox

Changeset 44631 in vbox


Ignore:
Timestamp:
Feb 11, 2013 12:38:33 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
83719
Message:

DevIchAc97.cpp: Eliminated PCIAC97LinkState.

File:
1 edited

Legend:

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

    r44630 r44631  
    8888#define GS_MIINT RT_BIT(1)         /* ro */
    8989#define GS_GSCI  RT_BIT(0)         /* rwc */
    90 #define GS_RO_MASK (GS_B3S12|                   \
    91                     GS_B2S12|                   \
    92                     GS_B1S12|                   \
    93                     GS_S1CR|                    \
    94                     GS_S0CR|                    \
    95                     GS_MINT|                    \
    96                     GS_POINT|                   \
    97                     GS_PIINT|                   \
    98                     GS_RSRVD|                   \
    99                     GS_MOINT|                   \
     90#define GS_RO_MASK (GS_B3S12 |                   \
     91                    GS_B2S12 |                   \
     92                    GS_B1S12 |                   \
     93                    GS_S1CR |                    \
     94                    GS_S0CR |                    \
     95                    GS_MINT |                    \
     96                    GS_POINT |                   \
     97                    GS_PIINT |                   \
     98                    GS_RSRVD |                   \
     99                    GS_MOINT |                   \
    100100                    GS_MIINT)
    101101#define GS_VALID_MASK (RT_BIT(18) - 1)
     
    188188typedef struct AC97LinkState
    189189{
     190    /** The PCI device state. */
     191    PCIDevice               PciDev;
     192
     193    /** Audio stuff.  */
    190194    QEMUSoundCard           card;
     195
    191196    /** Global Control (Bus Master Control Register) */
    192197    uint32_t                glob_cnt;
     
    220225
    221226#define ICHAC97STATE_2_DEVINS(a_pAC97)   ((a_pAC97)->pDevIns)
    222 #define PCIDEV_2_ICHAC97STATE(a_pPciDev) ((PCIAC97LinkState *)(a_pPciDev))
     227#define PCIDEV_2_ICHAC97STATE(a_pPciDev) ((AC97LinkState *)(a_pPciDev))
    223228
    224229enum
     
    227232    BUP_LAST = RT_BIT(1)
    228233};
    229 
    230 typedef struct PCIAC97LinkState
    231 {
    232     PCIDevice dev;
    233     AC97LinkState ac97;
    234 } PCIAC97LinkState;
    235234
    236235#define MKREGS(prefix, start)                   \
     
    851850static DECLCALLBACK(int) ichac97IOPortNABMRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
    852851{
    853     PCIAC97LinkState *d = (PCIAC97LinkState*)pvUser;
    854     AC97LinkState *s = &d->ac97;
     852    AC97LinkState *d = (AC97LinkState *)pvUser;
     853    AC97LinkState *s = d;
    855854
    856855    switch (cb)
     
    859858        {
    860859            AC97BusMasterRegs *r = NULL;
    861             uint32_t index = Port - d->ac97.IOPortBase[1];
     860            uint32_t index = Port - s->IOPortBase[1];
    862861            *pu32 = ~0U;
    863862
     
    920919        {
    921920            AC97BusMasterRegs *r = NULL;
    922             uint32_t index = Port - d->ac97.IOPortBase[1];
     921            uint32_t index = Port - s->IOPortBase[1];
    923922            *pu32 = ~0U;
    924923
     
    951950        {
    952951            AC97BusMasterRegs *r = NULL;
    953             uint32_t index = Port - d->ac97.IOPortBase[1];
     952            uint32_t index = Port - s->IOPortBase[1];
    954953            *pu32 = ~0U;
    955954
     
    10121011static DECLCALLBACK(int) ichac97IOPortNABMWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
    10131012{
    1014     PCIAC97LinkState *d = (PCIAC97LinkState*)pvUser;
    1015     AC97LinkState *s = &d->ac97;
     1013    AC97LinkState *d = (AC97LinkState *)pvUser;
     1014    AC97LinkState *s = d;
    10161015
    10171016    switch (cb)
     
    10201019        {
    10211020            AC97BusMasterRegs *r = NULL;
    1022             uint32_t index = Port - d->ac97.IOPortBase[1];
     1021            uint32_t index = Port - s->IOPortBase[1];
    10231022            switch (index)
    10241023            {
     
    10831082        {
    10841083            AC97BusMasterRegs *r = NULL;
    1085             uint32_t index = Port - d->ac97.IOPortBase[1];
     1084            uint32_t index = Port - s->IOPortBase[1];
    10861085            switch (index)
    10871086            {
     
    11051104        {
    11061105            AC97BusMasterRegs *r = NULL;
    1107             uint32_t index = Port - d->ac97.IOPortBase[1];
     1106            uint32_t index = Port - s->IOPortBase[1];
    11081107            switch (index)
    11091108            {
     
    11511150static DECLCALLBACK(int) ichac97IOPortNAMRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
    11521151{
    1153     PCIAC97LinkState *d = (PCIAC97LinkState*)pvUser;
    1154     AC97LinkState *s = &d->ac97;
     1152    AC97LinkState *d = (AC97LinkState *)pvUser;
     1153    AC97LinkState *s = d;
    11551154
    11561155    switch (cb)
     
    11661165        case 2:
    11671166        {
    1168             uint32_t index = Port - d->ac97.IOPortBase[0];
     1167            uint32_t index = Port - s->IOPortBase[0];
    11691168            *pu32 = ~0U;
    11701169            s->cas = 0;
     
    11981197static DECLCALLBACK(int) ichac97IOPortNAMWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
    11991198{
    1200     PCIAC97LinkState *d = (PCIAC97LinkState*)pvUser;
    1201     AC97LinkState *s = &d->ac97;
     1199    AC97LinkState *d = (AC97LinkState *)pvUser;
     1200    AC97LinkState *s = d;
    12021201
    12031202    switch (cb)
     
    12121211        case 2:
    12131212        {
    1214             uint32_t index = Port - d->ac97.IOPortBase[0];
     1213            uint32_t index = Port - s->IOPortBase[0];
    12151214            s->cas = 0;
    12161215            switch (index)
     
    13281327{
    13291328    PPDMDEVINS          pDevIns = pPciDev->pDevIns;
    1330     PCIAC97LinkState   *pThis = PCIDEV_2_ICHAC97STATE(pPciDev);
     1329    AC97LinkState      *pThis = PCIDEV_2_ICHAC97STATE(pPciDev);
    13311330    RTIOPORT            Port = (RTIOPORT)GCPhysAddress;
    13321331    int                 rc;
     
    13461345        return rc;
    13471346
    1348     pThis->ac97.IOPortBase[iRegion] = Port;
     1347    pThis->IOPortBase[iRegion] = Port;
    13491348    return VINF_SUCCESS;
    13501349}
     
    13561355static DECLCALLBACK(int) ichac97SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    13571356{
    1358     PCIAC97LinkState *pThis = PDMINS_2_DATA(pDevIns, PCIAC97LinkState *);
    1359     AC97LinkState *s = &pThis->ac97;
     1357    AC97LinkState *pThis = PDMINS_2_DATA(pDevIns, AC97LinkState *);
     1358    AC97LinkState *s = pThis;
    13601359
    13611360    SSMR3PutU32(pSSM, s->glob_cnt);
     
    13941393static DECLCALLBACK(int) ichac97LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
    13951394{
    1396     PCIAC97LinkState *pThis = PDMINS_2_DATA(pDevIns, PCIAC97LinkState *);
    1397     AC97LinkState *s = &pThis->ac97;
     1395    AC97LinkState *pThis = PDMINS_2_DATA(pDevIns, AC97LinkState *);
     1396    AC97LinkState *s = pThis;
    13981397
    13991398    AssertMsgReturn (uVersion == AC97_SSM_VERSION, ("%d\n", uVersion), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);
     
    14451444static DECLCALLBACK(void *) ichac97QueryInterface(struct PDMIBASE *pInterface, const char *pszIID)
    14461445{
    1447     PCIAC97LinkState *pThis = RT_FROM_MEMBER(pInterface, PCIAC97LinkState, ac97.IBase);
    1448     Assert(&pThis->ac97.IBase == pInterface);
    1449 
    1450     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->ac97.IBase);
     1446    AC97LinkState *pThis = RT_FROM_MEMBER(pInterface, AC97LinkState, IBase);
     1447    Assert(&pThis->IBase == pInterface);
     1448
     1449    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->IBase);
    14511450    return NULL;
    14521451}
     
    14611460static DECLCALLBACK(void)  ac97Reset(PPDMDEVINS pDevIns)
    14621461{
    1463     PCIAC97LinkState *pThis = PDMINS_2_DATA(pDevIns, PCIAC97LinkState *);
     1462    AC97LinkState *pThis = PDMINS_2_DATA(pDevIns, AC97LinkState *);
    14641463
    14651464    /*
    14661465     * Reset the device state (will need pDrv later).
    14671466     */
    1468     reset_bm_regs(&pThis->ac97, &pThis->ac97.bm_regs[0]);
    1469     reset_bm_regs(&pThis->ac97, &pThis->ac97.bm_regs[1]);
    1470     reset_bm_regs(&pThis->ac97, &pThis->ac97.bm_regs[2]);
     1467    reset_bm_regs(pThis, &pThis->bm_regs[0]);
     1468    reset_bm_regs(pThis, &pThis->bm_regs[1]);
     1469    reset_bm_regs(pThis, &pThis->bm_regs[2]);
    14711470
    14721471    /*
     
    14751474     * the codec manually.
    14761475     */
    1477     mixer_reset(&pThis->ac97);
     1476    mixer_reset(pThis);
    14781477}
    14791478
     
    14841483static DECLCALLBACK(int) ichac97Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
    14851484{
    1486     PCIAC97LinkState *pThis = PDMINS_2_DATA(pDevIns, PCIAC97LinkState *);
    1487     AC97LinkState    *s     = &pThis->ac97;
    1488     int               rc;
     1485    AC97LinkState  *pThis = PDMINS_2_DATA(pDevIns, AC97LinkState *);
     1486    int             rc;
    14891487
    14901488    Assert(iInstance == 0);
     
    15011499     * Initialize data (most of it anyway).
    15021500     */
    1503     s->pDevIns                  = pDevIns;
     1501    pThis->pDevIns                  = pDevIns;
    15041502    /* IBase */
    1505     s->IBase.pfnQueryInterface  = ichac97QueryInterface;
     1503    pThis->IBase.pfnQueryInterface  = ichac97QueryInterface;
    15061504
    15071505    /* PCI Device (the assertions will be removed later) */
    1508     PCIDevSetVendorId         (&pThis->dev, 0x8086); /* 00 ro - intel. */               Assert(pThis->dev.config[0x00] == 0x86); Assert(pThis->dev.config[0x01] == 0x80);
    1509     PCIDevSetDeviceId         (&pThis->dev, 0x2415); /* 02 ro - 82801 / 82801aa(?). */  Assert(pThis->dev.config[0x02] == 0x15); Assert(pThis->dev.config[0x03] == 0x24);
    1510     PCIDevSetCommand          (&pThis->dev, 0x0000); /* 04 rw,ro - pcicmd. */           Assert(pThis->dev.config[0x04] == 0x00); Assert(pThis->dev.config[0x05] == 0x00);
    1511     PCIDevSetStatus           (&pThis->dev, VBOX_PCI_STATUS_DEVSEL_MEDIUM |  VBOX_PCI_STATUS_FAST_BACK); /* 06 rwc?,ro? - pcists. */      Assert(pThis->dev.config[0x06] == 0x80); Assert(pThis->dev.config[0x07] == 0x02);
    1512     PCIDevSetRevisionId       (&pThis->dev, 0x01);   /* 08 ro - rid. */                 Assert(pThis->dev.config[0x08] == 0x01);
    1513     PCIDevSetClassProg        (&pThis->dev, 0x00);   /* 09 ro - pi. */                  Assert(pThis->dev.config[0x09] == 0x00);
    1514     PCIDevSetClassSub         (&pThis->dev, 0x01);   /* 0a ro - scc; 01 == Audio. */    Assert(pThis->dev.config[0x0a] == 0x01);
    1515     PCIDevSetClassBase        (&pThis->dev, 0x04);   /* 0b ro - bcc; 04 == multimedia. */ Assert(pThis->dev.config[0x0b] == 0x04);
    1516     PCIDevSetHeaderType       (&pThis->dev, 0x00);   /* 0e ro - headtyp. */             Assert(pThis->dev.config[0x0e] == 0x00);
    1517     PCIDevSetBaseAddress      (&pThis->dev, 0,       /* 10 rw - nambar - native audio mixer base. */
    1518                                true /* fIoSpace */, false /* fPrefetchable */, false /* f64Bit */, 0x00000000); Assert(pThis->dev.config[0x10] == 0x01); Assert(pThis->dev.config[0x11] == 0x00); Assert(pThis->dev.config[0x12] == 0x00); Assert(pThis->dev.config[0x13] == 0x00);
    1519     PCIDevSetBaseAddress      (&pThis->dev, 1,       /* 14 rw - nabmbar - native audio bus mastering. */
    1520                                true /* fIoSpace */, false /* fPrefetchable */, false /* f64Bit */, 0x00000000); Assert(pThis->dev.config[0x14] == 0x01); Assert(pThis->dev.config[0x15] == 0x00); Assert(pThis->dev.config[0x16] == 0x00); Assert(pThis->dev.config[0x17] == 0x00);
    1521     PCIDevSetSubSystemVendorId(&pThis->dev, 0x8086); /* 2c ro - intel.) */              Assert(pThis->dev.config[0x2c] == 0x86); Assert(pThis->dev.config[0x2d] == 0x80);
    1522     PCIDevSetSubSystemId      (&pThis->dev, 0x0000); /* 2e ro. */                       Assert(pThis->dev.config[0x2e] == 0x00); Assert(pThis->dev.config[0x2f] == 0x00);
    1523     PCIDevSetInterruptLine    (&pThis->dev, 0x00);   /* 3c rw. */                       Assert(pThis->dev.config[0x3c] == 0x00);
    1524     PCIDevSetInterruptPin     (&pThis->dev, 0x01);   /* 3d ro - INTA#. */               Assert(pThis->dev.config[0x3d] == 0x01);
     1506    PCIDevSetVendorId         (&pThis->PciDev, 0x8086); /* 00 ro - intel. */               Assert(pThis->PciDev.config[0x00] == 0x86); Assert(pThis->PciDev.config[0x01] == 0x80);
     1507    PCIDevSetDeviceId         (&pThis->PciDev, 0x2415); /* 02 ro - 82801 / 82801aa(?). */  Assert(pThis->PciDev.config[0x02] == 0x15); Assert(pThis->PciDev.config[0x03] == 0x24);
     1508    PCIDevSetCommand          (&pThis->PciDev, 0x0000); /* 04 rw,ro - pcicmd. */           Assert(pThis->PciDev.config[0x04] == 0x00); Assert(pThis->PciDev.config[0x05] == 0x00);
     1509    PCIDevSetStatus           (&pThis->PciDev, VBOX_PCI_STATUS_DEVSEL_MEDIUM |  VBOX_PCI_STATUS_FAST_BACK); /* 06 rwc?,ro? - pcists. */      Assert(pThis->PciDev.config[0x06] == 0x80); Assert(pThis->PciDev.config[0x07] == 0x02);
     1510    PCIDevSetRevisionId       (&pThis->PciDev, 0x01);   /* 08 ro - rid. */                 Assert(pThis->PciDev.config[0x08] == 0x01);
     1511    PCIDevSetClassProg        (&pThis->PciDev, 0x00);   /* 09 ro - pi. */                  Assert(pThis->PciDev.config[0x09] == 0x00);
     1512    PCIDevSetClassSub         (&pThis->PciDev, 0x01);   /* 0a ro - scc; 01 == Audio. */    Assert(pThis->PciDev.config[0x0a] == 0x01);
     1513    PCIDevSetClassBase        (&pThis->PciDev, 0x04);   /* 0b ro - bcc; 04 == multimedia. */ Assert(pThis->PciDev.config[0x0b] == 0x04);
     1514    PCIDevSetHeaderType       (&pThis->PciDev, 0x00);   /* 0e ro - headtyp. */             Assert(pThis->PciDev.config[0x0e] == 0x00);
     1515    PCIDevSetBaseAddress      (&pThis->PciDev, 0,       /* 10 rw - nambar - native audio mixer base. */
     1516                               true /* fIoSpace */, false /* fPrefetchable */, false /* f64Bit */, 0x00000000); Assert(pThis->PciDev.config[0x10] == 0x01); Assert(pThis->PciDev.config[0x11] == 0x00); Assert(pThis->PciDev.config[0x12] == 0x00); Assert(pThis->PciDev.config[0x13] == 0x00);
     1517    PCIDevSetBaseAddress      (&pThis->PciDev, 1,       /* 14 rw - nabmbar - native audio bus mastering. */
     1518                               true /* fIoSpace */, false /* fPrefetchable */, false /* f64Bit */, 0x00000000); Assert(pThis->PciDev.config[0x14] == 0x01); Assert(pThis->PciDev.config[0x15] == 0x00); Assert(pThis->PciDev.config[0x16] == 0x00); Assert(pThis->PciDev.config[0x17] == 0x00);
     1519    PCIDevSetSubSystemVendorId(&pThis->PciDev, 0x8086); /* 2c ro - intel.) */              Assert(pThis->PciDev.config[0x2c] == 0x86); Assert(pThis->PciDev.config[0x2d] == 0x80);
     1520    PCIDevSetSubSystemId      (&pThis->PciDev, 0x0000); /* 2e ro. */                       Assert(pThis->PciDev.config[0x2e] == 0x00); Assert(pThis->PciDev.config[0x2f] == 0x00);
     1521    PCIDevSetInterruptLine    (&pThis->PciDev, 0x00);   /* 3c rw. */                       Assert(pThis->PciDev.config[0x3c] == 0x00);
     1522    PCIDevSetInterruptPin     (&pThis->PciDev, 0x01);   /* 3d ro - INTA#. */               Assert(pThis->PciDev.config[0x3d] == 0x01);
    15251523
    15261524    /*
     
    15281526     * saved state item.
    15291527     */
    1530     rc = PDMDevHlpPCIRegister(pDevIns, &pThis->dev);
     1528    rc = PDMDevHlpPCIRegister(pDevIns, &pThis->PciDev);
    15311529    if (RT_FAILURE (rc))
    15321530        return rc;
     
    15471545     * Attach driver.
    15481546     */
    1549     rc = PDMDevHlpDriverAttach(pDevIns, 0, &s->IBase, &s->pDrvBase, "Audio Driver Port");
     1547    rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "Audio Driver Port");
    15501548    if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
    15511549        Log(("ac97: No attached driver!\n"));
     
    15561554    }
    15571555
    1558     AUD_register_card("ICH0", &s->card);
     1556    AUD_register_card("ICH0", &pThis->card);
    15591557
    15601558    ac97Reset(pDevIns);
    15611559
    1562     if (!AUD_is_host_voice_in_ok(s->voice_pi))
     1560    if (!AUD_is_host_voice_in_ok(pThis->voice_pi))
    15631561        LogRel(("AC97: WARNING: Unable to open PCM IN!\n"));
    1564     if (!AUD_is_host_voice_in_ok(s->voice_mc))
     1562    if (!AUD_is_host_voice_in_ok(pThis->voice_mc))
    15651563        LogRel(("AC97: WARNING: Unable to open PCM MC!\n"));
    1566     if (!AUD_is_host_voice_out_ok(s->voice_po))
     1564    if (!AUD_is_host_voice_out_ok(pThis->voice_po))
    15671565        LogRel(("AC97: WARNING: Unable to open PCM OUT!\n"));
    15681566
    1569     if (   !AUD_is_host_voice_in_ok( s->voice_pi)
    1570         && !AUD_is_host_voice_out_ok(s->voice_po)
    1571         && !AUD_is_host_voice_in_ok( s->voice_mc))
     1567    if (   !AUD_is_host_voice_in_ok( pThis->voice_pi)
     1568        && !AUD_is_host_voice_out_ok(pThis->voice_po)
     1569        && !AUD_is_host_voice_in_ok( pThis->voice_mc))
    15721570    {
    15731571        /* Was not able initialize *any* voice. Select the NULL audio driver instead */
    1574         AUD_close_in( &s->card, s->voice_pi);
    1575         AUD_close_out(&s->card, s->voice_po);
    1576         AUD_close_in( &s->card, s->voice_mc);
    1577         s->voice_po = NULL;
    1578         s->voice_pi = NULL;
    1579         s->voice_mc = NULL;
     1572        AUD_close_in( &pThis->card, pThis->voice_pi);
     1573        AUD_close_out(&pThis->card, pThis->voice_po);
     1574        AUD_close_in( &pThis->card, pThis->voice_mc);
     1575        pThis->voice_po = NULL;
     1576        pThis->voice_pi = NULL;
     1577        pThis->voice_mc = NULL;
    15801578        AUD_init_null();
    15811579        ac97Reset(pDevIns);
     
    15851583               "with the consequence that no sound is audible"));
    15861584    }
    1587     else if (   !AUD_is_host_voice_in_ok( s->voice_pi)
    1588              || !AUD_is_host_voice_out_ok(s->voice_po)
    1589              || !AUD_is_host_voice_in_ok( s->voice_mc))
     1585    else if (   !AUD_is_host_voice_in_ok( pThis->voice_pi)
     1586             || !AUD_is_host_voice_out_ok(pThis->voice_po)
     1587             || !AUD_is_host_voice_in_ok( pThis->voice_mc))
    15901588    {
    15911589        char   szMissingVoices[128];
    15921590        size_t len = 0;
    1593         if (!AUD_is_host_voice_in_ok(s->voice_pi))
     1591        if (!AUD_is_host_voice_in_ok(pThis->voice_pi))
    15941592            len = RTStrPrintf(szMissingVoices, sizeof(szMissingVoices), "PCM_in");
    1595         if (!AUD_is_host_voice_out_ok(s->voice_po))
     1593        if (!AUD_is_host_voice_out_ok(pThis->voice_po))
    15961594            len += RTStrPrintf(szMissingVoices + len, sizeof(szMissingVoices) - len, len ? ", PCM_out" : "PCM_out");
    1597         if (!AUD_is_host_voice_in_ok(s->voice_mc))
     1595        if (!AUD_is_host_voice_in_ok(pThis->voice_mc))
    15981596            len += RTStrPrintf(szMissingVoices + len, sizeof(szMissingVoices) - len, len ? ", PCM_mic" : "PCM_mic");
    15991597
     
    16301628    1,
    16311629    /* cbInstance */
    1632     sizeof(PCIAC97LinkState),
     1630    sizeof(AC97LinkState),
    16331631    /* pfnConstruct */
    16341632    ichac97Construct,
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