VirtualBox

Changeset 83941 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Apr 23, 2020 10:22:56 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137493
Message:

AMD IOMMU: bugref:9654 Hook into PCIPhys[Read|Write] for intercepting and translating device accesses through the IOMMU.

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

Legend:

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

    r83851 r83941  
    407407/**
    408408 * The Device ID.
    409  * In accordance with the AMD spec.
    410  */
    411 typedef union
    412 {
    413     struct
    414     {
    415         uint16_t    uFunction : 3;  /**< Bits 2:0  - Function. */
    416         uint16_t    uDevice : 5;    /**< Bits 7:3  - Device. */
    417         uint16_t    uBus : 8;       /**< Bits 15:8 - Bus. */
     409 * In accordance with VirtualBox's PCI configuration.
     410 */
     411typedef union
     412{
     413    struct
     414    {
     415        uint16_t    u3Function : 3;  /**< Bits 2:0   - Function. */
     416        uint16_t    u9Device : 9;    /**< Bits 11:3  - Device. */
     417        uint16_t    u4Bus : 4;       /**< Bits 15:12 - Bus. */
    418418    } n;
    419419    /** The unsigned integer view. */
     
    975975AssertCompileSize(EVT_EVENT_COUNTER_ZERO, 16);
    976976
    977 /* Not needed as we can initialize from bitfields and set/get using PCI config PDM helpers. */
    978 #if 0
    979977/**
    980978 * IOMMU Capability Header (PCI).
     
    994992        uint32_t    u1EfrSup : 1;       /**< Bit  27    - EFRSup: Extended Feature Register Support. */
    995993        uint32_t    u1CapExt : 1;       /**< Bit  28    - CapExt: Misc. Information Register 1 Support. */
    996         uint32_t    u4Rsvd0 : 4;        /**< Bits 31:29 - Reserved. */
     994        uint32_t    u3Rsvd0 : 3;        /**< Bits 31:29 - Reserved. */
    997995    } n;
    998996    /** The 32-bit unsigned integer view. */
     
    1000998} IOMMU_CAP_HDR_T;
    1001999AssertCompileSize(IOMMU_CAP_HDR_T, 4);
    1002 #endif
    10031000
    10041001/**
     
    18871884typedef struct IOMMU
    18881885{
    1889     /** IOMMU device index. */
     1886    /** IOMMU device index (0 is at the top of the PCI tree hierarchy). */
    18901887    uint32_t                    idxIommu;
    18911888    /** Alignment padding. */
     
    18951892    /** The MMIO handle. */
    18961893    IOMMMIOHANDLE               hMmio;
    1897     /** Whether this IOMMU is at the top of the PCI tree hierarchy or not. */
    1898     bool                        fRootComplex;
    1899     /** Alignment padding. */
    1900     bool                        afPadding[7];
    19011894
    19021895    /** @name PCI: Base capability block registers.
    19031896     * @{ */
    1904     IOMMU_BAR_T                 IommuBar;
     1897    IOMMU_BAR_T                 IommuBar;           /**< IOMMU base address register. */
    19051898    /** @} */
    19061899
     
    19621955    /** @name MMIO: x2APIC Control registers.
    19631956     * @{ */
    1964     IOMMU_XT_GEN_INTR_CTRL_T    XtGenIntrCtrl;     /**< IOMMU X2APIC General interrupt control register. */
    1965     IOMMU_XT_PPR_INTR_CTRL_T    XtPprIntrCtrl;     /**< IOMMU X2APIC PPR interrupt control register. */
    1966     IOMMU_XT_GALOG_INTR_CTRL_T  XtGALogIntrCtrl;   /**< IOMMU X2APIC Guest Log interrupt control register. */
     1957    IOMMU_XT_GEN_INTR_CTRL_T    XtGenIntrCtrl;      /**< IOMMU X2APIC General interrupt control register. */
     1958    IOMMU_XT_PPR_INTR_CTRL_T    XtPprIntrCtrl;      /**< IOMMU X2APIC PPR interrupt control register. */
     1959    IOMMU_XT_GALOG_INTR_CTRL_T  XtGALogIntrCtrl;    /**< IOMMU X2APIC Guest Log interrupt control register. */
    19671960    /** @} */
    19681961
    19691962    /** @name MMIO: MARC registers.
    19701963     * @{ */
    1971     MARC_APER_T                 aMarcApers[4];     /**< MARC Aperture Registers. */
     1964    MARC_APER_T                 aMarcApers[4];      /**< MARC Aperture Registers. */
    19721965    /** @} */
    19731966
    19741967    /** @name MMIO: Reserved register.
    19751968     *  @{ */
    1976     IOMMU_RSVD_REG_T            RsvdReg;           /**< IOMMU Reserved Register. */
     1969    IOMMU_RSVD_REG_T            RsvdReg;            /**< IOMMU Reserved Register. */
    19771970    /** @} */
    19781971
     
    20292022/** Pointer to the const IOMMU device state. */
    20302023typedef const struct IOMMU *PCIOMMU;
     2024AssertCompileMemberAlignment(IOMMU, hEvtCmdThread, 8);
     2025AssertCompileMemberAlignment(IOMMU, hMmio, 8);
     2026AssertCompileMemberAlignment(IOMMU, IommuBar, 8);
     2027
    20312028
    20322029/**
     
    24502447 *
    24512448 * @returns VBox status code.
    2452  * @param   pDevIns     The device instance.
     2449 * @param   pDevIns     The IOMMU device instance.
    24532450 * @param   pThread     The command thread.
    24542451 */
     
    24632460 *
    24642461 * @returns VBox status code.
    2465  * @param   pDevIns     The device instance.
     2462 * @param   pDevIns     The IOMMU device instance.
    24662463 * @param   pThread     The command thread.
    24672464 */
     
    24952492 *
    24962493 * @returns Strict VBox status code.
    2497  * @param   pDevIns     The device instance.
     2494 * @param   pDevIns     The IOMMU device instance.
    24982495 * @param   off         MMIO byte offset to the register.
    24992496 * @param   cb          The size of the write access.
     
    26392636 *
    26402637 * @returns Strict VBox status code.
    2641  * @param   pDevIns     The device instance.
     2638 * @param   pDevIns     The IOMMU device instance.
    26422639 * @param   off         Offset in bytes.
    26432640 * @param   puResult    Where to store the value being read.
     
    27932790    return VINF_SUCCESS;
    27942791}
     2792
     2793
     2794/**
     2795 * Memory read transaction from a downstream device.
     2796 *
     2797 * @returns VBox status code.
     2798 * @param   pDevIns     The IOMMU device instance.
     2799 * @param   uDeviceId   The device identifier (bus, device, function).
     2800 * @param   uDva        The device virtual address being read.
     2801 * @param   cbRead      The number of bytes being read.
     2802 * @param   GCPhysOut   Where to store the translated physical address.
     2803 *
     2804 * @thread  Any.
     2805 */
     2806static int iommuAmdDeviceMemRead(PPDMDEVINS pDevIns, uint16_t uDeviceId, uint64_t uDva, size_t cbRead, PRTGCPHYS pGCPhysOut)
     2807{
     2808    RT_NOREF(pDevIns, uDeviceId, uDva, cbRead, pGCPhysOut);
     2809    return VERR_NOT_IMPLEMENTED;
     2810}
     2811
     2812
     2813/**
     2814 * Memory write transaction from a downstream device.
     2815 *
     2816 * @returns VBox status code.
     2817 * @param   pDevIns     The IOMMU device instance.
     2818 * @param   uDeviceId   The device identifier (bus, device, function).
     2819 * @param   uDva        The device virtual address being written.
     2820 * @param   cbRead      The number of bytes being written.
     2821 * @param   GCPhysOut   Where to store the translated physical address.
     2822 *
     2823 * @thread  Any.
     2824 */
     2825static int iommuAmdDeviceMemWrite(PPDMDEVINS pDevIns, uint16_t uDeviceId, uint64_t uDva, size_t cbWrite, PRTGCPHYS pGCPhysOut)
     2826{
     2827    RT_NOREF(pDevIns, uDeviceId, uDva, cbWrite, pGCPhysOut);
     2828    return VERR_NOT_IMPLEMENTED;
     2829}
     2830
    27952831
    27962832/**
     
    36613697     * Register the IOMMU with PDM.
    36623698     */
    3663     PDMIOMMUREGCC IommuReg;
     3699    PDMIOMMUREGR3 IommuReg;
    36643700    RT_ZERO(IommuReg);
    3665     IommuReg.u32Version = PDM_IOMMUREGCC_VERSION;
    3666     IommuReg.u32TheEnd  = PDM_IOMMUREGCC_VERSION;
     3701    IommuReg.u32Version  = PDM_IOMMUREGCC_VERSION;
     3702    IommuReg.pfnMemRead  = iommuAmdDeviceMemRead;
     3703    IommuReg.pfnMemWrite = iommuAmdDeviceMemWrite;
     3704    IommuReg.u32TheEnd   = PDM_IOMMUREGCC_VERSION;
    36673705    rc = PDMDevHlpIommuRegister(pDevIns, &IommuReg, &pThisCC->CTX_SUFF(pIommuHlp), &pThis->idxIommu);
    36683706    if (RT_FAILURE(rc))
     
    38333871    PDMIOMMUREGCC IommuReg;
    38343872    RT_ZERO(IommuReg);
    3835     IommuReg.u32Version = PDM_IOMMUREGCC_VERSION;
    3836     IommuReg.idxIommu   = pThis->idxIommu;
    3837     IommuReg.u32TheEnd  = PDM_IOMMUREGCC_VERSION;
     3873    IommuReg.u32Version  = PDM_IOMMUREGCC_VERSION;
     3874    IommuReg.idxIommu    = pThis->idxIommu;
     3875    IommuReg.pfnMemRead  = iommuAmdDeviceMemRead;
     3876    IommuReg.pfnMemWrite = iommuAmdDeviceMemWrite;
     3877    IommuReg.u32TheEnd   = PDM_IOMMUREGCC_VERSION;
    38383878    rc = PDMDevHlpIommuSetUpContext(pDevIns, &IommuReg, &pThisCC->CTX_SUFF(pIommuHlp));
    38393879    AssertRCReturn(rc, rc);
  • trunk/src/VBox/Devices/Makefile.kmk

    r83816 r83941  
    137137        VBOX_WITH_DMI_CHASSIS \
    138138        VBOX_WITH_DMI_OEMSTRINGS \
    139         $(if $(VBOX_WITH_NEW_LPC_DEVICE),VBOX_WITH_NEW_LPC_DEVICE,)
     139        $(if $(VBOX_WITH_NEW_LPC_DEVICE),VBOX_WITH_NEW_LPC_DEVICE,) \
     140        $(if $(VBOX_WITH_IOMMU_AMD),VBOX_WITH_IOMMU_AMD,)
    140141 VBoxDD_DEFS.win         = _WIN32_WINNT=0x0510
    141142 ifeq ($(KBUILD_TARGET_ARCH),x86)
     
    918919   VBoxDDRC_DEFS.darwin   = VBOX_WITH_2X_4GB_ADDR_SPACE
    919920  endif
    920   VBoxDDRC_DEFS           = $(if $(VBOX_WITH_HGCM),VBOX_WITH_HGCM,)
     921  VBoxDDRC_DEFS           = $(if $(VBOX_WITH_HGCM),VBOX_WITH_HGCM,) $(if $(VBOX_WITH_IOMMU_AMD),VBOX_WITH_IOMMU_AMD,)
    921922  VBoxDDRC_INCS           = build $(VBOX_GRAPHICS_INCS)
    922923  VBoxDDRC_SOURCES        = \
     
    11001101 #
    11011102 VBoxDDR0_TEMPLATE       = VBoxR0
    1102  VBoxDDR0_DEFS           = IN_RT_R0 $(if $(VBOX_WITH_HGCM),VBOX_WITH_HGCM,) # - WTF is IN_RT_R0 doing here?
     1103 VBoxDDR0_DEFS           = \
     1104        $(if $(VBOX_WITH_HGCM),VBOX_WITH_HGCM,) \
     1105        $(if $(VBOX_WITH_IOMMU_AMD),VBOX_WITH_IOMMU_AMD,) \
     1106        IN_RT_R0  # - WTF is IN_RT_R0 doing here?
    11031107 VBoxDDR0_DEFS.win      += VBOX_WITH_WIN_PARPORT_SUP
    11041108 VBoxDDR0_INCS           = build $(VBOX_GRAPHICS_INCS)
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette