Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/Makefile.kmk
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/Makefile.kmk	(revision 34406)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/Makefile.kmk	(revision 34438)
@@ -47,4 +47,5 @@
 	vrdptext.c \
 	vbox.c \
+	$(PATH_ROOT)/src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp \
 	VBoxDisp.def \
 	VBoxDisp.rc
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/dd.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/dd.c	(revision 34406)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/dd.c	(revision 34438)
@@ -1176,18 +1176,18 @@
         if(!!(lpSurfaceLocal->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
                 && pDesc->UpdatedMemRegion.bValid
-                && vboxHwBufferBeginUpdate (pDev))
+                && VBoxVBVABufferBeginUpdate(&pDev->vbvaCtx, &pDev->guestCtx))
         {
             vbvaReportDirtyRect (pDev, &pDesc->UpdatedMemRegion.Rect);
 
-            if (  pDev->pVBVA->hostFlags.u32HostEvents
+            if (  pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents
                 & VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET)
             {
                 vrdpReset (pDev);
 
-                pDev->pVBVA->hostFlags.u32HostEvents &=
+                pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents &=
                           ~VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
             }
 
-            if (pDev->pVBVA->hostFlags.u32HostEvents
+            if (pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents
                 & VBVA_F_MODE_VRDP)
             {
@@ -1195,5 +1195,5 @@
             }
 
-            vboxHwBufferEndUpdate (pDev);
+            VBoxVBVABufferEndUpdate(&pDev->vbvaCtx);
 
             lpUnlock->ddRVal = DD_OK;
@@ -1245,18 +1245,19 @@
         DISPDBG((0, "%d,%d %dx%d\n", pDev->ddLock.rArea.left, pDev->ddLock.rArea.top, pDev->ddLock.rArea.right - pDev->ddLock.rArea.left, pDev->ddLock.rArea.bottom - pDev->ddLock.rArea.top));
 
-        if (pDev->bHGSMISupported && vboxHwBufferBeginUpdate (pDev))
+        if (   pDev->bHGSMISupported
+            && VBoxVBVABufferBeginUpdate(&pDev->vbvaCtx, &pDev->guestCtx))
         {
             vbvaReportDirtyRect (pDev, &pDev->ddLock.rArea);
 
-            if (  pDev->pVBVA->hostFlags.u32HostEvents
+            if (  pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents
                 & VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET)
             {
                 vrdpReset (pDev);
 
-                pDev->pVBVA->hostFlags.u32HostEvents &=
+                pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents &=
                           ~VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
             }
 
-            if (pDev->pVBVA->hostFlags.u32HostEvents
+            if (pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents
                 & VBVA_F_MODE_VRDP)
             {
@@ -1264,5 +1265,5 @@
             }
 
-            vboxHwBufferEndUpdate (pDev);
+            VBoxVBVABufferEndUpdate(&pDev->vbvaCtx);
         }
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/driver.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/driver.h	(revision 34406)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/driver.h	(revision 34438)
@@ -36,4 +36,5 @@
 #include "../Miniport/vboxioctl.h"
 
+#include <VBox/VBoxVideoGuest.h>
 #include <VBox/VBoxVideo.h>
 #ifdef VBOX_WITH_VIDEOHWACCEL
@@ -168,6 +169,4 @@
     FLONG   flHooks;
 
-    BOOL             fHwBufferOverflow;
-    VBVARECORD       *pRecord;
     VRDPBC           cache;
 
@@ -192,12 +191,10 @@
 
     BOOLEAN bHGSMISupported;
-    HGSMIHEAP hgsmiDisplayHeap;
-    VBVABUFFER *pVBVA; /* Pointer to the pjScreen + layout->offVBVABuffer. NULL if VBVA is not enabled. */
+    HGSMIGUESTCOMMANDCONTEXT guestCtx;
+    VBVABUFFERCONTEXT vbvaCtx;
 
     HVBOXVIDEOHGSMI hMpHGSMI; /* context handler passed to miniport HGSMI callbacks */
     PFNVBOXVIDEOHGSMICOMPLETION pfnHGSMICommandComplete; /* called to complete the command we receive from the miniport */
     PFNVBOXVIDEOHGSMICOMMANDS   pfnHGSMIRequestCommands; /* called to requests the commands posted to us from the host */
-
-    RTIOPORT IOPortGuestCommand;
 
     PVOID pVideoPortContext;
@@ -261,14 +258,4 @@
 } VRDPCLIPRECTS;
 
-
-BOOL vboxVbvaEnable (PPDEV ppdev);
-void vboxVbvaDisable (PPDEV ppdev);
-
-BOOL vboxHwBufferBeginUpdate (PPDEV ppdev);
-void vboxHwBufferEndUpdate (PPDEV ppdev);
-
-BOOL vboxWrite (PPDEV ppdev, const void *pv, uint32_t cb);
-
-BOOL vboxOrderSupported (PPDEV ppdev, unsigned code);
 
 void VBoxProcessDisplayInfo(PPDEV ppdev);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/drv.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/drv.c	(revision 34406)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/drv.c	(revision 34438)
@@ -106,18 +106,19 @@
         PPDEV ppdev = (PPDEV)__psoDest->dhpdev;                        \
                                                                        \
-        if (ppdev->bHGSMISupported && vboxHwBufferBeginUpdate (ppdev)) \
+        if (   ppdev->bHGSMISupported                                  \
+            && VBoxVBVABufferBeginUpdate(&ppdev->vbvaCtx, &ppdev->guestCtx)) \
         {                                                              \
             vbva##__fn __a;                                            \
                                                                        \
-            if (  ppdev->pVBVA->hostFlags.u32HostEvents                \
+            if (  ppdev->vbvaCtx.pVBVA->hostFlags.u32HostEvents                \
                 & VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET)            \
             {                                                          \
                 vrdpReset (ppdev);                                     \
                                                                        \
-                ppdev->pVBVA->hostFlags.u32HostEvents &=               \
+                ppdev->vbvaCtx.pVBVA->hostFlags.u32HostEvents &=               \
                           ~VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;   \
             }                                                          \
                                                                        \
-            if (ppdev->pVBVA->hostFlags.u32HostEvents                  \
+            if (ppdev->vbvaCtx.pVBVA->hostFlags.u32HostEvents                  \
                 & VBVA_F_MODE_VRDP)                                    \
             {                                                          \
@@ -125,5 +126,5 @@
             }                                                          \
                                                                        \
-            vboxHwBufferEndUpdate (ppdev);                             \
+            VBoxVBVABufferEndUpdate(&ppdev->vbvaCtx);                             \
         }                                                              \
     }                                                                  \
@@ -322,6 +323,6 @@
         DISPDBG((1, "offscreen->screen\n"));
 
-        if (   ppdev->pVBVA
-            && (ppdev->pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_ENABLED))
+        if (   ppdev->vbvaCtx.pVBVA
+            && (ppdev->vbvaCtx.pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_ENABLED))
         {
             if (   (psoSrc->fjBitmap & BMF_DONTCACHE) != 0
@@ -729,17 +730,17 @@
         PPDEV ppdev = (PPDEV)psoTarget->dhpdev;
 
-        if (   ppdev->pVBVA
-            && (ppdev->pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_ENABLED))
+        if (   ppdev->vbvaCtx.pVBVA
+            && (ppdev->vbvaCtx.pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_ENABLED))
         {
-            if (ppdev->pVBVA->hostFlags.u32HostEvents
+            if (ppdev->vbvaCtx.pVBVA->hostFlags.u32HostEvents
                 & VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET)
             {
                 vrdpReset (ppdev);
 
-                ppdev->pVBVA->hostFlags.u32HostEvents &=
+                ppdev->vbvaCtx.pVBVA->hostFlags.u32HostEvents &=
                     ~VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
             }
 
-            if (ppdev->pVBVA->hostFlags.u32HostEvents
+            if (ppdev->vbvaCtx.pVBVA->hostFlags.u32HostEvents
                 & VBVA_F_MODE_VRDP)
             {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/enable.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/enable.c	(revision 34406)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/enable.c	(revision 34438)
@@ -126,11 +126,11 @@
         ULONG ret = 0;
 
-        if (ppdev && ppdev->pVBVA)
-        {
-            if (ppdev->pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_VRDP)
+        if (ppdev && ppdev->vbvaCtx.pVBVA)
+        {
+            if (ppdev->vbvaCtx.pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_VRDP)
             {
                 ret = 1;
             }
-            DISPDBG((0, "VBOXESC_ISVRDPACTIVE -> %d (%x)\n", ret, ppdev->pVBVA->hostFlags.u32HostEvents));
+            DISPDBG((0, "VBOXESC_ISVRDPACTIVE -> %d (%x)\n", ret, ppdev->vbvaCtx.pVBVA->hostFlags.u32HostEvents));
         }
         else
@@ -909,5 +909,9 @@
 
         /* Free the driver's VBVA resources. */
-        vboxVbvaDisable ((PPDEV) dhpdev);
+        if (ppdev->bHGSMISupported)
+        {
+            PPDEV ppdev = (PPDEV) dhpdev;
+            VBoxVBVADisable(&ppdev->vbvaCtx, &ppdev->guestCtx);
+        }
 
         //
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/screen.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/screen.c	(revision 34406)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/screen.c	(revision 34438)
@@ -221,5 +221,5 @@
          * HGSMI event flags in the beginning.
          */
-        int rc = HGSMIHeapSetup (&ppdev->hgsmiDisplayHeap,
+        int rc = HGSMIHeapSetup (&ppdev->guestCtx.heapCtx,
                                  (uint8_t *)ppdev->pjScreen + ppdev->layout.offDisplayInformation + sizeof (HGSMIHOSTFLAGS),
                                  ppdev->layout.cbDisplayInformation - sizeof (HGSMIHOSTFLAGS),
@@ -239,7 +239,11 @@
         else
         {
-            ppdev->IOPortGuestCommand = info.IOPortGuestCommand;
-        }
-    }
+            ppdev->guestCtx.port = info.IOPortGuestCommand;
+        }
+    }
+    /* Update buffer layout in VBVA context information.  Shouldn't this get
+     * zeroed if initialising the HGSMI heap fails? */
+    ppdev->vbvaCtx.offVRAMBuffer = ppdev->layout.offVBVABuffer;
+    ppdev->vbvaCtx.cbBuffer = ppdev->layout.cbVBVABuffer;
 
     DISPDBG((0, "vboxInitVBoxVideo:\n"
@@ -405,5 +409,8 @@
         {
             /* Enable VBVA for this video mode. */
-            ppdev->bHGSMISupported = vboxVbvaEnable (ppdev);
+            VBVABUFFER *pVBVA = (VBVABUFFER *)((uint8_t *)ppdev->pjScreen + ppdev->layout.offVBVABuffer);
+            ppdev->bHGSMISupported = VBoxVBVAEnable(&ppdev->vbvaCtx,
+                                                    &ppdev->guestCtx,
+                                                    pVBVA);
             LogRel(("VBoxDisp[%d]: VBVA %senabled\n", ppdev->iDevice, ppdev->bHGSMISupported? "": "not "));
         }
@@ -414,5 +421,8 @@
     /* Inform the host about this screen layout. */
     DISPDBG((1, "bInitSURF: %d,%d\n", ppdev->ptlDevOrg.x, ppdev->ptlDevOrg.y));
-    VBoxProcessDisplayInfo (ppdev);
+    if (ppdev->bHGSMISupported)
+    {
+        VBoxProcessDisplayInfo (ppdev);
+    }
 
 #ifdef VBOX_WITH_VIDEOHWACCEL
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/vbox.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/vbox.c	(revision 34406)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/vbox.c	(revision 34438)
@@ -21,10 +21,12 @@
 #include <VBox/VBoxGuest.h>
 #include <VBox/err.h>
+#include <VBox/log.h>
 #include <iprt/asm.h>
 #include <iprt/asm-amd64-x86.h>
+#include <iprt/assert.h>
 
 /*
  * There is a hardware ring buffer in the VBox VMMDev PCI memory space.
- * All graphics commands go there serialized by vboxHwBufferBeginUpdate.
+ * All graphics commands go there serialized by VBoxVBVABufferBeginUpdate.
  * and vboxHwBufferEndUpdate.
  *
@@ -37,31 +39,29 @@
 
 /* Forward declarations of internal functions. */
-static void vboxHwBufferFlush (PPDEV ppdev);
-static void vboxHwBufferPlaceDataAt (PPDEV ppdev, void *p, uint32_t cb, uint32_t offset);
-static BOOL vboxHwBufferWrite (PPDEV ppdev, const void *p, uint32_t cb);
-
-
-static void vboxHGSMIBufferSubmit (PPDEV ppdev, void *p)
-{
-    HGSMIOFFSET offBuffer = HGSMIHeapBufferOffset (&ppdev->hgsmiDisplayHeap, p);
-
-    DISPDBG((0, "VBoxDISP::vboxHGSMIBufferSubmit: offset 0x%x\n", offBuffer));
-
-    ASMOutU32(ppdev->IOPortGuestCommand, offBuffer);
-}
-
-static BOOL vboxVBVAInformHost (PPDEV ppdev, BOOL bEnable)
-{
-    BOOL bRc = FALSE;
-
+static void vboxHwBufferFlush(PHGSMIGUESTCOMMANDCONTEXT pCtx);
+static void vboxHwBufferPlaceDataAt(PVBVABUFFERCONTEXT pCtx, const void *p,
+                                    uint32_t cb, uint32_t offset);
+static bool vboxHwBufferWrite(PVBVABUFFERCONTEXT pCtx,
+                              PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx,
+                              const void *p, uint32_t cb);
+
+
+static bool vboxVBVAInformHost(PVBVABUFFERCONTEXT pCtx,
+                               PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx,
+                               bool bEnable)
+{
+    bool bRc = false;
+
+#if 0  /* All callers check this */
     if (ppdev->bHGSMISupported)
-    {
-        void *p = HGSMIHeapAlloc (&ppdev->hgsmiDisplayHeap,
-                                  sizeof (VBVAENABLE),
-                                  HGSMI_CH_VBVA,
-                                  VBVA_ENABLE);
+#endif
+    {
+        void *p = VBoxHGSMIBufferAlloc(pHGSMICtx,
+                                       sizeof (VBVAENABLE),
+                                       HGSMI_CH_VBVA,
+                                       VBVA_ENABLE);
         if (!p)
         {
-            DISPDBG((0, "VBoxDISP::vboxVBVAInformHost: HGSMIHeapAlloc failed\n"));
+            LogFunc(("HGSMIHeapAlloc failed\n"));
         }
         else
@@ -70,8 +70,8 @@
 
             pEnable->u32Flags  = bEnable? VBVA_F_ENABLE: VBVA_F_DISABLE;
-            pEnable->u32Offset = ppdev->layout.offVBVABuffer;
+            pEnable->u32Offset = pCtx->offVRAMBuffer;
             pEnable->i32Result = VERR_NOT_SUPPORTED;
 
-            vboxHGSMIBufferSubmit (ppdev, p);
+            VBoxHGSMIBufferSubmit(pHGSMICtx, p);
 
             if (bEnable)
@@ -81,8 +81,8 @@
             else
             {
-                bRc = TRUE;
+                bRc = true;
             }
 
-            HGSMIHeapFree (&ppdev->hgsmiDisplayHeap, p);
+            VBoxHGSMIBufferFree(pHGSMICtx, p);
         }
     }
@@ -94,15 +94,17 @@
  * Public hardware buffer methods.
  */
-BOOL vboxVbvaEnable (PPDEV ppdev)
-{
-    BOOL bRc = FALSE;
-
-    DISPDBG((1, "VBoxDisp::vboxVbvaEnable called ppdev %p, hgsmi %d, vbva %p\n", ppdev, ppdev->bHGSMISupported, ppdev->pVBVA));
-
+RTDECL(bool) VBoxVBVAEnable(PVBVABUFFERCONTEXT pCtx,
+                            PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx,
+                            VBVABUFFER *pVBVA)
+{
+    bool bRc = false;
+
+    LogFlowFunc(("pVBVA %p\n", pVBVA));
+
+#if 0  /* All callers check this */
     if (ppdev->bHGSMISupported)
-    {
-        VBVABUFFER *pVBVA = (VBVABUFFER *)((uint8_t *)ppdev->pjScreen + ppdev->layout.offVBVABuffer);
-
-        DISPDBG((1, "VBoxDisp::vboxVbvaEnable screen %p vbva off 0x%x\n", ppdev->pjScreen, ppdev->layout.offVBVABuffer));
+#endif
+    {
+        LogFunc(("pVBVA %p vbva off 0x%x\n", pVBVA, pCtx->offVRAMBuffer));
 
         pVBVA->hostFlags.u32HostEvents      = 0;
@@ -110,20 +112,20 @@
         pVBVA->off32Data          = 0;
         pVBVA->off32Free          = 0;
-        RtlZeroMemory (pVBVA->aRecords, sizeof (pVBVA->aRecords));
+        memset(pVBVA->aRecords, 0, sizeof (pVBVA->aRecords));
         pVBVA->indexRecordFirst   = 0;
         pVBVA->indexRecordFree    = 0;
         pVBVA->cbPartialWriteThreshold = 256;
-        pVBVA->cbData             = ppdev->layout.cbVBVABuffer - sizeof (VBVABUFFER) + sizeof (pVBVA->au8Data);
-
-        ppdev->fHwBufferOverflow = FALSE;
-        ppdev->pRecord           = NULL;
-        ppdev->pVBVA             = pVBVA;
-
-        bRc = vboxVBVAInformHost (ppdev, TRUE);
+        pVBVA->cbData             = pCtx->cbBuffer - sizeof (VBVABUFFER) + sizeof (pVBVA->au8Data);
+
+        pCtx->fHwBufferOverflow = false;
+        pCtx->pRecord    = NULL;
+        pCtx->pVBVA      = pVBVA;
+
+        bRc = vboxVBVAInformHost(pCtx, pHGSMICtx, true);
     }
 
     if (!bRc)
     {
-        vboxVbvaDisable (ppdev);
+        VBoxVBVADisable(pCtx, pHGSMICtx);
     }
 
@@ -131,61 +133,62 @@
 }
 
-void vboxVbvaDisable (PPDEV ppdev)
-{
-    DISPDBG((1, "VBoxDisp::vbvaDisable called.\n"));
-
-    ppdev->fHwBufferOverflow = FALSE;
-    ppdev->pRecord           = NULL;
-    ppdev->pVBVA             = NULL;
-
-    vboxVBVAInformHost (ppdev, FALSE);
+RTDECL(void) VBoxVBVADisable(PVBVABUFFERCONTEXT pCtx,
+                             PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx)
+{
+    LogFlowFunc(("\n"));
+
+    pCtx->fHwBufferOverflow = false;
+    pCtx->pRecord           = NULL;
+    pCtx->pVBVA             = NULL;
+
+    vboxVBVAInformHost(pCtx, pHGSMICtx, false);
 
     return;
 }
 
-BOOL vboxHwBufferBeginUpdate (PPDEV ppdev)
-{
-    BOOL bRc = FALSE;
-
-    // DISPDBG((1, "VBoxDisp::vboxHwBufferBeginUpdate called flags = 0x%08X\n",
-    //          ppdev->pVBVA? ppdev->pVBVA->u32HostEvents: -1));
-
-    if (   ppdev->pVBVA
-        && (ppdev->pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_ENABLED))
+RTDECL(bool) VBoxVBVABufferBeginUpdate(PVBVABUFFERCONTEXT pCtx,
+                                       PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx)
+{
+    bool bRc = false;
+
+    // LogFunc(("flags = 0x%08X\n", pCtx->pVBVA? pCtx->pVBVA->u32HostEvents: -1));
+
+    if (   pCtx->pVBVA
+        && (pCtx->pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_ENABLED))
     {
         uint32_t indexRecordNext;
 
-        VBVA_ASSERT (!ppdev->fHwBufferOverflow);
-        VBVA_ASSERT (ppdev->pRecord == NULL);
-
-        indexRecordNext = (ppdev->pVBVA->indexRecordFree + 1) % VBVA_MAX_RECORDS;
-
-        if (indexRecordNext == ppdev->pVBVA->indexRecordFirst)
+        Assert(!pCtx->fHwBufferOverflow);
+        Assert(pCtx->pRecord == NULL);
+
+        indexRecordNext = (pCtx->pVBVA->indexRecordFree + 1) % VBVA_MAX_RECORDS;
+
+        if (indexRecordNext == pCtx->pVBVA->indexRecordFirst)
         {
             /* All slots in the records queue are used. */
-            vboxHwBufferFlush (ppdev);
-        }
-
-        if (indexRecordNext == ppdev->pVBVA->indexRecordFirst)
+            vboxHwBufferFlush (pHGSMICtx);
+        }
+
+        if (indexRecordNext == pCtx->pVBVA->indexRecordFirst)
         {
             /* Even after flush there is no place. Fail the request. */
-            DISPDBG((1, "VBoxDisp::vboxHwBufferBeginUpdate no space in the queue of records!!! first %d, last %d\n",
-                     ppdev->pVBVA->indexRecordFirst, ppdev->pVBVA->indexRecordFree));
+            LogFunc(("no space in the queue of records!!! first %d, last %d\n",
+                     pCtx->pVBVA->indexRecordFirst, pCtx->pVBVA->indexRecordFree));
         }
         else
         {
             /* Initialize the record. */
-            VBVARECORD *pRecord = &ppdev->pVBVA->aRecords[ppdev->pVBVA->indexRecordFree];
+            VBVARECORD *pRecord = &pCtx->pVBVA->aRecords[pCtx->pVBVA->indexRecordFree];
 
             pRecord->cbRecord = VBVA_F_RECORD_PARTIAL;
 
-            ppdev->pVBVA->indexRecordFree = indexRecordNext;
-
-            // DISPDBG((1, "VBoxDisp::vboxHwBufferBeginUpdate indexRecordNext = %d\n", indexRecordNext));
+            pCtx->pVBVA->indexRecordFree = indexRecordNext;
+
+            // LogFunc(("indexRecordNext = %d\n", indexRecordNext));
 
             /* Remember which record we are using. */
-            ppdev->pRecord = pRecord;
-
-            bRc = TRUE;
+            pCtx->pRecord = pRecord;
+
+            bRc = true;
         }
     }
@@ -194,20 +197,20 @@
 }
 
-void vboxHwBufferEndUpdate (PPDEV ppdev)
+RTDECL(void) VBoxVBVABufferEndUpdate(PVBVABUFFERCONTEXT pCtx)
 {
     VBVARECORD *pRecord;
 
-    // DISPDBG((1, "VBoxDisp::vboxHwBufferEndUpdate called\n"));
-
-    VBVA_ASSERT(ppdev->pVBVA);
-
-    pRecord = ppdev->pRecord;
-    VBVA_ASSERT (pRecord && (pRecord->cbRecord & VBVA_F_RECORD_PARTIAL));
+    // LogFunc(("\n"));
+
+    Assert(pCtx->pVBVA);
+
+    pRecord = pCtx->pRecord;
+    Assert(pRecord && (pRecord->cbRecord & VBVA_F_RECORD_PARTIAL));
 
     /* Mark the record completed. */
     pRecord->cbRecord &= ~VBVA_F_RECORD_PARTIAL;
 
-    ppdev->fHwBufferOverflow = FALSE;
-    ppdev->pRecord = NULL;
+    pCtx->fHwBufferOverflow = false;
+    pCtx->pRecord = NULL;
 
     return;
@@ -224,14 +227,14 @@
 }
 
-static void vboxHwBufferFlush (PPDEV ppdev)
+static void vboxHwBufferFlush(PHGSMIGUESTCOMMANDCONTEXT pCtx)
 {
     /* Issue the flush command. */
-    void *p = HGSMIHeapAlloc (&ppdev->hgsmiDisplayHeap,
-                              sizeof (VBVAFLUSH),
-                              HGSMI_CH_VBVA,
-                              VBVA_FLUSH);
+    void *p = VBoxHGSMIBufferAlloc(pCtx,
+                                   sizeof (VBVAFLUSH),
+                                   HGSMI_CH_VBVA,
+                                   VBVA_FLUSH);
     if (!p)
     {
-        DISPDBG((0, "VBoxDISP::vboxHwBufferFlush: HGSMIHeapAlloc failed\n"));
+        LogFunc(("HGSMIHeapAlloc failed\n"));
     }
     else
@@ -241,7 +244,7 @@
         pFlush->u32Reserved = 0;
 
-        vboxHGSMIBufferSubmit (ppdev, p);
-
-        HGSMIHeapFree (&ppdev->hgsmiDisplayHeap, p);
+        VBoxHGSMIBufferSubmit(pCtx, p);
+
+        VBoxHGSMIBufferSubmit(pCtx, p);
     }
 
@@ -249,7 +252,8 @@
 }
 
-static void vboxHwBufferPlaceDataAt (PPDEV ppdev, const void *p, uint32_t cb, uint32_t offset)
-{
-    VBVABUFFER *pVBVA = ppdev->pVBVA;
+static void vboxHwBufferPlaceDataAt(PVBVABUFFERCONTEXT pCtx, const void *p,
+                                    uint32_t cb, uint32_t offset)
+{
+    VBVABUFFER *pVBVA = pCtx->pVBVA;
     uint32_t u32BytesTillBoundary = pVBVA->cbData - offset;
     uint8_t  *dst                 = &pVBVA->au8Data[offset];
@@ -271,5 +275,7 @@
 }
 
-static BOOL vboxHwBufferWrite (PPDEV ppdev, const void *p, uint32_t cb)
+static bool vboxHwBufferWrite(PVBVABUFFERCONTEXT pCtx,
+                              PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx,
+                              const void *p, uint32_t cb)
 {
     VBVARECORD *pRecord;
@@ -278,18 +284,18 @@
     uint32_t cbWritten = 0;
 
-    VBVABUFFER *pVBVA = ppdev->pVBVA;
-    VBVA_ASSERT(pVBVA);
-
-    if (!pVBVA || ppdev->fHwBufferOverflow)
-    {
-        return FALSE;
-    }
-
-    VBVA_ASSERT (pVBVA->indexRecordFirst != pVBVA->indexRecordFree);
-
-    pRecord = ppdev->pRecord;
-    VBVA_ASSERT (pRecord && (pRecord->cbRecord & VBVA_F_RECORD_PARTIAL));
-
-    DISPDBG((1, "VW %d\n", cb));
+    VBVABUFFER *pVBVA = pCtx->pVBVA;
+    Assert(pVBVA);
+
+    if (!pVBVA || pCtx->fHwBufferOverflow)
+    {
+        return false;
+    }
+
+    Assert(pVBVA->indexRecordFirst != pVBVA->indexRecordFree);
+
+    pRecord = pCtx->pRecord;
+    Assert(pRecord && (pRecord->cbRecord & VBVA_F_RECORD_PARTIAL));
+
+    LogFunc(("%d\n", cb));
 
     cbHwBufferAvail = vboxHwBufferAvail (pVBVA);
@@ -299,12 +305,12 @@
         uint32_t cbChunk = cb;
 
-        // DISPDBG((1, "VBoxDisp::vboxHwBufferWrite pVBVA->off32Free %d, pRecord->cbRecord 0x%08X, cbHwBufferAvail %d, cb %d, cbWritten %d\n",
+        // LogFunc(("pVBVA->off32Free %d, pRecord->cbRecord 0x%08X, cbHwBufferAvail %d, cb %d, cbWritten %d\n",
         //             pVBVA->off32Free, pRecord->cbRecord, cbHwBufferAvail, cb, cbWritten));
 
         if (cbChunk >= cbHwBufferAvail)
         {
-            DISPDBG((1, "VBoxDisp::vboxHwBufferWrite 1) avail %d, chunk %d\n", cbHwBufferAvail, cbChunk));
-
-            vboxHwBufferFlush (ppdev);
+            LogFunc(("1) avail %d, chunk %d\n", cbHwBufferAvail, cbChunk));
+
+            vboxHwBufferFlush (pHGSMICtx);
 
             cbHwBufferAvail = vboxHwBufferAvail (pVBVA);
@@ -312,13 +318,13 @@
             if (cbChunk >= cbHwBufferAvail)
             {
-                DISPDBG((1, "VBoxDisp::vboxHwBufferWrite: no place for %d bytes. Only %d bytes available after flush. Going to partial writes.\n",
+                LogFunc(("no place for %d bytes. Only %d bytes available after flush. Going to partial writes.\n",
                             cb, cbHwBufferAvail));
 
                 if (cbHwBufferAvail <= pVBVA->cbPartialWriteThreshold)
                 {
-                    DISPDBG((1, "VBoxDisp::vboxHwBufferWrite: Buffer overflow!!!\n"));
-                    ppdev->fHwBufferOverflow = TRUE;
-                    VBVA_ASSERT(FALSE);
-                    return FALSE;
+                    LogFunc(("Buffer overflow!!!\n"));
+                    pCtx->fHwBufferOverflow = true;
+                    Assert(false);
+                    return false;
                 }
 
@@ -327,8 +333,8 @@
         }
 
-        VBVA_ASSERT(cbChunk <= cb);
-        VBVA_ASSERT(cbChunk <= vboxHwBufferAvail (pVBVA));
-
-        vboxHwBufferPlaceDataAt (ppdev, (uint8_t *)p + cbWritten, cbChunk, pVBVA->off32Free);
+        Assert(cbChunk <= cb);
+        Assert(cbChunk <= vboxHwBufferAvail (pVBVA));
+
+        vboxHwBufferPlaceDataAt (pCtx, (uint8_t *)p + cbWritten, cbChunk, pVBVA->off32Free);
 
         pVBVA->off32Free   = (pVBVA->off32Free + cbChunk) % pVBVA->cbData;
@@ -340,5 +346,5 @@
     }
 
-    return TRUE;
+    return true;
 }
 
@@ -346,12 +352,14 @@
  * Public writer to the hardware buffer.
  */
-BOOL vboxWrite (PPDEV ppdev, const void *pv, uint32_t cb)
-{
-    return vboxHwBufferWrite (ppdev, pv, cb);
-}
-
-BOOL vboxOrderSupported (PPDEV ppdev, unsigned code)
-{
-    VBVABUFFER *pVBVA = ppdev->pVBVA;
+RTDECL(bool) VBoxVBVAWrite(PVBVABUFFERCONTEXT pCtx,
+                           PHGSMIGUESTCOMMANDCONTEXT pHGSMICtx,
+                           const void *pv, uint32_t cb)
+{
+    return vboxHwBufferWrite (pCtx, pHGSMICtx, pv, cb);
+}
+
+RTDECL(bool) VBoxVBVAOrderSupported(PVBVABUFFERCONTEXT pCtx, unsigned code)
+{
+    VBVABUFFER *pVBVA = pCtx->pVBVA;
 
     if (!pVBVA)
@@ -362,5 +370,5 @@
     if (pVBVA->hostFlags.u32SupportedOrders & (1 << code))
     {
-        return TRUE;
+        return true;
     }
 
@@ -368,35 +376,54 @@
 }
 
+RTDECL(void) VBoxHGSMIProcessDisplayInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx,
+                                         uint32_t cDisplay,
+                                         int32_t  cOriginX,
+                                         int32_t  cOriginY,
+                                         uint32_t offStart,
+                                         uint32_t cbPitch,
+                                         uint32_t cWidth,
+                                         uint32_t cHeight,
+                                         uint16_t cBPP)
+{
+    /* Issue the screen info command. */
+    void *p = VBoxHGSMIBufferAlloc(pCtx,
+                                   sizeof (VBVAINFOSCREEN),
+                                   HGSMI_CH_VBVA,
+                                   VBVA_INFO_SCREEN);
+    if (!p)
+    {
+        LogFunc(("HGSMIHeapAlloc failed\n"));
+    }
+    else
+    {
+        VBVAINFOSCREEN *pScreen = (VBVAINFOSCREEN *)p;
+
+        pScreen->u32ViewIndex    = cDisplay;
+        pScreen->i32OriginX      = cOriginX;
+        pScreen->i32OriginY      = cOriginY;
+        pScreen->u32StartOffset  = offStart;
+        pScreen->u32LineSize     = cbPitch;
+        pScreen->u32Width        = cWidth;
+        pScreen->u32Height       = cHeight;
+        pScreen->u16BitsPerPixel = cBPP;
+        pScreen->u16Flags        = VBVA_SCREEN_F_ACTIVE;
+
+        VBoxHGSMIBufferSubmit(pCtx, p);
+
+        VBoxHGSMIBufferFree(pCtx, p);
+    }
+}
+
 void VBoxProcessDisplayInfo (PPDEV ppdev)
 {
     if (ppdev->bHGSMISupported)
     {
-        /* Issue the screen info command. */
-        void *p = HGSMIHeapAlloc (&ppdev->hgsmiDisplayHeap,
-                                  sizeof (VBVAINFOSCREEN),
-                                  HGSMI_CH_VBVA,
-                                  VBVA_INFO_SCREEN);
-        if (!p)
-        {
-            DISPDBG((0, "VBoxDISP::VBoxProcessDisplayInfo: HGSMIHeapAlloc failed\n"));
-        }
-        else
-        {
-            VBVAINFOSCREEN *pScreen = (VBVAINFOSCREEN *)p;
-
-            pScreen->u32ViewIndex    = ppdev->iDevice;
-            pScreen->i32OriginX      = ppdev->ptlDevOrg.x;
-            pScreen->i32OriginY      = ppdev->ptlDevOrg.y;
-            pScreen->u32StartOffset  = 0;
-            pScreen->u32LineSize     = ppdev->lDeltaScreen > 0?ppdev->lDeltaScreen: -ppdev->lDeltaScreen;
-            pScreen->u32Width        = ppdev->cxScreen;
-            pScreen->u32Height       = ppdev->cyScreen;
-            pScreen->u16BitsPerPixel = (uint16_t)ppdev->ulBitCount;
-            pScreen->u16Flags        = VBVA_SCREEN_F_ACTIVE;
-
-            vboxHGSMIBufferSubmit (ppdev, p);
-
-            HGSMIHeapFree (&ppdev->hgsmiDisplayHeap, p);
-        }
+        VBoxHGSMIProcessDisplayInfo(&ppdev->guestCtx, ppdev->iDevice,
+                                     ppdev->ptlDevOrg.x, ppdev->ptlDevOrg.y, 0,
+                                       ppdev->lDeltaScreen > 0
+                                     ? ppdev->lDeltaScreen
+                                     : -ppdev->lDeltaScreen, ppdev->cxScreen,
+                                     ppdev->cyScreen,
+                                     (uint16_t)ppdev->ulBitCount);
     }
 
@@ -408,5 +435,5 @@
 VBOXVHWACMD* vboxVHWACommandCreate (PPDEV ppdev, VBOXVHWACMD_TYPE enmCmd, VBOXVHWACMD_LENGTH cbCmd)
 {
-    VBOXVHWACMD* pHdr = (VBOXVHWACMD*)HGSMIHeapAlloc (&ppdev->hgsmiDisplayHeap,
+    VBOXVHWACMD* pHdr = (VBOXVHWACMD*)VBoxHGSMIBufferAlloc(&ppdev->guestCtx,
                               cbCmd + VBOXVHWACMD_HEADSIZE(),
                               HGSMI_CH_VBVA,
@@ -414,5 +441,5 @@
     if (!pHdr)
     {
-        DISPDBG((0, "VBoxDISP::vboxVHWACommandCreate: HGSMIHeapAlloc failed\n"));
+        LogFunc(("HGSMIHeapAlloc failed\n"));
     }
     else
@@ -433,5 +460,5 @@
 void vboxVHWACommandFree (PPDEV ppdev, VBOXVHWACMD* pCmd)
 {
-    HGSMIHeapFree (&ppdev->hgsmiDisplayHeap, pCmd);
+    VBoxHGSMIBufferFree(&ppdev->guestCtx, pCmd);
 }
 
@@ -446,5 +473,5 @@
 {
     VBVAHOSTCMDVHWACMDCOMPLETE * pComplete = VBVAHOSTCMD_BODY(pHostCmd, VBVAHOSTCMDVHWACMDCOMPLETE);
-    VBOXVHWACMD* pComplCmd = (VBOXVHWACMD*)HGSMIOffsetToPointer (&ppdev->hgsmiDisplayHeap.area, pComplete->offCmd);
+    VBOXVHWACMD* pComplCmd = (VBOXVHWACMD*)HGSMIOffsetToPointer (&ppdev->guestCtx.heapCtx.area, pComplete->offCmd);
     PFNVBOXVHWACMDCOMPLETION pfnCompletion = (PFNVBOXVHWACMDCOMPLETION)pComplCmd->GuestVBVAReserved1;
     void * pContext = (void *)pComplCmd->GuestVBVAReserved2;
@@ -502,5 +529,5 @@
     /* complete it asynchronously by setting event */
     pCmd->Flags |= VBOXVHWACMD_FLAG_GH_ASYNCH_EVENT;
-    vboxHGSMIBufferSubmit (ppdev, pCmd);
+    VBoxHGSMIBufferSubmit(&ppdev->guestCtx, pCmd);
 
     if(!(ASMAtomicReadU32((volatile uint32_t *)&pCmd->Flags)  & VBOXVHWACMD_FLAG_HG_ASYNCH))
@@ -543,5 +570,5 @@
     vbvaVHWACommandRetain(ppdev, pCmd);
 
-    vboxHGSMIBufferSubmit (ppdev, pCmd);
+    VBoxHGSMIBufferSubmit(&ppdev->guestCtx, pCmd);
 
     if(!(pCmd->Flags & VBOXVHWACMD_FLAG_HG_ASYNCH))
@@ -568,5 +595,5 @@
     pCmd->Flags |= VBOXVHWACMD_FLAG_GH_ASYNCH_NOCOMPLETION;
 
-    vboxHGSMIBufferSubmit (ppdev, pCmd);
+    VBoxHGSMIBufferSubmit(&ppdev->guestCtx, pCmd);
 
     if(!(pCmd->Flags & VBOXVHWACMD_FLAG_HG_ASYNCH)
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/vbva.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/vbva.c	(revision 34406)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/vbva.c	(revision 34438)
@@ -351,5 +351,5 @@
         hdr.h = (uint16_t)(rect.bottom - rect.top);
 
-        vboxWrite (ppdev, &hdr, sizeof(hdr));
+        VBoxVBVAWrite(&ppdev->vbvaCtx, &ppdev->guestCtx, &hdr, sizeof(hdr));
     }
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/vrdp.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/vrdp.c	(revision 34406)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/vrdp.c	(revision 34438)
@@ -365,5 +365,5 @@
 __inline BOOL vrdpWriteHdr (PPDEV ppdev, uint32_t u32Op)
 {
-    return vboxWrite (ppdev, &u32Op, sizeof (u32Op));
+    return VBoxVBVAWrite(&ppdev->vbvaCtx, &ppdev->guestCtx, &u32Op, sizeof (u32Op));
 }
 
@@ -381,5 +381,5 @@
     bits.cbPixel = (uint8_t)bytesPerPixel;
 
-    bRc = vboxWrite (ppdev, &bits, sizeof (bits));
+    bRc = VBoxVBVAWrite(&ppdev->vbvaCtx, &ppdev->guestCtx, &bits, sizeof (bits));
 
     if (bRc)
@@ -387,5 +387,5 @@
         while (cHeight--)
         {
-            bRc = vboxWrite (ppdev, pu8Bits, cWidth * bytesPerPixel);
+            bRc = VBoxVBVAWrite(&ppdev->vbvaCtx, &ppdev->guestCtx, pu8Bits, cWidth * bytesPerPixel);
 
             if (!bRc)
@@ -503,5 +503,5 @@
     if (bRc)
     {
-        vboxWrite (ppdev, pOrder, cbOrder);
+        VBoxVBVAWrite(&ppdev->vbvaCtx, &ppdev->guestCtx, pOrder, cbOrder);
     }
 
@@ -1434,5 +1434,5 @@
     else if (ppo->fl & PO_ELLIPSE)
     {
-        if (vboxOrderSupported (ppdev, VRDE_ORDER_ELLIPSE))
+        if (VBoxVBVAOrderSupported (&ppdev->vbvaCtx, VRDE_ORDER_ELLIPSE))
         {
             VRDEORDERELLIPSE order;
