68
#include "hw/intc/arm_gic.h"
69
#include "hw/intc/arm_gicv3_common.h"
70
#include "hw/intc/arm_gicv3_its_common.h"
71
+#include "hw/intc/arm_gicv5_common.h"
72
#include "hw/core/irq.h"
73
#include "kvm_arm.h"
74
#include "whpx_arm.h"
185
[VIRT_GIC_ITS] = { 0x08080000, 0x00020000 },
186
/* This redistributor space allows up to 2*64kB*123 CPUs */
187
[VIRT_GIC_REDIST] = { 0x080A0000, 0x00F60000 },
188
+ /* The GICv5 uses this address range differently from GICv2/v3/v4 */
189
+ [VIRT_GICV5_IRS_S] = { 0x08000000, 0x00010000 },
190
+ [VIRT_GICV5_IRS_NS] = { 0x08010000, 0x00010000 },
191
+ [VIRT_GICV5_IRS_EL3] = { 0x08020000, 0x00010000 },
192
+ [VIRT_GICV5_IRS_REALM] = { 0x08030000, 0x00010000 },
193
+ [VIRT_GICV5_ITS_S] = { 0x08040000, 0x00010000 },
194
+ [VIRT_GICV5_ITS_NS] = { 0x08050000, 0x00010000 },
195
+ [VIRT_GICV5_ITS_EL3] = { 0x08060000, 0x00010000 },
196
+ [VIRT_GICV5_ITS_REALM] = { 0x08070000, 0x00010000 },
197
+ [VIRT_GICV5_ITS_TR_S] = { 0x08080000, 0x00010000 },
198
+ [VIRT_GICV5_ITS_TR_NS] = { 0x08090000, 0x00010000 },
199
+ [VIRT_GICV5_ITS_TR_EL3] = { 0x080A0000, 0x00010000 },
200
+ [VIRT_GICV5_ITS_TR_REALM] = { 0x080B0000, 0x00010000 },
201
[VIRT_UART0] = { 0x09000000, 0x00001000 },
202
[VIRT_RTC] = { 0x09010000, 0x00001000 },
203
[VIRT_FW_CFG] = { 0x09020000, 0x00000018 },
1120
vms->msi_controller = VIRT_MSI_CTRL_GICV2M;
1121
}
1122
1123
+static void create_gicv5(VirtMachineState *vms, MemoryRegion *mem)
1124
+{
1125
+ MachineState *ms = MACHINE(vms);
1126
+ SysBusDevice *gicbusdev;
1127
+ const char *gictype = gicv5_class_name();
1128
+ QList *cpulist = qlist_new(), *iaffidlist = qlist_new();
1129
+
1130
+ vms->gic = qdev_new(gictype);
1131
+ qdev_prop_set_uint32(vms->gic, "spi-range", NUM_IRQS);
1132
+
1133
+ object_property_set_link(OBJECT(vms->gic), "sysmem", OBJECT(mem),
1134
+ &error_fatal);
1135
+
1136
+ for (int i = 0; i < ms->smp.cpus; i++) {
1137
+ qlist_append_link(cpulist, OBJECT(qemu_get_cpu(i)));
1138
+ /*
1139
+ * GICv5 IAFFIDs must be system-wide unique across all GICs.
1140
+ * For virt we make them the same as the CPU index.
1141
+ */
1142
+ qlist_append_int(iaffidlist, i);
1143
+ }
1144
+ qdev_prop_set_array(vms->gic, "cpus", cpulist);
1145
+ qdev_prop_set_array(vms->gic, "cpu-iaffids", iaffidlist);
1146
+
1147
+ gicbusdev = SYS_BUS_DEVICE(vms->gic);
1148
+ sysbus_realize_and_unref(gicbusdev, &error_fatal);
1149
+
1150
+ /*
1151
+ * Map the IRS config frames for the interrupt domains.
1152
+ * At the moment we implement only the NS domain, so this is simple.
1153
+ */
1154
+ sysbus_mmio_map(gicbusdev, GICV5_ID_NS,
1155
+ vms->memmap[VIRT_GICV5_IRS_NS].base);
1156
+
1157
+ /*
1158
+ * The GICv5 does not need to wire up CPU timer IRQ outputs to the GIC
1159
+ * because for the GICv5 those PPIs are entirely internal to the CPU.
1160
+ * Nor do we need to wire up GIC IRQ/FIQ signals to the CPUs, because
1161
+ * that information is communicated directly between a GICv5 IRS and
1162
+ * the GICv5 CPU interface via our equivalent of the stream protocol.
1163
+ */
1164
+}
1165
+
1166
/*
1167
* If the CPU has FEAT_NMI, then turn on the NMI support in the GICv3 too.
1168
* It's permitted to have a configuration with NMI in the CPU (and thus the
1376
case VIRT_GIC_VERSION_4:
1377
create_gicv3(vms, mem);
1378
break;
1379
+ case VIRT_GIC_VERSION_5:
1380
+ create_gicv5(vms, mem);
1381
+ break;
1382
default:
1383
g_assert_not_reached();
1384
}
2314
/*
2315
* Adjust MPIDR to make TCG consistent (with 64-bit KVM hosts)
2316
* and to improve SGI efficiency.
2317
+ * - GICv2 only supports 8 CPUs anyway
2318
+ * - GICv3 wants 16 CPUs per Aff0 because of an ICC_SGIxR
2319
+ * register limitation
2320
+ * - GICv5 has no restrictions, so we retain the GICv3 16-per-Aff0
2321
+ * layout because that's what KVM does
2322
*/
2323
if (vms->gic_version == VIRT_GIC_VERSION_2) {
2324
clustersz = GIC_TARGETLIST_BITS;
2464
return finalize_gic_version_do(accel_name, VIRT_GIC_VERSION_MAX,
2465
gics_supported, max_cpus);
2466
case VIRT_GIC_VERSION_MAX:
2467
+ /*
2468
+ * We don't (currently) make 'max' select GICv5 as it is not
2469
+ * backwards compatible for system software with GICv3/v4 and
2470
+ * at time of writing not widely supported in guest kernels.
2471
+ */
2472
if (gics_supported & VIRT_GIC_VERSION_4_MASK) {
2473
gic_version = VIRT_GIC_VERSION_4;
2474
} else if (gics_supported & VIRT_GIC_VERSION_3_MASK) {
2497
case VIRT_GIC_VERSION_2:
2498
case VIRT_GIC_VERSION_3:
2499
case VIRT_GIC_VERSION_4:
2500
+ case VIRT_GIC_VERSION_5:
2501
break;
2502
}
2503
2522
exit(1);
2523
}
2524
break;
2525
+ case VIRT_GIC_VERSION_5:
2526
+ if (!(gics_supported & VIRT_GIC_VERSION_5_MASK)) {
2527
+ error_report("%s does not support GICv5 emulation", accel_name);
2528
+ exit(1);
2529
+ }
2530
+ break;
2531
default:
2532
error_report("logic error in finalize_gic_version");
2533
exit(1);
2587
gics_supported |= VIRT_GIC_VERSION_4_MASK;
2588
}
2589
}
2590
+ if (!hvf_enabled() && module_object_class_by_name("arm-gicv5")) {
2591
+ /* HVF doesn't have GICv5 support */
2592
+ gics_supported |= VIRT_GIC_VERSION_5_MASK;
2593
+ }
2594
} else {
2595
error_report("Unsupported accelerator, can not determine GIC support");
2596
exit(1);
2626
vms->msi_controller = VIRT_MSI_CTRL_GICV2M;
2627
} else if (hvf_enabled() && hvf_irqchip_in_kernel()) {
2628
vms->msi_controller = VIRT_MSI_CTRL_GICV2M;
2629
+ } else if (vms->gic_version == VIRT_GIC_VERSION_5) {
2630
+ /* GICv5 ITS is not yet implemented */
2631
+ vms->msi_controller = VIRT_MSI_CTRL_NONE;
2632
} else {
2633
vms->msi_controller = VIRT_MSI_CTRL_ITS;
2634
}
2644
error_report("GICv2 + ITS is an invalid configuration.");
2645
exit(1);
2646
}
2647
+ if (vms->gic_version == VIRT_GIC_VERSION_5) {
2648
+ error_report("GICv5 + ITS is not yet implemented.");
2649
+ exit(1);
2650
+ }
2651
if (whpx_enabled()) {
2652
error_report("ITS not supported on WHPX.");
2653
exit(1);
2824
*/
2825
if (vms->gic_version == VIRT_GIC_VERSION_2) {
2826
virt_max_cpus = GIC_NCPU;
2827
+ } else if (vms->gic_version == VIRT_GIC_VERSION_5) {
2828
+ /*
2829
+ * GICv5 imposes no CPU limit beyond the 16-bit IAFFID field.
2830
+ * The maximum number of CPUs will be limited not by this, but
2831
+ * by the MachineClass::max_cpus value we set earlier.
2832
+ */
2833
+ virt_max_cpus = 1 << QEMU_GICV5_IAFFID_BITS;
2834
} else {
2835
virt_max_cpus = virt_redist_capacity(vms, VIRT_GIC_REDIST);
2836
if (vms->highmem_redists) {
2877
exit(1);
2878
}
2879
2880
+ if ((vms->virt || vms->secure) &&
2881
+ vms->gic_version == VIRT_GIC_VERSION_5) {
2882
+ error_report("mach-virt: GICv5 currently supports EL1 only");
2883
+ exit(1);
2884
+ }
2885
+
2886
create_fdt(vms);
2887
2888
assert(possible_cpus->len == max_cpus);