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.purcare...@freescale.com> --- include/exec/memory.h | 8 ++++++++ memory.c | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index d165b27..7503819 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -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. diff --git a/memory.c b/memory.c index ef0be1c..7445032 100644 --- a/memory.c +++ b/memory.c @@ -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) { -- 1.7.10.4