ddf19c
From 136eae41007e2e5b0d693cc656f3ec36cbabf16f Mon Sep 17 00:00:00 2001
ddf19c
From: Miroslav Rezanina <mrezanin@redhat.com>
ddf19c
Date: Fri, 19 Oct 2018 13:27:13 +0200
ddf19c
Subject: Add ppc64 machine types
ddf19c
ddf19c
Adding changes to add RHEL machine types for ppc64 architecture.
ddf19c
ddf19c
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ddf19c
ddf19c
Rebase changes (4.0.0):
ddf19c
- remove instance options and use upstream solution
ddf19c
- Use upstream compat handling
ddf19c
- Replace SPAPR_PCI_2_7_MMIO_WIN_SIZE with value (changed upstream)
ddf19c
- re-add handling of instance_options (removed upstream)
ddf19c
- Use p8 as default for rhel machine types (p9 default upstream)
ddf19c
- sPAPRMachineClass renamed to SpaprMachineClass (upstream)
ddf19c
ddf19c
Rebase changes (4.1.0):
ddf19c
- Update format for compat structures
ddf19c
ddf19c
Merged patches (4.0.0):
ddf19c
- 467d59a redhat: define pseries-rhel8.0.0 machine type
ddf19c
ddf19c
Merged patches (4.1.0):
ddf19c
- f21757edc target/ppc/spapr: Enable mitigations by default for pseries-4.0 machine type
ddf19c
- 2511c63 redhat: sync pseries-rhel7.6.0 with rhel-av-8.0.1
ddf19c
- 89f01da redhat: define pseries-rhel8.1.0 machine type
ddf19c
ddf19c
Merged patches (4.2.0):
ddf19c
- bcba728 redhat: update pseries-rhel8.1.0 machine type
ddf19c
- redhat: update pseries-rhel-7.6.0 machine type (patch 93039)
ddf19c
- redhat: define pseries-rhel8.2.0 machine type (patch 93041)
ddf19c
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 hw/ppc/spapr.c          | 278 ++++++++++++++++++++++++++++++++++++++++
ddf19c
 hw/ppc/spapr_cpu_core.c |  13 ++
ddf19c
 include/hw/ppc/spapr.h  |   1 +
ddf19c
 target/ppc/compat.c     |  13 +-
ddf19c
 target/ppc/cpu.h        |   1 +
ddf19c
 5 files changed, 305 insertions(+), 1 deletion(-)
ddf19c
ddf19c
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
ddf19c
index e076f6023c..8749c72066 100644
ddf19c
--- a/hw/ppc/spapr.c
ddf19c
+++ b/hw/ppc/spapr.c
ddf19c
@@ -4447,6 +4447,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
ddf19c
     smc->linux_pci_probe = true;
ddf19c
     smc->smp_threads_vsmt = true;
ddf19c
     smc->nr_xirqs = SPAPR_NR_XIRQS;
ddf19c
+    smc->has_power9_support = true;
ddf19c
 }
ddf19c
 
