|
|
1.1 root 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:
1.1.1.5 ! root 25: #include <glib.h>
! 26:
1.1 root 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"
1.1.1.4 root 37: #include "kvmclock.h"
1.1 root 38: #include "sysemu.h"
39: #include "sysbus.h"
1.1.1.2 root 40: #include "arch_init.h"
41: #include "blockdev.h"
1.1.1.4 root 42: #include "smbus.h"
43: #include "xen.h"
1.1.1.5 ! root 44: #include "memory.h"
! 45: #include "exec-memory.h"
1.1.1.4 root 46: #ifdef CONFIG_XEN
47: # include <xen/hvm/hvm_info_table.h>
48: #endif
1.1 root 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:
1.1.1.5 ! root 56: static void ioapic_init(GSIState *gsi_state)
1.1 root 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++) {
1.1.1.5 ! root 68: gsi_state->ioapic_irq[i] = qdev_get_gpio_in(dev, i);
1.1 root 69: }
70: }
71:
72: /* PC hardware initialisation */
1.1.1.5 ! root 73: static void pc_init1(MemoryRegion *system_memory,
! 74: MemoryRegion *system_io,
! 75: ram_addr_t ram_size,
1.1 root 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,
1.1.1.4 root 81: int pci_enabled,
82: int kvmclock_enabled)
1.1 root 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;
1.1.1.5 ! root 90: qemu_irq *gsi;
1.1 root 91: qemu_irq *i8259;
92: qemu_irq *cmos_s3;
93: qemu_irq *smi_irq;
1.1.1.5 ! root 94: GSIState *gsi_state;
1.1 root 95: DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
96: BusState *idebus[MAX_IDE_BUS];
97: ISADevice *rtc_state;
1.1.1.5 ! root 98: ISADevice *floppy;
! 99: MemoryRegion *ram_memory;
! 100: MemoryRegion *pci_memory;
! 101: MemoryRegion *rom_memory;
1.1 root 102:
103: pc_cpus_init(cpu_model);
104:
1.1.1.4 root 105: if (kvmclock_enabled) {
106: kvmclock_create();
107: }
108:
109: if (ram_size >= 0xe0000000 ) {
110: above_4g_mem_size = ram_size - 0xe0000000;
111: below_4g_mem_size = 0xe0000000;
112: } else {
113: above_4g_mem_size = 0;
114: below_4g_mem_size = ram_size;
115: }
1.1 root 116:
1.1.1.5 ! root 117: if (pci_enabled) {
! 118: pci_memory = g_new(MemoryRegion, 1);
! 119: memory_region_init(pci_memory, "pci", INT64_MAX);
! 120: rom_memory = pci_memory;
! 121: } else {
! 122: pci_memory = NULL;
! 123: rom_memory = system_memory;
! 124: }
! 125:
1.1 root 126: /* allocate ram and load rom/bios */
1.1.1.4 root 127: if (!xen_enabled()) {
1.1.1.5 ! root 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);
1.1.1.4 root 132: }
1.1 root 133:
1.1.1.5 ! root 134: gsi_state = g_malloc0(sizeof(*gsi_state));
! 135: gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
! 136:
! 137: if (pci_enabled) {
! 138: pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, gsi,
! 139: system_memory, system_io, ram_size,
! 140: below_4g_mem_size,
! 141: 0x100000000ULL - below_4g_mem_size,
! 142: 0x100000000ULL + above_4g_mem_size,
! 143: (sizeof(target_phys_addr_t) == 4
! 144: ? 0
! 145: : ((uint64_t)1 << 62)),
! 146: pci_memory, ram_memory);
! 147: } else {
! 148: pci_bus = NULL;
! 149: i440fx_state = NULL;
! 150: isa_bus_new(NULL, system_io);
! 151: no_hpet = 1;
! 152: }
! 153: isa_bus_irqs(gsi);
! 154:
1.1.1.4 root 155: if (!xen_enabled()) {
156: cpu_irq = pc_allocate_cpu_irq();
157: i8259 = i8259_init(cpu_irq[0]);
158: } else {
159: i8259 = xen_interrupt_controller_init();
160: }
1.1 root 161:
1.1.1.5 ! root 162: for (i = 0; i < ISA_NUM_IRQS; i++) {
! 163: gsi_state->i8259_irq[i] = i8259[i];
! 164: }
1.1 root 165: if (pci_enabled) {
1.1.1.5 ! root 166: ioapic_init(gsi_state);
1.1 root 167: }
168:
1.1.1.5 ! root 169: pc_register_ferr_irq(gsi[13]);
1.1 root 170:
171: pc_vga_init(pci_enabled? pci_bus: NULL);
172:
1.1.1.4 root 173: if (xen_enabled()) {
174: pci_create_simple(pci_bus, -1, "xen-platform");
175: }
176:
1.1 root 177: /* init basic PC hardware */
1.1.1.5 ! root 178: pc_basic_device_init(gsi, &rtc_state, &floppy, xen_enabled());
1.1 root 179:
180: for(i = 0; i < nb_nics; i++) {
181: NICInfo *nd = &nd_table[i];
182:
183: if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
184: pc_init_ne2k_isa(nd);
185: else
186: pci_nic_init_nofail(nd, "e1000", NULL);
187: }
188:
1.1.1.4 root 189: ide_drive_get(hd, MAX_IDE_BUS);
1.1 root 190: if (pci_enabled) {
191: PCIDevice *dev;
1.1.1.5 ! root 192: if (xen_enabled()) {
! 193: dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
! 194: } else {
! 195: dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
! 196: }
1.1 root 197: idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
198: idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
199: } else {
200: for(i = 0; i < MAX_IDE_BUS; i++) {
201: ISADevice *dev;
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");
205: }
206: }
207:
1.1.1.5 ! root 208: audio_init(gsi, pci_enabled ? pci_bus : NULL);
1.1 root 209:
210: pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
1.1.1.5 ! root 211: floppy, idebus[0], idebus[1], rtc_state);
1.1 root 212:
213: if (pci_enabled && usb_enabled) {
214: usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
215: }
216:
217: if (pci_enabled && acpi_enabled) {
218: i2c_bus *smbus;
219:
1.1.1.4 root 220: if (!xen_enabled()) {
221: cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
222: } else {
223: cmos_s3 = qemu_allocate_irqs(xen_cmos_set_s3_resume, rtc_state, 1);
224: }
1.1 root 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,
1.1.1.5 ! root 228: gsi[9], *cmos_s3, *smi_irq,
1.1 root 229: kvm_enabled());
1.1.1.4 root 230: smbus_eeprom_init(smbus, 8, NULL, 0);
1.1 root 231: }
232:
233: if (pci_enabled) {
234: pc_pci_device_init(pci_bus);
235: }
236: }
237:
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)
244: {
1.1.1.5 ! root 245: pc_init1(get_system_memory(),
! 246: get_system_io(),
! 247: ram_size, boot_device,
1.1 root 248: kernel_filename, kernel_cmdline,
1.1.1.4 root 249: initrd_filename, cpu_model, 1, 1);
250: }
251:
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)
258: {
1.1.1.5 ! root 259: pc_init1(get_system_memory(),
! 260: get_system_io(),
! 261: ram_size, boot_device,
1.1.1.4 root 262: kernel_filename, kernel_cmdline,
263: initrd_filename, cpu_model, 1, 0);
1.1 root 264: }
265:
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)
272: {
273: if (cpu_model == NULL)
274: cpu_model = "486";
1.1.1.5 ! root 275: pc_init1(get_system_memory(),
! 276: get_system_io(),
! 277: ram_size, boot_device,
1.1 root 278: kernel_filename, kernel_cmdline,
1.1.1.4 root 279: initrd_filename, cpu_model, 0, 1);
280: }
281:
282: #ifdef CONFIG_XEN
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)
289: {
290: if (xen_hvm_init() != 0) {
291: hw_error("xen hardware virtual machine initialisation failed");
292: }
293: pc_init_pci_no_kvmclock(ram_size, boot_device,
294: kernel_filename, kernel_cmdline,
295: initrd_filename, cpu_model);
296: xen_vcpu_init();
1.1 root 297: }
1.1.1.4 root 298: #endif
1.1 root 299:
1.1.1.5 ! root 300: static QEMUMachine pc_machine_v1_0 = {
! 301: .name = "pc-1.0",
1.1 root 302: .alias = "pc",
303: .desc = "Standard PC",
304: .init = pc_init_pci,
305: .max_cpus = 255,
306: .is_default = 1,
307: };
308:
1.1.1.5 ! root 309: static QEMUMachine pc_machine_v0_15 = {
! 310: .name = "pc-0.15",
! 311: .desc = "Standard PC",
! 312: .init = pc_init_pci,
! 313: .max_cpus = 255,
! 314: .is_default = 1,
! 315: };
! 316:
! 317: static QEMUMachine pc_machine_v0_14 = {
! 318: .name = "pc-0.14",
! 319: .desc = "Standard PC",
! 320: .init = pc_init_pci,
! 321: .max_cpus = 255,
! 322: .compat_props = (GlobalProperty[]) {
! 323: {
! 324: .driver = "qxl",
! 325: .property = "revision",
! 326: .value = stringify(2),
! 327: },{
! 328: .driver = "qxl-vga",
! 329: .property = "revision",
! 330: .value = stringify(2),
! 331: },{
! 332: .driver = "virtio-blk-pci",
! 333: .property = "event_idx",
! 334: .value = "off",
! 335: },{
! 336: .driver = "virtio-serial-pci",
! 337: .property = "event_idx",
! 338: .value = "off",
! 339: },{
! 340: .driver = "virtio-net-pci",
! 341: .property = "event_idx",
! 342: .value = "off",
! 343: },{
! 344: .driver = "virtio-balloon-pci",
! 345: .property = "event_idx",
! 346: .value = "off",
! 347: },
! 348: { /* end of list */ }
! 349: },
! 350: };
! 351:
1.1.1.2 root 352: static QEMUMachine pc_machine_v0_13 = {
353: .name = "pc-0.13",
354: .desc = "Standard PC",
1.1.1.4 root 355: .init = pc_init_pci_no_kvmclock,
1.1.1.2 root 356: .max_cpus = 255,
357: .compat_props = (GlobalProperty[]) {
358: {
359: .driver = "virtio-9p-pci",
360: .property = "vectors",
361: .value = stringify(0),
362: },{
363: .driver = "VGA",
364: .property = "rombar",
365: .value = stringify(0),
366: },{
367: .driver = "vmware-svga",
368: .property = "rombar",
369: .value = stringify(0),
370: },{
371: .driver = "PCI",
372: .property = "command_serr_enable",
373: .value = "off",
1.1.1.4 root 374: },{
375: .driver = "virtio-blk-pci",
376: .property = "event_idx",
377: .value = "off",
378: },{
379: .driver = "virtio-serial-pci",
380: .property = "event_idx",
381: .value = "off",
382: },{
383: .driver = "virtio-net-pci",
384: .property = "event_idx",
385: .value = "off",
1.1.1.5 ! root 386: },{
! 387: .driver = "virtio-balloon-pci",
! 388: .property = "event_idx",
! 389: .value = "off",
! 390: },{
! 391: .driver = "AC97",
! 392: .property = "use_broken_id",
! 393: .value = stringify(1),
1.1.1.2 root 394: },
395: { /* end of list */ }
396: },
397: };
398:
1.1 root 399: static QEMUMachine pc_machine_v0_12 = {
400: .name = "pc-0.12",
401: .desc = "Standard PC",
1.1.1.4 root 402: .init = pc_init_pci_no_kvmclock,
1.1 root 403: .max_cpus = 255,
404: .compat_props = (GlobalProperty[]) {
405: {
406: .driver = "virtio-serial-pci",
407: .property = "max_ports",
408: .value = stringify(1),
409: },{
410: .driver = "virtio-serial-pci",
411: .property = "vectors",
412: .value = stringify(0),
1.1.1.2 root 413: },{
414: .driver = "VGA",
415: .property = "rombar",
416: .value = stringify(0),
417: },{
418: .driver = "vmware-svga",
419: .property = "rombar",
420: .value = stringify(0),
421: },{
422: .driver = "PCI",
423: .property = "command_serr_enable",
424: .value = "off",
1.1.1.4 root 425: },{
426: .driver = "virtio-blk-pci",
427: .property = "event_idx",
428: .value = "off",
429: },{
430: .driver = "virtio-serial-pci",
431: .property = "event_idx",
432: .value = "off",
433: },{
434: .driver = "virtio-net-pci",
435: .property = "event_idx",
436: .value = "off",
1.1.1.5 ! root 437: },{
! 438: .driver = "virtio-balloon-pci",
! 439: .property = "event_idx",
! 440: .value = "off",
! 441: },{
! 442: .driver = "AC97",
! 443: .property = "use_broken_id",
! 444: .value = stringify(1),
1.1 root 445: },
446: { /* end of list */ }
447: }
448: };
449:
450: static QEMUMachine pc_machine_v0_11 = {
451: .name = "pc-0.11",
452: .desc = "Standard PC, qemu 0.11",
1.1.1.4 root 453: .init = pc_init_pci_no_kvmclock,
1.1 root 454: .max_cpus = 255,
455: .compat_props = (GlobalProperty[]) {
456: {
457: .driver = "virtio-blk-pci",
458: .property = "vectors",
459: .value = stringify(0),
460: },{
461: .driver = "virtio-serial-pci",
462: .property = "max_ports",
463: .value = stringify(1),
464: },{
465: .driver = "virtio-serial-pci",
466: .property = "vectors",
467: .value = stringify(0),
468: },{
469: .driver = "ide-drive",
470: .property = "ver",
471: .value = "0.11",
472: },{
473: .driver = "scsi-disk",
474: .property = "ver",
475: .value = "0.11",
476: },{
477: .driver = "PCI",
478: .property = "rombar",
479: .value = stringify(0),
1.1.1.2 root 480: },{
481: .driver = "PCI",
482: .property = "command_serr_enable",
483: .value = "off",
1.1.1.4 root 484: },{
485: .driver = "virtio-blk-pci",
486: .property = "event_idx",
487: .value = "off",
488: },{
489: .driver = "virtio-serial-pci",
490: .property = "event_idx",
491: .value = "off",
492: },{
493: .driver = "virtio-net-pci",
494: .property = "event_idx",
495: .value = "off",
1.1.1.5 ! root 496: },{
! 497: .driver = "virtio-balloon-pci",
! 498: .property = "event_idx",
! 499: .value = "off",
! 500: },{
! 501: .driver = "AC97",
! 502: .property = "use_broken_id",
! 503: .value = stringify(1),
1.1 root 504: },
505: { /* end of list */ }
506: }
507: };
508:
509: static QEMUMachine pc_machine_v0_10 = {
510: .name = "pc-0.10",
511: .desc = "Standard PC, qemu 0.10",
1.1.1.4 root 512: .init = pc_init_pci_no_kvmclock,
1.1 root 513: .max_cpus = 255,
514: .compat_props = (GlobalProperty[]) {
515: {
516: .driver = "virtio-blk-pci",
517: .property = "class",
518: .value = stringify(PCI_CLASS_STORAGE_OTHER),
519: },{
520: .driver = "virtio-serial-pci",
521: .property = "class",
522: .value = stringify(PCI_CLASS_DISPLAY_OTHER),
523: },{
524: .driver = "virtio-serial-pci",
525: .property = "max_ports",
526: .value = stringify(1),
527: },{
528: .driver = "virtio-serial-pci",
529: .property = "vectors",
530: .value = stringify(0),
531: },{
532: .driver = "virtio-net-pci",
533: .property = "vectors",
534: .value = stringify(0),
535: },{
536: .driver = "virtio-blk-pci",
537: .property = "vectors",
538: .value = stringify(0),
539: },{
540: .driver = "ide-drive",
541: .property = "ver",
542: .value = "0.10",
543: },{
544: .driver = "scsi-disk",
545: .property = "ver",
546: .value = "0.10",
547: },{
548: .driver = "PCI",
549: .property = "rombar",
550: .value = stringify(0),
1.1.1.2 root 551: },{
552: .driver = "PCI",
553: .property = "command_serr_enable",
554: .value = "off",
1.1.1.4 root 555: },{
556: .driver = "virtio-blk-pci",
557: .property = "event_idx",
558: .value = "off",
559: },{
560: .driver = "virtio-serial-pci",
561: .property = "event_idx",
562: .value = "off",
563: },{
564: .driver = "virtio-net-pci",
565: .property = "event_idx",
566: .value = "off",
1.1.1.5 ! root 567: },{
! 568: .driver = "virtio-balloon-pci",
! 569: .property = "event_idx",
! 570: .value = "off",
! 571: },{
! 572: .driver = "AC97",
! 573: .property = "use_broken_id",
! 574: .value = stringify(1),
1.1 root 575: },
576: { /* end of list */ }
577: },
578: };
579:
580: static QEMUMachine isapc_machine = {
581: .name = "isapc",
582: .desc = "ISA-only PC",
583: .init = pc_init_isa,
584: .max_cpus = 1,
585: };
586:
1.1.1.4 root 587: #ifdef CONFIG_XEN
588: static QEMUMachine xenfv_machine = {
589: .name = "xenfv",
590: .desc = "Xen Fully-virtualized PC",
591: .init = pc_xen_hvm_init,
592: .max_cpus = HVM_MAX_VCPUS,
593: .default_machine_opts = "accel=xen",
594: };
595: #endif
596:
1.1 root 597: static void pc_machine_init(void)
598: {
1.1.1.5 ! root 599: qemu_register_machine(&pc_machine_v1_0);
! 600: qemu_register_machine(&pc_machine_v0_15);
! 601: qemu_register_machine(&pc_machine_v0_14);
1.1.1.2 root 602: qemu_register_machine(&pc_machine_v0_13);
1.1 root 603: qemu_register_machine(&pc_machine_v0_12);
604: qemu_register_machine(&pc_machine_v0_11);
605: qemu_register_machine(&pc_machine_v0_10);
606: qemu_register_machine(&isapc_machine);
1.1.1.4 root 607: #ifdef CONFIG_XEN
608: qemu_register_machine(&xenfv_machine);
609: #endif
1.1 root 610: }
611:
612: machine_init(pc_machine_init);
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.