mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Leo Yu-Chi Liang <leo.liang@sifive.com>
To: Mayuresh Chitale <mchitale@gmail.com>,
	Anup Patel <anup@brainfault.org>,  Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>,
	Paul Walmsley <pjw@kernel.org>,
	 Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	 Alexandre Ghiti <alex@ghiti.fr>,
	Samuel Holland <samuel.holland@sifive.com>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org,
	 linux-kernel@vger.kernel.org,
	Leo Yu-Chi Liang <leo.liang@sifive.com>,
	 linmin@eswincomputing.com, vincent.chen@sifive.com,
	 luyulin@eswincomputing.com, pritesh.patel@einfochips.com,
	 ganboing@gmail.com, dongxuyang@eswincomputing.com,
	 pinkesh.vaghela@einfochips.com, nick.hu@sifive.com,
	eric.lin@sifive.com,  huangyifeng@eswincomputing.com,
	darshan.prajapati@einfochips.com
Subject: [PATCH 08/10] gtrace: rvtrace: Introduce struct rvtrace_ramsink_regs to abstract register offsets
Date: Thu, 26 Nov 2026 01:07:14 -0800	[thread overview]
Message-ID: <20261126-send-preratified-trace-v1-8-1e686fd75be7@sifive.com> (raw)
In-Reply-To: <20261126-send-preratified-trace-v1-0-1e686fd75be7@sifive.com>

From: Eric Lin <eric.lin@sifive.com>

The pre-ratified trace ramsink implementation uses different register
offsets compared to the ratified RISC-V trace specification. To allow
the pre-ratified trace ramsink to leverage the rvtrace ramsink setup
and copy functions, introduce 'struct rvtrace_ramsink_regs'. This
abstracts the register map, enabling both pre-ratified and ratified
trace hardware to provide their own register layouts.

The read/write pair helpers no longer assume that the high register
is located right after the low register, and take both offsets.

Co-developed-by: Nick Hu <nick.hu@sifive.com>
Signed-off-by: Nick Hu <nick.hu@sifive.com>
Co-developed-by: Vincent Chen <vincent.chen@sifive.com>
Signed-off-by: Vincent Chen <vincent.chen@sifive.com>
Signed-off-by: Eric Lin <eric.lin@sifive.com>
Signed-off-by: Leo Yu-Chi Liang <leo.liang@sifive.com>
---
 drivers/hwtracing/gtrace/rvtrace-ramsink.c | 69 ++++++++++++++++++++++++------
 1 file changed, 56 insertions(+), 13 deletions(-)

diff --git a/drivers/hwtracing/gtrace/rvtrace-ramsink.c b/drivers/hwtracing/gtrace/rvtrace-ramsink.c
index 52aeb7626a55..a164db57167f 100644
--- a/drivers/hwtracing/gtrace/rvtrace-ramsink.c
+++ b/drivers/hwtracing/gtrace/rvtrace-ramsink.c
@@ -15,8 +15,11 @@
 #include "rvtrace.h"
 
 #define RVTRACE_RAMSINK_STARTLOW_OFF		0x010
+#define RVTRACE_RAMSINK_STARTHIGH_OFF		0x014
 #define RVTRACE_RAMSINK_LIMITLOW_OFF		0x018
+#define RVTRACE_RAMSINK_LIMITHIGH_OFF		0x01c
 #define RVTRACE_RAMSINK_WPLOW_OFF		0x020
+#define RVTRACE_RAMSINK_WPHIGH_OFF		0x024
 #define RVTRACE_RAMSINK_WPLOW_WRAP		0x1
 #define RVTRACE_RAMSINK_CTRL_MODE_MASK		0x1
 #define RVTRACE_RAMSINK_CTRL_MODE_SHIFT		0x4
@@ -33,7 +36,39 @@ enum rvtrace_ramsink_mode {
 	MODE_SMEM
 };
 
