VirtualBox

Changeset 87478 in vbox for trunk/src/VBox/VMM/VMMAll


Ignore:
Timestamp:
Jan 29, 2021 1:42:32 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
142500
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/PDMAllIommu.cpp

    r87477 r87478  
    2727#ifdef IN_RING3
    2828# include <iprt/mem.h>
     29#endif
     30
     31
     32/*********************************************************************************************************************************
     33*   Defined Constants And Macros                                                                                                 *
     34*********************************************************************************************************************************/
     35/**
     36 * Gets the PDM IOMMU for the current context from the PDM device instance.
     37 */
     38#ifdef IN_RING0
     39#define PDMDEVINS_TO_IOMMU(a_pDevIns)   &(a_pDevIns)->Internal.s.pGVM->pdmr0.s.aIommus[0];
     40#else
     41#define PDMDEVINS_TO_IOMMU(a_pDevIns)   &(a_pDevIns)->Internal.s.pVMR3->pdm.s.aIommus[0];
    2942#endif
    3043
     
    5366
    5467
    55 #if 0
    56 /* Hmpf. We have no PPDMIOMMUR3 ... */
    57 DECL_FORCE_INLINE(PPDMDEVINS) pdmIommuGetInstance(PPDMDEVINS pDevIns)
    58 {
    59 #if defined(IN_RING0)
    60     PGVM        pGVM   = pDevIns->Internal.s.pGVM;
    61     PPDMIOMMUR0 pIommu = &pGVM->pdmr0.s.aIommus[0];
    62 #else
    63     PVM        pVM     = pDevIns->Internal.s.pVMR3;
    64     PPDMIOMMU  pIommu  = &pVM->pdm.s.aIommus[0];
    65 #endif
    66     return pIommu->CTX_SUFF(pDevIns);
    67 }
    68 #endif
    69 
    70 
    7168/**
    7269 * Bus master physical memory read after translating the physical address using the
     
    8784int pdmIommuMemAccessRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, uint32_t fFlags)
    8885{
    89     /** @todo IOMMU: Optimize/re-organize things here later. */
    90 #if defined(IN_RING0)
    91     PGVM        pGVM         = pDevIns->Internal.s.pGVM;
    92     PPDMIOMMUR0 pIommu       = &pGVM->pdmr0.s.aIommus[0];
    93     PPDMDEVINS  pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
     86    PPDMIOMMU  pIommu       = PDMDEVINS_TO_IOMMU(pDevIns);
     87    PPDMDEVINS pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    9488    if (   pDevInsIommu
    9589        && pDevInsIommu != pDevIns)
     
    10599            {
    106100                /** @todo Handle strict return codes from PGMPhysRead. */
    107                 rc = pDevIns->pHlpR0->pfnPhysRead(pDevIns, GCPhysOut, pvBuf, cbRead, fFlags);
     101                rc = pDevIns->CTX_SUFF(pHlp)->pfnPhysRead(pDevIns, GCPhysOut, pvBuf, cbRead, fFlags);
    108102                if (RT_SUCCESS(rc))
    109103                {
     
    117111            else
    118112            {
    119                 LogFunc(("R0: IOMMU memory read failed. uDeviceId=%#x GCPhys=%#RGp cb=%u rc=%Rrc\n", uDeviceId, GCPhys, cbRead,
    120                          rc));
     113                LogFunc(("IOMMU memory read failed. uDeviceId=%#x GCPhys=%#RGp cb=%zu rc=%Rrc\n", uDeviceId, GCPhys, cbRead, rc));
    121114                break;
    122115            }
     
    124117        return rc;
    125118    }
    126 
    127     return VERR_IOMMU_NOT_PRESENT;
    128 #elif defined(IN_RING3)
    129     PVM        pVM          = pDevIns->Internal.s.pVMR3;
    130     PPDMIOMMU  pIommu       = &pVM->pdm.s.aIommus[0];
    131     PPDMDEVINS pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    132     if (   pDevInsIommu
    133         && pDevInsIommu != pDevIns)
    134     {
    135         uint16_t const uDeviceId = pdmIommuGetPciDeviceId(pDevIns, pPciDev);
    136         int rc = VINF_SUCCESS;
    137         while (cbRead > 0)
    138         {
    139             RTGCPHYS GCPhysOut;
    140             size_t   cbContig;
    141             rc = pIommu->pfnMemAccess(pDevInsIommu, uDeviceId, GCPhys, cbRead, PDMIOMMU_MEM_F_READ, &GCPhysOut, &cbContig);
    142             if (RT_SUCCESS(rc))
    143             {
    144                 /** @todo Handle strict return codes from PGMPhysRead. */
    145                 rc = pDevIns->pHlpR3->pfnPhysRead(pDevIns, GCPhysOut, pvBuf, cbRead, fFlags);
    146                 if (RT_SUCCESS(rc))
    147                 {
    148                     cbRead -= cbContig;
    149                     pvBuf   = (void *)((uintptr_t)pvBuf + cbContig);
    150                     GCPhys += cbContig;
    151                 }
    152                 else
    153                     break;
    154             }
    155             else
    156             {
    157                 LogFunc(("R3: IOMMU memory read failed. uDeviceId=%#x GCPhys=%#RGp cb=%u rc=%Rrc\n", uDeviceId, GCPhys, cbRead,
    158                          rc));
    159                 break;
    160             }
    161         }
    162         return rc;
    163     }
    164 
    165     return VERR_IOMMU_NOT_PRESENT;
    166 #else
    167 # error "Implement me."
    168 #endif
     119    return VERR_IOMMU_NOT_PRESENT;
    169120}
    170121
     
    189140                           uint32_t fFlags)
    190141{
    191     /** @todo IOMMU: Optimize/re-organize things here later. */
    192 #if defined(IN_RING0)
    193     PGVM        pGVM         = pDevIns->Internal.s.pGVM;
    194     PPDMIOMMUR0 pIommu       = &pGVM->pdmr0.s.aIommus[0];
    195     PPDMDEVINS  pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
     142    PPDMIOMMU  pIommu       = PDMDEVINS_TO_IOMMU(pDevIns);
     143    PPDMDEVINS pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    196144    if (   pDevInsIommu
    197145        && pDevInsIommu != pDevIns)
     
    207155            {
    208156                /** @todo Handle strict return codes from PGMPhysWrite. */
    209                 rc = pDevIns->pHlpR0->pfnPhysWrite(pDevIns, GCPhysOut, pvBuf, cbWrite, fFlags);
     157                rc = pDevIns->CTX_SUFF(pHlp)->pfnPhysWrite(pDevIns, GCPhysOut, pvBuf, cbWrite, fFlags);
    210158                if (RT_SUCCESS(rc))
    211159                {
     
    219167            else
    220168            {
    221                 LogFunc(("R0: IOMMU memory write failed. uDeviceId=%#x GCPhys=%#RGp cb=%u rc=%Rrc\n", uDeviceId, GCPhys, cbWrite,
     169                LogFunc(("IOMMU memory write failed. uDeviceId=%#x GCPhys=%#RGp cb=%zu rc=%Rrc\n", uDeviceId, GCPhys, cbWrite,
    222170                         rc));
    223171                break;
     
    226174        return rc;
    227175    }
    228 
    229     return VERR_IOMMU_NOT_PRESENT;
    230 #elif defined(IN_RING3)
    231     PVM        pVM          = pDevIns->Internal.s.pVMR3;
    232     PPDMIOMMU  pIommu       = &pVM->pdm.s.aIommus[0];
    233     PPDMDEVINS pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    234     if (   pDevInsIommu
    235         && pDevInsIommu != pDevIns)
    236     {
    237         uint16_t const uDeviceId = pdmIommuGetPciDeviceId(pDevIns, pPciDev);
    238         int rc = VINF_SUCCESS;
    239         while (cbWrite > 0)
    240         {
    241             RTGCPHYS GCPhysOut;
    242             size_t   cbContig;
    243             rc = pIommu->pfnMemAccess(pDevInsIommu, uDeviceId, GCPhys, cbWrite, PDMIOMMU_MEM_F_WRITE, &GCPhysOut, &cbContig);
    244             if (RT_SUCCESS(rc))
    245             {
    246                 /** @todo Handle strict return codes from PGMPhysWrite. */
    247                 rc = pDevIns->pHlpR3->pfnPhysWrite(pDevIns, GCPhysOut, pvBuf, cbContig, fFlags);
    248                 if (RT_SUCCESS(rc))
    249                 {
    250                     cbWrite -= cbContig;
    251                     pvBuf    = (const void *)((uintptr_t)pvBuf + cbContig);
    252                     GCPhys  += cbContig;
    253                 }
    254                 else
    255                     break;
    256             }
    257             else
    258             {
    259                 LogFunc(("R3: IOMMU memory write failed. uDeviceId=%#x GCPhys=%#RGp cb=%u rc=%Rrc\n", uDeviceId, GCPhys, cbWrite,
    260                          rc));
    261                 break;
    262             }
    263         }
    264         return rc;
    265     }
    266 
    267     return VERR_IOMMU_NOT_PRESENT;
    268 #else
    269 # error "Implement me."
    270 #endif
     176    return VERR_IOMMU_NOT_PRESENT;
    271177}
    272178
     
    294200{
    295201#if defined(IN_RING3)
    296     PVM        pVM          = pDevIns->Internal.s.pVMR3;
    297     PPDMIOMMU  pIommu       = &pVM->pdm.s.aIommus[0];
     202    PPDMIOMMU  pIommu       = PDMDEVINS_TO_IOMMU(pDevIns);
    298203    PPDMDEVINS pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    299204    if (   pDevInsIommu
     
    315220        return rc;
    316221    }
    317 
    318222    return VERR_IOMMU_NOT_PRESENT;
    319223#else
     
    346250{
    347251#if defined(IN_RING3)
    348     PVM        pVM          = pDevIns->Internal.s.pVMR3;
    349     PPDMIOMMU  pIommu       = &pVM->pdm.s.aIommus[0];
     252    PPDMIOMMU  pIommu       = PDMDEVINS_TO_IOMMU(pDevIns);
    350253    PPDMDEVINS pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    351254    if (   pDevInsIommu
     
    367270        return rc;
    368271    }
    369 
    370272    return VERR_IOMMU_NOT_PRESENT;
    371273#else
     
    401303{
    402304#ifdef IN_RING3
    403     PVM        pVM          = pDevIns->Internal.s.pVMR3;
    404     PPDMIOMMU  pIommu       = &pVM->pdm.s.aIommus[0];
     305    PPDMIOMMU  pIommu       = PDMDEVINS_TO_IOMMU(pDevIns);
    405306    PPDMDEVINS pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    406307    if (   pDevInsIommu
     
    437338        return rc;
    438339    }
    439 
    440340    return VERR_IOMMU_NOT_PRESENT;
    441341#else
     
    471371{
    472372#ifdef IN_RING3
    473     PVM        pVM          = pDevIns->Internal.s.pVMR3;
    474     PPDMIOMMU  pIommu       = &pVM->pdm.s.aIommus[0];
     373    PPDMIOMMU  pIommu       = PDMDEVINS_TO_IOMMU(pDevIns);
    475374    PPDMDEVINS pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    476375    if (   pDevInsIommu
     
    507406        return rc;
    508407    }
    509 
    510408    return VERR_IOMMU_NOT_PRESENT;
    511409#else
     
    519417int pdmIommuMsiRemap(PPDMDEVINS pDevIns, uint16_t uDeviceId, PCMSIMSG pMsiIn, PMSIMSG pMsiOut)
    520418{
    521 #if defined(IN_RING0)
    522     PGVM        pGVM         = pDevIns->Internal.s.pGVM;
    523     PPDMIOMMUR0 pIommu       = &pGVM->pdmr0.s.aIommus[0];
    524     PPDMDEVINS  pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
     419    PPDMIOMMU  pIommu       = PDMDEVINS_TO_IOMMU(pDevIns);
     420    PPDMDEVINS pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    525421    if (   pDevInsIommu
    526422        && pDevInsIommu != pDevIns)
     
    529425        if (RT_FAILURE(rc))
    530426        {
    531             LogFunc(("R0: MSI remap failed. uDeviceId=%#x pMsiIn=(%#RX64, %#RU32) rc=%Rrc\n", uDeviceId, pMsiIn->Addr.u64,
     427            LogFunc(("MSI remap failed. uDeviceId=%#x pMsiIn=(%#RX64, %#RU32) rc=%Rrc\n", uDeviceId, pMsiIn->Addr.u64,
    532428                     pMsiIn->Data.u32, rc));
    533429        }
    534430        return rc;
    535431    }
    536 
    537     return VERR_IOMMU_NOT_PRESENT;
    538 #elif defined(IN_RING3)
    539     PVM        pVM          = pDevIns->Internal.s.pVMR3;
    540     PPDMIOMMU  pIommu       = &pVM->pdm.s.aIommus[0];
    541     PPDMDEVINS pDevInsIommu = pIommu->CTX_SUFF(pDevIns);
    542     if (   pDevInsIommu
    543         && pDevInsIommu != pDevIns)
    544     {
    545         int rc = pIommu->pfnMsiRemap(pDevInsIommu, uDeviceId, pMsiIn, pMsiOut);
    546         if (RT_FAILURE(rc))
    547         {
    548             LogFunc(("R3: MSI remap failed. uDeviceId=%#x pMsiIn=(%#RX64, %#RU32) rc=%Rrc\n", uDeviceId, pMsiIn->Addr.u64,
    549                      pMsiIn->Data.u32, rc));
    550         }
    551         return rc;
    552     }
    553 
    554     return VERR_IOMMU_NOT_PRESENT;
    555 #else
    556 # error "Implement me."
    557 #endif
    558 }
    559 
     432    return VERR_IOMMU_NOT_PRESENT;
     433}
     434
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