Changeset 83851 in vbox for trunk/src/VBox/Devices/Bus/DevIommuAmd.cpp
- Timestamp:
- Apr 20, 2020 11:35:38 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Bus/DevIommuAmd.cpp
r83742 r83851 26 26 #include "VBoxDD.h" 27 27 #include <iprt/x86.h> 28 #include <iprt/string.h> 28 29 29 30 … … 1886 1887 typedef struct IOMMU 1887 1888 { 1889 /** IOMMU device index. */ 1890 uint32_t idxIommu; 1891 /** Alignment padding. */ 1892 uint32_t uPadding0; 1888 1893 /** The event semaphore the command thread waits on. */ 1889 1894 SUPSEMEVENT hEvtCmdThread; … … 2033 2038 PPDMDEVINSR3 pDevInsR3; 2034 2039 /** The IOMMU helpers. */ 2035 PCPDMIOMMUHLPR3 pIommuHlp ;2040 PCPDMIOMMUHLPR3 pIommuHlpR3; 2036 2041 /** The command thread handle. */ 2037 2042 R3PTRTYPE(PPDMTHREAD) pCmdThread; … … 2048 2053 PPDMDEVINSR0 pDevInsR0; 2049 2054 /** The IOMMU helpers. */ 2050 PCPDMIOMMUHLPR0 pIommuHlp ;2055 PCPDMIOMMUHLPR0 pIommuHlpR0; 2051 2056 } IOMMUR0; 2052 2057 /** Pointer to the ring-0 IOMMU device state. */ … … 2061 2066 PPDMDEVINSR0 pDevInsRC; 2062 2067 /** The IOMMU helpers. */ 2063 PCPDMIOMMUHLPRC pIommuHlp ;2068 PCPDMIOMMUHLPRC pIommuHlpRC; 2064 2069 } IOMMURC; 2065 2070 /** Pointer to the raw-mode IOMMU device state. */ … … 2086 2091 2087 2092 /** 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. 2089 2094 * 2090 * @param uEncodedLen The length to decode .2095 * @param uEncodedLen The length to decode (power-of-2 encoded). 2091 2096 * @param pcEntries Where to store the number of entries. Optional, can be 2092 2097 * NULL. … … 2096 2101 * @remarks Both @a pcEntries and @a pcbBuffer cannot both be NULL. 2097 2102 */ 2098 static void iommuAmd DecodeBufferLength(uint8_t uEncodedLen, uint32_t *pcEntries, uint32_t *pcbBuffer)2103 static void iommuAmdGetBaseBufferLength(uint8_t uEncodedLen, uint32_t *pcEntries, uint32_t *pcbBuffer) 2099 2104 { 2100 2105 uint32_t cEntries; … … 2134 2139 #ifdef VBOX_STRICT 2135 2140 uint32_t cEntries; 2136 iommuAmd DecodeBufferLength(uEncodedLen, &cEntries, NULL /* pcbBuffer */);2141 iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, NULL /* pcbBuffer */); 2137 2142 if (!cEntries) 2138 2143 Log((IOMMU_LOG_PFX ": %s: Invalid length %#x\n", pszFunc, uEncodedLen)); … … 2378 2383 2379 2384 /* 2380 * IOMMU behavior is undefined when software writes a value valueoutside the buffer length.2381 * In our em tulation, 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. 2382 2387 */ 2383 2388 uint32_t const offBuf = u64Value & IOMMU_CMD_BUF_HEAD_PTR_VALID_MASK; 2384 2389 CMD_BUF_BAR_T const CmdBufBar = pThis->CmdBufBaseAddr; 2385 2390 uint32_t cbBuf; 2386 iommuAmd DecodeBufferLength(CmdBufBar.n.u4CmdLen, NULL, &cbBuf);2391 iommuAmdGetBaseBufferLength(CmdBufBar.n.u4CmdLen, NULL, &cbBuf); 2387 2392 if (offBuf >= cbBuf) 2388 2393 { … … 2854 2859 switch (uAddress) 2855 2860 { 2856 case IOMMU_PCI_OFF_CAP_HDR: /* All fields are read-only. */2861 case IOMMU_PCI_OFF_CAP_HDR: /* All bits are read-only. */ 2857 2862 case IOMMU_PCI_OFF_RANGE_REG: /* We don't have any devices integrated with the IOMMU. */ 2858 2863 case IOMMU_PCI_OFF_MISCINFO_REG_0: /* We don't support MSI-X. */ … … 2954 2959 uint32_t cbBuffer; 2955 2960 uint8_t const uEncodedLen = CmdBufBar.n.u4CmdLen; 2956 iommuAmd DecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);2961 iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, &cbBuffer); 2957 2962 pHlp->pfnPrintf(pHlp, " Command buffer BAR = %#RX64\n", CmdBufBar.u64); 2958 2963 if (fVerbose) … … 2969 2974 uint32_t cbBuffer; 2970 2975 uint8_t const uEncodedLen = EvtLogBar.n.u4EvtLen; 2971 iommuAmd DecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);2976 iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, &cbBuffer); 2972 2977 pHlp->pfnPrintf(pHlp, " Event log BAR = %#RX64\n", EvtLogBar.u64); 2973 2978 if (fVerbose) … … 3090 3095 uint32_t cbBuffer; 3091 3096 uint8_t const uEncodedLen = PprLogBar.n.u4PprLogLen; 3092 iommuAmd DecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);3097 iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, &cbBuffer); 3093 3098 pHlp->pfnPrintf(pHlp, " PPR Log BAR = %#RX64\n", PprLogBar.u64); 3094 3099 if (fVerbose) … … 3127 3132 uint32_t cbBuffer; 3128 3133 uint8_t const uEncodedLen = GALogBar.n.u4GALogLen; 3129 iommuAmd DecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);3134 iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, &cbBuffer); 3130 3135 pHlp->pfnPrintf(pHlp, " Guest Log BAR = %#RX64\n", GALogBar.u64); 3131 3136 if (fVerbose) … … 3149 3154 uint32_t cbBuffer; 3150 3155 uint8_t const uEncodedLen = PprLogBBar.n.u4PprLogLen; 3151 iommuAmd DecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);3156 iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, &cbBuffer); 3152 3157 pHlp->pfnPrintf(pHlp, " PPR Log B BAR = %#RX64\n", PprLogBBar.u64); 3153 3158 if (fVerbose) … … 3164 3169 uint32_t cbBuffer; 3165 3170 uint8_t const uEncodedLen = EvtLogBBar.n.u4EvtLen; 3166 iommuAmd DecodeBufferLength(uEncodedLen, &cEntries, &cbBuffer);3171 iommuAmdGetBaseBufferLength(uEncodedLen, &cEntries, &cbBuffer); 3167 3172 pHlp->pfnPrintf(pHlp, " Event Log B BAR = %#RX64\n", EvtLogBBar.u64); 3168 3173 if (fVerbose) … … 3654 3659 3655 3660 /* 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 /* 3656 3680 * Initialize read-only PCI configuration space. 3657 3681 */ … … 3802 3826 pThisCC->CTX_SUFF(pDevIns) = pDevIns; 3803 3827 3828 /* Set up the MMIO RZ handlers. */ 3804 3829 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)); 3805 3839 AssertRCReturn(rc, rc); 3806 3840
Note:
See TracChangeset
for help on using the changeset viewer.