From nobody Tue Feb 10 06:04:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512765310470390.0077598159321; Fri, 8 Dec 2017 12:35:10 -0800 (PST) Received: from localhost ([::1]:38934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eNPMQ-0003mn-VA for importer@patchew.org; Fri, 08 Dec 2017 15:35:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eNPKW-0002JD-Sc for qemu-devel@nongnu.org; Fri, 08 Dec 2017 15:33:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eNPKU-0001K8-PH for qemu-devel@nongnu.org; Fri, 08 Dec 2017 15:33:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49418) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eNPKU-0001Jq-IL for qemu-devel@nongnu.org; Fri, 08 Dec 2017 15:33:06 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9DDF5D9E0; Fri, 8 Dec 2017 20:33:05 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-141.ams2.redhat.com [10.36.117.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C72C7C5AD; Fri, 8 Dec 2017 20:33:04 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, imammedo@redhat.com Date: Fri, 8 Dec 2017 20:32:50 +0000 Message-Id: <20171208203257.13102-2-dgilbert@redhat.com> In-Reply-To: <20171208203257.13102-1-dgilbert@redhat.com> References: <20171208203257.13102-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 08 Dec 2017 20:33:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 1/8] memory: address_space_iterate 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: maxime.coquelin@redhat.com, groug@kaod.org, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Iterate through an address space calling a function for each section. The iteration is done in order. Signed-off-by: Dr. David Alan Gilbert --- include/exec/memory.h | 23 +++++++++++++++++++++++ memory.c | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 5ed4042f87..f5a9df642e 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1987,6 +1987,29 @@ address_space_write_cached(MemoryRegionCache *cache,= hwaddr addr, address_space_write(cache->as, cache->xlat + addr, MEMTXATTRS_UNSPECIF= IED, buf, len); } =20 +/** + * ASIterateCallback: Function type called by address_space_iterate + * + * Return 0 on success or a negative error code. + * + * @mrs: Memory region section for this range + * @opaque: The opaque value passed in to the iterator. + */ +typedef int (*ASIterateCallback)(MemoryRegionSection *mrs, void *opaque); + +/** + * address_space_iterate: Call the function for each address range in the + * AddressSpace, in sorted order. + * + * Return 0 on success or a negative error code. + * + * @as: Address space to iterate over + * @cb: Function to call. If the function returns none-0 the iteration wi= ll + * stop. + * @opaque: Value to pass to the function + */ +int +address_space_iterate(AddressSpace *as, ASIterateCallback cb, void *opaque= ); #endif =20 #endif diff --git a/memory.c b/memory.c index e26e5a3b1d..f45137f25e 100644 --- a/memory.c +++ b/memory.c @@ -2810,6 +2810,28 @@ void address_space_destroy(AddressSpace *as) call_rcu(as, do_address_space_destroy, rcu); } =20 +int address_space_iterate(AddressSpace *as, ASIterateCallback cb, + void *opaque) +{ + int res =3D 0; + FlatView *fv =3D address_space_to_flatview(as); + FlatRange *range; + + flatview_ref(fv); + + FOR_EACH_FLAT_RANGE(range, fv) { + MemoryRegionSection mrs =3D section_from_flat_range(range, fv); + res =3D cb(&mrs, opaque); + if (res) { + break; + } + } + + flatview_unref(fv); + + return res; +} + static const char *memory_region_type(MemoryRegion *mr) { if (memory_region_is_ram_device(mr)) { --=20 2.14.3