Skip to contentSkip to conversation

qemu: Introduce TargetInfo API (for single binary)

RFC In review Philippe Mathieu-Daudé 3 participants 51 messages Apr 3, 2025 – Apr 17, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover qemu: Introduce TargetInfo API (for single binary)

Hi,

At this point this series is mostly a draft for Pierrick. It implement his idea of a per-binary structure containing all target-specific information, exposing them via a target-agnostic API. Commits are barely commented, since I'd rather get feedback before pursuing further.

Available here, based on tcg-next:
https://gitlab.com/philmd/qemu/-/tags/single-binary-target-info-api-rfc-v1

Another series will follow with the ARM implementation.

Regards,

Phil.

Philippe Mathieu-Daudé (19):
qemu: Introduce TargetInfo API in 'target_info.h'
qemu: Convert target_name() to TargetInfo API
qemu: Factor target_system_arch() out
qemu: Convert target_words_bigendian() to TargetInfo API
qemu: Introduce target_long_bits()
target/tricore: Replace TARGET_LONG_BITS -> target_long_bits() target/hppa: Replace TARGET_LONG_BITS -> target_long_bits() target/riscv: Replace TARGET_LONG_BITS -> target_long_bits()
qemu: Introduce target_cpu_type()
cpus: Replace CPU_RESOLVING_TYPE -> target_cpu_type() accel/tcg: Replace CPU_RESOLVING_TYPE -> target_cpu_type()
cpus: Move target-agnostic methods out of cpu-target.c
accel: Replace CPU_RESOLVING_TYPE -> target_cpu_type()
accel: Implement accel_init_ops_interfaces() for both system/user mode
accel: Include missing 'qemu/accel.h' header in accel-internal.h
accel: Make AccelCPUClass structure target-agnostic
accel: Move target-agnostic code from accel-target.c -> accel-common.c
qemu: Prepare per-binary QOM filter via TYPE_BINARY_PREFIX system/vl: Filter machine list for binary using
machine_binary_filter()

 meson.build                                |  10 ++
 accel/{accel-system.h => accel-internal.h} |  10 +-
 include/accel/accel-cpu-target.h           |  12 +-
 include/accel/accel-cpu.h                  |  23 ++++
 include/exec/poison.h                      |   1 +
 include/exec/tswap.h                       |  13 +-
 include/hw/boards.h                        |   1 +
 include/hw/core/cpu.h                      |   2 -
 include/qemu/target_info-impl.h            |  38 ++++++
 include/qemu/target_info-qom.h             |  14 ++
 include/qemu/target_info.h                 |  39 ++++++
 accel/accel-common.c                       | 142 +++++++++++++++++++++
 accel/accel-system.c                       |   4 +-
 accel/accel-target.c                       | 134 -------------------
 accel/accel-user.c                         |   6 +
 accel/tcg/tcg-all.c                        |   4 +-
 cpu-target.c                               |  88 +------------
 hw/core/cpu-common.c                       |  74 +++++++++++
 hw/core/cpu-system.c                       |   2 +-
 hw/core/machine-qmp-cmds.c                 |   7 +-
 hw/display/vga.c                           |   2 +-
 hw/riscv/riscv-iommu.c                     |   3 +-
 hw/riscv/riscv_hart.c                      |   3 +-
 hw/virtio/virtio.c                         |   2 +-
 plugins/loader.c                           |   2 +-
 system/qtest.c                             |   1 +
 system/vl.c                                |  26 +++-
 target/hppa/mem_helper.c                   |   3 +-
 target/hppa/translate.c                    |   3 +-
 target/tricore/translate.c                 |   6 +-
 target_info-qom.c                          |  15 +++
 target_info-stub.c                         |  29 +++++
 target_info.c                              |  48 +++++++
 accel/meson.build                          |   1 +
 34 files changed, 499 insertions(+), 269 deletions(-)
 rename accel/{accel-system.h => accel-internal.h} (56%)
 create mode 100644 include/accel/accel-cpu.h
 create mode 100644 include/qemu/target_info-impl.h
 create mode 100644 include/qemu/target_info-qom.h
 create mode 100644 include/qemu/target_info.h
 create mode 100644 accel/accel-common.c
 create mode 100644 target_info-qom.c
 create mode 100644 target_info-stub.c
 create mode 100644 target_info.c
Signature · 1 line
2.47.1
#1 lore raw

RFC 1/19 qemu: Introduce TargetInfo API in 'target_info.h'

---
 meson.build                     |  9 +++++++++
 include/exec/poison.h           |  1 +
 include/qemu/target_info-impl.h | 21 +++++++++++++++++++++
 include/qemu/target_info.h      | 18 ++++++++++++++++++
 target_info-stub.c              | 23 +++++++++++++++++++++++
 target_info.c                   | 16 ++++++++++++++++
 6 files changed, 88 insertions(+)
 create mode 100644 include/qemu/target_info-impl.h
 create mode 100644 include/qemu/target_info.h
 create mode 100644 target_info-stub.c
 create mode 100644 target_info.c
meson.build +9 -0
index bcb9d39a387..de9c9dacd35 100644
@@ -3262,6 +3262,9 @@ host_kconfig = \
 
 ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR', 'TARGET_ARCH' ]
 
+target_info = [
+]
+
 default_targets = 'CONFIG_DEFAULT_TARGETS' in config_host
 actual_target_dirs = []
 fdt_required = []
@@ -3368,6 +3371,9 @@ foreach target : target_dirs
       config_target_data.set(k, v)
     endif
   endforeach
+  if target not in target_info
+    config_target_data.set('TARGET_INFO_STUB_NEEDED', 1)
+  endif
   config_target_data.set('QEMU_ARCH',
                          'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper())
   config_target_h += {target: configure_file(output: target + '-config-target.h',
@@ -3807,6 +3813,9 @@ endif
 common_ss.add(pagevary)
 specific_ss.add(files('page-target.c', 'page-vary-target.c'))
 
+specific_ss.add(files('target_info-stub.c'))
+common_ss.add(files('target_info.c'))
+
 subdir('backends')
 subdir('disas')
 subdir('migration')
include/exec/poison.h +1 -0
index bc422719d80..00aedc41d82 100644
@@ -38,6 +38,7 @@
 #pragma GCC poison TARGET_BIG_ENDIAN
 #pragma GCC poison TCG_GUEST_DEFAULT_MO
 #pragma GCC poison TARGET_HAS_PRECISE_SMC
+#pragma GCC poison TARGET_INFO_STUB_NEEDED
 
 #pragma GCC poison TARGET_LONG_BITS
 #pragma GCC poison TARGET_FMT_lx
include/qemu/target_info-impl.h new file +21 -0
new file mode 100644
index 00000000000..b340e192fce
@@ -0,0 +1,21 @@
+/*
+ * QEMU binary helpers
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_TARGET_INFO_IMPL_H
+#define QEMU_TARGET_INFO_IMPL_H
+
+#include "qemu/target_info.h"
+
+struct BinaryTargetInfo {
+
+    /* runtime equivalent of TARGET_INFO_STUB_NEEDED definition */
+    bool is_stub;
+
+};
+
+#endif
include/qemu/target_info.h new file +18 -0
new file mode 100644
index 00000000000..fab3f3153ea
@@ -0,0 +1,18 @@
+/*
+ * QEMU binary helpers
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_TARGET_INFO_H
+#define QEMU_TARGET_INFO_H
+
+typedef struct BinaryTargetInfo BinaryTargetInfo;
+
+const BinaryTargetInfo *target_info(void);
+
+bool target_info_is_stub(void);
+
+#endif
target_info-stub.c new file +23 -0
new file mode 100644
index 00000000000..d683a05977d
@@ -0,0 +1,23 @@
+/*
+ * QEMU target info stubs
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/target_info-impl.h"
+
+#ifdef TARGET_INFO_STUB_NEEDED
+
+static const BinaryTargetInfo target_info_stub = {
+    .is_stub = true,
+};
+
+const BinaryTargetInfo *target_info(void)
+{
+    return &target_info_stub;
+}
+
+#endif /* TARGET_INFO_STUB_NEEDED */
target_info.c new file +16 -0
new file mode 100644
index 00000000000..cb17d29b86d
@@ -0,0 +1,16 @@
+/*
+ * QEMU legacy binary helpers
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/target_info-impl.h"
+#include "qemu/target_info.h"
+
+bool target_info_is_stub(void)
+{
+    return target_info()->is_stub;
+}
Signature · 1 line
2.47.1
#2 lore raw

Re: [RFC PATCH-for-10.1 01/19] qemu: Introduce TargetInfo API in 'target_info.h'

Quoted 19 lines · Philippe Mathieu-Daudé
---
  meson.build                     |  9 +++++++++
  include/exec/poison.h           |  1 +
  include/qemu/target_info-impl.h | 21 +++++++++++++++++++++
  include/qemu/target_info.h      | 18 ++++++++++++++++++
  target_info-stub.c              | 23 +++++++++++++++++++++++
  target_info.c                   | 16 ++++++++++++++++
  6 files changed, 88 insertions(+)

create mode 100644 include/qemu/target_info-impl.h create mode 100644 include/qemu/target_info.h create mode 100644 target_info-stub.c create mode 100644 target_info.c

meson.build +0 -0
index bcb9d39a387..de9c9dacd35 100644

meson.build host_kconfig = \ · line 3267

Quoted 6 lines
meson.build +3 -0
@@ -3262,6 +3262,9 @@ host_kconfig = \
 
  ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR', 'TARGET_ARCH' ]
 
+target_info = [
+]
+

To follow what is already implemented, we should use a dictionary per target, pointing to the associated source file. This way, it allows to move files listing directly to each architecture, and the top meson.build only needs to add stub if it is not defined.

meson.build foreach target : target_dirs · line 3376

Quoted 10 lines
meson.build +3 -0
  default_targets = 'CONFIG_DEFAULT_TARGETS' in config_host
  actual_target_dirs = []
  fdt_required = []
@@ -3368,6 +3371,9 @@ foreach target : target_dirs
        config_target_data.set(k, v)
      endif
    endforeach
+  if target not in target_info
+    config_target_data.set('TARGET_INFO_STUB_NEEDED', 1)
+  endif

With the dictionary, this is not needed anymore.

Quoted 36 lines
meson.build +3 -0
    config_target_data.set('QEMU_ARCH',
                           'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper())
    config_target_h += {target: configure_file(output: target + '-config-target.h',
@@ -3807,6 +3813,9 @@ endif
  common_ss.add(pagevary)
  specific_ss.add(files('page-target.c', 'page-vary-target.c'))
 
+specific_ss.add(files('target_info-stub.c'))
+common_ss.add(files('target_info.c'))
+
  subdir('backends')
  subdir('disas')
  subdir('migration')
include/exec/poison.h +1 -0
index bc422719d80..00aedc41d82 100644
@@ -38,6 +38,7 @@
  #pragma GCC poison TARGET_BIG_ENDIAN
  #pragma GCC poison TCG_GUEST_DEFAULT_MO
  #pragma GCC poison TARGET_HAS_PRECISE_SMC
+#pragma GCC poison TARGET_INFO_STUB_NEEDED
 
  #pragma GCC poison TARGET_LONG_BITS
  #pragma GCC poison TARGET_FMT_lx
include/qemu/target_info-impl.h new file +5 -0
new file mode 100644
index 00000000000..b340e192fce
@@ -0,0 +1,21 @@
+/*
+ * QEMU binary helpers
+ *
+ *  Copyright (c) Linaro
+ *

include/qemu/target_info-impl.h line 15

Quoted 10 lines
include/qemu/target_info-impl.h new file +10 -0
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_TARGET_INFO_IMPL_H
+#define QEMU_TARGET_INFO_IMPL_H
+
+#include "qemu/target_info.h"
+
+struct BinaryTargetInfo {
+

I would be in favor to rename exising TargetInfo in QMPTargetInfo, and reuse that name here.

include/qemu/target_info-impl.h line 17

Quoted 2 lines
include/qemu/target_info-impl.h new file +2 -0
+    /* runtime equivalent of TARGET_INFO_STUB_NEEDED definition */
+    bool is_stub;

Why do we want to know if it's a stub at runtime?

Quoted 79 lines
include/qemu/target_info-impl.h new file +4 -0
+
+};
+
+#endif
include/qemu/target_info.h new file +18 -0
new file mode 100644
index 00000000000..fab3f3153ea
@@ -0,0 +1,18 @@
+/*
+ * QEMU binary helpers
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_TARGET_INFO_H
+#define QEMU_TARGET_INFO_H
+
+typedef struct BinaryTargetInfo BinaryTargetInfo;
+
+const BinaryTargetInfo *target_info(void);
+
+bool target_info_is_stub(void);
+
+#endif
target_info-stub.c new file +23 -0
new file mode 100644
index 00000000000..d683a05977d
@@ -0,0 +1,23 @@
+/*
+ * QEMU target info stubs
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/target_info-impl.h"
+
+#ifdef TARGET_INFO_STUB_NEEDED
+
+static const BinaryTargetInfo target_info_stub = {
+    .is_stub = true,
+};
+
+const BinaryTargetInfo *target_info(void)
+{
+    return &target_info_stub;
+}
+
+#endif /* TARGET_INFO_STUB_NEEDED */
target_info.c new file +16 -0
new file mode 100644
index 00000000000..cb17d29b86d
@@ -0,0 +1,16 @@
+/*
+ * QEMU legacy binary helpers
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/target_info-impl.h"
+#include "qemu/target_info.h"
+
+bool target_info_is_stub(void)
+{
+    return target_info()->is_stub;
+}
#3 lore raw

RFC 2/19 qemu: Convert target_name() to TargetInfo API

In reply to Philippe Mathieu-Daudé
---
 include/hw/core/cpu.h           | 2 --
 include/qemu/target_info-impl.h | 3 +++
 include/qemu/target_info.h      | 2 ++
 cpu-target.c                    | 5 -----
 hw/core/machine-qmp-cmds.c      | 1 +
 plugins/loader.c                | 2 +-
 system/vl.c                     | 2 +-
 target_info-stub.c              | 1 +
 target_info.c                   | 5 +++++
 9 files changed, 14 insertions(+), 9 deletions(-)
include/hw/core/cpu.h +0 -2
index 5b645df59f5..9d9448341d1 100644
@@ -1115,8 +1115,6 @@ bool cpu_exec_realizefn(CPUState *cpu, Error **errp);
 void cpu_exec_unrealizefn(CPUState *cpu);
 void cpu_exec_reset_hold(CPUState *cpu);
 
-const char *target_name(void);
-
 #ifdef COMPILING_PER_TARGET
 
 extern const VMStateDescription vmstate_cpu_common;
include/qemu/target_info-impl.h +3 -0
index b340e192fce..00bb746572b 100644
@@ -16,6 +16,9 @@ struct BinaryTargetInfo {
     /* runtime equivalent of TARGET_INFO_STUB_NEEDED definition */
     bool is_stub;
 
+    /* runtime equivalent of TARGET_NAME definition */
+    const char *const name;
+
 };
 
 #endif
include/qemu/target_info.h +2 -0
index fab3f3153ea..5b8f17a15a3 100644
@@ -15,4 +15,6 @@ const BinaryTargetInfo *target_info(void);
 
 bool target_info_is_stub(void);
 
+const char *target_name(void);
+
 #endif
cpu-target.c +0 -5
index c99d208a7c4..3f82d3ea444 100644
@@ -165,8 +165,3 @@ bool target_words_bigendian(void)
 {
     return TARGET_BIG_ENDIAN;
 }
-
-const char *target_name(void)
-{
-    return TARGET_NAME;
-}
hw/core/machine-qmp-cmds.c +1 -0
index 3130c5cd456..6701e210f54 100644
@@ -19,6 +19,7 @@
 #include "qapi/qobject-input-visitor.h"
 #include "qapi/type-helpers.h"
 #include "qemu/uuid.h"
+#include "qemu/target_info.h"
 #include "qom/qom-qobject.h"
 #include "system/hostmem.h"
 #include "system/hw_accel.h"
plugins/loader.c +1 -1
index 7523d554f03..36a4e88d4db 100644
@@ -29,7 +29,7 @@
 #include "qemu/xxhash.h"
 #include "qemu/plugin.h"
 #include "qemu/memalign.h"
-#include "hw/core/cpu.h"
+#include "qemu/target_info.h"
 #include "exec/tb-flush.h"
 
 #include "plugin.h"
system/vl.c +1 -1
index c17945c4939..d8a0fe713c9 100644
@@ -40,6 +40,7 @@
 #include "qemu/help_option.h"
 #include "qemu/hw-version.h"
 #include "qemu/uuid.h"
+#include "qemu/target_info.h"
 #include "system/reset.h"
 #include "system/runstate.h"
 #include "system/runstate-action.h"
@@ -79,7 +80,6 @@
 #include "hw/block/block.h"
 #include "hw/i386/x86.h"
 #include "hw/i386/pc.h"
-#include "hw/core/cpu.h"
 #include "migration/cpr.h"
 #include "migration/misc.h"
 #include "migration/snapshot.h"
target_info-stub.c +1 -0
index d683a05977d..db61a335908 100644
@@ -13,6 +13,7 @@
 
 static const BinaryTargetInfo target_info_stub = {
     .is_stub = true,
+    .name = TARGET_NAME,
 };
 
 const BinaryTargetInfo *target_info(void)
target_info.c +5 -0
index cb17d29b86d..6b44ea9fc0e 100644
@@ -14,3 +14,8 @@ bool target_info_is_stub(void)
 {
     return target_info()->is_stub;
 }
