@@ -444,6 +444,14 @@ struct Object *memory_region_owner(MemoryRegion *mr);
uint64_t memory_region_size(MemoryRegion *mr);
/**
+ * memory_region_get_address_space_offset: get a memory region's address
+ * within the address space
+ *
+ * @mr: the memory region being queried.
+ */
+hwaddr memory_region_get_address_space_offset(MemoryRegion *mr);
+
+/**
* memory_region_is_ram: check whether a memory region is random access
*
* Returns %true is a memory region is random access.
@@ -1307,6 +1307,16 @@ uint64_t memory_region_size(MemoryRegion *mr)
return int128_get64(mr->size);
}
+hwaddr memory_region_get_address_space_offset(MemoryRegion *mr)
+{
+ MemoryRegion *p;
+ hwaddr result = 0x0;
+
+ for (p = mr; p != NULL; result += p->addr, p = p->container);
+
+ return result;
+}
+
const char *memory_region_name(const MemoryRegion *mr)
{
if (!mr->name) {
Adding this function would allow a MemoryRegion to compute its start address within the AddressSpace. This is done recursively based on mr->container. Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com> --- include/exec/memory.h | 8 ++++++++ memory.c | 10 ++++++++++ 2 files changed, 18 insertions(+)