Changeset 81959 in vbox for trunk/src/VBox/Devices/PC
- Timestamp:
- Nov 18, 2019 6:24:54 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 134756
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/PC/DevHPET.cpp
r81955 r81959 278 278 /** Size alignment padding. */ 279 279 uint8_t abPadding0[7]; 280 281 /** The handle of the MMIO region. */ 282 IOMMMIOHANDLE hMmio; 280 283 } HPET; 281 284 /** Pointer to the shared HPET device state. */ … … 446 449 * Reads a HPET timer register. 447 450 * 448 * @returns VBox strict status code.449 451 * @param pDevIns The device instance. 450 452 * @param pThis The HPET instance. … … 455 457 * @remarks ASSUMES the caller holds the HPET lock. 456 458 */ 457 static inthpetTimerRegRead32(PPDMDEVINS pDevIns, PCHPET pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t *pu32Value)459 static void hpetTimerRegRead32(PPDMDEVINS pDevIns, PCHPET pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t *pu32Value) 458 460 { 459 461 Assert(PDMDevHlpCritSectIsOwner(pDevIns, &pThis->CritSect)); … … 465 467 LogRelMax(10, ("HPET: Using timer above configured range: %d\n", iTimerNo)); 466 468 *pu32Value = 0; 467 return VINF_SUCCESS;469 return; 468 470 } 469 471 … … 505 507 } 506 508 *pu32Value = u32Value; 507 return VINF_SUCCESS;508 509 } 509 510 … … 523 524 * the TM lock. 524 525 */ 525 static int hpetTimerRegWrite32(PPDMDEVINS pDevIns, PHPET pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t u32NewValue) 526 static VBOXSTRICTRC hpetTimerRegWrite32(PPDMDEVINS pDevIns, PHPET pThis, uint32_t iTimerNo, 527 uint32_t iTimerReg, uint32_t u32NewValue) 526 528 { 527 529 Assert(!PDMDevHlpCritSectIsOwner(pDevIns, &pThis->CritSect) || PDMDevHlpTimerIsLockOwner(pDevIns, pThis->aTimers[0].hTimer)); … … 728 730 * the TM lock. 729 731 */ 730 static inthpetConfigRegWrite32(PPDMDEVINS pDevIns, PHPET pThis, uint32_t idxReg, uint32_t u32NewValue)732 static VBOXSTRICTRC hpetConfigRegWrite32(PPDMDEVINS pDevIns, PHPET pThis, uint32_t idxReg, uint32_t u32NewValue) 731 733 { 732 734 Assert(!PDMDevHlpCritSectIsOwner(pDevIns, &pThis->CritSect) || PDMDevHlpTimerIsLockOwner(pDevIns, pThis->aTimers[0].hTimer)); 733 735 734 intrc = VINF_SUCCESS;736 VBOXSTRICTRC rc = VINF_SUCCESS; 735 737 switch (idxReg) 736 738 { … … 862 864 863 865 /** 864 * @callback_method_impl{FNIOMMMIO READ}865 */ 866 PDMBOTHCBDECL(int) hpetMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)866 * @callback_method_impl{FNIOMMMIONEWREAD} 867 */ 868 static DECLCALLBACK(VBOXSTRICTRC) hpetMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb) 867 869 { 868 870 HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET*); 869 uint32_t const idxReg = (uint32_t)(GCPhysAddr - HPET_BASE);870 871 NOREF(pvUser); 871 872 Assert(cb == 4 || cb == 8); 872 873 873 LogFlow(("hpetMMIORead (%d): % llx (%x)\n", cb, (uint64_t)GCPhysAddr, idxReg));874 875 intrc;874 LogFlow(("hpetMMIORead (%d): %RGp\n", cb, off)); 875 876 VBOXSTRICTRC rc; 876 877 if (cb == 4) 877 878 { … … 879 880 * 4-byte access. 880 881 */ 881 if ( idxReg >= 0x100 && idxReg< 0x400)882 if (off >= 0x100 && off < 0x400) 882 883 { 883 884 DEVHPET_LOCK_RETURN(pDevIns, pThis, VINF_IOM_R3_MMIO_READ); 884 rc =hpetTimerRegRead32(pDevIns, pThis,885 (idxReg- 0x100) / 0x20,886 (idxReg- 0x100) % 0x20,887 885 hpetTimerRegRead32(pDevIns, pThis, 886 (uint32_t)(off - 0x100) / 0x20, 887 (uint32_t)(off - 0x100) % 0x20, 888 (uint32_t *)pv); 888 889 DEVHPET_UNLOCK(pDevIns, pThis); 890 rc = VINF_SUCCESS; 889 891 } 890 892 else 891 rc = hpetConfigRegRead32(pDevIns, pThis, idxReg, (uint32_t *)pv);893 rc = hpetConfigRegRead32(pDevIns, pThis, off, (uint32_t *)pv); 892 894 } 893 895 else … … 898 900 */ 899 901 PRTUINT64U pValue = (PRTUINT64U)pv; 900 if ( idxReg== HPET_COUNTER)902 if (off == HPET_COUNTER) 901 903 { 902 904 /* When reading HPET counter we must read it in a single read, … … 913 915 { 914 916 DEVHPET_LOCK_RETURN(pDevIns, pThis, VINF_IOM_R3_MMIO_READ); 915 if ( idxReg >= 0x100 && idxReg< 0x400)917 if (off >= 0x100 && off < 0x400) 916 918 { 917 uint32_t iTimer = ( idxReg- 0x100) / 0x20;918 uint32_t iTimerReg = ( idxReg- 0x100) % 0x20;919 rc =hpetTimerRegRead32(pDevIns, pThis, iTimer, iTimerReg, &pValue->s.Lo);920 if (rc == VINF_SUCCESS)921 rc = hpetTimerRegRead32(pDevIns, pThis, iTimer, iTimerReg + 4, &pValue->s.Hi);919 uint32_t iTimer = (uint32_t)(off - 0x100) / 0x20; 920 uint32_t iTimerReg = (uint32_t)(off - 0x100) % 0x20; 921 hpetTimerRegRead32(pDevIns, pThis, iTimer, iTimerReg, &pValue->s.Lo); 922 hpetTimerRegRead32(pDevIns, pThis, iTimer, iTimerReg + 4, &pValue->s.Hi); 923 rc = VINF_SUCCESS; 922 924 } 923 925 else 924 926 { 925 927 /* for most 8-byte accesses we just split them, happens under lock anyway. */ 926 rc = hpetConfigRegRead32(pDevIns, pThis, idxReg, &pValue->s.Lo);928 rc = hpetConfigRegRead32(pDevIns, pThis, off, &pValue->s.Lo); 927 929 if (rc == VINF_SUCCESS) 928 rc = hpetConfigRegRead32(pDevIns, pThis, idxReg+ 4, &pValue->s.Hi);930 rc = hpetConfigRegRead32(pDevIns, pThis, off + 4, &pValue->s.Hi); 929 931 } 930 932 DEVHPET_UNLOCK(pDevIns, pThis); … … 936 938 937 939 /** 938 * @callback_method_impl{FNIOMMMIO WRITE}939 */ 940 PDMBOTHCBDECL(int) hpetMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb)940 * @callback_method_impl{FNIOMMMIONEWWRITE} 941 */ 942 static DECLCALLBACK(VBOXSTRICTRC) hpetMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb) 941 943 { 942 944 HPET *pThis = PDMDEVINS_2_DATA(pDevIns, HPET*); 943 uint32_t idxReg = (uint32_t)(GCPhysAddr - HPET_BASE); 944 LogFlow(("hpetMMIOWrite: cb=%u reg=%03x (%RGp) val=%llx\n", 945 cb, idxReg, GCPhysAddr, cb == 4 ? *(uint32_t *)pv : cb == 8 ? *(uint64_t *)pv : 0xdeadbeef)); 945 LogFlow(("hpetMMIOWrite: cb=%u reg=%RGp val=%llx\n", 946 cb, off, cb == 4 ? *(uint32_t *)pv : cb == 8 ? *(uint64_t *)pv : 0xdeadbeef)); 946 947 NOREF(pvUser); 947 948 Assert(cb == 4 || cb == 8); 948 949 949 intrc;950 VBOXSTRICTRC rc; 950 951 if (cb == 4) 951 952 { 952 if ( idxReg >= 0x100 && idxReg< 0x400)953 if (off >= 0x100 && off < 0x400) 953 954 rc = hpetTimerRegWrite32(pDevIns, pThis, 954 ( idxReg- 0x100) / 0x20,955 ( idxReg- 0x100) % 0x20,955 (uint32_t)(off - 0x100) / 0x20, 956 (uint32_t)(off - 0x100) % 0x20, 956 957 *(uint32_t const *)pv); 957 958 else 958 rc = hpetConfigRegWrite32(pDevIns, pThis, idxReg, *(uint32_t const *)pv);959 rc = hpetConfigRegWrite32(pDevIns, pThis, off, *(uint32_t const *)pv); 959 960 } 960 961 else … … 967 968 RTUINT64U uValue; 968 969 uValue.u = *(uint64_t const *)pv; 969 if ( idxReg >= 0x100 && idxReg< 0x400)970 { 971 uint32_t iTimer = ( idxReg- 0x100) / 0x20;972 uint32_t iTimerReg = ( idxReg- 0x100) % 0x20;970 if (off >= 0x100 && off < 0x400) 971 { 972 uint32_t iTimer = (uint32_t)(off - 0x100) / 0x20; 973 uint32_t iTimerReg = (uint32_t)(off - 0x100) % 0x20; 973 974 /** @todo Consider handling iTimerReg == HPET_TN_CMP specially here */ 974 975 rc = hpetTimerRegWrite32(pDevIns, pThis, iTimer, iTimerReg, uValue.s.Lo); … … 978 979 else 979 980 { 980 rc = hpetConfigRegWrite32(pDevIns, pThis, idxReg, uValue.s.Lo);981 rc = hpetConfigRegWrite32(pDevIns, pThis, off, uValue.s.Lo); 981 982 if (RT_LIKELY(rc == VINF_SUCCESS)) 982 rc = hpetConfigRegWrite32(pDevIns, pThis, idxReg+ 4, uValue.s.Hi);983 rc = hpetConfigRegWrite32(pDevIns, pThis, off + 4, uValue.s.Hi); 983 984 } 984 985 DEVHPET_UNLOCK_BOTH(pDevIns, pThis); … … 1415 1416 * addresses and sizes. 1416 1417 */ 1417 rc = PDMDevHlpM MIORegister(pDevIns, HPET_BASE, HPET_BAR_SIZE, pThis,1418 IOMMMIO_FLAGS_READ_DWORD_QWORD | IOMMMIO_FLAGS_WRITE_ONLY_DWORD_QWORD,1419 hpetMMIOWrite, hpetMMIORead, "HPET Memory");1418 rc = PDMDevHlpMmioCreateAndMap(pDevIns, HPET_BASE, HPET_BAR_SIZE, hpetMMIOWrite, hpetMMIORead, 1419 IOMMMIO_FLAGS_READ_DWORD_QWORD | IOMMMIO_FLAGS_WRITE_ONLY_DWORD_QWORD, 1420 "HPET Memory", &pThis->hMmio); 1420 1421 AssertRCReturn(rc, rc); 1421 1422 1422 1423 if (pDevIns->fRCEnabled) 1423 1424 { 1424 rc = PDMDevHlpMMIORegisterRC(pDevIns, HPET_BASE, HPET_BAR_SIZE, NIL_RTRCPTR /*pvUser*/, "hpetMMIOWrite", "hpetMMIORead");1425 AssertRCReturn(rc, rc);1426 1427 1425 pThis->pHpetHlpRC = pThis->pHpetHlpR3->pfnGetRCHelpers(pDevIns); 1428 1426 } … … 1430 1428 if (pDevIns->fR0Enabled) 1431 1429 { 1432 rc = PDMDevHlpMMIORegisterR0(pDevIns, HPET_BASE, HPET_BAR_SIZE, NIL_RTR0PTR /*pvUser*/, "hpetMMIOWrite", "hpetMMIORead");1433 AssertRCReturn(rc, rc);1434 1435 1430 pThis->pHpetHlpR0 = pThis->pHpetHlpR3->pfnGetR0Helpers(pDevIns); 1436 1431 AssertReturn(pThis->pHpetHlpR0 != NIL_RTR0PTR, VERR_INTERNAL_ERROR); 1437 1432 } 1438 1433 1439 /* Register SSM callbacks */ 1434 /* 1435 * Register SSM state and info item. 1436 */ 1440 1437 rc = PDMDevHlpSSMRegister3(pDevIns, HPET_SAVED_STATE_VERSION, sizeof(*pThis), hpetR3LiveExec, hpetR3SaveExec, hpetR3LoadExec); 1441 1438 AssertRCReturn(rc, rc); 1442 1439 1443 /* Register an info callback. */1444 1440 PDMDevHlpDBGFInfoRegister(pDevIns, "hpet", "Display HPET status. (no arguments)", hpetR3Info); 1445 1441 … … 1455 1451 { 1456 1452 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 1457 //PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET);1453 PHPET pThis = PDMDEVINS_2_DATA(pDevIns, PHPET); 1458 1454 //PHPETCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PHPETCC); 1459 1455 … … 1461 1457 AssertRCReturn(rc, rc); 1462 1458 1463 //int rc = PDMDevHlpMmioSetUpContext(pDevIns, pThis->hMmio, ohciMmioWrite, ohciMmioRead, NULL /*pvUser*/);1464 //AssertRCReturn(rc, rc);1459 rc = PDMDevHlpMmioSetUpContext(pDevIns, pThis->hMmio, hpetMMIOWrite, hpetMMIORead, NULL /*pvUser*/); 1460 AssertRCReturn(rc, rc); 1465 1461 1466 1462 return VINF_SUCCESS; 1467 1463 } 1468 1469 1464 1470 1465 #endif /* !IN_RING3 */
Note:
See TracChangeset
for help on using the changeset viewer.