acpi: move declarations from pc.h to acpi.h
[qemu/ar7.git] / hw / i386 / pc_piix.c
blob943758ad30ea961e3332b8262f6d38c02d2b1acc
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/hw.h"
28 #include "hw/i386/pc.h"
29 #include "hw/i386/apic.h"
30 #include "hw/pci/pci.h"
31 #include "hw/pci/pci_ids.h"
32 #include "hw/usb.h"
33 #include "net/net.h"
34 #include "hw/boards.h"
35 #include "hw/ide.h"
36 #include "sysemu/kvm.h"
37 #include "hw/kvm/clock.h"
38 #include "sysemu/sysemu.h"
39 #include "hw/sysbus.h"
40 #include "sysemu/arch_init.h"
41 #include "sysemu/blockdev.h"
42 #include "hw/i2c/smbus.h"
43 #include "hw/xen/xen.h"
44 #include "exec/memory.h"
45 #include "exec/address-spaces.h"
46 #include "hw/acpi/acpi.h"
47 #include "cpu.h"
48 #ifdef CONFIG_XEN
49 # include <xen/hvm/hvm_info_table.h>
50 #endif
52 #define MAX_IDE_BUS 2
54 static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
55 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
56 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
58 /* PC hardware initialisation */
59 static void pc_init1(MemoryRegion *system_memory,
60 MemoryRegion *system_io,
61 ram_addr_t ram_size,
62 const char *boot_device,
63 const char *kernel_filename,
64 const char *kernel_cmdline,
65 const char *initrd_filename,
66 const char *cpu_model,
67 int pci_enabled,
68 int kvmclock_enabled)
70 int i;
71 ram_addr_t below_4g_mem_size, above_4g_mem_size;
72 PCIBus *pci_bus;
73 ISABus *isa_bus;
74 PCII440FXState *i440fx_state;
75 int piix3_devfn = -1;
76 qemu_irq *cpu_irq;
77 qemu_irq *gsi;
78 qemu_irq *i8259;
79 qemu_irq *smi_irq;
80 GSIState *gsi_state;
81 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
82 BusState *idebus[MAX_IDE_BUS];
83 ISADevice *rtc_state;
84 ISADevice *floppy;
85 MemoryRegion *ram_memory;
86 MemoryRegion *pci_memory;
87 MemoryRegion *rom_memory;
88 void *fw_cfg = NULL;
90 pc_cpus_init(cpu_model);
91 pc_acpi_init("acpi-dsdt.aml");
93 if (kvmclock_enabled) {
94 kvmclock_create();
97 if (ram_size >= 0xe0000000 ) {
98 above_4g_mem_size = ram_size - 0xe0000000;
99 below_4g_mem_size = 0xe0000000;
100 } else {
101 above_4g_mem_size = 0;
102 below_4g_mem_size = ram_size;
105 if (pci_enabled) {
106 pci_memory = g_new(MemoryRegion, 1);
107 memory_region_init(pci_memory, "pci", INT64_MAX);
108 rom_memory = pci_memory;
109 } else {
110 pci_memory = NULL;
111 rom_memory = system_memory;
114 /* allocate ram and load rom/bios */
115 if (!xen_enabled()) {
116 fw_cfg = pc_memory_init(system_memory,
117 kernel_filename, kernel_cmdline, initrd_filename,
118 below_4g_mem_size, above_4g_mem_size,
119 rom_memory, &ram_memory);
122 gsi_state = g_malloc0(sizeof(*gsi_state));
123 if (kvm_irqchip_in_kernel()) {
124 kvm_pc_setup_irq_routing(pci_enabled);
125 gsi = qemu_allocate_irqs(kvm_pc_gsi_handler, gsi_state,
126 GSI_NUM_PINS);
127 } else {
128 gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
131 if (pci_enabled) {
132 pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, &isa_bus, gsi,
133 system_memory, system_io, ram_size,
134 below_4g_mem_size,
135 0x100000000ULL - below_4g_mem_size,
136 0x100000000ULL + above_4g_mem_size,
137 (sizeof(hwaddr) == 4
139 : ((uint64_t)1 << 62)),
140 pci_memory, ram_memory);
141 } else {
142 pci_bus = NULL;
143 i440fx_state = NULL;
144 isa_bus = isa_bus_new(NULL, system_io);
145 no_hpet = 1;
147 isa_bus_irqs(isa_bus, gsi);
149 if (kvm_irqchip_in_kernel()) {
150 i8259 = kvm_i8259_init(isa_bus);
151 } else if (xen_enabled()) {
152 i8259 = xen_interrupt_controller_init();
153 } else {
154 cpu_irq = pc_allocate_cpu_irq();
155 i8259 = i8259_init(isa_bus, cpu_irq[0]);
158 for (i = 0; i < ISA_NUM_IRQS; i++) {
159 gsi_state->i8259_irq[i] = i8259[i];
161 if (pci_enabled) {
162 ioapic_init_gsi(gsi_state, "i440fx");
165 pc_register_ferr_irq(gsi[13]);
167 pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
168 if (xen_enabled()) {
169 pci_create_simple(pci_bus, -1, "xen-platform");
172 /* init basic PC hardware */
173 pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy, xen_enabled());
175 pc_nic_init(isa_bus, pci_bus);
177 ide_drive_get(hd, MAX_IDE_BUS);
178 if (pci_enabled) {
179 PCIDevice *dev;
180 if (xen_enabled()) {
181 dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
182 } else {
183 dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
185 idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
186 idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
187 } else {
188 for(i = 0; i < MAX_IDE_BUS; i++) {
189 ISADevice *dev;
190 dev = isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i],
191 ide_irq[i],
192 hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
193 idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
197 audio_init(isa_bus, pci_enabled ? pci_bus : NULL);
199 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
200 floppy, idebus[0], idebus[1], rtc_state);
202 if (pci_enabled && usb_enabled(false)) {
203 pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
206 if (pci_enabled && acpi_enabled) {
207 i2c_bus *smbus;
209 smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt,
210 x86_env_get_cpu(first_cpu), 1);
211 /* TODO: Populate SPD eeprom data. */
212 smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
213 gsi[9], *smi_irq,
214 kvm_enabled(), fw_cfg);
215 smbus_eeprom_init(smbus, 8, NULL, 0);
218 if (pci_enabled) {
219 pc_pci_device_init(pci_bus);
223 static void pc_init_pci(QEMUMachineInitArgs *args)
225 ram_addr_t ram_size = args->ram_size;
226 const char *cpu_model = args->cpu_model;
227 const char *kernel_filename = args->kernel_filename;
228 const char *kernel_cmdline = args->kernel_cmdline;
229 const char *initrd_filename = args->initrd_filename;
230 const char *boot_device = args->boot_device;
231 pc_init1(get_system_memory(),
232 get_system_io(),
233 ram_size, boot_device,
234 kernel_filename, kernel_cmdline,
235 initrd_filename, cpu_model, 1, 1);
238 static void pc_init_pci_1_3(QEMUMachineInitArgs *args)
240 enable_compat_apic_id_mode();
241 pc_init_pci(args);
244 /* PC machine init function for pc-0.14 to pc-1.2 */
245 static void pc_init_pci_1_2(QEMUMachineInitArgs *args)
247 disable_kvm_pv_eoi();
248 pc_init_pci_1_3(args);
251 /* PC init function for pc-0.10 to pc-0.13, and reused by xenfv */
252 static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs *args)
254 ram_addr_t ram_size = args->ram_size;
255 const char *cpu_model = args->cpu_model;
256 const char *kernel_filename = args->kernel_filename;
257 const char *kernel_cmdline = args->kernel_cmdline;
258 const char *initrd_filename = args->initrd_filename;
259 const char *boot_device = args->boot_device;
260 disable_kvm_pv_eoi();
261 enable_compat_apic_id_mode();
262 pc_init1(get_system_memory(),
263 get_system_io(),
264 ram_size, boot_device,
265 kernel_filename, kernel_cmdline,
266 initrd_filename, cpu_model, 1, 0);
269 static void pc_init_isa(QEMUMachineInitArgs *args)
271 ram_addr_t ram_size = args->ram_size;
272 const char *cpu_model = args->cpu_model;
273 const char *kernel_filename = args->kernel_filename;
274 const char *kernel_cmdline = args->kernel_cmdline;
275 const char *initrd_filename = args->initrd_filename;
276 const char *boot_device = args->boot_device;
277 if (cpu_model == NULL)
278 cpu_model = "486";
279 disable_kvm_pv_eoi();
280 enable_compat_apic_id_mode();
281 pc_init1(get_system_memory(),
282 get_system_io(),
283 ram_size, boot_device,
284 kernel_filename, kernel_cmdline,
285 initrd_filename, cpu_model, 0, 1);
288 #ifdef CONFIG_XEN
289 static void pc_xen_hvm_init(QEMUMachineInitArgs *args)
291 if (xen_hvm_init() != 0) {
292 hw_error("xen hardware virtual machine initialisation failed");
294 pc_init_pci_no_kvmclock(args);
295 xen_vcpu_init();
297 #endif
299 static QEMUMachine pc_i440fx_machine_v1_5 = {
300 .name = "pc-i440fx-1.5",
301 .alias = "pc",
302 .desc = "Standard PC (i440FX + PIIX, 1996)",
303 .init = pc_init_pci,
304 .max_cpus = 255,
305 .is_default = 1,
306 DEFAULT_MACHINE_OPTIONS,
309 static QEMUMachine pc_i440fx_machine_v1_4 = {
310 .name = "pc-i440fx-1.4",
311 .desc = "Standard PC (i440FX + PIIX, 1996)",
312 .init = pc_init_pci,
313 .max_cpus = 255,
314 .compat_props = (GlobalProperty[]) {
315 PC_COMPAT_1_4,
316 { /* end of list */ }
318 DEFAULT_MACHINE_OPTIONS,
321 #define PC_COMPAT_1_3 \
322 PC_COMPAT_1_4, \
324 .driver = "usb-tablet",\
325 .property = "usb_version",\
326 .value = stringify(1),\
327 },{\
328 .driver = "virtio-net-pci",\
329 .property = "ctrl_mac_addr",\
330 .value = "off", \
331 },{ \
332 .driver = "virtio-net-pci", \
333 .property = "mq", \
334 .value = "off", \
335 }, {\
336 .driver = "e1000",\
337 .property = "autonegotiation",\
338 .value = "off",\
341 static QEMUMachine pc_machine_v1_3 = {
342 .name = "pc-1.3",
343 .desc = "Standard PC",
344 .init = pc_init_pci_1_3,
345 .max_cpus = 255,
346 .compat_props = (GlobalProperty[]) {
347 PC_COMPAT_1_3,
348 { /* end of list */ }
350 DEFAULT_MACHINE_OPTIONS,
353 #define PC_COMPAT_1_2 \
354 PC_COMPAT_1_3,\
356 .driver = "nec-usb-xhci",\
357 .property = "msi",\
358 .value = "off",\
359 },{\
360 .driver = "nec-usb-xhci",\
361 .property = "msix",\
362 .value = "off",\
363 },{\
364 .driver = "ivshmem",\
365 .property = "use64",\
366 .value = "0",\
367 },{\
368 .driver = "qxl",\
369 .property = "revision",\
370 .value = stringify(3),\
371 },{\
372 .driver = "qxl-vga",\
373 .property = "revision",\
374 .value = stringify(3),\
375 },{\
376 .driver = "VGA",\
377 .property = "mmio",\
378 .value = "off",\
381 static QEMUMachine pc_machine_v1_2 = {
382 .name = "pc-1.2",
383 .desc = "Standard PC",
384 .init = pc_init_pci_1_2,
385 .max_cpus = 255,
386 .compat_props = (GlobalProperty[]) {
387 PC_COMPAT_1_2,
388 { /* end of list */ }
390 DEFAULT_MACHINE_OPTIONS,
393 #define PC_COMPAT_1_1 \
394 PC_COMPAT_1_2,\
396 .driver = "virtio-scsi-pci",\
397 .property = "hotplug",\
398 .value = "off",\
399 },{\
400 .driver = "virtio-scsi-pci",\
401 .property = "param_change",\
402 .value = "off",\
403 },{\
404 .driver = "VGA",\
405 .property = "vgamem_mb",\
406 .value = stringify(8),\
407 },{\
408 .driver = "vmware-svga",\
409 .property = "vgamem_mb",\
410 .value = stringify(8),\
411 },{\
412 .driver = "qxl-vga",\
413 .property = "vgamem_mb",\
414 .value = stringify(8),\
415 },{\
416 .driver = "qxl",\
417 .property = "vgamem_mb",\
418 .value = stringify(8),\
419 },{\
420 .driver = "virtio-blk-pci",\
421 .property = "config-wce",\
422 .value = "off",\
425 static QEMUMachine pc_machine_v1_1 = {
426 .name = "pc-1.1",
427 .desc = "Standard PC",
428 .init = pc_init_pci_1_2,
429 .max_cpus = 255,
430 .compat_props = (GlobalProperty[]) {
431 PC_COMPAT_1_1,
432 { /* end of list */ }
434 DEFAULT_MACHINE_OPTIONS,
437 #define PC_COMPAT_1_0 \
438 PC_COMPAT_1_1,\
440 .driver = "pc-sysfw",\
441 .property = "rom_only",\
442 .value = stringify(1),\
443 }, {\
444 .driver = "isa-fdc",\
445 .property = "check_media_rate",\
446 .value = "off",\
447 }, {\
448 .driver = "virtio-balloon-pci",\
449 .property = "class",\
450 .value = stringify(PCI_CLASS_MEMORY_RAM),\
451 },{\
452 .driver = "apic",\
453 .property = "vapic",\
454 .value = "off",\
455 },{\
456 .driver = TYPE_USB_DEVICE,\
457 .property = "full-path",\
458 .value = "no",\
461 static QEMUMachine pc_machine_v1_0 = {
462 .name = "pc-1.0",
463 .desc = "Standard PC",
464 .init = pc_init_pci_1_2,
465 .max_cpus = 255,
466 .compat_props = (GlobalProperty[]) {
467 PC_COMPAT_1_0,
468 { /* end of list */ }
470 .hw_version = "1.0",
471 DEFAULT_MACHINE_OPTIONS,
474 #define PC_COMPAT_0_15 \
475 PC_COMPAT_1_0
477 static QEMUMachine pc_machine_v0_15 = {
478 .name = "pc-0.15",
479 .desc = "Standard PC",
480 .init = pc_init_pci_1_2,
481 .max_cpus = 255,
482 .compat_props = (GlobalProperty[]) {
483 PC_COMPAT_0_15,
484 { /* end of list */ }
486 .hw_version = "0.15",
487 DEFAULT_MACHINE_OPTIONS,
490 #define PC_COMPAT_0_14 \
491 PC_COMPAT_0_15,\
493 .driver = "virtio-blk-pci",\
494 .property = "event_idx",\
495 .value = "off",\
496 },{\
497 .driver = "virtio-serial-pci",\
498 .property = "event_idx",\
499 .value = "off",\
500 },{\
501 .driver = "virtio-net-pci",\
502 .property = "event_idx",\
503 .value = "off",\
504 },{\
505 .driver = "virtio-balloon-pci",\
506 .property = "event_idx",\
507 .value = "off",\
510 static QEMUMachine pc_machine_v0_14 = {
511 .name = "pc-0.14",
512 .desc = "Standard PC",
513 .init = pc_init_pci_1_2,
514 .max_cpus = 255,
515 .compat_props = (GlobalProperty[]) {
516 PC_COMPAT_0_14,
518 .driver = "qxl",
519 .property = "revision",
520 .value = stringify(2),
522 .driver = "qxl-vga",
523 .property = "revision",
524 .value = stringify(2),
526 { /* end of list */ }
528 .hw_version = "0.14",
529 DEFAULT_MACHINE_OPTIONS,
532 #define PC_COMPAT_0_13 \
533 PC_COMPAT_0_14,\
535 .driver = TYPE_PCI_DEVICE,\
536 .property = "command_serr_enable",\
537 .value = "off",\
538 },{\
539 .driver = "AC97",\
540 .property = "use_broken_id",\
541 .value = stringify(1),\
544 static QEMUMachine pc_machine_v0_13 = {
545 .name = "pc-0.13",
546 .desc = "Standard PC",
547 .init = pc_init_pci_no_kvmclock,
548 .max_cpus = 255,
549 .compat_props = (GlobalProperty[]) {
550 PC_COMPAT_0_13,
552 .driver = "virtio-9p-pci",
553 .property = "vectors",
554 .value = stringify(0),
556 .driver = "VGA",
557 .property = "rombar",
558 .value = stringify(0),
560 .driver = "vmware-svga",
561 .property = "rombar",
562 .value = stringify(0),
564 { /* end of list */ }
566 .hw_version = "0.13",
567 DEFAULT_MACHINE_OPTIONS,
570 #define PC_COMPAT_0_12 \
571 PC_COMPAT_0_13,\
573 .driver = "virtio-serial-pci",\
574 .property = "max_ports",\
575 .value = stringify(1),\
576 },{\
577 .driver = "virtio-serial-pci",\
578 .property = "vectors",\
579 .value = stringify(0),\
582 static QEMUMachine pc_machine_v0_12 = {
583 .name = "pc-0.12",
584 .desc = "Standard PC",
585 .init = pc_init_pci_no_kvmclock,
586 .max_cpus = 255,
587 .compat_props = (GlobalProperty[]) {
588 PC_COMPAT_0_12,
590 .driver = "VGA",
591 .property = "rombar",
592 .value = stringify(0),
594 .driver = "vmware-svga",
595 .property = "rombar",
596 .value = stringify(0),
598 { /* end of list */ }
600 .hw_version = "0.12",
601 DEFAULT_MACHINE_OPTIONS,
604 #define PC_COMPAT_0_11 \
605 PC_COMPAT_0_12,\
607 .driver = "virtio-blk-pci",\
608 .property = "vectors",\
609 .value = stringify(0),\
610 },{\
611 .driver = TYPE_PCI_DEVICE,\
612 .property = "rombar",\
613 .value = stringify(0),\
616 static QEMUMachine pc_machine_v0_11 = {
617 .name = "pc-0.11",
618 .desc = "Standard PC, qemu 0.11",
619 .init = pc_init_pci_no_kvmclock,
620 .max_cpus = 255,
621 .compat_props = (GlobalProperty[]) {
622 PC_COMPAT_0_11,
624 .driver = "ide-drive",
625 .property = "ver",
626 .value = "0.11",
628 .driver = "scsi-disk",
629 .property = "ver",
630 .value = "0.11",
632 { /* end of list */ }
634 .hw_version = "0.11",
635 DEFAULT_MACHINE_OPTIONS,
638 static QEMUMachine pc_machine_v0_10 = {
639 .name = "pc-0.10",
640 .desc = "Standard PC, qemu 0.10",
641 .init = pc_init_pci_no_kvmclock,
642 .max_cpus = 255,
643 .compat_props = (GlobalProperty[]) {
644 PC_COMPAT_0_11,
646 .driver = "virtio-blk-pci",
647 .property = "class",
648 .value = stringify(PCI_CLASS_STORAGE_OTHER),
650 .driver = "virtio-serial-pci",
651 .property = "class",
652 .value = stringify(PCI_CLASS_DISPLAY_OTHER),
654 .driver = "virtio-net-pci",
655 .property = "vectors",
656 .value = stringify(0),
658 .driver = "ide-drive",
659 .property = "ver",
660 .value = "0.10",
662 .driver = "scsi-disk",
663 .property = "ver",
664 .value = "0.10",
666 { /* end of list */ }
668 .hw_version = "0.10",
669 DEFAULT_MACHINE_OPTIONS,
672 static QEMUMachine isapc_machine = {
673 .name = "isapc",
674 .desc = "ISA-only PC",
675 .init = pc_init_isa,
676 .max_cpus = 1,
677 .compat_props = (GlobalProperty[]) {
679 .driver = "pc-sysfw",
680 .property = "rom_only",
681 .value = stringify(1),
683 { /* end of list */ }
685 DEFAULT_MACHINE_OPTIONS,
688 #ifdef CONFIG_XEN
689 static QEMUMachine xenfv_machine = {
690 .name = "xenfv",
691 .desc = "Xen Fully-virtualized PC",
692 .init = pc_xen_hvm_init,
693 .max_cpus = HVM_MAX_VCPUS,
694 .default_machine_opts = "accel=xen",
695 DEFAULT_MACHINE_OPTIONS,
697 #endif
699 static void pc_machine_init(void)
701 qemu_register_machine(&pc_i440fx_machine_v1_5);
702 qemu_register_machine(&pc_i440fx_machine_v1_4);
703 qemu_register_machine(&pc_machine_v1_3);
704 qemu_register_machine(&pc_machine_v1_2);
705 qemu_register_machine(&pc_machine_v1_1);
706 qemu_register_machine(&pc_machine_v1_0);
707 qemu_register_machine(&pc_machine_v0_15);
708 qemu_register_machine(&pc_machine_v0_14);
709 qemu_register_machine(&pc_machine_v0_13);
710 qemu_register_machine(&pc_machine_v0_12);
711 qemu_register_machine(&pc_machine_v0_11);
712 qemu_register_machine(&pc_machine_v0_10);
713 qemu_register_machine(&isapc_machine);
714 #ifdef CONFIG_XEN
715 qemu_register_machine(&xenfv_machine);
716 #endif
719 machine_init(pc_machine_init);