VirtualBox

Changeset 81959 in vbox for trunk/src/VBox/Devices/PC


Ignore:
Timestamp:
Nov 18, 2019 6:24:54 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134756
Message:

DevHPET: Convert MMIO handlers. bugref:9218

File:
1 edited

Legend:

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

    r81955 r81959  
    278278    /** Size alignment padding. */
    279279    uint8_t                     abPadding0[7];
     280
     281    /** The handle of the MMIO region.   */
     282    IOMMMIOHANDLE               hMmio;
    280283} HPET;
    281284/** Pointer to the shared HPET device state. */
     
    446449 * Reads a HPET timer register.
    447450 *
    448  * @returns VBox strict status code.
    449451 * @param   pDevIns             The device instance.
    450452 * @param   pThis               The HPET instance.
     
    455457 * @remarks ASSUMES the caller holds the HPET lock.
    456458 */
    457 static int hpetTimerRegRead32(PPDMDEVINS pDevIns, PCHPET pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t *pu32Value)
     459static void hpetTimerRegRead32(PPDMDEVINS pDevIns, PCHPET pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t *pu32Value)
    458460{
    459461    Assert(PDMDevHlpCritSectIsOwner(pDevIns, &pThis->CritSect));
     
    465467        LogRelMax(10, ("HPET: Using timer above configured range: %d\n", iTimerNo));
    466468        *pu32Value = 0;
    467         return VINF_SUCCESS;
     469        return;
    468470    }
    469471
     
    505507    }
    506508    *pu32Value = u32Value;
    507     return VINF_SUCCESS;
    508509}
    509510
     
    523524 *          the TM lock.
    524525 */
    525 static int hpetTimerRegWrite32(PPDMDEVINS pDevIns, PHPET pThis, uint32_t iTimerNo, uint32_t iTimerReg, uint32_t u32NewValue)
     526static VBOXSTRICTRC hpetTimerRegWrite32(PPDMDEVINS pDevIns, PHPET pThis, uint32_t iTimerNo,
     527                                        uint32_t iTimerReg, uint32_t u32NewValue)
    526528{
    527529    Assert(!PDMDevHlpCritSectIsOwner(pDevIns, &pThis->CritSect) || PDMDevHlpTimerIsLockOwner(pDevIns, pThis->aTimers[0].hTimer));
     
    728730 *          the TM lock.
    729731 */
    730 static int hpetConfigRegWrite32(PPDMDEVINS pDevIns, PHPET pThis, uint32_t idxReg, uint32_t u32NewValue)
     732static VBOXSTRICTRC hpetConfigRegWrite32(PPDMDEVINS pDevIns, PHPET pThis, uint32_t idxReg, uint32_t u32NewValue)
    731733{
    732734    Assert(!PDMDevHlpCritSectIsOwner(pDevIns, &pThis->CritSect) || PDMDevHlpTimerIsLockOwner(pDevIns, pThis->aTimers[0].hTimer));
    733735
    734     int rc = VINF_SUCCESS;
     736    VBOXSTRICTRC rc = VINF_SUCCESS;
    735737    switch (idxReg)
    736738    {
     
    862864
    863865/**
    864  * @callback_method_impl{FNIOMMMIOREAD}
    865  */
    866 PDMBOTHCBDECL(int)  hpetMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
     866 * @callback_method_impl{FNIOMMMIONEWREAD}
     867 */
     868static DECLCALLBACK(VBOXSTRICTRC) hpetMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb)
    867869{
    868870    HPET      *pThis  = PDMDEVINS_2_DATA(pDevIns, HPET*);
    869     uint32_t const  idxReg = (uint32_t)(GCPhysAddr - HPET_BASE);
    870871    NOREF(pvUser);
    871872    Assert(cb == 4 || cb == 8);
    872873
    873     LogFlow(("hpetMMIORead (%d): %llx (%x)\n", cb, (uint64_t)GCPhysAddr, idxReg));
    874 
    875     int rc;
     874    LogFlow(("hpetMMIORead (%d): %RGp\n", cb, off));
     875
     876    VBOXSTRICTRC rc;
    876877    if (cb == 4)
    877878    {
     
    879880         * 4-byte access.
    880881         */
    881         if (idxReg >= 0x100 && idxReg < 0x400)
     882        if (off >= 0x100 && off < 0x400)
    882883        {
    883884            DEVHPET_LOCK_RETURN(pDevIns, pThis, VINF_IOM_R3_MMIO_READ);
    884             rc = hpetTimerRegRead32(pDevIns, pThis,
    885                                     (idxReg - 0x100) / 0x20,
    886                                     (idxReg - 0x100) % 0x20,
    887                                     (uint32_t *)pv);
     885            hpetTimerRegRead32(pDevIns, pThis,
     886                               (uint32_t)(off - 0x100) / 0x20,
     887                               (uint32_t)(off - 0x100) % 0x20,
     888                               (uint32_t *)pv);
    888889            DEVHPET_UNLOCK(pDevIns, pThis);
     890            rc = VINF_SUCCESS;
    889891        }
    890892        else
    891             rc = hpetConfigRegRead32(pDevIns, pThis, idxReg, (uint32_t *)pv);
     893            rc = hpetConfigRegRead32(pDevIns, pThis, off, (uint32_t *)pv);
    892894    }
    893895    else
     
    898900         */
    899901        PRTUINT64U pValue = (PRTUINT64U)pv;
    900         if (idxReg == HPET_COUNTER)
     902        if (off == HPET_COUNTER)
    901903        {
    902904            /* When reading HPET counter we must read it in a single read,
     
    913915        {
    914916            DEVHPET_LOCK_RETURN(pDevIns, pThis, VINF_IOM_R3_MMIO_READ);
    915             if (idxReg >= 0x100 && idxReg < 0x400)
     917            if (off >= 0x100 && off < 0x400)
    916918            {
    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;
    922924            }
    923925            else
    924926            {
    925927                /* 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);
    927929                if (rc == VINF_SUCCESS)
    928                     rc = hpetConfigRegRead32(pDevIns, pThis, idxReg + 4, &pValue->s.Hi);
     930                    rc = hpetConfigRegRead32(pDevIns, pThis, off + 4, &pValue->s.Hi);
    929931            }
    930932            DEVHPET_UNLOCK(pDevIns, pThis);
     
    936938
    937939/**
    938  * @callback_method_impl{FNIOMMMIOWRITE}
    939  */
    940 PDMBOTHCBDECL(int) hpetMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb)
     940 * @callback_method_impl{FNIOMMMIONEWWRITE}
     941 */
     942static DECLCALLBACK(VBOXSTRICTRC) hpetMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb)
    941943{
    942944    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));
    946947    NOREF(pvUser);
    947948    Assert(cb == 4 || cb == 8);
    948949
    949     int rc;
     950    VBOXSTRICTRC rc;
    950951    if (cb == 4)
    951952    {
    952         if (idxReg >= 0x100 && idxReg < 0x400)
     953        if (off >= 0x100 && off < 0x400)
    953954            rc = hpetTimerRegWrite32(pDevIns, pThis,
    954                                      (idxReg - 0x100) / 0x20,
    955                                      (idxReg - 0x100) % 0x20,
     955                                     (uint32_t)(off - 0x100) / 0x20,
     956                                     (uint32_t)(off - 0x100) % 0x20,
    956957                                     *(uint32_t const *)pv);
    957958        else
    958             rc = hpetConfigRegWrite32(pDevIns, pThis, idxReg, *(uint32_t const *)pv);
     959            rc = hpetConfigRegWrite32(pDevIns, pThis, off, *(uint32_t const *)pv);
    959960    }
    960961    else
     
    967968        RTUINT64U uValue;
    968969        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;
    973974    /** @todo Consider handling iTimerReg == HPET_TN_CMP specially here */
    974975            rc = hpetTimerRegWrite32(pDevIns, pThis, iTimer, iTimerReg, uValue.s.Lo);
     
    978979        else
    979980        {
    980             rc = hpetConfigRegWrite32(pDevIns, pThis, idxReg, uValue.s.Lo);
     981            rc = hpetConfigRegWrite32(pDevIns, pThis, off, uValue.s.Lo);
    981982            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);
    983984        }
    984985        DEVHPET_UNLOCK_BOTH(pDevIns, pThis);
     
    14151416     * addresses and sizes.
    14161417     */
    1417     rc = PDMDevHlpMMIORegister(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);
    14201421    AssertRCReturn(rc, rc);
    14211422
    14221423    if (pDevIns->fRCEnabled)
    14231424    {
    1424         rc = PDMDevHlpMMIORegisterRC(pDevIns, HPET_BASE, HPET_BAR_SIZE, NIL_RTRCPTR /*pvUser*/, "hpetMMIOWrite", "hpetMMIORead");
    1425         AssertRCReturn(rc, rc);
    1426 
    14271425        pThis->pHpetHlpRC = pThis->pHpetHlpR3->pfnGetRCHelpers(pDevIns);
    14281426    }
     
    14301428    if (pDevIns->fR0Enabled)
    14311429    {
    1432         rc = PDMDevHlpMMIORegisterR0(pDevIns, HPET_BASE, HPET_BAR_SIZE, NIL_RTR0PTR /*pvUser*/, "hpetMMIOWrite", "hpetMMIORead");
    1433         AssertRCReturn(rc, rc);
    1434 
    14351430        pThis->pHpetHlpR0 = pThis->pHpetHlpR3->pfnGetR0Helpers(pDevIns);
    14361431        AssertReturn(pThis->pHpetHlpR0 != NIL_RTR0PTR, VERR_INTERNAL_ERROR);
    14371432    }
    14381433
    1439     /* Register SSM callbacks */
     1434    /*
     1435     * Register SSM state and info item.
     1436     */
    14401437    rc = PDMDevHlpSSMRegister3(pDevIns, HPET_SAVED_STATE_VERSION, sizeof(*pThis), hpetR3LiveExec, hpetR3SaveExec, hpetR3LoadExec);
    14411438    AssertRCReturn(rc, rc);
    14421439
    1443     /* Register an info callback. */
    14441440    PDMDevHlpDBGFInfoRegister(pDevIns, "hpet", "Display HPET status. (no arguments)", hpetR3Info);
    14451441
     
    14551451{
    14561452    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    1457     //PHPET   pThis   = PDMDEVINS_2_DATA(pDevIns, PHPET);
     1453    PHPET   pThis   = PDMDEVINS_2_DATA(pDevIns, PHPET);
    14581454    //PHPETCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PHPETCC);
    14591455
     
    14611457    AssertRCReturn(rc, rc);
    14621458
    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);
    14651461
    14661462    return VINF_SUCCESS;
    14671463}
    1468 
    14691464
    14701465#endif /* !IN_RING3 */
Note: See TracChangeset for help on using the changeset viewer.

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