VirtualBox

Changeset 82218 in vbox for trunk/src


Ignore:
Timestamp:
Nov 26, 2019 11:16:13 AM (5 years ago)
Author:
vboxsync
Message:

MsixCommon: Refactored the MMIO bits, changing the registration flags and code to make more sense (don't know it is correct). bugref:9218

Location:
trunk/src/VBox/Devices/Bus
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Bus/DevPciIch9.cpp

    r82073 r82218  
    980980    pPciDev->Int.s.pfnConfigRead    = NULL;
    981981    pPciDev->Int.s.pfnConfigWrite   = NULL;
     982    pPciDev->Int.s.hMmioMsix        = NIL_IOMMMIOHANDLE;
    982983    if (pBus->fTypePiix3 && pPciDev->cbConfig > 256)
    983984        pPciDev->cbConfig = 256;
  • trunk/src/VBox/Devices/Bus/MsixCommon.cpp

    r81035 r82218  
    2424#include <VBox/log.h>
    2525#include <VBox/vmm/mm.h>
     26#include <VBox/AssertGuest.h>
    2627
    2728#include <iprt/assert.h>
     
    117118}
    118119
    119 
    120 PDMBOTHCBDECL(int) msixR3MMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
     120/**
     121 * @callback_method_impl{FNIOMMMIONEWREAD}
     122 */
     123static DECLCALLBACK(VBOXSTRICTRC) msixR3MMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb)
    121124{
    122125    PPDMPCIDEV pPciDev = (PPDMPCIDEV)pvUser;
    123     uint32_t   off     = (uint32_t)(GCPhysAddr & 0xffff);
    124     LogFlowFunc(("GCPhysAddr=%RGp cb=%d\n", GCPhysAddr, cb));
    125 
    126     /// @todo qword accesses?
    127126    RT_NOREF(pDevIns);
    128     AssertMsgReturn(cb == 4, ("MSI-X must be accessed with 4-byte reads\n"), VERR_INTERNAL_ERROR);
    129     AssertMsgReturn(off + cb <= pPciDev->Int.s.cbMsixRegion, ("Out of bounds access for the MSI-X region\n"), VINF_IOM_MMIO_UNUSED_FF);
     127
     128    /* Validate IOM behaviour. */
     129    Assert(cb == 4);
     130    Assert((off & 3) == 0);
     131
     132    /* Do the read if it's within the MSI state. */
     133    ASSERT_GUEST_MSG_RETURN(off + cb <= pPciDev->Int.s.cbMsixRegion, ("Out of bounds access for the MSI-X region\n"),
     134                            VINF_IOM_MMIO_UNUSED_FF);
    130135    *(uint32_t *)pv = *(uint32_t *)&pPciDev->abMsixState[off];
    131136
     137    LogFlowFunc(("off=%RGp cb=%d -> %#010RX32\n", off, cb, *(uint32_t *)pv));
    132138    return VINF_SUCCESS;
    133139}
    134140
    135 PDMBOTHCBDECL(int) msixR3MMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb)
     141/**
     142 * @callback_method_impl{FNIOMMMIONEWWRITE}
     143 */
     144static DECLCALLBACK(VBOXSTRICTRC) msixR3MMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb)
    136145{
    137146    PPDMPCIDEV pPciDev = (PPDMPCIDEV)pvUser;
    138     uint32_t   off     = (uint32_t)(GCPhysAddr & 0xffff);
    139     LogFlowFunc(("GCPhysAddr=%RGp cb=%d\n", GCPhysAddr, cb));
    140 
    141     /// @todo qword accesses?
    142     AssertMsgReturn(cb == 4, ("MSI-X must be accessed with 4-byte reads\n"), VERR_INTERNAL_ERROR);
    143     AssertMsgReturn(off + cb <= pPciDev->Int.s.offMsixPba, ("Trying to write to PBA\n"), VINF_SUCCESS);
     147    LogFlowFunc(("off=%RGp cb=%d %#010RX32\n", off, cb, *(uint32_t *)pv));
     148
     149    /* Validate IOM behaviour. */
     150    Assert(cb == 4);
     151    Assert((off & 3) == 0);
     152
     153    /* Do the write if it's within the MSI state. */
     154    ASSERT_GUEST_MSG_RETURN(off + cb <= pPciDev->Int.s.offMsixPba, ("Trying to write to PBA\n"),
     155                            VINF_SUCCESS);
    144156    *(uint32_t *)&pPciDev->abMsixState[off] = *(uint32_t *)pv;
    145157
     
    147159    msixR3CheckPendingVector(pDevIns, (PCPDMPCIHLP)pPciDev->Int.s.pvPciBusPtrR3, pPciDev, off / VBOX_MSIX_ENTRY_SIZE);
    148160    return VINF_SUCCESS;
    149 }
    150 
    151 /**
    152  * @callback_method_impl{FNPCIIOREGIONMAP}
    153  */
    154 static DECLCALLBACK(int) msixR3Map(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
    155                                    RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType)
    156 {
    157     Assert(enmType == PCI_ADDRESS_SPACE_MEM);
    158     NOREF(iRegion); NOREF(enmType);
    159 
    160     return PDMDevHlpMMIORegister(pDevIns, GCPhysAddress, cb, pPciDev,
    161                                  IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU,
    162                                  msixR3MMIOWrite, msixR3MMIORead, "MSI-X tables");
    163161}
    164162
     
    179177    uint8_t    iBar        = pMsiReg->iMsixBar;
    180178
    181     AssertMsgReturn(cVectors <= VBOX_MSIX_MAX_ENTRIES,
    182                     ("Too many MSI-X vectors: %d\n", cVectors),
    183                     VERR_TOO_MUCH_DATA);
    184     AssertMsgReturn(iBar <= 5,
    185                     ("Using wrong BAR for MSI-X: %d\n", iBar),
    186                     VERR_INVALID_PARAMETER);
    187 
     179    AssertMsgReturn(cVectors <= VBOX_MSIX_MAX_ENTRIES, ("Too many MSI-X vectors: %d\n", cVectors), VERR_TOO_MUCH_DATA);
     180    AssertMsgReturn(iBar <= 5, ("Using wrong BAR for MSI-X: %d\n", iBar), VERR_INVALID_PARAMETER);
    188181    Assert(iCapOffset != 0 && iCapOffset < 0xff && iNextOffset < 0xff);
    189182
    190     int rc = VINF_SUCCESS;
    191183    uint16_t cbPba = cVectors / 8;
    192184    if (cVectors % 8)
     
    200192    if (!pciDevIsPassthrough(pDev))
    201193    {
    202         rc = PDMDevHlpPCIIORegionRegister(pDev->Int.s.CTX_SUFF(pDevIns), iBar, cbMsixRegion, PCI_ADDRESS_SPACE_MEM, msixR3Map);
    203         if (RT_FAILURE (rc))
    204             return rc;
     194        /** @todo r=bird: This used to be IOMMMIO_FLAGS_READ_PASSTHRU |
     195         * IOMMMIO_FLAGS_WRITE_PASSTHRU with the callbacks asserting and
     196         * returning VERR_INTERNAL_ERROR on non-dword reads.  That is of
     197         * course certifiable insane behaviour.  So, instead I've changed it
     198         * so the callbacks only see dword reads and writes.  I'm not at all
     199         * sure about the read-missing behaviour, but it seems like a good
     200         * idea for now. */
     201        int rc = PDMDevHlpPCIIORegionCreateMmio(pDev->Int.s.CTX_SUFF(pDevIns), iBar, cbMsixRegion, PCI_ADDRESS_SPACE_MEM,
     202                                                msixR3MMIOWrite, msixR3MMIORead, pDev,
     203                                                IOMMMIO_FLAGS_READ_DWORD | IOMMMIO_FLAGS_WRITE_DWORD_READ_MISSING,
     204                                                "MSI-X tables", &pDev->Int.s.hMmioMsix);
     205        AssertRCReturn(rc, rc);
    205206    }
    206207
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