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
28 #include "hw/i386/pc.h"
29 #include "hw/i386/apic.h"
30 #include "hw/pci/pci.h"
31 #include "hw/pci/pci_ids.h"
34 #include "hw/boards.h"
36 #include "sysemu/kvm.h"
37 #include "hw/kvm/clock.h"
38 #include "sysemu/sysemu.h"
39 #include "hw/sysbus.h"
40 #include "hw/cpu/icc_bus.h"
41 #include "sysemu/arch_init.h"
42 #include "sysemu/blockdev.h"
43 #include "hw/i2c/smbus.h"
44 #include "hw/xen/xen.h"
45 #include "exec/memory.h"
46 #include "exec/address-spaces.h"
47 #include "hw/acpi/acpi.h"
50 # include <xen/hvm/hvm_info_table.h>
55 static const int ide_iobase
[MAX_IDE_BUS
] = { 0x1f0, 0x170 };
56 static const int ide_iobase2
[MAX_IDE_BUS
] = { 0x3f6, 0x376 };
57 static const int ide_irq
[MAX_IDE_BUS
] = { 14, 15 };
59 static bool has_pvpanic
= true;
61 /* PC hardware initialisation */
62 static void pc_init1(MemoryRegion
*system_memory
,
63 MemoryRegion
*system_io
,
65 const char *boot_device
,
66 const char *kernel_filename
,
67 const char *kernel_cmdline
,
68 const char *initrd_filename
,
69 const char *cpu_model
,
74 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
77 PCII440FXState
*i440fx_state
;
84 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
85 BusState
*idebus
[MAX_IDE_BUS
];
88 MemoryRegion
*ram_memory
;
89 MemoryRegion
*pci_memory
;
90 MemoryRegion
*rom_memory
;
91 DeviceState
*icc_bridge
;
94 icc_bridge
= qdev_create(NULL
, TYPE_ICC_BRIDGE
);
95 object_property_add_child(qdev_get_machine(), "icc-bridge",
96 OBJECT(icc_bridge
), NULL
);
98 pc_cpus_init(cpu_model
, icc_bridge
);
99 pc_acpi_init("acpi-dsdt.aml");
101 if (kvmclock_enabled
) {
105 if (ram_size
>= 0xe0000000 ) {
106 above_4g_mem_size
= ram_size
- 0xe0000000;
107 below_4g_mem_size
= 0xe0000000;
109 above_4g_mem_size
= 0;
110 below_4g_mem_size
= ram_size
;
114 pci_memory
= g_new(MemoryRegion
, 1);
115 memory_region_init(pci_memory
, "pci", INT64_MAX
);
116 rom_memory
= pci_memory
;
119 rom_memory
= system_memory
;
122 /* allocate ram and load rom/bios */
123 if (!xen_enabled()) {
124 fw_cfg
= pc_memory_init(system_memory
,
125 kernel_filename
, kernel_cmdline
, initrd_filename
,
126 below_4g_mem_size
, above_4g_mem_size
,
127 rom_memory
, &ram_memory
);
130 gsi_state
= g_malloc0(sizeof(*gsi_state
));
131 if (kvm_irqchip_in_kernel()) {
132 kvm_pc_setup_irq_routing(pci_enabled
);
133 gsi
= qemu_allocate_irqs(kvm_pc_gsi_handler
, gsi_state
,
136 gsi
= qemu_allocate_irqs(gsi_handler
, gsi_state
, GSI_NUM_PINS
);
140 pci_bus
= i440fx_init(&i440fx_state
, &piix3_devfn
, &isa_bus
, gsi
,
141 system_memory
, system_io
, ram_size
,
143 0x100000000ULL
- below_4g_mem_size
,
144 0x100000000ULL
+ above_4g_mem_size
,
147 : ((uint64_t)1 << 62)),
148 pci_memory
, ram_memory
);
152 isa_bus
= isa_bus_new(NULL
, system_io
);
155 isa_bus_irqs(isa_bus
, gsi
);
157 if (kvm_irqchip_in_kernel()) {
158 i8259
= kvm_i8259_init(isa_bus
);
159 } else if (xen_enabled()) {
160 i8259
= xen_interrupt_controller_init();
162 cpu_irq
= pc_allocate_cpu_irq();
163 i8259
= i8259_init(isa_bus
, cpu_irq
[0]);
166 for (i
= 0; i
< ISA_NUM_IRQS
; i
++) {
167 gsi_state
->i8259_irq
[i
] = i8259
[i
];
170 ioapic_init_gsi(gsi_state
, "i440fx");
172 qdev_init_nofail(icc_bridge
);
174 pc_register_ferr_irq(gsi
[13]);
176 pc_vga_init(isa_bus
, pci_enabled
? pci_bus
: NULL
);
178 pci_create_simple(pci_bus
, -1, "xen-platform");
181 /* init basic PC hardware */
182 pc_basic_device_init(isa_bus
, gsi
, &rtc_state
, &floppy
, xen_enabled());
184 pc_nic_init(isa_bus
, pci_bus
);
186 ide_drive_get(hd
, MAX_IDE_BUS
);
190 dev
= pci_piix3_xen_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
192 dev
= pci_piix3_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
194 idebus
[0] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
195 idebus
[1] = qdev_get_child_bus(&dev
->qdev
, "ide.1");
197 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
199 dev
= isa_ide_init(isa_bus
, ide_iobase
[i
], ide_iobase2
[i
],
201 hd
[MAX_IDE_DEVS
* i
], hd
[MAX_IDE_DEVS
* i
+ 1]);
202 idebus
[i
] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
206 pc_cmos_init(below_4g_mem_size
, above_4g_mem_size
, boot_device
,
207 floppy
, idebus
[0], idebus
[1], rtc_state
);
209 if (pci_enabled
&& usb_enabled(false)) {
210 pci_create_simple(pci_bus
, piix3_devfn
+ 2, "piix3-usb-uhci");
213 if (pci_enabled
&& acpi_enabled
) {
216 smi_irq
= qemu_allocate_irqs(pc_acpi_smi_interrupt
,
217 x86_env_get_cpu(first_cpu
), 1);
218 /* TODO: Populate SPD eeprom data. */
219 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
221 kvm_enabled(), fw_cfg
);
222 smbus_eeprom_init(smbus
, 8, NULL
, 0);
226 pc_pci_device_init(pci_bus
);
230 pvpanic_init(isa_bus
);
234 static void pc_init_pci(QEMUMachineInitArgs
*args
)
236 ram_addr_t ram_size
= args
->ram_size
;
237 const char *cpu_model
= args
->cpu_model
;
238 const char *kernel_filename
= args
->kernel_filename
;
239 const char *kernel_cmdline
= args
->kernel_cmdline
;
240 const char *initrd_filename
= args
->initrd_filename
;
241 const char *boot_device
= args
->boot_device
;
242 pc_init1(get_system_memory(),
244 ram_size
, boot_device
,
245 kernel_filename
, kernel_cmdline
,
246 initrd_filename
, cpu_model
, 1, 1);
249 static void pc_init_pci_1_4(QEMUMachineInitArgs
*args
)
251 pc_sysfw_flash_vs_rom_bug_compatible
= true;
253 x86_cpu_compat_set_features("n270", FEAT_1_ECX
, 0, CPUID_EXT_MOVBE
);
257 static void pc_init_pci_1_3(QEMUMachineInitArgs
*args
)
259 enable_compat_apic_id_mode();
260 pc_sysfw_flash_vs_rom_bug_compatible
= true;
265 /* PC machine init function for pc-1.1 to pc-1.2 */
266 static void pc_init_pci_1_2(QEMUMachineInitArgs
*args
)
268 disable_kvm_pv_eoi();
269 enable_compat_apic_id_mode();
270 pc_sysfw_flash_vs_rom_bug_compatible
= true;
275 /* PC machine init function for pc-0.14 to pc-1.0 */
276 static void pc_init_pci_1_0(QEMUMachineInitArgs
*args
)
278 disable_kvm_pv_eoi();
279 enable_compat_apic_id_mode();
284 /* PC init function for pc-0.10 to pc-0.13, and reused by xenfv */
285 static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs
*args
)
287 ram_addr_t ram_size
= args
->ram_size
;
288 const char *cpu_model
= args
->cpu_model
;
289 const char *kernel_filename
= args
->kernel_filename
;
290 const char *kernel_cmdline
= args
->kernel_cmdline
;
291 const char *initrd_filename
= args
->initrd_filename
;
292 const char *boot_device
= args
->boot_device
;
294 disable_kvm_pv_eoi();
295 enable_compat_apic_id_mode();
296 pc_init1(get_system_memory(),
298 ram_size
, boot_device
,
299 kernel_filename
, kernel_cmdline
,
300 initrd_filename
, cpu_model
, 1, 0);
303 static void pc_init_isa(QEMUMachineInitArgs
*args
)
305 ram_addr_t ram_size
= args
->ram_size
;
306 const char *cpu_model
= args
->cpu_model
;
307 const char *kernel_filename
= args
->kernel_filename
;
308 const char *kernel_cmdline
= args
->kernel_cmdline
;
309 const char *initrd_filename
= args
->initrd_filename
;
310 const char *boot_device
= args
->boot_device
;
312 if (cpu_model
== NULL
)
314 disable_kvm_pv_eoi();
315 enable_compat_apic_id_mode();
316 pc_init1(get_system_memory(),
318 ram_size
, boot_device
,
319 kernel_filename
, kernel_cmdline
,
320 initrd_filename
, cpu_model
, 0, 1);
324 static void pc_xen_hvm_init(QEMUMachineInitArgs
*args
)
326 if (xen_hvm_init() != 0) {
327 hw_error("xen hardware virtual machine initialisation failed");
329 pc_init_pci_no_kvmclock(args
);
334 static QEMUMachine pc_i440fx_machine_v1_5
= {
335 .name
= "pc-i440fx-1.5",
337 .desc
= "Standard PC (i440FX + PIIX, 1996)",
339 .hot_add_cpu
= pc_hot_add_cpu
,
342 DEFAULT_MACHINE_OPTIONS
,
345 static QEMUMachine pc_i440fx_machine_v1_4
= {
346 .name
= "pc-i440fx-1.4",
347 .desc
= "Standard PC (i440FX + PIIX, 1996)",
348 .init
= pc_init_pci_1_4
,
350 .compat_props
= (GlobalProperty
[]) {
352 { /* end of list */ }
354 DEFAULT_MACHINE_OPTIONS
,
357 #define PC_COMPAT_1_3 \
360 .driver = "usb-tablet",\
361 .property = "usb_version",\
362 .value = stringify(1),\
364 .driver = "virtio-net-pci",\
365 .property = "ctrl_mac_addr",\
368 .driver = "virtio-net-pci", \
373 .property = "autonegotiation",\
377 static QEMUMachine pc_machine_v1_3
= {
379 .desc
= "Standard PC",
380 .init
= pc_init_pci_1_3
,
382 .compat_props
= (GlobalProperty
[]) {
384 { /* end of list */ }
386 DEFAULT_MACHINE_OPTIONS
,
389 #define PC_COMPAT_1_2 \
392 .driver = "nec-usb-xhci",\
396 .driver = "nec-usb-xhci",\
400 .driver = "ivshmem",\
401 .property = "use64",\
405 .property = "revision",\
406 .value = stringify(3),\
408 .driver = "qxl-vga",\
409 .property = "revision",\
410 .value = stringify(3),\
417 static QEMUMachine pc_machine_v1_2
= {
419 .desc
= "Standard PC",
420 .init
= pc_init_pci_1_2
,
422 .compat_props
= (GlobalProperty
[]) {
424 { /* end of list */ }
426 DEFAULT_MACHINE_OPTIONS
,
429 #define PC_COMPAT_1_1 \
432 .driver = "virtio-scsi-pci",\
433 .property = "hotplug",\
436 .driver = "virtio-scsi-pci",\
437 .property = "param_change",\
441 .property = "vgamem_mb",\
442 .value = stringify(8),\
444 .driver = "vmware-svga",\
445 .property = "vgamem_mb",\
446 .value = stringify(8),\
448 .driver = "qxl-vga",\
449 .property = "vgamem_mb",\
450 .value = stringify(8),\
453 .property = "vgamem_mb",\
454 .value = stringify(8),\
456 .driver = "virtio-blk-pci",\
457 .property = "config-wce",\
461 static QEMUMachine pc_machine_v1_1
= {
463 .desc
= "Standard PC",
464 .init
= pc_init_pci_1_2
,
466 .compat_props
= (GlobalProperty
[]) {
468 { /* end of list */ }
470 DEFAULT_MACHINE_OPTIONS
,
473 #define PC_COMPAT_1_0 \
476 .driver = "pc-sysfw",\
477 .property = "rom_only",\
478 .value = stringify(1),\
480 .driver = TYPE_ISA_FDC,\
481 .property = "check_media_rate",\
484 .driver = "virtio-balloon-pci",\
485 .property = "class",\
486 .value = stringify(PCI_CLASS_MEMORY_RAM),\
489 .property = "vapic",\
492 .driver = TYPE_USB_DEVICE,\
493 .property = "full-path",\
497 static QEMUMachine pc_machine_v1_0
= {
499 .desc
= "Standard PC",
500 .init
= pc_init_pci_1_0
,
502 .compat_props
= (GlobalProperty
[]) {
504 { /* end of list */ }
507 DEFAULT_MACHINE_OPTIONS
,
510 #define PC_COMPAT_0_15 \
513 static QEMUMachine pc_machine_v0_15
= {
515 .desc
= "Standard PC",
516 .init
= pc_init_pci_1_0
,
518 .compat_props
= (GlobalProperty
[]) {
520 { /* end of list */ }
522 .hw_version
= "0.15",
523 DEFAULT_MACHINE_OPTIONS
,
526 #define PC_COMPAT_0_14 \
529 .driver = "virtio-blk-pci",\
530 .property = "event_idx",\
533 .driver = "virtio-serial-pci",\
534 .property = "event_idx",\
537 .driver = "virtio-net-pci",\
538 .property = "event_idx",\
541 .driver = "virtio-balloon-pci",\
542 .property = "event_idx",\
546 static QEMUMachine pc_machine_v0_14
= {
548 .desc
= "Standard PC",
549 .init
= pc_init_pci_1_0
,
551 .compat_props
= (GlobalProperty
[]) {
555 .property
= "revision",
556 .value
= stringify(2),
559 .property
= "revision",
560 .value
= stringify(2),
562 { /* end of list */ }
564 .hw_version
= "0.14",
565 DEFAULT_MACHINE_OPTIONS
,
568 #define PC_COMPAT_0_13 \
571 .driver = TYPE_PCI_DEVICE,\
572 .property = "command_serr_enable",\
576 .property = "use_broken_id",\
577 .value = stringify(1),\
580 static QEMUMachine pc_machine_v0_13
= {
582 .desc
= "Standard PC",
583 .init
= pc_init_pci_no_kvmclock
,
585 .compat_props
= (GlobalProperty
[]) {
588 .driver
= "virtio-9p-pci",
589 .property
= "vectors",
590 .value
= stringify(0),
593 .property
= "rombar",
594 .value
= stringify(0),
596 .driver
= "vmware-svga",
597 .property
= "rombar",
598 .value
= stringify(0),
600 { /* end of list */ }
602 .hw_version
= "0.13",
603 DEFAULT_MACHINE_OPTIONS
,
606 #define PC_COMPAT_0_12 \
609 .driver = "virtio-serial-pci",\
610 .property = "max_ports",\
611 .value = stringify(1),\
613 .driver = "virtio-serial-pci",\
614 .property = "vectors",\
615 .value = stringify(0),\
618 static QEMUMachine pc_machine_v0_12
= {
620 .desc
= "Standard PC",
621 .init
= pc_init_pci_no_kvmclock
,
623 .compat_props
= (GlobalProperty
[]) {
627 .property
= "rombar",
628 .value
= stringify(0),
630 .driver
= "vmware-svga",
631 .property
= "rombar",
632 .value
= stringify(0),
634 { /* end of list */ }
636 .hw_version
= "0.12",
637 DEFAULT_MACHINE_OPTIONS
,
640 #define PC_COMPAT_0_11 \
643 .driver = "virtio-blk-pci",\
644 .property = "vectors",\
645 .value = stringify(0),\
647 .driver = TYPE_PCI_DEVICE,\
648 .property = "rombar",\
649 .value = stringify(0),\
652 static QEMUMachine pc_machine_v0_11
= {
654 .desc
= "Standard PC, qemu 0.11",
655 .init
= pc_init_pci_no_kvmclock
,
657 .compat_props
= (GlobalProperty
[]) {
660 .driver
= "ide-drive",
664 .driver
= "scsi-disk",
668 { /* end of list */ }
670 .hw_version
= "0.11",
671 DEFAULT_MACHINE_OPTIONS
,
674 static QEMUMachine pc_machine_v0_10
= {
676 .desc
= "Standard PC, qemu 0.10",
677 .init
= pc_init_pci_no_kvmclock
,
679 .compat_props
= (GlobalProperty
[]) {
682 .driver
= "virtio-blk-pci",
684 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
686 .driver
= "virtio-serial-pci",
688 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
690 .driver
= "virtio-net-pci",
691 .property
= "vectors",
692 .value
= stringify(0),
694 .driver
= "ide-drive",
698 .driver
= "scsi-disk",
702 { /* end of list */ }
704 .hw_version
= "0.10",
705 DEFAULT_MACHINE_OPTIONS
,
708 static QEMUMachine isapc_machine
= {
710 .desc
= "ISA-only PC",
713 .compat_props
= (GlobalProperty
[]) {
715 .driver
= "pc-sysfw",
716 .property
= "rom_only",
717 .value
= stringify(1),
719 { /* end of list */ }
721 DEFAULT_MACHINE_OPTIONS
,
725 static QEMUMachine xenfv_machine
= {
727 .desc
= "Xen Fully-virtualized PC",
728 .init
= pc_xen_hvm_init
,
729 .max_cpus
= HVM_MAX_VCPUS
,
730 .default_machine_opts
= "accel=xen",
731 DEFAULT_MACHINE_OPTIONS
,
735 static void pc_machine_init(void)
737 qemu_register_machine(&pc_i440fx_machine_v1_5
);
738 qemu_register_machine(&pc_i440fx_machine_v1_4
);
739 qemu_register_machine(&pc_machine_v1_3
);
740 qemu_register_machine(&pc_machine_v1_2
);
741 qemu_register_machine(&pc_machine_v1_1
);
742 qemu_register_machine(&pc_machine_v1_0
);
743 qemu_register_machine(&pc_machine_v0_15
);
744 qemu_register_machine(&pc_machine_v0_14
);
745 qemu_register_machine(&pc_machine_v0_13
);
746 qemu_register_machine(&pc_machine_v0_12
);
747 qemu_register_machine(&pc_machine_v0_11
);
748 qemu_register_machine(&pc_machine_v0_10
);
749 qemu_register_machine(&isapc_machine
);
751 qemu_register_machine(&xenfv_machine
);
755 machine_init(pc_machine_init
);