Patchwork [RFC,v2,11/13] qdev: introduce automatic creation of buses

login
register
mail settings
Submitter Paolo Bonzini
Date June 6, 2011, 4:04 p.m.
Message ID <1307376262-1255-12-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/98964/
State New
Headers show

Comments

Paolo Bonzini - June 6, 2011, 4:04 p.m.
When a logical unit is hung directly below an HBA, we want to introduce
the "missing levels" to avoid duplicating generic target code across
all devices.  To do this, I introduce a callback in qdev that is given
the bus specified by the user, and returns the actual bus to use.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
---
 hw/qdev.c |   13 +++++++++++++
 hw/qdev.h |    3 +++
 2 files changed, 16 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index 9519f5d..847bcda 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -204,6 +204,17 @@  int qdev_device_help(QemuOpts *opts)
     return 1;
 }
 
+static BusState *qbus_realize_topology(BusState *bus, DeviceInfo *info,
+				       QemuOpts *opts)
+{
+    BusState *old = NULL;
+    while (old != bus && bus->info->realize_topology) {
+        old = bus;
+        bus = bus->info->realize_topology(bus, info, opts);
+    }
+    return bus;
+}
+
 DeviceState *qdev_device_add(QemuOpts *opts)
 {
     const char *driver, *path, *id;
@@ -245,6 +256,8 @@  DeviceState *qdev_device_add(QemuOpts *opts)
             return NULL;
         }
     }
+
+    bus = qbus_realize_topology(bus, info, opts);
     if (qdev_hotplug && !bus->allow_hotplug) {
         qerror_report(QERR_BUS_NO_HOTPLUG, bus->name);
         return NULL;
diff --git a/hw/qdev.h b/hw/qdev.h
index 8a13ec9..ae18406 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -56,6 +56,8 @@  typedef char *(*bus_get_dev_path)(DeviceState *dev);
  */
 typedef char *(*bus_get_fw_dev_path)(DeviceState *dev);
 typedef int (qbus_resetfn)(BusState *bus);
+typedef BusState *(*bus_realize_topology)(BusState *bus, DeviceInfo *dev,
+                                          QemuOpts *opts);
 
 struct BusInfo {
     const char *name;
@@ -63,6 +65,7 @@  struct BusInfo {
     bus_dev_printfn print_dev;
     bus_get_dev_path get_dev_path;
     bus_get_fw_dev_path get_fw_dev_path;
+    bus_realize_topology realize_topology;
     qbus_resetfn *reset;
     Property *props;
 };