aboutsummaryrefslogtreecommitdiff
path: root/lib/utils/timer/fdt_timer_mtimer.c
diff options
context:
space:
mode:
authorBenoît Monin <benoit.monin@bootlin.com>2025-11-07 11:46:57 +0100
committerAnup Patel <anup@brainfault.org>2025-11-10 13:41:53 +0530
commit5de1d3240f9163de95bc6803fb4100a77d65ab6b (patch)
tree0bac4da1c4d8e8c6a8f94a8c3c72eb5bb1a68226 /lib/utils/timer/fdt_timer_mtimer.c
parent38a6106b1099646f25657bba53cefb80886721a7 (diff)
downloadopensbi-5de1d3240f9163de95bc6803fb4100a77d65ab6b.tar.gz
opensbi-5de1d3240f9163de95bc6803fb4100a77d65ab6b.tar.bz2
opensbi-5de1d3240f9163de95bc6803fb4100a77d65ab6b.zip
lib: utils/timer: mtimer: Select the reference mtimer from a DT property
The current selection of the reference MTIMER may fail in some setup. In a multi-cluster configuration, there is one MTIMER per cluster, each associated with the HARTS of the cluster. So we do not have a MTIMER with no associated HARTs to use as our reference. To be able to select a reference MTIMER in that case, look up an optional device tree property named "riscv,reference-mtimer" that indicate which MTIMER is the reference. Signed-off-by: Benoît Monin <benoit.monin@bootlin.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20251107-p8700-aclint-v3-1-93eabb17d54e@bootlin.com Signed-off-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'lib/utils/timer/fdt_timer_mtimer.c')
-rw-r--r--lib/utils/timer/fdt_timer_mtimer.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/utils/timer/fdt_timer_mtimer.c b/lib/utils/timer/fdt_timer_mtimer.c
index e1fd0519..1f29f3a2 100644
--- a/lib/utils/timer/fdt_timer_mtimer.c
+++ b/lib/utils/timer/fdt_timer_mtimer.c
@@ -39,6 +39,7 @@ static int timer_mtimer_cold_init(const void *fdt, int nodeoff,
struct aclint_mtimer_data *mt;
const struct timer_mtimer_quirks *quirks = match->data;
bool is_clint = quirks && quirks->is_clint;
+ bool is_ref = false;
mtn = sbi_zalloc(sizeof(*mtn));
if (!mtn)
@@ -110,13 +111,16 @@ static int timer_mtimer_cold_init(const void *fdt, int nodeoff,
}
/*
- * Select first MTIMER device with no associated HARTs as our
- * reference MTIMER device. This is only a temporary strategy
- * of selecting reference MTIMER device. In future, we might
- * define an optional DT property or some other mechanism to
- * help us select the reference MTIMER device.
+ * If we have a DT property to indicate which MTIMER is the reference,
+ * select the first MTIMER device that has it. Otherwise, select the
+ * first MTIMER device with no associated HARTs as our reference.
*/
- if (!mt->hart_count && !mt_reference) {
+ if (fdt_getprop(fdt, nodeoff, "riscv,reference-mtimer", NULL))
+ is_ref = true;
+ else if (!mt->hart_count)
+ is_ref = true;
+
+ if (is_ref && !mt_reference) {
mt_reference = mt;
/*
* Set reference for already propbed MTIMER devices