ddf19c
 static const TypeInfo spapr_machine_info = {
ddf19c
@@ -4491,6 +4492,7 @@ static const TypeInfo spapr_machine_info = {
ddf19c
     }                                                                \
ddf19c
     type_init(spapr_machine_register_##suffix)
ddf19c
 
ddf19c
+#if 0 /* Disabled for Red Hat Enterprise Linux */
ddf19c
 /*
ddf19c
  * pseries-4.2
ddf19c
  */
ddf19c
@@ -4520,6 +4522,7 @@ static void spapr_machine_4_1_class_options(MachineClass *mc)
ddf19c
 }
ddf19c
 
ddf19c
 DEFINE_SPAPR_MACHINE(4_1, "4.1", false);
ddf19c
+#endif
ddf19c
 
ddf19c
 /*
ddf19c
  * pseries-4.0
ddf19c
@@ -4536,6 +4539,7 @@ static void phb_placement_4_0(SpaprMachineState *spapr, uint32_t index,
ddf19c
     *nv2atsd = 0;
ddf19c
 }
ddf19c
 
ddf19c
+#if 0 /* Disabled for Red Hat Enterprise Linux */
ddf19c
 static void spapr_machine_4_0_class_options(MachineClass *mc)
ddf19c
 {
ddf19c
     SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
@@ -4695,6 +4699,7 @@ DEFINE_SPAPR_MACHINE(2_8, "2.8", false);
ddf19c
 /*
ddf19c
  * pseries-2.7
ddf19c
  */
ddf19c
+#endif
ddf19c
 
ddf19c
 static void phb_placement_2_7(SpaprMachineState *spapr, uint32_t index,
ddf19c
                               uint64_t *buid, hwaddr *pio,
ddf19c
@@ -4749,6 +4754,7 @@ static void phb_placement_2_7(SpaprMachineState *spapr, uint32_t index,
ddf19c
     *nv2atsd = 0;
ddf19c
 }
ddf19c
 
ddf19c
+#if 0 /* Disabled for Red Hat Enterprise Linux */
ddf19c
 static void spapr_machine_2_7_class_options(MachineClass *mc)
ddf19c
 {
ddf19c
     SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
@@ -4863,6 +4869,278 @@ static void spapr_machine_2_1_class_options(MachineClass *mc)
ddf19c
     compat_props_add(mc->compat_props, hw_compat_2_1, hw_compat_2_1_len);
ddf19c
 }
ddf19c
 DEFINE_SPAPR_MACHINE(2_1, "2.1", false);
ddf19c
+#endif
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel8.2.0
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel820_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    /* Defaults for the latest behaviour inherited from the base class */
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel820, "rhel8.2.0", true);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel8.1.0
ddf19c
+ * like pseries-4.1
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel810_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+    static GlobalProperty compat[] = {
ddf19c
+        /* Only allow 4kiB and 64kiB IOMMU pagesizes */
ddf19c
+        { TYPE_SPAPR_PCI_HOST_BRIDGE, "pgsz", "0x11000" },
ddf19c
+    };
ddf19c
+
ddf19c
+    spapr_machine_rhel820_class_options(mc);
ddf19c
+
ddf19c
+    /* from pseries-4.1 */
ddf19c
+    smc->linux_pci_probe = false;
ddf19c
+    smc->smp_threads_vsmt = false;
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_1,
ddf19c
+                     hw_compat_rhel_8_1_len);
ddf19c
+    compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
ddf19c
+
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel810, "rhel8.1.0", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel8.0.0
ddf19c
+ * like pseries-3.1 and pseries-4.0
ddf19c
+ * except SPAPR_CAP_CFPC, SPAPR_CAP_SBBC and SPAPR_CAP_IBS
ddf19c
+ * that have been backported to pseries-rhel8.0.0
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel800_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel810_class_options(mc);
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_0,
ddf19c
+                     hw_compat_rhel_8_0_len);
ddf19c
+
ddf19c
+    /* pseries-4.0 */
ddf19c
+    smc->phb_placement = phb_placement_4_0;
ddf19c
+    smc->irq = &spapr_irq_xics;
ddf19c
+    smc->pre_4_1_migration = true;
ddf19c
+
ddf19c
+    /* pseries-3.1 */
ddf19c
+    mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power8_v2.0");
ddf19c
+    smc->update_dt_enabled = false;
ddf19c
+    smc->dr_phb_enabled = false;
ddf19c
+    smc->broken_host_serial_model = true;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER] = SPAPR_CAP_OFF;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel800, "rhel8.0.0", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.6.0
ddf19c
+ * like spapr_compat_2_12 and spapr_compat_3_0
ddf19c
+ * spapr_compat_0 is empty
ddf19c
+ */
ddf19c
+GlobalProperty spapr_compat_rhel7_6[] = {
ddf19c
+    { TYPE_POWERPC_CPU, "pre-3.0-migration", "on" },
ddf19c
+    { TYPE_SPAPR_CPU_CORE, "pre-3.0-migration", "on" },
ddf19c
+};
ddf19c
+const size_t spapr_compat_rhel7_6_len = G_N_ELEMENTS(spapr_compat_rhel7_6);
ddf19c
+
ddf19c
+
ddf19c
+static void spapr_machine_rhel760_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel800_class_options(mc);
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_7_6, hw_compat_rhel_7_6_len);
ddf19c
+    compat_props_add(mc->compat_props, spapr_compat_rhel7_6, spapr_compat_rhel7_6_len);
ddf19c
+
ddf19c
+    /* from spapr_machine_3_0_class_options() */
ddf19c
+    smc->legacy_irq_allocation = true;
ddf19c
+    smc->nr_xirqs = 0x400;
ddf19c
+    smc->irq = &spapr_irq_xics_legacy;
ddf19c
+
ddf19c
+    /* from spapr_machine_2_12_class_options() */
ddf19c
+    /* We depend on kvm_enabled() to choose a default value for the
ddf19c
+     * hpt-max-page-size capability. Of course we can't do it here
ddf19c
+     * because this is too early and the HW accelerator isn't initialzed
ddf19c
+     * yet. Postpone this to machine init (see default_caps_with_cpu()).
ddf19c
+     */
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_HPT_MAXPAGESIZE] = 0;
ddf19c
+
ddf19c
+    /* SPAPR_CAP_WORKAROUND enabled in pseries-rhel800 by
ddf19c
+     * f21757edc554
ddf19c
+     * "Enable mitigations by default for pseries-4.0 machine type")
ddf19c
+     */
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_CFPC] = SPAPR_CAP_BROKEN;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_SBBC] = SPAPR_CAP_BROKEN;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_BROKEN;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel760, "rhel7.6.0", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.6.0-sxxm
ddf19c
+ *
ddf19c
+ * pseries-rhel7.6.0 with speculative execution exploit mitigations enabled by default
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel760sxxm_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel760_class_options(mc);
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_CFPC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_SBBC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_FIXED_CCD;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel760sxxm, "rhel7.6.0-sxxm", false);
ddf19c
+
ddf19c
+static void spapr_machine_rhel750_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    spapr_machine_rhel760_class_options(mc);
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_7_5, hw_compat_rhel_7_5_len);
ddf19c
+
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel750, "rhel7.5.0", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.5.0-sxxm
ddf19c
+ *
ddf19c
+ * pseries-rhel7.5.0 with speculative execution exploit mitigations enabled by default
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel750sxxm_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel750_class_options(mc);
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_CFPC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_SBBC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_FIXED_CCD;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel750sxxm, "rhel7.5.0-sxxm", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.4.0
ddf19c
+ * like spapr_compat_2_9
ddf19c
+ */
ddf19c
+GlobalProperty spapr_compat_rhel7_4[] = {
ddf19c
+    { TYPE_POWERPC_CPU, "pre-2.10-migration", "on" },
ddf19c
+};
ddf19c
+const size_t spapr_compat_rhel7_4_len = G_N_ELEMENTS(spapr_compat_rhel7_4);
ddf19c
+
ddf19c
+static void spapr_machine_rhel740_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel750_class_options(mc);
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_7_4, hw_compat_rhel_7_4_len);
ddf19c
+    compat_props_add(mc->compat_props, spapr_compat_rhel7_4, spapr_compat_rhel7_4_len);
ddf19c
+    mc->numa_auto_assign_ram = numa_legacy_auto_assign_ram;
ddf19c
+    smc->has_power9_support = false;
ddf19c
+    smc->pre_2_10_has_unused_icps = true;
ddf19c
+    smc->resize_hpt_default = SPAPR_RESIZE_HPT_DISABLED;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_HTM] = SPAPR_CAP_ON;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel740, "rhel7.4.0", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.4.0-sxxm
ddf19c
+ *
ddf19c
+ * pseries-rhel7.4.0 with speculative execution exploit mitigations enabled by default
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel740sxxm_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel740_class_options(mc);
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_CFPC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_SBBC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_FIXED_CCD;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel740sxxm, "rhel7.4.0-sxxm", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.3.0
ddf19c
+ * like spapr_compat_2_6/_2_7/_2_8 but "ddw" has been backported to RHEL7_3
ddf19c
+ */
ddf19c
+GlobalProperty spapr_compat_rhel7_3[] = {
ddf19c
+    { TYPE_SPAPR_PCI_HOST_BRIDGE, "mem_win_size", "0xf80000000" },
ddf19c
+    { TYPE_SPAPR_PCI_HOST_BRIDGE, "mem64_win_size", "0" },
ddf19c
+    { TYPE_POWERPC_CPU, "pre-2.8-migration", "on" },
ddf19c
+    { TYPE_SPAPR_PCI_HOST_BRIDGE, "pre-2.8-migration", "on" },
ddf19c
+    { TYPE_SPAPR_PCI_HOST_BRIDGE, "pcie-extended-configuration-space", "off" },
ddf19c
+};
ddf19c
+const size_t spapr_compat_rhel7_3_len = G_N_ELEMENTS(spapr_compat_rhel7_3);
ddf19c
+
ddf19c
+static void spapr_machine_rhel730_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel740_class_options(mc);
ddf19c
+    mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power7_v2.3");
ddf19c
+    mc->default_machine_opts = "modern-hotplug-events=off";
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_7_3, hw_compat_rhel_7_3_len);
ddf19c
+    compat_props_add(mc->compat_props, spapr_compat_rhel7_3, spapr_compat_rhel7_3_len);
ddf19c
+
ddf19c
+    smc->phb_placement = phb_placement_2_7;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel730, "rhel7.3.0", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.3.0-sxxm
ddf19c
+ *
ddf19c
+ * pseries-rhel7.3.0 with speculative execution exploit mitigations enabled by default
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel730sxxm_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel730_class_options(mc);
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_CFPC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_SBBC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_FIXED_CCD;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel730sxxm, "rhel7.3.0-sxxm", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.2.0
ddf19c
+ */
ddf19c
+/* Should be like spapr_compat_2_5 + 2_4 + 2_3, but "dynamic-reconfiguration"
ddf19c
+ * has been backported to RHEL7_2 so we don't need it here.
ddf19c
+ */
ddf19c
+
ddf19c
+GlobalProperty spapr_compat_rhel7_2[] = {
ddf19c
+    { "spapr-vlan", "use-rx-buffer-pools", "off" },
ddf19c
+    { TYPE_SPAPR_PCI_HOST_BRIDGE, "ddw", "off" },
ddf19c
+};
ddf19c
+const size_t spapr_compat_rhel7_2_len = G_N_ELEMENTS(spapr_compat_rhel7_2);
ddf19c
+
ddf19c
+static void spapr_machine_rhel720_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel730_class_options(mc);
ddf19c
+    smc->use_ohci_by_default = true;
ddf19c
+    mc->has_hotpluggable_cpus = NULL;
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_7_2, hw_compat_rhel_7_2_len);
ddf19c
+    compat_props_add(mc->compat_props, spapr_compat_rhel7_2, spapr_compat_rhel7_2_len);
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel720, "rhel7.2.0", false);
ddf19c
 
