@samitouri / QOSamiQemu / commits / df055f4c39

hw/intc/arm_gicv5: Create backing state for SPIs

The GICv5 allows an IRS to implement SPIs, which are fixed-wire interrupts connected directly to the IRS. For QEMU we want to use these for all our traditional fixed-wire interrupt devices. (The other option the architecture permits is an Interrupt Wire Bridge (IWB), which converts from a fixed-wire interrupt to an interrupt event that is then translated through an ITS to send an LPI to the ITS -- this is much more complexity than we need or want.) SPI configuration is set via the same CPUIF instructions as LPI configuration. Create an array of structs which track the SPI state information listed in I_JVVTZ and I_BWPPP (ignoring for the moment the VM assignment state, which we will add when we add virtualization support). Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Message-id: 20260327111700.795099-24-peter.maydell@linaro.org

Peter Maydell committed Mar 27, 2026 at 11:16 UTC df055f4c3935db9b55f224e6ccf5bb8e877a6d94
3 files changed +71
hw/intc/arm_gicv5_common.c
+30
@@ -64,6 +64,34 @@ static void gicv5_common_reset_hold(Object *obj, ResetType type)
64
65 memset(cs->irs_ist_baser, 0, sizeof(cs->irs_ist_baser));
66 memset(cs->irs_ist_cfgr, 0, sizeof(cs->irs_ist_cfgr));
67 +
68 + if (cs->spi) {
69 + GICv5Domain mp_domain;
70 +
71 + /*
72 + * D_YGLYC, D_TVVRZ: SPIs reset to edge-triggered, inactive,
73 + * idle, disabled, targeted routing mode, not assigned to a
74 + * VM, and assigned to the most-privileged interrupt domain.
75 + * Other state is UNKNOWN: we choose to zero it.
76 + */
77 + memset(cs->spi, 0, cs->spi_irs_range * sizeof(*cs->spi));
78 +
79 + /*
80 + * The most-privileged interrupt domain is effectively the
81 + * first in the list (EL3, S, NS) that we implement.
82 + */
83 + if (gicv5_domain_implemented(cs, GICV5_ID_EL3)) {
84 + mp_domain = GICV5_ID_EL3;
85 + } else if (gicv5_domain_implemented(cs, GICV5_ID_S)) {
86 + mp_domain = GICV5_ID_S;
87 + } else {
88 + mp_domain = GICV5_ID_NS;
89 + }
90 +
91 + for (int i = 0; i < cs->spi_irs_range; i++) {
92 + cs->spi[i].domain = mp_domain;
93 + }
94 + }
95 }
96
97 static void gicv5_common_init(Object *obj)
@@ -142,6 +170,8 @@ static void gicv5_common_realize(DeviceState *dev, Error **errp)
170
171 address_space_init(&cs->dma_as, cs->dma, "gicv5-sysmem");
172
173 + cs->spi = g_new0(GICv5SPIState, cs->spi_irs_range);
174 +
175 trace_gicv5_common_realize(cs->irsid, cs->num_cpus,
176 cs->spi_base, cs->spi_irs_range, cs->spi_range);
177 }
include/hw/intc/arm_gicv5_common.h
+27
@@ -55,6 +55,25 @@
55
56 OBJECT_DECLARE_TYPE(GICv5Common, GICv5CommonClass, ARM_GICV5_COMMON)
57
58 +/*
59 + * This is where we store the state the IRS handles for an SPI.
60 + * Generally this corresponds to the spec's list of state in I_JVVTZ
61 + * and J_BWPPP. level is a QEMU implementation detail and is where we
62 + * store the actual current state of the incoming qemu_irq line.
63 + */
64 +typedef struct GICv5SPIState {
65 + uint32_t iaffid;
66 + uint8_t priority;
67 + bool level;
68 + bool pending;
69 + bool active;
70 + bool enabled;
71 + GICv5HandlingMode hm;
72 + GICv5RoutingMode irm;
73 + GICv5TriggerMode tm;
74 + GICv5Domain domain;
75 +} GICv5SPIState;
76 +
77 /*
78 * This class is for common state that will eventually be shared
79 * between TCG and KVM implementations of the GICv5.
@@ -67,6 +86,14 @@ struct GICv5Common {
86 uint64_t irs_ist_baser[NUM_GICV5_DOMAINS];
87 uint32_t irs_ist_cfgr[NUM_GICV5_DOMAINS];
88
89 + /*
90 + * Pointer to an array of state information for the SPIs. Array
91 + * element 0 is SPI ID s->spi_base, and there are s->spi_irs_range
92 + * elements in total. SPI state is not per-domain: SPI is
93 + * configurable to a particular domain via IRS_SPI_DOMAINR.
94 + */
95 + GICv5SPIState *spi;
96 +
97 /* Bits here are set for each physical interrupt domain implemented */
98 uint8_t implemented_domains;
99
include/hw/intc/arm_gicv5_types.h
+14
@@ -70,4 +70,18 @@ typedef enum GICv5RoutingMode {
70 GICV5_1OFN = 1,
71 } GICv5RoutingMode;
72
73 +/*
74 + * Interrupt trigger mode (same encoding as IRS_SPI_CFGR.TM) Note that
75 + * this is not the same thing as handling mode, even though the two
76 + * possible states have the same names. Trigger mode applies only for
77 + * SPIs and tells the IRS what kinds of changes to the input signal
78 + * wire should make it generate SET and CLEAR events. Handling mode
79 + * affects whether the pending state of an interrupt is cleared when
80 + * the interrupt is acknowledged, and applies to both SPIs and LPIs.
81 + */
82 +typedef enum GICv5TriggerMode {
83 + GICV5_TRIGGER_EDGE = 0,
84 + GICV5_TRIGGER_LEVEL = 1,
85 +} GICv5TriggerMode;
86 +
87 #endif