Index: trunk/src/VBox/Devices/Audio/DevHda.cpp
===================================================================
--- trunk/src/VBox/Devices/Audio/DevHda.cpp	(revision 89875)
+++ trunk/src/VBox/Devices/Audio/DevHda.cpp	(revision 89876)
@@ -62,14 +62,4 @@
 *********************************************************************************************************************************/
 //#define HDA_AS_PCI_EXPRESS
-
-/* Installs a DMA access handler (via PGM callback) to monitor
- * HDA's DMA operations, that is, writing / reading audio stream data.
- *
- * !!! Note: Certain guests are *that* timing sensitive that when enabling  !!!
- * !!!       such a handler will mess up audio completely (e.g. Windows 7). !!! */
-//#define HDA_USE_DMA_ACCESS_HANDLER
-#ifdef HDA_USE_DMA_ACCESS_HANDLER
-# include <VBox/vmm/pgm.h>
-#endif
 
 /* Uses the DMA access handler to read the written DMA audio (output) data.
@@ -174,30 +164,4 @@
     R3PTRTYPE(PAUDMIXSTREAM)           pMixStrm;
 } HDADRIVERSTREAM, *PHDADRIVERSTREAM;
-
-#ifdef HDA_USE_DMA_ACCESS_HANDLER
-/**
- * Struct for keeping an HDA DMA access handler context.
- */
-typedef struct HDADMAACCESSHANDLER
-{
-    /** Node for storing this handler in our list in HDASTREAMSTATE. */
-    RTLISTNODER3            Node;
-    /** Pointer to stream to which this access handler is assigned to. */
-    R3PTRTYPE(PHDASTREAM)   pStream;
-    /** Access handler type handle. */
-    PGMPHYSHANDLERTYPE      hAccessHandlerType;
-    /** First address this handler uses. */
-    RTGCPHYS                GCPhysFirst;
-    /** Last address this handler uses. */
-    RTGCPHYS                GCPhysLast;
-    /** Actual BDLE address to handle. */
-    RTGCPHYS                BDLEAddr;
-    /** Actual BDLE buffer size to handle. */
-    RTGCPHYS                BDLESize;
-    /** Whether the access handler has been registered or not. */
-    bool                    fRegistered;
-    uint8_t                 Padding[3];
-} HDADMAACCESSHANDLER, *PHDADMAACCESSHANDLER;
-#endif
 
 /**
@@ -345,9 +309,4 @@
 static int                        hdaR3AddStream(PHDASTATER3 pThisCC, PPDMAUDIOSTREAMCFG pCfg);
 static int                        hdaR3RemoveStream(PHDASTATER3 pThisCC, PPDMAUDIOSTREAMCFG pCfg);
-# ifdef HDA_USE_DMA_ACCESS_HANDLER
-static DECLCALLBACK(VBOXSTRICTRC) hdaR3DmaAccessHandler(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void *pvPhys,
-                                                        void *pvBuf, size_t cbBuf,
-                                                        PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, void *pvUser);
-# endif
 #endif /* IN_RING3 */
 /** @} */
@@ -1603,16 +1562,4 @@
     AssertReturn(idxStream < RT_ELEMENTS(pThis->aStreams), VERR_INTERNAL_ERROR_3); /* paranoia^2: Bad g_aHdaRegMap. */
 
-#ifdef HDA_USE_DMA_ACCESS_HANDLER
-    if (hdaGetDirFromSD(uSD) == PDMAUDIODIR_OUT)
-    {
-        /* Try registering the DMA handlers.
-         * As we can't be sure in which order LVI + BDL base are set, try registering in both routines. */
-        PHDASTREAM pStream = hdaGetStreamFromSD(pThis, idxStream);
-        if (   pStream
-            && hdaR3StreamRegisterDMAHandlers(pThis, pStream))
-            LogFunc(("[SD%RU8] DMA logging enabled\n", pStream->u8SD));
-    }
-#endif
-
     ASSERT_GUEST_LOGREL_MSG(u32Value <= UINT8_MAX, /* Should be covered by the register write mask, but just to make sure. */
                             ("LVI for stream #%zu must not be bigger than %RU8\n", idxStream, UINT8_MAX - 1));
