Mark the AddressSpace structure const when it is only accessed read-only.

Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
 include/system/memory.h |  4 ++--
 system/physmem.c        | 10 ++++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/include/system/memory.h b/include/system/memory.h
index 858dc40dc5f..38e4f7b25e5 100644
--- a/include/system/memory.h
+++ b/include/system/memory.h
@@ -2783,7 +2783,7 @@ void address_space_flush_icache_range(AddressSpace *as, 
hwaddr addr, hwaddr len)
 /* address_space_get_iotlb_entry: translate an address into an IOTLB
  * entry. Should be called from an RCU critical section.
  */
-IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr,
+IOMMUTLBEntry address_space_get_iotlb_entry(const AddressSpace *as, hwaddr 
addr,
                                             bool is_write, MemTxAttrs attrs);
 
 /* address_space_translate: translate an address range into an address space
@@ -2804,7 +2804,7 @@ MemoryRegion *flatview_translate(FlatView *fv,
                                  hwaddr *len, bool is_write,
                                  MemTxAttrs attrs);
 
-static inline MemoryRegion *address_space_translate(AddressSpace *as,
+static inline MemoryRegion *address_space_translate(const AddressSpace *as,
                                                     hwaddr addr, hwaddr *xlat,
                                                     hwaddr *len, bool is_write,
                                                     MemTxAttrs attrs)
diff --git a/system/physmem.c b/system/physmem.c
index 23ea6b69255..bbcbcedda15 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -528,19 +528,21 @@ static MemoryRegionSection flatview_do_translate(FlatView 
*fv,
 }
 
 /* Called from RCU critical section */
-IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr,
+IOMMUTLBEntry address_space_get_iotlb_entry(const AddressSpace *as, hwaddr 
addr,
                                             bool is_write, MemTxAttrs attrs)
 {
     MemoryRegionSection section;
     hwaddr xlat, page_mask;
+    AddressSpace target_as = *as;
+    AddressSpace *ptarget_as = &target_as;
 
     /*
      * This can never be MMIO, and we don't really care about plen,
      * but page mask.
      */
     section = flatview_do_translate(address_space_to_flatview(as), addr, &xlat,
-                                    NULL, &page_mask, is_write, false, &as,
-                                    attrs);
+                                    NULL, &page_mask, is_write, false,
+                                    &ptarget_as, attrs);
 
     /* Illegal translation */
     if (section.mr == &io_mem_unassigned) {
@@ -552,7 +554,7 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace 
*as, hwaddr addr,
         section.offset_within_region;
 
     return (IOMMUTLBEntry) {
-        .target_as = as,
+        .target_as = &target_as,
         .iova = addr & ~page_mask,
         .translated_addr = xlat & ~page_mask,
         .addr_mask = page_mask,
-- 
2.53.0


Reply via email to