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
36 /* Machine info for ACPI build: */
42 * @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling
44 struct PCMachineState
{
46 MachineState parent_obj
;
50 /* State for other subsystems/APIs: */
51 MemoryHotplugState hotplug_memory
;
52 PcGuestInfo acpi_guest_info
;
53 Notifier machine_done
;
55 /* Pointers to devices and objects: */
56 HotplugHandler
*acpi_dev
;
61 /* Configuration options: */
62 uint64_t max_ram_below_4g
;
67 /* RAM information (sizes, addresses, configuration): */
68 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
70 /* CPU and apic information: */
71 bool apic_xrupt_override
;
72 unsigned apic_id_limit
;
74 /* NUMA information: */
80 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
81 #define PC_MACHINE_MEMHP_REGION_SIZE "hotplug-memory-region-size"
82 #define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g"
83 #define PC_MACHINE_VMPORT "vmport"
84 #define PC_MACHINE_SMM "smm"
85 #define PC_MACHINE_NVDIMM "nvdimm"
92 * @get_hotplug_handler: pointer to parent class callback @get_hotplug_handler
96 * @enforce_aligned_dimm: check that DIMM's address/size is aligned by
97 * backend's alignment value if provided
98 * @acpi_data_size: Size of the chunk of memory at the top of RAM
99 * for the BIOS ACPI tables and other BIOS
101 * @gigabyte_align: Make sure that guest addresses aligned at
102 * 1Gbyte boundaries get mapped to host
103 * addresses aligned at 1Gbyte boundaries. This
104 * way we can use 1GByte pages in the host.
107 struct PCMachineClass
{
109 MachineClass parent_class
;
114 HotplugHandler
*(*get_hotplug_handler
)(MachineState
*machine
,
117 /* Device configuration: */
119 bool kvmclock_enabled
;
121 /* Compat options: */
126 int legacy_acpi_table_size
;
127 unsigned acpi_data_size
;
130 bool smbios_defaults
;
131 bool smbios_legacy_mode
;
132 bool smbios_uuid_encoded
;
134 /* RAM / address space compat: */
136 bool has_reserved_memory
;
137 bool enforce_aligned_dimm
;
138 bool broken_reserved_end
;
140 /* TSC rate migration: */
144 #define TYPE_PC_MACHINE "generic-pc-machine"
145 #define PC_MACHINE(obj) \
146 OBJECT_CHECK(PCMachineState, (obj), TYPE_PC_MACHINE)
147 #define PC_MACHINE_GET_CLASS(obj) \
148 OBJECT_GET_CLASS(PCMachineClass, (obj), TYPE_PC_MACHINE)
149 #define PC_MACHINE_CLASS(klass) \
150 OBJECT_CLASS_CHECK(PCMachineClass, (klass), TYPE_PC_MACHINE)
152 /* PC-style peripherals (also used by other machines). */
154 typedef struct PcPciInfo
{
159 #define ACPI_PM_PROP_S3_DISABLED "disable_s3"
160 #define ACPI_PM_PROP_S4_DISABLED "disable_s4"
161 #define ACPI_PM_PROP_S4_VAL "s4_val"
162 #define ACPI_PM_PROP_SCI_INT "sci_int"
163 #define ACPI_PM_PROP_ACPI_ENABLE_CMD "acpi_enable_cmd"
164 #define ACPI_PM_PROP_ACPI_DISABLE_CMD "acpi_disable_cmd"
165 #define ACPI_PM_PROP_PM_IO_BASE "pm_io_base"
166 #define ACPI_PM_PROP_GPE0_BLK "gpe0_blk"
167 #define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len"
168 #define ACPI_PM_PROP_TCO_ENABLED "enable_tco"
172 void parallel_hds_isa_init(ISABus
*bus
, int n
);
174 bool parallel_mm_init(MemoryRegion
*address_space
,
175 hwaddr base
, int it_shift
, qemu_irq irq
,
176 CharDriverState
*chr
);
180 extern DeviceState
*isa_pic
;
181 qemu_irq
*i8259_init(ISABus
*bus
, qemu_irq parent_irq
);
182 qemu_irq
*kvm_i8259_init(ISABus
*bus
);
183 int pic_read_irq(DeviceState
*d
);
184 int pic_get_output(DeviceState
*d
);
185 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
);
186 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
);
190 void kvm_ioapic_dump_state(Monitor
*mon
, const QDict
*qdict
);
191 void ioapic_dump_state(Monitor
*mon
, const QDict
*qdict
);
193 /* Global System Interrupts */
195 #define GSI_NUM_PINS IOAPIC_NUM_PINS
197 typedef struct GSIState
{
198 qemu_irq i8259_irq
[ISA_NUM_IRQS
];
199 qemu_irq ioapic_irq
[IOAPIC_NUM_PINS
];
202 void gsi_handler(void *opaque
, int n
, int level
);
205 typedef uint32_t (VMPortReadFunc
)(void *opaque
, uint32_t address
);
207 static inline void vmport_init(ISABus
*bus
)
209 isa_create_simple(bus
, "vmport");
212 void vmport_register(unsigned char command
, VMPortReadFunc
*func
, void *opaque
);
213 void vmmouse_get_data(uint32_t *data
);
214 void vmmouse_set_data(const uint32_t *data
);
218 void i8042_init(qemu_irq kbd_irq
, qemu_irq mouse_irq
, uint32_t io_base
);
219 void i8042_mm_init(qemu_irq kbd_irq
, qemu_irq mouse_irq
,
220 MemoryRegion
*region
, ram_addr_t size
,
222 void i8042_isa_mouse_fake_event(void *opaque
);
223 void i8042_setup_a20_line(ISADevice
*dev
, qemu_irq
*a20_out
);
226 extern int fd_bootchk
;
228 bool pc_machine_is_smm_enabled(PCMachineState
*pcms
);
229 void pc_register_ferr_irq(qemu_irq irq
);
230 void pc_acpi_smi_interrupt(void *opaque
, int irq
, int level
);
232 void pc_cpus_init(PCMachineState
*pcms
);
233 void pc_hot_add_cpu(const int64_t id
, Error
**errp
);
234 void pc_acpi_init(const char *default_dsdt
);
236 PcGuestInfo
*pc_guest_info_init(PCMachineState
*pcms
);
238 #define PCI_HOST_PROP_PCI_HOLE_START "pci-hole-start"
239 #define PCI_HOST_PROP_PCI_HOLE_END "pci-hole-end"
240 #define PCI_HOST_PROP_PCI_HOLE64_START "pci-hole64-start"
241 #define PCI_HOST_PROP_PCI_HOLE64_END "pci-hole64-end"
242 #define PCI_HOST_PROP_PCI_HOLE64_SIZE "pci-hole64-size"
243 #define DEFAULT_PCI_HOLE64_SIZE (~0x0ULL)
246 void pc_pci_as_mapping_init(Object
*owner
, MemoryRegion
*system_memory
,
247 MemoryRegion
*pci_address_space
);
249 void xen_load_linux(PCMachineState
*pcms
);
250 void pc_memory_init(PCMachineState
*pcms
,
251 MemoryRegion
*system_memory
,
252 MemoryRegion
*rom_memory
,
253 MemoryRegion
**ram_memory
);
254 qemu_irq
pc_allocate_cpu_irq(void);
255 DeviceState
*pc_vga_init(ISABus
*isa_bus
, PCIBus
*pci_bus
);
256 void pc_basic_device_init(ISABus
*isa_bus
, qemu_irq
*gsi
,
257 ISADevice
**rtc_state
,
261 void pc_init_ne2k_isa(ISABus
*bus
, NICInfo
*nd
);
262 void pc_cmos_init(PCMachineState
*pcms
,
263 BusState
*ide0
, BusState
*ide1
,
265 void pc_nic_init(ISABus
*isa_bus
, PCIBus
*pci_bus
);
266 void pc_pci_device_init(PCIBus
*pci_bus
);
268 typedef void (*cpu_set_smm_t
)(int smm
, void *arg
);
270 void ioapic_init_gsi(GSIState
*gsi_state
, const char *parent_name
);
272 ISADevice
*pc_find_fdc0(void);
276 I2CBus
*piix4_pm_init(PCIBus
*bus
, int devfn
, uint32_t smb_io_base
,
277 qemu_irq sci_irq
, qemu_irq smi_irq
,
278 int smm_enabled
, DeviceState
**piix4_pm
);
279 void piix4_smbus_register_device(SMBusDevice
*dev
, uint8_t addr
);
285 struct PCII440FXState
;
286 typedef struct PCII440FXState PCII440FXState
;
288 #define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost"
289 #define TYPE_I440FX_PCI_DEVICE "i440FX"
291 #define TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "igd-passthrough-i440FX"
293 PCIBus
*i440fx_init(const char *host_type
, const char *pci_type
,
294 PCII440FXState
**pi440fx_state
, int *piix_devfn
,
295 ISABus
**isa_bus
, qemu_irq
*pic
,
296 MemoryRegion
*address_space_mem
,
297 MemoryRegion
*address_space_io
,
299 ram_addr_t below_4g_mem_size
,
300 ram_addr_t above_4g_mem_size
,
301 MemoryRegion
*pci_memory
,
302 MemoryRegion
*ram_memory
);
304 PCIBus
*find_i440fx(void);
306 extern PCIDevice
*piix4_dev
;
307 int piix4_init(PCIBus
*bus
, ISABus
**isa_bus
, int devfn
);
310 enum vga_retrace_method
{
315 extern enum vga_retrace_method vga_retrace_method
;
317 int isa_vga_mm_init(hwaddr vram_base
,
318 hwaddr ctrl_base
, int it_shift
,
319 MemoryRegion
*address_space
);
322 static inline bool isa_ne2000_init(ISABus
*bus
, int base
, int irq
, NICInfo
*nd
)
327 qemu_check_nic_model(nd
, "ne2k_isa");
329 isadev
= isa_try_create(bus
, "ne2k_isa");
333 dev
= DEVICE(isadev
);
334 qdev_prop_set_uint32(dev
, "iobase", base
);
335 qdev_prop_set_uint32(dev
, "irq", irq
);
336 qdev_set_nic_properties(dev
, nd
);
337 qdev_init_nofail(dev
);
342 void pc_system_firmware_init(MemoryRegion
*rom_memory
,
346 uint16_t pvpanic_port(void);
350 #define E820_RESERVED 2
353 #define E820_UNUSABLE 5
355 int e820_add_entry(uint64_t, uint64_t, uint32_t);
356 int e820_get_num_entries(void);
357 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
359 #define PC_COMPAT_2_5 \
362 #define PC_COMPAT_2_4 \
366 .driver = "Haswell-" TYPE_X86_CPU,\
371 .driver = "Haswell-noTSX-" TYPE_X86_CPU,\
376 .driver = "Broadwell-" TYPE_X86_CPU,\
381 .driver = "Broadwell-noTSX-" TYPE_X86_CPU,\
386 .driver = "host" "-" TYPE_X86_CPU,\
387 .property = "host-cache-info",\
391 .driver = TYPE_X86_CPU,\
392 .property = "check",\
396 .driver = "qemu64" "-" TYPE_X86_CPU,\
397 .property = "sse4a",\
401 .driver = "qemu64" "-" TYPE_X86_CPU,\
406 .driver = "qemu64" "-" TYPE_X86_CPU,\
407 .property = "popcnt",\
411 .driver = "qemu32" "-" TYPE_X86_CPU,\
412 .property = "popcnt",\
415 .driver = "Opteron_G2" "-" TYPE_X86_CPU,\
416 .property = "rdtscp",\
419 .driver = "Opteron_G3" "-" TYPE_X86_CPU,\
420 .property = "rdtscp",\
423 .driver = "Opteron_G4" "-" TYPE_X86_CPU,\
424 .property = "rdtscp",\
427 .driver = "Opteron_G5" "-" TYPE_X86_CPU,\
428 .property = "rdtscp",\
433 #define PC_COMPAT_2_3 \
437 .driver = TYPE_X86_CPU,\
441 .driver = "qemu64" "-" TYPE_X86_CPU,\
442 .property = "level",\
443 .value = stringify(4),\
445 .driver = "kvm64" "-" TYPE_X86_CPU,\
446 .property = "level",\
447 .value = stringify(5),\
449 .driver = "pentium3" "-" TYPE_X86_CPU,\
450 .property = "level",\
451 .value = stringify(2),\
453 .driver = "n270" "-" TYPE_X86_CPU,\
454 .property = "level",\
455 .value = stringify(5),\
457 .driver = "Conroe" "-" TYPE_X86_CPU,\
458 .property = "level",\
459 .value = stringify(4),\
461 .driver = "Penryn" "-" TYPE_X86_CPU,\
462 .property = "level",\
463 .value = stringify(4),\
465 .driver = "Nehalem" "-" TYPE_X86_CPU,\
466 .property = "level",\
467 .value = stringify(4),\
469 .driver = "n270" "-" TYPE_X86_CPU,\
470 .property = "xlevel",\
471 .value = stringify(0x8000000a),\
473 .driver = "Penryn" "-" TYPE_X86_CPU,\
474 .property = "xlevel",\
475 .value = stringify(0x8000000a),\
477 .driver = "Conroe" "-" TYPE_X86_CPU,\
478 .property = "xlevel",\
479 .value = stringify(0x8000000a),\
481 .driver = "Nehalem" "-" TYPE_X86_CPU,\
482 .property = "xlevel",\
483 .value = stringify(0x8000000a),\
485 .driver = "Westmere" "-" TYPE_X86_CPU,\
486 .property = "xlevel",\
487 .value = stringify(0x8000000a),\
489 .driver = "SandyBridge" "-" TYPE_X86_CPU,\
490 .property = "xlevel",\
491 .value = stringify(0x8000000a),\
493 .driver = "IvyBridge" "-" TYPE_X86_CPU,\
494 .property = "xlevel",\
495 .value = stringify(0x8000000a),\
497 .driver = "Haswell" "-" TYPE_X86_CPU,\
498 .property = "xlevel",\
499 .value = stringify(0x8000000a),\
501 .driver = "Haswell-noTSX" "-" TYPE_X86_CPU,\
502 .property = "xlevel",\
503 .value = stringify(0x8000000a),\
505 .driver = "Broadwell" "-" TYPE_X86_CPU,\
506 .property = "xlevel",\
507 .value = stringify(0x8000000a),\
509 .driver = "Broadwell-noTSX" "-" TYPE_X86_CPU,\
510 .property = "xlevel",\
511 .value = stringify(0x8000000a),\
514 #define PC_COMPAT_2_2 \
518 .driver = "kvm64" "-" TYPE_X86_CPU,\
523 .driver = "kvm32" "-" TYPE_X86_CPU,\
528 .driver = "Conroe" "-" TYPE_X86_CPU,\
533 .driver = "Penryn" "-" TYPE_X86_CPU,\
538 .driver = "Nehalem" "-" TYPE_X86_CPU,\
543 .driver = "Westmere" "-" TYPE_X86_CPU,\
548 .driver = "SandyBridge" "-" TYPE_X86_CPU,\
553 .driver = "Haswell" "-" TYPE_X86_CPU,\
558 .driver = "Broadwell" "-" TYPE_X86_CPU,\
563 .driver = "Opteron_G1" "-" TYPE_X86_CPU,\
568 .driver = "Opteron_G2" "-" TYPE_X86_CPU,\
573 .driver = "Opteron_G3" "-" TYPE_X86_CPU,\
578 .driver = "Opteron_G4" "-" TYPE_X86_CPU,\
583 .driver = "Opteron_G5" "-" TYPE_X86_CPU,\
588 .driver = "Haswell" "-" TYPE_X86_CPU,\
593 .driver = "Haswell" "-" TYPE_X86_CPU,\
594 .property = "rdrand",\
598 .driver = "Broadwell" "-" TYPE_X86_CPU,\
603 .driver = "Broadwell" "-" TYPE_X86_CPU,\
604 .property = "rdrand",\
608 #define PC_COMPAT_2_1 \
612 .driver = "coreduo" "-" TYPE_X86_CPU,\
617 .driver = "core2duo" "-" TYPE_X86_CPU,\
622 #define PC_COMPAT_2_0 \
625 .driver = "virtio-scsi-pci",\
626 .property = "any_layout",\
629 .driver = "PIIX4_PM",\
630 .property = "memory-hotplug-support",\
635 .property = "version",\
636 .value = stringify(0x11),\
639 .driver = "nec-usb-xhci",\
640 .property = "superspeed-ports-first",\
644 .driver = "nec-usb-xhci",\
645 .property = "force-pcie-endcap",\
649 .driver = "pci-serial",\
650 .property = "prog_if",\
651 .value = stringify(0),\
654 .driver = "pci-serial-2x",\
655 .property = "prog_if",\
656 .value = stringify(0),\
659 .driver = "pci-serial-4x",\
660 .property = "prog_if",\
661 .value = stringify(0),\
664 .driver = "virtio-net-pci",\
665 .property = "guest_announce",\
669 .driver = "ICH9-LPC",\
670 .property = "memory-hotplug-support",\
673 .driver = "xio3130-downstream",\
674 .property = COMPAT_PROP_PCP,\
677 .driver = "ioh3420",\
678 .property = COMPAT_PROP_PCP,\
682 #define PC_COMPAT_1_7 \
685 .driver = TYPE_USB_DEVICE,\
686 .property = "msos-desc",\
690 .driver = "PIIX4_PM",\
691 .property = "acpi-pci-hotplug-with-bridge-support",\
696 .property = HPET_INTCAP,\
697 .value = stringify(4),\
700 #define PC_COMPAT_1_6 \
704 .property = "mitigation",\
707 .driver = "qemu64-" TYPE_X86_CPU,\
708 .property = "model",\
709 .value = stringify(2),\
711 .driver = "qemu32-" TYPE_X86_CPU,\
712 .property = "model",\
713 .value = stringify(3),\
715 .driver = "i440FX-pcihost",\
716 .property = "short_root_bus",\
717 .value = stringify(1),\
719 .driver = "q35-pcihost",\
720 .property = "short_root_bus",\
721 .value = stringify(1),\
724 #define PC_COMPAT_1_5 \
727 .driver = "Conroe-" TYPE_X86_CPU,\
728 .property = "model",\
729 .value = stringify(2),\
731 .driver = "Conroe-" TYPE_X86_CPU,\
732 .property = "level",\
733 .value = stringify(2),\
735 .driver = "Penryn-" TYPE_X86_CPU,\
736 .property = "model",\
737 .value = stringify(2),\
739 .driver = "Penryn-" TYPE_X86_CPU,\
740 .property = "level",\
741 .value = stringify(2),\
743 .driver = "Nehalem-" TYPE_X86_CPU,\
744 .property = "model",\
745 .value = stringify(2),\
747 .driver = "Nehalem-" TYPE_X86_CPU,\
748 .property = "level",\
749 .value = stringify(2),\
751 .driver = "virtio-net-pci",\
752 .property = "any_layout",\
755 .driver = TYPE_X86_CPU,\
759 .driver = "i440FX-pcihost",\
760 .property = "short_root_bus",\
761 .value = stringify(0),\
763 .driver = "q35-pcihost",\
764 .property = "short_root_bus",\
765 .value = stringify(0),\
768 #define PC_COMPAT_1_4 \
771 .driver = "scsi-hd",\
772 .property = "discard_granularity",\
773 .value = stringify(0),\
775 .driver = "scsi-cd",\
776 .property = "discard_granularity",\
777 .value = stringify(0),\
779 .driver = "scsi-disk",\
780 .property = "discard_granularity",\
781 .value = stringify(0),\
784 .property = "discard_granularity",\
785 .value = stringify(0),\
788 .property = "discard_granularity",\
789 .value = stringify(0),\
791 .driver = "ide-drive",\
792 .property = "discard_granularity",\
793 .value = stringify(0),\
795 .driver = "virtio-blk-pci",\
796 .property = "discard_granularity",\
797 .value = stringify(0),\
799 .driver = "virtio-serial-pci",\
800 .property = "vectors",\
801 /* DEV_NVECTORS_UNSPECIFIED as a uint32_t string */\
802 .value = stringify(0xFFFFFFFF),\
804 .driver = "virtio-net-pci", \
805 .property = "ctrl_guest_offloads", \
809 .property = "romfile",\
810 .value = "pxe-e1000.rom",\
812 .driver = "ne2k_pci",\
813 .property = "romfile",\
814 .value = "pxe-ne2k_pci.rom",\
817 .property = "romfile",\
818 .value = "pxe-pcnet.rom",\
820 .driver = "rtl8139",\
821 .property = "romfile",\
822 .value = "pxe-rtl8139.rom",\
824 .driver = "virtio-net-pci",\
825 .property = "romfile",\
826 .value = "pxe-virtio.rom",\
828 .driver = "486-" TYPE_X86_CPU,\
829 .property = "model",\
830 .value = stringify(0),\
833 .driver = "n270" "-" TYPE_X86_CPU,\
834 .property = "movbe",\
838 .driver = "Westmere" "-" TYPE_X86_CPU,\
839 .property = "pclmulqdq",\
843 #define DEFINE_PC_MACHINE(suffix, namestr, initfn, optsfn) \
844 static void pc_machine_##suffix##_class_init(ObjectClass *oc, void *data) \
846 MachineClass *mc = MACHINE_CLASS(oc); \
848 mc->name = namestr; \
851 static const TypeInfo pc_machine_type_##suffix = { \
852 .name = namestr TYPE_MACHINE_SUFFIX, \
853 .parent = TYPE_PC_MACHINE, \
854 .class_init = pc_machine_##suffix##_class_init, \
856 static void pc_machine_init_##suffix(void) \
858 type_register(&pc_machine_type_##suffix); \
860 machine_init(pc_machine_init_##suffix)
862 extern void igd_passthrough_isa_bridge_create(PCIBus
*bus
, uint16_t gpu_dev_id
);