[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH V4 05/25] as_flat_walk
From: |
Steve Sistare |
Subject: |
[PATCH V4 05/25] as_flat_walk |
Date: |
Tue, 6 Jul 2021 09:45:36 -0700 |
Add an iterator over the sections of a flattened address space.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
include/exec/memory.h | 17 +++++++++++++++++
softmmu/memory.c | 18 ++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index e8b71d8..d87c059 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2003,6 +2003,23 @@ bool memory_region_present(MemoryRegion *container,
hwaddr addr);
*/
bool memory_region_is_mapped(MemoryRegion *mr);
+typedef int (*qemu_flat_walk_cb)(MemoryRegionSection *s,
+ void *handle,
+ Error **errp);
+
+/**
+ * as_flat_walk: walk the ranges in the address space flat view and call @func
+ * for each. Return 0 on success, else return non-zero with a message in
+ * @errp.
+ *
+ * @as: target address space
+ * @func: callback function
+ * @handle: passed to @func
+ * @errp: passed to @func
+ */
+int as_flat_walk(AddressSpace *as, qemu_flat_walk_cb func,
+ void *handle, Error **errp);
+
/**
* memory_region_find: translate an address/size relative to a
* MemoryRegion into a #MemoryRegionSection.
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 7197559..b2d5092 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -2570,6 +2570,24 @@ bool memory_region_is_mapped(MemoryRegion *mr)
return mr->container ? true : false;
}
+int as_flat_walk(AddressSpace *as, qemu_flat_walk_cb func,
+ void *handle, Error **errp)
+{
+ FlatView *view = address_space_get_flatview(as);
+ FlatRange *fr;
+ int ret;
+
+ FOR_EACH_FLAT_RANGE(fr, view) {
+ MemoryRegionSection section = section_from_flat_range(fr, view);
+ ret = func(§ion, handle, errp);
+ if (ret) {
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
/* Same as memory_region_find, but it does not add a reference to the
* returned region. It must be called from an RCU critical section.
*/
--
1.8.3.1
- [PATCH V4 00/25] Live Update, Steve Sistare, 2021/07/06
- [PATCH V4 01/25] qemu_ram_volatile, Steve Sistare, 2021/07/06
- [PATCH V4 02/25] cpr: reboot mode, Steve Sistare, 2021/07/06
- [PATCH V4 05/25] as_flat_walk,
Steve Sistare <=
- [PATCH V4 03/25] cpr: QMP interfaces for reboot, Steve Sistare, 2021/07/06
- [PATCH V4 06/25] oslib: qemu_clr_cloexec, Steve Sistare, 2021/07/06
- [PATCH V4 07/25] machine: memfd-alloc option, Steve Sistare, 2021/07/06
- [PATCH V4 08/25] vl: add helper to request re-exec, Steve Sistare, 2021/07/06
- [PATCH V4 09/25] string to strList, Steve Sistare, 2021/07/06
- [PATCH V4 10/25] util: env var helpers, Steve Sistare, 2021/07/06
- [PATCH V4 12/25] cpr: QMP interfaces for restart, Steve Sistare, 2021/07/06
- [PATCH V4 11/25] cpr: restart mode, Steve Sistare, 2021/07/06
- [PATCH V4 13/25] cpr: HMP interfaces for restart, Steve Sistare, 2021/07/06
- [PATCH V4 14/25] pci: export functions for cpr, Steve Sistare, 2021/07/06