]> Git Repo - qemu.git/blob - hw/pc_piix.c
hbitmap: add assertion on hbitmap_iter_init
[qemu.git] / hw / pc_piix.c
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
25 #include <glib.h>
26
27 #include "hw.h"
28 #include "pc.h"
29 #include "apic.h"
30 #include "pci/pci.h"
31 #include "pci/pci_ids.h"
32 #include "usb.h"
33 #include "net/net.h"
34 #include "boards.h"
35 #include "ide.h"
36 #include "sysemu/kvm.h"
37 #include "kvm/clock.h"
38 #include "sysemu/sysemu.h"
39 #include "sysbus.h"
40 #include "sysemu/arch_init.h"
41 #include "sysemu/blockdev.h"
42 #include "smbus.h"
43 #include "xen.h"
44 #include "exec/memory.h"
45 #include "exec/address-spaces.h"
46 #include "cpu.h"
47 #ifdef CONFIG_XEN
48 #  include <xen/hvm/hvm_info_table.h>
49 #endif
50
51 #define MAX_IDE_BUS 2
52
53 static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
54 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
55 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
56
57 /* PC hardware initialisation */
58 static void pc_init1(MemoryRegion *system_memory,
59                      MemoryRegion *system_io,
60                      ram_addr_t ram_size,
61                      const char *boot_device,
62                      const char *kernel_filename,
63                      const char *kernel_cmdline,
64                      const char *initrd_filename,
65                      const char *cpu_model,
66                      int pci_enabled,
67                      int kvmclock_enabled)
68 {
69     int i;
70     ram_addr_t below_4g_mem_size, above_4g_mem_size;
71     PCIBus *pci_bus;
72     ISABus *isa_bus;
73     PCII440FXState *i440fx_state;
74     int piix3_devfn = -1;
75     qemu_irq *cpu_irq;
76     qemu_irq *gsi;
77     qemu_irq *i8259;
78     qemu_irq *smi_irq;
79     GSIState *gsi_state;
80     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
81     BusState *idebus[MAX_IDE_BUS];
82     ISADevice *rtc_state;
83     ISADevice *floppy;
84     MemoryRegion *ram_memory;
85     MemoryRegion *pci_memory;
86     MemoryRegion *rom_memory;
87     void *fw_cfg = NULL;
88
89     pc_cpus_init(cpu_model);
90     pc_acpi_init("acpi-dsdt.aml");
91
92     if (kvmclock_enabled) {
93         kvmclock_create();
94     }
95
96     if (ram_size >= 0xe0000000 ) {
97         above_4g_mem_size = ram_size - 0xe0000000;
98         below_4g_mem_size = 0xe0000000;
99     } else {
100         above_4g_mem_size = 0;
101         below_4g_mem_size = ram_size;
102     }
103
104     if (pci_enabled) {
105         pci_memory = g_new(MemoryRegion, 1);
106         memory_region_init(pci_memory, "pci", INT64_MAX);
107         rom_memory = pci_memory;
108     } else {
109         pci_memory = NULL;
110         rom_memory = system_memory;
111     }
112
113     /* allocate ram and load rom/bios */
114     if (!xen_enabled()) {
115         fw_cfg = pc_memory_init(system_memory,
116                        kernel_filename, kernel_cmdline, initrd_filename,
117                        below_4g_mem_size, above_4g_mem_size,
118                        rom_memory, &ram_memory);
119     }
120
121     gsi_state = g_malloc0(sizeof(*gsi_state));
122     if (kvm_irqchip_in_kernel()) {
123         kvm_pc_setup_irq_routing(pci_enabled);
124         gsi = qemu_allocate_irqs(kvm_pc_gsi_handler, gsi_state,
125                                  GSI_NUM_PINS);
126     } else {
127         gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
128     }
129
130     if (pci_enabled) {
131         pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, &isa_bus, gsi,
132                               system_memory, system_io, ram_size,
133                               below_4g_mem_size,
134                               0x100000000ULL - below_4g_mem_size,
135                               0x100000000ULL + above_4g_mem_size,
136                               (sizeof(hwaddr) == 4
137                                ? 0
138                                : ((uint64_t)1 << 62)),
139                               pci_memory, ram_memory);
140     } else {
141         pci_bus = NULL;
142         i440fx_state = NULL;
143         isa_bus = isa_bus_new(NULL, system_io);
144         no_hpet = 1;
145     }
146     isa_bus_irqs(isa_bus, gsi);
147
148     if (kvm_irqchip_in_kernel()) {
149         i8259 = kvm_i8259_init(isa_bus);
150     } else if (xen_enabled()) {
151         i8259 = xen_interrupt_controller_init();
152     } else {
153         cpu_irq = pc_allocate_cpu_irq();
154         i8259 = i8259_init(isa_bus, cpu_irq[0]);
155     }
156
157     for (i = 0; i < ISA_NUM_IRQS; i++) {
158         gsi_state->i8259_irq[i] = i8259[i];
159     }
160     if (pci_enabled) {
161         ioapic_init_gsi(gsi_state, "i440fx");
162     }
163
164     pc_register_ferr_irq(gsi[13]);
165
166     pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
167     if (xen_enabled()) {
168         pci_create_simple(pci_bus, -1, "xen-platform");
169     }
170
171     /* init basic PC hardware */
172     pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy, xen_enabled());
173
174     pc_nic_init(isa_bus, pci_bus);
175
176     ide_drive_get(hd, MAX_IDE_BUS);
177     if (pci_enabled) {
178         PCIDevice *dev;
179         if (xen_enabled()) {
180             dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
181         } else {
182             dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
183         }
184         idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
185         idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
186     } else {
187         for(i = 0; i < MAX_IDE_BUS; i++) {
188             ISADevice *dev;
189             dev = isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i],
190                                ide_irq[i],
191                                hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
192             idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
193         }
194     }
195
196     audio_init(isa_bus, pci_enabled ? pci_bus : NULL);
197
198     pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
199                  floppy, idebus[0], idebus[1], rtc_state);
200
201     if (pci_enabled && usb_enabled(false)) {
202         pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
203     }
204
205     if (pci_enabled && acpi_enabled) {
206         i2c_bus *smbus;
207
208         smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
209         /* TODO: Populate SPD eeprom data.  */
210         smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
211                               gsi[9], *smi_irq,
212                               kvm_enabled(), fw_cfg);
213         smbus_eeprom_init(smbus, 8, NULL, 0);
214     }
215
216     if (pci_enabled) {
217         pc_pci_device_init(pci_bus);
218     }
219 }
220
221 static void pc_init_pci(QEMUMachineInitArgs *args)
222 {
223     ram_addr_t ram_size = args->ram_size;
224     const char *cpu_model = args->cpu_model;
225     const char *kernel_filename = args->kernel_filename;
226     const char *kernel_cmdline = args->kernel_cmdline;
227     const char *initrd_filename = args->initrd_filename;
228     const char *boot_device = args->boot_device;
229     pc_init1(get_system_memory(),
230              get_system_io(),
231              ram_size, boot_device,
232              kernel_filename, kernel_cmdline,
233              initrd_filename, cpu_model, 1, 1);
234 }
235
236 static void pc_init_pci_1_3(QEMUMachineInitArgs *args)
237 {
238     enable_kvm_pv_eoi();
239     pc_init_pci(args);
240 }
241
242 static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs *args)
243 {
244     ram_addr_t ram_size = args->ram_size;
245     const char *cpu_model = args->cpu_model;
246     const char *kernel_filename = args->kernel_filename;
247     const char *kernel_cmdline = args->kernel_cmdline;
248     const char *initrd_filename = args->initrd_filename;
249     const char *boot_device = args->boot_device;
250     pc_init1(get_system_memory(),
251              get_system_io(),
252              ram_size, boot_device,
253              kernel_filename, kernel_cmdline,
254              initrd_filename, cpu_model, 1, 0);
255 }
256
257 static void pc_init_isa(QEMUMachineInitArgs *args)
258 {
259     ram_addr_t ram_size = args->ram_size;
260     const char *cpu_model = args->cpu_model;
261     const char *kernel_filename = args->kernel_filename;
262     const char *kernel_cmdline = args->kernel_cmdline;
263     const char *initrd_filename = args->initrd_filename;
264     const char *boot_device = args->boot_device;
265     if (cpu_model == NULL)
266         cpu_model = "486";
267     pc_init1(get_system_memory(),
268              get_system_io(),
269              ram_size, boot_device,
270              kernel_filename, kernel_cmdline,
271              initrd_filename, cpu_model, 0, 1);
272 }
273
274 #ifdef CONFIG_XEN
275 static void pc_xen_hvm_init(QEMUMachineInitArgs *args)
276 {
277     if (xen_hvm_init() != 0) {
278         hw_error("xen hardware virtual machine initialisation failed");
279     }
280     pc_init_pci_no_kvmclock(args);
281     xen_vcpu_init();
282 }
283 #endif
284
285 static QEMUMachine pc_i440fx_machine_v1_4 = {
286     .name = "pc-i440fx-1.4",
287     .alias = "pc",
288     .desc = "Standard PC (i440FX + PIIX, 1996)",
289     .init = pc_init_pci_1_3,
290     .max_cpus = 255,
291     .is_default = 1,
292     DEFAULT_MACHINE_OPTIONS,
293 };
294
295 #define PC_COMPAT_1_3 \
296         {\
297             .driver   = "usb-tablet",\
298             .property = "usb_version",\
299             .value    = stringify(1),\
300         }
301
302 static QEMUMachine pc_machine_v1_3 = {
303     .name = "pc-1.3",
304     .desc = "Standard PC",
305     .init = pc_init_pci_1_3,
306     .max_cpus = 255,
307     .compat_props = (GlobalProperty[]) {
308         PC_COMPAT_1_3,
309         { /* end of list */ }
310     },
311     DEFAULT_MACHINE_OPTIONS,
312 };
313
314 #define PC_COMPAT_1_2 \
315         PC_COMPAT_1_3,\
316         {\
317             .driver   = "nec-usb-xhci",\
318             .property = "msi",\
319             .value    = "off",\
320         },{\
321             .driver   = "nec-usb-xhci",\
322             .property = "msix",\
323             .value    = "off",\
324         },{\
325             .driver   = "ivshmem",\
326             .property = "use64",\
327             .value    = "0",\
328         },{\
329             .driver   = "qxl",\
330             .property = "revision",\
331             .value    = stringify(3),\
332         },{\
333             .driver   = "qxl-vga",\
334             .property = "revision",\
335             .value    = stringify(3),\
336         },{\
337             .driver   = "VGA",\
338             .property = "mmio",\
339             .value    = "off",\
340         }
341
342 static QEMUMachine pc_machine_v1_2 = {
343     .name = "pc-1.2",
344     .desc = "Standard PC",
345     .init = pc_init_pci,
346     .max_cpus = 255,
347     .compat_props = (GlobalProperty[]) {
348         PC_COMPAT_1_2,
349         { /* end of list */ }
350     },
351     DEFAULT_MACHINE_OPTIONS,
352 };
353
354 #define PC_COMPAT_1_1 \
355         PC_COMPAT_1_2,\
356         {\
357             .driver   = "virtio-scsi-pci",\
358             .property = "hotplug",\
359             .value    = "off",\
360         },{\
361             .driver   = "virtio-scsi-pci",\
362             .property = "param_change",\
363             .value    = "off",\
364         },{\
365             .driver   = "VGA",\
366             .property = "vgamem_mb",\
367             .value    = stringify(8),\
368         },{\
369             .driver   = "vmware-svga",\
370             .property = "vgamem_mb",\
371             .value    = stringify(8),\
372         },{\
373             .driver   = "qxl-vga",\
374             .property = "vgamem_mb",\
375             .value    = stringify(8),\
376         },{\
377             .driver   = "qxl",\
378             .property = "vgamem_mb",\
379             .value    = stringify(8),\
380         },{\
381             .driver   = "virtio-blk-pci",\
382             .property = "config-wce",\
383             .value    = "off",\
384         }
385
386 static QEMUMachine pc_machine_v1_1 = {
387     .name = "pc-1.1",
388     .desc = "Standard PC",
389     .init = pc_init_pci,
390     .max_cpus = 255,
391     .compat_props = (GlobalProperty[]) {
392         PC_COMPAT_1_1,
393         { /* end of list */ }
394     },
395     DEFAULT_MACHINE_OPTIONS,
396 };
397
398 #define PC_COMPAT_1_0 \
399         PC_COMPAT_1_1,\
400         {\
401             .driver   = "pc-sysfw",\
402             .property = "rom_only",\
403             .value    = stringify(1),\
404         }, {\
405             .driver   = "isa-fdc",\
406             .property = "check_media_rate",\
407             .value    = "off",\
408         }, {\
409             .driver   = "virtio-balloon-pci",\
410             .property = "class",\
411             .value    = stringify(PCI_CLASS_MEMORY_RAM),\
412         },{\
413             .driver   = "apic",\
414             .property = "vapic",\
415             .value    = "off",\
416         },{\
417             .driver   = TYPE_USB_DEVICE,\
418             .property = "full-path",\
419             .value    = "no",\
420         }
421
422 static QEMUMachine pc_machine_v1_0 = {
423     .name = "pc-1.0",
424     .desc = "Standard PC",
425     .init = pc_init_pci,
426     .max_cpus = 255,
427     .compat_props = (GlobalProperty[]) {
428         PC_COMPAT_1_0,
429         { /* end of list */ }
430     },
431     .hw_version = "1.0",
432     DEFAULT_MACHINE_OPTIONS,
433 };
434
435 #define PC_COMPAT_0_15 \
436         PC_COMPAT_1_0
437
438 static QEMUMachine pc_machine_v0_15 = {
439     .name = "pc-0.15",
440     .desc = "Standard PC",
441     .init = pc_init_pci,
442     .max_cpus = 255,
443     .compat_props = (GlobalProperty[]) {
444         PC_COMPAT_0_15,
445         { /* end of list */ }
446     },
447     .hw_version = "0.15",
448     DEFAULT_MACHINE_OPTIONS,
449 };
450
451 #define PC_COMPAT_0_14 \
452         PC_COMPAT_0_15,\
453         {\
454             .driver   = "virtio-blk-pci",\
455             .property = "event_idx",\
456             .value    = "off",\
457         },{\
458             .driver   = "virtio-serial-pci",\
459             .property = "event_idx",\
460             .value    = "off",\
461         },{\
462             .driver   = "virtio-net-pci",\
463             .property = "event_idx",\
464             .value    = "off",\
465         },{\
466             .driver   = "virtio-balloon-pci",\
467             .property = "event_idx",\
468             .value    = "off",\
469         }
470
471 static QEMUMachine pc_machine_v0_14 = {
472     .name = "pc-0.14",
473     .desc = "Standard PC",
474     .init = pc_init_pci,
475     .max_cpus = 255,
476     .compat_props = (GlobalProperty[]) {
477         PC_COMPAT_0_14, 
478         {
479             .driver   = "qxl",
480             .property = "revision",
481             .value    = stringify(2),
482         },{
483             .driver   = "qxl-vga",
484             .property = "revision",
485             .value    = stringify(2),
486         },
487         { /* end of list */ }
488     },
489     .hw_version = "0.14",
490     DEFAULT_MACHINE_OPTIONS,
491 };
492
493 #define PC_COMPAT_0_13 \
494         PC_COMPAT_0_14,\
495         {\
496             .driver   = TYPE_PCI_DEVICE,\
497             .property = "command_serr_enable",\
498             .value    = "off",\
499         },{\
500             .driver   = "AC97",\
501             .property = "use_broken_id",\
502             .value    = stringify(1),\
503         }
504
505 static QEMUMachine pc_machine_v0_13 = {
506     .name = "pc-0.13",
507     .desc = "Standard PC",
508     .init = pc_init_pci_no_kvmclock,
509     .max_cpus = 255,
510     .compat_props = (GlobalProperty[]) {
511         PC_COMPAT_0_13,
512         {
513             .driver   = "virtio-9p-pci",
514             .property = "vectors",
515             .value    = stringify(0),
516         },{
517             .driver   = "VGA",
518             .property = "rombar",
519             .value    = stringify(0),
520         },{
521             .driver   = "vmware-svga",
522             .property = "rombar",
523             .value    = stringify(0),
524         },
525         { /* end of list */ }
526     },
527     .hw_version = "0.13",
528     DEFAULT_MACHINE_OPTIONS,
529 };
530
531 #define PC_COMPAT_0_12 \
532         PC_COMPAT_0_13,\
533         {\
534             .driver   = "virtio-serial-pci",\
535             .property = "max_ports",\
536             .value    = stringify(1),\
537         },{\
538             .driver   = "virtio-serial-pci",\
539             .property = "vectors",\
540             .value    = stringify(0),\
541         }
542
543 static QEMUMachine pc_machine_v0_12 = {
544     .name = "pc-0.12",
545     .desc = "Standard PC",
546     .init = pc_init_pci_no_kvmclock,
547     .max_cpus = 255,
548     .compat_props = (GlobalProperty[]) {
549         PC_COMPAT_0_12,
550         {
551             .driver   = "VGA",
552             .property = "rombar",
553             .value    = stringify(0),
554         },{
555             .driver   = "vmware-svga",
556             .property = "rombar",
557             .value    = stringify(0),
558         },
559         { /* end of list */ }
560     },
561     .hw_version = "0.12",
562     DEFAULT_MACHINE_OPTIONS,
563 };
564
565 #define PC_COMPAT_0_11 \
566         PC_COMPAT_0_12,\
567         {\
568             .driver   = "virtio-blk-pci",\
569             .property = "vectors",\
570             .value    = stringify(0),\
571         },{\
572             .driver   = TYPE_PCI_DEVICE,\
573             .property = "rombar",\
574             .value    = stringify(0),\
575         }
576
577 static QEMUMachine pc_machine_v0_11 = {
578     .name = "pc-0.11",
579     .desc = "Standard PC, qemu 0.11",
580     .init = pc_init_pci_no_kvmclock,
581     .max_cpus = 255,
582     .compat_props = (GlobalProperty[]) {
583         PC_COMPAT_0_11,
584         {
585             .driver   = "ide-drive",
586             .property = "ver",
587             .value    = "0.11",
588         },{
589             .driver   = "scsi-disk",
590             .property = "ver",
591             .value    = "0.11",
592         },
593         { /* end of list */ }
594     },
595     .hw_version = "0.11",
596     DEFAULT_MACHINE_OPTIONS,
597 };
598
599 static QEMUMachine pc_machine_v0_10 = {
600     .name = "pc-0.10",
601     .desc = "Standard PC, qemu 0.10",
602     .init = pc_init_pci_no_kvmclock,
603     .max_cpus = 255,
604     .compat_props = (GlobalProperty[]) {
605         PC_COMPAT_0_11,
606         {
607             .driver   = "virtio-blk-pci",
608             .property = "class",
609             .value    = stringify(PCI_CLASS_STORAGE_OTHER),
610         },{
611             .driver   = "virtio-serial-pci",
612             .property = "class",
613             .value    = stringify(PCI_CLASS_DISPLAY_OTHER),
614         },{
615             .driver   = "virtio-net-pci",
616             .property = "vectors",
617             .value    = stringify(0),
618         },{
619             .driver   = "ide-drive",
620             .property = "ver",
621             .value    = "0.10",
622         },{
623             .driver   = "scsi-disk",
624             .property = "ver",
625             .value    = "0.10",
626         },
627         { /* end of list */ }
628     },
629     .hw_version = "0.10",
630     DEFAULT_MACHINE_OPTIONS,
631 };
632
633 static QEMUMachine isapc_machine = {
634     .name = "isapc",
635     .desc = "ISA-only PC",
636     .init = pc_init_isa,
637     .max_cpus = 1,
638     .compat_props = (GlobalProperty[]) {
639         {
640             .driver   = "pc-sysfw",
641             .property = "rom_only",
642             .value    = stringify(1),
643         },
644         { /* end of list */ }
645     },
646     DEFAULT_MACHINE_OPTIONS,
647 };
648
649 #ifdef CONFIG_XEN
650 static QEMUMachine xenfv_machine = {
651     .name = "xenfv",
652     .desc = "Xen Fully-virtualized PC",
653     .init = pc_xen_hvm_init,
654     .max_cpus = HVM_MAX_VCPUS,
655     .default_machine_opts = "accel=xen",
656     DEFAULT_MACHINE_OPTIONS,
657 };
658 #endif
659
660 static void pc_machine_init(void)
661 {
662     qemu_register_machine(&pc_i440fx_machine_v1_4);
663     qemu_register_machine(&pc_machine_v1_3);
664     qemu_register_machine(&pc_machine_v1_2);
665     qemu_register_machine(&pc_machine_v1_1);
666     qemu_register_machine(&pc_machine_v1_0);
667     qemu_register_machine(&pc_machine_v0_15);
668     qemu_register_machine(&pc_machine_v0_14);
669     qemu_register_machine(&pc_machine_v0_13);
670     qemu_register_machine(&pc_machine_v0_12);
671     qemu_register_machine(&pc_machine_v0_11);
672     qemu_register_machine(&pc_machine_v0_10);
673     qemu_register_machine(&isapc_machine);
674 #ifdef CONFIG_XEN
675     qemu_register_machine(&xenfv_machine);
676 #endif
677 }
678
679 machine_init(pc_machine_init);
This page took 0.061428 seconds and 4 git commands to generate.