4 #include "qemu-common.h"
5 #include "qemu/typedefs.h"
6 #include "exec/memory.h"
8 #include "hw/isa/isa.h"
9 #include "hw/block/fdc.h"
11 #include "hw/i386/ioapic.h"
13 #include "qemu/range.h"
14 #include "qemu/bitmap.h"
15 #include "sysemu/sysemu.h"
16 #include "hw/pci/pci.h"
17 #include "hw/boards.h"
18 #include "hw/compat.h"
19 #include "hw/mem/pc-dimm.h"
21 #define HPET_INTCAP "hpet-intcap"
24 #define kvm_pit_in_kernel() \
25 (kvm_irqchip_in_kernel() && !kvm_irqchip_is_split())
26 #define kvm_pic_in_kernel() \
27 (kvm_irqchip_in_kernel() && !kvm_irqchip_is_split())
28 #define kvm_ioapic_in_kernel() \
29 (kvm_irqchip_in_kernel() && !kvm_irqchip_is_split())
31 #define kvm_pit_in_kernel() 0
32 #define kvm_pic_in_kernel() 0
33 #define kvm_ioapic_in_kernel() 0
38 * @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling
40 struct PCMachineState
{
42 MachineState parent_obj
;
46 /* State for other subsystems/APIs: */
47 MemoryHotplugState hotplug_memory
;
48 Notifier machine_done
;
50 /* Pointers to devices and objects: */
51 HotplugHandler
*acpi_dev
;
56 /* Configuration options: */
57 uint64_t max_ram_below_4g
;
62 /* RAM information (sizes, addresses, configuration): */
63 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
65 /* CPU and apic information: */
66 bool apic_xrupt_override
;
67 unsigned apic_id_limit
;
69 /* NUMA information: */
75 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
76 #define PC_MACHINE_MEMHP_REGION_SIZE "hotplug-memory-region-size"
77 #define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g"
78 #define PC_MACHINE_VMPORT "vmport"
79 #define PC_MACHINE_SMM "smm"
80 #define PC_MACHINE_NVDIMM "nvdimm"
87 * @get_hotplug_handler: pointer to parent class callback @get_hotplug_handler
91 * @enforce_aligned_dimm: check that DIMM's address/size is aligned by
92 * backend's alignment value if provided
93 * @acpi_data_size: Size of the chunk of memory at the top of RAM
94 * for the BIOS ACPI tables and other BIOS
96 * @gigabyte_align: Make sure that guest addresses aligned at
97 * 1Gbyte boundaries get mapped to host
98 * addresses aligned at 1Gbyte boundaries. This
99 * way we can use 1GByte pages in the host.
102 struct PCMachineClass
{
104 MachineClass parent_class
;
109 HotplugHandler
*(*get_hotplug_handler
)(MachineState
*machine
,
112 /* Device configuration: */
114 bool kvmclock_enabled
;
116 /* Compat options: */
121 int legacy_acpi_table_size
;
122 unsigned acpi_data_size
;
125 bool smbios_defaults
;
126 bool smbios_legacy_mode
;
127 bool smbios_uuid_encoded
;
129 /* RAM / address space compat: */
131 bool has_reserved_memory
;
132 bool enforce_aligned_dimm
;
133 bool broken_reserved_end
;
135 /* TSC rate migration: */
139 #define TYPE_PC_MACHINE "generic-pc-machine"
140 #define PC_MACHINE(obj) \
141 OBJECT_CHECK(PCMachineState, (obj), TYPE_PC_MACHINE)
142 #define PC_MACHINE_GET_CLASS(obj) \
143 OBJECT_GET_CLASS(PCMachineClass, (obj), TYPE_PC_MACHINE)
144 #define PC_MACHINE_CLASS(klass) \
145 OBJECT_CLASS_CHECK(PCMachineClass, (klass), TYPE_PC_MACHINE)
147 /* PC-style peripherals (also used by other machines). */
149 typedef struct PcPciInfo
{
154 #define ACPI_PM_PROP_S3_DISABLED "disable_s3"
155 #define ACPI_PM_PROP_S4_DISABLED "disable_s4"
156 #define ACPI_PM_PROP_S4_VAL "s4_val"
157 #define ACPI_PM_PROP_SCI_INT "sci_int"
158 #define ACPI_PM_PROP_ACPI_ENABLE_CMD "acpi_enable_cmd"
159 #define ACPI_PM_PROP_ACPI_DISABLE_CMD "acpi_disable_cmd"
160 #define ACPI_PM_PROP_PM_IO_BASE "pm_io_base"
161 #define ACPI_PM_PROP_GPE0_BLK "gpe0_blk"
162 #define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len"
163 #define ACPI_PM_PROP_TCO_ENABLED "enable_tco"
167 void parallel_hds_isa_init(ISABus
*bus
, int n
);
169 bool parallel_mm_init(MemoryRegion
*address_space
,
170 hwaddr base
, int it_shift
, qemu_irq irq
,
171 CharDriverState
*chr
);
175 extern DeviceState
*isa_pic
;
176 qemu_irq
*i8259_init(ISABus
*bus
, qemu_irq parent_irq
);
177 qemu_irq
*kvm_i8259_init(ISABus
*bus
);
178 int pic_read_irq(DeviceState
*d
);
179 int pic_get_output(DeviceState
*d
);
180 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
);
181 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
);
185 void kvm_ioapic_dump_state(Monitor
*mon
, const QDict
*qdict
);
186 void ioapic_dump_state(Monitor
*mon
, const QDict
*qdict
);
188 /* Global System Interrupts */
190 #define GSI_NUM_PINS IOAPIC_NUM_PINS
192 typedef struct GSIState
{
193 qemu_irq i8259_irq
[ISA_NUM_IRQS
];
194 qemu_irq ioapic_irq
[IOAPIC_NUM_PINS
];
197 void gsi_handler(void *opaque
, int n
, int level
);
200 typedef uint32_t (VMPortReadFunc
)(void *opaque
, uint32_t address
);
202 static inline void vmport_init(ISABus
*bus
)
204 isa_create_simple(bus
, "vmport");
207 void vmport_register(unsigned char command
, VMPortReadFunc
*func
, void *opaque
);
208 void vmmouse_get_data(uint32_t *data
);
209 void vmmouse_set_data(const uint32_t *data
);
213 void i8042_init(qemu_irq kbd_irq
, qemu_irq mouse_irq
, uint32_t io_base
);
214 void i8042_mm_init(qemu_irq kbd_irq
, qemu_irq mouse_irq
,
215 MemoryRegion
*region
, ram_addr_t size
,
217 void i8042_isa_mouse_fake_event(void *opaque
);
218 void i8042_setup_a20_line(ISADevice
*dev
, qemu_irq
*a20_out
);
221 extern int fd_bootchk
;
223 bool pc_machine_is_smm_enabled(PCMachineState
*pcms
);
224 void pc_register_ferr_irq(qemu_irq irq
);
225 void pc_acpi_smi_interrupt(void *opaque
, int irq
, int level
);
227 void pc_cpus_init(PCMachineState
*pcms
);
228 void pc_hot_add_cpu(const int64_t id
, Error
**errp
);
229 void pc_acpi_init(const char *default_dsdt
);
231 void pc_guest_info_init(PCMachineState
*pcms
);
233 #define PCI_HOST_PROP_PCI_HOLE_START "pci-hole-start"
234 #define PCI_HOST_PROP_PCI_HOLE_END "pci-hole-end"
235 #define PCI_HOST_PROP_PCI_HOLE64_START "pci-hole64-start"
236 #define PCI_HOST_PROP_PCI_HOLE64_END "pci-hole64-end"
237 #define PCI_HOST_PROP_PCI_HOLE64_SIZE "pci-hole64-size"
238 #define DEFAULT_PCI_HOLE64_SIZE (~0x0ULL)
241 void pc_pci_as_mapping_init(Object
*owner
, MemoryRegion
*system_memory
,
242 MemoryRegion
*pci_address_space
);
244 void xen_load_linux(PCMachineState
*pcms
);
245 void pc_memory_init(PCMachineState
*pcms
,
246 MemoryRegion
*system_memory
,
247 MemoryRegion
*rom_memory
,
248 MemoryRegion
**ram_memory
);
249 qemu_irq
pc_allocate_cpu_irq(void);
250 DeviceState
*pc_vga_init(ISABus
*isa_bus
, PCIBus
*pci_bus
);
251 void pc_basic_device_init(ISABus
*isa_bus
, qemu_irq
*gsi
,
252 ISADevice
**rtc_state
,
256 void pc_init_ne2k_isa(ISABus
*bus
, NICInfo
*nd
);
257 void pc_cmos_init(PCMachineState
*pcms
,
258 BusState
*ide0
, BusState
*ide1
,
260 void pc_nic_init(ISABus
*isa_bus
, PCIBus
*pci_bus
);
261 void pc_pci_device_init(PCIBus
*pci_bus
);
263 typedef void (*cpu_set_smm_t
)(int smm
, void *arg
);
265 void ioapic_init_gsi(GSIState
*gsi_state
, const char *parent_name
);
267 ISADevice
*pc_find_fdc0(void);
269 #define FW_CFG_IO_BASE 0x510
273 I2CBus
*piix4_pm_init(PCIBus
*bus
, int devfn
, uint32_t smb_io_base
,
274 qemu_irq sci_irq
, qemu_irq smi_irq
,
275 int smm_enabled
, DeviceState
**piix4_pm
);
276 void piix4_smbus_register_device(SMBusDevice
*dev
, uint8_t addr
);
282 struct PCII440FXState
;
283 typedef struct PCII440FXState PCII440FXState
;
285 #define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost"
286 #define TYPE_I440FX_PCI_DEVICE "i440FX"
288 #define TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "igd-passthrough-i440FX"
290 PCIBus
*i440fx_init(const char *host_type
, const char *pci_type
,
291 PCII440FXState
**pi440fx_state
, int *piix_devfn
,
292 ISABus
**isa_bus
, qemu_irq
*pic
,
293 MemoryRegion
*address_space_mem
,
294 MemoryRegion
*address_space_io
,
296 ram_addr_t below_4g_mem_size
,
297 ram_addr_t above_4g_mem_size
,
298 MemoryRegion
*pci_memory
,
299 MemoryRegion
*ram_memory
);
301 PCIBus
*find_i440fx(void);
303 extern PCIDevice
*piix4_dev
;
304 int piix4_init(PCIBus
*bus
, ISABus
**isa_bus
, int devfn
);
307 enum vga_retrace_method
{
312 extern enum vga_retrace_method vga_retrace_method
;
314 int isa_vga_mm_init(hwaddr vram_base
,
315 hwaddr ctrl_base
, int it_shift
,
316 MemoryRegion
*address_space
);
319 static inline bool isa_ne2000_init(ISABus
*bus
, int base
, int irq
, NICInfo
*nd
)
324 qemu_check_nic_model(nd
, "ne2k_isa");
326 isadev
= isa_try_create(bus
, "ne2k_isa");
330 dev
= DEVICE(isadev
);
331 qdev_prop_set_uint32(dev
, "iobase", base
);
332 qdev_prop_set_uint32(dev
, "irq", irq
);
333 qdev_set_nic_properties(dev
, nd
);
334 qdev_init_nofail(dev
);
339 void pc_system_firmware_init(MemoryRegion
*rom_memory
,
343 uint16_t pvpanic_port(void);
347 #define E820_RESERVED 2
350 #define E820_UNUSABLE 5
352 int e820_add_entry(uint64_t, uint64_t, uint32_t);
353 int e820_get_num_entries(void);
354 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
356 #define PC_COMPAT_2_5 \
359 #define PC_COMPAT_2_4 \
363 .driver = "Haswell-" TYPE_X86_CPU,\
368 .driver = "Haswell-noTSX-" TYPE_X86_CPU,\
373 .driver = "Broadwell-" TYPE_X86_CPU,\
378 .driver = "Broadwell-noTSX-" TYPE_X86_CPU,\
383 .driver = "host" "-" TYPE_X86_CPU,\
384 .property = "host-cache-info",\
388 .driver = TYPE_X86_CPU,\
389 .property = "check",\
393 .driver = "qemu64" "-" TYPE_X86_CPU,\
394 .property = "sse4a",\
398 .driver = "qemu64" "-" TYPE_X86_CPU,\
403 .driver = "qemu64" "-" TYPE_X86_CPU,\
404 .property = "popcnt",\
408 .driver = "qemu32" "-" TYPE_X86_CPU,\
409 .property = "popcnt",\
412 .driver = "Opteron_G2" "-" TYPE_X86_CPU,\
413 .property = "rdtscp",\
416 .driver = "Opteron_G3" "-" TYPE_X86_CPU,\
417 .property = "rdtscp",\
420 .driver = "Opteron_G4" "-" TYPE_X86_CPU,\
421 .property = "rdtscp",\
424 .driver = "Opteron_G5" "-" TYPE_X86_CPU,\
425 .property = "rdtscp",\
430 #define PC_COMPAT_2_3 \
434 .driver = TYPE_X86_CPU,\
438 .driver = "qemu64" "-" TYPE_X86_CPU,\
439 .property = "level",\
440 .value = stringify(4),\
442 .driver = "kvm64" "-" TYPE_X86_CPU,\
443 .property = "level",\
444 .value = stringify(5),\
446 .driver = "pentium3" "-" TYPE_X86_CPU,\
447 .property = "level",\
448 .value = stringify(2),\
450 .driver = "n270" "-" TYPE_X86_CPU,\
451 .property = "level",\
452 .value = stringify(5),\
454 .driver = "Conroe" "-" TYPE_X86_CPU,\
455 .property = "level",\
456 .value = stringify(4),\
458 .driver = "Penryn" "-" TYPE_X86_CPU,\
459 .property = "level",\
460 .value = stringify(4),\
462 .driver = "Nehalem" "-" TYPE_X86_CPU,\
463 .property = "level",\
464 .value = stringify(4),\
466 .driver = "n270" "-" TYPE_X86_CPU,\
467 .property = "xlevel",\
468 .value = stringify(0x8000000a),\
470 .driver = "Penryn" "-" TYPE_X86_CPU,\
471 .property = "xlevel",\
472 .value = stringify(0x8000000a),\
474 .driver = "Conroe" "-" TYPE_X86_CPU,\
475 .property = "xlevel",\
476 .value = stringify(0x8000000a),\
478 .driver = "Nehalem" "-" TYPE_X86_CPU,\
479 .property = "xlevel",\
480 .value = stringify(0x8000000a),\
482 .driver = "Westmere" "-" TYPE_X86_CPU,\
483 .property = "xlevel",\
484 .value = stringify(0x8000000a),\
486 .driver = "SandyBridge" "-" TYPE_X86_CPU,\
487 .property = "xlevel",\
488 .value = stringify(0x8000000a),\
490 .driver = "IvyBridge" "-" TYPE_X86_CPU,\
491 .property = "xlevel",\
492 .value = stringify(0x8000000a),\
494 .driver = "Haswell" "-" TYPE_X86_CPU,\
495 .property = "xlevel",\
496 .value = stringify(0x8000000a),\
498 .driver = "Haswell-noTSX" "-" TYPE_X86_CPU,\
499 .property = "xlevel",\
500 .value = stringify(0x8000000a),\
502 .driver = "Broadwell" "-" TYPE_X86_CPU,\
503 .property = "xlevel",\
504 .value = stringify(0x8000000a),\
506 .driver = "Broadwell-noTSX" "-" TYPE_X86_CPU,\
507 .property = "xlevel",\
508 .value = stringify(0x8000000a),\
511 #define PC_COMPAT_2_2 \
515 .driver = "kvm64" "-" TYPE_X86_CPU,\
520 .driver = "kvm32" "-" TYPE_X86_CPU,\
525 .driver = "Conroe" "-" TYPE_X86_CPU,\
530 .driver = "Penryn" "-" TYPE_X86_CPU,\
535 .driver = "Nehalem" "-" TYPE_X86_CPU,\
540 .driver = "Westmere" "-" TYPE_X86_CPU,\
545 .driver = "SandyBridge" "-" TYPE_X86_CPU,\
550 .driver = "Haswell" "-" TYPE_X86_CPU,\
555 .driver = "Broadwell" "-" TYPE_X86_CPU,\
560 .driver = "Opteron_G1" "-" TYPE_X86_CPU,\
565 .driver = "Opteron_G2" "-" TYPE_X86_CPU,\
570 .driver = "Opteron_G3" "-" TYPE_X86_CPU,\
575 .driver = "Opteron_G4" "-" TYPE_X86_CPU,\
580 .driver = "Opteron_G5" "-" TYPE_X86_CPU,\
585 .driver = "Haswell" "-" TYPE_X86_CPU,\
590 .driver = "Haswell" "-" TYPE_X86_CPU,\
591 .property = "rdrand",\
595 .driver = "Broadwell" "-" TYPE_X86_CPU,\
600 .driver = "Broadwell" "-" TYPE_X86_CPU,\
601 .property = "rdrand",\
605 #define PC_COMPAT_2_1 \
609 .driver = "coreduo" "-" TYPE_X86_CPU,\
614 .driver = "core2duo" "-" TYPE_X86_CPU,\
619 #define PC_COMPAT_2_0 \
622 .driver = "virtio-scsi-pci",\
623 .property = "any_layout",\
626 .driver = "PIIX4_PM",\
627 .property = "memory-hotplug-support",\
632 .property = "version",\
633 .value = stringify(0x11),\
636 .driver = "nec-usb-xhci",\
637 .property = "superspeed-ports-first",\
641 .driver = "nec-usb-xhci",\
642 .property = "force-pcie-endcap",\
646 .driver = "pci-serial",\
647 .property = "prog_if",\
648 .value = stringify(0),\
651 .driver = "pci-serial-2x",\
652 .property = "prog_if",\
653 .value = stringify(0),\
656 .driver = "pci-serial-4x",\
657 .property = "prog_if",\
658 .value = stringify(0),\
661 .driver = "virtio-net-pci",\
662 .property = "guest_announce",\
666 .driver = "ICH9-LPC",\
667 .property = "memory-hotplug-support",\
670 .driver = "xio3130-downstream",\
671 .property = COMPAT_PROP_PCP,\
674 .driver = "ioh3420",\
675 .property = COMPAT_PROP_PCP,\
679 #define PC_COMPAT_1_7 \
682 .driver = TYPE_USB_DEVICE,\
683 .property = "msos-desc",\
687 .driver = "PIIX4_PM",\
688 .property = "acpi-pci-hotplug-with-bridge-support",\
693 .property = HPET_INTCAP,\
694 .value = stringify(4),\
697 #define PC_COMPAT_1_6 \
701 .property = "mitigation",\
704 .driver = "qemu64-" TYPE_X86_CPU,\
705 .property = "model",\
706 .value = stringify(2),\
708 .driver = "qemu32-" TYPE_X86_CPU,\
709 .property = "model",\
710 .value = stringify(3),\
712 .driver = "i440FX-pcihost",\
713 .property = "short_root_bus",\
714 .value = stringify(1),\
716 .driver = "q35-pcihost",\
717 .property = "short_root_bus",\
718 .value = stringify(1),\
721 #define PC_COMPAT_1_5 \
724 .driver = "Conroe-" TYPE_X86_CPU,\
725 .property = "model",\
726 .value = stringify(2),\
728 .driver = "Conroe-" TYPE_X86_CPU,\
729 .property = "level",\
730 .value = stringify(2),\
732 .driver = "Penryn-" TYPE_X86_CPU,\
733 .property = "model",\
734 .value = stringify(2),\
736 .driver = "Penryn-" TYPE_X86_CPU,\
737 .property = "level",\
738 .value = stringify(2),\
740 .driver = "Nehalem-" TYPE_X86_CPU,\
741 .property = "model",\
742 .value = stringify(2),\
744 .driver = "Nehalem-" TYPE_X86_CPU,\
745 .property = "level",\
746 .value = stringify(2),\
748 .driver = "virtio-net-pci",\
749 .property = "any_layout",\
752 .driver = TYPE_X86_CPU,\
756 .driver = "i440FX-pcihost",\
757 .property = "short_root_bus",\
758 .value = stringify(0),\
760 .driver = "q35-pcihost",\
761 .property = "short_root_bus",\
762 .value = stringify(0),\
765 #define PC_COMPAT_1_4 \
768 .driver = "scsi-hd",\
769 .property = "discard_granularity",\
770 .value = stringify(0),\
772 .driver = "scsi-cd",\
773 .property = "discard_granularity",\
774 .value = stringify(0),\
776 .driver = "scsi-disk",\
777 .property = "discard_granularity",\
778 .value = stringify(0),\
781 .property = "discard_granularity",\
782 .value = stringify(0),\
785 .property = "discard_granularity",\
786 .value = stringify(0),\
788 .driver = "ide-drive",\
789 .property = "discard_granularity",\
790 .value = stringify(0),\
792 .driver = "virtio-blk-pci",\
793 .property = "discard_granularity",\
794 .value = stringify(0),\
796 .driver = "virtio-serial-pci",\
797 .property = "vectors",\
798 /* DEV_NVECTORS_UNSPECIFIED as a uint32_t string */\
799 .value = stringify(0xFFFFFFFF),\
801 .driver = "virtio-net-pci", \
802 .property = "ctrl_guest_offloads", \
806 .property = "romfile",\
807 .value = "pxe-e1000.rom",\
809 .driver = "ne2k_pci",\
810 .property = "romfile",\
811 .value = "pxe-ne2k_pci.rom",\
814 .property = "romfile",\
815 .value = "pxe-pcnet.rom",\
817 .driver = "rtl8139",\
818 .property = "romfile",\
819 .value = "pxe-rtl8139.rom",\
821 .driver = "virtio-net-pci",\
822 .property = "romfile",\
823 .value = "pxe-virtio.rom",\
825 .driver = "486-" TYPE_X86_CPU,\
826 .property = "model",\
827 .value = stringify(0),\
830 .driver = "n270" "-" TYPE_X86_CPU,\
831 .property = "movbe",\
835 .driver = "Westmere" "-" TYPE_X86_CPU,\
836 .property = "pclmulqdq",\
840 #define DEFINE_PC_MACHINE(suffix, namestr, initfn, optsfn) \
841 static void pc_machine_##suffix##_class_init(ObjectClass *oc, void *data) \
843 MachineClass *mc = MACHINE_CLASS(oc); \
845 mc->name = namestr; \
848 static const TypeInfo pc_machine_type_##suffix = { \
849 .name = namestr TYPE_MACHINE_SUFFIX, \
850 .parent = TYPE_PC_MACHINE, \
851 .class_init = pc_machine_##suffix##_class_init, \
853 static void pc_machine_init_##suffix(void) \
855 type_register(&pc_machine_type_##suffix); \
857 machine_init(pc_machine_init_##suffix)
859 extern void igd_passthrough_isa_bridge_create(PCIBus
*bus
, uint16_t gpu_dev_id
);