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
40 #include "arch_init.h"
45 #include "exec-memory.h"
47 # include <xen/hvm/hvm_info_table.h>
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
)
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
,
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
,
85 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
87 PCII440FXState
*i440fx_state
;
95 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
96 BusState
*idebus
[MAX_IDE_BUS
];
99 MemoryRegion
*ram_memory
;
100 MemoryRegion
*pci_memory
;
101 MemoryRegion
*rom_memory
;
104 pc_cpus_init(cpu_model
);
106 if (kvmclock_enabled
) {
110 if (ram_size
>= 0xe0000000 ) {
111 above_4g_mem_size
= ram_size
- 0xe0000000;
112 below_4g_mem_size
= 0xe0000000;
114 above_4g_mem_size
= 0;
115 below_4g_mem_size
= ram_size
;
119 pci_memory
= g_new(MemoryRegion
, 1);
120 memory_region_init(pci_memory
, "pci", INT64_MAX
);
121 rom_memory
= pci_memory
;
124 rom_memory
= system_memory
;
127 /* allocate ram and load rom/bios */
128 if (!xen_enabled()) {
129 pc_memory_init(system_memory
,
130 kernel_filename
, kernel_cmdline
, initrd_filename
,
131 below_4g_mem_size
, above_4g_mem_size
,
132 pci_enabled
? rom_memory
: system_memory
, &ram_memory
);
135 gsi_state
= g_malloc0(sizeof(*gsi_state
));
136 gsi
= qemu_allocate_irqs(gsi_handler
, gsi_state
, GSI_NUM_PINS
);
139 pci_bus
= i440fx_init(&i440fx_state
, &piix3_devfn
, gsi
,
140 system_memory
, system_io
, ram_size
,
142 0x100000000ULL
- below_4g_mem_size
,
143 0x100000000ULL
+ above_4g_mem_size
,
144 (sizeof(target_phys_addr_t
) == 4
146 : ((uint64_t)1 << 62)),
147 pci_memory
, ram_memory
);
151 isa_bus_new(NULL
, system_io
);
156 if (!xen_enabled()) {
157 cpu_irq
= pc_allocate_cpu_irq();
158 i8259
= i8259_init(cpu_irq
[0]);
160 i8259
= xen_interrupt_controller_init();
163 for (i
= 0; i
< ISA_NUM_IRQS
; i
++) {
164 gsi_state
->i8259_irq
[i
] = i8259
[i
];
167 ioapic_init(gsi_state
);
170 pc_register_ferr_irq(gsi
[13]);
172 dev
= pc_vga_init(pci_enabled
? pci_bus
: NULL
);
174 qdev_property_add_child(qdev_get_root(), "vga", dev
, NULL
);
178 pci_create_simple(pci_bus
, -1, "xen-platform");
181 /* init basic PC hardware */
182 pc_basic_device_init(gsi
, &rtc_state
, &floppy
, xen_enabled());
184 for(i
= 0; i
< nb_nics
; i
++) {
185 NICInfo
*nd
= &nd_table
[i
];
187 if (!pci_enabled
|| (nd
->model
&& strcmp(nd
->model
, "ne2k_isa") == 0))
188 pc_init_ne2k_isa(nd
);
190 pci_nic_init_nofail(nd
, "e1000", NULL
);
193 ide_drive_get(hd
, MAX_IDE_BUS
);
197 dev
= pci_piix3_xen_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
199 dev
= pci_piix3_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
201 idebus
[0] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
202 idebus
[1] = qdev_get_child_bus(&dev
->qdev
, "ide.1");
204 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
206 dev
= isa_ide_init(ide_iobase
[i
], ide_iobase2
[i
], ide_irq
[i
],
207 hd
[MAX_IDE_DEVS
* i
], hd
[MAX_IDE_DEVS
* i
+ 1]);
208 idebus
[i
] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
212 /* FIXME there's some major spaghetti here. Somehow we create the devices
213 * on the PIIX before we actually create it. We create the PIIX3 deep in
214 * the recess of the i440fx creation too and then lose the DeviceState.
216 * For now, let's "fix" this by making judicious use of paths. This is not
217 * generally the right way to do this.
220 qdev_property_add_child(qdev_resolve_path("/i440fx/piix3", NULL
),
221 "rtc", (DeviceState
*)rtc_state
, NULL
);
223 audio_init(gsi
, pci_enabled
? pci_bus
: NULL
);
225 pc_cmos_init(below_4g_mem_size
, above_4g_mem_size
, boot_device
,
226 floppy
, idebus
[0], idebus
[1], rtc_state
);
228 if (pci_enabled
&& usb_enabled
) {
229 usb_uhci_piix3_init(pci_bus
, piix3_devfn
+ 2);
232 if (pci_enabled
&& acpi_enabled
) {
235 if (!xen_enabled()) {
236 cmos_s3
= qemu_allocate_irqs(pc_cmos_set_s3_resume
, rtc_state
, 1);
238 cmos_s3
= qemu_allocate_irqs(xen_cmos_set_s3_resume
, rtc_state
, 1);
240 smi_irq
= qemu_allocate_irqs(pc_acpi_smi_interrupt
, first_cpu
, 1);
241 /* TODO: Populate SPD eeprom data. */
242 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
243 gsi
[9], *cmos_s3
, *smi_irq
,
245 smbus_eeprom_init(smbus
, 8, NULL
, 0);
249 pc_pci_device_init(pci_bus
);
253 static void pc_init_pci(ram_addr_t ram_size
,
254 const char *boot_device
,
255 const char *kernel_filename
,
256 const char *kernel_cmdline
,
257 const char *initrd_filename
,
258 const char *cpu_model
)
260 pc_init1(get_system_memory(),
262 ram_size
, boot_device
,
263 kernel_filename
, kernel_cmdline
,
264 initrd_filename
, cpu_model
, 1, 1);
267 static void pc_init_pci_no_kvmclock(ram_addr_t ram_size
,
268 const char *boot_device
,
269 const char *kernel_filename
,
270 const char *kernel_cmdline
,
271 const char *initrd_filename
,
272 const char *cpu_model
)
274 pc_init1(get_system_memory(),
276 ram_size
, boot_device
,
277 kernel_filename
, kernel_cmdline
,
278 initrd_filename
, cpu_model
, 1, 0);
281 static void pc_init_isa(ram_addr_t ram_size
,
282 const char *boot_device
,
283 const char *kernel_filename
,
284 const char *kernel_cmdline
,
285 const char *initrd_filename
,
286 const char *cpu_model
)
288 if (cpu_model
== NULL
)
290 pc_init1(get_system_memory(),
292 ram_size
, boot_device
,
293 kernel_filename
, kernel_cmdline
,
294 initrd_filename
, cpu_model
, 0, 1);
298 static void pc_xen_hvm_init(ram_addr_t ram_size
,
299 const char *boot_device
,
300 const char *kernel_filename
,
301 const char *kernel_cmdline
,
302 const char *initrd_filename
,
303 const char *cpu_model
)
305 if (xen_hvm_init() != 0) {
306 hw_error("xen hardware virtual machine initialisation failed");
308 pc_init_pci_no_kvmclock(ram_size
, boot_device
,
309 kernel_filename
, kernel_cmdline
,
310 initrd_filename
, cpu_model
);
315 static QEMUMachine pc_machine_v1_0
= {
318 .desc
= "Standard PC",
324 static QEMUMachine pc_machine_v0_15
= {
326 .desc
= "Standard PC",
332 static QEMUMachine pc_machine_v0_14
= {
334 .desc
= "Standard PC",
337 .compat_props
= (GlobalProperty
[]) {
340 .property
= "revision",
341 .value
= stringify(2),
344 .property
= "revision",
345 .value
= stringify(2),
347 .driver
= "virtio-blk-pci",
348 .property
= "event_idx",
351 .driver
= "virtio-serial-pci",
352 .property
= "event_idx",
355 .driver
= "virtio-net-pci",
356 .property
= "event_idx",
359 .driver
= "virtio-balloon-pci",
360 .property
= "event_idx",
363 { /* end of list */ }
367 static QEMUMachine pc_machine_v0_13
= {
369 .desc
= "Standard PC",
370 .init
= pc_init_pci_no_kvmclock
,
372 .compat_props
= (GlobalProperty
[]) {
374 .driver
= "virtio-9p-pci",
375 .property
= "vectors",
376 .value
= stringify(0),
379 .property
= "rombar",
380 .value
= stringify(0),
382 .driver
= "vmware-svga",
383 .property
= "rombar",
384 .value
= stringify(0),
387 .property
= "command_serr_enable",
390 .driver
= "virtio-blk-pci",
391 .property
= "event_idx",
394 .driver
= "virtio-serial-pci",
395 .property
= "event_idx",
398 .driver
= "virtio-net-pci",
399 .property
= "event_idx",
402 .driver
= "virtio-balloon-pci",
403 .property
= "event_idx",
407 .property
= "use_broken_id",
408 .value
= stringify(1),
410 { /* end of list */ }
414 static QEMUMachine pc_machine_v0_12
= {
416 .desc
= "Standard PC",
417 .init
= pc_init_pci_no_kvmclock
,
419 .compat_props
= (GlobalProperty
[]) {
421 .driver
= "virtio-serial-pci",
422 .property
= "max_ports",
423 .value
= stringify(1),
425 .driver
= "virtio-serial-pci",
426 .property
= "vectors",
427 .value
= stringify(0),
430 .property
= "rombar",
431 .value
= stringify(0),
433 .driver
= "vmware-svga",
434 .property
= "rombar",
435 .value
= stringify(0),
438 .property
= "command_serr_enable",
441 .driver
= "virtio-blk-pci",
442 .property
= "event_idx",
445 .driver
= "virtio-serial-pci",
446 .property
= "event_idx",
449 .driver
= "virtio-net-pci",
450 .property
= "event_idx",
453 .driver
= "virtio-balloon-pci",
454 .property
= "event_idx",
458 .property
= "use_broken_id",
459 .value
= stringify(1),
461 { /* end of list */ }
465 static QEMUMachine pc_machine_v0_11
= {
467 .desc
= "Standard PC, qemu 0.11",
468 .init
= pc_init_pci_no_kvmclock
,
470 .compat_props
= (GlobalProperty
[]) {
472 .driver
= "virtio-blk-pci",
473 .property
= "vectors",
474 .value
= stringify(0),
476 .driver
= "virtio-serial-pci",
477 .property
= "max_ports",
478 .value
= stringify(1),
480 .driver
= "virtio-serial-pci",
481 .property
= "vectors",
482 .value
= stringify(0),
484 .driver
= "ide-drive",
488 .driver
= "scsi-disk",
493 .property
= "rombar",
494 .value
= stringify(0),
497 .property
= "command_serr_enable",
500 .driver
= "virtio-blk-pci",
501 .property
= "event_idx",
504 .driver
= "virtio-serial-pci",
505 .property
= "event_idx",
508 .driver
= "virtio-net-pci",
509 .property
= "event_idx",
512 .driver
= "virtio-balloon-pci",
513 .property
= "event_idx",
517 .property
= "use_broken_id",
518 .value
= stringify(1),
520 { /* end of list */ }
524 static QEMUMachine pc_machine_v0_10
= {
526 .desc
= "Standard PC, qemu 0.10",
527 .init
= pc_init_pci_no_kvmclock
,
529 .compat_props
= (GlobalProperty
[]) {
531 .driver
= "virtio-blk-pci",
533 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
535 .driver
= "virtio-serial-pci",
537 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
539 .driver
= "virtio-serial-pci",
540 .property
= "max_ports",
541 .value
= stringify(1),
543 .driver
= "virtio-serial-pci",
544 .property
= "vectors",
545 .value
= stringify(0),
547 .driver
= "virtio-net-pci",
548 .property
= "vectors",
549 .value
= stringify(0),
551 .driver
= "virtio-blk-pci",
552 .property
= "vectors",
553 .value
= stringify(0),
555 .driver
= "ide-drive",
559 .driver
= "scsi-disk",
564 .property
= "rombar",
565 .value
= stringify(0),
568 .property
= "command_serr_enable",
571 .driver
= "virtio-blk-pci",
572 .property
= "event_idx",
575 .driver
= "virtio-serial-pci",
576 .property
= "event_idx",
579 .driver
= "virtio-net-pci",
580 .property
= "event_idx",
583 .driver
= "virtio-balloon-pci",
584 .property
= "event_idx",
588 .property
= "use_broken_id",
589 .value
= stringify(1),
591 { /* end of list */ }
595 static QEMUMachine isapc_machine
= {
597 .desc
= "ISA-only PC",
603 static QEMUMachine xenfv_machine
= {
605 .desc
= "Xen Fully-virtualized PC",
606 .init
= pc_xen_hvm_init
,
607 .max_cpus
= HVM_MAX_VCPUS
,
608 .default_machine_opts
= "accel=xen",
612 static void pc_machine_init(void)
614 qemu_register_machine(&pc_machine_v1_0
);
615 qemu_register_machine(&pc_machine_v0_15
);
616 qemu_register_machine(&pc_machine_v0_14
);
617 qemu_register_machine(&pc_machine_v0_13
);
618 qemu_register_machine(&pc_machine_v0_12
);
619 qemu_register_machine(&pc_machine_v0_11
);
620 qemu_register_machine(&pc_machine_v0_10
);
621 qemu_register_machine(&isapc_machine
);
623 qemu_register_machine(&xenfv_machine
);
627 machine_init(pc_machine_init
);