ddf19c
 static void spapr_machine_register_types(void)
ddf19c
 {
ddf19c
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
ddf19c
index 301cd7b4e4..ba5a8fb82b 100644
ddf19c
--- a/hw/ppc/spapr_cpu_core.c
ddf19c
+++ b/hw/ppc/spapr_cpu_core.c
ddf19c
@@ -24,6 +24,7 @@
ddf19c
 #include "sysemu/reset.h"
ddf19c
 #include "sysemu/hw_accel.h"
ddf19c
 #include "qemu/error-report.h"
ddf19c
+#include "cpu-models.h"
ddf19c
 
ddf19c
 static void spapr_reset_vcpu(PowerPCCPU *cpu)
ddf19c
 {
ddf19c
@@ -242,6 +243,7 @@ static void spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
ddf19c
     CPUPPCState *env = &cpu->env;
ddf19c
     CPUState *cs = CPU(cpu);
ddf19c
     Error *local_err = NULL;
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr);
ddf19c
 
ddf19c
     object_property_set_bool(OBJECT(cpu), true, "realized", &local_err);
ddf19c
     if (local_err) {
ddf19c
@@ -254,6 +256,17 @@ static void spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
ddf19c
     cpu_ppc_set_vhyp(cpu, PPC_VIRTUAL_HYPERVISOR(spapr));
ddf19c
     kvmppc_set_papr(cpu);
ddf19c
 
ddf19c
+    if (!smc->has_power9_support &&
ddf19c
+        (((spapr->max_compat_pvr &&
ddf19c
+           ppc_compat_cmp(spapr->max_compat_pvr,
ddf19c
+                          CPU_POWERPC_LOGICAL_3_00) >= 0)) ||
ddf19c
+          (!spapr->max_compat_pvr &&
ddf19c
+           ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_3_00, 0, 0)))) {
ddf19c
+        error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
ddf19c
+                  "POWER9 CPU is not supported by this machine class");
ddf19c
+        return;
ddf19c
+    }
ddf19c
+
ddf19c
     if (spapr_irq_cpu_intc_create(spapr, cpu, &local_err) < 0) {
ddf19c
         goto error_intc_create;
ddf19c
     }
