@@ -12,6 +12,9 @@
#include "hw/boards.h"
#include "qapi/visitor.h"
+#include "hw/sysbus.h"
+#include "sysemu/sysemu.h"
+#include "qemu/error-report.h"
static char *machine_get_accel(Object *obj, Error **errp)
{
@@ -235,8 +238,42 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp)
ms->firmware = g_strdup(value);
}
+static int search_for_sysbus_device(Object *obj, void *opaque)
+{
+ if (!object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE)) {
+ /* Container or different device, traverse it for children */
+ return object_child_foreach(obj, search_for_sysbus_device, opaque);
+ }
+
+ error_report("Device '%s' can not be handled by this machine",
+ qdev_fw_name(DEVICE(obj)));
+ exit(1);
+}
+
+static void machine_init_notify(Notifier *notifier, void *data)
+{
+ Object *machine = qdev_get_machine();
+ Object *container;
+
+ if (object_property_find(machine, "has-dynamic-sysbus", NULL)) {
+ /* Our machine can handle dynamic sysbus devices, we're all good */
+ return;
+ }
+
+ /*
+ * Loop through all dynamically created devices and check whether there
+ * are sysbus devices among them. If there are, error out.
+ */
+ container = container_get(machine, "/peripheral");
+ search_for_sysbus_device(container, NULL);
+ container = container_get(machine, "/peripheral-anon");
+ search_for_sysbus_device(container, NULL);
+}
+
static void machine_initfn(Object *obj)
{
+ MachineState *ms = MACHINE(obj);
+
object_property_add_str(obj, "accel",
machine_get_accel, machine_set_accel, NULL);
object_property_add_bool(obj, "kernel_irqchip",
@@ -274,6 +311,10 @@ static void machine_initfn(Object *obj)
object_property_add_bool(obj, "usb", machine_get_usb, machine_set_usb, NULL);
object_property_add_str(obj, "firmware",
machine_get_firmware, machine_set_firmware, NULL);
+
+ /* Register notifier when init is done for sysbus sanity checks */
+ ms->sysbus_notifier.notify = machine_init_notify;
+ qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
}
static void machine_finalize(Object *obj)
@@ -326,13 +326,6 @@ static void sysbus_device_class_init(ObjectClass *klass, void *data)
DeviceClass *k = DEVICE_CLASS(klass);
k->init = sysbus_device_init;
k->bus_type = TYPE_SYSTEM_BUS;
- /*
- * device_add plugs devices into suitable bus. For "real" buses,
- * that actually connects the device. For sysbus, the connections
- * need to be made separately, and device_add can't do that. The
- * device would be left unconnected, and could not possibly work.
- */
- k->cannot_instantiate_with_device_add_yet = true;
}
static const TypeInfo sysbus_device_type_info = {
@@ -110,6 +110,8 @@ struct MachineClass {
struct MachineState {
/*< private >*/
Object parent_obj;
+ Notifier sysbus_notifier;
+
/*< public >*/
char *accel;
Now that we can properly map sysbus devices that haven't been connected to something forcefully by C code, we can allow the -device command line option to spawn them. For machines that don't implement dynamic sysbus assignment in their board files we add a new property "has-dynamic-sysbus" to the machine object. Without that property available, we bail out when we see dynamically spawned sysbus devices, like we did before. Signed-off-by: Alexander Graf <agraf@suse.de> --- hw/core/machine.c | 41 +++++++++++++++++++++++++++++++++++++++++ hw/core/sysbus.c | 7 ------- include/hw/boards.h | 2 ++ 3 files changed, 43 insertions(+), 7 deletions(-)