xref: /openbmc/qemu/hw/i386/pc_piix.c (revision 0d70c5aa1bbfb0f5099d53d6e084337a8246cc0c)
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 "system/kvm.h"
47 #include "hw/i386/kvm/clock.h"
48 #include "hw/sysbus.h"
49 #include "hw/i2c/smbus_eeprom.h"
50 #include "system/memory.h"
51 #include "hw/acpi/acpi.h"
52 #include "qapi/error.h"
53 #include "qemu/error-report.h"
54 #include "system/xen.h"
55 #ifdef CONFIG_XEN
56 #include <xen/hvm/hvm_info_table.h>
57 #include "hw/xen/xen_pt.h"
58 #include "hw/xen/xen_igd.h"
59 #endif
60 #include "hw/xen/xen-x86.h"
61 #include "hw/xen/xen.h"
62 #include "migration/global_state.h"
63 #include "migration/misc.h"
64 #include "system/runstate.h"
65 #include "system/numa.h"
66 #include "hw/hyperv/vmbus-bridge.h"
67 #include "hw/mem/nvdimm.h"
68 #include "hw/uefi/var-service-api.h"
69 #include "hw/i386/acpi-build.h"
70 #include "target/i386/cpu.h"
71 
72 #define XEN_IOAPIC_NUM_PIRQS 128ULL
73 
74 #ifdef CONFIG_IDE_ISA
75 static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
76 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
77 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
78 #endif
79 
80 /*
81  * Return the global irq number corresponding to a given device irq
82  * pin. We could also use the bus number to have a more precise mapping.
83  */
84 static int pc_pci_slot_get_pirq(PCIDevice *pci_dev, int pci_intx)
85 {
86     int slot_addend;
87     slot_addend = PCI_SLOT(pci_dev->devfn) - 1;
88     return (pci_intx + slot_addend) & 3;
89 }
90 
91 static void piix_intx_routing_notifier_xen(PCIDevice *dev)
92 {
93     int i;
94 
95     /* Scan for updates to PCI link routes. */
96     for (i = 0; i < PIIX_NUM_PIRQS; i++) {
97         const PCIINTxRoute route = pci_device_route_intx_to_irq(dev, i);
98         const uint8_t v = route.mode == PCI_INTX_ENABLED ? route.irq : 0;
99         xen_set_pci_link_route(i, v);
100     }
101 }
102 
103 /* PC hardware initialisation */
104 static void pc_init1(MachineState *machine, const char *pci_type)
105 {
106     PCMachineState *pcms = PC_MACHINE(machine);
107     PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
108     X86MachineState *x86ms = X86_MACHINE(machine);
109     MemoryRegion *system_memory = get_system_memory();
110     MemoryRegion *system_io = get_system_io();
111     Object *phb = NULL;
112     ISABus *isa_bus;
113     Object *piix4_pm = NULL;
114     qemu_irq smi_irq;
115     GSIState *gsi_state;
116     MemoryRegion *ram_memory;
117     MemoryRegion *pci_memory = NULL;
118     MemoryRegion *rom_memory = system_memory;
119     ram_addr_t lowmem;
120     uint64_t hole64_size = 0;
121 
122     /*
123      * Calculate ram split, for memory below and above 4G.  It's a bit
124      * complicated for backward compatibility reasons ...
125      *
126      *  - Traditional split is 3.5G (lowmem = 0xe0000000).  This is the
127      *    default value for max_ram_below_4g now.
128      *
129      *  - Then, to gigabyte align the memory, we move the split to 3G
130      *    (lowmem = 0xc0000000).  But only in case we have to split in
131      *    the first place, i.e. ram_size is larger than (traditional)
132      *    lowmem.  And for new machine types (gigabyte_align = true)
133      *    only, for live migration compatibility reasons.
134      *
135      *  - Next the max-ram-below-4g option was added, which allowed to
136      *    reduce lowmem to a smaller value, to allow a larger PCI I/O
137      *    window below 4G.  qemu doesn't enforce gigabyte alignment here,
138      *    but prints a warning.
139      *
140      *  - Finally max-ram-below-4g got updated to also allow raising lowmem,
141      *    so legacy non-PAE guests can get as much memory as possible in
142      *    the 32bit address space below 4G.
143      *
144      *  - Note that Xen has its own ram setup code in xen_ram_init(),
145      *    called via xen_hvm_init_pc().
146      *
147      * Examples:
148      *    qemu -M pc-1.7 -m 4G    (old default)    -> 3584M low,  512M high
149      *    qemu -M pc -m 4G        (new default)    -> 3072M low, 1024M high
150      *    qemu -M pc,max-ram-below-4g=2G -m 4G     -> 2048M low, 2048M high
151      *    qemu -M pc,max-ram-below-4g=4G -m 3968M  -> 3968M low (=4G-128M)
152      */
153     if (xen_enabled()) {
154         xen_hvm_init_pc(pcms, &ram_memory);
155     } else {
156         ram_memory = machine->ram;
157         if (!pcms->max_ram_below_4g) {
158             pcms->max_ram_below_4g = 0xe0000000; /* default: 3.5G */
159         }
160         lowmem = pcms->max_ram_below_4g;
161         if (machine->ram_size >= pcms->max_ram_below_4g) {
162             if (pcmc->gigabyte_align) {
163                 if (lowmem > 0xc0000000) {
164                     lowmem = 0xc0000000;
165                 }
166                 if (lowmem & (1 * GiB - 1)) {
167                     warn_report("Large machine and max_ram_below_4g "
168                                 "(%" PRIu64 ") not a multiple of 1G; "
169                                 "possible bad performance.",
170                                 pcms->max_ram_below_4g);
171                 }
172             }
173         }
174 
175         if (machine->ram_size >= lowmem) {
176             x86ms->above_4g_mem_size = machine->ram_size - lowmem;
177             x86ms->below_4g_mem_size = lowmem;
178         } else {
179             x86ms->above_4g_mem_size = 0;
180             x86ms->below_4g_mem_size = machine->ram_size;
181         }
182     }
183 
184     pc_machine_init_sgx_epc(pcms);
185     x86_cpus_init(x86ms, pcmc->default_cpu_version);
186 
187     if (kvm_enabled()) {
188         kvmclock_create(pcmc->kvmclock_create_always);
189     }
190 
191     if (pcmc->pci_enabled) {
192         pci_memory = g_new(MemoryRegion, 1);
193         memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
194         rom_memory = pci_memory;
195 
196         phb = OBJECT(qdev_new(TYPE_I440FX_PCI_HOST_BRIDGE));
197         object_property_add_child(OBJECT(machine), "i440fx", phb);
198         object_property_set_link(phb, PCI_HOST_PROP_RAM_MEM,
199                                  OBJECT(ram_memory), &error_fatal);
200         object_property_set_link(phb, PCI_HOST_PROP_PCI_MEM,
201                                  OBJECT(pci_memory), &error_fatal);
202         object_property_set_link(phb, PCI_HOST_PROP_SYSTEM_MEM,
203                                  OBJECT(system_memory), &error_fatal);
204         object_property_set_link(phb, PCI_HOST_PROP_IO_MEM,
205                                  OBJECT(system_io), &error_fatal);
206         object_property_set_uint(phb, PCI_HOST_BELOW_4G_MEM_SIZE,
207                                  x86ms->below_4g_mem_size, &error_fatal);
208         object_property_set_uint(phb, PCI_HOST_ABOVE_4G_MEM_SIZE,
209                                  x86ms->above_4g_mem_size, &error_fatal);
210         object_property_set_str(phb, I440FX_HOST_PROP_PCI_TYPE, pci_type,
211                                 &error_fatal);
212         sysbus_realize_and_unref(SYS_BUS_DEVICE(phb), &error_fatal);
213 
214         pcms->pcibus = PCI_BUS(qdev_get_child_bus(DEVICE(phb), "pci.0"));
215         pci_bus_map_irqs(pcms->pcibus,
216                          xen_enabled() ? xen_pci_slot_get_pirq
217                                        : pc_pci_slot_get_pirq);
218 
219         hole64_size = object_property_get_uint(phb,
220                                                PCI_HOST_PROP_PCI_HOLE64_SIZE,
221                                                &error_abort);
222     }
223 
224     /* allocate ram and load rom/bios */
225     if (!xen_enabled()) {
226         pc_memory_init(pcms, system_memory, rom_memory, hole64_size);
227     } else {
228         assert(machine->ram_size == x86ms->below_4g_mem_size +
229                                     x86ms->above_4g_mem_size);
230 
231         pc_system_flash_cleanup_unused(pcms);
232         if (machine->kernel_filename != NULL) {
233             /* For xen HVM direct kernel boot, load linux here */
234             xen_load_linux(pcms);
235         }
236     }
237 
238     gsi_state = pc_gsi_create(&x86ms->gsi, pcmc->pci_enabled);
239 
240     if (pcmc->pci_enabled) {
241         PCIDevice *pci_dev;
242         DeviceState *dev;
243         size_t i;
244 
245         pci_dev = pci_new_multifunction(-1, pcms->south_bridge);
246         object_property_set_bool(OBJECT(pci_dev), "has-usb",
247                                  machine_usb(machine), &error_abort);
248         object_property_set_bool(OBJECT(pci_dev), "has-acpi",
249                                  x86_machine_is_acpi_enabled(x86ms),
250                                  &error_abort);
251         object_property_set_bool(OBJECT(pci_dev), "has-pic", false,
252                                  &error_abort);
253         object_property_set_bool(OBJECT(pci_dev), "has-pit", false,
254                                  &error_abort);
255         qdev_prop_set_uint32(DEVICE(pci_dev), "smb_io_base", 0xb100);
256         object_property_set_bool(OBJECT(pci_dev), "smm-enabled",
257                                  x86_machine_is_smm_enabled(x86ms),
258                                  &error_abort);
259         dev = DEVICE(pci_dev);
260         for (i = 0; i < ISA_NUM_IRQS; i++) {
261             qdev_connect_gpio_out_named(dev, "isa-irqs", i, x86ms->gsi[i]);
262         }
263         pci_realize_and_unref(pci_dev, pcms->pcibus, &error_fatal);
264 
265         if (xen_enabled()) {
266             pci_device_set_intx_routing_notifier(
267                         pci_dev, piix_intx_routing_notifier_xen);
268 
269             /*
270              * Xen supports additional interrupt routes from the PCI devices to
271              * the IOAPIC: the four pins of each PCI device on the bus are also
272              * connected to the IOAPIC directly.
273              * These additional routes can be discovered through ACPI.
274              */
275             pci_bus_irqs(pcms->pcibus, xen_intx_set_irq, pci_dev,
276                          XEN_IOAPIC_NUM_PIRQS);
277         }
278 
279         isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(pci_dev), "isa.0"));
280         x86ms->rtc = ISA_DEVICE(object_resolve_path_component(OBJECT(pci_dev),
281                                                               "rtc"));
282         piix4_pm = object_resolve_path_component(OBJECT(pci_dev), "pm");
283         dev = DEVICE(object_resolve_path_component(OBJECT(pci_dev), "ide"));
284         pci_ide_create_devs(PCI_DEVICE(dev));
285         pcms->idebus[0] = qdev_get_child_bus(dev, "ide.0");
286         pcms->idebus[1] = qdev_get_child_bus(dev, "ide.1");
287     } else {
288         uint32_t irq;
289 
290         isa_bus = isa_bus_new(NULL, system_memory, system_io,
291                               &error_abort);
292         isa_bus_register_input_irqs(isa_bus, x86ms->gsi);
293 
294         x86ms->rtc = isa_new(TYPE_MC146818_RTC);
295         qdev_prop_set_int32(DEVICE(x86ms->rtc), "base_year", 2000);
296         isa_realize_and_unref(x86ms->rtc, isa_bus, &error_fatal);
297         irq = object_property_get_uint(OBJECT(x86ms->rtc), "irq",
298                                        &error_fatal);
299         isa_connect_gpio_out(ISA_DEVICE(x86ms->rtc), 0, irq);
300 
301         i8257_dma_init(OBJECT(machine), isa_bus, 0);
302         pcms->hpet_enabled = false;
303     }
304 
305     if (x86ms->pic == ON_OFF_AUTO_ON || x86ms->pic == ON_OFF_AUTO_AUTO) {
306         pc_i8259_create(isa_bus, gsi_state->i8259_irq);
307     }
308 
309     if (phb) {
310         ioapic_init_gsi(gsi_state, phb);
311     }
312 
313     if (tcg_enabled()) {
314         x86_register_ferr_irq(x86ms->gsi[13]);
315     }
316 
317     pc_vga_init(isa_bus, pcmc->pci_enabled ? pcms->pcibus : NULL);
318 
319     /* init basic PC hardware */
320     pc_basic_device_init(pcms, isa_bus, x86ms->gsi, x86ms->rtc,
321                          !MACHINE_CLASS(pcmc)->no_floppy, 0x4);
322 
323     pc_nic_init(pcmc, isa_bus, pcms->pcibus);
324 
325 #ifdef CONFIG_IDE_ISA
326     if (!pcmc->pci_enabled) {
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             pcms->idebus[i] = qdev_get_child_bus(DEVICE(dev), busname);
343         }
344     }
345 #endif
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 #if defined(CONFIG_IGVM)
371     /* Apply guest state from IGVM if supplied */
372     if (x86ms->igvm) {
373         if (IGVM_CFG_GET_CLASS(x86ms->igvm)
374                 ->process(x86ms->igvm, machine->cgs, false, &error_fatal) < 0) {
375             g_assert_not_reached();
376         }
377     }
378 #endif
379 }
380 
381 typedef enum PCSouthBridgeOption {
382     PC_SOUTH_BRIDGE_OPTION_PIIX3,
383     PC_SOUTH_BRIDGE_OPTION_PIIX4,
384     PC_SOUTH_BRIDGE_OPTION_MAX,
385 } PCSouthBridgeOption;
386 
387 static const QEnumLookup PCSouthBridgeOption_lookup = {
388     .array = (const char *const[]) {
389         [PC_SOUTH_BRIDGE_OPTION_PIIX3] = TYPE_PIIX3_DEVICE,
390         [PC_SOUTH_BRIDGE_OPTION_PIIX4] = TYPE_PIIX4_PCI_DEVICE,
391     },
392     .size = PC_SOUTH_BRIDGE_OPTION_MAX
393 };
394 
395 static int pc_get_south_bridge(Object *obj, Error **errp)
396 {
397     PCMachineState *pcms = PC_MACHINE(obj);
398     int i;
399 
400     for (i = 0; i < PCSouthBridgeOption_lookup.size; i++) {
401         if (g_strcmp0(PCSouthBridgeOption_lookup.array[i],
402                       pcms->south_bridge) == 0) {
403             return i;
404         }
405     }
406 
407     error_setg(errp, "Invalid south bridge value set");
408     return 0;
409 }
410 
411 static void pc_set_south_bridge(Object *obj, int value, Error **errp)
412 {
413     PCMachineState *pcms = PC_MACHINE(obj);
414 
415     if (value < 0) {
416         error_setg(errp, "Value can't be negative");
417         return;
418     }
419 
420     if (value >= PCSouthBridgeOption_lookup.size) {
421         error_setg(errp, "Value too big");
422         return;
423     }
424 
425     pcms->south_bridge = PCSouthBridgeOption_lookup.array[value];
426 }
427 
428 #ifdef CONFIG_ISAPC
429 static void pc_init_isa(MachineState *machine)
430 {
431     pc_init1(machine, NULL);
432 }
433 #endif
434 
435 #ifdef CONFIG_XEN
436 static void pc_xen_hvm_init_pci(MachineState *machine)
437 {
438     const char *pci_type = xen_igd_gfx_pt_enabled() ?
439                 TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE : TYPE_I440FX_PCI_DEVICE;
440 
441     pc_init1(machine, pci_type);
442 }
443 
444 static void pc_xen_hvm_init(MachineState *machine)
445 {
446     PCMachineState *pcms = PC_MACHINE(machine);
447 
448     if (!xen_enabled()) {
449         error_report("xenfv machine requires the xen accelerator");
450         exit(1);
451     }
452 
453     pc_xen_hvm_init_pci(machine);
454     xen_igd_reserve_slot(pcms->pcibus);
455     pci_create_simple(pcms->pcibus, -1, "xen-platform");
456 }
457 #endif
458 
459 static void pc_i440fx_init(MachineState *machine)
460 {
461     pc_init1(machine, TYPE_I440FX_PCI_DEVICE);
462 }
463 
464 #define DEFINE_I440FX_MACHINE(major, minor) \
465     DEFINE_PC_VER_MACHINE(pc_i440fx, "pc-i440fx", pc_i440fx_init, false, NULL, major, minor);
466 
467 #define DEFINE_I440FX_MACHINE_AS_LATEST(major, minor) \
468     DEFINE_PC_VER_MACHINE(pc_i440fx, "pc-i440fx", pc_i440fx_init, true, "pc", major, minor);
469 
470 static void pc_i440fx_machine_options(MachineClass *m)
471 {
472     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
473     ObjectClass *oc = OBJECT_CLASS(m);
474     pcmc->default_south_bridge = TYPE_PIIX3_DEVICE;
475     pcmc->pci_root_uid = 0;
476     pcmc->default_cpu_version = 1;
477 
478     m->family = "pc_piix";
479     m->desc = "Standard PC (i440FX + PIIX, 1996)";
480     m->default_machine_opts = "firmware=bios-256k.bin";
481     m->default_display = "std";
482     m->default_nic = "e1000";
483     m->no_floppy = !module_object_class_by_name(TYPE_ISA_FDC);
484     m->no_parallel = !module_object_class_by_name(TYPE_ISA_PARALLEL);
485     machine_class_allow_dynamic_sysbus_dev(m, TYPE_RAMFB_DEVICE);
486     machine_class_allow_dynamic_sysbus_dev(m, TYPE_VMBUS_BRIDGE);
487     machine_class_allow_dynamic_sysbus_dev(m, TYPE_UEFI_VARS_X64);
488 
489     object_class_property_add_enum(oc, "x-south-bridge", "PCSouthBridgeOption",
490                                    &PCSouthBridgeOption_lookup,
491                                    pc_get_south_bridge,
492                                    pc_set_south_bridge);
493     object_class_property_set_description(oc, "x-south-bridge",
494                                      "Use a different south bridge than PIIX3");
495 }
496 
497 static void pc_i440fx_machine_10_1_options(MachineClass *m)
498 {
499     pc_i440fx_machine_options(m);
500 }
501 
502 DEFINE_I440FX_MACHINE_AS_LATEST(10, 1);
503 
504 static void pc_i440fx_machine_10_0_options(MachineClass *m)
505 {
506     pc_i440fx_machine_10_1_options(m);
507     compat_props_add(m->compat_props, hw_compat_10_0, hw_compat_10_0_len);
508     compat_props_add(m->compat_props, pc_compat_10_0, pc_compat_10_0_len);
509 }
510 
511 DEFINE_I440FX_MACHINE(10, 0);
512 
513 static void pc_i440fx_machine_9_2_options(MachineClass *m)
514 {
515     pc_i440fx_machine_10_0_options(m);
516     compat_props_add(m->compat_props, hw_compat_9_2, hw_compat_9_2_len);
517     compat_props_add(m->compat_props, pc_compat_9_2, pc_compat_9_2_len);
518 }
519 
520 DEFINE_I440FX_MACHINE(9, 2);
521 
522 static void pc_i440fx_machine_9_1_options(MachineClass *m)
523 {
524     pc_i440fx_machine_9_2_options(m);
525     compat_props_add(m->compat_props, hw_compat_9_1, hw_compat_9_1_len);
526     compat_props_add(m->compat_props, pc_compat_9_1, pc_compat_9_1_len);
527 }
528 
529 DEFINE_I440FX_MACHINE(9, 1);
530 
531 static void pc_i440fx_machine_9_0_options(MachineClass *m)
532 {
533     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
534 
535     pc_i440fx_machine_9_1_options(m);
536     m->smbios_memory_device_size = 16 * GiB;
537 
538     compat_props_add(m->compat_props, hw_compat_9_0, hw_compat_9_0_len);
539     compat_props_add(m->compat_props, pc_compat_9_0, pc_compat_9_0_len);
540     pcmc->isa_bios_alias = false;
541 }
542 
543 DEFINE_I440FX_MACHINE(9, 0);
544 
545 static void pc_i440fx_machine_8_2_options(MachineClass *m)
546 {
547     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
548 
549     pc_i440fx_machine_9_0_options(m);
550 
551     compat_props_add(m->compat_props, hw_compat_8_2, hw_compat_8_2_len);
552     compat_props_add(m->compat_props, pc_compat_8_2, pc_compat_8_2_len);
553     /* For pc-i44fx-8.2 and 8.1, use SMBIOS 3.X by default */
554     pcmc->default_smbios_ep_type = SMBIOS_ENTRY_POINT_TYPE_64;
555 }
556 
557 DEFINE_I440FX_MACHINE(8, 2);
558 
559 static void pc_i440fx_machine_8_1_options(MachineClass *m)
560 {
561     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
562 
563     pc_i440fx_machine_8_2_options(m);
564     pcmc->broken_32bit_mem_addr_check = true;
565 
566     compat_props_add(m->compat_props, hw_compat_8_1, hw_compat_8_1_len);
567     compat_props_add(m->compat_props, pc_compat_8_1, pc_compat_8_1_len);
568 }
569 
570 DEFINE_I440FX_MACHINE(8, 1);
571 
572 static void pc_i440fx_machine_8_0_options(MachineClass *m)
573 {
574     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
575 
576     pc_i440fx_machine_8_1_options(m);
577     compat_props_add(m->compat_props, hw_compat_8_0, hw_compat_8_0_len);
578     compat_props_add(m->compat_props, pc_compat_8_0, pc_compat_8_0_len);
579 
580     /* For pc-i44fx-8.0 and older, use SMBIOS 2.8 by default */
581     pcmc->default_smbios_ep_type = SMBIOS_ENTRY_POINT_TYPE_32;
582 }
583 
584 DEFINE_I440FX_MACHINE(8, 0);
585 
586 static void pc_i440fx_machine_7_2_options(MachineClass *m)
587 {
588     pc_i440fx_machine_8_0_options(m);
589     compat_props_add(m->compat_props, hw_compat_7_2, hw_compat_7_2_len);
590     compat_props_add(m->compat_props, pc_compat_7_2, pc_compat_7_2_len);
591 }
592 
593 DEFINE_I440FX_MACHINE(7, 2)
594 
595 static void pc_i440fx_machine_7_1_options(MachineClass *m)
596 {
597     pc_i440fx_machine_7_2_options(m);
598     compat_props_add(m->compat_props, hw_compat_7_1, hw_compat_7_1_len);
599     compat_props_add(m->compat_props, pc_compat_7_1, pc_compat_7_1_len);
600 }
601 
602 DEFINE_I440FX_MACHINE(7, 1);
603 
604 static void pc_i440fx_machine_7_0_options(MachineClass *m)
605 {
606     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
607     pc_i440fx_machine_7_1_options(m);
608     pcmc->enforce_amd_1tb_hole = false;
609     compat_props_add(m->compat_props, hw_compat_7_0, hw_compat_7_0_len);
610     compat_props_add(m->compat_props, pc_compat_7_0, pc_compat_7_0_len);
611 }
612 
613 DEFINE_I440FX_MACHINE(7, 0);
614 
615 static void pc_i440fx_machine_6_2_options(MachineClass *m)
616 {
617     pc_i440fx_machine_7_0_options(m);
618     compat_props_add(m->compat_props, hw_compat_6_2, hw_compat_6_2_len);
619     compat_props_add(m->compat_props, pc_compat_6_2, pc_compat_6_2_len);
620 }
621 
622 DEFINE_I440FX_MACHINE(6, 2);
623 
624 static void pc_i440fx_machine_6_1_options(MachineClass *m)
625 {
626     pc_i440fx_machine_6_2_options(m);
627     compat_props_add(m->compat_props, hw_compat_6_1, hw_compat_6_1_len);
628     compat_props_add(m->compat_props, pc_compat_6_1, pc_compat_6_1_len);
629     m->smp_props.prefer_sockets = true;
630 }
631 
632 DEFINE_I440FX_MACHINE(6, 1);
633 
634 static void pc_i440fx_machine_6_0_options(MachineClass *m)
635 {
636     pc_i440fx_machine_6_1_options(m);
637     compat_props_add(m->compat_props, hw_compat_6_0, hw_compat_6_0_len);
638     compat_props_add(m->compat_props, pc_compat_6_0, pc_compat_6_0_len);
639 }
640 
641 DEFINE_I440FX_MACHINE(6, 0);
642 
643 static void pc_i440fx_machine_5_2_options(MachineClass *m)
644 {
645     pc_i440fx_machine_6_0_options(m);
646     compat_props_add(m->compat_props, hw_compat_5_2, hw_compat_5_2_len);
647     compat_props_add(m->compat_props, pc_compat_5_2, pc_compat_5_2_len);
648 }
649 
650 DEFINE_I440FX_MACHINE(5, 2);
651 
652 static void pc_i440fx_machine_5_1_options(MachineClass *m)
653 {
654     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
655 
656     pc_i440fx_machine_5_2_options(m);
657     compat_props_add(m->compat_props, hw_compat_5_1, hw_compat_5_1_len);
658     compat_props_add(m->compat_props, pc_compat_5_1, pc_compat_5_1_len);
659     pcmc->kvmclock_create_always = false;
660     pcmc->pci_root_uid = 1;
661 }
662 
663 DEFINE_I440FX_MACHINE(5, 1);
664 
665 static void pc_i440fx_machine_5_0_options(MachineClass *m)
666 {
667     pc_i440fx_machine_5_1_options(m);
668     m->numa_mem_supported = true;
669     compat_props_add(m->compat_props, hw_compat_5_0, hw_compat_5_0_len);
670     compat_props_add(m->compat_props, pc_compat_5_0, pc_compat_5_0_len);
671     m->auto_enable_numa_with_memdev = false;
672 }
673 
674 DEFINE_I440FX_MACHINE(5, 0);
675 
676 static void pc_i440fx_machine_4_2_options(MachineClass *m)
677 {
678     pc_i440fx_machine_5_0_options(m);
679     compat_props_add(m->compat_props, hw_compat_4_2, hw_compat_4_2_len);
680     compat_props_add(m->compat_props, pc_compat_4_2, pc_compat_4_2_len);
681 }
682 
683 DEFINE_I440FX_MACHINE(4, 2);
684 
685 static void pc_i440fx_machine_4_1_options(MachineClass *m)
686 {
687     pc_i440fx_machine_4_2_options(m);
688     compat_props_add(m->compat_props, hw_compat_4_1, hw_compat_4_1_len);
689     compat_props_add(m->compat_props, pc_compat_4_1, pc_compat_4_1_len);
690 }
691 
692 DEFINE_I440FX_MACHINE(4, 1);
693 
694 static void pc_i440fx_machine_4_0_options(MachineClass *m)
695 {
696     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
697     pc_i440fx_machine_4_1_options(m);
698     pcmc->default_cpu_version = CPU_VERSION_LEGACY;
699     compat_props_add(m->compat_props, hw_compat_4_0, hw_compat_4_0_len);
700     compat_props_add(m->compat_props, pc_compat_4_0, pc_compat_4_0_len);
701 }
702 
703 DEFINE_I440FX_MACHINE(4, 0);
704 
705 static void pc_i440fx_machine_3_1_options(MachineClass *m)
706 {
707     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
708 
709     pc_i440fx_machine_4_0_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(3, 1);
717 
718 static void pc_i440fx_machine_3_0_options(MachineClass *m)
719 {
720     pc_i440fx_machine_3_1_options(m);
721     compat_props_add(m->compat_props, hw_compat_3_0, hw_compat_3_0_len);
722     compat_props_add(m->compat_props, pc_compat_3_0, pc_compat_3_0_len);
723 }
724 
725 DEFINE_I440FX_MACHINE(3, 0);
726 
727 static void pc_i440fx_machine_2_12_options(MachineClass *m)
728 {
729     pc_i440fx_machine_3_0_options(m);
730     compat_props_add(m->compat_props, hw_compat_2_12, hw_compat_2_12_len);
731     compat_props_add(m->compat_props, pc_compat_2_12, pc_compat_2_12_len);
732 }
733 
734 DEFINE_I440FX_MACHINE(2, 12);
735 
736 static void pc_i440fx_machine_2_11_options(MachineClass *m)
737 {
738     pc_i440fx_machine_2_12_options(m);
739     compat_props_add(m->compat_props, hw_compat_2_11, hw_compat_2_11_len);
740     compat_props_add(m->compat_props, pc_compat_2_11, pc_compat_2_11_len);
741 }
742 
743 DEFINE_I440FX_MACHINE(2, 11);
744 
745 static void pc_i440fx_machine_2_10_options(MachineClass *m)
746 {
747     pc_i440fx_machine_2_11_options(m);
748     compat_props_add(m->compat_props, hw_compat_2_10, hw_compat_2_10_len);
749     compat_props_add(m->compat_props, pc_compat_2_10, pc_compat_2_10_len);
750     m->auto_enable_numa_with_memhp = false;
751 }
752 
753 DEFINE_I440FX_MACHINE(2, 10);
754 
755 static void pc_i440fx_machine_2_9_options(MachineClass *m)
756 {
757     pc_i440fx_machine_2_10_options(m);
758     compat_props_add(m->compat_props, hw_compat_2_9, hw_compat_2_9_len);
759     compat_props_add(m->compat_props, pc_compat_2_9, pc_compat_2_9_len);
760 }
761 
762 DEFINE_I440FX_MACHINE(2, 9);
763 
764 static void pc_i440fx_machine_2_8_options(MachineClass *m)
765 {
766     pc_i440fx_machine_2_9_options(m);
767     compat_props_add(m->compat_props, hw_compat_2_8, hw_compat_2_8_len);
768     compat_props_add(m->compat_props, pc_compat_2_8, pc_compat_2_8_len);
769 }
770 
771 DEFINE_I440FX_MACHINE(2, 8);
772 
773 static void pc_i440fx_machine_2_7_options(MachineClass *m)
774 {
775     pc_i440fx_machine_2_8_options(m);
776     compat_props_add(m->compat_props, hw_compat_2_7, hw_compat_2_7_len);
777     compat_props_add(m->compat_props, pc_compat_2_7, pc_compat_2_7_len);
778 }
779 
780 DEFINE_I440FX_MACHINE(2, 7);
781 
782 static void pc_i440fx_machine_2_6_options(MachineClass *m)
783 {
784     X86MachineClass *x86mc = X86_MACHINE_CLASS(m);
785     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
786 
787     pc_i440fx_machine_2_7_options(m);
788     pcmc->legacy_cpu_hotplug = true;
789     x86mc->fwcfg_dma_enabled = false;
790     compat_props_add(m->compat_props, hw_compat_2_6, hw_compat_2_6_len);
791     compat_props_add(m->compat_props, pc_compat_2_6, pc_compat_2_6_len);
792 }
793 
794 DEFINE_I440FX_MACHINE(2, 6);
795 
796 #ifdef CONFIG_ISAPC
797 static void isapc_machine_options(MachineClass *m)
798 {
799     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
800     m->desc = "ISA-only PC";
801     m->max_cpus = 1;
802     m->option_rom_has_mr = true;
803     m->rom_file_has_mr = false;
804     pcmc->pci_enabled = false;
805     pcmc->has_acpi_build = false;
806     pcmc->smbios_defaults = false;
807     pcmc->gigabyte_align = false;
808     pcmc->smbios_legacy_mode = true;
809     pcmc->has_reserved_memory = false;
810     m->default_nic = "ne2k_isa";
811     m->default_cpu_type = X86_CPU_TYPE_NAME("486");
812     m->no_floppy = !module_object_class_by_name(TYPE_ISA_FDC);
813     m->no_parallel = !module_object_class_by_name(TYPE_ISA_PARALLEL);
814 }
815 
816 DEFINE_PC_MACHINE(isapc, "isapc", pc_init_isa,
817                   isapc_machine_options);
818 #endif
819 
820 #ifdef CONFIG_XEN
821 static void xenfv_machine_4_2_options(MachineClass *m)
822 {
823     pc_i440fx_machine_4_2_options(m);
824     m->desc = "Xen Fully-virtualized PC";
825     m->max_cpus = HVM_MAX_VCPUS;
826     m->default_machine_opts = "accel=xen,suppress-vmdesc=on";
827 }
828 
829 DEFINE_PC_MACHINE(xenfv_4_2, "xenfv-4.2", pc_xen_hvm_init,
830                   xenfv_machine_4_2_options);
831 
832 static void xenfv_machine_3_1_options(MachineClass *m)
833 {
834     pc_i440fx_machine_3_1_options(m);
835     m->desc = "Xen Fully-virtualized PC";
836     m->alias = "xenfv";
837     m->max_cpus = HVM_MAX_VCPUS;
838     m->default_machine_opts = "accel=xen,suppress-vmdesc=on";
839 }
840 
841 DEFINE_PC_MACHINE(xenfv, "xenfv-3.1", pc_xen_hvm_init,
842                   xenfv_machine_3_1_options);
843 #endif
844