VirtualBox

Changeset 81933 in vbox


Ignore:
Timestamp:
Nov 18, 2019 8:52:53 AM (5 years ago)
Author:
vboxsync
Message:

DevLpc-new: Converted to new PDM device style. bugref:9218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/DevLpc-new.cpp

    r81591 r81933  
    4646typedef struct LPCSTATE
    4747{
    48     /** Pointer to the ring-3 device instance. */
    49     PPDMDEVINSR3    pDevInsR3;
    50 
    5148    /** The root complex base address. */
    5249    RTGCPHYS32      GCPhys32Rcba;
    53     /** Set if R0/RC context is enabled.   */
    54     bool            fRZEnabled;
    5550    /** The ICH version (7 or 9). */
    5651    uint8_t         uIchVersion;
    5752    /** Explicit padding. */
    58     uint8_t         abPadding[HC_ARCH_BITS == 32 ? 2 : 6];
     53    uint8_t         abPadding[HC_ARCH_BITS == 32 ? 3 : 7];
    5954
    6055    /** Number of MMIO reads. */
     
    6661    /** Number of PCI config space writes. */
    6762    STAMCOUNTER     StatPciCfgWrites;
     63
     64    /** Handle to the MMIO region. */
     65    IOMMMIOHANDLE   hMmio;
    6866} LPCSTATE;
    6967/** Pointer to the LPC state. */
     
    7472
    7573/**
    76  * @callback_method_impl{FNIOMMMIOREAD}
    77  */
    78 PDMBOTHCBDECL(int) lpcMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
     74 * @callback_method_impl{FNIOMMMIONEWREAD}
     75 */
     76static DECLCALLBACK(VBOXSTRICTRC) lpcMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb)
    7977{
    8078    RT_NOREF(pvUser, cb);
    8179    PLPCSTATE        pThis  = PDMDEVINS_2_DATA(pDevIns, PLPCSTATE);
    82     RTGCPHYS32 const offReg = (RTGCPHYS32)GCPhysAddr - pThis->GCPhys32Rcba;
    83     Assert(cb == 4); Assert(!(GCPhysAddr & 3)); /* IOMMMIO_FLAGS_READ_DWORD should make sure of this */
     80    Assert(cb == 4); Assert(!(off & 3)); /* IOMMMIO_FLAGS_READ_DWORD should make sure of this */
    8481
    8582    uint32_t *puValue = (uint32_t *)pv;
    86     if (offReg == LPC_REG_HPET_CONFIG_POINTER)
     83    if (off == LPC_REG_HPET_CONFIG_POINTER)
    8784    {
    8885        *puValue = 0xf0;
    8986        Log(("lpcMmioRead: HPET_CONFIG_POINTER: %#x\n", *puValue));
    9087    }
    91     else if (offReg == LPC_REG_GCS)
     88    else if (off == LPC_REG_GCS)
    9289    {
    9390        *puValue = 0;
     
    9794    {
    9895        *puValue = 0;
    99         Log(("lpcMmioRead: WARNING! Unknown register %#x!\n", offReg));
     96        Log(("lpcMmioRead: WARNING! Unknown register %#RGp!\n", off));
    10097    }
    10198
     
    106103
    107104/**
    108  * @callback_method_impl{FNIOMMMIOWRITE}
    109  */
    110 PDMBOTHCBDECL(int) lpcMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb)
    111 {
     105 * @callback_method_impl{FNIOMMMIONEWWRITE}
     106 */
     107static DECLCALLBACK(VBOXSTRICTRC) lpcMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb)
     108{
     109    PLPCSTATE        pThis  = PDMDEVINS_2_DATA(pDevIns, PLPCSTATE);
    112110    RT_NOREF(pvUser, pv);
    113     PLPCSTATE        pThis  = PDMDEVINS_2_DATA(pDevIns, PLPCSTATE);
    114     RTGCPHYS32 const offReg = (RTGCPHYS32)GCPhysAddr - pThis->GCPhys32Rcba;
    115111
    116112    if (cb == 4)
    117113    {
    118         if (offReg == LPC_REG_GCS)
     114        if (off == LPC_REG_GCS)
    119115            Log(("lpcMmioWrite: Ignorning write to GCS: %.*Rhxs\n", cb, pv));
    120116        else
    121             Log(("lpcMmioWrite: Ignorning write to unknown register %#x: %.*Rhxs\n", offReg, cb, pv));
     117            Log(("lpcMmioWrite: Ignorning write to unknown register %#RGp: %.*Rhxs\n", off, cb, pv));
    122118    }
    123119    else
    124         Log(("lpcMmioWrite: WARNING! Ignoring non-DWORD write to offReg=%#x: %.*Rhxs\n", offReg, cb, pv));
     120        Log(("lpcMmioWrite: WARNING! Ignoring non-DWORD write to off=%#RGp: %.*Rhxs\n", off, cb, pv));
    125121
    126122    STAM_REL_COUNTER_INC(&pThis->StatMmioWrites);
     
    214210{
    215211    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    216     PLPCSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PLPCSTATE);
     212    PLPCSTATE       pThis = PDMDEVINS_2_DATA(pDevIns, PLPCSTATE);
     213    PCPDMDEVHLPR3   pHlp  = pDevIns->pHlpR3;
    217214    Assert(iInstance == 0); RT_NOREF(iInstance);
    218 
    219     /*
    220      * Initialize state.
    221      */
    222     pThis->pDevInsR3 = pDevIns;
    223215
    224216    /*
    225217     * Read configuration.
    226218     */
    227     PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "RZEnabled|RCBA|ICHVersion", "");
    228 
    229     int rc = CFGMR3QueryBoolDef(pCfg, "RZEnabled", &pThis->fRZEnabled, true);
    230     if (RT_FAILURE(rc))
    231         return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to query boolean value \"RZEnabled\""));
    232 
    233     rc = CFGMR3QueryU8Def(pCfg, "ICHVersion", &pThis->uIchVersion, 7 /** @todo 9 */);
     219    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "RCBA|ICHVersion", "");
     220
     221    int rc = pHlp->pfnCFGMQueryU8Def(pCfg, "ICHVersion", &pThis->uIchVersion, 7 /** @todo 9 */);
    234222    if (RT_FAILURE(rc))
    235223        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to query boolean value \"ICHVersion\""));
     
    238226        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Invalid \"ICHVersion\" value (must be 7 or 9)"));
    239227
    240     rc = CFGMR3QueryU32Def(pCfg, "RCBA", &pThis->GCPhys32Rcba, UINT32_C(0xfed1c000));
     228    rc = pHlp->pfnCFGMQueryU32Def(pCfg, "RCBA", &pThis->GCPhys32Rcba, UINT32_C(0xfed1c000));
    241229    if (RT_FAILURE(rc))
    242230        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to query boolean value \"RCBA\""));
     
    359347    /** @todo This should actually be done when RCBA is enabled, but was
    360348     *        mentioned above we just want this working. */
    361     rc = PDMDevHlpMMIORegister(pDevIns, pThis->GCPhys32Rcba, 0x4000, pThis,
    362                                IOMMMIO_FLAGS_READ_DWORD | IOMMMIO_FLAGS_WRITE_PASSTHRU,
    363                                lpcMmioWrite, lpcMmioRead, "LPC Memory");
     349    rc = PDMDevHlpMmioCreateAndMap(pDevIns, pThis->GCPhys32Rcba, 0x4000, lpcMmioWrite, lpcMmioRead,
     350                                   IOMMMIO_FLAGS_READ_DWORD | IOMMMIO_FLAGS_WRITE_PASSTHRU,
     351                                   "LPC Memory", &pThis->hMmio);
    364352    AssertRCReturn(rc, rc);
    365353
     
    368356     * Debug info and stats.
    369357     */
    370     PDMDevHlpSTAMRegister(pDevIns, &pThis->StatMmioReads,    STAMTYPE_COUNTER, "/Devices/LPC/MMIOReads", STAMUNIT_OCCURENCES, "MMIO reads");
    371     PDMDevHlpSTAMRegister(pDevIns, &pThis->StatMmioWrites,   STAMTYPE_COUNTER, "/Devices/LPC/MMIOWrites", STAMUNIT_OCCURENCES, "MMIO writes");
    372     PDMDevHlpSTAMRegister(pDevIns, &pThis->StatPciCfgReads,  STAMTYPE_COUNTER, "/Devices/LPC/ConfigReads", STAMUNIT_OCCURENCES, "PCI config reads");
    373     PDMDevHlpSTAMRegister(pDevIns, &pThis->StatPciCfgWrites, STAMTYPE_COUNTER, "/Devices/LPC/ConfigWrites", STAMUNIT_OCCURENCES, "PCI config writes");
     358    PDMDevHlpSTAMRegister(pDevIns, &pThis->StatMmioReads,    STAMTYPE_COUNTER, "MMIOReads", STAMUNIT_OCCURENCES, "MMIO reads");
     359    PDMDevHlpSTAMRegister(pDevIns, &pThis->StatMmioWrites,   STAMTYPE_COUNTER, "MMIOWrites", STAMUNIT_OCCURENCES, "MMIO writes");
     360    PDMDevHlpSTAMRegister(pDevIns, &pThis->StatPciCfgReads,  STAMTYPE_COUNTER, "ConfigReads", STAMUNIT_OCCURENCES, "PCI config reads");
     361    PDMDevHlpSTAMRegister(pDevIns, &pThis->StatPciCfgWrites, STAMTYPE_COUNTER, "ConfigWrites", STAMUNIT_OCCURENCES, "PCI config writes");
    374362
    375363    PDMDevHlpDBGFInfoRegister(pDevIns, "lpc", "Display LPC status. (no arguments)", lpcInfo);
     
    388376    /* .uReserved0 = */             0,
    389377    /* .szName = */                 "lpc",
    390     /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS,
     378    /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_NEW_STYLE,
    391379    /* .fClass = */                 PDM_DEVREG_CLASS_MISC,
    392380    /* .cMaxInstances = */          1,
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