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
);
91 pc_acpi_init("acpi-dsdt.aml");
93 if (kvmclock_enabled
) {
97 if (ram_size
>= 0xe0000000 ) {
98 above_4g_mem_size
= ram_size
- 0xe0000000;
99 below_4g_mem_size
= 0xe0000000;
101 above_4g_mem_size
= 0;
102 below_4g_mem_size
= ram_size
;
106 pci_memory
= g_new(MemoryRegion
, 1);
107 memory_region_init(pci_memory
, "pci", INT64_MAX
);
108 rom_memory
= pci_memory
;
111 rom_memory
= system_memory
;
114 /* allocate ram and load rom/bios */
115 if (!xen_enabled()) {
116 fw_cfg
= pc_memory_init(system_memory
,
117 kernel_filename
, kernel_cmdline
, initrd_filename
,
118 below_4g_mem_size
, above_4g_mem_size
,
119 rom_memory
, &ram_memory
);
122 gsi_state
= g_malloc0(sizeof(*gsi_state
));
123 if (kvm_irqchip_in_kernel()) {
124 kvm_pc_setup_irq_routing(pci_enabled
);
125 gsi
= qemu_allocate_irqs(kvm_pc_gsi_handler
, gsi_state
,
128 gsi
= qemu_allocate_irqs(gsi_handler
, gsi_state
, GSI_NUM_PINS
);
132 pci_bus
= i440fx_init(&i440fx_state
, &piix3_devfn
, &isa_bus
, gsi
,
133 system_memory
, system_io
, ram_size
,
135 0x100000000ULL
- below_4g_mem_size
,
136 0x100000000ULL
+ above_4g_mem_size
,
139 : ((uint64_t)1 << 62)),
140 pci_memory
, ram_memory
);
144 isa_bus
= isa_bus_new(NULL
, system_io
);
147 isa_bus_irqs(isa_bus
, gsi
);
149 if (kvm_irqchip_in_kernel()) {
150 i8259
= kvm_i8259_init(isa_bus
);
151 } else if (xen_enabled()) {
152 i8259
= xen_interrupt_controller_init();
154 cpu_irq
= pc_allocate_cpu_irq();
155 i8259
= i8259_init(isa_bus
, cpu_irq
[0]);
158 for (i
= 0; i
< ISA_NUM_IRQS
; i
++) {
159 gsi_state
->i8259_irq
[i
] = i8259
[i
];
162 ioapic_init_gsi(gsi_state
, "i440fx");
165 pc_register_ferr_irq(gsi
[13]);
167 pc_vga_init(isa_bus
, pci_enabled
? pci_bus
: NULL
);
169 pci_create_simple(pci_bus
, -1, "xen-platform");
172 /* init basic PC hardware */
173 pc_basic_device_init(isa_bus
, gsi
, &rtc_state
, &floppy
, xen_enabled());
175 pc_nic_init(isa_bus
, pci_bus
);
177 ide_drive_get(hd
, MAX_IDE_BUS
);
181 dev
= pci_piix3_xen_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
183 dev
= pci_piix3_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
185 idebus
[0] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
186 idebus
[1] = qdev_get_child_bus(&dev
->qdev
, "ide.1");
188 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
190 dev
= isa_ide_init(isa_bus
, ide_iobase
[i
], ide_iobase2
[i
],
192 hd
[MAX_IDE_DEVS
* i
], hd
[MAX_IDE_DEVS
* i
+ 1]);
193 idebus
[i
] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
197 audio_init(isa_bus
, pci_enabled
? pci_bus
: NULL
);
199 pc_cmos_init(below_4g_mem_size
, above_4g_mem_size
, boot_device
,
200 floppy
, idebus
[0], idebus
[1], rtc_state
);
202 if (pci_enabled
&& usb_enabled(false)) {
203 pci_create_simple(pci_bus
, piix3_devfn
+ 2, "piix3-usb-uhci");
206 if (pci_enabled
&& acpi_enabled
) {
209 smi_irq
= qemu_allocate_irqs(pc_acpi_smi_interrupt
,
210 x86_env_get_cpu(first_cpu
), 1);
211 /* TODO: Populate SPD eeprom data. */
212 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
214 kvm_enabled(), fw_cfg
);
215 smbus_eeprom_init(smbus
, 8, NULL
, 0);
219 pc_pci_device_init(pci_bus
);
223 static void pc_init_pci(QEMUMachineInitArgs
*args
)
225 ram_addr_t ram_size
= args
->ram_size
;
226 const char *cpu_model
= args
->cpu_model
;
227 const char *kernel_filename
= args
->kernel_filename
;
228 const char *kernel_cmdline
= args
->kernel_cmdline
;
229 const char *initrd_filename
= args
->initrd_filename
;
230 const char *boot_device
= args
->boot_device
;
231 pc_init1(get_system_memory(),
233 ram_size
, boot_device
,
234 kernel_filename
, kernel_cmdline
,
235 initrd_filename
, cpu_model
, 1, 1);
238 static void pc_init_pci_1_3(QEMUMachineInitArgs
*args
)
240 enable_compat_apic_id_mode();
244 /* PC machine init function for pc-0.14 to pc-1.2 */
245 static void pc_init_pci_1_2(QEMUMachineInitArgs
*args
)
247 disable_kvm_pv_eoi();
248 pc_init_pci_1_3(args
);
251 /* PC init function for pc-0.10 to pc-0.13, and reused by xenfv */
252 static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs
*args
)
254 ram_addr_t ram_size
= args
->ram_size
;
255 const char *cpu_model
= args
->cpu_model
;
256 const char *kernel_filename
= args
->kernel_filename
;
257 const char *kernel_cmdline
= args
->kernel_cmdline
;
258 const char *initrd_filename
= args
->initrd_filename
;
259 const char *boot_device
= args
->boot_device
;
260 disable_kvm_pv_eoi();
261 enable_compat_apic_id_mode();
262 pc_init1(get_system_memory(),
264 ram_size
, boot_device
,
265 kernel_filename
, kernel_cmdline
,
266 initrd_filename
, cpu_model
, 1, 0);
269 static void pc_init_isa(QEMUMachineInitArgs
*args
)
271 ram_addr_t ram_size
= args
->ram_size
;
272 const char *cpu_model
= args
->cpu_model
;
273 const char *kernel_filename
= args
->kernel_filename
;
274 const char *kernel_cmdline
= args
->kernel_cmdline
;
275 const char *initrd_filename
= args
->initrd_filename
;
276 const char *boot_device
= args
->boot_device
;
277 if (cpu_model
== NULL
)
279 disable_kvm_pv_eoi();
280 enable_compat_apic_id_mode();
281 pc_init1(get_system_memory(),
283 ram_size
, boot_device
,
284 kernel_filename
, kernel_cmdline
,
285 initrd_filename
, cpu_model
, 0, 1);
289 static void pc_xen_hvm_init(QEMUMachineInitArgs
*args
)
291 if (xen_hvm_init() != 0) {
292 hw_error("xen hardware virtual machine initialisation failed");
294 pc_init_pci_no_kvmclock(args
);
299 static QEMUMachine pc_i440fx_machine_v1_5
= {
300 .name
= "pc-i440fx-1.5",
302 .desc
= "Standard PC (i440FX + PIIX, 1996)",
306 DEFAULT_MACHINE_OPTIONS
,
309 static QEMUMachine pc_i440fx_machine_v1_4
= {
310 .name
= "pc-i440fx-1.4",
311 .desc
= "Standard PC (i440FX + PIIX, 1996)",
314 .compat_props
= (GlobalProperty
[]) {
316 { /* end of list */ }
318 DEFAULT_MACHINE_OPTIONS
,
321 #define PC_COMPAT_1_3 \
324 .driver = "usb-tablet",\
325 .property = "usb_version",\
326 .value = stringify(1),\
328 .driver = "virtio-net-pci",\
329 .property = "ctrl_mac_addr",\
332 .driver = "virtio-net-pci", \
337 .property = "autonegotiation",\
341 static QEMUMachine pc_machine_v1_3
= {
343 .desc
= "Standard PC",
344 .init
= pc_init_pci_1_3
,
346 .compat_props
= (GlobalProperty
[]) {
348 { /* end of list */ }
350 DEFAULT_MACHINE_OPTIONS
,
353 #define PC_COMPAT_1_2 \
356 .driver = "nec-usb-xhci",\
360 .driver = "nec-usb-xhci",\
364 .driver = "ivshmem",\
365 .property = "use64",\
369 .property = "revision",\
370 .value = stringify(3),\
372 .driver = "qxl-vga",\
373 .property = "revision",\
374 .value = stringify(3),\
381 static QEMUMachine pc_machine_v1_2
= {
383 .desc
= "Standard PC",
384 .init
= pc_init_pci_1_2
,
386 .compat_props
= (GlobalProperty
[]) {
388 { /* end of list */ }
390 DEFAULT_MACHINE_OPTIONS
,
393 #define PC_COMPAT_1_1 \
396 .driver = "virtio-scsi-pci",\
397 .property = "hotplug",\
400 .driver = "virtio-scsi-pci",\
401 .property = "param_change",\
405 .property = "vgamem_mb",\
406 .value = stringify(8),\
408 .driver = "vmware-svga",\
409 .property = "vgamem_mb",\
410 .value = stringify(8),\
412 .driver = "qxl-vga",\
413 .property = "vgamem_mb",\
414 .value = stringify(8),\
417 .property = "vgamem_mb",\
418 .value = stringify(8),\
420 .driver = "virtio-blk-pci",\
421 .property = "config-wce",\
425 static QEMUMachine pc_machine_v1_1
= {
427 .desc
= "Standard PC",
428 .init
= pc_init_pci_1_2
,
430 .compat_props
= (GlobalProperty
[]) {
432 { /* end of list */ }
434 DEFAULT_MACHINE_OPTIONS
,
437 #define PC_COMPAT_1_0 \
440 .driver = "pc-sysfw",\
441 .property = "rom_only",\
442 .value = stringify(1),\
444 .driver = "isa-fdc",\
445 .property = "check_media_rate",\
448 .driver = "virtio-balloon-pci",\
449 .property = "class",\
450 .value = stringify(PCI_CLASS_MEMORY_RAM),\
453 .property = "vapic",\
456 .driver = TYPE_USB_DEVICE,\
457 .property = "full-path",\
461 static QEMUMachine pc_machine_v1_0
= {
463 .desc
= "Standard PC",
464 .init
= pc_init_pci_1_2
,
466 .compat_props
= (GlobalProperty
[]) {
468 { /* end of list */ }
471 DEFAULT_MACHINE_OPTIONS
,
474 #define PC_COMPAT_0_15 \
477 static QEMUMachine pc_machine_v0_15
= {
479 .desc
= "Standard PC",
480 .init
= pc_init_pci_1_2
,
482 .compat_props
= (GlobalProperty
[]) {
484 { /* end of list */ }
486 .hw_version
= "0.15",
487 DEFAULT_MACHINE_OPTIONS
,
490 #define PC_COMPAT_0_14 \
493 .driver = "virtio-blk-pci",\
494 .property = "event_idx",\
497 .driver = "virtio-serial-pci",\
498 .property = "event_idx",\
501 .driver = "virtio-net-pci",\
502 .property = "event_idx",\
505 .driver = "virtio-balloon-pci",\
506 .property = "event_idx",\
510 static QEMUMachine pc_machine_v0_14
= {
512 .desc
= "Standard PC",
513 .init
= pc_init_pci_1_2
,
515 .compat_props
= (GlobalProperty
[]) {
519 .property
= "revision",
520 .value
= stringify(2),
523 .property
= "revision",
524 .value
= stringify(2),
526 { /* end of list */ }
528 .hw_version
= "0.14",
529 DEFAULT_MACHINE_OPTIONS
,
532 #define PC_COMPAT_0_13 \
535 .driver = TYPE_PCI_DEVICE,\
536 .property = "command_serr_enable",\
540 .property = "use_broken_id",\
541 .value = stringify(1),\
544 static QEMUMachine pc_machine_v0_13
= {
546 .desc
= "Standard PC",
547 .init
= pc_init_pci_no_kvmclock
,
549 .compat_props
= (GlobalProperty
[]) {
552 .driver
= "virtio-9p-pci",
553 .property
= "vectors",
554 .value
= stringify(0),
557 .property
= "rombar",
558 .value
= stringify(0),
560 .driver
= "vmware-svga",
561 .property
= "rombar",
562 .value
= stringify(0),
564 { /* end of list */ }
566 .hw_version
= "0.13",
567 DEFAULT_MACHINE_OPTIONS
,
570 #define PC_COMPAT_0_12 \
573 .driver = "virtio-serial-pci",\
574 .property = "max_ports",\
575 .value = stringify(1),\
577 .driver = "virtio-serial-pci",\
578 .property = "vectors",\
579 .value = stringify(0),\
582 static QEMUMachine pc_machine_v0_12
= {
584 .desc
= "Standard PC",
585 .init
= pc_init_pci_no_kvmclock
,
587 .compat_props
= (GlobalProperty
[]) {
591 .property
= "rombar",
592 .value
= stringify(0),
594 .driver
= "vmware-svga",
595 .property
= "rombar",
596 .value
= stringify(0),
598 { /* end of list */ }
600 .hw_version
= "0.12",
601 DEFAULT_MACHINE_OPTIONS
,
604 #define PC_COMPAT_0_11 \
607 .driver = "virtio-blk-pci",\
608 .property = "vectors",\
609 .value = stringify(0),\
611 .driver = TYPE_PCI_DEVICE,\
612 .property = "rombar",\
613 .value = stringify(0),\
616 static QEMUMachine pc_machine_v0_11
= {
618 .desc
= "Standard PC, qemu 0.11",
619 .init
= pc_init_pci_no_kvmclock
,
621 .compat_props
= (GlobalProperty
[]) {
624 .driver
= "ide-drive",
628 .driver
= "scsi-disk",
632 { /* end of list */ }
634 .hw_version
= "0.11",
635 DEFAULT_MACHINE_OPTIONS
,
638 static QEMUMachine pc_machine_v0_10
= {
640 .desc
= "Standard PC, qemu 0.10",
641 .init
= pc_init_pci_no_kvmclock
,
643 .compat_props
= (GlobalProperty
[]) {
646 .driver
= "virtio-blk-pci",
648 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
650 .driver
= "virtio-serial-pci",
652 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
654 .driver
= "virtio-net-pci",
655 .property
= "vectors",
656 .value
= stringify(0),
658 .driver
= "ide-drive",
662 .driver
= "scsi-disk",
666 { /* end of list */ }
668 .hw_version
= "0.10",
669 DEFAULT_MACHINE_OPTIONS
,
672 static QEMUMachine isapc_machine
= {
674 .desc
= "ISA-only PC",
677 .compat_props
= (GlobalProperty
[]) {
679 .driver
= "pc-sysfw",
680 .property
= "rom_only",
681 .value
= stringify(1),
683 { /* end of list */ }
685 DEFAULT_MACHINE_OPTIONS
,
689 static QEMUMachine xenfv_machine
= {
691 .desc
= "Xen Fully-virtualized PC",
692 .init
= pc_xen_hvm_init
,
693 .max_cpus
= HVM_MAX_VCPUS
,
694 .default_machine_opts
= "accel=xen",
695 DEFAULT_MACHINE_OPTIONS
,
699 static void pc_machine_init(void)
701 qemu_register_machine(&pc_i440fx_machine_v1_5
);
702 qemu_register_machine(&pc_i440fx_machine_v1_4
);
703 qemu_register_machine(&pc_machine_v1_3
);
704 qemu_register_machine(&pc_machine_v1_2
);
705 qemu_register_machine(&pc_machine_v1_1
);
706 qemu_register_machine(&pc_machine_v1_0
);
707 qemu_register_machine(&pc_machine_v0_15
);
708 qemu_register_machine(&pc_machine_v0_14
);
709 qemu_register_machine(&pc_machine_v0_13
);
710 qemu_register_machine(&pc_machine_v0_12
);
711 qemu_register_machine(&pc_machine_v0_11
);
712 qemu_register_machine(&pc_machine_v0_10
);
713 qemu_register_machine(&isapc_machine
);
715 qemu_register_machine(&xenfv_machine
);
719 machine_init(pc_machine_init
);