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