net: store guest timestamp in dump file instead of time since guest startup
[qemu/ar7.git] / hw / pc_piix.c
blobb9bb09d1e0c22fe07c13c31474e5867104f029fb
1 /*
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
22 * THE SOFTWARE.
25 #include <glib.h>
27 #include "hw.h"
28 #include "pc.h"
29 #include "apic.h"
30 #include "pci.h"
31 #include "usb-uhci.h"
32 #include "usb-ohci.h"
33 #include "net.h"
34 #include "boards.h"
35 #include "ide.h"
36 #include "kvm.h"
37 #include "kvmclock.h"
38 #include "sysemu.h"
39 #include "sysbus.h"
40 #include "arch_init.h"
41 #include "blockdev.h"
42 #include "smbus.h"
43 #include "xen.h"
44 #include "memory.h"
45 #include "exec-memory.h"
46 #ifdef CONFIG_XEN
47 # include <xen/hvm/hvm_info_table.h>
48 #endif
50 #define MAX_IDE_BUS 2
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)
58 DeviceState *dev;
59 SysBusDevice *d;
60 unsigned int i;
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,
75 ram_addr_t ram_size,
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,
81 int pci_enabled,
82 int kvmclock_enabled)
84 int i;
85 ram_addr_t below_4g_mem_size, above_4g_mem_size;
86 PCIBus *pci_bus;
87 PCII440FXState *i440fx_state;
88 int piix3_devfn = -1;
89 qemu_irq *cpu_irq;
90 qemu_irq *gsi;
91 qemu_irq *i8259;
92 qemu_irq *cmos_s3;
93 qemu_irq *smi_irq;
94 GSIState *gsi_state;
95 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
96 BusState *idebus[MAX_IDE_BUS];
97 ISADevice *rtc_state;
98 ISADevice *floppy;
99 MemoryRegion *ram_memory;
100 MemoryRegion *pci_memory;
101 MemoryRegion *rom_memory;
102 DeviceState *dev;
104 pc_cpus_init(cpu_model);
106 if (kvmclock_enabled) {
107 kvmclock_create();
110 if (ram_size >= 0xe0000000 ) {
111 above_4g_mem_size = ram_size - 0xe0000000;
112 below_4g_mem_size = 0xe0000000;
113 } else {
114 above_4g_mem_size = 0;
115 below_4g_mem_size = ram_size;
118 if (pci_enabled) {
119 pci_memory = g_new(MemoryRegion, 1);
120 memory_region_init(pci_memory, "pci", INT64_MAX);
121 rom_memory = pci_memory;
122 } else {
123 pci_memory = NULL;
124 rom_memory = system_memory;
127 /* allocate ram and load rom/bios */
128 if (!xen_enabled()) {
129 pc_memory_init(system_memory,
130 kernel_filename, kernel_cmdline, initrd_filename,
131 below_4g_mem_size, above_4g_mem_size,
132 pci_enabled ? rom_memory : system_memory, &ram_memory);
135 gsi_state = g_malloc0(sizeof(*gsi_state));
136 gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
138 if (pci_enabled) {
139 pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, gsi,
140 system_memory, system_io, ram_size,
141 below_4g_mem_size,
142 0x100000000ULL - below_4g_mem_size,
143 0x100000000ULL + above_4g_mem_size,
144 (sizeof(target_phys_addr_t) == 4
146 : ((uint64_t)1 << 62)),
147 pci_memory, ram_memory);
148 } else {
149 pci_bus = NULL;
150 i440fx_state = NULL;
151 isa_bus_new(NULL, system_io);
152 no_hpet = 1;
154 isa_bus_irqs(gsi);
156 if (!xen_enabled()) {
157 cpu_irq = pc_allocate_cpu_irq();
158 i8259 = i8259_init(cpu_irq[0]);
159 } else {
160 i8259 = xen_interrupt_controller_init();
163 for (i = 0; i < ISA_NUM_IRQS; i++) {
164 gsi_state->i8259_irq[i] = i8259[i];
166 if (pci_enabled) {
167 ioapic_init(gsi_state);
170 pc_register_ferr_irq(gsi[13]);
172 dev = pc_vga_init(pci_enabled? pci_bus: NULL);
173 if (dev) {
174 qdev_property_add_child(qdev_get_root(), "vga", dev, NULL);
177 if (xen_enabled()) {
178 pci_create_simple(pci_bus, -1, "xen-platform");
181 /* init basic PC hardware */
182 pc_basic_device_init(gsi, &rtc_state, &floppy, xen_enabled());
184 for(i = 0; i < nb_nics; i++) {
185 NICInfo *nd = &nd_table[i];
187 if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
188 pc_init_ne2k_isa(nd);
189 else
190 pci_nic_init_nofail(nd, "e1000", NULL);
193 ide_drive_get(hd, MAX_IDE_BUS);
194 if (pci_enabled) {
195 PCIDevice *dev;
196 if (xen_enabled()) {
197 dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
198 } else {
199 dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
201 idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
202 idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
203 } else {
204 for(i = 0; i < MAX_IDE_BUS; i++) {
205 ISADevice *dev;
206 dev = isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
207 hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
208 idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
212 /* FIXME there's some major spaghetti here. Somehow we create the devices
213 * on the PIIX before we actually create it. We create the PIIX3 deep in
214 * the recess of the i440fx creation too and then lose the DeviceState.
216 * For now, let's "fix" this by making judicious use of paths. This is not
217 * generally the right way to do this.
220 qdev_property_add_child(qdev_resolve_path("/i440fx/piix3", NULL),
221 "rtc", (DeviceState *)rtc_state, NULL);
223 audio_init(gsi, pci_enabled ? pci_bus : NULL);
225 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
226 floppy, idebus[0], idebus[1], rtc_state);
228 if (pci_enabled && usb_enabled) {
229 usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
232 if (pci_enabled && acpi_enabled) {
233 i2c_bus *smbus;
235 if (!xen_enabled()) {
236 cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
237 } else {
238 cmos_s3 = qemu_allocate_irqs(xen_cmos_set_s3_resume, rtc_state, 1);
240 smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
241 /* TODO: Populate SPD eeprom data. */
242 smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
243 gsi[9], *cmos_s3, *smi_irq,
244 kvm_enabled());
245 smbus_eeprom_init(smbus, 8, NULL, 0);
248 if (pci_enabled) {
249 pc_pci_device_init(pci_bus);
253 static void pc_init_pci(ram_addr_t ram_size,
254 const char *boot_device,
255 const char *kernel_filename,
256 const char *kernel_cmdline,
257 const char *initrd_filename,
258 const char *cpu_model)
260 pc_init1(get_system_memory(),
261 get_system_io(),
262 ram_size, boot_device,
263 kernel_filename, kernel_cmdline,
264 initrd_filename, cpu_model, 1, 1);
267 static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,
268 const char *boot_device,
269 const char *kernel_filename,
270 const char *kernel_cmdline,
271 const char *initrd_filename,
272 const char *cpu_model)
274 pc_init1(get_system_memory(),
275 get_system_io(),
276 ram_size, boot_device,
277 kernel_filename, kernel_cmdline,
278 initrd_filename, cpu_model, 1, 0);
281 static void pc_init_isa(ram_addr_t ram_size,
282 const char *boot_device,
283 const char *kernel_filename,
284 const char *kernel_cmdline,
285 const char *initrd_filename,
286 const char *cpu_model)
288 if (cpu_model == NULL)
289 cpu_model = "486";
290 pc_init1(get_system_memory(),
291 get_system_io(),
292 ram_size, boot_device,
293 kernel_filename, kernel_cmdline,
294 initrd_filename, cpu_model, 0, 1);
297 #ifdef CONFIG_XEN
298 static void pc_xen_hvm_init(ram_addr_t ram_size,
299 const char *boot_device,
300 const char *kernel_filename,
301 const char *kernel_cmdline,
302 const char *initrd_filename,
303 const char *cpu_model)
305 if (xen_hvm_init() != 0) {
306 hw_error("xen hardware virtual machine initialisation failed");
308 pc_init_pci_no_kvmclock(ram_size, boot_device,
309 kernel_filename, kernel_cmdline,
310 initrd_filename, cpu_model);
311 xen_vcpu_init();
313 #endif
315 static QEMUMachine pc_machine_v1_0 = {
316 .name = "pc-1.0",
317 .alias = "pc",
318 .desc = "Standard PC",
319 .init = pc_init_pci,
320 .max_cpus = 255,
321 .is_default = 1,
324 static QEMUMachine pc_machine_v0_15 = {
325 .name = "pc-0.15",
326 .desc = "Standard PC",
327 .init = pc_init_pci,
328 .max_cpus = 255,
329 .is_default = 1,
332 static QEMUMachine pc_machine_v0_14 = {
333 .name = "pc-0.14",
334 .desc = "Standard PC",
335 .init = pc_init_pci,
336 .max_cpus = 255,
337 .compat_props = (GlobalProperty[]) {
339 .driver = "qxl",
340 .property = "revision",
341 .value = stringify(2),
343 .driver = "qxl-vga",
344 .property = "revision",
345 .value = stringify(2),
347 .driver = "virtio-blk-pci",
348 .property = "event_idx",
349 .value = "off",
351 .driver = "virtio-serial-pci",
352 .property = "event_idx",
353 .value = "off",
355 .driver = "virtio-net-pci",
356 .property = "event_idx",
357 .value = "off",
359 .driver = "virtio-balloon-pci",
360 .property = "event_idx",
361 .value = "off",
363 { /* end of list */ }
367 static QEMUMachine pc_machine_v0_13 = {
368 .name = "pc-0.13",
369 .desc = "Standard PC",
370 .init = pc_init_pci_no_kvmclock,
371 .max_cpus = 255,
372 .compat_props = (GlobalProperty[]) {
374 .driver = "virtio-9p-pci",
375 .property = "vectors",
376 .value = stringify(0),
378 .driver = "VGA",
379 .property = "rombar",
380 .value = stringify(0),
382 .driver = "vmware-svga",
383 .property = "rombar",
384 .value = stringify(0),
386 .driver = "PCI",
387 .property = "command_serr_enable",
388 .value = "off",
390 .driver = "virtio-blk-pci",
391 .property = "event_idx",
392 .value = "off",
394 .driver = "virtio-serial-pci",
395 .property = "event_idx",
396 .value = "off",
398 .driver = "virtio-net-pci",
399 .property = "event_idx",
400 .value = "off",
402 .driver = "virtio-balloon-pci",
403 .property = "event_idx",
404 .value = "off",
406 .driver = "AC97",
407 .property = "use_broken_id",
408 .value = stringify(1),
410 { /* end of list */ }
414 static QEMUMachine pc_machine_v0_12 = {
415 .name = "pc-0.12",
416 .desc = "Standard PC",
417 .init = pc_init_pci_no_kvmclock,
418 .max_cpus = 255,
419 .compat_props = (GlobalProperty[]) {
421 .driver = "virtio-serial-pci",
422 .property = "max_ports",
423 .value = stringify(1),
425 .driver = "virtio-serial-pci",
426 .property = "vectors",
427 .value = stringify(0),
429 .driver = "VGA",
430 .property = "rombar",
431 .value = stringify(0),
433 .driver = "vmware-svga",
434 .property = "rombar",
435 .value = stringify(0),
437 .driver = "PCI",
438 .property = "command_serr_enable",
439 .value = "off",
441 .driver = "virtio-blk-pci",
442 .property = "event_idx",
443 .value = "off",
445 .driver = "virtio-serial-pci",
446 .property = "event_idx",
447 .value = "off",
449 .driver = "virtio-net-pci",
450 .property = "event_idx",
451 .value = "off",
453 .driver = "virtio-balloon-pci",
454 .property = "event_idx",
455 .value = "off",
457 .driver = "AC97",
458 .property = "use_broken_id",
459 .value = stringify(1),
461 { /* end of list */ }
465 static QEMUMachine pc_machine_v0_11 = {
466 .name = "pc-0.11",
467 .desc = "Standard PC, qemu 0.11",
468 .init = pc_init_pci_no_kvmclock,
469 .max_cpus = 255,
470 .compat_props = (GlobalProperty[]) {
472 .driver = "virtio-blk-pci",
473 .property = "vectors",
474 .value = stringify(0),
476 .driver = "virtio-serial-pci",
477 .property = "max_ports",
478 .value = stringify(1),
480 .driver = "virtio-serial-pci",
481 .property = "vectors",
482 .value = stringify(0),
484 .driver = "ide-drive",
485 .property = "ver",
486 .value = "0.11",
488 .driver = "scsi-disk",
489 .property = "ver",
490 .value = "0.11",
492 .driver = "PCI",
493 .property = "rombar",
494 .value = stringify(0),
496 .driver = "PCI",
497 .property = "command_serr_enable",
498 .value = "off",
500 .driver = "virtio-blk-pci",
501 .property = "event_idx",
502 .value = "off",
504 .driver = "virtio-serial-pci",
505 .property = "event_idx",
506 .value = "off",
508 .driver = "virtio-net-pci",
509 .property = "event_idx",
510 .value = "off",
512 .driver = "virtio-balloon-pci",
513 .property = "event_idx",
514 .value = "off",
516 .driver = "AC97",
517 .property = "use_broken_id",
518 .value = stringify(1),
520 { /* end of list */ }
524 static QEMUMachine pc_machine_v0_10 = {
525 .name = "pc-0.10",
526 .desc = "Standard PC, qemu 0.10",
527 .init = pc_init_pci_no_kvmclock,
528 .max_cpus = 255,
529 .compat_props = (GlobalProperty[]) {
531 .driver = "virtio-blk-pci",
532 .property = "class",
533 .value = stringify(PCI_CLASS_STORAGE_OTHER),
535 .driver = "virtio-serial-pci",
536 .property = "class",
537 .value = stringify(PCI_CLASS_DISPLAY_OTHER),
539 .driver = "virtio-serial-pci",
540 .property = "max_ports",
541 .value = stringify(1),
543 .driver = "virtio-serial-pci",
544 .property = "vectors",
545 .value = stringify(0),
547 .driver = "virtio-net-pci",
548 .property = "vectors",
549 .value = stringify(0),
551 .driver = "virtio-blk-pci",
552 .property = "vectors",
553 .value = stringify(0),
555 .driver = "ide-drive",
556 .property = "ver",
557 .value = "0.10",
559 .driver = "scsi-disk",
560 .property = "ver",
561 .value = "0.10",
563 .driver = "PCI",
564 .property = "rombar",
565 .value = stringify(0),
567 .driver = "PCI",
568 .property = "command_serr_enable",
569 .value = "off",
571 .driver = "virtio-blk-pci",
572 .property = "event_idx",
573 .value = "off",
575 .driver = "virtio-serial-pci",
576 .property = "event_idx",
577 .value = "off",
579 .driver = "virtio-net-pci",
580 .property = "event_idx",
581 .value = "off",
583 .driver = "virtio-balloon-pci",
584 .property = "event_idx",
585 .value = "off",
587 .driver = "AC97",
588 .property = "use_broken_id",
589 .value = stringify(1),
591 { /* end of list */ }
595 static QEMUMachine isapc_machine = {
596 .name = "isapc",
597 .desc = "ISA-only PC",
598 .init = pc_init_isa,
599 .max_cpus = 1,
602 #ifdef CONFIG_XEN
603 static QEMUMachine xenfv_machine = {
604 .name = "xenfv",
605 .desc = "Xen Fully-virtualized PC",
606 .init = pc_xen_hvm_init,
607 .max_cpus = HVM_MAX_VCPUS,
608 .default_machine_opts = "accel=xen",
610 #endif
612 static void pc_machine_init(void)
614 qemu_register_machine(&pc_machine_v1_0);
615 qemu_register_machine(&pc_machine_v0_15);
616 qemu_register_machine(&pc_machine_v0_14);
617 qemu_register_machine(&pc_machine_v0_13);
618 qemu_register_machine(&pc_machine_v0_12);
619 qemu_register_machine(&pc_machine_v0_11);
620 qemu_register_machine(&pc_machine_v0_10);
621 qemu_register_machine(&isapc_machine);
622 #ifdef CONFIG_XEN
623 qemu_register_machine(&xenfv_machine);
624 #endif
627 machine_init(pc_machine_init);