Commit c5d3937066 for qemu.org

commit c5d39370665efc6a6f4284a3450dd88461a6b6e0
Author: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Date:   Tue Sep 1 20:20:30 2026 +0000

    qom/object: add is_available callback to TypeInfo

    When removing target specific sections (#ifdef TARGET_X), we started
    exposing types for different targets in the same file.

    Previously, we implemented a filter based on interfaces, but it
    proved to be too cumbersome, requiring duplication across architectures.
    To simplify it, we add a new callback, is_available, to TypeInfo, that
    will replace the existing filtering mechanism.

    Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
    Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
    Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
    Tested-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
    Message-ID: <20260901202043.26532-2-pierrick.bouvier@oss.qualcomm.com>
    Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>

diff --git a/include/qom/object.h b/include/qom/object.h
index e24f0a2b2d..7ecd0f210f 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -469,6 +469,8 @@ struct Object
  * @class_data: Data to pass to the @class_init,
  *   @class_base_init. This can be useful when building dynamic
  *   classes.
+ * @is_available: callback invoked at registration time, to dynamically check if
+ *   this type should be available or not.
  * @interfaces: The list of interfaces associated with this type.  This
  *   should point to a static array that's terminated with a zero filled
  *   element.
@@ -491,6 +493,7 @@ struct TypeInfo
     void (*class_base_init)(ObjectClass *klass, const void *data);
     const void *class_data;

+    bool (*is_available)(void);
     const InterfaceInfo *interfaces;
 };

diff --git a/qom/object.c b/qom/object.c
index 85bbd7f9fe..b1834a57cc 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -163,6 +163,10 @@ static TypeImpl *type_register_internal(const TypeInfo *info)
         abort();
     }

+    if (info->is_available && !info->is_available()) {
+        return NULL;
+    }
+
     ti = type_new(info);

     type_table_add(ti);
diff --git a/rust/qom/src/qom.rs b/rust/qom/src/qom.rs
index cc00ddcfc9..bbb485e2cf 100644
--- a/rust/qom/src/qom.rs
+++ b/rust/qom/src/qom.rs
@@ -691,6 +691,7 @@ pub trait ObjectImpl: ObjectType + IsA<Object> {
         class_init: Some(rust_class_init::<Self>),
         class_base_init: Self::CLASS_BASE_INIT,
         class_data: core::ptr::null(),
+        is_available: None,
         interfaces: core::ptr::null(),
     };