On 4/18/25 10:28, Philippe Mathieu-Daudé wrote:
Binaries can register a QOM type to filter their machines
by filling their TargetInfo::machine_typename field.
This can be used by example by main() -> machine_help_func()
to filter the machines list.
Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org>
---
meson.build | 1 +
include/qemu/target_info-impl.h | 3 +++
include/qemu/target_info.h | 8 ++++++++
system/vl.c | 3 ++-
target_info-qom.c | 15 +++++++++++++++
target_info-stub.c | 2 ++
target_info.c | 5 +++++
7 files changed, 36 insertions(+), 1 deletion(-)
create mode 100644 target_info-qom.c
diff --git a/meson.build b/meson.build
index 49a050a28a3..168b07b5887 100644
--- a/meson.build
+++ b/meson.build
@@ -3808,6 +3808,7 @@ common_ss.add(pagevary)
specific_ss.add(files('page-target.c', 'page-vary-target.c'))
common_ss.add(files('target_info.c'))
+system_ss.add(files('target_info-qom.c'))
specific_ss.add(files('target_info-stub.c'))
subdir('backends')
diff --git a/include/qemu/target_info-impl.h b/include/qemu/target_info-impl.h
index 11b92796b28..e3344278a92 100644
--- a/include/qemu/target_info-impl.h
+++ b/include/qemu/target_info-impl.h
@@ -16,6 +16,9 @@ typedef struct TargetInfo {
/* runtime equivalent of TARGET_NAME definition */
const char *const target_name;
+ /* QOM typename machines for this binary must implement */
+ const char *const machine_typename;
+
} TargetInfo;
const TargetInfo *target_info(void);
diff --git a/include/qemu/target_info.h b/include/qemu/target_info.h
index 3f6cbbbd300..c67b97d66f3 100644
--- a/include/qemu/target_info.h
+++ b/include/qemu/target_info.h
@@ -16,4 +16,12 @@
*/
const char *target_name(void);
+/**
+ * target_machine_typename:
+ *
+ * Returns: Name of the QOM interface implemented by machines
+ * usable on this target binary.
+ */
+const char *target_machine_typename(void);
+
#endif
diff --git a/system/vl.c b/system/vl.c
index d8a0fe713c9..8fb18f82e20 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -27,6 +27,7 @@
#include "qemu/datadir.h"
#include "qemu/units.h"
#include "qemu/module.h"
+#include "qemu/target_info.h"
#include "exec/cpu-common.h"
#include "exec/page-vary.h"
#include "hw/qdev-properties.h"
@@ -1564,7 +1565,7 @@ static void machine_help_func(const QDict *qdict)
GSList *el;
const char *type = qdict_get_try_str(qdict, "type");
- machines = object_class_get_list(TYPE_MACHINE, false);
+ machines = object_class_get_list(target_machine_typename(), false);
if (type) {
ObjectClass *machine_class = OBJECT_CLASS(find_machine(type,
machines));
if (machine_class) {
diff --git a/target_info-qom.c b/target_info-qom.c
new file mode 100644
index 00000000000..a6fd8f1d5a3
--- /dev/null
+++ b/target_info-qom.c
@@ -0,0 +1,15 @@
+/*
+ * QEMU binary/target API (QOM types)
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qom/object.h"
+
+static const TypeInfo target_info_types[] = {
+};
+
+DEFINE_TYPES(target_info_types)
diff --git a/target_info-stub.c b/target_info-stub.c
index f15972c5b22..14e6d5e68d2 100644
--- a/target_info-stub.c
+++ b/target_info-stub.c
@@ -8,9 +8,11 @@
#include "qemu/osdep.h"
#include "qemu/target_info-impl.h"
+#include "hw/boards.h"
static const TargetInfo target_info_stub = {
.target_name = TARGET_NAME,
+ .machine_typename = TYPE_MACHINE,
};
Excellent, even more simple than returning NULL.
const TargetInfo *target_info(void)
diff --git a/target_info.c b/target_info.c
index 48c4a413326..1de4334ecc5 100644
--- a/target_info.c
+++ b/target_info.c
@@ -14,3 +14,8 @@ const char *target_name(void)
{
return target_info()->target_name;
}
+
+const char *target_machine_typename(void)
+{
+ return target_info()->machine_typename;
+}
Reviewed-by: Pierrick Bouvier <pierrick.bouv...@linaro.org>