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
39 * @enforce_aligned_dimm: check that DIMM's address/size is aligned by
40 * backend's alignment value if provided
42 struct PCMachineState
{
44 MachineState parent_obj
;
47 MemoryHotplugState hotplug_memory
;
49 HotplugHandler
*acpi_dev
;
52 uint64_t max_ram_below_4g
;
55 bool enforce_aligned_dimm
;
56 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
59 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
60 #define PC_MACHINE_MEMHP_REGION_SIZE "hotplug-memory-region-size"
61 #define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g"
62 #define PC_MACHINE_VMPORT "vmport"
63 #define PC_MACHINE_SMM "smm"
64 #define PC_MACHINE_ENFORCE_ALIGNED_DIMM "enforce-aligned-dimm"
68 * @get_hotplug_handler: pointer to parent class callback @get_hotplug_handler
70 struct PCMachineClass
{
72 MachineClass parent_class
;
75 bool broken_reserved_end
;
76 HotplugHandler
*(*get_hotplug_handler
)(MachineState
*machine
,
83 bool smbios_legacy_mode
;
84 bool smbios_uuid_encoded
;
85 /* Make sure that guest addresses aligned at 1Gbyte boundaries get
86 * mapped to host addresses aligned at 1Gbyte boundaries. This way
87 * we can use 1GByte pages in the host.
90 bool has_reserved_memory
;
91 bool kvmclock_enabled
;
92 int legacy_acpi_table_size
;
95 #define TYPE_PC_MACHINE "generic-pc-machine"
96 #define PC_MACHINE(obj) \
97 OBJECT_CHECK(PCMachineState, (obj), TYPE_PC_MACHINE)
98 #define PC_MACHINE_GET_CLASS(obj) \
99 OBJECT_GET_CLASS(PCMachineClass, (obj), TYPE_PC_MACHINE)
100 #define PC_MACHINE_CLASS(klass) \
101 OBJECT_CLASS_CHECK(PCMachineClass, (klass), TYPE_PC_MACHINE)
103 /* PC-style peripherals (also used by other machines). */
105 typedef struct PcPciInfo
{
110 #define ACPI_PM_PROP_S3_DISABLED "disable_s3"
111 #define ACPI_PM_PROP_S4_DISABLED "disable_s4"
112 #define ACPI_PM_PROP_S4_VAL "s4_val"
113 #define ACPI_PM_PROP_SCI_INT "sci_int"
114 #define ACPI_PM_PROP_ACPI_ENABLE_CMD "acpi_enable_cmd"
115 #define ACPI_PM_PROP_ACPI_DISABLE_CMD "acpi_disable_cmd"
116 #define ACPI_PM_PROP_PM_IO_BASE "pm_io_base"
117 #define ACPI_PM_PROP_GPE0_BLK "gpe0_blk"
118 #define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len"
119 #define ACPI_PM_PROP_TCO_ENABLED "enable_tco"
123 hwaddr ram_size
, ram_size_below_4g
;
124 unsigned apic_id_limit
;
125 bool apic_xrupt_override
;
130 int legacy_acpi_table_size
;
132 bool has_reserved_memory
;
138 void parallel_hds_isa_init(ISABus
*bus
, int n
);
140 bool parallel_mm_init(MemoryRegion
*address_space
,
141 hwaddr base
, int it_shift
, qemu_irq irq
,
142 CharDriverState
*chr
);
146 extern DeviceState
*isa_pic
;
147 qemu_irq
*i8259_init(ISABus
*bus
, qemu_irq parent_irq
);
148 qemu_irq
*kvm_i8259_init(ISABus
*bus
);
149 int pic_read_irq(DeviceState
*d
);
150 int pic_get_output(DeviceState
*d
);
151 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
);
152 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
);
156 void kvm_ioapic_dump_state(Monitor
*mon
, const QDict
*qdict
);
157 void ioapic_dump_state(Monitor
*mon
, const QDict
*qdict
);
159 /* Global System Interrupts */
161 #define GSI_NUM_PINS IOAPIC_NUM_PINS
163 typedef struct GSIState
{
164 qemu_irq i8259_irq
[ISA_NUM_IRQS
];
165 qemu_irq ioapic_irq
[IOAPIC_NUM_PINS
];
168 void gsi_handler(void *opaque
, int n
, int level
);
171 typedef uint32_t (VMPortReadFunc
)(void *opaque
, uint32_t address
);
173 static inline void vmport_init(ISABus
*bus
)
175 isa_create_simple(bus
, "vmport");
178 void vmport_register(unsigned char command
, VMPortReadFunc
*func
, void *opaque
);
179 void vmmouse_get_data(uint32_t *data
);
180 void vmmouse_set_data(const uint32_t *data
);
184 void i8042_init(qemu_irq kbd_irq
, qemu_irq mouse_irq
, uint32_t io_base
);
185 void i8042_mm_init(qemu_irq kbd_irq
, qemu_irq mouse_irq
,
186 MemoryRegion
*region
, ram_addr_t size
,
188 void i8042_isa_mouse_fake_event(void *opaque
);
189 void i8042_setup_a20_line(ISADevice
*dev
, qemu_irq
*a20_out
);
192 extern int fd_bootchk
;
194 bool pc_machine_is_smm_enabled(PCMachineState
*pcms
);
195 void pc_register_ferr_irq(qemu_irq irq
);
196 void pc_acpi_smi_interrupt(void *opaque
, int irq
, int level
);
198 void pc_cpus_init(PCMachineState
*pcms
);
199 void pc_hot_add_cpu(const int64_t id
, Error
**errp
);
200 void pc_acpi_init(const char *default_dsdt
);
202 PcGuestInfo
*pc_guest_info_init(PCMachineState
*pcms
);
204 void pc_set_legacy_acpi_data_size(void);
206 #define PCI_HOST_PROP_PCI_HOLE_START "pci-hole-start"
207 #define PCI_HOST_PROP_PCI_HOLE_END "pci-hole-end"
208 #define PCI_HOST_PROP_PCI_HOLE64_START "pci-hole64-start"
209 #define PCI_HOST_PROP_PCI_HOLE64_END "pci-hole64-end"
210 #define PCI_HOST_PROP_PCI_HOLE64_SIZE "pci-hole64-size"
211 #define DEFAULT_PCI_HOLE64_SIZE (~0x0ULL)
214 void pc_pci_as_mapping_init(Object
*owner
, MemoryRegion
*system_memory
,
215 MemoryRegion
*pci_address_space
);
217 FWCfgState
*xen_load_linux(PCMachineState
*pcms
,
218 PcGuestInfo
*guest_info
);
219 FWCfgState
*pc_memory_init(PCMachineState
*pcms
,
220 MemoryRegion
*system_memory
,
221 MemoryRegion
*rom_memory
,
222 MemoryRegion
**ram_memory
,
223 PcGuestInfo
*guest_info
);
224 qemu_irq
pc_allocate_cpu_irq(void);
225 DeviceState
*pc_vga_init(ISABus
*isa_bus
, PCIBus
*pci_bus
);
226 void pc_basic_device_init(ISABus
*isa_bus
, qemu_irq
*gsi
,
227 ISADevice
**rtc_state
,
231 void pc_init_ne2k_isa(ISABus
*bus
, NICInfo
*nd
);
232 void pc_cmos_init(PCMachineState
*pcms
,
233 BusState
*ide0
, BusState
*ide1
,
235 void pc_nic_init(ISABus
*isa_bus
, PCIBus
*pci_bus
);
236 void pc_pci_device_init(PCIBus
*pci_bus
);
238 typedef void (*cpu_set_smm_t
)(int smm
, void *arg
);
240 void ioapic_init_gsi(GSIState
*gsi_state
, const char *parent_name
);
244 I2CBus
*piix4_pm_init(PCIBus
*bus
, int devfn
, uint32_t smb_io_base
,
245 qemu_irq sci_irq
, qemu_irq smi_irq
,
246 int smm_enabled
, DeviceState
**piix4_pm
);
247 void piix4_smbus_register_device(SMBusDevice
*dev
, uint8_t addr
);
253 struct PCII440FXState
;
254 typedef struct PCII440FXState PCII440FXState
;
256 #define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost"
257 #define TYPE_I440FX_PCI_DEVICE "i440FX"
259 #define TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "igd-passthrough-i440FX"
261 PCIBus
*i440fx_init(const char *host_type
, const char *pci_type
,
262 PCII440FXState
**pi440fx_state
, int *piix_devfn
,
263 ISABus
**isa_bus
, qemu_irq
*pic
,
264 MemoryRegion
*address_space_mem
,
265 MemoryRegion
*address_space_io
,
267 ram_addr_t below_4g_mem_size
,
268 ram_addr_t above_4g_mem_size
,
269 MemoryRegion
*pci_memory
,
270 MemoryRegion
*ram_memory
);
272 PCIBus
*find_i440fx(void);
274 extern PCIDevice
*piix4_dev
;
275 int piix4_init(PCIBus
*bus
, ISABus
**isa_bus
, int devfn
);
278 enum vga_retrace_method
{
283 extern enum vga_retrace_method vga_retrace_method
;
285 int isa_vga_mm_init(hwaddr vram_base
,
286 hwaddr ctrl_base
, int it_shift
,
287 MemoryRegion
*address_space
);
290 static inline bool isa_ne2000_init(ISABus
*bus
, int base
, int irq
, NICInfo
*nd
)
295 qemu_check_nic_model(nd
, "ne2k_isa");
297 isadev
= isa_try_create(bus
, "ne2k_isa");
301 dev
= DEVICE(isadev
);
302 qdev_prop_set_uint32(dev
, "iobase", base
);
303 qdev_prop_set_uint32(dev
, "irq", irq
);
304 qdev_set_nic_properties(dev
, nd
);
305 qdev_init_nofail(dev
);
310 void pc_system_firmware_init(MemoryRegion
*rom_memory
,
314 uint16_t pvpanic_port(void);
318 #define E820_RESERVED 2
321 #define E820_UNUSABLE 5
323 int e820_add_entry(uint64_t, uint64_t, uint32_t);
324 int e820_get_num_entries(void);
325 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
327 #define PC_COMPAT_2_4 \
330 .driver = "Haswell-" TYPE_X86_CPU,\
335 .driver = "Haswell-noTSX-" TYPE_X86_CPU,\
340 .driver = "Broadwell-" TYPE_X86_CPU,\
345 .driver = "Broadwell-noTSX-" TYPE_X86_CPU,\
350 .driver = "host" "-" TYPE_X86_CPU,\
351 .property = "host-cache-info",\
355 .driver = TYPE_X86_CPU,\
356 .property = "check",\
360 .driver = "qemu64" "-" TYPE_X86_CPU,\
361 .property = "sse4a",\
365 .driver = "qemu64" "-" TYPE_X86_CPU,\
370 .driver = "qemu64" "-" TYPE_X86_CPU,\
371 .property = "popcnt",\
375 .driver = "qemu32" "-" TYPE_X86_CPU,\
376 .property = "popcnt",\
379 .driver = "Opteron_G2" "-" TYPE_X86_CPU,\
380 .property = "rdtscp",\
383 .driver = "Opteron_G3" "-" TYPE_X86_CPU,\
384 .property = "rdtscp",\
387 .driver = "Opteron_G4" "-" TYPE_X86_CPU,\
388 .property = "rdtscp",\
391 .driver = "Opteron_G5" "-" TYPE_X86_CPU,\
392 .property = "rdtscp",\
397 #define PC_COMPAT_2_3 \
401 .driver = TYPE_X86_CPU,\
405 .driver = "qemu64" "-" TYPE_X86_CPU,\
406 .property = "level",\
407 .value = stringify(4),\
409 .driver = "kvm64" "-" TYPE_X86_CPU,\
410 .property = "level",\
411 .value = stringify(5),\
413 .driver = "pentium3" "-" TYPE_X86_CPU,\
414 .property = "level",\
415 .value = stringify(2),\
417 .driver = "n270" "-" TYPE_X86_CPU,\
418 .property = "level",\
419 .value = stringify(5),\
421 .driver = "Conroe" "-" TYPE_X86_CPU,\
422 .property = "level",\
423 .value = stringify(4),\
425 .driver = "Penryn" "-" TYPE_X86_CPU,\
426 .property = "level",\
427 .value = stringify(4),\
429 .driver = "Nehalem" "-" TYPE_X86_CPU,\
430 .property = "level",\
431 .value = stringify(4),\
433 .driver = "n270" "-" TYPE_X86_CPU,\
434 .property = "xlevel",\
435 .value = stringify(0x8000000a),\
437 .driver = "Penryn" "-" TYPE_X86_CPU,\
438 .property = "xlevel",\
439 .value = stringify(0x8000000a),\
441 .driver = "Conroe" "-" TYPE_X86_CPU,\
442 .property = "xlevel",\
443 .value = stringify(0x8000000a),\
445 .driver = "Nehalem" "-" TYPE_X86_CPU,\
446 .property = "xlevel",\
447 .value = stringify(0x8000000a),\
449 .driver = "Westmere" "-" TYPE_X86_CPU,\
450 .property = "xlevel",\
451 .value = stringify(0x8000000a),\
453 .driver = "SandyBridge" "-" TYPE_X86_CPU,\
454 .property = "xlevel",\
455 .value = stringify(0x8000000a),\
457 .driver = "IvyBridge" "-" TYPE_X86_CPU,\
458 .property = "xlevel",\
459 .value = stringify(0x8000000a),\
461 .driver = "Haswell" "-" TYPE_X86_CPU,\
462 .property = "xlevel",\
463 .value = stringify(0x8000000a),\
465 .driver = "Haswell-noTSX" "-" TYPE_X86_CPU,\
466 .property = "xlevel",\
467 .value = stringify(0x8000000a),\
469 .driver = "Broadwell" "-" TYPE_X86_CPU,\
470 .property = "xlevel",\
471 .value = stringify(0x8000000a),\
473 .driver = "Broadwell-noTSX" "-" TYPE_X86_CPU,\
474 .property = "xlevel",\
475 .value = stringify(0x8000000a),\
478 #define PC_COMPAT_2_2 \
482 .driver = "kvm64" "-" TYPE_X86_CPU,\
487 .driver = "kvm32" "-" TYPE_X86_CPU,\
492 .driver = "Conroe" "-" TYPE_X86_CPU,\
497 .driver = "Penryn" "-" TYPE_X86_CPU,\
502 .driver = "Nehalem" "-" TYPE_X86_CPU,\
507 .driver = "Westmere" "-" TYPE_X86_CPU,\
512 .driver = "SandyBridge" "-" TYPE_X86_CPU,\
517 .driver = "Haswell" "-" TYPE_X86_CPU,\
522 .driver = "Broadwell" "-" TYPE_X86_CPU,\
527 .driver = "Opteron_G1" "-" TYPE_X86_CPU,\
532 .driver = "Opteron_G2" "-" TYPE_X86_CPU,\
537 .driver = "Opteron_G3" "-" TYPE_X86_CPU,\
542 .driver = "Opteron_G4" "-" TYPE_X86_CPU,\
547 .driver = "Opteron_G5" "-" TYPE_X86_CPU,\
552 .driver = "Haswell" "-" TYPE_X86_CPU,\
557 .driver = "Haswell" "-" TYPE_X86_CPU,\
558 .property = "rdrand",\
562 .driver = "Broadwell" "-" TYPE_X86_CPU,\
567 .driver = "Broadwell" "-" TYPE_X86_CPU,\
568 .property = "rdrand",\
572 #define PC_COMPAT_2_1 \
576 .driver = "coreduo" "-" TYPE_X86_CPU,\
581 .driver = "core2duo" "-" TYPE_X86_CPU,\
586 #define PC_COMPAT_2_0 \
589 .driver = "virtio-scsi-pci",\
590 .property = "any_layout",\
593 .driver = "PIIX4_PM",\
594 .property = "memory-hotplug-support",\
599 .property = "version",\
600 .value = stringify(0x11),\
603 .driver = "nec-usb-xhci",\
604 .property = "superspeed-ports-first",\
608 .driver = "nec-usb-xhci",\
609 .property = "force-pcie-endcap",\
613 .driver = "pci-serial",\
614 .property = "prog_if",\
615 .value = stringify(0),\
618 .driver = "pci-serial-2x",\
619 .property = "prog_if",\
620 .value = stringify(0),\
623 .driver = "pci-serial-4x",\
624 .property = "prog_if",\
625 .value = stringify(0),\
628 .driver = "virtio-net-pci",\
629 .property = "guest_announce",\
633 .driver = "ICH9-LPC",\
634 .property = "memory-hotplug-support",\
637 .driver = "xio3130-downstream",\
638 .property = COMPAT_PROP_PCP,\
641 .driver = "ioh3420",\
642 .property = COMPAT_PROP_PCP,\
646 #define PC_COMPAT_1_7 \
649 .driver = TYPE_USB_DEVICE,\
650 .property = "msos-desc",\
654 .driver = "PIIX4_PM",\
655 .property = "acpi-pci-hotplug-with-bridge-support",\
660 .property = HPET_INTCAP,\
661 .value = stringify(4),\
664 #define PC_COMPAT_1_6 \
668 .property = "mitigation",\
671 .driver = "qemu64-" TYPE_X86_CPU,\
672 .property = "model",\
673 .value = stringify(2),\
675 .driver = "qemu32-" TYPE_X86_CPU,\
676 .property = "model",\
677 .value = stringify(3),\
679 .driver = "i440FX-pcihost",\
680 .property = "short_root_bus",\
681 .value = stringify(1),\
683 .driver = "q35-pcihost",\
684 .property = "short_root_bus",\
685 .value = stringify(1),\
688 #define PC_COMPAT_1_5 \
691 .driver = "Conroe-" TYPE_X86_CPU,\
692 .property = "model",\
693 .value = stringify(2),\
695 .driver = "Conroe-" TYPE_X86_CPU,\
696 .property = "level",\
697 .value = stringify(2),\
699 .driver = "Penryn-" TYPE_X86_CPU,\
700 .property = "model",\
701 .value = stringify(2),\
703 .driver = "Penryn-" TYPE_X86_CPU,\
704 .property = "level",\
705 .value = stringify(2),\
707 .driver = "Nehalem-" TYPE_X86_CPU,\
708 .property = "model",\
709 .value = stringify(2),\
711 .driver = "Nehalem-" TYPE_X86_CPU,\
712 .property = "level",\
713 .value = stringify(2),\
715 .driver = "virtio-net-pci",\
716 .property = "any_layout",\
719 .driver = TYPE_X86_CPU,\
723 .driver = "i440FX-pcihost",\
724 .property = "short_root_bus",\
725 .value = stringify(0),\
727 .driver = "q35-pcihost",\
728 .property = "short_root_bus",\
729 .value = stringify(0),\
732 #define PC_COMPAT_1_4 \
735 .driver = "scsi-hd",\
736 .property = "discard_granularity",\
737 .value = stringify(0),\
739 .driver = "scsi-cd",\
740 .property = "discard_granularity",\
741 .value = stringify(0),\
743 .driver = "scsi-disk",\
744 .property = "discard_granularity",\
745 .value = stringify(0),\
748 .property = "discard_granularity",\
749 .value = stringify(0),\
752 .property = "discard_granularity",\
753 .value = stringify(0),\
755 .driver = "ide-drive",\
756 .property = "discard_granularity",\
757 .value = stringify(0),\
759 .driver = "virtio-blk-pci",\
760 .property = "discard_granularity",\
761 .value = stringify(0),\
763 .driver = "virtio-serial-pci",\
764 .property = "vectors",\
765 /* DEV_NVECTORS_UNSPECIFIED as a uint32_t string */\
766 .value = stringify(0xFFFFFFFF),\
768 .driver = "virtio-net-pci", \
769 .property = "ctrl_guest_offloads", \
773 .property = "romfile",\
774 .value = "pxe-e1000.rom",\
776 .driver = "ne2k_pci",\
777 .property = "romfile",\
778 .value = "pxe-ne2k_pci.rom",\
781 .property = "romfile",\
782 .value = "pxe-pcnet.rom",\
784 .driver = "rtl8139",\
785 .property = "romfile",\
786 .value = "pxe-rtl8139.rom",\
788 .driver = "virtio-net-pci",\
789 .property = "romfile",\
790 .value = "pxe-virtio.rom",\
792 .driver = "486-" TYPE_X86_CPU,\
793 .property = "model",\
794 .value = stringify(0),\
797 .driver = "n270" "-" TYPE_X86_CPU,\
798 .property = "movbe",\
802 .driver = "Westmere" "-" TYPE_X86_CPU,\
803 .property = "pclmulqdq",\
807 #define DEFINE_PC_MACHINE(suffix, namestr, initfn, optsfn) \
808 static void pc_machine_##suffix##_class_init(ObjectClass *oc, void *data) \
810 MachineClass *mc = MACHINE_CLASS(oc); \
812 mc->name = namestr; \
815 static const TypeInfo pc_machine_type_##suffix = { \
816 .name = namestr TYPE_MACHINE_SUFFIX, \
817 .parent = TYPE_PC_MACHINE, \
818 .class_init = pc_machine_##suffix##_class_init, \
820 static void pc_machine_init_##suffix(void) \
822 type_register(&pc_machine_type_##suffix); \
824 machine_init(pc_machine_init_##suffix)
826 #define SET_MACHINE_COMPAT(m, COMPAT) do { \
827 static GlobalProperty props[] = { \
829 { /* end of list */ } \
831 (m)->compat_props = props; \
834 extern void igd_passthrough_isa_bridge_create(PCIBus
*bus
, uint16_t gpu_dev_id
);