Hyper-V VMBus logically belongs to the machine, so make its presence be controlled by a boolean property of the machine.
TODO: consider doing this through adding the vmbus-bridge device instead Signed-off-by: Roman Kagan <rka...@virtuozzo.com> --- include/hw/i386/pc.h | 3 +++ hw/i386/pc.c | 34 ++++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 5 +++++ hw/i386/pc_q35.c | 5 +++++ util/qemu-config.c | 4 ++++ 5 files changed, 51 insertions(+) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 744f6a20d2..62b67cd927 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -46,6 +46,7 @@ struct PCMachineState { uint64_t max_ram_below_4g; OnOffAuto vmport; OnOffAuto smm; + bool vmbus; AcpiNVDIMMState acpi_nvdimm_state; @@ -80,6 +81,7 @@ struct PCMachineState { #define PC_MACHINE_SMBUS "smbus" #define PC_MACHINE_SATA "sata" #define PC_MACHINE_PIT "pit" +#define PC_MACHINE_VMBUS "vmbus" /** * PCMachineClass: @@ -209,6 +211,7 @@ void i8042_setup_a20_line(ISADevice *dev, qemu_irq a20_out); extern int fd_bootchk; bool pc_machine_is_smm_enabled(PCMachineState *pcms); +bool pc_machine_is_vmbus_enabled(PCMachineState *pcms); void pc_register_ferr_irq(qemu_irq irq); void pc_acpi_smi_interrupt(void *opaque, int irq, int level); diff --git a/hw/i386/pc.c b/hw/i386/pc.c index ccc50baa85..d37072b575 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2178,6 +2178,34 @@ static void pc_machine_set_smm(Object *obj, Visitor *v, const char *name, visit_type_OnOffAuto(v, name, &pcms->smm, errp); } +bool pc_machine_is_vmbus_enabled(PCMachineState *pcms) +{ + if (!pcms->vmbus) { + return false; + } + + if (!kvm_enabled()) { + error_report("VMBus requires KVM"); + exit(1); + } + + return true; +} + +static bool pc_machine_get_vmbus(Object *obj, Error **errp) +{ + PCMachineState *pcms = PC_MACHINE(obj); + + return pcms->vmbus; +} + +static void pc_machine_set_vmbus(Object *obj, bool vmbus, Error **errp) +{ + PCMachineState *pcms = PC_MACHINE(obj); + + pcms->vmbus = vmbus; +} + static bool pc_machine_get_nvdimm(Object *obj, Error **errp) { PCMachineState *pcms = PC_MACHINE(obj); @@ -2413,6 +2441,12 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) object_class_property_add_bool(oc, PC_MACHINE_PIT, pc_machine_get_pit, pc_machine_set_pit, &error_abort); + + /* no vmbus by default */ + object_class_property_add_bool(oc, PC_MACHINE_VMBUS, + pc_machine_get_vmbus, pc_machine_set_vmbus, &error_abort); + object_class_property_set_description(oc, PC_MACHINE_VMBUS, + "Enable Hyper-V VMBus", &error_abort); } static const TypeInfo pc_machine_info = { diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index a25619dfbf..4a3cb406d5 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -56,6 +56,7 @@ #include "migration/misc.h" #include "kvm_i386.h" #include "sysemu/numa.h" +#include "hw/vmbus/vmbus.h" #define MAX_IDE_BUS 2 @@ -302,6 +303,10 @@ static void pc_init1(MachineState *machine, nvdimm_init_acpi_state(&pcms->acpi_nvdimm_state, system_io, pcms->fw_cfg, OBJECT(pcms)); } + + if (pc_machine_is_vmbus_enabled(pcms)) { + vmbus_create(); + } } /* Looking for a pc_compat_2_4() function? It doesn't exist. diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index ed3a0b8ff7..9e5ce429b4 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -50,6 +50,7 @@ #include "hw/usb.h" #include "qemu/error-report.h" #include "sysemu/numa.h" +#include "hw/vmbus/vmbus.h" /* ICH9 AHCI has 6 ports */ #define MAX_SATA_PORTS 6 @@ -279,6 +280,10 @@ static void pc_q35_init(MachineState *machine) nvdimm_init_acpi_state(&pcms->acpi_nvdimm_state, system_io, pcms->fw_cfg, OBJECT(pcms)); } + + if (pc_machine_is_vmbus_enabled(pcms)) { + vmbus_create(); + } } #define DEFINE_Q35_MACHINE(suffix, name, compatfn, optionfn) \ diff --git a/util/qemu-config.c b/util/qemu-config.c index 029fec53a9..951a6360a0 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -234,6 +234,10 @@ static QemuOptsList machine_opts = { .help = "Up to 8 chars in set of [A-Za-z0-9. ](lower case chars" " converted to upper case) to pass to machine" " loader, boot manager, and guest kernel", + },{ + .name = "vmbus", + .type = QEMU_OPT_BOOL, + .help = "enable Hyper-V VMBus", }, { /* End of list */ } } -- 2.14.3