audio: look for the ISA and PCI buses
[qemu/ar7.git] / hw / i386 / pc_piix.c
blobda91e7065d202c517d746a6c0a148ca1d397c992
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);
92 if (kvmclock_enabled) {
93 kvmclock_create();
96 if (ram_size >= 0xe0000000 ) {
97 above_4g_mem_size = ram_size - 0xe0000000;
98 below_4g_mem_size = 0xe0000000;
99 } else {
100 above_4g_mem_size = 0;
101 below_4g_mem_size = ram_size;
104 if (pci_enabled) {
105 pci_memory = g_new(MemoryRegion, 1);
106 memory_region_init(pci_memory, "pci", INT64_MAX);
107 rom_memory = pci_memory;
108 } else {
109 pci_memory = NULL;
110 rom_memory = system_memory;
113 /* allocate ram and load rom/bios */
114 if (!xen_enabled()) {
115 fw_cfg = pc_memory_init(system_memory,
116 kernel_filename, kernel_cmdline, initrd_filename,
117 below_4g_mem_size, above_4g_mem_size,
118 rom_memory, &ram_memory);
121 gsi_state = g_malloc0(sizeof(*gsi_state));
122 if (kvm_irqchip_in_kernel()) {
123 kvm_pc_setup_irq_routing(pci_enabled);
124 gsi = qemu_allocate_irqs(kvm_pc_gsi_handler, gsi_state,
125 GSI_NUM_PINS);
126 } else {
127 gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
130 if (pci_enabled) {
131 pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, &isa_bus, gsi,
132 system_memory, system_io, ram_size,
133 below_4g_mem_size,
134 0x100000000ULL - below_4g_mem_size,
135 0x100000000ULL + above_4g_mem_size,
136 (sizeof(hwaddr) == 4
138 : ((uint64_t)1 << 62)),
139 pci_memory, ram_memory);
140 } else {
141 pci_bus = NULL;
142 i440fx_state = NULL;
143 isa_bus = isa_bus_new(NULL, system_io);
144 no_hpet = 1;
146 isa_bus_irqs(isa_bus, gsi);
148 if (kvm_irqchip_in_kernel()) {
149 i8259 = kvm_i8259_init(isa_bus);
150 } else if (xen_enabled()) {
151 i8259 = xen_interrupt_controller_init();
152 } else {
153 cpu_irq = pc_allocate_cpu_irq();
154 i8259 = i8259_init(isa_bus, cpu_irq[0]);
157 for (i = 0; i < ISA_NUM_IRQS; i++) {
158 gsi_state->i8259_irq[i] = i8259[i];
160 if (pci_enabled) {
161 ioapic_init_gsi(gsi_state, "i440fx");
164 pc_register_ferr_irq(gsi[13]);
166 pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
167 if (xen_enabled()) {
168 pci_create_simple(pci_bus, -1, "xen-platform");
171 /* init basic PC hardware */
172 pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy, xen_enabled());
174 pc_nic_init(isa_bus, pci_bus);
176 ide_drive_get(hd, MAX_IDE_BUS);
177 if (pci_enabled) {
178 PCIDevice *dev;
179 if (xen_enabled()) {
180 dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
181 } else {
182 dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
184 idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
185 idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
186 } else {
187 for(i = 0; i < MAX_IDE_BUS; i++) {
188 ISADevice *dev;
189 dev = isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i],
190 ide_irq[i],
191 hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
192 idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
196 audio_init();
198 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
199 floppy, idebus[0], idebus[1], rtc_state);
201 if (pci_enabled && usb_enabled(false)) {
202 pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
205 if (pci_enabled && acpi_enabled) {
206 i2c_bus *smbus;
208 smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt,
209 x86_env_get_cpu(first_cpu), 1);
210 /* TODO: Populate SPD eeprom data. */
211 smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
212 gsi[9], *smi_irq,
213 kvm_enabled(), fw_cfg);
214 smbus_eeprom_init(smbus, 8, NULL, 0);
217 if (pci_enabled) {
218 pc_pci_device_init(pci_bus);
222 static void pc_init_pci(QEMUMachineInitArgs *args)
224 ram_addr_t ram_size = args->ram_size;
225 const char *cpu_model = args->cpu_model;
226 const char *kernel_filename = args->kernel_filename;
227 const char *kernel_cmdline = args->kernel_cmdline;
228 const char *initrd_filename = args->initrd_filename;
229 const char *boot_device = args->boot_device;
230 pc_init1(get_system_memory(),
231 get_system_io(),
232 ram_size, boot_device,
233 kernel_filename, kernel_cmdline,
234 initrd_filename, cpu_model, 1, 1);
237 static void pc_init_pci_1_4(QEMUMachineInitArgs *args)
239 pc_sysfw_flash_vs_rom_bug_compatible = true;
240 pc_init_pci(args);
243 static void pc_init_pci_1_3(QEMUMachineInitArgs *args)
245 enable_compat_apic_id_mode();
246 pc_sysfw_flash_vs_rom_bug_compatible = true;
247 pc_init_pci(args);
250 /* PC machine init function for pc-1.1 to pc-1.2 */
251 static void pc_init_pci_1_2(QEMUMachineInitArgs *args)
253 disable_kvm_pv_eoi();
254 enable_compat_apic_id_mode();
255 pc_sysfw_flash_vs_rom_bug_compatible = true;
256 pc_init_pci(args);
259 /* PC machine init function for pc-0.14 to pc-1.0 */
260 static void pc_init_pci_1_0(QEMUMachineInitArgs *args)
262 disable_kvm_pv_eoi();
263 enable_compat_apic_id_mode();
264 pc_init_pci(args);
267 /* PC init function for pc-0.10 to pc-0.13, and reused by xenfv */
268 static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs *args)
270 ram_addr_t ram_size = args->ram_size;
271 const char *cpu_model = args->cpu_model;
272 const char *kernel_filename = args->kernel_filename;
273 const char *kernel_cmdline = args->kernel_cmdline;
274 const char *initrd_filename = args->initrd_filename;
275 const char *boot_device = args->boot_device;
276 disable_kvm_pv_eoi();
277 enable_compat_apic_id_mode();
278 pc_init1(get_system_memory(),
279 get_system_io(),
280 ram_size, boot_device,
281 kernel_filename, kernel_cmdline,
282 initrd_filename, cpu_model, 1, 0);
285 static void pc_init_isa(QEMUMachineInitArgs *args)
287 ram_addr_t ram_size = args->ram_size;
288 const char *cpu_model = args->cpu_model;
289 const char *kernel_filename = args->kernel_filename;
290 const char *kernel_cmdline = args->kernel_cmdline;
291 const char *initrd_filename = args->initrd_filename;
292 const char *boot_device = args->boot_device;
293 if (cpu_model == NULL)
294 cpu_model = "486";
295 disable_kvm_pv_eoi();
296 enable_compat_apic_id_mode();
297 pc_init1(get_system_memory(),
298 get_system_io(),
299 ram_size, boot_device,
300 kernel_filename, kernel_cmdline,
301 initrd_filename, cpu_model, 0, 1);
304 #ifdef CONFIG_XEN
305 static void pc_xen_hvm_init(QEMUMachineInitArgs *args)
307 if (xen_hvm_init() != 0) {
308 hw_error("xen hardware virtual machine initialisation failed");
310 pc_init_pci_no_kvmclock(args);
311 xen_vcpu_init();
313 #endif
315 static QEMUMachine pc_i440fx_machine_v1_5 = {
316 .name = "pc-i440fx-1.5",
317 .alias = "pc",
318 .desc = "Standard PC (i440FX + PIIX, 1996)",
319 .init = pc_init_pci,
320 .max_cpus = 255,
321 .is_default = 1,
322 DEFAULT_MACHINE_OPTIONS,
325 static QEMUMachine pc_i440fx_machine_v1_4 = {
326 .name = "pc-i440fx-1.4",
327 .desc = "Standard PC (i440FX + PIIX, 1996)",
328 .init = pc_init_pci_1_4,
329 .max_cpus = 255,
330 .compat_props = (GlobalProperty[]) {
331 PC_COMPAT_1_4,
332 { /* end of list */ }
334 DEFAULT_MACHINE_OPTIONS,
337 #define PC_COMPAT_1_3 \
338 PC_COMPAT_1_4, \
340 .driver = "usb-tablet",\
341 .property = "usb_version",\
342 .value = stringify(1),\
343 },{\
344 .driver = "virtio-net-pci",\
345 .property = "ctrl_mac_addr",\
346 .value = "off", \
347 },{ \
348 .driver = "virtio-net-pci", \
349 .property = "mq", \
350 .value = "off", \
351 }, {\
352 .driver = "e1000",\
353 .property = "autonegotiation",\
354 .value = "off",\
357 static QEMUMachine pc_machine_v1_3 = {
358 .name = "pc-1.3",
359 .desc = "Standard PC",
360 .init = pc_init_pci_1_3,
361 .max_cpus = 255,
362 .compat_props = (GlobalProperty[]) {
363 PC_COMPAT_1_3,
364 { /* end of list */ }
366 DEFAULT_MACHINE_OPTIONS,
369 #define PC_COMPAT_1_2 \
370 PC_COMPAT_1_3,\
372 .driver = "nec-usb-xhci",\
373 .property = "msi",\
374 .value = "off",\
375 },{\
376 .driver = "nec-usb-xhci",\
377 .property = "msix",\
378 .value = "off",\
379 },{\
380 .driver = "ivshmem",\
381 .property = "use64",\
382 .value = "0",\
383 },{\
384 .driver = "qxl",\
385 .property = "revision",\
386 .value = stringify(3),\
387 },{\
388 .driver = "qxl-vga",\
389 .property = "revision",\
390 .value = stringify(3),\
391 },{\
392 .driver = "VGA",\
393 .property = "mmio",\
394 .value = "off",\
397 static QEMUMachine pc_machine_v1_2 = {
398 .name = "pc-1.2",
399 .desc = "Standard PC",
400 .init = pc_init_pci_1_2,
401 .max_cpus = 255,
402 .compat_props = (GlobalProperty[]) {
403 PC_COMPAT_1_2,
404 { /* end of list */ }
406 DEFAULT_MACHINE_OPTIONS,
409 #define PC_COMPAT_1_1 \
410 PC_COMPAT_1_2,\
412 .driver = "virtio-scsi-pci",\
413 .property = "hotplug",\
414 .value = "off",\
415 },{\
416 .driver = "virtio-scsi-pci",\
417 .property = "param_change",\
418 .value = "off",\
419 },{\
420 .driver = "VGA",\
421 .property = "vgamem_mb",\
422 .value = stringify(8),\
423 },{\
424 .driver = "vmware-svga",\
425 .property = "vgamem_mb",\
426 .value = stringify(8),\
427 },{\
428 .driver = "qxl-vga",\
429 .property = "vgamem_mb",\
430 .value = stringify(8),\
431 },{\
432 .driver = "qxl",\
433 .property = "vgamem_mb",\
434 .value = stringify(8),\
435 },{\
436 .driver = "virtio-blk-pci",\
437 .property = "config-wce",\
438 .value = "off",\
441 static QEMUMachine pc_machine_v1_1 = {
442 .name = "pc-1.1",
443 .desc = "Standard PC",
444 .init = pc_init_pci_1_2,
445 .max_cpus = 255,
446 .compat_props = (GlobalProperty[]) {
447 PC_COMPAT_1_1,
448 { /* end of list */ }
450 DEFAULT_MACHINE_OPTIONS,
453 #define PC_COMPAT_1_0 \
454 PC_COMPAT_1_1,\
456 .driver = "pc-sysfw",\
457 .property = "rom_only",\
458 .value = stringify(1),\
459 }, {\
460 .driver = TYPE_ISA_FDC,\
461 .property = "check_media_rate",\
462 .value = "off",\
463 }, {\
464 .driver = "virtio-balloon-pci",\
465 .property = "class",\
466 .value = stringify(PCI_CLASS_MEMORY_RAM),\
467 },{\
468 .driver = "apic",\
469 .property = "vapic",\
470 .value = "off",\
471 },{\
472 .driver = TYPE_USB_DEVICE,\
473 .property = "full-path",\
474 .value = "no",\
477 static QEMUMachine pc_machine_v1_0 = {
478 .name = "pc-1.0",
479 .desc = "Standard PC",
480 .init = pc_init_pci_1_0,
481 .max_cpus = 255,
482 .compat_props = (GlobalProperty[]) {
483 PC_COMPAT_1_0,
484 { /* end of list */ }
486 .hw_version = "1.0",
487 DEFAULT_MACHINE_OPTIONS,
490 #define PC_COMPAT_0_15 \
491 PC_COMPAT_1_0
493 static QEMUMachine pc_machine_v0_15 = {
494 .name = "pc-0.15",
495 .desc = "Standard PC",
496 .init = pc_init_pci_1_0,
497 .max_cpus = 255,
498 .compat_props = (GlobalProperty[]) {
499 PC_COMPAT_0_15,
500 { /* end of list */ }
502 .hw_version = "0.15",
503 DEFAULT_MACHINE_OPTIONS,
506 #define PC_COMPAT_0_14 \
507 PC_COMPAT_0_15,\
509 .driver = "virtio-blk-pci",\
510 .property = "event_idx",\
511 .value = "off",\
512 },{\
513 .driver = "virtio-serial-pci",\
514 .property = "event_idx",\
515 .value = "off",\
516 },{\
517 .driver = "virtio-net-pci",\
518 .property = "event_idx",\
519 .value = "off",\
520 },{\
521 .driver = "virtio-balloon-pci",\
522 .property = "event_idx",\
523 .value = "off",\
526 static QEMUMachine pc_machine_v0_14 = {
527 .name = "pc-0.14",
528 .desc = "Standard PC",
529 .init = pc_init_pci_1_0,
530 .max_cpus = 255,
531 .compat_props = (GlobalProperty[]) {
532 PC_COMPAT_0_14,
534 .driver = "qxl",
535 .property = "revision",
536 .value = stringify(2),
538 .driver = "qxl-vga",
539 .property = "revision",
540 .value = stringify(2),
542 { /* end of list */ }
544 .hw_version = "0.14",
545 DEFAULT_MACHINE_OPTIONS,
548 #define PC_COMPAT_0_13 \
549 PC_COMPAT_0_14,\
551 .driver = TYPE_PCI_DEVICE,\
552 .property = "command_serr_enable",\
553 .value = "off",\
554 },{\
555 .driver = "AC97",\
556 .property = "use_broken_id",\
557 .value = stringify(1),\
560 static QEMUMachine pc_machine_v0_13 = {
561 .name = "pc-0.13",
562 .desc = "Standard PC",
563 .init = pc_init_pci_no_kvmclock,
564 .max_cpus = 255,
565 .compat_props = (GlobalProperty[]) {
566 PC_COMPAT_0_13,
568 .driver = "virtio-9p-pci",
569 .property = "vectors",
570 .value = stringify(0),
572 .driver = "VGA",
573 .property = "rombar",
574 .value = stringify(0),
576 .driver = "vmware-svga",
577 .property = "rombar",
578 .value = stringify(0),
580 { /* end of list */ }
582 .hw_version = "0.13",
583 DEFAULT_MACHINE_OPTIONS,
586 #define PC_COMPAT_0_12 \
587 PC_COMPAT_0_13,\
589 .driver = "virtio-serial-pci",\
590 .property = "max_ports",\
591 .value = stringify(1),\
592 },{\
593 .driver = "virtio-serial-pci",\
594 .property = "vectors",\
595 .value = stringify(0),\
598 static QEMUMachine pc_machine_v0_12 = {
599 .name = "pc-0.12",
600 .desc = "Standard PC",
601 .init = pc_init_pci_no_kvmclock,
602 .max_cpus = 255,
603 .compat_props = (GlobalProperty[]) {
604 PC_COMPAT_0_12,
606 .driver = "VGA",
607 .property = "rombar",
608 .value = stringify(0),
610 .driver = "vmware-svga",
611 .property = "rombar",
612 .value = stringify(0),
614 { /* end of list */ }
616 .hw_version = "0.12",
617 DEFAULT_MACHINE_OPTIONS,
620 #define PC_COMPAT_0_11 \
621 PC_COMPAT_0_12,\
623 .driver = "virtio-blk-pci",\
624 .property = "vectors",\
625 .value = stringify(0),\
626 },{\
627 .driver = TYPE_PCI_DEVICE,\
628 .property = "rombar",\
629 .value = stringify(0),\
632 static QEMUMachine pc_machine_v0_11 = {
633 .name = "pc-0.11",
634 .desc = "Standard PC, qemu 0.11",
635 .init = pc_init_pci_no_kvmclock,
636 .max_cpus = 255,
637 .compat_props = (GlobalProperty[]) {
638 PC_COMPAT_0_11,
640 .driver = "ide-drive",
641 .property = "ver",
642 .value = "0.11",
644 .driver = "scsi-disk",
645 .property = "ver",
646 .value = "0.11",
648 { /* end of list */ }
650 .hw_version = "0.11",
651 DEFAULT_MACHINE_OPTIONS,
654 static QEMUMachine pc_machine_v0_10 = {
655 .name = "pc-0.10",
656 .desc = "Standard PC, qemu 0.10",
657 .init = pc_init_pci_no_kvmclock,
658 .max_cpus = 255,
659 .compat_props = (GlobalProperty[]) {
660 PC_COMPAT_0_11,
662 .driver = "virtio-blk-pci",
663 .property = "class",
664 .value = stringify(PCI_CLASS_STORAGE_OTHER),
666 .driver = "virtio-serial-pci",
667 .property = "class",
668 .value = stringify(PCI_CLASS_DISPLAY_OTHER),
670 .driver = "virtio-net-pci",
671 .property = "vectors",
672 .value = stringify(0),
674 .driver = "ide-drive",
675 .property = "ver",
676 .value = "0.10",
678 .driver = "scsi-disk",
679 .property = "ver",
680 .value = "0.10",
682 { /* end of list */ }
684 .hw_version = "0.10",
685 DEFAULT_MACHINE_OPTIONS,
688 static QEMUMachine isapc_machine = {
689 .name = "isapc",
690 .desc = "ISA-only PC",
691 .init = pc_init_isa,
692 .max_cpus = 1,
693 .compat_props = (GlobalProperty[]) {
695 .driver = "pc-sysfw",
696 .property = "rom_only",
697 .value = stringify(1),
699 { /* end of list */ }
701 DEFAULT_MACHINE_OPTIONS,
704 #ifdef CONFIG_XEN
705 static QEMUMachine xenfv_machine = {
706 .name = "xenfv",
707 .desc = "Xen Fully-virtualized PC",
708 .init = pc_xen_hvm_init,
709 .max_cpus = HVM_MAX_VCPUS,
710 .default_machine_opts = "accel=xen",
711 DEFAULT_MACHINE_OPTIONS,
713 #endif
715 static void pc_machine_init(void)
717 qemu_register_machine(&pc_i440fx_machine_v1_5);
718 qemu_register_machine(&pc_i440fx_machine_v1_4);
719 qemu_register_machine(&pc_machine_v1_3);
720 qemu_register_machine(&pc_machine_v1_2);
721 qemu_register_machine(&pc_machine_v1_1);
722 qemu_register_machine(&pc_machine_v1_0);
723 qemu_register_machine(&pc_machine_v0_15);
724 qemu_register_machine(&pc_machine_v0_14);
725 qemu_register_machine(&pc_machine_v0_13);
726 qemu_register_machine(&pc_machine_v0_12);
727 qemu_register_machine(&pc_machine_v0_11);
728 qemu_register_machine(&pc_machine_v0_10);
729 qemu_register_machine(&isapc_machine);
730 #ifdef CONFIG_XEN
731 qemu_register_machine(&xenfv_machine);
732 #endif
735 machine_init(pc_machine_init);