Index: trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp
===================================================================
--- trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp	(revision 55493)
+++ trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp	(revision 55560)
@@ -1316,5 +1316,5 @@
             if(RT_SUCCESS(rc))
             {
-                rc = HGSMIHostCommandProcessAndFreeAsynch(pIns, pHostCmd, (pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_IRQ) != 0);
+                rc = HGSMIHostCommandSubmitAndFreeAsynch(pIns, pHostCmd, RT_BOOL(pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_IRQ));
                 AssertRC(rc);
                 if(RT_SUCCESS(rc))
Index: trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp
===================================================================
--- trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp	(revision 55493)
+++ trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp	(revision 55560)
@@ -199,22 +199,8 @@
     HGSMIINSTANCE *pIns;               /* Backlink to the HGSMI instance. */
 
-#if 0
-    /* removed to allow saved state handling */
-    /* The event which is signalled when the command has been processed by the host. */
-    RTSEMEVENTMULTI hEvent;
-#endif
-
     volatile uint32_t fl;              /* Status flags of the entry. */
 
     HGSMIOFFSET offBuffer;             /* Offset of the HGSMI buffer header in the HGSMI host heap:
                                         * [pIns->hostHeap.area.offBase .. offLast]. */
-
-#if 0
-    /* removed to allow saved state handling */
-    /* The command completion callback. */
-    PFNHGSMIHOSTFIFOCALLBACK pfnCallback;
-    void *pvCallback;
-#endif
-
 } HGSMIHOSTFIFOENTRY;
 
@@ -399,13 +385,7 @@
 
             hgsmiFIFOUnlock(pIns);
-#if 0
-            /* Inform the submitter. */
-            if (pEntry->pfnCallback)
-            {
-                pEntry->pfnCallback (pEntry->pvCallback);
-            }
-#else
+
             hgsmiHostCommandFreeCallback(pEntry);
-#endif
+
             return true;
         }
@@ -501,19 +481,4 @@
     ASMAtomicAndU32(&pIns->pHGFlags->u32HostFlags, (~flags));
 }
