From: Philippe Mathieu-Daudé Date: Sat, 25 Jan 2025 13:36:42 +0000 (+0100) Subject: hw/sysbus: Introduce TYPE_DYNAMIC_SYS_BUS_DEVICE X-Git-Tag: v10.0.0-rc0~48^2~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=47dfd350fbf80bdfc7dcc102974fad328bf3e993;p=thirdparty%2Fqemu.git hw/sysbus: Introduce TYPE_DYNAMIC_SYS_BUS_DEVICE Some TYPE_SYS_BUS_DEVICEs can be optionally dynamically plugged on the TYPE_PLATFORM_BUS_DEVICE. Rather than sometimes noting that with comment around the 'user_creatable = true' line in each DeviceRealize handler, introduce an abstract TYPE_DYNAMIC_SYS_BUS_DEVICE class. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Reviewed-by: Alexander Graf Reviewed-by: Clément Mathieu--Drif Message-Id: <20250125181343.59151-4-philmd@linaro.org> --- diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c index 075c7dfd69..98819d5dc6 100644 --- a/hw/core/sysbus.c +++ b/hw/core/sysbus.c @@ -320,6 +320,14 @@ BusState *sysbus_get_default(void) return main_system_bus; } +static void dynamic_sysbus_device_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *k = DEVICE_CLASS(klass); + + k->user_creatable = true; + k->hotpluggable = false; +} + static const TypeInfo sysbus_types[] = { { .name = TYPE_SYSTEM_BUS, @@ -335,6 +343,12 @@ static const TypeInfo sysbus_types[] = { .class_size = sizeof(SysBusDeviceClass), .class_init = sysbus_device_class_init, }, + { + .name = TYPE_DYNAMIC_SYS_BUS_DEVICE, + .parent = TYPE_SYS_BUS_DEVICE, + .class_init = dynamic_sysbus_device_class_init, + .abstract = true, + } }; DEFINE_TYPES(sysbus_types) diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h index c9b1e0e90e..81bbda10d3 100644 --- a/include/hw/sysbus.h +++ b/include/hw/sysbus.h @@ -19,6 +19,8 @@ DECLARE_INSTANCE_CHECKER(BusState, SYSTEM_BUS, OBJECT_DECLARE_TYPE(SysBusDevice, SysBusDeviceClass, SYS_BUS_DEVICE) +#define TYPE_DYNAMIC_SYS_BUS_DEVICE "dynamic-sysbus-device" + /** * SysBusDeviceClass: *