@@ -1985,24 +1932,6 @@
 DECLINLINE(VBOXSTRICTRC) hdaRegWriteSDBDPX(PPDMDEVINS pDevIns, PHDASTATE pThis, uint32_t iReg, uint32_t u32Value, uint8_t uSD)
 {
-#ifndef HDA_USE_DMA_ACCESS_HANDLER
     RT_NOREF(uSD);
     return hdaRegWriteU32(pDevIns, pThis, iReg, u32Value);
-#else
-# ifdef IN_RING3
-    if (hdaGetDirFromSD(uSD) == PDMAUDIODIR_OUT)
-    {
-        /* Try registering the DMA handlers.
-         * As we can't be sure in which order LVI + BDL base are set, try registering in both routines. */
-        PHDASTREAM pStream = hdaGetStreamFromSD(pThis, uSD);
-        if (   pStream
-            && hdaR3StreamRegisterDMAHandlers(pThis, pStream))
-            LogFunc(("[SD%RU8] DMA logging enabled\n", pStream->u8SD));
-    }
-    return hdaRegWriteU32(pDevIns, pThis, iReg, u32Value);
-# else
-    RT_NOREF(pDevIns, pThis, iReg, u32Value, uSD);
-    return VINF_IOM_R3_MMIO_WRITE;
-# endif
-#endif
 }
 
@@ -2726,137 +2655,4 @@
 }
 
