]> git.proxmox.com Git - qemu.git/blame - hw/pc_piix.c
audio: remove unused parameter isa_pic
[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;
48a18b3c 87 ISABus *isa_bus;
845773ab
IY
88 PCII440FXState *i440fx_state;
89 int piix3_devfn = -1;
90 qemu_irq *cpu_irq;
b881fbe9 91 qemu_irq *gsi;
845773ab
IY
92 qemu_irq *i8259;
93 qemu_irq *cmos_s3;
94 qemu_irq *smi_irq;
b881fbe9 95 GSIState *gsi_state;
845773ab 96 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
c0897e0c 97 BusState *idebus[MAX_IDE_BUS];
1d914fa0 98 ISADevice *rtc_state;
34d4260e 99 ISADevice *floppy;
ae0a5466
AK
100 MemoryRegion *ram_memory;
101 MemoryRegion *pci_memory;
4463aee6 102 MemoryRegion *rom_memory;
ad6d45fa 103 DeviceState *dev;
845773ab
IY
104
105 pc_cpus_init(cpu_model);
106
0ec329da
JK
107 if (kvmclock_enabled) {
108 kvmclock_create();
109 }
110
e0e7e67b
AP
111 if (ram_size >= 0xe0000000 ) {
112 above_4g_mem_size = ram_size - 0xe0000000;
113 below_4g_mem_size = 0xe0000000;
114 } else {
115 above_4g_mem_size = 0;
116 below_4g_mem_size = ram_size;
117 }
118
4463aee6
JK
119 if (pci_enabled) {
120 pci_memory = g_new(MemoryRegion, 1);
121 memory_region_init(pci_memory, "pci", INT64_MAX);
122 rom_memory = pci_memory;
123 } else {
124 pci_memory = NULL;
125 rom_memory = system_memory;
126 }
ae0a5466 127
845773ab 128 /* allocate ram and load rom/bios */
29d3ccde 129 if (!xen_enabled()) {
4aa63af1
AK
130 pc_memory_init(system_memory,
131 kernel_filename, kernel_cmdline, initrd_filename,
ae0a5466 132 below_4g_mem_size, above_4g_mem_size,
c1d23eac 133 pci_enabled ? rom_memory : system_memory, &ram_memory);
29d3ccde 134 }
845773ab 135
b881fbe9
JK
136 gsi_state = g_malloc0(sizeof(*gsi_state));
137 gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
845773ab
IY
138
139 if (pci_enabled) {
60573079 140 pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, &isa_bus, gsi,
ae0a5466
AK
141 system_memory, system_io, ram_size,
142 below_4g_mem_size,
143 0x100000000ULL - below_4g_mem_size,
144 0x100000000ULL + above_4g_mem_size,
145 (sizeof(target_phys_addr_t) == 4
146 ? 0
147 : ((uint64_t)1 << 62)),
148 pci_memory, ram_memory);
845773ab
IY
149 } else {
150 pci_bus = NULL;
02a89b21 151 i440fx_state = NULL;
48a18b3c 152 isa_bus = isa_bus_new(NULL, system_io);
57285cc3 153 no_hpet = 1;
845773ab 154 }
48a18b3c 155 isa_bus_irqs(isa_bus, gsi);
845773ab 156
4bae1efe
RH
157 if (!xen_enabled()) {
158 cpu_irq = pc_allocate_cpu_irq();
48a18b3c 159 i8259 = i8259_init(isa_bus, cpu_irq[0]);
4bae1efe
RH
160 } else {
161 i8259 = xen_interrupt_controller_init();
162 }
163
43a0db35
JK
164 for (i = 0; i < ISA_NUM_IRQS; i++) {
165 gsi_state->i8259_irq[i] = i8259[i];
166 }
4bae1efe 167 if (pci_enabled) {
b881fbe9 168 ioapic_init(gsi_state);
4bae1efe
RH
169 }
170
b881fbe9 171 pc_register_ferr_irq(gsi[13]);
845773ab 172
48a18b3c 173 dev = pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
ad6d45fa
AL
174 if (dev) {
175 qdev_property_add_child(qdev_get_root(), "vga", dev, NULL);
176 }
845773ab 177
01195b73
SS
178 if (xen_enabled()) {
179 pci_create_simple(pci_bus, -1, "xen-platform");
180 }
181
845773ab 182 /* init basic PC hardware */
48a18b3c 183 pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy, xen_enabled());
845773ab
IY
184
185 for(i = 0; i < nb_nics; i++) {
186 NICInfo *nd = &nd_table[i];
187
188 if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
48a18b3c 189 pc_init_ne2k_isa(isa_bus, nd);
845773ab
IY
190 else
191 pci_nic_init_nofail(nd, "e1000", NULL);
192 }
193
75717903 194 ide_drive_get(hd, MAX_IDE_BUS);
845773ab 195 if (pci_enabled) {
c0897e0c 196 PCIDevice *dev;
679f4f8b
SS
197 if (xen_enabled()) {
198 dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
199 } else {
200 dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
201 }
c0897e0c
MA
202 idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
203 idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
845773ab
IY
204 } else {
205 for(i = 0; i < MAX_IDE_BUS; i++) {
c0897e0c 206 ISADevice *dev;
48a18b3c
HP
207 dev = isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i],
208 ide_irq[i],
c0897e0c
MA
209 hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
210 idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
845773ab
IY
211 }
212 }
213
d0c5be58
AL
214 /* FIXME there's some major spaghetti here. Somehow we create the devices
215 * on the PIIX before we actually create it. We create the PIIX3 deep in
216 * the recess of the i440fx creation too and then lose the DeviceState.
217 *
218 * For now, let's "fix" this by making judicious use of paths. This is not
219 * generally the right way to do this.
220 */
221
222 qdev_property_add_child(qdev_resolve_path("/i440fx/piix3", NULL),
223 "rtc", (DeviceState *)rtc_state, NULL);
224
4a0f031d 225 audio_init(isa_bus, pci_enabled ? pci_bus : NULL);
845773ab 226
c0897e0c 227 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
34d4260e 228 floppy, idebus[0], idebus[1], rtc_state);
845773ab
IY
229
230 if (pci_enabled && usb_enabled) {
231 usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
232 }
233
234 if (pci_enabled && acpi_enabled) {
845773ab
IY
235 i2c_bus *smbus;
236
c9622478
AP
237 if (!xen_enabled()) {
238 cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
239 } else {
240 cmos_s3 = qemu_allocate_irqs(xen_cmos_set_s3_resume, rtc_state, 1);
241 }
845773ab
IY
242 smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
243 /* TODO: Populate SPD eeprom data. */
244 smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
b881fbe9 245 gsi[9], *cmos_s3, *smi_irq,
845773ab 246 kvm_enabled());
a88df0b9 247 smbus_eeprom_init(smbus, 8, NULL, 0);
845773ab
IY
248 }
249
845773ab
IY
250 if (pci_enabled) {
251 pc_pci_device_init(pci_bus);
252 }
253}
254
255static void pc_init_pci(ram_addr_t ram_size,
256 const char *boot_device,
257 const char *kernel_filename,
258 const char *kernel_cmdline,
259 const char *initrd_filename,
260 const char *cpu_model)
261{
6bd10515 262 pc_init1(get_system_memory(),
aee97b84 263 get_system_io(),
6bd10515 264 ram_size, boot_device,
845773ab 265 kernel_filename, kernel_cmdline,
0ec329da
JK
266 initrd_filename, cpu_model, 1, 1);
267}
268
269static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,
270 const char *boot_device,
271 const char *kernel_filename,
272 const char *kernel_cmdline,
273 const char *initrd_filename,
274 const char *cpu_model)
275{
6bd10515 276 pc_init1(get_system_memory(),
aee97b84 277 get_system_io(),
6bd10515 278 ram_size, boot_device,
0ec329da
JK
279 kernel_filename, kernel_cmdline,
280 initrd_filename, cpu_model, 1, 0);
845773ab
IY
281}
282
283static void pc_init_isa(ram_addr_t ram_size,
284 const char *boot_device,
285 const char *kernel_filename,
286 const char *kernel_cmdline,
287 const char *initrd_filename,
288 const char *cpu_model)
289{
290 if (cpu_model == NULL)
291 cpu_model = "486";
6bd10515 292 pc_init1(get_system_memory(),
aee97b84 293 get_system_io(),
6bd10515 294 ram_size, boot_device,
845773ab 295 kernel_filename, kernel_cmdline,
0ec329da 296 initrd_filename, cpu_model, 0, 1);
845773ab
IY
297}
298
29d3ccde
AP
299#ifdef CONFIG_XEN
300static void pc_xen_hvm_init(ram_addr_t ram_size,
301 const char *boot_device,
302 const char *kernel_filename,
303 const char *kernel_cmdline,
304 const char *initrd_filename,
305 const char *cpu_model)
306{
307 if (xen_hvm_init() != 0) {
308 hw_error("xen hardware virtual machine initialisation failed");
309 }
310 pc_init_pci_no_kvmclock(ram_size, boot_device,
311 kernel_filename, kernel_cmdline,
312 initrd_filename, cpu_model);
313 xen_vcpu_init();
314}
315#endif
316
19857e62
GH
317static QEMUMachine pc_machine_v1_0 = {
318 .name = "pc-1.0",
845773ab
IY
319 .alias = "pc",
320 .desc = "Standard PC",
321 .init = pc_init_pci,
322 .max_cpus = 255,
323 .is_default = 1,
324};
325
ce01a508
AL
326static QEMUMachine pc_machine_v0_15 = {
327 .name = "pc-0.15",
328 .desc = "Standard PC",
329 .init = pc_init_pci,
330 .max_cpus = 255,
331 .is_default = 1,
332};
333
19857e62
GH
334static QEMUMachine pc_machine_v0_14 = {
335 .name = "pc-0.14",
336 .desc = "Standard PC",
337 .init = pc_init_pci,
338 .max_cpus = 255,
3827cdb1
AL
339 .compat_props = (GlobalProperty[]) {
340 {
341 .driver = "qxl",
342 .property = "revision",
343 .value = stringify(2),
344 },{
345 .driver = "qxl-vga",
346 .property = "revision",
347 .value = stringify(2),
ea830ebb
AL
348 },{
349 .driver = "virtio-blk-pci",
350 .property = "event_idx",
351 .value = "off",
352 },{
353 .driver = "virtio-serial-pci",
354 .property = "event_idx",
355 .value = "off",
356 },{
357 .driver = "virtio-net-pci",
358 .property = "event_idx",
359 .value = "off",
360 },{
361 .driver = "virtio-balloon-pci",
362 .property = "event_idx",
363 .value = "off",
3827cdb1
AL
364 },
365 { /* end of list */ }
366 },
19857e62
GH
367};
368
b903a0f7
GH
369static QEMUMachine pc_machine_v0_13 = {
370 .name = "pc-0.13",
371 .desc = "Standard PC",
0ec329da 372 .init = pc_init_pci_no_kvmclock,
b903a0f7 373 .max_cpus = 255,
9dbcca5a
GH
374 .compat_props = (GlobalProperty[]) {
375 {
376 .driver = "virtio-9p-pci",
377 .property = "vectors",
378 .value = stringify(0),
281a26b1
GH
379 },{
380 .driver = "VGA",
381 .property = "rombar",
382 .value = stringify(0),
383 },{
384 .driver = "vmware-svga",
385 .property = "rombar",
386 .value = stringify(0),
362dd48c
IY
387 },{
388 .driver = "PCI",
389 .property = "command_serr_enable",
390 .value = "off",
b91cb442
MT
391 },{
392 .driver = "virtio-blk-pci",
393 .property = "event_idx",
394 .value = "off",
395 },{
396 .driver = "virtio-serial-pci",
397 .property = "event_idx",
398 .value = "off",
399 },{
400 .driver = "virtio-net-pci",
401 .property = "event_idx",
402 .value = "off",
ea830ebb
AL
403 },{
404 .driver = "virtio-balloon-pci",
405 .property = "event_idx",
406 .value = "off",
25a21c94
GH
407 },{
408 .driver = "AC97",
409 .property = "use_broken_id",
410 .value = stringify(1),
9dbcca5a
GH
411 },
412 { /* end of list */ }
413 },
b903a0f7
GH
414};
415
845773ab
IY
416static QEMUMachine pc_machine_v0_12 = {
417 .name = "pc-0.12",
418 .desc = "Standard PC",
0ec329da 419 .init = pc_init_pci_no_kvmclock,
845773ab
IY
420 .max_cpus = 255,
421 .compat_props = (GlobalProperty[]) {
422 {
423 .driver = "virtio-serial-pci",
1e29a009 424 .property = "max_ports",
845773ab
IY
425 .value = stringify(1),
426 },{
427 .driver = "virtio-serial-pci",
428 .property = "vectors",
429 .value = stringify(0),
281a26b1
GH
430 },{
431 .driver = "VGA",
432 .property = "rombar",
433 .value = stringify(0),
434 },{
435 .driver = "vmware-svga",
436 .property = "rombar",
437 .value = stringify(0),
b1aeb926
IY
438 },{
439 .driver = "PCI",
440 .property = "command_serr_enable",
441 .value = "off",
b91cb442
MT
442 },{
443 .driver = "virtio-blk-pci",
444 .property = "event_idx",
445 .value = "off",
446 },{
447 .driver = "virtio-serial-pci",
448 .property = "event_idx",
449 .value = "off",
450 },{
451 .driver = "virtio-net-pci",
452 .property = "event_idx",
453 .value = "off",
ea830ebb
AL
454 },{
455 .driver = "virtio-balloon-pci",
456 .property = "event_idx",
457 .value = "off",
25a21c94
GH
458 },{
459 .driver = "AC97",
460 .property = "use_broken_id",
461 .value = stringify(1),
845773ab
IY
462 },
463 { /* end of list */ }
464 }
465};
466
467static QEMUMachine pc_machine_v0_11 = {
468 .name = "pc-0.11",
469 .desc = "Standard PC, qemu 0.11",
0ec329da 470 .init = pc_init_pci_no_kvmclock,
845773ab
IY
471 .max_cpus = 255,
472 .compat_props = (GlobalProperty[]) {
473 {
474 .driver = "virtio-blk-pci",
475 .property = "vectors",
476 .value = stringify(0),
477 },{
478 .driver = "virtio-serial-pci",
1e29a009 479 .property = "max_ports",
845773ab
IY
480 .value = stringify(1),
481 },{
482 .driver = "virtio-serial-pci",
483 .property = "vectors",
484 .value = stringify(0),
485 },{
486 .driver = "ide-drive",
487 .property = "ver",
488 .value = "0.11",
489 },{
490 .driver = "scsi-disk",
491 .property = "ver",
492 .value = "0.11",
493 },{
494 .driver = "PCI",
495 .property = "rombar",
496 .value = stringify(0),
b1aeb926
IY
497 },{
498 .driver = "PCI",
499 .property = "command_serr_enable",
500 .value = "off",
b91cb442
MT
501 },{
502 .driver = "virtio-blk-pci",
503 .property = "event_idx",
504 .value = "off",
505 },{
506 .driver = "virtio-serial-pci",
507 .property = "event_idx",
508 .value = "off",
509 },{
510 .driver = "virtio-net-pci",
511 .property = "event_idx",
512 .value = "off",
ea830ebb
AL
513 },{
514 .driver = "virtio-balloon-pci",
515 .property = "event_idx",
516 .value = "off",
25a21c94
GH
517 },{
518 .driver = "AC97",
519 .property = "use_broken_id",
520 .value = stringify(1),
845773ab
IY
521 },
522 { /* end of list */ }
523 }
524};
525
526static QEMUMachine pc_machine_v0_10 = {
527 .name = "pc-0.10",
528 .desc = "Standard PC, qemu 0.10",
0ec329da 529 .init = pc_init_pci_no_kvmclock,
845773ab
IY
530 .max_cpus = 255,
531 .compat_props = (GlobalProperty[]) {
532 {
533 .driver = "virtio-blk-pci",
534 .property = "class",
535 .value = stringify(PCI_CLASS_STORAGE_OTHER),
536 },{
537 .driver = "virtio-serial-pci",
538 .property = "class",
539 .value = stringify(PCI_CLASS_DISPLAY_OTHER),
540 },{
541 .driver = "virtio-serial-pci",
1e29a009 542 .property = "max_ports",
845773ab
IY
543 .value = stringify(1),
544 },{
545 .driver = "virtio-serial-pci",
546 .property = "vectors",
547 .value = stringify(0),
548 },{
549 .driver = "virtio-net-pci",
550 .property = "vectors",
551 .value = stringify(0),
552 },{
553 .driver = "virtio-blk-pci",
554 .property = "vectors",
555 .value = stringify(0),
556 },{
557 .driver = "ide-drive",
558 .property = "ver",
559 .value = "0.10",
560 },{
561 .driver = "scsi-disk",
562 .property = "ver",
563 .value = "0.10",
564 },{
565 .driver = "PCI",
566 .property = "rombar",
567 .value = stringify(0),
b1aeb926
IY
568 },{
569 .driver = "PCI",
570 .property = "command_serr_enable",
571 .value = "off",
b91cb442
MT
572 },{
573 .driver = "virtio-blk-pci",
574 .property = "event_idx",
575 .value = "off",
576 },{
577 .driver = "virtio-serial-pci",
578 .property = "event_idx",
579 .value = "off",
580 },{
581 .driver = "virtio-net-pci",
582 .property = "event_idx",
583 .value = "off",
ea830ebb
AL
584 },{
585 .driver = "virtio-balloon-pci",
586 .property = "event_idx",
587 .value = "off",
25a21c94
GH
588 },{
589 .driver = "AC97",
590 .property = "use_broken_id",
591 .value = stringify(1),
845773ab
IY
592 },
593 { /* end of list */ }
594 },
595};
596
597static QEMUMachine isapc_machine = {
598 .name = "isapc",
599 .desc = "ISA-only PC",
600 .init = pc_init_isa,
601 .max_cpus = 1,
602};
603
29d3ccde
AP
604#ifdef CONFIG_XEN
605static QEMUMachine xenfv_machine = {
606 .name = "xenfv",
607 .desc = "Xen Fully-virtualized PC",
608 .init = pc_xen_hvm_init,
609 .max_cpus = HVM_MAX_VCPUS,
610 .default_machine_opts = "accel=xen",
611};
612#endif
613
845773ab
IY
614static void pc_machine_init(void)
615{
19857e62 616 qemu_register_machine(&pc_machine_v1_0);
ce01a508 617 qemu_register_machine(&pc_machine_v0_15);
19857e62 618 qemu_register_machine(&pc_machine_v0_14);
b903a0f7 619 qemu_register_machine(&pc_machine_v0_13);
845773ab
IY
620 qemu_register_machine(&pc_machine_v0_12);
621 qemu_register_machine(&pc_machine_v0_11);
622 qemu_register_machine(&pc_machine_v0_10);
623 qemu_register_machine(&isapc_machine);
29d3ccde
AP
624#ifdef CONFIG_XEN
625 qemu_register_machine(&xenfv_machine);
626#endif
845773ab
IY
627}
628
629machine_init(pc_machine_init);