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" 310ebf007dSSergio Lopez 320ebf007dSSergio Lopez #include "hw/loader.h" 330ebf007dSSergio Lopez #include "hw/irq.h" 340ebf007dSSergio Lopez #include "hw/kvm/clock.h" 350ebf007dSSergio Lopez #include "hw/i386/microvm.h" 360ebf007dSSergio Lopez #include "hw/i386/x86.h" 370ebf007dSSergio Lopez #include "target/i386/cpu.h" 38852c27e2SPaolo Bonzini #include "hw/intc/i8259.h" 390ebf007dSSergio Lopez #include "hw/timer/i8254.h" 40673652a7SPaolo Bonzini #include "hw/rtc/mc146818rtc.h" 410ebf007dSSergio Lopez #include "hw/char/serial.h" 4263bcfe7bSGerd Hoffmann #include "hw/display/ramfb.h" 430ebf007dSSergio Lopez #include "hw/i386/topology.h" 440ebf007dSSergio Lopez #include "hw/i386/e820_memory_layout.h" 450ebf007dSSergio Lopez #include "hw/i386/fw_cfg.h" 460ebf007dSSergio Lopez #include "hw/virtio/virtio-mmio.h" 478045df14SGerd Hoffmann #include "hw/acpi/acpi.h" 488045df14SGerd Hoffmann #include "hw/acpi/generic_event_device.h" 4924db877aSGerd Hoffmann #include "hw/pci-host/gpex.h" 50*d4a42e85SGerd Hoffmann #include "hw/usb/xhci.h" 510ebf007dSSergio Lopez 520ebf007dSSergio Lopez #include "cpu.h" 530ebf007dSSergio Lopez #include "elf.h" 540ebf007dSSergio Lopez #include "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 990ebf007dSSergio Lopez static void microvm_gsi_handler(void *opaque, int n, int level) 1000ebf007dSSergio Lopez { 1010ebf007dSSergio Lopez GSIState *s = opaque; 1020ebf007dSSergio Lopez 1030ebf007dSSergio Lopez qemu_set_irq(s->ioapic_irq[n], level); 1040ebf007dSSergio Lopez } 1050ebf007dSSergio Lopez 10624db877aSGerd Hoffmann static void create_gpex(MicrovmMachineState *mms) 10724db877aSGerd Hoffmann { 10824db877aSGerd Hoffmann X86MachineState *x86ms = X86_MACHINE(mms); 10924db877aSGerd Hoffmann MemoryRegion *mmio32_alias; 11024db877aSGerd Hoffmann MemoryRegion *mmio64_alias; 11124db877aSGerd Hoffmann MemoryRegion *mmio_reg; 11224db877aSGerd Hoffmann MemoryRegion *ecam_alias; 11324db877aSGerd Hoffmann MemoryRegion *ecam_reg; 11424db877aSGerd Hoffmann DeviceState *dev; 11524db877aSGerd Hoffmann int i; 11624db877aSGerd Hoffmann 11724db877aSGerd Hoffmann dev = qdev_new(TYPE_GPEX_HOST); 11824db877aSGerd Hoffmann sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); 11924db877aSGerd Hoffmann 12024db877aSGerd Hoffmann /* Map only the first size_ecam bytes of ECAM space */ 12124db877aSGerd Hoffmann ecam_alias = g_new0(MemoryRegion, 1); 12224db877aSGerd Hoffmann ecam_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); 12324db877aSGerd Hoffmann memory_region_init_alias(ecam_alias, OBJECT(dev), "pcie-ecam", 12424db877aSGerd Hoffmann ecam_reg, 0, mms->gpex.ecam.size); 12524db877aSGerd Hoffmann memory_region_add_subregion(get_system_memory(), 12624db877aSGerd Hoffmann mms->gpex.ecam.base, ecam_alias); 12724db877aSGerd Hoffmann 12824db877aSGerd Hoffmann /* Map the MMIO window into system address space so as to expose 12924db877aSGerd Hoffmann * the section of PCI MMIO space which starts at the same base address 13024db877aSGerd Hoffmann * (ie 1:1 mapping for that part of PCI MMIO space visible through 13124db877aSGerd Hoffmann * the window). 13224db877aSGerd Hoffmann */ 13324db877aSGerd Hoffmann mmio_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1); 13424db877aSGerd Hoffmann if (mms->gpex.mmio32.size) { 13524db877aSGerd Hoffmann mmio32_alias = g_new0(MemoryRegion, 1); 13624db877aSGerd Hoffmann memory_region_init_alias(mmio32_alias, OBJECT(dev), "pcie-mmio32", mmio_reg, 13724db877aSGerd Hoffmann mms->gpex.mmio32.base, mms->gpex.mmio32.size); 13824db877aSGerd Hoffmann memory_region_add_subregion(get_system_memory(), 13924db877aSGerd Hoffmann mms->gpex.mmio32.base, mmio32_alias); 14024db877aSGerd Hoffmann } 14124db877aSGerd Hoffmann if (mms->gpex.mmio64.size) { 14224db877aSGerd Hoffmann mmio64_alias = g_new0(MemoryRegion, 1); 14324db877aSGerd Hoffmann memory_region_init_alias(mmio64_alias, OBJECT(dev), "pcie-mmio64", mmio_reg, 14424db877aSGerd Hoffmann mms->gpex.mmio64.base, mms->gpex.mmio64.size); 14524db877aSGerd Hoffmann memory_region_add_subregion(get_system_memory(), 14624db877aSGerd Hoffmann mms->gpex.mmio64.base, mmio64_alias); 14724db877aSGerd Hoffmann } 14824db877aSGerd Hoffmann 14924db877aSGerd Hoffmann for (i = 0; i < GPEX_NUM_IRQS; i++) { 15024db877aSGerd Hoffmann sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, 15124db877aSGerd Hoffmann x86ms->gsi[mms->gpex.irq + i]); 15224db877aSGerd Hoffmann } 15324db877aSGerd Hoffmann } 15424db877aSGerd Hoffmann 1550ebf007dSSergio Lopez static void microvm_devices_init(MicrovmMachineState *mms) 1560ebf007dSSergio Lopez { 1570ebf007dSSergio Lopez X86MachineState *x86ms = X86_MACHINE(mms); 1580ebf007dSSergio Lopez ISABus *isa_bus; 1590ebf007dSSergio Lopez ISADevice *rtc_state; 1600ebf007dSSergio Lopez GSIState *gsi_state; 1610ebf007dSSergio Lopez int i; 1620ebf007dSSergio Lopez 1630ebf007dSSergio Lopez /* Core components */ 1640ebf007dSSergio Lopez 1650ebf007dSSergio Lopez gsi_state = g_malloc0(sizeof(*gsi_state)); 1660ebf007dSSergio Lopez if (mms->pic == ON_OFF_AUTO_ON || mms->pic == ON_OFF_AUTO_AUTO) { 1670ebf007dSSergio Lopez x86ms->gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS); 1680ebf007dSSergio Lopez } else { 1690ebf007dSSergio Lopez x86ms->gsi = qemu_allocate_irqs(microvm_gsi_handler, 1700ebf007dSSergio Lopez gsi_state, GSI_NUM_PINS); 1710ebf007dSSergio Lopez } 1720ebf007dSSergio Lopez 1730ebf007dSSergio Lopez isa_bus = isa_bus_new(NULL, get_system_memory(), get_system_io(), 1740ebf007dSSergio Lopez &error_abort); 1750ebf007dSSergio Lopez isa_bus_irqs(isa_bus, x86ms->gsi); 1760ebf007dSSergio Lopez 1770ebf007dSSergio Lopez ioapic_init_gsi(gsi_state, "machine"); 1780ebf007dSSergio Lopez 1798700a984SVitaly Kuznetsov kvmclock_create(true); 1800ebf007dSSergio Lopez 18155c4b069SGerd Hoffmann mms->virtio_irq_base = x86_machine_is_acpi_enabled(x86ms) ? 16 : 5; 1820ebf007dSSergio Lopez for (i = 0; i < VIRTIO_NUM_TRANSPORTS; i++) { 1830ebf007dSSergio Lopez sysbus_create_simple("virtio-mmio", 1840ebf007dSSergio Lopez VIRTIO_MMIO_BASE + i * 512, 185d4e9d577SGerd Hoffmann x86ms->gsi[mms->virtio_irq_base + i]); 1860ebf007dSSergio Lopez } 1870ebf007dSSergio Lopez 1880ebf007dSSergio Lopez /* Optional and legacy devices */ 1898045df14SGerd Hoffmann if (x86_machine_is_acpi_enabled(x86ms)) { 1908045df14SGerd Hoffmann DeviceState *dev = qdev_new(TYPE_ACPI_GED_X86); 1918045df14SGerd Hoffmann qdev_prop_set_uint32(dev, "ged-event", ACPI_GED_PWR_DOWN_EVT); 1928045df14SGerd Hoffmann sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, GED_MMIO_BASE); 1938045df14SGerd Hoffmann /* sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, GED_MMIO_BASE_MEMHP); */ 1948045df14SGerd Hoffmann sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, GED_MMIO_BASE_REGS); 1958045df14SGerd Hoffmann sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, 1968045df14SGerd Hoffmann x86ms->gsi[GED_MMIO_IRQ]); 1978045df14SGerd Hoffmann sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal); 19850aef131SGerd Hoffmann x86ms->acpi_dev = HOTPLUG_HANDLER(dev); 1998045df14SGerd Hoffmann } 2000ebf007dSSergio Lopez 201*d4a42e85SGerd Hoffmann if (x86_machine_is_acpi_enabled(x86ms) && machine_usb(MACHINE(mms))) { 202*d4a42e85SGerd Hoffmann DeviceState *dev = qdev_new(TYPE_XHCI_SYSBUS); 203*d4a42e85SGerd Hoffmann qdev_prop_set_uint32(dev, "intrs", 1); 204*d4a42e85SGerd Hoffmann qdev_prop_set_uint32(dev, "slots", XHCI_MAXSLOTS); 205*d4a42e85SGerd Hoffmann qdev_prop_set_uint32(dev, "p2", 8); 206*d4a42e85SGerd Hoffmann qdev_prop_set_uint32(dev, "p3", 8); 207*d4a42e85SGerd Hoffmann sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal); 208*d4a42e85SGerd Hoffmann sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, MICROVM_XHCI_BASE); 209*d4a42e85SGerd Hoffmann sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, 210*d4a42e85SGerd Hoffmann x86ms->gsi[MICROVM_XHCI_IRQ]); 211*d4a42e85SGerd Hoffmann } 212*d4a42e85SGerd Hoffmann 21324db877aSGerd Hoffmann if (x86_machine_is_acpi_enabled(x86ms) && mms->pcie == ON_OFF_AUTO_ON) { 2148c2d9f9aSGerd Hoffmann /* use topmost 25% of the address space available */ 2158c2d9f9aSGerd Hoffmann hwaddr phys_size = (hwaddr)1 << X86_CPU(first_cpu)->phys_bits; 2168c2d9f9aSGerd Hoffmann if (phys_size > 0x1000000ll) { 2178c2d9f9aSGerd Hoffmann mms->gpex.mmio64.size = phys_size / 4; 2188c2d9f9aSGerd Hoffmann mms->gpex.mmio64.base = phys_size - mms->gpex.mmio64.size; 2198c2d9f9aSGerd Hoffmann } 22024db877aSGerd Hoffmann mms->gpex.mmio32.base = PCIE_MMIO_BASE; 22124db877aSGerd Hoffmann mms->gpex.mmio32.size = PCIE_MMIO_SIZE; 22224db877aSGerd Hoffmann mms->gpex.ecam.base = PCIE_ECAM_BASE; 22324db877aSGerd Hoffmann mms->gpex.ecam.size = PCIE_ECAM_SIZE; 22424db877aSGerd Hoffmann mms->gpex.irq = PCIE_IRQ_BASE; 22524db877aSGerd Hoffmann create_gpex(mms); 22664b070daSGerd Hoffmann x86ms->pci_irq_mask = ((1 << (PCIE_IRQ_BASE + 0)) | 22764b070daSGerd Hoffmann (1 << (PCIE_IRQ_BASE + 1)) | 22864b070daSGerd Hoffmann (1 << (PCIE_IRQ_BASE + 2)) | 22964b070daSGerd Hoffmann (1 << (PCIE_IRQ_BASE + 3))); 23064b070daSGerd Hoffmann } else { 23164b070daSGerd Hoffmann x86ms->pci_irq_mask = 0; 23224db877aSGerd Hoffmann } 23324db877aSGerd Hoffmann 2340ebf007dSSergio Lopez if (mms->pic == ON_OFF_AUTO_ON || mms->pic == ON_OFF_AUTO_AUTO) { 2350ebf007dSSergio Lopez qemu_irq *i8259; 2360ebf007dSSergio Lopez 23789a289c7SPaolo Bonzini i8259 = i8259_init(isa_bus, x86_allocate_cpu_irq()); 2380ebf007dSSergio Lopez for (i = 0; i < ISA_NUM_IRQS; i++) { 2390ebf007dSSergio Lopez gsi_state->i8259_irq[i] = i8259[i]; 2400ebf007dSSergio Lopez } 2410ebf007dSSergio Lopez g_free(i8259); 2420ebf007dSSergio Lopez } 2430ebf007dSSergio Lopez 2440ebf007dSSergio Lopez if (mms->pit == ON_OFF_AUTO_ON || mms->pit == ON_OFF_AUTO_AUTO) { 2450ebf007dSSergio Lopez if (kvm_pit_in_kernel()) { 2460ebf007dSSergio Lopez kvm_pit_init(isa_bus, 0x40); 2470ebf007dSSergio Lopez } else { 2480ebf007dSSergio Lopez i8254_pit_init(isa_bus, 0x40, 0, NULL); 2490ebf007dSSergio Lopez } 2500ebf007dSSergio Lopez } 2510ebf007dSSergio Lopez 2520ebf007dSSergio Lopez if (mms->rtc == ON_OFF_AUTO_ON || 2530ebf007dSSergio Lopez (mms->rtc == ON_OFF_AUTO_AUTO && !kvm_enabled())) { 2540ebf007dSSergio Lopez rtc_state = mc146818_rtc_init(isa_bus, 2000, NULL); 2550ebf007dSSergio Lopez microvm_set_rtc(mms, rtc_state); 2560ebf007dSSergio Lopez } 2570ebf007dSSergio Lopez 2580ebf007dSSergio Lopez if (mms->isa_serial) { 2590ebf007dSSergio Lopez serial_hds_isa_init(isa_bus, 0, 1); 2600ebf007dSSergio Lopez } 2610ebf007dSSergio Lopez 2620ebf007dSSergio Lopez if (bios_name == NULL) { 26367eb6a40SGerd Hoffmann bios_name = x86_machine_is_acpi_enabled(x86ms) 26467eb6a40SGerd Hoffmann ? MICROVM_BIOS_FILENAME 26567eb6a40SGerd Hoffmann : MICROVM_QBOOT_FILENAME; 2660ebf007dSSergio Lopez } 2670ebf007dSSergio Lopez x86_bios_rom_init(get_system_memory(), true); 2680ebf007dSSergio Lopez } 2690ebf007dSSergio Lopez 2700ebf007dSSergio Lopez static void microvm_memory_init(MicrovmMachineState *mms) 2710ebf007dSSergio Lopez { 2720ebf007dSSergio Lopez MachineState *machine = MACHINE(mms); 2730ebf007dSSergio Lopez X86MachineState *x86ms = X86_MACHINE(mms); 2749ad54686SIgor Mammedov MemoryRegion *ram_below_4g, *ram_above_4g; 2750ebf007dSSergio Lopez MemoryRegion *system_memory = get_system_memory(); 2760ebf007dSSergio Lopez FWCfgState *fw_cfg; 277e289655cSGerd Hoffmann ram_addr_t lowmem = 0xc0000000; /* 3G */ 2780ebf007dSSergio Lopez int i; 2790ebf007dSSergio Lopez 2800ebf007dSSergio Lopez if (machine->ram_size > lowmem) { 2810ebf007dSSergio Lopez x86ms->above_4g_mem_size = machine->ram_size - lowmem; 2820ebf007dSSergio Lopez x86ms->below_4g_mem_size = lowmem; 2830ebf007dSSergio Lopez } else { 2840ebf007dSSergio Lopez x86ms->above_4g_mem_size = 0; 2850ebf007dSSergio Lopez x86ms->below_4g_mem_size = machine->ram_size; 2860ebf007dSSergio Lopez } 2870ebf007dSSergio Lopez 2880ebf007dSSergio Lopez ram_below_4g = g_malloc(sizeof(*ram_below_4g)); 2899ad54686SIgor Mammedov memory_region_init_alias(ram_below_4g, NULL, "ram-below-4g", machine->ram, 2900ebf007dSSergio Lopez 0, x86ms->below_4g_mem_size); 2910ebf007dSSergio Lopez memory_region_add_subregion(system_memory, 0, ram_below_4g); 2920ebf007dSSergio Lopez 2930ebf007dSSergio Lopez e820_add_entry(0, x86ms->below_4g_mem_size, E820_RAM); 2940ebf007dSSergio Lopez 2950ebf007dSSergio Lopez if (x86ms->above_4g_mem_size > 0) { 2960ebf007dSSergio Lopez ram_above_4g = g_malloc(sizeof(*ram_above_4g)); 2979ad54686SIgor Mammedov memory_region_init_alias(ram_above_4g, NULL, "ram-above-4g", 2989ad54686SIgor Mammedov machine->ram, 2990ebf007dSSergio Lopez x86ms->below_4g_mem_size, 3000ebf007dSSergio Lopez x86ms->above_4g_mem_size); 3010ebf007dSSergio Lopez memory_region_add_subregion(system_memory, 0x100000000ULL, 3020ebf007dSSergio Lopez ram_above_4g); 3030ebf007dSSergio Lopez e820_add_entry(0x100000000ULL, x86ms->above_4g_mem_size, E820_RAM); 3040ebf007dSSergio Lopez } 3050ebf007dSSergio Lopez 3060ebf007dSSergio Lopez fw_cfg = fw_cfg_init_io_dma(FW_CFG_IO_BASE, FW_CFG_IO_BASE + 4, 3070ebf007dSSergio Lopez &address_space_memory); 3080ebf007dSSergio Lopez 3090ebf007dSSergio Lopez fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, machine->smp.cpus); 3100ebf007dSSergio Lopez fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, machine->smp.max_cpus); 3110ebf007dSSergio Lopez fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)machine->ram_size); 312eafa0868SEduardo Habkost fw_cfg_add_i32(fw_cfg, FW_CFG_IRQ0_OVERRIDE, 1); 3130ebf007dSSergio Lopez fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, 3140ebf007dSSergio Lopez &e820_reserve, sizeof(e820_reserve)); 3150ebf007dSSergio Lopez fw_cfg_add_file(fw_cfg, "etc/e820", e820_table, 3160ebf007dSSergio Lopez sizeof(struct e820_entry) * e820_get_num_entries()); 3170ebf007dSSergio Lopez 3180ebf007dSSergio Lopez rom_set_fw(fw_cfg); 3190ebf007dSSergio Lopez 3200ebf007dSSergio Lopez if (machine->kernel_filename != NULL) { 3210ebf007dSSergio Lopez x86_load_linux(x86ms, fw_cfg, 0, true, true); 3220ebf007dSSergio Lopez } 3230ebf007dSSergio Lopez 3240ebf007dSSergio Lopez if (mms->option_roms) { 3250ebf007dSSergio Lopez for (i = 0; i < nb_option_roms; i++) { 3260ebf007dSSergio Lopez rom_add_option(option_rom[i].name, option_rom[i].bootindex); 3270ebf007dSSergio Lopez } 3280ebf007dSSergio Lopez } 3290ebf007dSSergio Lopez 3300ebf007dSSergio Lopez x86ms->fw_cfg = fw_cfg; 3310ebf007dSSergio Lopez x86ms->ioapic_as = &address_space_memory; 3320ebf007dSSergio Lopez } 3330ebf007dSSergio Lopez 334d4e9d577SGerd Hoffmann static gchar *microvm_get_mmio_cmdline(gchar *name, uint32_t virtio_irq_base) 3350ebf007dSSergio Lopez { 3360ebf007dSSergio Lopez gchar *cmdline; 3370ebf007dSSergio Lopez gchar *separator; 3380ebf007dSSergio Lopez long int index; 3390ebf007dSSergio Lopez int ret; 3400ebf007dSSergio Lopez 3410ebf007dSSergio Lopez separator = g_strrstr(name, "."); 3420ebf007dSSergio Lopez if (!separator) { 3430ebf007dSSergio Lopez return NULL; 3440ebf007dSSergio Lopez } 3450ebf007dSSergio Lopez 3460ebf007dSSergio Lopez if (qemu_strtol(separator + 1, NULL, 10, &index) != 0) { 3470ebf007dSSergio Lopez return NULL; 3480ebf007dSSergio Lopez } 3490ebf007dSSergio Lopez 3500ebf007dSSergio Lopez cmdline = g_malloc0(VIRTIO_CMDLINE_MAXLEN); 3510ebf007dSSergio Lopez ret = g_snprintf(cmdline, VIRTIO_CMDLINE_MAXLEN, 3520ebf007dSSergio Lopez " virtio_mmio.device=512@0x%lx:%ld", 3530ebf007dSSergio Lopez VIRTIO_MMIO_BASE + index * 512, 354d4e9d577SGerd Hoffmann virtio_irq_base + index); 3550ebf007dSSergio Lopez if (ret < 0 || ret >= VIRTIO_CMDLINE_MAXLEN) { 3560ebf007dSSergio Lopez g_free(cmdline); 3570ebf007dSSergio Lopez return NULL; 3580ebf007dSSergio Lopez } 3590ebf007dSSergio Lopez 3600ebf007dSSergio Lopez return cmdline; 3610ebf007dSSergio Lopez } 3620ebf007dSSergio Lopez 3630ebf007dSSergio Lopez static void microvm_fix_kernel_cmdline(MachineState *machine) 3640ebf007dSSergio Lopez { 3650ebf007dSSergio Lopez X86MachineState *x86ms = X86_MACHINE(machine); 366d4e9d577SGerd Hoffmann MicrovmMachineState *mms = MICROVM_MACHINE(machine); 3670ebf007dSSergio Lopez BusState *bus; 3680ebf007dSSergio Lopez BusChild *kid; 3690ebf007dSSergio Lopez char *cmdline; 3700ebf007dSSergio Lopez 3710ebf007dSSergio Lopez /* 3720ebf007dSSergio Lopez * Find MMIO transports with attached devices, and add them to the kernel 3730ebf007dSSergio Lopez * command line. 3740ebf007dSSergio Lopez * 3750ebf007dSSergio Lopez * Yes, this is a hack, but one that heavily improves the UX without 3760ebf007dSSergio Lopez * introducing any significant issues. 3770ebf007dSSergio Lopez */ 3780ebf007dSSergio Lopez cmdline = g_strdup(machine->kernel_cmdline); 3790ebf007dSSergio Lopez bus = sysbus_get_default(); 3800ebf007dSSergio Lopez QTAILQ_FOREACH(kid, &bus->children, sibling) { 3810ebf007dSSergio Lopez DeviceState *dev = kid->child; 3820ebf007dSSergio Lopez ObjectClass *class = object_get_class(OBJECT(dev)); 3830ebf007dSSergio Lopez 3840ebf007dSSergio Lopez if (class == object_class_by_name(TYPE_VIRTIO_MMIO)) { 3850ebf007dSSergio Lopez VirtIOMMIOProxy *mmio = VIRTIO_MMIO(OBJECT(dev)); 3860ebf007dSSergio Lopez VirtioBusState *mmio_virtio_bus = &mmio->bus; 3870ebf007dSSergio Lopez BusState *mmio_bus = &mmio_virtio_bus->parent_obj; 3880ebf007dSSergio Lopez 3890ebf007dSSergio Lopez if (!QTAILQ_EMPTY(&mmio_bus->children)) { 390d4e9d577SGerd Hoffmann gchar *mmio_cmdline = microvm_get_mmio_cmdline 391d4e9d577SGerd Hoffmann (mmio_bus->name, mms->virtio_irq_base); 3920ebf007dSSergio Lopez if (mmio_cmdline) { 3930ebf007dSSergio Lopez char *newcmd = g_strjoin(NULL, cmdline, mmio_cmdline, NULL); 3940ebf007dSSergio Lopez g_free(mmio_cmdline); 3950ebf007dSSergio Lopez g_free(cmdline); 3960ebf007dSSergio Lopez cmdline = newcmd; 3970ebf007dSSergio Lopez } 3980ebf007dSSergio Lopez } 3990ebf007dSSergio Lopez } 4000ebf007dSSergio Lopez } 4010ebf007dSSergio Lopez 4020ebf007dSSergio Lopez fw_cfg_modify_i32(x86ms->fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(cmdline) + 1); 4030ebf007dSSergio Lopez fw_cfg_modify_string(x86ms->fw_cfg, FW_CFG_CMDLINE_DATA, cmdline); 404c3157b74SSergio Lopez 405c3157b74SSergio Lopez g_free(cmdline); 4060ebf007dSSergio Lopez } 4070ebf007dSSergio Lopez 408e3ab9873SGerd Hoffmann static void microvm_device_pre_plug_cb(HotplugHandler *hotplug_dev, 409e3ab9873SGerd Hoffmann DeviceState *dev, Error **errp) 410e3ab9873SGerd Hoffmann { 4118c2d9f9aSGerd Hoffmann X86CPU *cpu = X86_CPU(dev); 4128c2d9f9aSGerd Hoffmann 4138c2d9f9aSGerd Hoffmann cpu->host_phys_bits = true; /* need reliable phys-bits */ 414e3ab9873SGerd Hoffmann x86_cpu_pre_plug(hotplug_dev, dev, errp); 415e3ab9873SGerd Hoffmann } 416e3ab9873SGerd Hoffmann 417e3ab9873SGerd Hoffmann static void microvm_device_plug_cb(HotplugHandler *hotplug_dev, 418e3ab9873SGerd Hoffmann DeviceState *dev, Error **errp) 419e3ab9873SGerd Hoffmann { 420e3ab9873SGerd Hoffmann x86_cpu_plug(hotplug_dev, dev, errp); 421e3ab9873SGerd Hoffmann } 422e3ab9873SGerd Hoffmann 423e3ab9873SGerd Hoffmann static void microvm_device_unplug_request_cb(HotplugHandler *hotplug_dev, 424e3ab9873SGerd Hoffmann DeviceState *dev, Error **errp) 425e3ab9873SGerd Hoffmann { 426e3ab9873SGerd Hoffmann error_setg(errp, "unplug not supported by microvm"); 427e3ab9873SGerd Hoffmann } 428e3ab9873SGerd Hoffmann 429e3ab9873SGerd Hoffmann static void microvm_device_unplug_cb(HotplugHandler *hotplug_dev, 430e3ab9873SGerd Hoffmann DeviceState *dev, Error **errp) 431e3ab9873SGerd Hoffmann { 432e3ab9873SGerd Hoffmann error_setg(errp, "unplug not supported by microvm"); 433e3ab9873SGerd Hoffmann } 434e3ab9873SGerd Hoffmann 435e3ab9873SGerd Hoffmann static HotplugHandler *microvm_get_hotplug_handler(MachineState *machine, 436e3ab9873SGerd Hoffmann DeviceState *dev) 437e3ab9873SGerd Hoffmann { 438e3ab9873SGerd Hoffmann if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { 439e3ab9873SGerd Hoffmann return HOTPLUG_HANDLER(machine); 440e3ab9873SGerd Hoffmann } 441e3ab9873SGerd Hoffmann return NULL; 442e3ab9873SGerd Hoffmann } 443e3ab9873SGerd Hoffmann 4440ebf007dSSergio Lopez static void microvm_machine_state_init(MachineState *machine) 4450ebf007dSSergio Lopez { 4460ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(machine); 4470ebf007dSSergio Lopez X86MachineState *x86ms = X86_MACHINE(machine); 4480ebf007dSSergio Lopez Error *local_err = NULL; 4490ebf007dSSergio Lopez 4500ebf007dSSergio Lopez microvm_memory_init(mms); 4510ebf007dSSergio Lopez 4520ebf007dSSergio Lopez x86_cpus_init(x86ms, CPU_VERSION_LATEST); 4530ebf007dSSergio Lopez if (local_err) { 4540ebf007dSSergio Lopez error_report_err(local_err); 4550ebf007dSSergio Lopez exit(1); 4560ebf007dSSergio Lopez } 4570ebf007dSSergio Lopez 4580ebf007dSSergio Lopez microvm_devices_init(mms); 4590ebf007dSSergio Lopez } 4600ebf007dSSergio Lopez 4610ebf007dSSergio Lopez static void microvm_machine_reset(MachineState *machine) 4620ebf007dSSergio Lopez { 4630ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(machine); 4640ebf007dSSergio Lopez CPUState *cs; 4650ebf007dSSergio Lopez X86CPU *cpu; 4660ebf007dSSergio Lopez 467f6f7e2d8SGerd Hoffmann if (!x86_machine_is_acpi_enabled(X86_MACHINE(machine)) && 468f6f7e2d8SGerd Hoffmann machine->kernel_filename != NULL && 4690ebf007dSSergio Lopez mms->auto_kernel_cmdline && !mms->kernel_cmdline_fixed) { 4700ebf007dSSergio Lopez microvm_fix_kernel_cmdline(machine); 4710ebf007dSSergio Lopez mms->kernel_cmdline_fixed = true; 4720ebf007dSSergio Lopez } 4730ebf007dSSergio Lopez 4740ebf007dSSergio Lopez qemu_devices_reset(); 4750ebf007dSSergio Lopez 4760ebf007dSSergio Lopez CPU_FOREACH(cs) { 4770ebf007dSSergio Lopez cpu = X86_CPU(cs); 4780ebf007dSSergio Lopez 4790ebf007dSSergio Lopez if (cpu->apic_state) { 480f703a04cSDamien Hedde device_legacy_reset(cpu->apic_state); 4810ebf007dSSergio Lopez } 4820ebf007dSSergio Lopez } 4830ebf007dSSergio Lopez } 4840ebf007dSSergio Lopez 4850ebf007dSSergio Lopez static void microvm_machine_get_pic(Object *obj, Visitor *v, const char *name, 4860ebf007dSSergio Lopez void *opaque, Error **errp) 4870ebf007dSSergio Lopez { 4880ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 4890ebf007dSSergio Lopez OnOffAuto pic = mms->pic; 4900ebf007dSSergio Lopez 4910ebf007dSSergio Lopez visit_type_OnOffAuto(v, name, &pic, errp); 4920ebf007dSSergio Lopez } 4930ebf007dSSergio Lopez 4940ebf007dSSergio Lopez static void microvm_machine_set_pic(Object *obj, Visitor *v, const char *name, 4950ebf007dSSergio Lopez void *opaque, Error **errp) 4960ebf007dSSergio Lopez { 4970ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 4980ebf007dSSergio Lopez 4990ebf007dSSergio Lopez visit_type_OnOffAuto(v, name, &mms->pic, errp); 5000ebf007dSSergio Lopez } 5010ebf007dSSergio Lopez 5020ebf007dSSergio Lopez static void microvm_machine_get_pit(Object *obj, Visitor *v, const char *name, 5030ebf007dSSergio Lopez void *opaque, Error **errp) 5040ebf007dSSergio Lopez { 5050ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5060ebf007dSSergio Lopez OnOffAuto pit = mms->pit; 5070ebf007dSSergio Lopez 5080ebf007dSSergio Lopez visit_type_OnOffAuto(v, name, &pit, errp); 5090ebf007dSSergio Lopez } 5100ebf007dSSergio Lopez 5110ebf007dSSergio Lopez static void microvm_machine_set_pit(Object *obj, Visitor *v, const char *name, 5120ebf007dSSergio Lopez void *opaque, Error **errp) 5130ebf007dSSergio Lopez { 5140ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5150ebf007dSSergio Lopez 5160ebf007dSSergio Lopez visit_type_OnOffAuto(v, name, &mms->pit, errp); 5170ebf007dSSergio Lopez } 5180ebf007dSSergio Lopez 5190ebf007dSSergio Lopez static void microvm_machine_get_rtc(Object *obj, Visitor *v, const char *name, 5200ebf007dSSergio Lopez void *opaque, Error **errp) 5210ebf007dSSergio Lopez { 5220ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5230ebf007dSSergio Lopez OnOffAuto rtc = mms->rtc; 5240ebf007dSSergio Lopez 5250ebf007dSSergio Lopez visit_type_OnOffAuto(v, name, &rtc, errp); 5260ebf007dSSergio Lopez } 5270ebf007dSSergio Lopez 5280ebf007dSSergio Lopez static void microvm_machine_set_rtc(Object *obj, Visitor *v, const char *name, 5290ebf007dSSergio Lopez void *opaque, Error **errp) 5300ebf007dSSergio Lopez { 5310ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5320ebf007dSSergio Lopez 5330ebf007dSSergio Lopez visit_type_OnOffAuto(v, name, &mms->rtc, errp); 5340ebf007dSSergio Lopez } 5350ebf007dSSergio Lopez 53624db877aSGerd Hoffmann static void microvm_machine_get_pcie(Object *obj, Visitor *v, const char *name, 53724db877aSGerd Hoffmann void *opaque, Error **errp) 53824db877aSGerd Hoffmann { 53924db877aSGerd Hoffmann MicrovmMachineState *mms = MICROVM_MACHINE(obj); 54024db877aSGerd Hoffmann OnOffAuto pcie = mms->pcie; 54124db877aSGerd Hoffmann 54224db877aSGerd Hoffmann visit_type_OnOffAuto(v, name, &pcie, errp); 54324db877aSGerd Hoffmann } 54424db877aSGerd Hoffmann 54524db877aSGerd Hoffmann static void microvm_machine_set_pcie(Object *obj, Visitor *v, const char *name, 54624db877aSGerd Hoffmann void *opaque, Error **errp) 54724db877aSGerd Hoffmann { 54824db877aSGerd Hoffmann MicrovmMachineState *mms = MICROVM_MACHINE(obj); 54924db877aSGerd Hoffmann 55024db877aSGerd Hoffmann visit_type_OnOffAuto(v, name, &mms->pcie, errp); 55124db877aSGerd Hoffmann } 55224db877aSGerd Hoffmann 5530ebf007dSSergio Lopez static bool microvm_machine_get_isa_serial(Object *obj, Error **errp) 5540ebf007dSSergio Lopez { 5550ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5560ebf007dSSergio Lopez 5570ebf007dSSergio Lopez return mms->isa_serial; 5580ebf007dSSergio Lopez } 5590ebf007dSSergio Lopez 5600ebf007dSSergio Lopez static void microvm_machine_set_isa_serial(Object *obj, bool value, 5610ebf007dSSergio Lopez Error **errp) 5620ebf007dSSergio Lopez { 5630ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5640ebf007dSSergio Lopez 5650ebf007dSSergio Lopez mms->isa_serial = value; 5660ebf007dSSergio Lopez } 5670ebf007dSSergio Lopez 5680ebf007dSSergio Lopez static bool microvm_machine_get_option_roms(Object *obj, Error **errp) 5690ebf007dSSergio Lopez { 5700ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5710ebf007dSSergio Lopez 5720ebf007dSSergio Lopez return mms->option_roms; 5730ebf007dSSergio Lopez } 5740ebf007dSSergio Lopez 5750ebf007dSSergio Lopez static void microvm_machine_set_option_roms(Object *obj, bool value, 5760ebf007dSSergio Lopez Error **errp) 5770ebf007dSSergio Lopez { 5780ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5790ebf007dSSergio Lopez 5800ebf007dSSergio Lopez mms->option_roms = value; 5810ebf007dSSergio Lopez } 5820ebf007dSSergio Lopez 5830ebf007dSSergio Lopez static bool microvm_machine_get_auto_kernel_cmdline(Object *obj, Error **errp) 5840ebf007dSSergio Lopez { 5850ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5860ebf007dSSergio Lopez 5870ebf007dSSergio Lopez return mms->auto_kernel_cmdline; 5880ebf007dSSergio Lopez } 5890ebf007dSSergio Lopez 5900ebf007dSSergio Lopez static void microvm_machine_set_auto_kernel_cmdline(Object *obj, bool value, 5910ebf007dSSergio Lopez Error **errp) 5920ebf007dSSergio Lopez { 5930ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 5940ebf007dSSergio Lopez 5950ebf007dSSergio Lopez mms->auto_kernel_cmdline = value; 5960ebf007dSSergio Lopez } 5970ebf007dSSergio Lopez 5988045df14SGerd Hoffmann static void microvm_machine_done(Notifier *notifier, void *data) 5998045df14SGerd Hoffmann { 6008045df14SGerd Hoffmann MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState, 6018045df14SGerd Hoffmann machine_done); 6028045df14SGerd Hoffmann 6038045df14SGerd Hoffmann acpi_setup_microvm(mms); 6048045df14SGerd Hoffmann } 6058045df14SGerd Hoffmann 6068045df14SGerd Hoffmann static void microvm_powerdown_req(Notifier *notifier, void *data) 6078045df14SGerd Hoffmann { 6088045df14SGerd Hoffmann MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState, 6098045df14SGerd Hoffmann powerdown_req); 61050aef131SGerd Hoffmann X86MachineState *x86ms = X86_MACHINE(mms); 6118045df14SGerd Hoffmann 61250aef131SGerd Hoffmann if (x86ms->acpi_dev) { 61350aef131SGerd Hoffmann Object *obj = OBJECT(x86ms->acpi_dev); 6148045df14SGerd Hoffmann AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj); 61550aef131SGerd Hoffmann adevc->send_event(ACPI_DEVICE_IF(x86ms->acpi_dev), 61650aef131SGerd Hoffmann ACPI_POWER_DOWN_STATUS); 6178045df14SGerd Hoffmann } 6188045df14SGerd Hoffmann } 6198045df14SGerd Hoffmann 6200ebf007dSSergio Lopez static void microvm_machine_initfn(Object *obj) 6210ebf007dSSergio Lopez { 6220ebf007dSSergio Lopez MicrovmMachineState *mms = MICROVM_MACHINE(obj); 6230ebf007dSSergio Lopez 6240ebf007dSSergio Lopez /* Configuration */ 6250ebf007dSSergio Lopez mms->pic = ON_OFF_AUTO_AUTO; 6260ebf007dSSergio Lopez mms->pit = ON_OFF_AUTO_AUTO; 6270ebf007dSSergio Lopez mms->rtc = ON_OFF_AUTO_AUTO; 62824db877aSGerd Hoffmann mms->pcie = ON_OFF_AUTO_AUTO; 6290ebf007dSSergio Lopez mms->isa_serial = true; 6300ebf007dSSergio Lopez mms->option_roms = true; 6310ebf007dSSergio Lopez mms->auto_kernel_cmdline = true; 6320ebf007dSSergio Lopez 6330ebf007dSSergio Lopez /* State */ 6340ebf007dSSergio Lopez mms->kernel_cmdline_fixed = false; 6358045df14SGerd Hoffmann 6368045df14SGerd Hoffmann mms->machine_done.notify = microvm_machine_done; 6378045df14SGerd Hoffmann qemu_add_machine_init_done_notifier(&mms->machine_done); 6388045df14SGerd Hoffmann mms->powerdown_req.notify = microvm_powerdown_req; 6398045df14SGerd Hoffmann qemu_register_powerdown_notifier(&mms->powerdown_req); 6400ebf007dSSergio Lopez } 6410ebf007dSSergio Lopez 6420ebf007dSSergio Lopez static void microvm_class_init(ObjectClass *oc, void *data) 6430ebf007dSSergio Lopez { 6440ebf007dSSergio Lopez MachineClass *mc = MACHINE_CLASS(oc); 645e3ab9873SGerd Hoffmann HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); 6460ebf007dSSergio Lopez 6470ebf007dSSergio Lopez mc->init = microvm_machine_state_init; 6480ebf007dSSergio Lopez 6490ebf007dSSergio Lopez mc->family = "microvm_i386"; 6500ebf007dSSergio Lopez mc->desc = "microvm (i386)"; 6510ebf007dSSergio Lopez mc->units_per_default_bus = 1; 6520ebf007dSSergio Lopez mc->no_floppy = 1; 6530ebf007dSSergio Lopez mc->max_cpus = 288; 6540ebf007dSSergio Lopez mc->has_hotpluggable_cpus = false; 6550ebf007dSSergio Lopez mc->auto_enable_numa_with_memhp = false; 656195784a0SDavid Hildenbrand mc->auto_enable_numa_with_memdev = false; 6570ebf007dSSergio Lopez mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE; 6580ebf007dSSergio Lopez mc->nvdimm_supported = false; 6599ad54686SIgor Mammedov mc->default_ram_id = "microvm.ram"; 6600ebf007dSSergio Lopez 6610ebf007dSSergio Lopez /* Avoid relying too much on kernel components */ 6620ebf007dSSergio Lopez mc->default_kernel_irqchip_split = true; 6630ebf007dSSergio Lopez 6640ebf007dSSergio Lopez /* Machine class handlers */ 6650ebf007dSSergio Lopez mc->reset = microvm_machine_reset; 6660ebf007dSSergio Lopez 667e3ab9873SGerd Hoffmann /* hotplug (for cpu coldplug) */ 668e3ab9873SGerd Hoffmann mc->get_hotplug_handler = microvm_get_hotplug_handler; 669e3ab9873SGerd Hoffmann hc->pre_plug = microvm_device_pre_plug_cb; 670e3ab9873SGerd Hoffmann hc->plug = microvm_device_plug_cb; 671e3ab9873SGerd Hoffmann hc->unplug_request = microvm_device_unplug_request_cb; 672e3ab9873SGerd Hoffmann hc->unplug = microvm_device_unplug_cb; 673e3ab9873SGerd Hoffmann 6740ebf007dSSergio Lopez object_class_property_add(oc, MICROVM_MACHINE_PIC, "OnOffAuto", 6750ebf007dSSergio Lopez microvm_machine_get_pic, 6760ebf007dSSergio Lopez microvm_machine_set_pic, 677d2623129SMarkus Armbruster NULL, NULL); 6780ebf007dSSergio Lopez object_class_property_set_description(oc, MICROVM_MACHINE_PIC, 6797eecec7dSMarkus Armbruster "Enable i8259 PIC"); 6800ebf007dSSergio Lopez 6810ebf007dSSergio Lopez object_class_property_add(oc, MICROVM_MACHINE_PIT, "OnOffAuto", 6820ebf007dSSergio Lopez microvm_machine_get_pit, 6830ebf007dSSergio Lopez microvm_machine_set_pit, 684d2623129SMarkus Armbruster NULL, NULL); 6850ebf007dSSergio Lopez object_class_property_set_description(oc, MICROVM_MACHINE_PIT, 6867eecec7dSMarkus Armbruster "Enable i8254 PIT"); 6870ebf007dSSergio Lopez 6880ebf007dSSergio Lopez object_class_property_add(oc, MICROVM_MACHINE_RTC, "OnOffAuto", 6890ebf007dSSergio Lopez microvm_machine_get_rtc, 6900ebf007dSSergio Lopez microvm_machine_set_rtc, 691d2623129SMarkus Armbruster NULL, NULL); 6920ebf007dSSergio Lopez object_class_property_set_description(oc, MICROVM_MACHINE_RTC, 6937eecec7dSMarkus Armbruster "Enable MC146818 RTC"); 6940ebf007dSSergio Lopez 69524db877aSGerd Hoffmann object_class_property_add(oc, MICROVM_MACHINE_PCIE, "OnOffAuto", 69624db877aSGerd Hoffmann microvm_machine_get_pcie, 69724db877aSGerd Hoffmann microvm_machine_set_pcie, 69824db877aSGerd Hoffmann NULL, NULL); 69924db877aSGerd Hoffmann object_class_property_set_description(oc, MICROVM_MACHINE_PCIE, 70024db877aSGerd Hoffmann "Enable PCIe"); 70124db877aSGerd Hoffmann 7020ebf007dSSergio Lopez object_class_property_add_bool(oc, MICROVM_MACHINE_ISA_SERIAL, 7030ebf007dSSergio Lopez microvm_machine_get_isa_serial, 704d2623129SMarkus Armbruster microvm_machine_set_isa_serial); 7050ebf007dSSergio Lopez object_class_property_set_description(oc, MICROVM_MACHINE_ISA_SERIAL, 7067eecec7dSMarkus Armbruster "Set off to disable the instantiation an ISA serial port"); 7070ebf007dSSergio Lopez 7080ebf007dSSergio Lopez object_class_property_add_bool(oc, MICROVM_MACHINE_OPTION_ROMS, 7090ebf007dSSergio Lopez microvm_machine_get_option_roms, 710d2623129SMarkus Armbruster microvm_machine_set_option_roms); 7110ebf007dSSergio Lopez object_class_property_set_description(oc, MICROVM_MACHINE_OPTION_ROMS, 7127eecec7dSMarkus Armbruster "Set off to disable loading option ROMs"); 7130ebf007dSSergio Lopez 7140ebf007dSSergio Lopez object_class_property_add_bool(oc, MICROVM_MACHINE_AUTO_KERNEL_CMDLINE, 7150ebf007dSSergio Lopez microvm_machine_get_auto_kernel_cmdline, 716d2623129SMarkus Armbruster microvm_machine_set_auto_kernel_cmdline); 7170ebf007dSSergio Lopez object_class_property_set_description(oc, 7180ebf007dSSergio Lopez MICROVM_MACHINE_AUTO_KERNEL_CMDLINE, 7197eecec7dSMarkus Armbruster "Set off to disable adding virtio-mmio devices to the kernel cmdline"); 72063bcfe7bSGerd Hoffmann 72163bcfe7bSGerd Hoffmann machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); 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