2 * QEMU PC System Emulator
4 * Copyright (c) 2003-2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
28 #include "hw/loader.h"
29 #include "hw/i386/pc.h"
30 #include "hw/i386/apic.h"
31 #include "hw/smbios/smbios.h"
32 #include "hw/pci/pci.h"
33 #include "hw/pci/pci_ids.h"
36 #include "hw/boards.h"
38 #include "sysemu/kvm.h"
39 #include "hw/kvm/clock.h"
40 #include "sysemu/sysemu.h"
41 #include "hw/sysbus.h"
42 #include "sysemu/arch_init.h"
43 #include "sysemu/block-backend.h"
44 #include "hw/i2c/smbus.h"
45 #include "hw/xen/xen.h"
46 #include "exec/memory.h"
47 #include "exec/address-spaces.h"
48 #include "hw/acpi/acpi.h"
50 #include "qapi/error.h"
51 #include "qemu/error-report.h"
53 #include <xen/hvm/hvm_info_table.h>
54 #include "hw/xen/xen_pt.h"
56 #include "migration/global_state.h"
57 #include "migration/misc.h"
59 #include "sysemu/numa.h"
63 static const int ide_iobase
[MAX_IDE_BUS
] = { 0x1f0, 0x170 };
64 static const int ide_iobase2
[MAX_IDE_BUS
] = { 0x3f6, 0x376 };
65 static const int ide_irq
[MAX_IDE_BUS
] = { 14, 15 };
67 /* PC hardware initialisation */
68 static void pc_init1(MachineState
*machine
,
69 const char *host_type
, const char *pci_type
)
71 PCMachineState
*pcms
= PC_MACHINE(machine
);
72 PCMachineClass
*pcmc
= PC_MACHINE_GET_CLASS(pcms
);
73 MemoryRegion
*system_memory
= get_system_memory();
74 MemoryRegion
*system_io
= get_system_io();
78 PCII440FXState
*i440fx_state
;
83 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
84 BusState
*idebus
[MAX_IDE_BUS
];
86 MemoryRegion
*ram_memory
;
87 MemoryRegion
*pci_memory
;
88 MemoryRegion
*rom_memory
;
92 * Calculate ram split, for memory below and above 4G. It's a bit
93 * complicated for backward compatibility reasons ...
95 * - Traditional split is 3.5G (lowmem = 0xe0000000). This is the
96 * default value for max_ram_below_4g now.
98 * - Then, to gigabyte align the memory, we move the split to 3G
99 * (lowmem = 0xc0000000). But only in case we have to split in
100 * the first place, i.e. ram_size is larger than (traditional)
101 * lowmem. And for new machine types (gigabyte_align = true)
102 * only, for live migration compatibility reasons.
104 * - Next the max-ram-below-4g option was added, which allowed to
105 * reduce lowmem to a smaller value, to allow a larger PCI I/O
106 * window below 4G. qemu doesn't enforce gigabyte alignment here,
107 * but prints a warning.
109 * - Finally max-ram-below-4g got updated to also allow raising lowmem,
110 * so legacy non-PAE guests can get as much memory as possible in
111 * the 32bit address space below 4G.
113 * - Note that Xen has its own ram setp code in xen_ram_init(),
114 * called via xen_hvm_init().
117 * qemu -M pc-1.7 -m 4G (old default) -> 3584M low, 512M high
118 * qemu -M pc -m 4G (new default) -> 3072M low, 1024M high
119 * qemu -M pc,max-ram-below-4g=2G -m 4G -> 2048M low, 2048M high
120 * qemu -M pc,max-ram-below-4g=4G -m 3968M -> 3968M low (=4G-128M)
123 xen_hvm_init(pcms
, &ram_memory
);
125 if (!pcms
->max_ram_below_4g
) {
126 pcms
->max_ram_below_4g
= 0xe0000000; /* default: 3.5G */
128 lowmem
= pcms
->max_ram_below_4g
;
129 if (machine
->ram_size
>= pcms
->max_ram_below_4g
) {
130 if (pcmc
->gigabyte_align
) {
131 if (lowmem
> 0xc0000000) {
134 if (lowmem
& ((1ULL << 30) - 1)) {
135 warn_report("Large machine and max_ram_below_4g "
136 "(%" PRIu64
") not a multiple of 1G; "
137 "possible bad performance.",
138 pcms
->max_ram_below_4g
);
143 if (machine
->ram_size
>= lowmem
) {
144 pcms
->above_4g_mem_size
= machine
->ram_size
- lowmem
;
145 pcms
->below_4g_mem_size
= lowmem
;
147 pcms
->above_4g_mem_size
= 0;
148 pcms
->below_4g_mem_size
= machine
->ram_size
;
154 if (kvm_enabled() && pcmc
->kvmclock_enabled
) {
158 if (pcmc
->pci_enabled
) {
159 pci_memory
= g_new(MemoryRegion
, 1);
160 memory_region_init(pci_memory
, NULL
, "pci", UINT64_MAX
);
161 rom_memory
= pci_memory
;
164 rom_memory
= system_memory
;
167 pc_guest_info_init(pcms
);
169 if (pcmc
->smbios_defaults
) {
170 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
171 /* These values are guest ABI, do not change */
172 smbios_set_defaults("QEMU", "Standard PC (i440FX + PIIX, 1996)",
173 mc
->name
, pcmc
->smbios_legacy_mode
,
174 pcmc
->smbios_uuid_encoded
,
175 SMBIOS_ENTRY_POINT_21
);
178 /* allocate ram and load rom/bios */
179 if (!xen_enabled()) {
180 pc_memory_init(pcms
, system_memory
,
181 rom_memory
, &ram_memory
);
182 } else if (machine
->kernel_filename
!= NULL
) {
183 /* For xen HVM direct kernel boot, load linux here */
184 xen_load_linux(pcms
);
187 gsi_state
= g_malloc0(sizeof(*gsi_state
));
188 if (kvm_ioapic_in_kernel()) {
189 kvm_pc_setup_irq_routing(pcmc
->pci_enabled
);
190 pcms
->gsi
= qemu_allocate_irqs(kvm_pc_gsi_handler
, gsi_state
,
193 pcms
->gsi
= qemu_allocate_irqs(gsi_handler
, gsi_state
, GSI_NUM_PINS
);
196 if (pcmc
->pci_enabled
) {
197 pci_bus
= i440fx_init(host_type
,
199 &i440fx_state
, &piix3_devfn
, &isa_bus
, pcms
->gsi
,
200 system_memory
, system_io
, machine
->ram_size
,
201 pcms
->below_4g_mem_size
,
202 pcms
->above_4g_mem_size
,
203 pci_memory
, ram_memory
);
208 isa_bus
= isa_bus_new(NULL
, get_system_memory(), system_io
,
212 isa_bus_irqs(isa_bus
, pcms
->gsi
);
214 if (kvm_pic_in_kernel()) {
215 i8259
= kvm_i8259_init(isa_bus
);
216 } else if (xen_enabled()) {
217 i8259
= xen_interrupt_controller_init();
219 i8259
= i8259_init(isa_bus
, pc_allocate_cpu_irq());
222 for (i
= 0; i
< ISA_NUM_IRQS
; i
++) {
223 gsi_state
->i8259_irq
[i
] = i8259
[i
];
226 if (pcmc
->pci_enabled
) {
227 ioapic_init_gsi(gsi_state
, "i440fx");
230 pc_register_ferr_irq(pcms
->gsi
[13]);
232 pc_vga_init(isa_bus
, pcmc
->pci_enabled
? pci_bus
: NULL
);
234 assert(pcms
->vmport
!= ON_OFF_AUTO__MAX
);
235 if (pcms
->vmport
== ON_OFF_AUTO_AUTO
) {
236 pcms
->vmport
= xen_enabled() ? ON_OFF_AUTO_OFF
: ON_OFF_AUTO_ON
;
239 /* init basic PC hardware */
240 pc_basic_device_init(isa_bus
, pcms
->gsi
, &rtc_state
, true,
241 (pcms
->vmport
!= ON_OFF_AUTO_ON
), pcms
->pit
, 0x4);
243 pc_nic_init(isa_bus
, pci_bus
);
245 ide_drive_get(hd
, ARRAY_SIZE(hd
));
246 if (pcmc
->pci_enabled
) {
249 dev
= pci_piix3_xen_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
251 dev
= pci_piix3_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
253 idebus
[0] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
254 idebus
[1] = qdev_get_child_bus(&dev
->qdev
, "ide.1");
256 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
258 char busname
[] = "ide.0";
259 dev
= isa_ide_init(isa_bus
, ide_iobase
[i
], ide_iobase2
[i
],
261 hd
[MAX_IDE_DEVS
* i
], hd
[MAX_IDE_DEVS
* i
+ 1]);
263 * The ide bus name is ide.0 for the first bus and ide.1 for the
266 busname
[4] = '0' + i
;
267 idebus
[i
] = qdev_get_child_bus(DEVICE(dev
), busname
);
271 pc_cmos_init(pcms
, idebus
[0], idebus
[1], rtc_state
);
273 if (pcmc
->pci_enabled
&& machine_usb(machine
)) {
274 pci_create_simple(pci_bus
, piix3_devfn
+ 2, "piix3-usb-uhci");
277 if (pcmc
->pci_enabled
&& acpi_enabled
) {
278 DeviceState
*piix4_pm
;
281 smi_irq
= qemu_allocate_irq(pc_acpi_smi_interrupt
, first_cpu
, 0);
282 /* TODO: Populate SPD eeprom data. */
283 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
284 pcms
->gsi
[9], smi_irq
,
285 pc_machine_is_smm_enabled(pcms
),
287 smbus_eeprom_init(smbus
, 8, NULL
, 0);
289 object_property_add_link(OBJECT(machine
), PC_MACHINE_ACPI_DEVICE_PROP
,
290 TYPE_HOTPLUG_HANDLER
,
291 (Object
**)&pcms
->acpi_dev
,
292 object_property_allow_set_link
,
293 OBJ_PROP_LINK_UNREF_ON_RELEASE
, &error_abort
);
294 object_property_set_link(OBJECT(machine
), OBJECT(piix4_pm
),
295 PC_MACHINE_ACPI_DEVICE_PROP
, &error_abort
);
298 if (pcmc
->pci_enabled
) {
299 pc_pci_device_init(pci_bus
);
302 if (pcms
->acpi_nvdimm_state
.is_enabled
) {
303 nvdimm_init_acpi_state(&pcms
->acpi_nvdimm_state
, system_io
,
304 pcms
->fw_cfg
, OBJECT(pcms
));
308 /* Looking for a pc_compat_2_4() function? It doesn't exist.
309 * pc_compat_*() functions that run on machine-init time and
310 * change global QEMU state are deprecated. Please don't create
311 * one, and implement any pc-*-2.4 (and newer) compat code in
312 * HW_COMPAT_*, PC_COMPAT_*, or * pc_*_machine_options().
315 static void pc_compat_2_3(MachineState
*machine
)
317 PCMachineState
*pcms
= PC_MACHINE(machine
);
319 pcms
->smm
= ON_OFF_AUTO_OFF
;
323 static void pc_compat_2_2(MachineState
*machine
)
325 pc_compat_2_3(machine
);
326 machine
->suppress_vmdesc
= true;
329 static void pc_compat_2_1(MachineState
*machine
)
331 pc_compat_2_2(machine
);
332 x86_cpu_change_kvm_default("svm", NULL
);
335 static void pc_compat_2_0(MachineState
*machine
)
337 pc_compat_2_1(machine
);
340 static void pc_compat_1_7(MachineState
*machine
)
342 pc_compat_2_0(machine
);
343 x86_cpu_change_kvm_default("x2apic", NULL
);
346 static void pc_compat_1_6(MachineState
*machine
)
348 pc_compat_1_7(machine
);
351 static void pc_compat_1_5(MachineState
*machine
)
353 pc_compat_1_6(machine
);
356 static void pc_compat_1_4(MachineState
*machine
)
358 pc_compat_1_5(machine
);
361 static void pc_compat_1_3(MachineState
*machine
)
363 pc_compat_1_4(machine
);
364 enable_compat_apic_id_mode();
367 /* PC compat function for pc-0.14 to pc-1.2 */
368 static void pc_compat_1_2(MachineState
*machine
)
370 pc_compat_1_3(machine
);
371 x86_cpu_change_kvm_default("kvm-pv-eoi", NULL
);
374 /* PC compat function for pc-0.10 to pc-0.13 */
375 static void pc_compat_0_13(MachineState
*machine
)
377 pc_compat_1_2(machine
);
380 static void pc_init_isa(MachineState
*machine
)
382 pc_init1(machine
, TYPE_I440FX_PCI_HOST_BRIDGE
, TYPE_I440FX_PCI_DEVICE
);
386 static void pc_xen_hvm_init_pci(MachineState
*machine
)
388 const char *pci_type
= has_igd_gfx_passthru
?
389 TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE
: TYPE_I440FX_PCI_DEVICE
;
392 TYPE_I440FX_PCI_HOST_BRIDGE
,
396 static void pc_xen_hvm_init(MachineState
*machine
)
398 PCMachineState
*pcms
= PC_MACHINE(machine
);
400 if (!xen_enabled()) {
401 error_report("xenfv machine requires the xen accelerator");
405 pc_xen_hvm_init_pci(machine
);
406 pci_create_simple(pcms
->bus
, -1, "xen-platform");
410 #define DEFINE_I440FX_MACHINE(suffix, name, compatfn, optionfn) \
411 static void pc_init_##suffix(MachineState *machine) \
413 void (*compat)(MachineState *m) = (compatfn); \
417 pc_init1(machine, TYPE_I440FX_PCI_HOST_BRIDGE, \
418 TYPE_I440FX_PCI_DEVICE); \
420 DEFINE_PC_MACHINE(suffix, name, pc_init_##suffix, optionfn)
422 static void pc_i440fx_machine_options(MachineClass
*m
)
424 m
->family
= "pc_piix";
425 m
->desc
= "Standard PC (i440FX + PIIX, 1996)";
426 m
->default_machine_opts
= "firmware=bios-256k.bin";
427 m
->default_display
= "std";
430 static void pc_i440fx_2_12_machine_options(MachineClass
*m
)
432 pc_i440fx_machine_options(m
);
437 DEFINE_I440FX_MACHINE(v2_12
, "pc-i440fx-2.12", NULL
,
438 pc_i440fx_2_12_machine_options
);
440 static void pc_i440fx_2_11_machine_options(MachineClass
*m
)
442 pc_i440fx_2_12_machine_options(m
);
445 SET_MACHINE_COMPAT(m
, PC_COMPAT_2_11
);
448 DEFINE_I440FX_MACHINE(v2_11
, "pc-i440fx-2.11", NULL
,
449 pc_i440fx_2_11_machine_options
);
451 static void pc_i440fx_2_10_machine_options(MachineClass
*m
)
453 pc_i440fx_2_11_machine_options(m
);
454 SET_MACHINE_COMPAT(m
, PC_COMPAT_2_10
);
455 m
->auto_enable_numa_with_memhp
= false;
458 DEFINE_I440FX_MACHINE(v2_10
, "pc-i440fx-2.10", NULL
,
459 pc_i440fx_2_10_machine_options
);
461 static void pc_i440fx_2_9_machine_options(MachineClass
*m
)
463 pc_i440fx_2_10_machine_options(m
);
464 SET_MACHINE_COMPAT(m
, PC_COMPAT_2_9
);
465 m
->numa_auto_assign_ram
= numa_legacy_auto_assign_ram
;
468 DEFINE_I440FX_MACHINE(v2_9
, "pc-i440fx-2.9", NULL
,
469 pc_i440fx_2_9_machine_options
);
471 static void pc_i440fx_2_8_machine_options(MachineClass
*m
)
473 pc_i440fx_2_9_machine_options(m
);
474 SET_MACHINE_COMPAT(m
, PC_COMPAT_2_8
);
477 DEFINE_I440FX_MACHINE(v2_8
, "pc-i440fx-2.8", NULL
,
478 pc_i440fx_2_8_machine_options
);
481 static void pc_i440fx_2_7_machine_options(MachineClass
*m
)
483 pc_i440fx_2_8_machine_options(m
);
484 SET_MACHINE_COMPAT(m
, PC_COMPAT_2_7
);
487 DEFINE_I440FX_MACHINE(v2_7
, "pc-i440fx-2.7", NULL
,
488 pc_i440fx_2_7_machine_options
);
491 static void pc_i440fx_2_6_machine_options(MachineClass
*m
)
493 PCMachineClass
*pcmc
= PC_MACHINE_CLASS(m
);
494 pc_i440fx_2_7_machine_options(m
);
495 pcmc
->legacy_cpu_hotplug
= true;
496 pcmc
->linuxboot_dma_enabled
= false;
497 SET_MACHINE_COMPAT(m
, PC_COMPAT_2_6
);
500 DEFINE_I440FX_MACHINE(v2_6
, "pc-i440fx-2.6", NULL
,
501 pc_i440fx_2_6_machine_options
);
504 static void pc_i440fx_2_5_machine_options(MachineClass
*m
)
506 PCMachineClass
*pcmc
= PC_MACHINE_CLASS(m
);
507 pc_i440fx_2_6_machine_options(m
);
508 pcmc
->save_tsc_khz
= false;
509 m
->legacy_fw_cfg_order
= 1;
510 SET_MACHINE_COMPAT(m
, PC_COMPAT_2_5
);
513 DEFINE_I440FX_MACHINE(v2_5
, "pc-i440fx-2.5", NULL
,
514 pc_i440fx_2_5_machine_options
);
517 static void pc_i440fx_2_4_machine_options(MachineClass
*m
)
519 PCMachineClass
*pcmc
= PC_MACHINE_CLASS(m
);
520 pc_i440fx_2_5_machine_options(m
);
521 m
->hw_version
= "2.4.0";
522 pcmc
->broken_reserved_end
= true;
523 SET_MACHINE_COMPAT(m
, PC_COMPAT_2_4
);
526 DEFINE_I440FX_MACHINE(v2_4
, "pc-i440fx-2.4", NULL
,
527 pc_i440fx_2_4_machine_options
)
530 static void pc_i440fx_2_3_machine_options(MachineClass
*m
)
532 pc_i440fx_2_4_machine_options(m
);
533 m
->hw_version
= "2.3.0";
534 SET_MACHINE_COMPAT(m
, PC_COMPAT_2_3
);
537 DEFINE_I440FX_MACHINE(v2_3
, "pc-i440fx-2.3", pc_compat_2_3
,
538 pc_i440fx_2_3_machine_options
);
541 static void pc_i440fx_2_2_machine_options(MachineClass
*m
)
543 PCMachineClass
*pcmc
= PC_MACHINE_CLASS(m
);
544 pc_i440fx_2_3_machine_options(m
);
545 m
->hw_version
= "2.2.0";
546 SET_MACHINE_COMPAT(m
, PC_COMPAT_2_2
);
547 pcmc
->rsdp_in_ram
= false;
550 DEFINE_I440FX_MACHINE(v2_2
, "pc-i440fx-2.2", pc_compat_2_2
,
551 pc_i440fx_2_2_machine_options
);
554 static void pc_i440fx_2_1_machine_options(MachineClass
*m
)
556 PCMachineClass
*pcmc
= PC_MACHINE_CLASS(m
);
557 pc_i440fx_2_2_machine_options(m
);
558 m
->hw_version
= "2.1.0";
559 m
->default_display
= NULL
;
560 SET_MACHINE_COMPAT(m
, PC_COMPAT_2_1
);
561 pcmc
->smbios_uuid_encoded
= false;
562 pcmc
->enforce_aligned_dimm
= false;
565 DEFINE_I440FX_MACHINE(v2_1
, "pc-i440fx-2.1", pc_compat_2_1
,
566 pc_i440fx_2_1_machine_options
);
570 static void pc_i440fx_2_0_machine_options(MachineClass
*m
)
572 PCMachineClass
*pcmc
= PC_MACHINE_CLASS(m
);
573 pc_i440fx_2_1_machine_options(m
);
574 m
->hw_version
= "2.0.0";
575 SET_MACHINE_COMPAT(m
, PC_COMPAT_2_0
);
576 pcmc
->smbios_legacy_mode
= true;
577 pcmc
->has_reserved_memory
= false;
578 /* This value depends on the actual DSDT and SSDT compiled into
579 * the source QEMU; unfortunately it depends on the binary and
580 * not on the machine type, so we cannot make pc-i440fx-1.7 work on
581 * both QEMU 1.7 and QEMU 2.0.
583 * Large variations cause migration to fail for more than one
584 * consecutive value of the "-smp" maxcpus option.
586 * For small variations of the kind caused by different iasl versions,
587 * the 4k rounding usually leaves slack. However, there could be still
588 * one or two values that break. For QEMU 1.7 and QEMU 2.0 the
589 * slack is only ~10 bytes before one "-smp maxcpus" value breaks!
591 * 6652 is valid for QEMU 2.0, the right value for pc-i440fx-1.7 on
592 * QEMU 1.7 it is 6414. For RHEL/CentOS 7.0 it is 6418.
594 pcmc
->legacy_acpi_table_size
= 6652;
595 pcmc
->acpi_data_size
= 0x10000;
598 DEFINE_I440FX_MACHINE(v2_0
, "pc-i440fx-2.0", pc_compat_2_0
,
599 pc_i440fx_2_0_machine_options
);
602 static void pc_i440fx_1_7_machine_options(MachineClass
*m
)
604 PCMachineClass
*pcmc
= PC_MACHINE_CLASS(m
);
605 pc_i440fx_2_0_machine_options(m
);
606 m
->hw_version
= "1.7.0";
607 m
->default_machine_opts
= NULL
;
608 m
->option_rom_has_mr
= true;
609 SET_MACHINE_COMPAT(m
, PC_COMPAT_1_7
);
610 pcmc
->smbios_defaults
= false;
611 pcmc
->gigabyte_align
= false;
612 pcmc
->legacy_acpi_table_size
= 6414;
615 DEFINE_I440FX_MACHINE(v1_7
, "pc-i440fx-1.7", pc_compat_1_7
,
616 pc_i440fx_1_7_machine_options
);
619 static void pc_i440fx_1_6_machine_options(MachineClass
*m
)
621 PCMachineClass
*pcmc
= PC_MACHINE_CLASS(m
);
622 pc_i440fx_1_7_machine_options(m
);
623 m
->hw_version
= "1.6.0";
624 m
->rom_file_has_mr
= false;
625 SET_MACHINE_COMPAT(m
, PC_COMPAT_1_6
);
626 pcmc
->has_acpi_build
= false;
629 DEFINE_I440FX_MACHINE(v1_6
, "pc-i440fx-1.6", pc_compat_1_6
,
630 pc_i440fx_1_6_machine_options
);
633 static void pc_i440fx_1_5_machine_options(MachineClass
*m
)
635 pc_i440fx_1_6_machine_options(m
);
636 m
->hw_version
= "1.5.0";
637 SET_MACHINE_COMPAT(m
, PC_COMPAT_1_5
);
640 DEFINE_I440FX_MACHINE(v1_5
, "pc-i440fx-1.5", pc_compat_1_5
,
641 pc_i440fx_1_5_machine_options
);
644 static void pc_i440fx_1_4_machine_options(MachineClass
*m
)
646 pc_i440fx_1_5_machine_options(m
);
647 m
->hw_version
= "1.4.0";
648 m
->hot_add_cpu
= NULL
;
649 SET_MACHINE_COMPAT(m
, PC_COMPAT_1_4
);
652 DEFINE_I440FX_MACHINE(v1_4
, "pc-i440fx-1.4", pc_compat_1_4
,
653 pc_i440fx_1_4_machine_options
);
656 #define PC_COMPAT_1_3 \
657 PC_CPU_MODEL_IDS("1.3.0") \
659 .driver = "usb-tablet",\
660 .property = "usb_version",\
661 .value = stringify(1),\
663 .driver = "virtio-net-pci",\
664 .property = "ctrl_mac_addr",\
667 .driver = "virtio-net-pci", \
672 .property = "autonegotiation",\
677 static void pc_i440fx_1_3_machine_options(MachineClass
*m
)
679 pc_i440fx_1_4_machine_options(m
);
680 m
->hw_version
= "1.3.0";
681 SET_MACHINE_COMPAT(m
, PC_COMPAT_1_3
);
684 DEFINE_I440FX_MACHINE(v1_3
, "pc-1.3", pc_compat_1_3
,
685 pc_i440fx_1_3_machine_options
);
688 #define PC_COMPAT_1_2 \
689 PC_CPU_MODEL_IDS("1.2.0") \
691 .driver = "nec-usb-xhci",\
695 .driver = "nec-usb-xhci",\
699 .driver = "ivshmem",\
700 .property = "use64",\
704 .property = "revision",\
705 .value = stringify(3),\
707 .driver = "qxl-vga",\
708 .property = "revision",\
709 .value = stringify(3),\
716 static void pc_i440fx_1_2_machine_options(MachineClass
*m
)
718 pc_i440fx_1_3_machine_options(m
);
719 m
->hw_version
= "1.2.0";
720 SET_MACHINE_COMPAT(m
, PC_COMPAT_1_2
);
723 DEFINE_I440FX_MACHINE(v1_2
, "pc-1.2", pc_compat_1_2
,
724 pc_i440fx_1_2_machine_options
);
727 #define PC_COMPAT_1_1 \
728 PC_CPU_MODEL_IDS("1.1.0") \
730 .driver = "virtio-scsi-pci",\
731 .property = "hotplug",\
734 .driver = "virtio-scsi-pci",\
735 .property = "param_change",\
739 .property = "vgamem_mb",\
740 .value = stringify(8),\
742 .driver = "vmware-svga",\
743 .property = "vgamem_mb",\
744 .value = stringify(8),\
746 .driver = "qxl-vga",\
747 .property = "vgamem_mb",\
748 .value = stringify(8),\
751 .property = "vgamem_mb",\
752 .value = stringify(8),\
754 .driver = "virtio-blk-pci",\
755 .property = "config-wce",\
759 static void pc_i440fx_1_1_machine_options(MachineClass
*m
)
761 pc_i440fx_1_2_machine_options(m
);
762 m
->hw_version
= "1.1.0";
763 SET_MACHINE_COMPAT(m
, PC_COMPAT_1_1
);
766 DEFINE_I440FX_MACHINE(v1_1
, "pc-1.1", pc_compat_1_2
,
767 pc_i440fx_1_1_machine_options
);
770 #define PC_COMPAT_1_0 \
771 PC_CPU_MODEL_IDS("1.0") \
773 .driver = TYPE_ISA_FDC,\
774 .property = "check_media_rate",\
777 .driver = "virtio-balloon-pci",\
778 .property = "class",\
779 .value = stringify(PCI_CLASS_MEMORY_RAM),\
781 .driver = "apic-common",\
782 .property = "vapic",\
785 .driver = TYPE_USB_DEVICE,\
786 .property = "full-path",\
790 static void pc_i440fx_1_0_machine_options(MachineClass
*m
)
792 pc_i440fx_1_1_machine_options(m
);
793 m
->hw_version
= "1.0";
794 SET_MACHINE_COMPAT(m
, PC_COMPAT_1_0
);
797 DEFINE_I440FX_MACHINE(v1_0
, "pc-1.0", pc_compat_1_2
,
798 pc_i440fx_1_0_machine_options
);
801 #define PC_COMPAT_0_15 \
802 PC_CPU_MODEL_IDS("0.15")
804 static void pc_i440fx_0_15_machine_options(MachineClass
*m
)
806 pc_i440fx_1_0_machine_options(m
);
807 m
->hw_version
= "0.15";
808 SET_MACHINE_COMPAT(m
, PC_COMPAT_0_15
);
811 DEFINE_I440FX_MACHINE(v0_15
, "pc-0.15", pc_compat_1_2
,
812 pc_i440fx_0_15_machine_options
);
815 #define PC_COMPAT_0_14 \
816 PC_CPU_MODEL_IDS("0.14") \
818 .driver = "virtio-blk-pci",\
819 .property = "event_idx",\
822 .driver = "virtio-serial-pci",\
823 .property = "event_idx",\
826 .driver = "virtio-net-pci",\
827 .property = "event_idx",\
830 .driver = "virtio-balloon-pci",\
831 .property = "event_idx",\
835 .property = "revision",\
836 .value = stringify(2),\
838 .driver = "qxl-vga",\
839 .property = "revision",\
840 .value = stringify(2),\
843 static void pc_i440fx_0_14_machine_options(MachineClass
*m
)
845 pc_i440fx_0_15_machine_options(m
);
846 m
->hw_version
= "0.14";
847 SET_MACHINE_COMPAT(m
, PC_COMPAT_0_14
);
850 DEFINE_I440FX_MACHINE(v0_14
, "pc-0.14", pc_compat_1_2
,
851 pc_i440fx_0_14_machine_options
);
854 #define PC_COMPAT_0_13 \
855 PC_CPU_MODEL_IDS("0.13") \
857 .driver = TYPE_PCI_DEVICE,\
858 .property = "command_serr_enable",\
862 .property = "use_broken_id",\
863 .value = stringify(1),\
865 .driver = "virtio-9p-pci",\
866 .property = "vectors",\
867 .value = stringify(0),\
870 .property = "rombar",\
871 .value = stringify(0),\
873 .driver = "vmware-svga",\
874 .property = "rombar",\
875 .value = stringify(0),\
878 static void pc_i440fx_0_13_machine_options(MachineClass
*m
)
880 PCMachineClass
*pcmc
= PC_MACHINE_CLASS(m
);
881 pc_i440fx_0_14_machine_options(m
);
882 m
->hw_version
= "0.13";
883 SET_MACHINE_COMPAT(m
, PC_COMPAT_0_13
);
884 pcmc
->kvmclock_enabled
= false;
887 DEFINE_I440FX_MACHINE(v0_13
, "pc-0.13", pc_compat_0_13
,
888 pc_i440fx_0_13_machine_options
);
891 #define PC_COMPAT_0_12 \
892 PC_CPU_MODEL_IDS("0.12") \
894 .driver = "virtio-serial-pci",\
895 .property = "max_ports",\
896 .value = stringify(1),\
898 .driver = "virtio-serial-pci",\
899 .property = "vectors",\
900 .value = stringify(0),\
902 .driver = "usb-mouse",\
903 .property = "serial",\
906 .driver = "usb-tablet",\
907 .property = "serial",\
910 .driver = "usb-kbd",\
911 .property = "serial",\
915 static void pc_i440fx_0_12_machine_options(MachineClass
*m
)
917 pc_i440fx_0_13_machine_options(m
);
918 m
->hw_version
= "0.12";
919 SET_MACHINE_COMPAT(m
, PC_COMPAT_0_12
);
922 DEFINE_I440FX_MACHINE(v0_12
, "pc-0.12", pc_compat_0_13
,
923 pc_i440fx_0_12_machine_options
);
926 #define PC_COMPAT_0_11 \
927 PC_CPU_MODEL_IDS("0.11") \
929 .driver = "virtio-blk-pci",\
930 .property = "vectors",\
931 .value = stringify(0),\
933 .driver = TYPE_PCI_DEVICE,\
934 .property = "rombar",\
935 .value = stringify(0),\
937 .driver = "ide-drive",\
941 .driver = "scsi-disk",\
946 static void pc_i440fx_0_11_machine_options(MachineClass
*m
)
948 pc_i440fx_0_12_machine_options(m
);
949 m
->hw_version
= "0.11";
950 SET_MACHINE_COMPAT(m
, PC_COMPAT_0_11
);
953 DEFINE_I440FX_MACHINE(v0_11
, "pc-0.11", pc_compat_0_13
,
954 pc_i440fx_0_11_machine_options
);
957 #define PC_COMPAT_0_10 \
958 PC_CPU_MODEL_IDS("0.10") \
960 .driver = "virtio-blk-pci",\
961 .property = "class",\
962 .value = stringify(PCI_CLASS_STORAGE_OTHER),\
964 .driver = "virtio-serial-pci",\
965 .property = "class",\
966 .value = stringify(PCI_CLASS_DISPLAY_OTHER),\
968 .driver = "virtio-net-pci",\
969 .property = "vectors",\
970 .value = stringify(0),\
972 .driver = "ide-drive",\
976 .driver = "scsi-disk",\
981 static void pc_i440fx_0_10_machine_options(MachineClass
*m
)
983 pc_i440fx_0_11_machine_options(m
);
984 m
->hw_version
= "0.10";
985 SET_MACHINE_COMPAT(m
, PC_COMPAT_0_10
);
988 DEFINE_I440FX_MACHINE(v0_10
, "pc-0.10", pc_compat_0_13
,
989 pc_i440fx_0_10_machine_options
);
992 uint16_t gpu_device_id
;
993 uint16_t pch_device_id
;
994 uint8_t pch_revision_id
;
997 /* In real world different GPU should have different PCH. But actually
998 * the different PCH DIDs likely map to different PCH SKUs. We do the
999 * same thing for the GPU. For PCH, the different SKUs are going to be
1000 * all the same silicon design and implementation, just different
1001 * features turn on and off with fuses. The SW interfaces should be
1002 * consistent across all SKUs in a given family (eg LPT). But just same
1003 * features may not be supported.
1005 * Most of these different PCH features probably don't matter to the
1006 * Gfx driver, but obviously any difference in display port connections
1007 * will so it should be fine with any PCH in case of passthrough.
1009 * So currently use one PCH version, 0x8c4e, to cover all HSW(Haswell)
1010 * scenarios, 0x9cc3 for BDW(Broadwell).
1012 static const IGDDeviceIDInfo igd_combo_id_infos
[] = {
1014 {0x0402, 0x8c4e, 0x04}, /* HSWGT1D, HSWD_w7 */
1015 {0x0406, 0x8c4e, 0x04}, /* HSWGT1M, HSWM_w7 */
1016 {0x0412, 0x8c4e, 0x04}, /* HSWGT2D, HSWD_w7 */
1017 {0x0416, 0x8c4e, 0x04}, /* HSWGT2M, HSWM_w7 */
1018 {0x041E, 0x8c4e, 0x04}, /* HSWGT15D, HSWD_w7 */
1020 {0x0A06, 0x8c4e, 0x04}, /* HSWGT1UT, HSWM_w7 */
1021 {0x0A16, 0x8c4e, 0x04}, /* HSWGT2UT, HSWM_w7 */
1022 {0x0A26, 0x8c4e, 0x06}, /* HSWGT3UT, HSWM_w7 */
1023 {0x0A2E, 0x8c4e, 0x04}, /* HSWGT3UT28W, HSWM_w7 */
1024 {0x0A1E, 0x8c4e, 0x04}, /* HSWGT2UX, HSWM_w7 */
1025 {0x0A0E, 0x8c4e, 0x04}, /* HSWGT1ULX, HSWM_w7 */
1027 {0x0D26, 0x8c4e, 0x04}, /* HSWGT3CW, HSWM_w7 */
1028 {0x0D22, 0x8c4e, 0x04}, /* HSWGT3CWDT, HSWD_w7 */
1030 {0x041A, 0x8c4e, 0x04}, /* HSWSVGT2, HSWD_w7 */
1032 {0x040A, 0x8c4e, 0x04}, /* HSWSVGT1, HSWD_w7 */
1034 {0x1606, 0x9cc3, 0x03}, /* BDWULTGT1, BDWM_w7 */
1035 {0x1616, 0x9cc3, 0x03}, /* BDWULTGT2, BDWM_w7 */
1036 {0x1626, 0x9cc3, 0x03}, /* BDWULTGT3, BDWM_w7 */
1037 {0x160E, 0x9cc3, 0x03}, /* BDWULXGT1, BDWM_w7 */
1038 {0x161E, 0x9cc3, 0x03}, /* BDWULXGT2, BDWM_w7 */
1039 {0x1602, 0x9cc3, 0x03}, /* BDWHALOGT1, BDWM_w7 */
1040 {0x1612, 0x9cc3, 0x03}, /* BDWHALOGT2, BDWM_w7 */
1041 {0x1622, 0x9cc3, 0x03}, /* BDWHALOGT3, BDWM_w7 */
1042 {0x162B, 0x9cc3, 0x03}, /* BDWHALO28W, BDWM_w7 */
1043 {0x162A, 0x9cc3, 0x03}, /* BDWGT3WRKS, BDWM_w7 */
1044 {0x162D, 0x9cc3, 0x03}, /* BDWGT3SRVR, BDWM_w7 */
1047 static void isa_bridge_class_init(ObjectClass
*klass
, void *data
)
1049 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1050 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
1052 dc
->desc
= "ISA bridge faked to support IGD PT";
1053 k
->vendor_id
= PCI_VENDOR_ID_INTEL
;
1054 k
->class_id
= PCI_CLASS_BRIDGE_ISA
;
1057 static TypeInfo isa_bridge_info
= {
1058 .name
= "igd-passthrough-isa-bridge",
1059 .parent
= TYPE_PCI_DEVICE
,
1060 .instance_size
= sizeof(PCIDevice
),
1061 .class_init
= isa_bridge_class_init
,
1062 .interfaces
= (InterfaceInfo
[]) {
1063 { INTERFACE_CONVENTIONAL_PCI_DEVICE
},
1068 static void pt_graphics_register_types(void)
1070 type_register_static(&isa_bridge_info
);
1072 type_init(pt_graphics_register_types
)
1074 void igd_passthrough_isa_bridge_create(PCIBus
*bus
, uint16_t gpu_dev_id
)
1076 struct PCIDevice
*bridge_dev
;
1078 uint16_t pch_dev_id
= 0xffff;
1081 num
= ARRAY_SIZE(igd_combo_id_infos
);
1082 for (i
= 0; i
< num
; i
++) {
1083 if (gpu_dev_id
== igd_combo_id_infos
[i
].gpu_device_id
) {
1084 pch_dev_id
= igd_combo_id_infos
[i
].pch_device_id
;
1085 pch_rev_id
= igd_combo_id_infos
[i
].pch_revision_id
;
1089 if (pch_dev_id
== 0xffff) {
1093 /* Currently IGD drivers always need to access PCH by 1f.0. */
1094 bridge_dev
= pci_create_simple(bus
, PCI_DEVFN(0x1f, 0),
1095 "igd-passthrough-isa-bridge");
1098 * Note that vendor id is always PCI_VENDOR_ID_INTEL.
1101 fprintf(stderr
, "set igd-passthrough-isa-bridge failed!\n");
1104 pci_config_set_device_id(bridge_dev
->config
, pch_dev_id
);
1105 pci_config_set_revision(bridge_dev
->config
, pch_rev_id
);
1108 static void isapc_machine_options(MachineClass
*m
)
1110 PCMachineClass
*pcmc
= PC_MACHINE_CLASS(m
);
1111 m
->desc
= "ISA-only PC";
1113 m
->option_rom_has_mr
= true;
1114 m
->rom_file_has_mr
= false;
1115 pcmc
->pci_enabled
= false;
1116 pcmc
->has_acpi_build
= false;
1117 pcmc
->smbios_defaults
= false;
1118 pcmc
->gigabyte_align
= false;
1119 pcmc
->smbios_legacy_mode
= true;
1120 pcmc
->has_reserved_memory
= false;
1121 m
->default_cpu_type
= X86_CPU_TYPE_NAME("486");
1124 DEFINE_PC_MACHINE(isapc
, "isapc", pc_init_isa
,
1125 isapc_machine_options
);
1129 static void xenfv_machine_options(MachineClass
*m
)
1131 m
->desc
= "Xen Fully-virtualized PC";
1132 m
->max_cpus
= HVM_MAX_VCPUS
;
1133 m
->default_machine_opts
= "accel=xen";
1136 DEFINE_PC_MACHINE(xenfv
, "xenfv", pc_xen_hvm_init
,
1137 xenfv_machine_options
);