diff --git a/sys/arch/arm64/dev/agtimer.c b/sys/arch/arm64/dev/agtimer.c index d5700a13f71..9e54031936b 100644 --- a/sys/arch/arm64/dev/agtimer.c +++ b/sys/arch/arm64/dev/agtimer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agtimer.c,v 1.29 2025/01/31 16:46:41 kettenis Exp $ */ +/* $OpenBSD: agtimer.c,v 1.30 2026/05/04 20:43:41 kettenis Exp $ */ /* * Copyright (c) 2011 Dale Rahn * Copyright (c) 2013 Patrick Wildt @@ -289,7 +289,9 @@ agtimer_set_clockrate(int32_t new_frequency) void agtimer_cpu_initclocks(void) { - struct agtimer_softc *sc = agtimer_cd.cd_devs[0]; + struct agtimer_softc *sc = agtimer_cd.cd_devs[0]; + uint64_t el; + int idx; stathz = hz; profhz = stathz * 10; @@ -299,8 +301,20 @@ agtimer_cpu_initclocks(void) agtimer_set_clockrate(agtimer_frequency); } + /* Pick the correct PPI depending on the running EL. */ + el = READ_SPECIALREG(CurrentEL) & CURRENTEL_EL_MASK; + if (el == CURRENTEL_EL_EL2) { + idx = OF_getindex(sc->sc_node, "hyp-virt", "interrupt-names"); + if (idx == -1) + idx = 4; + } else { + idx = OF_getindex(sc->sc_node, "virt", "interrupt-names"); + if (idx == -1) + idx = 2; + } + /* configure virtual timer interrupt */ - sc->sc_ih = arm_intr_establish_fdt_idx(sc->sc_node, 2, + sc->sc_ih = arm_intr_establish_fdt_idx(sc->sc_node, idx, IPL_CLOCK|IPL_MPSAFE, agtimer_intr, NULL, "tick"); } diff --git a/sys/arch/arm64/include/armreg.h b/sys/arch/arm64/include/armreg.h index 6f45879676a..fefcb935aea 100644 --- a/sys/arch/arm64/include/armreg.h +++ b/sys/arch/arm64/include/armreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: armreg.h,v 1.44 2025/07/22 09:20:41 kettenis Exp $ */ +/* $OpenBSD: armreg.h,v 1.45 2026/05/04 20:43:42 kettenis Exp $ */ /*- * Copyright (c) 2013, 2014 Andrew Turner * Copyright (c) 2015 The FreeBSD Foundation @@ -119,6 +119,14 @@ #define CTR_ILINE_MASK (0xf << CTR_ILINE_SHIFT) #define CTR_ILINE_SIZE(reg) (((reg) & CTR_ILINE_MASK) >> CTR_ILINE_SHIFT) +/* CurrentEL - Current Exception Level */ +#define CURRENTEL_EL_SHIFT 2 +#define CURRENTEL_EL_MASK (0x3 << CURRENTEL_EL_SHIFT) +#define CURRENTEL_EL_EL0 (0x0 << CURRENTEL_EL_SHIFT) +#define CURRENTEL_EL_EL1 (0x1 << CURRENTEL_EL_SHIFT) +#define CURRENTEL_EL_EL2 (0x2 << CURRENTEL_EL_SHIFT) +#define CURRENTEL_EL_EL3 (0x3 << CURRENTEL_EL_SHIFT) + /* MPIDR_EL1 - Multiprocessor Affinity Register */ #define MPIDR_AFF3 (0xFFULL << 32) #define MPIDR_AFF2 (0xFFULL << 16)