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
38 #include "arch_init.h"
43 #include "exec-memory.h"
45 # include <xen/hvm/hvm_info_table.h>
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
)
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
,
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
,
82 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
84 PCII440FXState
*i440fx_state
;
91 IsaIrqState
*isa_irq_state
;
92 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
93 BusState
*idebus
[MAX_IDE_BUS
];
96 pc_cpus_init(cpu_model
);
98 if (kvmclock_enabled
) {
102 if (ram_size
>= 0xe0000000 ) {
103 above_4g_mem_size
= ram_size
- 0xe0000000;
104 below_4g_mem_size
= 0xe0000000;
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]);
121 i8259
= xen_interrupt_controller_init();
123 isa_irq_state
= qemu_mallocz(sizeof(*isa_irq_state
));
124 isa_irq_state
->i8259
= i8259
;
126 ioapic_init(isa_irq_state
);
128 isa_irq
= qemu_allocate_irqs(isa_irq_handler
, isa_irq_state
, 24);
131 pci_bus
= i440fx_init(&i440fx_state
, &piix3_devfn
, isa_irq
,
132 system_memory
, ram_size
);
138 isa_bus_irqs(isa_irq
);
140 pc_register_ferr_irq(isa_get_irq(13));
142 pc_vga_init(pci_enabled
? pci_bus
: NULL
);
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
);
157 pci_nic_init_nofail(nd
, "e1000", NULL
);
160 ide_drive_get(hd
, MAX_IDE_BUS
);
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");
167 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
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
) {
187 if (!xen_enabled()) {
188 cmos_s3
= qemu_allocate_irqs(pc_cmos_set_s3_resume
, rtc_state
, 1);
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
,
197 smbus_eeprom_init(smbus
, 8, NULL
, 0);
201 i440fx_init_memory_mappings(i440fx_state
);
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
)
244 pc_init1(get_system_memory(),
245 ram_size
, boot_device
,
246 kernel_filename
, kernel_cmdline
,
247 initrd_filename
, cpu_model
, 0, 1);
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
);
268 static QEMUMachine pc_machine
= {
271 .desc
= "Standard PC",
277 static QEMUMachine pc_machine_v0_13
= {
279 .desc
= "Standard PC",
280 .init
= pc_init_pci_no_kvmclock
,
282 .compat_props
= (GlobalProperty
[]) {
284 .driver
= "virtio-9p-pci",
285 .property
= "vectors",
286 .value
= stringify(0),
289 .property
= "rombar",
290 .value
= stringify(0),
292 .driver
= "vmware-svga",
293 .property
= "rombar",
294 .value
= stringify(0),
297 .property
= "command_serr_enable",
300 .driver
= "virtio-blk-pci",
301 .property
= "event_idx",
304 .driver
= "virtio-serial-pci",
305 .property
= "event_idx",
308 .driver
= "virtio-net-pci",
309 .property
= "event_idx",
312 { /* end of list */ }
316 static QEMUMachine pc_machine_v0_12
= {
318 .desc
= "Standard PC",
319 .init
= pc_init_pci_no_kvmclock
,
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),
332 .property
= "rombar",
333 .value
= stringify(0),
335 .driver
= "vmware-svga",
336 .property
= "rombar",
337 .value
= stringify(0),
340 .property
= "command_serr_enable",
343 .driver
= "virtio-blk-pci",
344 .property
= "event_idx",
347 .driver
= "virtio-serial-pci",
348 .property
= "event_idx",
351 .driver
= "virtio-net-pci",
352 .property
= "event_idx",
355 { /* end of list */ }
359 static QEMUMachine pc_machine_v0_11
= {
361 .desc
= "Standard PC, qemu 0.11",
362 .init
= pc_init_pci_no_kvmclock
,
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",
382 .driver
= "scsi-disk",
387 .property
= "rombar",
388 .value
= stringify(0),
391 .property
= "command_serr_enable",
394 .driver
= "virtio-blk-pci",
395 .property
= "event_idx",
398 .driver
= "virtio-serial-pci",
399 .property
= "event_idx",
402 .driver
= "virtio-net-pci",
403 .property
= "event_idx",
406 { /* end of list */ }
410 static QEMUMachine pc_machine_v0_10
= {
412 .desc
= "Standard PC, qemu 0.10",
413 .init
= pc_init_pci_no_kvmclock
,
415 .compat_props
= (GlobalProperty
[]) {
417 .driver
= "virtio-blk-pci",
419 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
421 .driver
= "virtio-serial-pci",
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",
445 .driver
= "scsi-disk",
450 .property
= "rombar",
451 .value
= stringify(0),
454 .property
= "command_serr_enable",
457 .driver
= "virtio-blk-pci",
458 .property
= "event_idx",
461 .driver
= "virtio-serial-pci",
462 .property
= "event_idx",
465 .driver
= "virtio-net-pci",
466 .property
= "event_idx",
469 { /* end of list */ }
473 static QEMUMachine isapc_machine
= {
475 .desc
= "ISA-only PC",
481 static QEMUMachine xenfv_machine
= {
483 .desc
= "Xen Fully-virtualized PC",
484 .init
= pc_xen_hvm_init
,
485 .max_cpus
= HVM_MAX_VCPUS
,
486 .default_machine_opts
= "accel=xen",
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
);
499 qemu_register_machine(&xenfv_machine
);
503 machine_init(pc_machine_init
);