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" 350ebf007dSSergio Lopez #include "hw/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 600ebf007dSSergio Lopez static void microvm_set_rtc(MicrovmMachineState *mms, ISADevice *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); 660ebf007dSSergio Lopez rtc_set_memory(s, 0x15, val); 670ebf007dSSergio Lopez rtc_set_memory(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 } 770ebf007dSSergio Lopez rtc_set_memory(s, 0x17, val); 780ebf007dSSergio Lopez rtc_set_memory(s, 0x18, val >> 8); 790ebf007dSSergio Lopez rtc_set_memory(s, 0x30, val); 800ebf007dSSergio Lopez rtc_set_memory(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 } 900ebf007dSSergio Lopez rtc_set_memory(s, 0x34, val); 910ebf007dSSergio Lopez rtc_set_memory(s, 0x35, val >> 8); 920ebf007dSSergio Lopez /* memory above 4GiB */ 930ebf007dSSergio Lopez val = x86ms->above_4g_mem_size / 65536; 940ebf007dSSergio Lopez rtc_set_memory(s, 0x5b, val); 950ebf007dSSergio Lopez rtc_set_memory(s, 0x5c, val >> 8); 960ebf007dSSergio Lopez rtc_set_memory(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 ISADevice *rtc_state; 1650ebf007dSSergio Lopez GSIState *gsi_state; 1664d01b899SGerd Hoffmann int ioapics; 1670ebf007dSSergio Lopez int i; 1680ebf007dSSergio Lopez 1690ebf007dSSergio Lopez /* Core components */ 1704d01b899SGerd Hoffmann ioapics = microvm_ioapics(mms); 1710ebf007dSSergio Lopez gsi_state = g_malloc0(sizeof(*gsi_state)); 1724d01b899SGerd Hoffmann x86ms->gsi = qemu_allocate_irqs(gsi_handler, gsi_state, 1734d01b899SGerd Hoffmann IOAPIC_NUM_PINS * ioapics); 1740ebf007dSSergio Lopez 1750ebf007dSSergio Lopez isa_bus = isa_bus_new(NULL, get_system_memory(), get_system_io(), 1760ebf007dSSergio Lopez &error_abort); 177*7067887eSPhilippe Mathieu-Daudé isa_bus_register_input_irqs(isa_bus, x86ms->gsi); 1780ebf007dSSergio Lopez 1790ebf007dSSergio Lopez ioapic_init_gsi(gsi_state, "machine"); 1804d01b899SGerd Hoffmann if (ioapics > 1) { 1814d01b899SGerd Hoffmann x86ms->ioapic2 = ioapic_init_secondary(gsi_state); 1824d01b899SGerd Hoffmann } 1830ebf007dSSergio Lopez 1848700a984SVitaly Kuznetsov kvmclock_create(true); 1850ebf007dSSergio Lopez 186c214a7bcSGerd Hoffmann mms->virtio_irq_base = 5; 187c214a7bcSGerd Hoffmann mms->virtio_num_transports = 8; 1884d01b899SGerd Hoffmann if (x86ms->ioapic2) { 1894d01b899SGerd Hoffmann mms->pcie_irq_base = 16; /* 16 -> 19 */ 1904d01b899SGerd Hoffmann /* use second ioapic (24 -> 47) for virtio-mmio irq lines */ 1914d01b899SGerd Hoffmann mms->virtio_irq_base = IO_APIC_SECONDARY_IRQBASE; 1924d01b899SGerd Hoffmann mms->virtio_num_transports = IOAPIC_NUM_PINS; 1934d01b899SGerd Hoffmann } else if (x86_machine_is_acpi_enabled(x86ms)) { 1944d01b899SGerd Hoffmann mms->pcie_irq_base = 12; /* 12 -> 15 */ 1954d01b899SGerd Hoffmann mms->virtio_irq_base = 16; /* 16 -> 23 */ 196c214a7bcSGerd Hoffmann } 197c214a7bcSGerd Hoffmann 198c214a7bcSGerd Hoffmann for (i = 0; i < mms->virtio_num_transports; i++) { 1990ebf007dSSergio Lopez sysbus_create_simple("virtio-mmio", 2000ebf007dSSergio Lopez VIRTIO_MMIO_BASE + i * 512, 201d4e9d577SGerd Hoffmann x86ms->gsi[mms->virtio_irq_base + i]); 2020ebf007dSSergio Lopez } 2030ebf007dSSergio Lopez 2040ebf007dSSergio Lopez /* Optional and legacy devices */ 2058045df14SGerd Hoffmann if (x86_machine_is_acpi_enabled(x86ms)) { 2068045df14SGerd Hoffmann DeviceState *dev = qdev_new(TYPE_ACPI_GED_X86); 2078045df14SGerd Hoffmann qdev_prop_set_uint32(dev, "ged-event", ACPI_GED_PWR_DOWN_EVT); 2088045df14SGerd Hoffmann sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, GED_MMIO_BASE); 2098045df14SGerd Hoffmann /* sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, GED_MMIO_BASE_MEMHP); */ 2108045df14SGerd Hoffmann sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, GED_MMIO_BASE_REGS); 2118045df14SGerd Hoffmann sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, 2128045df14SGerd Hoffmann x86ms->gsi[GED_MMIO_IRQ]); 2138045df14SGerd Hoffmann sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal); 21450aef131SGerd Hoffmann x86ms->acpi_dev = HOTPLUG_HANDLER(dev); 2158045df14SGerd Hoffmann } 2160ebf007dSSergio Lopez 217d4a42e85SGerd Hoffmann if (x86_machine_is_acpi_enabled(x86ms) && machine_usb(MACHINE(mms))) { 218d4a42e85SGerd Hoffmann DeviceState *dev = qdev_new(TYPE_XHCI_SYSBUS); 219d4a42e85SGerd Hoffmann qdev_prop_set_uint32(dev, "intrs", 1); 220d4a42e85SGerd Hoffmann qdev_prop_set_uint32(dev, "slots", XHCI_MAXSLOTS); 221d4a42e85SGerd Hoffmann qdev_prop_set_uint32(dev, "p2", 8); 222d4a42e85SGerd Hoffmann qdev_prop_set_uint32(dev, "p3", 8); 223d4a42e85SGerd Hoffmann sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal); 224d4a42e85SGerd Hoffmann sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, MICROVM_XHCI_BASE); 225d4a42e85SGerd Hoffmann sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, 226d4a42e85SGerd Hoffmann x86ms->gsi[MICROVM_XHCI_IRQ]); 227d4a42e85SGerd Hoffmann } 228d4a42e85SGerd Hoffmann 22924db877aSGerd Hoffmann if (x86_machine_is_acpi_enabled(x86ms) && mms->pcie == ON_OFF_AUTO_ON) { 2308c2d9f9aSGerd Hoffmann /* use topmost 25% of the address space available */ 2318c2d9f9aSGerd Hoffmann hwaddr phys_size = (hwaddr)1 << X86_CPU(first_cpu)->phys_bits; 2328c2d9f9aSGerd Hoffmann if (phys_size > 0x1000000ll) { 2338c2d9f9aSGerd Hoffmann mms->gpex.mmio64.size = phys_size / 4; 2348c2d9f9aSGerd Hoffmann mms->gpex.mmio64.base = phys_size - mms->gpex.mmio64.size; 2358c2d9f9aSGerd Hoffmann } 23624db877aSGerd Hoffmann mms->gpex.mmio32.base = PCIE_MMIO_BASE; 23724db877aSGerd Hoffmann mms->gpex.mmio32.size = PCIE_MMIO_SIZE; 23824db877aSGerd Hoffmann mms->gpex.ecam.base = PCIE_ECAM_BASE; 23924db877aSGerd Hoffmann mms->gpex.ecam.size = PCIE_ECAM_SIZE; 2403d09c007SGerd Hoffmann mms->gpex.irq = mms->pcie_irq_base; 24124db877aSGerd Hoffmann create_gpex(mms); 2423d09c007SGerd Hoffmann x86ms->pci_irq_mask = ((1 << (mms->pcie_irq_base + 0)) | 2433d09c007SGerd Hoffmann (1 << (mms->pcie_irq_base + 1)) | 2443d09c007SGerd Hoffmann (1 << (mms->pcie_irq_base + 2)) | 2453d09c007SGerd Hoffmann (1 << (mms->pcie_irq_base + 3))); 24664b070daSGerd Hoffmann } else { 24764b070daSGerd Hoffmann x86ms->pci_irq_mask = 0; 24824db877aSGerd Hoffmann } 24924db877aSGerd Hoffmann 250c300bbe8SXiaoyao Li if (x86ms->pic == ON_OFF_AUTO_ON || x86ms->pic == ON_OFF_AUTO_AUTO) { 2510ebf007dSSergio Lopez qemu_irq *i8259; 2520ebf007dSSergio Lopez 25389a289c7SPaolo Bonzini i8259 = i8259_init(isa_bus, x86_allocate_cpu_irq()); 2540ebf007dSSergio Lopez for (i = 0; i < ISA_NUM_IRQS; i++) { 2550ebf007dSSergio Lopez gsi_state->i8259_irq[i] = i8259[i]; 2560ebf007dSSergio Lopez } 2570ebf007dSSergio Lopez g_free(i8259); 2580ebf007dSSergio Lopez } 2590ebf007dSSergio Lopez 2609dee7e51SXiaoyao Li if (x86ms->pit == ON_OFF_AUTO_ON || x86ms->pit == ON_OFF_AUTO_AUTO) { 2610ebf007dSSergio Lopez if (kvm_pit_in_kernel()) { 2620ebf007dSSergio Lopez kvm_pit_init(isa_bus, 0x40); 2630ebf007dSSergio Lopez } else { 2640ebf007dSSergio Lopez i8254_pit_init(isa_bus, 0x40, 0, NULL); 2650ebf007dSSergio Lopez } 2660ebf007dSSergio Lopez } 2670ebf007dSSergio Lopez 2680ebf007dSSergio Lopez if (mms->rtc == ON_OFF_AUTO_ON || 2690ebf007dSSergio Lopez (mms->rtc == ON_OFF_AUTO_AUTO && !kvm_enabled())) { 2700ebf007dSSergio Lopez rtc_state = mc146818_rtc_init(isa_bus, 2000, NULL); 2710ebf007dSSergio Lopez microvm_set_rtc(mms, rtc_state); 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; 2817d435078SPaolo Bonzini x86_bios_rom_init(MACHINE(mms), 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) { 333ffe2d238SJason A. Donenfeld x86_load_linux(x86ms, fw_cfg, 0, true, false); 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; 381eac7a779SJason A. Donenfeld char *cmdline, *existing_cmdline; 382eac7a779SJason A. Donenfeld size_t len; 3830ebf007dSSergio Lopez 3840ebf007dSSergio Lopez /* 3850ebf007dSSergio Lopez * Find MMIO transports with attached devices, and add them to the kernel 3860ebf007dSSergio Lopez * command line. 3870ebf007dSSergio Lopez * 3880ebf007dSSergio Lopez * Yes, this is a hack, but one that heavily improves the UX without 3890ebf007dSSergio Lopez * introducing any significant issues. 3900ebf007dSSergio Lopez */ 391eac7a779SJason A. Donenfeld existing_cmdline = fw_cfg_read_bytes_ptr(x86ms->fw_cfg, FW_CFG_CMDLINE_DATA); 392eac7a779SJason A. Donenfeld cmdline = g_strdup(existing_cmdline); 3930ebf007dSSergio Lopez bus = sysbus_get_default(); 3940ebf007dSSergio Lopez QTAILQ_FOREACH(kid, &bus->children, sibling) { 3950ebf007dSSergio Lopez DeviceState *dev = kid->child; 3960ebf007dSSergio Lopez ObjectClass *class = object_get_class(OBJECT(dev)); 3970ebf007dSSergio Lopez 3980ebf007dSSergio Lopez if (class == object_class_by_name(TYPE_VIRTIO_MMIO)) { 3990ebf007dSSergio Lopez VirtIOMMIOProxy *mmio = VIRTIO_MMIO(OBJECT(dev)); 4000ebf007dSSergio Lopez VirtioBusState *mmio_virtio_bus = &mmio->bus; 4010ebf007dSSergio Lopez BusState *mmio_bus = &mmio_virtio_bus->parent_obj; 4020ebf007dSSergio Lopez 4030ebf007dSSergio Lopez if (!QTAILQ_EMPTY(&mmio_bus->children)) { 404d4e9d577SGerd Hoffmann gchar *mmio_cmdline = microvm_get_mmio_cmdline 405d4e9d577SGerd Hoffmann (mmio_bus->name, mms->virtio_irq_base); 4060ebf007dSSergio Lopez if (mmio_cmdline) { 4070ebf007dSSergio Lopez char *newcmd = g_strjoin(NULL, cmdline, mmio_cmdline, NULL); 4080ebf007dSSergio Lopez g_free(mmio_cmdline); 4090ebf007dSSergio Lopez g_free(cmdline); 4100ebf007dSSergio Lopez cmdline = newcmd; 4110ebf007dSSergio Lopez } 4120ebf007dSSergio Lopez } 4130ebf007dSSergio Lopez } 4140ebf007dSSergio Lopez } 4150ebf007dSSergio Lopez 416eac7a779SJason A. Donenfeld len = strlen(cmdline); 417eac7a779SJason A. Donenfeld if (len > VIRTIO_CMDLINE_TOTAL_MAX_LEN + strlen(existing_cmdline)) { 418eac7a779SJason A. Donenfeld fprintf(stderr, "qemu: virtio mmio cmdline too large, skipping\n"); 419eac7a779SJason A. Donenfeld } else { 420eac7a779SJason A. Donenfeld memcpy(existing_cmdline, cmdline, len + 1); 421eac7a779SJason A. Donenfeld } 422c3157b74SSergio Lopez g_free(cmdline); 4230ebf007dSSergio Lopez } 4240ebf007dSSergio Lopez 425e3ab9873SGerd Hoffmann static void microvm_device_pre_plug_cb(HotplugHandler *hotplug_dev, 426e3ab9873SGerd Hoffmann DeviceState *dev, Error **errp) 427e3ab9873SGerd Hoffmann { 4288c2d9f9aSGerd Hoffmann X86CPU *cpu = X86_CPU(dev); 4298c2d9f9aSGerd Hoffmann 4308c2d9f9aSGerd Hoffmann cpu->host_phys_bits = true; /* need reliable phys-bits */ 431e3ab9873SGerd Hoffmann x86_cpu_pre_plug(hotplug_dev, dev, errp); 432e3ab9873SGerd Hoffmann } 433e3ab9873SGerd Hoffmann 434e3ab9873SGerd Hoffmann static void microvm_device_plug_cb(HotplugHandler *hotplug_dev, 435e3ab9873SGerd Hoffmann DeviceState *dev, Error **errp) 436e3ab9873SGerd Hoffmann { 437e3ab9873SGerd Hoffmann x86_cpu_plug(hotplug_dev, dev, errp); 438e3ab9873SGerd Hoffmann } 439e3ab9873SGerd Hoffmann 440e3ab9873SGerd Hoffmann static void microvm_device_unplug_request_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 void microvm_device_unplug_cb(HotplugHandler *hotplug_dev, 447e3ab9873SGerd Hoffmann DeviceState *dev, Error **errp) 448e3ab9873SGerd Hoffmann { 449e3ab9873SGerd Hoffmann error_setg(errp, "unplug not supported by microvm"); 450e3ab9873SGerd Hoffmann } 451e3ab9873SGerd Hoffmann 452e3ab9873SGerd Hoffmann static HotplugHandler *microvm_get_hotplug_handler(MachineState *machine, 453e3ab9873SGerd Hoffmann DeviceState *dev) 454e3ab9873SGerd Hoffmann { 455e3ab9873SGerd Hoffmann if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { 456e3ab9873SGerd Hoffmann return HOTPLUG_HANDLER(machine); 457e3ab9873SGerd Hoffmann } 458e3ab9873SGerd Hoffmann return NULL; 459e3ab9873SGerd Hoffmann } 460e3ab9873SGerd Hoffmann 4610ebf007dSSergio Lopez static void microvm_machine_state_init(MachineState *machine) 4620ebf007dSSergio Lopez { 4630ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(machine); 4640ebf007dSSergio Lopez X86MachineState *x86ms = X86_MACHINE(machine); 4650ebf007dSSergio Lopez 4660ebf007dSSergio Lopez microvm_memory_init(mms); 4670ebf007dSSergio Lopez 4680ebf007dSSergio Lopez x86_cpus_init(x86ms, CPU_VERSION_LATEST); 4690ebf007dSSergio Lopez 4700ebf007dSSergio Lopez microvm_devices_init(mms); 4710ebf007dSSergio Lopez } 4720ebf007dSSergio Lopez 4737966d70fSJason A. Donenfeld static void microvm_machine_reset(MachineState *machine, ShutdownCause reason) 4740ebf007dSSergio Lopez { 4750ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(machine); 4760ebf007dSSergio Lopez CPUState *cs; 4770ebf007dSSergio Lopez X86CPU *cpu; 4780ebf007dSSergio Lopez 479f6f7e2d8SGerd Hoffmann if (!x86_machine_is_acpi_enabled(X86_MACHINE(machine)) && 480f6f7e2d8SGerd Hoffmann machine->kernel_filename != NULL && 4810ebf007dSSergio Lopez mms->auto_kernel_cmdline && !mms->kernel_cmdline_fixed) { 4820ebf007dSSergio Lopez microvm_fix_kernel_cmdline(machine); 4830ebf007dSSergio Lopez mms->kernel_cmdline_fixed = true; 4840ebf007dSSergio Lopez } 4850ebf007dSSergio Lopez 4867966d70fSJason A. Donenfeld qemu_devices_reset(reason); 4870ebf007dSSergio Lopez 4880ebf007dSSergio Lopez CPU_FOREACH(cs) { 4890ebf007dSSergio Lopez cpu = X86_CPU(cs); 4900ebf007dSSergio Lopez 491ec19444aSMaciej S. Szmigiero x86_cpu_after_reset(cpu); 4920ebf007dSSergio Lopez } 4930ebf007dSSergio Lopez } 4940ebf007dSSergio Lopez 4950ebf007dSSergio Lopez static void microvm_machine_get_rtc(Object *obj, Visitor *v, const char *name, 4960ebf007dSSergio Lopez void *opaque, Error **errp) 4970ebf007dSSergio Lopez { 4980ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 4990ebf007dSSergio Lopez OnOffAuto rtc = mms->rtc; 5000ebf007dSSergio Lopez 5010ebf007dSSergio Lopez visit_type_OnOffAuto(v, name, &rtc, errp); 5020ebf007dSSergio Lopez } 5030ebf007dSSergio Lopez 5040ebf007dSSergio Lopez static void microvm_machine_set_rtc(Object *obj, Visitor *v, const char *name, 5050ebf007dSSergio Lopez void *opaque, Error **errp) 5060ebf007dSSergio Lopez { 5070ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5080ebf007dSSergio Lopez 5090ebf007dSSergio Lopez visit_type_OnOffAuto(v, name, &mms->rtc, errp); 5100ebf007dSSergio Lopez } 5110ebf007dSSergio Lopez 51224db877aSGerd Hoffmann static void microvm_machine_get_pcie(Object *obj, Visitor *v, const char *name, 51324db877aSGerd Hoffmann void *opaque, Error **errp) 51424db877aSGerd Hoffmann { 51524db877aSGerd Hoffmann MicrovmMachineState *mms = MICROVM_MACHINE(obj); 51624db877aSGerd Hoffmann OnOffAuto pcie = mms->pcie; 51724db877aSGerd Hoffmann 51824db877aSGerd Hoffmann visit_type_OnOffAuto(v, name, &pcie, errp); 51924db877aSGerd Hoffmann } 52024db877aSGerd Hoffmann 52124db877aSGerd Hoffmann static void microvm_machine_set_pcie(Object *obj, Visitor *v, const char *name, 52224db877aSGerd Hoffmann void *opaque, Error **errp) 52324db877aSGerd Hoffmann { 52424db877aSGerd Hoffmann MicrovmMachineState *mms = MICROVM_MACHINE(obj); 52524db877aSGerd Hoffmann 52624db877aSGerd Hoffmann visit_type_OnOffAuto(v, name, &mms->pcie, errp); 52724db877aSGerd Hoffmann } 52824db877aSGerd Hoffmann 5294d01b899SGerd Hoffmann static void microvm_machine_get_ioapic2(Object *obj, Visitor *v, const char *name, 5304d01b899SGerd Hoffmann void *opaque, Error **errp) 5314d01b899SGerd Hoffmann { 5324d01b899SGerd Hoffmann MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5334d01b899SGerd Hoffmann OnOffAuto ioapic2 = mms->ioapic2; 5344d01b899SGerd Hoffmann 5354d01b899SGerd Hoffmann visit_type_OnOffAuto(v, name, &ioapic2, errp); 5364d01b899SGerd Hoffmann } 5374d01b899SGerd Hoffmann 5384d01b899SGerd Hoffmann static void microvm_machine_set_ioapic2(Object *obj, Visitor *v, const char *name, 5394d01b899SGerd Hoffmann void *opaque, Error **errp) 5404d01b899SGerd Hoffmann { 5414d01b899SGerd Hoffmann MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5424d01b899SGerd Hoffmann 5434d01b899SGerd Hoffmann visit_type_OnOffAuto(v, name, &mms->ioapic2, errp); 5444d01b899SGerd Hoffmann } 5454d01b899SGerd Hoffmann 5460ebf007dSSergio Lopez static bool microvm_machine_get_isa_serial(Object *obj, Error **errp) 5470ebf007dSSergio Lopez { 5480ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5490ebf007dSSergio Lopez 5500ebf007dSSergio Lopez return mms->isa_serial; 5510ebf007dSSergio Lopez } 5520ebf007dSSergio Lopez 5530ebf007dSSergio Lopez static void microvm_machine_set_isa_serial(Object *obj, bool value, 5540ebf007dSSergio Lopez Error **errp) 5550ebf007dSSergio Lopez { 5560ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5570ebf007dSSergio Lopez 5580ebf007dSSergio Lopez mms->isa_serial = value; 5590ebf007dSSergio Lopez } 5600ebf007dSSergio Lopez 5610ebf007dSSergio Lopez static bool microvm_machine_get_option_roms(Object *obj, Error **errp) 5620ebf007dSSergio Lopez { 5630ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5640ebf007dSSergio Lopez 5650ebf007dSSergio Lopez return mms->option_roms; 5660ebf007dSSergio Lopez } 5670ebf007dSSergio Lopez 5680ebf007dSSergio Lopez static void microvm_machine_set_option_roms(Object *obj, bool value, 5690ebf007dSSergio Lopez Error **errp) 5700ebf007dSSergio Lopez { 5710ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5720ebf007dSSergio Lopez 5730ebf007dSSergio Lopez mms->option_roms = value; 5740ebf007dSSergio Lopez } 5750ebf007dSSergio Lopez 5760ebf007dSSergio Lopez static bool microvm_machine_get_auto_kernel_cmdline(Object *obj, Error **errp) 5770ebf007dSSergio Lopez { 5780ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5790ebf007dSSergio Lopez 5800ebf007dSSergio Lopez return mms->auto_kernel_cmdline; 5810ebf007dSSergio Lopez } 5820ebf007dSSergio Lopez 5830ebf007dSSergio Lopez static void microvm_machine_set_auto_kernel_cmdline(Object *obj, bool value, 5840ebf007dSSergio Lopez Error **errp) 5850ebf007dSSergio Lopez { 5860ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5870ebf007dSSergio Lopez 5880ebf007dSSergio Lopez mms->auto_kernel_cmdline = value; 5890ebf007dSSergio Lopez } 5900ebf007dSSergio Lopez 5918045df14SGerd Hoffmann static void microvm_machine_done(Notifier *notifier, void *data) 5928045df14SGerd Hoffmann { 5938045df14SGerd Hoffmann MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState, 5948045df14SGerd Hoffmann machine_done); 5958045df14SGerd Hoffmann 5968045df14SGerd Hoffmann acpi_setup_microvm(mms); 597f5918a99SGerd Hoffmann dt_setup_microvm(mms); 5988045df14SGerd Hoffmann } 5998045df14SGerd Hoffmann 6008045df14SGerd Hoffmann static void microvm_powerdown_req(Notifier *notifier, void *data) 6018045df14SGerd Hoffmann { 6028045df14SGerd Hoffmann MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState, 6038045df14SGerd Hoffmann powerdown_req); 60450aef131SGerd Hoffmann X86MachineState *x86ms = X86_MACHINE(mms); 6058045df14SGerd Hoffmann 60650aef131SGerd Hoffmann if (x86ms->acpi_dev) { 60750aef131SGerd Hoffmann Object *obj = OBJECT(x86ms->acpi_dev); 6088045df14SGerd Hoffmann AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj); 60950aef131SGerd Hoffmann adevc->send_event(ACPI_DEVICE_IF(x86ms->acpi_dev), 61050aef131SGerd Hoffmann ACPI_POWER_DOWN_STATUS); 6118045df14SGerd Hoffmann } 6128045df14SGerd Hoffmann } 6138045df14SGerd Hoffmann 6140ebf007dSSergio Lopez static void microvm_machine_initfn(Object *obj) 6150ebf007dSSergio Lopez { 6160ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 6170ebf007dSSergio Lopez 6180ebf007dSSergio Lopez /* Configuration */ 6190ebf007dSSergio Lopez mms->rtc = ON_OFF_AUTO_AUTO; 62024db877aSGerd Hoffmann mms->pcie = ON_OFF_AUTO_AUTO; 6214d01b899SGerd Hoffmann mms->ioapic2 = ON_OFF_AUTO_AUTO; 6220ebf007dSSergio Lopez mms->isa_serial = true; 6230ebf007dSSergio Lopez mms->option_roms = true; 6240ebf007dSSergio Lopez mms->auto_kernel_cmdline = true; 6250ebf007dSSergio Lopez 6260ebf007dSSergio Lopez /* State */ 6270ebf007dSSergio Lopez mms->kernel_cmdline_fixed = false; 6288045df14SGerd Hoffmann 6298045df14SGerd Hoffmann mms->machine_done.notify = microvm_machine_done; 6308045df14SGerd Hoffmann qemu_add_machine_init_done_notifier(&mms->machine_done); 6318045df14SGerd Hoffmann mms->powerdown_req.notify = microvm_powerdown_req; 6328045df14SGerd Hoffmann qemu_register_powerdown_notifier(&mms->powerdown_req); 6330ebf007dSSergio Lopez } 6340ebf007dSSergio Lopez 6353ef1497bSGerd Hoffmann GlobalProperty microvm_properties[] = { 6363ef1497bSGerd Hoffmann /* 6373ef1497bSGerd Hoffmann * pcie host bridge (gpex) on microvm has no io address window, 6383ef1497bSGerd Hoffmann * so reserving io space is not going to work. Turn it off. 6393ef1497bSGerd Hoffmann */ 6403ef1497bSGerd Hoffmann { "pcie-root-port", "io-reserve", "0" }, 6413ef1497bSGerd Hoffmann }; 6423ef1497bSGerd Hoffmann 6430ebf007dSSergio Lopez static void microvm_class_init(ObjectClass *oc, void *data) 6440ebf007dSSergio Lopez { 645f014c974SPaolo Bonzini X86MachineClass *x86mc = X86_MACHINE_CLASS(oc); 6460ebf007dSSergio Lopez MachineClass *mc = MACHINE_CLASS(oc); 647e3ab9873SGerd Hoffmann HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); 6480ebf007dSSergio Lopez 6490ebf007dSSergio Lopez mc->init = microvm_machine_state_init; 6500ebf007dSSergio Lopez 6510ebf007dSSergio Lopez mc->family = "microvm_i386"; 6520ebf007dSSergio Lopez mc->desc = "microvm (i386)"; 6530ebf007dSSergio Lopez mc->units_per_default_bus = 1; 6540ebf007dSSergio Lopez mc->no_floppy = 1; 6550ebf007dSSergio Lopez mc->max_cpus = 288; 6560ebf007dSSergio Lopez mc->has_hotpluggable_cpus = false; 6570ebf007dSSergio Lopez mc->auto_enable_numa_with_memhp = false; 658195784a0SDavid Hildenbrand mc->auto_enable_numa_with_memdev = false; 6590ebf007dSSergio Lopez mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE; 6600ebf007dSSergio Lopez mc->nvdimm_supported = false; 6619ad54686SIgor Mammedov mc->default_ram_id = "microvm.ram"; 6620ebf007dSSergio Lopez 6630ebf007dSSergio Lopez /* Avoid relying too much on kernel components */ 6640ebf007dSSergio Lopez mc->default_kernel_irqchip_split = true; 6650ebf007dSSergio Lopez 6660ebf007dSSergio Lopez /* Machine class handlers */ 6670ebf007dSSergio Lopez mc->reset = microvm_machine_reset; 6680ebf007dSSergio Lopez 669e3ab9873SGerd Hoffmann /* hotplug (for cpu coldplug) */ 670e3ab9873SGerd Hoffmann mc->get_hotplug_handler = microvm_get_hotplug_handler; 671e3ab9873SGerd Hoffmann hc->pre_plug = microvm_device_pre_plug_cb; 672e3ab9873SGerd Hoffmann hc->plug = microvm_device_plug_cb; 673e3ab9873SGerd Hoffmann hc->unplug_request = microvm_device_unplug_request_cb; 674e3ab9873SGerd Hoffmann hc->unplug = microvm_device_unplug_cb; 675e3ab9873SGerd Hoffmann 676f014c974SPaolo Bonzini x86mc->fwcfg_dma_enabled = true; 677f014c974SPaolo Bonzini 6780ebf007dSSergio Lopez object_class_property_add(oc, MICROVM_MACHINE_RTC, "OnOffAuto", 6790ebf007dSSergio Lopez microvm_machine_get_rtc, 6800ebf007dSSergio Lopez microvm_machine_set_rtc, 681d2623129SMarkus Armbruster NULL, NULL); 6820ebf007dSSergio Lopez object_class_property_set_description(oc, MICROVM_MACHINE_RTC, 6837eecec7dSMarkus Armbruster "Enable MC146818 RTC"); 6840ebf007dSSergio Lopez 68524db877aSGerd Hoffmann object_class_property_add(oc, MICROVM_MACHINE_PCIE, "OnOffAuto", 68624db877aSGerd Hoffmann microvm_machine_get_pcie, 68724db877aSGerd Hoffmann microvm_machine_set_pcie, 68824db877aSGerd Hoffmann NULL, NULL); 68924db877aSGerd Hoffmann object_class_property_set_description(oc, MICROVM_MACHINE_PCIE, 69024db877aSGerd Hoffmann "Enable PCIe"); 69124db877aSGerd Hoffmann 6924d01b899SGerd Hoffmann object_class_property_add(oc, MICROVM_MACHINE_IOAPIC2, "OnOffAuto", 6934d01b899SGerd Hoffmann microvm_machine_get_ioapic2, 6944d01b899SGerd Hoffmann microvm_machine_set_ioapic2, 6954d01b899SGerd Hoffmann NULL, NULL); 6964d01b899SGerd Hoffmann object_class_property_set_description(oc, MICROVM_MACHINE_IOAPIC2, 6974d01b899SGerd Hoffmann "Enable second IO-APIC"); 6984d01b899SGerd Hoffmann 6990ebf007dSSergio Lopez object_class_property_add_bool(oc, MICROVM_MACHINE_ISA_SERIAL, 7000ebf007dSSergio Lopez microvm_machine_get_isa_serial, 701d2623129SMarkus Armbruster microvm_machine_set_isa_serial); 7020ebf007dSSergio Lopez object_class_property_set_description(oc, MICROVM_MACHINE_ISA_SERIAL, 7037eecec7dSMarkus Armbruster "Set off to disable the instantiation an ISA serial port"); 7040ebf007dSSergio Lopez 7050ebf007dSSergio Lopez object_class_property_add_bool(oc, MICROVM_MACHINE_OPTION_ROMS, 7060ebf007dSSergio Lopez microvm_machine_get_option_roms, 707d2623129SMarkus Armbruster microvm_machine_set_option_roms); 7080ebf007dSSergio Lopez object_class_property_set_description(oc, MICROVM_MACHINE_OPTION_ROMS, 7097eecec7dSMarkus Armbruster "Set off to disable loading option ROMs"); 7100ebf007dSSergio Lopez 7110ebf007dSSergio Lopez object_class_property_add_bool(oc, MICROVM_MACHINE_AUTO_KERNEL_CMDLINE, 7120ebf007dSSergio Lopez microvm_machine_get_auto_kernel_cmdline, 713d2623129SMarkus Armbruster microvm_machine_set_auto_kernel_cmdline); 7140ebf007dSSergio Lopez object_class_property_set_description(oc, 7150ebf007dSSergio Lopez MICROVM_MACHINE_AUTO_KERNEL_CMDLINE, 7167eecec7dSMarkus Armbruster "Set off to disable adding virtio-mmio devices to the kernel cmdline"); 71763bcfe7bSGerd Hoffmann 71863bcfe7bSGerd Hoffmann machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); 7193ef1497bSGerd Hoffmann 7203ef1497bSGerd Hoffmann compat_props_add(mc->compat_props, microvm_properties, 7213ef1497bSGerd Hoffmann G_N_ELEMENTS(microvm_properties)); 7220ebf007dSSergio Lopez } 7230ebf007dSSergio Lopez 7240ebf007dSSergio Lopez static const TypeInfo microvm_machine_info = { 7250ebf007dSSergio Lopez .name = TYPE_MICROVM_MACHINE, 7260ebf007dSSergio Lopez .parent = TYPE_X86_MACHINE, 7270ebf007dSSergio Lopez .instance_size = sizeof(MicrovmMachineState), 7280ebf007dSSergio Lopez .instance_init = microvm_machine_initfn, 7290ebf007dSSergio Lopez .class_size = sizeof(MicrovmMachineClass), 7300ebf007dSSergio Lopez .class_init = microvm_class_init, 7310ebf007dSSergio Lopez .interfaces = (InterfaceInfo[]) { 732e3ab9873SGerd Hoffmann { TYPE_HOTPLUG_HANDLER }, 7330ebf007dSSergio Lopez { } 7340ebf007dSSergio Lopez }, 7350ebf007dSSergio Lopez }; 7360ebf007dSSergio Lopez 7370ebf007dSSergio Lopez static void microvm_machine_init(void) 7380ebf007dSSergio Lopez { 7390ebf007dSSergio Lopez type_register_static(µvm_machine_info); 7400ebf007dSSergio Lopez } 7410ebf007dSSergio Lopez type_init(microvm_machine_init); 742