586cba
From 697aaa43e3c0f20fc312f06be6c1093f1ba907e1 Mon Sep 17 00:00:00 2001
495e37
From: Miroslav Rezanina <mrezanin@redhat.com>
495e37
Date: Fri, 19 Oct 2018 12:53:31 +0200
495e37
Subject: Add aarch64 machine types
495e37
495e37
Adding changes to add RHEL machine types for aarch64 architecture.
495e37
495e37
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
495e37
---
495e37
Rebase notes (6.1.0):
495e37
- Use CONFIG_TPM check when using TPM structures
495e37
- Add support for default_bus_bypass_iommu
495e37
- ea4c0b32d9 arm/virt: Register highmem and gic-version as class properties
495e37
- 895e1fa86a hw/arm/virt: Add 8.5 and 9.0 machine types and remove older ones
495e37
586cba
Rebase notes (7.0.0):
586cba
- Added dtb-kaslr-seed option
586cba
- Set no_tcg_lpa2 to true
586cba
586cba
Merged patches (6.2.0):
495e37
- 9a3d4fde0e hw/arm/virt: Remove 9.0 machine type
495e37
- f7d04d6695 hw: arm: virt: Add hw_compat_rhel_8_5 to 8.5 machine type
586cba
586cba
Merged patches (7.0.0):
586cba
- 3b82be3dd3 redhat: virt-rhel8.5.0: Update machine type compatibility for QEMU 6.2.0 update
586cba
- c354a86c9b hw/arm/virt: Register "iommu" as a class property
586cba
- c1a2630dc9 hw/arm/virt: Register "its" as a class property
586cba
- 9d8c61dc93 hw/arm/virt: Rename default_bus_bypass_iommu
586cba
- a1d1b6eeb6 hw/arm/virt: Expose the 'RAS' option
586cba
- 47f8fe1b82 hw/arm/virt: Add 9.0 machine type and remove 8.5 one
586cba
- ed2346788f hw/arm/virt: Check no_tcg_its and minor style changes
495e37
---
586cba
 hw/arm/virt.c         | 234 +++++++++++++++++++++++++++++++++++++++++-
495e37
 include/hw/arm/virt.h |   8 ++
586cba
 2 files changed, 241 insertions(+), 1 deletion(-)
495e37
495e37
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
586cba
index 6a84031fd7..e06862d22a 100644
495e37
--- a/hw/arm/virt.c
495e37
+++ b/hw/arm/virt.c
586cba
@@ -80,6 +80,7 @@
495e37
 #include "hw/char/pl011.h"
495e37
 #include "qemu/guest-random.h"
495e37
 
495e37
+#if 0 /* Disabled for Red Hat Enterprise Linux */
495e37
 #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \
495e37
     static void virt_##major##_##minor##_class_init(ObjectClass *oc, \
495e37
                                                     void *data) \
586cba
@@ -106,7 +107,48 @@
495e37
     DEFINE_VIRT_MACHINE_LATEST(major, minor, true)
495e37
 #define DEFINE_VIRT_MACHINE(major, minor) \
495e37
     DEFINE_VIRT_MACHINE_LATEST(major, minor, false)
