From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: Eduardo Habkost <ehabkost@redhat.com>,
Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
Greg Kurz <groug@kaod.org>,
qemu-ppc@nongnu.org, Igor Mammedov <imammedo@redhat.com>,
David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH for-6.0 2/4] machine: Provide a function to check the dynamic sysbus whitelist
Date: Thu, 25 Mar 2021 15:33:08 +0000 [thread overview]
Message-ID: <20210325153310.9131-3-peter.maydell@linaro.org> (raw)
In-Reply-To: <20210325153310.9131-1-peter.maydell@linaro.org>
Provide a new function dynamic_sysbus_dev_allowed() which checks
the per-machine whitelist of dynamic sysbus devices and returns
a boolean result indicating whether the device is whitelisted.
We can use this in the implementation of validate_sysbus_device(),
but we will also need it so that machine hotplug callbacks can
validate devices rather than assuming that any sysbus device
might be hotpluggable into the platform bus.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/hw/boards.h | 24 ++++++++++++++++++++++++
hw/core/machine.c | 21 ++++++++++++++++-----
2 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 27106abc11d..609112a4e1a 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -51,6 +51,30 @@ void machine_set_cpu_numa_node(MachineState *machine,
*/
void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type);
+/**
+ * device_is_dynamic_sysbus: test whether device is a dynamic sysbus device
+ * @mc: Machine class
+ * @dev: device to check
+ *
+ * Returns: true if @dev is a sysbus device on the machine's whitelist
+ * of dynamically pluggable sysbus devices; otherwise false.
+ *
+ * This function checks whether @dev is a valid dynamic sysbus device,
+ * by first confirming that it is a sysbus device and then checking it
+ * against the whitelist of permitted dynamic sysbus devices which has
+ * been set up by the machine using machine_class_allow_dynamic_sysbus_dev().
+ *
+ * It is valid to call this with something that is not a subclass of
+ * TYPE_SYS_BUS_DEVICE; the function will return false in this case.
+ * This allows hotplug callback functions to be written as:
+ * if (device_is_dynamic_sysbus(mc, dev)) {
+ * handle dynamic sysbus case;
+ * } else if (some other kind of hotplug) {
+ * handle that;
+ * }
+ */
+bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev);
+
/*
* Checks that backend isn't used, preps it for exclusive usage and
* returns migratable MemoryRegion provided by backend.
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 9935c6ddd56..8d97094736a 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -529,20 +529,31 @@ void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)
QAPI_LIST_PREPEND(mc->allowed_dynamic_sysbus_devices, g_strdup(type));
}
-static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque)
+bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev)
{
- MachineState *machine = opaque;
- MachineClass *mc = MACHINE_GET_CLASS(machine);
bool allowed = false;
strList *wl;
+ Object *obj = OBJECT(dev);
+
+ if (!object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE)) {
+ return false;
+ }
for (wl = mc->allowed_dynamic_sysbus_devices;
!allowed && wl;
wl = wl->next) {
- allowed |= !!object_dynamic_cast(OBJECT(sbdev), wl->value);
+ allowed |= !!object_dynamic_cast(obj, wl->value);
}
- if (!allowed) {
+ return allowed;
+}
+
+static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque)
+{
+ MachineState *machine = opaque;
+ MachineClass *mc = MACHINE_GET_CLASS(machine);
+
+ if (!device_is_dynamic_sysbus(mc, DEVICE(sbdev))) {
error_report("Option '-device %s' cannot be handled by this machine",
object_class_get_name(object_get_class(OBJECT(sbdev))));
exit(1);
--
2.20.1
next prev parent reply other threads:[~2021-03-25 15:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-25 15:33 [PATCH for-6.0 0/4] Don't treat all sysbus devices as hotpluggable Peter Maydell
2021-03-25 15:33 ` [PATCH for-6.0 1/4] include/hw/boards.h: Document machine_class_allow_dynamic_sysbus_dev() Peter Maydell
2021-03-26 9:27 ` Auger Eric
2021-03-26 10:20 ` Peter Maydell
2021-03-26 10:26 ` Auger Eric
2021-03-25 15:33 ` Peter Maydell [this message]
2021-03-26 9:35 ` [PATCH for-6.0 2/4] machine: Provide a function to check the dynamic sysbus whitelist Auger Eric
2021-03-25 15:33 ` [PATCH for-6.0 3/4] hw/arm/virt: Only try to add valid dynamic sysbus devices to platform bus Peter Maydell
2021-03-26 9:38 ` Auger Eric
2021-03-25 15:33 ` [PATCH for-6.0 4/4] hw/ppc/e500plat: " Peter Maydell
2021-03-25 22:48 ` David Gibson
2021-03-26 9:39 ` Auger Eric
2021-03-25 17:23 ` [PATCH for-6.0 0/4] Don't treat all sysbus devices as hotpluggable Richard Henderson
2021-03-25 20:51 ` Mark Cave-Ayland
2021-04-04 16:20 ` Peter Maydell
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=20210325153310.9131-3-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=david@gibson.dropbear.id.au \
--cc=ehabkost@redhat.com \
--cc=groug@kaod.org \
--cc=imammedo@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@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 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).