VirtualBox

Changeset 99768 in vbox for trunk/src/VBox/Devices/PC


Ignore:
Timestamp:
May 12, 2023 7:25:21 AM (22 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
157360
Message:

Devices/DevPit-i8254: Move the host speaker data to the R3 structure where it belongs and close the host speaker file descriptor during destruction, bugref:3409

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/DevPit-i8254.cpp

    r98103 r99768  
    231231    /** Config: I/O port base. */
    232232    RTIOPORT                IOPortBaseCfg;
    233     /** Config: Speaker enabled. */
    234     bool                    fSpeakerCfg;
    235233    /** Disconnect PIT from the interrupt controllers if requested by HPET. */
    236234    bool                    fDisabledByHpet;
    237     /** Config: What to do with speaker activity. */
    238     PITSPEAKEREMU           enmSpeakerEmu;
    239 #ifdef RT_OS_LINUX
    240     /** File handle for host speaker functionality. */
    241     int                     hHostSpeaker;
    242     int                     afAlignment2;
    243 #endif
    244235    /** Number of IRQs that's been raised. */
    245236    STAMCOUNTER             StatPITIrq;
     
    266257    /** Pointer to the device instance. */
    267258    PPDMDEVINSR3            pDevIns;
     259    /** Config: Speaker enabled. */
     260    bool                    fSpeakerCfg;
     261    /** Config: What to do with speaker activity. */
     262    PITSPEAKEREMU           enmSpeakerEmu;
     263#ifdef RT_OS_LINUX
     264    /** File handle for host speaker functionality. */
     265    int                     hHostSpeaker;
     266    int                     afAlignment2;
     267#endif
    268268} PITSTATER3;
    269269/** Pointer to the ring-3 PIT device state. */
     
    881881         * impact on VM execution. */
    882882# ifdef RT_OS_LINUX
    883         if (pThis->enmSpeakerEmu != PIT_SPEAKER_EMU_NONE)
     883        PPITSTATER3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PPITSTATER3);
     884
     885        if (pThisCC->enmSpeakerEmu != PIT_SPEAKER_EMU_NONE)
    884886        {
    885887            PPITCHANNEL pChan = &pThis->channels[2];
     
    887889            {
    888890                Log2Func(("starting beep freq=%d\n", PIT_FREQ / pChan->count));
    889                 switch (pThis->enmSpeakerEmu)
     891                switch (pThisCC->enmSpeakerEmu)
    890892                {
    891893                    case PIT_SPEAKER_EMU_CONSOLE:
    892894                    {
    893895                        int res;
    894                         res = ioctl(pThis->hHostSpeaker, KIOCSOUND, pChan->count);
     896                        res = ioctl(pThisCC->hHostSpeaker, KIOCSOUND, pChan->count);
    895897                        if (res == -1)
    896898                        {
    897899                            LogRel(("PIT: speaker: ioctl failed errno=%d, disabling emulation\n", errno));
    898                             pThis->enmSpeakerEmu = PIT_SPEAKER_EMU_NONE;
     900                            pThisCC->enmSpeakerEmu = PIT_SPEAKER_EMU_NONE;
    899901                        }
    900902                        break;
     
    906908                        e.code = SND_TONE;
    907909                        e.value = PIT_FREQ / pChan->count;
    908                         int res = write(pThis->hHostSpeaker, &e, sizeof(struct input_event));
     910                        int res = write(pThisCC->hHostSpeaker, &e, sizeof(struct input_event));
    909911                        NOREF(res);
    910912                        break;
     
    912914                    case PIT_SPEAKER_EMU_TTY:
    913915                    {
    914                         int res = write(pThis->hHostSpeaker, "\a", 1);
     916                        int res = write(pThisCC->hHostSpeaker, "\a", 1);
    915917                        NOREF(res);
    916918                        break;
     
    919921                        break;
    920922                    default:
    921                         Log2Func(("unknown speaker emulation %d, disabling emulation\n", pThis->enmSpeakerEmu));
    922                         pThis->enmSpeakerEmu = PIT_SPEAKER_EMU_NONE;
     923                        Log2Func(("unknown speaker emulation %d, disabling emulation\n", pThisCC->enmSpeakerEmu));
     924                        pThisCC->enmSpeakerEmu = PIT_SPEAKER_EMU_NONE;
    923925                }
    924926            }
     
    926928            {
    927929                Log2Func(("stopping beep\n"));
    928                 switch (pThis->enmSpeakerEmu)
     930                switch (pThisCC->enmSpeakerEmu)
    929931                {
    930932                    case PIT_SPEAKER_EMU_CONSOLE:
     
    936938                         * disabled->disabled ones, but it's not worth the
    937939                         * effort. */
    938                         ioctl(pThis->hHostSpeaker, KIOCSOUND, 0);
     940                        ioctl(pThisCC->hHostSpeaker, KIOCSOUND, 0);
    939941                        break;
    940942                    case PIT_SPEAKER_EMU_EVDEV:
     
    944946                        e.code = SND_TONE;
    945947                        e.value = 0;
    946                         int res = write(pThis->hHostSpeaker, &e, sizeof(struct input_event));
     948                        int res = write(pThisCC->hHostSpeaker, &e, sizeof(struct input_event));
    947949                        NOREF(res);
    948950                        break;
     
    953955                        break;
    954956                    default:
    955                         Log2Func(("unknown speaker emulation %d, disabling emulation\n", pThis->enmSpeakerEmu));
    956                         pThis->enmSpeakerEmu = PIT_SPEAKER_EMU_NONE;
     957                        Log2Func(("unknown speaker emulation %d, disabling emulation\n", pThisCC->enmSpeakerEmu));
     958                        pThisCC->enmSpeakerEmu = PIT_SPEAKER_EMU_NONE;
    957959                }
    958960            }
     
    974976static DECLCALLBACK(int) pitR3LiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
    975977{
    976     PPITSTATE     pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
     978    PPITSTATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
     979    PPITSTATER3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PPITSTATER3);
     980
    977981    PCPDMDEVHLPR3 pHlp  = pDevIns->pHlpR3;
    978982    RT_NOREF(uPass);
    979983    pHlp->pfnSSMPutIOPort(pSSM, pThis->IOPortBaseCfg);
    980984    pHlp->pfnSSMPutU8(    pSSM, pThis->channels[0].irq);
    981     pHlp->pfnSSMPutBool(  pSSM, pThis->fSpeakerCfg);
     985    pHlp->pfnSSMPutBool(  pSSM, pThisCC->fSpeakerCfg);
    982986    return VINF_SSM_DONT_CALL_AGAIN;
    983987}
     
    10401044static DECLCALLBACK(int) pitR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
    10411045{
    1042     PPITSTATE     pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
    1043     PCPDMDEVHLPR3 pHlp  = pDevIns->pHlpR3;
     1046    PPITSTATE     pThis   = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
     1047    PPITSTATER3   pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PPITSTATER3);
     1048    PCPDMDEVHLPR3 pHlp    = pDevIns->pHlpR3;
    10441049    int           rc;
    10451050
     
    10661071        bool fSpeakerCfg;
    10671072        rc = pHlp->pfnSSMGetBool(pSSM, &fSpeakerCfg); AssertRCReturn(rc, rc);
    1068         if (fSpeakerCfg != pThis->fSpeakerCfg)
     1073        if (fSpeakerCfg != pThisCC->fSpeakerCfg)
    10691074            return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fSpeakerCfg: saved=%RTbool config=%RTbool"),
    1070                                     fSpeakerCfg, pThis->fSpeakerCfg);
     1075                                    fSpeakerCfg, pThisCC->fSpeakerCfg);
    10711076    }
    10721077
     
    13041309
    13051310/**
     1311 * @interface_method_impl{PDMDEVREG,pfnDestruct}
     1312 */
     1313static DECLCALLBACK(int)  pitR3Destruct(PPDMDEVINS pDevIns)
     1314{
     1315    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
     1316
     1317#ifdef RT_OS_LINUX
     1318    PPITSTATER3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PPITSTATER3);
     1319
     1320    if (pThisCC->enmSpeakerEmu != PIT_SPEAKER_EMU_NONE)
     1321    {
     1322        Assert(pThisCC->hHostSpeaker != -1);
     1323        close(pThisCC->hHostSpeaker);
     1324        pThisCC->hHostSpeaker = -1;
     1325    }
     1326#endif
     1327
     1328    return VINF_SUCCESS;
     1329}
     1330
     1331
     1332/**
    13061333 * @interface_method_impl{PDMDEVREG,pfnConstruct}
    13071334 */
     
    13581385        pThis->channels[i].iChan  = i;
    13591386    }
    1360     pThis->fSpeakerCfg     = fSpeaker;
    1361     pThis->enmSpeakerEmu  = PIT_SPEAKER_EMU_NONE;
     1387    pThisCC->fSpeakerCfg   = fSpeaker;
     1388    pThisCC->enmSpeakerEmu = PIT_SPEAKER_EMU_NONE;
    13621389    if (uPassthroughSpeaker)
    13631390    {
     
    13771404        if ((uPassthroughSpeaker == 9 || uPassthroughSpeaker == 100) && pszPassthroughSpeakerDevice && fd == -1)
    13781405            fd = pitR3TryDeviceOpenSanitizeIoctl(pszPassthroughSpeakerDevice, O_WRONLY);
    1379         if (pThis->enmSpeakerEmu == PIT_SPEAKER_EMU_NONE && fd != -1)
     1406        if (pThisCC->enmSpeakerEmu == PIT_SPEAKER_EMU_NONE && fd != -1)
    13801407        {
    1381             pThis->hHostSpeaker = fd;
     1408            pThisCC->hHostSpeaker = fd;
    13821409            if (ioctl(fd, EVIOCGSND(0)) != -1)
    13831410            {
    1384                 pThis->enmSpeakerEmu = PIT_SPEAKER_EMU_EVDEV;
     1411                pThisCC->enmSpeakerEmu = PIT_SPEAKER_EMU_EVDEV;
    13851412                LogRel(("PIT: speaker: emulation mode evdev\n"));
    13861413            }
    13871414            else
    13881415            {
    1389                 pThis->enmSpeakerEmu = PIT_SPEAKER_EMU_CONSOLE;
     1416                pThisCC->enmSpeakerEmu = PIT_SPEAKER_EMU_CONSOLE;
    13901417                LogRel(("PIT: speaker: emulation mode console\n"));
    13911418            }
     
    13951422        if ((uPassthroughSpeaker == 79 || uPassthroughSpeaker == 100) && pszPassthroughSpeakerDevice && fd == -1)
    13961423            fd = pitR3TryDeviceOpen(pszPassthroughSpeakerDevice, O_WRONLY);
    1397         if (pThis->enmSpeakerEmu == PIT_SPEAKER_EMU_NONE && fd != -1)
     1424        if (pThisCC->enmSpeakerEmu == PIT_SPEAKER_EMU_NONE && fd != -1)
    13981425        {
    1399             pThis->hHostSpeaker = fd;
    1400             pThis->enmSpeakerEmu = PIT_SPEAKER_EMU_TTY;
     1426            pThisCC->hHostSpeaker = fd;
     1427            pThisCC->enmSpeakerEmu = PIT_SPEAKER_EMU_TTY;
    14011428            LogRel(("PIT: speaker: emulation mode tty\n"));
    14021429        }
    1403         if (pThis->enmSpeakerEmu == PIT_SPEAKER_EMU_NONE)
     1430        if (pThisCC->enmSpeakerEmu == PIT_SPEAKER_EMU_NONE)
    14041431        {
    14051432            Assert(fd == -1);
     
    15261553    /* .pszR0Mod = */               "VBoxDDR0.r0",
    15271554    /* .pfnConstruct = */           pitR3Construct,
    1528     /* .pfnDestruct = */            NULL,
     1555    /* .pfnDestruct = */            pitR3Destruct,
    15291556    /* .pfnRelocate = */            NULL,
    15301557    /* .pfnMemSetup = */            NULL,
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