+/**
+ * struct rvtrace_ramsink_regs - Register offsets for RAM sink implementations
+ * @start_low:  Offset of the start address low register
+ * @start_high: Offset of the start address high register
+ * @limit_low:  Offset of the limit address low register
+ * @limit_high: Offset of the limit address high register
+ * @wp_low:     Offset of the write pointer low register
+ * @wp_high:    Offset of the write pointer high register
+ *
+ * Different RAM sink implementations may have different register layouts.
+ * This structure allows the common code to work with any layout.
+ */
+struct rvtrace_ramsink_regs {
+	u32 start_low;
+	u32 start_high;
+	u32 limit_low;
+	u32 limit_high;
+	u32 wp_low;
+	u32 wp_high;
+};
+
+/* Register offsets for the standard RISC-V trace ramsink */
+static const struct rvtrace_ramsink_regs rvtrace_std_ramsink_regs = {
+	.start_low	= RVTRACE_RAMSINK_STARTLOW_OFF,
+	.start_high	= RVTRACE_RAMSINK_STARTHIGH_OFF,
+	.limit_low	= RVTRACE_RAMSINK_LIMITLOW_OFF,
+	.limit_high	= RVTRACE_RAMSINK_LIMITHIGH_OFF,
+	.wp_low		= RVTRACE_RAMSINK_WPLOW_OFF,
+	.wp_high	= RVTRACE_RAMSINK_WPHIGH_OFF,
+};
+
 struct rvtrace_ramsink_priv {
+	const struct rvtrace_ramsink_regs *regs;
 	size_t size;
 	void *va;
 	dma_addr_t start;
@@ -56,20 +91,22 @@ struct trace_buf {
 };
 
 /* Helper to access start, limit, wp pair registers */
-static u64 rvtrace_ramsink_read_pair(struct gtrace_platform_data *pdata, u32 low_off)
+static u64 rvtrace_ramsink_read_pair(struct gtrace_platform_data *pdata,
+				     u32 low_off, u32 high_off)
 {
 	u32 low, high;
 
 	low = gtrace_read32(pdata, low_off);
-	high = gtrace_read32(pdata, low_off + 4);
+	high = gtrace_read32(pdata, high_off);
 
 	return (u64)high << 32 | low;
 }
 
-static void rvtrace_ramsink_write_pair(struct gtrace_platform_data *pdata, u64 val, u32 low_off)
+static void rvtrace_ramsink_write_pair(struct gtrace_platform_data *pdata, u64 val,
+				       u32 low_off, u32 high_off)
 {
 	gtrace_write32(pdata, lower_32_bits(val), low_off);
-	gtrace_write32(pdata, upper_32_bits(val), low_off + 4);
+	gtrace_write32(pdata, upper_32_bits(val), high_off);
 }
 
 static int rvtrace_ramsink_start(struct gtrace_path_node *node)
@@ -152,6 +189,7 @@ static size_t rvtrace_ramsink_copyto_auxbuf(struct gtrace_component *comp,
 					    u64 *format)
 {
 	struct rvtrace_ramsink_priv *priv = dev_get_drvdata(&comp->dev);
+	const struct rvtrace_ramsink_regs *regs = priv->regs;
 	struct trace_buf src, dst;
 	size_t bytes = 0;
 	bool wrap;
@@ -163,12 +201,13 @@ static size_t rvtrace_ramsink_copyto_auxbuf(struct gtrace_component *comp,
 	src.base = priv->va;
 	src.len = priv->size;
 	*format = PERF_AUX_FLAG_GTRACE_FORMAT_ETRACE;
-	wp = rvtrace_ramsink_read_pair(comp->pdata, RVTRACE_RAMSINK_WPLOW_OFF);
+	wp = rvtrace_ramsink_read_pair(comp->pdata, regs->wp_low, regs->wp_high);
 	wrap = wp & RVTRACE_RAMSINK_WPLOW_WRAP;
 	wp &= ~RVTRACE_RAMSINK_WPLOW_WRAP;
 
 	if (wrap) {
-		rvtrace_ramsink_write_pair(comp->pdata, priv->start, RVTRACE_RAMSINK_WPLOW_OFF);
+		rvtrace_ramsink_write_pair(comp->pdata, priv->start,
+					   regs->wp_low, regs->wp_high);
 		src.cur = wp - priv->start;
 		priv->prev_wp = priv->start;
 		/*
@@ -191,13 +230,14 @@ static size_t rvtrace_ramsink_copyto_auxbuf(struct gtrace_component *comp,
 static int rvtrace_ramsink_setup_buf(struct gtrace_component *comp,
 				     struct rvtrace_ramsink_priv *priv)
 {
+	const struct rvtrace_ramsink_regs *regs = priv->regs;
 	struct device *pdev = comp->pdata->dev;
 	u64 limit_max, end;
 	int ret;
 
 	/* Probe max value for limit register */
-	rvtrace_ramsink_write_pair(comp->pdata, U64_MAX, RVTRACE_RAMSINK_LIMITLOW_OFF);
-	limit_max = rvtrace_ramsink_read_pair(comp->pdata, RVTRACE_RAMSINK_LIMITLOW_OFF);
+	rvtrace_ramsink_write_pair(comp->pdata, U64_MAX, regs->limit_low, regs->limit_high);
+	limit_max = rvtrace_ramsink_read_pair(comp->pdata, regs->limit_low, regs->limit_high);
 	if (!limit_max) {
 		dev_err(&comp->dev, "trRamLimit register not implemented\n");
 		return -EINVAL;
@@ -218,13 +258,14 @@ static int rvtrace_ramsink_setup_buf(struct gtrace_component *comp,
 	 * Check if DMA start and end addresses allocated by the kernel can be set in the ramsink
 	 * start, limit registers respectively.
 	 */
-	rvtrace_ramsink_write_pair(comp->pdata, priv->alloc_start, RVTRACE_RAMSINK_STARTLOW_OFF);
+	rvtrace_ramsink_write_pair(comp->pdata, priv->alloc_start,
+				   regs->start_low, regs->start_high);
 	/* Limit address needs to be set to end - mem_access_width to avoid overflow */
 	end = priv->alloc_start + priv->alloc_size - priv->mem_acc_width;
-	rvtrace_ramsink_write_pair(comp->pdata, end, RVTRACE_RAMSINK_LIMITLOW_OFF);
+	rvtrace_ramsink_write_pair(comp->pdata, end, regs->limit_low, regs->limit_high);
 
-	priv->start = rvtrace_ramsink_read_pair(comp->pdata, RVTRACE_RAMSINK_STARTLOW_OFF);
-	priv->end = rvtrace_ramsink_read_pair(comp->pdata, RVTRACE_RAMSINK_LIMITLOW_OFF) +
+	priv->start = rvtrace_ramsink_read_pair(comp->pdata, regs->start_low, regs->start_high);
+	priv->end = rvtrace_ramsink_read_pair(comp->pdata, regs->limit_low, regs->limit_high) +
 		    priv->mem_acc_width;
 
 	/* Sanity check start, end addresses */
@@ -245,7 +286,7 @@ static int rvtrace_ramsink_setup_buf(struct gtrace_component *comp,
 	priv->va = priv->alloc_va + (priv->start - priv->alloc_start);
 	priv->size = priv->end - priv->start;
 	priv->prev_wp = priv->start;
-	rvtrace_ramsink_write_pair(comp->pdata, priv->start, RVTRACE_RAMSINK_WPLOW_OFF);
+	rvtrace_ramsink_write_pair(comp->pdata, priv->start, regs->wp_low, regs->wp_high);
 
 	return 0;
 
@@ -275,6 +316,8 @@ static int rvtrace_ramsink_setup(struct gtrace_component *comp)
 		break;
 	}
 
+	priv->regs = &rvtrace_std_ramsink_regs;
+
 	if (priv->mode != MODE_SMEM) {
 		dev_err(&comp->dev, "only smem mode is supported\n");
 		return -EOPNOTSUPP;

-- 
2.43.7


  parent reply	other threads:[~2026-11-26  9:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  9:07 [PATCH 00/10] gtrace: Add support for SiFive pre-ratified RISC-V trace components Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 01/10] dt-bindings: riscv: Add SiFive pre-ratified " Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 02/10] gtrace: rvtrace: Add pre-ratified implementation callback Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 03/10] gtrace: rvtrace: Add pre-ratified private data callback Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 04/10] gtrace: rvtrace: Add pre-ratified encoder support Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 05/10] gtrace: Terminate id_table iteration on GTRACE_COMPONENT_TYPE_NONE Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 06/10] gtrace: rvtrace: Add pre-ratified trace sink config Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 07/10] gtrace: rvtrace: Add pre-ratified trace funnel driver Leo Yu-Chi Liang
2026-11-26  9:07 ` Leo Yu-Chi Liang [this message]
2026-11-26  9:07 ` [PATCH 09/10] gtrace: rvtrace: Add pre-ratified ramsink setup Leo Yu-Chi Liang
2026-11-26  9:07 ` [PATCH 10/10] gtrace: rvtrace: Add copyto_auxbuf callback for pre-ratified encoder and funnel Leo Yu-Chi Liang

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=20261126-send-preratified-trace-v1-8-1e686fd75be7@sifive.com \
    --to=leo.liang@sifive.com \
    --cc=alex@ghiti.fr \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=anup@brainfault.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=conor+dt@kernel.org \
    --cc=darshan.prajapati@einfochips.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dongxuyang@eswincomputing.com \
    --cc=eric.lin@sifive.com \
    --cc=ganboing@gmail.com \
    --cc=huangyifeng@eswincomputing.com \
    --cc=krzk+dt@kernel.org \
    --cc=linmin@eswincomputing.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=luyulin@eswincomputing.com \
    --cc=mchitale@gmail.com \
    --cc=nick.hu@sifive.com \
    --cc=palmer@dabbelt.com \
    --cc=pinkesh.vaghela@einfochips.com \
    --cc=pjw@kernel.org \
    --cc=pritesh.patel@einfochips.com \
    --cc=robh@kernel.org \
    --cc=samuel.holland@sifive.com \
    --cc=vincent.chen@sifive.com \
    /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

all inboxes | Powered by JetHome®