+
+const char *target_name(void)
+{
+    return target_info()->name;
+}
Signature · 1 line
2.47.1
Reviewed-by on v1 2/19
#4 lore raw

Re: [RFC PATCH-for-10.1 02/19] qemu: Convert target_name() to TargetInfo API

Quoted 13 lines · Philippe Mathieu-Daudé
---
  include/hw/core/cpu.h           | 2 --
  include/qemu/target_info-impl.h | 3 +++
  include/qemu/target_info.h      | 2 ++
  cpu-target.c                    | 5 -----
  hw/core/machine-qmp-cmds.c      | 1 +
  plugins/loader.c                | 2 +-
  system/vl.c                     | 2 +-
  target_info-stub.c              | 1 +
  target_info.c                   | 5 +++++
  9 files changed, 14 insertions(+), 9 deletions(-)
#5 lore raw

RFC 3/19 qemu: Factor target_system_arch() out

In reply to Philippe Mathieu-Daudé
---
 include/qemu/target_info-impl.h |  4 ++++
 include/qemu/target_info.h      |  4 ++++
 hw/core/machine-qmp-cmds.c      |  6 ++----
 target_info-stub.c              |  1 +
 target_info.c                   | 12 ++++++++++++
 5 files changed, 23 insertions(+), 4 deletions(-)
include/qemu/target_info-impl.h +4 -0
index 00bb746572b..0cec211e362 100644
@@ -10,6 +10,7 @@
 #define QEMU_TARGET_INFO_IMPL_H
 
 #include "qemu/target_info.h"
+#include "qapi/qapi-types-machine.h"
 
 struct BinaryTargetInfo {
 
@@ -19,6 +20,9 @@ struct BinaryTargetInfo {
     /* runtime equivalent of TARGET_NAME definition */
     const char *const name;
 
+    /* related to TARGET_ARCH definition */
+    SysEmuTarget system_arch;
+
 };
 
 #endif
include/qemu/target_info.h +4 -0
index 5b8f17a15a3..6ca36dae8a3 100644
@@ -9,6 +9,8 @@
 #ifndef QEMU_TARGET_INFO_H
 #define QEMU_TARGET_INFO_H
 
+#include "qapi/qapi-types-machine.h"
+
 typedef struct BinaryTargetInfo BinaryTargetInfo;
 
 const BinaryTargetInfo *target_info(void);
@@ -17,4 +19,6 @@ bool target_info_is_stub(void);
 
 const char *target_name(void);
 
+SysEmuTarget target_system_arch(void);
+
 #endif
hw/core/machine-qmp-cmds.c +2 -4
index 6701e210f54..9e2dd348c06 100644
@@ -36,8 +36,7 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
     MachineState *ms = MACHINE(qdev_get_machine());
     MachineClass *mc = MACHINE_GET_CLASS(ms);
     CpuInfoFastList *head = NULL, **tail = &head;
-    SysEmuTarget target = qapi_enum_parse(&SysEmuTarget_lookup, target_name(),
-                                          -1, &error_abort);
+    SysEmuTarget target = target_system_arch();
     CPUState *cpu;
 
     CPU_FOREACH(cpu) {
@@ -137,8 +136,7 @@ TargetInfo *qmp_query_target(Error **errp)
 {
     TargetInfo *info = g_malloc0(sizeof(*info));
 
-    info->arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
-                                 &error_abort);
+    info->arch = target_system_arch();
 
     return info;
 }
target_info-stub.c +1 -0
index db61a335908..46a240ac66a 100644
@@ -14,6 +14,7 @@
 static const BinaryTargetInfo target_info_stub = {
     .is_stub = true,
     .name = TARGET_NAME,
+    .system_arch = -1,
 };
 
 const BinaryTargetInfo *target_info(void)
target_info.c +12 -0
index 6b44ea9fc0e..be4f19009b3 100644
@@ -9,6 +9,7 @@
 #include "qemu/osdep.h"
 #include "qemu/target_info-impl.h"
 #include "qemu/target_info.h"
+#include "qapi/error.h"
 
 bool target_info_is_stub(void)
 {
@@ -19,3 +20,14 @@ const char *target_name(void)
 {
     return target_info()->name;
 }
+
+SysEmuTarget target_system_arch(void)
+{
+    SysEmuTarget system_arch = target_info()->system_arch;
+
+    if (system_arch >= SYS_EMU_TARGET__MAX) {
+        system_arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
+                                      &error_abort);
+    }
+    return system_arch;
+}
Signature · 1 line
2.47.1
#6 lore raw

Re: [RFC PATCH-for-10.1 03/19] qemu: Factor target_system_arch() out

Quoted 104 lines · Philippe Mathieu-Daudé
---
  include/qemu/target_info-impl.h |  4 ++++
  include/qemu/target_info.h      |  4 ++++
  hw/core/machine-qmp-cmds.c      |  6 ++----
  target_info-stub.c              |  1 +
  target_info.c                   | 12 ++++++++++++
  5 files changed, 23 insertions(+), 4 deletions(-)
include/qemu/target_info-impl.h +4 -0
index 00bb746572b..0cec211e362 100644
@@ -10,6 +10,7 @@
  #define QEMU_TARGET_INFO_IMPL_H
 
  #include "qemu/target_info.h"
+#include "qapi/qapi-types-machine.h"
 
  struct BinaryTargetInfo {
 
@@ -19,6 +20,9 @@ struct BinaryTargetInfo {
      /* runtime equivalent of TARGET_NAME definition */
      const char *const name;
 
+    /* related to TARGET_ARCH definition */
+    SysEmuTarget system_arch;
+
  };
 
  #endif
include/qemu/target_info.h +4 -0
index 5b8f17a15a3..6ca36dae8a3 100644
@@ -9,6 +9,8 @@
  #ifndef QEMU_TARGET_INFO_H
  #define QEMU_TARGET_INFO_H
 
+#include "qapi/qapi-types-machine.h"
+
  typedef struct BinaryTargetInfo BinaryTargetInfo;
 
  const BinaryTargetInfo *target_info(void);
@@ -17,4 +19,6 @@ bool target_info_is_stub(void);
 
  const char *target_name(void);
 
+SysEmuTarget target_system_arch(void);
+
  #endif
hw/core/machine-qmp-cmds.c +2 -4
index 6701e210f54..9e2dd348c06 100644
@@ -36,8 +36,7 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
      MachineState *ms = MACHINE(qdev_get_machine());
      MachineClass *mc = MACHINE_GET_CLASS(ms);
      CpuInfoFastList *head = NULL, **tail = &head;
-    SysEmuTarget target = qapi_enum_parse(&SysEmuTarget_lookup, target_name(),
-                                          -1, &error_abort);
+    SysEmuTarget target = target_system_arch();
      CPUState *cpu;
 
      CPU_FOREACH(cpu) {
@@ -137,8 +136,7 @@ TargetInfo *qmp_query_target(Error **errp)
  {
      TargetInfo *info = g_malloc0(sizeof(*info));
 
-    info->arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
-                                 &error_abort);
+    info->arch = target_system_arch();
 
      return info;
  }
target_info-stub.c +1 -0
index db61a335908..46a240ac66a 100644
@@ -14,6 +14,7 @@
  static const BinaryTargetInfo target_info_stub = {
      .is_stub = true,
      .name = TARGET_NAME,
+    .system_arch = -1,
  };
 
  const BinaryTargetInfo *target_info(void)
target_info.c +2 -0
index 6b44ea9fc0e..be4f19009b3 100644
@@ -9,6 +9,7 @@
  #include "qemu/osdep.h"
  #include "qemu/target_info-impl.h"
  #include "qemu/target_info.h"
+#include "qapi/error.h"
 
  bool target_info_is_stub(void)
  {
@@ -19,3 +20,14 @@ const char *target_name(void)
  {
      return target_info()->name;
  }
+

target_info.c const char *target_name(void) · line 33

Quoted 10 lines
target_info.c +10 -0
+SysEmuTarget target_system_arch(void)
+{
+    SysEmuTarget system_arch = target_info()->system_arch;
+
+    if (system_arch >= SYS_EMU_TARGET__MAX) {
+        system_arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
+                                      &error_abort);
+    }
+    return system_arch;
+}

Maybe we could leave that out for now, and focus on representing compile time defines only as a first step.

#7 lore raw

RFC 4/19 qemu: Convert target_words_bigendian() to TargetInfo API

In reply to Philippe Mathieu-Daudé
---
 include/exec/tswap.h            | 13 +------------
 include/qemu/target_info-impl.h |  4 ++++
 include/qemu/target_info.h      | 11 +++++++++++
 cpu-target.c                    |  6 ------
 hw/core/cpu-system.c            |  2 +-
 hw/display/vga.c                |  2 +-
 hw/virtio/virtio.c              |  2 +-
 system/qtest.c                  |  1 +
 target_info-stub.c              |  1 +
 target_info.c                   |  5 +++++
 10 files changed, 26 insertions(+), 21 deletions(-)
include/exec/tswap.h +1 -12
index 84060a49994..415781b2bcc 100644
@@ -9,18 +9,7 @@
 #define TSWAP_H
 
 #include "qemu/bswap.h"
-
-/**
- * target_words_bigendian:
- * Returns true if the (default) endianness of the target is big endian,
- * false otherwise. Common code should normally never need to know about the
- * endianness of the target, so please do *not* use this function unless you
- * know very well what you are doing!
- */
-bool target_words_bigendian(void);
-#ifdef COMPILING_PER_TARGET
-#define target_words_bigendian()  TARGET_BIG_ENDIAN
-#endif
+#include "qemu/target_info.h"
 
 /*
  * If we're in target-specific code, we can hard-code the swapping
include/qemu/target_info-impl.h +4 -0
index 0cec211e362..14566e4a913 100644
@@ -10,6 +10,7 @@
 #define QEMU_TARGET_INFO_IMPL_H
 
 #include "qemu/target_info.h"
+#include "qapi/qapi-types-common.h"
 #include "qapi/qapi-types-machine.h"
 
 struct BinaryTargetInfo {
@@ -23,6 +24,9 @@ struct BinaryTargetInfo {
     /* related to TARGET_ARCH definition */
     SysEmuTarget system_arch;
 
+    /* related to TARGET_BIG_ENDIAN definition */
+    EndianMode endianness;
+
 };
 
 #endif
include/qemu/target_info.h +11 -0
index 6ca36dae8a3..e84f16d1034 100644
@@ -21,4 +21,15 @@ const char *target_name(void);
 
 SysEmuTarget target_system_arch(void);
 
+/**
+ * target_words_bigendian:
+ * Returns true if the (default) endianness of the target is big endian,
+ * false otherwise. Note that in target-specific code, you can use
+ * TARGET_BIG_ENDIAN directly instead. On the other hand, common
+ * code should normally never need to know about the endianness of the
+ * target, so please do *not* use this function unless you know very well
+ * what you are doing!
+ */
+bool target_words_bigendian(void);
+
 #endif
cpu-target.c +0 -6
index 3f82d3ea444..761c2d28645 100644
@@ -159,9 +159,3 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...)
 #endif
     abort();
 }
-
-#undef target_words_bigendian
-bool target_words_bigendian(void)
-{
-    return TARGET_BIG_ENDIAN;
-}
hw/core/cpu-system.c +1 -1
index 82b68b8927d..32700c49b43 100644
@@ -24,7 +24,7 @@
 #include "exec/cputlb.h"
 #include "system/memory.h"
 #include "exec/tb-flush.h"
-#include "exec/tswap.h"
+#include "qemu/target_info.h"
 #include "hw/qdev-core.h"
 #include "hw/qdev-properties.h"
 #include "hw/core/sysemu-cpu-ops.h"
hw/display/vga.c +1 -1
index b01f67c65fb..1883e03d3d8 100644
@@ -26,7 +26,7 @@
 #include "qemu/units.h"
 #include "system/reset.h"
 #include "qapi/error.h"
-#include "exec/tswap.h"
+#include "qemu/target_info.h"
 #include "hw/display/vga.h"
 #include "hw/i386/x86.h"
 #include "hw/pci/pci.h"
hw/virtio/virtio.c +1 -1
index 85110bce374..4ef56c183b2 100644
@@ -20,7 +20,7 @@
 #include "qemu/log.h"
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
-#include "exec/tswap.h"
+#include "qemu/target_info.h"
 #include "qom/object_interfaces.h"
 #include "hw/core/cpu.h"
 #include "hw/virtio/virtio.h"
system/qtest.c +1 -0
index 523a0479959..6146a7bfdc0 100644
@@ -29,6 +29,7 @@
 #include "qemu/error-report.h"
 #include "qemu/module.h"
 #include "qemu/cutils.h"
+#include "qemu/target_info.h"
 #include "qom/object_interfaces.h"
 
 #define MAX_IRQ 256
target_info-stub.c +1 -0
index 46a240ac66a..c1a15f5cc12 100644
@@ -15,6 +15,7 @@ static const BinaryTargetInfo target_info_stub = {
     .is_stub = true,
     .name = TARGET_NAME,
     .system_arch = -1,
+    .endianness = TARGET_BIG_ENDIAN ? ENDIAN_MODE_BIG : ENDIAN_MODE_LITTLE,
 };
 
 const BinaryTargetInfo *target_info(void)
target_info.c +5 -0
index be4f19009b3..22796dda543 100644
@@ -31,3 +31,8 @@ SysEmuTarget target_system_arch(void)
     }
     return system_arch;
 }
+
+bool target_words_bigendian(void)
+{
+    return target_info()->endianness == ENDIAN_MODE_BIG;
+}
Signature · 1 line
2.47.1
Reviewed-by on v1 4/19
#8 lore raw

Re: [RFC PATCH-for-10.1 04/19] qemu: Convert target_words_bigendian() to TargetInfo API

Quoted 69 lines · Philippe Mathieu-Daudé
---
  include/exec/tswap.h            | 13 +------------
  include/qemu/target_info-impl.h |  4 ++++
  include/qemu/target_info.h      | 11 +++++++++++
  cpu-target.c                    |  6 ------
  hw/core/cpu-system.c            |  2 +-
  hw/display/vga.c                |  2 +-
  hw/virtio/virtio.c              |  2 +-
  system/qtest.c                  |  1 +
  target_info-stub.c              |  1 +
  target_info.c                   |  5 +++++
  10 files changed, 26 insertions(+), 21 deletions(-)
include/exec/tswap.h +1 -12
index 84060a49994..415781b2bcc 100644
@@ -9,18 +9,7 @@
  #define TSWAP_H
 
  #include "qemu/bswap.h"
-
-/**
- * target_words_bigendian:
- * Returns true if the (default) endianness of the target is big endian,
- * false otherwise. Common code should normally never need to know about the
- * endianness of the target, so please do *not* use this function unless you
- * know very well what you are doing!
- */
-bool target_words_bigendian(void);
-#ifdef COMPILING_PER_TARGET
-#define target_words_bigendian()  TARGET_BIG_ENDIAN
-#endif
+#include "qemu/target_info.h"
 
  /*
   * If we're in target-specific code, we can hard-code the swapping
include/qemu/target_info-impl.h +4 -0
index 0cec211e362..14566e4a913 100644
@@ -10,6 +10,7 @@
  #define QEMU_TARGET_INFO_IMPL_H
 
  #include "qemu/target_info.h"
+#include "qapi/qapi-types-common.h"
  #include "qapi/qapi-types-machine.h"
 
  struct BinaryTargetInfo {
@@ -23,6 +24,9 @@ struct BinaryTargetInfo {
      /* related to TARGET_ARCH definition */
      SysEmuTarget system_arch;
 
+    /* related to TARGET_BIG_ENDIAN definition */
+    EndianMode endianness;
+
  };
 
  #endif
include/qemu/target_info.h +1 -0
index 6ca36dae8a3..e84f16d1034 100644
@@ -21,4 +21,15 @@ const char *target_name(void);
 
  SysEmuTarget target_system_arch(void);
 
+/**

include/qemu/target_info.h const char *target_name(void); · line 34

Quoted 10 lines
include/qemu/target_info.h +10 -0
+ * target_words_bigendian:
+ * Returns true if the (default) endianness of the target is big endian,
+ * false otherwise. Note that in target-specific code, you can use
+ * TARGET_BIG_ENDIAN directly instead. On the other hand, common
+ * code should normally never need to know about the endianness of the
+ * target, so please do *not* use this function unless you know very well
+ * what you are doing!
+ */
+bool target_words_bigendian(void);
+

We don't want to reintroduce TARGET_BIG_ENDIAN in the comment, it was purposefully removed previously.

Quoted 83 lines
include/qemu/target_info.h +0 -0
  #endif
cpu-target.c +0 -6
index 3f82d3ea444..761c2d28645 100644
@@ -159,9 +159,3 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...)
  #endif
      abort();
  }
-
-#undef target_words_bigendian
-bool target_words_bigendian(void)
-{
-    return TARGET_BIG_ENDIAN;
-}
hw/core/cpu-system.c +1 -1
index 82b68b8927d..32700c49b43 100644
@@ -24,7 +24,7 @@
  #include "exec/cputlb.h"
  #include "system/memory.h"
  #include "exec/tb-flush.h"
-#include "exec/tswap.h"
+#include "qemu/target_info.h"
  #include "hw/qdev-core.h"
  #include "hw/qdev-properties.h"
  #include "hw/core/sysemu-cpu-ops.h"
