From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:54844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTcIp-000635-Mx for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:05:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QTcIo-0000QT-5G for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:05:19 -0400 Received: from mail-px0-f174.google.com ([209.85.212.174]:49894) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTcIn-0000F3-7g for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:05:17 -0400 Received: by mail-px0-f174.google.com with SMTP id 15so947212pxi.33 for ; Mon, 06 Jun 2011 09:05:16 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 6 Jun 2011 18:04:20 +0200 Message-Id: <1307376262-1255-12-git-send-email-pbonzini@redhat.com> In-Reply-To: <1307376262-1255-1-git-send-email-pbonzini@redhat.com> References: <1307376262-1255-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [RFC PATCH v2 11/13] qdev: introduce automatic creation of buses List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Markus Armbruster 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 Cc: Markus Armbruster --- hw/qdev.c | 13 +++++++++++++ hw/qdev.h | 3 +++ 2 files changed, 16 insertions(+), 0 deletions(-) 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; }; -- 1.7.4.4