From patchwork Wed Jan 7 19:48:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 426393 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 E9EDF1400EA for ; Thu, 8 Jan 2015 06:49:43 +1100 (AEDT) Received: from localhost ([::1]:42546 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8wbt-0005vW-SX for incoming@patchwork.ozlabs.org; Wed, 07 Jan 2015 14:49:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51684) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8wbG-0004f7-DT for qemu-devel@nongnu.org; Wed, 07 Jan 2015 14:49:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y8wb8-0008LA-Vx for qemu-devel@nongnu.org; Wed, 07 Jan 2015 14:49:02 -0500 Received: from mail.kernel.org ([198.145.29.136]:52622) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y8wb8-0008L3-Pm for qemu-devel@nongnu.org; Wed, 07 Jan 2015 14:48:54 -0500 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CB75B20375; Wed, 7 Jan 2015 19:48:53 +0000 (UTC) Received: from redhat.com (bzq-79-182-177-46.red.bezeqint.net [79.182.177.46]) (using TLSv1.2 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 897D520374; Wed, 7 Jan 2015 19:48:51 +0000 (UTC) Date: Wed, 7 Jan 2015 21:48:48 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1420660083-9961-2-git-send-email-mst@redhat.com> References: <1420660083-9961-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1420660083-9961-1-git-send-email-mst@redhat.com> X-Mailer: git-send-email 2.0.0.545.gd9cabeb X-Mutt-Fcc: =sent X-Virus-Scanned: ClamAV using ClamSMTP X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 198.145.29.136 Cc: Amit Shah , pbonzini@redhat.com, imammedo@redhat.com, dgilbert@redhat.com, Juan Quintela Subject: [Qemu-devel] [PATCH v3 1/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;