qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: qemu-ppc@nongnu.org
Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com,
	eric.auger@linaro.org, qemu-devel@nongnu.org,
	sean.stalley@intel.com, pbonzini@redhat.com, afaerber@suse.de
Subject: [Qemu-devel] [PATCH v2 6/9] sysbus: Make devices spawnable via -device
Date: Wed,  2 Jul 2014 20:01:30 +0200	[thread overview]
Message-ID: <1404324093-19225-7-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1404324093-19225-1-git-send-email-agraf@suse.de>

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 bool "has_dynamic_sysbus" to the machine class.
When that property is false (default), we bail out when we see dynamically
spawned sysbus devices, like we did before.

Signed-off-by: Alexander Graf <agraf@suse.de>

---

v1 -> v2:

  - use bool in MachineClass rather than property
---
 hw/core/machine.c   | 43 +++++++++++++++++++++++++++++++++++++++++++
 hw/core/sysbus.c    |  7 -------
 include/hw/boards.h |  8 ++++++--
 vl.c                |  1 +
 4 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index c25cc07..713c9d8 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -13,6 +13,9 @@
 #include "hw/boards.h"
 #include "qapi/visitor.h"
 #include "qom/property.h"
+#include "hw/sysbus.h"
+#include "sysemu/sysemu.h"
+#include "qemu/error-report.h"
 
 static char *machine_get_accel(Object *obj, Error **errp)
 {
@@ -236,8 +239,44 @@ 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();
+    ObjectClass *oc = object_get_class(machine);
+    MachineClass *mc = MACHINE_CLASS(oc);
+    Object *container;
+
+    if (mc->has_dynamic_sysbus) {
+        /* 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",
@@ -275,6 +314,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)
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index e551e16..aacc446 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -294,13 +294,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 = {
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 605a970..9514c62 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -35,7 +35,8 @@ struct QEMUMachine {
         use_sclp:1,
         no_floppy:1,
         no_cdrom:1,
-        no_sdcard:1;
+        no_sdcard:1,
+        has_dynamic_sysbus:1;
     int is_default;
     const char *default_machine_opts;
     const char *default_boot_order;
@@ -93,7 +94,8 @@ struct MachineClass {
         use_sclp:1,
         no_floppy:1,
         no_cdrom:1,
-        no_sdcard:1;
+        no_sdcard:1,
+        has_dynamic_sysbus:1;
     int is_default;
     const char *default_machine_opts;
     const char *default_boot_order;
@@ -110,6 +112,8 @@ struct MachineClass {
 struct MachineState {
     /*< private >*/
     Object parent_obj;
+    Notifier sysbus_notifier;
+
     /*< public >*/
 
     char *accel;
diff --git a/vl.c b/vl.c
index 6e084c2..1df8d4e 100644
--- a/vl.c
+++ b/vl.c
@@ -1569,6 +1569,7 @@ static void machine_class_init(ObjectClass *oc, void *data)
     mc->no_floppy = qm->no_floppy;
     mc->no_cdrom = qm->no_cdrom;
     mc->no_sdcard = qm->no_sdcard;
+    mc->has_dynamic_sysbus = qm->has_dynamic_sysbus;
     mc->is_default = qm->is_default;
     mc->default_machine_opts = qm->default_machine_opts;
     mc->default_boot_order = qm->default_boot_order;
-- 
1.8.1.4

  parent reply	other threads:[~2014-07-02 18:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-02 18:01 [Qemu-devel] [PATCH v2 0/9] Dynamic sysbus device allocation support Alexander Graf
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 1/9] qom: Move property helpers to own file Alexander Graf
2014-07-31 13:46   ` Peter Crosthwaite
2014-07-31 14:12     ` Alexander Graf
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 2/9] qom: macroify integer property helpers Alexander Graf
2014-07-31 13:44   ` Peter Crosthwaite
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 3/9] qom: Expose property helpers for get/set of integers Alexander Graf
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 4/9] qom: Add generic object property g_free helper Alexander Graf
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 5/9] sysbus: Add user map hints Alexander Graf
2014-07-02 18:01 ` Alexander Graf [this message]
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 7/9] PPC: e500: Support dynamically spawned sysbus devices Alexander Graf
2014-07-30 14:55   ` Peter Maydell
2014-07-31  4:07     ` Peter Crosthwaite
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 8/9] e500: Add support for eTSEC in device tree Alexander Graf
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 9/9] PPC: Fix default config ordering and add eTSEC for ppc64 Alexander Graf

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=1404324093-19225-7-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=afaerber@suse.de \
    --cc=eric.auger@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=sean.stalley@intel.com \
    /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).