From: Denis V. Lunev <[email protected]>

address_space_translate_internal() takes the dispatch, so every caller
resolves the view to its tree first and the tree is the only structure a
lookup can go through. Take the view instead and let the lookup reach the
tree, so that a view which answers some other way is expressible.

No functional change: every caller already had the view, or an address
space to take it from.

CC: Paolo Bonzini <[email protected]>
CC: Peter Xu <[email protected]>
CC: Philippe Mathieu-Daude <[email protected]>
CC: Fabiano Rosas <[email protected]>
Signed-off-by: Denis V. Lunev <[email protected]>
---
 system/memory-internal.h | 11 -----------
 system/physmem.c         | 25 ++++++++++++-------------
 2 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/system/memory-internal.h b/system/memory-internal.h
index d06c136744..d81881ba54 100644
--- a/system/memory-internal.h
+++ b/system/memory-internal.h
@@ -16,17 +16,6 @@
 
 void machine_memory_init(void);
 
-static inline AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv)
-{
-    return fv->dispatch;
-}
-
-static inline
-AddressSpaceDispatch *address_space_to_dispatch(const AddressSpace *as)
-{
-    return flatview_to_dispatch(address_space_to_flatview(as));
-}
-
 FlatView *address_space_get_flatview(const AddressSpace *as);
 void flatview_unref(FlatView *view);
 
diff --git a/system/physmem.c b/system/physmem.c
index 2cfdb1e6b4..6f11e31799 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -361,14 +361,14 @@ static MemoryRegionSection 
*address_space_lookup_region(AddressSpaceDispatch *d,
 
 /* Called from RCU critical section */
 static MemoryRegionSection *
-address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr 
*xlat,
+address_space_translate_internal(FlatView *fv, hwaddr addr, hwaddr *xlat,
                                  hwaddr *plen, bool resolve_subpage)
 {
     MemoryRegionSection *section;
     MemoryRegion *mr;
     Int128 diff;
 
-    section = address_space_lookup_region(d, addr, resolve_subpage);
+    section = address_space_lookup_region(fv->dispatch, addr, resolve_subpage);
     /* Compute offset within MemoryRegionSection */
     addr -= section->offset_within_address_space;
 
@@ -453,7 +453,7 @@ static MemoryRegionSection 
address_space_translate_iommu(IOMMUMemoryRegion *iomm
         *target_as = iotlb.target_as;
 
         section = address_space_translate_internal(
-                address_space_to_dispatch(iotlb.target_as), addr, xlat,
+                address_space_to_flatview(iotlb.target_as), addr, xlat,
                 plen_out, is_mmio);
 
         iommu_mr = memory_region_get_iommu(section->mr);
@@ -506,9 +506,8 @@ static MemoryRegionSection flatview_do_translate(FlatView 
*fv,
         plen_out = &plen;
     }
 
-    section = address_space_translate_internal(
-            flatview_to_dispatch(fv), addr, xlat,
-            plen_out, is_mmio);
+    section = address_space_translate_internal(fv, addr, xlat,
+                                               plen_out, is_mmio);
 
     iommu_mr = memory_region_get_iommu(section->mr);
     if (unlikely(iommu_mr)) {
@@ -691,10 +690,11 @@ address_space_translate_for_iotlb(CPUState *cpu, int 
asidx, hwaddr orig_addr,
     IOMMUTLBEntry iotlb;
     int iommu_idx;
     hwaddr addr = orig_addr;
-    AddressSpaceDispatch *d = 
address_space_to_dispatch(cpu->cpu_ases[asidx].as);
+    FlatView *fv = address_space_to_flatview(cpu->cpu_ases[asidx].as);
 
     for (;;) {
-        section = address_space_translate_internal(d, addr, &addr, plen, 
false);
+        section = address_space_translate_internal(fv, addr, &addr, plen,
+                                                   false);
 
         iommu_mr = memory_region_get_iommu(section->mr);
         if (!iommu_mr) {
@@ -726,7 +726,7 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, 
hwaddr orig_addr,
             goto translate_fail;
         }
 
-        d = flatview_to_dispatch(address_space_to_flatview(iotlb.target_as));
+        fv = address_space_to_flatview(iotlb.target_as);
     }
 
     assert(!memory_region_is_iommu(section->mr));
@@ -744,7 +744,7 @@ translate_fail:
      */
     assert((orig_addr & ~TARGET_PAGE_MASK) == 0);
     *xlat = orig_addr;
-    return &d->map.sections[PHYS_SECTION_UNASSIGNED];
+    return &fv->dispatch->map.sections[PHYS_SECTION_UNASSIGNED];
 }
 
 #endif /* CONFIG_TCG */
@@ -3886,7 +3886,6 @@ int64_t address_space_cache_init(MemoryRegionCache *cache,
                                  hwaddr len,
                                  bool is_write)
 {
-    AddressSpaceDispatch *d;
     hwaddr l;
     MemoryRegion *mr;
     Int128 diff;
@@ -3895,8 +3894,8 @@ int64_t address_space_cache_init(MemoryRegionCache *cache,
 
     l = len;
     cache->fv = address_space_get_flatview(as);
-    d = flatview_to_dispatch(cache->fv);
-    cache->mrs = *address_space_translate_internal(d, addr, &cache->xlat, &l, 
true);
+    cache->mrs = *address_space_translate_internal(cache->fv, addr,
+                                                   &cache->xlat, &l, true);
 
     /*
      * cache->xlat is now relative to cache->mrs.mr, not to the section itself.
-- 
2.53.0


Reply via email to