ff9ada
From 670e90f5cbd92189155e079b8c6e2aafdf82d162 Mon Sep 17 00:00:00 2001
ddf19c
From: Miroslav Rezanina <mrezanin@redhat.com>
ddf19c
Date: Fri, 19 Oct 2018 12:53:31 +0200
ddf19c
Subject: Add aarch64 machine types
ddf19c
ddf19c
Adding changes to add RHEL machine types for aarch64 architecture.
ddf19c
ddf19c
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ddf19c
ff9ada
Rebase notes (4.0.0):
ddf19c
- Use upstream compat handling
ddf19c
ff9ada
Rebase notes (4.1.0-rc0):
ddf19c
- Removed a15memmap (upstream)
ddf19c
- Use virt_flash_create in rhel800_virt_instance_init
ddf19c
ff9ada
Rebase notes (4.2.0-rc0):
ddf19c
- Set numa_mem_supported
ddf19c
ddf19c
Rebase notes (4.2.0-rc3):
ddf19c
- aarch64: Add virt-rhel8.2.0 machine type for ARM (patch 92246)
ddf19c
- aarch64: virt: Allow more than 1TB of RAM (patch 92249)
ddf19c
- aarch64: virt: Allow PCDIMM instantiation (patch 92247)
ddf19c
- aarch64: virt: Enhance the comment related to gic-version (patch 92248)
ddf19c
ff9ada
Rebase notes (5.0.0):
ff9ada
- Set default_ram_id in rhel_machine_class_init
ff9ada
- Added setting acpi properties
ff9ada
ff9ada
Rebase notes (5.1.0):
ff9ada
- Added ras property
ff9ada
- Added to virt_machine_device_unplug_cb to machine type (upstream)
ff9ada
- added mte property (upstream)
ff9ada
ff9ada
Rebase notes (weekly-210210):
ff9ada
- Added support for oem fields to machine type
ff9ada
ff9ada
Rebase notes (weekly-210303):
ff9ada
- Use rhel-8.4.0 hw compat
ff9ada
ff9ada
Rebase notes (6.0.0-rc2):
ff9ada
- renamed oem-id and oem-table-id to x-oem-id and x-oem-table-id
ff9ada
ff9ada
Rebase notes (210623):
ff9ada
- Protect TPM functions by CONFIG_TPM ifdef
ff9ada
ff9ada
Rebase notes (6.1.0-rc0):
ff9ada
- Add support for default_bus_bypass_iommu
ff9ada
ddf19c
Merged patches (4.0.0):
ddf19c
- 7bfdb4c aarch64: Add virt-rhel8.0.0 machine type for ARM
ddf19c
- 3433e69 aarch64: Set virt-rhel8.0.0 max_cpus to 512
ddf19c
- 4d20863 aarch64: Use 256MB ECAM region by default
ddf19c
ddf19c
Merged patches (4.1.0):
ddf19c
- c3e39ef aarch64: Add virt-rhel8.1.0 machine type for ARM
ddf19c
- 59a46d1 aarch64: Allow ARM VIRT iommu option in RHEL8.1 machine
ddf19c
ff9ada
Merged patches (5.2.0 rc0):
ff9ada
- 12990ad hw/arm: Changes to rhel820 machine
ff9ada
- 46d5a79 hw/arm: Introduce rhel_virt_instance_init() helper
ff9ada
- 098954a hw/arm: Add rhel830 machine type
ff9ada
- ee8e99d arm: Set correct max_cpus value on virt-rhel* machine types
ff9ada
- e5edd38 RHEL-only: arm/virt: Allow the TPM_TIS_SYSBUS device dynamic allocation in machvirt
ff9ada
- 6d7ba66 machine types/numa: set numa_mem_supported on old machine types (partialy)
ff9ada
- 25c5644 machine_types/numa: compatibility for auto_enable_numa_with_memdev (partialy)
ff9ada
ff9ada
Merged patches (6.0):
ff9ada
- 078fadb5da AArch64 machine types cleanup
ff9ada
- ea7b7425fa hw/arm/virt: Add 8.4 Machine type
ff9ada
ff9ada
Merged patches (weekly-210609):
ff9ada
- 73b1578882 hw/arm/virt: Add 8.5 machine type
ff9ada
- 5333038d11 hw/arm/virt: Disable PL011 clock migration through hw_compat_rhel_8_3
ff9ada
- 63adb8ae86 arm/virt: Register highmem and gic-version as class properties
ff9ada
ff9ada
Merged patches (weekly-211027):
ff9ada
- 86e3057c0a hw: arm: virt: Add hw_compat_rhel_8_5 to 8.5 machine type
ddf19c
---
ff9ada
 hw/arm/virt.c         | 226 +++++++++++++++++++++++++++++++++++++++++-
