aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorXiaojuan Yang <yangxiaojuan@loongson.cn>2022-08-10 16:37:21 +0800
committerSong Gao <gaosong@loongson.cn>2022-09-20 15:44:24 +0800
commite27e535768129834cf6debed4575a161f7013dda (patch)
tree69a89642339d132e8b0bc0eff0c4e1024d3bd1ab /hw
parenta1f7d78e564a453ea07159efaa1af9a7210ddeda (diff)
hw/loongarch: Add hotplug handler for machine
Add hotplug handler for LoongArch virt machine and now only support the dynamic sysbus device. Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> Acked-by: Song Gao <gaosong@loongson.cn> Message-Id: <20220908094623.73051-6-yangxiaojuan@loongson.cn> Signed-off-by: Song Gao <gaosong@loongson.cn>
Diffstat (limited to 'hw')
-rw-r--r--hw/loongarch/virt.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 5fd3834c0a..eedff10758 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -803,9 +803,35 @@ static void loongarch_machine_initfn(Object *obj)
lams->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8);
}
+static void loongarch_machine_device_plug_cb(HotplugHandler *hotplug_dev,
+ DeviceState *dev, Error **errp)
+{
+ LoongArchMachineState *lams = LOONGARCH_MACHINE(hotplug_dev);
+ MachineClass *mc = MACHINE_GET_CLASS(lams);
+
+ if (device_is_dynamic_sysbus(mc, dev)) {
+ if (lams->platform_bus_dev) {
+ platform_bus_link_device(PLATFORM_BUS_DEVICE(lams->platform_bus_dev),
+ SYS_BUS_DEVICE(dev));
+ }
+ }
+}
+
+static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine,
+ DeviceState *dev)
+{
+ MachineClass *mc = MACHINE_GET_CLASS(machine);
+
+ if (device_is_dynamic_sysbus(mc, dev)) {
+ return HOTPLUG_HANDLER(machine);
+ }
+ return NULL;
+}
+
static void loongarch_class_init(ObjectClass *oc, void *data)
{
MachineClass *mc = MACHINE_CLASS(oc);
+ HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
mc->desc = "Loongson-3A5000 LS7A1000 machine";
mc->init = loongarch_init;
@@ -818,6 +844,8 @@ static void loongarch_class_init(ObjectClass *oc, void *data)
mc->block_default_type = IF_VIRTIO;
mc->default_boot_order = "c";
mc->no_cdrom = 1;
+ mc->get_hotplug_handler = virt_machine_get_hotplug_handler;
+ hc->plug = loongarch_machine_device_plug_cb;
object_class_property_add(oc, "acpi", "OnOffAuto",
loongarch_get_acpi, loongarch_set_acpi,
@@ -833,6 +861,10 @@ static const TypeInfo loongarch_machine_types[] = {
.instance_size = sizeof(LoongArchMachineState),
.class_init = loongarch_class_init,
.instance_init = loongarch_machine_initfn,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_HOTPLUG_HANDLER },
+ { }
+ },
}
};