VirtualBox

Changeset 87477 in vbox for trunk/src/VBox/VMM/VMMR0


Ignore:
Timestamp:
Jan 29, 2021 11:43:09 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
142499
Message:

AMD IOMMU: bugref:9654 PDM IOMMU code de-duplication and cleanup.

Location:
trunk/src/VBox/VMM/VMMR0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/PDMR0DevHlp.cpp

    r87371 r87477  
    144144    else
    145145    {
    146         Log(("pdmRCDevHlp_PCIPhysRead: caller=%p/%d: returns %Rrc - Not bus master! GCPhys=%RGp cbRead=%#zx\n",
    147              pDevIns, pDevIns->iInstance, VERR_PDM_NOT_PCI_BUS_MASTER, GCPhys, cbRead));
     146        LogFunc(("caller=%p/%d: returns %Rrc - Not bus master! GCPhys=%RGp cbRead=%#zx\n", pDevIns, pDevIns->iInstance,
     147                 VERR_PDM_NOT_PCI_BUS_MASTER, GCPhys, cbRead));
    148148        memset(pvBuf, 0xff, cbRead);
    149149        return VERR_PDM_NOT_PCI_BUS_MASTER;
     
    152152
    153153#ifdef VBOX_WITH_IOMMU_AMD
    154     /** @todo IOMMU: Optimize/re-organize things here later. */
    155     PGVM        pGVM         = pDevIns->Internal.s.pGVM;
    156     PPDMIOMMUR0 pIommu       = &pGVM->pdmr0.s.aIommus[0];
    157     PPDMDEVINS  pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    158     if (   pDevInsIommu
    159         && pDevInsIommu != pDevIns)
    160     {
    161         size_t const idxBus = pPciDev->Int.s.idxPdmBus;
    162         Assert(idxBus < RT_ELEMENTS(pGVM->pdmr0.s.aPciBuses));
    163         PPDMPCIBUSR0 pBus = &pGVM->pdmr0.s.aPciBuses[idxBus];
    164         uint16_t const uDeviceId = PCIBDF_MAKE(pBus->iBus, pPciDev->uDevFn);
    165         int rc = VINF_SUCCESS;
    166         while (cbRead > 0)
    167         {
    168             RTGCPHYS GCPhysOut;
    169             size_t   cbContig;
    170             rc = pIommu->pfnMemAccess(pDevInsIommu, uDeviceId, GCPhys, cbRead, PDMIOMMU_MEM_F_READ, &GCPhysOut, &cbContig);
    171             if (RT_SUCCESS(rc))
    172             {
    173                 /** @todo Handle strict return codes from PGMPhysRead. */
    174                 rc = pDevIns->pHlpR0->pfnPhysRead(pDevIns, GCPhysOut, pvBuf, cbRead, fFlags);
    175                 if (RT_SUCCESS(rc))
    176                 {
    177                     cbRead -= cbContig;
    178                     pvBuf   = (void *)((uintptr_t)pvBuf + cbContig);
    179                     GCPhys += cbContig;
    180                 }
    181                 else
    182                     break;
    183             }
    184             else
    185             {
    186                 Log(("pdmR0DevHlp_PCIPhysRead: IOMMU translation failed. uDeviceId=%#x GCPhys=%#RGp cb=%u rc=%Rrc\n", uDeviceId,
    187                      GCPhys, cbRead, rc));
    188                 break;
    189             }
    190         }
     154    int rc = pdmIommuMemAccessRead(pDevIns, pPciDev, GCPhys, pvBuf, cbRead, fFlags);
     155    if (RT_SUCCESS(rc) || rc != VERR_IOMMU_NOT_PRESENT)
    191156        return rc;
    192     }
    193157#endif
    194158
     
    215179    else
    216180    {
    217         Log(("pdmRCDevHlp_PCIPhysWrite: caller=%p/%d: returns %Rrc - Not bus master! GCPhys=%RGp cbWrite=%#zx\n",
    218              pDevIns, pDevIns->iInstance, VERR_PDM_NOT_PCI_BUS_MASTER, GCPhys, cbWrite));
     181        LogFunc(("caller=%p/%d: returns %Rrc - Not bus master! GCPhys=%RGp cbWrite=%#zx\n", pDevIns, pDevIns->iInstance,
     182                 VERR_PDM_NOT_PCI_BUS_MASTER, GCPhys, cbWrite));
    219183        return VERR_PDM_NOT_PCI_BUS_MASTER;
    220184    }
     
    222186
    223187#ifdef VBOX_WITH_IOMMU_AMD
    224     /** @todo IOMMU: Optimize/re-organize things here later. */
    225     PGVM        pGVM         = pDevIns->Internal.s.pGVM;
    226     PPDMIOMMUR0 pIommu       = &pGVM->pdmr0.s.aIommus[0];
    227     PPDMDEVINS  pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    228     if (   pDevInsIommu
    229         && pDevInsIommu != pDevIns)
    230     {
    231         size_t const idxBus = pPciDev->Int.s.idxPdmBus;
    232         Assert(idxBus < RT_ELEMENTS(pGVM->pdmr0.s.aPciBuses));
    233         PPDMPCIBUSR0 pBus = &pGVM->pdmr0.s.aPciBuses[idxBus];
    234         uint16_t const uDeviceId = PCIBDF_MAKE(pBus->iBus, pPciDev->uDevFn);
    235         int rc = VINF_SUCCESS;
    236         while (cbWrite > 0)
    237         {
    238             RTGCPHYS GCPhysOut;
    239             size_t   cbContig;
    240             rc = pIommu->pfnMemAccess(pDevInsIommu, uDeviceId, GCPhys, cbWrite, PDMIOMMU_MEM_F_WRITE, &GCPhysOut, &cbContig);
    241             if (RT_SUCCESS(rc))
    242             {
    243                 /** @todo Handle strict return codes from PGMPhysWrite. */
    244                 rc = pDevIns->pHlpR0->pfnPhysWrite(pDevIns, GCPhysOut, pvBuf, cbWrite, fFlags);
    245                 if (RT_SUCCESS(rc))
    246                 {
    247                     cbWrite -= cbContig;
    248                     pvBuf    = (const void *)((uintptr_t)pvBuf + cbContig);
    249                     GCPhys  += cbContig;
    250                 }
    251                 else
    252                     break;
    253             }
    254             else
    255             {
    256                 Log(("pdmR0DevHlp_PCIPhysWrite: IOMMU translation failed. uDeviceId=%#x GCPhys=%#RGp cb=%u rc=%Rrc\n", uDeviceId,
    257                      GCPhys, cbWrite, rc));
    258                 break;
    259             }
    260         }
     188    int rc = pdmIommuMemAccessWrite(pDevIns, pPciDev, GCPhys, pvBuf, cbWrite, fFlags);
     189    if (RT_SUCCESS(rc) || rc != VERR_IOMMU_NOT_PRESENT)
    261190        return rc;
    262     }
    263191#endif
    264192
     
    15881516
    15891517/** @interface_method_impl{PDMIOAPICHLP,pfnIommuMsiRemap} */
    1590 static DECLCALLBACK(int) pdmR0IoApicHlp_IommuMsiRemap(PPDMDEVINS pDevIns, uint16_t uDevId, PCMSIMSG pMsiIn, PMSIMSG pMsiOut)
     1518static DECLCALLBACK(int) pdmR0IoApicHlp_IommuMsiRemap(PPDMDEVINS pDevIns, uint16_t uDeviceId, PCMSIMSG pMsiIn, PMSIMSG pMsiOut)
    15911519{
    15921520    PDMDEV_ASSERT_DEVINS(pDevIns);
     
    15951523
    15961524#ifdef VBOX_WITH_IOMMU_AMD
    1597     /** @todo IOMMU: Optimize/re-organize things here later. */
    1598     PGVM        pGVM         = pDevIns->Internal.s.pGVM;
    1599     PPDMIOMMUR0 pIommu       = &pGVM->pdmr0.s.aIommus[0];
    1600     PPDMDEVINS  pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    1601     if (   pDevInsIommu
    1602         && pDevInsIommu != pDevIns)
    1603     {
    1604         AssertMsgReturn(VALID_PTR(pIommu->pfnMsiRemap),
    1605                         ("pdmR0IoApicHlp_IommuMsiRemap: pfnMsiRemap invalid!\n"), VERR_INVALID_POINTER);
    1606         int rc = pIommu->pfnMsiRemap(pDevInsIommu, uDevId, pMsiIn, pMsiOut);
    1607         if (RT_SUCCESS(rc))
    1608             return rc;
    1609 
    1610         Log(("pdmR0IoApicHlp_IommuMsiRemap: IOMMU MSI remap failed. uDevId=%#x pMsiIn=(%#RX64, %#RU32) rc=%Rrc\n",
    1611              uDevId, pMsiIn->Addr.u64, pMsiIn->Data.u32, rc));
    1612     }
     1525    int rc = pdmIommuMsiRemap(pDevIns, uDeviceId, pMsiIn, pMsiOut);
     1526    if (RT_SUCCESS(rc) || rc != VERR_IOMMU_NOT_PRESENT)
     1527        return rc;
    16131528#else
    1614     RT_NOREF(pDevIns, uDevId);
     1529    RT_NOREF(pDevIns, uDeviceId);
    16151530#endif
    16161531
  • trunk/src/VBox/VMM/VMMR0/PDMR0DevHlpTracing.cpp

    r87474 r87477  
    313313
    314314#ifdef VBOX_WITH_IOMMU_AMD
    315     /** @todo IOMMU: Optimize/re-organize things here later. */
    316     PGVM        pGVM         = pDevIns->Internal.s.pGVM;
    317     PPDMIOMMUR0 pIommu       = &pGVM->pdmr0.s.aIommus[0];
    318     PPDMDEVINS  pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    319     if (   pDevInsIommu
    320         && pDevInsIommu != pDevIns)
    321     {
    322         size_t const idxBus = pPciDev->Int.s.idxPdmBus;
    323         Assert(idxBus < RT_ELEMENTS(pGVM->pdmr0.s.aPciBuses));
    324         PPDMPCIBUSR0 pBus = &pGVM->pdmr0.s.aPciBuses[idxBus];
    325         uint16_t const uDeviceId = PCIBDF_MAKE(pBus->iBus, pPciDev->uDevFn);
    326         int rc = VINF_SUCCESS;
    327         while (cbRead > 0)
    328         {
    329             RTGCPHYS GCPhysOut;
    330             size_t   cbContig;
    331             rc = pIommu->pfnMemAccess(pDevInsIommu, uDeviceId, GCPhys, cbRead, PDMIOMMU_MEM_F_READ, &GCPhysOut, &cbContig);
    332             if (RT_SUCCESS(rc))
    333             {
    334                 /** @todo Handle strict return codes from PGMPhysRead. */
    335                 rc = pDevIns->pHlpR0->pfnPhysRead(pDevIns, GCPhysOut, pvBuf, cbRead, fFlags);
    336                 if (RT_SUCCESS(rc))
    337                 {
    338                     cbRead -= cbContig;
    339                     pvBuf   = (void *)((uintptr_t)pvBuf + cbContig);
    340                     GCPhys += cbContig;
    341                 }
    342                 else
    343                     break;
    344             }
    345             else
    346             {
    347                 Log(("pdmR0DevHlp_PCIPhysRead: IOMMU translation failed. uDeviceId=%#x GCPhys=%#RGp cb=%u rc=%Rrc\n", uDeviceId,
    348                      GCPhys, cbRead, rc));
    349                 break;
    350             }
    351         }
     315    int rc = pdmIommuMemAccessRead(pDevIns, pPciDev, GCPhys, pvBuf, cbRead, fFlags);
     316    if (RT_SUCCESS(rc) || rc != VERR_IOMMU_NOT_PRESENT)
    352317        return rc;
    353     }
    354318#endif
    355319
     
    383347
    384348#ifdef VBOX_WITH_IOMMU_AMD
    385     /** @todo IOMMU: Optimize/re-organize things here later. */
    386     PGVM        pGVM          = pDevIns->Internal.s.pGVM;
    387     PPDMIOMMUR0 pIommu        = &pGVM->pdmr0.s.aIommus[0];
    388     PPDMDEVINS   pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    389     if (   pDevInsIommu
    390         && pDevInsIommu != pDevIns)
    391     {
    392         size_t const idxBus = pPciDev->Int.s.idxPdmBus;
    393         Assert(idxBus < RT_ELEMENTS(pGVM->pdmr0.s.aPciBuses));
    394         PPDMPCIBUSR0 pBus = &pGVM->pdmr0.s.aPciBuses[idxBus];
    395         uint16_t const uDeviceId = PCIBDF_MAKE(pBus->iBus, pPciDev->uDevFn);
    396         int rc = VINF_SUCCESS;
    397         while (cbWrite > 0)
    398         {
    399             RTGCPHYS GCPhysOut;
    400             size_t   cbContig;
    401             rc = pIommu->pfnMemAccess(pDevInsIommu, uDeviceId, GCPhys, cbWrite, PDMIOMMU_MEM_F_WRITE, &GCPhysOut, &cbContig);
    402             if (RT_SUCCESS(rc))
    403             {
    404                 /** @todo Handle strict return codes from PGMPhysWrite. */
    405                 rc = pDevIns->pHlpR0->pfnPhysWrite(pDevIns, GCPhysOut, pvBuf, cbWrite, fFlags);
    406                 if (RT_SUCCESS(rc))
    407                 {
    408                     cbWrite -= cbContig;
    409                     pvBuf    = (const void *)((uintptr_t)pvBuf + cbContig);
    410                     GCPhys  += cbContig;
    411                 }
    412                 else
    413                     break;
    414             }
    415             else
    416             {
    417                 LogFunc(("IOMMU translation failed. uDeviceId=%#x GCPhys=%#RGp cb=%u rc=%Rrc\n", uDeviceId, GCPhys, cbWrite, rc));
    418                 break;
    419             }
    420         }
     349    int rc = pdmIommuMemAccessWrite(pDevIns, pPciDev, GCPhys, pvBuf, cbWrite, fFlags);
     350    if (RT_SUCCESS(rc) || rc != VERR_IOMMU_NOT_PRESENT)
    421351        return rc;
    422     }
    423352#endif
    424353
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