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
39 qemu_irq
*ioapic_irq_hack
;
43 static const int ide_iobase
[MAX_IDE_BUS
] = { 0x1f0, 0x170 };
44 static const int ide_iobase2
[MAX_IDE_BUS
] = { 0x3f6, 0x376 };
45 static const int ide_irq
[MAX_IDE_BUS
] = { 14, 15 };
47 const char *global_cpu_model
; /* cpu hotadd */
49 static void ioapic_init(IsaIrqState
*isa_irq_state
)
55 dev
= qdev_create(NULL
, "ioapic");
56 qdev_init_nofail(dev
);
57 d
= sysbus_from_qdev(dev
);
58 sysbus_mmio_map(d
, 0, 0xfec00000);
60 for (i
= 0; i
< IOAPIC_NUM_PINS
; i
++) {
61 isa_irq_state
->ioapic
[i
] = qdev_get_gpio_in(dev
, i
);
65 /* PC hardware initialisation */
66 static void pc_init1(ram_addr_t ram_size
,
67 const char *boot_device
,
68 const char *kernel_filename
,
69 const char *kernel_cmdline
,
70 const char *initrd_filename
,
71 const char *cpu_model
,
75 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
77 PCII440FXState
*i440fx_state
;
84 IsaIrqState
*isa_irq_state
;
85 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
86 FDCtrl
*floppy_controller
;
87 BusState
*idebus
[MAX_IDE_BUS
];
90 global_cpu_model
= cpu_model
;
92 pc_cpus_init(cpu_model
);
96 /* allocate ram and load rom/bios */
97 pc_memory_init(ram_size
, kernel_filename
, kernel_cmdline
, initrd_filename
,
98 &below_4g_mem_size
, &above_4g_mem_size
);
100 cpu_irq
= pc_allocate_cpu_irq();
101 #ifdef KVM_CAP_IRQCHIP
102 if (kvm_enabled() && kvm_irqchip_in_kernel()) {
103 isa_irq_state
= qemu_mallocz(sizeof(*isa_irq_state
));
105 ioapic_init(isa_irq_state
);
107 isa_irq
= i8259
= kvm_i8259_init(cpu_irq
[0]);
108 ioapic_irq_hack
= isa_irq
;
112 i8259
= i8259_init(cpu_irq
[0]);
113 isa_irq_state
= qemu_mallocz(sizeof(*isa_irq_state
));
114 isa_irq_state
->i8259
= i8259
;
116 ioapic_init(isa_irq_state
);
118 isa_irq
= qemu_allocate_irqs(isa_irq_handler
, isa_irq_state
, 24);
122 pci_bus
= i440fx_init(&i440fx_state
, &piix3_devfn
, isa_irq
, ram_size
);
128 isa_bus_irqs(isa_irq
);
130 pc_register_ferr_irq(isa_reserve_irq(13));
132 pc_vga_init(pci_enabled
? pci_bus
: NULL
);
134 /* init basic PC hardware */
135 pc_basic_device_init(isa_irq
, &floppy_controller
, &rtc_state
);
137 for(i
= 0; i
< nb_nics
; i
++) {
138 NICInfo
*nd
= &nd_table
[i
];
140 if (!pci_enabled
|| (nd
->model
&& strcmp(nd
->model
, "ne2k_isa") == 0))
141 pc_init_ne2k_isa(nd
);
143 pci_nic_init_nofail(nd
, "rtl8139", NULL
);
146 if (drive_get_max_bus(IF_IDE
) >= MAX_IDE_BUS
) {
147 fprintf(stderr
, "qemu: too many IDE bus\n");
151 for(i
= 0; i
< MAX_IDE_BUS
* MAX_IDE_DEVS
; i
++) {
152 hd
[i
] = drive_get(IF_IDE
, i
/ MAX_IDE_DEVS
, i
% MAX_IDE_DEVS
);
157 dev
= pci_piix3_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
158 idebus
[0] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
159 idebus
[1] = qdev_get_child_bus(&dev
->qdev
, "ide.1");
161 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
163 dev
= isa_ide_init(ide_iobase
[i
], ide_iobase2
[i
], ide_irq
[i
],
164 hd
[MAX_IDE_DEVS
* i
], hd
[MAX_IDE_DEVS
* i
+ 1]);
165 idebus
[i
] = qdev_get_child_bus(&dev
->qdev
, "ide.0");
169 pc_audio_init(pci_enabled
? pci_bus
: NULL
, isa_irq
);
171 pc_cmos_init(below_4g_mem_size
, above_4g_mem_size
, boot_device
,
172 idebus
[0], idebus
[1], floppy_controller
, rtc_state
);
174 if (pci_enabled
&& usb_enabled
) {
175 usb_uhci_piix3_init(pci_bus
, piix3_devfn
+ 2);
178 if (pci_enabled
&& acpi_enabled
) {
179 uint8_t *eeprom_buf
= qemu_mallocz(8 * 256); /* XXX: make this persistent */
182 cmos_s3
= qemu_allocate_irqs(pc_cmos_set_s3_resume
, rtc_state
, 1);
183 smi_irq
= qemu_allocate_irqs(pc_acpi_smi_interrupt
, first_cpu
, 1);
184 /* TODO: Populate SPD eeprom data. */
185 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
186 isa_reserve_irq(9), *cmos_s3
, *smi_irq
,
188 for (i
= 0; i
< 8; i
++) {
190 eeprom
= qdev_create((BusState
*)smbus
, "smbus-eeprom");
191 qdev_prop_set_uint8(eeprom
, "address", 0x50 + i
);
192 qdev_prop_set_ptr(eeprom
, "data", eeprom_buf
+ (i
* 256));
193 qdev_init_nofail(eeprom
);
198 i440fx_init_memory_mappings(i440fx_state
);
202 pc_pci_device_init(pci_bus
);
206 static void pc_init_pci(ram_addr_t ram_size
,
207 const char *boot_device
,
208 const char *kernel_filename
,
209 const char *kernel_cmdline
,
210 const char *initrd_filename
,
211 const char *cpu_model
)
213 pc_init1(ram_size
, boot_device
,
214 kernel_filename
, kernel_cmdline
,
215 initrd_filename
, cpu_model
, 1);
218 static void pc_init_isa(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 if (cpu_model
== NULL
)
227 pc_init1(ram_size
, boot_device
,
228 kernel_filename
, kernel_cmdline
,
229 initrd_filename
, cpu_model
, 0);
232 static QEMUMachine pc_machine
= {
235 .desc
= "Standard PC",
241 static QEMUMachine pc_machine_v0_13
= {
243 .desc
= "Standard PC",
246 .compat_props
= (GlobalProperty
[]) {
248 .driver
= "virtio-9p-pci",
249 .property
= "vectors",
250 .value
= stringify(0),
253 .property
= "rombar",
254 .value
= stringify(0),
256 .driver
= "vmware-svga",
257 .property
= "rombar",
258 .value
= stringify(0),
260 { /* end of list */ }
264 static QEMUMachine pc_machine_v0_12
= {
266 .desc
= "Standard PC",
269 .compat_props
= (GlobalProperty
[]) {
271 .driver
= "virtio-serial-pci",
272 .property
= "max_ports",
273 .value
= stringify(1),
275 .driver
= "virtio-serial-pci",
276 .property
= "vectors",
277 .value
= stringify(0),
280 .property
= "rombar",
281 .value
= stringify(0),
283 .driver
= "vmware-svga",
284 .property
= "rombar",
285 .value
= stringify(0),
287 { /* end of list */ }
291 static QEMUMachine pc_machine_v0_11
= {
293 .desc
= "Standard PC, qemu 0.11",
296 .compat_props
= (GlobalProperty
[]) {
298 .driver
= "virtio-blk-pci",
299 .property
= "vectors",
300 .value
= stringify(0),
302 .driver
= "virtio-serial-pci",
303 .property
= "max_ports",
304 .value
= stringify(1),
306 .driver
= "virtio-serial-pci",
307 .property
= "vectors",
308 .value
= stringify(0),
310 .driver
= "ide-drive",
314 .driver
= "scsi-disk",
319 .property
= "rombar",
320 .value
= stringify(0),
322 { /* end of list */ }
326 static QEMUMachine pc_machine_v0_10
= {
328 .desc
= "Standard PC, qemu 0.10",
331 .compat_props
= (GlobalProperty
[]) {
333 .driver
= "virtio-blk-pci",
335 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
337 .driver
= "virtio-serial-pci",
339 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
341 .driver
= "virtio-serial-pci",
342 .property
= "max_ports",
343 .value
= stringify(1),
345 .driver
= "virtio-serial-pci",
346 .property
= "vectors",
347 .value
= stringify(0),
349 .driver
= "virtio-net-pci",
350 .property
= "vectors",
351 .value
= stringify(0),
353 .driver
= "virtio-blk-pci",
354 .property
= "vectors",
355 .value
= stringify(0),
357 .driver
= "ide-drive",
361 .driver
= "scsi-disk",
366 .property
= "rombar",
367 .value
= stringify(0),
369 { /* end of list */ }
373 static QEMUMachine isapc_machine
= {
375 .desc
= "ISA-only PC",
380 static void pc_machine_init(void)
382 qemu_register_machine(&pc_machine
);
383 qemu_register_machine(&pc_machine_v0_13
);
384 qemu_register_machine(&pc_machine_v0_12
);
385 qemu_register_machine(&pc_machine_v0_11
);
386 qemu_register_machine(&pc_machine_v0_10
);
387 qemu_register_machine(&isapc_machine
);
390 machine_init(pc_machine_init
);