]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
qdev: Implement qdev_create_fake_machine() for user emulation
authorPhilippe Mathieu-Daudé <philmd@linaro.org>
Thu, 2 Jan 2025 13:50:19 +0000 (14:50 +0100)
committerPhilippe Mathieu-Daudé <philmd@linaro.org>
Thu, 9 Jan 2025 17:16:24 +0000 (18:16 +0100)
When a QDev instance is realized, qdev_get_machine() ends up called.
In the next commit, qdev_get_machine() will require a "machine"
container to be always present. To satisfy this QOM containers design,
Implement qdev_create_fake_machine() which creates a fake "machine"
container for user emulation.

On system emulation, qemu_create_machine() is called from qemu_init().
For user emulation, since the TCG accelerator always calls
tcg_init_machine(), we use it to hook our fake machine creation.

Suggested-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Acked-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250102211800.79235-2-philmd@linaro.org>

accel/tcg/tcg-all.c
hw/core/meson.build
hw/core/qdev-user.c [new file with mode: 0644]
include/hw/qdev-core.h

index c256575887676e0f59cc613939acdd4a6e3485df..95adaacee82adf9e568798ea59c06b92d8d41976 100644 (file)
@@ -35,7 +35,9 @@
 #include "qemu/atomic.h"
 #include "qapi/qapi-builtin-visit.h"
 #include "qemu/units.h"
-#if !defined(CONFIG_USER_ONLY)
+#if defined(CONFIG_USER_ONLY)
+#include "hw/qdev-core.h"
+#else
 #include "hw/boards.h"
 #endif
 #include "internal-common.h"
@@ -124,6 +126,10 @@ static int tcg_init_machine(MachineState *ms)
     tcg_prologue_init();
 #endif
 
+#ifdef CONFIG_USER_ONLY
+    qdev_create_fake_machine();
+#endif
+
     return 0;
 }
 
index ce9dfa3f4bf2cb2ede8405e6fd1afa686b141e18..65a1698ed1fbd25531899e0b568c8551bc0d33cb 100644 (file)
@@ -46,3 +46,4 @@ system_ss.add(files(
   'vm-change-state-handler.c',
   'clock-vmstate.c',
 ))
+user_ss.add(files('qdev-user.c'))
diff --git a/hw/core/qdev-user.c b/hw/core/qdev-user.c
new file mode 100644 (file)
index 0000000..3d421d8
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * QDev helpers specific to user emulation.
+ *
+ * Copyright 2025 Linaro, Ltd.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "qemu/osdep.h"
+#include "qom/object.h"
+#include "hw/qdev-core.h"
+
+void qdev_create_fake_machine(void)
+{
+    Object *fake_machine_obj;
+
+    fake_machine_obj = object_property_add_new_container(object_get_root(),
+                                                         "machine");
+    object_property_add_new_container(fake_machine_obj, "unattached");
+}
index c4d3dc39064cb5bc6b14bfc0027aa2e0cb78c8b3..50cbbf81211967dc1f453bf9e790087ffb934c3a 100644 (file)
@@ -1023,6 +1023,16 @@ const char *qdev_fw_name(DeviceState *dev);
 void qdev_assert_realized_properly(void);
 Object *qdev_get_machine(void);
 
+/**
+ * qdev_create_fake_machine(): Create a fake machine container.
+ *
+ * .. note::
+ *    This function is a kludge for user emulation (USER_ONLY)
+ *    because when thread (TYPE_CPU) are realized, qdev_realize()
+ *    access a machine container.
+ */
+void qdev_create_fake_machine(void);
+
 /**
  * qdev_get_human_name() - Return a human-readable name for a device
  * @dev: The device. Must be a valid and non-NULL pointer.