VirtualBox

Changeset 83495 in vbox for trunk/src


Ignore:
Timestamp:
Mar 31, 2020 11:10:04 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

    r83462 r83495  
    6363
    6464/**
    65  * @name Capability Header.
     65 * @name IOMMU Capability Header.
    6666 * In accordance with the AMD spec.
    6767 * @{
     
    102102
    103103/**
    104  * @name Base Address Low Register.
     104 * @name IOMMU Base Address Low Register.
    105105 * In accordance with the AMD spec.
    106106 * @{
     
    112112#define IOMMU_BF_BASEADDR_LO_RSVD_1_13_SHIFT        1
    113113#define IOMMU_BF_BASEADDR_LO_RSVD_1_13_MASK         UINT32_C(0x00003ffe)
    114 /** Base Address[18:14]: Low Base address (Lo) of IOMMU control registers. */
    115 #define IOMMU_BF_BASEADDR_LO_ADDR_LO_SHIFT          14
    116 #define IOMMU_BF_BASEADDR_LO_ADDR_LO_MASK           UINT32_C(0x0007c000)
    117 /** Base Address[31:19]: Low Base address (Hi) of IOMMU control registers. */
    118 #define IOMMU_BF_BASEADDR_LO_ADDR_HI_SHIFT          19
    119 #define IOMMU_BF_BASEADDR_LO_ADDR_HI_MASK           UINT32_C(0xfff80000)
     114/** Base Address[31:14]: Low Base address of IOMMU MMIO control registers. */
     115#define IOMMU_BF_BASEADDR_LO_ADDR_SHIFT             14
     116#define IOMMU_BF_BASEADDR_LO_ADDR_MASK              UINT32_C(0xffffc000)
    120117RT_BF_ASSERT_COMPILE_CHECKS(IOMMU_BF_BASEADDR_LO_, UINT32_C(0), UINT32_MAX,
    121                             (ENABLE, RSVD_1_13, ADDR_LO, ADDR_HI));
     118                            (ENABLE, RSVD_1_13, ADDR));
    122119/** @} */
    123120
    124121/**
    125  * @name Range Register.
     122 * @name IOMMU Range Register.
    126123 * In accordance with the AMD spec.
    127124 * @{
     
    150147
    151148/**
    152  * @name Miscellaneous Information Register 0.
     149 * @name IOMMU Miscellaneous Information Register 0.
    153150 * In accordance with the AMD spec.
    154151 * @{
     
    180177
    181178/**
    182  * @name Miscellaneous Information Register 1.
     179 * @name IOMMU Miscellaneous Information Register 1.
    183180 * In accordance with the AMD spec.
    184181 * @{
     
    254251 * @{ */
    255252#define IOMMU_LOG_PFX                               "AMD_IOMMU"     /**< Log prefix string. */
     253#define IOMMU_SAVED_STATE_VERSION                   1               /**< The current saved state version. */
    256254#define IOMMU_PCI_VENDOR_ID                         0x1022          /**< AMD's vendor ID. */
    257255#define IOMMU_PCI_DEVICE_ID                         0xc0de          /**< VirtualBox IOMMU Device ID. */
    258256#define IOMMU_PCI_REVISION_ID                       0x01            /**< VirtualBox IOMMU Device Revision ID. */
     257#define IOMMU_MMIO_SIZE                             _16K            /**< Size of the MMIO region in bytes. */
    259258/** @} */
    260259
     
    833832AssertCompileSize(EVT_EVENT_COUNTER_ZERO, 16);
    834833
     834/* Not needed as we can initialize from bitfields and set/get using PCI config PDM helpers. */
     835#if 0
     836/**
     837 * IOMMU Capability Header (PCI).
     838 * In accordance with the AMD spec.
     839 */
     840typedef union
     841{
     842    struct
     843    {
     844        uint32_t    u8CapId : 8;        /**< Bits 7:0   - CapId: Capability ID. */
     845        uint32_t    u8CapPtr : 8;       /**< Bits 15:8  - CapPtr: Pointer (PCI config offset) to the next capability. */
     846        uint32_t    u3CapType : 3;      /**< Bits 18:16 - CapType: Capability Type. */
     847        uint32_t    u5CapRev : 5;       /**< Bits 23:19 - CapRev: Capability revision. */
     848        uint32_t    u1IoTlbSup : 1;     /**< Bit  24    - IotlbSup: IOTLB Support. */
     849        uint32_t    u1HtTunnel : 1;     /**< Bit  25    - HtTunnel: HyperTransport Tunnel translation support. */
     850        uint32_t    u1NpCache : 1;      /**< Bit  26    - NpCache: Not Present table entries are cached. */
     851        uint32_t    u1EfrSup : 1;       /**< Bit  27    - EFRSup: Extended Feature Register Support. */
     852        uint32_t    u1CapExt : 1;       /**< Bit  28    - CapExt: Misc. Information Register 1 Support. */
     853        uint32_t    u4Rsvd0 : 4;        /**< Bits 31:29 - Reserved. */
     854    } n;
     855    /** The 32-bit unsigned integer view. */
     856    uint32_t    u32;
     857} IOMMU_CAP_HDR_T;
     858AssertCompileSize(IOMMU_CAP_HDR_T, 4);
     859#endif
     860
    835861/**
    836862 * Device Table Base Address Register (MMIO).
     
    16071633    /** Alignment padding. */
    16081634    bool                        afPadding[3];
     1635    /** The MMIO handle. */
     1636    IOMMMIOHANDLE               hMmio;
    16091637
    16101638    /** @name MMIO: Control and status registers.
     
    17711799#ifndef VBOX_DEVICE_STRUCT_TESTCASE
    17721800
     1801/**
     1802 * @callback_method_impl{FNIOMMMIONEWWRITE}
     1803 */
     1804static DECLCALLBACK(VBOXSTRICTRC) iommuAmdMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb)
     1805{
     1806    /** @todo IOMMU: MMIO write. */
     1807    RT_NOREF5(pDevIns, pvUser, off, pv, cb);
     1808    return VERR_NOT_IMPLEMENTED;
     1809}
     1810
     1811
     1812/**
     1813 * @callback_method_impl{FNIOMMMIONEWREAD}
     1814 */
     1815static DECLCALLBACK(VBOXSTRICTRC) iommuAmdMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb)
     1816{
     1817    /** @todo IOMMU: MMIO read. */
     1818    RT_NOREF5(pDevIns, pvUser, off, pv, cb);
     1819    return VERR_NOT_IMPLEMENTED;
     1820}
     1821
     1822
    17731823# ifdef IN_RING3
     1824/**
     1825 * @callback_method_impl{FNSSMDEVSAVEEXEC}
     1826 */
     1827static DECLCALLBACK(int) iommuAmdR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
     1828{
     1829    /** @todo IOMMU: Save state. */
     1830    RT_NOREF2(pDevIns, pSSM);
     1831    return VERR_NOT_IMPLEMENTED;
     1832}
     1833
     1834/**
     1835 * @callback_method_impl{FNSSMDEVLOADEXEC}
     1836 */
     1837static DECLCALLBACK(int) iommuAmdR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
     1838{
     1839    /** @todo IOMMU: Load state. */
     1840    RT_NOREF4(pDevIns, pSSM, uVersion, uPass);
     1841    return VERR_NOT_IMPLEMENTED;
     1842}
     1843
     1844
    17741845/**
    17751846 * @interface_method_impl{PDMDEVREG,pfnReset}
     
    17971868{
    17981869    NOREF(iInstance);
    1799     NOREF(pCfg);
    18001870
    18011871    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
     
    18111881     * Validate and read the configuration.
    18121882     */
    1813     PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "RootComplex", "");
     1883    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "RootComplex|MmioBase", "");
    18141884
    18151885    rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "RootComplex", &pThis->fRootComplex, true);
    1816     AssertLogRelRCReturn(rc, rc);
     1886    if (RT_FAILURE(rc))
     1887        return PDMDEV_SET_ERROR(pDevIns, rc, N_("IOMMU: Failed to query \"RootComplex\""));
     1888
     1889    uint64_t u64MmioBase;
     1890    rc = pHlp->pfnCFGMQueryU64Def(pCfg, "MmioBase", &u64MmioBase, 0);
     1891    if (RT_FAILURE(rc))
     1892        return PDMDEV_SET_ERROR(pDevIns, rc, N_("IOMMU: Failed to query \"MmioBase\""));
     1893    /* Must be 16KB aligned when we don't support IOMMU performance counters.  */
     1894    if (u64MmioBase & 0x3fff)
     1895        return PDMDEV_SET_ERROR(pDevIns, rc, N_("IOMMU: \"MmioBase\" must be 16 KB aligned"));
    18171896
    18181897    /*
     
    18641943    /* Base Address Low Register. */
    18651944    PDMPciDevSetDWord(pPciDev, offBaseAddrLo,
    1866                         RT_BF_MAKE(IOMMU_BF_BASEADDR_LO_ENABLE,  0x0)       /* RW - Enable */
    1867                       | RT_BF_MAKE(IOMMU_BF_BASEADDR_LO_ADDR_LO, 0x0)       /* RW - Base address low (lo) */
    1868                       | RT_BF_MAKE(IOMMU_BF_BASEADDR_LO_ADDR_HI, 0x0));     /* RW - Base address low (hi) */
     1945                        RT_BF_MAKE(IOMMU_BF_BASEADDR_LO_ENABLE, 0x1)                    /* RW1S - Enable */
     1946                      | RT_BF_MAKE(IOMMU_BF_BASEADDR_LO_ADDR,   (u64MmioBase >> 14)));  /* RO - Base address (Lo) */
    18691947
    18701948    /* Base Address High Register. */
    1871     PDMPciDevSetDWord(pPciDev, offBaseAddrHi, 0);                           /* RW - Base address high */
     1949    PDMPciDevSetDWord(pPciDev, offBaseAddrHi, RT_HI_U32(u64MmioBase));      /* RO - Base address (Hi) */
    18721950
    18731951    /* IOMMU Range Register. */
    1874     PDMPciDevSetDWord(pPciDev, offRange,
    1875                         RT_BF_MAKE(IOMMU_BF_RANGE_UNIT_ID,      0x0)        /* RO - HyperTransport Unit ID */
    1876                       | RT_BF_MAKE(IOMMU_BF_RANGE_VALID,        0x0)        /* RW - Range Valid */
    1877                       | RT_BF_MAKE(IOMMU_BF_RANGE_BUS_NUMBER,   0x0)        /* RO - Bus number */
    1878                       | RT_BF_MAKE(IOMMU_BF_RANGE_FIRST_DEVICE, 0x0)        /* RO - First device */
    1879                       | RT_BF_MAKE(IOMMU_BF_RANGE_LAST_DEVICE,  0x0));      /* RO - Last device */
     1952    PDMPciDevSetDWord(pPciDev, offRange, 0x0);                              /* RO - Range register. */
    18801953
    18811954    /* Misc. Information Register 0. */
     
    19161989                      | RT_BF_MAKE(IOMMU_BF_MSI_MAP_CAPHDR_FIXED,    0x1)       /* RO - MSI mapping range is fixed */
    19171990                      | RT_BF_MAKE(IOMMU_BF_MSI_MAP_CAPHDR_CAP_TYPE, 0x15));    /* RO - MSI mapping capability */
     1991
     1992    /*
     1993     * Register the PCI device with PDM.
     1994     */
     1995    rc = PDMDevHlpPCIRegister(pDevIns, pDevIns->apPciDevs[0]);
     1996    AssertRCReturn(rc, rc);
     1997
     1998    /*
     1999     * Map MMIO registers.
     2000     */
     2001    rc = PDMDevHlpMmioCreateAndMap(pDevIns, u64MmioBase, _16K, iommuAmdMmioWrite, iommuAmdMmioRead,
     2002                                   IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU,
     2003                                   "IOMMU-AMD", &pThis->hMmio);
     2004    AssertRCReturn(rc, rc);
     2005
     2006    /*
     2007     * Register saved state.
     2008     */
     2009    rc = PDMDevHlpSSMRegisterEx(pDevIns, IOMMU_SAVED_STATE_VERSION, sizeof(IOMMU), NULL,
     2010                                NULL, NULL, NULL,
     2011                                NULL, iommuAmdR3SaveExec, NULL,
     2012                                NULL, iommuAmdR3LoadExec, NULL);
     2013    AssertRCReturn(rc, rc);
    19182014
    19192015    return VINF_SUCCESS;
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