arm: GICv5: minor fixes
cover arm: GICv5: minor fixes
This patchset has some fixes for minor GICv5 issues that I noticed while I've been working on the GICv5 virtualization support:
- 2 actual (but minor) bugs
- the GICv5 spec now has a final URL we can cite
- a minor cleanup of how we say "no pending interrupt"
- the ICC_HAPR_EL1 register is removed in the latest version of the spec, so we can drop it from our implementation
thanks
-- PMM
Peter Maydell (5):
arm/gicv5: Add URL to GICv5 specification
target/arm: GICv5 cpuif: Recalculate IRQ/FIQ on ICC_PCR_EL1 write target/arm: GICv5 cpuif: Tag ICC_PPI_PRIORITYR<n> regs as
ARM_CP_NO_RAW
target/arm: GICv5 cpuif: Remove ICC_HAPR_EL1 hw/intc/gicv5: Define and use GICV5_PENDING_IRQ_NONE
hw/intc/arm_gicv5.c | 11 +++++++---- include/hw/intc/arm_gicv5_types.h | 4 ++++ target/arm/tcg/gicv5-cpuif.c | 29 ++++++++++------------------- 3 files changed, 21 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/5 arm/gicv5: Add URL to GICv5 specification
The GICv5 specification has now been assigned its final document ID for a rev A.a spec version. This seems like a good point to add a pointer to the spec to the main source files.
--- hw/intc/arm_gicv5.c | 5 +++++ target/arm/tcg/gicv5-cpuif.c | 5 +++++ 2 files changed, 10 insertions(+)
hw/intc/arm_gicv5.c +5 -0
@@ -4,6 +4,11 @@* Copyright (c) 2025 Linaro Limited * * SPDX-License-Identifier: GPL-2.0-or-later +* +* The IRS is defined in IHI 111701 +* (ARM Generic Interrupt Controller Architecture Specification, +* GIC architecture version 5): +* https://developer.arm.com/documentation/111701/latest */ #include "qemu/osdep.h"
target/arm/tcg/gicv5-cpuif.c +5 -0
@@ -4,6 +4,11 @@* Copyright (c) 2025 Linaro Limited * * SPDX-License-Identifier: GPL-2.0-or-later +* +* The cpu interface is defined in IHI 111701 +* (ARM Generic Interrupt Controller Architecture Specification, +* GIC architecture version 5): +* https://developer.arm.com/documentation/111701/latest */ #include "qemu/osdep.h"
Signature · 1 line
2.43.0
Re: [PATCH 1/5] arm/gicv5: Add URL to GICv5 specification
Quoted 9 lines · Peter Maydell
The GICv5 specification has now been assigned its final document ID for a rev A.a spec version. This seems like a good point to add a pointer to the spec to the main source files.
Signed-off-by Peter Maydell <[email protected]>--- hw/intc/arm_gicv5.c | 5 +++++ target/arm/tcg/gicv5-cpuif.c | 5 +++++ 2 files changed, 10 insertions(+)
PATCH 2/5 target/arm: GICv5 cpuif: Recalculate IRQ/FIQ on ICC_PCR_EL1 write
In reply to Peter MaydellWhen the guest writes ICC_PCR_EL1 we should recheck whether we should be signalling IRQ or FIQ, because we use this priority mask value in determining whether the highest priority interrupt should be signalled or not.
--- target/arm/tcg/gicv5-cpuif.c | 1 + 1 file changed, 1 insertion(+)
target/arm/tcg/gicv5-cpuif.c +1 -0
@@ -565,6 +565,7 @@ static void gic_icc_pcr_el1_write(CPUARMState *env, const ARMCPRegInfo *ri, value &=R_ICC_PCR_PRIORITY_MASK ; env->gicv5_cpuif.icc_pcr[domain] = value; +gicv5_update_irq_fiq (env); }static void gic_icc_pcr_el1_reset (CPUARMState *env,const ARMCPRegInfo *ri)
Signature · 1 line
2.43.0
Re: [PATCH 2/5] target/arm: GICv5 cpuif: Recalculate IRQ/FIQ on ICC_PCR_EL1 write
Quoted 10 lines · Peter Maydell
When the guest writes
ICC_PCR_EL1we should recheck whether we should be signalling IRQ or FIQ, because we use this priority mask value in determining whether the highest priority interrupt should be signalled or not.Fixes 9bd90bddb79b ("target/arm: GICv5 cpuif: Signal IRQ or FIQ")Signed-off-by Peter Maydell <[email protected]>--- target/arm/tcg/gicv5-cpuif.c | 1 + 1 file changed, 1 insertion(+)
PATCH 3/5 target/arm: GICv5 cpuif: Tag ICC_PPI_PRIORITYR<n> regs as ARM_CP_NO_RAW
In reply to Peter MaydellThe GICv5 system registers are all tagged with ARM_CP_NO_RAW, because we don't want them to use the standard mechanisms for migration or KVM state synchronization. (GICv5 handling of both migration and KVM support is a "will be implemented later" feature.) We missed this tag on the ICC_PPI_PRIORITYR<n>_EL1 registers; add it.
--- target/arm/tcg/gicv5-cpuif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/tcg/gicv5-cpuif.c +1 -1
@@ -950,7 +950,7 @@ void define_gicv5_cpuif_regs(ARMCPU *cpu) .name = name, .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 14 + (i >> 3), .opc2 = i & 7, - .access = PL1_RW, .type = ARM_CP_IO, + .access = PL1_RW, .type = ARM_CP_IO | ARM_CP_NO_RAW, .fieldoffset = offsetof(CPUARMState, gicv5_cpuif.ppi_priority[i]), .writefn = gic_ppi_priority_write, .raw_writefn = raw_write, };
Signature · 1 line
2.43.0
Re: [PATCH 3/5] target/arm: GICv5 cpuif: Tag ICC_PPI_PRIORITYR<n> regs as ARM_CP_NO_RAW
Quoted 11 lines · Peter Maydell
The GICv5 system registers are all tagged with
ARM_CP_NO_RAW, because we don't want them to use the standard mechanisms for migration or KVM state synchronization. (GICv5 handling of both migration and KVM support is a "will be implemented later" feature.) We missed this tag on the ICC_PPI_PRIORITYR<n>_EL1 registers; add it.Fixes ef540c1d301 ("target/arm: GICv5 cpuif: Implement PPI priority registers")Signed-off-by Peter Maydell <[email protected]>--- target/arm/tcg/gicv5-cpuif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 4/5 target/arm: GICv5 cpuif: Remove ICC_HAPR_EL1
In reply to Peter MaydellThe ICC_HAPR_EL1 register reported the current running priority of the CPU. However this can be easily calculated by reading the APR register, so it has been removed in the newly released A.a version of the GICv5 spec (IHI 111701).
Remove QEMU's implementation of this register. (This is OK for us to do without warning because our GICv5 support is listed as "experimental"; we anticipated that this kind of spec change might happen.)
--- target/arm/tcg/gicv5-cpuif.c | 14 -------------- 1 file changed, 14 deletions(-)
target/arm/tcg/gicv5-cpuif.c +0 -14
@@ -511,15 +511,6 @@ static void gic_icc_apr_el1_reset(CPUARMState *env, const ARMCPRegInfo *ri) } } -static uint64_t gic_icc_hapr_el1_read (CPUARMState *env,const ARMCPRegInfo *ri) -{ -/* -* ICC_HAPR_EL1 reports the current running priority, which can be -* calculated from the APR register. -*/ -return gic_running_prio (env,gicv5_current_phys_domain (env)); -} -/* ICC_CR0_EL1 is also banked */ static uint64_t gic_icc_cr0_el1_read (CPUARMState *env,const ARMCPRegInfo *ri) {
@@ -928,11 +919,6 @@ static const ARMCPRegInfo gicv5_cpuif_reginfo[] = { .writefn = gic_icc_pcr_el1_write, .resetfn = gic_icc_pcr_el1_reset, }, - { .name = "ICC_HAPR_EL1", .state = ARM_CP_STATE_AA64, - .opc0 = 3, .opc1 = 1, .crn = 12, .crm = 0, .opc2 = 3, - .access = PL1_R, .type = ARM_CP_IO | ARM_CP_NO_RAW, - .readfn = gic_icc_hapr_el1_read, .raw_writefn = arm_cp_write_ignore, - }, };void define_gicv5_cpuif_regs (ARMCPU *cpu)
Signature · 1 line
2.43.0
Re: [PATCH 4/5] target/arm: GICv5 cpuif: Remove ICC_HAPR_EL1
Quoted 10 lines · Peter Maydell
The
ICC_HAPR_EL1register reported the current running priority of the CPU. However this can be easily calculated by reading the APR register, so it has been removed in the newly released A.a version of the GICv5 spec (IHI 111701).Remove QEMU's implementation of this register. (This is OK for us to do without warning because our GICv5 support is listed as "experimental"; we anticipated that this kind of spec change might happen.)
Quoted 4 lines
Signed-off-by Peter Maydell <[email protected]>--- target/arm/tcg/gicv5-cpuif.c | 14 -------------- 1 file changed, 14 deletions(-)
PATCH 5/5 hw/intc/gicv5: Define and use GICV5_PENDING_IRQ_NONE
In reply to Peter MaydellThe GICv5PendingIrq struct representation of "there is no pending interrupt" sets the prio field to PRIO_IDLE, and generally to avoid confusion we also set the intid to 0. We want to return this value or initialize some variable to it in several places in the GICv5 implementation, and the support for the virtual interrupt domain introduces more.
Define a convenience macro for this special-case struct value, and use it instead of opencoding either the structure initializer or explicit assignment to the two fields.
--- hw/intc/arm_gicv5.c | 6 ++---- include/hw/intc/arm_gicv5_types.h | 4 ++++ target/arm/tcg/gicv5-cpuif.c | 7 +++---- 3 files changed, 9 insertions(+), 8 deletions(-)
hw/intc/arm_gicv5.c +2 -4
@@ -429,8 +429,7 @@ static void irs_recalc_hppi(GICv5 *s, GICv5Domain domain, uint32_t iaffid)ARMCPU *cpu = cpuidx >=0 ? cs->cpus[cpuidx] :NULL ;GICv5PendingIrq best; - best.intid =0 ; - best.prio =PRIO_IDLE ; + best =GICV5_PENDING_IRQ_NONE ;if (!cpu) {/* Nothing happens for iaffids targeting nonexistent CPUs */
@@ -526,8 +525,7 @@ static void irs_recall_hppis(GICv5 *s, GICv5Domain domain)GICv5Common *cs =ARM_GICV5_COMMON (s);for (int i =0 ; i < cs->num_cpus; i++) { - s->hppi[domain][i].intid =0 ; - s->hppi[domain][i].prio =PRIO_IDLE ; + s->hppi[domain][i] =GICV5_PENDING_IRQ_NONE ;gicv5_forward_interrupt (cs->cpus[i], domain); } }
include/hw/intc/arm_gicv5_types.h +4 -0
@@ -105,6 +105,10 @@ typedef struct GICv5PendingIrq {uint8_t prio; } GICv5PendingIrq; +/* A GICv5PendingIrq struct initializer for "no pending interrupt" */ +#define GICV5_PENDING_IRQ_NONE \ + ((GICv5PendingIrq) { .intid = 0, .prio = PRIO_IDLE }) +/* Fields in a generic 32-bit INTID, per R_TJPHS */ FIELD(INTID, ID, 0, 24)FIELD (INTID ,TYPE ,29 ,3 )
target/arm/tcg/gicv5-cpuif.c +3 -4
@@ -144,7 +144,7 @@ static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain)if (!(env->gicv5_cpuif.icc_cr0[domain] &R_ICC_CR0_EN_MASK )) {/* If cpuif is disabled there is no HPPI */ -return (GICv5PendingIrq ) { .intid =0 , .prio =PRIO_IDLE }; +return GICV5_PENDING_IRQ_NONE ; } irs_hppi =gicv5_get_hppi (gic, domain, env->gicv5_iaffid);
@@ -168,7 +168,7 @@ static GICv5PendingIrq gic_hppi(CPUARMState *env, GICv5Domain domain)if (best.prio ==PRIO_IDLE || best.prio > env->gicv5_cpuif.icc_pcr[domain] || best.prio >=gic_running_prio (env, domain)) { -return (GICv5PendingIrq ) { .intid =0 , .prio =PRIO_IDLE }; +return GICV5_PENDING_IRQ_NONE ; }return best; }
@@ -258,8 +258,7 @@ static void gic_recalc_ppi_hppi(CPUARMState *env)* enabled, pending and not active. */ for (int i =0 ; i <ARRAY_SIZE (env->gicv5_cpuif.ppi_hppi); i++) { - env->gicv5_cpuif.ppi_hppi[i].intid =0 ; - env->gicv5_cpuif.ppi_hppi[i].prio =PRIO_IDLE ; + env->gicv5_cpuif.ppi_hppi[i] =GICV5_PENDING_IRQ_NONE ; };for (int i =0 ; i <ARRAY_SIZE (env->gicv5_cpuif.ppi_active); i++) {
Signature · 1 line
2.43.0
Re: [PATCH 5/5] hw/intc/gicv5: Define and use GICV5_PENDING_IRQ_NONE
Quoted 11 lines · Peter Maydell
The GICv5PendingIrq struct representation of "there is no pending interrupt" sets the prio field to
PRIO_IDLE, and generally to avoid confusion we also set the intid to 0. We want to return this value or initialize some variable to it in several places in the GICv5 implementation, and the support for the virtual interrupt domain introduces more.Define a convenience macro for this special-case struct value, and use it instead of opencoding either the structure initializer or explicit assignment to the two fields.
Quoted 6 lines
Signed-off-by Peter Maydell <[email protected]>--- hw/intc/arm_gicv5.c | 6 ++---- include/hw/intc/arm_gicv5_types.h | 4 ++++ target/arm/tcg/gicv5-cpuif.c | 7 +++---- 3 files changed, 9 insertions(+), 8 deletions(-)
Quoted 7 lines · Peter Maydell
Peter Maydell (5):
arm/gicv5: Add URL to GICv5 specification
target/arm: GICv5 cpuif: Recalculate IRQ/FIQ onICC_PCR_EL1write target/arm: GICv5 cpuif: Tag ICC_PPI_PRIORITYR<n> regs as
ARM_CP_NO_RAW
target/arm: GICv5 cpuif: RemoveICC_HAPR_EL1hw/intc/gicv5: Define and useGICV5_PENDING_IRQ_NONE
r~