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
37 #include "arch_init.h"
40 qemu_irq
*ioapic_irq_hack
;
44 static const int ide_iobase
[MAX_IDE_BUS
] = { 0x1f0, 0x170 };
45 static const int ide_iobase2
[MAX_IDE_BUS
] = { 0x3f6, 0x376 };
46 static const int ide_irq
[MAX_IDE_BUS
] = { 14, 15 };
48 const char *global_cpu_model
; /* cpu hotadd */
50 static void ioapic_init(IsaIrqState
*isa_irq_state
)
56 dev
= qdev_create(NULL
, "ioapic");
57 qdev_init_nofail(dev
);
58 d
= sysbus_from_qdev(dev
);
59 sysbus_mmio_map(d
, 0, 0xfec00000);
61 for (i
= 0; i
< IOAPIC_NUM_PINS
; i
++) {
62 isa_irq_state
->ioapic
[i
] = qdev_get_gpio_in(dev
, i
);
66 /* PC hardware initialisation */
67 static void pc_init1(ram_addr_t ram_size
,
68 const char *boot_device
,
69 const char *kernel_filename
,
70 const char *kernel_cmdline
,
71 const char *initrd_filename
,
72 const char *cpu_model
,
76 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
78 PCII440FXState
*i440fx_state
;
85 IsaIrqState
*isa_irq_state
;
86 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
87 FDCtrl
*floppy_controller
;
88 BusState
*idebus
[MAX_IDE_BUS
];
91 global_cpu_model
= cpu_model
;
93 pc_cpus_init(cpu_model
);
97 /* allocate ram and load rom/bios */
98 pc_memory_init(ram_size
, kernel_filename
, kernel_cmdline
, initrd_filename
,
99 &below_4g_mem_size
, &above_4g_mem_size
);
101 cpu_irq
= pc_allocate_cpu_irq();
102 #ifdef KVM_CAP_IRQCHIP
103 if (kvm_enabled() && kvm_irqchip_in_kernel()) {
104 isa_irq_state
= qemu_mallocz(sizeof(*isa_irq_state
));
106 ioapic_init(isa_irq_state
);
108 isa_irq
= i8259
= kvm_i8259_init(cpu_irq
[0]);
109 ioapic_irq_hack
= isa_irq
;
113 i8259
= i8259_init(cpu_irq
[0]);
114 isa_irq_state
= qemu_mallocz(sizeof(*isa_irq_state
));
115 isa_irq_state
->i8259
= i8259
;
117 ioapic_init(isa_irq_state
);
119 isa_irq
= qemu_allocate_irqs(isa_irq_handler
, isa_irq_state
, 24);
123 pci_bus
= i440fx_init(&i440fx_state
, &piix3_devfn
, isa_irq
, ram_size
);
129 isa_bus_irqs(isa_irq
);
131 pc_register_ferr_irq(isa_reserve_irq(13));
133 pc_vga_init(pci_enabled
? pci_bus
: NULL
);
135 /* init basic PC hardware */
136 pc_basic_device_init(isa_irq
, &floppy_controller
, &rtc_state
);
138 for(i
= 0; i
< nb_nics
; i
++) {
139 NICInfo
*nd
= &nd_table
[i
];
141 if (!pci_enabled
|| (nd
->model
&& strcmp(nd
->model
, "ne2k_isa") == 0))
142 pc_init_ne2k_isa(nd
);
144 pci_nic_init_nofail(nd
, "rtl8139", NULL
);
147 if (drive_get_max_bus(IF_IDE
) >= MAX_IDE_BUS
) {
148 fprintf(stderr
, "qemu: too many IDE bus\n");
152 for(i
= 0; i
< MAX_IDE_BUS
* MAX_IDE_DEVS
; i
++) {
153 hd
[i
] = drive_get(IF_IDE
, i
/ MAX_IDE_DEVS
, i
% MAX_IDE_DEVS
);
158 dev
= pci_piix3_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
159 idebus
[0] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
160 idebus
[1] = qdev_get_child_bus(&dev
->qdev
, "ide.1");
162 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
164 dev
= isa_ide_init(ide_iobase
[i
], ide_iobase2
[i
], ide_irq
[i
],
165 hd
[MAX_IDE_DEVS
* i
], hd
[MAX_IDE_DEVS
* i
+ 1]);
166 idebus
[i
] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
170 audio_init(isa_irq
, pci_enabled
? pci_bus
: NULL
);
172 pc_cmos_init(below_4g_mem_size
, above_4g_mem_size
, boot_device
,
173 idebus
[0], idebus
[1], floppy_controller
, rtc_state
);
175 if (pci_enabled
&& usb_enabled
) {
176 usb_uhci_piix3_init(pci_bus
, piix3_devfn
+ 2);
179 if (pci_enabled
&& acpi_enabled
) {
180 uint8_t *eeprom_buf
= qemu_mallocz(8 * 256); /* XXX: make this persistent */
183 cmos_s3
= qemu_allocate_irqs(pc_cmos_set_s3_resume
, rtc_state
, 1);
184 smi_irq
= qemu_allocate_irqs(pc_acpi_smi_interrupt
, first_cpu
, 1);
185 /* TODO: Populate SPD eeprom data. */
186 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
187 isa_reserve_irq(9), *cmos_s3
, *smi_irq
,
189 for (i
= 0; i
< 8; i
++) {
191 eeprom
= qdev_create((BusState
*)smbus
, "smbus-eeprom");
192 qdev_prop_set_uint8(eeprom
, "address", 0x50 + i
);
193 qdev_prop_set_ptr(eeprom
, "data", eeprom_buf
+ (i
* 256));
194 qdev_init_nofail(eeprom
);
199 i440fx_init_memory_mappings(i440fx_state
);
203 pc_pci_device_init(pci_bus
);
207 static void pc_init_pci(ram_addr_t ram_size
,
208 const char *boot_device
,
209 const char *kernel_filename
,
210 const char *kernel_cmdline
,
211 const char *initrd_filename
,
212 const char *cpu_model
)
214 pc_init1(ram_size
, boot_device
,
215 kernel_filename
, kernel_cmdline
,
216 initrd_filename
, cpu_model
, 1);
219 static void pc_init_isa(ram_addr_t ram_size
,
220 const char *boot_device
,
221 const char *kernel_filename
,
222 const char *kernel_cmdline
,
223 const char *initrd_filename
,
224 const char *cpu_model
)
226 if (cpu_model
== NULL
)
228 pc_init1(ram_size
, boot_device
,
229 kernel_filename
, kernel_cmdline
,
230 initrd_filename
, cpu_model
, 0);
233 static QEMUMachine pc_machine
= {
236 .desc
= "Standard PC",
242 static QEMUMachine pc_machine_v0_13
= {
244 .desc
= "Standard PC",
247 .compat_props
= (GlobalProperty
[]) {
249 .driver
= "virtio-9p-pci",
250 .property
= "vectors",
251 .value
= stringify(0),
254 .property
= "rombar",
255 .value
= stringify(0),
257 .driver
= "vmware-svga",
258 .property
= "rombar",
259 .value
= stringify(0),
262 .property
= "command_serr_enable",
265 { /* end of list */ }
269 static QEMUMachine pc_machine_v0_12
= {
271 .desc
= "Standard PC",
274 .compat_props
= (GlobalProperty
[]) {
276 .driver
= "virtio-serial-pci",
277 .property
= "max_ports",
278 .value
= stringify(1),
280 .driver
= "virtio-serial-pci",
281 .property
= "vectors",
282 .value
= stringify(0),
285 .property
= "rombar",
286 .value
= stringify(0),
288 .driver
= "vmware-svga",
289 .property
= "rombar",
290 .value
= stringify(0),
293 .property
= "command_serr_enable",
296 { /* end of list */ }
300 static QEMUMachine pc_machine_v0_11
= {
302 .desc
= "Standard PC, qemu 0.11",
305 .compat_props
= (GlobalProperty
[]) {
307 .driver
= "virtio-blk-pci",
308 .property
= "vectors",
309 .value
= stringify(0),
311 .driver
= "virtio-serial-pci",
312 .property
= "max_ports",
313 .value
= stringify(1),
315 .driver
= "virtio-serial-pci",
316 .property
= "vectors",
317 .value
= stringify(0),
319 .driver
= "ide-drive",
323 .driver
= "scsi-disk",
328 .property
= "rombar",
329 .value
= stringify(0),
332 .property
= "command_serr_enable",
335 { /* end of list */ }
339 static QEMUMachine pc_machine_v0_10
= {
341 .desc
= "Standard PC, qemu 0.10",
344 .compat_props
= (GlobalProperty
[]) {
346 .driver
= "virtio-blk-pci",
348 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
350 .driver
= "virtio-serial-pci",
352 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
354 .driver
= "virtio-serial-pci",
355 .property
= "max_ports",
356 .value
= stringify(1),
358 .driver
= "virtio-serial-pci",
359 .property
= "vectors",
360 .value
= stringify(0),
362 .driver
= "virtio-net-pci",
363 .property
= "vectors",
364 .value
= stringify(0),
366 .driver
= "virtio-blk-pci",
367 .property
= "vectors",
368 .value
= stringify(0),
370 .driver
= "ide-drive",
374 .driver
= "scsi-disk",
379 .property
= "rombar",
380 .value
= stringify(0),
383 .property
= "command_serr_enable",
386 { /* end of list */ }
390 static QEMUMachine isapc_machine
= {
392 .desc
= "ISA-only PC",
397 static void pc_machine_init(void)
399 qemu_register_machine(&pc_machine
);
400 qemu_register_machine(&pc_machine_v0_13
);
401 qemu_register_machine(&pc_machine_v0_12
);
402 qemu_register_machine(&pc_machine_v0_11
);
403 qemu_register_machine(&pc_machine_v0_10
);
404 qemu_register_machine(&isapc_machine
);
407 machine_init(pc_machine_init
);