Index: /trunk/src/VBox/Devices/Bus/DevIommuAmd.cpp
===================================================================
--- /trunk/src/VBox/Devices/Bus/DevIommuAmd.cpp	(revision 87827)
+++ /trunk/src/VBox/Devices/Bus/DevIommuAmd.cpp	(revision 87828)
@@ -347,17 +347,8 @@
     uint32_t                    u32Magic;
 
-    /** Whether the command thread is sleeping. */
-    bool volatile               fCmdThreadSleeping;
-    /** Alignment padding. */
-    uint8_t                     afPadding0[3];
-    /** Whether the command thread has been signaled for wake up. */
-    bool volatile               fCmdThreadSignaled;
-    /** Alignment padding. */
-    uint8_t                     afPadding1[3];
-
+    /** The MMIO handle. */
+    IOMMMIOHANDLE               hMmio;
     /** The event semaphore the command thread waits on. */
     SUPSEMEVENT                 hEvtCmdThread;
-    /** The MMIO handle. */
-    IOMMMIOHANDLE               hMmio;
 
 #ifdef IOMMU_WITH_DTE_CACHE
@@ -546,12 +537,10 @@
 } IOMMU;
 /** Pointer to the IOMMU device state. */
-typedef struct IOMMU *PIOMMU;
+typedef IOMMU *PIOMMU;
 /** Pointer to the const IOMMU device state. */
-typedef const struct IOMMU *PCIOMMU;
-AssertCompileMemberAlignment(IOMMU, fCmdThreadSleeping, 4);
-AssertCompileMemberAlignment(IOMMU, fCmdThreadSignaled, 4);
-AssertCompileMemberAlignment(IOMMU, hEvtCmdThread, 8);
+typedef const IOMMU *PCIOMMU;
 AssertCompileMemberAlignment(IOMMU, hMmio, 8);
 #ifdef IOMMU_WITH_DTE_CACHE
+AssertCompileMemberAlignment(IOMMU, CritSectCache, 8);
 AssertCompileMemberAlignment(IOMMU, aDeviceIds, 8);
 AssertCompileMemberAlignment(IOMMU, aDteCache, 8);
@@ -576,4 +565,10 @@
     /** The command thread handle. */
     R3PTRTYPE(PPDMTHREAD)       pCmdThread;
+    /** Whether the command thread is sleeping. */
+    bool volatile               fCmdThreadSleeping;
+    /** Whether the command thread has been signaled for wake up. */
+    bool volatile               fCmdThreadSignaled;
+    /** Alignment padding. */
+    uint8_t                     afPadding0[6];
 #ifdef IOMMU_WITH_IOTLBE_CACHE
     /** Pointer to array of pre-allocated IOTLBEs. */
@@ -591,4 +586,6 @@
 /** Pointer to the ring-3 IOMMU device state. */
 typedef IOMMUR3 *PIOMMUR3;
+/** Pointer to the const ring-3 IOMMU device state. */
+typedef const IOMMUR3 *PCIOMMUR3;
 #ifdef IOMMU_WITH_IOTLBE_CACHE
 AssertCompileMemberAlignment(IOMMUR3, paIotlbes, 8);
@@ -1673,5 +1670,5 @@
     Log4Func(("\n"));
 
-    PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
+    PCIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
     if (pThis->Status.n.u1CmdBufRunning)
     {
@@ -5001,5 +4998,5 @@
 {
     PIOMMU   pThis   = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
-    PIOMMUCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUCC);
+    PIOMMUCC pThisR3 = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUCC);
 
     if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
@@ -5021,9 +5018,9 @@
          */
         {
-            ASMAtomicWriteBool(&pThis->fCmdThreadSleeping, true);
-            bool fSignaled = ASMAtomicXchgBool(&pThis->fCmdThreadSignaled, false);
+            ASMAtomicWriteBool(&pThisR3->fCmdThreadSleeping, true);
+            bool fSignaled = ASMAtomicXchgBool(&pThisR3->fCmdThreadSignaled, false);
             if (!fSignaled)
             {
-                Assert(ASMAtomicReadBool(&pThis->fCmdThreadSleeping));
+                Assert(ASMAtomicReadBool(&pThisR3->fCmdThreadSleeping));
                 int rc = PDMDevHlpSUPSemEventWaitNoResume(pDevIns, pThis->hEvtCmdThread, RT_INDEFINITE_WAIT);
                 AssertLogRelMsgReturn(RT_SUCCESS(rc) || rc == VERR_INTERRUPTED, ("%Rrc\n", rc), rc);
@@ -5031,7 +5028,7 @@
                     break;
                 Log4Func(("Woken up with rc=%Rrc\n", rc));
-                ASMAtomicWriteBool(&pThis->fCmdThreadSignaled, false);
+                ASMAtomicWriteBool(&pThisR3->fCmdThreadSignaled, false);
             }
-            ASMAtomicWriteBool(&pThis->fCmdThreadSleeping, false);
+            ASMAtomicWriteBool(&pThisR3->fCmdThreadSleeping, false);
         }
 