495e37
-
495e37
+#endif /* disabled for RHEL */
495e37
+
495e37
+#define DEFINE_RHEL_MACHINE_LATEST(m, n, s, latest)                     \
495e37
+    static void rhel##m##n##s##_virt_class_init(ObjectClass *oc,        \
495e37
+                                                void *data)             \
495e37
+    {                                                                   \
495e37
+        MachineClass *mc = MACHINE_CLASS(oc);                           \
495e37
+        rhel##m##n##s##_virt_options(mc);                               \
495e37
+        mc->desc = "RHEL " # m "." # n "." # s " ARM Virtual Machine";  \
495e37
+        if (latest) {                                                   \
495e37
+            mc->alias = "virt";                                         \
495e37
+            mc->is_default = 1;                                         \
495e37
+        }                                                               \
495e37
+    }                                                                   \
495e37
+    static const TypeInfo rhel##m##n##s##_machvirt_info = {             \
495e37
+        .name = MACHINE_TYPE_NAME("virt-rhel" # m "." # n "." # s),     \
495e37
+        .parent = TYPE_RHEL_MACHINE,                                    \
495e37
+        .class_init = rhel##m##n##s##_virt_class_init,                  \
495e37
+    };                                                                  \
495e37
+    static void rhel##m##n##s##_machvirt_init(void)                     \
495e37
+    {                                                                   \
495e37
+        type_register_static(&rhel##m##n##s##_machvirt_info);           \
495e37
+    }                                                                   \
495e37
+    type_init(rhel##m##n##s##_machvirt_init);
495e37
+
495e37
+#define DEFINE_RHEL_MACHINE_AS_LATEST(major, minor, subminor)   \
495e37
+    DEFINE_RHEL_MACHINE_LATEST(major, minor, subminor, true)
495e37
+#define DEFINE_RHEL_MACHINE(major, minor, subminor)             \
495e37
+    DEFINE_RHEL_MACHINE_LATEST(major, minor, subminor, false)
495e37
+
495e37
+/* This variable is for changes to properties that are RHEL specific,
495e37
+ * different to the current upstream and to be applied to the latest
495e37
+ * machine type.
495e37
+ */
495e37
+GlobalProperty arm_rhel_compat[] = {
495e37
+    {
495e37
+        .driver   = "virtio-net-pci",
495e37
+        .property = "romfile",
495e37
+        .value    = "",
495e37
+    },
495e37
+};
495e37
+const size_t arm_rhel_compat_len = G_N_ELEMENTS(arm_rhel_compat);
495e37
 
495e37
 /* Number of external interrupt lines to configure the GIC with */
495e37
 #define NUM_IRQS 256
586cba
@@ -2250,6 +2292,7 @@ static void machvirt_init(MachineState *machine)
495e37
     qemu_add_machine_init_done_notifier(&vms->machine_done);
495e37
 }
495e37
 
495e37
+#if 0 /* Disabled for Red Hat Enterprise Linux */
495e37
 static bool virt_get_secure(Object *obj, Error **errp)
495e37
 {
495e37
     VirtMachineState *vms = VIRT_MACHINE(obj);
586cba
@@ -2277,6 +2320,7 @@ static void virt_set_virt(Object *obj, bool value, Error **errp)
495e37
 
495e37
     vms->virt = value;
495e37
 }
495e37
+#endif /* disabled for RHEL */
495e37
 
495e37
 static bool virt_get_highmem(Object *obj, Error **errp)
495e37
 {
586cba
@@ -2402,6 +2446,7 @@ static void virt_set_ras(Object *obj, bool value, Error **errp)
586cba
     vms->ras = value;
495e37
 }
495e37
 
495e37
+#if 0 /* Disabled for Red Hat Enterprise Linux */
586cba
 static bool virt_get_mte(Object *obj, Error **errp)
495e37
 {
495e37
     VirtMachineState *vms = VIRT_MACHINE(obj);
586cba
@@ -2415,6 +2460,7 @@ static void virt_set_mte(Object *obj, bool value, Error **errp)
495e37
 
495e37
     vms->mte = value;
495e37
 }
495e37
+#endif /* disabled for RHEL */
495e37
 
495e37
 static char *virt_get_gic_version(Object *obj, Error **errp)
495e37
 {
586cba
@@ -2818,6 +2864,7 @@ static int virt_kvm_type(MachineState *ms, const char *type_str)
495e37
     return fixed_ipa ? 0 : requested_pa_size;
495e37
 }
495e37
 
495e37
+#if 0 /* Disabled for Red Hat Enterprise Linux */
495e37
 static void virt_machine_class_init(ObjectClass *oc, void *data)
495e37
 {
495e37
     MachineClass *mc = MACHINE_CLASS(oc);
586cba
@@ -3206,3 +3253,188 @@ static void virt_machine_2_6_options(MachineClass *mc)
495e37
     vmc->no_pmu = true;
495e37
 }
495e37
 DEFINE_VIRT_MACHINE(2, 6)
495e37
+#endif /* disabled for RHEL */
495e37
+
495e37
+static void rhel_machine_class_init(ObjectClass *oc, void *data)
495e37
+{
495e37
+    MachineClass *mc = MACHINE_CLASS(oc);
495e37
+    HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
495e37
+
495e37
+    mc->family = "virt-rhel-Z";
495e37
+    mc->init = machvirt_init;
495e37
+    /* Maximum supported VCPU count for all virt-rhel* machines */
495e37
+    mc->max_cpus = 384;
495e37
+#ifdef CONFIG_TPM
495e37
+    machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS);
495e37
+#endif
495e37
+    mc->block_default_type = IF_VIRTIO;
495e37
+    mc->no_cdrom = 1;
495e37
+    mc->pci_allow_0_address = true;
495e37
+    /* We know we will never create a pre-ARMv7 CPU which needs 1K pages */
495e37
+    mc->minimum_page_bits = 12;
495e37
+    mc->possible_cpu_arch_ids = virt_possible_cpu_arch_ids;
495e37
+    mc->cpu_index_to_instance_props = virt_cpu_index_to_props;
495e37
+    mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a57");
495e37
+    mc->get_default_cpu_node_id = virt_get_default_cpu_node_id;
495e37
+    mc->kvm_type = virt_kvm_type;
495e37
+    assert(!mc->get_hotplug_handler);
495e37
+    mc->get_hotplug_handler = virt_machine_get_hotplug_handler;
495e37
+    hc->pre_plug = virt_machine_device_pre_plug_cb;
495e37
+    hc->plug = virt_machine_device_plug_cb;
495e37
+    hc->unplug_request = virt_machine_device_unplug_request_cb;
495e37
+    hc->unplug = virt_machine_device_unplug_cb;
495e37
+    mc->nvdimm_supported = true;
495e37
+    mc->auto_enable_numa_with_memhp = true;
495e37
+    mc->auto_enable_numa_with_memdev = true;
495e37
+    mc->default_ram_id = "mach-virt.ram";
495e37
+
495e37
+    object_class_property_add(oc, "acpi", "OnOffAuto",
495e37
+        virt_get_acpi, virt_set_acpi,
495e37
+        NULL, NULL);
495e37
+    object_class_property_set_description(oc, "acpi",
495e37
+        "Enable ACPI");
495e37
+
495e37
+    object_class_property_add_bool(oc, "highmem", virt_get_highmem,
495e37
+                                   virt_set_highmem);
495e37
+    object_class_property_set_description(oc, "highmem",
495e37
+                                          "Set on/off to enable/disable using "
495e37
+                                          "physical address space above 32 bits");
495e37
+
495e37
+    object_class_property_add_str(oc, "gic-version", virt_get_gic_version,
495e37
+                                  virt_set_gic_version);
495e37
+    object_class_property_set_description(oc, "gic-version",
495e37
+                                          "Set GIC version. "
495e37
+                                          "Valid values are 2, 3, host and max");
495e37
+
586cba
+    object_class_property_add_str(oc, "iommu", virt_get_iommu, virt_set_iommu);
586cba
+    object_class_property_set_description(oc, "iommu",
586cba
+                                          "Set the IOMMU type. "
586cba
+                                          "Valid values are none and smmuv3");
586cba
+
586cba
+    object_class_property_add_bool(oc, "default-bus-bypass-iommu",
586cba
+                                   virt_get_default_bus_bypass_iommu,
586cba
+                                   virt_set_default_bus_bypass_iommu);
586cba
+    object_class_property_set_description(oc, "default-bus-bypass-iommu",
586cba
+                                          "Set on/off to enable/disable "
586cba
+                                          "bypass_iommu for default root bus");
586cba
+
586cba
+    object_class_property_add_bool(oc, "ras", virt_get_ras,
586cba
+                                   virt_set_ras);
586cba
+    object_class_property_set_description(oc, "ras",
586cba
+                                          "Set on/off to enable/disable reporting host memory errors "
586cba
+                                          "to a KVM guest using ACPI and guest external abort exceptions");
586cba
+
586cba
+    object_class_property_add_bool(oc, "its", virt_get_its,
586cba
+                                   virt_set_its);
586cba
+    object_class_property_set_description(oc, "its",
586cba
+                                          "Set on/off to enable/disable "
586cba
+                                          "ITS instantiation");
586cba
+
495e37
+    object_class_property_add_str(oc, "x-oem-id",
495e37
+                                  virt_get_oem_id,
495e37
+                                  virt_set_oem_id);
495e37
+    object_class_property_set_description(oc, "x-oem-id",
495e37
+                                          "Override the default value of field OEMID "
495e37
+                                          "in ACPI table header."
495e37
+                                          "The string may be up to 6 bytes in size");
495e37
+
586cba
+
495e37
+    object_class_property_add_str(oc, "x-oem-table-id",
495e37
+                                  virt_get_oem_table_id,
495e37
+                                  virt_set_oem_table_id);
495e37
+    object_class_property_set_description(oc, "x-oem-table-id",
495e37
+                                          "Override the default value of field OEM Table ID "
495e37
+                                          "in ACPI table header."
495e37
+                                          "The string may be up to 8 bytes in size");
495e37
+
586cba
+    object_class_property_add_bool(oc, "dtb-kaslr-seed",
586cba
+                                   virt_get_dtb_kaslr_seed,
586cba
+                                   virt_set_dtb_kaslr_seed);
586cba
+    object_class_property_set_description(oc, "dtb-kaslr-seed",
586cba
+                                          "Set off to disable passing of kaslr-seed "
586cba
+                                          "dtb node to guest");
495e37
+}
495e37
+
495e37
+static void rhel_virt_instance_init(Object *obj)
495e37
+{
495e37
+    VirtMachineState *vms = VIRT_MACHINE(obj);
495e37
+    VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
495e37
+
495e37
+    /* EL3 is disabled by default and non-configurable for RHEL */
495e37
+    vms->secure = false;
495e37
+
495e37
+    /* EL2 is disabled by default and non-configurable for RHEL */
495e37
+    vms->virt = false;
495e37
+
495e37
+    /* High memory is enabled by default */
495e37
+    vms->highmem = true;
495e37
+    vms->gic_version = VIRT_GIC_VERSION_NOSEL;
495e37
+
495e37
+    vms->highmem_ecam = !vmc->no_highmem_ecam;
495e37
+
495e37
+    if (vmc->no_its) {
495e37
+        vms->its = false;
495e37
+    } else {
495e37
+        /* Default allows ITS instantiation */
495e37
+        vms->its = true;
586cba
+
586cba
+        if (vmc->no_tcg_its) {
586cba
+            vms->tcg_its = false;
586cba
+        } else {
586cba
+            vms->tcg_its = true;
586cba
+        }
495e37
+    }
495e37
+
495e37
+    /* Default disallows iommu instantiation */
495e37
+    vms->iommu = VIRT_IOMMU_NONE;
586cba
+
586cba
+    /* The default root bus is attached to iommu by default */
586cba
+    vms->default_bus_bypass_iommu = false;
495e37
+
495e37
+    /* Default disallows RAS instantiation and is non-configurable for RHEL */
495e37
+    vms->ras = false;
495e37
+
495e37
+    /* MTE is disabled by default and non-configurable for RHEL */
495e37
+    vms->mte = false;
495e37
+
586cba
+    /* Supply a kaslr-seed by default */
586cba
+    vms->dtb_kaslr_seed = true;
495e37
+
495e37
+    vms->irqmap = a15irqmap;
495e37
+
495e37
+    virt_flash_create(vms);
586cba
+
495e37
+    vms->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6);
495e37
+    vms->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8);
495e37
+}
495e37
+
495e37
+static const TypeInfo rhel_machine_info = {
495e37
+    .name          = TYPE_RHEL_MACHINE,
495e37
+    .parent        = TYPE_MACHINE,
495e37
+    .abstract      = true,
495e37
+    .instance_size = sizeof(VirtMachineState),
495e37
+    .class_size    = sizeof(VirtMachineClass),
495e37
+    .class_init    = rhel_machine_class_init,
495e37
+    .instance_init = rhel_virt_instance_init,
495e37
+    .interfaces = (InterfaceInfo[]) {
495e37
+         { TYPE_HOTPLUG_HANDLER },
495e37
+         { }
495e37
+    },
495e37
+};
495e37
+
495e37
+static void rhel_machine_init(void)
495e37
+{
495e37
+    type_register_static(&rhel_machine_info);
495e37
+}
495e37
+type_init(rhel_machine_init);
495e37
+
586cba
+static void rhel900_virt_options(MachineClass *mc)
495e37
+{
586cba
+    VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc));
586cba
+
495e37
+    compat_props_add(mc->compat_props, arm_rhel_compat, arm_rhel_compat_len);
586cba
+
586cba
+    /* Disable FEAT_LPA2 since old kernels (<= v5.12) don't boot with that feature */
586cba
+    vmc->no_tcg_lpa2 = true;
495e37
+}
586cba
+DEFINE_RHEL_MACHINE_AS_LATEST(9, 0, 0)
495e37
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
586cba
index 7e76ee2619..9b1efe8f0e 100644
495e37
--- a/include/hw/arm/virt.h
495e37
+++ b/include/hw/arm/virt.h
586cba
@@ -179,9 +179,17 @@ struct VirtMachineState {
495e37
 
495e37
 #define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM)
495e37
 
495e37
+#if 0 /* disabled for Red Hat Enterprise Linux */
495e37
 #define TYPE_VIRT_MACHINE   MACHINE_TYPE_NAME("virt")
495e37
 OBJECT_DECLARE_TYPE(VirtMachineState, VirtMachineClass, VIRT_MACHINE)
495e37
 
495e37
+#else
495e37
+#define TYPE_RHEL_MACHINE MACHINE_TYPE_NAME("virt-rhel")
495e37
+typedef struct VirtMachineClass VirtMachineClass;
495e37
+typedef struct VirtMachineState VirtMachineState;
495e37
+DECLARE_OBJ_CHECKERS(VirtMachineState, VirtMachineClass, VIRT_MACHINE, TYPE_RHEL_MACHINE)
495e37
+#endif
495e37
+
495e37
 void virt_acpi_setup(VirtMachineState *vms);
495e37
 bool virt_is_acpi_enabled(VirtMachineState *vms);
495e37
 
495e37
-- 
586cba
2.31.1
495e37