Make memory_region_set_ops() function public. In some cases such as
when devices have configurable endianness or different behaviour based
on settings it is necessary to change the ops callback after the
memory region is created. Export memory_region_set_ops() function for
this.

Signed-off-by: BALATON Zoltan <[email protected]>
---
 include/system/memory.h | 13 +++++++++++++
 system/memory.c         |  7 +++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/include/system/memory.h b/include/system/memory.h
index 1417132f6d..da07b52885 100644
--- a/include/system/memory.h
+++ b/include/system/memory.h
@@ -1343,6 +1343,19 @@ void memory_region_ref(MemoryRegion *mr);
  */
 void memory_region_unref(MemoryRegion *mr);
 
+/**
+ * memory_region_set_ops: Set ops of an I/O memory region.
+ *
+ * Accesses into the region will cause the callbacks in @ops to be called.
+ *
+ * @mr: the #MemoryRegion to be changed.
+ * @ops: a structure containing read and write callbacks to be used when
+ *       I/O is performed on the region.
+ * @opaque: passed to the read and write callbacks of the @ops structure.
+ */
+void memory_region_set_ops(MemoryRegion *mr, const MemoryRegionOps *ops,
+                           void *opaque);
+
 /**
  * memory_region_init_io: Initialize an I/O memory region.
  *
diff --git a/system/memory.c b/system/memory.c
index 739ba11da6..edcdf91d48 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -1560,10 +1560,10 @@ MemTxResult memory_region_dispatch_write(MemoryRegion 
*mr,
     }
 }
 
-static void memory_region_set_ops(MemoryRegion *mr,
-                                  const MemoryRegionOps *ops,
-                                  void *opaque)
+void memory_region_set_ops(MemoryRegion *mr, const MemoryRegionOps *ops,
+                           void *opaque)
 {
+    g_assert(!ops || !(ops->impl.unaligned && !ops->valid.unaligned));
     mr->ops = ops ?: &unassigned_mem_ops;
     mr->opaque = opaque;
     mr->terminates = true;
@@ -1573,7 +1573,6 @@ void memory_region_init_io(MemoryRegion *mr, Object 
*owner,
                            const MemoryRegionOps *ops, void *opaque,
                            const char *name, uint64_t size)
 {
-    g_assert(!ops || !(ops->impl.unaligned && !ops->valid.unaligned));
     memory_region_init(mr, owner, name, size);
     memory_region_set_ops(mr, ops, opaque);
 }
-- 
2.41.3


Reply via email to