fix event fallout in sh_serial.c
[qemu/aliguori.git] / hw / pc_piix.c
blob7dd5008dce9d510a973a15a8531c2e3e85d69715
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 "hw.h"
26 #include "pc.h"
27 #include "apic.h"
28 #include "pci.h"
29 #include "usb-uhci.h"
30 #include "usb-ohci.h"
31 #include "net.h"
32 #include "boards.h"
33 #include "ide.h"
34 #include "kvm.h"
35 #include "kvmclock.h"
36 #include "sysemu.h"
37 #include "sysbus.h"
38 #include "arch_init.h"
39 #include "blockdev.h"
40 #include "smbus.h"
41 #include "xen.h"
42 #include "memory.h"
43 #include "exec-memory.h"
44 #ifdef CONFIG_XEN
45 # include <xen/hvm/hvm_info_table.h>
46 #endif
48 #define MAX_IDE_BUS 2
50 static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
51 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
52 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
54 static void ioapic_init(IsaIrqState *isa_irq_state)
56 DeviceState *dev;
57 SysBusDevice *d;
58 unsigned int i;
60 dev = qdev_create(NULL, "ioapic");
61 qdev_init_nofail(dev);
62 d = sysbus_from_qdev(dev);
63 sysbus_mmio_map(d, 0, 0xfec00000);
65 for (i = 0; i < IOAPIC_NUM_PINS; i++) {
66 isa_irq_state->ioapic[i] = qdev_get_gpio_in(dev, i);
70 /* PC hardware initialisation */
71 static void pc_init1(MemoryRegion *system_memory,
72 MemoryRegion *system_io,
73 ram_addr_t ram_size,
74 const char *boot_device,
75 const char *kernel_filename,
76 const char *kernel_cmdline,
77 const char *initrd_filename,
78 const char *cpu_model,
79 int pci_enabled,
80 int kvmclock_enabled)
82 int i;
83 ram_addr_t below_4g_mem_size, above_4g_mem_size;
84 PCIBus *pci_bus;
85 PCII440FXState *i440fx_state;
86 int piix3_devfn = -1;
87 qemu_irq *cpu_irq;
88 qemu_irq *isa_irq;
89 qemu_irq *i8259;
90 qemu_irq *cmos_s3;
91 qemu_irq *smi_irq;
92 IsaIrqState *isa_irq_state;
93 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
94 BusState *idebus[MAX_IDE_BUS];
95 ISADevice *rtc_state;
97 pc_cpus_init(cpu_model);
99 if (kvmclock_enabled) {
100 kvmclock_create();
103 if (ram_size >= 0xe0000000 ) {
104 above_4g_mem_size = ram_size - 0xe0000000;
105 below_4g_mem_size = 0xe0000000;
106 } else {
107 above_4g_mem_size = 0;
108 below_4g_mem_size = ram_size;
111 /* allocate ram and load rom/bios */
112 if (!xen_enabled()) {
113 pc_memory_init(system_memory,
114 kernel_filename, kernel_cmdline, initrd_filename,
115 below_4g_mem_size, above_4g_mem_size);
118 if (!xen_enabled()) {
119 cpu_irq = pc_allocate_cpu_irq();
120 i8259 = i8259_init(cpu_irq[0]);
121 } else {
122 i8259 = xen_interrupt_controller_init();
124 isa_irq_state = qemu_mallocz(sizeof(*isa_irq_state));
125 isa_irq_state->i8259 = i8259;
126 if (pci_enabled) {
127 ioapic_init(isa_irq_state);
129 isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
131 if (pci_enabled) {
132 pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq,
133 system_memory, system_io, ram_size);
134 } else {
135 pci_bus = NULL;
136 i440fx_state = NULL;
137 isa_bus_new(NULL);
139 isa_bus_irqs(isa_irq);
141 pc_register_ferr_irq(isa_get_irq(13));
143 pc_vga_init(pci_enabled? pci_bus: NULL);
145 if (xen_enabled()) {
146 pci_create_simple(pci_bus, -1, "xen-platform");
149 /* init basic PC hardware */
150 pc_basic_device_init(isa_irq, &rtc_state, xen_enabled());
152 for(i = 0; i < nb_nics; i++) {
153 NICInfo *nd = &nd_table[i];
155 if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
156 pc_init_ne2k_isa(nd);
157 else
158 pci_nic_init_nofail(nd, "e1000", NULL);
161 ide_drive_get(hd, MAX_IDE_BUS);
162 if (pci_enabled) {
163 PCIDevice *dev;
164 if (xen_enabled()) {
165 dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
166 } else {
167 dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
169 idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
170 idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
171 } else {
172 for(i = 0; i < MAX_IDE_BUS; i++) {
173 ISADevice *dev;
174 dev = isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
175 hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
176 idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
180 audio_init(isa_irq, pci_enabled ? pci_bus : NULL);
182 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
183 idebus[0], idebus[1], rtc_state);
185 if (pci_enabled && usb_enabled) {
186 usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
189 if (pci_enabled && acpi_enabled) {
190 i2c_bus *smbus;
192 if (!xen_enabled()) {
193 cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
194 } else {
195 cmos_s3 = qemu_allocate_irqs(xen_cmos_set_s3_resume, rtc_state, 1);
197 smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
198 /* TODO: Populate SPD eeprom data. */
199 smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
200 isa_get_irq(9), *cmos_s3, *smi_irq,
201 kvm_enabled());
202 smbus_eeprom_init(smbus, 8, NULL, 0);
205 if (i440fx_state) {
206 i440fx_init_memory_mappings(i440fx_state);
209 if (pci_enabled) {
210 pc_pci_device_init(pci_bus);
214 static void pc_init_pci(ram_addr_t ram_size,
215 const char *boot_device,
216 const char *kernel_filename,
217 const char *kernel_cmdline,
218 const char *initrd_filename,
219 const char *cpu_model)
221 pc_init1(get_system_memory(),
222 get_system_io(),
223 ram_size, boot_device,
224 kernel_filename, kernel_cmdline,
225 initrd_filename, cpu_model, 1, 1);
228 static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,
229 const char *boot_device,
230 const char *kernel_filename,
231 const char *kernel_cmdline,
232 const char *initrd_filename,
233 const char *cpu_model)
235 pc_init1(get_system_memory(),
236 get_system_io(),
237 ram_size, boot_device,
238 kernel_filename, kernel_cmdline,
239 initrd_filename, cpu_model, 1, 0);
242 static void pc_init_isa(ram_addr_t ram_size,
243 const char *boot_device,
244 const char *kernel_filename,
245 const char *kernel_cmdline,
246 const char *initrd_filename,
247 const char *cpu_model)
249 if (cpu_model == NULL)
250 cpu_model = "486";
251 pc_init1(get_system_memory(),
252 get_system_io(),
253 ram_size, boot_device,
254 kernel_filename, kernel_cmdline,
255 initrd_filename, cpu_model, 0, 1);
258 #ifdef CONFIG_XEN
259 static void pc_xen_hvm_init(ram_addr_t ram_size,
260 const char *boot_device,
261 const char *kernel_filename,
262 const char *kernel_cmdline,
263 const char *initrd_filename,
264 const char *cpu_model)
266 if (xen_hvm_init() != 0) {
267 hw_error("xen hardware virtual machine initialisation failed");
269 pc_init_pci_no_kvmclock(ram_size, boot_device,
270 kernel_filename, kernel_cmdline,
271 initrd_filename, cpu_model);
272 xen_vcpu_init();
274 #endif
276 static QEMUMachine pc_machine = {
277 .name = "pc-0.14",
278 .alias = "pc",
279 .desc = "Standard PC",
280 .init = pc_init_pci,
281 .max_cpus = 255,
282 .is_default = 1,
285 static QEMUMachine pc_machine_v0_13 = {
286 .name = "pc-0.13",
287 .desc = "Standard PC",
288 .init = pc_init_pci_no_kvmclock,
289 .max_cpus = 255,
290 .compat_props = (GlobalProperty[]) {
292 .driver = "virtio-9p-pci",
293 .property = "vectors",
294 .value = stringify(0),
296 .driver = "VGA",
297 .property = "rombar",
298 .value = stringify(0),
300 .driver = "vmware-svga",
301 .property = "rombar",
302 .value = stringify(0),
304 .driver = "PCI",
305 .property = "command_serr_enable",
306 .value = "off",
308 .driver = "virtio-blk-pci",
309 .property = "event_idx",
310 .value = "off",
312 .driver = "virtio-serial-pci",
313 .property = "event_idx",
314 .value = "off",
316 .driver = "virtio-net-pci",
317 .property = "event_idx",
318 .value = "off",
320 { /* end of list */ }
324 static QEMUMachine pc_machine_v0_12 = {
325 .name = "pc-0.12",
326 .desc = "Standard PC",
327 .init = pc_init_pci_no_kvmclock,
328 .max_cpus = 255,
329 .compat_props = (GlobalProperty[]) {
331 .driver = "virtio-serial-pci",
332 .property = "max_ports",
333 .value = stringify(1),
335 .driver = "virtio-serial-pci",
336 .property = "vectors",
337 .value = stringify(0),
339 .driver = "VGA",
340 .property = "rombar",
341 .value = stringify(0),
343 .driver = "vmware-svga",
344 .property = "rombar",
345 .value = stringify(0),
347 .driver = "PCI",
348 .property = "command_serr_enable",
349 .value = "off",
351 .driver = "virtio-blk-pci",
352 .property = "event_idx",
353 .value = "off",
355 .driver = "virtio-serial-pci",
356 .property = "event_idx",
357 .value = "off",
359 .driver = "virtio-net-pci",
360 .property = "event_idx",
361 .value = "off",
363 { /* end of list */ }
367 static QEMUMachine pc_machine_v0_11 = {
368 .name = "pc-0.11",
369 .desc = "Standard PC, qemu 0.11",
370 .init = pc_init_pci_no_kvmclock,
371 .max_cpus = 255,
372 .compat_props = (GlobalProperty[]) {
374 .driver = "virtio-blk-pci",
375 .property = "vectors",
376 .value = stringify(0),
378 .driver = "virtio-serial-pci",
379 .property = "max_ports",
380 .value = stringify(1),
382 .driver = "virtio-serial-pci",
383 .property = "vectors",
384 .value = stringify(0),
386 .driver = "ide-drive",
387 .property = "ver",
388 .value = "0.11",
390 .driver = "scsi-disk",
391 .property = "ver",
392 .value = "0.11",
394 .driver = "PCI",
395 .property = "rombar",
396 .value = stringify(0),
398 .driver = "PCI",
399 .property = "command_serr_enable",
400 .value = "off",
402 .driver = "virtio-blk-pci",
403 .property = "event_idx",
404 .value = "off",
406 .driver = "virtio-serial-pci",
407 .property = "event_idx",
408 .value = "off",
410 .driver = "virtio-net-pci",
411 .property = "event_idx",
412 .value = "off",
414 { /* end of list */ }
418 static QEMUMachine pc_machine_v0_10 = {
419 .name = "pc-0.10",
420 .desc = "Standard PC, qemu 0.10",
421 .init = pc_init_pci_no_kvmclock,
422 .max_cpus = 255,
423 .compat_props = (GlobalProperty[]) {
425 .driver = "virtio-blk-pci",
426 .property = "class",
427 .value = stringify(PCI_CLASS_STORAGE_OTHER),
429 .driver = "virtio-serial-pci",
430 .property = "class",
431 .value = stringify(PCI_CLASS_DISPLAY_OTHER),
433 .driver = "virtio-serial-pci",
434 .property = "max_ports",
435 .value = stringify(1),
437 .driver = "virtio-serial-pci",
438 .property = "vectors",
439 .value = stringify(0),
441 .driver = "virtio-net-pci",
442 .property = "vectors",
443 .value = stringify(0),
445 .driver = "virtio-blk-pci",
446 .property = "vectors",
447 .value = stringify(0),
449 .driver = "ide-drive",
450 .property = "ver",
451 .value = "0.10",
453 .driver = "scsi-disk",
454 .property = "ver",
455 .value = "0.10",
457 .driver = "PCI",
458 .property = "rombar",
459 .value = stringify(0),
461 .driver = "PCI",
462 .property = "command_serr_enable",
463 .value = "off",
465 .driver = "virtio-blk-pci",
466 .property = "event_idx",
467 .value = "off",
469 .driver = "virtio-serial-pci",
470 .property = "event_idx",
471 .value = "off",
473 .driver = "virtio-net-pci",
474 .property = "event_idx",
475 .value = "off",
477 { /* end of list */ }
481 static QEMUMachine isapc_machine = {
482 .name = "isapc",
483 .desc = "ISA-only PC",
484 .init = pc_init_isa,
485 .max_cpus = 1,
488 #ifdef CONFIG_XEN
489 static QEMUMachine xenfv_machine = {
490 .name = "xenfv",
491 .desc = "Xen Fully-virtualized PC",
492 .init = pc_xen_hvm_init,
493 .max_cpus = HVM_MAX_VCPUS,
494 .default_machine_opts = "accel=xen",
496 #endif
498 static void pc_machine_init(void)
500 qemu_register_machine(&pc_machine);
501 qemu_register_machine(&pc_machine_v0_13);
502 qemu_register_machine(&pc_machine_v0_12);
503 qemu_register_machine(&pc_machine_v0_11);
504 qemu_register_machine(&pc_machine_v0_10);
505 qemu_register_machine(&isapc_machine);
506 #ifdef CONFIG_XEN
507 qemu_register_machine(&xenfv_machine);
508 #endif
511 machine_init(pc_machine_init);