qed: remove unneeded variable assignment
[qemu/ar7.git] / hw / pc_piix.c
blobc89042f1ced20748756f4916a777324a9d4abe8f
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 <glib.h>
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"
37 #include "kvmclock.h"
38 #include "sysemu.h"
39 #include "sysbus.h"
40 #include "arch_init.h"
41 #include "blockdev.h"
42 #include "smbus.h"
43 #include "xen.h"
44 #include "memory.h"
45 #include "exec-memory.h"
46 #ifdef CONFIG_XEN
47 # include <xen/hvm/hvm_info_table.h>
48 #endif
50 #define MAX_IDE_BUS 2
52 static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
53 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
54 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
56 static void ioapic_init(GSIState *gsi_state)
58 DeviceState *dev;
59 SysBusDevice *d;
60 unsigned int i;
62 dev = qdev_create(NULL, "ioapic");
63 qdev_init_nofail(dev);
64 d = sysbus_from_qdev(dev);
65 sysbus_mmio_map(d, 0, 0xfec00000);
67 for (i = 0; i < IOAPIC_NUM_PINS; i++) {
68 gsi_state->ioapic_irq[i] = qdev_get_gpio_in(dev, i);
72 /* PC hardware initialisation */
73 static void pc_init1(MemoryRegion *system_memory,
74 MemoryRegion *system_io,
75 ram_addr_t ram_size,
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,
81 int pci_enabled,
82 int kvmclock_enabled)
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;
90 qemu_irq *gsi;
91 qemu_irq *i8259;
92 qemu_irq *cmos_s3;
93 qemu_irq *smi_irq;
94 GSIState *gsi_state;
95 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
96 BusState *idebus[MAX_IDE_BUS];
97 ISADevice *rtc_state;
98 MemoryRegion *ram_memory;
99 MemoryRegion *pci_memory;
100 MemoryRegion *rom_memory;
102 pc_cpus_init(cpu_model);
104 if (kvmclock_enabled) {
105 kvmclock_create();
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;
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;
125 /* allocate ram and load rom/bios */
126 if (!xen_enabled()) {
127 pc_memory_init(system_memory,
128 kernel_filename, kernel_cmdline, initrd_filename,
129 below_4g_mem_size, above_4g_mem_size,
130 pci_enabled ? rom_memory : system_memory, &ram_memory);
133 gsi_state = g_malloc0(sizeof(*gsi_state));
134 gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
136 if (pci_enabled) {
137 pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, gsi,
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
144 : ((uint64_t)1 << 62)),
145 pci_memory, ram_memory);
146 } else {
147 pci_bus = NULL;
148 i440fx_state = NULL;
149 isa_bus_new(NULL, system_io);
150 no_hpet = 1;
152 isa_bus_irqs(gsi);
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();
161 for (i = 0; i < ISA_NUM_IRQS; i++) {
162 gsi_state->i8259_irq[i] = i8259[i];
164 if (pci_enabled) {
165 ioapic_init(gsi_state);
168 pc_register_ferr_irq(gsi[13]);
170 pc_vga_init(pci_enabled? pci_bus: NULL);
172 if (xen_enabled()) {
173 pci_create_simple(pci_bus, -1, "xen-platform");
176 /* init basic PC hardware */
177 pc_basic_device_init(gsi, &rtc_state, xen_enabled());
179 for(i = 0; i < nb_nics; i++) {
180 NICInfo *nd = &nd_table[i];
182 if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
183 pc_init_ne2k_isa(nd);
184 else
185 pci_nic_init_nofail(nd, "e1000", NULL);
188 ide_drive_get(hd, MAX_IDE_BUS);
189 if (pci_enabled) {
190 PCIDevice *dev;
191 if (xen_enabled()) {
192 dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
193 } else {
194 dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
196 idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
197 idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
198 } else {
199 for(i = 0; i < MAX_IDE_BUS; i++) {
200 ISADevice *dev;
201 dev = isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
202 hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
203 idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
207 audio_init(gsi, pci_enabled ? pci_bus : NULL);
209 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
210 idebus[0], idebus[1], rtc_state);
212 if (pci_enabled && usb_enabled) {
213 usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
216 if (pci_enabled && acpi_enabled) {
217 i2c_bus *smbus;
219 if (!xen_enabled()) {
220 cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
221 } else {
222 cmos_s3 = qemu_allocate_irqs(xen_cmos_set_s3_resume, rtc_state, 1);
224 smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
225 /* TODO: Populate SPD eeprom data. */
226 smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
227 gsi[9], *cmos_s3, *smi_irq,
228 kvm_enabled());
229 smbus_eeprom_init(smbus, 8, NULL, 0);
232 if (pci_enabled) {
233 pc_pci_device_init(pci_bus);
237 static void pc_init_pci(ram_addr_t ram_size,
238 const char *boot_device,
239 const char *kernel_filename,
240 const char *kernel_cmdline,
241 const char *initrd_filename,
242 const char *cpu_model)
244 pc_init1(get_system_memory(),
245 get_system_io(),
246 ram_size, boot_device,
247 kernel_filename, kernel_cmdline,
248 initrd_filename, cpu_model, 1, 1);
251 static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,
252 const char *boot_device,
253 const char *kernel_filename,
254 const char *kernel_cmdline,
255 const char *initrd_filename,
256 const char *cpu_model)
258 pc_init1(get_system_memory(),
259 get_system_io(),
260 ram_size, boot_device,
261 kernel_filename, kernel_cmdline,
262 initrd_filename, cpu_model, 1, 0);
265 static void pc_init_isa(ram_addr_t ram_size,
266 const char *boot_device,
267 const char *kernel_filename,
268 const char *kernel_cmdline,
269 const char *initrd_filename,
270 const char *cpu_model)
272 if (cpu_model == NULL)
273 cpu_model = "486";
274 pc_init1(get_system_memory(),
275 get_system_io(),
276 ram_size, boot_device,
277 kernel_filename, kernel_cmdline,
278 initrd_filename, cpu_model, 0, 1);
281 #ifdef CONFIG_XEN
282 static void pc_xen_hvm_init(ram_addr_t ram_size,
283 const char *boot_device,
284 const char *kernel_filename,
285 const char *kernel_cmdline,
286 const char *initrd_filename,
287 const char *cpu_model)
289 if (xen_hvm_init() != 0) {
290 hw_error("xen hardware virtual machine initialisation failed");
292 pc_init_pci_no_kvmclock(ram_size, boot_device,
293 kernel_filename, kernel_cmdline,
294 initrd_filename, cpu_model);
295 xen_vcpu_init();
297 #endif
299 static QEMUMachine pc_machine = {
300 .name = "pc-0.14",
301 .alias = "pc",
302 .desc = "Standard PC",
303 .init = pc_init_pci,
304 .max_cpus = 255,
305 .is_default = 1,
308 static QEMUMachine pc_machine_v0_13 = {
309 .name = "pc-0.13",
310 .desc = "Standard PC",
311 .init = pc_init_pci_no_kvmclock,
312 .max_cpus = 255,
313 .compat_props = (GlobalProperty[]) {
315 .driver = "virtio-9p-pci",
316 .property = "vectors",
317 .value = stringify(0),
319 .driver = "VGA",
320 .property = "rombar",
321 .value = stringify(0),
323 .driver = "vmware-svga",
324 .property = "rombar",
325 .value = stringify(0),
327 .driver = "PCI",
328 .property = "command_serr_enable",
329 .value = "off",
331 .driver = "virtio-blk-pci",
332 .property = "event_idx",
333 .value = "off",
335 .driver = "virtio-serial-pci",
336 .property = "event_idx",
337 .value = "off",
339 .driver = "virtio-net-pci",
340 .property = "event_idx",
341 .value = "off",
343 { /* end of list */ }
347 static QEMUMachine pc_machine_v0_12 = {
348 .name = "pc-0.12",
349 .desc = "Standard PC",
350 .init = pc_init_pci_no_kvmclock,
351 .max_cpus = 255,
352 .compat_props = (GlobalProperty[]) {
354 .driver = "virtio-serial-pci",
355 .property = "max_ports",
356 .value = stringify(1),
358 .driver = "virtio-serial-pci",
359 .property = "vectors",
360 .value = stringify(0),
362 .driver = "VGA",
363 .property = "rombar",
364 .value = stringify(0),
366 .driver = "vmware-svga",
367 .property = "rombar",
368 .value = stringify(0),
370 .driver = "PCI",
371 .property = "command_serr_enable",
372 .value = "off",
374 .driver = "virtio-blk-pci",
375 .property = "event_idx",
376 .value = "off",
378 .driver = "virtio-serial-pci",
379 .property = "event_idx",
380 .value = "off",
382 .driver = "virtio-net-pci",
383 .property = "event_idx",
384 .value = "off",
386 { /* end of list */ }
390 static QEMUMachine pc_machine_v0_11 = {
391 .name = "pc-0.11",
392 .desc = "Standard PC, qemu 0.11",
393 .init = pc_init_pci_no_kvmclock,
394 .max_cpus = 255,
395 .compat_props = (GlobalProperty[]) {
397 .driver = "virtio-blk-pci",
398 .property = "vectors",
399 .value = stringify(0),
401 .driver = "virtio-serial-pci",
402 .property = "max_ports",
403 .value = stringify(1),
405 .driver = "virtio-serial-pci",
406 .property = "vectors",
407 .value = stringify(0),
409 .driver = "ide-drive",
410 .property = "ver",
411 .value = "0.11",
413 .driver = "scsi-disk",
414 .property = "ver",
415 .value = "0.11",
417 .driver = "PCI",
418 .property = "rombar",
419 .value = stringify(0),
421 .driver = "PCI",
422 .property = "command_serr_enable",
423 .value = "off",
425 .driver = "virtio-blk-pci",
426 .property = "event_idx",
427 .value = "off",
429 .driver = "virtio-serial-pci",
430 .property = "event_idx",
431 .value = "off",
433 .driver = "virtio-net-pci",
434 .property = "event_idx",
435 .value = "off",
437 { /* end of list */ }
441 static QEMUMachine pc_machine_v0_10 = {
442 .name = "pc-0.10",
443 .desc = "Standard PC, qemu 0.10",
444 .init = pc_init_pci_no_kvmclock,
445 .max_cpus = 255,
446 .compat_props = (GlobalProperty[]) {
448 .driver = "virtio-blk-pci",
449 .property = "class",
450 .value = stringify(PCI_CLASS_STORAGE_OTHER),
452 .driver = "virtio-serial-pci",
453 .property = "class",
454 .value = stringify(PCI_CLASS_DISPLAY_OTHER),
456 .driver = "virtio-serial-pci",
457 .property = "max_ports",
458 .value = stringify(1),
460 .driver = "virtio-serial-pci",
461 .property = "vectors",
462 .value = stringify(0),
464 .driver = "virtio-net-pci",
465 .property = "vectors",
466 .value = stringify(0),
468 .driver = "virtio-blk-pci",
469 .property = "vectors",
470 .value = stringify(0),
472 .driver = "ide-drive",
473 .property = "ver",
474 .value = "0.10",
476 .driver = "scsi-disk",
477 .property = "ver",
478 .value = "0.10",
480 .driver = "PCI",
481 .property = "rombar",
482 .value = stringify(0),
484 .driver = "PCI",
485 .property = "command_serr_enable",
486 .value = "off",
488 .driver = "virtio-blk-pci",
489 .property = "event_idx",
490 .value = "off",
492 .driver = "virtio-serial-pci",
493 .property = "event_idx",
494 .value = "off",
496 .driver = "virtio-net-pci",
497 .property = "event_idx",
498 .value = "off",
500 { /* end of list */ }
504 static QEMUMachine isapc_machine = {
505 .name = "isapc",
506 .desc = "ISA-only PC",
507 .init = pc_init_isa,
508 .max_cpus = 1,
511 #ifdef CONFIG_XEN
512 static QEMUMachine xenfv_machine = {
513 .name = "xenfv",
514 .desc = "Xen Fully-virtualized PC",
515 .init = pc_xen_hvm_init,
516 .max_cpus = HVM_MAX_VCPUS,
517 .default_machine_opts = "accel=xen",
519 #endif
521 static void pc_machine_init(void)
523 qemu_register_machine(&pc_machine);
524 qemu_register_machine(&pc_machine_v0_13);
525 qemu_register_machine(&pc_machine_v0_12);
526 qemu_register_machine(&pc_machine_v0_11);
527 qemu_register_machine(&pc_machine_v0_10);
528 qemu_register_machine(&isapc_machine);
529 #ifdef CONFIG_XEN
530 qemu_register_machine(&xenfv_machine);
531 #endif
534 machine_init(pc_machine_init);