From: Vikram Singh <vikram.singh3@oss.qualcomm.com>
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
namhyung@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
irogers@google.com, adrian.hunter@intel.com,
paul.walmsley@sifive.com, palmer@dabbelt.com,
aou@eecs.berkeley.edu, alex@ghiti.fr, atishp@rivosinc.com,
anup.patel@oss.qualcomm.com, will@kernel.org, robh@kernel.org,
krzk+dt@kernel.org, conor+dt@kernel.org, beeman@rivosinc.com
Cc: Vikram Singh <vikram.singh3@oss.qualcomm.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-riscv@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
Conor Dooley <conor@kernel.org>,
devicetree@vger.kernel.org,
Rajnesh Kanwal <rajnesh.kanwal49@gmail.com>,
Anup Patel <anup@brainfault.org>
Subject: [PATCH v5 2/7] riscv: pmu: Add Control transfer records CSR definations.
Date: Wed, 18 Nov 2026 15:20:48 +0530 [thread overview]
Message-ID: <20261118095053.3871267-3-vikram.singh3@oss.qualcomm.com> (raw)
In-Reply-To: <20261118095053.3871267-1-vikram.singh3@oss.qualcomm.com>
Adding CSR defines for RISCV Control Transfer Records extension [0]
along with bit-field macros for each CSR.
[0]: https://github.com/riscv/riscv-control-transfer-records
Co-developed-by: Rajnesh Kanwal <rajnesh.kanwal49@gmail.com>
Signed-off-by: Rajnesh Kanwal <rajnesh.kanwal49@gmail.com>
Signed-off-by: Vikram Singh <vikram.singh3@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20261106173942.3175069-3-vikram.singh3@oss.qualcomm.com
Signed-off-by: Anup Patel <anup@brainfault.org>
---
arch/riscv/include/asm/csr.h | 95 ++++++++++++++++++++++++++++++++++++
1 file changed, 95 insertions(+)
diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h
index 621f84d1898f..063351d9b406 100644
--- a/arch/riscv/include/asm/csr.h
+++ b/arch/riscv/include/asm/csr.h
@@ -350,6 +350,97 @@
#define CSR_SCOUNTOVF 0xda0
+/* M-mode Control Transfer Records CSRs */
+#define CSR_MCTRCTL 0x34e
+
+/* S-mode Control Transfer Records CSRs */
+#define CSR_SCTRCTL 0x14e
+#define CSR_SCTRSTATUS 0x14f
+#define CSR_SCTRDEPTH 0x15f
+
+/* VS-mode Control Transfer Records CSRs */
+#define CSR_VSCTRCTL 0x24e
+
+/* xctrtl CSR bits. */
+#define CTRCTL_U_ENABLE _AC(0x1, UL)
+#define CTRCTL_S_ENABLE _AC(0x2, UL)
+#define CTRCTL_M_ENABLE _AC(0x4, UL)
+#define CTRCTL_RASEMU _AC(0x80, UL)
+#define CTRCTL_STE _AC(0x100, UL)
+#define CTRCTL_MTE _AC(0x200, UL)
+#define CTRCTL_BPFRZ _AC(0x800, UL)
+#define CTRCTL_LCOFIFRZ _AC(0x1000, UL)
+#define CTRCTL_EXCINH _AC(0x200000000, UL)
+#define CTRCTL_INTRINH _AC(0x400000000, UL)
+#define CTRCTL_TRETINH _AC(0x800000000, UL)
+#define CTRCTL_NTBREN _AC(0x1000000000, UL)
+#define CTRCTL_TKBRINH _AC(0x2000000000, UL)
+#define CTRCTL_INDCALL_INH _AC(0x10000000000, UL)
+#define CTRCTL_DIRCALL_INH _AC(0x20000000000, UL)
+#define CTRCTL_INDJUMP_INH _AC(0x40000000000, UL)
+#define CTRCTL_DIRJUMP_INH _AC(0x80000000000, UL)
+#define CTRCTL_CORSWAP_INH _AC(0x100000000000, UL)
+#define CTRCTL_RET_INH _AC(0x200000000000, UL)
+#define CTRCTL_INDOJUMP_INH _AC(0x400000000000, UL)
+#define CTRCTL_DIROJUMP_INH _AC(0x800000000000, UL)
+
+/* sctrstatus CSR bits. */
+#define SCTRSTATUS_WRPTR_MASK 0xFF
+#define SCTRSTATUS_FROZEN _AC(0x80000000, UL)
+
+#ifdef CONFIG_RISCV_M_MODE
+#define CTRCTL_KERNEL_ENABLE CTRCTL_M_ENABLE
+#else
+#define CTRCTL_KERNEL_ENABLE CTRCTL_S_ENABLE
+#endif
+
+/* sctrdepth CSR bits. */
+#define SCTRDEPTH_MASK 0x7
+
+#define SCTRDEPTH_MIN 0x0 /* 16 Entries. */
+#define SCTRDEPTH_MAX 0x4 /* 256 Entries. */
+
+/* ctrsource, ctrtarget and ctrdata CSR bits. */
+#define CTRSOURCE_VALID 0x1ULL
+#define CTRTARGET_MISP 0x1ULL
+
+#define CTRDATA_TYPE_MASK 0xF
+#define CTRDATA_CCV 0x8000
+#define CTRDATA_CCM_MASK 0xFFF0000
+#define CTRDATA_CCE_MASK 0xF0000000
+
+#define CTRDATA_TYPE_NONE 0
+#define CTRDATA_TYPE_EXCEPTION 1
+#define CTRDATA_TYPE_INTERRUPT 2
+#define CTRDATA_TYPE_TRAP_RET 3
+#define CTRDATA_TYPE_NONTAKEN_BRANCH 4
+#define CTRDATA_TYPE_TAKEN_BRANCH 5
+#define CTRDATA_TYPE_RESERVED_6 6
+#define CTRDATA_TYPE_RESERVED_7 7
+#define CTRDATA_TYPE_INDIRECT_CALL 8
+#define CTRDATA_TYPE_DIRECT_CALL 9
+#define CTRDATA_TYPE_INDIRECT_JUMP 10
+#define CTRDATA_TYPE_DIRECT_JUMP 11
+#define CTRDATA_TYPE_CO_ROUTINE_SWAP 12
+#define CTRDATA_TYPE_RETURN 13
+#define CTRDATA_TYPE_OTHER_INDIRECT_JUMP 14
+#define CTRDATA_TYPE_OTHER_DIRECT_JUMP 15
+
+#define CTR_ENTRIES_FIRST 0x200
+#define CTR_ENTRIES_LAST 0x2ff
+
+/* Temporary addresses for Sspesa (Precise Event Sample Attribution) CSRs. */
+#define CSR_SHPMSPC 0x5d0
+#define CSR_SHPMSDATA 0x5d1
+
+/* shpmsdata fields */
+#define SHPMSDATA_CNTRID GENMASK(4, 0)
+#define SHPMSDATA_MODE GENMASK(6, 5)
+#define SHPMSDATA_V BIT(7)
+#define SHPMSDATA_METADATA_SHIFT 8
+#define SHPMSDATA_MODE_U 0
+#define SHPMSDATA_MODE_S 1
+
#define CSR_SSTATUS 0x100
#define CSR_SIE 0x104
#define CSR_STVEC 0x105
@@ -563,6 +654,8 @@
# define CSR_TOPEI CSR_MTOPEI
# define CSR_TOPI CSR_MTOPI
+# define CSR_CTRCTL CSR_MCTRCTL
+
# define SR_IE SR_MIE
# define SR_PIE SR_MPIE
# define SR_PP SR_MPP
@@ -593,6 +686,8 @@
# define CSR_TOPEI CSR_STOPEI
# define CSR_TOPI CSR_STOPI
+# define CSR_CTRCTL CSR_SCTRCTL
+
# define SR_IE SR_SIE
# define SR_PIE SR_SPIE
# define SR_PP SR_SPP
--
2.43.0
next prev parent reply other threads:[~2026-11-18 9:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 9:50 [PATCH v5 0/7] riscv: pmu: Add support for Control Transfer Records Ext Vikram Singh
2026-11-18 9:50 ` [PATCH v5 1/7] perf: Increase the maximum number of branches remove_loops() can process Vikram Singh
2026-11-18 9:58 ` sashiko-bot
2026-11-18 9:50 ` Vikram Singh [this message]
2026-11-18 10:00 ` [PATCH v5 2/7] riscv: pmu: Add Control transfer records CSR definations sashiko-bot
2026-11-18 9:50 ` [PATCH v5 3/7] riscv: Add Control Transfer Records extension parsing Vikram Singh
2026-11-18 10:02 ` sashiko-bot
2026-11-18 9:50 ` [PATCH v5 4/7] riscv: pmu: Add infrastructure for Control Transfer Record Vikram Singh
2026-11-18 10:09 ` sashiko-bot
2026-11-18 9:50 ` [PATCH v5 5/7] riscv: pmu: Add driver for Control Transfer Records Ext Vikram Singh
2026-11-18 10:20 ` sashiko-bot
2026-11-18 9:50 ` [PATCH v5 6/7] riscv: pmu: Integrate CTR Ext support in riscv_pmu_dev driver Vikram Singh
2026-11-18 10:21 ` sashiko-bot
2026-11-18 9:50 ` [PATCH v5 7/7] dt-bindings: riscv: add Sxctr ISA extension description Vikram Singh
2026-11-18 10:24 ` sashiko-bot
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=20261118095053.3871267-3-vikram.singh3@oss.qualcomm.com \
--to=vikram.singh3@oss.qualcomm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alex@ghiti.fr \
--cc=alexander.shishkin@linux.intel.com \
--cc=anup.patel@oss.qualcomm.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atishp@rivosinc.com \
--cc=beeman@rivosinc.com \
--cc=conor+dt@kernel.org \
--cc=conor@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=peterz@infradead.org \
--cc=rajnesh.kanwal49@gmail.com \
--cc=robh@kernel.org \
--cc=will@kernel.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