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"
37 #include "kvm/clock.h"
40 #include "arch_init.h"
45 #include "exec-memory.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
);
91 if (kvmclock_enabled
) {
95 if (ram_size
>= 0xe0000000 ) {
96 above_4g_mem_size
= ram_size
- 0xe0000000;
97 below_4g_mem_size
= 0xe0000000;
99 above_4g_mem_size
= 0;
100 below_4g_mem_size
= ram_size
;
104 pci_memory
= g_new(MemoryRegion
, 1);
105 memory_region_init(pci_memory
, "pci", INT64_MAX
);
106 rom_memory
= pci_memory
;
109 rom_memory
= system_memory
;
112 /* allocate ram and load rom/bios */
113 if (!xen_enabled()) {
114 fw_cfg
= pc_memory_init(system_memory
,
115 kernel_filename
, kernel_cmdline
, initrd_filename
,
116 below_4g_mem_size
, above_4g_mem_size
,
117 rom_memory
, &ram_memory
);
120 gsi_state
= g_malloc0(sizeof(*gsi_state
));
121 if (kvm_irqchip_in_kernel()) {
122 kvm_pc_setup_irq_routing(pci_enabled
);
123 gsi
= qemu_allocate_irqs(kvm_pc_gsi_handler
, gsi_state
,
126 gsi
= qemu_allocate_irqs(gsi_handler
, gsi_state
, GSI_NUM_PINS
);
130 pci_bus
= i440fx_init(&i440fx_state
, &piix3_devfn
, &isa_bus
, gsi
,
131 system_memory
, system_io
, ram_size
,
133 0x100000000ULL
- below_4g_mem_size
,
134 0x100000000ULL
+ above_4g_mem_size
,
137 : ((uint64_t)1 << 62)),
138 pci_memory
, ram_memory
);
142 isa_bus
= isa_bus_new(NULL
, system_io
);
145 isa_bus_irqs(isa_bus
, gsi
);
147 if (kvm_irqchip_in_kernel()) {
148 i8259
= kvm_i8259_init(isa_bus
);
149 } else if (xen_enabled()) {
150 i8259
= xen_interrupt_controller_init();
152 cpu_irq
= pc_allocate_cpu_irq();
153 i8259
= i8259_init(isa_bus
, cpu_irq
[0]);
156 for (i
= 0; i
< ISA_NUM_IRQS
; i
++) {
157 gsi_state
->i8259_irq
[i
] = i8259
[i
];
160 ioapic_init_gsi(gsi_state
, "i440fx");
163 pc_register_ferr_irq(gsi
[13]);
165 pc_vga_init(isa_bus
, pci_enabled
? pci_bus
: NULL
);
167 pci_create_simple(pci_bus
, -1, "xen-platform");
170 /* init basic PC hardware */
171 pc_basic_device_init(isa_bus
, gsi
, &rtc_state
, &floppy
, xen_enabled());
173 pc_nic_init(isa_bus
, pci_bus
);
175 ide_drive_get(hd
, MAX_IDE_BUS
);
179 dev
= pci_piix3_xen_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
181 dev
= pci_piix3_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
183 idebus
[0] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
184 idebus
[1] = qdev_get_child_bus(&dev
->qdev
, "ide.1");
186 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
188 dev
= isa_ide_init(isa_bus
, ide_iobase
[i
], ide_iobase2
[i
],
190 hd
[MAX_IDE_DEVS
* i
], hd
[MAX_IDE_DEVS
* i
+ 1]);
191 idebus
[i
] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
195 audio_init(isa_bus
, pci_enabled
? pci_bus
: NULL
);
197 pc_cmos_init(below_4g_mem_size
, above_4g_mem_size
, boot_device
,
198 floppy
, idebus
[0], idebus
[1], rtc_state
);
200 if (pci_enabled
&& usb_enabled(false)) {
201 pci_create_simple(pci_bus
, piix3_devfn
+ 2, "piix3-usb-uhci");
204 if (pci_enabled
&& acpi_enabled
) {
207 smi_irq
= qemu_allocate_irqs(pc_acpi_smi_interrupt
, first_cpu
, 1);
208 /* TODO: Populate SPD eeprom data. */
209 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
211 kvm_enabled(), fw_cfg
);
212 smbus_eeprom_init(smbus
, 8, NULL
, 0);
216 pc_pci_device_init(pci_bus
);
220 static void pc_init_pci(QEMUMachineInitArgs
*args
)
222 ram_addr_t ram_size
= args
->ram_size
;
223 const char *cpu_model
= args
->cpu_model
;
224 const char *kernel_filename
= args
->kernel_filename
;
225 const char *kernel_cmdline
= args
->kernel_cmdline
;
226 const char *initrd_filename
= args
->initrd_filename
;
227 const char *boot_device
= args
->boot_device
;
228 pc_init1(get_system_memory(),
230 ram_size
, boot_device
,
231 kernel_filename
, kernel_cmdline
,
232 initrd_filename
, cpu_model
, 1, 1);
235 static void pc_init_pci_1_3(QEMUMachineInitArgs
*args
)
241 static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs
*args
)
243 ram_addr_t ram_size
= args
->ram_size
;
244 const char *cpu_model
= args
->cpu_model
;
245 const char *kernel_filename
= args
->kernel_filename
;
246 const char *kernel_cmdline
= args
->kernel_cmdline
;
247 const char *initrd_filename
= args
->initrd_filename
;
248 const char *boot_device
= args
->boot_device
;
249 pc_init1(get_system_memory(),
251 ram_size
, boot_device
,
252 kernel_filename
, kernel_cmdline
,
253 initrd_filename
, cpu_model
, 1, 0);
256 static void pc_init_isa(QEMUMachineInitArgs
*args
)
258 ram_addr_t ram_size
= args
->ram_size
;
259 const char *cpu_model
= args
->cpu_model
;
260 const char *kernel_filename
= args
->kernel_filename
;
261 const char *kernel_cmdline
= args
->kernel_cmdline
;
262 const char *initrd_filename
= args
->initrd_filename
;
263 const char *boot_device
= args
->boot_device
;
264 if (cpu_model
== NULL
)
266 pc_init1(get_system_memory(),
268 ram_size
, boot_device
,
269 kernel_filename
, kernel_cmdline
,
270 initrd_filename
, cpu_model
, 0, 1);
274 static void pc_xen_hvm_init(QEMUMachineInitArgs
*args
)
276 if (xen_hvm_init() != 0) {
277 hw_error("xen hardware virtual machine initialisation failed");
279 pc_init_pci_no_kvmclock(args
);
284 static QEMUMachine pc_machine_v1_4
= {
287 .desc
= "Standard PC",
288 .init
= pc_init_pci_1_3
,
293 #define PC_COMPAT_1_3 \
295 .driver = "usb-tablet",\
296 .property = "usb_version",\
297 .value = stringify(1),\
300 static QEMUMachine pc_machine_v1_3
= {
302 .desc
= "Standard PC",
303 .init
= pc_init_pci_1_3
,
305 .compat_props
= (GlobalProperty
[]) {
307 { /* end of list */ }
311 #define PC_COMPAT_1_2 \
314 .driver = "nec-usb-xhci",\
318 .driver = "nec-usb-xhci",\
322 .driver = "ivshmem",\
323 .property = "use64",\
327 .property = "revision",\
328 .value = stringify(3),\
330 .driver = "qxl-vga",\
331 .property = "revision",\
332 .value = stringify(3),\
339 static QEMUMachine pc_machine_v1_2
= {
341 .desc
= "Standard PC",
344 .compat_props
= (GlobalProperty
[]) {
346 { /* end of list */ }
350 #define PC_COMPAT_1_1 \
353 .driver = "virtio-scsi-pci",\
354 .property = "hotplug",\
357 .driver = "virtio-scsi-pci",\
358 .property = "param_change",\
362 .property = "vgamem_mb",\
363 .value = stringify(8),\
365 .driver = "vmware-svga",\
366 .property = "vgamem_mb",\
367 .value = stringify(8),\
369 .driver = "qxl-vga",\
370 .property = "vgamem_mb",\
371 .value = stringify(8),\
374 .property = "vgamem_mb",\
375 .value = stringify(8),\
377 .driver = "virtio-blk-pci",\
378 .property = "config-wce",\
382 static QEMUMachine pc_machine_v1_1
= {
384 .desc
= "Standard PC",
387 .compat_props
= (GlobalProperty
[]) {
389 { /* end of list */ }
393 #define PC_COMPAT_1_0 \
396 .driver = "pc-sysfw",\
397 .property = "rom_only",\
398 .value = stringify(1),\
400 .driver = "isa-fdc",\
401 .property = "check_media_rate",\
404 .driver = "virtio-balloon-pci",\
405 .property = "class",\
406 .value = stringify(PCI_CLASS_MEMORY_RAM),\
409 .property = "vapic",\
412 .driver = TYPE_USB_DEVICE,\
413 .property = "full-path",\
417 static QEMUMachine pc_machine_v1_0
= {
419 .desc
= "Standard PC",
422 .compat_props
= (GlobalProperty
[]) {
424 { /* end of list */ }
429 #define PC_COMPAT_0_15 \
432 static QEMUMachine pc_machine_v0_15
= {
434 .desc
= "Standard PC",
437 .compat_props
= (GlobalProperty
[]) {
439 { /* end of list */ }
441 .hw_version
= "0.15",
444 #define PC_COMPAT_0_14 \
447 .driver = "virtio-blk-pci",\
448 .property = "event_idx",\
451 .driver = "virtio-serial-pci",\
452 .property = "event_idx",\
455 .driver = "virtio-net-pci",\
456 .property = "event_idx",\
459 .driver = "virtio-balloon-pci",\
460 .property = "event_idx",\
464 static QEMUMachine pc_machine_v0_14
= {
466 .desc
= "Standard PC",
469 .compat_props
= (GlobalProperty
[]) {
473 .property
= "revision",
474 .value
= stringify(2),
477 .property
= "revision",
478 .value
= stringify(2),
480 { /* end of list */ }
482 .hw_version
= "0.14",
485 #define PC_COMPAT_0_13 \
488 .driver = TYPE_PCI_DEVICE,\
489 .property = "command_serr_enable",\
493 .property = "use_broken_id",\
494 .value = stringify(1),\
497 static QEMUMachine pc_machine_v0_13
= {
499 .desc
= "Standard PC",
500 .init
= pc_init_pci_no_kvmclock
,
502 .compat_props
= (GlobalProperty
[]) {
505 .driver
= "virtio-9p-pci",
506 .property
= "vectors",
507 .value
= stringify(0),
510 .property
= "rombar",
511 .value
= stringify(0),
513 .driver
= "vmware-svga",
514 .property
= "rombar",
515 .value
= stringify(0),
517 { /* end of list */ }
519 .hw_version
= "0.13",
522 #define PC_COMPAT_0_12 \
525 .driver = "virtio-serial-pci",\
526 .property = "max_ports",\
527 .value = stringify(1),\
529 .driver = "virtio-serial-pci",\
530 .property = "vectors",\
531 .value = stringify(0),\
534 static QEMUMachine pc_machine_v0_12
= {
536 .desc
= "Standard PC",
537 .init
= pc_init_pci_no_kvmclock
,
539 .compat_props
= (GlobalProperty
[]) {
543 .property
= "rombar",
544 .value
= stringify(0),
546 .driver
= "vmware-svga",
547 .property
= "rombar",
548 .value
= stringify(0),
550 { /* end of list */ }
552 .hw_version
= "0.12",
555 #define PC_COMPAT_0_11 \
558 .driver = "virtio-blk-pci",\
559 .property = "vectors",\
560 .value = stringify(0),\
562 .driver = TYPE_PCI_DEVICE,\
563 .property = "rombar",\
564 .value = stringify(0),\
567 static QEMUMachine pc_machine_v0_11
= {
569 .desc
= "Standard PC, qemu 0.11",
570 .init
= pc_init_pci_no_kvmclock
,
572 .compat_props
= (GlobalProperty
[]) {
575 .driver
= "ide-drive",
579 .driver
= "scsi-disk",
583 { /* end of list */ }
585 .hw_version
= "0.11",
588 static QEMUMachine pc_machine_v0_10
= {
590 .desc
= "Standard PC, qemu 0.10",
591 .init
= pc_init_pci_no_kvmclock
,
593 .compat_props
= (GlobalProperty
[]) {
596 .driver
= "virtio-blk-pci",
598 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
600 .driver
= "virtio-serial-pci",
602 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
604 .driver
= "virtio-net-pci",
605 .property
= "vectors",
606 .value
= stringify(0),
608 .driver
= "ide-drive",
612 .driver
= "scsi-disk",
616 { /* end of list */ }
618 .hw_version
= "0.10",
621 static QEMUMachine isapc_machine
= {
623 .desc
= "ISA-only PC",
626 .compat_props
= (GlobalProperty
[]) {
628 .driver
= "pc-sysfw",
629 .property
= "rom_only",
630 .value
= stringify(1),
632 { /* end of list */ }
637 static QEMUMachine xenfv_machine
= {
639 .desc
= "Xen Fully-virtualized PC",
640 .init
= pc_xen_hvm_init
,
641 .max_cpus
= HVM_MAX_VCPUS
,
642 .default_machine_opts
= "accel=xen",
646 static void pc_machine_init(void)
648 qemu_register_machine(&pc_machine_v1_4
);
649 qemu_register_machine(&pc_machine_v1_3
);
650 qemu_register_machine(&pc_machine_v1_2
);
651 qemu_register_machine(&pc_machine_v1_1
);
652 qemu_register_machine(&pc_machine_v1_0
);
653 qemu_register_machine(&pc_machine_v0_15
);
654 qemu_register_machine(&pc_machine_v0_14
);
655 qemu_register_machine(&pc_machine_v0_13
);
656 qemu_register_machine(&pc_machine_v0_12
);
657 qemu_register_machine(&pc_machine_v0_11
);
658 qemu_register_machine(&pc_machine_v0_10
);
659 qemu_register_machine(&isapc_machine
);
661 qemu_register_machine(&xenfv_machine
);
665 machine_init(pc_machine_init
);