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