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 <xen/hvm/hvm_info_table.h>
46 qemu_irq
*ioapic_irq_hack
;
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 const char *global_cpu_model
; /* cpu hotadd */
56 static void ioapic_init(IsaIrqState
*isa_irq_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 isa_irq_state
->ioapic
[i
] = qdev_get_gpio_in(dev
, i
);
72 /* PC hardware initialisation */
73 static void pc_init1(ram_addr_t ram_size
,
74 const char *boot_device
,
75 const char *kernel_filename
,
76 const char *kernel_cmdline
,
77 const char *initrd_filename
,
78 const char *cpu_model
,
83 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
85 PCII440FXState
*i440fx_state
;
92 IsaIrqState
*isa_irq_state
;
93 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
94 BusState
*idebus
[MAX_IDE_BUS
];
97 global_cpu_model
= cpu_model
;
99 pc_cpus_init(cpu_model
);
101 if (kvmclock_enabled
) {
105 if (ram_size
>= 0xe0000000 ) {
106 above_4g_mem_size
= ram_size
- 0xe0000000;
107 below_4g_mem_size
= 0xe0000000;
109 above_4g_mem_size
= 0;
110 below_4g_mem_size
= ram_size
;
113 /* allocate ram and load rom/bios */
114 if (!xen_enabled()) {
115 pc_memory_init(kernel_filename
, kernel_cmdline
, initrd_filename
,
116 below_4g_mem_size
, above_4g_mem_size
);
119 if (!xen_enabled()) {
120 cpu_irq
= pc_allocate_cpu_irq();
121 if (!(kvm_enabled() && kvm_irqchip_in_kernel())) {
122 i8259
= i8259_init(cpu_irq
[0]);
124 i8259
= kvm_i8259_init(cpu_irq
[0]);
127 i8259
= xen_interrupt_controller_init();
129 isa_irq_state
= qemu_mallocz(sizeof(*isa_irq_state
));
130 isa_irq_state
->i8259
= i8259
;
132 ioapic_init(isa_irq_state
);
134 if (!(kvm_enabled() && kvm_irqchip_in_kernel())) {
135 isa_irq
= qemu_allocate_irqs(isa_irq_handler
, isa_irq_state
, 24);
141 if (!xen_enabled()) {
142 pci_bus
= i440fx_init(&i440fx_state
, &piix3_devfn
, isa_irq
, ram_size
);
144 pci_bus
= i440fx_xen_init(&i440fx_state
, &piix3_devfn
, isa_irq
, ram_size
);
151 isa_bus_irqs(isa_irq
);
153 pc_register_ferr_irq(isa_get_irq(13));
155 pc_vga_init(pci_enabled
? pci_bus
: NULL
);
157 /* init basic PC hardware */
158 pc_basic_device_init(isa_irq
, &rtc_state
, xen_enabled());
160 for(i
= 0; i
< nb_nics
; i
++) {
161 NICInfo
*nd
= &nd_table
[i
];
163 if (!pci_enabled
|| (nd
->model
&& strcmp(nd
->model
, "ne2k_isa") == 0))
164 pc_init_ne2k_isa(nd
);
166 pci_nic_init_nofail(nd
, "rtl8139", NULL
);
169 ide_drive_get(hd
, MAX_IDE_BUS
);
172 dev
= pci_piix3_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
173 idebus
[0] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
174 idebus
[1] = qdev_get_child_bus(&dev
->qdev
, "ide.1");
176 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
178 dev
= isa_ide_init(ide_iobase
[i
], ide_iobase2
[i
], ide_irq
[i
],
179 hd
[MAX_IDE_DEVS
* i
], hd
[MAX_IDE_DEVS
* i
+ 1]);
180 idebus
[i
] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
184 audio_init(isa_irq
, pci_enabled
? pci_bus
: NULL
);
186 pc_cmos_init(below_4g_mem_size
, above_4g_mem_size
, boot_device
,
187 idebus
[0], idebus
[1], rtc_state
);
189 if (pci_enabled
&& usb_enabled
) {
190 usb_uhci_piix3_init(pci_bus
, piix3_devfn
+ 2);
193 if (pci_enabled
&& acpi_enabled
) {
196 if (!xen_enabled()) {
197 cmos_s3
= qemu_allocate_irqs(pc_cmos_set_s3_resume
, rtc_state
, 1);
199 cmos_s3
= qemu_allocate_irqs(xen_cmos_set_s3_resume
, rtc_state
, 1);
201 smi_irq
= qemu_allocate_irqs(pc_acpi_smi_interrupt
, first_cpu
, 1);
202 /* TODO: Populate SPD eeprom data. */
203 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
204 isa_get_irq(9), *cmos_s3
, *smi_irq
,
206 smbus_eeprom_init(smbus
, 8, NULL
, 0);
210 i440fx_init_memory_mappings(i440fx_state
);
214 pc_pci_device_init(pci_bus
);
218 static void pc_init_pci(ram_addr_t ram_size
,
219 const char *boot_device
,
220 const char *kernel_filename
,
221 const char *kernel_cmdline
,
222 const char *initrd_filename
,
223 const char *cpu_model
)
225 pc_init1(ram_size
, boot_device
,
226 kernel_filename
, kernel_cmdline
,
227 initrd_filename
, cpu_model
, 1, 1);
230 static void pc_init_pci_no_kvmclock(ram_addr_t ram_size
,
231 const char *boot_device
,
232 const char *kernel_filename
,
233 const char *kernel_cmdline
,
234 const char *initrd_filename
,
235 const char *cpu_model
)
237 pc_init1(ram_size
, boot_device
,
238 kernel_filename
, kernel_cmdline
,
239 initrd_filename
, cpu_model
, 1, 0);
242 static void pc_init_isa(ram_addr_t ram_size
,
243 const char *boot_device
,
244 const char *kernel_filename
,
245 const char *kernel_cmdline
,
246 const char *initrd_filename
,
247 const char *cpu_model
)
249 if (cpu_model
== NULL
)
251 pc_init1(ram_size
, boot_device
,
252 kernel_filename
, kernel_cmdline
,
253 initrd_filename
, cpu_model
, 0, 1);
257 static void pc_xen_hvm_init(ram_addr_t ram_size
,
258 const char *boot_device
,
259 const char *kernel_filename
,
260 const char *kernel_cmdline
,
261 const char *initrd_filename
,
262 const char *cpu_model
)
264 if (xen_hvm_init() != 0) {
265 hw_error("xen hardware virtual machine initialisation failed");
267 pc_init_pci_no_kvmclock(ram_size
, boot_device
,
268 kernel_filename
, kernel_cmdline
,
269 initrd_filename
, cpu_model
);
274 static QEMUMachine pc_machine
= {
277 .desc
= "Standard PC",
283 static QEMUMachine pc_machine_v0_13
= {
285 .desc
= "Standard PC",
286 .init
= pc_init_pci_no_kvmclock
,
288 .compat_props
= (GlobalProperty
[]) {
290 .driver
= "virtio-9p-pci",
291 .property
= "vectors",
292 .value
= stringify(0),
295 .property
= "rombar",
296 .value
= stringify(0),
298 .driver
= "vmware-svga",
299 .property
= "rombar",
300 .value
= stringify(0),
303 .property
= "command_serr_enable",
306 { /* end of list */ }
310 static QEMUMachine pc_machine_v0_12
= {
312 .desc
= "Standard PC",
313 .init
= pc_init_pci_no_kvmclock
,
315 .compat_props
= (GlobalProperty
[]) {
317 .driver
= "virtio-serial-pci",
318 .property
= "max_ports",
319 .value
= stringify(1),
321 .driver
= "virtio-serial-pci",
322 .property
= "vectors",
323 .value
= stringify(0),
326 .property
= "rombar",
327 .value
= stringify(0),
329 .driver
= "vmware-svga",
330 .property
= "rombar",
331 .value
= stringify(0),
334 .property
= "command_serr_enable",
337 { /* end of list */ }
341 static QEMUMachine pc_machine_v0_11
= {
343 .desc
= "Standard PC, qemu 0.11",
344 .init
= pc_init_pci_no_kvmclock
,
346 .compat_props
= (GlobalProperty
[]) {
348 .driver
= "virtio-blk-pci",
349 .property
= "vectors",
350 .value
= stringify(0),
352 .driver
= "virtio-serial-pci",
353 .property
= "max_ports",
354 .value
= stringify(1),
356 .driver
= "virtio-serial-pci",
357 .property
= "vectors",
358 .value
= stringify(0),
360 .driver
= "ide-drive",
364 .driver
= "scsi-disk",
369 .property
= "rombar",
370 .value
= stringify(0),
373 .property
= "command_serr_enable",
376 { /* end of list */ }
380 static QEMUMachine pc_machine_v0_10
= {
382 .desc
= "Standard PC, qemu 0.10",
383 .init
= pc_init_pci_no_kvmclock
,
385 .compat_props
= (GlobalProperty
[]) {
387 .driver
= "virtio-blk-pci",
389 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
391 .driver
= "virtio-serial-pci",
393 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
395 .driver
= "virtio-serial-pci",
396 .property
= "max_ports",
397 .value
= stringify(1),
399 .driver
= "virtio-serial-pci",
400 .property
= "vectors",
401 .value
= stringify(0),
403 .driver
= "virtio-net-pci",
404 .property
= "vectors",
405 .value
= stringify(0),
407 .driver
= "virtio-blk-pci",
408 .property
= "vectors",
409 .value
= stringify(0),
411 .driver
= "ide-drive",
415 .driver
= "scsi-disk",
420 .property
= "rombar",
421 .value
= stringify(0),
424 .property
= "command_serr_enable",
427 { /* end of list */ }
431 static QEMUMachine isapc_machine
= {
433 .desc
= "ISA-only PC",
439 static QEMUMachine xenfv_machine
= {
441 .desc
= "Xen Fully-virtualized PC",
442 .init
= pc_xen_hvm_init
,
443 .max_cpus
= HVM_MAX_VCPUS
,
444 .default_machine_opts
= "accel=xen",
448 static void pc_machine_init(void)
450 qemu_register_machine(&pc_machine
);
451 qemu_register_machine(&pc_machine_v0_13
);
452 qemu_register_machine(&pc_machine_v0_12
);
453 qemu_register_machine(&pc_machine_v0_11
);
454 qemu_register_machine(&pc_machine_v0_10
);
455 qemu_register_machine(&isapc_machine
);
457 qemu_register_machine(&xenfv_machine
);
461 machine_init(pc_machine_init
);