Add missing trace call to oslib-posix.c:qemu_vmalloc()
[qemu/kevin.git] / hw / pc_piix.c
blob2b9c2b113cb102b8ebd0e3c3d7dea60afdbef864
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 ram_addr_t ram_size,
73 const char *boot_device,
74 const char *kernel_filename,
75 const char *kernel_cmdline,
76 const char *initrd_filename,
77 const char *cpu_model,
78 int pci_enabled,
79 int kvmclock_enabled)
81 int i;
82 ram_addr_t below_4g_mem_size, above_4g_mem_size;
83 PCIBus *pci_bus;
84 PCII440FXState *i440fx_state;
85 int piix3_devfn = -1;
86 qemu_irq *cpu_irq;
87 qemu_irq *isa_irq;
88 qemu_irq *i8259;
89 qemu_irq *cmos_s3;
90 qemu_irq *smi_irq;
91 IsaIrqState *isa_irq_state;
92 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
93 BusState *idebus[MAX_IDE_BUS];
94 ISADevice *rtc_state;
96 pc_cpus_init(cpu_model);
98 if (kvmclock_enabled) {
99 kvmclock_create();
102 if (ram_size >= 0xe0000000 ) {
103 above_4g_mem_size = ram_size - 0xe0000000;
104 below_4g_mem_size = 0xe0000000;
105 } else {
106 above_4g_mem_size = 0;
107 below_4g_mem_size = ram_size;
110 /* allocate ram and load rom/bios */
111 if (!xen_enabled()) {
112 pc_memory_init(system_memory,
113 kernel_filename, kernel_cmdline, initrd_filename,
114 below_4g_mem_size, above_4g_mem_size);
117 if (!xen_enabled()) {
118 cpu_irq = pc_allocate_cpu_irq();
119 i8259 = i8259_init(cpu_irq[0]);
120 } else {
121 i8259 = xen_interrupt_controller_init();
123 isa_irq_state = qemu_mallocz(sizeof(*isa_irq_state));
124 isa_irq_state->i8259 = i8259;
125 if (pci_enabled) {
126 ioapic_init(isa_irq_state);
128 isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
130 if (pci_enabled) {
131 pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq,
132 system_memory, ram_size);
133 } else {
134 pci_bus = NULL;
135 i440fx_state = NULL;
136 isa_bus_new(NULL);
138 isa_bus_irqs(isa_irq);
140 pc_register_ferr_irq(isa_get_irq(13));
142 pc_vga_init(pci_enabled? pci_bus: NULL);
144 if (xen_enabled()) {
145 pci_create_simple(pci_bus, -1, "xen-platform");
148 /* init basic PC hardware */
149 pc_basic_device_init(isa_irq, &rtc_state, xen_enabled());
151 for(i = 0; i < nb_nics; i++) {
152 NICInfo *nd = &nd_table[i];
154 if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
155 pc_init_ne2k_isa(nd);
156 else
157 pci_nic_init_nofail(nd, "e1000", NULL);
160 ide_drive_get(hd, MAX_IDE_BUS);
161 if (pci_enabled) {
162 PCIDevice *dev;
163 dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
164 idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
165 idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
166 } else {
167 for(i = 0; i < MAX_IDE_BUS; i++) {
168 ISADevice *dev;
169 dev = isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
170 hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
171 idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
175 audio_init(isa_irq, pci_enabled ? pci_bus : NULL);
177 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
178 idebus[0], idebus[1], rtc_state);
180 if (pci_enabled && usb_enabled) {
181 usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
184 if (pci_enabled && acpi_enabled) {
185 i2c_bus *smbus;
187 if (!xen_enabled()) {
188 cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
189 } else {
190 cmos_s3 = qemu_allocate_irqs(xen_cmos_set_s3_resume, rtc_state, 1);
192 smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
193 /* TODO: Populate SPD eeprom data. */
194 smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
195 isa_get_irq(9), *cmos_s3, *smi_irq,
196 kvm_enabled());
197 smbus_eeprom_init(smbus, 8, NULL, 0);
200 if (i440fx_state) {
201 i440fx_init_memory_mappings(i440fx_state);
204 if (pci_enabled) {
205 pc_pci_device_init(pci_bus);
209 static void pc_init_pci(ram_addr_t ram_size,
210 const char *boot_device,
211 const char *kernel_filename,
212 const char *kernel_cmdline,
213 const char *initrd_filename,
214 const char *cpu_model)
216 pc_init1(get_system_memory(),
217 ram_size, boot_device,
218 kernel_filename, kernel_cmdline,
219 initrd_filename, cpu_model, 1, 1);
222 static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,
223 const char *boot_device,
224 const char *kernel_filename,
225 const char *kernel_cmdline,
226 const char *initrd_filename,
227 const char *cpu_model)
229 pc_init1(get_system_memory(),
230 ram_size, boot_device,
231 kernel_filename, kernel_cmdline,
232 initrd_filename, cpu_model, 1, 0);
235 static void pc_init_isa(ram_addr_t ram_size,
236 const char *boot_device,
237 const char *kernel_filename,
238 const char *kernel_cmdline,
239 const char *initrd_filename,
240 const char *cpu_model)
242 if (cpu_model == NULL)
243 cpu_model = "486";
244 pc_init1(get_system_memory(),
245 ram_size, boot_device,
246 kernel_filename, kernel_cmdline,
247 initrd_filename, cpu_model, 0, 1);
250 #ifdef CONFIG_XEN
251 static void pc_xen_hvm_init(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 if (xen_hvm_init() != 0) {
259 hw_error("xen hardware virtual machine initialisation failed");
261 pc_init_pci_no_kvmclock(ram_size, boot_device,
262 kernel_filename, kernel_cmdline,
263 initrd_filename, cpu_model);
264 xen_vcpu_init();
266 #endif
268 static QEMUMachine pc_machine = {
269 .name = "pc-0.14",
270 .alias = "pc",
271 .desc = "Standard PC",
272 .init = pc_init_pci,
273 .max_cpus = 255,
274 .is_default = 1,
277 static QEMUMachine pc_machine_v0_13 = {
278 .name = "pc-0.13",
279 .desc = "Standard PC",
280 .init = pc_init_pci_no_kvmclock,
281 .max_cpus = 255,
282 .compat_props = (GlobalProperty[]) {
284 .driver = "virtio-9p-pci",
285 .property = "vectors",
286 .value = stringify(0),
288 .driver = "VGA",
289 .property = "rombar",
290 .value = stringify(0),
292 .driver = "vmware-svga",
293 .property = "rombar",
294 .value = stringify(0),
296 .driver = "PCI",
297 .property = "command_serr_enable",
298 .value = "off",
300 .driver = "virtio-blk-pci",
301 .property = "event_idx",
302 .value = "off",
304 .driver = "virtio-serial-pci",
305 .property = "event_idx",
306 .value = "off",
308 .driver = "virtio-net-pci",
309 .property = "event_idx",
310 .value = "off",
312 { /* end of list */ }
316 static QEMUMachine pc_machine_v0_12 = {
317 .name = "pc-0.12",
318 .desc = "Standard PC",
319 .init = pc_init_pci_no_kvmclock,
320 .max_cpus = 255,
321 .compat_props = (GlobalProperty[]) {
323 .driver = "virtio-serial-pci",
324 .property = "max_ports",
325 .value = stringify(1),
327 .driver = "virtio-serial-pci",
328 .property = "vectors",
329 .value = stringify(0),
331 .driver = "VGA",
332 .property = "rombar",
333 .value = stringify(0),
335 .driver = "vmware-svga",
336 .property = "rombar",
337 .value = stringify(0),
339 .driver = "PCI",
340 .property = "command_serr_enable",
341 .value = "off",
343 .driver = "virtio-blk-pci",
344 .property = "event_idx",
345 .value = "off",
347 .driver = "virtio-serial-pci",
348 .property = "event_idx",
349 .value = "off",
351 .driver = "virtio-net-pci",
352 .property = "event_idx",
353 .value = "off",
355 { /* end of list */ }
359 static QEMUMachine pc_machine_v0_11 = {
360 .name = "pc-0.11",
361 .desc = "Standard PC, qemu 0.11",
362 .init = pc_init_pci_no_kvmclock,
363 .max_cpus = 255,
364 .compat_props = (GlobalProperty[]) {
366 .driver = "virtio-blk-pci",
367 .property = "vectors",
368 .value = stringify(0),
370 .driver = "virtio-serial-pci",
371 .property = "max_ports",
372 .value = stringify(1),
374 .driver = "virtio-serial-pci",
375 .property = "vectors",
376 .value = stringify(0),
378 .driver = "ide-drive",
379 .property = "ver",
380 .value = "0.11",
382 .driver = "scsi-disk",
383 .property = "ver",
384 .value = "0.11",
386 .driver = "PCI",
387 .property = "rombar",
388 .value = stringify(0),
390 .driver = "PCI",
391 .property = "command_serr_enable",
392 .value = "off",
394 .driver = "virtio-blk-pci",
395 .property = "event_idx",
396 .value = "off",
398 .driver = "virtio-serial-pci",
399 .property = "event_idx",
400 .value = "off",
402 .driver = "virtio-net-pci",
403 .property = "event_idx",
404 .value = "off",
406 { /* end of list */ }
410 static QEMUMachine pc_machine_v0_10 = {
411 .name = "pc-0.10",
412 .desc = "Standard PC, qemu 0.10",
413 .init = pc_init_pci_no_kvmclock,
414 .max_cpus = 255,
415 .compat_props = (GlobalProperty[]) {
417 .driver = "virtio-blk-pci",
418 .property = "class",
419 .value = stringify(PCI_CLASS_STORAGE_OTHER),
421 .driver = "virtio-serial-pci",
422 .property = "class",
423 .value = stringify(PCI_CLASS_DISPLAY_OTHER),
425 .driver = "virtio-serial-pci",
426 .property = "max_ports",
427 .value = stringify(1),
429 .driver = "virtio-serial-pci",
430 .property = "vectors",
431 .value = stringify(0),
433 .driver = "virtio-net-pci",
434 .property = "vectors",
435 .value = stringify(0),
437 .driver = "virtio-blk-pci",
438 .property = "vectors",
439 .value = stringify(0),
441 .driver = "ide-drive",
442 .property = "ver",
443 .value = "0.10",
445 .driver = "scsi-disk",
446 .property = "ver",
447 .value = "0.10",
449 .driver = "PCI",
450 .property = "rombar",
451 .value = stringify(0),
453 .driver = "PCI",
454 .property = "command_serr_enable",
455 .value = "off",
457 .driver = "virtio-blk-pci",
458 .property = "event_idx",
459 .value = "off",
461 .driver = "virtio-serial-pci",
462 .property = "event_idx",
463 .value = "off",
465 .driver = "virtio-net-pci",
466 .property = "event_idx",
467 .value = "off",
469 { /* end of list */ }
473 static QEMUMachine isapc_machine = {
474 .name = "isapc",
475 .desc = "ISA-only PC",
476 .init = pc_init_isa,
477 .max_cpus = 1,
480 #ifdef CONFIG_XEN
481 static QEMUMachine xenfv_machine = {
482 .name = "xenfv",
483 .desc = "Xen Fully-virtualized PC",
484 .init = pc_xen_hvm_init,
485 .max_cpus = HVM_MAX_VCPUS,
486 .default_machine_opts = "accel=xen",
488 #endif
490 static void pc_machine_init(void)
492 qemu_register_machine(&pc_machine);
493 qemu_register_machine(&pc_machine_v0_13);
494 qemu_register_machine(&pc_machine_v0_12);
495 qemu_register_machine(&pc_machine_v0_11);
496 qemu_register_machine(&pc_machine_v0_10);
497 qemu_register_machine(&isapc_machine);
498 #ifdef CONFIG_XEN
499 qemu_register_machine(&xenfv_machine);
500 #endif
503 machine_init(pc_machine_init);