xref: /qemu/hw/i386/pc_piix.c (revision 78f314cf)
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 "qemu/osdep.h"
26 #include CONFIG_DEVICES
27 
28 #include "qemu/units.h"
29 #include "hw/char/parallel.h"
30 #include "hw/dma/i8257.h"
31 #include "hw/loader.h"
32 #include "hw/i386/x86.h"
33 #include "hw/i386/pc.h"
34 #include "hw/i386/apic.h"
35 #include "hw/pci-host/i440fx.h"
36 #include "hw/rtc/mc146818rtc.h"
37 #include "hw/southbridge/piix.h"
38 #include "hw/display/ramfb.h"
39 #include "hw/firmware/smbios.h"
40 #include "hw/pci/pci.h"
41 #include "hw/pci/pci_ids.h"
42 #include "hw/usb.h"
43 #include "net/net.h"
44 #include "hw/ide/isa.h"
45 #include "hw/ide/pci.h"
46 #include "hw/ide/piix.h"
47 #include "hw/irq.h"
48 #include "sysemu/kvm.h"
49 #include "hw/kvm/clock.h"
50 #include "hw/sysbus.h"
51 #include "hw/i2c/smbus_eeprom.h"
52 #include "exec/memory.h"
53 #include "hw/acpi/acpi.h"
54 #include "hw/acpi/piix4.h"
55 #include "hw/usb/hcd-uhci.h"
56 #include "qapi/error.h"
57 #include "qemu/error-report.h"
58 #include "sysemu/xen.h"
59 #ifdef CONFIG_XEN
60 #include <xen/hvm/hvm_info_table.h>
61 #include "hw/xen/xen_pt.h"
62 #endif
63 #include "hw/xen/xen-x86.h"
64 #include "hw/xen/xen.h"
65 #include "migration/global_state.h"
66 #include "migration/misc.h"
67 #include "sysemu/numa.h"
68 #include "hw/hyperv/vmbus-bridge.h"
69 #include "hw/mem/nvdimm.h"
70 #include "hw/i386/acpi-build.h"
71 #include "kvm/kvm-cpu.h"
72 
73 #define MAX_IDE_BUS 2
74 
75 #ifdef CONFIG_IDE_ISA
76 static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
77 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
78 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
79 #endif
80 
81 /*
82  * Return the global irq number corresponding to a given device irq
83  * pin. We could also use the bus number to have a more precise mapping.
84  */
85 static int pc_pci_slot_get_pirq(PCIDevice *pci_dev, int pci_intx)
86 {
87     int slot_addend;
88     slot_addend = PCI_SLOT(pci_dev->devfn) - 1;
89     return (pci_intx + slot_addend) & 3;
90 }
91 
92 /* PC hardware initialisation */
93 static void pc_init1(MachineState *machine,
94                      const char *host_type, const char *pci_type)
95 {
96     PCMachineState *pcms = PC_MACHINE(machine);
97     PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
98     X86MachineState *x86ms = X86_MACHINE(machine);
99     MemoryRegion *system_memory = get_system_memory();
100     MemoryRegion *system_io = get_system_io();
101     PCIBus *pci_bus;
102     ISABus *isa_bus;
103     int piix3_devfn = -1;
104     qemu_irq smi_irq;
105     GSIState *gsi_state;
106     BusState *idebus[MAX_IDE_BUS];
107     ISADevice *rtc_state;
108     MemoryRegion *ram_memory;
109     MemoryRegion *pci_memory;
110     MemoryRegion *rom_memory;
111     ram_addr_t lowmem;
112     uint64_t hole64_size;
113     DeviceState *i440fx_host;
114 
115     /*
116      * Calculate ram split, for memory below and above 4G.  It's a bit
117      * complicated for backward compatibility reasons ...
118      *
119      *  - Traditional split is 3.5G (lowmem = 0xe0000000).  This is the
120      *    default value for max_ram_below_4g now.
121      *
122      *  - Then, to gigabyte align the memory, we move the split to 3G
123      *    (lowmem = 0xc0000000).  But only in case we have to split in
124      *    the first place, i.e. ram_size is larger than (traditional)
125      *    lowmem.  And for new machine types (gigabyte_align = true)
126      *    only, for live migration compatibility reasons.
127      *
128      *  - Next the max-ram-below-4g option was added, which allowed to
129      *    reduce lowmem to a smaller value, to allow a larger PCI I/O
130      *    window below 4G.  qemu doesn't enforce gigabyte alignment here,
131      *    but prints a warning.
132      *
133      *  - Finally max-ram-below-4g got updated to also allow raising lowmem,
134      *    so legacy non-PAE guests can get as much memory as possible in
135      *    the 32bit address space below 4G.
136      *
137      *  - Note that Xen has its own ram setup code in xen_ram_init(),
138      *    called via xen_hvm_init_pc().
139      *
140      * Examples:
141      *    qemu -M pc-1.7 -m 4G    (old default)    -> 3584M low,  512M high
142      *    qemu -M pc -m 4G        (new default)    -> 3072M low, 1024M high
143      *    qemu -M pc,max-ram-below-4g=2G -m 4G     -> 2048M low, 2048M high
144      *    qemu -M pc,max-ram-below-4g=4G -m 3968M  -> 3968M low (=4G-128M)
145      */
146     if (xen_enabled()) {
147         xen_hvm_init_pc(pcms, &ram_memory);
148     } else {
149         ram_memory = machine->ram;
150         if (!pcms->max_ram_below_4g) {
151             pcms->max_ram_below_4g = 0xe0000000; /* default: 3.5G */
152         }
153         lowmem = pcms->max_ram_below_4g;
154         if (machine->ram_size >= pcms->max_ram_below_4g) {
155             if (pcmc->gigabyte_align) {
156                 if (lowmem > 0xc0000000) {
157                     lowmem = 0xc0000000;
158                 }
159                 if (lowmem & (1 * GiB - 1)) {
160                     warn_report("Large machine and max_ram_below_4g "
161                                 "(%" PRIu64 ") not a multiple of 1G; "
162                                 "possible bad performance.",
163                                 pcms->max_ram_below_4g);
164                 }
165             }
166         }
167 
168         if (machine->ram_size >= lowmem) {
169             x86ms->above_4g_mem_size = machine->ram_size - lowmem;
170             x86ms->below_4g_mem_size = lowmem;
171         } else {
172             x86ms->above_4g_mem_size = 0;
173             x86ms->below_4g_mem_size = machine->ram_size;
174         }
175     }
176 
177     pc_machine_init_sgx_epc(pcms);
178     x86_cpus_init(x86ms, pcmc->default_cpu_version);
179 
180     if (pcmc->kvmclock_enabled) {
181         kvmclock_create(pcmc->kvmclock_create_always);
182     }
183 
184     if (pcmc->pci_enabled) {
185         pci_memory = g_new(MemoryRegion, 1);
186         memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
187         rom_memory = pci_memory;
188         i440fx_host = qdev_new(host_type);
189         hole64_size = object_property_get_uint(OBJECT(i440fx_host),
190                                                PCI_HOST_PROP_PCI_HOLE64_SIZE,
191                                                &error_abort);
192     } else {
193         pci_memory = NULL;
194         rom_memory = system_memory;
195         i440fx_host = NULL;
196         hole64_size = 0;
197     }
198 
199     pc_guest_info_init(pcms);
200 
201     if (pcmc->smbios_defaults) {
202         MachineClass *mc = MACHINE_GET_CLASS(machine);
203         /* These values are guest ABI, do not change */
204         smbios_set_defaults("QEMU", mc->desc,
205                             mc->name, pcmc->smbios_legacy_mode,
206                             pcmc->smbios_uuid_encoded,
207                             pcms->smbios_entry_point_type);
208     }
209 
210     /* allocate ram and load rom/bios */
211     if (!xen_enabled()) {
212         pc_memory_init(pcms, system_memory, rom_memory, hole64_size);
213     } else {
214         pc_system_flash_cleanup_unused(pcms);
215         if (machine->kernel_filename != NULL) {
216             /* For xen HVM direct kernel boot, load linux here */
217             xen_load_linux(pcms);
218         }
219     }
220 
221     gsi_state = pc_gsi_create(&x86ms->gsi, pcmc->pci_enabled);
222 
223     if (pcmc->pci_enabled) {
224         PIIX3State *piix3;
225         PCIDevice *pci_dev;
226         const char *type = xen_enabled() ? TYPE_PIIX3_XEN_DEVICE
227                                          : TYPE_PIIX3_DEVICE;
228 
229         pci_bus = i440fx_init(pci_type,
230                               i440fx_host,
231                               system_memory, system_io, machine->ram_size,
232                               x86ms->below_4g_mem_size,
233                               x86ms->above_4g_mem_size,
234                               pci_memory, ram_memory);
235         pci_bus_map_irqs(pci_bus,
236                          xen_enabled() ? xen_pci_slot_get_pirq
237                                        : pc_pci_slot_get_pirq);
238         pcms->bus = pci_bus;
239 
240         pci_dev = pci_create_simple_multifunction(pci_bus, -1, true, type);
241         piix3 = PIIX3_PCI_DEVICE(pci_dev);
242         piix3->pic = x86ms->gsi;
243         piix3_devfn = piix3->dev.devfn;
244         isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(piix3), "isa.0"));
245         rtc_state = ISA_DEVICE(object_resolve_path_component(OBJECT(pci_dev),
246                                                              "rtc"));
247     } else {
248         pci_bus = NULL;
249         isa_bus = isa_bus_new(NULL, system_memory, system_io,
250                               &error_abort);
251 
252         rtc_state = isa_new(TYPE_MC146818_RTC);
253         qdev_prop_set_int32(DEVICE(rtc_state), "base_year", 2000);
254         isa_realize_and_unref(rtc_state, isa_bus, &error_fatal);
255 
256         i8257_dma_init(isa_bus, 0);
257         pcms->hpet_enabled = false;
258     }
259     isa_bus_register_input_irqs(isa_bus, x86ms->gsi);
260 
261     if (x86ms->pic == ON_OFF_AUTO_ON || x86ms->pic == ON_OFF_AUTO_AUTO) {
262         pc_i8259_create(isa_bus, gsi_state->i8259_irq);
263     }
264 
265     if (pcmc->pci_enabled) {
266         ioapic_init_gsi(gsi_state, "i440fx");
267     }
268 
269     if (tcg_enabled()) {
270         x86_register_ferr_irq(x86ms->gsi[13]);
271     }
272 
273     pc_vga_init(isa_bus, pcmc->pci_enabled ? pci_bus : NULL);
274 
275     assert(pcms->vmport != ON_OFF_AUTO__MAX);
276     if (pcms->vmport == ON_OFF_AUTO_AUTO) {
277         pcms->vmport = xen_enabled() ? ON_OFF_AUTO_OFF : ON_OFF_AUTO_ON;
278     }
279 
280     /* init basic PC hardware */
281     pc_basic_device_init(pcms, isa_bus, x86ms->gsi, rtc_state, true,
282                          0x4);
283 
284     pc_nic_init(pcmc, isa_bus, pci_bus);
285 
286     if (pcmc->pci_enabled) {
287         PCIDevice *dev;
288 
289         dev = pci_create_simple(pci_bus, piix3_devfn + 1, TYPE_PIIX3_IDE);
290         pci_ide_create_devs(dev);
291         idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
292         idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
293         pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);
294     }
295 #ifdef CONFIG_IDE_ISA
296     else {
297         DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
298         int i;
299 
300         ide_drive_get(hd, ARRAY_SIZE(hd));
301         for (i = 0; i < MAX_IDE_BUS; i++) {
302             ISADevice *dev;
303             char busname[] = "ide.0";
304             dev = isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i],
305                                ide_irq[i],
306                                hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
307             /*
308              * The ide bus name is ide.0 for the first bus and ide.1 for the
309              * second one.
310              */
311             busname[4] = '0' + i;
312             idebus[i] = qdev_get_child_bus(DEVICE(dev), busname);
313         }
314         pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);
315     }
316 #endif
317 
318     if (pcmc->pci_enabled && machine_usb(machine)) {
319         pci_create_simple(pci_bus, piix3_devfn + 2, TYPE_PIIX3_USB_UHCI);
320     }
321 
322     if (pcmc->pci_enabled && x86_machine_is_acpi_enabled(X86_MACHINE(pcms))) {
323         PCIDevice *piix4_pm;
324 
325         smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0);
326         piix4_pm = pci_new(piix3_devfn + 3, TYPE_PIIX4_PM);
327         qdev_prop_set_uint32(DEVICE(piix4_pm), "smb_io_base", 0xb100);
328         qdev_prop_set_bit(DEVICE(piix4_pm), "smm-enabled",
329                           x86_machine_is_smm_enabled(x86ms));
330         pci_realize_and_unref(piix4_pm, pci_bus, &error_fatal);
331 
332         qdev_connect_gpio_out(DEVICE(piix4_pm), 0, x86ms->gsi[9]);
333         qdev_connect_gpio_out_named(DEVICE(piix4_pm), "smi-irq", 0, smi_irq);
334         pcms->smbus = I2C_BUS(qdev_get_child_bus(DEVICE(piix4_pm), "i2c"));
335         /* TODO: Populate SPD eeprom data.  */
336         smbus_eeprom_init(pcms->smbus, 8, NULL, 0);
337 
338         object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
339                                  TYPE_HOTPLUG_HANDLER,
340                                  (Object **)&x86ms->acpi_dev,
341                                  object_property_allow_set_link,
342                                  OBJ_PROP_LINK_STRONG);
343         object_property_set_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
344                                  OBJECT(piix4_pm), &error_abort);
345     }
346 
347     if (machine->nvdimms_state->is_enabled) {
348         nvdimm_init_acpi_state(machine->nvdimms_state, system_io,
349                                x86_nvdimm_acpi_dsmio,
350                                x86ms->fw_cfg, OBJECT(pcms));
351     }
352 }
353 
354 /* Looking for a pc_compat_2_4() function? It doesn't exist.
355  * pc_compat_*() functions that run on machine-init time and
356  * change global QEMU state are deprecated. Please don't create
357  * one, and implement any pc-*-2.4 (and newer) compat code in
358  * hw_compat_*, pc_compat_*, or * pc_*_machine_options().
359  */
360 
361 static void pc_compat_2_3_fn(MachineState *machine)
362 {
363     X86MachineState *x86ms = X86_MACHINE(machine);
364     if (kvm_enabled()) {
365         x86ms->smm = ON_OFF_AUTO_OFF;
366     }
367 }
368 
369 static void pc_compat_2_2_fn(MachineState *machine)
370 {
371     pc_compat_2_3_fn(machine);
372 }
373 
374 static void pc_compat_2_1_fn(MachineState *machine)
375 {
376     pc_compat_2_2_fn(machine);
377     x86_cpu_change_kvm_default("svm", NULL);
378 }
379 
380 static void pc_compat_2_0_fn(MachineState *machine)
381 {
382     pc_compat_2_1_fn(machine);
383 }
384 
385 static void pc_compat_1_7_fn(MachineState *machine)
386 {
387     pc_compat_2_0_fn(machine);
388     x86_cpu_change_kvm_default("x2apic", NULL);
389 }
390 
391 static void pc_compat_1_6_fn(MachineState *machine)
392 {
393     pc_compat_1_7_fn(machine);
394 }
395 
396 static void pc_compat_1_5_fn(MachineState *machine)
397 {
398     pc_compat_1_6_fn(machine);
399 }
400 
401 static void pc_compat_1_4_fn(MachineState *machine)
402 {
403     pc_compat_1_5_fn(machine);
404 }
405 
406 #ifdef CONFIG_ISAPC
407 static void pc_init_isa(MachineState *machine)
408 {
409     pc_init1(machine, TYPE_I440FX_PCI_HOST_BRIDGE, TYPE_I440FX_PCI_DEVICE);
410 }
411 #endif
412 
413 #ifdef CONFIG_XEN
414 static void pc_xen_hvm_init_pci(MachineState *machine)
415 {
416     const char *pci_type = xen_igd_gfx_pt_enabled() ?
417                 TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE : TYPE_I440FX_PCI_DEVICE;
418 
419     pc_init1(machine,
420              TYPE_I440FX_PCI_HOST_BRIDGE,
421              pci_type);
422 }
423 
424 static void pc_xen_hvm_init(MachineState *machine)
425 {
426     PCMachineState *pcms = PC_MACHINE(machine);
427 
428     if (!xen_enabled()) {
429         error_report("xenfv machine requires the xen accelerator");
430         exit(1);
431     }
432 
433     pc_xen_hvm_init_pci(machine);
434     xen_igd_reserve_slot(pcms->bus);
435     pci_create_simple(pcms->bus, -1, "xen-platform");
436 }
437 #endif
438 
439 #define DEFINE_I440FX_MACHINE(suffix, name, compatfn, optionfn) \
440     static void pc_init_##suffix(MachineState *machine) \
441     { \
442         void (*compat)(MachineState *m) = (compatfn); \
443         if (compat) { \
444             compat(machine); \
445         } \
446         pc_init1(machine, TYPE_I440FX_PCI_HOST_BRIDGE, \
447                  TYPE_I440FX_PCI_DEVICE); \
448     } \
449     DEFINE_PC_MACHINE(suffix, name, pc_init_##suffix, optionfn)
450 
451 static void pc_i440fx_machine_options(MachineClass *m)
452 {
453     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
454     pcmc->pci_root_uid = 0;
455     pcmc->default_cpu_version = 1;
456 
457     m->family = "pc_piix";
458     m->desc = "Standard PC (i440FX + PIIX, 1996)";
459     m->default_machine_opts = "firmware=bios-256k.bin";
460     m->default_display = "std";
461     m->default_nic = "e1000";
462     m->no_parallel = !module_object_class_by_name(TYPE_ISA_PARALLEL);
463     machine_class_allow_dynamic_sysbus_dev(m, TYPE_RAMFB_DEVICE);
464     machine_class_allow_dynamic_sysbus_dev(m, TYPE_VMBUS_BRIDGE);
465 }
466 
467 static void pc_i440fx_8_1_machine_options(MachineClass *m)
468 {
469     pc_i440fx_machine_options(m);
470     m->alias = "pc";
471     m->is_default = true;
472 }
473 
474 DEFINE_I440FX_MACHINE(v8_1, "pc-i440fx-8.1", NULL,
475                       pc_i440fx_8_1_machine_options);
476 
477 static void pc_i440fx_8_0_machine_options(MachineClass *m)
478 {
479     pc_i440fx_8_1_machine_options(m);
480     m->alias = NULL;
481     m->is_default = false;
482     compat_props_add(m->compat_props, hw_compat_8_0, hw_compat_8_0_len);
483     compat_props_add(m->compat_props, pc_compat_8_0, pc_compat_8_0_len);
484 }
485 
486 DEFINE_I440FX_MACHINE(v8_0, "pc-i440fx-8.0", NULL,
487                       pc_i440fx_8_0_machine_options);
488 
489 static void pc_i440fx_7_2_machine_options(MachineClass *m)
490 {
491     pc_i440fx_8_0_machine_options(m);
492     compat_props_add(m->compat_props, hw_compat_7_2, hw_compat_7_2_len);
493     compat_props_add(m->compat_props, pc_compat_7_2, pc_compat_7_2_len);
494 }
495 
496 DEFINE_I440FX_MACHINE(v7_2, "pc-i440fx-7.2", NULL,
497                       pc_i440fx_7_2_machine_options);
498 
499 static void pc_i440fx_7_1_machine_options(MachineClass *m)
500 {
501     pc_i440fx_7_2_machine_options(m);
502     compat_props_add(m->compat_props, hw_compat_7_1, hw_compat_7_1_len);
503     compat_props_add(m->compat_props, pc_compat_7_1, pc_compat_7_1_len);
504 }
505 
506 DEFINE_I440FX_MACHINE(v7_1, "pc-i440fx-7.1", NULL,
507                       pc_i440fx_7_1_machine_options);
508 
509 static void pc_i440fx_7_0_machine_options(MachineClass *m)
510 {
511     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
512     pc_i440fx_7_1_machine_options(m);
513     pcmc->enforce_amd_1tb_hole = false;
514     compat_props_add(m->compat_props, hw_compat_7_0, hw_compat_7_0_len);
515     compat_props_add(m->compat_props, pc_compat_7_0, pc_compat_7_0_len);
516 }
517 
518 DEFINE_I440FX_MACHINE(v7_0, "pc-i440fx-7.0", NULL,
519                       pc_i440fx_7_0_machine_options);
520 
521 static void pc_i440fx_6_2_machine_options(MachineClass *m)
522 {
523     pc_i440fx_7_0_machine_options(m);
524     compat_props_add(m->compat_props, hw_compat_6_2, hw_compat_6_2_len);
525     compat_props_add(m->compat_props, pc_compat_6_2, pc_compat_6_2_len);
526 }
527 
528 DEFINE_I440FX_MACHINE(v6_2, "pc-i440fx-6.2", NULL,
529                       pc_i440fx_6_2_machine_options);
530 
531 static void pc_i440fx_6_1_machine_options(MachineClass *m)
532 {
533     pc_i440fx_6_2_machine_options(m);
534     compat_props_add(m->compat_props, hw_compat_6_1, hw_compat_6_1_len);
535     compat_props_add(m->compat_props, pc_compat_6_1, pc_compat_6_1_len);
536     m->smp_props.prefer_sockets = true;
537 }
538 
539 DEFINE_I440FX_MACHINE(v6_1, "pc-i440fx-6.1", NULL,
540                       pc_i440fx_6_1_machine_options);
541 
542 static void pc_i440fx_6_0_machine_options(MachineClass *m)
543 {
544     pc_i440fx_6_1_machine_options(m);
545     compat_props_add(m->compat_props, hw_compat_6_0, hw_compat_6_0_len);
546     compat_props_add(m->compat_props, pc_compat_6_0, pc_compat_6_0_len);
547 }
548 
549 DEFINE_I440FX_MACHINE(v6_0, "pc-i440fx-6.0", NULL,
550                       pc_i440fx_6_0_machine_options);
551 
552 static void pc_i440fx_5_2_machine_options(MachineClass *m)
553 {
554     pc_i440fx_6_0_machine_options(m);
555     compat_props_add(m->compat_props, hw_compat_5_2, hw_compat_5_2_len);
556     compat_props_add(m->compat_props, pc_compat_5_2, pc_compat_5_2_len);
557 }
558 
559 DEFINE_I440FX_MACHINE(v5_2, "pc-i440fx-5.2", NULL,
560                       pc_i440fx_5_2_machine_options);
561 
562 static void pc_i440fx_5_1_machine_options(MachineClass *m)
563 {
564     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
565 
566     pc_i440fx_5_2_machine_options(m);
567     compat_props_add(m->compat_props, hw_compat_5_1, hw_compat_5_1_len);
568     compat_props_add(m->compat_props, pc_compat_5_1, pc_compat_5_1_len);
569     pcmc->kvmclock_create_always = false;
570     pcmc->pci_root_uid = 1;
571 }
572 
573 DEFINE_I440FX_MACHINE(v5_1, "pc-i440fx-5.1", NULL,
574                       pc_i440fx_5_1_machine_options);
575 
576 static void pc_i440fx_5_0_machine_options(MachineClass *m)
577 {
578     pc_i440fx_5_1_machine_options(m);
579     m->numa_mem_supported = true;
580     compat_props_add(m->compat_props, hw_compat_5_0, hw_compat_5_0_len);
581     compat_props_add(m->compat_props, pc_compat_5_0, pc_compat_5_0_len);
582     m->auto_enable_numa_with_memdev = false;
583 }
584 
585 DEFINE_I440FX_MACHINE(v5_0, "pc-i440fx-5.0", NULL,
586                       pc_i440fx_5_0_machine_options);
587 
588 static void pc_i440fx_4_2_machine_options(MachineClass *m)
589 {
590     pc_i440fx_5_0_machine_options(m);
591     compat_props_add(m->compat_props, hw_compat_4_2, hw_compat_4_2_len);
592     compat_props_add(m->compat_props, pc_compat_4_2, pc_compat_4_2_len);
593 }
594 
595 DEFINE_I440FX_MACHINE(v4_2, "pc-i440fx-4.2", NULL,
596                       pc_i440fx_4_2_machine_options);
597 
598 static void pc_i440fx_4_1_machine_options(MachineClass *m)
599 {
600     pc_i440fx_4_2_machine_options(m);
601     compat_props_add(m->compat_props, hw_compat_4_1, hw_compat_4_1_len);
602     compat_props_add(m->compat_props, pc_compat_4_1, pc_compat_4_1_len);
603 }
604 
605 DEFINE_I440FX_MACHINE(v4_1, "pc-i440fx-4.1", NULL,
606                       pc_i440fx_4_1_machine_options);
607 
608 static void pc_i440fx_4_0_machine_options(MachineClass *m)
609 {
610     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
611     pc_i440fx_4_1_machine_options(m);
612     pcmc->default_cpu_version = CPU_VERSION_LEGACY;
613     compat_props_add(m->compat_props, hw_compat_4_0, hw_compat_4_0_len);
614     compat_props_add(m->compat_props, pc_compat_4_0, pc_compat_4_0_len);
615 }
616 
617 DEFINE_I440FX_MACHINE(v4_0, "pc-i440fx-4.0", NULL,
618                       pc_i440fx_4_0_machine_options);
619 
620 static void pc_i440fx_3_1_machine_options(MachineClass *m)
621 {
622     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
623 
624     pc_i440fx_4_0_machine_options(m);
625     m->smbus_no_migration_support = true;
626     pcmc->pvh_enabled = false;
627     compat_props_add(m->compat_props, hw_compat_3_1, hw_compat_3_1_len);
628     compat_props_add(m->compat_props, pc_compat_3_1, pc_compat_3_1_len);
629 }
630 
631 DEFINE_I440FX_MACHINE(v3_1, "pc-i440fx-3.1", NULL,
632                       pc_i440fx_3_1_machine_options);
633 
634 static void pc_i440fx_3_0_machine_options(MachineClass *m)
635 {
636     pc_i440fx_3_1_machine_options(m);
637     compat_props_add(m->compat_props, hw_compat_3_0, hw_compat_3_0_len);
638     compat_props_add(m->compat_props, pc_compat_3_0, pc_compat_3_0_len);
639 }
640 
641 DEFINE_I440FX_MACHINE(v3_0, "pc-i440fx-3.0", NULL,
642                       pc_i440fx_3_0_machine_options);
643 
644 static void pc_i440fx_2_12_machine_options(MachineClass *m)
645 {
646     pc_i440fx_3_0_machine_options(m);
647     compat_props_add(m->compat_props, hw_compat_2_12, hw_compat_2_12_len);
648     compat_props_add(m->compat_props, pc_compat_2_12, pc_compat_2_12_len);
649 }
650 
651 DEFINE_I440FX_MACHINE(v2_12, "pc-i440fx-2.12", NULL,
652                       pc_i440fx_2_12_machine_options);
653 
654 static void pc_i440fx_2_11_machine_options(MachineClass *m)
655 {
656     pc_i440fx_2_12_machine_options(m);
657     compat_props_add(m->compat_props, hw_compat_2_11, hw_compat_2_11_len);
658     compat_props_add(m->compat_props, pc_compat_2_11, pc_compat_2_11_len);
659 }
660 
661 DEFINE_I440FX_MACHINE(v2_11, "pc-i440fx-2.11", NULL,
662                       pc_i440fx_2_11_machine_options);
663 
664 static void pc_i440fx_2_10_machine_options(MachineClass *m)
665 {
666     pc_i440fx_2_11_machine_options(m);
667     compat_props_add(m->compat_props, hw_compat_2_10, hw_compat_2_10_len);
668     compat_props_add(m->compat_props, pc_compat_2_10, pc_compat_2_10_len);
669     m->auto_enable_numa_with_memhp = false;
670 }
671 
672 DEFINE_I440FX_MACHINE(v2_10, "pc-i440fx-2.10", NULL,
673                       pc_i440fx_2_10_machine_options);
674 
675 static void pc_i440fx_2_9_machine_options(MachineClass *m)
676 {
677     pc_i440fx_2_10_machine_options(m);
678     compat_props_add(m->compat_props, hw_compat_2_9, hw_compat_2_9_len);
679     compat_props_add(m->compat_props, pc_compat_2_9, pc_compat_2_9_len);
680 }
681 
682 DEFINE_I440FX_MACHINE(v2_9, "pc-i440fx-2.9", NULL,
683                       pc_i440fx_2_9_machine_options);
684 
685 static void pc_i440fx_2_8_machine_options(MachineClass *m)
686 {
687     pc_i440fx_2_9_machine_options(m);
688     compat_props_add(m->compat_props, hw_compat_2_8, hw_compat_2_8_len);
689     compat_props_add(m->compat_props, pc_compat_2_8, pc_compat_2_8_len);
690 }
691 
692 DEFINE_I440FX_MACHINE(v2_8, "pc-i440fx-2.8", NULL,
693                       pc_i440fx_2_8_machine_options);
694 
695 static void pc_i440fx_2_7_machine_options(MachineClass *m)
696 {
697     pc_i440fx_2_8_machine_options(m);
698     compat_props_add(m->compat_props, hw_compat_2_7, hw_compat_2_7_len);
699     compat_props_add(m->compat_props, pc_compat_2_7, pc_compat_2_7_len);
700 }
701 
702 DEFINE_I440FX_MACHINE(v2_7, "pc-i440fx-2.7", NULL,
703                       pc_i440fx_2_7_machine_options);
704 
705 static void pc_i440fx_2_6_machine_options(MachineClass *m)
706 {
707     X86MachineClass *x86mc = X86_MACHINE_CLASS(m);
708     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
709 
710     pc_i440fx_2_7_machine_options(m);
711     pcmc->legacy_cpu_hotplug = true;
712     x86mc->fwcfg_dma_enabled = false;
713     compat_props_add(m->compat_props, hw_compat_2_6, hw_compat_2_6_len);
714     compat_props_add(m->compat_props, pc_compat_2_6, pc_compat_2_6_len);
715 }
716 
717 DEFINE_I440FX_MACHINE(v2_6, "pc-i440fx-2.6", NULL,
718                       pc_i440fx_2_6_machine_options);
719 
720 static void pc_i440fx_2_5_machine_options(MachineClass *m)
721 {
722     X86MachineClass *x86mc = X86_MACHINE_CLASS(m);
723 
724     pc_i440fx_2_6_machine_options(m);
725     x86mc->save_tsc_khz = false;
726     m->legacy_fw_cfg_order = 1;
727     compat_props_add(m->compat_props, hw_compat_2_5, hw_compat_2_5_len);
728     compat_props_add(m->compat_props, pc_compat_2_5, pc_compat_2_5_len);
729 }
730 
731 DEFINE_I440FX_MACHINE(v2_5, "pc-i440fx-2.5", NULL,
732                       pc_i440fx_2_5_machine_options);
733 
734 static void pc_i440fx_2_4_machine_options(MachineClass *m)
735 {
736     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
737 
738     pc_i440fx_2_5_machine_options(m);
739     m->hw_version = "2.4.0";
740     pcmc->broken_reserved_end = true;
741     compat_props_add(m->compat_props, hw_compat_2_4, hw_compat_2_4_len);
742     compat_props_add(m->compat_props, pc_compat_2_4, pc_compat_2_4_len);
743 }
744 
745 DEFINE_I440FX_MACHINE(v2_4, "pc-i440fx-2.4", NULL,
746                       pc_i440fx_2_4_machine_options)
747 
748 static void pc_i440fx_2_3_machine_options(MachineClass *m)
749 {
750     pc_i440fx_2_4_machine_options(m);
751     m->hw_version = "2.3.0";
752     compat_props_add(m->compat_props, hw_compat_2_3, hw_compat_2_3_len);
753     compat_props_add(m->compat_props, pc_compat_2_3, pc_compat_2_3_len);
754 }
755 
756 DEFINE_I440FX_MACHINE(v2_3, "pc-i440fx-2.3", pc_compat_2_3_fn,
757                       pc_i440fx_2_3_machine_options);
758 
759 static void pc_i440fx_2_2_machine_options(MachineClass *m)
760 {
761     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
762 
763     pc_i440fx_2_3_machine_options(m);
764     m->hw_version = "2.2.0";
765     m->default_machine_opts = "firmware=bios-256k.bin,suppress-vmdesc=on";
766     compat_props_add(m->compat_props, hw_compat_2_2, hw_compat_2_2_len);
767     compat_props_add(m->compat_props, pc_compat_2_2, pc_compat_2_2_len);
768     pcmc->rsdp_in_ram = false;
769     pcmc->resizable_acpi_blob = false;
770 }
771 
772 DEFINE_I440FX_MACHINE(v2_2, "pc-i440fx-2.2", pc_compat_2_2_fn,
773                       pc_i440fx_2_2_machine_options);
774 
775 static void pc_i440fx_2_1_machine_options(MachineClass *m)
776 {
777     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
778 
779     pc_i440fx_2_2_machine_options(m);
780     m->hw_version = "2.1.0";
781     m->default_display = NULL;
782     compat_props_add(m->compat_props, hw_compat_2_1, hw_compat_2_1_len);
783     compat_props_add(m->compat_props, pc_compat_2_1, pc_compat_2_1_len);
784     pcmc->smbios_uuid_encoded = false;
785     pcmc->enforce_aligned_dimm = false;
786 }
787 
788 DEFINE_I440FX_MACHINE(v2_1, "pc-i440fx-2.1", pc_compat_2_1_fn,
789                       pc_i440fx_2_1_machine_options);
790 
791 static void pc_i440fx_2_0_machine_options(MachineClass *m)
792 {
793     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
794 
795     pc_i440fx_2_1_machine_options(m);
796     m->hw_version = "2.0.0";
797     compat_props_add(m->compat_props, pc_compat_2_0, pc_compat_2_0_len);
798     pcmc->smbios_legacy_mode = true;
799     pcmc->has_reserved_memory = false;
800     /* This value depends on the actual DSDT and SSDT compiled into
801      * the source QEMU; unfortunately it depends on the binary and
802      * not on the machine type, so we cannot make pc-i440fx-1.7 work on
803      * both QEMU 1.7 and QEMU 2.0.
804      *
805      * Large variations cause migration to fail for more than one
806      * consecutive value of the "-smp" maxcpus option.
807      *
808      * For small variations of the kind caused by different iasl versions,
809      * the 4k rounding usually leaves slack.  However, there could be still
810      * one or two values that break.  For QEMU 1.7 and QEMU 2.0 the
811      * slack is only ~10 bytes before one "-smp maxcpus" value breaks!
812      *
813      * 6652 is valid for QEMU 2.0, the right value for pc-i440fx-1.7 on
814      * QEMU 1.7 it is 6414.  For RHEL/CentOS 7.0 it is 6418.
815      */
816     pcmc->legacy_acpi_table_size = 6652;
817     pcmc->acpi_data_size = 0x10000;
818 }
819 
820 DEFINE_I440FX_MACHINE(v2_0, "pc-i440fx-2.0", pc_compat_2_0_fn,
821                       pc_i440fx_2_0_machine_options);
822 
823 static void pc_i440fx_1_7_machine_options(MachineClass *m)
824 {
825     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
826 
827     pc_i440fx_2_0_machine_options(m);
828     m->hw_version = "1.7.0";
829     m->default_machine_opts = NULL;
830     m->option_rom_has_mr = true;
831     m->deprecation_reason = "old and unattended - use a newer version instead";
832     compat_props_add(m->compat_props, pc_compat_1_7, pc_compat_1_7_len);
833     pcmc->smbios_defaults = false;
834     pcmc->gigabyte_align = false;
835     pcmc->legacy_acpi_table_size = 6414;
836 }
837 
838 DEFINE_I440FX_MACHINE(v1_7, "pc-i440fx-1.7", pc_compat_1_7_fn,
839                       pc_i440fx_1_7_machine_options);
840 
841 static void pc_i440fx_1_6_machine_options(MachineClass *m)
842 {
843     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
844 
845     pc_i440fx_1_7_machine_options(m);
846     m->hw_version = "1.6.0";
847     m->rom_file_has_mr = false;
848     compat_props_add(m->compat_props, pc_compat_1_6, pc_compat_1_6_len);
849     pcmc->has_acpi_build = false;
850 }
851 
852 DEFINE_I440FX_MACHINE(v1_6, "pc-i440fx-1.6", pc_compat_1_6_fn,
853                       pc_i440fx_1_6_machine_options);
854 
855 static void pc_i440fx_1_5_machine_options(MachineClass *m)
856 {
857     pc_i440fx_1_6_machine_options(m);
858     m->hw_version = "1.5.0";
859     compat_props_add(m->compat_props, pc_compat_1_5, pc_compat_1_5_len);
860 }
861 
862 DEFINE_I440FX_MACHINE(v1_5, "pc-i440fx-1.5", pc_compat_1_5_fn,
863                       pc_i440fx_1_5_machine_options);
864 
865 static void pc_i440fx_1_4_machine_options(MachineClass *m)
866 {
867     pc_i440fx_1_5_machine_options(m);
868     m->hw_version = "1.4.0";
869     compat_props_add(m->compat_props, pc_compat_1_4, pc_compat_1_4_len);
870 }
871 
872 DEFINE_I440FX_MACHINE(v1_4, "pc-i440fx-1.4", pc_compat_1_4_fn,
873                       pc_i440fx_1_4_machine_options);
874 
875 #ifdef CONFIG_ISAPC
876 static void isapc_machine_options(MachineClass *m)
877 {
878     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
879     m->desc = "ISA-only PC";
880     m->max_cpus = 1;
881     m->option_rom_has_mr = true;
882     m->rom_file_has_mr = false;
883     pcmc->pci_enabled = false;
884     pcmc->has_acpi_build = false;
885     pcmc->smbios_defaults = false;
886     pcmc->gigabyte_align = false;
887     pcmc->smbios_legacy_mode = true;
888     pcmc->has_reserved_memory = false;
889     m->default_nic = "ne2k_isa";
890     m->default_cpu_type = X86_CPU_TYPE_NAME("486");
891     m->no_parallel = !module_object_class_by_name(TYPE_ISA_PARALLEL);
892 }
893 
894 DEFINE_PC_MACHINE(isapc, "isapc", pc_init_isa,
895                   isapc_machine_options);
896 #endif
897 
898 #ifdef CONFIG_XEN
899 static void xenfv_4_2_machine_options(MachineClass *m)
900 {
901     pc_i440fx_4_2_machine_options(m);
902     m->desc = "Xen Fully-virtualized PC";
903     m->max_cpus = HVM_MAX_VCPUS;
904     m->default_machine_opts = "accel=xen,suppress-vmdesc=on";
905 }
906 
907 DEFINE_PC_MACHINE(xenfv_4_2, "xenfv-4.2", pc_xen_hvm_init,
908                   xenfv_4_2_machine_options);
909 
910 static void xenfv_3_1_machine_options(MachineClass *m)
911 {
912     pc_i440fx_3_1_machine_options(m);
913     m->desc = "Xen Fully-virtualized PC";
914     m->alias = "xenfv";
915     m->max_cpus = HVM_MAX_VCPUS;
916     m->default_machine_opts = "accel=xen,suppress-vmdesc=on";
917 }
918 
919 DEFINE_PC_MACHINE(xenfv, "xenfv-3.1", pc_xen_hvm_init,
920                   xenfv_3_1_machine_options);
921 #endif
922