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
,
72 MemoryRegion
*system_io
,
74 const char *boot_device
,
75 const char *kernel_filename
,
76 const char *kernel_cmdline
,
77 const char *initrd_filename
,
78 const char *cpu_model
,
83 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
85 PCII440FXState
*i440fx_state
;
92 IsaIrqState
*isa_irq_state
;
93 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
94 BusState
*idebus
[MAX_IDE_BUS
];
97 pc_cpus_init(cpu_model
);
99 if (kvmclock_enabled
) {
103 if (ram_size
>= 0xe0000000 ) {
104 above_4g_mem_size
= ram_size
- 0xe0000000;
105 below_4g_mem_size
= 0xe0000000;
107 above_4g_mem_size
= 0;
108 below_4g_mem_size
= ram_size
;
111 /* allocate ram and load rom/bios */
112 if (!xen_enabled()) {
113 pc_memory_init(system_memory
,
114 kernel_filename
, kernel_cmdline
, initrd_filename
,
115 below_4g_mem_size
, above_4g_mem_size
);
118 if (!xen_enabled()) {
119 cpu_irq
= pc_allocate_cpu_irq();
120 i8259
= i8259_init(cpu_irq
[0]);
122 i8259
= xen_interrupt_controller_init();
124 isa_irq_state
= qemu_mallocz(sizeof(*isa_irq_state
));
125 isa_irq_state
->i8259
= i8259
;
127 ioapic_init(isa_irq_state
);
129 isa_irq
= qemu_allocate_irqs(isa_irq_handler
, isa_irq_state
, 24);
132 pci_bus
= i440fx_init(&i440fx_state
, &piix3_devfn
, isa_irq
,
133 system_memory
, system_io
, ram_size
);
139 isa_bus_irqs(isa_irq
);
141 pc_register_ferr_irq(isa_get_irq(13));
143 pc_vga_init(pci_enabled
? pci_bus
: NULL
);
146 pci_create_simple(pci_bus
, -1, "xen-platform");
149 /* init basic PC hardware */
150 pc_basic_device_init(isa_irq
, &rtc_state
, xen_enabled());
152 for(i
= 0; i
< nb_nics
; i
++) {
153 NICInfo
*nd
= &nd_table
[i
];
155 if (!pci_enabled
|| (nd
->model
&& strcmp(nd
->model
, "ne2k_isa") == 0))
156 pc_init_ne2k_isa(nd
);
158 pci_nic_init_nofail(nd
, "e1000", NULL
);
161 ide_drive_get(hd
, MAX_IDE_BUS
);
165 dev
= pci_piix3_xen_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
167 dev
= pci_piix3_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
169 idebus
[0] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
170 idebus
[1] = qdev_get_child_bus(&dev
->qdev
, "ide.1");
172 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
174 dev
= isa_ide_init(ide_iobase
[i
], ide_iobase2
[i
], ide_irq
[i
],
175 hd
[MAX_IDE_DEVS
* i
], hd
[MAX_IDE_DEVS
* i
+ 1]);
176 idebus
[i
] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
180 audio_init(isa_irq
, pci_enabled
? pci_bus
: NULL
);
182 pc_cmos_init(below_4g_mem_size
, above_4g_mem_size
, boot_device
,
183 idebus
[0], idebus
[1], rtc_state
);
185 if (pci_enabled
&& usb_enabled
) {
186 usb_uhci_piix3_init(pci_bus
, piix3_devfn
+ 2);
189 if (pci_enabled
&& acpi_enabled
) {
192 if (!xen_enabled()) {
193 cmos_s3
= qemu_allocate_irqs(pc_cmos_set_s3_resume
, rtc_state
, 1);
195 cmos_s3
= qemu_allocate_irqs(xen_cmos_set_s3_resume
, rtc_state
, 1);
197 smi_irq
= qemu_allocate_irqs(pc_acpi_smi_interrupt
, first_cpu
, 1);
198 /* TODO: Populate SPD eeprom data. */
199 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
200 isa_get_irq(9), *cmos_s3
, *smi_irq
,
202 smbus_eeprom_init(smbus
, 8, NULL
, 0);
206 i440fx_init_memory_mappings(i440fx_state
);
210 pc_pci_device_init(pci_bus
);
214 static void pc_init_pci(ram_addr_t ram_size
,
215 const char *boot_device
,
216 const char *kernel_filename
,
217 const char *kernel_cmdline
,
218 const char *initrd_filename
,
219 const char *cpu_model
)
221 pc_init1(get_system_memory(),
223 ram_size
, boot_device
,
224 kernel_filename
, kernel_cmdline
,
225 initrd_filename
, cpu_model
, 1, 1);
228 static void pc_init_pci_no_kvmclock(ram_addr_t ram_size
,
229 const char *boot_device
,
230 const char *kernel_filename
,
231 const char *kernel_cmdline
,
232 const char *initrd_filename
,
233 const char *cpu_model
)
235 pc_init1(get_system_memory(),
237 ram_size
, boot_device
,
238 kernel_filename
, kernel_cmdline
,
239 initrd_filename
, cpu_model
, 1, 0);
242 static void pc_init_isa(ram_addr_t ram_size
,
243 const char *boot_device
,
244 const char *kernel_filename
,
245 const char *kernel_cmdline
,
246 const char *initrd_filename
,
247 const char *cpu_model
)
249 if (cpu_model
== NULL
)
251 pc_init1(get_system_memory(),
253 ram_size
, boot_device
,
254 kernel_filename
, kernel_cmdline
,
255 initrd_filename
, cpu_model
, 0, 1);
259 static void pc_xen_hvm_init(ram_addr_t ram_size
,
260 const char *boot_device
,
261 const char *kernel_filename
,
262 const char *kernel_cmdline
,
263 const char *initrd_filename
,
264 const char *cpu_model
)
266 if (xen_hvm_init() != 0) {
267 hw_error("xen hardware virtual machine initialisation failed");
269 pc_init_pci_no_kvmclock(ram_size
, boot_device
,
270 kernel_filename
, kernel_cmdline
,
271 initrd_filename
, cpu_model
);
276 static QEMUMachine pc_machine
= {
279 .desc
= "Standard PC",
285 static QEMUMachine pc_machine_v0_13
= {
287 .desc
= "Standard PC",
288 .init
= pc_init_pci_no_kvmclock
,
290 .compat_props
= (GlobalProperty
[]) {
292 .driver
= "virtio-9p-pci",
293 .property
= "vectors",
294 .value
= stringify(0),
297 .property
= "rombar",
298 .value
= stringify(0),
300 .driver
= "vmware-svga",
301 .property
= "rombar",
302 .value
= stringify(0),
305 .property
= "command_serr_enable",
308 .driver
= "virtio-blk-pci",
309 .property
= "event_idx",
312 .driver
= "virtio-serial-pci",
313 .property
= "event_idx",
316 .driver
= "virtio-net-pci",
317 .property
= "event_idx",
320 { /* end of list */ }
324 static QEMUMachine pc_machine_v0_12
= {
326 .desc
= "Standard PC",
327 .init
= pc_init_pci_no_kvmclock
,
329 .compat_props
= (GlobalProperty
[]) {
331 .driver
= "virtio-serial-pci",
332 .property
= "max_ports",
333 .value
= stringify(1),
335 .driver
= "virtio-serial-pci",
336 .property
= "vectors",
337 .value
= stringify(0),
340 .property
= "rombar",
341 .value
= stringify(0),
343 .driver
= "vmware-svga",
344 .property
= "rombar",
345 .value
= stringify(0),
348 .property
= "command_serr_enable",
351 .driver
= "virtio-blk-pci",
352 .property
= "event_idx",
355 .driver
= "virtio-serial-pci",
356 .property
= "event_idx",
359 .driver
= "virtio-net-pci",
360 .property
= "event_idx",
363 { /* end of list */ }
367 static QEMUMachine pc_machine_v0_11
= {
369 .desc
= "Standard PC, qemu 0.11",
370 .init
= pc_init_pci_no_kvmclock
,
372 .compat_props
= (GlobalProperty
[]) {
374 .driver
= "virtio-blk-pci",
375 .property
= "vectors",
376 .value
= stringify(0),
378 .driver
= "virtio-serial-pci",
379 .property
= "max_ports",
380 .value
= stringify(1),
382 .driver
= "virtio-serial-pci",
383 .property
= "vectors",
384 .value
= stringify(0),
386 .driver
= "ide-drive",
390 .driver
= "scsi-disk",
395 .property
= "rombar",
396 .value
= stringify(0),
399 .property
= "command_serr_enable",
402 .driver
= "virtio-blk-pci",
403 .property
= "event_idx",
406 .driver
= "virtio-serial-pci",
407 .property
= "event_idx",
410 .driver
= "virtio-net-pci",
411 .property
= "event_idx",
414 { /* end of list */ }
418 static QEMUMachine pc_machine_v0_10
= {
420 .desc
= "Standard PC, qemu 0.10",
421 .init
= pc_init_pci_no_kvmclock
,
423 .compat_props
= (GlobalProperty
[]) {
425 .driver
= "virtio-blk-pci",
427 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
429 .driver
= "virtio-serial-pci",
431 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
433 .driver
= "virtio-serial-pci",
434 .property
= "max_ports",
435 .value
= stringify(1),
437 .driver
= "virtio-serial-pci",
438 .property
= "vectors",
439 .value
= stringify(0),
441 .driver
= "virtio-net-pci",
442 .property
= "vectors",
443 .value
= stringify(0),
445 .driver
= "virtio-blk-pci",
446 .property
= "vectors",
447 .value
= stringify(0),
449 .driver
= "ide-drive",
453 .driver
= "scsi-disk",
458 .property
= "rombar",
459 .value
= stringify(0),
462 .property
= "command_serr_enable",
465 .driver
= "virtio-blk-pci",
466 .property
= "event_idx",
469 .driver
= "virtio-serial-pci",
470 .property
= "event_idx",
473 .driver
= "virtio-net-pci",
474 .property
= "event_idx",
477 { /* end of list */ }
481 static QEMUMachine isapc_machine
= {
483 .desc
= "ISA-only PC",
489 static QEMUMachine xenfv_machine
= {
491 .desc
= "Xen Fully-virtualized PC",
492 .init
= pc_xen_hvm_init
,
493 .max_cpus
= HVM_MAX_VCPUS
,
494 .default_machine_opts
= "accel=xen",
498 static void pc_machine_init(void)
500 qemu_register_machine(&pc_machine
);
501 qemu_register_machine(&pc_machine_v0_13
);
502 qemu_register_machine(&pc_machine_v0_12
);
503 qemu_register_machine(&pc_machine_v0_11
);
504 qemu_register_machine(&pc_machine_v0_10
);
505 qemu_register_machine(&isapc_machine
);
507 qemu_register_machine(&xenfv_machine
);
511 machine_init(pc_machine_init
);