VirtualBox

Ignore:
Timestamp:
Apr 20, 2020 11:35:38 AM (5 years ago)
Author:
vboxsync
Message:

AMD IOMMU: bugref:9654 Bits.

File:
1 edited

Legend:

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

    r83742 r83851  
    2626#include "VBoxDD.h"
    2727#include <iprt/x86.h>
     28#include <iprt/string.h>
    2829
    2930
     
    18861887typedef struct IOMMU
    18871888{
     1889    /** IOMMU device index. */
     1890    uint32_t                    idxIommu;
     1891    /** Alignment padding. */
     1892    uint32_t                    uPadding0;
    18881893    /** The event semaphore the command thread waits on. */
    18891894    SUPSEMEVENT                 hEvtCmdThread;
     
    20332038    PPDMDEVINSR3            pDevInsR3;
    20342039    /** The IOMMU helpers. */
    2035     PCPDMIOMMUHLPR3         pIommuHlp;
     2040    PCPDMIOMMUHLPR3         pIommuHlpR3;
    20362041    /** The command thread handle. */
    20372042    R3PTRTYPE(PPDMTHREAD)   pCmdThread;
     
    20482053    PPDMDEVINSR0            pDevInsR0;
    20492054    /** The IOMMU helpers. */
    2050     PCPDMIOMMUHLPR0         pIommuHlp;
     2055    PCPDMIOMMUHLPR0         pIommuHlpR0;
    20512056} IOMMUR0;
    20522057/** Pointer to the ring-0 IOMMU device state. */
     
    20612066    PPDMDEVINSR0            pDevInsRC;
    20622067    /** The IOMMU helpers. */
    2063     PCPDMIOMMUHLPRC         pIommuHlp;
     2068    PCPDMIOMMUHLPRC         pIommuHlpRC;
    20642069} IOMMURC;
    20652070/** Pointer to the raw-mode IOMMU device state. */
     
    20862091
    20872092/**
    2088  * Returns the number of entries and buffer size for a power-of-2 encoded length.
     2093 * Gets the buffer length length corresponding to a base address.
    20892094 *
    2090  * @param   uEncodedLen     The length to decode.
     2095 * @param   uEncodedLen     The length to decode (power-of-2 encoded).
    20912096 * @param   pcEntries       Where to store the number of entries. Optional, can be
    20922097 *                          NULL.
     
    20962101 * @remarks Both @a pcEntries and @a pcbBuffer cannot both be NULL.
    20972102 */
    2098 static void iommuAmdDecodeBufferLength(uint8_t uEncodedLen, uint32_t *pcEntries, uint32_t *pcbBuffer)
     2103static void iommuAmdGetBaseBufferLength(uint8_t uEncodedLen, uint32_t *pcEntries, uint32_t *pcbBuffer)
    20992104{
    21002105    uint32_t cEntries;
     
    21342139#ifdef VBOX_STRICT
    21352140    uint32_t cEntries;
    2136     iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, NULL /* pcbBuffer */);
     2141    iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, NULL /* pcbBuffer */);
    21372142    if (!cEntries)
    21382143        Log((IOMMU_LOG_PFX ": %s: Invalid length %#x\n", pszFunc, uEncodedLen));
     
    23782383
    23792384    /*
    2380      * IOMMU behavior is undefined when software writes a value value outside the buffer length.
    2381      * In our emtulation, we ignore the write entirely.
     2385     * IOMMU behavior is undefined when software writes a value outside the buffer length.
     2386     * In our emulation, we ignore the write entirely.
    23822387     */
    23832388    uint32_t const      offBuf     = u64Value & IOMMU_CMD_BUF_HEAD_PTR_VALID_MASK;
    23842389    CMD_BUF_BAR_T const CmdBufBar  = pThis->CmdBufBaseAddr;
    23852390    uint32_t            cbBuf;
    2386     iommuAmdDecodeBufferLength(CmdBufBar.n.u4CmdLen, NULL, &cbBuf);
     2391    iommuAmdGetBaseBufferLength(CmdBufBar.n.u4CmdLen, NULL, &cbBuf);
    23872392    if (offBuf >= cbBuf)
    23882393    {
     
    28542859    switch (uAddress)
    28552860    {
    2856         case IOMMU_PCI_OFF_CAP_HDR:         /* All fields are read-only. */
     2861        case IOMMU_PCI_OFF_CAP_HDR:         /* All bits are read-only. */
    28572862        case IOMMU_PCI_OFF_RANGE_REG:       /* We don't have any devices integrated with the IOMMU. */
    28582863        case IOMMU_PCI_OFF_MISCINFO_REG_0:  /* We don't support MSI-X. */
     
    29542959        uint32_t      cbBuffer;
    29552960        uint8_t const uEncodedLen = CmdBufBar.n.u4CmdLen;
    2956         iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
     2961        iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, &cbBuffer);
    29572962        pHlp->pfnPrintf(pHlp, "  Command buffer BAR                      = %#RX64\n", CmdBufBar.u64);
    29582963        if (fVerbose)
     
    29692974        uint32_t      cbBuffer;
    29702975        uint8_t const uEncodedLen = EvtLogBar.n.u4EvtLen;
    2971         iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
     2976        iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, &cbBuffer);
    29722977        pHlp->pfnPrintf(pHlp, "  Event log BAR                           = %#RX64\n", EvtLogBar.u64);
    29732978        if (fVerbose)
     
    30903095        uint32_t      cbBuffer;
    30913096        uint8_t const uEncodedLen = PprLogBar.n.u4PprLogLen;
    3092         iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
     3097        iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, &cbBuffer);
    30933098        pHlp->pfnPrintf(pHlp, "  PPR Log BAR                             = %#RX64\n",   PprLogBar.u64);
    30943099        if (fVerbose)
     
    31273132        uint32_t      cbBuffer;
    31283133        uint8_t const uEncodedLen = GALogBar.n.u4GALogLen;
    3129         iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
     3134        iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, &cbBuffer);
    31303135        pHlp->pfnPrintf(pHlp, "  Guest Log BAR                           = %#RX64\n",    GALogBar.u64);
    31313136        if (fVerbose)
     
    31493154        uint32_t      cbBuffer;
    31503155        uint8_t const uEncodedLen = PprLogBBar.n.u4PprLogLen;
    3151         iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
     3156        iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, &cbBuffer);
    31523157        pHlp->pfnPrintf(pHlp, "  PPR Log B BAR                           = %#RX64\n",   PprLogBBar.u64);
    31533158        if (fVerbose)
     
    31643169        uint32_t      cbBuffer;
    31653170        uint8_t const uEncodedLen = EvtLogBBar.n.u4EvtLen;
    3166         iommuAmdDecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);
     3171        iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, &cbBuffer);
    31673172        pHlp->pfnPrintf(pHlp, "  Event Log B BAR                         = %#RX64\n",   EvtLogBBar.u64);
    31683173        if (fVerbose)
     
    36543659
    36553660    /*
     3661     * Register the IOMMU with PDM.
     3662     */
     3663    PDMIOMMUREGCC IommuReg;
     3664    RT_ZERO(IommuReg);
     3665    IommuReg.u32Version = PDM_IOMMUREGCC_VERSION;
     3666    IommuReg.u32TheEnd  = PDM_IOMMUREGCC_VERSION;
     3667    rc = PDMDevHlpIommuRegister(pDevIns, &IommuReg, &pThisCC->CTX_SUFF(pIommuHlp), &pThis->idxIommu);
     3668    if (RT_FAILURE(rc))
     3669        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to register ourselves as an IOMMU device"));
     3670    if (pThisCC->CTX_SUFF(pIommuHlp)->u32Version != PDM_IOMMUHLPR3_VERSION)
     3671        return PDMDevHlpVMSetError(pDevIns, VERR_VERSION_MISMATCH, RT_SRC_POS,
     3672                                   N_("IOMMU helper version mismatch; got %#x expected %#x"),
     3673                                   pThisCC->CTX_SUFF(pIommuHlp)->u32Version, PDM_IOMMUHLPR3_VERSION);
     3674    if (pThisCC->CTX_SUFF(pIommuHlp)->u32TheEnd != PDM_IOMMUHLPR3_VERSION)
     3675        return PDMDevHlpVMSetError(pDevIns, VERR_VERSION_MISMATCH, RT_SRC_POS,
     3676                                   N_("IOMMU helper end-version mismatch; got %#x expected %#x"),
     3677                                   pThisCC->CTX_SUFF(pIommuHlp)->u32TheEnd, PDM_IOMMUHLPR3_VERSION);
     3678
     3679    /*
    36563680     * Initialize read-only PCI configuration space.
    36573681     */
     
    38023826    pThisCC->CTX_SUFF(pDevIns) = pDevIns;
    38033827
     3828    /* Set up the MMIO RZ handlers. */
    38043829    int rc = PDMDevHlpMmioSetUpContext(pDevIns, pThis->hMmio, iommuAmdMmioWrite, iommuAmdMmioRead, NULL /* pvUser */);
     3830    AssertRCReturn(rc, rc);
     3831
     3832    /* Set up the IOMMU RZ callbacks. */
     3833    PDMIOMMUREGCC IommuReg;
     3834    RT_ZERO(IommuReg);
     3835    IommuReg.u32Version = PDM_IOMMUREGCC_VERSION;
     3836    IommuReg.idxIommu   = pThis->idxIommu;
     3837    IommuReg.u32TheEnd  = PDM_IOMMUREGCC_VERSION;
     3838    rc = PDMDevHlpIommuSetUpContext(pDevIns, &IommuReg, &pThisCC->CTX_SUFF(pIommuHlp));
    38053839    AssertRCReturn(rc, rc);
    38063840
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