From: Eduardo Habkost <ehabkost@redhat.com>
To: Eric Blake <eblake@redhat.com>,
qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Marcel Apfelbaum <marcel@redhat.com>,
Laine Stump <laine@redhat.com>
Subject: [Qemu-devel] [RFC v4 06/13] qdev core: generic enumerate_slots implementation
Date: Mon, 14 Aug 2017 18:57:41 -0300 [thread overview]
Message-ID: <20170814215748.5158-7-ehabkost@redhat.com> (raw)
In-Reply-To: <20170814215748.5158-1-ehabkost@redhat.com>
Implement a generic enumerate_slots method on TYPE_BUS
The generic implementation will just report a opts-complete=false
entry, listing the "bus" option. This will let clients know that
the bus is available, but that detailed slot information is not
available by the running QEMU version.
We disable the implementation on TYPE_SYS_BUS as sysbus is an
exceptional case where only a handful of device types are
actually user-creatable. This will be handled later by
sysbus-specific slot enumeration code.
TODO: write sysbus-specific slot enumeration code, based on
sysbus device whitelist.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
hw/core/bus.c | 42 ++++++++++++++++++++++++++++++++++++++++++
hw/core/sysbus.c | 7 +++++++
2 files changed, 49 insertions(+)
diff --git a/hw/core/bus.c b/hw/core/bus.c
index 4651f24..227c092 100644
--- a/hw/core/bus.c
+++ b/hw/core/bus.c
@@ -20,6 +20,7 @@
#include "qemu/osdep.h"
#include "qemu-common.h"
#include "hw/qdev.h"
+#include "hw/qdev-slotinfo.h"
#include "qapi/error.h"
static void qbus_set_hotplug_handler_internal(BusState *bus, Object *handler,
@@ -208,12 +209,53 @@ static char *default_bus_get_fw_dev_path(DeviceState *dev)
return g_strdup(object_get_typename(OBJECT(dev)));
}
+static void class_check_user_creatable(ObjectClass *oc, void *opaque)
+{
+ DeviceClass *dc = DEVICE_CLASS(oc);
+ bool *r = opaque;
+
+ if (dc->user_creatable) {
+ *r = true;
+ }
+}
+
+static bool bus_class_is_user_pluggable(BusClass *bc)
+{
+ bool r = false;
+
+ object_class_foreach(class_check_user_creatable,
+ bc->device_type, false, &r);
+ return r;
+}
+
+static DeviceSlotInfoList *bus_generic_enumerate_slots(BusState *bus)
+{
+ DeviceSlotInfoList *r = NULL;
+ BusChild *kid = NULL;
+
+ if (!bus_class_is_user_pluggable(BUS_GET_CLASS(bus))) {
+ return NULL;
+ }
+
+ QTAILQ_FOREACH(kid, &bus->children, sibling) {
+ DeviceSlotInfo *slot = make_slot(bus);
+ slot->available = false;
+ slot->has_device = true;
+ slot->device = object_get_canonical_path(OBJECT(kid->child));
+ slot_list_add_slot(&r, slot);
+ }
+
+ slot_list_add_slot(&r, make_slot(bus));
+ return r;
+}
+
static void bus_class_init(ObjectClass *class, void *data)
{
BusClass *bc = BUS_CLASS(class);
class->unparent = bus_unparent;
bc->get_fw_dev_path = default_bus_get_fw_dev_path;
+ bc->enumerate_slots = bus_generic_enumerate_slots;
}
static void qbus_finalize(Object *obj)
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 9259931..06cb4d8 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -77,6 +77,13 @@ static void system_bus_class_init(ObjectClass *klass, void *data)
k->print_dev = sysbus_dev_print;
k->get_fw_dev_path = sysbus_get_fw_dev_path;
k->device_type = TYPE_SYS_BUS_DEVICE;
+ /*
+ * We won't return sysbus devices on query-device-slots by now.
+ *
+ * TODO: return user-creatable whitelisted sybus devices
+ * if the machine supports dynamic sysbus devices.
+ */
+ k->enumerate_slots = NULL;
}
static const TypeInfo system_bus_info = {
--
2.9.4
next prev parent reply other threads:[~2017-08-14 21:59 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-14 21:57 [Qemu-devel] [RFC v4 00/13] qmp: query-device-slots command Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 01/13] qmp: Define " Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 02/13] qapi: qobject_compare() helper Eduardo Habkost
2017-08-15 16:16 ` Eric Blake
2017-08-15 17:59 ` Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 03/13] qdev: Add BusClass::device_type field Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 04/13] qdev: Slot info helpers Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 05/13] query-device-slots: Collapse similar entries Eduardo Habkost
2017-08-14 21:57 ` Eduardo Habkost [this message]
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 07/13] qdev: Enumerate CPU slots on query-device-slots Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 08/13] ide: enumerate_slots implementation Eduardo Habkost
2017-08-16 21:46 ` John Snow
2017-08-17 4:54 ` Markus Armbruster
2017-08-17 18:40 ` John Snow
2017-08-18 16:57 ` Eduardo Habkost
2017-08-21 21:46 ` John Snow
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 09/13] pci: pci_bus_has_pcie_upstream_port() function Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 10/13] pci: device-number & function properties Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 11/13] pci: enumerate_slots implementation Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 12/13] usb: " Eduardo Habkost
2017-08-21 11:44 ` Gerd Hoffmann
2017-08-23 17:17 ` Eduardo Habkost
2017-08-14 21:57 ` [Qemu-devel] [RFC v4 13/13] tests: Experimental query-device-slots test code Eduardo Habkost
2017-08-14 22:37 ` [Qemu-devel] [libvirt] [RFC v4 00/13] qmp: query-device-slots command no-reply
2017-08-15 18:57 ` [Qemu-devel] " Eric Blake
2017-08-15 19:44 ` Eduardo Habkost
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=20170814215748.5158-7-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=laine@redhat.com \
--cc=marcel@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.