hw/display/vga.c +1 -1
index b01f67c65fb..1883e03d3d8 100644
@@ -26,7 +26,7 @@
  #include "qemu/units.h"
  #include "system/reset.h"
  #include "qapi/error.h"
-#include "exec/tswap.h"
+#include "qemu/target_info.h"
  #include "hw/display/vga.h"
  #include "hw/i386/x86.h"
  #include "hw/pci/pci.h"
hw/virtio/virtio.c +1 -1
index 85110bce374..4ef56c183b2 100644
@@ -20,7 +20,7 @@
  #include "qemu/log.h"
  #include "qemu/main-loop.h"
  #include "qemu/module.h"
-#include "exec/tswap.h"
+#include "qemu/target_info.h"
  #include "qom/object_interfaces.h"
  #include "hw/core/cpu.h"
  #include "hw/virtio/virtio.h"
system/qtest.c +1 -0
index 523a0479959..6146a7bfdc0 100644
@@ -29,6 +29,7 @@
  #include "qemu/error-report.h"
  #include "qemu/module.h"
  #include "qemu/cutils.h"
+#include "qemu/target_info.h"
  #include "qom/object_interfaces.h"
 
  #define MAX_IRQ 256
target_info-stub.c +1 -0
index 46a240ac66a..c1a15f5cc12 100644
@@ -15,6 +15,7 @@ static const BinaryTargetInfo target_info_stub = {
      .is_stub = true,
      .name = TARGET_NAME,
      .system_arch = -1,
+    .endianness = TARGET_BIG_ENDIAN ? ENDIAN_MODE_BIG : ENDIAN_MODE_LITTLE,
  };
 
  const BinaryTargetInfo *target_info(void)
target_info.c +0 -0
index be4f19009b3..22796dda543 100644

target_info.c SysEmuTarget target_system_arch(void) · line 38

Quoted 8 lines
target_info.c +5 -0
@@ -31,3 +31,8 @@ SysEmuTarget target_system_arch(void)
      }
      return system_arch;
  }
+
+bool target_words_bigendian(void)
+{
+    return target_info()->endianness == ENDIAN_MODE_BIG;
+}

With the comment update,

#9 lore raw

RFC 5/19 qemu: Introduce target_long_bits()

In reply to Philippe Mathieu-Daudé
---
 include/qemu/target_info-impl.h | 3 +++
 include/qemu/target_info.h      | 2 ++
 target_info-stub.c              | 1 +
 target_info.c                   | 5 +++++
 4 files changed, 11 insertions(+)
include/qemu/target_info-impl.h +3 -0
index 14566e4a913..8fa585f8138 100644
@@ -27,6 +27,9 @@ struct BinaryTargetInfo {
     /* related to TARGET_BIG_ENDIAN definition */
     EndianMode endianness;
 
+    /* runtime equivalent of TARGET_LONG_BITS definition */
+    unsigned long_bits;
+
 };
 
 #endif
include/qemu/target_info.h +2 -0
index e84f16d1034..66c43b329cc 100644
@@ -32,4 +32,6 @@ SysEmuTarget target_system_arch(void);
  */
 bool target_words_bigendian(void);
 
+unsigned target_long_bits(void);
+
 #endif
target_info-stub.c +1 -0
index c1a15f5cc12..a5374caed6c 100644
@@ -16,6 +16,7 @@ static const BinaryTargetInfo target_info_stub = {
     .name = TARGET_NAME,
     .system_arch = -1,
     .endianness = TARGET_BIG_ENDIAN ? ENDIAN_MODE_BIG : ENDIAN_MODE_LITTLE,
+    .long_bits = TARGET_LONG_BITS,
 };
 
 const BinaryTargetInfo *target_info(void)
target_info.c +5 -0
index 22796dda543..2fd32931e13 100644
@@ -36,3 +36,8 @@ bool target_words_bigendian(void)
 {
     return target_info()->endianness == ENDIAN_MODE_BIG;
 }
+
+unsigned target_long_bits(void)
+{
+    return target_info()->long_bits;
+}
Signature · 1 line
2.47.1
#11 lore raw

RFC 6/19 target/tricore: Replace TARGET_LONG_BITS -> target_long_bits()

In reply to Philippe Mathieu-Daudé
---
 target/tricore/translate.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
target/tricore/translate.c +4 -2
index 7cd26d8eaba..ad959f3b0a1 100644
@@ -24,6 +24,7 @@
 #include "tcg/tcg-op.h"
 #include "accel/tcg/cpu-ldst.h"
 #include "qemu/qemu-print.h"
+#include "qemu/target_info.h"
 
 #include "exec/helper-proto.h"
 #include "exec/helper-gen.h"
@@ -5922,6 +5923,7 @@ static void decode_rr_logical_shift(DisasContext *ctx)
 {
     uint32_t op2;
     int r3, r2, r1;
+    unsigned long_bits = target_long_bits();
 
     r3 = MASK_OP_RR_D(ctx->opcode);
     r2 = MASK_OP_RR_S2(ctx->opcode);
@@ -5937,7 +5939,7 @@ static void decode_rr_logical_shift(DisasContext *ctx)
         break;
     case OPC2_32_RR_CLO:
         tcg_gen_not_tl(cpu_gpr_d[r3], cpu_gpr_d[r1]);
-        tcg_gen_clzi_tl(cpu_gpr_d[r3], cpu_gpr_d[r3], TARGET_LONG_BITS);
+        tcg_gen_clzi_tl(cpu_gpr_d[r3], cpu_gpr_d[r3], long_bits);
         break;
     case OPC2_32_RR_CLO_H:
         gen_helper_clo_h(cpu_gpr_d[r3], cpu_gpr_d[r1]);
@@ -5949,7 +5951,7 @@ static void decode_rr_logical_shift(DisasContext *ctx)
         gen_helper_cls_h(cpu_gpr_d[r3], cpu_gpr_d[r1]);
         break;
     case OPC2_32_RR_CLZ:
-        tcg_gen_clzi_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], TARGET_LONG_BITS);
+        tcg_gen_clzi_tl(cpu_gpr_d[r3], cpu_gpr_d[r1], long_bits);
         break;
     case OPC2_32_RR_CLZ_H:
         gen_helper_clz_h(cpu_gpr_d[r3], cpu_gpr_d[r1]);
Signature · 1 line
2.47.1
#12 lore raw

Re: [RFC PATCH-for-10.1 06/19] target/tricore: Replace TARGET_LONG_BITS -> target_long_bits()

Quoted 5 lines · Philippe Mathieu-Daudé
---
  target/tricore/translate.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)

The temptation is good, but please do not touch any target code at this point. We want to focus on defining the API first, and we can perform codebase changes as a second step, without letting any occurrences of the old macros/functions, instead of just adding "another way to do it".

#13 lore raw

Re: [RFC PATCH-for-10.1 06/19] target/tricore: Replace TARGET_LONG_BITS -> target_long_bits()

Quoted 8 lines · Pierrick Bouvier
Quoted 5 lines · Philippe Mathieu-Daudé

---
  target/tricore/translate.c | 6 ++++--

  1 file changed, 4 insertions(+), 2 deletions(-)

The temptation is good, but please do not touch any target code at this point. We want to focus on defining the API first, and we can perform codebase changes as a second step, without letting any occurrences of the old macros/functions, instead of just adding "another way to do it".

I meant to remove these patch before posting, to focus on ARM, but apparently forgot to do so...

#14 lore raw

Re: [RFC PATCH-for-10.1 06/19] target/tricore: Replace TARGET_LONG_BITS -> target_long_bits()

Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Pierrick Bouvier
Quoted 5 lines · Philippe Mathieu-Daudé

---
  target/tricore/translate.c | 6 ++++--

  1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 4 lines
Quoted 1 line

The temptation is good, but please do not touch any target code at this point. We want to focus on defining the API first, and we can perform codebase changes as a second step, without letting any occurrences of the old macros/functions, instead of just adding "another way to do it".

I meant to remove these patch before posting, to focus on ARM, but apparently forgot to do so...

In this particular case TARGET_LONG_BITS is a constant 32 (and 32 is present many times in the code), so it can be replaced as a cleanup.

Paolo

#15 lore raw

Re: [RFC PATCH-for-10.1 06/19] target/tricore: Replace TARGET_LONG_BITS -> target_long_bits()

Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Pierrick Bouvier
Quoted 5 lines · Philippe Mathieu-Daudé

---
  target/tricore/translate.c | 6 ++++--

  1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

The temptation is good, but please do not touch any target code at this point. We want to focus on defining the API first, and we can perform codebase changes as a second step, without letting any occurrences of the old macros/functions, instead of just adding "another way to do it".

I meant to remove these patch before posting, to focus on ARM, but apparently forgot to do so...

In this particular case TARGET_LONG_BITS is a constant 32 (and 32 is present many times in the code), so it can be replaced as a cleanup.

Indeed. Richard suggested a similar cleanup (~ s/tl/i32/) for TriCore:
https://lore.kernel.org/qemu-devel/[email protected]/

#16 lore raw

RFC 7/19 target/hppa: Replace TARGET_LONG_BITS -> target_long_bits()

In reply to Philippe Mathieu-Daudé
---
 target/hppa/mem_helper.c | 3 ++-
 target/hppa/translate.c  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
target/hppa/mem_helper.c +2 -1
index 554d7bf4d14..03cd103f284 100644
@@ -19,6 +19,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/log.h"
+#include "qemu/target_info.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
 #include "exec/cputlb.h"
@@ -101,7 +102,7 @@ static void hppa_flush_tlb_ent(CPUHPPAState *env, HPPATLBEntry *ent,
 
     tlb_flush_range_by_mmuidx(cs, ent->itree.start,
                               ent->itree.last - ent->itree.start + 1,
-                              HPPA_MMU_FLUSH_MASK, TARGET_LONG_BITS);
+                              HPPA_MMU_FLUSH_MASK, target_long_bits());
 
     /* Never clear BTLBs, unless forced to do so. */
     is_btlb = ent < &env->tlb[HPPA_BTLB_ENTRIES(env)];
target/hppa/translate.c +2 -1
index 14f38333222..81f535589cf 100644
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/target_info.h"
 #include "cpu.h"
 #include "qemu/host-utils.h"
 #include "exec/exec-all.h"
