]> git.proxmox.com Git - mirror_qemu.git/commitdiff
memory: add memory_region_set_size
authorMichael S. Tsirkin <mst@redhat.com>
Tue, 16 Dec 2014 09:21:23 +0000 (11:21 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 8 Jan 2015 11:17:54 +0000 (13:17 +0200)
Add API to change MR size.
Will be used internally for RAM resize.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
include/exec/memory.h
memory.c

index f64ab5e3e558e043cfbbb65490b03557009b6bf0..08822213955dc174e21d21b84062b1123b3fe012 100644 (file)
@@ -877,6 +877,16 @@ void memory_region_set_enabled(MemoryRegion *mr, bool enabled);
  */
 void memory_region_set_address(MemoryRegion *mr, hwaddr addr);
 
+/*
+ * memory_region_set_size: dynamically update the size of a region.
+ *
+ * Dynamically updates the size of a region.
+ *
+ * @mr: the region to be updated
+ * @size: used size of the region.
+ */
+void memory_region_set_size(MemoryRegion *mr, uint64_t size);
+
 /*
  * memory_region_set_alias_offset: dynamically update a memory alias's offset
  *
index 15cf9ebd8423b0b04862df77772f147b085d54fd..618470bc4feb977cffd772c759cce6d3af9674d5 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -1707,6 +1707,22 @@ void memory_region_set_enabled(MemoryRegion *mr, bool enabled)
     memory_region_transaction_commit();
 }
 
+void memory_region_set_size(MemoryRegion *mr, uint64_t size)
+{
+    Int128 s = int128_make64(size);
+
+    if (size == UINT64_MAX) {
+        s = int128_2_64();
+    }
+    if (int128_eq(s, mr->size)) {
+        return;
+    }
+    memory_region_transaction_begin();
+    mr->size = s;
+    memory_region_update_pending = true;
+    memory_region_transaction_commit();
+}
+
 static void memory_region_readd_subregion(MemoryRegion *mr)
 {
     MemoryRegion *container = mr->container;