From patchwork Thu Oct 6 09:50:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9364517 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 ED72F600C8 for ; Thu, 6 Oct 2016 09:51:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF95228E94 for ; Thu, 6 Oct 2016 09:51:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D457A28E96; Thu, 6 Oct 2016 09:51:47 +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 885E228E94 for ; Thu, 6 Oct 2016 09:51:47 +0000 (UTC) Received: from localhost ([::1]:54332 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bs5L8-00072a-Om for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Oct 2016 05:51:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44845) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bs5KW-0006zv-CL for qemu-devel@nongnu.org; Thu, 06 Oct 2016 05:51:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bs5KV-0007Fk-Cu for qemu-devel@nongnu.org; Thu, 06 Oct 2016 05:51:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60274) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bs5KT-0007EJ-0e; Thu, 06 Oct 2016 05:51:05 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 61A5A12B48; Thu, 6 Oct 2016 09:51:04 +0000 (UTC) Received: from localhost.redhat.com (vpn1-6-233.ams2.redhat.com [10.36.6.233]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u969okS4016130; Thu, 6 Oct 2016 05:51:01 -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: Thu, 6 Oct 2016 09:50:41 +0000 Message-Id: <1475747444-12552-6-git-send-email-eric.auger@redhat.com> In-Reply-To: <1475747444-12552-1-git-send-email-eric.auger@redhat.com> References: <1475747444-12552-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 06 Oct 2016 09:51:04 +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 v3 5/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 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;