@@ -54,6 +54,12 @@ struct MemoryRegionIORange {
* Memory region callbacks
*/
struct MemoryRegionOps {
+
+ /* ref/unref pair is optional; ref.
+ * inc refcnt of object who store MemoryRegion
+ */
+ void (*ref)(void);
+ void (*unref)(void);
/* Read from the memory region. @addr is relative to @mr; @size is
* in bytes. */
uint64_t (*read)(void *opaque,
@@ -223,6 +229,10 @@ struct MemoryListener {
QTAILQ_ENTRY(MemoryListener) link;
};
+/**/
+bool memory_region_ref(MemoryRegion *mr);
+bool memory_region_unref(MemoryRegion *mr);
+
/**
* memory_region_init: Initialize a memory region
*
@@ -786,6 +786,24 @@ static bool memory_region_wrong_endianness(MemoryRegion *mr)
#endif
}
+bool memory_region_ref(MemoryRegion *mr)
+{
+ if (mr->ops && mr->ops->ref) {
+ mr->ops->ref();
+ return true;
+ }
+ return false;
+}
+
+bool memory_region_unref(MemoryRegion *mr)
+{
+ if (mr->ops && mr->ops->unref) {
+ mr->ops->unref();
+ return true;
+ }
+ return false;
+}
+
void memory_region_init(MemoryRegion *mr,
const char *name,
uint64_t size)