ff9ada
 hw/core/machine.c     |   2 +
ff9ada
 include/hw/arm/virt.h |   8 ++
ff9ada
 3 files changed, 235 insertions(+), 1 deletion(-)
ddf19c
ddf19c
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
ff9ada
index 5de4d9d73b..c77d26ab13 100644
ddf19c
--- a/hw/arm/virt.c
ddf19c
+++ b/hw/arm/virt.c
ff9ada
@@ -79,6 +79,7 @@
ff9ada
 #include "hw/char/pl011.h"
ff9ada
 #include "qemu/guest-random.h"
ddf19c
 
ddf19c
+#if 0 /* Disabled for Red Hat Enterprise Linux */
ddf19c
 #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \
ddf19c
     static void virt_##major##_##minor##_class_init(ObjectClass *oc, \
ddf19c
                                                     void *data) \
ff9ada
@@ -105,7 +106,48 @@
ddf19c
     DEFINE_VIRT_MACHINE_LATEST(major, minor, true)
ddf19c
 #define DEFINE_VIRT_MACHINE(major, minor) \
ddf19c
     DEFINE_VIRT_MACHINE_LATEST(major, minor, false)
ddf19c
-
ddf19c
+#endif /* disabled for RHEL */
ddf19c
+
ddf19c
+#define DEFINE_RHEL_MACHINE_LATEST(m, n, s, latest)                     \
ddf19c
+    static void rhel##m##n##s##_virt_class_init(ObjectClass *oc,        \
ddf19c
+                                                void *data)             \
ddf19c
+    {                                                                   \
ddf19c
+        MachineClass *mc = MACHINE_CLASS(oc);                           \
ddf19c
+        rhel##m##n##s##_virt_options(mc);                               \
ddf19c
+        mc->desc = "RHEL " # m "." # n "." # s " ARM Virtual Machine";  \
ddf19c
+        if (latest) {                                                   \
ddf19c
+            mc->alias = "virt";                                         \
ddf19c
+            mc->is_default = 1;                                         \
ddf19c
+        }                                                               \
ddf19c
+    }                                                                   \
ddf19c
+    static const TypeInfo rhel##m##n##s##_machvirt_info = {             \
ddf19c
+        .name = MACHINE_TYPE_NAME("virt-rhel" # m "." # n "." # s),     \
ddf19c
+        .parent = TYPE_RHEL_MACHINE,                                    \
ddf19c
+        .class_init = rhel##m##n##s##_virt_class_init,                  \
ddf19c
+    };                                                                  \
ddf19c
+    static void rhel##m##n##s##_machvirt_init(void)                     \
ddf19c
+    {                                                                   \
ddf19c
+        type_register_static(&rhel##m##n##s##_machvirt_info);           \
ddf19c
+    }                                                                   \
ddf19c
+    type_init(rhel##m##n##s##_machvirt_init);
ddf19c
+
ddf19c
+#define DEFINE_RHEL_MACHINE_AS_LATEST(major, minor, subminor)   \
ddf19c
+    DEFINE_RHEL_MACHINE_LATEST(major, minor, subminor, true)
ddf19c
+#define DEFINE_RHEL_MACHINE(major, minor, subminor)             \
ddf19c
+    DEFINE_RHEL_MACHINE_LATEST(major, minor, subminor, false)
ddf19c
+
ddf19c
+/* This variable is for changes to properties that are RHEL specific,
ddf19c
+ * different to the current upstream and to be applied to the latest
ddf19c
+ * machine type.
ddf19c
+ */
ddf19c
+GlobalProperty arm_rhel_compat[] = {
ddf19c
+    {
ddf19c
+        .driver   = "virtio-net-pci",
ddf19c
+        .property = "romfile",
ddf19c
+        .value    = "",
ddf19c
+    },
ddf19c
+};
ddf19c
+const size_t arm_rhel_compat_len = G_N_ELEMENTS(arm_rhel_compat);
ddf19c
 
ddf19c
 /* Number of external interrupt lines to configure the GIC with */
ddf19c
 #define NUM_IRQS 256
ff9ada
@@ -2180,6 +2222,7 @@ static void machvirt_init(MachineState *machine)
ddf19c
     qemu_add_machine_init_done_notifier(&vms->machine_done);
ddf19c
 }
ddf19c
 
ddf19c
+#if 0 /* Disabled for Red Hat Enterprise Linux */
ddf19c
 static bool virt_get_secure(Object *obj, Error **errp)
ddf19c
 {
ddf19c
     VirtMachineState *vms = VIRT_MACHINE(obj);
ff9ada
@@ -2207,6 +2250,7 @@ static void virt_set_virt(Object *obj, bool value, Error **errp)
ff9ada
 
ddf19c
     vms->virt = value;
ddf19c
 }
ddf19c
+#endif /* disabled for RHEL */
ff9ada
 
ddf19c
 static bool virt_get_highmem(Object *obj, Error **errp)
ddf19c
 {
ff9ada
@@ -2304,6 +2348,7 @@ static void virt_set_acpi(Object *obj, Visitor *v, const char *name,
ff9ada
     visit_type_OnOffAuto(v, name, &vms->acpi, errp);
ff9ada
 }
ff9ada
 
ff9ada
+#if 0 /* Disabled for Red Hat Enterprise Linux */
ff9ada
 static bool virt_get_ras(Object *obj, Error **errp)
ff9ada
 {
ddf19c
     VirtMachineState *vms = VIRT_MACHINE(obj);
ff9ada
@@ -2331,6 +2376,7 @@ static void virt_set_mte(Object *obj, bool value, Error **errp)
ff9ada
 
ff9ada
     vms->mte = value;
ff9ada
 }
ff9ada
+#endif /* disabled for RHEL */
ff9ada
 
ff9ada
 static char *virt_get_gic_version(Object *obj, Error **errp)
ff9ada
 {
ff9ada
@@ -2666,6 +2712,7 @@ static int virt_kvm_type(MachineState *ms, const char *type_str)
ff9ada
     return fixed_ipa ? 0 : requested_pa_size;
ddf19c
 }
ddf19c
 
ddf19c
+#if 0 /* Disabled for Red Hat Enterprise Linux */
ddf19c
 static void virt_machine_class_init(ObjectClass *oc, void *data)
ddf19c
 {
ddf19c
     MachineClass *mc = MACHINE_CLASS(oc);
ff9ada
@@ -3031,3 +3078,180 @@ static void virt_machine_2_6_options(MachineClass *mc)
ddf19c
     vmc->no_pmu = true;
ddf19c
 }
ddf19c
 DEFINE_VIRT_MACHINE(2, 6)
ddf19c
+#endif /* disabled for RHEL */
ddf19c
+
ddf19c
+static void rhel_machine_class_init(ObjectClass *oc, void *data)
ddf19c
+{
ddf19c
+    MachineClass *mc = MACHINE_CLASS(oc);
ddf19c
+    HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
ddf19c
+
ddf19c
+    mc->family = "virt-rhel-Z";
ddf19c
+    mc->init = machvirt_init;
ff9ada
+    /* Maximum supported VCPU count for all virt-rhel* machines */
ff9ada
+    mc->max_cpus = 384;
ff9ada
+#ifdef CONFIG_TPM
ff9ada
+    machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS);
ff9ada
+#endif
ddf19c
+    mc->block_default_type = IF_VIRTIO;
ddf19c
+    mc->no_cdrom = 1;
ddf19c
+    mc->pci_allow_0_address = true;
ddf19c
+    /* We know we will never create a pre-ARMv7 CPU which needs 1K pages */
ddf19c
+    mc->minimum_page_bits = 12;
ddf19c
+    mc->possible_cpu_arch_ids = virt_possible_cpu_arch_ids;
ddf19c
+    mc->cpu_index_to_instance_props = virt_cpu_index_to_props;
ddf19c
+    mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a57");
ddf19c
+    mc->get_default_cpu_node_id = virt_get_default_cpu_node_id;
ddf19c
+    mc->kvm_type = virt_kvm_type;
ddf19c
+    assert(!mc->get_hotplug_handler);
ddf19c
+    mc->get_hotplug_handler = virt_machine_get_hotplug_handler;
ddf19c
+    hc->pre_plug = virt_machine_device_pre_plug_cb;
ddf19c
+    hc->plug = virt_machine_device_plug_cb;
ddf19c
+    hc->unplug_request = virt_machine_device_unplug_request_cb;
ff9ada
+    hc->unplug = virt_machine_device_unplug_cb;
ff9ada
+    mc->nvdimm_supported = true;
ddf19c
+    mc->auto_enable_numa_with_memhp = true;
ff9ada
+    mc->auto_enable_numa_with_memdev = true;
ff9ada
+    mc->default_ram_id = "mach-virt.ram";
ddf19c
+
ff9ada
+    object_class_property_add(oc, "acpi", "OnOffAuto",
ff9ada
+        virt_get_acpi, virt_set_acpi,
ff9ada
+        NULL, NULL);
ff9ada
+    object_class_property_set_description(oc, "acpi",
ff9ada
+        "Enable ACPI");
ff9ada
+
ff9ada
+    object_class_property_add_bool(oc, "highmem", virt_get_highmem,
ff9ada
+                                   virt_set_highmem);
ff9ada
+    object_class_property_set_description(oc, "highmem",
ff9ada
+                                          "Set on/off to enable/disable using "
ff9ada
+                                          "physical address space above 32 bits");
ff9ada
+
ff9ada
+    object_class_property_add_str(oc, "gic-version", virt_get_gic_version,
ff9ada
+                                  virt_set_gic_version);
ff9ada
+    object_class_property_set_description(oc, "gic-version",
ff9ada
+                                          "Set GIC version. "
ff9ada
+                                          "Valid values are 2, 3, host and max");
ff9ada
+
ff9ada
+    object_class_property_add_str(oc, "x-oem-id",
ff9ada
+                                  virt_get_oem_id,
ff9ada
+                                  virt_set_oem_id);
ff9ada
+    object_class_property_set_description(oc, "x-oem-id",
ff9ada
+                                          "Override the default value of field OEMID "
ff9ada
+                                          "in ACPI table header."
ff9ada
+                                          "The string may be up to 6 bytes in size");
ff9ada
+
ff9ada
+    object_class_property_add_str(oc, "x-oem-table-id",
ff9ada
+                                  virt_get_oem_table_id,
ff9ada
+                                  virt_set_oem_table_id);
ff9ada
+    object_class_property_set_description(oc, "x-oem-table-id",
ff9ada
+                                          "Override the default value of field OEM Table ID "
ff9ada
+                                          "in ACPI table header."
ff9ada
+                                          "The string may be up to 8 bytes in size");
ff9ada
+    object_class_property_add_bool(oc, "default_bus_bypass_iommu",
ff9ada
+                                   virt_get_default_bus_bypass_iommu,
ff9ada
+                                   virt_set_default_bus_bypass_iommu);
ddf19c
+
ddf19c
+}
ddf19c
+
ff9ada
+static void rhel_virt_instance_init(Object *obj)
ddf19c
+{
ddf19c
+    VirtMachineState *vms = VIRT_MACHINE(obj);
ddf19c
+    VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
ddf19c
+
ddf19c
+    /* EL3 is disabled by default and non-configurable for RHEL */
ddf19c
+    vms->secure = false;
ff9ada
+
ddf19c
+    /* EL2 is disabled by default and non-configurable for RHEL */
ddf19c
+    vms->virt = false;
ff9ada
+
ff9ada
+    /* High memory is enabled by default */
ddf19c
+    vms->highmem = true;
ff9ada
+    vms->gic_version = VIRT_GIC_VERSION_NOSEL;
ddf19c
+
ddf19c
+    vms->highmem_ecam = !vmc->no_highmem_ecam;
ddf19c
+
ddf19c
+    if (vmc->no_its) {
ddf19c
+        vms->its = false;
ddf19c
+    } else {
ddf19c
+        /* Default allows ITS instantiation */
ddf19c
+        vms->its = true;
ddf19c
+        object_property_add_bool(obj, "its", virt_get_its,
ff9ada
+                                 virt_set_its);
ddf19c
+        object_property_set_description(obj, "its",
ddf19c
+                                        "Set on/off to enable/disable "
ff9ada
+                                        "ITS instantiation");
ddf19c
+    }
ddf19c
+
ddf19c
+    /* Default disallows iommu instantiation */
ddf19c
+    vms->iommu = VIRT_IOMMU_NONE;
ff9ada
+    object_property_add_str(obj, "iommu", virt_get_iommu, virt_set_iommu);
ddf19c
+    object_property_set_description(obj, "iommu",
ddf19c
+                                    "Set the IOMMU type. "
ff9ada
+                                    "Valid values are none and smmuv3");
ff9ada
+
ff9ada
+    /* Default disallows RAS instantiation and is non-configurable for RHEL */
ff9ada
+    vms->ras = false;
ff9ada
+
ff9ada
+    /* MTE is disabled by default and non-configurable for RHEL */
ff9ada
+    vms->mte = false;
ff9ada
+
ff9ada
+    vms->default_bus_bypass_iommu = false;
ff9ada
+    vms->irqmap = a15irqmap;
ddf19c
+
ddf19c
+    virt_flash_create(vms);
ff9ada
+    vms->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6);
ff9ada
+    vms->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8);
ff9ada
+
ddf19c
+}
ddf19c
+
ff9ada
+static const TypeInfo rhel_machine_info = {
ff9ada
+    .name          = TYPE_RHEL_MACHINE,
ff9ada
+    .parent        = TYPE_MACHINE,
ff9ada
+    .abstract      = true,
ff9ada
+    .instance_size = sizeof(VirtMachineState),
ff9ada
+    .class_size    = sizeof(VirtMachineClass),
ff9ada
+    .class_init    = rhel_machine_class_init,
ff9ada
+    .instance_init = rhel_virt_instance_init,
ff9ada
+    .interfaces = (InterfaceInfo[]) {
ff9ada
+         { TYPE_HOTPLUG_HANDLER },
ff9ada
+         { }
ff9ada
+    },
ff9ada
+};
ff9ada
+
ff9ada
+static void rhel_machine_init(void)
ff9ada
+{
ff9ada
+    type_register_static(&rhel_machine_info);
ff9ada
+}
ff9ada
+type_init(rhel_machine_init);
ff9ada
+
ff9ada
+static void rhel850_virt_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    compat_props_add(mc->compat_props, arm_rhel_compat, arm_rhel_compat_len);
ff9ada
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_5, hw_compat_rhel_8_5_len);
ff9ada
+}
ff9ada
+DEFINE_RHEL_MACHINE_AS_LATEST(8, 5, 0)
ff9ada
+
ff9ada
+static void rhel840_virt_options(MachineClass *mc)
ff9ada
+{
ff9ada
+    rhel850_virt_options(mc);
ff9ada
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_4, hw_compat_rhel_8_4_len);
ff9ada
+}
ff9ada
+DEFINE_RHEL_MACHINE(8, 4, 0)
ff9ada
+
ff9ada
+static void rhel830_virt_options(MachineClass *mc)
ff9ada
+{
ff9ada
+    VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc));
ff9ada
+
ff9ada
+    rhel840_virt_options(mc);
ff9ada
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_3, hw_compat_rhel_8_3_len);
ff9ada
+    vmc->no_kvm_steal_time = true;
ff9ada
+}
ff9ada
+DEFINE_RHEL_MACHINE(8, 3, 0)
ff9ada
+
ff9ada
+static void rhel820_virt_options(MachineClass *mc)
ff9ada
+{
ff9ada
+    rhel830_virt_options(mc);
ff9ada
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_2, hw_compat_rhel_8_2_len);
ff9ada
+    mc->numa_mem_supported = true;
ff9ada
+    mc->auto_enable_numa_with_memdev = false;
ddf19c
+}
ff9ada
+DEFINE_RHEL_MACHINE(8, 2, 0)
ff9ada
diff --git a/hw/core/machine.c b/hw/core/machine.c
ff9ada
index be4f9864cd..62febde5aa 100644
ff9ada
--- a/hw/core/machine.c
ff9ada
+++ b/hw/core/machine.c
ff9ada
@@ -87,6 +87,8 @@ GlobalProperty hw_compat_rhel_8_3[] = {
ff9ada
     { "nvme", "use-intel-id", "on"},
ff9ada
     /* hw_compat_rhel_8_3 from hw_compat_5_1 */
ff9ada
     { "pvpanic", "events", "1"}, /* PVPANIC_PANICKED */
ff9ada
+    /* hw_compat_rhel_8_3 from hw_compat_5_1 */
ff9ada
+    { "pl011", "migrate-clk", "off" },
ff9ada
     /* hw_compat_rhel_8_3 bz 1912846 */
ff9ada
     { "pci-xhci", "x-rh-late-msi-cap", "off" },
ff9ada
     /* hw_compat_rhel_8_3 from hw_compat_5_1 */
ddf19c
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
ff9ada
index dc6b66ffc8..9364628847 100644
ddf19c
--- a/include/hw/arm/virt.h
ddf19c
+++ b/include/hw/arm/virt.h
ff9ada
@@ -175,9 +175,17 @@ struct VirtMachineState {
ddf19c
 
ddf19c
 #define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM)
ddf19c
 
ddf19c
+#if 0 /* disabled for Red Hat Enterprise Linux */
ddf19c
 #define TYPE_VIRT_MACHINE   MACHINE_TYPE_NAME("virt")
ff9ada
 OBJECT_DECLARE_TYPE(VirtMachineState, VirtMachineClass, VIRT_MACHINE)
ddf19c
 
ddf19c
+#else
ddf19c
+#define TYPE_RHEL_MACHINE MACHINE_TYPE_NAME("virt-rhel")
ff9ada
+typedef struct VirtMachineClass VirtMachineClass;
ff9ada
+typedef struct VirtMachineState VirtMachineState;
ff9ada
+DECLARE_OBJ_CHECKERS(VirtMachineState, VirtMachineClass, VIRT_MACHINE, TYPE_RHEL_MACHINE)
ddf19c
+#endif
ddf19c
+
ddf19c
 void virt_acpi_setup(VirtMachineState *vms);
ff9ada
 bool virt_is_acpi_enabled(VirtMachineState *vms);
ddf19c
 
ddf19c
-- 
ff9ada
2.27.0
ddf19c