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 "sysemu/arch_init.h"
41 #include "sysemu/blockdev.h"
42 #include "hw/i2c/smbus.h"
43 #include "hw/xen/xen.h"
44 #include "exec/memory.h"
45 #include "exec/address-spaces.h"
46 #include "hw/acpi/acpi.h"
49 # include <xen/hvm/hvm_info_table.h>
54 static const int ide_iobase
[MAX_IDE_BUS
] = { 0x1f0, 0x170 };
55 static const int ide_iobase2
[MAX_IDE_BUS
] = { 0x3f6, 0x376 };
56 static const int ide_irq
[MAX_IDE_BUS
] = { 14, 15 };
58 /* PC hardware initialisation */
59 static void pc_init1(MemoryRegion
*system_memory
,
60 MemoryRegion
*system_io
,
62 const char *boot_device
,
63 const char *kernel_filename
,
64 const char *kernel_cmdline
,
65 const char *initrd_filename
,
66 const char *cpu_model
,
71 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
74 PCII440FXState
*i440fx_state
;
81 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
82 BusState
*idebus
[MAX_IDE_BUS
];
85 MemoryRegion
*ram_memory
;
86 MemoryRegion
*pci_memory
;
87 MemoryRegion
*rom_memory
;
90 pc_cpus_init(cpu_model
);
92 if (kvmclock_enabled
) {
96 if (ram_size
>= 0xe0000000 ) {
97 above_4g_mem_size
= ram_size
- 0xe0000000;
98 below_4g_mem_size
= 0xe0000000;
100 above_4g_mem_size
= 0;
101 below_4g_mem_size
= ram_size
;
105 pci_memory
= g_new(MemoryRegion
, 1);
106 memory_region_init(pci_memory
, "pci", INT64_MAX
);
107 rom_memory
= pci_memory
;
110 rom_memory
= system_memory
;
113 /* allocate ram and load rom/bios */
114 if (!xen_enabled()) {
115 fw_cfg
= pc_memory_init(system_memory
,
116 kernel_filename
, kernel_cmdline
, initrd_filename
,
117 below_4g_mem_size
, above_4g_mem_size
,
118 rom_memory
, &ram_memory
);
121 gsi_state
= g_malloc0(sizeof(*gsi_state
));
122 if (kvm_irqchip_in_kernel()) {
123 kvm_pc_setup_irq_routing(pci_enabled
);
124 gsi
= qemu_allocate_irqs(kvm_pc_gsi_handler
, gsi_state
,
127 gsi
= qemu_allocate_irqs(gsi_handler
, gsi_state
, GSI_NUM_PINS
);
131 pci_bus
= i440fx_init(&i440fx_state
, &piix3_devfn
, &isa_bus
, gsi
,
132 system_memory
, system_io
, ram_size
,
134 0x100000000ULL
- below_4g_mem_size
,
135 0x100000000ULL
+ above_4g_mem_size
,
138 : ((uint64_t)1 << 62)),
139 pci_memory
, ram_memory
);
143 isa_bus
= isa_bus_new(NULL
, system_io
);
146 isa_bus_irqs(isa_bus
, gsi
);
148 if (kvm_irqchip_in_kernel()) {
149 i8259
= kvm_i8259_init(isa_bus
);
150 } else if (xen_enabled()) {
151 i8259
= xen_interrupt_controller_init();
153 cpu_irq
= pc_allocate_cpu_irq();
154 i8259
= i8259_init(isa_bus
, cpu_irq
[0]);
157 for (i
= 0; i
< ISA_NUM_IRQS
; i
++) {
158 gsi_state
->i8259_irq
[i
] = i8259
[i
];
161 ioapic_init_gsi(gsi_state
, "i440fx");
164 pc_register_ferr_irq(gsi
[13]);
166 pc_vga_init(isa_bus
, pci_enabled
? pci_bus
: NULL
);
168 pci_create_simple(pci_bus
, -1, "xen-platform");
171 /* init basic PC hardware */
172 pc_basic_device_init(isa_bus
, gsi
, &rtc_state
, &floppy
, xen_enabled());
174 pc_nic_init(isa_bus
, pci_bus
);
176 ide_drive_get(hd
, MAX_IDE_BUS
);
180 dev
= pci_piix3_xen_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
182 dev
= pci_piix3_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
184 idebus
[0] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
185 idebus
[1] = qdev_get_child_bus(&dev
->qdev
, "ide.1");
187 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
189 dev
= isa_ide_init(isa_bus
, ide_iobase
[i
], ide_iobase2
[i
],
191 hd
[MAX_IDE_DEVS
* i
], hd
[MAX_IDE_DEVS
* i
+ 1]);
192 idebus
[i
] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
198 pc_cmos_init(below_4g_mem_size
, above_4g_mem_size
, boot_device
,
199 floppy
, idebus
[0], idebus
[1], rtc_state
);
201 if (pci_enabled
&& usb_enabled(false)) {
202 pci_create_simple(pci_bus
, piix3_devfn
+ 2, "piix3-usb-uhci");
205 if (pci_enabled
&& acpi_enabled
) {
208 smi_irq
= qemu_allocate_irqs(pc_acpi_smi_interrupt
,
209 x86_env_get_cpu(first_cpu
), 1);
210 /* TODO: Populate SPD eeprom data. */
211 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
213 kvm_enabled(), fw_cfg
);
214 smbus_eeprom_init(smbus
, 8, NULL
, 0);
218 pc_pci_device_init(pci_bus
);
222 static void pc_init_pci(QEMUMachineInitArgs
*args
)
224 ram_addr_t ram_size
= args
->ram_size
;
225 const char *cpu_model
= args
->cpu_model
;
226 const char *kernel_filename
= args
->kernel_filename
;
227 const char *kernel_cmdline
= args
->kernel_cmdline
;
228 const char *initrd_filename
= args
->initrd_filename
;
229 const char *boot_device
= args
->boot_device
;
230 pc_init1(get_system_memory(),
232 ram_size
, boot_device
,
233 kernel_filename
, kernel_cmdline
,
234 initrd_filename
, cpu_model
, 1, 1);
237 static void pc_init_pci_1_4(QEMUMachineInitArgs
*args
)
239 pc_sysfw_flash_vs_rom_bug_compatible
= true;
243 static void pc_init_pci_1_3(QEMUMachineInitArgs
*args
)
245 enable_compat_apic_id_mode();
246 pc_sysfw_flash_vs_rom_bug_compatible
= true;
250 /* PC machine init function for pc-1.1 to pc-1.2 */
251 static void pc_init_pci_1_2(QEMUMachineInitArgs
*args
)
253 disable_kvm_pv_eoi();
254 enable_compat_apic_id_mode();
255 pc_sysfw_flash_vs_rom_bug_compatible
= true;
259 /* PC machine init function for pc-0.14 to pc-1.0 */
260 static void pc_init_pci_1_0(QEMUMachineInitArgs
*args
)
262 disable_kvm_pv_eoi();
263 enable_compat_apic_id_mode();
267 /* PC init function for pc-0.10 to pc-0.13, and reused by xenfv */
268 static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs
*args
)
270 ram_addr_t ram_size
= args
->ram_size
;
271 const char *cpu_model
= args
->cpu_model
;
272 const char *kernel_filename
= args
->kernel_filename
;
273 const char *kernel_cmdline
= args
->kernel_cmdline
;
274 const char *initrd_filename
= args
->initrd_filename
;
275 const char *boot_device
= args
->boot_device
;
276 disable_kvm_pv_eoi();
277 enable_compat_apic_id_mode();
278 pc_init1(get_system_memory(),
280 ram_size
, boot_device
,
281 kernel_filename
, kernel_cmdline
,
282 initrd_filename
, cpu_model
, 1, 0);
285 static void pc_init_isa(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
;
293 if (cpu_model
== NULL
)
295 disable_kvm_pv_eoi();
296 enable_compat_apic_id_mode();
297 pc_init1(get_system_memory(),
299 ram_size
, boot_device
,
300 kernel_filename
, kernel_cmdline
,
301 initrd_filename
, cpu_model
, 0, 1);
305 static void pc_xen_hvm_init(QEMUMachineInitArgs
*args
)
307 if (xen_hvm_init() != 0) {
308 hw_error("xen hardware virtual machine initialisation failed");
310 pc_init_pci_no_kvmclock(args
);
315 static QEMUMachine pc_i440fx_machine_v1_5
= {
316 .name
= "pc-i440fx-1.5",
318 .desc
= "Standard PC (i440FX + PIIX, 1996)",
322 DEFAULT_MACHINE_OPTIONS
,
325 static QEMUMachine pc_i440fx_machine_v1_4
= {
326 .name
= "pc-i440fx-1.4",
327 .desc
= "Standard PC (i440FX + PIIX, 1996)",
328 .init
= pc_init_pci_1_4
,
330 .compat_props
= (GlobalProperty
[]) {
332 { /* end of list */ }
334 DEFAULT_MACHINE_OPTIONS
,
337 #define PC_COMPAT_1_3 \
340 .driver = "usb-tablet",\
341 .property = "usb_version",\
342 .value = stringify(1),\
344 .driver = "virtio-net-pci",\
345 .property = "ctrl_mac_addr",\
348 .driver = "virtio-net-pci", \
353 .property = "autonegotiation",\
357 static QEMUMachine pc_machine_v1_3
= {
359 .desc
= "Standard PC",
360 .init
= pc_init_pci_1_3
,
362 .compat_props
= (GlobalProperty
[]) {
364 { /* end of list */ }
366 DEFAULT_MACHINE_OPTIONS
,
369 #define PC_COMPAT_1_2 \
372 .driver = "nec-usb-xhci",\
376 .driver = "nec-usb-xhci",\
380 .driver = "ivshmem",\
381 .property = "use64",\
385 .property = "revision",\
386 .value = stringify(3),\
388 .driver = "qxl-vga",\
389 .property = "revision",\
390 .value = stringify(3),\
397 static QEMUMachine pc_machine_v1_2
= {
399 .desc
= "Standard PC",
400 .init
= pc_init_pci_1_2
,
402 .compat_props
= (GlobalProperty
[]) {
404 { /* end of list */ }
406 DEFAULT_MACHINE_OPTIONS
,
409 #define PC_COMPAT_1_1 \
412 .driver = "virtio-scsi-pci",\
413 .property = "hotplug",\
416 .driver = "virtio-scsi-pci",\
417 .property = "param_change",\
421 .property = "vgamem_mb",\
422 .value = stringify(8),\
424 .driver = "vmware-svga",\
425 .property = "vgamem_mb",\
426 .value = stringify(8),\
428 .driver = "qxl-vga",\
429 .property = "vgamem_mb",\
430 .value = stringify(8),\
433 .property = "vgamem_mb",\
434 .value = stringify(8),\
436 .driver = "virtio-blk-pci",\
437 .property = "config-wce",\
441 static QEMUMachine pc_machine_v1_1
= {
443 .desc
= "Standard PC",
444 .init
= pc_init_pci_1_2
,
446 .compat_props
= (GlobalProperty
[]) {
448 { /* end of list */ }
450 DEFAULT_MACHINE_OPTIONS
,
453 #define PC_COMPAT_1_0 \
456 .driver = "pc-sysfw",\
457 .property = "rom_only",\
458 .value = stringify(1),\
460 .driver = TYPE_ISA_FDC,\
461 .property = "check_media_rate",\
464 .driver = "virtio-balloon-pci",\
465 .property = "class",\
466 .value = stringify(PCI_CLASS_MEMORY_RAM),\
469 .property = "vapic",\
472 .driver = TYPE_USB_DEVICE,\
473 .property = "full-path",\
477 static QEMUMachine pc_machine_v1_0
= {
479 .desc
= "Standard PC",
480 .init
= pc_init_pci_1_0
,
482 .compat_props
= (GlobalProperty
[]) {
484 { /* end of list */ }
487 DEFAULT_MACHINE_OPTIONS
,
490 #define PC_COMPAT_0_15 \
493 static QEMUMachine pc_machine_v0_15
= {
495 .desc
= "Standard PC",
496 .init
= pc_init_pci_1_0
,
498 .compat_props
= (GlobalProperty
[]) {
500 { /* end of list */ }
502 .hw_version
= "0.15",
503 DEFAULT_MACHINE_OPTIONS
,
506 #define PC_COMPAT_0_14 \
509 .driver = "virtio-blk-pci",\
510 .property = "event_idx",\
513 .driver = "virtio-serial-pci",\
514 .property = "event_idx",\
517 .driver = "virtio-net-pci",\
518 .property = "event_idx",\
521 .driver = "virtio-balloon-pci",\
522 .property = "event_idx",\
526 static QEMUMachine pc_machine_v0_14
= {
528 .desc
= "Standard PC",
529 .init
= pc_init_pci_1_0
,
531 .compat_props
= (GlobalProperty
[]) {
535 .property
= "revision",
536 .value
= stringify(2),
539 .property
= "revision",
540 .value
= stringify(2),
542 { /* end of list */ }
544 .hw_version
= "0.14",
545 DEFAULT_MACHINE_OPTIONS
,
548 #define PC_COMPAT_0_13 \
551 .driver = TYPE_PCI_DEVICE,\
552 .property = "command_serr_enable",\
556 .property = "use_broken_id",\
557 .value = stringify(1),\
560 static QEMUMachine pc_machine_v0_13
= {
562 .desc
= "Standard PC",
563 .init
= pc_init_pci_no_kvmclock
,
565 .compat_props
= (GlobalProperty
[]) {
568 .driver
= "virtio-9p-pci",
569 .property
= "vectors",
570 .value
= stringify(0),
573 .property
= "rombar",
574 .value
= stringify(0),
576 .driver
= "vmware-svga",
577 .property
= "rombar",
578 .value
= stringify(0),
580 { /* end of list */ }
582 .hw_version
= "0.13",
583 DEFAULT_MACHINE_OPTIONS
,
586 #define PC_COMPAT_0_12 \
589 .driver = "virtio-serial-pci",\
590 .property = "max_ports",\
591 .value = stringify(1),\
593 .driver = "virtio-serial-pci",\
594 .property = "vectors",\
595 .value = stringify(0),\
598 static QEMUMachine pc_machine_v0_12
= {
600 .desc
= "Standard PC",
601 .init
= pc_init_pci_no_kvmclock
,
603 .compat_props
= (GlobalProperty
[]) {
607 .property
= "rombar",
608 .value
= stringify(0),
610 .driver
= "vmware-svga",
611 .property
= "rombar",
612 .value
= stringify(0),
614 { /* end of list */ }
616 .hw_version
= "0.12",
617 DEFAULT_MACHINE_OPTIONS
,
620 #define PC_COMPAT_0_11 \
623 .driver = "virtio-blk-pci",\
624 .property = "vectors",\
625 .value = stringify(0),\
627 .driver = TYPE_PCI_DEVICE,\
628 .property = "rombar",\
629 .value = stringify(0),\
632 static QEMUMachine pc_machine_v0_11
= {
634 .desc
= "Standard PC, qemu 0.11",
635 .init
= pc_init_pci_no_kvmclock
,
637 .compat_props
= (GlobalProperty
[]) {
640 .driver
= "ide-drive",
644 .driver
= "scsi-disk",
648 { /* end of list */ }
650 .hw_version
= "0.11",
651 DEFAULT_MACHINE_OPTIONS
,
654 static QEMUMachine pc_machine_v0_10
= {
656 .desc
= "Standard PC, qemu 0.10",
657 .init
= pc_init_pci_no_kvmclock
,
659 .compat_props
= (GlobalProperty
[]) {
662 .driver
= "virtio-blk-pci",
664 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
666 .driver
= "virtio-serial-pci",
668 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
670 .driver
= "virtio-net-pci",
671 .property
= "vectors",
672 .value
= stringify(0),
674 .driver
= "ide-drive",
678 .driver
= "scsi-disk",
682 { /* end of list */ }
684 .hw_version
= "0.10",
685 DEFAULT_MACHINE_OPTIONS
,
688 static QEMUMachine isapc_machine
= {
690 .desc
= "ISA-only PC",
693 .compat_props
= (GlobalProperty
[]) {
695 .driver
= "pc-sysfw",
696 .property
= "rom_only",
697 .value
= stringify(1),
699 { /* end of list */ }
701 DEFAULT_MACHINE_OPTIONS
,
705 static QEMUMachine xenfv_machine
= {
707 .desc
= "Xen Fully-virtualized PC",
708 .init
= pc_xen_hvm_init
,
709 .max_cpus
= HVM_MAX_VCPUS
,
710 .default_machine_opts
= "accel=xen",
711 DEFAULT_MACHINE_OPTIONS
,
715 static void pc_machine_init(void)
717 qemu_register_machine(&pc_i440fx_machine_v1_5
);
718 qemu_register_machine(&pc_i440fx_machine_v1_4
);
719 qemu_register_machine(&pc_machine_v1_3
);
720 qemu_register_machine(&pc_machine_v1_2
);
721 qemu_register_machine(&pc_machine_v1_1
);
722 qemu_register_machine(&pc_machine_v1_0
);
723 qemu_register_machine(&pc_machine_v0_15
);
724 qemu_register_machine(&pc_machine_v0_14
);
725 qemu_register_machine(&pc_machine_v0_13
);
726 qemu_register_machine(&pc_machine_v0_12
);
727 qemu_register_machine(&pc_machine_v0_11
);
728 qemu_register_machine(&pc_machine_v0_10
);
729 qemu_register_machine(&isapc_machine
);
731 qemu_register_machine(&xenfv_machine
);
735 machine_init(pc_machine_init
);