VirtualBox

Changeset 83703 in vbox


Ignore:
Timestamp:
Apr 15, 2020 2:58:14 PM (4 years ago)
Author:
vboxsync
Message:

AMD IOMMU: bugref:9654 Bits.

File:
1 edited

Legend:

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

    r83684 r83703  
    12661266} IOMMU_HW_EVT_STATUS_T;
    12671267AssertCompileSize(IOMMU_HW_EVT_STATUS_T, 8);
     1268#define IOMMU_HW_EVT_STATUS_VALID_MASK      UINT64_C(0x0000000000000003)
    12681269
    12691270/**
     
    18421843typedef struct IOMMU
    18431844{
     1845    /** The event semaphore the command thread waits on. */
     1846    SUPSEMEVENT                 hEvtCmdThread;
     1847    /** The MMIO handle. */
     1848    IOMMMIOHANDLE               hMmio;
    18441849    /** Whether this IOMMU is at the top of the PCI tree hierarchy or not. */
    18451850    bool                        fRootComplex;
    18461851    /** Alignment padding. */
    1847     bool                        afPadding[3];
    1848     /** The MMIO handle. */
    1849     IOMMMIOHANDLE               hMmio;
    1850     /** The event semaphore the command thread waits on. */
    1851     SUPSEMEVENT                 hEvtCmdThread;
     1852    bool                        afPadding[7];
    18521853
    18531854    /** @name MMIO: Control and status registers.
     
    19851986typedef struct IOMMUR3
    19861987{
     1988    /** Device instance. */
     1989    PPDMDEVINSR3            pDevInsR3;
    19871990    /** The IOMMU helpers. */
    19881991    PCPDMIOMMUHLPR3         pIommuHlp;
     
    19982001typedef struct IOMMUR0
    19992002{
     2003    /** Device instance. */
     2004    PPDMDEVINSR0            pDevInsR0;
    20002005    /** The IOMMU helpers. */
    20012006    PCPDMIOMMUHLPR0         pIommuHlp;
     
    20092014typedef struct IOMMURC
    20102015{
     2016    /** Device instance. */
     2017    PPDMDEVINSR0            pDevInsRC;
    20112018    /** The IOMMU helpers. */
    20122019    PCPDMIOMMUHLPRC         pIommuHlp;
     
    20162023
    20172024/** The IOMMU device state for the current context. */
    2018 typedef CTX_SUFF(IOMMU) IOMMUCC;
     2025typedef CTX_SUFF(IOMMU)  IOMMUCC;
    20192026/** Pointer to the IOMMU device state for the current context. */
    20202027typedef CTX_SUFF(PIOMMU) PIOMMUCC;
     
    21172124}
    21182125
     2126
    21192127/**
    21202128 * Writes the Event Log Base Address Register.
     
    21592167    pThis->PprLogBaseAddr.u64 = u64Value & IOMMU_PPR_LOG_BAR_VALID_MASK;
    21602168    iommuAmdCheckBufferLength(pThis->PprLogBaseAddr.n.u4PprLogLen, __PRETTY_FUNCTION__);
     2169    return VINF_SUCCESS;
     2170}
     2171
     2172
     2173/**
     2174 * Writes the Hardware Event Register (Hi).
     2175 */
     2176static VBOXSTRICTRC iommuAmdHwEvtHi_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
     2177{
     2178    /** @todo IOMMU: Why the heck is this marked read/write by the AMD IOMMU spec? */
     2179    RT_NOREF(pDevIns, iReg);
     2180    Log((IOMMU_LOG_PFX ": Writing %#RX64 to hardware event (Hi) register!\n", u64Value));
     2181    pThis->HwEvtHi.u64 = u64Value;
     2182    return VINF_SUCCESS;
     2183}
     2184
     2185
     2186/**
     2187 * Writes the Hardware Event Register (Lo).
     2188 */
     2189static VBOXSTRICTRC iommuAmdHwEvtLo_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
     2190{
     2191    /** @todo IOMMU: Why the heck is this marked read/write by the AMD IOMMU spec? */
     2192    RT_NOREF(pDevIns, iReg);
     2193    Log((IOMMU_LOG_PFX ": Writing %#RX64 to hardware event (Lo) register!\n", u64Value));
     2194    pThis->HwEvtLo = u64Value;
     2195    return VINF_SUCCESS;
     2196}
     2197
     2198
     2199/**
     2200 * Writes the Hardware Event Status Register.
     2201 */
     2202static VBOXSTRICTRC iommuAmdHwEvtStatus_w(PPDMDEVINS pDevIns, PIOMMU pThis, uint32_t iReg, uint64_t u64Value)
     2203{
     2204    RT_NOREF(pDevIns, iReg);
     2205
     2206    /* Ignore all unrecognized bits. */
     2207    u64Value &= IOMMU_HW_EVT_STATUS_VALID_MASK;
     2208
     2209    /*
     2210     * The two bits (HEO and HEV) are RW1C (Read/Write 1-to-Clear; writing 0 has no effect).
     2211     * If the current status bits or the bits being written are both 0, we've nothing to do.
     2212     * The Overflow bit (bit 1) is only valid when the Valid bit (bit 0) is 1.
     2213     */
     2214    uint64_t HwStatus = pThis->HwEvtStatus.u64;
     2215    if (!(HwStatus & RT_BIT(0)))
     2216        return VINF_SUCCESS;
     2217    if (u64Value & HwStatus & RT_BIT(0))
     2218        HwStatus &= ~RT_BIT(0);
     2219    if (u64Value & HwStatus & RT_BIT(1))
     2220        HwStatus &= ~RT_BIT(1);
     2221    pThis->HwEvtStatus.u64 = HwStatus;
    21612222    return VINF_SUCCESS;
    21622223}
     
    23542415
    23552416        case IOMMU_MMIO_OFF_PPR_LOG_BAR:         return iommuAmdPprLogBar_w(pDevIns, pThis, off, uValue);
    2356         case IOMMU_MMIO_OFF_HW_EVT_HI:
    2357         case IOMMU_MMIO_OFF_HW_EVT_LO:           return iommuAmdIgnore_w(pDevIns, pThis, off, uValue);
    2358         case IOMMU_MMIO_OFF_HW_EVT_STATUS:       /** @todo IOMMU: HW Event Status is RW. Figure this out later. */
     2417        case IOMMU_MMIO_OFF_HW_EVT_HI:           return iommuAmdHwEvtHi_w(pDevIns, pThis, off, uValue);
     2418        case IOMMU_MMIO_OFF_HW_EVT_LO:           return iommuAmdHwEvtLo_w(pDevIns, pThis, off, uValue);
     2419        case IOMMU_MMIO_OFF_HW_EVT_STATUS:       return iommuAmdHwEvtStatus_w(pDevIns, pThis, off, uValue);
    23592420
    23602421        case IOMMU_MMIO_OFF_GALOG_BAR:
     
    24742535 *
    24752536 * @returns Strict VBox status code.
    2476  * @param   pThis       The IOMMU device state.
     2537 * @param   pDevIns     The device instance.
    24772538 * @param   off         Offset in bytes.
    24782539 * @param   puResult    Where to store the value being read.
    24792540 */
    2480 static VBOXSTRICTRC iommuAmdReadRegister(PCIOMMU pThis, uint32_t off, uint64_t *puResult)
     2541static VBOXSTRICTRC iommuAmdReadRegister(PPDMDEVINS pDevIns, uint32_t off, uint64_t *puResult)
    24812542{
    24822543    Assert(off < IOMMU_MMIO_REGION_SIZE);
    24832544    Assert(!(off & 7) || !(off & 3));
     2545
     2546    PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
     2547    Assert(pThis);
    24842548
    24852549    /** @todo IOMMU: fine-grained locking? */
     
    26182682
    26192683    uint64_t uResult;
    2620     PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
    2621     VBOXSTRICTRC rcStrict = iommuAmdReadRegister(pThis, off, &uResult);
     2684    VBOXSTRICTRC rcStrict = iommuAmdReadRegister(pDevIns, off, &uResult);
    26222685    if (cb == 8)
    26232686        *(uint64_t *)pv = uResult;
     
    33663429    LogFlowFunc(("\n"));
    33673430
    3368     NOREF(pThisCC); /** @todo IOMMU: populate CC data. */
     3431    pThisCC->pDevInsR3 = pDevIns;
    33693432
    33703433    /*
     
    35363599{
    35373600    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
     3601    PIOMMU   pThis   = PDMDEVINS_2_DATA(pDevIns, PIOMMU);
     3602    PIOMMUCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUCC);
     3603
     3604    pThisCC->CTX_SUFF(pDevIns) = pDevIns;
     3605
     3606    int rc = PDMDevHlpMmioSetUpContext(pDevIns, pThis->hMmio, iommuAmdMmioWrite, iommuAmdMmioRead, NULL /* pvUser */);
     3607    AssertRCReturn(rc, rc);
     3608
    35383609    return VINF_SUCCESS;
    35393610}
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