1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "qemu/osdep.h"
26
27#include "qemu/units.h"
28#include "hw/hw.h"
29#include "hw/loader.h"
30#include "hw/i386/pc.h"
31#include "hw/i386/apic.h"
32#include "hw/display/ramfb.h"
33#include "hw/smbios/smbios.h"
34#include "hw/pci/pci.h"
35#include "hw/pci/pci_ids.h"
36#include "hw/usb.h"
37#include "net/net.h"
38#include "hw/boards.h"
39#include "hw/ide.h"
40#include "sysemu/kvm.h"
41#include "hw/kvm/clock.h"
42#include "sysemu/sysemu.h"
43#include "hw/sysbus.h"
44#include "sysemu/arch_init.h"
45#include "hw/i2c/smbus.h"
46#include "hw/xen/xen.h"
47#include "exec/memory.h"
48#include "exec/address-spaces.h"
49#include "hw/acpi/acpi.h"
50#include "cpu.h"
51#include "qapi/error.h"
52#include "qemu/error-report.h"
53#ifdef CONFIG_XEN
54#include <xen/hvm/hvm_info_table.h>
55#include "hw/xen/xen_pt.h"
56#endif
57#include "migration/global_state.h"
58#include "migration/misc.h"
59#include "kvm_i386.h"
60#include "sysemu/numa.h"
61
62#define MAX_IDE_BUS 2
63
64static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
65static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
66static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
67
68
69static void pc_init1(MachineState *machine,
70 const char *host_type, const char *pci_type)
71{
72 PCMachineState *pcms = PC_MACHINE(machine);
73 PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
74 MemoryRegion *system_memory = get_system_memory();
75 MemoryRegion *system_io = get_system_io();
76 int i;
77 PCIBus *pci_bus;
78 ISABus *isa_bus;
79 PCII440FXState *i440fx_state;
80 int piix3_devfn = -1;
81 qemu_irq *i8259;
82 qemu_irq smi_irq;
83 GSIState *gsi_state;
84 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
85 BusState *idebus[MAX_IDE_BUS];
86 ISADevice *rtc_state;
87 MemoryRegion *ram_memory;
88 MemoryRegion *pci_memory;
89 MemoryRegion *rom_memory;
90 ram_addr_t lowmem;
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 if (xen_enabled()) {
124 xen_hvm_init(pcms, &ram_memory);
125 } else {
126 if (!pcms->max_ram_below_4g) {
127 pcms->max_ram_below_4g = 0xe0000000;
128 }
129 lowmem = pcms->max_ram_below_4g;
130 if (machine->ram_size >= pcms->max_ram_below_4g) {
131 if (pcmc->gigabyte_align) {
132 if (lowmem > 0xc0000000) {
133 lowmem = 0xc0000000;
134 }
135 if (lowmem & (1 * GiB - 1)) {
136 warn_report("Large machine and max_ram_below_4g "
137 "(%" PRIu64 ") not a multiple of 1G; "
138 "possible bad performance.",
139 pcms->max_ram_below_4g);
140 }
141 }
142 }
143
144 if (machine->ram_size >= lowmem) {
145 pcms->above_4g_mem_size = machine->ram_size - lowmem;
146 pcms->below_4g_mem_size = lowmem;
147 } else {
148 pcms->above_4g_mem_size = 0;
149 pcms->below_4g_mem_size = machine->ram_size;
150 }
151 }
152
153 pc_cpus_init(pcms);
154
155 if (kvm_enabled() && pcmc->kvmclock_enabled) {
156 kvmclock_create();
157 }
158
159 if (pcmc->pci_enabled) {
160 pci_memory = g_new(MemoryRegion, 1);
161 memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
162 rom_memory = pci_memory;
163 } else {
164 pci_memory = NULL;
165 rom_memory = system_memory;
166 }
167
168 pc_guest_info_init(pcms);
169
170 if (pcmc->smbios_defaults) {
171 MachineClass *mc = MACHINE_GET_CLASS(machine);
172
173 smbios_set_defaults("QEMU", "Standard PC (i440FX + PIIX, 1996)",
174 mc->name, pcmc->smbios_legacy_mode,
175 pcmc->smbios_uuid_encoded,
176 SMBIOS_ENTRY_POINT_21);
177 }
178
179
180 if (!xen_enabled()) {
181 pc_memory_init(pcms, system_memory,
182 rom_memory, &ram_memory);
183 } else if (machine->kernel_filename != NULL) {
184
185 xen_load_linux(pcms);
186 }
187
188 gsi_state = g_malloc0(sizeof(*gsi_state));
189 if (kvm_ioapic_in_kernel()) {
190 kvm_pc_setup_irq_routing(pcmc->pci_enabled);
191 pcms->gsi = qemu_allocate_irqs(kvm_pc_gsi_handler, gsi_state,
192 GSI_NUM_PINS);
193 } else {
194 pcms->gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
195 }
196
197 if (pcmc->pci_enabled) {
198 pci_bus = i440fx_init(host_type,
199 pci_type,
200 &i440fx_state, &piix3_devfn, &isa_bus, pcms->gsi,
201 system_memory, system_io, machine->ram_size,
202 pcms->below_4g_mem_size,
203 pcms->above_4g_mem_size,
204 pci_memory, ram_memory);
205 pcms->bus = pci_bus;
206 } else {
207 pci_bus = NULL;
208 i440fx_state = NULL;
209 isa_bus = isa_bus_new(NULL, get_system_memory(), system_io,
210 &error_abort);
211 no_hpet = 1;
212 }
213 isa_bus_irqs(isa_bus, pcms->gsi);
214
215 if (kvm_pic_in_kernel()) {
216 i8259 = kvm_i8259_init(isa_bus);
217 } else if (xen_enabled()) {
218 i8259 = xen_interrupt_controller_init();
219 } else {
220 i8259 = i8259_init(isa_bus, pc_allocate_cpu_irq());
221 }
222
223 for (i = 0; i < ISA_NUM_IRQS; i++) {
224 gsi_state->i8259_irq[i] = i8259[i];
225 }
226 g_free(i8259);
227 if (pcmc->pci_enabled) {
228 ioapic_init_gsi(gsi_state, "i440fx");
229 }
230
231 pc_register_ferr_irq(pcms->gsi[13]);
232
233 pc_vga_init(isa_bus, pcmc->pci_enabled ? pci_bus : NULL);
234
235 assert(pcms->vmport != ON_OFF_AUTO__MAX);
236 if (pcms->vmport == ON_OFF_AUTO_AUTO) {
237 pcms->vmport = xen_enabled() ? ON_OFF_AUTO_OFF : ON_OFF_AUTO_ON;
238 }
239
240
241 pc_basic_device_init(isa_bus, pcms->gsi, &rtc_state, true,
242 (pcms->vmport != ON_OFF_AUTO_ON), pcms->pit, 0x4);
243
244 pc_nic_init(pcmc, isa_bus, pci_bus);
245
246 ide_drive_get(hd, ARRAY_SIZE(hd));
247 if (pcmc->pci_enabled) {
248 PCIDevice *dev;
249 if (xen_enabled()) {
250 dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
251 } else {
252 dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
253 }
254 idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
255 idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
256 } else {
257 for(i = 0; i < MAX_IDE_BUS; i++) {
258 ISADevice *dev;
259 char busname[] = "ide.0";
260 dev = isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i],
261 ide_irq[i],
262 hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
263
264
265
266
267 busname[4] = '0' + i;
268 idebus[i] = qdev_get_child_bus(DEVICE(dev), busname);
269 }
270 }
271
272 pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);
273
274 if (pcmc->pci_enabled && machine_usb(machine)) {
275 pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
276 }
277
278 if (pcmc->pci_enabled && acpi_enabled) {
279 DeviceState *piix4_pm;
280 I2CBus *smbus;
281
282 smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0);
283
284 smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
285 pcms->gsi[9], smi_irq,
286 pc_machine_is_smm_enabled(pcms),
287 &piix4_pm);
288 smbus_eeprom_init(smbus, 8, NULL, 0);
289
290 object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
291 TYPE_HOTPLUG_HANDLER,
292 (Object **)&pcms->acpi_dev,
293 object_property_allow_set_link,
294 OBJ_PROP_LINK_STRONG, &error_abort);
295 object_property_set_link(OBJECT(machine), OBJECT(piix4_pm),
296 PC_MACHINE_ACPI_DEVICE_PROP, &error_abort);
297 }
298
299 if (pcms->acpi_nvdimm_state.is_enabled) {
300 nvdimm_init_acpi_state(&pcms->acpi_nvdimm_state, system_io,
301 pcms->fw_cfg, OBJECT(pcms));
302 }
303}
304
305
306
307
308
309
310
311
312static void pc_compat_2_3(MachineState *machine)
313{
314 PCMachineState *pcms = PC_MACHINE(machine);
315 if (kvm_enabled()) {
316 pcms->smm = ON_OFF_AUTO_OFF;
317 }
318}
319
320static void pc_compat_2_2(MachineState *machine)
321{
322 pc_compat_2_3(machine);
323 machine->suppress_vmdesc = true;
324}
325
326static void pc_compat_2_1(MachineState *machine)
327{
328 pc_compat_2_2(machine);
329 x86_cpu_change_kvm_default("svm", NULL);
330}
331
332static void pc_compat_2_0(MachineState *machine)
333{
334 pc_compat_2_1(machine);
335}
336
337static void pc_compat_1_7(MachineState *machine)
338{
339 pc_compat_2_0(machine);
340 x86_cpu_change_kvm_default("x2apic", NULL);
341}
342
343static void pc_compat_1_6(MachineState *machine)
344{
345 pc_compat_1_7(machine);
346}
347
348static void pc_compat_1_5(MachineState *machine)
349{
350 pc_compat_1_6(machine);
351}
352
353static void pc_compat_1_4(MachineState *machine)
354{
355 pc_compat_1_5(machine);
356}
357
358static void pc_compat_1_3(MachineState *machine)
359{
360 pc_compat_1_4(machine);
361 enable_compat_apic_id_mode();
362}
363
364
365static void pc_compat_1_2(MachineState *machine)
366{
367 pc_compat_1_3(machine);
368 x86_cpu_change_kvm_default("kvm-pv-eoi", NULL);
369}
370
371
372static void pc_compat_0_13(MachineState *machine)
373{
374 pc_compat_1_2(machine);
375}
376
377static void pc_init_isa(MachineState *machine)
378{
379 pc_init1(machine, TYPE_I440FX_PCI_HOST_BRIDGE, TYPE_I440FX_PCI_DEVICE);
380}
381
382#ifdef CONFIG_XEN
383static void pc_xen_hvm_init_pci(MachineState *machine)
384{
385 const char *pci_type = has_igd_gfx_passthru ?
386 TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE : TYPE_I440FX_PCI_DEVICE;
387
388 pc_init1(machine,
389 TYPE_I440FX_PCI_HOST_BRIDGE,
390 pci_type);
391}
392
393static void pc_xen_hvm_init(MachineState *machine)
394{
395 PCMachineState *pcms = PC_MACHINE(machine);
396
397 if (!xen_enabled()) {
398 error_report("xenfv machine requires the xen accelerator");
399 exit(1);
400 }
401
402 pc_xen_hvm_init_pci(machine);
403 pci_create_simple(pcms->bus, -1, "xen-platform");
404}
405#endif
406
407#define DEFINE_I440FX_MACHINE(suffix, name, compatfn, optionfn) \
408 static void pc_init_##suffix(MachineState *machine) \
409 { \
410 void (*compat)(MachineState *m) = (compatfn); \
411 if (compat) { \
412 compat(machine); \
413 } \
414 pc_init1(machine, TYPE_I440FX_PCI_HOST_BRIDGE, \
415 TYPE_I440FX_PCI_DEVICE); \
416 } \
417 DEFINE_PC_MACHINE(suffix, name, pc_init_##suffix, optionfn)
418
419static void pc_i440fx_machine_options(MachineClass *m)
420{
421 PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
422 pcmc->default_nic_model = "e1000";
423
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";
428 machine_class_allow_dynamic_sysbus_dev(m, TYPE_RAMFB_DEVICE);
429}
430
431static void pc_i440fx_3_1_machine_options(MachineClass *m)
432{
433 pc_i440fx_machine_options(m);
434 m->alias = "pc";
435 m->is_default = 1;
436}
437
438DEFINE_I440FX_MACHINE(v3_1, "pc-i440fx-3.1", NULL,
439 pc_i440fx_3_1_machine_options);
440
441static void pc_i440fx_3_0_machine_options(MachineClass *m)
442{
443 pc_i440fx_3_1_machine_options(m);
444 m->is_default = 0;
445 m->alias = NULL;
446 SET_MACHINE_COMPAT(m, PC_COMPAT_3_0);
447}
448
449DEFINE_I440FX_MACHINE(v3_0, "pc-i440fx-3.0", NULL,
450 pc_i440fx_3_0_machine_options);
451
452static void pc_i440fx_2_12_machine_options(MachineClass *m)
453{
454 pc_i440fx_3_0_machine_options(m);
455 SET_MACHINE_COMPAT(m, PC_COMPAT_2_12);
456}
457
458DEFINE_I440FX_MACHINE(v2_12, "pc-i440fx-2.12", NULL,
459 pc_i440fx_2_12_machine_options);
460
461static void pc_i440fx_2_11_machine_options(MachineClass *m)
462{
463 pc_i440fx_2_12_machine_options(m);
464 SET_MACHINE_COMPAT(m, PC_COMPAT_2_11);
465}
466
467DEFINE_I440FX_MACHINE(v2_11, "pc-i440fx-2.11", NULL,
468 pc_i440fx_2_11_machine_options);
469
470static void pc_i440fx_2_10_machine_options(MachineClass *m)
471{
472 pc_i440fx_2_11_machine_options(m);
473 SET_MACHINE_COMPAT(m, PC_COMPAT_2_10);
474 m->auto_enable_numa_with_memhp = false;
475}
476
477DEFINE_I440FX_MACHINE(v2_10, "pc-i440fx-2.10", NULL,
478 pc_i440fx_2_10_machine_options);
479
480static void pc_i440fx_2_9_machine_options(MachineClass *m)
481{
482 pc_i440fx_2_10_machine_options(m);
483 SET_MACHINE_COMPAT(m, PC_COMPAT_2_9);
484 m->numa_auto_assign_ram = numa_legacy_auto_assign_ram;
485}
486
487DEFINE_I440FX_MACHINE(v2_9, "pc-i440fx-2.9", NULL,
488 pc_i440fx_2_9_machine_options);
489
490static void pc_i440fx_2_8_machine_options(MachineClass *m)
491{
492 pc_i440fx_2_9_machine_options(m);
493 SET_MACHINE_COMPAT(m, PC_COMPAT_2_8);
494}
495
496DEFINE_I440FX_MACHINE(v2_8, "pc-i440fx-2.8", NULL,
497 pc_i440fx_2_8_machine_options);
498
499
500static void pc_i440fx_2_7_machine_options(MachineClass *m)
501{
502 pc_i440fx_2_8_machine_options(m);
503 SET_MACHINE_COMPAT(m, PC_COMPAT_2_7);
504}
505
506DEFINE_I440FX_MACHINE(v2_7, "pc-i440fx-2.7", NULL,
507 pc_i440fx_2_7_machine_options);
508
509
510static void pc_i440fx_2_6_machine_options(MachineClass *m)
511{
512 PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
513 pc_i440fx_2_7_machine_options(m);
514 pcmc->legacy_cpu_hotplug = true;
515 pcmc->linuxboot_dma_enabled = false;
516 SET_MACHINE_COMPAT(m, PC_COMPAT_2_6);
517}
518
519DEFINE_I440FX_MACHINE(v2_6, "pc-i440fx-2.6", NULL,
520 pc_i440fx_2_6_machine_options);
521
522
523static void pc_i440fx_2_5_machine_options(MachineClass *m)
524{
525 PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
526 pc_i440fx_2_6_machine_options(m);
527 pcmc->save_tsc_khz = false;
528 m->legacy_fw_cfg_order = 1;
529 SET_MACHINE_COMPAT(m, PC_COMPAT_2_5);
530}
531
532DEFINE_I440FX_MACHINE(v2_5, "pc-i440fx-2.5", NULL,
533 pc_i440fx_2_5_machine_options);
534
535
536static void pc_i440fx_2_4_machine_options(MachineClass *m)
537{
538 PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
539 pc_i440fx_2_5_machine_options(m);
540 m->hw_version = "2.4.0";
541 pcmc->broken_reserved_end = true;
542 SET_MACHINE_COMPAT(m, PC_COMPAT_2_4);
543}
544
545DEFINE_I440FX_MACHINE(v2_4, "pc-i440fx-2.4", NULL,
546 pc_i440fx_2_4_machine_options)
547
548
549static void pc_i440fx_2_3_machine_options(MachineClass *m)
550{
551 pc_i440fx_2_4_machine_options(m);
552 m->hw_version = "2.3.0";
553 SET_MACHINE_COMPAT(m, PC_COMPAT_2_3);
554}
555
556DEFINE_I440FX_MACHINE(v2_3, "pc-i440fx-2.3", pc_compat_2_3,
557 pc_i440fx_2_3_machine_options);
558
559
560static void pc_i440fx_2_2_machine_options(MachineClass *m)
561{
562 PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
563 pc_i440fx_2_3_machine_options(m);
564 m->hw_version = "2.2.0";
565 SET_MACHINE_COMPAT(m, PC_COMPAT_2_2);
566 pcmc->rsdp_in_ram = false;
567}
568
569DEFINE_I440FX_MACHINE(v2_2, "pc-i440fx-2.2", pc_compat_2_2,
570 pc_i440fx_2_2_machine_options);
571
572
573static void pc_i440fx_2_1_machine_options(MachineClass *m)
574{
575 PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
576 pc_i440fx_2_2_machine_options(m);
577 m->hw_version = "2.1.0";
578 m->default_display = NULL;
579 SET_MACHINE_COMPAT(m, PC_COMPAT_2_1);
580 pcmc->smbios_uuid_encoded = false;
581 pcmc->enforce_aligned_dimm = false;
582}
583
584DEFINE_I440FX_MACHINE(v2_1, "pc-i440fx-2.1", pc_compat_2_1,
585 pc_i440fx_2_1_machine_options);
586
587
588
589static void pc_i440fx_2_0_machine_options(MachineClass *m)
590{
591 PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
592 pc_i440fx_2_1_machine_options(m);
593 m->hw_version = "2.0.0";
594 SET_MACHINE_COMPAT(m, PC_COMPAT_2_0);
595 pcmc->smbios_legacy_mode = true;
596 pcmc->has_reserved_memory = false;
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613 pcmc->legacy_acpi_table_size = 6652;
614 pcmc->acpi_data_size = 0x10000;
615}
616
617DEFINE_I440FX_MACHINE(v2_0, "pc-i440fx-2.0", pc_compat_2_0,
618 pc_i440fx_2_0_machine_options);
619
620
621static void pc_i440fx_1_7_machine_options(MachineClass *m)
622{
623 PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
624 pc_i440fx_2_0_machine_options(m);
625 m->hw_version = "1.7.0";
626 m->default_machine_opts = NULL;
627 m->option_rom_has_mr = true;
628 SET_MACHINE_COMPAT(m, PC_COMPAT_1_7);
629 pcmc->smbios_defaults = false;
630 pcmc->gigabyte_align = false;
631 pcmc->legacy_acpi_table_size = 6414;
632}
633
634DEFINE_I440FX_MACHINE(v1_7, "pc-i440fx-1.7", pc_compat_1_7,
635 pc_i440fx_1_7_machine_options);
636
637
638static void pc_i440fx_1_6_machine_options(MachineClass *m)
639{
640 PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
641 pc_i440fx_1_7_machine_options(m);
642 m->hw_version = "1.6.0";
643 m->rom_file_has_mr = false;
644 SET_MACHINE_COMPAT(m, PC_COMPAT_1_6);
645 pcmc->has_acpi_build = false;
646}
647
648DEFINE_I440FX_MACHINE(v1_6, "pc-i440fx-1.6", pc_compat_1_6,
649 pc_i440fx_1_6_machine_options);
650
651
652static void pc_i440fx_1_5_machine_options(MachineClass *m)
653{
654 pc_i440fx_1_6_machine_options(m);
655 m->hw_version = "1.5.0";
656 SET_MACHINE_COMPAT(m, PC_COMPAT_1_5);
657}
658
659DEFINE_I440FX_MACHINE(v1_5, "pc-i440fx-1.5", pc_compat_1_5,
660 pc_i440fx_1_5_machine_options);
661
662
663static void pc_i440fx_1_4_machine_options(MachineClass *m)
664{
665 pc_i440fx_1_5_machine_options(m);
666 m->hw_version = "1.4.0";
667 m->hot_add_cpu = NULL;
668 SET_MACHINE_COMPAT(m, PC_COMPAT_1_4);
669}
670
671DEFINE_I440FX_MACHINE(v1_4, "pc-i440fx-1.4", pc_compat_1_4,
672 pc_i440fx_1_4_machine_options);
673
674
675#define PC_COMPAT_1_3 \
676 PC_CPU_MODEL_IDS("1.3.0") \
677 {\
678 .driver = "usb-tablet",\
679 .property = "usb_version",\
680 .value = stringify(1),\
681 },{\
682 .driver = "virtio-net-pci",\
683 .property = "ctrl_mac_addr",\
684 .value = "off", \
685 },{ \
686 .driver = "virtio-net-pci", \
687 .property = "mq", \
688 .value = "off", \
689 }, {\
690 .driver = "e1000",\
691 .property = "autonegotiation",\
692 .value = "off",\
693 },
694
695
696static void pc_i440fx_1_3_machine_options(MachineClass *m)
697{
698 pc_i440fx_1_4_machine_options(m);
699 m->hw_version = "1.3.0";
700 SET_MACHINE_COMPAT(m, PC_COMPAT_1_3);
701}
702
703DEFINE_I440FX_MACHINE(v1_3, "pc-1.3", pc_compat_1_3,
704 pc_i440fx_1_3_machine_options);
705
706
707#define PC_COMPAT_1_2 \
708 PC_CPU_MODEL_IDS("1.2.0") \
709 {\
710 .driver = "nec-usb-xhci",\
711 .property = "msi",\
712 .value = "off",\
713 },{\
714 .driver = "nec-usb-xhci",\
715 .property = "msix",\
716 .value = "off",\
717 },{\
718 .driver = "ivshmem",\
719 .property = "use64",\
720 .value = "0",\
721 },{\
722 .driver = "qxl",\
723 .property = "revision",\
724 .value = stringify(3),\
725 },{\
726 .driver = "qxl-vga",\
727 .property = "revision",\
728 .value = stringify(3),\
729 },{\
730 .driver = "VGA",\
731 .property = "mmio",\
732 .value = "off",\
733 },
734
735static void pc_i440fx_1_2_machine_options(MachineClass *m)
736{
737 pc_i440fx_1_3_machine_options(m);
738 m->hw_version = "1.2.0";
739 SET_MACHINE_COMPAT(m, PC_COMPAT_1_2);
740}
741
742DEFINE_I440FX_MACHINE(v1_2, "pc-1.2", pc_compat_1_2,
743 pc_i440fx_1_2_machine_options);
744
745
746#define PC_COMPAT_1_1 \
747 PC_CPU_MODEL_IDS("1.1.0") \
748 {\
749 .driver = "virtio-scsi-pci",\
750 .property = "hotplug",\
751 .value = "off",\
752 },{\
753 .driver = "virtio-scsi-pci",\
754 .property = "param_change",\
755 .value = "off",\
756 },{\
757 .driver = "VGA",\
758 .property = "vgamem_mb",\
759 .value = stringify(8),\
760 },{\
761 .driver = "vmware-svga",\
762 .property = "vgamem_mb",\
763 .value = stringify(8),\
764 },{\
765 .driver = "qxl-vga",\
766 .property = "vgamem_mb",\
767 .value = stringify(8),\
768 },{\
769 .driver = "qxl",\
770 .property = "vgamem_mb",\
771 .value = stringify(8),\
772 },{\
773 .driver = "virtio-blk-pci",\
774 .property = "config-wce",\
775 .value = "off",\
776 },
777
778static void pc_i440fx_1_1_machine_options(MachineClass *m)
779{
780 pc_i440fx_1_2_machine_options(m);
781 m->hw_version = "1.1.0";
782 SET_MACHINE_COMPAT(m, PC_COMPAT_1_1);
783}
784
785DEFINE_I440FX_MACHINE(v1_1, "pc-1.1", pc_compat_1_2,
786 pc_i440fx_1_1_machine_options);
787
788
789#define PC_COMPAT_1_0 \
790 PC_CPU_MODEL_IDS("1.0") \
791 {\
792 .driver = TYPE_ISA_FDC,\
793 .property = "check_media_rate",\
794 .value = "off",\
795 }, {\
796 .driver = "virtio-balloon-pci",\
797 .property = "class",\
798 .value = stringify(PCI_CLASS_MEMORY_RAM),\
799 },{\
800 .driver = "apic-common",\
801 .property = "vapic",\
802 .value = "off",\
803 },{\
804 .driver = TYPE_USB_DEVICE,\
805 .property = "full-path",\
806 .value = "no",\
807 },
808
809static void pc_i440fx_1_0_machine_options(MachineClass *m)
810{
811 pc_i440fx_1_1_machine_options(m);
812 m->hw_version = "1.0";
813 SET_MACHINE_COMPAT(m, PC_COMPAT_1_0);
814}
815
816DEFINE_I440FX_MACHINE(v1_0, "pc-1.0", pc_compat_1_2,
817 pc_i440fx_1_0_machine_options);
818
819
820#define PC_COMPAT_0_15 \
821 PC_CPU_MODEL_IDS("0.15")
822
823static void pc_i440fx_0_15_machine_options(MachineClass *m)
824{
825 pc_i440fx_1_0_machine_options(m);
826 m->hw_version = "0.15";
827 SET_MACHINE_COMPAT(m, PC_COMPAT_0_15);
828}
829
830DEFINE_I440FX_MACHINE(v0_15, "pc-0.15", pc_compat_1_2,
831 pc_i440fx_0_15_machine_options);
832
833
834#define PC_COMPAT_0_14 \
835 PC_CPU_MODEL_IDS("0.14") \
836 {\
837 .driver = "virtio-blk-pci",\
838 .property = "event_idx",\
839 .value = "off",\
840 },{\
841 .driver = "virtio-serial-pci",\
842 .property = "event_idx",\
843 .value = "off",\
844 },{\
845 .driver = "virtio-net-pci",\
846 .property = "event_idx",\
847 .value = "off",\
848 },{\
849 .driver = "virtio-balloon-pci",\
850 .property = "event_idx",\
851 .value = "off",\
852 },{\
853 .driver = "qxl",\
854 .property = "revision",\
855 .value = stringify(2),\
856 },{\
857 .driver = "qxl-vga",\
858 .property = "revision",\
859 .value = stringify(2),\
860 },
861
862static void pc_i440fx_0_14_machine_options(MachineClass *m)
863{
864 pc_i440fx_0_15_machine_options(m);
865 m->hw_version = "0.14";
866 SET_MACHINE_COMPAT(m, PC_COMPAT_0_14);
867}
868
869DEFINE_I440FX_MACHINE(v0_14, "pc-0.14", pc_compat_1_2,
870 pc_i440fx_0_14_machine_options);
871
872
873#define PC_COMPAT_0_13 \
874 PC_CPU_MODEL_IDS("0.13") \
875 {\
876 .driver = TYPE_PCI_DEVICE,\
877 .property = "command_serr_enable",\
878 .value = "off",\
879 },{\
880 .driver = "AC97",\
881 .property = "use_broken_id",\
882 .value = stringify(1),\
883 },{\
884 .driver = "virtio-9p-pci",\
885 .property = "vectors",\
886 .value = stringify(0),\
887 },{\
888 .driver = "VGA",\
889 .property = "rombar",\
890 .value = stringify(0),\
891 },{\
892 .driver = "vmware-svga",\
893 .property = "rombar",\
894 .value = stringify(0),\
895 },
896
897static void pc_i440fx_0_13_machine_options(MachineClass *m)
898{
899 PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
900 pc_i440fx_0_14_machine_options(m);
901 m->hw_version = "0.13";
902 SET_MACHINE_COMPAT(m, PC_COMPAT_0_13);
903 pcmc->kvmclock_enabled = false;
904}
905
906DEFINE_I440FX_MACHINE(v0_13, "pc-0.13", pc_compat_0_13,
907 pc_i440fx_0_13_machine_options);
908
909
910#define PC_COMPAT_0_12 \
911 PC_CPU_MODEL_IDS("0.12") \
912 {\
913 .driver = "virtio-serial-pci",\
914 .property = "max_ports",\
915 .value = stringify(1),\
916 },{\
917 .driver = "virtio-serial-pci",\
918 .property = "vectors",\
919 .value = stringify(0),\
920 },{\
921 .driver = "usb-mouse",\
922 .property = "serial",\
923 .value = "1",\
924 },{\
925 .driver = "usb-tablet",\
926 .property = "serial",\
927 .value = "1",\
928 },{\
929 .driver = "usb-kbd",\
930 .property = "serial",\
931 .value = "1",\
932 },
933
934static void pc_i440fx_0_12_machine_options(MachineClass *m)
935{
936 pc_i440fx_0_13_machine_options(m);
937 m->hw_version = "0.12";
938 SET_MACHINE_COMPAT(m, PC_COMPAT_0_12);
939}
940
941DEFINE_I440FX_MACHINE(v0_12, "pc-0.12", pc_compat_0_13,
942 pc_i440fx_0_12_machine_options);
943
944
945#define PC_COMPAT_0_11 \
946 PC_CPU_MODEL_IDS("0.11") \
947 {\
948 .driver = "virtio-blk-pci",\
949 .property = "vectors",\
950 .value = stringify(0),\
951 },{\
952 .driver = TYPE_PCI_DEVICE,\
953 .property = "rombar",\
954 .value = stringify(0),\
955 },{\
956 .driver = "ide-drive",\
957 .property = "ver",\
958 .value = "0.11",\
959 },{\
960 .driver = "scsi-disk",\
961 .property = "ver",\
962 .value = "0.11",\
963 },
964
965static void pc_i440fx_0_11_machine_options(MachineClass *m)
966{
967 pc_i440fx_0_12_machine_options(m);
968 m->hw_version = "0.11";
969 m->deprecation_reason = "use a newer machine type instead";
970 SET_MACHINE_COMPAT(m, PC_COMPAT_0_11);
971}
972
973DEFINE_I440FX_MACHINE(v0_11, "pc-0.11", pc_compat_0_13,
974 pc_i440fx_0_11_machine_options);
975
976
977#define PC_COMPAT_0_10 \
978 PC_CPU_MODEL_IDS("0.10") \
979 {\
980 .driver = "virtio-blk-pci",\
981 .property = "class",\
982 .value = stringify(PCI_CLASS_STORAGE_OTHER),\
983 },{\
984 .driver = "virtio-serial-pci",\
985 .property = "class",\
986 .value = stringify(PCI_CLASS_DISPLAY_OTHER),\
987 },{\
988 .driver = "virtio-net-pci",\
989 .property = "vectors",\
990 .value = stringify(0),\
991 },{\
992 .driver = "ide-drive",\
993 .property = "ver",\
994 .value = "0.10",\
995 },{\
996 .driver = "scsi-disk",\
997 .property = "ver",\
998 .value = "0.10",\
999 },
1000
1001static void pc_i440fx_0_10_machine_options(MachineClass *m)
1002{
1003 pc_i440fx_0_11_machine_options(m);
1004 m->hw_version = "0.10";
1005 SET_MACHINE_COMPAT(m, PC_COMPAT_0_10);
1006}
1007
1008DEFINE_I440FX_MACHINE(v0_10, "pc-0.10", pc_compat_0_13,
1009 pc_i440fx_0_10_machine_options);
1010
1011typedef struct {
1012 uint16_t gpu_device_id;
1013 uint16_t pch_device_id;
1014 uint8_t pch_revision_id;
1015} IGDDeviceIDInfo;
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032static const IGDDeviceIDInfo igd_combo_id_infos[] = {
1033
1034 {0x0402, 0x8c4e, 0x04},
1035 {0x0406, 0x8c4e, 0x04},
1036 {0x0412, 0x8c4e, 0x04},
1037 {0x0416, 0x8c4e, 0x04},
1038 {0x041E, 0x8c4e, 0x04},
1039
1040 {0x0A06, 0x8c4e, 0x04},
1041 {0x0A16, 0x8c4e, 0x04},
1042 {0x0A26, 0x8c4e, 0x06},
1043 {0x0A2E, 0x8c4e, 0x04},
1044 {0x0A1E, 0x8c4e, 0x04},
1045 {0x0A0E, 0x8c4e, 0x04},
1046
1047 {0x0D26, 0x8c4e, 0x04},
1048 {0x0D22, 0x8c4e, 0x04},
1049
1050 {0x041A, 0x8c4e, 0x04},
1051
1052 {0x040A, 0x8c4e, 0x04},
1053
1054 {0x1606, 0x9cc3, 0x03},
1055 {0x1616, 0x9cc3, 0x03},
1056 {0x1626, 0x9cc3, 0x03},
1057 {0x160E, 0x9cc3, 0x03},
1058 {0x161E, 0x9cc3, 0x03},
1059 {0x1602, 0x9cc3, 0x03},
1060 {0x1612, 0x9cc3, 0x03},
1061 {0x1622, 0x9cc3, 0x03},
1062 {0x162B, 0x9cc3, 0x03},
1063 {0x162A, 0x9cc3, 0x03},
1064 {0x162D, 0x9cc3, 0x03},
1065};
1066
1067static void isa_bridge_class_init(ObjectClass *klass, void *data)
1068{
1069 DeviceClass *dc = DEVICE_CLASS(klass);
1070 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
1071
1072 dc->desc = "ISA bridge faked to support IGD PT";
1073 k->vendor_id = PCI_VENDOR_ID_INTEL;
1074 k->class_id = PCI_CLASS_BRIDGE_ISA;
1075};
1076
1077static TypeInfo isa_bridge_info = {
1078 .name = "igd-passthrough-isa-bridge",
1079 .parent = TYPE_PCI_DEVICE,
1080 .instance_size = sizeof(PCIDevice),
1081 .class_init = isa_bridge_class_init,
1082 .interfaces = (InterfaceInfo[]) {
1083 { INTERFACE_CONVENTIONAL_PCI_DEVICE },
1084 { },
1085 },
1086};
1087
1088static void pt_graphics_register_types(void)
1089{
1090 type_register_static(&isa_bridge_info);
1091}
1092type_init(pt_graphics_register_types)
1093
1094void igd_passthrough_isa_bridge_create(PCIBus *bus, uint16_t gpu_dev_id)
1095{
1096 struct PCIDevice *bridge_dev;
1097 int i, num;
1098 uint16_t pch_dev_id = 0xffff;
1099 uint8_t pch_rev_id;
1100
1101 num = ARRAY_SIZE(igd_combo_id_infos);
1102 for (i = 0; i < num; i++) {
1103 if (gpu_dev_id == igd_combo_id_infos[i].gpu_device_id) {
1104 pch_dev_id = igd_combo_id_infos[i].pch_device_id;
1105 pch_rev_id = igd_combo_id_infos[i].pch_revision_id;
1106 }
1107 }
1108
1109 if (pch_dev_id == 0xffff) {
1110 return;
1111 }
1112
1113
1114 bridge_dev = pci_create_simple(bus, PCI_DEVFN(0x1f, 0),
1115 "igd-passthrough-isa-bridge");
1116
1117
1118
1119
1120 if (!bridge_dev) {
1121 fprintf(stderr, "set igd-passthrough-isa-bridge failed!\n");
1122 return;
1123 }
1124 pci_config_set_device_id(bridge_dev->config, pch_dev_id);
1125 pci_config_set_revision(bridge_dev->config, pch_rev_id);
1126}
1127
1128static void isapc_machine_options(MachineClass *m)
1129{
1130 PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
1131 m->desc = "ISA-only PC";
1132 m->max_cpus = 1;
1133 m->option_rom_has_mr = true;
1134 m->rom_file_has_mr = false;
1135 pcmc->pci_enabled = false;
1136 pcmc->has_acpi_build = false;
1137 pcmc->smbios_defaults = false;
1138 pcmc->gigabyte_align = false;
1139 pcmc->smbios_legacy_mode = true;
1140 pcmc->has_reserved_memory = false;
1141 pcmc->default_nic_model = "ne2k_isa";
1142 m->default_cpu_type = X86_CPU_TYPE_NAME("486");
1143}
1144
1145DEFINE_PC_MACHINE(isapc, "isapc", pc_init_isa,
1146 isapc_machine_options);
1147
1148
1149#ifdef CONFIG_XEN
1150static void xenfv_machine_options(MachineClass *m)
1151{
1152 m->desc = "Xen Fully-virtualized PC";
1153 m->max_cpus = HVM_MAX_VCPUS;
1154 m->default_machine_opts = "accel=xen";
1155}
1156
1157DEFINE_PC_MACHINE(xenfv, "xenfv", pc_xen_hvm_init,
1158 xenfv_machine_options);
1159#endif
1160