]>
Commit | Line | Data |
---|---|---|
845773ab IY |
1 | /* |
2 | * QEMU PC System Emulator | |
3 | * | |
4 | * Copyright (c) 2003-2004 Fabrice Bellard | |
5 | * | |
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: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
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 | |
22 | * THE SOFTWARE. | |
23 | */ | |
24 | ||
ae0a5466 AK |
25 | #include <glib.h> |
26 | ||
845773ab IY |
27 | #include "hw.h" |
28 | #include "pc.h" | |
29 | #include "apic.h" | |
30 | #include "pci.h" | |
31 | #include "usb-uhci.h" | |
32 | #include "usb-ohci.h" | |
33 | #include "net.h" | |
34 | #include "boards.h" | |
35 | #include "ide.h" | |
36 | #include "kvm.h" | |
0ec329da | 37 | #include "kvmclock.h" |
666daa68 | 38 | #include "sysemu.h" |
96051119 | 39 | #include "sysbus.h" |
0dfa5ef9 | 40 | #include "arch_init.h" |
2446333c | 41 | #include "blockdev.h" |
a88df0b9 | 42 | #include "smbus.h" |
29d3ccde | 43 | #include "xen.h" |
4aa63af1 AK |
44 | #include "memory.h" |
45 | #include "exec-memory.h" | |
29d3ccde AP |
46 | #ifdef CONFIG_XEN |
47 | # include <xen/hvm/hvm_info_table.h> | |
48 | #endif | |
845773ab IY |
49 | |
50 | #define MAX_IDE_BUS 2 | |
51 | ||
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 }; | |
55 | ||
96051119 BS |
56 | static void ioapic_init(IsaIrqState *isa_irq_state) |
57 | { | |
58 | DeviceState *dev; | |
59 | SysBusDevice *d; | |
60 | unsigned int i; | |
61 | ||
62 | dev = qdev_create(NULL, "ioapic"); | |
63 | qdev_init_nofail(dev); | |
64 | d = sysbus_from_qdev(dev); | |
65 | sysbus_mmio_map(d, 0, 0xfec00000); | |
66 | ||
67 | for (i = 0; i < IOAPIC_NUM_PINS; i++) { | |
68 | isa_irq_state->ioapic[i] = qdev_get_gpio_in(dev, i); | |
69 | } | |
70 | } | |
71 | ||
845773ab | 72 | /* PC hardware initialisation */ |
6bd10515 | 73 | static void pc_init1(MemoryRegion *system_memory, |
aee97b84 | 74 | MemoryRegion *system_io, |
6bd10515 | 75 | ram_addr_t ram_size, |
845773ab IY |
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, | |
0ec329da JK |
81 | int pci_enabled, |
82 | int kvmclock_enabled) | |
845773ab IY |
83 | { |
84 | int i; | |
85 | ram_addr_t below_4g_mem_size, above_4g_mem_size; | |
86 | PCIBus *pci_bus; | |
87 | PCII440FXState *i440fx_state; | |
88 | int piix3_devfn = -1; | |
89 | qemu_irq *cpu_irq; | |
90 | qemu_irq *isa_irq; | |
91 | qemu_irq *i8259; | |
92 | qemu_irq *cmos_s3; | |
93 | qemu_irq *smi_irq; | |
94 | IsaIrqState *isa_irq_state; | |
95 | DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; | |
c0897e0c | 96 | BusState *idebus[MAX_IDE_BUS]; |
1d914fa0 | 97 | ISADevice *rtc_state; |
ae0a5466 AK |
98 | MemoryRegion *ram_memory; |
99 | MemoryRegion *pci_memory; | |
4463aee6 | 100 | MemoryRegion *rom_memory; |
845773ab IY |
101 | |
102 | pc_cpus_init(cpu_model); | |
103 | ||
0ec329da JK |
104 | if (kvmclock_enabled) { |
105 | kvmclock_create(); | |
106 | } | |
107 | ||
e0e7e67b AP |
108 | if (ram_size >= 0xe0000000 ) { |
109 | above_4g_mem_size = ram_size - 0xe0000000; | |
110 | below_4g_mem_size = 0xe0000000; | |
111 | } else { | |
112 | above_4g_mem_size = 0; | |
113 | below_4g_mem_size = ram_size; | |
114 | } | |
115 | ||
4463aee6 JK |
116 | if (pci_enabled) { |
117 | pci_memory = g_new(MemoryRegion, 1); | |
118 | memory_region_init(pci_memory, "pci", INT64_MAX); | |
119 | rom_memory = pci_memory; | |
120 | } else { | |
121 | pci_memory = NULL; | |
122 | rom_memory = system_memory; | |
123 | } | |
ae0a5466 | 124 | |
845773ab | 125 | /* allocate ram and load rom/bios */ |
29d3ccde | 126 | if (!xen_enabled()) { |
4aa63af1 AK |
127 | pc_memory_init(system_memory, |
128 | kernel_filename, kernel_cmdline, initrd_filename, | |
ae0a5466 | 129 | below_4g_mem_size, above_4g_mem_size, |
c1d23eac | 130 | pci_enabled ? rom_memory : system_memory, &ram_memory); |
29d3ccde | 131 | } |
845773ab | 132 | |
9c11a8ac AP |
133 | if (!xen_enabled()) { |
134 | cpu_irq = pc_allocate_cpu_irq(); | |
135 | i8259 = i8259_init(cpu_irq[0]); | |
136 | } else { | |
137 | i8259 = xen_interrupt_controller_init(); | |
138 | } | |
7267c094 | 139 | isa_irq_state = g_malloc0(sizeof(*isa_irq_state)); |
845773ab IY |
140 | isa_irq_state->i8259 = i8259; |
141 | if (pci_enabled) { | |
96051119 | 142 | ioapic_init(isa_irq_state); |
845773ab IY |
143 | } |
144 | isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24); | |
145 | ||
146 | if (pci_enabled) { | |
1e39101c | 147 | pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, |
ae0a5466 AK |
148 | system_memory, system_io, ram_size, |
149 | below_4g_mem_size, | |
150 | 0x100000000ULL - below_4g_mem_size, | |
151 | 0x100000000ULL + above_4g_mem_size, | |
152 | (sizeof(target_phys_addr_t) == 4 | |
153 | ? 0 | |
154 | : ((uint64_t)1 << 62)), | |
155 | pci_memory, ram_memory); | |
845773ab IY |
156 | } else { |
157 | pci_bus = NULL; | |
02a89b21 | 158 | i440fx_state = NULL; |
c2d0d012 | 159 | isa_bus_new(NULL, system_io); |
57285cc3 | 160 | no_hpet = 1; |
845773ab IY |
161 | } |
162 | isa_bus_irqs(isa_irq); | |
163 | ||
ee951a37 | 164 | pc_register_ferr_irq(isa_get_irq(13)); |
845773ab IY |
165 | |
166 | pc_vga_init(pci_enabled? pci_bus: NULL); | |
167 | ||
01195b73 SS |
168 | if (xen_enabled()) { |
169 | pci_create_simple(pci_bus, -1, "xen-platform"); | |
170 | } | |
171 | ||
845773ab | 172 | /* init basic PC hardware */ |
1611977c | 173 | pc_basic_device_init(isa_irq, &rtc_state, xen_enabled()); |
845773ab IY |
174 | |
175 | for(i = 0; i < nb_nics; i++) { | |
176 | NICInfo *nd = &nd_table[i]; | |
177 | ||
178 | if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0)) | |
179 | pc_init_ne2k_isa(nd); | |
180 | else | |
181 | pci_nic_init_nofail(nd, "e1000", NULL); | |
182 | } | |
183 | ||
75717903 | 184 | ide_drive_get(hd, MAX_IDE_BUS); |
845773ab | 185 | if (pci_enabled) { |
c0897e0c | 186 | PCIDevice *dev; |
679f4f8b SS |
187 | if (xen_enabled()) { |
188 | dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1); | |
189 | } else { | |
190 | dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1); | |
191 | } | |
c0897e0c MA |
192 | idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0"); |
193 | idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1"); | |
845773ab IY |
194 | } else { |
195 | for(i = 0; i < MAX_IDE_BUS; i++) { | |
c0897e0c MA |
196 | ISADevice *dev; |
197 | dev = isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i], | |
198 | hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]); | |
199 | idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0"); | |
845773ab IY |
200 | } |
201 | } | |
202 | ||
0dfa5ef9 | 203 | audio_init(isa_irq, pci_enabled ? pci_bus : NULL); |
845773ab | 204 | |
c0897e0c | 205 | pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device, |
63ffb564 | 206 | idebus[0], idebus[1], rtc_state); |
845773ab IY |
207 | |
208 | if (pci_enabled && usb_enabled) { | |
209 | usb_uhci_piix3_init(pci_bus, piix3_devfn + 2); | |
210 | } | |
211 | ||
212 | if (pci_enabled && acpi_enabled) { | |
845773ab IY |
213 | i2c_bus *smbus; |
214 | ||
c9622478 AP |
215 | if (!xen_enabled()) { |
216 | cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1); | |
217 | } else { | |
218 | cmos_s3 = qemu_allocate_irqs(xen_cmos_set_s3_resume, rtc_state, 1); | |
219 | } | |
845773ab IY |
220 | smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1); |
221 | /* TODO: Populate SPD eeprom data. */ | |
222 | smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100, | |
ee951a37 | 223 | isa_get_irq(9), *cmos_s3, *smi_irq, |
845773ab | 224 | kvm_enabled()); |
a88df0b9 | 225 | smbus_eeprom_init(smbus, 8, NULL, 0); |
845773ab IY |
226 | } |
227 | ||
845773ab IY |
228 | if (pci_enabled) { |
229 | pc_pci_device_init(pci_bus); | |
230 | } | |
231 | } | |
232 | ||
233 | static void pc_init_pci(ram_addr_t ram_size, | |
234 | const char *boot_device, | |
235 | const char *kernel_filename, | |
236 | const char *kernel_cmdline, | |
237 | const char *initrd_filename, | |
238 | const char *cpu_model) | |
239 | { | |
6bd10515 | 240 | pc_init1(get_system_memory(), |
aee97b84 | 241 | get_system_io(), |
6bd10515 | 242 | ram_size, boot_device, |
845773ab | 243 | kernel_filename, kernel_cmdline, |
0ec329da JK |
244 | initrd_filename, cpu_model, 1, 1); |
245 | } | |
246 | ||
247 | static void pc_init_pci_no_kvmclock(ram_addr_t ram_size, | |
248 | const char *boot_device, | |
249 | const char *kernel_filename, | |
250 | const char *kernel_cmdline, | |
251 | const char *initrd_filename, | |
252 | const char *cpu_model) | |
253 | { | |
6bd10515 | 254 | pc_init1(get_system_memory(), |
aee97b84 | 255 | get_system_io(), |
6bd10515 | 256 | ram_size, boot_device, |
0ec329da JK |
257 | kernel_filename, kernel_cmdline, |
258 | initrd_filename, cpu_model, 1, 0); | |
845773ab IY |
259 | } |
260 | ||
261 | static void pc_init_isa(ram_addr_t ram_size, | |
262 | const char *boot_device, | |
263 | const char *kernel_filename, | |
264 | const char *kernel_cmdline, | |
265 | const char *initrd_filename, | |
266 | const char *cpu_model) | |
267 | { | |
268 | if (cpu_model == NULL) | |
269 | cpu_model = "486"; | |
6bd10515 | 270 | pc_init1(get_system_memory(), |
aee97b84 | 271 | get_system_io(), |
6bd10515 | 272 | ram_size, boot_device, |
845773ab | 273 | kernel_filename, kernel_cmdline, |
0ec329da | 274 | initrd_filename, cpu_model, 0, 1); |
845773ab IY |
275 | } |
276 | ||
29d3ccde AP |
277 | #ifdef CONFIG_XEN |
278 | static void pc_xen_hvm_init(ram_addr_t ram_size, | |
279 | const char *boot_device, | |
280 | const char *kernel_filename, | |
281 | const char *kernel_cmdline, | |
282 | const char *initrd_filename, | |
283 | const char *cpu_model) | |
284 | { | |
285 | if (xen_hvm_init() != 0) { | |
286 | hw_error("xen hardware virtual machine initialisation failed"); | |
287 | } | |
288 | pc_init_pci_no_kvmclock(ram_size, boot_device, | |
289 | kernel_filename, kernel_cmdline, | |
290 | initrd_filename, cpu_model); | |
291 | xen_vcpu_init(); | |
292 | } | |
293 | #endif | |
294 | ||
845773ab | 295 | static QEMUMachine pc_machine = { |
b903a0f7 | 296 | .name = "pc-0.14", |
845773ab IY |
297 | .alias = "pc", |
298 | .desc = "Standard PC", | |
299 | .init = pc_init_pci, | |
300 | .max_cpus = 255, | |
301 | .is_default = 1, | |
302 | }; | |
303 | ||
b903a0f7 GH |
304 | static QEMUMachine pc_machine_v0_13 = { |
305 | .name = "pc-0.13", | |
306 | .desc = "Standard PC", | |
0ec329da | 307 | .init = pc_init_pci_no_kvmclock, |
b903a0f7 | 308 | .max_cpus = 255, |
9dbcca5a GH |
309 | .compat_props = (GlobalProperty[]) { |
310 | { | |
311 | .driver = "virtio-9p-pci", | |
312 | .property = "vectors", | |
313 | .value = stringify(0), | |
281a26b1 GH |
314 | },{ |
315 | .driver = "VGA", | |
316 | .property = "rombar", | |
317 | .value = stringify(0), | |
318 | },{ | |
319 | .driver = "vmware-svga", | |
320 | .property = "rombar", | |
321 | .value = stringify(0), | |
362dd48c IY |
322 | },{ |
323 | .driver = "PCI", | |
324 | .property = "command_serr_enable", | |
325 | .value = "off", | |
b91cb442 MT |
326 | },{ |
327 | .driver = "virtio-blk-pci", | |
328 | .property = "event_idx", | |
329 | .value = "off", | |
330 | },{ | |
331 | .driver = "virtio-serial-pci", | |
332 | .property = "event_idx", | |
333 | .value = "off", | |
334 | },{ | |
335 | .driver = "virtio-net-pci", | |
336 | .property = "event_idx", | |
337 | .value = "off", | |
9dbcca5a GH |
338 | }, |
339 | { /* end of list */ } | |
340 | }, | |
b903a0f7 GH |
341 | }; |
342 | ||
845773ab IY |
343 | static QEMUMachine pc_machine_v0_12 = { |
344 | .name = "pc-0.12", | |
345 | .desc = "Standard PC", | |
0ec329da | 346 | .init = pc_init_pci_no_kvmclock, |
845773ab IY |
347 | .max_cpus = 255, |
348 | .compat_props = (GlobalProperty[]) { | |
349 | { | |
350 | .driver = "virtio-serial-pci", | |
1e29a009 | 351 | .property = "max_ports", |
845773ab IY |
352 | .value = stringify(1), |
353 | },{ | |
354 | .driver = "virtio-serial-pci", | |
355 | .property = "vectors", | |
356 | .value = stringify(0), | |
281a26b1 GH |
357 | },{ |
358 | .driver = "VGA", | |
359 | .property = "rombar", | |
360 | .value = stringify(0), | |
361 | },{ | |
362 | .driver = "vmware-svga", | |
363 | .property = "rombar", | |
364 | .value = stringify(0), | |
b1aeb926 IY |
365 | },{ |
366 | .driver = "PCI", | |
367 | .property = "command_serr_enable", | |
368 | .value = "off", | |
b91cb442 MT |
369 | },{ |
370 | .driver = "virtio-blk-pci", | |
371 | .property = "event_idx", | |
372 | .value = "off", | |
373 | },{ | |
374 | .driver = "virtio-serial-pci", | |
375 | .property = "event_idx", | |
376 | .value = "off", | |
377 | },{ | |
378 | .driver = "virtio-net-pci", | |
379 | .property = "event_idx", | |
380 | .value = "off", | |
845773ab IY |
381 | }, |
382 | { /* end of list */ } | |
383 | } | |
384 | }; | |
385 | ||
386 | static QEMUMachine pc_machine_v0_11 = { | |
387 | .name = "pc-0.11", | |
388 | .desc = "Standard PC, qemu 0.11", | |
0ec329da | 389 | .init = pc_init_pci_no_kvmclock, |
845773ab IY |
390 | .max_cpus = 255, |
391 | .compat_props = (GlobalProperty[]) { | |
392 | { | |
393 | .driver = "virtio-blk-pci", | |
394 | .property = "vectors", | |
395 | .value = stringify(0), | |
396 | },{ | |
397 | .driver = "virtio-serial-pci", | |
1e29a009 | 398 | .property = "max_ports", |
845773ab IY |
399 | .value = stringify(1), |
400 | },{ | |
401 | .driver = "virtio-serial-pci", | |
402 | .property = "vectors", | |
403 | .value = stringify(0), | |
404 | },{ | |
405 | .driver = "ide-drive", | |
406 | .property = "ver", | |
407 | .value = "0.11", | |
408 | },{ | |
409 | .driver = "scsi-disk", | |
410 | .property = "ver", | |
411 | .value = "0.11", | |
412 | },{ | |
413 | .driver = "PCI", | |
414 | .property = "rombar", | |
415 | .value = stringify(0), | |
b1aeb926 IY |
416 | },{ |
417 | .driver = "PCI", | |
418 | .property = "command_serr_enable", | |
419 | .value = "off", | |
b91cb442 MT |
420 | },{ |
421 | .driver = "virtio-blk-pci", | |
422 | .property = "event_idx", | |
423 | .value = "off", | |
424 | },{ | |
425 | .driver = "virtio-serial-pci", | |
426 | .property = "event_idx", | |
427 | .value = "off", | |
428 | },{ | |
429 | .driver = "virtio-net-pci", | |
430 | .property = "event_idx", | |
431 | .value = "off", | |
845773ab IY |
432 | }, |
433 | { /* end of list */ } | |
434 | } | |
435 | }; | |
436 | ||
437 | static QEMUMachine pc_machine_v0_10 = { | |
438 | .name = "pc-0.10", | |
439 | .desc = "Standard PC, qemu 0.10", | |
0ec329da | 440 | .init = pc_init_pci_no_kvmclock, |
845773ab IY |
441 | .max_cpus = 255, |
442 | .compat_props = (GlobalProperty[]) { | |
443 | { | |
444 | .driver = "virtio-blk-pci", | |
445 | .property = "class", | |
446 | .value = stringify(PCI_CLASS_STORAGE_OTHER), | |
447 | },{ | |
448 | .driver = "virtio-serial-pci", | |
449 | .property = "class", | |
450 | .value = stringify(PCI_CLASS_DISPLAY_OTHER), | |
451 | },{ | |
452 | .driver = "virtio-serial-pci", | |
1e29a009 | 453 | .property = "max_ports", |
845773ab IY |
454 | .value = stringify(1), |
455 | },{ | |
456 | .driver = "virtio-serial-pci", | |
457 | .property = "vectors", | |
458 | .value = stringify(0), | |
459 | },{ | |
460 | .driver = "virtio-net-pci", | |
461 | .property = "vectors", | |
462 | .value = stringify(0), | |
463 | },{ | |
464 | .driver = "virtio-blk-pci", | |
465 | .property = "vectors", | |
466 | .value = stringify(0), | |
467 | },{ | |
468 | .driver = "ide-drive", | |
469 | .property = "ver", | |
470 | .value = "0.10", | |
471 | },{ | |
472 | .driver = "scsi-disk", | |
473 | .property = "ver", | |
474 | .value = "0.10", | |
475 | },{ | |
476 | .driver = "PCI", | |
477 | .property = "rombar", | |
478 | .value = stringify(0), | |
b1aeb926 IY |
479 | },{ |
480 | .driver = "PCI", | |
481 | .property = "command_serr_enable", | |
482 | .value = "off", | |
b91cb442 MT |
483 | },{ |
484 | .driver = "virtio-blk-pci", | |
485 | .property = "event_idx", | |
486 | .value = "off", | |
487 | },{ | |
488 | .driver = "virtio-serial-pci", | |
489 | .property = "event_idx", | |
490 | .value = "off", | |
491 | },{ | |
492 | .driver = "virtio-net-pci", | |
493 | .property = "event_idx", | |
494 | .value = "off", | |
845773ab IY |
495 | }, |
496 | { /* end of list */ } | |
497 | }, | |
498 | }; | |
499 | ||
500 | static QEMUMachine isapc_machine = { | |
501 | .name = "isapc", | |
502 | .desc = "ISA-only PC", | |
503 | .init = pc_init_isa, | |
504 | .max_cpus = 1, | |
505 | }; | |
506 | ||
29d3ccde AP |
507 | #ifdef CONFIG_XEN |
508 | static QEMUMachine xenfv_machine = { | |
509 | .name = "xenfv", | |
510 | .desc = "Xen Fully-virtualized PC", | |
511 | .init = pc_xen_hvm_init, | |
512 | .max_cpus = HVM_MAX_VCPUS, | |
513 | .default_machine_opts = "accel=xen", | |
514 | }; | |
515 | #endif | |
516 | ||
845773ab IY |
517 | static void pc_machine_init(void) |
518 | { | |
519 | qemu_register_machine(&pc_machine); | |
b903a0f7 | 520 | qemu_register_machine(&pc_machine_v0_13); |
845773ab IY |
521 | qemu_register_machine(&pc_machine_v0_12); |
522 | qemu_register_machine(&pc_machine_v0_11); | |
523 | qemu_register_machine(&pc_machine_v0_10); | |
524 | qemu_register_machine(&isapc_machine); | |
29d3ccde AP |
525 | #ifdef CONFIG_XEN |
526 | qemu_register_machine(&xenfv_machine); | |
527 | #endif | |
845773ab IY |
528 | } |
529 | ||
530 | machine_init(pc_machine_init); |