VirtualBox

Ignore:
Timestamp:
Dec 1, 2019 3:38:40 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
135137
Message:

IOM,PDMDevHlp: Kicked out the old MMIO code. bugref:9218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/include/IOMInline.h

    r82311 r82313  
    255255#endif
    256256
    257 
    258 /**
    259  * Gets the MMIO range for the specified physical address in the current context.
    260  *
    261  * @returns Pointer to MMIO range.
    262  * @returns NULL if address not in a MMIO range.
    263  *
    264  * @param   pVM     The cross context VM structure.
    265  * @param   pVCpu   The cross context virtual CPU structure of the calling EMT.
    266  * @param   GCPhys  Physical address to lookup.
    267  */
    268 DECLINLINE(PIOMMMIORANGE) iomMmioGetRange(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys)
    269 {
    270     Assert(IOM_IS_SHARED_LOCK_OWNER(pVM));
    271     PIOMMMIORANGE pRange = pVCpu->iom.s.CTX_SUFF(pMMIORangeLast);
    272     if (    !pRange
    273         ||  GCPhys - pRange->GCPhys >= pRange->cb)
    274         pVCpu->iom.s.CTX_SUFF(pMMIORangeLast) = pRange
    275             = (PIOMMMIORANGE)RTAvlroGCPhysRangeGet(&pVM->iom.s.CTX_SUFF(pTrees)->MMIOTree, GCPhys);
    276     return pRange;
    277 }
    278 
    279 /**
    280  * Retain a MMIO range.
    281  *
    282  * @param   pRange  The range to release.
    283  */
    284 DECLINLINE(void) iomMmioRetainRange(PIOMMMIORANGE pRange)
    285 {
    286     uint32_t cRefs = ASMAtomicIncU32(&pRange->cRefs);
    287     Assert(cRefs > 1);
    288     Assert(cRefs < _1M);
    289     NOREF(cRefs);
    290 }
    291 
    292 
    293 /**
    294  * Gets the referenced MMIO range for the specified physical address in the
    295  * current context.
    296  *
    297  * @returns Pointer to MMIO range.
    298  * @returns NULL if address not in a MMIO range.
    299  *
    300  * @param   pVM     The cross context VM structure.
    301  * @param   pVCpu   The cross context virtual CPU structure of the calling EMT.
    302  * @param   GCPhys  Physical address to lookup.
    303  */
    304 DECLINLINE(PIOMMMIORANGE) iomMmioGetRangeWithRef(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys)
    305 {
    306     int rc = IOM_LOCK_SHARED_EX(pVM, VINF_SUCCESS);
    307     AssertRCReturn(rc, NULL);
    308 
    309     PIOMMMIORANGE pRange = pVCpu->iom.s.CTX_SUFF(pMMIORangeLast);
    310     if (   !pRange
    311         || GCPhys - pRange->GCPhys >= pRange->cb)
    312         pVCpu->iom.s.CTX_SUFF(pMMIORangeLast) = pRange
    313             = (PIOMMMIORANGE)RTAvlroGCPhysRangeGet(&pVM->iom.s.CTX_SUFF(pTrees)->MMIOTree, GCPhys);
    314     if (pRange)
    315         iomMmioRetainRange(pRange);
    316 
    317     IOM_UNLOCK_SHARED(pVM);
    318     return pRange;
    319 }
    320 
    321 
    322 /**
    323  * Releases a MMIO range.
    324  *
    325  * @param   pVM     The cross context VM structure.
    326  * @param   pRange  The range to release.
    327  */
    328 DECLINLINE(void) iomMmioReleaseRange(PVMCC pVM, PIOMMMIORANGE pRange)
    329 {
    330     uint32_t cRefs = ASMAtomicDecU32(&pRange->cRefs);
    331     if (!cRefs)
    332         iomMmioFreeRange(pVM, pRange);
    333 }
    334 
    335 
    336 #ifdef VBOX_STRICT
    337 /**
    338  * Gets the MMIO range for the specified physical address in the current context.
    339  *
    340  * @returns Pointer to MMIO range.
    341  * @returns NULL if address not in a MMIO range.
    342  *
    343  * @param   pVM     The cross context VM structure.
    344  * @param   pVCpu   The cross context virtual CPU structure of the calling EMT.
    345  * @param   GCPhys  Physical address to lookup.
    346  */
    347 DECLINLINE(PIOMMMIORANGE) iomMMIOGetRangeUnsafe(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys)
    348 {
    349     PIOMMMIORANGE pRange = pVCpu->iom.s.CTX_SUFF(pMMIORangeLast);
    350     if (    !pRange
    351         ||  GCPhys - pRange->GCPhys >= pRange->cb)
    352         pVCpu->iom.s.CTX_SUFF(pMMIORangeLast) = pRange
    353             = (PIOMMMIORANGE)RTAvlroGCPhysRangeGet(&pVM->iom.s.CTX_SUFF(pTrees)->MMIOTree, GCPhys);
    354     return pRange;
    355 }
    356 #endif /* VBOX_STRICT */
    357 
    358 
    359 #ifdef VBOX_WITH_STATISTICS
    360 /**
    361  * Gets the MMIO statistics record.
    362  *
    363  * In ring-3 this will lazily create missing records, while in GC/R0 the caller has to
    364  * return the appropriate status to defer the operation to ring-3.
    365  *
    366  * @returns Pointer to MMIO stats.
    367  * @returns NULL if not found (R0/GC), or out of memory (R3).
    368  *
    369  * @param   pVM         The cross context VM structure.
    370  * @param   pVCpu       The cross context virtual CPU structure of the calling EMT.
    371  * @param   GCPhys      Physical address to lookup.
    372  * @param   pRange      The MMIO range.
    373  *
    374  * @remarks The caller holds the IOM critical section with shared access prior
    375  *          to calling this method.  Upon return, the lock has been released!
    376  *          This is ugly, but it's a necessary evil since we cannot upgrade read
    377  *          locks to write locks and the whole purpose here is calling
    378  *          iomR3MMIOStatsCreate.
    379  */
    380 DECLINLINE(PIOMMMIOSTATS) iomMmioGetStats(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, PIOMMMIORANGE pRange)
    381 {
    382     Assert(IOM_IS_SHARED_LOCK_OWNER(pVM));
    383 
    384     /* For large ranges, we'll put everything on the first byte. */
    385     if (pRange->cb > PAGE_SIZE)
    386         GCPhys = pRange->GCPhys;
    387 
    388     PIOMMMIOSTATS pStats = pVCpu->iom.s.CTX_SUFF(pMMIOStatsLast);
    389     if (    !pStats
    390         ||  pStats->Core.Key != GCPhys)
    391     {
    392         pStats = (PIOMMMIOSTATS)RTAvloGCPhysGet(&pVM->iom.s.CTX_SUFF(pTrees)->MmioStatTree, GCPhys);
    393 # ifdef IN_RING3
    394         if (!pStats)
    395         {
    396             IOM_UNLOCK_SHARED(pVM);
    397             return iomR3MMIOStatsCreate(pVM, GCPhys, pRange->pszDesc);
    398         }
    399 # endif
    400     }
    401 
    402     IOM_UNLOCK_SHARED(pVM);
    403     return pStats;
    404 }
    405 #endif /* VBOX_WITH_STATISTICS */
    406 
    407 
    408257/** @}  */
    409258
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