From e7af4c67300b3f9382e96f7a6741a5992116b2d2 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Tue, 16 Dec 2014 11:21:23 +0200 Subject: [PATCH] memory: add memory_region_set_size Add API to change MR size. Will be used internally for RAM resize. Signed-off-by: Michael S. Tsirkin Reviewed-by: Paolo Bonzini --- include/exec/memory.h | 10 ++++++++++ memory.c | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index f64ab5e3e5..0882221395 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -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 * diff --git a/memory.c b/memory.c index 15cf9ebd84..618470bc4f 100644 --- 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;