]> git.proxmox.com Git - mirror_qemu.git/blame - hw/pc_piix.c
net: store guest timestamp in dump file instead of time since guest startup
[mirror_qemu.git] / hw / pc_piix.c
CommitLineData
845773ab
IY
1/*
2 * QEMU PC System Emulator
3 *
4 * Copyright (c) 2003-2004 Fabrice Bellard
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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.
23 */
24
ae0a5466
AK
25#include <glib.h>
26
845773ab
IY
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"
0ec329da 37#include "kvmclock.h"
666daa68 38#include "sysemu.h"
96051119 39#include "sysbus.h"
0dfa5ef9 40#include "arch_init.h"
2446333c 41#include "blockdev.h"
a88df0b9 42#include "smbus.h"
29d3ccde 43#include "xen.h"
4aa63af1
AK
44#include "memory.h"
45#include "exec-memory.h"
29d3ccde
AP
46#ifdef CONFIG_XEN
47# include <xen/hvm/hvm_info_table.h>
48#endif
845773ab
IY
49
50#define MAX_IDE_BUS 2
51
52static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
53static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
54static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
55
b881fbe9 56static void ioapic_init(GSIState *gsi_state)
96051119
BS
57{
58 DeviceState *dev;
59 SysBusDevice *d;
60 unsigned int i;
61
62 dev = qdev_create(NULL, "ioapic");
63 qdev_init_nofail(dev);
64 d = sysbus_from_qdev(dev);
65 sysbus_mmio_map(d, 0, 0xfec00000);
66
67 for (i = 0; i < IOAPIC_NUM_PINS; i++) {
b881fbe9 68 gsi_state->ioapic_irq[i] = qdev_get_gpio_in(dev, i);
96051119
BS
69 }
70}
71
845773ab 72/* PC hardware initialisation */
6bd10515 73static void pc_init1(MemoryRegion *system_memory,
aee97b84 74 MemoryRegion *system_io,
6bd10515 75 ram_addr_t ram_size,
845773ab
IY
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,
0ec329da
JK
81 int pci_enabled,
82 int kvmclock_enabled)
845773ab
IY
83{
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;
b881fbe9 90 qemu_irq *gsi;
845773ab
IY
91 qemu_irq *i8259;
92 qemu_irq *cmos_s3;
93 qemu_irq *smi_irq;
b881fbe9 94 GSIState *gsi_state;
845773ab 95 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
c0897e0c 96 BusState *idebus[MAX_IDE_BUS];
1d914fa0 97 ISADevice *rtc_state;
34d4260e 98 ISADevice *floppy;
ae0a5466
AK
99 MemoryRegion *ram_memory;
100 MemoryRegion *pci_memory;
4463aee6 101 MemoryRegion *rom_memory;
ad6d45fa 102 DeviceState *dev;
845773ab
IY
103
104 pc_cpus_init(cpu_model);
105
0ec329da
JK
106 if (kvmclock_enabled) {
107 kvmclock_create();
108 }
109
e0e7e67b
AP
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;
116 }
117
4463aee6
JK
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;
125 }
ae0a5466 126
845773ab 127 /* allocate ram and load rom/bios */
29d3ccde 128 if (!xen_enabled()) {
4aa63af1
AK
129 pc_memory_init(system_memory,
130 kernel_filename, kernel_cmdline, initrd_filename,
ae0a5466 131 below_4g_mem_size, above_4g_mem_size,
c1d23eac 132 pci_enabled ? rom_memory : system_memory, &ram_memory);
29d3ccde 133 }
845773ab 134
b881fbe9
JK
135 gsi_state = g_malloc0(sizeof(*gsi_state));
136 gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
845773ab
IY
137
138 if (pci_enabled) {
b881fbe9 139 pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, gsi,
ae0a5466
AK
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
145 ? 0
146 : ((uint64_t)1 << 62)),
147 pci_memory, ram_memory);
845773ab
IY
148 } else {
149 pci_bus = NULL;
02a89b21 150 i440fx_state = NULL;
c2d0d012 151 isa_bus_new(NULL, system_io);
57285cc3 152 no_hpet = 1;
845773ab 153 }
b881fbe9 154 isa_bus_irqs(gsi);
845773ab 155
4bae1efe
RH
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();
161 }
162
43a0db35
JK
163 for (i = 0; i < ISA_NUM_IRQS; i++) {
164 gsi_state->i8259_irq[i] = i8259[i];
165 }
4bae1efe 166 if (pci_enabled) {
b881fbe9 167 ioapic_init(gsi_state);
4bae1efe
RH
168 }
169
b881fbe9 170 pc_register_ferr_irq(gsi[13]);
845773ab 171
ad6d45fa
AL
172 dev = pc_vga_init(pci_enabled? pci_bus: NULL);
173 if (dev) {
174 qdev_property_add_child(qdev_get_root(), "vga", dev, NULL);
175 }
845773ab 176
01195b73
SS
177 if (xen_enabled()) {
178 pci_create_simple(pci_bus, -1, "xen-platform");
179 }
180
845773ab 181 /* init basic PC hardware */
34d4260e 182 pc_basic_device_init(gsi, &rtc_state, &floppy, xen_enabled());
845773ab
IY
183
184 for(i = 0; i < nb_nics; i++) {
185 NICInfo *nd = &nd_table[i];
186
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);
191 }
192
75717903 193 ide_drive_get(hd, MAX_IDE_BUS);
845773ab 194 if (pci_enabled) {
c0897e0c 195 PCIDevice *dev;
679f4f8b
SS
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);
200 }
c0897e0c
MA
201 idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
202 idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
845773ab
IY
203 } else {
204 for(i = 0; i < MAX_IDE_BUS; i++) {
c0897e0c
MA
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");
845773ab
IY
209 }
210 }
211
d0c5be58
AL
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.
215 *
216 * For now, let's "fix" this by making judicious use of paths. This is not
217 * generally the right way to do this.
218 */
219
220 qdev_property_add_child(qdev_resolve_path("/i440fx/piix3", NULL),
221 "rtc", (DeviceState *)rtc_state, NULL);
222
b881fbe9 223 audio_init(gsi, pci_enabled ? pci_bus : NULL);
845773ab 224
c0897e0c 225 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
34d4260e 226 floppy, idebus[0], idebus[1], rtc_state);
845773ab
IY
227
228 if (pci_enabled && usb_enabled) {
229 usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
230 }
231
232 if (pci_enabled && acpi_enabled) {
845773ab
IY
233 i2c_bus *smbus;
234
c9622478
AP
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);
239 }
845773ab
IY
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,
b881fbe9 243 gsi[9], *cmos_s3, *smi_irq,
845773ab 244 kvm_enabled());
a88df0b9 245 smbus_eeprom_init(smbus, 8, NULL, 0);
845773ab
IY
246 }
247
845773ab
IY
248 if (pci_enabled) {
249 pc_pci_device_init(pci_bus);
250 }
251}
252
253static 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)
259{
6bd10515 260 pc_init1(get_system_memory(),
aee97b84 261 get_system_io(),
6bd10515 262 ram_size, boot_device,
845773ab 263 kernel_filename, kernel_cmdline,
0ec329da
JK
264 initrd_filename, cpu_model, 1, 1);
265}
266
267static 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)
273{
6bd10515 274 pc_init1(get_system_memory(),
aee97b84 275 get_system_io(),
6bd10515 276 ram_size, boot_device,
0ec329da
JK
277 kernel_filename, kernel_cmdline,
278 initrd_filename, cpu_model, 1, 0);
845773ab
IY
279}
280
281static 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)
287{
288 if (cpu_model == NULL)
289 cpu_model = "486";
6bd10515 290 pc_init1(get_system_memory(),
aee97b84 291 get_system_io(),
6bd10515 292 ram_size, boot_device,
845773ab 293 kernel_filename, kernel_cmdline,
0ec329da 294 initrd_filename, cpu_model, 0, 1);
845773ab
IY
295}
296
29d3ccde
AP
297#ifdef CONFIG_XEN
298static 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)
304{
305 if (xen_hvm_init() != 0) {
306 hw_error("xen hardware virtual machine initialisation failed");
307 }
308 pc_init_pci_no_kvmclock(ram_size, boot_device,
309 kernel_filename, kernel_cmdline,
310 initrd_filename, cpu_model);
311 xen_vcpu_init();
312}
313#endif
314
19857e62
GH
315static QEMUMachine pc_machine_v1_0 = {
316 .name = "pc-1.0",
845773ab
IY
317 .alias = "pc",
318 .desc = "Standard PC",
319 .init = pc_init_pci,
320 .max_cpus = 255,
321 .is_default = 1,
322};
323
ce01a508
AL
324static 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,
330};
331
19857e62
GH
332static QEMUMachine pc_machine_v0_14 = {
333 .name = "pc-0.14",
334 .desc = "Standard PC",
335 .init = pc_init_pci,
336 .max_cpus = 255,
3827cdb1
AL
337 .compat_props = (GlobalProperty[]) {
338 {
339 .driver = "qxl",
340 .property = "revision",
341 .value = stringify(2),
342 },{
343 .driver = "qxl-vga",
344 .property = "revision",
345 .value = stringify(2),
ea830ebb
AL
346 },{
347 .driver = "virtio-blk-pci",
348 .property = "event_idx",
349 .value = "off",
350 },{
351 .driver = "virtio-serial-pci",
352 .property = "event_idx",
353 .value = "off",
354 },{
355 .driver = "virtio-net-pci",
356 .property = "event_idx",
357 .value = "off",
358 },{
359 .driver = "virtio-balloon-pci",
360 .property = "event_idx",
361 .value = "off",
3827cdb1
AL
362 },
363 { /* end of list */ }
364 },
19857e62
GH
365};
366
b903a0f7
GH
367static QEMUMachine pc_machine_v0_13 = {
368 .name = "pc-0.13",
369 .desc = "Standard PC",
0ec329da 370 .init = pc_init_pci_no_kvmclock,
b903a0f7 371 .max_cpus = 255,
9dbcca5a
GH
372 .compat_props = (GlobalProperty[]) {
373 {
374 .driver = "virtio-9p-pci",
375 .property = "vectors",
376 .value = stringify(0),
281a26b1
GH
377 },{
378 .driver = "VGA",
379 .property = "rombar",
380 .value = stringify(0),
381 },{
382 .driver = "vmware-svga",
383 .property = "rombar",
384 .value = stringify(0),
362dd48c
IY
385 },{
386 .driver = "PCI",
387 .property = "command_serr_enable",
388 .value = "off",
b91cb442
MT
389 },{
390 .driver = "virtio-blk-pci",
391 .property = "event_idx",
392 .value = "off",
393 },{
394 .driver = "virtio-serial-pci",
395 .property = "event_idx",
396 .value = "off",
397 },{
398 .driver = "virtio-net-pci",
399 .property = "event_idx",
400 .value = "off",
ea830ebb
AL
401 },{
402 .driver = "virtio-balloon-pci",
403 .property = "event_idx",
404 .value = "off",
25a21c94
GH
405 },{
406 .driver = "AC97",
407 .property = "use_broken_id",
408 .value = stringify(1),
9dbcca5a
GH
409 },
410 { /* end of list */ }
411 },
b903a0f7
GH
412};
413
845773ab
IY
414static QEMUMachine pc_machine_v0_12 = {
415 .name = "pc-0.12",
416 .desc = "Standard PC",
0ec329da 417 .init = pc_init_pci_no_kvmclock,
845773ab
IY
418 .max_cpus = 255,
419 .compat_props = (GlobalProperty[]) {
420 {
421 .driver = "virtio-serial-pci",
1e29a009 422 .property = "max_ports",
845773ab
IY
423 .value = stringify(1),
424 },{
425 .driver = "virtio-serial-pci",
426 .property = "vectors",
427 .value = stringify(0),
281a26b1
GH
428 },{
429 .driver = "VGA",
430 .property = "rombar",
431 .value = stringify(0),
432 },{
433 .driver = "vmware-svga",
434 .property = "rombar",
435 .value = stringify(0),
b1aeb926
IY
436 },{
437 .driver = "PCI",
438 .property = "command_serr_enable",
439 .value = "off",
b91cb442
MT
440 },{
441 .driver = "virtio-blk-pci",
442 .property = "event_idx",
443 .value = "off",
444 },{
445 .driver = "virtio-serial-pci",
446 .property = "event_idx",
447 .value = "off",
448 },{
449 .driver = "virtio-net-pci",
450 .property = "event_idx",
451 .value = "off",
ea830ebb
AL
452 },{
453 .driver = "virtio-balloon-pci",
454 .property = "event_idx",
455 .value = "off",
25a21c94
GH
456 },{
457 .driver = "AC97",
458 .property = "use_broken_id",
459 .value = stringify(1),
845773ab
IY
460 },
461 { /* end of list */ }
462 }
463};
464
465static QEMUMachine pc_machine_v0_11 = {
466 .name = "pc-0.11",
467 .desc = "Standard PC, qemu 0.11",
0ec329da 468 .init = pc_init_pci_no_kvmclock,
845773ab
IY
469 .max_cpus = 255,
470 .compat_props = (GlobalProperty[]) {
471 {
472 .driver = "virtio-blk-pci",
473 .property = "vectors",
474 .value = stringify(0),
475 },{
476 .driver = "virtio-serial-pci",
1e29a009 477 .property = "max_ports",
845773ab
IY
478 .value = stringify(1),
479 },{
480 .driver = "virtio-serial-pci",
481 .property = "vectors",
482 .value = stringify(0),
483 },{
484 .driver = "ide-drive",
485 .property = "ver",
486 .value = "0.11",
487 },{
488 .driver = "scsi-disk",
489 .property = "ver",
490 .value = "0.11",
491 },{
492 .driver = "PCI",
493 .property = "rombar",
494 .value = stringify(0),
b1aeb926
IY
495 },{
496 .driver = "PCI",
497 .property = "command_serr_enable",
498 .value = "off",
b91cb442
MT
499 },{
500 .driver = "virtio-blk-pci",
501 .property = "event_idx",
502 .value = "off",
503 },{
504 .driver = "virtio-serial-pci",
505 .property = "event_idx",
506 .value = "off",
507 },{
508 .driver = "virtio-net-pci",
509 .property = "event_idx",
510 .value = "off",
ea830ebb
AL
511 },{
512 .driver = "virtio-balloon-pci",
513 .property = "event_idx",
514 .value = "off",
25a21c94
GH
515 },{
516 .driver = "AC97",
517 .property = "use_broken_id",
518 .value = stringify(1),
845773ab
IY
519 },
520 { /* end of list */ }
521 }
522};
523
524static QEMUMachine pc_machine_v0_10 = {
525 .name = "pc-0.10",
526 .desc = "Standard PC, qemu 0.10",
0ec329da 527 .init = pc_init_pci_no_kvmclock,
845773ab
IY
528 .max_cpus = 255,
529 .compat_props = (GlobalProperty[]) {
530 {
531 .driver = "virtio-blk-pci",
532 .property = "class",
533 .value = stringify(PCI_CLASS_STORAGE_OTHER),
534 },{
535 .driver = "virtio-serial-pci",
536 .property = "class",
537 .value = stringify(PCI_CLASS_DISPLAY_OTHER),
538 },{
539 .driver = "virtio-serial-pci",
1e29a009 540 .property = "max_ports",
845773ab
IY
541 .value = stringify(1),
542 },{
543 .driver = "virtio-serial-pci",
544 .property = "vectors",
545 .value = stringify(0),
546 },{
547 .driver = "virtio-net-pci",
548 .property = "vectors",
549 .value = stringify(0),
550 },{
551 .driver = "virtio-blk-pci",
552 .property = "vectors",
553 .value = stringify(0),
554 },{
555 .driver = "ide-drive",
556 .property = "ver",
557 .value = "0.10",
558 },{
559 .driver = "scsi-disk",
560 .property = "ver",
561 .value = "0.10",
562 },{
563 .driver = "PCI",
564 .property = "rombar",
565 .value = stringify(0),
b1aeb926
IY
566 },{
567 .driver = "PCI",
568 .property = "command_serr_enable",
569 .value = "off",
b91cb442
MT
570 },{
571 .driver = "virtio-blk-pci",
572 .property = "event_idx",
573 .value = "off",
574 },{
575 .driver = "virtio-serial-pci",
576 .property = "event_idx",
577 .value = "off",
578 },{
579 .driver = "virtio-net-pci",
580 .property = "event_idx",
581 .value = "off",
ea830ebb
AL
582 },{
583 .driver = "virtio-balloon-pci",
584 .property = "event_idx",
585 .value = "off",
25a21c94
GH
586 },{
587 .driver = "AC97",
588 .property = "use_broken_id",
589 .value = stringify(1),
845773ab
IY
590 },
591 { /* end of list */ }
592 },
593};
594
595static QEMUMachine isapc_machine = {
596 .name = "isapc",
597 .desc = "ISA-only PC",
598 .init = pc_init_isa,
599 .max_cpus = 1,
600};
601
29d3ccde
AP
602#ifdef CONFIG_XEN
603static 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",
609};
610#endif
611
845773ab
IY
612static void pc_machine_init(void)
613{
19857e62 614 qemu_register_machine(&pc_machine_v1_0);
ce01a508 615 qemu_register_machine(&pc_machine_v0_15);
19857e62 616 qemu_register_machine(&pc_machine_v0_14);
b903a0f7 617 qemu_register_machine(&pc_machine_v0_13);
845773ab
IY
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);
29d3ccde
AP
622#ifdef CONFIG_XEN
623 qemu_register_machine(&xenfv_machine);
624#endif
845773ab
IY
625}
626
627machine_init(pc_machine_init);