aboutsummaryrefslogtreecommitdiff
path: root/hw/core/machine.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2021-03-25 15:33:08 +0000
committerPeter Maydell <peter.maydell@linaro.org>2021-04-06 11:49:14 +0100
commit0fb124dbfa135945fb892d0d2b7a427cdc59220d (patch)
treea15eeb324467b89df7b34a5a405076c04a0d6b78 /hw/core/machine.c
parent387c0e8b41ac30ea0791bbd12fefcfc7ea93a436 (diff)
downloadqemu-0fb124dbfa135945fb892d0d2b7a427cdc59220d.zip
qemu-0fb124dbfa135945fb892d0d2b7a427cdc59220d.tar.gz
qemu-0fb124dbfa135945fb892d0d2b7a427cdc59220d.tar.bz2
machine: Provide a function to check the dynamic sysbus allowlist
Provide a new function dynamic_sysbus_dev_allowed() which checks the per-machine list of permitted dynamic sysbus devices and returns a boolean result indicating whether the device is allowed. 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> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Reviewed-by: Eric Auger <eric.auger@redhat.com> Message-id: 20210325153310.9131-3-peter.maydell@linaro.org
Diffstat (limited to 'hw/core/machine.c')
-rw-r--r--hw/core/machine.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 9935c6d..8d97094 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);