@@ -5043,5 +5040,5 @@
          *        save on host memory a bit, we could (once PGM has the necessary APIs)
          *        lock the page mappings page mappings and access them directly. */
-        IOMMU_LOCK(pDevIns, pThisCC);
+        IOMMU_LOCK(pDevIns, pThisR3);
 
         if (pThis->Status.n.u1CmdBufRunning)
@@ -5062,7 +5059,7 @@
                 RTGCPHYS const GCPhysCmdBufBase = pThis->CmdBufBaseAddr.n.u40Base << X86_PAGE_4K_SHIFT;
 
-                IOMMU_UNLOCK(pDevIns, pThisCC);
+                IOMMU_UNLOCK(pDevIns, pThisR3);
                 int rc = PDMDevHlpPCIPhysRead(pDevIns, GCPhysCmdBufBase, pvCmds, cbCmdBuf);
-                IOMMU_LOCK(pDevIns, pThisCC);
+                IOMMU_LOCK(pDevIns, pThisR3);
 
                 if (RT_SUCCESS(rc))
@@ -5072,5 +5069,5 @@
 
                     /* Allow IOMMU to do other work while we process commands. */
-                    IOMMU_UNLOCK(pDevIns, pThisCC);
+                    IOMMU_UNLOCK(pDevIns, pThisR3);
 
                     /* Process the fetched commands. */
@@ -5108,12 +5105,12 @@
                     iommuAmdCmdHwErrorEventRaise(pDevIns, &EvtCmdHwErr);
 
-                    IOMMU_UNLOCK(pDevIns, pThisCC);
+                    IOMMU_UNLOCK(pDevIns, pThisR3);
                 }
             }
             else
-                IOMMU_UNLOCK(pDevIns, pThisCC);
+                IOMMU_UNLOCK(pDevIns, pThisR3);
         }
         else
-            IOMMU_UNLOCK(pDevIns, pThisCC);
+            IOMMU_UNLOCK(pDevIns, pThisR3);
     }
 
@@ -5135,5 +5132,5 @@
     RT_NOREF(pThread);
     LogFlowFunc(("\n"));
-    PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
+    PCIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
     return PDMDevHlpSUPSemEventSignal(pDevIns, pThis->hEvtCmdThread);
 }
@@ -6263,9 +6260,9 @@
 {
     PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
-    PIOMMU   pThis  = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
-    PIOMMUCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUCC);
+    PIOMMU   pThis   = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
+    PIOMMUCC pThisR3 = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUCC);
     LogFlowFunc(("\n"));
 
-    IOMMU_LOCK_NORET(pDevIns, pThisCC);
+    IOMMU_LOCK_NORET(pDevIns, pThisR3);
 
     /* Close the command thread semaphore. */
@@ -6278,13 +6275,13 @@
 #ifdef IOMMU_WITH_IOTLBE_CACHE
     /* Destroy the IOTLB cache. */
-    if (pThisCC->paIotlbes)
-    {
-        PDMDevHlpMMHeapFree(pDevIns, pThisCC->paIotlbes);
-        pThisCC->paIotlbes = NULL;
-        pThisCC->idxUnusedIotlbe = 0;
+    if (pThisR3->paIotlbes)
+    {
+        PDMDevHlpMMHeapFree(pDevIns, pThisR3->paIotlbes);
+        pThisR3->paIotlbes = NULL;
+        pThisR3->idxUnusedIotlbe = 0;
     }
 #endif
 
-    IOMMU_UNLOCK(pDevIns, pThisCC);
+    IOMMU_UNLOCK(pDevIns, pThisR3);
     return VINF_SUCCESS;
 }
