VirtualBox

Changeset 37501 in vbox


Ignore:
Timestamp:
Jun 16, 2011 3:08:48 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
72326
Message:

DevHPET: More code massaging...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/DevHPET.cpp

    r37500 r37501  
    195195    PCPDMHPETHLPRC       pHpetHlpRC;
    196196
    197     /* Timer structures. */
     197    /** Timer structures. */
    198198    HpetTimer            aTimers[HPET_NUM_TIMERS];
    199199
    200     /* Offset realtive to the system clock. */
     200    /** Offset realtive to the virtual sync clock. */
    201201    uint64_t             u64HpetOffset;
    202202
    203     /* Memory-mapped, software visible registers */
    204     /* capabilities. */
     203    /** @name Memory-mapped, software visible registers
     204     * @{ */
     205    /** Capabilities. */
    205206    uint64_t             u64Capabilities;
    206     /* Configuration. */
     207    /** Configuration. */
    207208    uint64_t             u64HpetConfig;
    208     /* Interrupt status register. */
     209    /** Interrupt status register. */
    209210    uint64_t             u64Isr;
    210     /* Main counter. */
     211    /** Main counter. */
    211212    uint64_t             u64HpetCounter;
    212 
    213     /* Global device lock. */
     213    /** @}  */
     214
     215    /** Global device lock. */
    214216    PDMCRITSECT          csLock;
    215217
    216     /* If we emulate ICH9 HPET (different frequency). */
     218    /** If we emulate ICH9 HPET (different frequency).
     219     * @todo different number of timers  */
    217220    uint8_t              fIch9;
    218221    uint8_t              padding0[7];
     
    10831086{
    10841087    HpetState *pThis = PDMINS_2_DATA(pDevIns, HpetState *);
    1085     unsigned i;
    10861088    LogFlow(("hpetRelocate:\n"));
    10871089
     
    10891091    pThis->pHpetHlpRC   = pThis->pHpetHlpR3->pfnGetRCHelpers(pDevIns);
    10901092
    1091     for (i = 0; i < RT_ELEMENTS(pThis->aTimers); i++)
     1093    for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++)
    10921094    {
    10931095        HpetTimer *pTm = &pThis->aTimers[i];
     
    11071109{
    11081110    HpetState *pThis = PDMINS_2_DATA(pDevIns, HpetState *);
    1109     unsigned i;
    1110 
    11111111    LogFlow(("hpetReset:\n"));
    11121112
    11131113    pThis->u64HpetConfig = 0;
    1114     for (i = 0; i < HPET_NUM_TIMERS; i++)
     1114    for (unsigned i = 0; i < HPET_NUM_TIMERS; i++)
    11151115    {
    11161116        HpetTimer *pHpetTimer = &pThis->aTimers[i];
    1117         pHpetTimer->idxTimer = i;
     1117        Assert(pHpetTimer->idxTimer == i);
     1118
    11181119        /* capable of periodic operations and 64-bits */
    11191120        if (pThis->fIch9)
     
    11361137    uint32_t u32Vendor = 0x8086;
    11371138    /* 64-bit main counter; 3 timers supported; LegacyReplacementRoute. */
    1138     uint32_t u32Caps =
    1139       (1 << 15) /* LEG_RT_CAP, LegacyReplacementRoute capable */ |
    1140       (1 << 13) /* COUNTER_SIZE_CAP, main counter is 64-bit capable */ |
    1141       /* Actually ICH9 has 4 timers, but to avoid breaking saved state we'll stick with 3 so far. */
    1142       (HPET_NUM_TIMERS << 8) /* NUM_TIM_CAP, number of timers -1 */ |
    1143       1 /* REV_ID, revision, must not be 0 */;
     1139    uint32_t u32Caps = (1 << 15)              /* LEG_RT_CAP       - LegacyReplacementRoute capable. */
     1140                     | (1 << 13)              /* COUNTER_SIZE_CAP - Main counter is 64-bit capable. */
     1141                     | (HPET_NUM_TIMERS << 8) /* NUM_TIM_CAP      - Number of timers -1.
     1142                                                 Actually ICH9 has 4 timers, but to avoid breaking
     1143                                                 saved state we'll stick with 3 so far. */ /** @todo fix this ICH9 timer count bug. */
     1144                     | 1                      /* REV_ID           - Revision, must not be 0 */
     1145                     ;
    11441146    pThis->u64Capabilities = (u32Vendor << 16) | u32Caps;
    11451147    pThis->u64Capabilities |= ((uint64_t)(pThis->fIch9 ? HPET_CLK_PERIOD_ICH9 : HPET_CLK_PERIOD) << 32);
     
    11471149    /* Notify PIT/RTC devices */
    11481150    hpetLegacyMode(pThis, false);
    1149 }
    1150 
    1151 /**
    1152  * Initialization routine.
    1153  *
    1154  * @returns VBox status.
    1155  * @param   pDevIns     The device instance data.
    1156  */
    1157 static int hpetInit(PPDMDEVINS pDevIns)
    1158 {
    1159     HpetState *pThis = PDMINS_2_DATA(pDevIns, HpetState *);
    1160 
    1161     pThis->pDevInsR3 = pDevIns;
    1162     pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
    1163     pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
    1164 
    1165     for (unsigned i = 0; i < HPET_NUM_TIMERS; i++)
    1166     {
    1167         HpetTimer *pHpetTimer = &pThis->aTimers[i];
    1168 
    1169         pHpetTimer->pHpetR3 = pThis;
    1170         pHpetTimer->pHpetR0 = PDMINS_2_DATA_R0PTR(pDevIns);
    1171         pHpetTimer->pHpetRC = PDMINS_2_DATA_RCPTR(pDevIns);
    1172 
    1173         int rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, hpetTimer, pHpetTimer,
    1174                                         TMTIMER_FLAGS_NO_CRIT_SECT, "HPET Timer",
    1175                                         &pThis->aTimers[i].pTimerR3);
    1176         if (RT_FAILURE(rc))
    1177             return rc;
    1178         pThis->aTimers[i].pTimerRC = TMTimerRCPtr(pThis->aTimers[i].pTimerR3);
    1179         pThis->aTimers[i].pTimerR0 = TMTimerR0Ptr(pThis->aTimers[i].pTimerR3);
    1180         /// @todo TMR3TimerSetCritSect(pThis->aTimers[i].pTimerR3, &pThis->csLock);
    1181     }
    1182 
    1183     hpetReset(pDevIns);
    1184 
    1185     return VINF_SUCCESS;
    11861151}
    11871152
     
    12571222                                N_("Configuration error: failed to read ICH9 as boolean"));
    12581223
    1259     /* Initialize the device state */
    1260     pThis->fIch9 = (uint8_t)fIch9;
    1261 
    1262     rc = hpetInit(pDevIns);
    1263     if (RT_FAILURE(rc))
    1264         return rc;
    1265 
     1224    /*
     1225     * Initialize the device state
     1226     */
    12661227    pThis->pDevInsR3 = pDevIns;
    12671228    pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
    12681229    pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
     1230    pThis->fIch9     = (uint8_t)fIch9;
     1231
     1232    rc = PDMDevHlpCritSectInit(pDevIns, &pThis->csLock, RT_SRC_POS, "HPET#%u", pDevIns->iInstance);
     1233    AssertRCReturn(rc, rc);
     1234
     1235    /* Init timers. */
     1236    for (unsigned i = 0; i < HPET_NUM_TIMERS; i++)
     1237    {
     1238        HpetTimer *pHpetTimer = &pThis->aTimers[i];
     1239
     1240        pHpetTimer->idxTimer = i;
     1241        pHpetTimer->pHpetR3  = pThis;
     1242        pHpetTimer->pHpetR0  = PDMINS_2_DATA_R0PTR(pDevIns);
     1243        pHpetTimer->pHpetRC  = PDMINS_2_DATA_RCPTR(pDevIns);
     1244
     1245        rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, hpetTimer, pHpetTimer,
     1246                                        TMTIMER_FLAGS_NO_CRIT_SECT, "HPET Timer",
     1247                                        &pThis->aTimers[i].pTimerR3);
     1248        AssertRCReturn(rc, rc);
     1249        pThis->aTimers[i].pTimerRC = TMTimerRCPtr(pThis->aTimers[i].pTimerR3);
     1250        pThis->aTimers[i].pTimerR0 = TMTimerR0Ptr(pThis->aTimers[i].pTimerR3);
     1251        /// @todo TMR3TimerSetCritSect(pThis->aTimers[i].pTimerR3, &pThis->csLock);
     1252    }
     1253
     1254    hpetReset(pDevIns);
    12691255
    12701256    /*
     
    12771263
    12781264    /*
    1279      * Initialize critical section.
    1280      */
    1281     rc = PDMDevHlpCritSectInit(pDevIns, &pThis->csLock, RT_SRC_POS, "HPET#%u", pDevIns->iInstance);
    1282     if (RT_FAILURE(rc))
    1283         return PDMDEV_SET_ERROR(pDevIns, rc, N_("HPET cannot initialize critical section"));
    1284 
    1285     /*
    12861265     * Register the MMIO range, PDM API requests page aligned
    12871266     * addresses and sizes.
     
    12891268    rc = PDMDevHlpMMIORegister(pDevIns, HPET_BASE, 0x1000, pThis,
    12901269                               hpetMMIOWrite, hpetMMIORead, NULL, "HPET Memory");
    1291     if (RT_FAILURE(rc))
    1292     {
    1293         AssertMsgRC(rc, ("Cannot register MMIO: %Rrc\n", rc));
    1294         return rc;
    1295     }
     1270    AssertRCReturn(rc, rc);
    12961271
    12971272    if (fRCEnabled)
     
    12991274        rc = PDMDevHlpMMIORegisterRC(pDevIns, HPET_BASE, 0x1000, 0,
    13001275                                     "hpetMMIOWrite", "hpetMMIORead", NULL);
    1301         if (RT_FAILURE(rc))
    1302             return rc;
     1276        AssertRCReturn(rc, rc);
    13031277
    13041278        pThis->pHpetHlpRC = pThis->pHpetHlpR3->pfnGetRCHelpers(pDevIns);
    1305         if (!pThis->pHpetHlpRC)
    1306         {
    1307             AssertReleaseMsgFailed(("cannot get RC helper\n"));
    1308             return VERR_INTERNAL_ERROR;
    1309         }
     1279        AssertReturn(pThis->pHpetHlpRC != NIL_RTRCPTR, VERR_INTERNAL_ERROR);
    13101280    }
    13111281
     
    13141284        rc = PDMDevHlpMMIORegisterR0(pDevIns, HPET_BASE, 0x1000, 0,
    13151285                                     "hpetMMIOWrite", "hpetMMIORead", NULL);
    1316         if (RT_FAILURE(rc))
    1317             return rc;
     1286        AssertRCReturn(rc, rc);
    13181287
    13191288        pThis->pHpetHlpR0 = pThis->pHpetHlpR3->pfnGetR0Helpers(pDevIns);
    1320         if (!pThis->pHpetHlpR0)
    1321         {
    1322             AssertReleaseMsgFailed(("cannot get R0 helper\n"));
    1323             return VERR_INTERNAL_ERROR;
    1324         }
     1289        AssertReturn(pThis->pHpetHlpR0 != NIL_RTR0PTR, VERR_INTERNAL_ERROR);
    13251290    }
    13261291
    13271292    /* Register SSM callbacks */
    13281293    rc = PDMDevHlpSSMRegister3(pDevIns, HPET_SAVED_STATE_VERSION, sizeof(*pThis), hpetLiveExec, hpetSaveExec, hpetLoadExec);
    1329     if (RT_FAILURE(rc))
    1330         return rc;
     1294    AssertRCReturn(rc, rc);
    13311295
    13321296    /**
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette