From patchwork Wed Dec 24 11:51:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 423908 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6B0A5140081 for ; Wed, 24 Dec 2014 22:52:07 +1100 (AEDT) Received: from localhost ([::1]:47881 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y3kU1-0000JO-MA for incoming@patchwork.ozlabs.org; Wed, 24 Dec 2014 06:52:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y3kTd-00085K-41 for qemu-devel@nongnu.org; Wed, 24 Dec 2014 06:51:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y3kTb-0001XP-Uj for qemu-devel@nongnu.org; Wed, 24 Dec 2014 06:51:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56458) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y3kTb-0001XI-ML for qemu-devel@nongnu.org; Wed, 24 Dec 2014 06:51:39 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBOBpb8U018563 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 24 Dec 2014 06:51:37 -0500 Received: from redhat.com (ovpn-116-33.ams2.redhat.com [10.36.116.33]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id sBOBpZVL028216; Wed, 24 Dec 2014 06:51:35 -0500 Date: Wed, 24 Dec 2014 13:51:34 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1419421800-27505-3-git-send-email-mst@redhat.com> References: <1419421800-27505-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1419421800-27505-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Paolo Bonzini , dgilbert@redhat.com, Juan Quintela Subject: [Qemu-devel] [PULL 2/8] memory: add memory_region_set_size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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;