@@ -3731,7 +3732,7 @@ static bool trans_shrp_imm(DisasContext *ctx, arg_shrp_imm *a)
     t2 = load_gpr(ctx, a->r2);
     if (a->r1 == 0) {
         tcg_gen_extract_i64(dest, t2, sa, width - sa);
-    } else if (width == TARGET_LONG_BITS) {
+    } else if (width == target_long_bits()) {
         tcg_gen_extract2_i64(dest, t2, cpu_gr[a->r1], sa);
     } else {
         assert(!a->d);
Signature · 1 line
2.47.1
#17 lore raw

Re: [RFC PATCH-for-10.1 07/19] target/hppa: Replace TARGET_LONG_BITS -> target_long_bits()

Quoted 40 lines · Philippe Mathieu-Daudé
---
  target/hppa/mem_helper.c | 3 ++-
  target/hppa/translate.c  | 3 ++-
  2 files changed, 4 insertions(+), 2 deletions(-)
target/hppa/mem_helper.c +2 -1
index 554d7bf4d14..03cd103f284 100644
@@ -19,6 +19,7 @@
 
  #include "qemu/osdep.h"
  #include "qemu/log.h"
+#include "qemu/target_info.h"
  #include "cpu.h"
  #include "exec/exec-all.h"
  #include "exec/cputlb.h"
@@ -101,7 +102,7 @@ static void hppa_flush_tlb_ent(CPUHPPAState *env, HPPATLBEntry *ent,
 
      tlb_flush_range_by_mmuidx(cs, ent->itree.start,
                                ent->itree.last - ent->itree.start + 1,
-                              HPPA_MMU_FLUSH_MASK, TARGET_LONG_BITS);
+                              HPPA_MMU_FLUSH_MASK, target_long_bits());
 
      /* Never clear BTLBs, unless forced to do so. */
      is_btlb = ent < &env->tlb[HPPA_BTLB_ENTRIES(env)];
target/hppa/translate.c +1 -0
index 14f38333222..81f535589cf 100644
@@ -18,6 +18,7 @@
   */
 
  #include "qemu/osdep.h"
+#include "qemu/target_info.h"
  #include "cpu.h"
  #include "qemu/host-utils.h"
  #include "exec/exec-all.h"

target/hppa/translate.c static bool trans_shrp_imm(DisasContext *ctx, arg_shrp_imm *a) · line 3738

Quoted 8 lines
target/hppa/translate.c +1 -1
@@ -3731,7 +3732,7 @@ static bool trans_shrp_imm(DisasContext *ctx, arg_shrp_imm *a)
      t2 = load_gpr(ctx, a->r2);
      if (a->r1 == 0) {
          tcg_gen_extract_i64(dest, t2, sa, width - sa);
-    } else if (width == TARGET_LONG_BITS) {
+    } else if (width == target_long_bits()) {
          tcg_gen_extract2_i64(dest, t2, cpu_gr[a->r1], sa);
      } else {
          assert(!a->d);

The temptation is good, but please do not touch any target code at this point. We want to focus on defining the API first, and we can perform codebase changes as a second step, without letting any occurrences of the old macros/functions, instead of just adding "another way to do it".

#18 lore raw

Re: [RFC PATCH-for-10.1 07/19] target/hppa: Replace TARGET_LONG_BITS -> target_long_bits()

Quoted 9 lines · Pierrick Bouvier
Quoted 5 lines · Philippe Mathieu-Daudé

---
  target/hppa/mem_helper.c | 3 ++-
  target/hppa/translate.c  | 3 ++-

  2 files changed, 4 insertions(+), 2 deletions(-)

The temptation is good, but please do not touch any target code at this point. We want to focus on defining the API first, and we can perform codebase changes as a second step, without letting any occurrences of the old macros/functions, instead of just adding "another way to do it".

I meant to remove these patch before posting, to focus on ARM, but apparently forgot to do so...

#19 lore raw

Re: [RFC PATCH-for-10.1 07/19] target/hppa: Replace TARGET_LONG_BITS -> target_long_bits()

In reply to Philippe Mathieu-Daudé

target/hppa/mem_helper.c static void hppa_flush_tlb_ent(CPUHPPAState *env, HPPATLBEntry *ent, · line 105

Quoted 6 lines · Philippe Mathieu-Daudé
target/hppa/mem_helper.c +1 -1
@@ -101,7 +102,7 @@ static void hppa_flush_tlb_ent(CPUHPPAState *env, HPPATLBEntry *ent,
 
      tlb_flush_range_by_mmuidx(cs, ent->itree.start,
                                ent->itree.last - ent->itree.start + 1,
-                              HPPA_MMU_FLUSH_MASK, TARGET_LONG_BITS);
+                              HPPA_MMU_FLUSH_MASK, target_long_bits());

This ignores the fact that TCG is still using the target_long type, so there's no real hope at this point of differentiating TARGET_LONG_BITS this way.

I think that you really need to make sure that target_long/target_ulong are little more than a shortcut used by TCG backends to invoke *_tl functions. Basically remove all uses outside target/ and tcg/ (a lot of uses in hw/ are for sPAPR devices and they can be replaced easily with uint64_t; there are actually not many).

Then let cpu.h define target_long/target_ulong so that you can remove the uses in tcg/ as well, and poison TARGET_LONG_BITS outside target/. This way TARGET_LONG_BITS does not need to be part of the TargetInfo.

On the other hand, if I'm missing something in your plan just tell me.

Paolo

#20 lore raw

RFC 8/19 target/riscv: Replace TARGET_LONG_BITS -> target_long_bits()

In reply to Philippe Mathieu-Daudé
---
 hw/riscv/riscv-iommu.c | 3 ++-
 hw/riscv/riscv_hart.c  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
hw/riscv/riscv-iommu.c +2 -1
index 65411b3e4c0..37563b2102f 100644
@@ -26,6 +26,7 @@
 #include "migration/vmstate.h"
 #include "qapi/error.h"
 #include "qemu/timer.h"
+#include "qemu/target_info.h"
 
 #include "cpu_bits.h"
 #include "riscv-iommu.h"
@@ -393,7 +394,7 @@ static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx,
             if (pass == S_STAGE && va_len > 32) {
                 target_ulong mask, masked_msbs;
 
-                mask = (1L << (TARGET_LONG_BITS - (va_len - 1))) - 1;
+                mask = (1L << (target_long_bits() - (va_len - 1))) - 1;
                 masked_msbs = (addr >> (va_len - 1)) & mask;
 
                 if (masked_msbs != 0 && masked_msbs != mask) {
hw/riscv/riscv_hart.c +2 -1
index a55d1566687..667d3b0a507 100644
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
+#include "qemu/target_info.h"
 #include "system/reset.h"
 #include "system/qtest.h"
 #include "qemu/cutils.h"
@@ -72,7 +73,7 @@ static void csr_call(char *cmd, uint64_t cpu_num, int csrno, uint64_t *val)
         ret = riscv_csrr(env, csrno, (target_ulong *)val);
     } else if (strcmp(cmd, "set_csr") == 0) {
         ret = riscv_csrrw(env, csrno, NULL, *(target_ulong *)val,
-                MAKE_64BIT_MASK(0, TARGET_LONG_BITS));
+                MAKE_64BIT_MASK(0, target_long_bits()));
     }
 
     g_assert(ret == RISCV_EXCP_NONE);
Signature · 1 line
2.47.1
#21 lore raw

Re: [RFC PATCH-for-10.1 08/19] target/riscv: Replace TARGET_LONG_BITS -> target_long_bits()

Quoted 40 lines · Philippe Mathieu-Daudé
---
  hw/riscv/riscv-iommu.c | 3 ++-
  hw/riscv/riscv_hart.c  | 3 ++-
  2 files changed, 4 insertions(+), 2 deletions(-)
hw/riscv/riscv-iommu.c +2 -1
index 65411b3e4c0..37563b2102f 100644
@@ -26,6 +26,7 @@
  #include "migration/vmstate.h"
  #include "qapi/error.h"
  #include "qemu/timer.h"
+#include "qemu/target_info.h"
 
  #include "cpu_bits.h"
  #include "riscv-iommu.h"
@@ -393,7 +394,7 @@ static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx,
              if (pass == S_STAGE && va_len > 32) {
                  target_ulong mask, masked_msbs;
 
-                mask = (1L << (TARGET_LONG_BITS - (va_len - 1))) - 1;
+                mask = (1L << (target_long_bits() - (va_len - 1))) - 1;
                  masked_msbs = (addr >> (va_len - 1)) & mask;
 
                  if (masked_msbs != 0 && masked_msbs != mask) {
hw/riscv/riscv_hart.c +1 -0
index a55d1566687..667d3b0a507 100644
@@ -21,6 +21,7 @@
  #include "qemu/osdep.h"
  #include "qapi/error.h"
  #include "qemu/module.h"
+#include "qemu/target_info.h"
  #include "system/reset.h"
  #include "system/qtest.h"
  #include "qemu/cutils.h"

hw/riscv/riscv_hart.c static void csr_call(char *cmd, uint64_t cpu_num, int csrno, uint64_t *val) · line 79

Quoted 8 lines
hw/riscv/riscv_hart.c +1 -1
@@ -72,7 +73,7 @@ static void csr_call(char *cmd, uint64_t cpu_num, int csrno, uint64_t *val)
          ret = riscv_csrr(env, csrno, (target_ulong *)val);
      } else if (strcmp(cmd, "set_csr") == 0) {
          ret = riscv_csrrw(env, csrno, NULL, *(target_ulong *)val,
-                MAKE_64BIT_MASK(0, TARGET_LONG_BITS));
+                MAKE_64BIT_MASK(0, target_long_bits()));
      }
 
      g_assert(ret == RISCV_EXCP_NONE);

The temptation is good, but please do not touch any target code at this point. We want to focus on defining the API first, and we can perform codebase changes as a second step, without letting any occurrences of the old macros/functions, instead of just adding "another way to do it".

#22 lore raw

Re: [RFC PATCH-for-10.1 08/19] target/riscv: Replace TARGET_LONG_BITS -> target_long_bits()

Quoted 9 lines · Pierrick Bouvier
Quoted 5 lines · Philippe Mathieu-Daudé

---
  hw/riscv/riscv-iommu.c | 3 ++-
  hw/riscv/riscv_hart.c  | 3 ++-

  2 files changed, 4 insertions(+), 2 deletions(-)

The temptation is good, but please do not touch any target code at this point. We want to focus on defining the API first, and we can perform codebase changes as a second step, without letting any occurrences of the old macros/functions, instead of just adding "another way to do it".

I meant to remove these patch before posting, to focus on ARM, but apparently forgot to do so...

#23 lore raw

RFC 9/19 qemu: Introduce target_cpu_type()

In reply to Philippe Mathieu-Daudé
---
 include/qemu/target_info-impl.h | 3 +++
 include/qemu/target_info.h      | 2 ++
 target_info-stub.c              | 2 ++
 target_info.c                   | 5 +++++
 4 files changed, 12 insertions(+)
include/qemu/target_info-impl.h +3 -0
index 8fa585f8138..d6d671a03c0 100644
@@ -30,6 +30,9 @@ struct BinaryTargetInfo {
     /* runtime equivalent of TARGET_LONG_BITS definition */
     unsigned long_bits;
 
+    /* runtime equivalent of CPU_RESOLVING_TYPE definition */
+    const char *const cpu_resolving_type;
+
 };
 
 #endif
include/qemu/target_info.h +2 -0
index 66c43b329cc..407ce328e85 100644
@@ -34,4 +34,6 @@ bool target_words_bigendian(void);
 
 unsigned target_long_bits(void);
 
+const char *target_cpu_type(void);
+
 #endif
target_info-stub.c +2 -0
index a5374caed6c..7d21675d4c0 100644
@@ -8,6 +8,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/target_info-impl.h"
+#include "cpu.h"
 
 #ifdef TARGET_INFO_STUB_NEEDED
 
@@ -17,6 +18,7 @@ static const BinaryTargetInfo target_info_stub = {
     .system_arch = -1,
     .endianness = TARGET_BIG_ENDIAN ? ENDIAN_MODE_BIG : ENDIAN_MODE_LITTLE,
     .long_bits = TARGET_LONG_BITS,
+    .cpu_resolving_type = CPU_RESOLVING_TYPE,
 };
 
 const BinaryTargetInfo *target_info(void)
target_info.c +5 -0
index 2fd32931e13..4ad205636c2 100644
@@ -41,3 +41,8 @@ unsigned target_long_bits(void)
 {
     return target_info()->long_bits;
 }
+
+const char *target_cpu_type(void)
+{
+    return target_info()->cpu_resolving_type;
+}
Signature · 1 line
2.47.1
Reviewed-by on v1 9/19
#24 lore raw

Re: [RFC PATCH-for-10.1 09/19] qemu: Introduce target_cpu_type()

Quoted 58 lines · Philippe Mathieu-Daudé
---
  include/qemu/target_info-impl.h | 3 +++
  include/qemu/target_info.h      | 2 ++
  target_info-stub.c              | 2 ++
  target_info.c                   | 5 +++++
  4 files changed, 12 insertions(+)
include/qemu/target_info-impl.h +3 -0
index 8fa585f8138..d6d671a03c0 100644
@@ -30,6 +30,9 @@ struct BinaryTargetInfo {
      /* runtime equivalent of TARGET_LONG_BITS definition */
      unsigned long_bits;
 
+    /* runtime equivalent of CPU_RESOLVING_TYPE definition */
+    const char *const cpu_resolving_type;
+
  };
 
  #endif
include/qemu/target_info.h +2 -0
index 66c43b329cc..407ce328e85 100644
@@ -34,4 +34,6 @@ bool target_words_bigendian(void);
 
  unsigned target_long_bits(void);
 
+const char *target_cpu_type(void);
+
  #endif
target_info-stub.c +2 -0
index a5374caed6c..7d21675d4c0 100644
@@ -8,6 +8,7 @@
 
  #include "qemu/osdep.h"
  #include "qemu/target_info-impl.h"
+#include "cpu.h"
 
  #ifdef TARGET_INFO_STUB_NEEDED
 
@@ -17,6 +18,7 @@ static const BinaryTargetInfo target_info_stub = {
      .system_arch = -1,
      .endianness = TARGET_BIG_ENDIAN ? ENDIAN_MODE_BIG : ENDIAN_MODE_LITTLE,
      .long_bits = TARGET_LONG_BITS,
+    .cpu_resolving_type = CPU_RESOLVING_TYPE,
  };
 
  const BinaryTargetInfo *target_info(void)
target_info.c +0 -0
index 2fd32931e13..4ad205636c2 100644

target_info.c unsigned target_long_bits(void) · line 48

Quoted 8 lines
target_info.c +5 -0
@@ -41,3 +41,8 @@ unsigned target_long_bits(void)
  {
      return target_info()->long_bits;
  }
+
+const char *target_cpu_type(void)
+{
+    return target_info()->cpu_resolving_type;
+}
#25 lore raw

RFC 10/19 cpus: Replace CPU_RESOLVING_TYPE -> target_cpu_type()

In reply to Philippe Mathieu-Daudé
---
 cpu-target.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
cpu-target.c +4 -3
index 761c2d28645..01b0064b91f 100644
@@ -22,6 +22,7 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qemu/qemu-print.h"
+#include "qemu/target_info.h"
 #include "system/accel-ops.h"
 #include "system/cpus.h"
 #include "exec/cpu-common.h"
@@ -37,7 +38,7 @@ QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
 
 char *cpu_model_from_type(const char *typename)
 {
-    const char *suffix = "-" CPU_RESOLVING_TYPE;
+    g_autofree char *suffix = g_strdup_printf("-%s", target_cpu_type());
 
     if (!object_class_by_name(typename)) {
         return NULL;
@@ -63,7 +64,7 @@ const char *parse_cpu_option(const char *cpu_option)
         exit(1);
     }
 
-    oc = cpu_class_by_name(CPU_RESOLVING_TYPE, model_pieces[0]);
+    oc = cpu_class_by_name(target_cpu_type(), model_pieces[0]);
     if (oc == NULL) {
         error_report("unable to find CPU model '%s'", model_pieces[0]);
         g_strfreev(model_pieces);
@@ -92,7 +93,7 @@ static void cpu_list_entry(gpointer data, gpointer user_data)
 
 void list_cpus(void)
 {
-    CPUClass *cc = CPU_CLASS(object_class_by_name(CPU_RESOLVING_TYPE));
+    CPUClass *cc = CPU_CLASS(object_class_by_name(target_cpu_type()));
 
     if (cc->list_cpus) {
         cc->list_cpus();
Signature · 1 line
2.47.1
Reviewed-by on v1 10/19
#26 lore raw

Re: [RFC PATCH-for-10.1 10/19] cpus: Replace CPU_RESOLVING_TYPE -> target_cpu_type()

Quoted 36 lines · Philippe Mathieu-Daudé
---
  cpu-target.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
cpu-target.c +3 -2
index 761c2d28645..01b0064b91f 100644
@@ -22,6 +22,7 @@
  #include "qapi/error.h"
  #include "qemu/error-report.h"
  #include "qemu/qemu-print.h"
+#include "qemu/target_info.h"
  #include "system/accel-ops.h"
  #include "system/cpus.h"
  #include "exec/cpu-common.h"
@@ -37,7 +38,7 @@ QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
 
  char *cpu_model_from_type(const char *typename)
  {
-    const char *suffix = "-" CPU_RESOLVING_TYPE;
+    g_autofree char *suffix = g_strdup_printf("-%s", target_cpu_type());
 
      if (!object_class_by_name(typename)) {
          return NULL;
@@ -63,7 +64,7 @@ const char *parse_cpu_option(const char *cpu_option)
          exit(1);
      }
 
-    oc = cpu_class_by_name(CPU_RESOLVING_TYPE, model_pieces[0]);
+    oc = cpu_class_by_name(target_cpu_type(), model_pieces[0]);
      if (oc == NULL) {
          error_report("unable to find CPU model '%s'", model_pieces[0]);
          g_strfreev(model_pieces);

cpu-target.c static void cpu_list_entry(gpointer data, gpointer user_data) · line 99

Quoted 8 lines
cpu-target.c +1 -1
@@ -92,7 +93,7 @@ static void cpu_list_entry(gpointer data, gpointer user_data)
 
  void list_cpus(void)
  {
-    CPUClass *cc = CPU_CLASS(object_class_by_name(CPU_RESOLVING_TYPE));
+    CPUClass *cc = CPU_CLASS(object_class_by_name(target_cpu_type()));
 
      if (cc->list_cpus) {
          cc->list_cpus();

This change can be done as it's not target dependent.
Please also squash other commits doing the same for other files, so we have a single commit doing the change for whole codebase.

#27 lore raw

RFC 11/19 accel/tcg: Replace CPU_RESOLVING_TYPE -> target_cpu_type()

In reply to Philippe Mathieu-Daudé
---
 accel/tcg/tcg-all.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
accel/tcg/tcg-all.c +2 -2
index bf27c5c0fb3..a13cb39644f 100644
@@ -35,6 +35,7 @@
 #include "qapi/qapi-types-common.h"
 #include "qapi/qapi-builtin-visit.h"
 #include "qemu/units.h"
+#include "qemu/target_info.h"
 #if defined(CONFIG_USER_ONLY)
 #include "hw/qdev-core.h"
 #else
@@ -44,7 +45,6 @@
 #include "accel/tcg/cpu-ops.h"
 #include "internal-common.h"
 #include "cpu-param.h"
-#include "cpu.h"
 
 
 struct TCGState {
@@ -73,7 +73,7 @@ bool qemu_tcg_mttcg_enabled(void)
 
 static void mttcg_init(TCGState *s)
 {
-    CPUClass *cc = CPU_CLASS(object_class_by_name(CPU_RESOLVING_TYPE));
+    CPUClass *cc = CPU_CLASS(object_class_by_name(target_cpu_type()));
     bool mttcg_supported = cc->tcg_ops->mttcg_supported;
 
     if (s->mttcg_enabled == ON_OFF_AUTO_AUTO) {
Signature · 1 line
2.47.1
Reviewed-by on v1 11/19
#28 lore raw

Re: [RFC PATCH-for-10.1 11/19] accel/tcg: Replace CPU_RESOLVING_TYPE -> target_cpu_type()

Quoted 26 lines · Philippe Mathieu-Daudé
---
  accel/tcg/tcg-all.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
accel/tcg/tcg-all.c +1 -1
index bf27c5c0fb3..a13cb39644f 100644
@@ -35,6 +35,7 @@
  #include "qapi/qapi-types-common.h"
  #include "qapi/qapi-builtin-visit.h"
  #include "qemu/units.h"
+#include "qemu/target_info.h"
  #if defined(CONFIG_USER_ONLY)
  #include "hw/qdev-core.h"
  #else
@@ -44,7 +45,6 @@
  #include "accel/tcg/cpu-ops.h"
  #include "internal-common.h"
  #include "cpu-param.h"
-#include "cpu.h"
 
 
  struct TCGState {

accel/tcg/tcg-all.c bool qemu_tcg_mttcg_enabled(void) · line 79

Quoted 8 lines
accel/tcg/tcg-all.c +1 -1
@@ -73,7 +73,7 @@ bool qemu_tcg_mttcg_enabled(void)
 
  static void mttcg_init(TCGState *s)
  {
-    CPUClass *cc = CPU_CLASS(object_class_by_name(CPU_RESOLVING_TYPE));
+    CPUClass *cc = CPU_CLASS(object_class_by_name(target_cpu_type()));
      bool mttcg_supported = cc->tcg_ops->mttcg_supported;
 
      if (s->mttcg_enabled == ON_OFF_AUTO_AUTO) {

It can be squashed with previous commit.

#29 lore raw

Re: [RFC PATCH-for-10.1 11/19] accel/tcg: Replace CPU_RESOLVING_TYPE -> target_cpu_type()

Quoted 25 lines · Pierrick Bouvier
Quoted 24 lines · Philippe Mathieu-Daudé

---
  accel/tcg/tcg-all.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
accel/tcg/tcg-all.c +1 -1
index bf27c5c0fb3..a13cb39644f 100644
@@ -35,6 +35,7 @@
   #include "qapi/qapi-types-common.h"
   #include "qapi/qapi-builtin-visit.h"
   #include "qemu/units.h"
+#include "qemu/target_info.h"
   #if defined(CONFIG_USER_ONLY)
   #include "hw/qdev-core.h"
   #else
@@ -44,7 +45,6 @@
   #include "accel/tcg/cpu-ops.h"
   #include "internal-common.h"
   #include "cpu-param.h"
-#include "cpu.h"
   struct TCGState {
@@ -73,7 +73,7 @@ bool qemu_tcg_mttcg_enabled(void)
Quoted 8 lines

accel/tcg/tcg-all.c bool qemu_tcg_mttcg_enabled(void) · line 79

Quoted 6 lines
accel/tcg/tcg-all.c +1 -1
   static void mttcg_init(TCGState *s)
   {
-    CPUClass *cc = CPU_CLASS(object_class_by_name(CPU_RESOLVING_TYPE));
+    CPUClass *cc = CPU_CLASS(object_class_by_name(target_cpu_type()));
       bool mttcg_supported = cc->tcg_ops->mttcg_supported;
       if (s->mttcg_enabled == ON_OFF_AUTO_AUTO) {

It can be squashed with previous commit.

Not exactly the same set of maintainers, but can do.

Quoted 1 line

Thanks!

#30 lore raw

Re: [RFC PATCH-for-10.1 11/19] accel/tcg: Replace CPU_RESOLVING_TYPE -> target_cpu_type()

Quoted 35 lines · Philippe Mathieu-Daudé
Quoted 25 lines · Pierrick Bouvier
Quoted 24 lines · Philippe Mathieu-Daudé
---
   accel/tcg/tcg-all.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
accel/tcg/tcg-all.c +1 -1
index bf27c5c0fb3..a13cb39644f 100644
@@ -35,6 +35,7 @@
   #include "qapi/qapi-types-common.h"
   #include "qapi/qapi-builtin-visit.h"
   #include "qemu/units.h"
+#include "qemu/target_info.h"
   #if defined(CONFIG_USER_ONLY)
   #include "hw/qdev-core.h"
   #else
@@ -44,7 +45,6 @@
   #include "accel/tcg/cpu-ops.h"
   #include "internal-common.h"
   #include "cpu-param.h"
-#include "cpu.h"
   struct TCGState {
@@ -73,7 +73,7 @@ bool qemu_tcg_mttcg_enabled(void)
Quoted 8 lines

accel/tcg/tcg-all.c bool qemu_tcg_mttcg_enabled(void) · line 79

Quoted 6 lines
accel/tcg/tcg-all.c +1 -1
   static void mttcg_init(TCGState *s)
   {
-    CPUClass *cc = CPU_CLASS(object_class_by_name(CPU_RESOLVING_TYPE));
+    CPUClass *cc = CPU_CLASS(object_class_by_name(target_cpu_type()));
       bool mttcg_supported = cc->tcg_ops->mttcg_supported;
       if (s->mttcg_enabled == ON_OFF_AUTO_AUTO) {

It can be squashed with previous commit.

Quoted 2 lines

Not exactly the same set of maintainers, but can do.

For mechanical changes like this, I guess it's less important than when really touching a specific subsystem.

Quoted 3 lines
Quoted 1 line

Thanks!

#31 lore raw

RFC 12/19 cpus: Move target-agnostic methods out of cpu-target.c

In reply to Philippe Mathieu-Daudé
---
 cpu-target.c         | 78 +-------------------------------------------
 hw/core/cpu-common.c | 74 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 77 deletions(-)
cpu-target.c +1 -77
index 01b0064b91f..20db5ff3108 100644
@@ -19,94 +19,18 @@
 
 #include "qemu/osdep.h"
 #include "cpu.h"
-#include "qapi/error.h"
-#include "qemu/error-report.h"
-#include "qemu/qemu-print.h"
-#include "qemu/target_info.h"
 #include "system/accel-ops.h"
 #include "system/cpus.h"
 #include "exec/cpu-common.h"
-#include "exec/tswap.h"
 #include "exec/replay-core.h"
 #include "exec/log.h"
-#include "accel/accel-cpu-target.h"
+#include "hw/core/cpu.h"
 #include "trace/trace-root.h"
 
 /* Validate correct placement of CPUArchState. */
 QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
 QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
 
-char *cpu_model_from_type(const char *typename)
-{
-    g_autofree char *suffix = g_strdup_printf("-%s", target_cpu_type());
-
-    if (!object_class_by_name(typename)) {
-        return NULL;
-    }
-
-    if (g_str_has_suffix(typename, suffix)) {
-        return g_strndup(typename, strlen(typename) - strlen(suffix));
-    }
-
-    return g_strdup(typename);
-}
-
-const char *parse_cpu_option(const char *cpu_option)
-{
-    ObjectClass *oc;
-    CPUClass *cc;
-    gchar **model_pieces;
-    const char *cpu_type;
-
-    model_pieces = g_strsplit(cpu_option, ",", 2);
-    if (!model_pieces[0]) {
-        error_report("-cpu option cannot be empty");
-        exit(1);
-    }
-
-    oc = cpu_class_by_name(target_cpu_type(), model_pieces[0]);
-    if (oc == NULL) {
-        error_report("unable to find CPU model '%s'", model_pieces[0]);
-        g_strfreev(model_pieces);
-        exit(EXIT_FAILURE);
-    }
-
-    cpu_type = object_class_get_name(oc);
-    cc = CPU_CLASS(oc);
-    cc->parse_features(cpu_type, model_pieces[1], &error_fatal);
-    g_strfreev(model_pieces);
-    return cpu_type;
-}
-
-static void cpu_list_entry(gpointer data, gpointer user_data)
-{
-    CPUClass *cc = CPU_CLASS(OBJECT_CLASS(data));
-    const char *typename = object_class_get_name(OBJECT_CLASS(data));
-    g_autofree char *model = cpu_model_from_type(typename);
-
-    if (cc->deprecation_note) {
-        qemu_printf("  %s (deprecated)\n", model);
-    } else {
-        qemu_printf("  %s\n", model);
-    }
-}
-
-void list_cpus(void)
-{
-    CPUClass *cc = CPU_CLASS(object_class_by_name(target_cpu_type()));
-
-    if (cc->list_cpus) {
-        cc->list_cpus();
-    } else {
-        GSList *list;
-
-        list = object_class_get_list_sorted(TYPE_CPU, false);
-        qemu_printf("Available CPUs:\n");
-        g_slist_foreach(list, cpu_list_entry, NULL);
-        g_slist_free(list);
-    }
-}
-
 /* enable or disable single step mode. EXCP_DEBUG is returned by the
    CPU loop after each instruction */
 void cpu_single_step(CPUState *cpu, int enabled)
hw/core/cpu-common.c +74 -0

95 lines not on this page · raw message

Signature · 1 line
2.47.1
Reviewed-by on v1 12/19
#32 lore raw

Re: [RFC PATCH-for-10.1 12/19] cpus: Move target-agnostic methods out of cpu-target.c

Quoted 199 lines · Philippe Mathieu-Daudé
---
  cpu-target.c         | 78 +-------------------------------------------
  hw/core/cpu-common.c | 74 +++++++++++++++++++++++++++++++++++++++++
  2 files changed, 75 insertions(+), 77 deletions(-)
cpu-target.c +1 -77
index 01b0064b91f..20db5ff3108 100644
@@ -19,94 +19,18 @@
 
  #include "qemu/osdep.h"
  #include "cpu.h"
-#include "qapi/error.h"
-#include "qemu/error-report.h"
-#include "qemu/qemu-print.h"
-#include "qemu/target_info.h"
  #include "system/accel-ops.h"
  #include "system/cpus.h"
  #include "exec/cpu-common.h"
-#include "exec/tswap.h"
  #include "exec/replay-core.h"
  #include "exec/log.h"
-#include "accel/accel-cpu-target.h"
+#include "hw/core/cpu.h"
  #include "trace/trace-root.h"
 
  /* Validate correct placement of CPUArchState. */
  QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
  QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
 
-char *cpu_model_from_type(const char *typename)
-{
-    g_autofree char *suffix = g_strdup_printf("-%s", target_cpu_type());
-
-    if (!object_class_by_name(typename)) {
-        return NULL;
-    }
-
-    if (g_str_has_suffix(typename, suffix)) {
-        return g_strndup(typename, strlen(typename) - strlen(suffix));
-    }
-
-    return g_strdup(typename);
-}
-
-const char *parse_cpu_option(const char *cpu_option)
-{
-    ObjectClass *oc;
-    CPUClass *cc;
-    gchar **model_pieces;
-    const char *cpu_type;
-
-    model_pieces = g_strsplit(cpu_option, ",", 2);
-    if (!model_pieces[0]) {
-        error_report("-cpu option cannot be empty");
-        exit(1);
-    }
-
-    oc = cpu_class_by_name(target_cpu_type(), model_pieces[0]);
-    if (oc == NULL) {
-        error_report("unable to find CPU model '%s'", model_pieces[0]);
-        g_strfreev(model_pieces);
-        exit(EXIT_FAILURE);
-    }
-
-    cpu_type = object_class_get_name(oc);
-    cc = CPU_CLASS(oc);
-    cc->parse_features(cpu_type, model_pieces[1], &error_fatal);
-    g_strfreev(model_pieces);
-    return cpu_type;
-}
-
-static void cpu_list_entry(gpointer data, gpointer user_data)
-{
-    CPUClass *cc = CPU_CLASS(OBJECT_CLASS(data));
-    const char *typename = object_class_get_name(OBJECT_CLASS(data));
-    g_autofree char *model = cpu_model_from_type(typename);
-
-    if (cc->deprecation_note) {
-        qemu_printf("  %s (deprecated)\n", model);
-    } else {
-        qemu_printf("  %s\n", model);
-    }
-}
-
-void list_cpus(void)
-{
-    CPUClass *cc = CPU_CLASS(object_class_by_name(target_cpu_type()));
-
-    if (cc->list_cpus) {
-        cc->list_cpus();
-    } else {
-        GSList *list;
-
-        list = object_class_get_list_sorted(TYPE_CPU, false);
-        qemu_printf("Available CPUs:\n");
-        g_slist_foreach(list, cpu_list_entry, NULL);
-        g_slist_free(list);
-    }
-}
-
  /* enable or disable single step mode. EXCP_DEBUG is returned by the
     CPU loop after each instruction */
  void cpu_single_step(CPUState *cpu, int enabled)
hw/core/cpu-common.c +64 -0
index 9064dd24f82..6d0788331c7 100644
@@ -25,6 +25,9 @@
  #include "qemu/log.h"
  #include "qemu/main-loop.h"
  #include "qemu/lockcnt.h"
+#include "qemu/error-report.h"
+#include "qemu/qemu-print.h"
+#include "qemu/target_info.h"
  #include "exec/log.h"
  #include "exec/gdbstub.h"
  #include "system/tcg.h"
@@ -152,6 +155,21 @@ ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model)
      return NULL;
  }
 
+char *cpu_model_from_type(const char *typename)
+{
+    g_autofree char *suffix = g_strdup_printf("-%s", target_cpu_type());
+
+    if (!object_class_by_name(typename)) {
+        return NULL;
+    }
+
+    if (g_str_has_suffix(typename, suffix)) {
+        return g_strndup(typename, strlen(typename) - strlen(suffix));
+    }
+
+    return g_strdup(typename);
+}
+
  static void cpu_common_parse_features(const char *typename, char *features,
                                        Error **errp)
  {
@@ -183,6 +201,33 @@ static void cpu_common_parse_features(const char *typename, char *features,
      }
  }
 
+const char *parse_cpu_option(const char *cpu_option)
+{
+    ObjectClass *oc;
+    CPUClass *cc;
+    gchar **model_pieces;
+    const char *cpu_type;
+
+    model_pieces = g_strsplit(cpu_option, ",", 2);
+    if (!model_pieces[0]) {
+        error_report("-cpu option cannot be empty");
+        exit(1);
+    }
+
+    oc = cpu_class_by_name(target_cpu_type(), model_pieces[0]);
+    if (oc == NULL) {
+        error_report("unable to find CPU model '%s'", model_pieces[0]);
+        g_strfreev(model_pieces);
+        exit(EXIT_FAILURE);
+    }
+
+    cpu_type = object_class_get_name(oc);
+    cc = CPU_CLASS(oc);
+    cc->parse_features(cpu_type, model_pieces[1], &error_fatal);
+    g_strfreev(model_pieces);
+    return cpu_type;
+}
+
  bool cpu_exec_realizefn(CPUState *cpu, Error **errp)
  {
      if (!accel_cpu_common_realize(cpu, errp)) {
@@ -359,3 +404,32 @@ static void cpu_register_types(void)
  }
 
  type_init(cpu_register_types)
+
+static void cpu_list_entry(gpointer data, gpointer user_data)
+{
+    CPUClass *cc = CPU_CLASS(OBJECT_CLASS(data));
+    const char *typename = object_class_get_name(OBJECT_CLASS(data));
+    g_autofree char *model = cpu_model_from_type(typename);
+
+    if (cc->deprecation_note) {
+        qemu_printf("  %s (deprecated)\n", model);
+    } else {
+        qemu_printf("  %s\n", model);
+    }
+}
+
+void list_cpus(void)
+{
+    CPUClass *cc = CPU_CLASS(object_class_by_name(target_cpu_type()));
+
+    if (cc->list_cpus) {

hw/core/cpu-common.c static void cpu_register_types(void) · line 435

Quoted 10 lines
hw/core/cpu-common.c +10 -0
+        cc->list_cpus();
+    } else {
+        GSList *list;
+
+        list = object_class_get_list_sorted(TYPE_CPU, false);
+        qemu_printf("Available CPUs:\n");
+        g_slist_foreach(list, cpu_list_entry, NULL);
+        g_slist_free(list);
+    }
+}

Sounds good,

#33 lore raw

RFC 13/19 accel: Replace CPU_RESOLVING_TYPE -> target_cpu_type()

In reply to Philippe Mathieu-Daudé
---
 accel/accel-target.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
accel/accel-target.c +4 -2
index 33a539b4cbb..9e9e70be876 100644
@@ -25,6 +25,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/accel.h"
+#include "qemu/target_info.h"
 
 #include "cpu.h"
 #include "accel/accel-cpu-target.h"
@@ -88,17 +89,18 @@ static void accel_init_cpu_interfaces(AccelClass *ac)
     const char *ac_name; /* AccelClass name */
     char *acc_name;      /* AccelCPUClass name */
     ObjectClass *acc;    /* AccelCPUClass */
+    const char *cpu_resolving_type = target_cpu_type();
 
     ac_name = object_class_get_name(OBJECT_CLASS(ac));
     g_assert(ac_name != NULL);
 
-    acc_name = g_strdup_printf("%s-%s", ac_name, CPU_RESOLVING_TYPE);
+    acc_name = g_strdup_printf("%s-%s", ac_name, cpu_resolving_type);
     acc = object_class_by_name(acc_name);
     g_free(acc_name);
 
     if (acc) {
         object_class_foreach(accel_init_cpu_int_aux,
-                             CPU_RESOLVING_TYPE, false, acc);
+                             cpu_resolving_type, false, acc);
     }
 }
 
Signature · 1 line
2.47.1
Reviewed-by on v1 13/19
#34 lore raw

Re: [RFC PATCH-for-10.1 13/19] accel: Replace CPU_RESOLVING_TYPE -> target_cpu_type()

Quoted 28 lines · Philippe Mathieu-Daudé
---
  accel/accel-target.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
accel/accel-target.c +3 -1
index 33a539b4cbb..9e9e70be876 100644
@@ -25,6 +25,7 @@
 
  #include "qemu/osdep.h"
  #include "qemu/accel.h"
+#include "qemu/target_info.h"
 
  #include "cpu.h"
  #include "accel/accel-cpu-target.h"
@@ -88,17 +89,18 @@ static void accel_init_cpu_interfaces(AccelClass *ac)
      const char *ac_name; /* AccelClass name */
      char *acc_name;      /* AccelCPUClass name */
      ObjectClass *acc;    /* AccelCPUClass */
+    const char *cpu_resolving_type = target_cpu_type();
 
      ac_name = object_class_get_name(OBJECT_CLASS(ac));
      g_assert(ac_name != NULL);
 
-    acc_name = g_strdup_printf("%s-%s", ac_name, CPU_RESOLVING_TYPE);
+    acc_name = g_strdup_printf("%s-%s", ac_name, cpu_resolving_type);

accel/accel-target.c static void accel_init_cpu_interfaces(AccelClass *ac) · line 106

Quoted 10 lines
accel/accel-target.c +1 -1
      acc = object_class_by_name(acc_name);
      g_free(acc_name);
 
      if (acc) {
          object_class_foreach(accel_init_cpu_int_aux,
-                             CPU_RESOLVING_TYPE, false, acc);
+                             cpu_resolving_type, false, acc);
      }
  }
 

Please squash with related commit.

#35 lore raw

RFC 14/19 accel: Implement accel_init_ops_interfaces() for both system/user mode

In reply to Philippe Mathieu-Daudé
---
 accel/{accel-system.h => accel-internal.h} |  8 ++++----
 accel/accel-system.c                       |  4 ++--
 accel/accel-target.c                       | 10 ++--------
 accel/accel-user.c                         |  6 ++++++
 4 files changed, 14 insertions(+), 14 deletions(-)
 rename accel/{accel-system.h => accel-internal.h} (56%)
accel/accel-internal.h renamed from accel/accel-system.h +4 -4
similarity index 56%
rename from accel/accel-system.h
rename to accel/accel-internal.h
index 2d37c73c97b..03426aa21ee 100644
@@ -1,5 +1,5 @@
 /*
- * QEMU System Emulation accel internal functions
+ * QEMU accel internal functions
  *
  * Copyright 2021 SUSE LLC
  *
@@ -7,9 +7,9 @@
  * See the COPYING file in the top-level directory.
  */
 
-#ifndef ACCEL_SYSTEM_H
-#define ACCEL_SYSTEM_H
+#ifndef ACCEL_INTERNAL_H
+#define ACCEL_INTERNAL_H
 
-void accel_system_init_ops_interfaces(AccelClass *ac);
+void accel_init_ops_interfaces(AccelClass *ac);
 
 #endif /* ACCEL_SYSTEM_H */
accel/accel-system.c +2 -2
index 5df49fbe831..a0f562ae9ff 100644
@@ -29,7 +29,7 @@
 #include "system/accel-ops.h"
 #include "system/cpus.h"
 #include "qemu/error-report.h"
-#include "accel-system.h"
+#include "accel-internal.h"
 
 int accel_init_machine(AccelState *accel, MachineState *ms)
 {
@@ -63,7 +63,7 @@ void accel_setup_post(MachineState *ms)
 }
 
 /* initialize the arch-independent accel operation interfaces */
-void accel_system_init_ops_interfaces(AccelClass *ac)
+void accel_init_ops_interfaces(AccelClass *ac)
 {
     const char *ac_name;
     char *ops_name;
accel/accel-target.c +2 -8
index 9e9e70be876..6fa5c3ef04e 100644
@@ -29,10 +29,7 @@
 
 #include "cpu.h"
 #include "accel/accel-cpu-target.h"
-
-#ifndef CONFIG_USER_ONLY
-#include "accel-system.h"
-#endif /* !CONFIG_USER_ONLY */
+#include "accel-internal.h"
 
 static const TypeInfo accel_type = {
     .name = TYPE_ACCEL,
@@ -106,10 +103,7 @@ static void accel_init_cpu_interfaces(AccelClass *ac)
 
 void accel_init_interfaces(AccelClass *ac)
 {
-#ifndef CONFIG_USER_ONLY
-    accel_system_init_ops_interfaces(ac);
-#endif /* !CONFIG_USER_ONLY */
-
+    accel_init_ops_interfaces(ac);
     accel_init_cpu_interfaces(ac);
 }
 
accel/accel-user.c +6 -0
index 22b6a1a1a89..7d192306a65 100644
@@ -9,6 +9,12 @@
 
 #include "qemu/osdep.h"
 #include "qemu/accel.h"
+#include "accel-internal.h"
+
+void accel_init_ops_interfaces(AccelClass *ac)
+{
+    /* nothing */
+}
 
 AccelState *current_accel(void)
 {
Signature · 1 line
2.47.1
Reviewed-by on v1 14/19
#36 lore raw

Re: [RFC PATCH-for-10.1 14/19] accel: Implement accel_init_ops_interfaces() for both system/user mode

Quoted 93 lines · Philippe Mathieu-Daudé
---
  accel/{accel-system.h => accel-internal.h} |  8 ++++----
  accel/accel-system.c                       |  4 ++--
  accel/accel-target.c                       | 10 ++--------
  accel/accel-user.c                         |  6 ++++++
  4 files changed, 14 insertions(+), 14 deletions(-)

rename accel/{accel-system.h => accel-internal.h} (56%)

accel/accel-internal.h renamed from accel/accel-system.h +4 -4
similarity index 56%
rename from accel/accel-system.h
rename to accel/accel-internal.h
index 2d37c73c97b..03426aa21ee 100644
@@ -1,5 +1,5 @@
  /*
- * QEMU System Emulation accel internal functions
+ * QEMU accel internal functions
   *
   * Copyright 2021 SUSE LLC
   *
@@ -7,9 +7,9 @@
   * See the COPYING file in the top-level directory.
   */
 
-#ifndef ACCEL_SYSTEM_H
-#define ACCEL_SYSTEM_H
+#ifndef ACCEL_INTERNAL_H
+#define ACCEL_INTERNAL_H
 
-void accel_system_init_ops_interfaces(AccelClass *ac);
+void accel_init_ops_interfaces(AccelClass *ac);
 
  #endif /* ACCEL_SYSTEM_H */
accel/accel-system.c +2 -2
index 5df49fbe831..a0f562ae9ff 100644
@@ -29,7 +29,7 @@
  #include "system/accel-ops.h"
  #include "system/cpus.h"
  #include "qemu/error-report.h"
-#include "accel-system.h"
+#include "accel-internal.h"
 
  int accel_init_machine(AccelState *accel, MachineState *ms)
  {
@@ -63,7 +63,7 @@ void accel_setup_post(MachineState *ms)
  }
 
  /* initialize the arch-independent accel operation interfaces */
-void accel_system_init_ops_interfaces(AccelClass *ac)
+void accel_init_ops_interfaces(AccelClass *ac)
  {
      const char *ac_name;
      char *ops_name;
accel/accel-target.c +2 -8
index 9e9e70be876..6fa5c3ef04e 100644
@@ -29,10 +29,7 @@
 
  #include "cpu.h"
  #include "accel/accel-cpu-target.h"
-
-#ifndef CONFIG_USER_ONLY
-#include "accel-system.h"
-#endif /* !CONFIG_USER_ONLY */
+#include "accel-internal.h"
 
  static const TypeInfo accel_type = {
      .name = TYPE_ACCEL,
@@ -106,10 +103,7 @@ static void accel_init_cpu_interfaces(AccelClass *ac)
 
  void accel_init_interfaces(AccelClass *ac)
  {
-#ifndef CONFIG_USER_ONLY
-    accel_system_init_ops_interfaces(ac);
-#endif /* !CONFIG_USER_ONLY */
-
+    accel_init_ops_interfaces(ac);
      accel_init_cpu_interfaces(ac);
  }
 
accel/accel-user.c +0 -0
index 22b6a1a1a89..7d192306a65 100644
@@ -9,6 +9,12 @@
 
  #include "qemu/osdep.h"

accel/accel-user.c line 20

Quoted 10 lines
accel/accel-user.c +6 -0
  #include "qemu/accel.h"
+#include "accel-internal.h"
+
+void accel_init_ops_interfaces(AccelClass *ac)
+{
+    /* nothing */
+}
 
  AccelState *current_accel(void)
  {

That's good, and it's how we want to get rid of user/system conditionals.

#37 lore raw

RFC 15/19 accel: Include missing 'qemu/accel.h' header in accel-internal.h

In reply to Philippe Mathieu-Daudé

In file included from ../../accel/accel-target.c:29:
../../accel/accel-internal.h:13:32: error: unknown type name 'AccelClass'
13 | void accel_init_ops_interfaces(AccelClass *ac);
| ^

---
 accel/accel-internal.h | 2 ++
 1 file changed, 2 insertions(+)
accel/accel-internal.h +2 -0
index 03426aa21ee..d3a4422cbf7 100644
@@ -10,6 +10,8 @@
 #ifndef ACCEL_INTERNAL_H
 #define ACCEL_INTERNAL_H
 
+#include "qemu/accel.h"
+
 void accel_init_ops_interfaces(AccelClass *ac);
 
 #endif /* ACCEL_SYSTEM_H */
Signature · 1 line
2.47.1
Reviewed-by on v1 15/19
#38 lore raw

Re: [RFC PATCH-for-10.1 15/19] accel: Include missing 'qemu/accel.h' header in accel-internal.h

Quoted 15 lines · Philippe Mathieu-Daudé

In file included from ../../accel/accel-target.c:29:
../../accel/accel-internal.h:13:32: error: unknown type name 'AccelClass'

    13 | void accel_init_ops_interfaces(AccelClass *ac);
       |                                ^
---
  accel/accel-internal.h | 2 ++
  1 file changed, 2 insertions(+)
accel/accel-internal.h +0 -0
index 03426aa21ee..d3a4422cbf7 100644

accel/accel-internal.h line 17

Quoted 8 lines
accel/accel-internal.h +2 -0
@@ -10,6 +10,8 @@
  #ifndef ACCEL_INTERNAL_H
  #define ACCEL_INTERNAL_H
 
+#include "qemu/accel.h"
+
  void accel_init_ops_interfaces(AccelClass *ac);
 
  #endif /* ACCEL_SYSTEM_H */
#39 lore raw

RFC 16/19 accel: Make AccelCPUClass structure target-agnostic

In reply to Philippe Mathieu-Daudé

Include missing "hw/core/cpu.h" header in "accel/accel-cpu.h" to avoid:

include/accel/accel-cpu-target.h:39:28: error: unknown type name 'CPUClass'
39 | void (*cpu_class_init)(CPUClass *cc);
| ^

---
 include/accel/accel-cpu-target.h | 12 +-----------
 include/accel/accel-cpu.h        | 23 +++++++++++++++++++++++
 accel/accel-target.c             |  1 -
 3 files changed, 24 insertions(+), 12 deletions(-)
 create mode 100644 include/accel/accel-cpu.h
include/accel/accel-cpu-target.h +1 -11
index 37dde7fae3e..6feb344e29b 100644
@@ -21,21 +21,11 @@
  */
 
 #include "qom/object.h"
+#include "accel/accel-cpu.h"
 #include "cpu.h"
 
 #define TYPE_ACCEL_CPU "accel-" CPU_RESOLVING_TYPE
 #define ACCEL_CPU_NAME(name) (name "-" TYPE_ACCEL_CPU)
-typedef struct AccelCPUClass AccelCPUClass;
 DECLARE_CLASS_CHECKERS(AccelCPUClass, ACCEL_CPU, TYPE_ACCEL_CPU)
 
-typedef struct AccelCPUClass {
-    /*< private >*/
-    ObjectClass parent_class;
-    /*< public >*/
-
-    void (*cpu_class_init)(CPUClass *cc);
-    void (*cpu_instance_init)(CPUState *cpu);
-    bool (*cpu_target_realize)(CPUState *cpu, Error **errp);
-} AccelCPUClass;
-
 #endif /* ACCEL_CPU_H */
include/accel/accel-cpu.h new file +23 -0
new file mode 100644
index 00000000000..9e7eede7c3c
@@ -0,0 +1,23 @@
+/*
+ * Accelerator interface, specializes CPUClass
+ *
+ * Copyright 2021 SUSE LLC
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef ACCEL_CPU_H
+#define ACCEL_CPU_H
+
+#include "qom/object.h"
+#include "hw/core/cpu.h"
+
+typedef struct AccelCPUClass {
+    ObjectClass parent_class;
+
+    void (*cpu_class_init)(CPUClass *cc);
+    void (*cpu_instance_init)(CPUState *cpu);
+    bool (*cpu_target_realize)(CPUState *cpu, Error **errp);
+} AccelCPUClass;
+
+#endif /* ACCEL_CPU_H */
accel/accel-target.c +0 -1
index 6fa5c3ef04e..769a90230bf 100644
@@ -27,7 +27,6 @@
 #include "qemu/accel.h"
 #include "qemu/target_info.h"
 
-#include "cpu.h"
 #include "accel/accel-cpu-target.h"
 #include "accel-internal.h"
 
Signature · 1 line
2.47.1
Reviewed-by on v1 16/19
#40 lore raw

Re: [RFC PATCH-for-10.1 16/19] accel: Make AccelCPUClass structure target-agnostic

Quoted 75 lines · Philippe Mathieu-Daudé

Include missing "hw/core/cpu.h" header in "accel/accel-cpu.h" to avoid:

include/accel/accel-cpu-target.h:39:28: error: unknown type name 'CPUClass'

    39 |     void (*cpu_class_init)(CPUClass *cc);
       |                            ^
---
  include/accel/accel-cpu-target.h | 12 +-----------
  include/accel/accel-cpu.h        | 23 +++++++++++++++++++++++
  accel/accel-target.c             |  1 -
  3 files changed, 24 insertions(+), 12 deletions(-)

create mode 100644 include/accel/accel-cpu.h

include/accel/accel-cpu-target.h +1 -11
index 37dde7fae3e..6feb344e29b 100644
@@ -21,21 +21,11 @@
   */
 
  #include "qom/object.h"
+#include "accel/accel-cpu.h"
  #include "cpu.h"
 
  #define TYPE_ACCEL_CPU "accel-" CPU_RESOLVING_TYPE
  #define ACCEL_CPU_NAME(name) (name "-" TYPE_ACCEL_CPU)
-typedef struct AccelCPUClass AccelCPUClass;
  DECLARE_CLASS_CHECKERS(AccelCPUClass, ACCEL_CPU, TYPE_ACCEL_CPU)
 
-typedef struct AccelCPUClass {
-    /*< private >*/
-    ObjectClass parent_class;
-    /*< public >*/
-
-    void (*cpu_class_init)(CPUClass *cc);
-    void (*cpu_instance_init)(CPUState *cpu);
-    bool (*cpu_target_realize)(CPUState *cpu, Error **errp);
-} AccelCPUClass;
-
  #endif /* ACCEL_CPU_H */
include/accel/accel-cpu.h new file +23 -0
new file mode 100644
index 00000000000..9e7eede7c3c
@@ -0,0 +1,23 @@
+/*
+ * Accelerator interface, specializes CPUClass
+ *
+ * Copyright 2021 SUSE LLC
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef ACCEL_CPU_H
+#define ACCEL_CPU_H
+
+#include "qom/object.h"
+#include "hw/core/cpu.h"
+
+typedef struct AccelCPUClass {
+    ObjectClass parent_class;
+
+    void (*cpu_class_init)(CPUClass *cc);
+    void (*cpu_instance_init)(CPUState *cpu);
+    bool (*cpu_target_realize)(CPUState *cpu, Error **errp);
+} AccelCPUClass;
+
+#endif /* ACCEL_CPU_H */
accel/accel-target.c +0 -0
index 6fa5c3ef04e..769a90230bf 100644

accel/accel-target.c line 32

Quoted 7 lines
accel/accel-target.c +0 -1
@@ -27,7 +27,6 @@
  #include "qemu/accel.h"
  #include "qemu/target_info.h"
 
-#include "cpu.h"
  #include "accel/accel-cpu-target.h"
  #include "accel-internal.h"
 
#41 lore raw

RFC 17/19 accel: Move target-agnostic code from accel-target.c -> accel-common.c

In reply to Philippe Mathieu-Daudé
---
 accel/accel-common.c | 142 +++++++++++++++++++++++++++++++++++++++++++
 accel/accel-target.c | 129 ---------------------------------------
 accel/meson.build    |   1 +
 3 files changed, 143 insertions(+), 129 deletions(-)
 create mode 100644 accel/accel-common.c
accel/accel-common.c new file +142 -0
new file mode 100644
index 00000000000..f505461fc88
@@ -0,0 +1,142 @@
+/*
+ * QEMU accel class, components common to system emulation and user mode
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2014 Red Hat Inc.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/accel.h"
+#include "qemu/target_info.h"
+#include "accel/accel-cpu.h"
+#include "accel-internal.h"
+
+/* Lookup AccelClass from opt_name. Returns NULL if not found */
+AccelClass *accel_find(const char *opt_name)
+{
+    char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name);
+    AccelClass *ac = ACCEL_CLASS(module_object_class_by_name(class_name));
+    g_free(class_name);
+    return ac;
+}
+
+/* Return the name of the current accelerator */
+const char *current_accel_name(void)
+{
+    AccelClass *ac = ACCEL_GET_CLASS(current_accel());
+
+    return ac->name;
+}
+
+static void accel_init_cpu_int_aux(ObjectClass *klass, void *opaque)
+{
+    CPUClass *cc = CPU_CLASS(klass);
+    AccelCPUClass *accel_cpu = opaque;
+
+    /*
+     * The first callback allows accel-cpu to run initializations
+     * for the CPU, customizing CPU behavior according to the accelerator.
+     *
+     * The second one allows the CPU to customize the accel-cpu
+     * behavior according to the CPU.
+     *
+     * The second is currently only used by TCG, to specialize the
+     * TCGCPUOps depending on the CPU type.
+     */
+    cc->accel_cpu = accel_cpu;
+    if (accel_cpu->cpu_class_init) {
+        accel_cpu->cpu_class_init(cc);
+    }
+    if (cc->init_accel_cpu) {
+        cc->init_accel_cpu(accel_cpu, cc);
+    }
+}
+
+/* initialize the arch-specific accel CpuClass interfaces */
+static void accel_init_cpu_interfaces(AccelClass *ac)
+{
+    const char *ac_name; /* AccelClass name */
+    char *acc_name;      /* AccelCPUClass name */
+    ObjectClass *acc;    /* AccelCPUClass */
+    const char *cpu_resolving_type = target_cpu_type();
+
+    ac_name = object_class_get_name(OBJECT_CLASS(ac));
+    g_assert(ac_name != NULL);
+
+    acc_name = g_strdup_printf("%s-%s", ac_name, cpu_resolving_type);
+    acc = object_class_by_name(acc_name);
+    g_free(acc_name);
+
+    if (acc) {
+        object_class_foreach(accel_init_cpu_int_aux,
+                             cpu_resolving_type, false, acc);
+    }
+}
+
+void accel_init_interfaces(AccelClass *ac)
+{
+    accel_init_ops_interfaces(ac);
+    accel_init_cpu_interfaces(ac);
+}
+
+void accel_cpu_instance_init(CPUState *cpu)
+{
+    if (cpu->cc->accel_cpu && cpu->cc->accel_cpu->cpu_instance_init) {
+        cpu->cc->accel_cpu->cpu_instance_init(cpu);
+    }
+}
+
+bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
+{
+    AccelState *accel = current_accel();
+    AccelClass *acc = ACCEL_GET_CLASS(accel);
+
+    /* target specific realization */
+    if (cpu->cc->accel_cpu
+        && cpu->cc->accel_cpu->cpu_target_realize
+        && !cpu->cc->accel_cpu->cpu_target_realize(cpu, errp)) {
+        return false;
+    }
+
+    /* generic realization */
+    if (acc->cpu_common_realize && !acc->cpu_common_realize(cpu, errp)) {
+        return false;
+    }
+
+    return true;
+}
+
+void accel_cpu_common_unrealize(CPUState *cpu)
+{
+    AccelState *accel = current_accel();
+    AccelClass *acc = ACCEL_GET_CLASS(accel);
+
+    /* generic unrealization */
+    if (acc->cpu_common_unrealize) {
+        acc->cpu_common_unrealize(cpu);
+    }
+}
+
+int accel_supported_gdbstub_sstep_flags(void)
+{
+    AccelState *accel = current_accel();
+    AccelClass *acc = ACCEL_GET_CLASS(accel);
+    if (acc->gdbstub_supported_sstep_flags) {
+        return acc->gdbstub_supported_sstep_flags();
+    }
+    return 0;
+}
+
+static const TypeInfo accel_types[] = {
+    {
+        .name           = TYPE_ACCEL,
+        .parent         = TYPE_OBJECT,
+        .class_size     = sizeof(AccelClass),
+        .instance_size  = sizeof(AccelState),
+        .abstract       = true,
+    },
+};
+
+DEFINE_TYPES(accel_types)
accel/accel-target.c +0 -129

142 lines not on this page · raw message

accel/meson.build +1 -0
index 5eaeb683385..52909314bfa 100644
@@ -1,3 +1,4 @@
+common_ss.add(files('accel-common.c'))
 specific_ss.add(files('accel-target.c'))
 system_ss.add(files('accel-system.c', 'accel-blocker.c'))
 user_ss.add(files('accel-user.c'))
Signature · 1 line
2.47.1
Reviewed-by on v1 17/19
#42 lore raw

Re: [RFC PATCH-for-10.1 17/19] accel: Move target-agnostic code from accel-target.c -> accel-common.c

Quoted 309 lines · Philippe Mathieu-Daudé
---
  accel/accel-common.c | 142 +++++++++++++++++++++++++++++++++++++++++++
  accel/accel-target.c | 129 ---------------------------------------
  accel/meson.build    |   1 +
  3 files changed, 143 insertions(+), 129 deletions(-)

create mode 100644 accel/accel-common.c

accel/accel-common.c new file +142 -0
new file mode 100644
index 00000000000..f505461fc88
@@ -0,0 +1,142 @@
+/*
+ * QEMU accel class, components common to system emulation and user mode
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2014 Red Hat Inc.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/accel.h"
+#include "qemu/target_info.h"
+#include "accel/accel-cpu.h"
+#include "accel-internal.h"
+
+/* Lookup AccelClass from opt_name. Returns NULL if not found */
+AccelClass *accel_find(const char *opt_name)
+{
+    char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name);
+    AccelClass *ac = ACCEL_CLASS(module_object_class_by_name(class_name));
+    g_free(class_name);
+    return ac;
+}
+
+/* Return the name of the current accelerator */
+const char *current_accel_name(void)
+{
+    AccelClass *ac = ACCEL_GET_CLASS(current_accel());
+
+    return ac->name;
+}
+
+static void accel_init_cpu_int_aux(ObjectClass *klass, void *opaque)
+{
+    CPUClass *cc = CPU_CLASS(klass);
+    AccelCPUClass *accel_cpu = opaque;
+
+    /*
+     * The first callback allows accel-cpu to run initializations
+     * for the CPU, customizing CPU behavior according to the accelerator.
+     *
+     * The second one allows the CPU to customize the accel-cpu
+     * behavior according to the CPU.
+     *
+     * The second is currently only used by TCG, to specialize the
+     * TCGCPUOps depending on the CPU type.
+     */
+    cc->accel_cpu = accel_cpu;
+    if (accel_cpu->cpu_class_init) {
+        accel_cpu->cpu_class_init(cc);
+    }
+    if (cc->init_accel_cpu) {
+        cc->init_accel_cpu(accel_cpu, cc);
+    }
+}
+
+/* initialize the arch-specific accel CpuClass interfaces */
+static void accel_init_cpu_interfaces(AccelClass *ac)
+{
+    const char *ac_name; /* AccelClass name */
+    char *acc_name;      /* AccelCPUClass name */
+    ObjectClass *acc;    /* AccelCPUClass */
+    const char *cpu_resolving_type = target_cpu_type();
+
+    ac_name = object_class_get_name(OBJECT_CLASS(ac));
+    g_assert(ac_name != NULL);
+
+    acc_name = g_strdup_printf("%s-%s", ac_name, cpu_resolving_type);
+    acc = object_class_by_name(acc_name);
+    g_free(acc_name);
+
+    if (acc) {
+        object_class_foreach(accel_init_cpu_int_aux,
+                             cpu_resolving_type, false, acc);
+    }
+}
+
+void accel_init_interfaces(AccelClass *ac)
+{
+    accel_init_ops_interfaces(ac);
+    accel_init_cpu_interfaces(ac);
+}
+
+void accel_cpu_instance_init(CPUState *cpu)
+{
+    if (cpu->cc->accel_cpu && cpu->cc->accel_cpu->cpu_instance_init) {
+        cpu->cc->accel_cpu->cpu_instance_init(cpu);
+    }
+}
+
+bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
+{
+    AccelState *accel = current_accel();
+    AccelClass *acc = ACCEL_GET_CLASS(accel);
+
+    /* target specific realization */
+    if (cpu->cc->accel_cpu
+        && cpu->cc->accel_cpu->cpu_target_realize
+        && !cpu->cc->accel_cpu->cpu_target_realize(cpu, errp)) {
+        return false;
+    }
+
+    /* generic realization */
+    if (acc->cpu_common_realize && !acc->cpu_common_realize(cpu, errp)) {
+        return false;
+    }
+
+    return true;
+}
+
+void accel_cpu_common_unrealize(CPUState *cpu)
+{
+    AccelState *accel = current_accel();
+    AccelClass *acc = ACCEL_GET_CLASS(accel);
+
+    /* generic unrealization */
+    if (acc->cpu_common_unrealize) {
+        acc->cpu_common_unrealize(cpu);
+    }
+}
+
+int accel_supported_gdbstub_sstep_flags(void)
+{
+    AccelState *accel = current_accel();
+    AccelClass *acc = ACCEL_GET_CLASS(accel);
+    if (acc->gdbstub_supported_sstep_flags) {
+        return acc->gdbstub_supported_sstep_flags();
+    }
+    return 0;
+}
+
+static const TypeInfo accel_types[] = {
+    {
+        .name           = TYPE_ACCEL,
+        .parent         = TYPE_OBJECT,
+        .class_size     = sizeof(AccelClass),
+        .instance_size  = sizeof(AccelState),
+        .abstract       = true,
+    },
+};
+
+DEFINE_TYPES(accel_types)
accel/accel-target.c +0 -129
index 769a90230bf..7fd392fbc4a 100644
@@ -24,135 +24,7 @@
   */
 
  #include "qemu/osdep.h"
-#include "qemu/accel.h"
-#include "qemu/target_info.h"
-
  #include "accel/accel-cpu-target.h"
-#include "accel-internal.h"
-
-static const TypeInfo accel_type = {
-    .name = TYPE_ACCEL,
-    .parent = TYPE_OBJECT,
-    .class_size = sizeof(AccelClass),
-    .instance_size = sizeof(AccelState),
-    .abstract = true,
-};
-
-/* Lookup AccelClass from opt_name. Returns NULL if not found */
-AccelClass *accel_find(const char *opt_name)
-{
-    char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name);
-    AccelClass *ac = ACCEL_CLASS(module_object_class_by_name(class_name));
-    g_free(class_name);
-    return ac;
-}
-
-/* Return the name of the current accelerator */
-const char *current_accel_name(void)
-{
-    AccelClass *ac = ACCEL_GET_CLASS(current_accel());
-
-    return ac->name;
-}
-
-static void accel_init_cpu_int_aux(ObjectClass *klass, void *opaque)
-{
-    CPUClass *cc = CPU_CLASS(klass);
-    AccelCPUClass *accel_cpu = opaque;
-
-    /*
-     * The first callback allows accel-cpu to run initializations
-     * for the CPU, customizing CPU behavior according to the accelerator.
-     *
-     * The second one allows the CPU to customize the accel-cpu
-     * behavior according to the CPU.
-     *
-     * The second is currently only used by TCG, to specialize the
-     * TCGCPUOps depending on the CPU type.
-     */
-    cc->accel_cpu = accel_cpu;
-    if (accel_cpu->cpu_class_init) {
-        accel_cpu->cpu_class_init(cc);
-    }
-    if (cc->init_accel_cpu) {
-        cc->init_accel_cpu(accel_cpu, cc);
-    }
-}
-
-/* initialize the arch-specific accel CpuClass interfaces */
-static void accel_init_cpu_interfaces(AccelClass *ac)
-{
-    const char *ac_name; /* AccelClass name */
-    char *acc_name;      /* AccelCPUClass name */
-    ObjectClass *acc;    /* AccelCPUClass */
-    const char *cpu_resolving_type = target_cpu_type();
-
-    ac_name = object_class_get_name(OBJECT_CLASS(ac));
-    g_assert(ac_name != NULL);
-
-    acc_name = g_strdup_printf("%s-%s", ac_name, cpu_resolving_type);
-    acc = object_class_by_name(acc_name);
-    g_free(acc_name);
-
-    if (acc) {
-        object_class_foreach(accel_init_cpu_int_aux,
-                             cpu_resolving_type, false, acc);
-    }
-}
-
-void accel_init_interfaces(AccelClass *ac)
-{
-    accel_init_ops_interfaces(ac);
-    accel_init_cpu_interfaces(ac);
-}
-
-void accel_cpu_instance_init(CPUState *cpu)
-{
-    if (cpu->cc->accel_cpu && cpu->cc->accel_cpu->cpu_instance_init) {
-        cpu->cc->accel_cpu->cpu_instance_init(cpu);
-    }
-}
-
-bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
-{
-    AccelState *accel = current_accel();
-    AccelClass *acc = ACCEL_GET_CLASS(accel);
-
-    /* target specific realization */
-    if (cpu->cc->accel_cpu
-        && cpu->cc->accel_cpu->cpu_target_realize
-        && !cpu->cc->accel_cpu->cpu_target_realize(cpu, errp)) {
-        return false;
-    }
-
-    /* generic realization */
-    if (acc->cpu_common_realize && !acc->cpu_common_realize(cpu, errp)) {
-        return false;
-    }
-
-    return true;
-}
-
-void accel_cpu_common_unrealize(CPUState *cpu)
-{
-    AccelState *accel = current_accel();
-    AccelClass *acc = ACCEL_GET_CLASS(accel);
-
-    /* generic unrealization */
-    if (acc->cpu_common_unrealize) {
-        acc->cpu_common_unrealize(cpu);
-    }
-}
-
-int accel_supported_gdbstub_sstep_flags(void)
-{
-    AccelState *accel = current_accel();
-    AccelClass *acc = ACCEL_GET_CLASS(accel);
-    if (acc->gdbstub_supported_sstep_flags) {
-        return acc->gdbstub_supported_sstep_flags();
-    }
-    return 0;
-}
 
  static const TypeInfo accel_cpu_type = {
      .name = TYPE_ACCEL_CPU,
@@ -163,7 +35,6 @@ static const TypeInfo accel_cpu_type = {
 
  static void register_accel_types(void)
  {
-    type_register_static(&accel_type);
      type_register_static(&accel_cpu_type);
  }
 
accel/meson.build +0 -0
index 5eaeb683385..52909314bfa 100644

accel/meson.build line 4

Quoted 4 lines
accel/meson.build +1 -0
@@ -1,3 +1,4 @@
+common_ss.add(files('accel-common.c'))
  specific_ss.add(files('accel-target.c'))
  system_ss.add(files('accel-system.c', 'accel-blocker.c'))
  user_ss.add(files('accel-user.c'))

It seems that only accel_cpu_type is left in accel-target.c after that.
Couldn't we move that to TargetInfo, so the whole accel-target.c file can become common instead? If there is something I missed, I'm ok with the current change.
I just feel the last 3 commits, and this one, are a bit disconnected from the series.

#43 lore raw

Re: [RFC PATCH-for-10.1 17/19] accel: Move target-agnostic code from accel-target.c -> accel-common.c

Quoted 10 lines · Pierrick Bouvier
Quoted 7 lines · Philippe Mathieu-Daudé

---
  accel/accel-common.c | 142 +++++++++++++++++++++++++++++++++++++++++++ accel/accel-target.c | 129 --------------------------------------- accel/meson.build    |   1 +

  3 files changed, 143 insertions(+), 129 deletions(-)

  create mode 100644 accel/accel-common.c

Quoted 2 lines

It seems that only accel_cpu_type is left in accel-target.c after that.
Couldn't we move that to TargetInfo, so the whole accel-target.c file can become common instead?

IIUC "accel/accel-cpu-target.h" defines the AccelCPUClass QOM CLASS_CHECKERS macros based on CPU_RESOLVING_TYPE.

Quoted 1 line

If there is something I missed, I'm ok with the current change.

Thanks.

Quoted 1 line

I just feel the last 3 commits, and this one, are a bit disconnected from the series.

OK, will do.

#44 lore raw

RFC 18/19 qemu: Prepare per-binary QOM filter via TYPE_BINARY_PREFIX

In reply to Philippe Mathieu-Daudé
---
 meson.build                    |  1 +
 include/hw/boards.h            |  1 +
 include/qemu/target_info-qom.h | 14 ++++++++++++++
 target_info-qom.c              | 15 +++++++++++++++
 4 files changed, 31 insertions(+)
 create mode 100644 include/qemu/target_info-qom.h
 create mode 100644 target_info-qom.c
meson.build +1 -0
index de9c9dacd35..b93253166c8 100644
@@ -3815,6 +3815,7 @@ specific_ss.add(files('page-target.c', 'page-vary-target.c'))
 
 specific_ss.add(files('target_info-stub.c'))
 common_ss.add(files('target_info.c'))
+system_ss.add(files('target_info-qom.c'))
 
 subdir('backends')
 subdir('disas')
include/hw/boards.h +1 -0
index 02f43ac5d4d..b1bbf3c34d4 100644
@@ -7,6 +7,7 @@
 #include "system/hostmem.h"
 #include "system/blockdev.h"
 #include "qapi/qapi-types-machine.h"
+#include "qemu/target_info-qom.h"
 #include "qemu/module.h"
 #include "qom/object.h"
 #include "hw/core/cpu.h"
include/qemu/target_info-qom.h new file +14 -0
new file mode 100644
index 00000000000..c87d47acf66
@@ -0,0 +1,14 @@
+/*
+ * QEMU binary helpers
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_TARGET_INFO_QOM_H
+#define QEMU_TARGET_INFO_QOM_H
+
+#define TYPE_LEGACY_BINARY_PREFIX "legacy-binary-"
+
+#endif
target_info-qom.c new file +15 -0
new file mode 100644
index 00000000000..6970b95ee0b
@@ -0,0 +1,15 @@
+/*
+ * QEMU legacy binary helpers
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/target_info-qom.h"
+
+static const TypeInfo target_info_types[] = {
+};
+
+DEFINE_TYPES(target_info_types)
Signature · 1 line
2.47.1
#45 lore raw

Re: [RFC PATCH-for-10.1 18/19] qemu: Prepare per-binary QOM filter via TYPE_BINARY_PREFIX

Quoted 43 lines · Philippe Mathieu-Daudé
---
  meson.build                    |  1 +
  include/hw/boards.h            |  1 +
  include/qemu/target_info-qom.h | 14 ++++++++++++++
  target_info-qom.c              | 15 +++++++++++++++
  4 files changed, 31 insertions(+)

create mode 100644 include/qemu/target_info-qom.h create mode 100644 target_info-qom.c

meson.build +1 -0
index de9c9dacd35..b93253166c8 100644
@@ -3815,6 +3815,7 @@ specific_ss.add(files('page-target.c', 'page-vary-target.c'))
 
  specific_ss.add(files('target_info-stub.c'))
  common_ss.add(files('target_info.c'))
+system_ss.add(files('target_info-qom.c'))
 
  subdir('backends')
  subdir('disas')
include/hw/boards.h +1 -0
index 02f43ac5d4d..b1bbf3c34d4 100644
@@ -7,6 +7,7 @@
  #include "system/hostmem.h"
  #include "system/blockdev.h"
  #include "qapi/qapi-types-machine.h"
+#include "qemu/target_info-qom.h"
  #include "qemu/module.h"
  #include "qom/object.h"
  #include "hw/core/cpu.h"
include/qemu/target_info-qom.h new file +3 -0
new file mode 100644
index 00000000000..c87d47acf66
@@ -0,0 +1,14 @@
+/*
+ * QEMU binary helpers
+ *

include/qemu/target_info-qom.h line 13

Quoted 10 lines
include/qemu/target_info-qom.h new file +10 -0
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_TARGET_INFO_QOM_H
+#define QEMU_TARGET_INFO_QOM_H
+
+#define TYPE_LEGACY_BINARY_PREFIX "legacy-binary-"
+

How about TYPE_TARGET_PREFIX instead?
It's not related to any legacy stuff, as the new API will be used in the future (and will stay). As well, I don't think we should mention "binary" in any name, because what we really talk about are targets {user|system, architecture}, in the meaning of our build system (configure --target-list).

So please replace [legacy, binary] with target simply, so we keep a sane vocabulary in the future.

Quoted 22 lines
include/qemu/target_info-qom.h new file +1 -0
+#endif
target_info-qom.c new file +15 -0
new file mode 100644
index 00000000000..6970b95ee0b
@@ -0,0 +1,15 @@
+/*
+ * QEMU legacy binary helpers
+ *
+ *  Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/target_info-qom.h"
+
+static const TypeInfo target_info_types[] = {
+};
+
+DEFINE_TYPES(target_info_types)
#46 lore raw

RFC 19/19 system/vl: Filter machine list for binary using machine_binary_filter()

In reply to Philippe Mathieu-Daudé
---
 system/vl.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
system/vl.c +24 -0
index d8a0fe713c9..554f5f2a467 100644
@@ -27,6 +27,8 @@
 #include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "qemu/module.h"
+#include "qemu/target_info.h"
+#include "qemu/target_info-qom.h"
 #include "exec/cpu-common.h"
 #include "exec/page-vary.h"
 #include "hw/qdev-properties.h"
@@ -833,14 +835,29 @@ static bool usb_parse(const char *cmdline, Error **errp)
 /***********************************************************/
 /* machine registration */
 
+static char *machine_binary_filter(void)
+{
+    if (target_info_is_stub()) {
+        return NULL;
+    }
+    return g_strconcat(TYPE_LEGACY_BINARY_PREFIX,
+                       "qemu-system-", target_name(), NULL);
+}
+
 static MachineClass *find_machine(const char *name, GSList *machines)
 {
     GSList *el;
+    g_autofree char *binary_filter = machine_binary_filter();
 
     for (el = machines; el; el = el->next) {
         MachineClass *mc = el->data;
 
         if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) {
+            if (binary_filter && !object_class_dynamic_cast(el->data,
+                                                            binary_filter)) {
+                /* Machine is not for this binary: fail */
+                return NULL;
+            }
             return mc;
         }
     }
@@ -1563,6 +1580,7 @@ static void machine_help_func(const QDict *qdict)
     g_autoptr(GSList) machines = NULL;
     GSList *el;
     const char *type = qdict_get_try_str(qdict, "type");
+    g_autofree char *binary_filter = machine_binary_filter();
 
     machines = object_class_get_list(TYPE_MACHINE, false);
     if (type) {
@@ -1577,6 +1595,12 @@ static void machine_help_func(const QDict *qdict)
     machines = g_slist_sort(machines, machine_class_cmp);
     for (el = machines; el; el = el->next) {
         MachineClass *mc = el->data;
+
+        if (binary_filter && !object_class_dynamic_cast(el->data,
+                                                        binary_filter)) {
+            /* Machine is not for this binary: skip */
+            continue;
+        }
         if (mc->alias) {
             printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name);
         }
Signature · 1 line
2.47.1
#47 lore raw

Re: [RFC PATCH-for-10.1 19/19] system/vl: Filter machine list for binary using machine_binary_filter()

Quoted 19 lines · Philippe Mathieu-Daudé
---
  system/vl.c | 24 ++++++++++++++++++++++++
  1 file changed, 24 insertions(+)
system/vl.c +2 -0
index d8a0fe713c9..554f5f2a467 100644
@@ -27,6 +27,8 @@
  #include "qemu/datadir.h"
  #include "qemu/units.h"
  #include "qemu/module.h"
+#include "qemu/target_info.h"
+#include "qemu/target_info-qom.h"
  #include "exec/cpu-common.h"
  #include "exec/page-vary.h"
  #include "hw/qdev-properties.h"

system/vl.c static bool usb_parse(const char *cmdline, Error **errp) · line 844

Quoted 10 lines
system/vl.c +7 -0
@@ -833,14 +835,29 @@ static bool usb_parse(const char *cmdline, Error **errp)
  /***********************************************************/
  /* machine registration */
 
+static char *machine_binary_filter(void)
+{
+    if (target_info_is_stub()) {
+        return NULL;
+    }
+    return g_strconcat(TYPE_LEGACY_BINARY_PREFIX,
+                       "qemu-system-", target_name(), NULL);

No, we should not have such things.
We can make it work with proper QOM types, defined by target, instead of relying on string construction/compare like this.

Quoted 20 lines
system/vl.c +8 -0
+}
+
  static MachineClass *find_machine(const char *name, GSList *machines)
  {
      GSList *el;
+    g_autofree char *binary_filter = machine_binary_filter();
 
      for (el = machines; el; el = el->next) {
          MachineClass *mc = el->data;
 
          if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) {
+            if (binary_filter && !object_class_dynamic_cast(el->data,
+                                                            binary_filter)) {
+                /* Machine is not for this binary: fail */
+                return NULL;
+            }
              return mc;
          }
      }

system/vl.c static void machine_help_func(const QDict *qdict) · line 1585

Quoted 6 lines
system/vl.c +1 -0
@@ -1563,6 +1580,7 @@ static void machine_help_func(const QDict *qdict)
      g_autoptr(GSList) machines = NULL;
      GSList *el;
      const char *type = qdict_get_try_str(qdict, "type");
+    g_autofree char *binary_filter = machine_binary_filter();
 
      machines = object_class_get_list(TYPE_MACHINE, false);

If we define a proper TYPE_TARGET_MACHINE per target, and we add this to TargetInfo, this can become:

machines = object_class_get_list(target_machine_type(), false);

And we don't need any other string hack to detect what is the correct type.

system/vl.c static void machine_help_func(const QDict *qdict) · line 1603

Quoted 11 lines
system/vl.c +6 -0
      if (type) {
@@ -1577,6 +1595,12 @@ static void machine_help_func(const QDict *qdict)
      machines = g_slist_sort(machines, machine_class_cmp);
      for (el = machines; el; el = el->next) {
          MachineClass *mc = el->data;
+
+        if (binary_filter && !object_class_dynamic_cast(el->data,
+                                                        binary_filter)) {
+            /* Machine is not for this binary: skip */
+            continue;
+        }

With the approach above, this is not needed anymore.

system/vl.c static void machine_help_func(const QDict *qdict) · line 1606

Quoted 3 lines
system/vl.c +0 -0
          if (mc->alias) {
              printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name);
          }

I think we are missing a commit here, defining a proper TYPE_TARGET_MACHINE_PREFIX, that is target dependent, instead of the TYPE_LEGACY_BINARY_PREFIX.

And we should include in this type in TargetInfo, the same way it was done for cpus.

#48 lore raw

Re: [RFC PATCH-for-10.1 19/19] system/vl: Filter machine list for binary using machine_binary_filter()

Hi Pierrick,

Quoted 25 lines · Pierrick Bouvier
Quoted 24 lines · Philippe Mathieu-Daudé

---
  system/vl.c | 24 ++++++++++++++++++++++++

  1 file changed, 24 insertions(+)
system/vl.c +4 -0
index d8a0fe713c9..554f5f2a467 100644
@@ -27,6 +27,8 @@
   #include "qemu/datadir.h"
   #include "qemu/units.h"
   #include "qemu/module.h"
+#include "qemu/target_info.h"
+#include "qemu/target_info-qom.h"
   #include "exec/cpu-common.h"
   #include "exec/page-vary.h"
   #include "hw/qdev-properties.h"
@@ -833,14 +835,29 @@ static bool usb_parse(const char *cmdline, Error 
 **errp)
   /***********************************************************/
   /* machine registration */
+static char *machine_binary_filter(void)
+{
Quoted 8 lines

system/vl.c static bool usb_parse(const char *cmdline, Error **errp) · line 844

Quoted 5 lines
system/vl.c +5 -0
+    if (target_info_is_stub()) {
+        return NULL;
+    }
+    return g_strconcat(TYPE_LEGACY_BINARY_PREFIX,
+                       "qemu-system-", target_name(), NULL);

No, we should not have such things.
We can make it work with proper QOM types, defined by target, instead of relying on string construction/compare like this.

I am not understanding you, do you mind sharing code snippets of what you have in mind?

Quoted 54 lines
Quoted 20 lines
system/vl.c +8 -0
+}
+
   static MachineClass *find_machine(const char *name, GSList *machines)
   {
       GSList *el;
+    g_autofree char *binary_filter = machine_binary_filter();
       for (el = machines; el; el = el->next) {
           MachineClass *mc = el->data;
           if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) {
+            if (binary_filter && !object_class_dynamic_cast(el->data,
+                                                            
 binary_filter)) {
+                /* Machine is not for this binary: fail */
+                return NULL;
+            }
               return mc;
           }
       }

system/vl.c static void machine_help_func(const QDict *qdict) · line 1584

Quoted 5 lines
system/vl.c +1 -0
@@ -1563,6 +1580,7 @@ static void machine_help_func(const QDict *qdict)
       g_autoptr(GSList) machines = NULL;
       GSList *el;
       const char *type = qdict_get_try_str(qdict, "type");
+    g_autofree char *binary_filter = machine_binary_filter();
       machines = object_class_get_list(TYPE_MACHINE, false);

If we define a proper TYPE_TARGET_MACHINE per target, and we add this to TargetInfo, this can become:

machines = object_class_get_list(target_machine_type(), false);

And we don't need any other string hack to detect what is the correct type.

system/vl.c static void machine_help_func(const QDict *qdict) · line 1604

Quoted 12 lines
system/vl.c +6 -0
       if (type) {
@@ -1577,6 +1595,12 @@ static void machine_help_func(const QDict *qdict)
       machines = g_slist_sort(machines, machine_class_cmp);
       for (el = machines; el; el = el->next) {
           MachineClass *mc = el->data;
+
+        if (binary_filter && !object_class_dynamic_cast(el->data,
+                                                        
 binary_filter)) {
+            /* Machine is not for this binary: skip */
+            continue;
+        }

With the approach above, this is not needed anymore.

Quoted 3 lines
system/vl.c +0 -0
           if (mc->alias) {
               printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name);

          }

I think we are missing a commit here, defining a proper TYPE_TARGET_MACHINE_PREFIX, that is target dependent, instead of the TYPE_LEGACY_BINARY_PREFIX.

And we should include in this type in TargetInfo, the same way it was done for cpus.

#49 lore raw

Re: [RFC PATCH-for-10.1 19/19] system/vl: Filter machine list for binary using machine_binary_filter()

Quoted 38 lines · Philippe Mathieu-Daudé

Hi Pierrick,

Quoted 26 lines · Pierrick Bouvier
Quoted 25 lines · Philippe Mathieu-Daudé
---
   system/vl.c | 24 ++++++++++++++++++++++++
   1 file changed, 24 insertions(+)
system/vl.c +5 -0
index d8a0fe713c9..554f5f2a467 100644
@@ -27,6 +27,8 @@
   #include "qemu/datadir.h"
   #include "qemu/units.h"
   #include "qemu/module.h"
+#include "qemu/target_info.h"
+#include "qemu/target_info-qom.h"
   #include "exec/cpu-common.h"
   #include "exec/page-vary.h"
   #include "hw/qdev-properties.h"
@@ -833,14 +835,29 @@ static bool usb_parse(const char *cmdline, Error
 **errp)
   /***********************************************************/
   /* machine registration */
+static char *machine_binary_filter(void)
+{
+    if (target_info_is_stub()) {
Quoted 8 lines

system/vl.c static bool usb_parse(const char *cmdline, Error **errp) · line 844

Quoted 4 lines
system/vl.c +4 -0
+        return NULL;
+    }
+    return g_strconcat(TYPE_LEGACY_BINARY_PREFIX,
+                       "qemu-system-", target_name(), NULL);

No, we should not have such things.
We can make it work with proper QOM types, defined by target, instead of relying on string construction/compare like this.

Quoted 3 lines

I am not understanding you, do you mind sharing code snippets of what you have in mind?

Instead of the current and previous patch,

we define TYPE_TARGET_MACHINE_PREFIX.

For each target, we define a specific TYPE_TARGET_MACHINE variant, like:
- TYPE_TARGET_MACHINE_ARM
- TYPE_TARGET_MACHINE_AARCH64
...

In TargetInfo, we add a new function target_machine_type(), that returns this type, specialized for each architecture. As a first step, the stub implementation can return TYPE_MACHINE, and we can enable this architecture per architecture later.

For the first architecture implementation, arm, we will define TYPE_TARGET_MACHINE_ARM, and TYPE_TARGET_MACHINE_AARCH64, which will allow concerned files to be common, while still maintaining a specific set of machines per target.

Is that more clear?

Quoted 60 lines
Quoted 59 lines
Quoted 20 lines
system/vl.c +8 -0
+}
+
   static MachineClass *find_machine(const char *name, GSList *machines)
   {
       GSList *el;
+    g_autofree char *binary_filter = machine_binary_filter();
       for (el = machines; el; el = el->next) {
           MachineClass *mc = el->data;
           if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) {
+            if (binary_filter && !object_class_dynamic_cast(el->data,
+
 binary_filter)) {
+                /* Machine is not for this binary: fail */
+                return NULL;
+            }
               return mc;
           }
       }

system/vl.c static void machine_help_func(const QDict *qdict) · line 1584

Quoted 5 lines
system/vl.c +1 -0
@@ -1563,6 +1580,7 @@ static void machine_help_func(const QDict *qdict)
       g_autoptr(GSList) machines = NULL;
       GSList *el;
       const char *type = qdict_get_try_str(qdict, "type");
+    g_autofree char *binary_filter = machine_binary_filter();
       machines = object_class_get_list(TYPE_MACHINE, false);

If we define a proper TYPE_TARGET_MACHINE per target, and we add this to TargetInfo, this can become:

machines = object_class_get_list(target_machine_type(), false);

And we don't need any other string hack to detect what is the correct type.

system/vl.c static void machine_help_func(const QDict *qdict) · line 1604

Quoted 12 lines
system/vl.c +6 -0
       if (type) {
@@ -1577,6 +1595,12 @@ static void machine_help_func(const QDict *qdict)
       machines = g_slist_sort(machines, machine_class_cmp);
       for (el = machines; el; el = el->next) {
           MachineClass *mc = el->data;
+
+        if (binary_filter && !object_class_dynamic_cast(el->data,
+
 binary_filter)) {
+            /* Machine is not for this binary: skip */
+            continue;
+        }

With the approach above, this is not needed anymore.

Quoted 4 lines
system/vl.c +0 -0
           if (mc->alias) {
               printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc,

mc->name);
          }

I think we are missing a commit here, defining a proper TYPE_TARGET_MACHINE_PREFIX, that is target dependent, instead of the TYPE_LEGACY_BINARY_PREFIX.

And we should include in this type in TargetInfo, the same way it was done for cpus.

#50 lore raw

Re: [RFC PATCH-for-10.1 19/19] system/vl: Filter machine list for binary using machine_binary_filter()

Quoted 57 lines · Pierrick Bouvier
Quoted 38 lines · Philippe Mathieu-Daudé

Hi Pierrick,

Quoted 26 lines · Pierrick Bouvier
Quoted 25 lines · Philippe Mathieu-Daudé
---
    system/vl.c | 24 ++++++++++++++++++++++++
    1 file changed, 24 insertions(+)
system/vl.c +5 -0
index d8a0fe713c9..554f5f2a467 100644
@@ -27,6 +27,8 @@
    #include "qemu/datadir.h"
    #include "qemu/units.h"
    #include "qemu/module.h"
+#include "qemu/target_info.h"
+#include "qemu/target_info-qom.h"
    #include "exec/cpu-common.h"
    #include "exec/page-vary.h"
    #include "hw/qdev-properties.h"
@@ -833,14 +835,29 @@ static bool usb_parse(const char *cmdline, Error
 **errp)
    /***********************************************************/
    /* machine registration */
+static char *machine_binary_filter(void)
+{
+    if (target_info_is_stub()) {
Quoted 8 lines

system/vl.c static bool usb_parse(const char *cmdline, Error **errp) · line 844

Quoted 4 lines
system/vl.c +4 -0
+        return NULL;
+    }
+    return g_strconcat(TYPE_LEGACY_BINARY_PREFIX,
+                       "qemu-system-", target_name(), NULL);

No, we should not have such things.
We can make it work with proper QOM types, defined by target, instead of relying on string construction/compare like this.

Quoted 3 lines

I am not understanding you, do you mind sharing code snippets of what you have in mind?

Instead of the current and previous patch,

we define TYPE_TARGET_MACHINE_PREFIX.

For each target, we define a specific TYPE_TARGET_MACHINE variant, like:
- TYPE_TARGET_MACHINE_ARM
- TYPE_TARGET_MACHINE_AARCH64
...

In TargetInfo, we add a new function target_machine_type(), that returns this type, specialized for each architecture.
As a first step, the stub implementation can return TYPE_MACHINE, and we can enable this architecture per architecture later.

Quoted 5 lines

For the first architecture implementation, arm, we will define TYPE_TARGET_MACHINE_ARM, and TYPE_TARGET_MACHINE_AARCH64, which will allow concerned files to be common, while still maintaining a specific set of machines per target.

Note: Those TYPE_TARGET_MACHINE_* types are QOM interfaces, that every concerned machine implements.

Once things are done this way, the only required change is:
- machines = object_class_get_list(TYPE_MACHINE, false);
+ machines = object_class_get_list(target_machine_type(), false);

As a further step, it will be very easy to support having multiple targets enabled at the same time (build a list of machine types instead of a single one), but we can do this *later* when tackling heterogeneous emulation.

Quoted 63 lines

Is that more clear?

Quoted 60 lines
Quoted 59 lines
Quoted 20 lines
system/vl.c +8 -0
+}
+
    static MachineClass *find_machine(const char *name, GSList *machines)
    {
        GSList *el;
+    g_autofree char *binary_filter = machine_binary_filter();
        for (el = machines; el; el = el->next) {
            MachineClass *mc = el->data;
            if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) {
+            if (binary_filter && !object_class_dynamic_cast(el->data,
+
 binary_filter)) {
+                /* Machine is not for this binary: fail */
+                return NULL;
+            }
                return mc;
            }
        }

system/vl.c static void machine_help_func(const QDict *qdict) · line 1584

Quoted 5 lines
system/vl.c +1 -0
@@ -1563,6 +1580,7 @@ static void machine_help_func(const QDict *qdict)
        g_autoptr(GSList) machines = NULL;
        GSList *el;
        const char *type = qdict_get_try_str(qdict, "type");
+    g_autofree char *binary_filter = machine_binary_filter();
        machines = object_class_get_list(TYPE_MACHINE, false);

If we define a proper TYPE_TARGET_MACHINE per target, and we add this to TargetInfo, this can become:

machines = object_class_get_list(target_machine_type(), false);

And we don't need any other string hack to detect what is the correct type.

system/vl.c static void machine_help_func(const QDict *qdict) · line 1604

Quoted 12 lines
system/vl.c +6 -0
        if (type) {
@@ -1577,6 +1595,12 @@ static void machine_help_func(const QDict *qdict)
        machines = g_slist_sort(machines, machine_class_cmp);
        for (el = machines; el; el = el->next) {
            MachineClass *mc = el->data;
+
+        if (binary_filter && !object_class_dynamic_cast(el->data,
+
 binary_filter)) {
+            /* Machine is not for this binary: skip */
+            continue;
+        }

With the approach above, this is not needed anymore.

Quoted 4 lines
system/vl.c +0 -0
            if (mc->alias) {
                printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc,

mc->name);
          }

I think we are missing a commit here, defining a proper TYPE_TARGET_MACHINE_PREFIX, that is target dependent, instead of the TYPE_LEGACY_BINARY_PREFIX.

And we should include in this type in TargetInfo, the same way it was done for cpus.