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
;
49 /* Pointers to devices and objects: */
50 HotplugHandler
*acpi_dev
;
54 /* Configuration options: */
55 uint64_t max_ram_below_4g
;
60 /* RAM information (sizes, addresses, configuration): */
61 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
64 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
65 #define PC_MACHINE_MEMHP_REGION_SIZE "hotplug-memory-region-size"
66 #define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g"
67 #define PC_MACHINE_VMPORT "vmport"
68 #define PC_MACHINE_SMM "smm"
69 #define PC_MACHINE_NVDIMM "nvdimm"
76 * @get_hotplug_handler: pointer to parent class callback @get_hotplug_handler
80 * @enforce_aligned_dimm: check that DIMM's address/size is aligned by
81 * backend's alignment value if provided
82 * @acpi_data_size: Size of the chunk of memory at the top of RAM
83 * for the BIOS ACPI tables and other BIOS
85 * @gigabyte_align: Make sure that guest addresses aligned at
86 * 1Gbyte boundaries get mapped to host
87 * addresses aligned at 1Gbyte boundaries. This
88 * way we can use 1GByte pages in the host.
91 struct PCMachineClass
{
93 MachineClass parent_class
;
98 HotplugHandler
*(*get_hotplug_handler
)(MachineState
*machine
,
101 /* Device configuration: */
103 bool kvmclock_enabled
;
105 /* Compat options: */
110 int legacy_acpi_table_size
;
111 unsigned acpi_data_size
;
114 bool smbios_defaults
;
115 bool smbios_legacy_mode
;
116 bool smbios_uuid_encoded
;
118 /* RAM / address space compat: */
120 bool has_reserved_memory
;
121 bool enforce_aligned_dimm
;
122 bool broken_reserved_end
;
124 /* TSC rate migration: */
128 #define TYPE_PC_MACHINE "generic-pc-machine"
129 #define PC_MACHINE(obj) \
130 OBJECT_CHECK(PCMachineState, (obj), TYPE_PC_MACHINE)
131 #define PC_MACHINE_GET_CLASS(obj) \
132 OBJECT_GET_CLASS(PCMachineClass, (obj), TYPE_PC_MACHINE)
133 #define PC_MACHINE_CLASS(klass) \
134 OBJECT_CLASS_CHECK(PCMachineClass, (klass), TYPE_PC_MACHINE)
136 /* PC-style peripherals (also used by other machines). */
138 typedef struct PcPciInfo
{
143 #define ACPI_PM_PROP_S3_DISABLED "disable_s3"
144 #define ACPI_PM_PROP_S4_DISABLED "disable_s4"
145 #define ACPI_PM_PROP_S4_VAL "s4_val"
146 #define ACPI_PM_PROP_SCI_INT "sci_int"
147 #define ACPI_PM_PROP_ACPI_ENABLE_CMD "acpi_enable_cmd"
148 #define ACPI_PM_PROP_ACPI_DISABLE_CMD "acpi_disable_cmd"
149 #define ACPI_PM_PROP_PM_IO_BASE "pm_io_base"
150 #define ACPI_PM_PROP_GPE0_BLK "gpe0_blk"
151 #define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len"
152 #define ACPI_PM_PROP_TCO_ENABLED "enable_tco"
156 hwaddr ram_size
, ram_size_below_4g
;
157 unsigned apic_id_limit
;
158 bool apic_xrupt_override
;
163 int legacy_acpi_table_size
;
165 bool has_reserved_memory
;
171 void parallel_hds_isa_init(ISABus
*bus
, int n
);
173 bool parallel_mm_init(MemoryRegion
*address_space
,
174 hwaddr base
, int it_shift
, qemu_irq irq
,
175 CharDriverState
*chr
);
179 extern DeviceState
*isa_pic
;
180 qemu_irq
*i8259_init(ISABus
*bus
, qemu_irq parent_irq
);
181 qemu_irq
*kvm_i8259_init(ISABus
*bus
);
182 int pic_read_irq(DeviceState
*d
);
183 int pic_get_output(DeviceState
*d
);
184 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
);
185 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
);
189 void kvm_ioapic_dump_state(Monitor
*mon
, const QDict
*qdict
);
190 void ioapic_dump_state(Monitor
*mon
, const QDict
*qdict
);
192 /* Global System Interrupts */
194 #define GSI_NUM_PINS IOAPIC_NUM_PINS
196 typedef struct GSIState
{
197 qemu_irq i8259_irq
[ISA_NUM_IRQS
];
198 qemu_irq ioapic_irq
[IOAPIC_NUM_PINS
];
201 void gsi_handler(void *opaque
, int n
, int level
);
204 typedef uint32_t (VMPortReadFunc
)(void *opaque
, uint32_t address
);
206 static inline void vmport_init(ISABus
*bus
)
208 isa_create_simple(bus
, "vmport");
211 void vmport_register(unsigned char command
, VMPortReadFunc
*func
, void *opaque
);
212 void vmmouse_get_data(uint32_t *data
);
213 void vmmouse_set_data(const uint32_t *data
);
217 void i8042_init(qemu_irq kbd_irq
, qemu_irq mouse_irq
, uint32_t io_base
);
218 void i8042_mm_init(qemu_irq kbd_irq
, qemu_irq mouse_irq
,
219 MemoryRegion
*region
, ram_addr_t size
,
221 void i8042_isa_mouse_fake_event(void *opaque
);
222 void i8042_setup_a20_line(ISADevice
*dev
, qemu_irq
*a20_out
);
225 extern int fd_bootchk
;
227 bool pc_machine_is_smm_enabled(PCMachineState
*pcms
);
228 void pc_register_ferr_irq(qemu_irq irq
);
229 void pc_acpi_smi_interrupt(void *opaque
, int irq
, int level
);
231 void pc_cpus_init(PCMachineState
*pcms
);
232 void pc_hot_add_cpu(const int64_t id
, Error
**errp
);
233 void pc_acpi_init(const char *default_dsdt
);
235 PcGuestInfo
*pc_guest_info_init(PCMachineState
*pcms
);
237 #define PCI_HOST_PROP_PCI_HOLE_START "pci-hole-start"
238 #define PCI_HOST_PROP_PCI_HOLE_END "pci-hole-end"
239 #define PCI_HOST_PROP_PCI_HOLE64_START "pci-hole64-start"
240 #define PCI_HOST_PROP_PCI_HOLE64_END "pci-hole64-end"
241 #define PCI_HOST_PROP_PCI_HOLE64_SIZE "pci-hole64-size"
242 #define DEFAULT_PCI_HOLE64_SIZE (~0x0ULL)
245 void pc_pci_as_mapping_init(Object
*owner
, MemoryRegion
*system_memory
,
246 MemoryRegion
*pci_address_space
);
248 FWCfgState
*xen_load_linux(PCMachineState
*pcms
,
249 PcGuestInfo
*guest_info
);
250 FWCfgState
*pc_memory_init(PCMachineState
*pcms
,
251 MemoryRegion
*system_memory
,
252 MemoryRegion
*rom_memory
,
253 MemoryRegion
**ram_memory
,
254 PcGuestInfo
*guest_info
);
255 qemu_irq
pc_allocate_cpu_irq(void);
256 DeviceState
*pc_vga_init(ISABus
*isa_bus
, PCIBus
*pci_bus
);
257 void pc_basic_device_init(ISABus
*isa_bus
, qemu_irq
*gsi
,
258 ISADevice
**rtc_state
,
262 void pc_init_ne2k_isa(ISABus
*bus
, NICInfo
*nd
);
263 void pc_cmos_init(PCMachineState
*pcms
,
264 BusState
*ide0
, BusState
*ide1
,
266 void pc_nic_init(ISABus
*isa_bus
, PCIBus
*pci_bus
);
267 void pc_pci_device_init(PCIBus
*pci_bus
);
269 typedef void (*cpu_set_smm_t
)(int smm
, void *arg
);
271 void ioapic_init_gsi(GSIState
*gsi_state
, const char *parent_name
);
273 ISADevice
*pc_find_fdc0(void);
277 I2CBus
*piix4_pm_init(PCIBus
*bus
, int devfn
, uint32_t smb_io_base
,
278 qemu_irq sci_irq
, qemu_irq smi_irq
,
279 int smm_enabled
, DeviceState
**piix4_pm
);
280 void piix4_smbus_register_device(SMBusDevice
*dev
, uint8_t addr
);
286 struct PCII440FXState
;
287 typedef struct PCII440FXState PCII440FXState
;
289 #define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost"
290 #define TYPE_I440FX_PCI_DEVICE "i440FX"
292 #define TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "igd-passthrough-i440FX"
294 PCIBus
*i440fx_init(const char *host_type
, const char *pci_type
,
295 PCII440FXState
**pi440fx_state
, int *piix_devfn
,
296 ISABus
**isa_bus
, qemu_irq
*pic
,
297 MemoryRegion
*address_space_mem
,
298 MemoryRegion
*address_space_io
,
300 ram_addr_t below_4g_mem_size
,
301 ram_addr_t above_4g_mem_size
,
302 MemoryRegion
*pci_memory
,
303 MemoryRegion
*ram_memory
);
305 PCIBus
*find_i440fx(void);
307 extern PCIDevice
*piix4_dev
;
308 int piix4_init(PCIBus
*bus
, ISABus
**isa_bus
, int devfn
);
311 enum vga_retrace_method
{
316 extern enum vga_retrace_method vga_retrace_method
;
318 int isa_vga_mm_init(hwaddr vram_base
,
319 hwaddr ctrl_base
, int it_shift
,
320 MemoryRegion
*address_space
);
323 static inline bool isa_ne2000_init(ISABus
*bus
, int base
, int irq
, NICInfo
*nd
)
328 qemu_check_nic_model(nd
, "ne2k_isa");
330 isadev
= isa_try_create(bus
, "ne2k_isa");
334 dev
= DEVICE(isadev
);
335 qdev_prop_set_uint32(dev
, "iobase", base
);
336 qdev_prop_set_uint32(dev
, "irq", irq
);
337 qdev_set_nic_properties(dev
, nd
);
338 qdev_init_nofail(dev
);
343 void pc_system_firmware_init(MemoryRegion
*rom_memory
,
347 uint16_t pvpanic_port(void);
351 #define E820_RESERVED 2
354 #define E820_UNUSABLE 5
356 int e820_add_entry(uint64_t, uint64_t, uint32_t);
357 int e820_get_num_entries(void);
358 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
360 #define PC_COMPAT_2_5 \
363 #define PC_COMPAT_2_4 \
367 .driver = "Haswell-" TYPE_X86_CPU,\
372 .driver = "Haswell-noTSX-" TYPE_X86_CPU,\
377 .driver = "Broadwell-" TYPE_X86_CPU,\
382 .driver = "Broadwell-noTSX-" TYPE_X86_CPU,\
387 .driver = "host" "-" TYPE_X86_CPU,\
388 .property = "host-cache-info",\
392 .driver = TYPE_X86_CPU,\
393 .property = "check",\
397 .driver = "qemu64" "-" TYPE_X86_CPU,\
398 .property = "sse4a",\
402 .driver = "qemu64" "-" TYPE_X86_CPU,\
407 .driver = "qemu64" "-" TYPE_X86_CPU,\
408 .property = "popcnt",\
412 .driver = "qemu32" "-" TYPE_X86_CPU,\
413 .property = "popcnt",\
416 .driver = "Opteron_G2" "-" TYPE_X86_CPU,\
417 .property = "rdtscp",\
420 .driver = "Opteron_G3" "-" TYPE_X86_CPU,\
421 .property = "rdtscp",\
424 .driver = "Opteron_G4" "-" TYPE_X86_CPU,\
425 .property = "rdtscp",\
428 .driver = "Opteron_G5" "-" TYPE_X86_CPU,\
429 .property = "rdtscp",\
434 #define PC_COMPAT_2_3 \
438 .driver = TYPE_X86_CPU,\
442 .driver = "qemu64" "-" TYPE_X86_CPU,\
443 .property = "level",\
444 .value = stringify(4),\
446 .driver = "kvm64" "-" TYPE_X86_CPU,\
447 .property = "level",\
448 .value = stringify(5),\
450 .driver = "pentium3" "-" TYPE_X86_CPU,\
451 .property = "level",\
452 .value = stringify(2),\
454 .driver = "n270" "-" TYPE_X86_CPU,\
455 .property = "level",\
456 .value = stringify(5),\
458 .driver = "Conroe" "-" TYPE_X86_CPU,\
459 .property = "level",\
460 .value = stringify(4),\
462 .driver = "Penryn" "-" TYPE_X86_CPU,\
463 .property = "level",\
464 .value = stringify(4),\
466 .driver = "Nehalem" "-" TYPE_X86_CPU,\
467 .property = "level",\
468 .value = stringify(4),\
470 .driver = "n270" "-" TYPE_X86_CPU,\
471 .property = "xlevel",\
472 .value = stringify(0x8000000a),\
474 .driver = "Penryn" "-" TYPE_X86_CPU,\
475 .property = "xlevel",\
476 .value = stringify(0x8000000a),\
478 .driver = "Conroe" "-" TYPE_X86_CPU,\
479 .property = "xlevel",\
480 .value = stringify(0x8000000a),\
482 .driver = "Nehalem" "-" TYPE_X86_CPU,\
483 .property = "xlevel",\
484 .value = stringify(0x8000000a),\
486 .driver = "Westmere" "-" TYPE_X86_CPU,\
487 .property = "xlevel",\
488 .value = stringify(0x8000000a),\
490 .driver = "SandyBridge" "-" TYPE_X86_CPU,\
491 .property = "xlevel",\
492 .value = stringify(0x8000000a),\
494 .driver = "IvyBridge" "-" TYPE_X86_CPU,\
495 .property = "xlevel",\
496 .value = stringify(0x8000000a),\
498 .driver = "Haswell" "-" TYPE_X86_CPU,\
499 .property = "xlevel",\
500 .value = stringify(0x8000000a),\
502 .driver = "Haswell-noTSX" "-" TYPE_X86_CPU,\
503 .property = "xlevel",\
504 .value = stringify(0x8000000a),\
506 .driver = "Broadwell" "-" TYPE_X86_CPU,\
507 .property = "xlevel",\
508 .value = stringify(0x8000000a),\
510 .driver = "Broadwell-noTSX" "-" TYPE_X86_CPU,\
511 .property = "xlevel",\
512 .value = stringify(0x8000000a),\
515 #define PC_COMPAT_2_2 \
519 .driver = "kvm64" "-" TYPE_X86_CPU,\
524 .driver = "kvm32" "-" TYPE_X86_CPU,\
529 .driver = "Conroe" "-" TYPE_X86_CPU,\
534 .driver = "Penryn" "-" TYPE_X86_CPU,\
539 .driver = "Nehalem" "-" TYPE_X86_CPU,\
544 .driver = "Westmere" "-" TYPE_X86_CPU,\
549 .driver = "SandyBridge" "-" TYPE_X86_CPU,\
554 .driver = "Haswell" "-" TYPE_X86_CPU,\
559 .driver = "Broadwell" "-" TYPE_X86_CPU,\
564 .driver = "Opteron_G1" "-" TYPE_X86_CPU,\
569 .driver = "Opteron_G2" "-" TYPE_X86_CPU,\
574 .driver = "Opteron_G3" "-" TYPE_X86_CPU,\
579 .driver = "Opteron_G4" "-" TYPE_X86_CPU,\
584 .driver = "Opteron_G5" "-" TYPE_X86_CPU,\
589 .driver = "Haswell" "-" TYPE_X86_CPU,\
594 .driver = "Haswell" "-" TYPE_X86_CPU,\
595 .property = "rdrand",\
599 .driver = "Broadwell" "-" TYPE_X86_CPU,\
604 .driver = "Broadwell" "-" TYPE_X86_CPU,\
605 .property = "rdrand",\
609 #define PC_COMPAT_2_1 \
613 .driver = "coreduo" "-" TYPE_X86_CPU,\
618 .driver = "core2duo" "-" TYPE_X86_CPU,\
623 #define PC_COMPAT_2_0 \
626 .driver = "virtio-scsi-pci",\
627 .property = "any_layout",\
630 .driver = "PIIX4_PM",\
631 .property = "memory-hotplug-support",\
636 .property = "version",\
637 .value = stringify(0x11),\
640 .driver = "nec-usb-xhci",\
641 .property = "superspeed-ports-first",\
645 .driver = "nec-usb-xhci",\
646 .property = "force-pcie-endcap",\
650 .driver = "pci-serial",\
651 .property = "prog_if",\
652 .value = stringify(0),\
655 .driver = "pci-serial-2x",\
656 .property = "prog_if",\
657 .value = stringify(0),\
660 .driver = "pci-serial-4x",\
661 .property = "prog_if",\
662 .value = stringify(0),\
665 .driver = "virtio-net-pci",\
666 .property = "guest_announce",\
670 .driver = "ICH9-LPC",\
671 .property = "memory-hotplug-support",\
674 .driver = "xio3130-downstream",\
675 .property = COMPAT_PROP_PCP,\
678 .driver = "ioh3420",\
679 .property = COMPAT_PROP_PCP,\
683 #define PC_COMPAT_1_7 \
686 .driver = TYPE_USB_DEVICE,\
687 .property = "msos-desc",\
691 .driver = "PIIX4_PM",\
692 .property = "acpi-pci-hotplug-with-bridge-support",\
697 .property = HPET_INTCAP,\
698 .value = stringify(4),\
701 #define PC_COMPAT_1_6 \
705 .property = "mitigation",\
708 .driver = "qemu64-" TYPE_X86_CPU,\
709 .property = "model",\
710 .value = stringify(2),\
712 .driver = "qemu32-" TYPE_X86_CPU,\
713 .property = "model",\
714 .value = stringify(3),\
716 .driver = "i440FX-pcihost",\
717 .property = "short_root_bus",\
718 .value = stringify(1),\
720 .driver = "q35-pcihost",\
721 .property = "short_root_bus",\
722 .value = stringify(1),\
725 #define PC_COMPAT_1_5 \
728 .driver = "Conroe-" TYPE_X86_CPU,\
729 .property = "model",\
730 .value = stringify(2),\
732 .driver = "Conroe-" TYPE_X86_CPU,\
733 .property = "level",\
734 .value = stringify(2),\
736 .driver = "Penryn-" TYPE_X86_CPU,\
737 .property = "model",\
738 .value = stringify(2),\
740 .driver = "Penryn-" TYPE_X86_CPU,\
741 .property = "level",\
742 .value = stringify(2),\
744 .driver = "Nehalem-" TYPE_X86_CPU,\
745 .property = "model",\
746 .value = stringify(2),\
748 .driver = "Nehalem-" TYPE_X86_CPU,\
749 .property = "level",\
750 .value = stringify(2),\
752 .driver = "virtio-net-pci",\
753 .property = "any_layout",\
756 .driver = TYPE_X86_CPU,\
760 .driver = "i440FX-pcihost",\
761 .property = "short_root_bus",\
762 .value = stringify(0),\
764 .driver = "q35-pcihost",\
765 .property = "short_root_bus",\
766 .value = stringify(0),\
769 #define PC_COMPAT_1_4 \
772 .driver = "scsi-hd",\
773 .property = "discard_granularity",\
774 .value = stringify(0),\
776 .driver = "scsi-cd",\
777 .property = "discard_granularity",\
778 .value = stringify(0),\
780 .driver = "scsi-disk",\
781 .property = "discard_granularity",\
782 .value = stringify(0),\
785 .property = "discard_granularity",\
786 .value = stringify(0),\
789 .property = "discard_granularity",\
790 .value = stringify(0),\
792 .driver = "ide-drive",\
793 .property = "discard_granularity",\
794 .value = stringify(0),\
796 .driver = "virtio-blk-pci",\
797 .property = "discard_granularity",\
798 .value = stringify(0),\
800 .driver = "virtio-serial-pci",\
801 .property = "vectors",\
802 /* DEV_NVECTORS_UNSPECIFIED as a uint32_t string */\
803 .value = stringify(0xFFFFFFFF),\
805 .driver = "virtio-net-pci", \
806 .property = "ctrl_guest_offloads", \
810 .property = "romfile",\
811 .value = "pxe-e1000.rom",\
813 .driver = "ne2k_pci",\
814 .property = "romfile",\
815 .value = "pxe-ne2k_pci.rom",\
818 .property = "romfile",\
819 .value = "pxe-pcnet.rom",\
821 .driver = "rtl8139",\
822 .property = "romfile",\
823 .value = "pxe-rtl8139.rom",\
825 .driver = "virtio-net-pci",\
826 .property = "romfile",\
827 .value = "pxe-virtio.rom",\
829 .driver = "486-" TYPE_X86_CPU,\
830 .property = "model",\
831 .value = stringify(0),\
834 .driver = "n270" "-" TYPE_X86_CPU,\
835 .property = "movbe",\
839 .driver = "Westmere" "-" TYPE_X86_CPU,\
840 .property = "pclmulqdq",\
844 #define DEFINE_PC_MACHINE(suffix, namestr, initfn, optsfn) \
845 static void pc_machine_##suffix##_class_init(ObjectClass *oc, void *data) \
847 MachineClass *mc = MACHINE_CLASS(oc); \
849 mc->name = namestr; \
852 static const TypeInfo pc_machine_type_##suffix = { \
853 .name = namestr TYPE_MACHINE_SUFFIX, \
854 .parent = TYPE_PC_MACHINE, \
855 .class_init = pc_machine_##suffix##_class_init, \
857 static void pc_machine_init_##suffix(void) \
859 type_register(&pc_machine_type_##suffix); \
861 machine_init(pc_machine_init_##suffix)
863 extern void igd_passthrough_isa_bridge_create(PCIBus
*bus
, uint16_t gpu_dev_id
);