Now that all targets implement the get_note_size sysemu op, we can
replace the per-target cpu_get_note_size() implementations (and its stub)
with a single generic version in hw/core/cpu-system.c, taking the cpu as
parameter, like other dump related sysemu ops wrappers.

Signed-off-by: Pierrick Bouvier <[email protected]>
---
 dump/dump.c                  |  2 +-
 hw/core/cpu-system.c         |  9 +++++++++
 include/hw/core/cpu.h        | 13 +++++++++++++
 include/system/dump-arch.h   |  2 --
 stubs/dump.c                 | 21 ---------------------
 stubs/meson.build            |  1 -
 target/arm/arch_dump.c       |  5 -----
 target/i386/arch_dump.c      |  5 -----
 target/loongarch/arch_dump.c |  5 -----
 target/ppc/arch_dump.c       |  5 -----
 target/riscv/arch_dump.c     |  5 -----
 target/s390x/arch_dump.c     |  5 -----
 12 files changed, 23 insertions(+), 55 deletions(-)
 delete mode 100644 stubs/dump.c

diff --git a/dump/dump.c b/dump/dump.c
index 60ecde02173..23ac689907a 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -1873,7 +1873,7 @@ static void dump_init(DumpState *s, int fd, bool 
has_format,
         s->dump_info.page_size = qemu_target_page_size();
     }
 
