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 02/10] gtrace: rvtrace: Add pre-ratified implementation callback
Date: Thu, 26 Nov 2026 01:07:08 -0800 [thread overview]
Message-ID: <20261126-send-preratified-trace-v1-2-1e686fd75be7@sifive.com> (raw)
In-Reply-To: <20261126-send-preratified-trace-v1-0-1e686fd75be7@sifive.com>
From: Eric Lin <eric.lin@sifive.com>
For pre-ratified trace hardware, the implementation register
bitfields differ from the ratified RISC-V trace specification,
and the component type is not defined in the hardware
implementation register.
To address this, add a get_impl() callback function in the
driver data to translate the pre-ratified trace hardware
implementation register information and encode it into the
standard RISC-V trace implementation register format.
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/Kconfig | 12 ++++++++++
drivers/hwtracing/gtrace/Makefile | 4 +++-
drivers/hwtracing/gtrace/rvtrace-platform.c | 36 ++++++++++++++++++++++++++---
drivers/hwtracing/gtrace/rvtrace-v0.c | 34 +++++++++++++++++++++++++++
drivers/hwtracing/gtrace/rvtrace-v0.h | 17 ++++++++++++++
drivers/hwtracing/gtrace/rvtrace.h | 12 ++++++++++
6 files changed, 111 insertions(+), 4 deletions(-)
diff --git a/drivers/hwtracing/gtrace/Kconfig b/drivers/hwtracing/gtrace/Kconfig
index e5b62d65e2fd..b1f9ca8f73cb 100644
--- a/drivers/hwtracing/gtrace/Kconfig
+++ b/drivers/hwtracing/gtrace/Kconfig
@@ -57,3 +57,15 @@ config RVTRACE_RAMSINK
To compile this driver as a module, choose M here: the module
will be called rvtrace-ramsink.
+
+config RVTRACE_V0
+ bool "RISC-V pre-ratified trace support"
+ depends on RVTRACE
+ select RVTRACE_ENCODER
+ select RVTRACE_RAMSINK
+ default y
+ help
+ This provides support for pre-ratified (version 0.x) RISC-V trace
+ hardware, such as the SiFive trace encoder and trace funnel, whose
+ register layout differs from the RISC-V Trace Control Interface
+ specification.
diff --git a/drivers/hwtracing/gtrace/Makefile b/drivers/hwtracing/gtrace/Makefile
index 33274a1ed0b8..0a2e2d1732c2 100644
--- a/drivers/hwtracing/gtrace/Makefile
+++ b/drivers/hwtracing/gtrace/Makefile
@@ -4,6 +4,8 @@ obj-$(CONFIG_GTRACE) += gtrace.o
gtrace-y := gtrace-core.o gtrace-perf.o
gtrace-$(CONFIG_OF) += gtrace-of.o
-obj-$(CONFIG_RVTRACE) += rvtrace-platform.o
+obj-$(CONFIG_RVTRACE) += rvtrace.o
+rvtrace-y := rvtrace-platform.o
+rvtrace-$(CONFIG_RVTRACE_V0) += rvtrace-v0.o
obj-$(CONFIG_RVTRACE_ENCODER) += rvtrace-encoder.o
obj-$(CONFIG_RVTRACE_RAMSINK) += rvtrace-ramsink.o
diff --git a/drivers/hwtracing/gtrace/rvtrace-platform.c b/drivers/hwtracing/gtrace/rvtrace-platform.c
index a5655e983e51..8c1503bd8d98 100644
--- a/drivers/hwtracing/gtrace/rvtrace-platform.c
+++ b/drivers/hwtracing/gtrace/rvtrace-platform.c
@@ -11,6 +11,7 @@
#include <linux/property.h>
#include <linux/types.h>
#include "rvtrace.h"
+#include "rvtrace-v0.h"
static int rvtrace_hw_enable(struct gtrace_platform_data *pdata)
{
@@ -62,6 +63,7 @@ const struct gtrace_hw_ops rvtrace_hw_ops = {
static int rvtrace_platform_probe(struct platform_device *pdev)
{
+ const struct rvtrace_match_data *match_data;
struct gtrace_platform_data *pdata;
struct device *dev = &pdev->dev;
struct gtrace_component_id id;
@@ -72,13 +74,17 @@ static int rvtrace_platform_probe(struct platform_device *pdev)
int gtype;
int ret;
+ match_data = device_get_match_data(dev);
+ if (!match_data)
+ return -ENODEV;
+
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
pdata->dev = dev;
pdata->impid = RVTRACE_COMPONENT_IMPID_UNKNOWN;
pdata->hw_ops = &rvtrace_hw_ops;
- pdata->format = (uintptr_t)device_get_match_data(dev);
+ pdata->format = match_data->format;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
@@ -115,7 +121,11 @@ static int rvtrace_platform_probe(struct platform_device *pdev)
if (ret)
return dev_err_probe(dev, ret, "failed to reset component\n");
- impl = gtrace_read32(pdata, RVTRACE_COMPONENT_IMPL_OFFSET);
+ if (match_data->get_impl)
+ impl = match_data->get_impl(pdata);
+ else
+ impl = gtrace_read32(pdata, RVTRACE_COMPONENT_IMPL_OFFSET);
+
type = (impl >> RVTRACE_COMPONENT_IMPL_TYPE_SHIFT) &
RVTRACE_COMPONENT_IMPL_TYPE_MASK;
major = (impl >> RVTRACE_COMPONENT_IMPL_VERMAJOR_SHIFT) &
@@ -154,8 +164,28 @@ static void rvtrace_platform_remove(struct platform_device *pdev)
gtrace_unregister_component(comp);
}
+static const struct rvtrace_match_data rvtrace_std_data = {
+ .format = GTRACE_FORMAT_ETRACE,
+};
+
+#ifdef CONFIG_RVTRACE_V0
+static const struct rvtrace_match_data rvtrace_v0_encoder_data = {
+ .format = GTRACE_FORMAT_NTRACE,
+ .get_impl = rvtrace_v0_get_encoder_impl,
+};
+
+static const struct rvtrace_match_data rvtrace_v0_funnel_data = {
+ .format = GTRACE_FORMAT_NTRACE,
+ .get_impl = rvtrace_v0_get_funnel_impl,
+};
+#endif
+
static const struct of_device_id rvtrace_platform_match[] = {
- { .compatible = "riscv,trace-component", .data = (void *)GTRACE_FORMAT_ETRACE },
+ { .compatible = "riscv,trace-component", .data = &rvtrace_std_data },
+#ifdef CONFIG_RVTRACE_V0
+ { .compatible = "sifive,trace-encoder0", .data = &rvtrace_v0_encoder_data },
+ { .compatible = "sifive,trace-funnel0", .data = &rvtrace_v0_funnel_data },
+#endif
{}
};
diff --git a/drivers/hwtracing/gtrace/rvtrace-v0.c b/drivers/hwtracing/gtrace/rvtrace-v0.c
new file mode 100644
index 000000000000..a5ca9001bc08
--- /dev/null
+++ b/drivers/hwtracing/gtrace/rvtrace-v0.c
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2026 SiFive Inc.
+ */
+
+#include <linux/gtrace.h>
+#include "rvtrace.h"
+#include "rvtrace-v0.h"
+
+static u32 rvtrace_v0_get_impl(struct gtrace_platform_data *pdata,
+ enum rvtrace_component_type type)
+{
+ u32 impl, major, minor;
+
+ impl = gtrace_read32(pdata, RVTRACE_COMPONENT_IMPL_OFFSET);
+ major = 0;
+ minor = (impl >> RVTRACE_COMPONENT_IMPL_VERMAJOR_SHIFT) &
+ RVTRACE_COMPONENT_IMPL_VERMAJOR_MASK;
+
+ /* Encode to standard rvtrace impl format */
+ return (type << RVTRACE_COMPONENT_IMPL_TYPE_SHIFT) |
+ (minor << RVTRACE_COMPONENT_IMPL_VERMINOR_SHIFT) |
+ (major << RVTRACE_COMPONENT_IMPL_VERMAJOR_SHIFT);
+}
+
+u32 rvtrace_v0_get_encoder_impl(struct gtrace_platform_data *pdata)
+{
+ return rvtrace_v0_get_impl(pdata, RVTRACE_COMPONENT_TYPE_ENCODER);
+}
+
+u32 rvtrace_v0_get_funnel_impl(struct gtrace_platform_data *pdata)
+{
+ return rvtrace_v0_get_impl(pdata, RVTRACE_COMPONENT_TYPE_FUNNEL);
+}
diff --git a/drivers/hwtracing/gtrace/rvtrace-v0.h b/drivers/hwtracing/gtrace/rvtrace-v0.h
new file mode 100644
index 000000000000..2d83c87936b9
--- /dev/null
+++ b/drivers/hwtracing/gtrace/rvtrace-v0.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2026 SiFive, Inc.
+ *
+ * Support for pre-ratified (version 0.x) RISC-V trace components.
+ */
+
+#ifndef __RVTRACE_V0_H__
+#define __RVTRACE_V0_H__
+
+#include <linux/gtrace.h>
+#include <linux/types.h>
+
+u32 rvtrace_v0_get_encoder_impl(struct gtrace_platform_data *pdata);
+u32 rvtrace_v0_get_funnel_impl(struct gtrace_platform_data *pdata);
+
+#endif /* __RVTRACE_V0_H__ */
diff --git a/drivers/hwtracing/gtrace/rvtrace.h b/drivers/hwtracing/gtrace/rvtrace.h
index e6be1ce303cc..7f9e88d99b8f 100644
--- a/drivers/hwtracing/gtrace/rvtrace.h
+++ b/drivers/hwtracing/gtrace/rvtrace.h
@@ -109,6 +109,18 @@ static inline const char *rvtrace_type_name(enum gtrace_component_type type)
}
}
+/**
+ * struct rvtrace_match_data - Per-compatible data for RISC-V trace components
+ * @format: Trace format to be used by the component.
+ * @get_impl: Optional callback to retrieve the implementation register value
+ * encoded in the standard RISC-V trace IMPL register format. Used
+ * by pre-ratified components whose IMPL register layout differs.
+ */
+struct rvtrace_match_data {
+ enum gtrace_format format;
+ u32 (*get_impl)(struct gtrace_platform_data *pdata);
+};
+
static inline int rvtrace_comp_poll_empty(struct gtrace_component *comp)
{
return gtrace_poll_bit(comp->pdata, RVTRACE_COMPONENT_CTRL_OFFSET,
--
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 ` Leo Yu-Chi Liang [this message]
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 ` [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-2-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®