@samitouri / QOSamiQemu / commits / 78919a66ae

hw/intc/arm_gicv5: Cache LPI IST config in a struct

The IRS has multiple ISTs, for different contexts: * physical LPIs (separately for each interrupt domain) * virtual LPIs * virtual SPIs The config information for physical LPIs is in the IRS_IST_BASER and IRS_IST_CFGR registers; for virtual LPIs and virtual SPIs it will be in the L2_VMTE VM table entry. We would like to be able to write generic code that can manipulate any of these ISTs. Define a struct which captures the config information for an IST, and cache the IRS_IST_CFGR/IRS_IST_BASER data into this format when the guest sets the VALID bit. This also allows us to enforce the correct handling of reserved and out-of-range values, and expand the encodings of sizes into a more convenient format for later use. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Message-id: 20260327111700.795099-18-peter.maydell@linaro.org

Peter Maydell committed Mar 27, 2026 at 11:16 UTC 78919a66ae549683831bcde8330dc7c083440edb
3 files changed +78
hw/intc/arm_gicv5.c
+64
@@ -278,9 +278,68 @@ static void irs_ist_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
278 }
279 cs->irs_ist_baser[domain] = FIELD_DP64(cs->irs_ist_baser[domain],
280 IRS_IST_BASER, VALID, valid);
281 + s->phys_lpi_config[domain].valid = false;
282 + trace_gicv5_ist_invalid(domain_name[domain]);
283 return;
284 }
285 cs->irs_ist_baser[domain] = value;
286 +
287 + if (FIELD_EX64(cs->irs_ist_baser[domain], IRS_IST_BASER, VALID)) {
288 + /*
289 + * If the guest just set VALID then capture data into config struct,
290 + * sanitize the reserved values, and expand fields out into byte counts.
291 + */
292 + GICv5ISTConfig *cfg = &s->phys_lpi_config[domain];
293 + uint8_t istbits, l2bits, l2_idx_bits;
294 + uint8_t id_bits = FIELD_EX64(cs->irs_ist_cfgr[domain],
295 + IRS_IST_CFGR, LPI_ID_BITS);
296 + id_bits = MIN(MAX(id_bits, QEMU_GICV5_MIN_LPI_ID_BITS), QEMU_GICV5_ID_BITS);
297 +
298 + switch (FIELD_EX64(cs->irs_ist_cfgr[domain], IRS_IST_CFGR, ISTSZ)) {
299 + case 0:
300 + case 3: /* reserved: acts like the minimum required size */
301 + istbits = 2;
302 + break;
303 + case 1:
304 + istbits = 3;
305 + break;
306 + case 2:
307 + istbits = 4;
308 + break;
309 + default:
310 + g_assert_not_reached();
311 + }
312 + switch (FIELD_EX64(cs->irs_ist_cfgr[domain], IRS_IST_CFGR, L2SZ)) {
313 + case 0:
314 + case 3: /* reserved; CONSTRAINED UNPREDICTABLE */
315 + l2bits = 12; /* 4K: 12 bits */
316 + break;
317 + case 1:
318 + l2bits = 14; /* 16K: 14 bits */
319 + break;
320 + case 2:
321 + l2bits = 16; /* 64K: 16 bits */
322 + break;
323 + default:
324 + g_assert_not_reached();
325 + }
326 + /*
327 + * Calculate how many bits of an ID index the L2 table
328 + * (e.g. if we need 14 bits to index each byte in a 16K L2 table,
329 + * but each entry is 4 bytes wide then we need 14 - 2 = 12 bits
330 + * to index an entry in the table).
331 + */
332 + l2_idx_bits = l2bits - istbits;
333 + cfg->base = cs->irs_ist_baser[domain] & R_IRS_IST_BASER_ADDR_MASK;
334 + cfg->id_bits = id_bits;
335 + cfg->istsz = 1 << istbits;
336 + cfg->l2_idx_bits = l2_idx_bits;
337 + cfg->structure = FIELD_EX64(cs->irs_ist_cfgr[domain],
338 + IRS_IST_CFGR, STRUCTURE);
339 + cfg->valid = true;
340 + trace_gicv5_ist_valid(domain_name[domain], cfg->base, cfg->id_bits,
341 + cfg->l2_idx_bits, cfg->istsz, cfg->structure);
342 + }
343 }
344
345 static bool config_readl(GICv5 *s, GICv5Domain domain, hwaddr offset,
@@ -553,6 +612,11 @@ static void gicv5_reset_hold(Object *obj, ResetType type)
612 if (c->parent_phases.hold) {
613 c->parent_phases.hold(obj, type);
614 }
615 +
616 + /* IRS_IST_BASER and IRS_IST_CFGR reset to 0, clear cached info */
617 + for (int i = 0; i < NUM_GICV5_DOMAINS; i++) {
618 + s->phys_lpi_config[i].valid = false;
619 + }
620 }
621
622 static void gicv5_set_idregs(GICv5Common *cs)
hw/intc/trace-events
+2
@@ -233,6 +233,8 @@ gicv5_badread(const char *domain, uint64_t offset, unsigned size) "GICv5 IRS %s
233 gicv5_write(const char *domain, uint64_t offset, uint64_t data, unsigned size) "GICv5 IRS %s config frame write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
234 gicv5_badwrite(const char *domain, uint64_t offset, uint64_t data, unsigned size) "GICv5 IRS %s config frame write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u: error"
235 gicv5_spi(uint32_t id, int level) "GICv5 SPI ID %u asserted at level %d"
236 +gicv5_ist_valid(const char *domain, uint64_t base, uint8_t id_bits, uint8_t l2_idx_bits, uint8_t istsz, bool structure) "GICv5 IRS %s IST now valid: base 0x%" PRIx64 " id_bits %u l2_idx_bits %u IST entry size %u 2-level %d"
237 +gicv5_ist_invalid(const char *domain) "GICv5 IRS %s IST no longer valid"
238
239 # arm_gicv5_common.c
240 gicv5_common_realize(uint32_t irsid, uint32_t num_cpus, uint32_t spi_base, uint32_t spi_irs_range, uint32_t spi_range) "GICv5 IRS realized: IRS ID %u, %u CPUs, SPI base %u, SPI IRS range %u, SPI range %u"
include/hw/intc/arm_gicv5.h
+12
@@ -17,11 +17,23 @@
17
18 OBJECT_DECLARE_TYPE(GICv5, GICv5Class, ARM_GICV5)
19
20 +typedef struct GICv5ISTConfig {
21 + hwaddr base; /* Base address */
22 + uint8_t id_bits; /* number of bits in an ID for this table */
23 + uint8_t l2_idx_bits; /* number of ID bits that index into L2 table */
24 + uint8_t istsz; /* L2 ISTE size in bytes */
25 + bool structure; /* true if using 2-level table */
26 + bool valid; /* true if this table is valid and usable */
27 +} GICv5ISTConfig;
28 +
29 /*
30 * This class is for TCG-specific state for the GICv5.
31 */
32 struct GICv5 {
33 GICv5Common parent_obj;
34 +
35 + /* This is the info from IRS_IST_BASER and IRS_IST_CFGR */
36 + GICv5ISTConfig phys_lpi_config[NUM_GICV5_DOMAINS];
37 };
38
39 struct GICv5Class {