Patchwork [03/23] memory: add memory_region_is_ram()

login
register
mail settings
Submitter Avi Kivity
Date Dec. 19, 2011, 2:13 p.m.
Message ID <1324304024-11220-4-git-send-email-avi@redhat.com>
Download mbox | patch
Permalink /patch/132252/
State New
Headers show

Comments

Avi Kivity - Dec. 19, 2011, 2:13 p.m.
Signed-off-by: Avi Kivity <avi@redhat.com>
---
 memory.c |    8 ++++++++
 memory.h |   10 ++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

Patch

diff --git a/memory.c b/memory.c
index d8b7c27..6fd31d4 100644
--- a/memory.c
+++ b/memory.c
@@ -831,6 +831,7 @@  void memory_region_init(MemoryRegion *mr,
     mr->addr = 0;
     mr->offset = 0;
     mr->terminates = false;
+    mr->ram = false;
     mr->readable = true;
     mr->readonly = false;
     mr->destructor = memory_region_destructor_none;
@@ -997,6 +998,7 @@  void memory_region_init_ram(MemoryRegion *mr,
                             uint64_t size)
 {
     memory_region_init(mr, name, size);
+    mr->ram = true;
     mr->terminates = true;
     mr->destructor = memory_region_destructor_ram;
     mr->ram_addr = qemu_ram_alloc(dev, name, size, mr);
@@ -1010,6 +1012,7 @@  void memory_region_init_ram_ptr(MemoryRegion *mr,
                                 void *ptr)
 {
     memory_region_init(mr, name, size);
+    mr->ram = true;
     mr->terminates = true;
     mr->destructor = memory_region_destructor_ram_from_ptr;
     mr->ram_addr = qemu_ram_alloc_from_ptr(dev, name, size, ptr, mr);
@@ -1065,6 +1068,11 @@  uint64_t memory_region_size(MemoryRegion *mr)
     return int128_get64(mr->size);
 }
 
+bool memory_region_is_ram(MemoryRegion *mr)
+{
+    return mr->ram;
+}
+
 void memory_region_set_offset(MemoryRegion *mr, target_phys_addr_t offset)
 {
     mr->offset = offset;
diff --git a/memory.h b/memory.h
index 1d5c414..13f88c0 100644
--- a/memory.h
+++ b/memory.h
@@ -122,6 +122,7 @@  struct MemoryRegion {
     IORange iorange;
     bool terminates;
     bool readable;
+    bool ram;
     bool readonly; /* For RAM regions */
     MemoryRegion *alias;
     target_phys_addr_t alias_offset;
@@ -284,6 +285,15 @@  void memory_region_destroy(MemoryRegion *mr);
 uint64_t memory_region_size(MemoryRegion *mr);
 
 /**
+ * memory_region_is_ram: check whether a memory region is random access
+ *
+ * Returns %true is a memory region is random access.
+ *
+ * @mr: the memory region being queried
+ */
+bool memory_region_is_ram(MemoryRegion *mr);
+
+/**
  * memory_region_get_ram_ptr: Get a pointer into a RAM memory region.
  *
  * Returns a host pointer to a RAM memory region (created with