From patchwork Tue May 20 15:15:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 350756 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 3FC2B140088 for ; Wed, 21 May 2014 01:24:42 +1000 (EST) Received: from localhost ([::1]:54021 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmluB-0006so-R3 for incoming@patchwork.ozlabs.org; Tue, 20 May 2014 11:24:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54302) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wmlor-0008DV-Qq for qemu-devel@nongnu.org; Tue, 20 May 2014 11:19:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wmlol-0000vO-Ne for qemu-devel@nongnu.org; Tue, 20 May 2014 11:19:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15614) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wmlol-0000vC-Bu for qemu-devel@nongnu.org; Tue, 20 May 2014 11:19:03 -0400 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 s4KFI3qp031654 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 May 2014 11:18:04 -0400 Received: from dell-pet610-01.lab.eng.brq.redhat.com (dell-pet610-01.lab.eng.brq.redhat.com [10.34.42.20]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4KFGs7V027688; Tue, 20 May 2014 11:17:57 -0400 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Tue, 20 May 2014 17:15:13 +0200 Message-Id: <1400598934-31921-11-git-send-email-imammedo@redhat.com> In-Reply-To: <1400598934-31921-1-git-send-email-imammedo@redhat.com> References: <1400598934-31921-1-git-send-email-imammedo@redhat.com> 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@linaro.org, alex@alex.org.uk, mst@redhat.com, aik@ozlabs.ru, hutao@cn.fujitsu.com, mjt@tls.msk.ru, tangchen@cn.fujitsu.com, kraxel@redhat.com, pasteka@kabsi.at, s.priebe@profihost.ag, agarcia@igalia.com, armbru@redhat.com, aliguori@amazon.com, david@gibson.dropbear.id.au, lersek@redhat.com, ehabkost@redhat.com, marcel.a@redhat.com, stefanha@redhat.com, cornelia.huck@de.ibm.com, rth@twiddle.net, agraf@suse.de, andrey@xdel.ru, vasilis.liaskovitis@profitbricks.com, pbonzini@redhat.com, afaerber@suse.de, aurelien@aurel32.net Subject: [Qemu-devel] [PATCH v2 10/31] memory: add memory_region_is_mapped() API 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 which allows to check if MemoryRegion is already mapped. Signed-off-by: Igor Mammedov --- include/exec/memory.h | 8 ++++++++ memory.c | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 1d55ad9..ab11c32 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -848,6 +848,14 @@ void memory_region_set_alias_offset(MemoryRegion *mr, bool memory_region_present(MemoryRegion *parent, hwaddr addr); /** + * memory_region_is_mapped: returns true if #MemoryRegion is mapped + * into any address space. + * + * @mr: a #MemoryRegion which should be checked if it's mapped + */ +bool memory_region_is_mapped(MemoryRegion *mr); + +/** * memory_region_find: translate an address/size relative to a * MemoryRegion into a #MemoryRegionSection. * diff --git a/memory.c b/memory.c index 3f1df23..f4d8e69 100644 --- a/memory.c +++ b/memory.c @@ -492,7 +492,7 @@ static AddressSpace *memory_region_to_address_space(MemoryRegion *mr) return as; } } - abort(); + return NULL; } /* Render a memory region into the global view. Ranges in @view obscure @@ -1569,6 +1569,16 @@ bool memory_region_present(MemoryRegion *parent, hwaddr addr) return true; } +bool memory_region_is_mapped(MemoryRegion *mr) +{ + mr = memory_region_find(mr, 0, 1).mr; + if (!mr) { + return false; + } + memory_region_unref(mr); + return true; +} + MemoryRegionSection memory_region_find(MemoryRegion *mr, hwaddr addr, uint64_t size) { @@ -1586,6 +1596,9 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr, } as = memory_region_to_address_space(root); + if (!as) { + return ret; + } range = addrrange_make(int128_make64(addr), int128_make64(size)); view = address_space_get_flatview(as);