From patchwork Mon Oct 17 19:38:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9380381 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 30E98600CA for ; Mon, 17 Oct 2016 19:49:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B05D28CB0 for ; Mon, 17 Oct 2016 19:49:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E08928EB7; Mon, 17 Oct 2016 19:49:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A545228CB0 for ; Mon, 17 Oct 2016 19:49:29 +0000 (UTC) Received: from localhost ([::1]:35509 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwDua-0001cz-UG for patchwork-qemu-devel@patchwork.kernel.org; Mon, 17 Oct 2016 15:49:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwDkN-0001Lk-N7 for qemu-devel@nongnu.org; Mon, 17 Oct 2016 15:38:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwDkM-0007s8-RM for qemu-devel@nongnu.org; Mon, 17 Oct 2016 15:38:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59992) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bwDkK-0007qb-Rx; Mon, 17 Oct 2016 15:38:52 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14A0A3F1F9; Mon, 17 Oct 2016 19:38:52 +0000 (UTC) Received: from localhost.redhat.com (vpn1-5-170.ams2.redhat.com [10.36.5.170]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9HJcVFX009529; Mon, 17 Oct 2016 15:38:48 -0400 From: Eric Auger To: eric.auger@redhat.com, eric.auger.pro@gmail.com, peter.maydell@linaro.org, qemu-arm@nongnu.org, qemu-devel@nongnu.org, alex.williamson@redhat.com, pranav.sawargaonkar@gmail.com Date: Mon, 17 Oct 2016 19:38:26 +0000 Message-Id: <1476733110-14293-5-git-send-email-eric.auger@redhat.com> In-Reply-To: <1476733110-14293-1-git-send-email-eric.auger@redhat.com> References: <1476733110-14293-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 17 Oct 2016 19:38:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v5 4/8] memory: memory_region_find_by_name X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: diana.craciun@freescale.com, Bharat.Bhushan@freescale.com, drjones@redhat.com, christoffer.dall@linaro.org, fkan@apm.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This new helper makes possible to search for a MemoryRegion matching a given name within a root MemoryRegion. Signed-off-by: Eric Auger --- include/exec/memory.h | 11 +++++++++++ memory.c | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index f97b1f4..f62e5b5 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1217,6 +1217,17 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr, hwaddr addr, uint64_t size); /** + * memory_region_find_by_name: Locates the first #MemoryRegion within @mr + * whose name matches @name + * + * @mr: the root MemoryRegion + * @name: name of the target MemoryRegion + * + * Returns the matched memory region or NULL + */ +MemoryRegion *memory_region_find_by_name(MemoryRegion *mr, const char *name); + +/** * memory_global_dirty_log_sync: synchronize the dirty log for all memory * * Synchronizes the dirty page log for all address spaces. diff --git a/memory.c b/memory.c index 00a0ebe..3701b4f 100644 --- a/memory.c +++ b/memory.c @@ -2166,6 +2166,22 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr, return ret; } +MemoryRegion *memory_region_find_by_name(MemoryRegion *root, + const char *name) +{ + MemoryRegion *other; + + QTAILQ_FOREACH(other, &root->subregions, subregions_link) { + if (!strcmp(other->name, name)) { + memory_region_ref(other); + return other; + } else { + memory_region_find_by_name(other, name); + } + } + return NULL; +} + bool memory_region_present(MemoryRegion *container, hwaddr addr) { MemoryRegion *mr;