-
-#if 0
-static void hgsmiRaiseEvent (const HGSMIHOSTFIFOENTRY *pEntry)
-{
-    int rc = RTSemEventMultiSignal (pEntry->hEvent);
-    AssertRC(rc);
-}
-
-static int hgsmiWaitEvent (const HGSMIHOSTFIFOENTRY *pEntry)
-{
-    int rc = RTSemEventMultiWait (pEntry->hEvent, RT_INDEFINITE_WAIT);
-    AssertRC(rc);
-    return rc;
-}
-#endif
 
 /*
@@ -723,12 +688,4 @@
     {
         pEntry->fl = HGSMI_F_HOST_FIFO_ALLOCATED;
-#if 0
-        rc = RTSemEventMultiCreate (&pEntry->hEvent);
-
-        if (RT_FAILURE (rc))
-        {
-            RTMemFree (pEntry);
-        }
-#endif
     }
     else
@@ -748,10 +705,4 @@
 {
     NOREF (pIns);
-#if 0
-    if (pEntry->hEvent)
-    {
-        RTSemEventMultiDestroy (pEntry->hEvent);
-    }
-#endif
     RTMemFree (pEntry);
 }
@@ -786,69 +737,58 @@
 }
 
-static int hgsmiHostCommandFree (HGSMIINSTANCE *pIns,
-                                                void *pvData)
-{
-    int rc = VINF_SUCCESS;
-    if (HGSMIAreaContainsPointer(&pIns->hostHeap.area, pvData))
-    {
-        HGSMIHOSTFIFOENTRY *pEntry = NULL;
-        HGSMIOFFSET offBuffer = HGSMIBufferOffsetFromData(&pIns->hostHeap.area, pvData);
-
-        rc = hgsmiFIFOLock (pIns);
-        if(RT_SUCCESS(rc))
-        {
-            /* Search the Processed list for the given offBuffer. */
-            HGSMIHOSTFIFOENTRY *pIter;
-            RTListForEach(&pIns->hostFIFOProcessed, pIter, HGSMIHOSTFIFOENTRY, nodeEntry)
-            {
-                Assert(pIter->fl == (HGSMI_F_HOST_FIFO_ALLOCATED | HGSMI_F_HOST_FIFO_PROCESSED));
-
-                if (pIter->offBuffer == offBuffer)
-                {
-                    pEntry = pIter;
-                    break;
-                }
+static int hgsmiHostCommandFree(HGSMIINSTANCE *pIns,
+                                void *pvData)
+{
+    HGSMIOFFSET offBuffer = HGSMIBufferOffsetFromData(&pIns->hostHeap.area, pvData);
+    HGSMIHOSTFIFOENTRY *pEntry = NULL;
+
+    int rc = hgsmiFIFOLock(pIns);
+    if (RT_SUCCESS(rc))
+    {
+        /* Search the Processed list for the given offBuffer. */
+        HGSMIHOSTFIFOENTRY *pIter;
+        RTListForEach(&pIns->hostFIFOProcessed, pIter, HGSMIHOSTFIFOENTRY, nodeEntry)
+        {
+            Assert(pIter->fl == (HGSMI_F_HOST_FIFO_ALLOCATED | HGSMI_F_HOST_FIFO_PROCESSED));
+
+            if (pIter->offBuffer == offBuffer)
+            {
+                pEntry = pIter;
+                break;
             }
-
-            if (pEntry)
-            {
-                RTListNodeRemove(&pEntry->nodeEntry);
-            }
-            else
-            {
-                AssertLogRelMsgFailed(("HGSMI[%s]: the host frees unprocessed FIFO entry: 0x%08X\n",
-                                       pIns->pszName, offBuffer));
-            }
-
-            hgsmiFIFOUnlock (pIns);
-
-            rc = hgsmiHostHeapLock (pIns);
-            if(RT_SUCCESS(rc))
-            {
-                /* Deallocate the host heap memory. */
-                hgsmiHostHeapDataFree(&pIns->hostHeap, pvData);
-
-                hgsmiHostHeapUnlock(pIns);
-            }
-
-            if(pEntry)
-            {
-                /* Deallocate the entry. */
-                hgsmiHostFIFOFree (pIns, pEntry);
-            }
-        }
-
-    }
-    else
-    {
-        AssertLogRelMsgFailed(("HGSMI[%s]: the host frees invalid FIFO entry: %p\n",
-                               pIns->pszName, pvData));
-        rc = VERR_INVALID_POINTER;
-    }
-    return rc;
-}
-
-#if 0
-static DECLCALLBACK(void) hgsmiHostCommandRaiseEventCallback (void *pvCallback)
+        }
+
+        if (pEntry)
+        {
+            RTListNodeRemove(&pEntry->nodeEntry);
+        }
+        else
+        {
+            AssertLogRelMsgFailed(("HGSMI[%s]: the host frees unprocessed FIFO entry: 0x%08X\n",
+                                   pIns->pszName, offBuffer));
+        }
+
+        hgsmiFIFOUnlock (pIns);
+
+        rc = hgsmiHostHeapLock (pIns);
+        if (RT_SUCCESS(rc))
+        {
+            /* Deallocate the host heap memory. */
+            hgsmiHostHeapDataFree(&pIns->hostHeap, pvData);
+
+            hgsmiHostHeapUnlock(pIns);
+        }
+
+        if (pEntry)
+        {
+            /* Deallocate the entry. */
+            hgsmiHostFIFOFree(pIns, pEntry);
+        }
+    }
+
+    return rc;
+}
+
+static DECLCALLBACK(void) hgsmiHostCommandFreeCallback (void *pvCallback)
 {
     /* Guest has processed the command. */
@@ -858,31 +798,16 @@
 
     /* This is a simple callback, just signal the event. */
-    hgsmiRaiseEvent (pEntry);
-}
-#endif
-
-static DECLCALLBACK(void) hgsmiHostCommandFreeCallback (void *pvCallback)
-{
-    /* Guest has processed the command. */
-    HGSMIHOSTFIFOENTRY *pEntry = (HGSMIHOSTFIFOENTRY *)pvCallback;
-
-    Assert(pEntry->fl == (HGSMI_F_HOST_FIFO_ALLOCATED | HGSMI_F_HOST_FIFO_PROCESSED));
-
-    /* This is a simple callback, just signal the event. */
     hgsmiHostCommandFreeByEntry (pEntry);
 }
 
