mirror of https://github.com/xemu-project/xemu.git
hw/riscv: virt: Add device plug support
Add support for plugging in devices, this was tested with the TPM device. Signed-off-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Message-Id: <20220427234146.1130752-6-alistair.francis@opensource.wdc.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
This commit is contained in:
parent
3029fab643
commit
58d5a5a78c
|
@ -1569,10 +1569,37 @@ static void virt_set_aclint(Object *obj, bool value, Error **errp)
|
|||
s->have_aclint = value;
|
||||
}
|
||||
|
||||
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 virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,
|
||||
DeviceState *dev, Error **errp)
|
||||
{
|
||||
RISCVVirtState *s = RISCV_VIRT_MACHINE(hotplug_dev);
|
||||
|
||||
if (s->platform_bus_dev) {
|
||||
MachineClass *mc = MACHINE_GET_CLASS(s);
|
||||
|
||||
if (device_is_dynamic_sysbus(mc, dev)) {
|
||||
platform_bus_link_device(PLATFORM_BUS_DEVICE(s->platform_bus_dev),
|
||||
SYS_BUS_DEVICE(dev));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void virt_machine_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
char str[128];
|
||||
MachineClass *mc = MACHINE_CLASS(oc);
|
||||
HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
|
||||
|
||||
mc->desc = "RISC-V VirtIO board";
|
||||
mc->init = virt_machine_init;
|
||||
|
@ -1584,6 +1611,10 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
|
|||
mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id;
|
||||
mc->numa_mem_supported = true;
|
||||
mc->default_ram_id = "riscv_virt_board.ram";
|
||||
assert(!mc->get_hotplug_handler);
|
||||
mc->get_hotplug_handler = virt_machine_get_hotplug_handler;
|
||||
|
||||
hc->plug = virt_machine_device_plug_cb;
|
||||
|
||||
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE);
|
||||
|
||||
|
@ -1614,6 +1645,10 @@ static const TypeInfo virt_machine_typeinfo = {
|
|||
.class_init = virt_machine_class_init,
|
||||
.instance_init = virt_machine_instance_init,
|
||||
.instance_size = sizeof(RISCVVirtState),
|
||||
.interfaces = (InterfaceInfo[]) {
|
||||
{ TYPE_HOTPLUG_HANDLER },
|
||||
{ }
|
||||
},
|
||||
};
|
||||
|
||||
static void virt_machine_init_register_types(void)
|
||||
|
|
Loading…
Reference in New Issue