-    s->note_size = cpu_get_note_size(s->dump_info.d_class,
+    s->note_size = cpu_get_note_size(first_cpu, s->dump_info.d_class,
                                      s->dump_info.d_machine, nr_cpus);
     assert(s->note_size >= 0);
 
diff --git a/hw/core/cpu-system.c b/hw/core/cpu-system.c
index 499fad1c68a..3704dd40640 100644
--- a/hw/core/cpu-system.c
+++ b/hw/core/cpu-system.c
@@ -139,6 +139,15 @@ int cpu_get_dump_info(const CPUState *cpu, ArchDumpInfo 
*info,
     return cpu->cc->sysemu_ops->get_dump_info(cpu, info, guest_phys_blocks);
 }
 
+ssize_t cpu_get_note_size(const CPUState *cpu, int class, int machine,
+                          int nr_cpus)
+{
+    if (!cpu->cc->sysemu_ops->get_note_size) {
+        return -1;
+    }
+    return cpu->cc->sysemu_ops->get_note_size(cpu, class, machine, nr_cpus);
+}
+
 bool cpu_internal_is_big_endian(CPUState *cpu)
 {
     if (cpu->cc->sysemu_ops->internal_is_big_endian) {
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index d80a6a4e752..a3b4c6c08a7 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -712,6 +712,19 @@ int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, 
CPUState *cpu,
 int cpu_get_dump_info(const CPUState *cpu, ArchDumpInfo *info,
                       const GuestPhysBlockList *guest_phys_blocks);
 
+/**
+ * cpu_get_note_size:
+ * @cpu: The CPU whose memory is to be dumped
+ * @class: ELF class reported by cpu_get_dump_info()
+ * @machine: ELF machine reported by cpu_get_dump_info()
+ * @nr_cpus: Number of CPUs to be dumped
+ *
+ * Returns: size of the ELF notes needed to dump @nr_cpus CPUs,
+ * or -1 if not supported.
+ */
+ssize_t cpu_get_note_size(const CPUState *cpu, int class, int machine,
+                          int nr_cpus);
+
 /**
  * cpu_memory_rw_debug:
  * @cpu: The CPU whose memory is to be accessed
diff --git a/include/system/dump-arch.h b/include/system/dump-arch.h
index b89e495661f..1df88e732d0 100644
--- a/include/system/dump-arch.h
+++ b/include/system/dump-arch.h
@@ -27,6 +27,4 @@ typedef struct ArchDumpInfo {
     void (*arch_cleanup_fn)(DumpState *s);
 } ArchDumpInfo;
 
-ssize_t cpu_get_note_size(int class, int machine, int nr_cpus);
-
 #endif
diff --git a/stubs/dump.c b/stubs/dump.c
deleted file mode 100644
index 2ce3c5e274d..00000000000
--- a/stubs/dump.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * QEMU dump
- *
- * Copyright Fujitsu, Corp. 2011, 2012
- *
- * Authors:
- *     Wen Congyang <[email protected]>
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- *
- */
-
-#include "qemu/osdep.h"
-#include "system/dump-arch.h"
-
-ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
-{
-    return -1;
-}
-
diff --git a/stubs/meson.build b/stubs/meson.build
index dcb67ce5295..4a26f795a6a 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -71,7 +71,6 @@ if have_system
   # adding more of these.  If the symbol is used in specific_ss,
   # in particular, consider defining a preprocessor macro via
   # Kconfig or configs/targets/.
-  stub_ss.add(files('dump.c'))
   stub_ss.add(files('cmos.c'))
   stub_ss.add(files('fw_cfg.c'))
   if igvm.found()
diff --git a/target/arm/arch_dump.c b/target/arm/arch_dump.c
index 60456e81bf8..986ce3d7884 100644
--- a/target/arm/arch_dump.c
+++ b/target/arm/arch_dump.c
@@ -453,8 +453,3 @@ ssize_t arm_get_note_size(const CPUState *cs, int class, 
int machine,
 
     return note_size * nr_cpus;
 }
-
-ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
-{
-    return arm_get_note_size(first_cpu, class, machine, nr_cpus);
-}
diff --git a/target/i386/arch_dump.c b/target/i386/arch_dump.c
index 4d8e9374cd1..4a375f5cbe0 100644
--- a/target/i386/arch_dump.c
+++ b/target/i386/arch_dump.c
@@ -461,8 +461,3 @@ ssize_t x86_get_note_size(const CPUState *cs, int class, 
int machine,
 
     return (elf_note_size + qemu_note_size) * nr_cpus;
 }
-
-ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
-{
-    return x86_get_note_size(first_cpu, class, machine, nr_cpus);
-}
diff --git a/target/loongarch/arch_dump.c b/target/loongarch/arch_dump.c
index e27bd0f6497..0b39fc73c12 100644
--- a/target/loongarch/arch_dump.c
+++ b/target/loongarch/arch_dump.c
@@ -163,8 +163,3 @@ ssize_t loongarch_get_note_size(const CPUState *cs, int 
class,
 
     return note_size * nr_cpus;
 }
-
-ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
-{
-    return loongarch_get_note_size(first_cpu, class, machine, nr_cpus);
-}
diff --git a/target/ppc/arch_dump.c b/target/ppc/arch_dump.c
index b59fef3c48e..f54729d77a8 100644
--- a/target/ppc/arch_dump.c
+++ b/target/ppc/arch_dump.c
@@ -269,11 +269,6 @@ ssize_t ppc_get_note_size(const CPUState *cs, int class, 
int machine,
     return (elf_note_size) * nr_cpus;
 }
 
-ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
-{
-    return ppc_get_note_size(first_cpu, class, machine, nr_cpus);
-}
-
 static int ppc_write_all_elf_notes(const char *note_name,
                                    WriteCoreDumpFunction f,
                                    PowerPCCPU *cpu, int id,
diff --git a/target/riscv/arch_dump.c b/target/riscv/arch_dump.c
index 74b1489ddcb..05b637bea93 100644
--- a/target/riscv/arch_dump.c
+++ b/target/riscv/arch_dump.c
@@ -195,8 +195,3 @@ ssize_t riscv_get_note_size(const CPUState *cs, int class, 
int machine,
 
     return note_size * nr_cpus;
 }
-
-ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
-{
-    return riscv_get_note_size(first_cpu, class, machine, nr_cpus);
-}
diff --git a/target/s390x/arch_dump.c b/target/s390x/arch_dump.c
index 3ca85e6b64b..5048fbaf982 100644
--- a/target/s390x/arch_dump.c
+++ b/target/s390x/arch_dump.c
@@ -496,8 +496,3 @@ ssize_t s390_get_note_size(const CPUState *cs, int class, 
int machine,
 
     return (elf_note_size) * nr_cpus;
 }
-
-ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
-{
-    return s390_get_note_size(first_cpu, class, machine, nr_cpus);
-}
-- 
2.43.0


Reply via email to