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
;
103 pc_cpus_init(cpu_model
);
105 if (kvmclock_enabled
) {
109 if (ram_size
>= 0xe0000000 ) {
110 above_4g_mem_size
= ram_size
- 0xe0000000;
111 below_4g_mem_size
= 0xe0000000;
113 above_4g_mem_size
= 0;
114 below_4g_mem_size
= ram_size
;
118 pci_memory
= g_new(MemoryRegion
, 1);
119 memory_region_init(pci_memory
, "pci", INT64_MAX
);
120 rom_memory
= pci_memory
;
123 rom_memory
= system_memory
;
126 /* allocate ram and load rom/bios */
127 if (!xen_enabled()) {
128 pc_memory_init(system_memory
,
129 kernel_filename
, kernel_cmdline
, initrd_filename
,
130 below_4g_mem_size
, above_4g_mem_size
,
131 pci_enabled
? rom_memory
: system_memory
, &ram_memory
);
134 gsi_state
= g_malloc0(sizeof(*gsi_state
));
135 gsi
= qemu_allocate_irqs(gsi_handler
, gsi_state
, GSI_NUM_PINS
);
138 pci_bus
= i440fx_init(&i440fx_state
, &piix3_devfn
, gsi
,
139 system_memory
, system_io
, ram_size
,
141 0x100000000ULL
- below_4g_mem_size
,
142 0x100000000ULL
+ above_4g_mem_size
,
143 (sizeof(target_phys_addr_t
) == 4
145 : ((uint64_t)1 << 62)),
146 pci_memory
, ram_memory
);
150 isa_bus_new(NULL
, system_io
);
155 if (!xen_enabled()) {
156 cpu_irq
= pc_allocate_cpu_irq();
157 i8259
= i8259_init(cpu_irq
[0]);
159 i8259
= xen_interrupt_controller_init();
162 for (i
= 0; i
< ISA_NUM_IRQS
; i
++) {
163 gsi_state
->i8259_irq
[i
] = i8259
[i
];
166 ioapic_init(gsi_state
);
169 pc_register_ferr_irq(gsi
[13]);
171 pc_vga_init(pci_enabled
? pci_bus
: NULL
);
174 pci_create_simple(pci_bus
, -1, "xen-platform");
177 /* init basic PC hardware */
178 pc_basic_device_init(gsi
, &rtc_state
, &floppy
, xen_enabled());
180 for(i
= 0; i
< nb_nics
; i
++) {
181 NICInfo
*nd
= &nd_table
[i
];
183 if (!pci_enabled
|| (nd
->model
&& strcmp(nd
->model
, "ne2k_isa") == 0))
184 pc_init_ne2k_isa(nd
);
186 pci_nic_init_nofail(nd
, "e1000", NULL
);
189 ide_drive_get(hd
, MAX_IDE_BUS
);
193 dev
= pci_piix3_xen_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
195 dev
= pci_piix3_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
197 idebus
[0] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
198 idebus
[1] = qdev_get_child_bus(&dev
->qdev
, "ide.1");
200 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
202 dev
= isa_ide_init(ide_iobase
[i
], ide_iobase2
[i
], ide_irq
[i
],
203 hd
[MAX_IDE_DEVS
* i
], hd
[MAX_IDE_DEVS
* i
+ 1]);
204 idebus
[i
] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
208 audio_init(gsi
, pci_enabled
? pci_bus
: NULL
);
210 pc_cmos_init(below_4g_mem_size
, above_4g_mem_size
, boot_device
,
211 floppy
, idebus
[0], idebus
[1], rtc_state
);
213 if (pci_enabled
&& usb_enabled
) {
214 usb_uhci_piix3_init(pci_bus
, piix3_devfn
+ 2);
217 if (pci_enabled
&& acpi_enabled
) {
220 if (!xen_enabled()) {
221 cmos_s3
= qemu_allocate_irqs(pc_cmos_set_s3_resume
, rtc_state
, 1);
223 cmos_s3
= qemu_allocate_irqs(xen_cmos_set_s3_resume
, rtc_state
, 1);
225 smi_irq
= qemu_allocate_irqs(pc_acpi_smi_interrupt
, first_cpu
, 1);
226 /* TODO: Populate SPD eeprom data. */
227 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
228 gsi
[9], *cmos_s3
, *smi_irq
,
230 smbus_eeprom_init(smbus
, 8, NULL
, 0);
234 pc_pci_device_init(pci_bus
);
238 static void pc_init_pci(ram_addr_t ram_size
,
239 const char *boot_device
,
240 const char *kernel_filename
,
241 const char *kernel_cmdline
,
242 const char *initrd_filename
,
243 const char *cpu_model
)
245 pc_init1(get_system_memory(),
247 ram_size
, boot_device
,
248 kernel_filename
, kernel_cmdline
,
249 initrd_filename
, cpu_model
, 1, 1);
252 static void pc_init_pci_no_kvmclock(ram_addr_t ram_size
,
253 const char *boot_device
,
254 const char *kernel_filename
,
255 const char *kernel_cmdline
,
256 const char *initrd_filename
,
257 const char *cpu_model
)
259 pc_init1(get_system_memory(),
261 ram_size
, boot_device
,
262 kernel_filename
, kernel_cmdline
,
263 initrd_filename
, cpu_model
, 1, 0);
266 static void pc_init_isa(ram_addr_t ram_size
,
267 const char *boot_device
,
268 const char *kernel_filename
,
269 const char *kernel_cmdline
,
270 const char *initrd_filename
,
271 const char *cpu_model
)
273 if (cpu_model
== NULL
)
275 pc_init1(get_system_memory(),
277 ram_size
, boot_device
,
278 kernel_filename
, kernel_cmdline
,
279 initrd_filename
, cpu_model
, 0, 1);
283 static void pc_xen_hvm_init(ram_addr_t ram_size
,
284 const char *boot_device
,
285 const char *kernel_filename
,
286 const char *kernel_cmdline
,
287 const char *initrd_filename
,
288 const char *cpu_model
)
290 if (xen_hvm_init() != 0) {
291 hw_error("xen hardware virtual machine initialisation failed");
293 pc_init_pci_no_kvmclock(ram_size
, boot_device
,
294 kernel_filename
, kernel_cmdline
,
295 initrd_filename
, cpu_model
);
300 static QEMUMachine pc_machine_v1_0
= {
303 .desc
= "Standard PC",
309 static QEMUMachine pc_machine_v0_14
= {
311 .desc
= "Standard PC",
316 static QEMUMachine pc_machine_v0_13
= {
318 .desc
= "Standard PC",
319 .init
= pc_init_pci_no_kvmclock
,
321 .compat_props
= (GlobalProperty
[]) {
323 .driver
= "virtio-9p-pci",
324 .property
= "vectors",
325 .value
= stringify(0),
328 .property
= "rombar",
329 .value
= stringify(0),
331 .driver
= "vmware-svga",
332 .property
= "rombar",
333 .value
= stringify(0),
336 .property
= "command_serr_enable",
339 .driver
= "virtio-blk-pci",
340 .property
= "event_idx",
343 .driver
= "virtio-serial-pci",
344 .property
= "event_idx",
347 .driver
= "virtio-net-pci",
348 .property
= "event_idx",
352 .property
= "use_broken_id",
353 .value
= stringify(1),
355 { /* end of list */ }
359 static QEMUMachine pc_machine_v0_12
= {
361 .desc
= "Standard PC",
362 .init
= pc_init_pci_no_kvmclock
,
364 .compat_props
= (GlobalProperty
[]) {
366 .driver
= "virtio-serial-pci",
367 .property
= "max_ports",
368 .value
= stringify(1),
370 .driver
= "virtio-serial-pci",
371 .property
= "vectors",
372 .value
= stringify(0),
375 .property
= "rombar",
376 .value
= stringify(0),
378 .driver
= "vmware-svga",
379 .property
= "rombar",
380 .value
= stringify(0),
383 .property
= "command_serr_enable",
386 .driver
= "virtio-blk-pci",
387 .property
= "event_idx",
390 .driver
= "virtio-serial-pci",
391 .property
= "event_idx",
394 .driver
= "virtio-net-pci",
395 .property
= "event_idx",
399 .property
= "use_broken_id",
400 .value
= stringify(1),
402 { /* end of list */ }
406 static QEMUMachine pc_machine_v0_11
= {
408 .desc
= "Standard PC, qemu 0.11",
409 .init
= pc_init_pci_no_kvmclock
,
411 .compat_props
= (GlobalProperty
[]) {
413 .driver
= "virtio-blk-pci",
414 .property
= "vectors",
415 .value
= stringify(0),
417 .driver
= "virtio-serial-pci",
418 .property
= "max_ports",
419 .value
= stringify(1),
421 .driver
= "virtio-serial-pci",
422 .property
= "vectors",
423 .value
= stringify(0),
425 .driver
= "ide-drive",
429 .driver
= "scsi-disk",
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",
454 .property
= "use_broken_id",
455 .value
= stringify(1),
457 { /* end of list */ }
461 static QEMUMachine pc_machine_v0_10
= {
463 .desc
= "Standard PC, qemu 0.10",
464 .init
= pc_init_pci_no_kvmclock
,
466 .compat_props
= (GlobalProperty
[]) {
468 .driver
= "virtio-blk-pci",
470 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
472 .driver
= "virtio-serial-pci",
474 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
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
= "virtio-net-pci",
485 .property
= "vectors",
486 .value
= stringify(0),
488 .driver
= "virtio-blk-pci",
489 .property
= "vectors",
490 .value
= stringify(0),
492 .driver
= "ide-drive",
496 .driver
= "scsi-disk",
501 .property
= "rombar",
502 .value
= stringify(0),
505 .property
= "command_serr_enable",
508 .driver
= "virtio-blk-pci",
509 .property
= "event_idx",
512 .driver
= "virtio-serial-pci",
513 .property
= "event_idx",
516 .driver
= "virtio-net-pci",
517 .property
= "event_idx",
521 .property
= "use_broken_id",
522 .value
= stringify(1),
524 { /* end of list */ }
528 static QEMUMachine isapc_machine
= {
530 .desc
= "ISA-only PC",
536 static QEMUMachine xenfv_machine
= {
538 .desc
= "Xen Fully-virtualized PC",
539 .init
= pc_xen_hvm_init
,
540 .max_cpus
= HVM_MAX_VCPUS
,
541 .default_machine_opts
= "accel=xen",
545 static void pc_machine_init(void)
547 qemu_register_machine(&pc_machine_v1_0
);
548 qemu_register_machine(&pc_machine_v0_14
);
549 qemu_register_machine(&pc_machine_v0_13
);
550 qemu_register_machine(&pc_machine_v0_12
);
551 qemu_register_machine(&pc_machine_v0_11
);
552 qemu_register_machine(&pc_machine_v0_10
);
553 qemu_register_machine(&isapc_machine
);
555 qemu_register_machine(&xenfv_machine
);
559 machine_init(pc_machine_init
);