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
40 #include "arch_init.h"
45 #include "exec-memory.h"
47 # include <xen/hvm/hvm_info_table.h>
52 static const int ide_iobase
[MAX_IDE_BUS
] = { 0x1f0, 0x170 };
53 static const int ide_iobase2
[MAX_IDE_BUS
] = { 0x3f6, 0x376 };
54 static const int ide_irq
[MAX_IDE_BUS
] = { 14, 15 };
56 static void ioapic_init(GSIState
*gsi_state
)
62 dev
= qdev_create(NULL
, "ioapic");
63 qdev_init_nofail(dev
);
64 d
= sysbus_from_qdev(dev
);
65 sysbus_mmio_map(d
, 0, 0xfec00000);
67 for (i
= 0; i
< IOAPIC_NUM_PINS
; i
++) {
68 gsi_state
->ioapic_irq
[i
] = qdev_get_gpio_in(dev
, i
);
72 /* PC hardware initialisation */
73 static void pc_init1(MemoryRegion
*system_memory
,
74 MemoryRegion
*system_io
,
76 const char *boot_device
,
77 const char *kernel_filename
,
78 const char *kernel_cmdline
,
79 const char *initrd_filename
,
80 const char *cpu_model
,
85 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
88 PCII440FXState
*i440fx_state
;
96 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
97 BusState
*idebus
[MAX_IDE_BUS
];
100 MemoryRegion
*ram_memory
;
101 MemoryRegion
*pci_memory
;
102 MemoryRegion
*rom_memory
;
105 pc_cpus_init(cpu_model
);
107 if (kvmclock_enabled
) {
111 if (ram_size
>= 0xe0000000 ) {
112 above_4g_mem_size
= ram_size
- 0xe0000000;
113 below_4g_mem_size
= 0xe0000000;
115 above_4g_mem_size
= 0;
116 below_4g_mem_size
= ram_size
;
120 pci_memory
= g_new(MemoryRegion
, 1);
121 memory_region_init(pci_memory
, "pci", INT64_MAX
);
122 rom_memory
= pci_memory
;
125 rom_memory
= system_memory
;
128 /* allocate ram and load rom/bios */
129 if (!xen_enabled()) {
130 pc_memory_init(system_memory
,
131 kernel_filename
, kernel_cmdline
, initrd_filename
,
132 below_4g_mem_size
, above_4g_mem_size
,
133 pci_enabled
? rom_memory
: system_memory
, &ram_memory
);
136 gsi_state
= g_malloc0(sizeof(*gsi_state
));
137 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
,
145 (sizeof(target_phys_addr_t
) == 4
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 (!xen_enabled()) {
158 cpu_irq
= pc_allocate_cpu_irq();
159 i8259
= i8259_init(isa_bus
, cpu_irq
[0]);
161 i8259
= xen_interrupt_controller_init();
164 for (i
= 0; i
< ISA_NUM_IRQS
; i
++) {
165 gsi_state
->i8259_irq
[i
] = i8259
[i
];
168 ioapic_init(gsi_state
);
171 pc_register_ferr_irq(gsi
[13]);
173 dev
= pc_vga_init(isa_bus
, pci_enabled
? pci_bus
: NULL
);
175 qdev_property_add_child(qdev_get_root(), "vga", dev
, NULL
);
179 pci_create_simple(pci_bus
, -1, "xen-platform");
182 /* init basic PC hardware */
183 pc_basic_device_init(isa_bus
, gsi
, &rtc_state
, &floppy
, xen_enabled());
185 for(i
= 0; i
< nb_nics
; i
++) {
186 NICInfo
*nd
= &nd_table
[i
];
188 if (!pci_enabled
|| (nd
->model
&& strcmp(nd
->model
, "ne2k_isa") == 0))
189 pc_init_ne2k_isa(isa_bus
, nd
);
191 pci_nic_init_nofail(nd
, "e1000", NULL
);
194 ide_drive_get(hd
, MAX_IDE_BUS
);
198 dev
= pci_piix3_xen_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
200 dev
= pci_piix3_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
202 idebus
[0] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
203 idebus
[1] = qdev_get_child_bus(&dev
->qdev
, "ide.1");
205 /* FIXME there's some major spaghetti here. Somehow we create the
206 * devices on the PIIX before we actually create it. We create the
207 * PIIX3 deep in the recess of the i440fx creation too and then lose
210 * For now, let's "fix" this by making judicious use of paths. This
211 * is not generally the right way to do this.
213 qdev_property_add_child(qdev_resolve_path("/i440fx/piix3", NULL
),
214 "rtc", (DeviceState
*)rtc_state
, NULL
);
216 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
218 dev
= isa_ide_init(isa_bus
, ide_iobase
[i
], ide_iobase2
[i
],
220 hd
[MAX_IDE_DEVS
* i
], hd
[MAX_IDE_DEVS
* i
+ 1]);
221 idebus
[i
] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
225 audio_init(isa_bus
, pci_enabled
? pci_bus
: NULL
);
227 pc_cmos_init(below_4g_mem_size
, above_4g_mem_size
, boot_device
,
228 floppy
, idebus
[0], idebus
[1], rtc_state
);
230 if (pci_enabled
&& usb_enabled
) {
231 usb_uhci_piix3_init(pci_bus
, piix3_devfn
+ 2);
234 if (pci_enabled
&& acpi_enabled
) {
237 if (!xen_enabled()) {
238 cmos_s3
= qemu_allocate_irqs(pc_cmos_set_s3_resume
, rtc_state
, 1);
240 cmos_s3
= qemu_allocate_irqs(xen_cmos_set_s3_resume
, rtc_state
, 1);
242 smi_irq
= qemu_allocate_irqs(pc_acpi_smi_interrupt
, first_cpu
, 1);
243 /* TODO: Populate SPD eeprom data. */
244 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
245 gsi
[9], *cmos_s3
, *smi_irq
,
247 smbus_eeprom_init(smbus
, 8, NULL
, 0);
251 pc_pci_device_init(pci_bus
);
255 static void pc_init_pci(ram_addr_t ram_size
,
256 const char *boot_device
,
257 const char *kernel_filename
,
258 const char *kernel_cmdline
,
259 const char *initrd_filename
,
260 const char *cpu_model
)
262 pc_init1(get_system_memory(),
264 ram_size
, boot_device
,
265 kernel_filename
, kernel_cmdline
,
266 initrd_filename
, cpu_model
, 1, 1);
269 static void pc_init_pci_no_kvmclock(ram_addr_t ram_size
,
270 const char *boot_device
,
271 const char *kernel_filename
,
272 const char *kernel_cmdline
,
273 const char *initrd_filename
,
274 const char *cpu_model
)
276 pc_init1(get_system_memory(),
278 ram_size
, boot_device
,
279 kernel_filename
, kernel_cmdline
,
280 initrd_filename
, cpu_model
, 1, 0);
283 static void pc_init_isa(ram_addr_t ram_size
,
284 const char *boot_device
,
285 const char *kernel_filename
,
286 const char *kernel_cmdline
,
287 const char *initrd_filename
,
288 const char *cpu_model
)
290 if (cpu_model
== NULL
)
292 pc_init1(get_system_memory(),
294 ram_size
, boot_device
,
295 kernel_filename
, kernel_cmdline
,
296 initrd_filename
, cpu_model
, 0, 1);
300 static void pc_xen_hvm_init(ram_addr_t ram_size
,
301 const char *boot_device
,
302 const char *kernel_filename
,
303 const char *kernel_cmdline
,
304 const char *initrd_filename
,
305 const char *cpu_model
)
307 if (xen_hvm_init() != 0) {
308 hw_error("xen hardware virtual machine initialisation failed");
310 pc_init_pci_no_kvmclock(ram_size
, boot_device
,
311 kernel_filename
, kernel_cmdline
,
312 initrd_filename
, cpu_model
);
317 static QEMUMachine pc_machine_v1_0
= {
320 .desc
= "Standard PC",
326 static QEMUMachine pc_machine_v0_15
= {
328 .desc
= "Standard PC",
334 static QEMUMachine pc_machine_v0_14
= {
336 .desc
= "Standard PC",
339 .compat_props
= (GlobalProperty
[]) {
342 .property
= "revision",
343 .value
= stringify(2),
346 .property
= "revision",
347 .value
= stringify(2),
349 .driver
= "virtio-blk-pci",
350 .property
= "event_idx",
353 .driver
= "virtio-serial-pci",
354 .property
= "event_idx",
357 .driver
= "virtio-net-pci",
358 .property
= "event_idx",
361 .driver
= "virtio-balloon-pci",
362 .property
= "event_idx",
365 { /* end of list */ }
369 static QEMUMachine pc_machine_v0_13
= {
371 .desc
= "Standard PC",
372 .init
= pc_init_pci_no_kvmclock
,
374 .compat_props
= (GlobalProperty
[]) {
376 .driver
= "virtio-9p-pci",
377 .property
= "vectors",
378 .value
= stringify(0),
381 .property
= "rombar",
382 .value
= stringify(0),
384 .driver
= "vmware-svga",
385 .property
= "rombar",
386 .value
= stringify(0),
389 .property
= "command_serr_enable",
392 .driver
= "virtio-blk-pci",
393 .property
= "event_idx",
396 .driver
= "virtio-serial-pci",
397 .property
= "event_idx",
400 .driver
= "virtio-net-pci",
401 .property
= "event_idx",
404 .driver
= "virtio-balloon-pci",
405 .property
= "event_idx",
409 .property
= "use_broken_id",
410 .value
= stringify(1),
412 { /* end of list */ }
416 static QEMUMachine pc_machine_v0_12
= {
418 .desc
= "Standard PC",
419 .init
= pc_init_pci_no_kvmclock
,
421 .compat_props
= (GlobalProperty
[]) {
423 .driver
= "virtio-serial-pci",
424 .property
= "max_ports",
425 .value
= stringify(1),
427 .driver
= "virtio-serial-pci",
428 .property
= "vectors",
429 .value
= stringify(0),
432 .property
= "rombar",
433 .value
= stringify(0),
435 .driver
= "vmware-svga",
436 .property
= "rombar",
437 .value
= stringify(0),
440 .property
= "command_serr_enable",
443 .driver
= "virtio-blk-pci",
444 .property
= "event_idx",
447 .driver
= "virtio-serial-pci",
448 .property
= "event_idx",
451 .driver
= "virtio-net-pci",
452 .property
= "event_idx",
455 .driver
= "virtio-balloon-pci",
456 .property
= "event_idx",
460 .property
= "use_broken_id",
461 .value
= stringify(1),
463 { /* end of list */ }
467 static QEMUMachine pc_machine_v0_11
= {
469 .desc
= "Standard PC, qemu 0.11",
470 .init
= pc_init_pci_no_kvmclock
,
472 .compat_props
= (GlobalProperty
[]) {
474 .driver
= "virtio-blk-pci",
475 .property
= "vectors",
476 .value
= stringify(0),
478 .driver
= "virtio-serial-pci",
479 .property
= "max_ports",
480 .value
= stringify(1),
482 .driver
= "virtio-serial-pci",
483 .property
= "vectors",
484 .value
= stringify(0),
486 .driver
= "ide-drive",
490 .driver
= "scsi-disk",
495 .property
= "rombar",
496 .value
= stringify(0),
499 .property
= "command_serr_enable",
502 .driver
= "virtio-blk-pci",
503 .property
= "event_idx",
506 .driver
= "virtio-serial-pci",
507 .property
= "event_idx",
510 .driver
= "virtio-net-pci",
511 .property
= "event_idx",
514 .driver
= "virtio-balloon-pci",
515 .property
= "event_idx",
519 .property
= "use_broken_id",
520 .value
= stringify(1),
522 { /* end of list */ }
526 static QEMUMachine pc_machine_v0_10
= {
528 .desc
= "Standard PC, qemu 0.10",
529 .init
= pc_init_pci_no_kvmclock
,
531 .compat_props
= (GlobalProperty
[]) {
533 .driver
= "virtio-blk-pci",
535 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
537 .driver
= "virtio-serial-pci",
539 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
541 .driver
= "virtio-serial-pci",
542 .property
= "max_ports",
543 .value
= stringify(1),
545 .driver
= "virtio-serial-pci",
546 .property
= "vectors",
547 .value
= stringify(0),
549 .driver
= "virtio-net-pci",
550 .property
= "vectors",
551 .value
= stringify(0),
553 .driver
= "virtio-blk-pci",
554 .property
= "vectors",
555 .value
= stringify(0),
557 .driver
= "ide-drive",
561 .driver
= "scsi-disk",
566 .property
= "rombar",
567 .value
= stringify(0),
570 .property
= "command_serr_enable",
573 .driver
= "virtio-blk-pci",
574 .property
= "event_idx",
577 .driver
= "virtio-serial-pci",
578 .property
= "event_idx",
581 .driver
= "virtio-net-pci",
582 .property
= "event_idx",
585 .driver
= "virtio-balloon-pci",
586 .property
= "event_idx",
590 .property
= "use_broken_id",
591 .value
= stringify(1),
593 { /* end of list */ }
597 static QEMUMachine isapc_machine
= {
599 .desc
= "ISA-only PC",
605 static QEMUMachine xenfv_machine
= {
607 .desc
= "Xen Fully-virtualized PC",
608 .init
= pc_xen_hvm_init
,
609 .max_cpus
= HVM_MAX_VCPUS
,
610 .default_machine_opts
= "accel=xen",
614 static void pc_machine_init(void)
616 qemu_register_machine(&pc_machine_v1_0
);
617 qemu_register_machine(&pc_machine_v0_15
);
618 qemu_register_machine(&pc_machine_v0_14
);
619 qemu_register_machine(&pc_machine_v0_13
);
620 qemu_register_machine(&pc_machine_v0_12
);
621 qemu_register_machine(&pc_machine_v0_11
);
622 qemu_register_machine(&pc_machine_v0_10
);
623 qemu_register_machine(&isapc_machine
);
625 qemu_register_machine(&xenfv_machine
);
629 machine_init(pc_machine_init
);