10ebf007dSSergio Lopez /* 20ebf007dSSergio Lopez * Copyright (c) 2018 Intel Corporation 30ebf007dSSergio Lopez * Copyright (c) 2019 Red Hat, Inc. 40ebf007dSSergio Lopez * 50ebf007dSSergio Lopez * This program is free software; you can redistribute it and/or modify it 60ebf007dSSergio Lopez * under the terms and conditions of the GNU General Public License, 70ebf007dSSergio Lopez * version 2 or later, as published by the Free Software Foundation. 80ebf007dSSergio Lopez * 90ebf007dSSergio Lopez * This program is distributed in the hope it will be useful, but WITHOUT 100ebf007dSSergio Lopez * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 110ebf007dSSergio Lopez * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 120ebf007dSSergio Lopez * more details. 130ebf007dSSergio Lopez * 140ebf007dSSergio Lopez * You should have received a copy of the GNU General Public License along with 150ebf007dSSergio Lopez * this program. If not, see <http://www.gnu.org/licenses/>. 160ebf007dSSergio Lopez */ 170ebf007dSSergio Lopez 180ebf007dSSergio Lopez #include "qemu/osdep.h" 190ebf007dSSergio Lopez #include "qemu/error-report.h" 200ebf007dSSergio Lopez #include "qemu/cutils.h" 210ebf007dSSergio Lopez #include "qemu/units.h" 220ebf007dSSergio Lopez #include "qapi/error.h" 230ebf007dSSergio Lopez #include "qapi/visitor.h" 240ebf007dSSergio Lopez #include "qapi/qapi-visit-common.h" 250ebf007dSSergio Lopez #include "sysemu/sysemu.h" 260ebf007dSSergio Lopez #include "sysemu/cpus.h" 270ebf007dSSergio Lopez #include "sysemu/numa.h" 280ebf007dSSergio Lopez #include "sysemu/reset.h" 298045df14SGerd Hoffmann #include "sysemu/runstate.h" 308045df14SGerd Hoffmann #include "acpi-microvm.h" 31f5918a99SGerd Hoffmann #include "microvm-dt.h" 320ebf007dSSergio Lopez 330ebf007dSSergio Lopez #include "hw/loader.h" 340ebf007dSSergio Lopez #include "hw/irq.h" 35a09ef8ffSPhilippe Mathieu-Daudé #include "hw/i386/kvm/clock.h" 360ebf007dSSergio Lopez #include "hw/i386/microvm.h" 370ebf007dSSergio Lopez #include "hw/i386/x86.h" 380ebf007dSSergio Lopez #include "target/i386/cpu.h" 39852c27e2SPaolo Bonzini #include "hw/intc/i8259.h" 400ebf007dSSergio Lopez #include "hw/timer/i8254.h" 41673652a7SPaolo Bonzini #include "hw/rtc/mc146818rtc.h" 420ebf007dSSergio Lopez #include "hw/char/serial.h" 4363bcfe7bSGerd Hoffmann #include "hw/display/ramfb.h" 440ebf007dSSergio Lopez #include "hw/i386/topology.h" 450ebf007dSSergio Lopez #include "hw/i386/e820_memory_layout.h" 460ebf007dSSergio Lopez #include "hw/i386/fw_cfg.h" 470ebf007dSSergio Lopez #include "hw/virtio/virtio-mmio.h" 488045df14SGerd Hoffmann #include "hw/acpi/acpi.h" 498045df14SGerd Hoffmann #include "hw/acpi/generic_event_device.h" 5024db877aSGerd Hoffmann #include "hw/pci-host/gpex.h" 51d4a42e85SGerd Hoffmann #include "hw/usb/xhci.h" 520ebf007dSSergio Lopez 530ebf007dSSergio Lopez #include "elf.h" 54a9dc68d9SClaudio Fontana #include "kvm/kvm_i386.h" 550ebf007dSSergio Lopez #include "hw/xen/start_info.h" 560ebf007dSSergio Lopez 573bee1d1dSGerd Hoffmann #define MICROVM_QBOOT_FILENAME "qboot.rom" 5867eb6a40SGerd Hoffmann #define MICROVM_BIOS_FILENAME "bios-microvm.bin" 590ebf007dSSergio Lopez 6055c86cb8SPhilippe Mathieu-Daudé static void microvm_set_rtc(MicrovmMachineState *mms, MC146818RtcState *s) 610ebf007dSSergio Lopez { 620ebf007dSSergio Lopez X86MachineState *x86ms = X86_MACHINE(mms); 630ebf007dSSergio Lopez int val; 640ebf007dSSergio Lopez 650ebf007dSSergio Lopez val = MIN(x86ms->below_4g_mem_size / KiB, 640); 662d4bd81eSPhilippe Mathieu-Daudé mc146818rtc_set_cmos_data(s, 0x15, val); 672d4bd81eSPhilippe Mathieu-Daudé mc146818rtc_set_cmos_data(s, 0x16, val >> 8); 680ebf007dSSergio Lopez /* extended memory (next 64MiB) */ 690ebf007dSSergio Lopez if (x86ms->below_4g_mem_size > 1 * MiB) { 700ebf007dSSergio Lopez val = (x86ms->below_4g_mem_size - 1 * MiB) / KiB; 710ebf007dSSergio Lopez } else { 720ebf007dSSergio Lopez val = 0; 730ebf007dSSergio Lopez } 740ebf007dSSergio Lopez if (val > 65535) { 750ebf007dSSergio Lopez val = 65535; 760ebf007dSSergio Lopez } 772d4bd81eSPhilippe Mathieu-Daudé mc146818rtc_set_cmos_data(s, 0x17, val); 782d4bd81eSPhilippe Mathieu-Daudé mc146818rtc_set_cmos_data(s, 0x18, val >> 8); 792d4bd81eSPhilippe Mathieu-Daudé mc146818rtc_set_cmos_data(s, 0x30, val); 802d4bd81eSPhilippe Mathieu-Daudé mc146818rtc_set_cmos_data(s, 0x31, val >> 8); 810ebf007dSSergio Lopez /* memory between 16MiB and 4GiB */ 820ebf007dSSergio Lopez if (x86ms->below_4g_mem_size > 16 * MiB) { 830ebf007dSSergio Lopez val = (x86ms->below_4g_mem_size - 16 * MiB) / (64 * KiB); 840ebf007dSSergio Lopez } else { 850ebf007dSSergio Lopez val = 0; 860ebf007dSSergio Lopez } 870ebf007dSSergio Lopez if (val > 65535) { 880ebf007dSSergio Lopez val = 65535; 890ebf007dSSergio Lopez } 902d4bd81eSPhilippe Mathieu-Daudé mc146818rtc_set_cmos_data(s, 0x34, val); 912d4bd81eSPhilippe Mathieu-Daudé mc146818rtc_set_cmos_data(s, 0x35, val >> 8); 920ebf007dSSergio Lopez /* memory above 4GiB */ 930ebf007dSSergio Lopez val = x86ms->above_4g_mem_size / 65536; 942d4bd81eSPhilippe Mathieu-Daudé mc146818rtc_set_cmos_data(s, 0x5b, val); 952d4bd81eSPhilippe Mathieu-Daudé mc146818rtc_set_cmos_data(s, 0x5c, val >> 8); 962d4bd81eSPhilippe Mathieu-Daudé mc146818rtc_set_cmos_data(s, 0x5d, val >> 16); 970ebf007dSSergio Lopez } 980ebf007dSSergio Lopez 9924db877aSGerd Hoffmann static void create_gpex(MicrovmMachineState *mms) 10024db877aSGerd Hoffmann { 10124db877aSGerd Hoffmann X86MachineState *x86ms = X86_MACHINE(mms); 10224db877aSGerd Hoffmann MemoryRegion *mmio32_alias; 10324db877aSGerd Hoffmann MemoryRegion *mmio64_alias; 10424db877aSGerd Hoffmann MemoryRegion *mmio_reg; 10524db877aSGerd Hoffmann MemoryRegion *ecam_alias; 10624db877aSGerd Hoffmann MemoryRegion *ecam_reg; 10724db877aSGerd Hoffmann DeviceState *dev; 10824db877aSGerd Hoffmann int i; 10924db877aSGerd Hoffmann 11024db877aSGerd Hoffmann dev = qdev_new(TYPE_GPEX_HOST); 11124db877aSGerd Hoffmann sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); 11224db877aSGerd Hoffmann 11324db877aSGerd Hoffmann /* Map only the first size_ecam bytes of ECAM space */ 11424db877aSGerd Hoffmann ecam_alias = g_new0(MemoryRegion, 1); 11524db877aSGerd Hoffmann ecam_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); 11624db877aSGerd Hoffmann memory_region_init_alias(ecam_alias, OBJECT(dev), "pcie-ecam", 11724db877aSGerd Hoffmann ecam_reg, 0, mms->gpex.ecam.size); 11824db877aSGerd Hoffmann memory_region_add_subregion(get_system_memory(), 11924db877aSGerd Hoffmann mms->gpex.ecam.base, ecam_alias); 12024db877aSGerd Hoffmann 12124db877aSGerd Hoffmann /* Map the MMIO window into system address space so as to expose 12224db877aSGerd Hoffmann * the section of PCI MMIO space which starts at the same base address 12324db877aSGerd Hoffmann * (ie 1:1 mapping for that part of PCI MMIO space visible through 12424db877aSGerd Hoffmann * the window). 12524db877aSGerd Hoffmann */ 12624db877aSGerd Hoffmann mmio_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1); 12724db877aSGerd Hoffmann if (mms->gpex.mmio32.size) { 12824db877aSGerd Hoffmann mmio32_alias = g_new0(MemoryRegion, 1); 12924db877aSGerd Hoffmann memory_region_init_alias(mmio32_alias, OBJECT(dev), "pcie-mmio32", mmio_reg, 13024db877aSGerd Hoffmann mms->gpex.mmio32.base, mms->gpex.mmio32.size); 13124db877aSGerd Hoffmann memory_region_add_subregion(get_system_memory(), 13224db877aSGerd Hoffmann mms->gpex.mmio32.base, mmio32_alias); 13324db877aSGerd Hoffmann } 13424db877aSGerd Hoffmann if (mms->gpex.mmio64.size) { 13524db877aSGerd Hoffmann mmio64_alias = g_new0(MemoryRegion, 1); 13624db877aSGerd Hoffmann memory_region_init_alias(mmio64_alias, OBJECT(dev), "pcie-mmio64", mmio_reg, 13724db877aSGerd Hoffmann mms->gpex.mmio64.base, mms->gpex.mmio64.size); 13824db877aSGerd Hoffmann memory_region_add_subregion(get_system_memory(), 13924db877aSGerd Hoffmann mms->gpex.mmio64.base, mmio64_alias); 14024db877aSGerd Hoffmann } 14124db877aSGerd Hoffmann 14224db877aSGerd Hoffmann for (i = 0; i < GPEX_NUM_IRQS; i++) { 14324db877aSGerd Hoffmann sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, 14424db877aSGerd Hoffmann x86ms->gsi[mms->gpex.irq + i]); 14524db877aSGerd Hoffmann } 14624db877aSGerd Hoffmann } 14724db877aSGerd Hoffmann 1484d01b899SGerd Hoffmann static int microvm_ioapics(MicrovmMachineState *mms) 1494d01b899SGerd Hoffmann { 1504d01b899SGerd Hoffmann if (!x86_machine_is_acpi_enabled(X86_MACHINE(mms))) { 1514d01b899SGerd Hoffmann return 1; 1524d01b899SGerd Hoffmann } 1534d01b899SGerd Hoffmann if (mms->ioapic2 == ON_OFF_AUTO_OFF) { 1544d01b899SGerd Hoffmann return 1; 1554d01b899SGerd Hoffmann } 1564d01b899SGerd Hoffmann return 2; 1574d01b899SGerd Hoffmann } 1584d01b899SGerd Hoffmann 1590ebf007dSSergio Lopez static void microvm_devices_init(MicrovmMachineState *mms) 1600ebf007dSSergio Lopez { 1617d435078SPaolo Bonzini const char *default_firmware; 1620ebf007dSSergio Lopez X86MachineState *x86ms = X86_MACHINE(mms); 1630ebf007dSSergio Lopez ISABus *isa_bus; 1640ebf007dSSergio Lopez GSIState *gsi_state; 1654d01b899SGerd Hoffmann int ioapics; 1660ebf007dSSergio Lopez int i; 1670ebf007dSSergio Lopez 1680ebf007dSSergio Lopez /* Core components */ 1694d01b899SGerd Hoffmann ioapics = microvm_ioapics(mms); 1700ebf007dSSergio Lopez gsi_state = g_malloc0(sizeof(*gsi_state)); 1714d01b899SGerd Hoffmann x86ms->gsi = qemu_allocate_irqs(gsi_handler, gsi_state, 1724d01b899SGerd Hoffmann IOAPIC_NUM_PINS * ioapics); 1730ebf007dSSergio Lopez 1740ebf007dSSergio Lopez isa_bus = isa_bus_new(NULL, get_system_memory(), get_system_io(), 1750ebf007dSSergio Lopez &error_abort); 1767067887eSPhilippe Mathieu-Daudé isa_bus_register_input_irqs(isa_bus, x86ms->gsi); 1770ebf007dSSergio Lopez 1789b0c4433SBernhard Beschow ioapic_init_gsi(gsi_state, OBJECT(mms)); 1794d01b899SGerd Hoffmann if (ioapics > 1) { 1804d01b899SGerd Hoffmann x86ms->ioapic2 = ioapic_init_secondary(gsi_state); 1814d01b899SGerd Hoffmann } 1820ebf007dSSergio Lopez 183b797c98dSPhilippe Mathieu-Daudé if (kvm_enabled()) { 1848700a984SVitaly Kuznetsov kvmclock_create(true); 185b797c98dSPhilippe Mathieu-Daudé } 1860ebf007dSSergio Lopez 187c214a7bcSGerd Hoffmann mms->virtio_irq_base = 5; 188c214a7bcSGerd Hoffmann mms->virtio_num_transports = 8; 1894d01b899SGerd Hoffmann if (x86ms->ioapic2) { 1904d01b899SGerd Hoffmann mms->pcie_irq_base = 16; /* 16 -> 19 */ 1914d01b899SGerd Hoffmann /* use second ioapic (24 -> 47) for virtio-mmio irq lines */ 1924d01b899SGerd Hoffmann mms->virtio_irq_base = IO_APIC_SECONDARY_IRQBASE; 1934d01b899SGerd Hoffmann mms->virtio_num_transports = IOAPIC_NUM_PINS; 1944d01b899SGerd Hoffmann } else if (x86_machine_is_acpi_enabled(x86ms)) { 1954d01b899SGerd Hoffmann mms->pcie_irq_base = 12; /* 12 -> 15 */ 1964d01b899SGerd Hoffmann mms->virtio_irq_base = 16; /* 16 -> 23 */ 197c214a7bcSGerd Hoffmann } 198c214a7bcSGerd Hoffmann 199c214a7bcSGerd Hoffmann for (i = 0; i < mms->virtio_num_transports; i++) { 2000ebf007dSSergio Lopez sysbus_create_simple("virtio-mmio", 2010ebf007dSSergio Lopez VIRTIO_MMIO_BASE + i * 512, 202d4e9d577SGerd Hoffmann x86ms->gsi[mms->virtio_irq_base + i]); 2030ebf007dSSergio Lopez } 2040ebf007dSSergio Lopez 2050ebf007dSSergio Lopez /* Optional and legacy devices */ 2068045df14SGerd Hoffmann if (x86_machine_is_acpi_enabled(x86ms)) { 207c9c8ba69SBernhard Beschow DeviceState *dev = qdev_new(TYPE_ACPI_GED); 2088045df14SGerd Hoffmann qdev_prop_set_uint32(dev, "ged-event", ACPI_GED_PWR_DOWN_EVT); 209bec4be77SPhilippe Mathieu-Daudé sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal); 2108045df14SGerd Hoffmann sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, GED_MMIO_BASE); 2118045df14SGerd Hoffmann /* sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, GED_MMIO_BASE_MEMHP); */ 2128045df14SGerd Hoffmann sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, GED_MMIO_BASE_REGS); 2138045df14SGerd Hoffmann sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, 2148045df14SGerd Hoffmann x86ms->gsi[GED_MMIO_IRQ]); 21550aef131SGerd Hoffmann x86ms->acpi_dev = HOTPLUG_HANDLER(dev); 2168045df14SGerd Hoffmann } 2170ebf007dSSergio Lopez 218d4a42e85SGerd Hoffmann if (x86_machine_is_acpi_enabled(x86ms) && machine_usb(MACHINE(mms))) { 219d4a42e85SGerd Hoffmann DeviceState *dev = qdev_new(TYPE_XHCI_SYSBUS); 220d4a42e85SGerd Hoffmann qdev_prop_set_uint32(dev, "intrs", 1); 221d4a42e85SGerd Hoffmann qdev_prop_set_uint32(dev, "slots", XHCI_MAXSLOTS); 222d4a42e85SGerd Hoffmann qdev_prop_set_uint32(dev, "p2", 8); 223d4a42e85SGerd Hoffmann qdev_prop_set_uint32(dev, "p3", 8); 224d4a42e85SGerd Hoffmann sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal); 225d4a42e85SGerd Hoffmann sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, MICROVM_XHCI_BASE); 226d4a42e85SGerd Hoffmann sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, 227d4a42e85SGerd Hoffmann x86ms->gsi[MICROVM_XHCI_IRQ]); 228d4a42e85SGerd Hoffmann } 229d4a42e85SGerd Hoffmann 23024db877aSGerd Hoffmann if (x86_machine_is_acpi_enabled(x86ms) && mms->pcie == ON_OFF_AUTO_ON) { 2318c2d9f9aSGerd Hoffmann /* use topmost 25% of the address space available */ 2328c2d9f9aSGerd Hoffmann hwaddr phys_size = (hwaddr)1 << X86_CPU(first_cpu)->phys_bits; 2338c2d9f9aSGerd Hoffmann if (phys_size > 0x1000000ll) { 2348c2d9f9aSGerd Hoffmann mms->gpex.mmio64.size = phys_size / 4; 2358c2d9f9aSGerd Hoffmann mms->gpex.mmio64.base = phys_size - mms->gpex.mmio64.size; 2368c2d9f9aSGerd Hoffmann } 23724db877aSGerd Hoffmann mms->gpex.mmio32.base = PCIE_MMIO_BASE; 23824db877aSGerd Hoffmann mms->gpex.mmio32.size = PCIE_MMIO_SIZE; 23924db877aSGerd Hoffmann mms->gpex.ecam.base = PCIE_ECAM_BASE; 24024db877aSGerd Hoffmann mms->gpex.ecam.size = PCIE_ECAM_SIZE; 2413d09c007SGerd Hoffmann mms->gpex.irq = mms->pcie_irq_base; 24224db877aSGerd Hoffmann create_gpex(mms); 2433d09c007SGerd Hoffmann x86ms->pci_irq_mask = ((1 << (mms->pcie_irq_base + 0)) | 2443d09c007SGerd Hoffmann (1 << (mms->pcie_irq_base + 1)) | 2453d09c007SGerd Hoffmann (1 << (mms->pcie_irq_base + 2)) | 2463d09c007SGerd Hoffmann (1 << (mms->pcie_irq_base + 3))); 24764b070daSGerd Hoffmann } else { 24864b070daSGerd Hoffmann x86ms->pci_irq_mask = 0; 24924db877aSGerd Hoffmann } 25024db877aSGerd Hoffmann 251c300bbe8SXiaoyao Li if (x86ms->pic == ON_OFF_AUTO_ON || x86ms->pic == ON_OFF_AUTO_AUTO) { 2520ebf007dSSergio Lopez qemu_irq *i8259; 2530ebf007dSSergio Lopez 25489a289c7SPaolo Bonzini i8259 = i8259_init(isa_bus, x86_allocate_cpu_irq()); 2550ebf007dSSergio Lopez for (i = 0; i < ISA_NUM_IRQS; i++) { 2560ebf007dSSergio Lopez gsi_state->i8259_irq[i] = i8259[i]; 2570ebf007dSSergio Lopez } 2580ebf007dSSergio Lopez g_free(i8259); 2590ebf007dSSergio Lopez } 2600ebf007dSSergio Lopez 2619dee7e51SXiaoyao Li if (x86ms->pit == ON_OFF_AUTO_ON || x86ms->pit == ON_OFF_AUTO_AUTO) { 2620ebf007dSSergio Lopez if (kvm_pit_in_kernel()) { 2630ebf007dSSergio Lopez kvm_pit_init(isa_bus, 0x40); 2640ebf007dSSergio Lopez } else { 2650ebf007dSSergio Lopez i8254_pit_init(isa_bus, 0x40, 0, NULL); 2660ebf007dSSergio Lopez } 2670ebf007dSSergio Lopez } 2680ebf007dSSergio Lopez 2690ebf007dSSergio Lopez if (mms->rtc == ON_OFF_AUTO_ON || 2700ebf007dSSergio Lopez (mms->rtc == ON_OFF_AUTO_AUTO && !kvm_enabled())) { 27155c86cb8SPhilippe Mathieu-Daudé microvm_set_rtc(mms, mc146818_rtc_init(isa_bus, 2000, NULL)); 2720ebf007dSSergio Lopez } 2730ebf007dSSergio Lopez 2740ebf007dSSergio Lopez if (mms->isa_serial) { 2750ebf007dSSergio Lopez serial_hds_isa_init(isa_bus, 0, 1); 2760ebf007dSSergio Lopez } 2770ebf007dSSergio Lopez 2787d435078SPaolo Bonzini default_firmware = x86_machine_is_acpi_enabled(x86ms) 27967eb6a40SGerd Hoffmann ? MICROVM_BIOS_FILENAME 28067eb6a40SGerd Hoffmann : MICROVM_QBOOT_FILENAME; 281*84835184SBernhard Beschow x86_bios_rom_init(x86ms, default_firmware, get_system_memory(), true); 2820ebf007dSSergio Lopez } 2830ebf007dSSergio Lopez 2840ebf007dSSergio Lopez static void microvm_memory_init(MicrovmMachineState *mms) 2850ebf007dSSergio Lopez { 2860ebf007dSSergio Lopez MachineState *machine = MACHINE(mms); 2870ebf007dSSergio Lopez X86MachineState *x86ms = X86_MACHINE(mms); 2889ad54686SIgor Mammedov MemoryRegion *ram_below_4g, *ram_above_4g; 2890ebf007dSSergio Lopez MemoryRegion *system_memory = get_system_memory(); 2900ebf007dSSergio Lopez FWCfgState *fw_cfg; 291e289655cSGerd Hoffmann ram_addr_t lowmem = 0xc0000000; /* 3G */ 2920ebf007dSSergio Lopez int i; 2930ebf007dSSergio Lopez 2940ebf007dSSergio Lopez if (machine->ram_size > lowmem) { 2950ebf007dSSergio Lopez x86ms->above_4g_mem_size = machine->ram_size - lowmem; 2960ebf007dSSergio Lopez x86ms->below_4g_mem_size = lowmem; 2970ebf007dSSergio Lopez } else { 2980ebf007dSSergio Lopez x86ms->above_4g_mem_size = 0; 2990ebf007dSSergio Lopez x86ms->below_4g_mem_size = machine->ram_size; 3000ebf007dSSergio Lopez } 3010ebf007dSSergio Lopez 3020ebf007dSSergio Lopez ram_below_4g = g_malloc(sizeof(*ram_below_4g)); 3039ad54686SIgor Mammedov memory_region_init_alias(ram_below_4g, NULL, "ram-below-4g", machine->ram, 3040ebf007dSSergio Lopez 0, x86ms->below_4g_mem_size); 3050ebf007dSSergio Lopez memory_region_add_subregion(system_memory, 0, ram_below_4g); 3060ebf007dSSergio Lopez 3070ebf007dSSergio Lopez e820_add_entry(0, x86ms->below_4g_mem_size, E820_RAM); 3080ebf007dSSergio Lopez 3090ebf007dSSergio Lopez if (x86ms->above_4g_mem_size > 0) { 3100ebf007dSSergio Lopez ram_above_4g = g_malloc(sizeof(*ram_above_4g)); 3119ad54686SIgor Mammedov memory_region_init_alias(ram_above_4g, NULL, "ram-above-4g", 3129ad54686SIgor Mammedov machine->ram, 3130ebf007dSSergio Lopez x86ms->below_4g_mem_size, 3140ebf007dSSergio Lopez x86ms->above_4g_mem_size); 3150ebf007dSSergio Lopez memory_region_add_subregion(system_memory, 0x100000000ULL, 3160ebf007dSSergio Lopez ram_above_4g); 3170ebf007dSSergio Lopez e820_add_entry(0x100000000ULL, x86ms->above_4g_mem_size, E820_RAM); 3180ebf007dSSergio Lopez } 3190ebf007dSSergio Lopez 3200ebf007dSSergio Lopez fw_cfg = fw_cfg_init_io_dma(FW_CFG_IO_BASE, FW_CFG_IO_BASE + 4, 3210ebf007dSSergio Lopez &address_space_memory); 3220ebf007dSSergio Lopez 3230ebf007dSSergio Lopez fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, machine->smp.cpus); 3240ebf007dSSergio Lopez fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, machine->smp.max_cpus); 3250ebf007dSSergio Lopez fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)machine->ram_size); 326eafa0868SEduardo Habkost fw_cfg_add_i32(fw_cfg, FW_CFG_IRQ0_OVERRIDE, 1); 3270ebf007dSSergio Lopez fw_cfg_add_file(fw_cfg, "etc/e820", e820_table, 3280ebf007dSSergio Lopez sizeof(struct e820_entry) * e820_get_num_entries()); 3290ebf007dSSergio Lopez 3300ebf007dSSergio Lopez rom_set_fw(fw_cfg); 3310ebf007dSSergio Lopez 3320ebf007dSSergio Lopez if (machine->kernel_filename != NULL) { 333167f4873SMichael S. Tsirkin x86_load_linux(x86ms, fw_cfg, 0, true); 3340ebf007dSSergio Lopez } 3350ebf007dSSergio Lopez 3360ebf007dSSergio Lopez if (mms->option_roms) { 3370ebf007dSSergio Lopez for (i = 0; i < nb_option_roms; i++) { 3380ebf007dSSergio Lopez rom_add_option(option_rom[i].name, option_rom[i].bootindex); 3390ebf007dSSergio Lopez } 3400ebf007dSSergio Lopez } 3410ebf007dSSergio Lopez 3420ebf007dSSergio Lopez x86ms->fw_cfg = fw_cfg; 3430ebf007dSSergio Lopez x86ms->ioapic_as = &address_space_memory; 3440ebf007dSSergio Lopez } 3450ebf007dSSergio Lopez 346d4e9d577SGerd Hoffmann static gchar *microvm_get_mmio_cmdline(gchar *name, uint32_t virtio_irq_base) 3470ebf007dSSergio Lopez { 3480ebf007dSSergio Lopez gchar *cmdline; 3490ebf007dSSergio Lopez gchar *separator; 3500ebf007dSSergio Lopez long int index; 3510ebf007dSSergio Lopez int ret; 3520ebf007dSSergio Lopez 3530ebf007dSSergio Lopez separator = g_strrstr(name, "."); 3540ebf007dSSergio Lopez if (!separator) { 3550ebf007dSSergio Lopez return NULL; 3560ebf007dSSergio Lopez } 3570ebf007dSSergio Lopez 3580ebf007dSSergio Lopez if (qemu_strtol(separator + 1, NULL, 10, &index) != 0) { 3590ebf007dSSergio Lopez return NULL; 3600ebf007dSSergio Lopez } 3610ebf007dSSergio Lopez 3620ebf007dSSergio Lopez cmdline = g_malloc0(VIRTIO_CMDLINE_MAXLEN); 3630ebf007dSSergio Lopez ret = g_snprintf(cmdline, VIRTIO_CMDLINE_MAXLEN, 3640ebf007dSSergio Lopez " virtio_mmio.device=512@0x%lx:%ld", 3650ebf007dSSergio Lopez VIRTIO_MMIO_BASE + index * 512, 366d4e9d577SGerd Hoffmann virtio_irq_base + index); 3670ebf007dSSergio Lopez if (ret < 0 || ret >= VIRTIO_CMDLINE_MAXLEN) { 3680ebf007dSSergio Lopez g_free(cmdline); 3690ebf007dSSergio Lopez return NULL; 3700ebf007dSSergio Lopez } 3710ebf007dSSergio Lopez 3720ebf007dSSergio Lopez return cmdline; 3730ebf007dSSergio Lopez } 3740ebf007dSSergio Lopez 3750ebf007dSSergio Lopez static void microvm_fix_kernel_cmdline(MachineState *machine) 3760ebf007dSSergio Lopez { 3770ebf007dSSergio Lopez X86MachineState *x86ms = X86_MACHINE(machine); 378d4e9d577SGerd Hoffmann MicrovmMachineState *mms = MICROVM_MACHINE(machine); 3790ebf007dSSergio Lopez BusState *bus; 3800ebf007dSSergio Lopez BusChild *kid; 381b34f2fd1SMichael S. Tsirkin char *cmdline; 3820ebf007dSSergio Lopez 3830ebf007dSSergio Lopez /* 3840ebf007dSSergio Lopez * Find MMIO transports with attached devices, and add them to the kernel 3850ebf007dSSergio Lopez * command line. 3860ebf007dSSergio Lopez * 3870ebf007dSSergio Lopez * Yes, this is a hack, but one that heavily improves the UX without 3880ebf007dSSergio Lopez * introducing any significant issues. 3890ebf007dSSergio Lopez */ 390b34f2fd1SMichael S. Tsirkin cmdline = g_strdup(machine->kernel_cmdline); 3910ebf007dSSergio Lopez bus = sysbus_get_default(); 3920ebf007dSSergio Lopez QTAILQ_FOREACH(kid, &bus->children, sibling) { 3930ebf007dSSergio Lopez DeviceState *dev = kid->child; 3940ebf007dSSergio Lopez 395a5c80ab8SPhilippe Mathieu-Daudé if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MMIO)) { 3960ebf007dSSergio Lopez VirtIOMMIOProxy *mmio = VIRTIO_MMIO(OBJECT(dev)); 3970ebf007dSSergio Lopez VirtioBusState *mmio_virtio_bus = &mmio->bus; 3980ebf007dSSergio Lopez BusState *mmio_bus = &mmio_virtio_bus->parent_obj; 3990ebf007dSSergio Lopez 4000ebf007dSSergio Lopez if (!QTAILQ_EMPTY(&mmio_bus->children)) { 401d4e9d577SGerd Hoffmann gchar *mmio_cmdline = microvm_get_mmio_cmdline 402d4e9d577SGerd Hoffmann (mmio_bus->name, mms->virtio_irq_base); 4030ebf007dSSergio Lopez if (mmio_cmdline) { 4040ebf007dSSergio Lopez char *newcmd = g_strjoin(NULL, cmdline, mmio_cmdline, NULL); 4050ebf007dSSergio Lopez g_free(mmio_cmdline); 4060ebf007dSSergio Lopez g_free(cmdline); 4070ebf007dSSergio Lopez cmdline = newcmd; 4080ebf007dSSergio Lopez } 4090ebf007dSSergio Lopez } 4100ebf007dSSergio Lopez } 4110ebf007dSSergio Lopez } 4120ebf007dSSergio Lopez 413b34f2fd1SMichael S. Tsirkin fw_cfg_modify_i32(x86ms->fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(cmdline) + 1); 414b34f2fd1SMichael S. Tsirkin fw_cfg_modify_string(x86ms->fw_cfg, FW_CFG_CMDLINE_DATA, cmdline); 415b34f2fd1SMichael S. Tsirkin 416c3157b74SSergio Lopez g_free(cmdline); 4170ebf007dSSergio Lopez } 4180ebf007dSSergio Lopez 419e3ab9873SGerd Hoffmann static void microvm_device_pre_plug_cb(HotplugHandler *hotplug_dev, 420e3ab9873SGerd Hoffmann DeviceState *dev, Error **errp) 421e3ab9873SGerd Hoffmann { 4228c2d9f9aSGerd Hoffmann X86CPU *cpu = X86_CPU(dev); 4238c2d9f9aSGerd Hoffmann 4248c2d9f9aSGerd Hoffmann cpu->host_phys_bits = true; /* need reliable phys-bits */ 425e3ab9873SGerd Hoffmann x86_cpu_pre_plug(hotplug_dev, dev, errp); 426e3ab9873SGerd Hoffmann } 427e3ab9873SGerd Hoffmann 428e3ab9873SGerd Hoffmann static void microvm_device_plug_cb(HotplugHandler *hotplug_dev, 429e3ab9873SGerd Hoffmann DeviceState *dev, Error **errp) 430e3ab9873SGerd Hoffmann { 431e3ab9873SGerd Hoffmann x86_cpu_plug(hotplug_dev, dev, errp); 432e3ab9873SGerd Hoffmann } 433e3ab9873SGerd Hoffmann 434e3ab9873SGerd Hoffmann static void microvm_device_unplug_request_cb(HotplugHandler *hotplug_dev, 435e3ab9873SGerd Hoffmann DeviceState *dev, Error **errp) 436e3ab9873SGerd Hoffmann { 437e3ab9873SGerd Hoffmann error_setg(errp, "unplug not supported by microvm"); 438e3ab9873SGerd Hoffmann } 439e3ab9873SGerd Hoffmann 440e3ab9873SGerd Hoffmann static void microvm_device_unplug_cb(HotplugHandler *hotplug_dev, 441e3ab9873SGerd Hoffmann DeviceState *dev, Error **errp) 442e3ab9873SGerd Hoffmann { 443e3ab9873SGerd Hoffmann error_setg(errp, "unplug not supported by microvm"); 444e3ab9873SGerd Hoffmann } 445e3ab9873SGerd Hoffmann 446e3ab9873SGerd Hoffmann static HotplugHandler *microvm_get_hotplug_handler(MachineState *machine, 447e3ab9873SGerd Hoffmann DeviceState *dev) 448e3ab9873SGerd Hoffmann { 449e3ab9873SGerd Hoffmann if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { 450e3ab9873SGerd Hoffmann return HOTPLUG_HANDLER(machine); 451e3ab9873SGerd Hoffmann } 452e3ab9873SGerd Hoffmann return NULL; 453e3ab9873SGerd Hoffmann } 454e3ab9873SGerd Hoffmann 4550ebf007dSSergio Lopez static void microvm_machine_state_init(MachineState *machine) 4560ebf007dSSergio Lopez { 4570ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(machine); 4580ebf007dSSergio Lopez X86MachineState *x86ms = X86_MACHINE(machine); 4590ebf007dSSergio Lopez 4600ebf007dSSergio Lopez microvm_memory_init(mms); 4610ebf007dSSergio Lopez 4620ebf007dSSergio Lopez x86_cpus_init(x86ms, CPU_VERSION_LATEST); 4630ebf007dSSergio Lopez 4640ebf007dSSergio Lopez microvm_devices_init(mms); 4650ebf007dSSergio Lopez } 4660ebf007dSSergio Lopez 4677966d70fSJason A. Donenfeld static void microvm_machine_reset(MachineState *machine, ShutdownCause reason) 4680ebf007dSSergio Lopez { 4690ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(machine); 4700ebf007dSSergio Lopez CPUState *cs; 4710ebf007dSSergio Lopez X86CPU *cpu; 4720ebf007dSSergio Lopez 473f6f7e2d8SGerd Hoffmann if (!x86_machine_is_acpi_enabled(X86_MACHINE(machine)) && 474f6f7e2d8SGerd Hoffmann machine->kernel_filename != NULL && 4750ebf007dSSergio Lopez mms->auto_kernel_cmdline && !mms->kernel_cmdline_fixed) { 4760ebf007dSSergio Lopez microvm_fix_kernel_cmdline(machine); 4770ebf007dSSergio Lopez mms->kernel_cmdline_fixed = true; 4780ebf007dSSergio Lopez } 4790ebf007dSSergio Lopez 4807966d70fSJason A. Donenfeld qemu_devices_reset(reason); 4810ebf007dSSergio Lopez 4820ebf007dSSergio Lopez CPU_FOREACH(cs) { 4830ebf007dSSergio Lopez cpu = X86_CPU(cs); 4840ebf007dSSergio Lopez 485ec19444aSMaciej S. Szmigiero x86_cpu_after_reset(cpu); 4860ebf007dSSergio Lopez } 4870ebf007dSSergio Lopez } 4880ebf007dSSergio Lopez 4890ebf007dSSergio Lopez static void microvm_machine_get_rtc(Object *obj, Visitor *v, const char *name, 4900ebf007dSSergio Lopez void *opaque, Error **errp) 4910ebf007dSSergio Lopez { 4920ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 4930ebf007dSSergio Lopez OnOffAuto rtc = mms->rtc; 4940ebf007dSSergio Lopez 4950ebf007dSSergio Lopez visit_type_OnOffAuto(v, name, &rtc, errp); 4960ebf007dSSergio Lopez } 4970ebf007dSSergio Lopez 4980ebf007dSSergio Lopez static void microvm_machine_set_rtc(Object *obj, Visitor *v, const char *name, 4990ebf007dSSergio Lopez void *opaque, Error **errp) 5000ebf007dSSergio Lopez { 5010ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5020ebf007dSSergio Lopez 5030ebf007dSSergio Lopez visit_type_OnOffAuto(v, name, &mms->rtc, errp); 5040ebf007dSSergio Lopez } 5050ebf007dSSergio Lopez 50624db877aSGerd Hoffmann static void microvm_machine_get_pcie(Object *obj, Visitor *v, const char *name, 50724db877aSGerd Hoffmann void *opaque, Error **errp) 50824db877aSGerd Hoffmann { 50924db877aSGerd Hoffmann MicrovmMachineState *mms = MICROVM_MACHINE(obj); 51024db877aSGerd Hoffmann OnOffAuto pcie = mms->pcie; 51124db877aSGerd Hoffmann 51224db877aSGerd Hoffmann visit_type_OnOffAuto(v, name, &pcie, errp); 51324db877aSGerd Hoffmann } 51424db877aSGerd Hoffmann 51524db877aSGerd Hoffmann static void microvm_machine_set_pcie(Object *obj, Visitor *v, const char *name, 51624db877aSGerd Hoffmann void *opaque, Error **errp) 51724db877aSGerd Hoffmann { 51824db877aSGerd Hoffmann MicrovmMachineState *mms = MICROVM_MACHINE(obj); 51924db877aSGerd Hoffmann 52024db877aSGerd Hoffmann visit_type_OnOffAuto(v, name, &mms->pcie, errp); 52124db877aSGerd Hoffmann } 52224db877aSGerd Hoffmann 5234d01b899SGerd Hoffmann static void microvm_machine_get_ioapic2(Object *obj, Visitor *v, const char *name, 5244d01b899SGerd Hoffmann void *opaque, Error **errp) 5254d01b899SGerd Hoffmann { 5264d01b899SGerd Hoffmann MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5274d01b899SGerd Hoffmann OnOffAuto ioapic2 = mms->ioapic2; 5284d01b899SGerd Hoffmann 5294d01b899SGerd Hoffmann visit_type_OnOffAuto(v, name, &ioapic2, errp); 5304d01b899SGerd Hoffmann } 5314d01b899SGerd Hoffmann 5324d01b899SGerd Hoffmann static void microvm_machine_set_ioapic2(Object *obj, Visitor *v, const char *name, 5334d01b899SGerd Hoffmann void *opaque, Error **errp) 5344d01b899SGerd Hoffmann { 5354d01b899SGerd Hoffmann MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5364d01b899SGerd Hoffmann 5374d01b899SGerd Hoffmann visit_type_OnOffAuto(v, name, &mms->ioapic2, errp); 5384d01b899SGerd Hoffmann } 5394d01b899SGerd Hoffmann 5400ebf007dSSergio Lopez static bool microvm_machine_get_isa_serial(Object *obj, Error **errp) 5410ebf007dSSergio Lopez { 5420ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5430ebf007dSSergio Lopez 5440ebf007dSSergio Lopez return mms->isa_serial; 5450ebf007dSSergio Lopez } 5460ebf007dSSergio Lopez 5470ebf007dSSergio Lopez static void microvm_machine_set_isa_serial(Object *obj, bool value, 5480ebf007dSSergio Lopez Error **errp) 5490ebf007dSSergio Lopez { 5500ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5510ebf007dSSergio Lopez 5520ebf007dSSergio Lopez mms->isa_serial = value; 5530ebf007dSSergio Lopez } 5540ebf007dSSergio Lopez 5550ebf007dSSergio Lopez static bool microvm_machine_get_option_roms(Object *obj, Error **errp) 5560ebf007dSSergio Lopez { 5570ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5580ebf007dSSergio Lopez 5590ebf007dSSergio Lopez return mms->option_roms; 5600ebf007dSSergio Lopez } 5610ebf007dSSergio Lopez 5620ebf007dSSergio Lopez static void microvm_machine_set_option_roms(Object *obj, bool value, 5630ebf007dSSergio Lopez Error **errp) 5640ebf007dSSergio Lopez { 5650ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5660ebf007dSSergio Lopez 5670ebf007dSSergio Lopez mms->option_roms = value; 5680ebf007dSSergio Lopez } 5690ebf007dSSergio Lopez 5700ebf007dSSergio Lopez static bool microvm_machine_get_auto_kernel_cmdline(Object *obj, Error **errp) 5710ebf007dSSergio Lopez { 5720ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5730ebf007dSSergio Lopez 5740ebf007dSSergio Lopez return mms->auto_kernel_cmdline; 5750ebf007dSSergio Lopez } 5760ebf007dSSergio Lopez 5770ebf007dSSergio Lopez static void microvm_machine_set_auto_kernel_cmdline(Object *obj, bool value, 5780ebf007dSSergio Lopez Error **errp) 5790ebf007dSSergio Lopez { 5800ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5810ebf007dSSergio Lopez 5820ebf007dSSergio Lopez mms->auto_kernel_cmdline = value; 5830ebf007dSSergio Lopez } 5840ebf007dSSergio Lopez 5858045df14SGerd Hoffmann static void microvm_machine_done(Notifier *notifier, void *data) 5868045df14SGerd Hoffmann { 5878045df14SGerd Hoffmann MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState, 5888045df14SGerd Hoffmann machine_done); 5898045df14SGerd Hoffmann 5908045df14SGerd Hoffmann acpi_setup_microvm(mms); 591f5918a99SGerd Hoffmann dt_setup_microvm(mms); 5928045df14SGerd Hoffmann } 5938045df14SGerd Hoffmann 5948045df14SGerd Hoffmann static void microvm_powerdown_req(Notifier *notifier, void *data) 5958045df14SGerd Hoffmann { 5968045df14SGerd Hoffmann MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState, 5978045df14SGerd Hoffmann powerdown_req); 59850aef131SGerd Hoffmann X86MachineState *x86ms = X86_MACHINE(mms); 5998045df14SGerd Hoffmann 60050aef131SGerd Hoffmann if (x86ms->acpi_dev) { 60150aef131SGerd Hoffmann Object *obj = OBJECT(x86ms->acpi_dev); 6028045df14SGerd Hoffmann AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj); 60350aef131SGerd Hoffmann adevc->send_event(ACPI_DEVICE_IF(x86ms->acpi_dev), 60450aef131SGerd Hoffmann ACPI_POWER_DOWN_STATUS); 6058045df14SGerd Hoffmann } 6068045df14SGerd Hoffmann } 6078045df14SGerd Hoffmann 6080ebf007dSSergio Lopez static void microvm_machine_initfn(Object *obj) 6090ebf007dSSergio Lopez { 6100ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 6110ebf007dSSergio Lopez 6120ebf007dSSergio Lopez /* Configuration */ 6130ebf007dSSergio Lopez mms->rtc = ON_OFF_AUTO_AUTO; 61424db877aSGerd Hoffmann mms->pcie = ON_OFF_AUTO_AUTO; 6154d01b899SGerd Hoffmann mms->ioapic2 = ON_OFF_AUTO_AUTO; 6160ebf007dSSergio Lopez mms->isa_serial = true; 6170ebf007dSSergio Lopez mms->option_roms = true; 6180ebf007dSSergio Lopez mms->auto_kernel_cmdline = true; 6190ebf007dSSergio Lopez 6200ebf007dSSergio Lopez /* State */ 6210ebf007dSSergio Lopez mms->kernel_cmdline_fixed = false; 6228045df14SGerd Hoffmann 6238045df14SGerd Hoffmann mms->machine_done.notify = microvm_machine_done; 6248045df14SGerd Hoffmann qemu_add_machine_init_done_notifier(&mms->machine_done); 6258045df14SGerd Hoffmann mms->powerdown_req.notify = microvm_powerdown_req; 6268045df14SGerd Hoffmann qemu_register_powerdown_notifier(&mms->powerdown_req); 6270ebf007dSSergio Lopez } 6280ebf007dSSergio Lopez 6293ef1497bSGerd Hoffmann GlobalProperty microvm_properties[] = { 6303ef1497bSGerd Hoffmann /* 6313ef1497bSGerd Hoffmann * pcie host bridge (gpex) on microvm has no io address window, 6323ef1497bSGerd Hoffmann * so reserving io space is not going to work. Turn it off. 6333ef1497bSGerd Hoffmann */ 6343ef1497bSGerd Hoffmann { "pcie-root-port", "io-reserve", "0" }, 6353ef1497bSGerd Hoffmann }; 6363ef1497bSGerd Hoffmann 6370ebf007dSSergio Lopez static void microvm_class_init(ObjectClass *oc, void *data) 6380ebf007dSSergio Lopez { 639f014c974SPaolo Bonzini X86MachineClass *x86mc = X86_MACHINE_CLASS(oc); 6400ebf007dSSergio Lopez MachineClass *mc = MACHINE_CLASS(oc); 641e3ab9873SGerd Hoffmann HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); 6420ebf007dSSergio Lopez 6430ebf007dSSergio Lopez mc->init = microvm_machine_state_init; 6440ebf007dSSergio Lopez 6450ebf007dSSergio Lopez mc->family = "microvm_i386"; 6460ebf007dSSergio Lopez mc->desc = "microvm (i386)"; 6470ebf007dSSergio Lopez mc->units_per_default_bus = 1; 6480ebf007dSSergio Lopez mc->no_floppy = 1; 6490ebf007dSSergio Lopez mc->max_cpus = 288; 6500ebf007dSSergio Lopez mc->has_hotpluggable_cpus = false; 6510ebf007dSSergio Lopez mc->auto_enable_numa_with_memhp = false; 652195784a0SDavid Hildenbrand mc->auto_enable_numa_with_memdev = false; 6530ebf007dSSergio Lopez mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE; 6540ebf007dSSergio Lopez mc->nvdimm_supported = false; 6559ad54686SIgor Mammedov mc->default_ram_id = "microvm.ram"; 6560ebf007dSSergio Lopez 6570ebf007dSSergio Lopez /* Avoid relying too much on kernel components */ 6580ebf007dSSergio Lopez mc->default_kernel_irqchip_split = true; 6590ebf007dSSergio Lopez 6600ebf007dSSergio Lopez /* Machine class handlers */ 6610ebf007dSSergio Lopez mc->reset = microvm_machine_reset; 6620ebf007dSSergio Lopez 663e3ab9873SGerd Hoffmann /* hotplug (for cpu coldplug) */ 664e3ab9873SGerd Hoffmann mc->get_hotplug_handler = microvm_get_hotplug_handler; 665e3ab9873SGerd Hoffmann hc->pre_plug = microvm_device_pre_plug_cb; 666e3ab9873SGerd Hoffmann hc->plug = microvm_device_plug_cb; 667e3ab9873SGerd Hoffmann hc->unplug_request = microvm_device_unplug_request_cb; 668e3ab9873SGerd Hoffmann hc->unplug = microvm_device_unplug_cb; 669e3ab9873SGerd Hoffmann 670f014c974SPaolo Bonzini x86mc->fwcfg_dma_enabled = true; 671f014c974SPaolo Bonzini 6720ebf007dSSergio Lopez object_class_property_add(oc, MICROVM_MACHINE_RTC, "OnOffAuto", 6730ebf007dSSergio Lopez microvm_machine_get_rtc, 6740ebf007dSSergio Lopez microvm_machine_set_rtc, 675d2623129SMarkus Armbruster NULL, NULL); 6760ebf007dSSergio Lopez object_class_property_set_description(oc, MICROVM_MACHINE_RTC, 6777eecec7dSMarkus Armbruster "Enable MC146818 RTC"); 6780ebf007dSSergio Lopez 67924db877aSGerd Hoffmann object_class_property_add(oc, MICROVM_MACHINE_PCIE, "OnOffAuto", 68024db877aSGerd Hoffmann microvm_machine_get_pcie, 68124db877aSGerd Hoffmann microvm_machine_set_pcie, 68224db877aSGerd Hoffmann NULL, NULL); 68324db877aSGerd Hoffmann object_class_property_set_description(oc, MICROVM_MACHINE_PCIE, 68424db877aSGerd Hoffmann "Enable PCIe"); 68524db877aSGerd Hoffmann 6864d01b899SGerd Hoffmann object_class_property_add(oc, MICROVM_MACHINE_IOAPIC2, "OnOffAuto", 6874d01b899SGerd Hoffmann microvm_machine_get_ioapic2, 6884d01b899SGerd Hoffmann microvm_machine_set_ioapic2, 6894d01b899SGerd Hoffmann NULL, NULL); 6904d01b899SGerd Hoffmann object_class_property_set_description(oc, MICROVM_MACHINE_IOAPIC2, 6914d01b899SGerd Hoffmann "Enable second IO-APIC"); 6924d01b899SGerd Hoffmann 6930ebf007dSSergio Lopez object_class_property_add_bool(oc, MICROVM_MACHINE_ISA_SERIAL, 6940ebf007dSSergio Lopez microvm_machine_get_isa_serial, 695d2623129SMarkus Armbruster microvm_machine_set_isa_serial); 6960ebf007dSSergio Lopez object_class_property_set_description(oc, MICROVM_MACHINE_ISA_SERIAL, 6977eecec7dSMarkus Armbruster "Set off to disable the instantiation an ISA serial port"); 6980ebf007dSSergio Lopez 6990ebf007dSSergio Lopez object_class_property_add_bool(oc, MICROVM_MACHINE_OPTION_ROMS, 7000ebf007dSSergio Lopez microvm_machine_get_option_roms, 701d2623129SMarkus Armbruster microvm_machine_set_option_roms); 7020ebf007dSSergio Lopez object_class_property_set_description(oc, MICROVM_MACHINE_OPTION_ROMS, 7037eecec7dSMarkus Armbruster "Set off to disable loading option ROMs"); 7040ebf007dSSergio Lopez 7050ebf007dSSergio Lopez object_class_property_add_bool(oc, MICROVM_MACHINE_AUTO_KERNEL_CMDLINE, 7060ebf007dSSergio Lopez microvm_machine_get_auto_kernel_cmdline, 707d2623129SMarkus Armbruster microvm_machine_set_auto_kernel_cmdline); 7080ebf007dSSergio Lopez object_class_property_set_description(oc, 7090ebf007dSSergio Lopez MICROVM_MACHINE_AUTO_KERNEL_CMDLINE, 7107eecec7dSMarkus Armbruster "Set off to disable adding virtio-mmio devices to the kernel cmdline"); 71163bcfe7bSGerd Hoffmann 71263bcfe7bSGerd Hoffmann machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); 7133ef1497bSGerd Hoffmann 7143ef1497bSGerd Hoffmann compat_props_add(mc->compat_props, microvm_properties, 7153ef1497bSGerd Hoffmann G_N_ELEMENTS(microvm_properties)); 7160ebf007dSSergio Lopez } 7170ebf007dSSergio Lopez 7180ebf007dSSergio Lopez static const TypeInfo microvm_machine_info = { 7190ebf007dSSergio Lopez .name = TYPE_MICROVM_MACHINE, 7200ebf007dSSergio Lopez .parent = TYPE_X86_MACHINE, 7210ebf007dSSergio Lopez .instance_size = sizeof(MicrovmMachineState), 7220ebf007dSSergio Lopez .instance_init = microvm_machine_initfn, 7230ebf007dSSergio Lopez .class_size = sizeof(MicrovmMachineClass), 7240ebf007dSSergio Lopez .class_init = microvm_class_init, 7250ebf007dSSergio Lopez .interfaces = (InterfaceInfo[]) { 726e3ab9873SGerd Hoffmann { TYPE_HOTPLUG_HANDLER }, 7270ebf007dSSergio Lopez { } 7280ebf007dSSergio Lopez }, 7290ebf007dSSergio Lopez }; 7300ebf007dSSergio Lopez 7310ebf007dSSergio Lopez static void microvm_machine_init(void) 7320ebf007dSSergio Lopez { 7330ebf007dSSergio Lopez type_register_static(µvm_machine_info); 7340ebf007dSSergio Lopez } 7350ebf007dSSergio Lopez type_init(microvm_machine_init); 736