]> git.proxmox.com Git - mirror_qemu.git/blame - hw/pc_piix.c
pc: Generalize ISA IRQs to GSIs
[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;
ae0a5466
AK
98 MemoryRegion *ram_memory;
99 MemoryRegion *pci_memory;
4463aee6 100 MemoryRegion *rom_memory;
845773ab
IY
101
102 pc_cpus_init(cpu_model);
103
0ec329da
JK
104 if (kvmclock_enabled) {
105 kvmclock_create();
106 }
107
e0e7e67b
AP
108 if (ram_size >= 0xe0000000 ) {
109 above_4g_mem_size = ram_size - 0xe0000000;
110 below_4g_mem_size = 0xe0000000;
111 } else {
112 above_4g_mem_size = 0;
113 below_4g_mem_size = ram_size;
114 }
115
4463aee6
JK
116 if (pci_enabled) {
117 pci_memory = g_new(MemoryRegion, 1);
118 memory_region_init(pci_memory, "pci", INT64_MAX);
119 rom_memory = pci_memory;
120 } else {
121 pci_memory = NULL;
122 rom_memory = system_memory;
123 }
ae0a5466 124
845773ab 125 /* allocate ram and load rom/bios */
29d3ccde 126 if (!xen_enabled()) {
4aa63af1
AK
127 pc_memory_init(system_memory,
128 kernel_filename, kernel_cmdline, initrd_filename,
ae0a5466 129 below_4g_mem_size, above_4g_mem_size,
c1d23eac 130 pci_enabled ? rom_memory : system_memory, &ram_memory);
29d3ccde 131 }
845773ab 132
b881fbe9
JK
133 gsi_state = g_malloc0(sizeof(*gsi_state));
134 gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
845773ab
IY
135
136 if (pci_enabled) {
b881fbe9 137 pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, gsi,
ae0a5466
AK
138 system_memory, system_io, ram_size,
139 below_4g_mem_size,
140 0x100000000ULL - below_4g_mem_size,
141 0x100000000ULL + above_4g_mem_size,
142 (sizeof(target_phys_addr_t) == 4
143 ? 0
144 : ((uint64_t)1 << 62)),
145 pci_memory, ram_memory);
845773ab
IY
146 } else {
147 pci_bus = NULL;
02a89b21 148 i440fx_state = NULL;
c2d0d012 149 isa_bus_new(NULL, system_io);
57285cc3 150 no_hpet = 1;
845773ab 151 }
b881fbe9 152 isa_bus_irqs(gsi);
845773ab 153
4bae1efe
RH
154 if (!xen_enabled()) {
155 cpu_irq = pc_allocate_cpu_irq();
156 i8259 = i8259_init(cpu_irq[0]);
157 } else {
158 i8259 = xen_interrupt_controller_init();
159 }
160
b881fbe9 161 gsi_state->i8259_irq = i8259;
4bae1efe 162 if (pci_enabled) {
b881fbe9 163 ioapic_init(gsi_state);
4bae1efe
RH
164 }
165
b881fbe9 166 pc_register_ferr_irq(gsi[13]);
845773ab
IY
167
168 pc_vga_init(pci_enabled? pci_bus: NULL);
169
01195b73
SS
170 if (xen_enabled()) {
171 pci_create_simple(pci_bus, -1, "xen-platform");
172 }
173
845773ab 174 /* init basic PC hardware */
b881fbe9 175 pc_basic_device_init(gsi, &rtc_state, xen_enabled());
845773ab
IY
176
177 for(i = 0; i < nb_nics; i++) {
178 NICInfo *nd = &nd_table[i];
179
180 if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
181 pc_init_ne2k_isa(nd);
182 else
183 pci_nic_init_nofail(nd, "e1000", NULL);
184 }
185
75717903 186 ide_drive_get(hd, MAX_IDE_BUS);
845773ab 187 if (pci_enabled) {
c0897e0c 188 PCIDevice *dev;
679f4f8b
SS
189 if (xen_enabled()) {
190 dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
191 } else {
192 dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
193 }
c0897e0c
MA
194 idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
195 idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
845773ab
IY
196 } else {
197 for(i = 0; i < MAX_IDE_BUS; i++) {
c0897e0c
MA
198 ISADevice *dev;
199 dev = isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
200 hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
201 idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
845773ab
IY
202 }
203 }
204
b881fbe9 205 audio_init(gsi, pci_enabled ? pci_bus : NULL);
845773ab 206
c0897e0c 207 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
63ffb564 208 idebus[0], idebus[1], rtc_state);
845773ab
IY
209
210 if (pci_enabled && usb_enabled) {
211 usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
212 }
213
214 if (pci_enabled && acpi_enabled) {
845773ab
IY
215 i2c_bus *smbus;
216
c9622478
AP
217 if (!xen_enabled()) {
218 cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
219 } else {
220 cmos_s3 = qemu_allocate_irqs(xen_cmos_set_s3_resume, rtc_state, 1);
221 }
845773ab
IY
222 smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
223 /* TODO: Populate SPD eeprom data. */
224 smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
b881fbe9 225 gsi[9], *cmos_s3, *smi_irq,
845773ab 226 kvm_enabled());
a88df0b9 227 smbus_eeprom_init(smbus, 8, NULL, 0);
845773ab
IY
228 }
229
845773ab
IY
230 if (pci_enabled) {
231 pc_pci_device_init(pci_bus);
232 }
233}
234
235static void pc_init_pci(ram_addr_t ram_size,
236 const char *boot_device,
237 const char *kernel_filename,
238 const char *kernel_cmdline,
239 const char *initrd_filename,
240 const char *cpu_model)
241{
6bd10515 242 pc_init1(get_system_memory(),
aee97b84 243 get_system_io(),
6bd10515 244 ram_size, boot_device,
845773ab 245 kernel_filename, kernel_cmdline,
0ec329da
JK
246 initrd_filename, cpu_model, 1, 1);
247}
248
249static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,
250 const char *boot_device,
251 const char *kernel_filename,
252 const char *kernel_cmdline,
253 const char *initrd_filename,
254 const char *cpu_model)
255{
6bd10515 256 pc_init1(get_system_memory(),
aee97b84 257 get_system_io(),
6bd10515 258 ram_size, boot_device,
0ec329da
JK
259 kernel_filename, kernel_cmdline,
260 initrd_filename, cpu_model, 1, 0);
845773ab
IY
261}
262
263static void pc_init_isa(ram_addr_t ram_size,
264 const char *boot_device,
265 const char *kernel_filename,
266 const char *kernel_cmdline,
267 const char *initrd_filename,
268 const char *cpu_model)
269{
270 if (cpu_model == NULL)
271 cpu_model = "486";
6bd10515 272 pc_init1(get_system_memory(),
aee97b84 273 get_system_io(),
6bd10515 274 ram_size, boot_device,
845773ab 275 kernel_filename, kernel_cmdline,
0ec329da 276 initrd_filename, cpu_model, 0, 1);
845773ab
IY
277}
278
29d3ccde
AP
279#ifdef CONFIG_XEN
280static void pc_xen_hvm_init(ram_addr_t ram_size,
281 const char *boot_device,
282 const char *kernel_filename,
283 const char *kernel_cmdline,
284 const char *initrd_filename,
285 const char *cpu_model)
286{
287 if (xen_hvm_init() != 0) {
288 hw_error("xen hardware virtual machine initialisation failed");
289 }
290 pc_init_pci_no_kvmclock(ram_size, boot_device,
291 kernel_filename, kernel_cmdline,
292 initrd_filename, cpu_model);
293 xen_vcpu_init();
294}
295#endif
296
845773ab 297static QEMUMachine pc_machine = {
b903a0f7 298 .name = "pc-0.14",
845773ab
IY
299 .alias = "pc",
300 .desc = "Standard PC",
301 .init = pc_init_pci,
302 .max_cpus = 255,
303 .is_default = 1,
304};
305
b903a0f7
GH
306static QEMUMachine pc_machine_v0_13 = {
307 .name = "pc-0.13",
308 .desc = "Standard PC",
0ec329da 309 .init = pc_init_pci_no_kvmclock,
b903a0f7 310 .max_cpus = 255,
9dbcca5a
GH
311 .compat_props = (GlobalProperty[]) {
312 {
313 .driver = "virtio-9p-pci",
314 .property = "vectors",
315 .value = stringify(0),
281a26b1
GH
316 },{
317 .driver = "VGA",
318 .property = "rombar",
319 .value = stringify(0),
320 },{
321 .driver = "vmware-svga",
322 .property = "rombar",
323 .value = stringify(0),
362dd48c
IY
324 },{
325 .driver = "PCI",
326 .property = "command_serr_enable",
327 .value = "off",
b91cb442
MT
328 },{
329 .driver = "virtio-blk-pci",
330 .property = "event_idx",
331 .value = "off",
332 },{
333 .driver = "virtio-serial-pci",
334 .property = "event_idx",
335 .value = "off",
336 },{
337 .driver = "virtio-net-pci",
338 .property = "event_idx",
339 .value = "off",
9dbcca5a
GH
340 },
341 { /* end of list */ }
342 },
b903a0f7
GH
343};
344
845773ab
IY
345static QEMUMachine pc_machine_v0_12 = {
346 .name = "pc-0.12",
347 .desc = "Standard PC",
0ec329da 348 .init = pc_init_pci_no_kvmclock,
845773ab
IY
349 .max_cpus = 255,
350 .compat_props = (GlobalProperty[]) {
351 {
352 .driver = "virtio-serial-pci",
1e29a009 353 .property = "max_ports",
845773ab
IY
354 .value = stringify(1),
355 },{
356 .driver = "virtio-serial-pci",
357 .property = "vectors",
358 .value = stringify(0),
281a26b1
GH
359 },{
360 .driver = "VGA",
361 .property = "rombar",
362 .value = stringify(0),
363 },{
364 .driver = "vmware-svga",
365 .property = "rombar",
366 .value = stringify(0),
b1aeb926
IY
367 },{
368 .driver = "PCI",
369 .property = "command_serr_enable",
370 .value = "off",
b91cb442
MT
371 },{
372 .driver = "virtio-blk-pci",
373 .property = "event_idx",
374 .value = "off",
375 },{
376 .driver = "virtio-serial-pci",
377 .property = "event_idx",
378 .value = "off",
379 },{
380 .driver = "virtio-net-pci",
381 .property = "event_idx",
382 .value = "off",
845773ab
IY
383 },
384 { /* end of list */ }
385 }
386};
387
388static QEMUMachine pc_machine_v0_11 = {
389 .name = "pc-0.11",
390 .desc = "Standard PC, qemu 0.11",
0ec329da 391 .init = pc_init_pci_no_kvmclock,
845773ab
IY
392 .max_cpus = 255,
393 .compat_props = (GlobalProperty[]) {
394 {
395 .driver = "virtio-blk-pci",
396 .property = "vectors",
397 .value = stringify(0),
398 },{
399 .driver = "virtio-serial-pci",
1e29a009 400 .property = "max_ports",
845773ab
IY
401 .value = stringify(1),
402 },{
403 .driver = "virtio-serial-pci",
404 .property = "vectors",
405 .value = stringify(0),
406 },{
407 .driver = "ide-drive",
408 .property = "ver",
409 .value = "0.11",
410 },{
411 .driver = "scsi-disk",
412 .property = "ver",
413 .value = "0.11",
414 },{
415 .driver = "PCI",
416 .property = "rombar",
417 .value = stringify(0),
b1aeb926
IY
418 },{
419 .driver = "PCI",
420 .property = "command_serr_enable",
421 .value = "off",
b91cb442
MT
422 },{
423 .driver = "virtio-blk-pci",
424 .property = "event_idx",
425 .value = "off",
426 },{
427 .driver = "virtio-serial-pci",
428 .property = "event_idx",
429 .value = "off",
430 },{
431 .driver = "virtio-net-pci",
432 .property = "event_idx",
433 .value = "off",
845773ab
IY
434 },
435 { /* end of list */ }
436 }
437};
438
439static QEMUMachine pc_machine_v0_10 = {
440 .name = "pc-0.10",
441 .desc = "Standard PC, qemu 0.10",
0ec329da 442 .init = pc_init_pci_no_kvmclock,
845773ab
IY
443 .max_cpus = 255,
444 .compat_props = (GlobalProperty[]) {
445 {
446 .driver = "virtio-blk-pci",
447 .property = "class",
448 .value = stringify(PCI_CLASS_STORAGE_OTHER),
449 },{
450 .driver = "virtio-serial-pci",
451 .property = "class",
452 .value = stringify(PCI_CLASS_DISPLAY_OTHER),
453 },{
454 .driver = "virtio-serial-pci",
1e29a009 455 .property = "max_ports",
845773ab
IY
456 .value = stringify(1),
457 },{
458 .driver = "virtio-serial-pci",
459 .property = "vectors",
460 .value = stringify(0),
461 },{
462 .driver = "virtio-net-pci",
463 .property = "vectors",
464 .value = stringify(0),
465 },{
466 .driver = "virtio-blk-pci",
467 .property = "vectors",
468 .value = stringify(0),
469 },{
470 .driver = "ide-drive",
471 .property = "ver",
472 .value = "0.10",
473 },{
474 .driver = "scsi-disk",
475 .property = "ver",
476 .value = "0.10",
477 },{
478 .driver = "PCI",
479 .property = "rombar",
480 .value = stringify(0),
b1aeb926
IY
481 },{
482 .driver = "PCI",
483 .property = "command_serr_enable",
484 .value = "off",
b91cb442
MT
485 },{
486 .driver = "virtio-blk-pci",
487 .property = "event_idx",
488 .value = "off",
489 },{
490 .driver = "virtio-serial-pci",
491 .property = "event_idx",
492 .value = "off",
493 },{
494 .driver = "virtio-net-pci",
495 .property = "event_idx",
496 .value = "off",
845773ab
IY
497 },
498 { /* end of list */ }
499 },
500};
501
502static QEMUMachine isapc_machine = {
503 .name = "isapc",
504 .desc = "ISA-only PC",
505 .init = pc_init_isa,
506 .max_cpus = 1,
507};
508
29d3ccde
AP
509#ifdef CONFIG_XEN
510static QEMUMachine xenfv_machine = {
511 .name = "xenfv",
512 .desc = "Xen Fully-virtualized PC",
513 .init = pc_xen_hvm_init,
514 .max_cpus = HVM_MAX_VCPUS,
515 .default_machine_opts = "accel=xen",
516};
517#endif
518
845773ab
IY
519static void pc_machine_init(void)
520{
521 qemu_register_machine(&pc_machine);
b903a0f7 522 qemu_register_machine(&pc_machine_v0_13);
845773ab
IY
523 qemu_register_machine(&pc_machine_v0_12);
524 qemu_register_machine(&pc_machine_v0_11);
525 qemu_register_machine(&pc_machine_v0_10);
526 qemu_register_machine(&isapc_machine);
29d3ccde
AP
527#ifdef CONFIG_XEN
528 qemu_register_machine(&xenfv_machine);
529#endif
845773ab
IY
530}
531
532machine_init(pc_machine_init);