From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: Eric Auger 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> Subject: [Qemu-devel] [RFC v5 4/8] memory: memory_region_find_by_name List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 Cc: diana.craciun@freescale.com, christoffer.dall@linaro.org, drjones@redhat.com, Bharat.Bhushan@freescale.com, fkan@apm.com 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; -- 1.9.1