Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp	(revision 33710)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp	(revision 33711)
@@ -1475,46 +1475,29 @@
 }
 
-BOOLEAN VBoxUnmapAdpInfoCallback(PVOID ext)
-{
-    PDEVICE_EXTENSION   PrimaryExtension = (PDEVICE_EXTENSION)ext;
-    Assert(PrimaryExtension);
-
-    commonFromDeviceExt(PrimaryExtension)->pHostFlags = NULL;
-    return TRUE;
-}
-
-void VBoxUnmapAdapterInformation(PDEVICE_EXTENSION PrimaryExtension)
-{
-    void                *ppv;
-
-    dprintf(("VBoxVideo::VBoxUnmapAdapterInformation\n"));
-
-    ppv = commonFromDeviceExt(PrimaryExtension)->pvAdapterInformation;
-    if (ppv)
-    {
+bool VBoxSyncToVideoIRQ(PVBOXVIDEO_COMMON pCommon, PFNVIDEOIRQSYNC pfnSync,
+                        void *pvUser)
+{
+    PDEVICE_EXTENSION PrimaryExtension = commonToPrimaryExt(pCommon);
+    PMINIPORT_SYNCHRONIZE_ROUTINE pfnSyncMiniport;
+    pfnSyncMiniport = (PMINIPORT_SYNCHRONIZE_ROUTINE) pfnSync;
 #ifndef VBOX_WITH_WDDM
-        /* The pHostFlags field is mapped through pvAdapterInformation. It must be cleared first,
-         * and it must be done in a way which avoids races with the interrupt handler.
-         */
-        VideoPortSynchronizeExecution(PrimaryExtension, VpMediumPriority,
-                                      VBoxUnmapAdpInfoCallback, PrimaryExtension);
-        VideoPortUnmapMemory(PrimaryExtension, ppv, NULL);
+    return !!VideoPortSynchronizeExecution(PrimaryExtension, VpMediumPriority,
+                                           pfnSyncMiniport, pvUser);
 #else
-        BOOLEAN bRet;
-        NTSTATUS ntStatus = PrimaryExtension->u.primary.DxgkInterface.DxgkCbSynchronizeExecution(PrimaryExtension->u.primary.DxgkInterface.DeviceHandle,
-                VBoxUnmapAdpInfoCallback, PrimaryExtension,
-                0, &bRet);
-        Assert(ntStatus == STATUS_SUCCESS);
-        ntStatus = PrimaryExtension->u.primary.DxgkInterface.DxgkCbUnmapMemory(PrimaryExtension->u.primary.DxgkInterface.DeviceHandle,
-                ppv);
-        Assert(ntStatus == STATUS_SUCCESS);
-#endif
-        commonFromDeviceExt(PrimaryExtension)->pvAdapterInformation = NULL;
-    }
-}
-
-void VBoxUnmapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension, void **ppv)
+    BOOLEAN fRet;
+    DXGKCB_SYNCHRONIZE_EXECUTION pfnDxgkCbSync =
+        PrimaryExtension->u.primary.DxgkInterface.DxgkCbSynchronizeExecution;
+    HANDLE hDev = PrimaryExtension->u.primary.DxgkInterface.DeviceHandle;
+    NTSTATUS ntStatus = pfnDxgkCbSync(hDev, pfnSyncMiniport, pvUser, 0, &fRet);
+    AssertReturn(ntStatus == STATUS_SUCCESS, false);
+    return !!fRet;
+#endif
+}
+
+void VBoxUnmapAdapterMemory (PVBOXVIDEO_COMMON pCommon, void **ppv)
 {
     dprintf(("VBoxVideo::VBoxUnmapAdapterMemory\n"));
+
+    PDEVICE_EXTENSION PrimaryExtension = commonToPrimaryExt(pCommon);
 
     if (*ppv)
@@ -2691,5 +2674,5 @@
     VbglTerminate ();
 
-    VBoxFreeDisplaysHGSMI(pDevExt);
+    VBoxFreeDisplaysHGSMI(commonFromDeviceExt(pDevExt));
     /** @note using this callback instead of doing things manually adds an
      *        additional call to HGSMIHeapDestroy().  I assume that call was
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h	(revision 33710)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h	(revision 33711)
@@ -807,7 +807,9 @@
                           ULONG ulSize);
 
-void VBoxUnmapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension,
-                             void **ppv);
-void VBoxUnmapAdapterInformation (PDEVICE_EXTENSION PrimaryExtension);
+void VBoxUnmapAdapterMemory (PVBOXVIDEO_COMMON pCommon, void **ppv);
+
+typedef bool(*PFNVIDEOIRQSYNC)(void *);
+bool VBoxSyncToVideoIRQ(PVBOXVIDEO_COMMON pCommon, PFNVIDEOIRQSYNC pfnSync,
+                        void *pvUser);
 
 void VBoxComputeFrameBufferSizes (PDEVICE_EXTENSION PrimaryExtension);
@@ -850,5 +852,5 @@
                                 uint32_t cbLength);
 
-void VBoxFreeDisplaysHGSMI(PDEVICE_EXTENSION PrimaryExtension);
+void VBoxFreeDisplaysHGSMI(PVBOXVIDEO_COMMON pCommon);
 #ifndef VBOX_WITH_WDDM
 DECLCALLBACK(void) hgsmiHostCmdComplete (HVBOXVIDEOHGSMI hHGSMI, struct _VBVAHOSTCMD * pCmd);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideoHGSMI.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideoHGSMI.cpp	(revision 33710)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideoHGSMI.cpp	(revision 33711)
@@ -539,124 +539,26 @@
     }
 
-#ifdef VBOX_WITH_WDDM
-    /* For WDDM, we simply store the number of monitors as we will deal with
-     * VidPN stuff later */
-    if (commonFromDeviceExt(PrimaryExtension)->bHGSMI)
-    {
-        ULONG ulAvailable = commonFromDeviceExt(PrimaryExtension)->cbVRAM
-                            - commonFromDeviceExt(PrimaryExtension)->cbMiniportHeap
-                            - VBVA_ADAPTER_INFORMATION_SIZE;
-
-        ULONG ulSize;
-        ULONG offset;
-#ifdef VBOX_WITH_VDMA
-        ulSize = ulAvailable / 2;
-        if (ulSize > VBOXWDDM_C_VDMA_BUFFER_SIZE)
-            ulSize = VBOXWDDM_C_VDMA_BUFFER_SIZE;
-
-        /* Align down to 4096 bytes. */
-        ulSize &= ~0xFFF;
-        offset = ulAvailable - ulSize;
-
-        Assert(!(offset & 0xFFF));
-#else
-        offset = ulAvailable;
-#endif
-        rc = vboxVdmaCreate (PrimaryExtension, &PrimaryExtension->u.primary.Vdma
-#ifdef VBOX_WITH_VDMA
-                , offset, ulSize
-#endif
-                );
-        AssertRC(rc);
-        if (RT_SUCCESS(rc))
-        {
-            /* can enable it right away since the host does not need any screen/FB info
-             * for basic DMA functionality */
-            rc = vboxVdmaEnable(PrimaryExtension, &PrimaryExtension->u.primary.Vdma);
-            AssertRC(rc);
-            if (RT_FAILURE(rc))
-                vboxVdmaDestroy(PrimaryExtension, &PrimaryExtension->u.primary.Vdma);
-        }
-
-        ulAvailable = offset;
-        ulSize = ulAvailable/2;
-        offset = ulAvailable - ulSize;
-
-        NTSTATUS Status = vboxVideoAMgrCreate(PrimaryExtension, &PrimaryExtension->AllocMgr, offset, ulSize);
-        Assert(Status == STATUS_SUCCESS);
-        if (Status != STATUS_SUCCESS)
-        {
-            offset = ulAvailable;
-        }
-
-#ifdef VBOXWDDM_RENDER_FROM_SHADOW
-        if (RT_SUCCESS(rc))
-        {
-            ulAvailable = offset;
-            ulSize = ulAvailable / 2;
-            ulSize /= commonFromDeviceExt(PrimaryExtension)->cDisplays;
-            Assert(ulSize > VBVA_MIN_BUFFER_SIZE);
-            if (ulSize > VBVA_MIN_BUFFER_SIZE)
-            {
-                ULONG ulRatio = ulSize/VBVA_MIN_BUFFER_SIZE;
-                ulRatio >>= 4; /* /= 16; */
-                if (ulRatio)
-                    ulSize = VBVA_MIN_BUFFER_SIZE * ulRatio;
-                else
-                    ulSize = VBVA_MIN_BUFFER_SIZE;
-            }
-            else
-            {
-                /* todo: ?? */
-            }
-
-            ulSize &= ~0xFFF;
-            Assert(ulSize);
-
-            Assert(ulSize * commonFromDeviceExt(PrimaryExtension)->cDisplays < ulAvailable);
-
-            for (int i = commonFromDeviceExt(PrimaryExtension)->cDisplays-1; i >= 0; --i)
-            {
-                offset -= ulSize;
-                rc = vboxVbvaCreate(PrimaryExtension, &PrimaryExtension->aSources[i].Vbva, offset, ulSize, i);
-                AssertRC(rc);
-                if (RT_SUCCESS(rc))
-                {
-                    rc = vboxVbvaEnable(PrimaryExtension, &PrimaryExtension->aSources[i].Vbva);
-                    AssertRC(rc);
-                    if (RT_FAILURE(rc))
-                    {
-                        /* @todo: de-initialize */
-                    }
-                }
-            }
-        }
-#endif
-
-        rc = VBoxMapAdapterMemory(commonFromDeviceExt(PrimaryExtension), (void**)&PrimaryExtension->pvVisibleVram,
-                                       0,
-                                       vboxWddmVramCpuVisibleSize(PrimaryExtension));
-        Assert(rc == VINF_SUCCESS);
-        if (rc != VINF_SUCCESS)
-            PrimaryExtension->pvVisibleVram = NULL;
-
-        if (RT_FAILURE(rc))
-            commonFromDeviceExt(PrimaryExtension)->bHGSMI = FALSE;
-    }
-#endif
-
     if (!commonFromDeviceExt(PrimaryExtension)->bHGSMI)
-        VBoxFreeDisplaysHGSMI(PrimaryExtension);
+        VBoxFreeDisplaysHGSMI(commonFromDeviceExt(PrimaryExtension));
 
     dprintf(("VBoxVideo::VBoxSetupDisplays: finished\n"));
 }
 
