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