ddf19c
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
ddf19c
index d5ab5ea7b2..aa89cc4a95 100644
ddf19c
--- a/include/hw/ppc/spapr.h
ddf19c
+++ b/include/hw/ppc/spapr.h
ddf19c
@@ -125,6 +125,7 @@ struct SpaprMachineClass {
ddf19c
     bool linux_pci_probe;
ddf19c
     bool smp_threads_vsmt; /* set VSMT to smp_threads by default */
ddf19c
 
ddf19c
+    bool has_power9_support;
ddf19c
     void (*phb_placement)(SpaprMachineState *spapr, uint32_t index,
ddf19c
                           uint64_t *buid, hwaddr *pio, 
ddf19c
                           hwaddr *mmio32, hwaddr *mmio64,
ddf19c
diff --git a/target/ppc/compat.c b/target/ppc/compat.c
ddf19c
index 7de4bf3122..3e2e35342d 100644
ddf19c
--- a/target/ppc/compat.c
ddf19c
+++ b/target/ppc/compat.c
ddf19c
@@ -105,8 +105,19 @@ static const CompatInfo *compat_by_pvr(uint32_t pvr)
ddf19c
     return NULL;
ddf19c
 }
ddf19c
 
ddf19c
+long ppc_compat_cmp(uint32_t pvr1, uint32_t pvr2)
ddf19c
+{
ddf19c
+    const CompatInfo *compat1 = compat_by_pvr(pvr1);
ddf19c
+    const CompatInfo *compat2 = compat_by_pvr(pvr2);
ddf19c
+
ddf19c
+    g_assert(compat1);
ddf19c
+    g_assert(compat2);
ddf19c
+
ddf19c
+    return compat1 - compat2;
ddf19c
+}
ddf19c
+
ddf19c
 static bool pcc_compat(PowerPCCPUClass *pcc, uint32_t compat_pvr,
ddf19c
-                       uint32_t min_compat_pvr, uint32_t max_compat_pvr)
ddf19c
+                      uint32_t min_compat_pvr, uint32_t max_compat_pvr)
ddf19c
 {
ddf19c
     const CompatInfo *compat = compat_by_pvr(compat_pvr);
ddf19c
     const CompatInfo *min = compat_by_pvr(min_compat_pvr);
ddf19c
diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
ddf19c
index e3e82327b7..5c53801cfd 100644
ddf19c
--- a/target/ppc/cpu.h
ddf19c
+++ b/target/ppc/cpu.h
ddf19c
@@ -1367,6 +1367,7 @@ static inline int cpu_mmu_index(CPUPPCState *env, bool ifetch)
ddf19c
 
ddf19c
 /* Compatibility modes */
ddf19c
 #if defined(TARGET_PPC64)
ddf19c
+long ppc_compat_cmp(uint32_t pvr1, uint32_t pvr2);
ddf19c
 bool ppc_check_compat(PowerPCCPU *cpu, uint32_t compat_pvr,
ddf19c
                       uint32_t min_compat_pvr, uint32_t max_compat_pvr);
ddf19c
 bool ppc_type_check_compat(const char *cputype, uint32_t compat_pvr,
ddf19c
-- 
ddf19c
2.21.0
ddf19c