From: Juan Quintela Date: Thu, 11 May 2023 14:12:04 +0000 (+0200) Subject: softmmu: Create qemu_target_pages_to_MiB() X-Git-Tag: v8.1.0-rc0~126^2~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=62c5e181eef9482c081bed2cdcc61c1091a7739c;p=thirdparty%2Fqemu.git softmmu: Create qemu_target_pages_to_MiB() Function that convert a number of target_pages into its size in MiB. Suggested-by: Richard Henderson Richard Henderson Signed-off-by: Juan Quintela Message-Id: <20230511141208.17779-2-quintela@redhat.com> --- diff --git a/include/exec/target_page.h b/include/exec/target_page.h index 96726c36a41..bbf37aea177 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 0e0182d9f2a..efaed36773c 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;