Function that convert a number of target_pages into its size in MiB. Suggested-by: Richard Henderson <richard.hender...@linaro.org> Richard Henderson <richard.hender...@linaro.org> Signed-off-by: Juan Quintela <quint...@redhat.com> Message-Id: <20230511141208.17779-2-quint...@redhat.com> --- include/exec/target_page.h | 1 + softmmu/physmem.c | 11 +++++++++++ 2 files changed, 12 insertions(+)
diff --git a/include/exec/target_page.h b/include/exec/target_page.h index 96726c36a4..bbf37aea17 100644 --- a/include/exec/target_page.h +++ b/include/exec/target_page.h @@ -18,4 +18,5 @@ size_t qemu_target_page_size(void); int qemu_target_page_bits(void); int qemu_target_page_bits_min(void); +size_t qemu_target_pages_to_MiB(size_t pages); #endif diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 0e0182d9f2..efaed36773 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -3357,6 +3357,17 @@ int qemu_target_page_bits_min(void) return TARGET_PAGE_BITS_MIN; } +/* Convert target pages to MiB (2**20). */ +size_t qemu_target_pages_to_MiB(size_t pages) +{ + int page_bits = TARGET_PAGE_BITS; + + /* So far, the largest (non-huge) page size is 64k, i.e. 16 bits. */ + g_assert(page_bits < 20); + + return pages >> (20 - page_bits); +} + bool cpu_physical_memory_is_io(hwaddr phys_addr) { MemoryRegion*mr; -- 2.40.1