-# ifdef HDA_USE_DMA_ACCESS_HANDLER
-/**
- * HC access handler for the FIFO.
- *
- * @returns VINF_SUCCESS if the handler have carried out the operation.
- * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
- * @param   pVM             VM Handle.
- * @param   pVCpu           The cross context CPU structure for the calling EMT.
- * @param   GCPhys          The physical address the guest is writing to.
- * @param   pvPhys          The HC mapping of that address.
- * @param   pvBuf           What the guest is reading/writing.
- * @param   cbBuf           How much it's reading/writing.
- * @param   enmAccessType   The access type.
- * @param   enmOrigin       Who is making the access.
- * @param   pvUser          User argument.
- */
-static DECLCALLBACK(VBOXSTRICTRC) hdaR3DmaAccessHandler(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void *pvPhys,
-                                                        void *pvBuf, size_t cbBuf,
-                                                        PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, void *pvUser)
-{
-    RT_NOREF(pVM, pVCpu, pvPhys, pvBuf, enmOrigin);
-
-    PHDADMAACCESSHANDLER pHandler = (PHDADMAACCESSHANDLER)pvUser;
-    AssertPtr(pHandler);
-
-    PHDASTREAM pStream = pHandler->pStream;
-    AssertPtr(pStream);
-
-    Assert(GCPhys >= pHandler->GCPhysFirst);
-    Assert(GCPhys <= pHandler->GCPhysLast);
-    Assert(enmAccessType == PGMACCESSTYPE_WRITE);
-
-    /* Not within BDLE range? Bail out. */
-    if (   (GCPhys         < pHandler->BDLEAddr)
-        || (GCPhys + cbBuf > pHandler->BDLEAddr + pHandler->BDLESize))
-    {
-        return VINF_PGM_HANDLER_DO_DEFAULT;
-    }
-
-    switch (enmAccessType)
-    {
-        case PGMACCESSTYPE_WRITE:
-        {
-#  ifdef DEBUG
-            const uint64_t tsNowNs     = RTTimeNanoTS();
-            const uint32_t tsElapsedMs = (tsNowNs - pStream->Dbg.tsWriteSlotBegin) / 1000 / 1000;
-
-            uint64_t cWritesHz   = ASMAtomicReadU64(&pStream->Dbg.cWritesHz);
-            uint64_t cbWrittenHz = ASMAtomicReadU64(&pStream->Dbg.cbWrittenHz);
-
-            if (tsElapsedMs >= (1000 / HDA_TIMER_HZ_DEFAULT))
-            {
-                LogFunc(("[SD%RU8] %RU32ms elapsed, cbWritten=%RU64, cWritten=%RU64 -- %RU32 bytes on average per time slot (%zums)\n",
-                         pStream->u8SD, tsElapsedMs, cbWrittenHz, cWritesHz,
-                         ASMDivU64ByU32RetU32(cbWrittenHz, cWritesHz ? cWritesHz : 1), 1000 / HDA_TIMER_HZ_DEFAULT));
-
-                pStream->Dbg.tsWriteSlotBegin = tsNowNs;
-
-                cWritesHz   = 0;
-                cbWrittenHz = 0;
-            }
-
-            cWritesHz   += 1;
-            cbWrittenHz += cbBuf;
-
-            ASMAtomicIncU64(&pStream->Dbg.cWritesTotal);
-            ASMAtomicAddU64(&pStream->Dbg.cbWrittenTotal, cbBuf);
-
-            ASMAtomicWriteU64(&pStream->Dbg.cWritesHz,   cWritesHz);
-            ASMAtomicWriteU64(&pStream->Dbg.cbWrittenHz, cbWrittenHz);
-
-            LogFunc(("[SD%RU8] Writing %3zu @ 0x%x (off %zu)\n",
-                     pStream->u8SD, cbBuf, GCPhys, GCPhys - pHandler->BDLEAddr));
-
-            LogFunc(("[SD%RU8] cWrites=%RU64, cbWritten=%RU64 -> %RU32 bytes on average\n",
-                     pStream->u8SD, pStream->Dbg.cWritesTotal, pStream->Dbg.cbWrittenTotal,
-                     ASMDivU64ByU32RetU32(pStream->Dbg.cbWrittenTotal, pStream->Dbg.cWritesTotal)));
-#  endif
-
-#  ifdef VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH
-            if (pThis->fDebugEnabled)
-            {
-                RTFILE fh;
-                RTFileOpen(&fh, VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH "hdaDMAAccessWrite.pcm",
-                           RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
-                RTFileWrite(fh, pvBuf, cbBuf, NULL);
-                RTFileClose(fh);
-            }
-#  endif
-
-#  ifdef HDA_USE_DMA_ACCESS_HANDLER_WRITING
-            PRTCIRCBUF pCircBuf = pStream->State.pCircBuf;
-            AssertPtr(pCircBuf);
-
-            uint8_t *pbBuf = (uint8_t *)pvBuf;
-            while (cbBuf)
-            {
-                /* Make sure we only copy as much as the stream's FIFO can hold (SDFIFOS, 18.2.39). */
-                void *pvChunk;
-                size_t cbChunk;
-                RTCircBufAcquireWriteBlock(pCircBuf, cbBuf, &pvChunk, &cbChunk);
-
-                if (cbChunk)
-                {
-                    memcpy(pvChunk, pbBuf, cbChunk);
-
-                    pbBuf  += cbChunk;
-                    Assert(cbBuf >= cbChunk);
-                    cbBuf  -= cbChunk;
-                }
-                else
-                {
-                    //AssertMsg(RTCircBufFree(pCircBuf), ("No more space but still %zu bytes to write\n", cbBuf));
-                    break;
-                }
-
-                LogFunc(("[SD%RU8] cbChunk=%zu\n", pStream->u8SD, cbChunk));
-
-                RTCircBufReleaseWriteBlock(pCircBuf, cbChunk);
-            }
-#  endif /* HDA_USE_DMA_ACCESS_HANDLER_WRITING */
-            break;
-        }
-
-        default:
-            AssertMsgFailed(("Access type not implemented\n"));
-            break;
-    }
-
-    return VINF_PGM_HANDLER_DO_DEFAULT;
-}
-# endif /* HDA_USE_DMA_ACCESS_HANDLER */
-
 /**
  * Soft reset of the device triggered via GCTL.
@@ -3588,9 +3384,4 @@
             rc2 = hdaR3AddStream(pThisCC, &pStreamShared->State.Cfg);
             AssertRC(rc2);
-
-#ifdef HDA_USE_DMA_ACCESS_HANDLER
-            /* (Re-)install the DMA handler. */
-            hdaR3StreamRegisterDMAHandlers(pThis, pStreamShared);
-#endif
 
             /* Use the LPIB to find the current scheduling position.  If this isn't
Index: trunk/src/VBox/Devices/Audio/DevHdaStream.cpp
===================================================================
--- trunk/src/VBox/Devices/Audio/DevHdaStream.cpp	(revision 89875)
+++ trunk/src/VBox/Devices/Audio/DevHdaStream.cpp	(revision 89876)
@@ -81,7 +81,4 @@
     pStreamShared->State.fInReset = false;
     pStreamShared->State.fRunning = false;
-# ifdef HDA_USE_DMA_ACCESS_HANDLER
-    RTListInit(&pStreamR3->State.lstDMAHandlers);
-# endif
 
     AssertPtr(pStreamR3->pHDAStateR3);
@@ -855,8 +852,4 @@
     HDA_STREAM_REG(pThis, BDPU,  uSD) = 0;
     HDA_STREAM_REG(pThis, BDPL,  uSD) = 0;
-
-# ifdef HDA_USE_DMA_ACCESS_HANDLER
-    hdaR3StreamUnregisterDMAHandlers(pThis, pStream);
-# endif
 
     /* Assign the default mixer sink to the stream. */
@@ -2600,176 +2593,4 @@
 }
 
-
-# ifdef HDA_USE_DMA_ACCESS_HANDLER
-/**
- * Registers access handlers for a stream's BDLE DMA accesses.
- *
- * @returns true if registration was successful, false if not.
- * @param   pStream             HDA stream to register BDLE access handlers for.
- */
-bool hdaR3StreamRegisterDMAHandlers(PHDASTREAM pStream)
-{
-    /* At least LVI and the BDL base must be set. */
-    if (   !pStreamShared->u16LVI
-        || !pStreamShared->u64BDLBase)
-    {
-        return false;
-    }
-
-    hdaR3StreamUnregisterDMAHandlers(pStream);
-
-    LogFunc(("Registering ...\n"));
-
-    int rc = VINF_SUCCESS;
-
-    /*
-     * Create BDLE ranges.
-     */
-
-    struct BDLERANGE
-    {
-        RTGCPHYS uAddr;
-        uint32_t uSize;
-    } arrRanges[16]; /** @todo Use a define. */
-
-    size_t cRanges = 0;
-
-    for (uint16_t i = 0; i < pStreamShared->u16LVI + 1; i++)
-    {
-        HDABDLE BDLE;
-        rc = hdaR3BDLEFetch(pDevIns, &BDLE, pStreamShared->u64BDLBase, i /* Index */);
-        if (RT_FAILURE(rc))
-            break;
-
-        bool fAddRange = true;
-        BDLERANGE *pRange;
-
-        if (cRanges)
-        {
-            pRange = &arrRanges[cRanges - 1];
-
-            /* Is the current range a direct neighbor of the current BLDE? */
-            if ((pRange->uAddr + pRange->uSize) == BDLE.Desc.u64BufAddr)
-            {
-                /* Expand the current range by the current BDLE's size. */
-                pRange->uSize += BDLE.Desc.u32BufSize;
-
-                /* Adding a new range in this case is not needed anymore. */
-                fAddRange = false;
-
-                LogFunc(("Expanding range %zu by %RU32 (%RU32 total now)\n", cRanges - 1, BDLE.Desc.u32BufSize, pRange->uSize));
-            }
-        }
-
-        /* Do we need to add a new range? */
-        if (   fAddRange
-            && cRanges < RT_ELEMENTS(arrRanges))
-        {
-            pRange = &arrRanges[cRanges];
-
-            pRange->uAddr = BDLE.Desc.u64BufAddr;
-            pRange->uSize = BDLE.Desc.u32BufSize;
-
-            LogFunc(("Adding range %zu - 0x%x (%RU32)\n", cRanges, pRange->uAddr, pRange->uSize));
-
-            cRanges++;
-        }
-    }
-
-    LogFunc(("%zu ranges total\n", cRanges));
-
-    /*
-     * Register all ranges as DMA access handlers.
-     */
-
-    for (size_t i = 0; i < cRanges; i++)
-    {
-        BDLERANGE *pRange = &arrRanges[i];
-
-        PHDADMAACCESSHANDLER pHandler = (PHDADMAACCESSHANDLER)RTMemAllocZ(sizeof(HDADMAACCESSHANDLER));
-        if (!pHandler)
-        {
-            rc = VERR_NO_MEMORY;
-            break;
-        }
-
-        RTListAppend(&pStream->State.lstDMAHandlers, &pHandler->Node);
-
-        pHandler->pStream = pStream; /* Save a back reference to the owner. */
-
-        char szDesc[32];
-        RTStrPrintf(szDesc, sizeof(szDesc), "HDA[SD%RU8 - RANGE%02zu]", pStream->u8SD, i);
-
-        int rc2 = PGMR3HandlerPhysicalTypeRegister(PDMDevHlpGetVM(pStream->pHDAState->pDevInsR3), PGMPHYSHANDLERKIND_WRITE,
-                                                   hdaDMAAccessHandler,
-                                                   NULL, NULL, NULL,
-                                                   NULL, NULL, NULL,
-                                                   szDesc, &pHandler->hAccessHandlerType);
-        AssertRCBreak(rc2);
-
-        pHandler->BDLEAddr  = pRange->uAddr;
-        pHandler->BDLESize  = pRange->uSize;
-
-        /* Get first and last pages of the BDLE range. */
-        RTGCPHYS pgFirst = pRange->uAddr & ~PAGE_OFFSET_MASK;
-        RTGCPHYS pgLast  = RT_ALIGN(pgFirst + pRange->uSize, PAGE_SIZE);
-
-        /* Calculate the region size (in pages). */
-        RTGCPHYS regionSize = RT_ALIGN(pgLast - pgFirst, PAGE_SIZE);
-
-        pHandler->GCPhysFirst = pgFirst;
-        pHandler->GCPhysLast  = pHandler->GCPhysFirst + (regionSize - 1);
-
-        LogFunc(("  Registering region '%s': %#RGp - %#RGp (region size: %#zx)\n",
-                 szDesc, pHandler->GCPhysFirst, pHandler->GCPhysLast, regionSize));
-        LogFunc(("  BDLE @ %#RGp - %#RGp (%#RX32)\n",
-                 pHandler->BDLEAddr, pHandler->BDLEAddr + pHandler->BDLESize, pHandler->BDLESize));
-
-        rc2 = PGMHandlerPhysicalRegister(PDMDevHlpGetVM(pStream->pHDAState->pDevInsR3),
-                                         pHandler->GCPhysFirst, pHandler->GCPhysLast,
-                                         pHandler->hAccessHandlerType, pHandler, NIL_RTR0PTR, NIL_RTRCPTR,
-                                         szDesc);
-        AssertRCBreak(rc2);
-
-        pHandler->fRegistered = true;
-    }
-
-    LogFunc(("Registration ended with rc=%Rrc\n", rc));
-
-    return RT_SUCCESS(rc);
-}
-
-/**
- * Unregisters access handlers of a stream's BDLEs.
- *
- * @param   pStream             HDA stream to unregister BDLE access handlers for.
- */
-void hdaR3StreamUnregisterDMAHandlers(PHDASTREAM pStream)
-{
-    LogFunc(("\n"));
-
-    PHDADMAACCESSHANDLER pHandler, pHandlerNext;
-    RTListForEachSafe(&pStream->State.lstDMAHandlers, pHandler, pHandlerNext, HDADMAACCESSHANDLER, Node)
-    {
-        if (!pHandler->fRegistered) /* Handler not registered? Skip. */
-            continue;
-
-        LogFunc(("Unregistering 0x%x - 0x%x (%zu)\n",
-                 pHandler->GCPhysFirst, pHandler->GCPhysLast, pHandler->GCPhysLast - pHandler->GCPhysFirst));
-
-        int rc2 = PGMHandlerPhysicalDeregister(PDMDevHlpGetVM(pStream->pHDAState->pDevInsR3),
-                                               pHandler->GCPhysFirst);
-        AssertRC(rc2);
-
-        RTListNodeRemove(&pHandler->Node);
-
-        RTMemFree(pHandler);
-        pHandler = NULL;
-    }
-
-    Assert(RTListIsEmpty(&pStream->State.lstDMAHandlers));
-}
-
-# endif /* HDA_USE_DMA_ACCESS_HANDLER */
-
 #endif /* IN_RING3 */
