Skip to content

Commit 8e936e9

Browse files
committed
RISC-V: KVM: Fix APLIC in_clrip[x] read emulation
The reads to APLIC in_clrip[x] registers returns rectified input values of the interrupt sources. A rectified input value of an interrupt source is defined by the section "4.5.2 Source configurations (sourcecfg[1]–sourcecfg[1023])" of the RISC-V AIA specification as: rectified input value = (incoming wire value) XOR (source is inverted) Update the riscv_aplic_input() implementation to match the above. Cc: [email protected] Fixes: 74967aa ("RISC-V: KVM: Add in-kernel emulation of AIA APLIC") Signed-off-by: Anup Patel <[email protected]> Signed-off-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d8dd9f1 commit 8e936e9

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

arch/riscv/kvm/aia_aplic.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,31 @@ static void aplic_write_enabled(struct aplic *aplic, u32 irq, bool enabled)
197197

198198
static bool aplic_read_input(struct aplic *aplic, u32 irq)
199199
{
200-
bool ret;
201-
unsigned long flags;
200+
u32 sourcecfg, sm, raw_input, irq_inverted;
202201
struct aplic_irq *irqd;
202+
unsigned long flags;
203+
bool ret = false;
203204

204205
if (!irq || aplic->nr_irqs <= irq)
205206
return false;
206207
irqd = &aplic->irqs[irq];
207208

208209
raw_spin_lock_irqsave(&irqd->lock, flags);
209-
ret = (irqd->state & APLIC_IRQ_STATE_INPUT) ? true : false;
210+
211+
sourcecfg = irqd->sourcecfg;
212+
if (sourcecfg & APLIC_SOURCECFG_D)
213+
goto skip;
214+
215+
sm = sourcecfg & APLIC_SOURCECFG_SM_MASK;
216+
if (sm == APLIC_SOURCECFG_SM_INACTIVE)
217+
goto skip;
218+
219+
raw_input = (irqd->state & APLIC_IRQ_STATE_INPUT) ? 1 : 0;
220+
irq_inverted = (sm == APLIC_SOURCECFG_SM_LEVEL_LOW ||
221+
sm == APLIC_SOURCECFG_SM_EDGE_FALL) ? 1 : 0;
222+
ret = !!(raw_input ^ irq_inverted);
223+
224+
skip:
210225
raw_spin_unlock_irqrestore(&irqd->lock, flags);
211226

212227
return ret;

0 commit comments

Comments
 (0)