a83cc2
From ee8aeb6b79bde21b581090c479faf10e716a7e6d Mon Sep 17 00:00:00 2001
a83cc2
From: Miroslav Rezanina <mrezanin@redhat.com>
a83cc2
Date: Fri, 19 Oct 2018 12:53:31 +0200
a83cc2
Subject: Add aarch64 machine types
a83cc2
a83cc2
Adding changes to add RHEL machine types for aarch64 architecture.
a83cc2
a83cc2
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
a83cc2
---
a83cc2
 hw/arm/virt.c         | 211 +++++++++++++++++++++++++++++++++++++++++-
a83cc2
 include/hw/arm/virt.h |   8 ++
a83cc2
 2 files changed, 218 insertions(+), 1 deletion(-)
a83cc2
a83cc2
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
a83cc2
index f904d3e98e..080cf54ef1 100644
a83cc2
--- a/hw/arm/virt.c
a83cc2
+++ b/hw/arm/virt.c
a83cc2
@@ -80,6 +80,7 @@
a83cc2
 #include "hw/char/pl011.h"
a83cc2
 #include "qemu/guest-random.h"
a83cc2
 
a83cc2
+#if 0 /* Disabled for Red Hat Enterprise Linux */
a83cc2
 #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \
a83cc2
     static void virt_##major##_##minor##_class_init(ObjectClass *oc, \
a83cc2
                                                     void *data) \
a83cc2
@@ -106,7 +107,48 @@
a83cc2
     DEFINE_VIRT_MACHINE_LATEST(major, minor, true)
a83cc2
 #define DEFINE_VIRT_MACHINE(major, minor) \
a83cc2
     DEFINE_VIRT_MACHINE_LATEST(major, minor, false)
