Index: trunk/src/VBox/Devices/PC/DevHPET.cpp
===================================================================
--- trunk/src/VBox/Devices/PC/DevHPET.cpp	(revision 81949)
+++ trunk/src/VBox/Devices/PC/DevHPET.cpp	(revision 81952)
@@ -241,4 +241,9 @@
 } HPETTIMER;
 AssertCompileMemberAlignment(HPETTIMER, u64Config, sizeof(uint64_t));
+/** Pointer to the shared state of an HPET timer. */
+typedef HPETTIMER *PHPETTIMER;
+/** Const pointer to the shared state of an HPET timer. */
+typedef HPETTIMER const *PCHPETTIMER;
+
 
 /**
@@ -290,4 +295,8 @@
     uint8_t                     abPadding0[7];
 } HPET;
+/** Pointer to the shared HPET device state. */
+typedef HPET *PHPET;
+/** Const pointer to the shared HPET device state. */
+typedef const HPET *PCHPET;
 
 
@@ -295,5 +304,5 @@
 
 
-DECLINLINE(bool) hpet32bitTimer(HPETTIMER *pHpetTimer)
+DECLINLINE(bool) hpet32bitTimer(PHPETTIMER pHpetTimer)
 {
     uint64_t u64Cfg = pHpetTimer->u64Config;
@@ -302,20 +311,20 @@
 }
 
-DECLINLINE(uint64_t) hpetInvalidValue(HPETTIMER *pHpetTimer)
+DECLINLINE(uint64_t) hpetInvalidValue(PHPETTIMER pHpetTimer)
 {
     return hpet32bitTimer(pHpetTimer) ? UINT32_MAX : UINT64_MAX;
 }
 
-DECLINLINE(uint64_t) hpetTicksToNs(HPET *pThis, uint64_t value)
+DECLINLINE(uint64_t) hpetTicksToNs(PHPET pThis, uint64_t value)
 {
     return ASMMultU64ByU32DivByU32(value,  pThis->u32Period, FS_PER_NS);
 }
 
-DECLINLINE(uint64_t) nsToHpetTicks(HPET const *pThis, uint64_t u64Value)
+DECLINLINE(uint64_t) nsToHpetTicks(PCHPET pThis, uint64_t u64Value)
 {
     return ASMMultU64ByU32DivByU32(u64Value, FS_PER_NS, pThis->u32Period);
 }
 
