OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mayuresh Chitale <mchitale@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH v3 7/8] lib: sbi_pmu: Introduce fw_counter_write_value API
Date: Thu,  9 Mar 2023 11:21:11 +0530	[thread overview]
Message-ID: <20230309055112.1516581-8-mchitale@ventanamicro.com> (raw)
In-Reply-To: <20230309055112.1516581-1-mchitale@ventanamicro.com>

Add fw_counter_write_value API for platform specific firmware events
which separates setting the counter's initial value from starting the
counter. This is required so that the fw_event_data array can be reused
to save the event data received.

Signed-off-by: Mayuresh Chitale <mchitale@ventanamicro.com>
---
 include/sbi/sbi_pmu.h | 11 ++++++++---
 lib/sbi/sbi_pmu.c     | 25 +++++++++++++------------
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/include/sbi/sbi_pmu.h b/include/sbi/sbi_pmu.h
index 3232e14..53f2700 100644
--- a/include/sbi/sbi_pmu.h
+++ b/include/sbi/sbi_pmu.h
@@ -51,14 +51,19 @@ struct sbi_pmu_device {
 	 */
 	uint64_t (*fw_counter_read_value)(uint32_t counter_index);
 
+	/**
+	 * Write value to custom firmware counter
+	 * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX
+	 */
+	void (*fw_counter_write_value)(uint32_t counter_index,
+				       uint64_t value);
+
 	/**
 	 * Start custom firmware counter
-	 * Note: SBI_PMU_FW_MAX <= event_idx_code
 	 * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX
 	 */
 	int (*fw_counter_start)(uint32_t counter_index,
-				uint64_t event_data,
-				uint64_t init_val, bool init_val_update);
+				uint64_t event_data);
 
 	/**
 	 * Stop custom firmware counter
diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c
index d083198..00a2c3e 100644
--- a/lib/sbi/sbi_pmu.c
+++ b/lib/sbi/sbi_pmu.c
@@ -376,7 +376,6 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code,
 			    uint64_t event_data, uint64_t ival,
 			    bool ival_update)
 {
-	int ret;
 	u32 hartid = current_hartid();
 
 	if ((event_code >= SBI_PMU_FW_MAX &&
@@ -386,19 +385,22 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code,
 
 	if (SBI_PMU_FW_PLATFORM == event_code) {
 		if (!pmu_dev ||
+		    !pmu_dev->fw_counter_write_value ||
 		    !pmu_dev->fw_counter_start) {
 			return SBI_EINVAL;
 		    }
 
-		ret = pmu_dev->fw_counter_start(cidx - num_hw_ctrs,
-						event_data,
-						ival, ival_update);
-		if (ret)
-			return ret;
+		if (ival_update)
+			pmu_dev->fw_counter_write_value(cidx - num_hw_ctrs,
+							ival);
+
+		return pmu_dev->fw_counter_start(cidx - num_hw_ctrs,
+						 event_data);
+	} else {
+		if (ival_update)
+			fw_counters_data[hartid][cidx - num_hw_ctrs] = ival;
 	}
 
-	if (ival_update)
-		fw_counters_data[hartid][cidx - num_hw_ctrs] = ival;
 	fw_counters_started[hartid] |= BIT(cidx - num_hw_ctrs);
 
 	return 0;
@@ -762,10 +764,9 @@ skip_match:
 		if (flags & SBI_PMU_CFG_FLAG_AUTO_START) {
 			if (SBI_PMU_FW_PLATFORM == event_code &&
 			    pmu_dev && pmu_dev->fw_counter_start) {
-				ret = pmu_dev->fw_counter_start(
-					ctr_idx - num_hw_ctrs, event_data,
-					fw_counters_data[hartid][ctr_idx - num_hw_ctrs],
-					true);
+				ret = pmu_dev->fw_counter_start(ctr_idx -
+								num_hw_ctrs,
+								event_data);
 				if (ret)
 					return ret;
 			}
-- 
2.34.1



  parent reply	other threads:[~2023-03-09  5:51 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-09  5:51 [PATCH v3 0/8] SBI PMU firmware counters and events improvement Mayuresh Chitale
2023-03-09  5:51 ` [PATCH v3 1/8] lib: sbi_pmu: add callback for counter width Mayuresh Chitale
2023-03-09  6:18   ` Anup Patel
2023-03-09  5:51 ` [PATCH v3 2/8] lib: sbi_pmu: Implement sbi_pmu_counter_fw_read_hi Mayuresh Chitale
2023-03-09  6:18   ` Anup Patel
2023-03-09  5:51 ` [PATCH v3 3/8] lib: sbi_pmu: Reserve space for implementation specific firmware events Mayuresh Chitale
2023-03-09  6:19   ` Anup Patel
2023-03-09  9:16   ` Andrew Jones
2023-03-09 12:30     ` mchitale
2023-03-09  5:51 ` [PATCH v3 4/8] lib: sbi_pmu: Rename fw_counter_value Mayuresh Chitale
2023-03-09  6:19   ` Anup Patel
2023-03-09  9:19   ` Andrew Jones
2023-03-09  5:51 ` [PATCH v3 5/8] lib: sbi_pmu: Update sbi_pmu dev ops Mayuresh Chitale
2023-03-09  6:21   ` Anup Patel
2023-03-09  5:51 ` [PATCH v3 6/8] lib: sbi_pmu: Use dedicated event code for platform firmware events Mayuresh Chitale
2023-03-09  6:28   ` Anup Patel
2023-03-09 12:33     ` mchitale
2023-03-09  5:51 ` Mayuresh Chitale [this message]
2023-03-09  6:31   ` [PATCH v3 7/8] lib: sbi_pmu: Introduce fw_counter_write_value API Anup Patel
2023-03-09  5:51 ` [PATCH v3 8/8] lib: sbi_pmu: Add hartid parameter PMU device ops Mayuresh Chitale
2023-03-09  6:32   ` Anup Patel

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=20230309055112.1516581-8-mchitale@ventanamicro.com \
    --to=mchitale@ventanamicro.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