VirtualBox

Changeset 87307 in vbox


Ignore:
Timestamp:
Jan 19, 2021 5:52:50 PM (4 years ago)
Author:
vboxsync
Message:

DevPlayground.cpp: Added some very simple MMIO handling code that uses one backing page per function to preserve some content written and make it possible to read back, just as an example. Fixed saved state.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Samples/DevPlayground.cpp

    r82968 r87307  
    6363    /** The MMIO region \#2 handle. */
    6464    IOMMMIOHANDLE   hMmio2;
     65    /** Backing storage. */
     66    uint8_t         abBacking[4096];
    6567} VBOXPLAYGROUNDDEVICEFUNCTION;
    6668/** Pointer to a PCI function of the playground device. */
     
    8688*********************************************************************************************************************************/
    8789
     90/**
     91 * @callback_method_impl{FNIOMMMIONEWREAD}
     92 */
    8893static DECLCALLBACK(VBOXSTRICTRC) devPlaygroundMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb)
    8994{
     95    PVBOXPLAYGROUNDDEVICEFUNCTION pFun = (PVBOXPLAYGROUNDDEVICEFUNCTION)pvUser;
    9096    NOREF(pDevIns);
    91     NOREF(pvUser);
    92     NOREF(off);
    93     NOREF(pv);
    94     NOREF(cb);
    95     return VINF_SUCCESS;
    96 }
    97 
    98 
     97
     98#ifdef LOG_ENABLED
     99    unsigned const cbLog  = cb;
     100    RTGCPHYS       offLog = off;
     101#endif
     102    uint8_t *pbDst = (uint8_t *)pv;
     103    while (cb-- > 0)
     104    {
     105        *pbDst = pFun->abBacking[off % RT_ELEMENTS(pFun->abBacking)];
     106        pbDst++;
     107        off++;
     108    }
     109
     110    Log(("DevPlayGr/[%u]: READ  off=%RGv cb=%u: %.*Rhxs\n", pFun->iFun, offLog, cbLog, cbLog, pv));
     111    return VINF_SUCCESS;
     112}
     113
     114
     115/**
     116 * @callback_method_impl{FNIOMMMIONEWWRITE}
     117 */
    99118static DECLCALLBACK(VBOXSTRICTRC) devPlaygroundMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb)
    100119{
     120    PVBOXPLAYGROUNDDEVICEFUNCTION pFun = (PVBOXPLAYGROUNDDEVICEFUNCTION)pvUser;
    101121    NOREF(pDevIns);
    102     NOREF(pvUser);
    103     NOREF(off);
    104     NOREF(pv);
    105     NOREF(cb);
     122    Log(("DevPlayGr/[%u]: WRITE off=%RGv cb=%u: %.*Rhxs\n", pFun->iFun, off, cb, cb, pv));
     123
     124    uint8_t const *pbSrc = (uint8_t const *)pv;
     125    while (cb-- > 0)
     126    {
     127        pFun->abBacking[off % RT_ELEMENTS(pFun->abBacking)] = *pbSrc;
     128        pbSrc++;
     129        off++;
     130    }
     131
    106132    return VINF_SUCCESS;
    107133}
     
    143169    }
    144170#else
    145 RT_NOREF(pSSM, pHlp);
     171    pHlp->pfnSSMPutStrZ(pSSM, "playground");
    146172#endif
    147173
     
    292318        RTStrPrintf(pFun->szMmio0, sizeof(pFun->szMmio0), "PG-F%d-BAR0", iPciFun);
    293319        rc = PDMDevHlpMmioCreate(pDevIns, cbFirst, pPciDev, 0 /*iPciRegion*/,
    294                                  devPlaygroundMMIOWrite, devPlaygroundMMIORead, NULL /*pvUser*/,
     320                                 devPlaygroundMMIOWrite, devPlaygroundMMIORead, pFun,
    295321                                 IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU, pFun->szMmio0, &pFun->hMmio0);
    296322        AssertLogRelRCReturn(rc, rc);
     
    306332        RTStrPrintf(pFun->szMmio2, sizeof(pFun->szMmio2), "PG-F%d-BAR2", iPciFun);
    307333        rc = PDMDevHlpMmioCreate(pDevIns, cbSecond, pPciDev, 2 << 16 /*iPciRegion*/,
    308                                  devPlaygroundMMIOWrite, devPlaygroundMMIORead, NULL /*pvUser*/,
     334                                 devPlaygroundMMIOWrite, devPlaygroundMMIORead, pFun,
    309335                                 IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU, pFun->szMmio2, &pFun->hMmio2);
    310336        AssertLogRelRCReturn(rc, rc);
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