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: */
38 unsigned apic_id_limit
;
39 bool apic_xrupt_override
;
47 * @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling
49 struct PCMachineState
{
51 MachineState parent_obj
;
55 /* State for other subsystems/APIs: */
56 MemoryHotplugState hotplug_memory
;
57 PcGuestInfo acpi_guest_info
;
58 Notifier machine_done
;
60 /* Pointers to devices and objects: */
61 HotplugHandler
*acpi_dev
;
66 /* Configuration options: */
67 uint64_t max_ram_below_4g
;
72 /* RAM information (sizes, addresses, configuration): */
73 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
76 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
77 #define PC_MACHINE_MEMHP_REGION_SIZE "hotplug-memory-region-size"
78 #define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g"
79 #define PC_MACHINE_VMPORT "vmport"
80 #define PC_MACHINE_SMM "smm"
81 #define PC_MACHINE_NVDIMM "nvdimm"
88 * @get_hotplug_handler: pointer to parent class callback @get_hotplug_handler
92 * @enforce_aligned_dimm: check that DIMM's address/size is aligned by
93 * backend's alignment value if provided
94 * @acpi_data_size: Size of the chunk of memory at the top of RAM
95 * for the BIOS ACPI tables and other BIOS
97 * @gigabyte_align: Make sure that guest addresses aligned at
98 * 1Gbyte boundaries get mapped to host
99 * addresses aligned at 1Gbyte boundaries. This
100 * way we can use 1GByte pages in the host.
103 struct PCMachineClass
{
105 MachineClass parent_class
;
110 HotplugHandler
*(*get_hotplug_handler
)(MachineState
*machine
,
113 /* Device configuration: */
115 bool kvmclock_enabled
;
117 /* Compat options: */
122 int legacy_acpi_table_size
;
123 unsigned acpi_data_size
;
126 bool smbios_defaults
;
127 bool smbios_legacy_mode
;
128 bool smbios_uuid_encoded
;
130 /* RAM / address space compat: */
132 bool has_reserved_memory
;
133 bool enforce_aligned_dimm
;
134 bool broken_reserved_end
;
136 /* TSC rate migration: */
140 #define TYPE_PC_MACHINE "generic-pc-machine"
141 #define PC_MACHINE(obj) \
142 OBJECT_CHECK(PCMachineState, (obj), TYPE_PC_MACHINE)
143 #define PC_MACHINE_GET_CLASS(obj) \
144 OBJECT_GET_CLASS(PCMachineClass, (obj), TYPE_PC_MACHINE)
145 #define PC_MACHINE_CLASS(klass) \
146 OBJECT_CLASS_CHECK(PCMachineClass, (klass), TYPE_PC_MACHINE)
148 /* PC-style peripherals (also used by other machines). */
150 typedef struct PcPciInfo
{
155 #define ACPI_PM_PROP_S3_DISABLED "disable_s3"
156 #define ACPI_PM_PROP_S4_DISABLED "disable_s4"
157 #define ACPI_PM_PROP_S4_VAL "s4_val"
158 #define ACPI_PM_PROP_SCI_INT "sci_int"
159 #define ACPI_PM_PROP_ACPI_ENABLE_CMD "acpi_enable_cmd"
160 #define ACPI_PM_PROP_ACPI_DISABLE_CMD "acpi_disable_cmd"
161 #define ACPI_PM_PROP_PM_IO_BASE "pm_io_base"
162 #define ACPI_PM_PROP_GPE0_BLK "gpe0_blk"
163 #define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len"
164 #define ACPI_PM_PROP_TCO_ENABLED "enable_tco"
168 void parallel_hds_isa_init(ISABus
*bus
, int n
);
170 bool parallel_mm_init(MemoryRegion
*address_space
,
171 hwaddr base
, int it_shift
, qemu_irq irq
,
172 CharDriverState
*chr
);
176 extern DeviceState
*isa_pic
;
177 qemu_irq
*i8259_init(ISABus
*bus
, qemu_irq parent_irq
);
178 qemu_irq
*kvm_i8259_init(ISABus
*bus
);
179 int pic_read_irq(DeviceState
*d
);
180 int pic_get_output(DeviceState
*d
);
181 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
);
182 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
);
186 void kvm_ioapic_dump_state(Monitor
*mon
, const QDict
*qdict
);
187 void ioapic_dump_state(Monitor
*mon
, const QDict
*qdict
);
189 /* Global System Interrupts */
191 #define GSI_NUM_PINS IOAPIC_NUM_PINS
193 typedef struct GSIState
{
194 qemu_irq i8259_irq
[ISA_NUM_IRQS
];
195 qemu_irq ioapic_irq
[IOAPIC_NUM_PINS
];
198 void gsi_handler(void *opaque
, int n
, int level
);
201 typedef uint32_t (VMPortReadFunc
)(void *opaque
, uint32_t address
);
203 static inline void vmport_init(ISABus
*bus
)
205 isa_create_simple(bus
, "vmport");
208 void vmport_register(unsigned char command
, VMPortReadFunc
*func
, void *opaque
);
209 void vmmouse_get_data(uint32_t *data
);
210 void vmmouse_set_data(const uint32_t *data
);
214 void i8042_init(qemu_irq kbd_irq
, qemu_irq mouse_irq
, uint32_t io_base
);
215 void i8042_mm_init(qemu_irq kbd_irq
, qemu_irq mouse_irq
,
216 MemoryRegion
*region
, ram_addr_t size
,
218 void i8042_isa_mouse_fake_event(void *opaque
);
219 void i8042_setup_a20_line(ISADevice
*dev
, qemu_irq
*a20_out
);
222 extern int fd_bootchk
;
224 bool pc_machine_is_smm_enabled(PCMachineState
*pcms
);
225 void pc_register_ferr_irq(qemu_irq irq
);
226 void pc_acpi_smi_interrupt(void *opaque
, int irq
, int level
);
228 void pc_cpus_init(PCMachineState
*pcms
);
229 void pc_hot_add_cpu(const int64_t id
, Error
**errp
);
230 void pc_acpi_init(const char *default_dsdt
);
232 PcGuestInfo
*pc_guest_info_init(PCMachineState
*pcms
);
234 #define PCI_HOST_PROP_PCI_HOLE_START "pci-hole-start"
235 #define PCI_HOST_PROP_PCI_HOLE_END "pci-hole-end"
236 #define PCI_HOST_PROP_PCI_HOLE64_START "pci-hole64-start"
237 #define PCI_HOST_PROP_PCI_HOLE64_END "pci-hole64-end"
238 #define PCI_HOST_PROP_PCI_HOLE64_SIZE "pci-hole64-size"
239 #define DEFAULT_PCI_HOLE64_SIZE (~0x0ULL)
242 void pc_pci_as_mapping_init(Object
*owner
, MemoryRegion
*system_memory
,
243 MemoryRegion
*pci_address_space
);
245 void xen_load_linux(PCMachineState
*pcms
);
246 void pc_memory_init(PCMachineState
*pcms
,
247 MemoryRegion
*system_memory
,
248 MemoryRegion
*rom_memory
,
249 MemoryRegion
**ram_memory
);
250 qemu_irq
pc_allocate_cpu_irq(void);
251 DeviceState
*pc_vga_init(ISABus
*isa_bus
, PCIBus
*pci_bus
);
252 void pc_basic_device_init(ISABus
*isa_bus
, qemu_irq
*gsi
,
253 ISADevice
**rtc_state
,
257 void pc_init_ne2k_isa(ISABus
*bus
, NICInfo
*nd
);
258 void pc_cmos_init(PCMachineState
*pcms
,
259 BusState
*ide0
, BusState
*ide1
,
261 void pc_nic_init(ISABus
*isa_bus
, PCIBus
*pci_bus
);
262 void pc_pci_device_init(PCIBus
*pci_bus
);
264 typedef void (*cpu_set_smm_t
)(int smm
, void *arg
);
266 void ioapic_init_gsi(GSIState
*gsi_state
, const char *parent_name
);
268 ISADevice
*pc_find_fdc0(void);
272 I2CBus
*piix4_pm_init(PCIBus
*bus
, int devfn
, uint32_t smb_io_base
,
273 qemu_irq sci_irq
, qemu_irq smi_irq
,
274 int smm_enabled
, DeviceState
**piix4_pm
);
275 void piix4_smbus_register_device(SMBusDevice
*dev
, uint8_t addr
);
281 struct PCII440FXState
;
282 typedef struct PCII440FXState PCII440FXState
;
284 #define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost"
285 #define TYPE_I440FX_PCI_DEVICE "i440FX"
287 #define TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "igd-passthrough-i440FX"
289 PCIBus
*i440fx_init(const char *host_type
, const char *pci_type
,
290 PCII440FXState
**pi440fx_state
, int *piix_devfn
,
291 ISABus
**isa_bus
, qemu_irq
*pic
,
292 MemoryRegion
*address_space_mem
,
293 MemoryRegion
*address_space_io
,
295 ram_addr_t below_4g_mem_size
,
296 ram_addr_t above_4g_mem_size
,
297 MemoryRegion
*pci_memory
,
298 MemoryRegion
*ram_memory
);
300 PCIBus
*find_i440fx(void);
302 extern PCIDevice
*piix4_dev
;
303 int piix4_init(PCIBus
*bus
, ISABus
**isa_bus
, int devfn
);
306 enum vga_retrace_method
{
311 extern enum vga_retrace_method vga_retrace_method
;
313 int isa_vga_mm_init(hwaddr vram_base
,
314 hwaddr ctrl_base
, int it_shift
,
315 MemoryRegion
*address_space
);
318 static inline bool isa_ne2000_init(ISABus
*bus
, int base
, int irq
, NICInfo
*nd
)
323 qemu_check_nic_model(nd
, "ne2k_isa");
325 isadev
= isa_try_create(bus
, "ne2k_isa");
329 dev
= DEVICE(isadev
);
330 qdev_prop_set_uint32(dev
, "iobase", base
);
331 qdev_prop_set_uint32(dev
, "irq", irq
);
332 qdev_set_nic_properties(dev
, nd
);
333 qdev_init_nofail(dev
);
338 void pc_system_firmware_init(MemoryRegion
*rom_memory
,
342 uint16_t pvpanic_port(void);
346 #define E820_RESERVED 2
349 #define E820_UNUSABLE 5
351 int e820_add_entry(uint64_t, uint64_t, uint32_t);
352 int e820_get_num_entries(void);
353 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
355 #define PC_COMPAT_2_5 \
358 #define PC_COMPAT_2_4 \
362 .driver = "Haswell-" TYPE_X86_CPU,\
367 .driver = "Haswell-noTSX-" TYPE_X86_CPU,\
372 .driver = "Broadwell-" TYPE_X86_CPU,\
377 .driver = "Broadwell-noTSX-" TYPE_X86_CPU,\
382 .driver = "host" "-" TYPE_X86_CPU,\
383 .property = "host-cache-info",\
387 .driver = TYPE_X86_CPU,\
388 .property = "check",\
392 .driver = "qemu64" "-" TYPE_X86_CPU,\
393 .property = "sse4a",\
397 .driver = "qemu64" "-" TYPE_X86_CPU,\
402 .driver = "qemu64" "-" TYPE_X86_CPU,\
403 .property = "popcnt",\
407 .driver = "qemu32" "-" TYPE_X86_CPU,\
408 .property = "popcnt",\
411 .driver = "Opteron_G2" "-" TYPE_X86_CPU,\
412 .property = "rdtscp",\
415 .driver = "Opteron_G3" "-" TYPE_X86_CPU,\
416 .property = "rdtscp",\
419 .driver = "Opteron_G4" "-" TYPE_X86_CPU,\
420 .property = "rdtscp",\
423 .driver = "Opteron_G5" "-" TYPE_X86_CPU,\
424 .property = "rdtscp",\
429 #define PC_COMPAT_2_3 \
433 .driver = TYPE_X86_CPU,\
437 .driver = "qemu64" "-" TYPE_X86_CPU,\
438 .property = "level",\
439 .value = stringify(4),\
441 .driver = "kvm64" "-" TYPE_X86_CPU,\
442 .property = "level",\
443 .value = stringify(5),\
445 .driver = "pentium3" "-" TYPE_X86_CPU,\
446 .property = "level",\
447 .value = stringify(2),\
449 .driver = "n270" "-" TYPE_X86_CPU,\
450 .property = "level",\
451 .value = stringify(5),\
453 .driver = "Conroe" "-" TYPE_X86_CPU,\
454 .property = "level",\
455 .value = stringify(4),\
457 .driver = "Penryn" "-" TYPE_X86_CPU,\
458 .property = "level",\
459 .value = stringify(4),\
461 .driver = "Nehalem" "-" TYPE_X86_CPU,\
462 .property = "level",\
463 .value = stringify(4),\
465 .driver = "n270" "-" TYPE_X86_CPU,\
466 .property = "xlevel",\
467 .value = stringify(0x8000000a),\
469 .driver = "Penryn" "-" TYPE_X86_CPU,\
470 .property = "xlevel",\
471 .value = stringify(0x8000000a),\
473 .driver = "Conroe" "-" TYPE_X86_CPU,\
474 .property = "xlevel",\
475 .value = stringify(0x8000000a),\
477 .driver = "Nehalem" "-" TYPE_X86_CPU,\
478 .property = "xlevel",\
479 .value = stringify(0x8000000a),\
481 .driver = "Westmere" "-" TYPE_X86_CPU,\
482 .property = "xlevel",\
483 .value = stringify(0x8000000a),\
485 .driver = "SandyBridge" "-" TYPE_X86_CPU,\
486 .property = "xlevel",\
487 .value = stringify(0x8000000a),\
489 .driver = "IvyBridge" "-" TYPE_X86_CPU,\
490 .property = "xlevel",\
491 .value = stringify(0x8000000a),\
493 .driver = "Haswell" "-" TYPE_X86_CPU,\
494 .property = "xlevel",\
495 .value = stringify(0x8000000a),\
497 .driver = "Haswell-noTSX" "-" TYPE_X86_CPU,\
498 .property = "xlevel",\
499 .value = stringify(0x8000000a),\
501 .driver = "Broadwell" "-" TYPE_X86_CPU,\
502 .property = "xlevel",\
503 .value = stringify(0x8000000a),\
505 .driver = "Broadwell-noTSX" "-" TYPE_X86_CPU,\
506 .property = "xlevel",\
507 .value = stringify(0x8000000a),\
510 #define PC_COMPAT_2_2 \
514 .driver = "kvm64" "-" TYPE_X86_CPU,\
519 .driver = "kvm32" "-" TYPE_X86_CPU,\
524 .driver = "Conroe" "-" TYPE_X86_CPU,\
529 .driver = "Penryn" "-" TYPE_X86_CPU,\
534 .driver = "Nehalem" "-" TYPE_X86_CPU,\
539 .driver = "Westmere" "-" TYPE_X86_CPU,\
544 .driver = "SandyBridge" "-" TYPE_X86_CPU,\
549 .driver = "Haswell" "-" TYPE_X86_CPU,\
554 .driver = "Broadwell" "-" TYPE_X86_CPU,\
559 .driver = "Opteron_G1" "-" TYPE_X86_CPU,\
564 .driver = "Opteron_G2" "-" TYPE_X86_CPU,\
569 .driver = "Opteron_G3" "-" TYPE_X86_CPU,\
574 .driver = "Opteron_G4" "-" TYPE_X86_CPU,\
579 .driver = "Opteron_G5" "-" TYPE_X86_CPU,\
584 .driver = "Haswell" "-" TYPE_X86_CPU,\
589 .driver = "Haswell" "-" TYPE_X86_CPU,\
590 .property = "rdrand",\
594 .driver = "Broadwell" "-" TYPE_X86_CPU,\
599 .driver = "Broadwell" "-" TYPE_X86_CPU,\
600 .property = "rdrand",\
604 #define PC_COMPAT_2_1 \
608 .driver = "coreduo" "-" TYPE_X86_CPU,\
613 .driver = "core2duo" "-" TYPE_X86_CPU,\
618 #define PC_COMPAT_2_0 \
621 .driver = "virtio-scsi-pci",\
622 .property = "any_layout",\
625 .driver = "PIIX4_PM",\
626 .property = "memory-hotplug-support",\
631 .property = "version",\
632 .value = stringify(0x11),\
635 .driver = "nec-usb-xhci",\
636 .property = "superspeed-ports-first",\
640 .driver = "nec-usb-xhci",\
641 .property = "force-pcie-endcap",\
645 .driver = "pci-serial",\
646 .property = "prog_if",\
647 .value = stringify(0),\
650 .driver = "pci-serial-2x",\
651 .property = "prog_if",\
652 .value = stringify(0),\
655 .driver = "pci-serial-4x",\
656 .property = "prog_if",\
657 .value = stringify(0),\
660 .driver = "virtio-net-pci",\
661 .property = "guest_announce",\
665 .driver = "ICH9-LPC",\
666 .property = "memory-hotplug-support",\
669 .driver = "xio3130-downstream",\
670 .property = COMPAT_PROP_PCP,\
673 .driver = "ioh3420",\
674 .property = COMPAT_PROP_PCP,\
678 #define PC_COMPAT_1_7 \
681 .driver = TYPE_USB_DEVICE,\
682 .property = "msos-desc",\
686 .driver = "PIIX4_PM",\
687 .property = "acpi-pci-hotplug-with-bridge-support",\
692 .property = HPET_INTCAP,\
693 .value = stringify(4),\
696 #define PC_COMPAT_1_6 \
700 .property = "mitigation",\
703 .driver = "qemu64-" TYPE_X86_CPU,\
704 .property = "model",\
705 .value = stringify(2),\
707 .driver = "qemu32-" TYPE_X86_CPU,\
708 .property = "model",\
709 .value = stringify(3),\
711 .driver = "i440FX-pcihost",\
712 .property = "short_root_bus",\
713 .value = stringify(1),\
715 .driver = "q35-pcihost",\
716 .property = "short_root_bus",\
717 .value = stringify(1),\
720 #define PC_COMPAT_1_5 \
723 .driver = "Conroe-" TYPE_X86_CPU,\
724 .property = "model",\
725 .value = stringify(2),\
727 .driver = "Conroe-" TYPE_X86_CPU,\
728 .property = "level",\
729 .value = stringify(2),\
731 .driver = "Penryn-" TYPE_X86_CPU,\
732 .property = "model",\
733 .value = stringify(2),\
735 .driver = "Penryn-" TYPE_X86_CPU,\
736 .property = "level",\
737 .value = stringify(2),\
739 .driver = "Nehalem-" TYPE_X86_CPU,\
740 .property = "model",\
741 .value = stringify(2),\
743 .driver = "Nehalem-" TYPE_X86_CPU,\
744 .property = "level",\
745 .value = stringify(2),\
747 .driver = "virtio-net-pci",\
748 .property = "any_layout",\
751 .driver = TYPE_X86_CPU,\
755 .driver = "i440FX-pcihost",\
756 .property = "short_root_bus",\
757 .value = stringify(0),\
759 .driver = "q35-pcihost",\
760 .property = "short_root_bus",\
761 .value = stringify(0),\
764 #define PC_COMPAT_1_4 \
767 .driver = "scsi-hd",\
768 .property = "discard_granularity",\
769 .value = stringify(0),\
771 .driver = "scsi-cd",\
772 .property = "discard_granularity",\
773 .value = stringify(0),\
775 .driver = "scsi-disk",\
776 .property = "discard_granularity",\
777 .value = stringify(0),\
780 .property = "discard_granularity",\
781 .value = stringify(0),\
784 .property = "discard_granularity",\
785 .value = stringify(0),\
787 .driver = "ide-drive",\
788 .property = "discard_granularity",\
789 .value = stringify(0),\
791 .driver = "virtio-blk-pci",\
792 .property = "discard_granularity",\
793 .value = stringify(0),\
795 .driver = "virtio-serial-pci",\
796 .property = "vectors",\
797 /* DEV_NVECTORS_UNSPECIFIED as a uint32_t string */\
798 .value = stringify(0xFFFFFFFF),\
800 .driver = "virtio-net-pci", \
801 .property = "ctrl_guest_offloads", \
805 .property = "romfile",\
806 .value = "pxe-e1000.rom",\
808 .driver = "ne2k_pci",\
809 .property = "romfile",\
810 .value = "pxe-ne2k_pci.rom",\
813 .property = "romfile",\
814 .value = "pxe-pcnet.rom",\
816 .driver = "rtl8139",\
817 .property = "romfile",\
818 .value = "pxe-rtl8139.rom",\
820 .driver = "virtio-net-pci",\
821 .property = "romfile",\
822 .value = "pxe-virtio.rom",\
824 .driver = "486-" TYPE_X86_CPU,\
825 .property = "model",\
826 .value = stringify(0),\
829 .driver = "n270" "-" TYPE_X86_CPU,\
830 .property = "movbe",\
834 .driver = "Westmere" "-" TYPE_X86_CPU,\
835 .property = "pclmulqdq",\
839 #define DEFINE_PC_MACHINE(suffix, namestr, initfn, optsfn) \
840 static void pc_machine_##suffix##_class_init(ObjectClass *oc, void *data) \
842 MachineClass *mc = MACHINE_CLASS(oc); \
844 mc->name = namestr; \
847 static const TypeInfo pc_machine_type_##suffix = { \
848 .name = namestr TYPE_MACHINE_SUFFIX, \
849 .parent = TYPE_PC_MACHINE, \
850 .class_init = pc_machine_##suffix##_class_init, \
852 static void pc_machine_init_##suffix(void) \
854 type_register(&pc_machine_type_##suffix); \
856 machine_init(pc_machine_init_##suffix)
858 extern void igd_passthrough_isa_bridge_create(PCIBus
*bus
, uint16_t gpu_dev_id
);