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