address_space_lookup_region() retures the pointer to
MemoryRegionSection, instead of MemoryRegion, so it's better to rename
it to address_space_lookup_section().
And add its declaration to memory.h so that bindgen could generate its
binding.
This interface will be used to implement GuestMemory::find_region() of
vm_memory crate.
In addition, add its documentation in memory.h.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
include/system/memory.h | 21 +++++++++++++++++++++
system/physmem.c | 8 ++++----
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/include/system/memory.h b/include/system/memory.h
index 4b9a2f528d86..f492e1fc78bf 100644
--- a/include/system/memory.h
+++ b/include/system/memory.h
@@ -1203,6 +1203,27 @@ struct FlatView {
MemoryRegion *root;
};
+/**
+ * address_space_lookup_section: Find the MemoryRegionSection by a
+ * given #AddressSpaceDispatch.
+ *
+ * @d: The AddressSpaceDispatch to search within.
+ * @addr: The address to look up.
+ * @resolve_subpage: If 'true', resolve to a subpage section if the
+ * region is a subpage container.
+ *
+ * This function translates a address (@addr) into its corresponding
+ * #MemoryRegionSection within a given address space dispatch (@d).
+ * Called within RCU critical section.
+ *
+ * Returns:
+ * A pointer to the #MemoryRegionSection. If the address is not
+ * mapped, this will be a pointer to the 'unassigned' section.
+ */
+MemoryRegionSection *address_space_lookup_section(AddressSpaceDispatch *d,
+ hwaddr addr,
+ bool resolve_subpage);
+
/**
* address_space_to_flatview: Get a transient RCU-protected pointer to
* the current FlatView.
diff --git a/system/physmem.c b/system/physmem.c
index e5dd760e0bca..785c9a4050c6 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -341,9 +341,9 @@ static MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr addr)
}
/* Called from RCU critical section */
-static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d,
- hwaddr addr,
- bool resolve_subpage)
+MemoryRegionSection *address_space_lookup_section(AddressSpaceDispatch *d,
+ hwaddr addr,
+ bool resolve_subpage)
{
MemoryRegionSection *section = qatomic_read(&d->mru_section);
subpage_t *subpage;
@@ -369,7 +369,7 @@ address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr *x
MemoryRegion *mr;
Int128 diff;
- section = address_space_lookup_region(d, addr, resolve_subpage);
+ section = address_space_lookup_section(d, addr, resolve_subpage);
/* Compute offset within MemoryRegionSection */
addr -= section->offset_within_address_space;
--
2.34.1