All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib: sbi_hart: Reset mhpmcounter after probing its bits
@ 2026-09-10 18:02 Evgenii Prokopiev
  0 siblings, 0 replies; only message in thread
From: Evgenii Prokopiev @ 2026-09-10 18:02 UTC (permalink / raw)
  To: opensbi; +Cc: Evgenii Prokopiev

Writting mhpmcounter3 (and 3H) to determine the allowed bit width
has a side effect: the counter starts counting.

Explicitly clear the counter right after the probe so the probing
writes do not leave any persistent hardware side effect.

Signed-off-by: Evgenii Prokopiev <eestelle0626@gmail.com>
---
 lib/sbi/sbi_hart.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index bee88557..a413bfe0 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -448,6 +448,7 @@ static int hart_mhpm_get_allowed_bits(void)
 	csr_write_allowed(CSR_MHPMCOUNTER3, &trap, val);
 	if (!trap.cause) {
 		val = csr_read_allowed(CSR_MHPMCOUNTER3, &trap);
+		csr_write(CSR_MHPMCOUNTER3, 0);
 		if (trap.cause)
 			return 0;
 	}
@@ -456,6 +457,7 @@ static int hart_mhpm_get_allowed_bits(void)
 	csr_write_allowed(CSR_MHPMCOUNTER3H, &trap, val);
 	if (!trap.cause) {
 		val = csr_read_allowed(CSR_MHPMCOUNTER3H, &trap);
+		csr_write(CSR_MHPMCOUNTER3H, 0);
 		if (trap.cause)
 			return num_bits;
 	}
-- 
2.50.1 (Apple Git-155)


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-10 18:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-10 18:02 [PATCH] lib: sbi_hart: Reset mhpmcounter after probing its bits Evgenii Prokopiev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.