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 06/10] gtrace: rvtrace: Add pre-ratified trace sink config
Date: Thu, 26 Nov 2026 01:07:12 -0800 [thread overview]
Message-ID: <20261126-send-preratified-trace-v1-6-1e686fd75be7@sifive.com> (raw)
In-Reply-To: <20261126-send-preratified-trace-v1-0-1e686fd75be7@sifive.com>
From: Eric Lin <eric.lin@sifive.com>
To decide which sink to send trace data to, pre-ratified trace
hardware (eg., SiFive, Eswin) sets a sink bitfield directly within the
current component's control MMIO register.
Routing trace data from a source to an output component requires
configuring the connections between components, and the mechanism
varies between hardware implementations:
- Standard (ratified) RISC-V trace configures routing at the
receiving end. For example, a funnel uses the trFunnelDisInput
register to control which source input is accepted.
- Pre-ratified hardware configures routing at the sending end,
selecting the output destination by setting a bitfield directly
within the current component's control MMIO register.
To support both, component drivers need the path topology when
starting, rather than just the component itself, so update the
gtrace_driver start() callback to take a struct gtrace_path_node.
Introduce rvtrace_v0_sink_config() for pre-ratified trace hardware to
configure the destination sink based on the hardware capabilities and
the current trace path before starting the trace.
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/gtrace-core.c | 13 +++------
drivers/hwtracing/gtrace/rvtrace-encoder.c | 10 ++++++-
drivers/hwtracing/gtrace/rvtrace-ramsink.c | 3 ++-
drivers/hwtracing/gtrace/rvtrace-v0.c | 43 ++++++++++++++++++++++++++++++
drivers/hwtracing/gtrace/rvtrace-v0.h | 23 ++++++++++++++++
include/linux/gtrace.h | 19 +++++++++++--
6 files changed, 98 insertions(+), 13 deletions(-)
diff --git a/drivers/hwtracing/gtrace/gtrace-core.c b/drivers/hwtracing/gtrace/gtrace-core.c
index 09b200bd1690..6fe71c5cd0cf 100644
--- a/drivers/hwtracing/gtrace/gtrace-core.c
+++ b/drivers/hwtracing/gtrace/gtrace-core.c
@@ -498,12 +498,6 @@ void gtrace_unregister_component(struct gtrace_component *comp)
}
EXPORT_SYMBOL_GPL(gtrace_unregister_component);
-struct gtrace_path_node {
- struct list_head head;
- struct gtrace_component *comp;
- struct gtrace_connection *conn;
-};
-
struct gtrace_component *gtrace_path_source(struct gtrace_path *path)
{
struct gtrace_path_node *node;
@@ -621,8 +615,9 @@ static void gtrace_release_path_nodes(struct gtrace_path *path)
}
}
-static int __gtrace_comp_start(struct gtrace_component *comp, pid_t owner)
+static int __gtrace_comp_start(struct gtrace_path_node *node, pid_t owner)
{
+ struct gtrace_component *comp = node->comp;
struct gtrace_comp_priv *cpriv = to_gtrace_comp_priv(comp);
const struct gtrace_driver *gtdrv = to_gtrace_driver(comp->dev.driver);
unsigned long flags;
@@ -639,7 +634,7 @@ static int __gtrace_comp_start(struct gtrace_component *comp, pid_t owner)
}
} else {
if (gtdrv->start) {
- ret = gtdrv->start(comp);
+ ret = gtdrv->start(node);
if (ret)
goto out;
}
@@ -686,7 +681,7 @@ int gtrace_path_start(struct gtrace_path *path)
int ret = 0;
list_for_each_entry_reverse(node, &path->comp_list, head) {
- ret = __gtrace_comp_start(node->comp, path->owner);
+ ret = __gtrace_comp_start(node, path->owner);
if (ret)
break;
}
diff --git a/drivers/hwtracing/gtrace/rvtrace-encoder.c b/drivers/hwtracing/gtrace/rvtrace-encoder.c
index 0a23c78c0caf..92672f1e7098 100644
--- a/drivers/hwtracing/gtrace/rvtrace-encoder.c
+++ b/drivers/hwtracing/gtrace/rvtrace-encoder.c
@@ -155,8 +155,9 @@ static int rvtrace_encoder_probe(struct gtrace_component *comp)
return 0;
}
-static int rvtrace_encoder_start(struct gtrace_component *comp)
+static int rvtrace_encoder_start(struct gtrace_path_node *node)
{
+ struct gtrace_component *comp = node->comp;
struct rvtrace_encoder_priv *priv = dev_get_drvdata(&comp->dev);
struct gtrace_platform_data *pdata = comp->pdata;
int ret;
@@ -171,6 +172,13 @@ static int rvtrace_encoder_start(struct gtrace_component *comp)
dev_err(&comp->dev, "failed to set format %d\n", pdata->format);
return ret;
}
+ } else {
+ /* Set pre-ratified comp's next sink */
+ ret = rvtrace_v0_sink_config(node);
+ if (ret) {
+ dev_err(&comp->dev, "failed to set next sink.\n");
+ return ret;
+ }
}
ret = gtrace_enable_component(comp);
diff --git a/drivers/hwtracing/gtrace/rvtrace-ramsink.c b/drivers/hwtracing/gtrace/rvtrace-ramsink.c
index 67b6779aacee..52aeb7626a55 100644
--- a/drivers/hwtracing/gtrace/rvtrace-ramsink.c
+++ b/drivers/hwtracing/gtrace/rvtrace-ramsink.c
@@ -72,8 +72,9 @@ static void rvtrace_ramsink_write_pair(struct gtrace_platform_data *pdata, u64 v
gtrace_write32(pdata, upper_32_bits(val), low_off + 4);
}
-static int rvtrace_ramsink_start(struct gtrace_component *comp)
+static int rvtrace_ramsink_start(struct gtrace_path_node *node)
{
+ struct gtrace_component *comp = node->comp;
struct rvtrace_ramsink_priv *priv = dev_get_drvdata(&comp->dev);
u32 trram_ctrl;
int ret;
diff --git a/drivers/hwtracing/gtrace/rvtrace-v0.c b/drivers/hwtracing/gtrace/rvtrace-v0.c
index 01e62642c245..c9254e71a972 100644
--- a/drivers/hwtracing/gtrace/rvtrace-v0.c
+++ b/drivers/hwtracing/gtrace/rvtrace-v0.c
@@ -5,10 +5,53 @@
#include <linux/device.h>
#include <linux/err.h>
+#include <linux/export.h>
#include <linux/gtrace.h>
#include "rvtrace.h"
#include "rvtrace-v0.h"
+/*
+ * Pre-ratified trace hardware selects the destination of the trace data
+ * with the teSink/tfSink field in the component's own control register,
+ * i.e. routing is configured at the sending end. The destination is
+ * derived from the trace path: the last node of the path (no outgoing
+ * connection) writes to system memory (SBA), otherwise the component
+ * feeds the funnel the path connection leads to.
+ */
+int rvtrace_v0_sink_config(struct gtrace_path_node *node)
+{
+ struct gtrace_component *comp = node->comp;
+ struct gtrace_platform_data *pdata = comp->pdata;
+ struct rvtrace_v0_comp_features *data = comp->id.data;
+ struct gtrace_component *next;
+ u32 val;
+
+ if (!data)
+ return -EINVAL;
+
+ val = gtrace_read32(pdata, RVTRACE_COMPONENT_CTRL_OFFSET);
+ val &= ~RVTRACE_V0_CTRL_SINK_MASK;
+
+ if (!node->conn) {
+ /* Last node in the path */
+ if (data->has_sba_sink)
+ val |= TE_SINK_SBA << RVTRACE_V0_CTRL_SINK_SHIFT;
+ else
+ dev_warn(&comp->dev,
+ "Component is last node but doesn't support SBA sink\n");
+ } else {
+ next = node->conn->dest_comp;
+ if (next && next->id.type == GTRACE_RVTRACE_FUNNEL &&
+ data->has_funnel_sink)
+ val |= TE_SINK_FUNNEL << RVTRACE_V0_CTRL_SINK_SHIFT;
+ }
+
+ gtrace_write32(pdata, val, RVTRACE_COMPONENT_CTRL_OFFSET);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(rvtrace_v0_sink_config);
+
void *rvtrace_v0_get_comp_data(struct gtrace_platform_data *pdata)
{
struct rvtrace_v0_comp_features *data;
diff --git a/drivers/hwtracing/gtrace/rvtrace-v0.h b/drivers/hwtracing/gtrace/rvtrace-v0.h
index 5abdc4788f64..d1dac2034a14 100644
--- a/drivers/hwtracing/gtrace/rvtrace-v0.h
+++ b/drivers/hwtracing/gtrace/rvtrace-v0.h
@@ -10,6 +10,7 @@
#include <linux/gtrace.h>
#include <linux/bits.h>
+#include <linux/errno.h>
#include <linux/types.h>
#define RVTRACE_V0_IMPL_HAS_SRAM_SINK_BIT 4
@@ -24,6 +25,19 @@
#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)
+/* teControl/tfControl sink selection */
+#define RVTRACE_V0_CTRL_SINK_SHIFT 28
+#define RVTRACE_V0_CTRL_SINK_MASK GENMASK(31, RVTRACE_V0_CTRL_SINK_SHIFT)
+
+enum rvtrace_v0_sink {
+ TE_SINK_DEFAULT = 0,
+ TE_SINK_SRAM = 4,
+ TE_SINK_ATB = 5,
+ TE_SINK_PIB = 6,
+ TE_SINK_SBA = 7,
+ TE_SINK_FUNNEL = 8,
+};
+
/* 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
@@ -40,4 +54,13 @@ u32 rvtrace_v0_get_encoder_impl(struct gtrace_platform_data *pdata);
u32 rvtrace_v0_get_funnel_impl(struct gtrace_platform_data *pdata);
void *rvtrace_v0_get_comp_data(struct gtrace_platform_data *pdata);
+#ifdef CONFIG_RVTRACE_V0
+int rvtrace_v0_sink_config(struct gtrace_path_node *node);
+#else
+static inline int rvtrace_v0_sink_config(struct gtrace_path_node *node)
+{
+ return -EOPNOTSUPP;
+}
+#endif
+
#endif /* __RVTRACE_V0_H__ */
diff --git a/include/linux/gtrace.h b/include/linux/gtrace.h
index b8826b25d35a..6b2ff2a63694 100644
--- a/include/linux/gtrace.h
+++ b/include/linux/gtrace.h
@@ -258,6 +258,18 @@ struct gtrace_path {
pid_t owner;
};
+/**
+ * struct gtrace_path_node - Representation of a node in the trace path.
+ * @head: List head for linking nodes in the path.
+ * @comp: Pointer to the trace component at this node.
+ * @conn: Pointer to the connection leading to the next node (NULL for sink).
+ */
+struct gtrace_path_node {
+ struct list_head head;
+ struct gtrace_component *comp;
+ struct gtrace_connection *conn;
+};
+
struct gtrace_component *gtrace_path_source(struct gtrace_path *path);
struct gtrace_component *gtrace_path_sink(struct gtrace_path *path);
struct gtrace_path *gtrace_create_path(struct gtrace_component *source,
@@ -291,7 +303,10 @@ int gtrace_path_copyto_auxbuf(struct gtrace_path *path,
* @copyto_auxbuf: Callback to copy data into perf AUX buffer. The driver
* reports the PMU specific trace format of the copied data
* via @format (see PERF_AUX_FLAG_PMU_FORMAT_TYPE_MASK).
- * @start: Callback to start tracing.
+ * @start: Callback to start tracing. The path node gives access to
+ * the component and to the connection leading to the next
+ * component of the path, so that drivers can program their
+ * routing registers.
* @stop: Callback to stop tracing.
* @probe: Driver probe() function.
* @remove: Driver remove() function.
@@ -304,7 +319,7 @@ struct gtrace_driver {
size_t (*copyto_auxbuf)(struct gtrace_component *comp,
struct gtrace_perf_auxbuf *buf,
u64 *format);
- int (*start)(struct gtrace_component *comp);
+ int (*start)(struct gtrace_path_node *node);
int (*stop)(struct gtrace_component *comp);
int (*probe)(struct gtrace_component *comp);
void (*remove)(struct gtrace_component *comp);
--
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 ` [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 ` Leo Yu-Chi Liang [this message]
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-6-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®