a83cc2
-
a83cc2
+#endif /* disabled for RHEL */
a83cc2
+
a83cc2
+#define DEFINE_RHEL_MACHINE_LATEST(m, n, s, latest)                     \
a83cc2
+    static void rhel##m##n##s##_virt_class_init(ObjectClass *oc,        \
a83cc2
+                                                void *data)             \
a83cc2
+    {                                                                   \
a83cc2
+        MachineClass *mc = MACHINE_CLASS(oc);                           \
a83cc2
+        rhel##m##n##s##_virt_options(mc);                               \
a83cc2
+        mc->desc = "RHEL " # m "." # n "." # s " ARM Virtual Machine";  \
a83cc2
+        if (latest) {                                                   \
a83cc2
+            mc->alias = "virt";                                         \
a83cc2
+            mc->is_default = 1;                                         \
a83cc2
+        }                                                               \
a83cc2
+    }                                                                   \
a83cc2
+    static const TypeInfo rhel##m##n##s##_machvirt_info = {             \
a83cc2
+        .name = MACHINE_TYPE_NAME("virt-rhel" # m "." # n "." # s),     \
a83cc2
+        .parent = TYPE_RHEL_MACHINE,                                    \
a83cc2
+        .class_init = rhel##m##n##s##_virt_class_init,                  \
a83cc2
+    };                                                                  \
a83cc2
+    static void rhel##m##n##s##_machvirt_init(void)                     \
a83cc2
+    {                                                                   \
a83cc2
+        type_register_static(&rhel##m##n##s##_machvirt_info);           \
a83cc2
+    }                                                                   \
a83cc2
+    type_init(rhel##m##n##s##_machvirt_init);
a83cc2
+
a83cc2
+#define DEFINE_RHEL_MACHINE_AS_LATEST(major, minor, subminor)   \
a83cc2
+    DEFINE_RHEL_MACHINE_LATEST(major, minor, subminor, true)
a83cc2
+#define DEFINE_RHEL_MACHINE(major, minor, subminor)             \
a83cc2
+    DEFINE_RHEL_MACHINE_LATEST(major, minor, subminor, false)
a83cc2
+
a83cc2
+/* This variable is for changes to properties that are RHEL specific,
a83cc2
+ * different to the current upstream and to be applied to the latest
a83cc2
+ * machine type.
a83cc2
+ */
a83cc2
+GlobalProperty arm_rhel_compat[] = {
a83cc2
+    {
a83cc2
+        .driver   = "virtio-net-pci",
a83cc2
+        .property = "romfile",
a83cc2
+        .value    = "",
a83cc2
+    },
a83cc2
+};
a83cc2
+const size_t arm_rhel_compat_len = G_N_ELEMENTS(arm_rhel_compat);
a83cc2
 
a83cc2
 /* Number of external interrupt lines to configure the GIC with */
a83cc2
 #define NUM_IRQS 256
a83cc2
@@ -2113,6 +2155,7 @@ static void machvirt_init(MachineState *machine)
a83cc2
     qemu_add_machine_init_done_notifier(&vms->machine_done);
a83cc2
 }
a83cc2
 
a83cc2
+#if 0 /* Disabled for Red Hat Enterprise Linux */
a83cc2
 static bool virt_get_secure(Object *obj, Error **errp)
a83cc2
 {
a83cc2
     VirtMachineState *vms = VIRT_MACHINE(obj);
a83cc2
@@ -2140,6 +2183,7 @@ static void virt_set_virt(Object *obj, bool value, Error **errp)
a83cc2
 
a83cc2
     vms->virt = value;
a83cc2
 }
a83cc2
+#endif /* disabled for RHEL */
a83cc2
 
a83cc2
 static bool virt_get_highmem(Object *obj, Error **errp)
a83cc2
 {
a83cc2
@@ -2237,6 +2281,7 @@ static void virt_set_acpi(Object *obj, Visitor *v, const char *name,
a83cc2
     visit_type_OnOffAuto(v, name, &vms->acpi, errp);
a83cc2
 }
a83cc2
 
a83cc2
+#if 0 /* Disabled for Red Hat Enterprise Linux */
a83cc2
 static bool virt_get_ras(Object *obj, Error **errp)
a83cc2
 {
a83cc2
     VirtMachineState *vms = VIRT_MACHINE(obj);
a83cc2
@@ -2264,6 +2309,7 @@ static void virt_set_mte(Object *obj, bool value, Error **errp)
a83cc2
 
a83cc2
     vms->mte = value;
a83cc2
 }
a83cc2
+#endif /* disabled for RHEL */
a83cc2
 
a83cc2
 static char *virt_get_gic_version(Object *obj, Error **errp)
a83cc2
 {
a83cc2
@@ -2584,6 +2630,7 @@ static int virt_kvm_type(MachineState *ms, const char *type_str)
a83cc2
     return fixed_ipa ? 0 : requested_pa_size;
a83cc2
 }
a83cc2
 
a83cc2
+#if 0 /* Disabled for Red Hat Enterprise Linux */
a83cc2
 static void virt_machine_class_init(ObjectClass *oc, void *data)
a83cc2
 {
a83cc2
     MachineClass *mc = MACHINE_CLASS(oc);
a83cc2
@@ -2910,3 +2957,165 @@ static void virt_machine_2_6_options(MachineClass *mc)
a83cc2
     vmc->no_pmu = true;
a83cc2
 }
a83cc2
 DEFINE_VIRT_MACHINE(2, 6)
a83cc2
+#endif /* disabled for RHEL */
a83cc2
+
a83cc2
+static void rhel_machine_class_init(ObjectClass *oc, void *data)
a83cc2
+{
a83cc2
+    MachineClass *mc = MACHINE_CLASS(oc);
a83cc2
+    HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
a83cc2
+
a83cc2
+    mc->family = "virt-rhel-Z";
a83cc2
+    mc->init = machvirt_init;
a83cc2
+    /* Maximum supported VCPU count for all virt-rhel* machines */
a83cc2
+    mc->max_cpus = 384;
a83cc2
+    machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS);
a83cc2
+    mc->block_default_type = IF_VIRTIO;
a83cc2
+    mc->no_cdrom = 1;
a83cc2
+    mc->pci_allow_0_address = true;
a83cc2
+    /* We know we will never create a pre-ARMv7 CPU which needs 1K pages */
a83cc2
+    mc->minimum_page_bits = 12;
a83cc2
+    mc->possible_cpu_arch_ids = virt_possible_cpu_arch_ids;
a83cc2
+    mc->cpu_index_to_instance_props = virt_cpu_index_to_props;
a83cc2
+    mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a57");
a83cc2
+    mc->get_default_cpu_node_id = virt_get_default_cpu_node_id;
a83cc2
+    mc->kvm_type = virt_kvm_type;
a83cc2
+    assert(!mc->get_hotplug_handler);
a83cc2
+    mc->get_hotplug_handler = virt_machine_get_hotplug_handler;
a83cc2
+    hc->pre_plug = virt_machine_device_pre_plug_cb;
a83cc2
+    hc->plug = virt_machine_device_plug_cb;
a83cc2
+    hc->unplug_request = virt_machine_device_unplug_request_cb;
a83cc2
+    hc->unplug = virt_machine_device_unplug_cb;
a83cc2
+    mc->nvdimm_supported = true;
a83cc2
+    mc->auto_enable_numa_with_memhp = true;
a83cc2
+    mc->auto_enable_numa_with_memdev = true;
a83cc2
+    mc->default_ram_id = "mach-virt.ram";
a83cc2
+
a83cc2
+    object_class_property_add(oc, "acpi", "OnOffAuto",
a83cc2
+        virt_get_acpi, virt_set_acpi,
a83cc2
+        NULL, NULL);
a83cc2
+    object_class_property_set_description(oc, "acpi",
a83cc2
+        "Enable ACPI");
a83cc2
+
a83cc2
+    object_class_property_add_str(oc, "x-oem-id",
a83cc2
+                                  virt_get_oem_id,
a83cc2
+                                  virt_set_oem_id);
a83cc2
+    object_class_property_set_description(oc, "x-oem-id",
a83cc2
+                                          "Override the default value of field OEMID "
a83cc2
+                                          "in ACPI table header."
a83cc2
+                                          "The string may be up to 6 bytes in size");
a83cc2
+
a83cc2
+
a83cc2
+    object_class_property_add_str(oc, "x-oem-table-id",
a83cc2
+                                  virt_get_oem_table_id,
a83cc2
+                                  virt_set_oem_table_id);
a83cc2
+    object_class_property_set_description(oc, "x-oem-table-id",
a83cc2
+                                          "Override the default value of field OEM Table ID "
a83cc2
+                                          "in ACPI table header."
a83cc2
+                                          "The string may be up to 8 bytes in size");
a83cc2
+}
a83cc2
+
a83cc2
+static void rhel_virt_instance_init(Object *obj)
a83cc2
+{
a83cc2
+    VirtMachineState *vms = VIRT_MACHINE(obj);
a83cc2
+    VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
a83cc2
+
a83cc2
+    /* EL3 is disabled by default and non-configurable for RHEL */
a83cc2
+    vms->secure = false;
a83cc2
+
a83cc2
+    /* EL2 is disabled by default and non-configurable for RHEL */
a83cc2
+    vms->virt = false;
a83cc2
+
a83cc2
+    /* High memory is enabled by default */
a83cc2
+    vms->highmem = true;
a83cc2
+    object_property_add_bool(obj, "highmem", virt_get_highmem,
a83cc2
+                             virt_set_highmem);
a83cc2
+    object_property_set_description(obj, "highmem",
a83cc2
+                                    "Set on/off to enable/disable using "
a83cc2
+                                    "physical address space above 32 bits");
a83cc2
+    vms->gic_version = VIRT_GIC_VERSION_NOSEL;
a83cc2
+    object_property_add_str(obj, "gic-version", virt_get_gic_version,
a83cc2
+                        virt_set_gic_version);
a83cc2
+    object_property_set_description(obj, "gic-version",
a83cc2
+                                    "Set GIC version. "
a83cc2
+                                    "Valid values are 2, 3, host and max");
a83cc2
+
a83cc2
+    vms->highmem_ecam = !vmc->no_highmem_ecam;
a83cc2
+
a83cc2
+    if (vmc->no_its) {
a83cc2
+        vms->its = false;
a83cc2
+    } else {
a83cc2
+        /* Default allows ITS instantiation */
a83cc2
+        vms->its = true;
a83cc2
+        object_property_add_bool(obj, "its", virt_get_its,
a83cc2
+                                 virt_set_its);
a83cc2
+        object_property_set_description(obj, "its",
a83cc2
+                                        "Set on/off to enable/disable "
a83cc2
+                                        "ITS instantiation");
a83cc2
+    }
a83cc2
+
a83cc2
+    /* Default disallows iommu instantiation */
a83cc2
+    vms->iommu = VIRT_IOMMU_NONE;
a83cc2
+    object_property_add_str(obj, "iommu", virt_get_iommu, virt_set_iommu);
a83cc2
+    object_property_set_description(obj, "iommu",
a83cc2
+                                    "Set the IOMMU type. "
a83cc2
+                                    "Valid values are none and smmuv3");
a83cc2
+
a83cc2
+    /* Default disallows RAS instantiation and is non-configurable for RHEL */
a83cc2
+    vms->ras = false;
a83cc2
+
a83cc2
+    /* MTE is disabled by default and non-configurable for RHEL */
a83cc2
+    vms->mte = false;
a83cc2
+
a83cc2
+    vms->irqmap = a15irqmap;
a83cc2
+
a83cc2
+    virt_flash_create(vms);
a83cc2
+    vms->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6);
a83cc2
+    vms->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8);
a83cc2
+
a83cc2
+}
a83cc2
+
a83cc2
+static const TypeInfo rhel_machine_info = {
a83cc2
+    .name          = TYPE_RHEL_MACHINE,
a83cc2
+    .parent        = TYPE_MACHINE,
a83cc2
+    .abstract      = true,
a83cc2
+    .instance_size = sizeof(VirtMachineState),
a83cc2
+    .class_size    = sizeof(VirtMachineClass),
a83cc2
+    .class_init    = rhel_machine_class_init,
a83cc2
+    .instance_init = rhel_virt_instance_init,
a83cc2
+    .interfaces = (InterfaceInfo[]) {
a83cc2
+         { TYPE_HOTPLUG_HANDLER },
a83cc2
+         { }
a83cc2
+    },
a83cc2
+};
a83cc2
+
a83cc2
+static void rhel_machine_init(void)
a83cc2
+{
a83cc2
+    type_register_static(&rhel_machine_info);
a83cc2
+}
a83cc2
+type_init(rhel_machine_init);
a83cc2
+
a83cc2
+static void rhel840_virt_options(MachineClass *mc)
a83cc2
+{
a83cc2
+    compat_props_add(mc->compat_props, arm_rhel_compat, arm_rhel_compat_len);
a83cc2
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_4, hw_compat_rhel_8_4_len);
a83cc2
+}
a83cc2
+DEFINE_RHEL_MACHINE_AS_LATEST(8, 4, 0)
a83cc2
+
a83cc2
+static void rhel830_virt_options(MachineClass *mc)
a83cc2
+{
a83cc2
+    VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc));
a83cc2
+
a83cc2
+    rhel840_virt_options(mc);
a83cc2
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_3, hw_compat_rhel_8_3_len);
a83cc2
+    vmc->no_kvm_steal_time = true;
a83cc2
+}
a83cc2
+DEFINE_RHEL_MACHINE(8, 3, 0)
a83cc2
+
a83cc2
+static void rhel820_virt_options(MachineClass *mc)
a83cc2
+{
a83cc2
+    rhel830_virt_options(mc);
a83cc2
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_2, hw_compat_rhel_8_2_len);
a83cc2
+    mc->numa_mem_supported = true;
a83cc2
+    mc->auto_enable_numa_with_memdev = false;
a83cc2
+}
a83cc2
+DEFINE_RHEL_MACHINE(8, 2, 0)
a83cc2
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
a83cc2
index 921416f918..6c34864a0a 100644
a83cc2
--- a/include/hw/arm/virt.h
a83cc2
+++ b/include/hw/arm/virt.h
a83cc2
@@ -170,9 +170,17 @@ struct VirtMachineState {
a83cc2
 
a83cc2
 #define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM)
a83cc2
 
a83cc2
+#if 0 /* disabled for Red Hat Enterprise Linux */
a83cc2
 #define TYPE_VIRT_MACHINE   MACHINE_TYPE_NAME("virt")
a83cc2
 OBJECT_DECLARE_TYPE(VirtMachineState, VirtMachineClass, VIRT_MACHINE)
a83cc2
 
a83cc2
+#else
a83cc2
+#define TYPE_RHEL_MACHINE MACHINE_TYPE_NAME("virt-rhel")
a83cc2
+typedef struct VirtMachineClass VirtMachineClass;
a83cc2
+typedef struct VirtMachineState VirtMachineState;
a83cc2
+DECLARE_OBJ_CHECKERS(VirtMachineState, VirtMachineClass, VIRT_MACHINE, TYPE_RHEL_MACHINE)
a83cc2
+#endif
a83cc2
+
a83cc2
 void virt_acpi_setup(VirtMachineState *vms);
a83cc2
 bool virt_is_acpi_enabled(VirtMachineState *vms);
a83cc2
 
a83cc2
-- 
a83cc2
2.27.0
a83cc2