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
38 #include "arch_init.h"
43 #include "exec-memory.h"
45 # include <xen/hvm/hvm_info_table.h>
50 static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
51 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
52 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
54 static void ioapic_init(IsaIrqState *isa_irq_state)
60 dev = qdev_create(NULL, "ioapic");
61 qdev_init_nofail(dev);
62 d = sysbus_from_qdev(dev);
63 sysbus_mmio_map(d, 0, 0xfec00000);
65 for (i = 0; i < IOAPIC_NUM_PINS; i++) {
66 isa_irq_state->ioapic[i] = qdev_get_gpio_in(dev, i);
70 /* PC hardware initialisation */
71 static void pc_init1(MemoryRegion *system_memory,
73 const char *boot_device,
74 const char *kernel_filename,
75 const char *kernel_cmdline,
76 const char *initrd_filename,
77 const char *cpu_model,
82 ram_addr_t below_4g_mem_size, above_4g_mem_size;
84 PCII440FXState *i440fx_state;
91 IsaIrqState *isa_irq_state;
92 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
93 BusState *idebus[MAX_IDE_BUS];
96 pc_cpus_init(cpu_model);
98 if (kvmclock_enabled) {
102 if (ram_size >= 0xe0000000 ) {
103 above_4g_mem_size = ram_size - 0xe0000000;
104 below_4g_mem_size = 0xe0000000;
106 above_4g_mem_size = 0;
107 below_4g_mem_size = ram_size;
110 /* allocate ram and load rom/bios */
111 if (!xen_enabled()) {
112 pc_memory_init(system_memory,
113 kernel_filename, kernel_cmdline, initrd_filename,
114 below_4g_mem_size, above_4g_mem_size);
117 if (!xen_enabled()) {
118 cpu_irq = pc_allocate_cpu_irq();
119 i8259 = i8259_init(cpu_irq[0]);
121 i8259 = xen_interrupt_controller_init();
123 isa_irq_state = qemu_mallocz(sizeof(*isa_irq_state));
124 isa_irq_state->i8259 = i8259;
126 ioapic_init(isa_irq_state);
128 isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
131 pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq,
132 system_memory, ram_size);
138 isa_bus_irqs(isa_irq);
140 pc_register_ferr_irq(isa_get_irq(13));
142 pc_vga_init(pci_enabled? pci_bus: NULL);
145 pci_create_simple(pci_bus, -1, "xen-platform");
148 /* init basic PC hardware */
149 pc_basic_device_init(isa_irq, &rtc_state, xen_enabled());
151 for(i = 0; i < nb_nics; i++) {
152 NICInfo *nd = &nd_table[i];
154 if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
155 pc_init_ne2k_isa(nd);
157 pci_nic_init_nofail(nd, "e1000", NULL);
160 ide_drive_get(hd, MAX_IDE_BUS);
164 dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
166 dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
168 idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
169 idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
171 for(i = 0; i < MAX_IDE_BUS; i++) {
173 dev = isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
174 hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
175 idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
179 audio_init(isa_irq, pci_enabled ? pci_bus : NULL);
181 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
182 idebus[0], idebus[1], rtc_state);
184 if (pci_enabled && usb_enabled) {
185 usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
188 if (pci_enabled && acpi_enabled) {
191 if (!xen_enabled()) {
192 cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
194 cmos_s3 = qemu_allocate_irqs(xen_cmos_set_s3_resume, rtc_state, 1);
196 smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
197 /* TODO: Populate SPD eeprom data. */
198 smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
199 isa_get_irq(9), *cmos_s3, *smi_irq,
201 smbus_eeprom_init(smbus, 8, NULL, 0);
205 i440fx_init_memory_mappings(i440fx_state);
209 pc_pci_device_init(pci_bus);
213 static void pc_init_pci(ram_addr_t ram_size,
214 const char *boot_device,
215 const char *kernel_filename,
216 const char *kernel_cmdline,
217 const char *initrd_filename,
218 const char *cpu_model)
220 pc_init1(get_system_memory(),
221 ram_size, boot_device,
222 kernel_filename, kernel_cmdline,
223 initrd_filename, cpu_model, 1, 1);
226 static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,
227 const char *boot_device,
228 const char *kernel_filename,
229 const char *kernel_cmdline,
230 const char *initrd_filename,
231 const char *cpu_model)
233 pc_init1(get_system_memory(),
234 ram_size, boot_device,
235 kernel_filename, kernel_cmdline,
236 initrd_filename, cpu_model, 1, 0);
239 static void pc_init_isa(ram_addr_t ram_size,
240 const char *boot_device,
241 const char *kernel_filename,
242 const char *kernel_cmdline,
243 const char *initrd_filename,
244 const char *cpu_model)
246 if (cpu_model == NULL)
248 pc_init1(get_system_memory(),
249 ram_size, boot_device,
250 kernel_filename, kernel_cmdline,
251 initrd_filename, cpu_model, 0, 1);
255 static void pc_xen_hvm_init(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 if (xen_hvm_init() != 0) {
263 hw_error("xen hardware virtual machine initialisation failed");
265 pc_init_pci_no_kvmclock(ram_size, boot_device,
266 kernel_filename, kernel_cmdline,
267 initrd_filename, cpu_model);
272 static QEMUMachine pc_machine = {
275 .desc = "Standard PC",
281 static QEMUMachine pc_machine_v0_13 = {
283 .desc = "Standard PC",
284 .init = pc_init_pci_no_kvmclock,
286 .compat_props = (GlobalProperty[]) {
288 .driver = "virtio-9p-pci",
289 .property = "vectors",
290 .value = stringify(0),
293 .property = "rombar",
294 .value = stringify(0),
296 .driver = "vmware-svga",
297 .property = "rombar",
298 .value = stringify(0),
301 .property = "command_serr_enable",
304 .driver = "virtio-blk-pci",
305 .property = "event_idx",
308 .driver = "virtio-serial-pci",
309 .property = "event_idx",
312 .driver = "virtio-net-pci",
313 .property = "event_idx",
316 { /* end of list */ }
320 static QEMUMachine pc_machine_v0_12 = {
322 .desc = "Standard PC",
323 .init = pc_init_pci_no_kvmclock,
325 .compat_props = (GlobalProperty[]) {
327 .driver = "virtio-serial-pci",
328 .property = "max_ports",
329 .value = stringify(1),
331 .driver = "virtio-serial-pci",
332 .property = "vectors",
333 .value = stringify(0),
336 .property = "rombar",
337 .value = stringify(0),
339 .driver = "vmware-svga",
340 .property = "rombar",
341 .value = stringify(0),
344 .property = "command_serr_enable",
347 .driver = "virtio-blk-pci",
348 .property = "event_idx",
351 .driver = "virtio-serial-pci",
352 .property = "event_idx",
355 .driver = "virtio-net-pci",
356 .property = "event_idx",
359 { /* end of list */ }
363 static QEMUMachine pc_machine_v0_11 = {
365 .desc = "Standard PC, qemu 0.11",
366 .init = pc_init_pci_no_kvmclock,
368 .compat_props = (GlobalProperty[]) {
370 .driver = "virtio-blk-pci",
371 .property = "vectors",
372 .value = stringify(0),
374 .driver = "virtio-serial-pci",
375 .property = "max_ports",
376 .value = stringify(1),
378 .driver = "virtio-serial-pci",
379 .property = "vectors",
380 .value = stringify(0),
382 .driver = "ide-drive",
386 .driver = "scsi-disk",
391 .property = "rombar",
392 .value = stringify(0),
395 .property = "command_serr_enable",
398 .driver = "virtio-blk-pci",
399 .property = "event_idx",
402 .driver = "virtio-serial-pci",
403 .property = "event_idx",
406 .driver = "virtio-net-pci",
407 .property = "event_idx",
410 { /* end of list */ }
414 static QEMUMachine pc_machine_v0_10 = {
416 .desc = "Standard PC, qemu 0.10",
417 .init = pc_init_pci_no_kvmclock,
419 .compat_props = (GlobalProperty[]) {
421 .driver = "virtio-blk-pci",
423 .value = stringify(PCI_CLASS_STORAGE_OTHER),
425 .driver = "virtio-serial-pci",
427 .value = stringify(PCI_CLASS_DISPLAY_OTHER),
429 .driver = "virtio-serial-pci",
430 .property = "max_ports",
431 .value = stringify(1),
433 .driver = "virtio-serial-pci",
434 .property = "vectors",
435 .value = stringify(0),
437 .driver = "virtio-net-pci",
438 .property = "vectors",
439 .value = stringify(0),
441 .driver = "virtio-blk-pci",
442 .property = "vectors",
443 .value = stringify(0),
445 .driver = "ide-drive",
449 .driver = "scsi-disk",
454 .property = "rombar",
455 .value = stringify(0),
458 .property = "command_serr_enable",
461 .driver = "virtio-blk-pci",
462 .property = "event_idx",
465 .driver = "virtio-serial-pci",
466 .property = "event_idx",
469 .driver = "virtio-net-pci",
470 .property = "event_idx",
473 { /* end of list */ }
477 static QEMUMachine isapc_machine = {
479 .desc = "ISA-only PC",
485 static QEMUMachine xenfv_machine = {
487 .desc = "Xen Fully-virtualized PC",
488 .init = pc_xen_hvm_init,
489 .max_cpus = HVM_MAX_VCPUS,
490 .default_machine_opts = "accel=xen",
494 static void pc_machine_init(void)
496 qemu_register_machine(&pc_machine);
497 qemu_register_machine(&pc_machine_v0_13);
498 qemu_register_machine(&pc_machine_v0_12);
499 qemu_register_machine(&pc_machine_v0_11);
500 qemu_register_machine(&pc_machine_v0_10);
501 qemu_register_machine(&isapc_machine);
503 qemu_register_machine(&xenfv_machine);
507 machine_init(pc_machine_init);