-static int hgsmiHostCommandWrite (HGSMIINSTANCE *pIns, HGSMIOFFSET offMem
-#if 0
-        , PFNHGSMIHOSTFIFOCALLBACK pfnCallback, void **ppvContext
-#endif
-        )
-{
+static int hgsmiHostCommandWrite(HGSMIINSTANCE *pIns,
+                                 HGSMIOFFSET offBuffer)
+{
+    AssertPtrReturn(pIns->pHGFlags, VERR_WRONG_ORDER);
+
     HGSMIHOSTFIFOENTRY *pEntry;
-
-    AssertPtrReturn(pIns->pHGFlags, VERR_WRONG_ORDER);
-    int rc = hgsmiHostFIFOAlloc (pIns, &pEntry);
-
-    if (RT_SUCCESS (rc))
+    int rc = hgsmiHostFIFOAlloc(pIns, &pEntry);
+
+    if (RT_SUCCESS(rc))
     {
         /* Initialize the new entry and add it to the FIFO. */
@@ -890,20 +815,13 @@
 
         pEntry->pIns = pIns;
-        pEntry->offBuffer = offMem;
-#if 0
-        pEntry->pfnCallback = pfnCallback;
-        pEntry->pvCallback = pEntry;
-#endif
+        pEntry->offBuffer = offBuffer;
 
         rc = hgsmiFIFOLock(pIns);
-        if (RT_SUCCESS (rc))
-        {
+        if (RT_SUCCESS(rc))
+        {
+            ASMAtomicOrU32(&pIns->pHGFlags->u32HostFlags, HGSMIHOSTFLAGS_COMMANDS_PENDING);
             RTListAppend(&pIns->hostFIFO, &pEntry->nodeEntry);
-            ASMAtomicOrU32(&pIns->pHGFlags->u32HostFlags, HGSMIHOSTFLAGS_COMMANDS_PENDING);
 
             hgsmiFIFOUnlock(pIns);
-#if 0
-            *ppvContext = pEntry;
-#endif
         }
         else
@@ -920,65 +838,30 @@
  * Append the shared memory block to the FIFO, inform the guest.
  *
- * @param pIns       Pointer to HGSMI instance,
- * @param pv         The HC memory pointer to the information.
- * @param ppvContext Where to store a pointer, which will allow the caller
- *                   to wait for the command completion.
- * @param            bDoIrq specifies whether the guest interrupt should be generated,
- * i.e. in case the command is not urgent(e.g. some guest command completion notification that does not require post-processing)
- * the command could be posted without raising an irq.
- *
+ * @param pIns       Pointer to HGSMI instance.
+ * @param pvData     The shared memory block data pointer.
+ * @param fDoIrq     Whether the guest interrupt should be generated, i.e. if the command is not
+ *                   urgent (e.g. some guest command completion notification that does not require
+ *                   post-processing) the command could be submitted without raising an irq.
  * @thread EMT
  */
-static int hgsmiHostCommandProcess (HGSMIINSTANCE *pIns, HGSMIOFFSET offBuffer,
-#if 0
-        PFNHGSMIHOSTFIFOCALLBACK pfnCallback, void **ppvContext,
-#endif
-        bool bDoIrq)
-{
-//    HGSMIOFFSET offMem;
-//
-//    int rc = hgsmiCheckMemPtr (pIns, pvMem, &offMem);
-//
-//    if (RT_SUCCESS (rc))
-//    {
-        /* Append the command to FIFO. */
-        int rc = hgsmiHostCommandWrite (pIns, offBuffer
-#if 0
-                , pfnCallback, ppvContext
-#endif
-                );
-
-        if (RT_SUCCESS (rc))
-        {
-            if(bDoIrq)
-            {
-                /* Now guest can read the FIFO, the notification is informational. */
-                hgsmiNotifyGuest (pIns);
-            }
-        }
-//    }
-//    else
-//    {
-//        AssertFailed ();
-//    }
-
-    return rc;
-}
-#if 0
-static void hgsmiWait (void *pvContext)
-{
-    HGSMIHOSTFIFOENTRY *pEntry = (HGSMIHOSTFIFOENTRY *)pvContext;
-
-    for (;;)
-    {
-        hgsmiWaitEvent (pEntry);
-
-        if (pEntry->fl & (HGSMI_F_HOST_FIFO_PROCESSED | HGSMI_F_HOST_FIFO_CANCELED))
-        {
-            return;
-        }
-    }
-}
-#endif
+static int hgsmiHostCommandSubmit(HGSMIINSTANCE *pIns,
+                                  void *pvData,
+                                  bool fDoIrq)
+{
+    /* Append the command to FIFO. */
+    HGSMIOFFSET offBuffer = HGSMIBufferOffsetFromData(&pIns->hostHeap.area, pvData);
+    int rc = hgsmiHostCommandWrite(pIns, offBuffer);
+    if (RT_SUCCESS(rc))
+    {
+        if (fDoIrq)
+        {
+            /* Now guest can read the FIFO, the notification is informational. */
+            hgsmiNotifyGuest(pIns);
+        }
+    }
+
+    return rc;
+}
+
 /**
  * Allocate a shared memory buffer. The host can write command/data to the memory.
@@ -993,14 +876,15 @@
  * @param u16ChannelInfo Command parameter.
  */
-int HGSMIHostCommandAlloc (HGSMIINSTANCE *pIns,
-                           void **ppvData,
-                           HGSMISIZE cbData,
-                           uint8_t u8Channel,
-                           uint16_t u16ChannelInfo)
-{
-    LogFlowFunc (("pIns = %p, cbData = 0x%08X(%d)\n", pIns, cbData, cbData));
-
-    int rc = hgsmiHostHeapLock (pIns);
-    if(RT_SUCCESS(rc))
+int HGSMIHostCommandAlloc(HGSMIINSTANCE *pIns,
+                          void **ppvData,
+                          HGSMISIZE cbData,
+                          uint8_t u8Channel,
+                          uint16_t u16ChannelInfo)
+{
+    LogFlowFunc(("pIns = %p, cbData = %d, u8Channel %d, u16ChannelInfo 0x%04X\n",
+                 pIns, cbData, u8Channel, u16ChannelInfo));
+
+    int rc = hgsmiHostHeapLock(pIns);
+    if (RT_SUCCESS(rc))
     {
         void *pvData = hgsmiHostHeapDataAlloc(&pIns->hostHeap,
@@ -1016,5 +900,5 @@
         else
         {
-            LogRel(("HGSMI[%s]: host heap allocation failed %dbytes\n", pIns->pszName, cbData));
+            LogRel(("HGSMI[%s]: host heap allocation failed %d bytes\n", pIns->pszName, cbData));
             rc = VERR_NO_MEMORY;
         }
@@ -1033,86 +917,56 @@
  * @param pIns   HGSMI instance,
  * @param pvData The pointer returned by 'HGSMIHostCommandAlloc'.
- * @param bDoIrq Specifies whether the guest interrupt should be generated.
+ * @param fDoIrq Specifies whether the guest interrupt should be generated.
  *               In case the command is not urgent (e.g. some guest command
  *               completion notification that does not require post-processing)
  *               the command could be posted without raising an irq.
  */
-int HGSMIHostCommandProcessAndFreeAsynch (PHGSMIINSTANCE pIns,
-                             void *pvData,
-                             bool bDoIrq)
-{
-    LogFlowFunc(("pIns = %p, pvData = %p\n", pIns, pvData));
-
-#if 0
-    void *pvContext = NULL;
-#endif
-
-    HGSMIOFFSET offBuffer = HGSMIBufferOffsetFromData(&pIns->hostHeap.area, pvData);
-
-    int rc = hgsmiHostCommandProcess (pIns, offBuffer,
-#if 0
-            hgsmiHostCommandFreeCallback, &pvContext,
-#endif
-            bDoIrq);
-    AssertRC (rc);
+int HGSMIHostCommandSubmitAndFreeAsynch(PHGSMIINSTANCE pIns,
+                                        void *pvData,
+                                        bool fDoIrq)
+{
+    LogFlowFunc(("pIns = %p, pvData = %p, fDoIrq = %d\n", pIns, pvData, fDoIrq));
+
+    int rc;
+    if (HGSMIAreaContainsPointer(&pIns->hostHeap.area, pvData))
+    {
+        rc = hgsmiHostCommandSubmit(pIns, pvData, fDoIrq);
+    }
+    else
+    {
+        AssertLogRelMsgFailed(("HGSMI[%s]: host submits invalid command %p/%p\n",
+                               pIns->pszName, pvData, pIns->hostHeap.area.pu8Base));
+        rc = VERR_INVALID_POINTER;
+    }
 
     LogFlowFunc(("rc = %Rrc\n", rc));
-
-    return rc;
-}
-#if 0
-/**
- * Submit the shared memory block to the guest.
- *
- * @param pIns  Pointer to HGSMI instance,
- * @param pvMem The pointer returned by 'HGSMIHostCommandAlloc'.
- */
-int HGSMIHostCommandProcess (HGSMIINSTANCE *pIns,
-                             void *pvMem)
-{
-    LogFlowFunc(("pIns = %p, pvMem = %p\n", pIns, pvMem));
-
-    VM_ASSERT_OTHER_THREAD(pIns->pVM);
-
-    void *pvContext = NULL;
-
-    HGSMIOFFSET offBuffer = HGSMIHeapBufferOffset (&pIns->hostHeap, pvMem);
-
-//    /* Have to forward to EMT because FIFO processing is there. */
-//    int rc = VMR3ReqCallVoid (pIns->pVM, &pReq, RT_INDEFINITE_WAIT,
-//                              (PFNRT) hgsmiHostCommandProcess,
-//                              3, pIns, offBuffer, &pvContext);
-
-    int rc = hgsmiHostCommandProcess (pIns, offBuffer,
-#if 0
-            hgsmiHostCommandRaiseEventCallback, &pvContext,
-#endif
-            true);
-    AssertReleaseRC (rc);
-
-    if (RT_SUCCESS (rc))
-    {
-        /* Wait for completion. */
-        hgsmiWait (pvContext);
-    }
-
-    LogFlowFunc(("rc = %Rrc\n", rc));
-
-    return rc;
-}
-#endif
+    return rc;
+}
 
 /**
  * Free the shared memory block.
  *
- * @param pIns  Pointer to HGSMI instance,
- * @param pvMem The pointer returned by 'HGSMIHostCommandAlloc'.
+ * @param pIns   Pointer to HGSMI instance,
+ * @param pvData The pointer returned by 'HGSMIHostCommandAlloc'.
  */
-int HGSMIHostCommandFree (HGSMIINSTANCE *pIns,
-                          void *pvMem)
-{
-    LogFlowFunc(("pIns = %p, pvMem = %p\n", pIns, pvMem));
-
-    return hgsmiHostCommandFree (pIns, pvMem);
+int HGSMIHostCommandFree(HGSMIINSTANCE *pIns,
+                         void *pvData)
+{
+    LogFlowFunc(("pIns = %p, pvData = %p\n", pIns, pvData));
+
+    int rc;
+    if (HGSMIAreaContainsPointer(&pIns->hostHeap.area, pvData))
+    {
+        rc = hgsmiHostCommandFree(pIns, pvData);
+    }
+    else
+    {
+        AssertLogRelMsgFailed(("HGSMI[%s]: the host frees invalid FIFO entry %p/%p\n",
+                               pIns->pszName, pvData, pIns->hostHeap.area.pu8Base));
+        rc = VERR_INVALID_POINTER;
+    }
+
+    LogFlowFunc(("rc = %Rrc\n", rc));
+    return rc;
 }
 
Index: trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.h
===================================================================
--- trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.h	(revision 55493)
+++ trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.h	(revision 55560)
@@ -73,7 +73,4 @@
                        HGSMISIZE      cbHeap);
 
-int HGSMISaveStateExec (PHGSMIINSTANCE pIns, PSSMHANDLE pSSM);
-int HGSMILoadStateExec (PHGSMIINSTANCE pIns, PSSMHANDLE pSSM);
-
 /*
  * Virtual hardware IO handlers.
@@ -106,19 +103,16 @@
 
 /* Allocate a buffer in the host heap. */
-int HGSMIHostCommandAlloc (PHGSMIINSTANCE pIns,
-                           void **ppvData,
-                           HGSMISIZE cbData,
-                           uint8_t u8Channel,
-                           uint16_t u16ChannelInfo);
+int HGSMIHostCommandAlloc(PHGSMIINSTANCE pIns,
+                          void **ppvData,
+                          HGSMISIZE cbData,
+                          uint8_t u8Channel,
+                          uint16_t u16ChannelInfo);
 
-int HGSMIHostCommandProcess (PHGSMIINSTANCE pIns,
-                             void *pvMem);
+int HGSMIHostCommandSubmitAndFreeAsynch(PHGSMIINSTANCE pIns,
+                                        void *pvData,
+                                        bool fDoIrq);
 
-int HGSMIHostCommandProcessAndFreeAsynch (PHGSMIINSTANCE pIns,
-                             void *pvData,
-                             bool bDoIrq);
-
-int HGSMIHostCommandFree (PHGSMIINSTANCE pIns,
-                          void *pvMem);
+int HGSMIHostCommandFree(PHGSMIINSTANCE pIns,
+                         void *pvData);
 
 int HGSMIHostLoadStateExec (PHGSMIINSTANCE pIns, PSSMHANDLE pSSM, uint32_t u32Version);
