From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0umG-0007ia-Gi for qemu-devel@nongnu.org; Tue, 16 Dec 2014 11:15:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y0um8-0001jy-Ue for qemu-devel@nongnu.org; Tue, 16 Dec 2014 11:15:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34787) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0um8-0001ip-Mk for qemu-devel@nongnu.org; Tue, 16 Dec 2014 11:15:04 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBGGF49Y017773 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 16 Dec 2014 11:15:04 -0500 Date: Tue, 16 Dec 2014 18:15:00 +0200 From: "Michael S. Tsirkin" Message-ID: <1418746479-21634-3-git-send-email-mst@redhat.com> References: <1418746479-21634-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1418746479-21634-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PATCH v2 2/8] memory: add memory_region_set_size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Amit Shah , pbonzini@redhat.com, imammedo@redhat.com, dgilbert@redhat.com, Juan Quintela Add API to change MR size. Will be used internally for RAM resize. Signed-off-by: Michael S. Tsirkin --- 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 f64ab5e..0882221 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -878,6 +878,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 * * Dynamically updates the offset into the target region that an alias points diff --git a/memory.c b/memory.c index 15cf9eb..618470b 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; -- MST