[PATCH] Plumbed previously ununsed defaults_enabled in vl.c, s.t. it provides the status of the '-nodefaults' flag to created machines

Patrick Eads posted 1 patch 4 days, 9 hours ago
.gitignore          |  2 ++
hw/core/machine.c   | 15 +++++++++++++++
hw/m68k/q800.c      | 15 ++++++++-------
include/hw/boards.h |  1 +
system/vl.c         |  2 +-
5 files changed, 27 insertions(+), 8 deletions(-)
[PATCH] Plumbed previously ununsed defaults_enabled in vl.c, s.t. it provides the status of the '-nodefaults' flag to created machines
Posted by Patrick Eads 4 days, 9 hours ago
From: Patrick Eads <patrick.eads@gmail.com>

Signed-off-by: Patrick Eads <patrick.eads@gmail.com>
---
 .gitignore          |  2 ++
 hw/core/machine.c   | 15 +++++++++++++++
 hw/m68k/q800.c      | 15 ++++++++-------
 include/hw/boards.h |  1 +
 system/vl.c         |  2 +-
 5 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore
index 61fa39967b..306799820c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,3 +20,5 @@ GTAGS
 *.swp
 *.patch
 *.gcov
+.idea
+buildDir
diff --git a/hw/core/machine.c b/hw/core/machine.c
index adaba17eba..5b133cc3f2 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -475,6 +475,16 @@ static void machine_set_usb(Object *obj, bool value, Error **errp)
     ms->usb_disabled = !value;
 }
 
+static bool machine_get_defaults(Object *obj, __attribute__((unused)) Error **errp) {
+    MachineState *ms = MACHINE(obj);
+    return ms->has_defaults;
+}
+
+static void machine_set_defaults(Object *obj, bool val, __attribute__((unused)) Error **errp) {
+    MachineState *ms = MACHINE(obj);
+    ms->has_defaults = val;
+}
+
 static bool machine_get_graphics(Object *obj, Error **errp)
 {
     MachineState *ms = MACHINE(obj);
@@ -1083,6 +1093,11 @@ static void machine_class_init(ObjectClass *oc, void *data)
     object_class_property_set_description(oc, "usb",
         "Set on/off to enable/disable usb");
 
+    object_class_property_add_bool(oc, "defaults",
+                                          machine_get_defaults, machine_set_defaults);
+    object_class_property_set_description(oc, "defaults",
+                                          "Set on/off to enable/disable hardware defaults");
+
     object_class_property_add_bool(oc, "graphics",
         machine_get_graphics, machine_set_graphics);
     object_class_property_set_description(oc, "graphics",
diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index 556604e1dc..63782315fe 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -262,13 +262,13 @@ static void q800_machine_init(MachineState *machine)
     const char *initrd_filename = machine->initrd_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *bios_name = machine->firmware ?: MACROM_FILENAME;
+    const bool has_defaults = m->parent_obj.has_defaults;
     hwaddr parameters_base;
     CPUState *cs;
     DeviceState *dev;
     SysBusESPState *sysbus_esp;
     ESPState *esp;
     SysBusDevice *sysbus;
-    BusState *adb_bus;
     NubusBus *nubus;
     DriveInfo *dinfo;
     NICInfo *nd;
@@ -354,12 +354,13 @@ static void q800_machine_init(MachineState *machine)
     qdev_connect_gpio_out(DEVICE(&m->via1), 0,
                           qdev_get_gpio_in_named(DEVICE(&m->glue),
                                                  "auxmode", 0));
-
-    adb_bus = qdev_get_child_bus(DEVICE(&m->via1), "adb.0");
-    dev = qdev_new(TYPE_ADB_KEYBOARD);
-    qdev_realize_and_unref(dev, adb_bus, &error_fatal);
-    dev = qdev_new(TYPE_ADB_MOUSE);
-    qdev_realize_and_unref(dev, adb_bus, &error_fatal);
+    if (has_defaults) {
+        BusState *adb_bus = qdev_get_child_bus(DEVICE(&m->via1), "adb.0");
+        dev = qdev_new(TYPE_ADB_KEYBOARD);
+        qdev_realize_and_unref(dev, adb_bus, &error_fatal);
+        dev = qdev_new(TYPE_ADB_MOUSE);
+        qdev_realize_and_unref(dev, adb_bus, &error_fatal);
+    }
 
     /* VIA 2 */
     object_initialize_child(OBJECT(machine), "via2", &m->via2,
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 5966069baa..6d0e22e73a 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -387,6 +387,7 @@ struct MachineState {
     bool mem_merge;
     bool usb;
     bool usb_disabled;
+    bool has_defaults;
     char *firmware;
     bool iommu;
     bool suppress_vmdesc;
diff --git a/system/vl.c b/system/vl.c
index e83b3b2608..e4f330f49b 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -2122,7 +2122,7 @@ static void qemu_create_machine(QDict *qdict)
     object_property_add_child(container_get(OBJECT(current_machine),
                                             "/unattached"),
                               "sysbus", OBJECT(sysbus_get_default()));
-
+    current_machine->has_defaults = defaults_enabled();
     if (machine_class->minimum_page_bits) {
         if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) {
             /* This would be a board error: specifying a minimum smaller than
-- 
2.45.2