b697b4
From 19d36c4519a1a560cce60b212e3afdf7eb026e45 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
---
b697b4
Rebase notes (6.1.0):
77609c
- Use CONFIG_TPM check when using TPM structures
77609c
- Add support for default_bus_bypass_iommu
77609c
- ea4c0b32d9 arm/virt: Register highmem and gic-version as class properties
77609c
- 895e1fa86a hw/arm/virt: Add 8.5 and 9.0 machine types and remove older ones
b697b4
b697b4
Merged patches (6.2.0 RC0):
b697b4
- 9a3d4fde0e hw/arm/virt: Remove 9.0 machine type
b697b4
- f7d04d6695 hw: arm: virt: Add hw_compat_rhel_8_5 to 8.5 machine type
77609c
---
b697b4
 hw/arm/virt.c         | 205 +++++++++++++++++++++++++++++++++++++++++-
a83cc2
 include/hw/arm/virt.h |   8 ++
b697b4
 2 files changed, 212 insertions(+), 1 deletion(-)
a83cc2
a83cc2
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
b697b4
index 5de4d9d73b..7d51824263 100644
a83cc2
--- a/hw/arm/virt.c
a83cc2
+++ b/hw/arm/virt.c
b697b4
@@ -79,6 +79,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) \
b697b4
@@ -105,7 +106,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
b697b4
@@ -2180,6 +2222,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);
b697b4
@@ -2207,6 +2250,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
 {
b697b4
@@ -2304,6 +2348,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);
b697b4
@@ -2331,6 +2376,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
 {
b697b4
@@ -2666,6 +2712,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);
b697b4
@@ -3031,3 +3078,159 @@ 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;
77609c
+#ifdef CONFIG_TPM
a83cc2
+    machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS);
77609c
+#endif
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
+
77609c
+    object_class_property_add_bool(oc, "highmem", virt_get_highmem,
77609c
+                                   virt_set_highmem);
77609c
+    object_class_property_set_description(oc, "highmem",
77609c
+                                          "Set on/off to enable/disable using "
77609c
+                                          "physical address space above 32 bits");
77609c
+
77609c
+    object_class_property_add_str(oc, "gic-version", virt_get_gic_version,
77609c
+                                  virt_set_gic_version);
77609c
+    object_class_property_set_description(oc, "gic-version",
77609c
+                                          "Set GIC version. "
77609c
+                                          "Valid values are 2, 3, host and max");
77609c
+
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
+    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");
77609c
+    object_class_property_add_bool(oc, "default_bus_bypass_iommu",
77609c
+                                   virt_get_default_bus_bypass_iommu,
77609c
+                                   virt_set_default_bus_bypass_iommu);
77609c
+    object_class_property_set_description(oc, "default_bus_bypass_iommu",
77609c
+                                          "Set on/off to enable/disable "
77609c
+                                          "bypass_iommu for default root bus");
77609c
+
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
+    vms->gic_version = VIRT_GIC_VERSION_NOSEL;
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
+
77609c
+    /* The default root bus is attached to iommu by default */
77609c
+    vms->default_bus_bypass_iommu = false;
77609c
+
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
+
77609c
+static void rhel850_virt_options(MachineClass *mc)
a83cc2
+{
b697b4
+    compat_props_add(mc->compat_props, arm_rhel_compat, arm_rhel_compat_len);
b697b4
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_5, hw_compat_rhel_8_5_len);
a83cc2
+}
b697b4
+DEFINE_RHEL_MACHINE_AS_LATEST(8, 5, 0)
a83cc2
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
b697b4
index dc6b66ffc8..9364628847 100644
a83cc2
--- a/include/hw/arm/virt.h
a83cc2
+++ b/include/hw/arm/virt.h
b697b4
@@ -175,9 +175,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