-DECLINLINE(uint64_t) hpetGetTicks(HPET const *pThis)
+DECLINLINE(uint64_t) hpetGetTicks(PCHPET pThis)
 {
     /*
@@ -347,5 +356,5 @@
 }
 
-DECLINLINE(uint64_t) hpetComputeDiff(HPETTIMER *pHpetTimer, uint64_t u64Now)
+DECLINLINE(uint64_t) hpetComputeDiff(PHPETTIMER pHpetTimer, uint64_t u64Now)
 {
 
@@ -369,5 +378,5 @@
 
 
-static void hpetAdjustComparator(HPETTIMER *pHpetTimer, uint64_t u64Now)
+static void hpetAdjustComparator(PHPETTIMER pHpetTimer, uint64_t u64Now)
 {
     uint64_t    u64Period = pHpetTimer->u64Period;
@@ -388,5 +397,5 @@
  * @param   pHpetTimer  The timer.
  */
-DECLINLINE(void) hpetTimerSetFrequencyHint(HPET *pThis, HPETTIMER *pHpetTimer)
+DECLINLINE(void) hpetTimerSetFrequencyHint(PHPET pThis, PHPETTIMER pHpetTimer)
 {
     if (pHpetTimer->u64Config & HPET_TN_PERIODIC)
@@ -400,5 +409,5 @@
 
 
-static void hpetProgramTimer(HPET *pThis, HPETTIMER *pHpetTimer)
+static void hpetProgramTimer(PHPET pThis, PHPETTIMER pHpetTimer)
 {
     /* no wrapping on new timers */
@@ -463,5 +472,5 @@
  * @remarks ASSUMES the caller holds the HPET lock.
  */
-static int hpetTimerRegRead32(HPET const *pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t *pu32Value)
+static int hpetTimerRegRead32(PCHPET pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t *pu32Value)
 {
     Assert(PDMCritSectIsOwner(&pThis->CritSect));
@@ -475,5 +484,5 @@
     }
 
-    HPETTIMER const *pHpetTimer = &pThis->aTimers[iTimerNo];
+    PCHPETTIMER pHpetTimer = &pThis->aTimers[iTimerNo];
     uint32_t u32Value;
     switch (iTimerReg)
@@ -529,5 +538,5 @@
  *          the TM lock.
  */
-static int hpetTimerRegWrite32(HPET *pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t u32NewValue)
+static int hpetTimerRegWrite32(PHPET pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t u32NewValue)
 {
     Assert(!PDMCritSectIsOwner(&pThis->CritSect) || TMTimerIsLockOwner(pThis->aTimers[0].CTX_SUFF(pTimer)));
@@ -539,5 +548,5 @@
         return VINF_SUCCESS;
     }
-    HPETTIMER *pHpetTimer = &pThis->aTimers[iTimerNo];
+    PHPETTIMER pHpetTimer = &pThis->aTimers[iTimerNo];
 
     switch (iTimerReg)
@@ -647,5 +656,5 @@
  * @remarks The caller must not own the device lock if HPET_COUNTER is read.
  */
-static int hpetConfigRegRead32(HPET *pThis, uint32_t idxReg, uint32_t *pu32Value)
+static int hpetConfigRegRead32(PHPET pThis, uint32_t idxReg, uint32_t *pu32Value)
 {
     Assert(!PDMCritSectIsOwner(&pThis->CritSect) || (idxReg != HPET_COUNTER && idxReg != HPET_COUNTER + 4));
@@ -732,5 +741,5 @@
  *          the TM lock.
  */
-static int hpetConfigRegWrite32(HPET *pThis, uint32_t idxReg, uint32_t u32NewValue)
+static int hpetConfigRegWrite32(PHPET pThis, uint32_t idxReg, uint32_t u32NewValue)
 {
     Assert(!PDMCritSectIsOwner(&pThis->CritSect) || TMTimerIsLockOwner(pThis->aTimers[0].CTX_SUFF(pTimer)));
@@ -1002,5 +1011,5 @@
  * @param   pHpetTimer          The HPET timer.
  */
-static uint32_t hpetR3TimerGetIrq(struct HPETTIMER const *pHpetTimer)
+static uint32_t hpetR3TimerGetIrq(PCHPETTIMER pHpetTimer)
 {
     /*
@@ -1026,5 +1035,5 @@
  * @param   pHpetTimer          The HPET timer.
  */
-static void hpetR3TimerUpdateIrq(HPET *pThis, struct HPETTIMER *pHpetTimer)
+static void hpetR3TimerUpdateIrq(PHPET pThis, PHPETTIMER pHpetTimer)
 {
     /** @todo is it correct? */
@@ -1058,6 +1067,6 @@
 static DECLCALLBACK(void) hpetR3Timer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
 {
-    HPET *pThis      = PDMDEVINS_2_DATA(pDevIns, HPET *);
-    HPETTIMER *pHpetTimer = (HPETTIMER *)pvUser;
+    PHPET pThis      = PDMDEVINS_2_DATA(pDevIns, PHPET);
+    PHPETTIMER pHpetTimer = (HPETTIMER *)pvUser;
     uint64_t   u64Period  = pHpetTimer->u64Period;
     uint64_t   u64CurTick = hpetGetTicks(pThis);
@@ -1107,5 +1116,5 @@
 static DECLCALLBACK(void) hpetR3Info(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
 {
-    HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
+    PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET);
     NOREF(pszArgs);
 
@@ -1140,8 +1149,9 @@
 static DECLCALLBACK(int) hpetR3LiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
 {
-    HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
+    PHPET           pThis   = PDMDEVINS_2_DATA(pDevIns, PHPET);
+    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
     NOREF(uPass);
 
-    SSMR3PutU8(pSSM, HPET_CAP_GET_TIMERS(pThis->u32Capabilities));
+    pHlp->pfnSSMPutU8(pSSM, HPET_CAP_GET_TIMERS(pThis->u32Capabilities));
 
     return VINF_SSM_DONT_CALL_AGAIN;
@@ -1154,5 +1164,6 @@
 static DECLCALLBACK(int) hpetR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
 {
-    HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
+    PHPET           pThis   = PDMDEVINS_2_DATA(pDevIns, PHPET);
+    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
 
     /*
@@ -1167,19 +1178,19 @@
     for (uint32_t iTimer = 0; iTimer < cTimers; iTimer++)
     {
-        HPETTIMER *pHpetTimer = &pThis->aTimers[iTimer];
+        PHPETTIMER pHpetTimer = &pThis->aTimers[iTimer];
         TMR3TimerSave(pHpetTimer->pTimerR3, pSSM);
-        SSMR3PutU8(pSSM,  pHpetTimer->u8Wrap);
-        SSMR3PutU64(pSSM, pHpetTimer->u64Config);
-        SSMR3PutU64(pSSM, pHpetTimer->u64Cmp);
-        SSMR3PutU64(pSSM, pHpetTimer->u64Fsb);
-        SSMR3PutU64(pSSM, pHpetTimer->u64Period);
-    }
-
-    SSMR3PutU64(pSSM, pThis->u64HpetOffset);
+        pHlp->pfnSSMPutU8(pSSM,  pHpetTimer->u8Wrap);
+        pHlp->pfnSSMPutU64(pSSM, pHpetTimer->u64Config);
+        pHlp->pfnSSMPutU64(pSSM, pHpetTimer->u64Cmp);
+        pHlp->pfnSSMPutU64(pSSM, pHpetTimer->u64Fsb);
+        pHlp->pfnSSMPutU64(pSSM, pHpetTimer->u64Period);
+    }
+
+    pHlp->pfnSSMPutU64(pSSM, pThis->u64HpetOffset);
     uint64_t u64CapPer = RT_MAKE_U64(pThis->u32Capabilities, pThis->u32Period);
-    SSMR3PutU64(pSSM, u64CapPer);
-    SSMR3PutU64(pSSM, pThis->u64HpetConfig);
-    SSMR3PutU64(pSSM, pThis->u64Isr);
-    return SSMR3PutU64(pSSM, pThis->u64HpetCounter);
+    pHlp->pfnSSMPutU64(pSSM, u64CapPer);
+    pHlp->pfnSSMPutU64(pSSM, pThis->u64HpetConfig);
+    pHlp->pfnSSMPutU64(pSSM, pThis->u64Isr);
+    return pHlp->pfnSSMPutU64(pSSM, pThis->u64HpetCounter);
 }
 
@@ -1190,5 +1201,6 @@
 static DECLCALLBACK(int) hpetR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
 {
-    HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
+    PHPET           pThis   = PDMDEVINS_2_DATA(pDevIns, PHPET);
+    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
 
     /*
@@ -1204,9 +1216,9 @@
      */
     uint8_t cTimers;
-    int rc = SSMR3GetU8(pSSM, &cTimers);
+    int rc = pHlp->pfnSSMGetU8(pSSM, &cTimers);
     AssertRCReturn(rc, rc);
     if (cTimers > RT_ELEMENTS(pThis->aTimers))
-        return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - too many timers: saved=%#x config=%#x"),
-                                cTimers, RT_ELEMENTS(pThis->aTimers));
+        return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - too many timers: saved=%#x config=%#x"),
+                                       cTimers, RT_ELEMENTS(pThis->aTimers));
 
     if (uPass != SSM_PASS_FINAL)
@@ -1218,24 +1230,24 @@
     for (uint32_t iTimer = 0; iTimer < cTimers; iTimer++)
     {
-        HPETTIMER *pHpetTimer = &pThis->aTimers[iTimer];
+        PHPETTIMER pHpetTimer = &pThis->aTimers[iTimer];
         TMR3TimerLoad(pHpetTimer->pTimerR3, pSSM);
-        SSMR3GetU8(pSSM,  &pHpetTimer->u8Wrap);
-        SSMR3GetU64(pSSM, &pHpetTimer->u64Config);
-        SSMR3GetU64(pSSM, &pHpetTimer->u64Cmp);
-        SSMR3GetU64(pSSM, &pHpetTimer->u64Fsb);
-        SSMR3GetU64(pSSM, &pHpetTimer->u64Period);
-    }
-
-    SSMR3GetU64(pSSM, &pThis->u64HpetOffset);
+        pHlp->pfnSSMGetU8(pSSM,  &pHpetTimer->u8Wrap);
+        pHlp->pfnSSMGetU64(pSSM, &pHpetTimer->u64Config);
+        pHlp->pfnSSMGetU64(pSSM, &pHpetTimer->u64Cmp);
+        pHlp->pfnSSMGetU64(pSSM, &pHpetTimer->u64Fsb);
+        pHlp->pfnSSMGetU64(pSSM, &pHpetTimer->u64Period);
+    }
+
+    pHlp->pfnSSMGetU64(pSSM, &pThis->u64HpetOffset);
     uint64_t u64CapPer;
-    SSMR3GetU64(pSSM, &u64CapPer);
-    SSMR3GetU64(pSSM, &pThis->u64HpetConfig);
-    SSMR3GetU64(pSSM, &pThis->u64Isr);
-    rc = SSMR3GetU64(pSSM, &pThis->u64HpetCounter);
+    pHlp->pfnSSMGetU64(pSSM, &u64CapPer);
+    pHlp->pfnSSMGetU64(pSSM, &pThis->u64HpetConfig);
+    pHlp->pfnSSMGetU64(pSSM, &pThis->u64Isr);
+    rc = pHlp->pfnSSMGetU64(pSSM, &pThis->u64HpetCounter);
     if (RT_FAILURE(rc))
         return rc;
     if (HPET_CAP_GET_TIMERS(RT_LO_U32(u64CapPer)) != cTimers)
-        return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Capabilities does not match timer count: cTimers=%#x caps=%#x"),
-                                cTimers, (unsigned)HPET_CAP_GET_TIMERS(u64CapPer));
+        return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Capabilities does not match timer count: cTimers=%#x caps=%#x"),
+                                       cTimers, (unsigned)HPET_CAP_GET_TIMERS(u64CapPer));
     pThis->u32Capabilities  = RT_LO_U32(u64CapPer);
     pThis->u32Period        = RT_HI_U32(u64CapPer);
@@ -1247,5 +1259,5 @@
     for (uint32_t iTimer = 0; iTimer < cTimers; iTimer++)
     {
-        HPETTIMER *pHpetTimer = &pThis->aTimers[iTimer];
+        PHPETTIMER pHpetTimer = &pThis->aTimers[iTimer];
         if (TMTimerIsActive(pHpetTimer->CTX_SUFF(pTimer)))
             hpetTimerSetFrequencyHint(pThis, pHpetTimer);
@@ -1264,5 +1276,5 @@
 static DECLCALLBACK(void) hpetR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
 {
-    HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
+    PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET);
     LogFlow(("hpetR3Relocate:\n"));
     NOREF(offDelta);
@@ -1273,5 +1285,5 @@
     for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++)
     {
-        HPETTIMER *pTm = &pThis->aTimers[i];
+        PHPETTIMER pTm = &pThis->aTimers[i];
         if (pTm->pTimerR3)
             pTm->pTimerRC = TMTimerRCPtr(pTm->pTimerR3);
@@ -1286,5 +1298,5 @@
 static DECLCALLBACK(void) hpetR3Reset(PPDMDEVINS pDevIns)
 {
-    HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
+    PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET);
     LogFlow(("hpetR3Reset:\n"));
 
@@ -1295,5 +1307,5 @@
     for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++)
     {
-        HPETTIMER *pHpetTimer = &pThis->aTimers[i];
+        PHPETTIMER pHpetTimer = &pThis->aTimers[i];
         Assert(pHpetTimer->idxTimer == i);
         TMTimerStop(pHpetTimer->pTimerR3);
@@ -1351,5 +1363,6 @@
 {
     PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
-    HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);
+    PHPET           pThis   = PDMDEVINS_2_DATA(pDevIns, PHPET);
+    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
 
     /* Only one HPET device now, as we use fixed MMIO region. */
@@ -1366,5 +1379,5 @@
     for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++)
     {
-        HPETTIMER *pHpetTimer = &pThis->aTimers[i];
+        PHPETTIMER pHpetTimer = &pThis->aTimers[i];
 
         pHpetTimer->idxTimer = i;
@@ -1377,22 +1390,9 @@
      * Validate and read the configuration.
      */
-    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "GCEnabled|R0Enabled|ICH9", "");
-
-    bool fRCEnabled;
-    int rc = CFGMR3QueryBoolDef(pCfg, "GCEnabled", &fRCEnabled, true);
+    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "ICH9", "");
+
+    int rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "ICH9", &pThis->fIch9, false);
     if (RT_FAILURE(rc))
-        return PDMDEV_SET_ERROR(pDevIns, rc,
-                                N_("Configuration error: Querying \"GCEnabled\" as a bool failed"));
-
-    bool fR0Enabled;
-    rc = CFGMR3QueryBoolDef(pCfg, "R0Enabled", &fR0Enabled, true);
-    if (RT_FAILURE(rc))
-        return PDMDEV_SET_ERROR(pDevIns, rc,
-                                N_("Configuration error: failed to read R0Enabled as boolean"));
-
-    rc = CFGMR3QueryBoolDef(pCfg, "ICH9", &pThis->fIch9, false);
-    if (RT_FAILURE(rc))
-        return PDMDEV_SET_ERROR(pDevIns, rc,
-                                N_("Configuration error: failed to read ICH9 as boolean"));
+        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: failed to read ICH9 as boolean"));
 
 
@@ -1410,5 +1410,5 @@
     for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++)
     {
-        HPETTIMER *pHpetTimer = &pThis->aTimers[i];
+        PHPETTIMER pHpetTimer = &pThis->aTimers[i];
 
         rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, hpetR3Timer, pHpetTimer,
@@ -1444,5 +1444,5 @@
     AssertRCReturn(rc, rc);
 
-    if (fRCEnabled)
+    if (pDevIns->fRCEnabled)
     {
         rc = PDMDevHlpMMIORegisterRC(pDevIns, HPET_BASE, HPET_BAR_SIZE, NIL_RTRCPTR /*pvUser*/, "hpetMMIOWrite", "hpetMMIORead");
@@ -1452,8 +1452,7 @@
     }
 
-    if (fR0Enabled)
-    {
-        rc = PDMDevHlpMMIORegisterR0(pDevIns, HPET_BASE, HPET_BAR_SIZE, NIL_RTR0PTR /*pvUser*/,
-                                     "hpetMMIOWrite", "hpetMMIORead");
+    if (pDevIns->fR0Enabled)
+    {
+        rc = PDMDevHlpMMIORegisterR0(pDevIns, HPET_BASE, HPET_BAR_SIZE, NIL_RTR0PTR /*pvUser*/, "hpetMMIOWrite", "hpetMMIORead");
         AssertRCReturn(rc, rc);
 
