]> git.proxmox.com Git - mirror_qemu.git/blame - hw/pc_piix.c
vga: drop get_system_memory() from vga devices and derivatives
[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
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"
0ec329da 35#include "kvmclock.h"
666daa68 36#include "sysemu.h"
96051119 37#include "sysbus.h"
0dfa5ef9 38#include "arch_init.h"
2446333c 39#include "blockdev.h"
a88df0b9 40#include "smbus.h"
29d3ccde 41#include "xen.h"
4aa63af1
AK
42#include "memory.h"
43#include "exec-memory.h"
29d3ccde
AP
44#ifdef CONFIG_XEN
45# include <xen/hvm/hvm_info_table.h>
46#endif
845773ab
IY
47
48#define MAX_IDE_BUS 2
49
50static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
51static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
52static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
53
96051119
BS
54static void ioapic_init(IsaIrqState *isa_irq_state)
55{
56 DeviceState *dev;
57 SysBusDevice *d;
58 unsigned int i;
59
60 dev = qdev_create(NULL, "ioapic");
61 qdev_init_nofail(dev);
62 d = sysbus_from_qdev(dev);
63 sysbus_mmio_map(d, 0, 0xfec00000);
64
65 for (i = 0; i < IOAPIC_NUM_PINS; i++) {
66 isa_irq_state->ioapic[i] = qdev_get_gpio_in(dev, i);
67 }
68}
69
845773ab 70/* PC hardware initialisation */
6bd10515 71static void pc_init1(MemoryRegion *system_memory,
aee97b84 72 MemoryRegion *system_io,
6bd10515 73 ram_addr_t ram_size,
845773ab
IY
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,
0ec329da
JK
79 int pci_enabled,
80 int kvmclock_enabled)
845773ab
IY
81{
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];
c0897e0c 94 BusState *idebus[MAX_IDE_BUS];
1d914fa0 95 ISADevice *rtc_state;
845773ab
IY
96
97 pc_cpus_init(cpu_model);
98
0ec329da
JK
99 if (kvmclock_enabled) {
100 kvmclock_create();
101 }
102
e0e7e67b
AP
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;
109 }
110
845773ab 111 /* allocate ram and load rom/bios */
29d3ccde 112 if (!xen_enabled()) {
4aa63af1
AK
113 pc_memory_init(system_memory,
114 kernel_filename, kernel_cmdline, initrd_filename,
29d3ccde
AP
115 below_4g_mem_size, above_4g_mem_size);
116 }
845773ab 117
9c11a8ac
AP
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();
123 }
7267c094 124 isa_irq_state = g_malloc0(sizeof(*isa_irq_state));
845773ab
IY
125 isa_irq_state->i8259 = i8259;
126 if (pci_enabled) {
96051119 127 ioapic_init(isa_irq_state);
845773ab
IY
128 }
129 isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
130
131 if (pci_enabled) {
1e39101c 132 pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq,
aee97b84 133 system_memory, system_io, ram_size);
845773ab
IY
134 } else {
135 pci_bus = NULL;
02a89b21 136 i440fx_state = NULL;
845773ab
IY
137 isa_bus_new(NULL);
138 }
139 isa_bus_irqs(isa_irq);
140
ee951a37 141 pc_register_ferr_irq(isa_get_irq(13));
845773ab
IY
142
143 pc_vga_init(pci_enabled? pci_bus: NULL);
144
01195b73
SS
145 if (xen_enabled()) {
146 pci_create_simple(pci_bus, -1, "xen-platform");
147 }
148
845773ab 149 /* init basic PC hardware */
1611977c 150 pc_basic_device_init(isa_irq, &rtc_state, xen_enabled());
845773ab
IY
151
152 for(i = 0; i < nb_nics; i++) {
153 NICInfo *nd = &nd_table[i];
154
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);
159 }
160
75717903 161 ide_drive_get(hd, MAX_IDE_BUS);
845773ab 162 if (pci_enabled) {
c0897e0c 163 PCIDevice *dev;
679f4f8b
SS
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);
168 }
c0897e0c
MA
169 idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
170 idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
845773ab
IY
171 } else {
172 for(i = 0; i < MAX_IDE_BUS; i++) {
c0897e0c
MA
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");
845773ab
IY
177 }
178 }
179
0dfa5ef9 180 audio_init(isa_irq, pci_enabled ? pci_bus : NULL);
845773ab 181
c0897e0c 182 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
63ffb564 183 idebus[0], idebus[1], rtc_state);
845773ab
IY
184
185 if (pci_enabled && usb_enabled) {
186 usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
187 }
188
189 if (pci_enabled && acpi_enabled) {
845773ab
IY
190 i2c_bus *smbus;
191
c9622478
AP
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);
196 }
845773ab
IY
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,
ee951a37 200 isa_get_irq(9), *cmos_s3, *smi_irq,
845773ab 201 kvm_enabled());
a88df0b9 202 smbus_eeprom_init(smbus, 8, NULL, 0);
845773ab
IY
203 }
204
205 if (i440fx_state) {
206 i440fx_init_memory_mappings(i440fx_state);
207 }
208
209 if (pci_enabled) {
210 pc_pci_device_init(pci_bus);
211 }
212}
213
214static 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)
220{
6bd10515 221 pc_init1(get_system_memory(),
aee97b84 222 get_system_io(),
6bd10515 223 ram_size, boot_device,
845773ab 224 kernel_filename, kernel_cmdline,
0ec329da
JK
225 initrd_filename, cpu_model, 1, 1);
226}
227
228static 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)
234{
6bd10515 235 pc_init1(get_system_memory(),
aee97b84 236 get_system_io(),
6bd10515 237 ram_size, boot_device,
0ec329da
JK
238 kernel_filename, kernel_cmdline,
239 initrd_filename, cpu_model, 1, 0);
845773ab
IY
240}
241
242static 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)
248{
249 if (cpu_model == NULL)
250 cpu_model = "486";
6bd10515 251 pc_init1(get_system_memory(),
aee97b84 252 get_system_io(),
6bd10515 253 ram_size, boot_device,
845773ab 254 kernel_filename, kernel_cmdline,
0ec329da 255 initrd_filename, cpu_model, 0, 1);
845773ab
IY
256}
257
29d3ccde
AP
258#ifdef CONFIG_XEN
259static 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)
265{
266 if (xen_hvm_init() != 0) {
267 hw_error("xen hardware virtual machine initialisation failed");
268 }
269 pc_init_pci_no_kvmclock(ram_size, boot_device,
270 kernel_filename, kernel_cmdline,
271 initrd_filename, cpu_model);
272 xen_vcpu_init();
273}
274#endif
275
845773ab 276static QEMUMachine pc_machine = {
b903a0f7 277 .name = "pc-0.14",
845773ab
IY
278 .alias = "pc",
279 .desc = "Standard PC",
280 .init = pc_init_pci,
281 .max_cpus = 255,
282 .is_default = 1,
283};
284
b903a0f7
GH
285static QEMUMachine pc_machine_v0_13 = {
286 .name = "pc-0.13",
287 .desc = "Standard PC",
0ec329da 288 .init = pc_init_pci_no_kvmclock,
b903a0f7 289 .max_cpus = 255,
9dbcca5a
GH
290 .compat_props = (GlobalProperty[]) {
291 {
292 .driver = "virtio-9p-pci",
293 .property = "vectors",
294 .value = stringify(0),
281a26b1
GH
295 },{
296 .driver = "VGA",
297 .property = "rombar",
298 .value = stringify(0),
299 },{
300 .driver = "vmware-svga",
301 .property = "rombar",
302 .value = stringify(0),
362dd48c
IY
303 },{
304 .driver = "PCI",
305 .property = "command_serr_enable",
306 .value = "off",
b91cb442
MT
307 },{
308 .driver = "virtio-blk-pci",
309 .property = "event_idx",
310 .value = "off",
311 },{
312 .driver = "virtio-serial-pci",
313 .property = "event_idx",
314 .value = "off",
315 },{
316 .driver = "virtio-net-pci",
317 .property = "event_idx",
318 .value = "off",
9dbcca5a
GH
319 },
320 { /* end of list */ }
321 },
b903a0f7
GH
322};
323
845773ab
IY
324static QEMUMachine pc_machine_v0_12 = {
325 .name = "pc-0.12",
326 .desc = "Standard PC",
0ec329da 327 .init = pc_init_pci_no_kvmclock,
845773ab
IY
328 .max_cpus = 255,
329 .compat_props = (GlobalProperty[]) {
330 {
331 .driver = "virtio-serial-pci",
1e29a009 332 .property = "max_ports",
845773ab
IY
333 .value = stringify(1),
334 },{
335 .driver = "virtio-serial-pci",
336 .property = "vectors",
337 .value = stringify(0),
281a26b1
GH
338 },{
339 .driver = "VGA",
340 .property = "rombar",
341 .value = stringify(0),
342 },{
343 .driver = "vmware-svga",
344 .property = "rombar",
345 .value = stringify(0),
b1aeb926
IY
346 },{
347 .driver = "PCI",
348 .property = "command_serr_enable",
349 .value = "off",
b91cb442
MT
350 },{
351 .driver = "virtio-blk-pci",
352 .property = "event_idx",
353 .value = "off",
354 },{
355 .driver = "virtio-serial-pci",
356 .property = "event_idx",
357 .value = "off",
358 },{
359 .driver = "virtio-net-pci",
360 .property = "event_idx",
361 .value = "off",
845773ab
IY
362 },
363 { /* end of list */ }
364 }
365};
366
367static QEMUMachine pc_machine_v0_11 = {
368 .name = "pc-0.11",
369 .desc = "Standard PC, qemu 0.11",
0ec329da 370 .init = pc_init_pci_no_kvmclock,
845773ab
IY
371 .max_cpus = 255,
372 .compat_props = (GlobalProperty[]) {
373 {
374 .driver = "virtio-blk-pci",
375 .property = "vectors",
376 .value = stringify(0),
377 },{
378 .driver = "virtio-serial-pci",
1e29a009 379 .property = "max_ports",
845773ab
IY
380 .value = stringify(1),
381 },{
382 .driver = "virtio-serial-pci",
383 .property = "vectors",
384 .value = stringify(0),
385 },{
386 .driver = "ide-drive",
387 .property = "ver",
388 .value = "0.11",
389 },{
390 .driver = "scsi-disk",
391 .property = "ver",
392 .value = "0.11",
393 },{
394 .driver = "PCI",
395 .property = "rombar",
396 .value = stringify(0),
b1aeb926
IY
397 },{
398 .driver = "PCI",
399 .property = "command_serr_enable",
400 .value = "off",
b91cb442
MT
401 },{
402 .driver = "virtio-blk-pci",
403 .property = "event_idx",
404 .value = "off",
405 },{
406 .driver = "virtio-serial-pci",
407 .property = "event_idx",
408 .value = "off",
409 },{
410 .driver = "virtio-net-pci",
411 .property = "event_idx",
412 .value = "off",
845773ab
IY
413 },
414 { /* end of list */ }
415 }
416};
417
418static QEMUMachine pc_machine_v0_10 = {
419 .name = "pc-0.10",
420 .desc = "Standard PC, qemu 0.10",
0ec329da 421 .init = pc_init_pci_no_kvmclock,
845773ab
IY
422 .max_cpus = 255,
423 .compat_props = (GlobalProperty[]) {
424 {
425 .driver = "virtio-blk-pci",
426 .property = "class",
427 .value = stringify(PCI_CLASS_STORAGE_OTHER),
428 },{
429 .driver = "virtio-serial-pci",
430 .property = "class",
431 .value = stringify(PCI_CLASS_DISPLAY_OTHER),
432 },{
433 .driver = "virtio-serial-pci",
1e29a009 434 .property = "max_ports",
845773ab
IY
435 .value = stringify(1),
436 },{
437 .driver = "virtio-serial-pci",
438 .property = "vectors",
439 .value = stringify(0),
440 },{
441 .driver = "virtio-net-pci",
442 .property = "vectors",
443 .value = stringify(0),
444 },{
445 .driver = "virtio-blk-pci",
446 .property = "vectors",
447 .value = stringify(0),
448 },{
449 .driver = "ide-drive",
450 .property = "ver",
451 .value = "0.10",
452 },{
453 .driver = "scsi-disk",
454 .property = "ver",
455 .value = "0.10",
456 },{
457 .driver = "PCI",
458 .property = "rombar",
459 .value = stringify(0),
b1aeb926
IY
460 },{
461 .driver = "PCI",
462 .property = "command_serr_enable",
463 .value = "off",
b91cb442
MT
464 },{
465 .driver = "virtio-blk-pci",
466 .property = "event_idx",
467 .value = "off",
468 },{
469 .driver = "virtio-serial-pci",
470 .property = "event_idx",
471 .value = "off",
472 },{
473 .driver = "virtio-net-pci",
474 .property = "event_idx",
475 .value = "off",
845773ab
IY
476 },
477 { /* end of list */ }
478 },
479};
480
481static QEMUMachine isapc_machine = {
482 .name = "isapc",
483 .desc = "ISA-only PC",
484 .init = pc_init_isa,
485 .max_cpus = 1,
486};
487
29d3ccde
AP
488#ifdef CONFIG_XEN
489static 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",
495};
496#endif
497
845773ab
IY
498static void pc_machine_init(void)
499{
500 qemu_register_machine(&pc_machine);
b903a0f7 501 qemu_register_machine(&pc_machine_v0_13);
845773ab
IY
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);
29d3ccde
AP
506#ifdef CONFIG_XEN
507 qemu_register_machine(&xenfv_machine);
508#endif
845773ab
IY
509}
510
511machine_init(pc_machine_init);