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 v3 1/7] sysbus: Add dynamic sysbus device search
Date: Wed, 24 Sep 2014 17:22:17 +0200 [thread overview]
Message-ID: <1411572143-40345-2-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1411572143-40345-1-git-send-email-agraf@suse.de>
Sysbus devices can be spawned by C code or dynamically via the command line.
In the latter case, we need to be able to find the dynamically created devices
to do things with them.
This patch adds a search helper that makes it easy to look for dynamically
spawned sysbus devices.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
hw/core/sysbus.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
include/hw/sysbus.h | 5 +++++
2 files changed, 50 insertions(+)
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index e55c3c1..19437e6 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -24,6 +24,51 @@
static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
static char *sysbus_get_fw_dev_path(DeviceState *dev);
+typedef struct SysBusFind {
+ void *opaque;
+ FindSysbusDeviceFunc *func;
+} SysBusFind;
+
+/* Run func() for every sysbus device, traverse the tree for everything else */
+static int find_sysbus_device(Object *obj, void *opaque)
+{
+ SysBusFind *find = opaque;
+ Object *dev;
+ SysBusDevice *sbdev;
+
+ dev = object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE);
+ sbdev = (SysBusDevice *)dev;
+
+ if (!sbdev) {
+ /* Container, traverse it for children */
+ return object_child_foreach(obj, find_sysbus_device, opaque);
+ }
+
+ find->func(sbdev, find->opaque);
+
+ return 0;
+}
+
+/*
+ * Loop through all dynamically created sysbus devices and call
+ * func() for each instance.
+ */
+void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque)
+{
+ Object *container;
+ SysBusFind find = {
+ .func = func,
+ .opaque = opaque,
+ };
+
+ /* Loop through all sysbus devices that were spawened outside the machine */
+ container = container_get(qdev_get_machine(), "/peripheral");
+ find_sysbus_device(container, &find);
+ container = container_get(qdev_get_machine(), "/peripheral-anon");
+ find_sysbus_device(container, &find);
+}
+
+
static void system_bus_class_init(ObjectClass *klass, void *data)
{
BusClass *k = BUS_CLASS(klass);
diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h
index 470e2e5..6c618e6 100644
--- a/include/hw/sysbus.h
+++ b/include/hw/sysbus.h
@@ -58,6 +58,8 @@ struct SysBusDevice {
pio_addr_t pio[QDEV_MAX_PIO];
};
+typedef int FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
+
void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
@@ -73,6 +75,9 @@ void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
MemoryRegion *mem);
MemoryRegion *sysbus_address_space(SysBusDevice *dev);
+/* Call func for every dynamically created sysbus device in the system */
+void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque);
+
/* Legacy helper function for creating devices. */
DeviceState *sysbus_create_varargs(const char *name,
hwaddr addr, ...);
--
1.8.1.4
next prev parent reply other threads:[~2014-09-24 15:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-24 15:22 [Qemu-devel] [PATCH v3 0/7] Dynamic sysbus device allocation support Alexander Graf
2014-09-24 15:22 ` Alexander Graf [this message]
2014-09-24 15:22 ` [Qemu-devel] [PATCH v3 2/7] sysbus: Make devices spawnable via -device Alexander Graf
2014-09-24 15:37 ` Paolo Bonzini
2014-09-25 13:17 ` [Qemu-devel] [PATCH v4 " Alexander Graf
2014-09-24 15:22 ` [Qemu-devel] [PATCH v3 3/7] sysbus: Expose IRQ enumeration helpers Alexander Graf
2014-09-24 15:22 ` [Qemu-devel] [PATCH v3 4/7] sysbus: Expose MMIO enumeration helper Alexander Graf
2014-09-24 15:22 ` [Qemu-devel] [PATCH v3 5/7] sysbus: Add new platform bus helper device Alexander Graf
2014-09-26 12:05 ` Paolo Bonzini
2014-09-26 12:26 ` Alexander Graf
2014-09-26 12:44 ` Paolo Bonzini
2014-09-29 8:24 ` Alexander Graf
2014-09-29 8:30 ` Paolo Bonzini
2014-09-24 15:22 ` [Qemu-devel] [PATCH v3 6/7] PPC: e500: Support dynamically spawned sysbus devices Alexander Graf
2014-09-24 15:22 ` [Qemu-devel] [PATCH v3 7/7] e500: Add support for eTSEC in device tree Alexander Graf
2014-09-24 15:40 ` [Qemu-devel] [PATCH v3 0/7] Dynamic sysbus device allocation support Paolo Bonzini
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=1411572143-40345-2-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).