qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Pierrick Bouvier <pierrick.bouvier@linaro.org>, qemu-devel@nongnu.org
Cc: Anton Johansson <anjo@rev.ng>,
	Richard Henderson <richard.henderson@linaro.org>
Subject: [RFC PATCH v2 03/11] system/vl: Filter machine list available for a particular target binary
Date: Fri, 18 Apr 2025 02:50:51 +0200	[thread overview]
Message-ID: <20250418005059.4436-4-philmd@linaro.org> (raw)
In-Reply-To: <20250418005059.4436-1-philmd@linaro.org>

Binaries can register a QOM type to filter their machines
by filling their TargetInfo::machine_typename field.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/qemu/target_info-impl.h |  3 +++
 include/qemu/target_info.h      |  8 ++++++++
 system/vl.c                     | 14 ++++++++++++++
 target_info.c                   |  5 +++++
 4 files changed, 30 insertions(+)

diff --git a/include/qemu/target_info-impl.h b/include/qemu/target_info-impl.h
index d5c94ed5296..990fb067d20 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 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..e9fd2fdd7b0 100644
--- a/include/qemu/target_info.h
+++ b/include/qemu/target_info.h
@@ -16,4 +16,12 @@
  */
 const char *target_name(void);
 
+/**
+ * target_machine_interface_typename:
+ *
+ * Returns: Name of the QOM interface implemented by machines
+ *          usable on this target binary.
+ */
+const char *target_machine_interface_typename(void);
+
 #endif
diff --git a/system/vl.c b/system/vl.c
index d8a0fe713c9..4e43e55afe7 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"
@@ -836,11 +837,17 @@ static bool usb_parse(const char *cmdline, Error **errp)
 static MachineClass *find_machine(const char *name, GSList *machines)
 {
     GSList *el;
+    const char *qom_typename_filter = target_machine_interface_typename();
 
     for (el = machines; el; el = el->next) {
         MachineClass *mc = el->data;
 
         if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) {
+            if (qom_typename_filter
+                && !object_class_dynamic_cast(el->data, qom_typename_filter)) {
+                /* Machine is not for this binary: fail */
+                return NULL;
+            }
             return mc;
         }
     }
@@ -1563,6 +1570,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");
+    const char *qom_typename_filter = target_machine_interface_typename();
 
     machines = object_class_get_list(TYPE_MACHINE, false);
     if (type) {
@@ -1577,6 +1585,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 (qom_typename_filter
+            && !object_class_dynamic_cast(el->data, qom_typename_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);
         }
diff --git a/target_info.c b/target_info.c
index 877a6a15014..226eed1fd7d 100644
--- a/target_info.c
+++ b/target_info.c
@@ -14,3 +14,8 @@ const char *target_name(void)
 {
     return target_info()->name;
 }
+
+const char *target_machine_interface_typename(void)
+{
+    return target_info()->machine_typename;
+}
-- 
2.47.1



  parent reply	other threads:[~2025-04-18  0:52 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-18  0:50 [RFC PATCH v2 00/11] single-binary: Make hw/arm/ common Philippe Mathieu-Daudé
2025-04-18  0:50 ` [RFC PATCH v2 01/11] qapi: Rename TargetInfo structure as BinaryTargetInfo Philippe Mathieu-Daudé
2025-04-18  2:55   ` Pierrick Bouvier
2025-04-18  0:50 ` [RFC PATCH v2 02/11] qemu: Convert target_name() to TargetInfo API Philippe Mathieu-Daudé
2025-04-18  3:01   ` Pierrick Bouvier
2025-04-18 14:02     ` Philippe Mathieu-Daudé
2025-04-18 16:23       ` Pierrick Bouvier
2025-04-18 17:15         ` Philippe Mathieu-Daudé
2025-04-18  0:50 ` Philippe Mathieu-Daudé [this message]
2025-04-18  3:06   ` [RFC PATCH v2 03/11] system/vl: Filter machine list available for a particular target binary Pierrick Bouvier
2025-04-18 14:14     ` Philippe Mathieu-Daudé
2025-04-18  0:50 ` [RFC PATCH v2 04/11] hw/arm: Register TYPE_TARGET_ARM/AARCH64_CPU QOM interfaces Philippe Mathieu-Daudé
2025-04-18  3:07   ` Pierrick Bouvier
2025-04-18 14:07     ` Philippe Mathieu-Daudé
2025-04-18 16:30       ` Pierrick Bouvier
2025-04-18 17:04         ` Philippe Mathieu-Daudé
2025-04-18 17:07           ` Pierrick Bouvier
2025-04-18 17:10             ` Philippe Mathieu-Daudé
2025-04-18 17:23               ` Pierrick Bouvier
2025-04-18 17:32                 ` Philippe Mathieu-Daudé
2025-04-19  1:17                   ` Pierrick Bouvier
2025-04-18  0:50 ` [RFC PATCH v2 05/11] hw/arm: Filter machine types for qemu-system-aarch64 binary Philippe Mathieu-Daudé
2025-04-18  0:50 ` [RFC PATCH v2 06/11] hw/arm: Filter machine types for qemu-system-arm binary Philippe Mathieu-Daudé
2025-04-18  3:08   ` Pierrick Bouvier
2025-04-18  0:50 ` [RFC PATCH v2 07/11] hw/core: Allow ARM/Aarch64 binaries to use the 'none' machine Philippe Mathieu-Daudé
2025-04-18  3:32   ` Pierrick Bouvier
2025-04-18  0:50 ` [RFC PATCH v2 08/11] config/target: Implement per-binary TargetInfo structure (ARM) Philippe Mathieu-Daudé
2025-04-18  3:39   ` Pierrick Bouvier
2025-04-18  4:02   ` Pierrick Bouvier
2025-04-18 11:20     ` Philippe Mathieu-Daudé
2025-04-18  0:50 ` [RFC PATCH v2 09/11] config/target: Implement per-binary TargetInfo structure (Aarch64) Philippe Mathieu-Daudé
2025-04-18  3:34   ` Pierrick Bouvier
2025-04-18  0:50 ` [RFC PATCH v2 10/11] hw/arm/aspeed: Build objects once Philippe Mathieu-Daudé
2025-04-18  4:02   ` Pierrick Bouvier
2025-04-18  0:50 ` [RFC PATCH v2 11/11] hw/arm/raspi: " Philippe Mathieu-Daudé
2025-04-18  4:03   ` Pierrick Bouvier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250418005059.4436-4-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=anjo@rev.ng \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).