OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Evgenii Prokopiev <eestelle0626@gmail.com>
To: opensbi@lists.infradead.org
Cc: Evgenii Prokopiev <eestelle0626@gmail.com>
Subject: [PATCH] lib: sbi_hart: Reset mhpmcounter after probing its bits
Date: Thu, 10 Sep 2026 21:02:17 +0300	[thread overview]
Message-ID: <20260910180217.3256-1-eestelle0626@gmail.com> (raw)

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

                 reply	other threads:[~2026-09-10 18:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260910180217.3256-1-eestelle0626@gmail.com \
    --to=eestelle0626@gmail.com \
    --cc=opensbi@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox