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 04/10] gtrace: rvtrace: Add pre-ratified encoder support
Date: Thu, 26 Nov 2026 01:07:10 -0800 [thread overview]
Message-ID: <20261126-send-preratified-trace-v1-4-1e686fd75be7@sifive.com> (raw)
In-Reply-To: <20261126-send-preratified-trace-v1-0-1e686fd75be7@sifive.com>
From: Eric Lin <eric.lin@sifive.com>
Add pre-ratified version support to the encoder driver. This allows
pre-ratified trace hardware to leverage the gtrace driver framework.
The pre-ratified encoder has a different register layout for the
source ID: the SRC field width (nSrcBits) and value are preset by
hardware in teImpl, while offset 0x8 is the read-only teImplExtra
register rather than trTeInstFeatures. Add rvtrace_comp_is_v0() and,
for pre-ratified encoders, derive srcbits from teImpl and skip
programming the trTeInstFeatures source ID fields.
Another difference is the encoding of the trTeInstMode field,
so set the corresponding "Optimized intruction trace" for
the pre-ratified encoder.
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-encoder.c | 42 +++++++++++++++++++++++++-----
drivers/hwtracing/gtrace/rvtrace-v0.h | 4 +++
drivers/hwtracing/gtrace/rvtrace.h | 6 +++++
3 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/drivers/hwtracing/gtrace/rvtrace-encoder.c b/drivers/hwtracing/gtrace/rvtrace-encoder.c
index 1f06b1a2b412..0a23c78c0caf 100644
--- a/drivers/hwtracing/gtrace/rvtrace-encoder.c
+++ b/drivers/hwtracing/gtrace/rvtrace-encoder.c
@@ -11,6 +11,9 @@
#include <linux/slab.h>
#include <linux/types.h>
#include "rvtrace.h"
+#include "rvtrace-v0.h"
+
+#define RVTRACE_V0_COMPONENT_CTRL_INSTMODE_OPIT 0x7
#define RVTRACE_COMPONENT_CTRL_ITRACE_SHIFT 2
#define RVTRACE_COMPONENT_CTRL_INSTMODE_MASK 0x7
@@ -95,6 +98,23 @@ static int rvtrace_encoder_probe(struct gtrace_component *comp)
if (!priv)
return -ENOMEM;
+ if (rvtrace_comp_is_v0(comp)) {
+ /*
+ * Pre-ratified encoders have the SRC field width and value preset
+ * by hardware in teImpl. Offset 0x8 is the read-only teImplExtra
+ * register rather than trTeInstFeatures, so don't program it.
+ */
+ val = gtrace_read32(pdata, RVTRACE_COMPONENT_IMPL_OFFSET);
+ priv->srcbits = (val >> RVTRACE_V0_IMPL_NSRCBITS_SHIFT) &
+ RVTRACE_V0_IMPL_NSRCBITS_MASK;
+ if (priv->srcbits) {
+ val = gtrace_read32(pdata, RVTRACE_COMPONENT_CTRL_OFFSET);
+ val &= ~BIT(RVTRACE_COMPONENT_CTRL_INHIBITSRC_SHIFT);
+ gtrace_write32(pdata, val, RVTRACE_COMPONENT_CTRL_OFFSET);
+ }
+ goto out;
+ }
+
ret = rvtrace_encoder_set_format(pdata);
if (ret) {
dev_err(&comp->dev, "failed to set format %d\n", pdata->format);
@@ -123,6 +143,7 @@ static int rvtrace_encoder_probe(struct gtrace_component *comp)
priv->srcbits = srcbits;
}
}
+out:
if (!priv->srcbits) {
dev_warn(&comp->dev, "cpu %d trace will not carry source id\n",
pdata->bound_cpu);
@@ -141,13 +162,15 @@ static int rvtrace_encoder_start(struct gtrace_component *comp)
int ret;
u32 val;
- if (priv->srcbits)
- rvtrace_encoder_set_srcid(pdata, priv->srcbits);
+ if (!rvtrace_comp_is_v0(comp)) {
+ if (priv->srcbits)
+ rvtrace_encoder_set_srcid(pdata, priv->srcbits);
- ret = rvtrace_encoder_set_format(pdata);
- if (ret) {
- dev_err(&comp->dev, "failed to set format %d\n", pdata->format);
- return ret;
+ ret = rvtrace_encoder_set_format(pdata);
+ if (ret) {
+ dev_err(&comp->dev, "failed to set format %d\n", pdata->format);
+ return ret;
+ }
}
ret = gtrace_enable_component(comp);
@@ -159,7 +182,10 @@ static int rvtrace_encoder_start(struct gtrace_component *comp)
/* set mode */
val = gtrace_read32(pdata, RVTRACE_COMPONENT_CTRL_OFFSET);
val &= ~(RVTRACE_COMPONENT_CTRL_INSTMODE_MASK << RVTRACE_COMPONENT_CTRL_INSTMODE_SHIFT);
- val |= (RVTRACE_COMPONENT_CTRL_INSTMODE_OPIT << RVTRACE_COMPONENT_CTRL_INSTMODE_SHIFT);
+ if (!rvtrace_comp_is_v0(comp))
+ val |= (RVTRACE_COMPONENT_CTRL_INSTMODE_OPIT << RVTRACE_COMPONENT_CTRL_INSTMODE_SHIFT);
+ else
+ val |= (RVTRACE_V0_COMPONENT_CTRL_INSTMODE_OPIT << RVTRACE_COMPONENT_CTRL_INSTMODE_SHIFT);
gtrace_write32(pdata, val, RVTRACE_COMPONENT_CTRL_OFFSET);
val = gtrace_read32(pdata, RVTRACE_COMPONENT_CTRL_OFFSET);
@@ -204,6 +230,8 @@ static int rvtrace_encoder_stop(struct gtrace_component *comp)
static const struct gtrace_component_id rvtrace_encoder_ids[] = {
{ .type = GTRACE_RVTRACE_ENCODER,
.version = rvtrace_component_mkversion(1, 0), },
+ { .type = GTRACE_RVTRACE_ENCODER,
+ .version = rvtrace_component_mkversion(0, 0), },
{},
};
diff --git a/drivers/hwtracing/gtrace/rvtrace-v0.h b/drivers/hwtracing/gtrace/rvtrace-v0.h
index 0681405fa414..5abdc4788f64 100644
--- a/drivers/hwtracing/gtrace/rvtrace-v0.h
+++ b/drivers/hwtracing/gtrace/rvtrace-v0.h
@@ -24,6 +24,10 @@
#define RVTRACE_V0_IMPL_HAS_SBA_SINK_MASK BIT(RVTRACE_V0_IMPL_HAS_SBA_SINK_BIT)
#define RVTRACE_V0_IMPL_HAS_FUNNEL_SINK_MASK BIT(RVTRACE_V0_IMPL_HAS_FUNNEL_SINK_BIT)
+/* Number of SRC bits preset by hardware in the Nexus messages */
+#define RVTRACE_V0_IMPL_NSRCBITS_SHIFT 24
+#define RVTRACE_V0_IMPL_NSRCBITS_MASK 0xf
+
struct rvtrace_v0_comp_features {
bool has_sram_sink;
bool has_atb_sink;
diff --git a/drivers/hwtracing/gtrace/rvtrace.h b/drivers/hwtracing/gtrace/rvtrace.h
index b0cf2e1d875f..308de9fe39ae 100644
--- a/drivers/hwtracing/gtrace/rvtrace.h
+++ b/drivers/hwtracing/gtrace/rvtrace.h
@@ -72,6 +72,12 @@ enum rvtrace_component_impid {
#define rvtrace_component_mkversion(__major, __minor) \
((((__major) & 0xffff) << 16) | ((__minor) & 0xffff))
+/* Pre-ratified (version 0.x) components are identified by major version 0 */
+static inline bool rvtrace_comp_is_v0(struct gtrace_component *comp)
+{
+ return rvtrace_component_version_major(comp->id.version) == 0;
+}
+
/* Map a RISC-V hardware component type to the global gtrace type */
static inline int rvtrace_type_to_gtrace(enum rvtrace_component_type type)
{
--
2.43.7
next prev 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 ` Leo Yu-Chi Liang [this message]
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 ` [PATCH 08/10] gtrace: rvtrace: Introduce struct rvtrace_ramsink_regs to abstract register offsets Leo Yu-Chi Liang
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-4-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®