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