Changeset 81952 in vbox
- Timestamp:
- Nov 18, 2019 4:54:34 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 134749
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/PC/DevHPET.cpp
r81591 r81952 241 241 } HPETTIMER; 242 242 AssertCompileMemberAlignment(HPETTIMER, u64Config, sizeof(uint64_t)); 243 /** Pointer to the shared state of an HPET timer. */ 244 typedef HPETTIMER *PHPETTIMER; 245 /** Const pointer to the shared state of an HPET timer. */ 246 typedef HPETTIMER const *PCHPETTIMER; 247 243 248 244 249 /** … … 290 295 uint8_t abPadding0[7]; 291 296 } HPET; 297 /** Pointer to the shared HPET device state. */ 298 typedef HPET *PHPET; 299 /** Const pointer to the shared HPET device state. */ 300 typedef const HPET *PCHPET; 292 301 293 302 … … 295 304 296 305 297 DECLINLINE(bool) hpet32bitTimer( HPETTIMER *pHpetTimer)306 DECLINLINE(bool) hpet32bitTimer(PHPETTIMER pHpetTimer) 298 307 { 299 308 uint64_t u64Cfg = pHpetTimer->u64Config; … … 302 311 } 303 312 304 DECLINLINE(uint64_t) hpetInvalidValue( HPETTIMER *pHpetTimer)313 DECLINLINE(uint64_t) hpetInvalidValue(PHPETTIMER pHpetTimer) 305 314 { 306 315 return hpet32bitTimer(pHpetTimer) ? UINT32_MAX : UINT64_MAX; 307 316 } 308 317 309 DECLINLINE(uint64_t) hpetTicksToNs( HPET *pThis, uint64_t value)318 DECLINLINE(uint64_t) hpetTicksToNs(PHPET pThis, uint64_t value) 310 319 { 311 320 return ASMMultU64ByU32DivByU32(value, pThis->u32Period, FS_PER_NS); 312 321 } 313 322 314 DECLINLINE(uint64_t) nsToHpetTicks( HPET const *pThis, uint64_t u64Value)323 DECLINLINE(uint64_t) nsToHpetTicks(PCHPET pThis, uint64_t u64Value) 315 324 { 316 325 return ASMMultU64ByU32DivByU32(u64Value, FS_PER_NS, pThis->u32Period); 317 326 } 318 327 319 DECLINLINE(uint64_t) hpetGetTicks( HPET const *pThis)328 DECLINLINE(uint64_t) hpetGetTicks(PCHPET pThis) 320 329 { 321 330 /* … … 347 356 } 348 357 349 DECLINLINE(uint64_t) hpetComputeDiff( HPETTIMER *pHpetTimer, uint64_t u64Now)358 DECLINLINE(uint64_t) hpetComputeDiff(PHPETTIMER pHpetTimer, uint64_t u64Now) 350 359 { 351 360 … … 369 378 370 379 371 static void hpetAdjustComparator( HPETTIMER *pHpetTimer, uint64_t u64Now)380 static void hpetAdjustComparator(PHPETTIMER pHpetTimer, uint64_t u64Now) 372 381 { 373 382 uint64_t u64Period = pHpetTimer->u64Period; … … 388 397 * @param pHpetTimer The timer. 389 398 */ 390 DECLINLINE(void) hpetTimerSetFrequencyHint( HPET *pThis, HPETTIMER *pHpetTimer)399 DECLINLINE(void) hpetTimerSetFrequencyHint(PHPET pThis, PHPETTIMER pHpetTimer) 391 400 { 392 401 if (pHpetTimer->u64Config & HPET_TN_PERIODIC) … … 400 409 401 410 402 static void hpetProgramTimer( HPET *pThis, HPETTIMER *pHpetTimer)411 static void hpetProgramTimer(PHPET pThis, PHPETTIMER pHpetTimer) 403 412 { 404 413 /* no wrapping on new timers */ … … 463 472 * @remarks ASSUMES the caller holds the HPET lock. 464 473 */ 465 static int hpetTimerRegRead32( HPET const *pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t *pu32Value)474 static int hpetTimerRegRead32(PCHPET pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t *pu32Value) 466 475 { 467 476 Assert(PDMCritSectIsOwner(&pThis->CritSect)); … … 475 484 } 476 485 477 HPETTIMER const *pHpetTimer = &pThis->aTimers[iTimerNo];486 PCHPETTIMER pHpetTimer = &pThis->aTimers[iTimerNo]; 478 487 uint32_t u32Value; 479 488 switch (iTimerReg) … … 529 538 * the TM lock. 530 539 */ 531 static int hpetTimerRegWrite32( HPET *pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t u32NewValue)540 static int hpetTimerRegWrite32(PHPET pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t u32NewValue) 532 541 { 533 542 Assert(!PDMCritSectIsOwner(&pThis->CritSect) || TMTimerIsLockOwner(pThis->aTimers[0].CTX_SUFF(pTimer))); … … 539 548 return VINF_SUCCESS; 540 549 } 541 HPETTIMER *pHpetTimer = &pThis->aTimers[iTimerNo];550 PHPETTIMER pHpetTimer = &pThis->aTimers[iTimerNo]; 542 551 543 552 switch (iTimerReg) … … 647 656 * @remarks The caller must not own the device lock if HPET_COUNTER is read. 648 657 */ 649 static int hpetConfigRegRead32( HPET *pThis, uint32_t idxReg, uint32_t *pu32Value)658 static int hpetConfigRegRead32(PHPET pThis, uint32_t idxReg, uint32_t *pu32Value) 650 659 { 651 660 Assert(!PDMCritSectIsOwner(&pThis->CritSect) || (idxReg != HPET_COUNTER && idxReg != HPET_COUNTER + 4)); … … 732 741 * the TM lock. 733 742 */ 734 static int hpetConfigRegWrite32( HPET *pThis, uint32_t idxReg, uint32_t u32NewValue)743 static int hpetConfigRegWrite32(PHPET pThis, uint32_t idxReg, uint32_t u32NewValue) 735 744 { 736 745 Assert(!PDMCritSectIsOwner(&pThis->CritSect) || TMTimerIsLockOwner(pThis->aTimers[0].CTX_SUFF(pTimer))); … … 1002 1011 * @param pHpetTimer The HPET timer. 1003 1012 */ 1004 static uint32_t hpetR3TimerGetIrq( struct HPETTIMER const *pHpetTimer)1013 static uint32_t hpetR3TimerGetIrq(PCHPETTIMER pHpetTimer) 1005 1014 { 1006 1015 /* … … 1026 1035 * @param pHpetTimer The HPET timer. 1027 1036 */ 1028 static void hpetR3TimerUpdateIrq( HPET *pThis, struct HPETTIMER *pHpetTimer)1037 static void hpetR3TimerUpdateIrq(PHPET pThis, PHPETTIMER pHpetTimer) 1029 1038 { 1030 1039 /** @todo is it correct? */ … … 1058 1067 static DECLCALLBACK(void) hpetR3Timer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser) 1059 1068 { 1060 HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);1061 HPETTIMER *pHpetTimer = (HPETTIMER *)pvUser;1069 PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET); 1070 PHPETTIMER pHpetTimer = (HPETTIMER *)pvUser; 1062 1071 uint64_t u64Period = pHpetTimer->u64Period; 1063 1072 uint64_t u64CurTick = hpetGetTicks(pThis); … … 1107 1116 static DECLCALLBACK(void) hpetR3Info(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs) 1108 1117 { 1109 HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);1118 PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET); 1110 1119 NOREF(pszArgs); 1111 1120 … … 1140 1149 static DECLCALLBACK(int) hpetR3LiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass) 1141 1150 { 1142 HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *); 1151 PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET); 1152 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3; 1143 1153 NOREF(uPass); 1144 1154 1145 SSMR3PutU8(pSSM, HPET_CAP_GET_TIMERS(pThis->u32Capabilities));1155 pHlp->pfnSSMPutU8(pSSM, HPET_CAP_GET_TIMERS(pThis->u32Capabilities)); 1146 1156 1147 1157 return VINF_SSM_DONT_CALL_AGAIN; … … 1154 1164 static DECLCALLBACK(int) hpetR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM) 1155 1165 { 1156 HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *); 1166 PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET); 1167 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3; 1157 1168 1158 1169 /* … … 1167 1178 for (uint32_t iTimer = 0; iTimer < cTimers; iTimer++) 1168 1179 { 1169 HPETTIMER *pHpetTimer = &pThis->aTimers[iTimer];1180 PHPETTIMER pHpetTimer = &pThis->aTimers[iTimer]; 1170 1181 TMR3TimerSave(pHpetTimer->pTimerR3, pSSM); 1171 SSMR3PutU8(pSSM, pHpetTimer->u8Wrap);1172 SSMR3PutU64(pSSM, pHpetTimer->u64Config);1173 SSMR3PutU64(pSSM, pHpetTimer->u64Cmp);1174 SSMR3PutU64(pSSM, pHpetTimer->u64Fsb);1175 SSMR3PutU64(pSSM, pHpetTimer->u64Period);1176 } 1177 1178 SSMR3PutU64(pSSM, pThis->u64HpetOffset);1182 pHlp->pfnSSMPutU8(pSSM, pHpetTimer->u8Wrap); 1183 pHlp->pfnSSMPutU64(pSSM, pHpetTimer->u64Config); 1184 pHlp->pfnSSMPutU64(pSSM, pHpetTimer->u64Cmp); 1185 pHlp->pfnSSMPutU64(pSSM, pHpetTimer->u64Fsb); 1186 pHlp->pfnSSMPutU64(pSSM, pHpetTimer->u64Period); 1187 } 1188 1189 pHlp->pfnSSMPutU64(pSSM, pThis->u64HpetOffset); 1179 1190 uint64_t u64CapPer = RT_MAKE_U64(pThis->u32Capabilities, pThis->u32Period); 1180 SSMR3PutU64(pSSM, u64CapPer);1181 SSMR3PutU64(pSSM, pThis->u64HpetConfig);1182 SSMR3PutU64(pSSM, pThis->u64Isr);1183 return SSMR3PutU64(pSSM, pThis->u64HpetCounter);1191 pHlp->pfnSSMPutU64(pSSM, u64CapPer); 1192 pHlp->pfnSSMPutU64(pSSM, pThis->u64HpetConfig); 1193 pHlp->pfnSSMPutU64(pSSM, pThis->u64Isr); 1194 return pHlp->pfnSSMPutU64(pSSM, pThis->u64HpetCounter); 1184 1195 } 1185 1196 … … 1190 1201 static DECLCALLBACK(int) hpetR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass) 1191 1202 { 1192 HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *); 1203 PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET); 1204 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3; 1193 1205 1194 1206 /* … … 1204 1216 */ 1205 1217 uint8_t cTimers; 1206 int rc = SSMR3GetU8(pSSM, &cTimers);1218 int rc = pHlp->pfnSSMGetU8(pSSM, &cTimers); 1207 1219 AssertRCReturn(rc, rc); 1208 1220 if (cTimers > RT_ELEMENTS(pThis->aTimers)) 1209 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - too many timers: saved=%#x config=%#x"),1210 cTimers, RT_ELEMENTS(pThis->aTimers));1221 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - too many timers: saved=%#x config=%#x"), 1222 cTimers, RT_ELEMENTS(pThis->aTimers)); 1211 1223 1212 1224 if (uPass != SSM_PASS_FINAL) … … 1218 1230 for (uint32_t iTimer = 0; iTimer < cTimers; iTimer++) 1219 1231 { 1220 HPETTIMER *pHpetTimer = &pThis->aTimers[iTimer];1232 PHPETTIMER pHpetTimer = &pThis->aTimers[iTimer]; 1221 1233 TMR3TimerLoad(pHpetTimer->pTimerR3, pSSM); 1222 SSMR3GetU8(pSSM, &pHpetTimer->u8Wrap);1223 SSMR3GetU64(pSSM, &pHpetTimer->u64Config);1224 SSMR3GetU64(pSSM, &pHpetTimer->u64Cmp);1225 SSMR3GetU64(pSSM, &pHpetTimer->u64Fsb);1226 SSMR3GetU64(pSSM, &pHpetTimer->u64Period);1227 } 1228 1229 SSMR3GetU64(pSSM, &pThis->u64HpetOffset);1234 pHlp->pfnSSMGetU8(pSSM, &pHpetTimer->u8Wrap); 1235 pHlp->pfnSSMGetU64(pSSM, &pHpetTimer->u64Config); 1236 pHlp->pfnSSMGetU64(pSSM, &pHpetTimer->u64Cmp); 1237 pHlp->pfnSSMGetU64(pSSM, &pHpetTimer->u64Fsb); 1238 pHlp->pfnSSMGetU64(pSSM, &pHpetTimer->u64Period); 1239 } 1240 1241 pHlp->pfnSSMGetU64(pSSM, &pThis->u64HpetOffset); 1230 1242 uint64_t u64CapPer; 1231 SSMR3GetU64(pSSM, &u64CapPer);1232 SSMR3GetU64(pSSM, &pThis->u64HpetConfig);1233 SSMR3GetU64(pSSM, &pThis->u64Isr);1234 rc = SSMR3GetU64(pSSM, &pThis->u64HpetCounter);1243 pHlp->pfnSSMGetU64(pSSM, &u64CapPer); 1244 pHlp->pfnSSMGetU64(pSSM, &pThis->u64HpetConfig); 1245 pHlp->pfnSSMGetU64(pSSM, &pThis->u64Isr); 1246 rc = pHlp->pfnSSMGetU64(pSSM, &pThis->u64HpetCounter); 1235 1247 if (RT_FAILURE(rc)) 1236 1248 return rc; 1237 1249 if (HPET_CAP_GET_TIMERS(RT_LO_U32(u64CapPer)) != cTimers) 1238 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Capabilities does not match timer count: cTimers=%#x caps=%#x"),1239 cTimers, (unsigned)HPET_CAP_GET_TIMERS(u64CapPer));1250 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Capabilities does not match timer count: cTimers=%#x caps=%#x"), 1251 cTimers, (unsigned)HPET_CAP_GET_TIMERS(u64CapPer)); 1240 1252 pThis->u32Capabilities = RT_LO_U32(u64CapPer); 1241 1253 pThis->u32Period = RT_HI_U32(u64CapPer); … … 1247 1259 for (uint32_t iTimer = 0; iTimer < cTimers; iTimer++) 1248 1260 { 1249 HPETTIMER *pHpetTimer = &pThis->aTimers[iTimer];1261 PHPETTIMER pHpetTimer = &pThis->aTimers[iTimer]; 1250 1262 if (TMTimerIsActive(pHpetTimer->CTX_SUFF(pTimer))) 1251 1263 hpetTimerSetFrequencyHint(pThis, pHpetTimer); … … 1264 1276 static DECLCALLBACK(void) hpetR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta) 1265 1277 { 1266 HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);1278 PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET); 1267 1279 LogFlow(("hpetR3Relocate:\n")); 1268 1280 NOREF(offDelta); … … 1273 1285 for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++) 1274 1286 { 1275 HPETTIMER *pTm = &pThis->aTimers[i];1287 PHPETTIMER pTm = &pThis->aTimers[i]; 1276 1288 if (pTm->pTimerR3) 1277 1289 pTm->pTimerRC = TMTimerRCPtr(pTm->pTimerR3); … … 1286 1298 static DECLCALLBACK(void) hpetR3Reset(PPDMDEVINS pDevIns) 1287 1299 { 1288 HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *);1300 PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET); 1289 1301 LogFlow(("hpetR3Reset:\n")); 1290 1302 … … 1295 1307 for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++) 1296 1308 { 1297 HPETTIMER *pHpetTimer = &pThis->aTimers[i];1309 PHPETTIMER pHpetTimer = &pThis->aTimers[i]; 1298 1310 Assert(pHpetTimer->idxTimer == i); 1299 1311 TMTimerStop(pHpetTimer->pTimerR3); … … 1351 1363 { 1352 1364 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 1353 HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET *); 1365 PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET); 1366 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3; 1354 1367 1355 1368 /* Only one HPET device now, as we use fixed MMIO region. */ … … 1366 1379 for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++) 1367 1380 { 1368 HPETTIMER *pHpetTimer = &pThis->aTimers[i];1381 PHPETTIMER pHpetTimer = &pThis->aTimers[i]; 1369 1382 1370 1383 pHpetTimer->idxTimer = i; … … 1377 1390 * Validate and read the configuration. 1378 1391 */ 1379 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "GCEnabled|R0Enabled|ICH9", ""); 1380 1381 bool fRCEnabled; 1382 int rc = CFGMR3QueryBoolDef(pCfg, "GCEnabled", &fRCEnabled, true); 1392 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "ICH9", ""); 1393 1394 int rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "ICH9", &pThis->fIch9, false); 1383 1395 if (RT_FAILURE(rc)) 1384 return PDMDEV_SET_ERROR(pDevIns, rc, 1385 N_("Configuration error: Querying \"GCEnabled\" as a bool failed")); 1386 1387 bool fR0Enabled; 1388 rc = CFGMR3QueryBoolDef(pCfg, "R0Enabled", &fR0Enabled, true); 1389 if (RT_FAILURE(rc)) 1390 return PDMDEV_SET_ERROR(pDevIns, rc, 1391 N_("Configuration error: failed to read R0Enabled as boolean")); 1392 1393 rc = CFGMR3QueryBoolDef(pCfg, "ICH9", &pThis->fIch9, false); 1394 if (RT_FAILURE(rc)) 1395 return PDMDEV_SET_ERROR(pDevIns, rc, 1396 N_("Configuration error: failed to read ICH9 as boolean")); 1396 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: failed to read ICH9 as boolean")); 1397 1397 1398 1398 … … 1410 1410 for (unsigned i = 0; i < RT_ELEMENTS(pThis->aTimers); i++) 1411 1411 { 1412 HPETTIMER *pHpetTimer = &pThis->aTimers[i];1412 PHPETTIMER pHpetTimer = &pThis->aTimers[i]; 1413 1413 1414 1414 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, hpetR3Timer, pHpetTimer, … … 1444 1444 AssertRCReturn(rc, rc); 1445 1445 1446 if ( fRCEnabled)1446 if (pDevIns->fRCEnabled) 1447 1447 { 1448 1448 rc = PDMDevHlpMMIORegisterRC(pDevIns, HPET_BASE, HPET_BAR_SIZE, NIL_RTRCPTR /*pvUser*/, "hpetMMIOWrite", "hpetMMIORead"); … … 1452 1452 } 1453 1453 1454 if (fR0Enabled) 1455 { 1456 rc = PDMDevHlpMMIORegisterR0(pDevIns, HPET_BASE, HPET_BAR_SIZE, NIL_RTR0PTR /*pvUser*/, 1457 "hpetMMIOWrite", "hpetMMIORead"); 1454 if (pDevIns->fR0Enabled) 1455 { 1456 rc = PDMDevHlpMMIORegisterR0(pDevIns, HPET_BASE, HPET_BAR_SIZE, NIL_RTR0PTR /*pvUser*/, "hpetMMIOWrite", "hpetMMIORead"); 1458 1457 AssertRCReturn(rc, rc); 1459 1458
Note:
See TracChangeset
for help on using the changeset viewer.