-void VBoxFreeDisplaysHGSMI(PDEVICE_EXTENSION PrimaryExtension)
-{
-    VBoxUnmapAdapterMemory(PrimaryExtension, &commonFromDeviceExt(PrimaryExtension)->pvMiniportHeap);
-    HGSMIHeapDestroy(&commonFromDeviceExt(PrimaryExtension)->hgsmiAdapterHeap);
+static bool VBoxUnmapAdpInfoCallback(PVOID pvCommon)
+{
+    PVBOXVIDEO_COMMON pCommon = (PVBOXVIDEO_COMMON)pvCommon;
+
+    pCommon->pHostFlags = NULL;
+    return TRUE;
+}
+
+void VBoxFreeDisplaysHGSMI(PVBOXVIDEO_COMMON pCommon)
+{
+    VBoxUnmapAdapterMemory(pCommon, &pCommon->pvMiniportHeap);
+    HGSMIHeapDestroy(&pCommon->hgsmiAdapterHeap);
 
     /* Unmap the adapter information needed for HGSMI IO. */
-    VBoxUnmapAdapterInformation(PrimaryExtension);
+    VBoxSyncToVideoIRQ(pCommon, VBoxUnmapAdpInfoCallback, pCommon);
+    VBoxUnmapAdapterMemory(pCommon, &pCommon->pvAdapterInformation);
 }
 
@@ -746,5 +648,5 @@
     uint32_t cbData = 0;
 
-    if (pointerAttr->Enable & VBOX_MOUSE_POINTER_SHAPE)
+    if (!pointerAttr->Enable & VBOX_MOUSE_POINTER_SHAPE)
     {
         /* Size of the pointer data: sizeof (AND mask) + sizeof (XOR_MASK) */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVbva.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVbva.cpp	(revision 33710)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVbva.cpp	(revision 33711)
@@ -125,5 +125,5 @@
 {
     int rc = VINF_SUCCESS;
-    VBoxUnmapAdapterMemory(pDevExt, (void**)&pVbva->pVBVA);
+    VBoxUnmapAdapterMemory(commonFromDeviceExt(pDevExt), (void**)&pVbva->pVBVA);
     memset(pVbva, 0, sizeof(VBOXVBVAINFO));
     return rc;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVdma.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVdma.cpp	(revision 33710)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVdma.cpp	(revision 33711)
@@ -1116,5 +1116,5 @@
             drprintf((__FUNCTION__": HGSMIHeapSetup failed rc = 0x%x\n", rc));
 
-        VBoxUnmapAdapterMemory(pDevExt, &pvBuffer);
+        VBoxUnmapAdapterMemory(commonFromDeviceExt(pDevExt), &pvBuffer);
     }
     else
@@ -1189,5 +1189,5 @@
             rc = vboxVdmaDisable (pDevExt, pInfo);
 #ifdef VBOX_WITH_VDMA
-        VBoxUnmapAdapterMemory (pDevExt, (void**)&pInfo->CmdHeap.area.pu8Base);
+        VBoxUnmapAdapterMemory (commonFromDeviceExt(pDevExt), (void**)&pInfo->CmdHeap.area.pu8Base);
 #endif
     }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp	(revision 33710)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp	(revision 33711)
@@ -609,5 +609,5 @@
     Assert(pDevExt->pvVisibleVram);
     if (pDevExt->pvVisibleVram)
-        VBoxUnmapAdapterMemory(pDevExt, (void**)&pDevExt->pvVisibleVram);
+        VBoxUnmapAdapterMemory(commonFromDeviceExt(pDevExt), (void**)&pDevExt->pvVisibleVram);
 
     for (int i = commonFromDeviceExt(pDevExt)->cDisplays-1; i >= 0; --i)
@@ -739,5 +739,5 @@
                     vboxWddmSetupDisplays(pContext);
                     if (!commonFromDeviceExt(pContext)->bHGSMI)
-                        VBoxFreeDisplaysHGSMI(pContext);
+                        VBoxFreeDisplaysHGSMI(commonFromDeviceExt(pContext));
                 }
                 if (commonFromDeviceExt(pContext)->bHGSMI)
@@ -813,5 +813,5 @@
     int rc = vboxWddmFreeDisplays(pDevExt);
     if (RT_SUCCESS(rc))
-        VBoxFreeDisplaysHGSMI(pDevExt);
+        VBoxFreeDisplaysHGSMI(commonFromDeviceExt(pDevExt));
     AssertRC(rc);
     if (RT_SUCCESS(rc))
