diff options
| author | Alex Bennée <alex.bennee@linaro.org> | 2025-03-04 22:24:34 +0000 |
|---|---|---|
| committer | Alex Bennée <alex.bennee@linaro.org> | 2025-03-10 10:30:01 +0000 |
| commit | 455a2d265cf6c3947243d772b9e5d1b8dd13a9bf (patch) | |
| tree | cc5e155cfb31720cd491e152fc6b571e50dbec6a /plugins/api-system.c | |
| parent | 903e870f2453731f9b44ce9734cfcb5509304677 (diff) | |
| download | focaccia-qemu-455a2d265cf6c3947243d772b9e5d1b8dd13a9bf.tar.gz focaccia-qemu-455a2d265cf6c3947243d772b9e5d1b8dd13a9bf.zip | |
plugins/api: split out the vaddr/hwaddr helpers
These only work for system-mode and are NOPs for user-mode. Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20250304222439.2035603-28-alex.bennee@linaro.org>
Diffstat (limited to 'plugins/api-system.c')
| -rw-r--r-- | plugins/api-system.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/plugins/api-system.c b/plugins/api-system.c index cb0dd8f730..38560de342 100644 --- a/plugins/api-system.c +++ b/plugins/api-system.c @@ -12,6 +12,10 @@ #include "qemu/osdep.h" #include "qemu/main-loop.h" +#include "qapi/error.h" +#include "migration/blocker.h" +#include "hw/boards.h" +#include "qemu/plugin-memory.h" #include "qemu/plugin.h" /* @@ -37,3 +41,57 @@ uint64_t qemu_plugin_entry_code(void) { return 0; } + +/* + * Virtual Memory queries + */ + +static __thread struct qemu_plugin_hwaddr hwaddr_info; + +struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, + uint64_t vaddr) +{ + CPUState *cpu = current_cpu; + unsigned int mmu_idx = get_mmuidx(info); + enum qemu_plugin_mem_rw rw = get_plugin_meminfo_rw(info); + hwaddr_info.is_store = (rw & QEMU_PLUGIN_MEM_W) != 0; + + assert(mmu_idx < NB_MMU_MODES); + + if (!tlb_plugin_lookup(cpu, vaddr, mmu_idx, + hwaddr_info.is_store, &hwaddr_info)) { + error_report("invalid use of qemu_plugin_get_hwaddr"); + return NULL; + } + + return &hwaddr_info; +} + +bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr) +{ + return haddr->is_io; +} + +uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr) +{ + if (haddr) { + return haddr->phys_addr; + } + return 0; +} + +const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h) +{ + if (h && h->is_io) { + MemoryRegion *mr = h->mr; + if (!mr->name) { + unsigned maddr = (uintptr_t)mr; + g_autofree char *temp = g_strdup_printf("anon%08x", maddr); + return g_intern_string(temp); + } else { + return g_intern_string(mr->name); + } + } else { + return g_intern_static_string("RAM"); + } +} |