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
31 #include "pci/pci_ids.h"
36 #include "sysemu/kvm.h"
37 #include "kvm/clock.h"
38 #include "sysemu/sysemu.h"
40 #include "sysemu/arch_init.h"
41 #include "sysemu/blockdev.h"
44 #include "exec/memory.h"
45 #include "exec/address-spaces.h"
48 # include <xen/hvm/hvm_info_table.h>
53 static const int ide_iobase
[MAX_IDE_BUS
] = { 0x1f0, 0x170 };
54 static const int ide_iobase2
[MAX_IDE_BUS
] = { 0x3f6, 0x376 };
55 static const int ide_irq
[MAX_IDE_BUS
] = { 14, 15 };
57 /* PC hardware initialisation */
58 static void pc_init1(MemoryRegion
*system_memory
,
59 MemoryRegion
*system_io
,
61 const char *boot_device
,
62 const char *kernel_filename
,
63 const char *kernel_cmdline
,
64 const char *initrd_filename
,
65 const char *cpu_model
,
70 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
73 PCII440FXState
*i440fx_state
;
80 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
81 BusState
*idebus
[MAX_IDE_BUS
];
84 MemoryRegion
*ram_memory
;
85 MemoryRegion
*pci_memory
;
86 MemoryRegion
*rom_memory
;
89 pc_cpus_init(cpu_model
);
90 pc_acpi_init("acpi-dsdt.aml");
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");
196 audio_init(isa_bus
, pci_enabled
? pci_bus
: NULL
);
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
, first_cpu
, 1);
209 /* TODO: Populate SPD eeprom data. */
210 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
212 kvm_enabled(), fw_cfg
);
213 smbus_eeprom_init(smbus
, 8, NULL
, 0);
217 pc_pci_device_init(pci_bus
);
221 static void pc_init_pci(QEMUMachineInitArgs
*args
)
223 ram_addr_t ram_size
= args
->ram_size
;
224 const char *cpu_model
= args
->cpu_model
;
225 const char *kernel_filename
= args
->kernel_filename
;
226 const char *kernel_cmdline
= args
->kernel_cmdline
;
227 const char *initrd_filename
= args
->initrd_filename
;
228 const char *boot_device
= args
->boot_device
;
229 pc_init1(get_system_memory(),
231 ram_size
, boot_device
,
232 kernel_filename
, kernel_cmdline
,
233 initrd_filename
, cpu_model
, 1, 1);
236 static void pc_init_pci_1_3(QEMUMachineInitArgs
*args
)
238 enable_compat_apic_id_mode();
242 /* PC machine init function for pc-0.14 to pc-1.2 */
243 static void pc_init_pci_1_2(QEMUMachineInitArgs
*args
)
245 disable_kvm_pv_eoi();
246 pc_init_pci_1_3(args
);
249 /* PC init function for pc-0.10 to pc-0.13, and reused by xenfv */
250 static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs
*args
)
252 ram_addr_t ram_size
= args
->ram_size
;
253 const char *cpu_model
= args
->cpu_model
;
254 const char *kernel_filename
= args
->kernel_filename
;
255 const char *kernel_cmdline
= args
->kernel_cmdline
;
256 const char *initrd_filename
= args
->initrd_filename
;
257 const char *boot_device
= args
->boot_device
;
258 disable_kvm_pv_eoi();
259 enable_compat_apic_id_mode();
260 pc_init1(get_system_memory(),
262 ram_size
, boot_device
,
263 kernel_filename
, kernel_cmdline
,
264 initrd_filename
, cpu_model
, 1, 0);
267 static void pc_init_isa(QEMUMachineInitArgs
*args
)
269 ram_addr_t ram_size
= args
->ram_size
;
270 const char *cpu_model
= args
->cpu_model
;
271 const char *kernel_filename
= args
->kernel_filename
;
272 const char *kernel_cmdline
= args
->kernel_cmdline
;
273 const char *initrd_filename
= args
->initrd_filename
;
274 const char *boot_device
= args
->boot_device
;
275 if (cpu_model
== NULL
)
277 disable_kvm_pv_eoi();
278 enable_compat_apic_id_mode();
279 pc_init1(get_system_memory(),
281 ram_size
, boot_device
,
282 kernel_filename
, kernel_cmdline
,
283 initrd_filename
, cpu_model
, 0, 1);
287 static void pc_xen_hvm_init(QEMUMachineInitArgs
*args
)
289 if (xen_hvm_init() != 0) {
290 hw_error("xen hardware virtual machine initialisation failed");
292 pc_init_pci_no_kvmclock(args
);
297 static QEMUMachine pc_i440fx_machine_v1_4
= {
298 .name
= "pc-i440fx-1.4",
300 .desc
= "Standard PC (i440FX + PIIX, 1996)",
304 DEFAULT_MACHINE_OPTIONS
,
307 #define PC_COMPAT_1_3 \
309 .driver = "usb-tablet",\
310 .property = "usb_version",\
311 .value = stringify(1),\
314 static QEMUMachine pc_machine_v1_3
= {
316 .desc
= "Standard PC",
317 .init
= pc_init_pci_1_3
,
319 .compat_props
= (GlobalProperty
[]) {
321 { /* end of list */ }
323 DEFAULT_MACHINE_OPTIONS
,
326 #define PC_COMPAT_1_2 \
329 .driver = "nec-usb-xhci",\
333 .driver = "nec-usb-xhci",\
337 .driver = "ivshmem",\
338 .property = "use64",\
342 .property = "revision",\
343 .value = stringify(3),\
345 .driver = "qxl-vga",\
346 .property = "revision",\
347 .value = stringify(3),\
354 static QEMUMachine pc_machine_v1_2
= {
356 .desc
= "Standard PC",
357 .init
= pc_init_pci_1_2
,
359 .compat_props
= (GlobalProperty
[]) {
361 { /* end of list */ }
363 DEFAULT_MACHINE_OPTIONS
,
366 #define PC_COMPAT_1_1 \
369 .driver = "virtio-scsi-pci",\
370 .property = "hotplug",\
373 .driver = "virtio-scsi-pci",\
374 .property = "param_change",\
378 .property = "vgamem_mb",\
379 .value = stringify(8),\
381 .driver = "vmware-svga",\
382 .property = "vgamem_mb",\
383 .value = stringify(8),\
385 .driver = "qxl-vga",\
386 .property = "vgamem_mb",\
387 .value = stringify(8),\
390 .property = "vgamem_mb",\
391 .value = stringify(8),\
393 .driver = "virtio-blk-pci",\
394 .property = "config-wce",\
398 static QEMUMachine pc_machine_v1_1
= {
400 .desc
= "Standard PC",
401 .init
= pc_init_pci_1_2
,
403 .compat_props
= (GlobalProperty
[]) {
405 { /* end of list */ }
407 DEFAULT_MACHINE_OPTIONS
,
410 #define PC_COMPAT_1_0 \
413 .driver = "pc-sysfw",\
414 .property = "rom_only",\
415 .value = stringify(1),\
417 .driver = "isa-fdc",\
418 .property = "check_media_rate",\
421 .driver = "virtio-balloon-pci",\
422 .property = "class",\
423 .value = stringify(PCI_CLASS_MEMORY_RAM),\
426 .property = "vapic",\
429 .driver = TYPE_USB_DEVICE,\
430 .property = "full-path",\
434 static QEMUMachine pc_machine_v1_0
= {
436 .desc
= "Standard PC",
437 .init
= pc_init_pci_1_2
,
439 .compat_props
= (GlobalProperty
[]) {
441 { /* end of list */ }
444 DEFAULT_MACHINE_OPTIONS
,
447 #define PC_COMPAT_0_15 \
450 static QEMUMachine pc_machine_v0_15
= {
452 .desc
= "Standard PC",
453 .init
= pc_init_pci_1_2
,
455 .compat_props
= (GlobalProperty
[]) {
457 { /* end of list */ }
459 .hw_version
= "0.15",
460 DEFAULT_MACHINE_OPTIONS
,
463 #define PC_COMPAT_0_14 \
466 .driver = "virtio-blk-pci",\
467 .property = "event_idx",\
470 .driver = "virtio-serial-pci",\
471 .property = "event_idx",\
474 .driver = "virtio-net-pci",\
475 .property = "event_idx",\
478 .driver = "virtio-balloon-pci",\
479 .property = "event_idx",\
483 static QEMUMachine pc_machine_v0_14
= {
485 .desc
= "Standard PC",
486 .init
= pc_init_pci_1_2
,
488 .compat_props
= (GlobalProperty
[]) {
492 .property
= "revision",
493 .value
= stringify(2),
496 .property
= "revision",
497 .value
= stringify(2),
499 { /* end of list */ }
501 .hw_version
= "0.14",
502 DEFAULT_MACHINE_OPTIONS
,
505 #define PC_COMPAT_0_13 \
508 .driver = TYPE_PCI_DEVICE,\
509 .property = "command_serr_enable",\
513 .property = "use_broken_id",\
514 .value = stringify(1),\
517 static QEMUMachine pc_machine_v0_13
= {
519 .desc
= "Standard PC",
520 .init
= pc_init_pci_no_kvmclock
,
522 .compat_props
= (GlobalProperty
[]) {
525 .driver
= "virtio-9p-pci",
526 .property
= "vectors",
527 .value
= stringify(0),
530 .property
= "rombar",
531 .value
= stringify(0),
533 .driver
= "vmware-svga",
534 .property
= "rombar",
535 .value
= stringify(0),
537 { /* end of list */ }
539 .hw_version
= "0.13",
540 DEFAULT_MACHINE_OPTIONS
,
543 #define PC_COMPAT_0_12 \
546 .driver = "virtio-serial-pci",\
547 .property = "max_ports",\
548 .value = stringify(1),\
550 .driver = "virtio-serial-pci",\
551 .property = "vectors",\
552 .value = stringify(0),\
555 static QEMUMachine pc_machine_v0_12
= {
557 .desc
= "Standard PC",
558 .init
= pc_init_pci_no_kvmclock
,
560 .compat_props
= (GlobalProperty
[]) {
564 .property
= "rombar",
565 .value
= stringify(0),
567 .driver
= "vmware-svga",
568 .property
= "rombar",
569 .value
= stringify(0),
571 { /* end of list */ }
573 .hw_version
= "0.12",
574 DEFAULT_MACHINE_OPTIONS
,
577 #define PC_COMPAT_0_11 \
580 .driver = "virtio-blk-pci",\
581 .property = "vectors",\
582 .value = stringify(0),\
584 .driver = TYPE_PCI_DEVICE,\
585 .property = "rombar",\
586 .value = stringify(0),\
589 static QEMUMachine pc_machine_v0_11
= {
591 .desc
= "Standard PC, qemu 0.11",
592 .init
= pc_init_pci_no_kvmclock
,
594 .compat_props
= (GlobalProperty
[]) {
597 .driver
= "ide-drive",
601 .driver
= "scsi-disk",
605 { /* end of list */ }
607 .hw_version
= "0.11",
608 DEFAULT_MACHINE_OPTIONS
,
611 static QEMUMachine pc_machine_v0_10
= {
613 .desc
= "Standard PC, qemu 0.10",
614 .init
= pc_init_pci_no_kvmclock
,
616 .compat_props
= (GlobalProperty
[]) {
619 .driver
= "virtio-blk-pci",
621 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
623 .driver
= "virtio-serial-pci",
625 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
627 .driver
= "virtio-net-pci",
628 .property
= "vectors",
629 .value
= stringify(0),
631 .driver
= "ide-drive",
635 .driver
= "scsi-disk",
639 { /* end of list */ }
641 .hw_version
= "0.10",
642 DEFAULT_MACHINE_OPTIONS
,
645 static QEMUMachine isapc_machine
= {
647 .desc
= "ISA-only PC",
650 .compat_props
= (GlobalProperty
[]) {
652 .driver
= "pc-sysfw",
653 .property
= "rom_only",
654 .value
= stringify(1),
656 { /* end of list */ }
658 DEFAULT_MACHINE_OPTIONS
,
662 static QEMUMachine xenfv_machine
= {
664 .desc
= "Xen Fully-virtualized PC",
665 .init
= pc_xen_hvm_init
,
666 .max_cpus
= HVM_MAX_VCPUS
,
667 .default_machine_opts
= "accel=xen",
668 DEFAULT_MACHINE_OPTIONS
,
672 static void pc_machine_init(void)
674 qemu_register_machine(&pc_i440fx_machine_v1_4
);
675 qemu_register_machine(&pc_machine_v1_3
);
676 qemu_register_machine(&pc_machine_v1_2
);
677 qemu_register_machine(&pc_machine_v1_1
);
678 qemu_register_machine(&pc_machine_v1_0
);
679 qemu_register_machine(&pc_machine_v0_15
);
680 qemu_register_machine(&pc_machine_v0_14
);
681 qemu_register_machine(&pc_machine_v0_13
);
682 qemu_register_machine(&pc_machine_v0_12
);
683 qemu_register_machine(&pc_machine_v0_11
);
684 qemu_register_machine(&pc_machine_v0_10
);
685 qemu_register_machine(&isapc_machine
);
687 qemu_register_machine(&xenfv_machine
);
691 machine_init(pc_machine_init
);