+
Index: trunk/src/VBox/Devices/Audio/DevHdaStream.h
===================================================================
--- trunk/src/VBox/Devices/Audio/DevHdaStream.h	(revision 89875)
+++ trunk/src/VBox/Devices/Audio/DevHdaStream.h	(revision 89876)
@@ -283,8 +283,4 @@
         /** Circular buffer (FIFO) for holding DMA'ed data. */
         R3PTRTYPE(PRTCIRCBUF)   pCircBuf;
-#ifdef HDA_USE_DMA_ACCESS_HANDLER
-        /** List of DMA handlers. */
-        RTLISTANCHORR3          lstDMAHandlers;
-#endif
         /** The mixer sink this stream has registered AIO update callback with.
          * This is NULL till we register it, typically in hdaR3StreamEnable.
@@ -347,8 +343,4 @@
                                          PHDASTREAM pStreamShared, PHDASTREAMR3 pStreamR3);
 DECLCALLBACK(void)  hdaR3StreamUpdateAsyncIoJob(PPDMDEVINS pDevIns, PAUDMIXSINK pSink, void *pvUser);
-# ifdef HDA_USE_DMA_ACCESS_HANDLER
-bool                hdaR3StreamRegisterDMAHandlers(PHDASTREAM pStream);
-void                hdaR3StreamUnregisterDMAHandlers(PHDASTREAM pStream);
-# endif
 /** @} */
 
