Introduce support for SBI Debug Trigger Extension
v3 cover Introduce support for SBI Debug Trigger Extension
RISC-V Debug specification includes Sdtrig ISA extension which describes Trigger Module. Triggers can cause a breakpoint exception or trace action without execution of a special instruction. They can be used to implement hardware breakpoints and watchpoints for native debugging.
The SBI Debug Trigger extension v6 can be found at:
https://lists.riscv.org/g/tech-debug/topic/99825362#1302
This patch is an initial implementation of SBI Debug Trigger Extension(v6) in OpenSBI. It is based on similar patchset from Sergey Matyukevich.
(http://lists.infradead.org/pipermail/opensbi/2022-October/003531.html)
The following features are supported:
* mcontrol, mcontrol6 triggers
* Breakpoint and trace actions
Linux Kernel Branch (Breakpoint driver support):
https://github.com/hschauhan/riscv-linux/tree/sdtrig-v6
NOTE: Chained triggers are not supported
Changes from v2:
- Detection of sdtrig support (via trap and ISA string)
- Removed redundant functions (sdtrig supports and get total triggers)
- Removed check for S-mode
- Skip the debug trigger probing if already probed for CPU (warm boot)
Changes from v1:
- Rebased to latest OpenSBI master
- Other cosmetic changes as per the comments
Himanshu Chauhan (8):
include: sbi: Introduce common endianess conversion macro
include: sbi: Add TINFO debug trigger CSR
include: sbi: Introduce debug trigger register encodings
lib: sbi: Detect support of debug triggers
lib: sbi: Introduce the SBI debug triggers extension support
include: sbi: Add SBI debug trigger extension related defines
lib: sbi: Implement SBI debug trigger extension
lib: sbi: Print number of debug triggers found
include/sbi/riscv_dbtr.h | 249 ++++++++++ include/sbi/riscv_encoding.h | 1 + include/sbi/sbi_byteorder.h | 10 + include/sbi/sbi_dbtr.h | 128 ++++++ include/sbi/sbi_ecall_interface.h | 11 + include/sbi/sbi_hart.h | 2 + lib/sbi/Kconfig | 4 + lib/sbi/objects.mk | 4 + lib/sbi/sbi_dbtr.c | 739 ++++++++++++++++++++++++++++++ lib/sbi/sbi_ecall_dbtr.c | 73 +++ lib/sbi/sbi_hart.c | 4 + lib/sbi/sbi_init.c | 11 + 12 files changed, 1236 insertions(+) create mode 100644 include/sbi/riscv_dbtr.h create mode 100644 include/sbi/sbi_dbtr.h create mode 100644 lib/sbi/sbi_dbtr.c create mode 100644 lib/sbi/sbi_ecall_dbtr.c
Signature · 1 line
2.34.1
PATCH v3 1/8 include: sbi: Introduce common endianess conversion macro
Introduce cpu_to_lle and lle_to_cpu macros which invoke correct word length cpu_to_le<64/32> conversion based on __riscv_xlen.
--- include/sbi/sbi_byteorder.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/sbi/sbi_byteorder.h +10 -0
@@ -58,4 +58,14 @@#define le64_to_cpu (x) ((uint64_t)BSWAP64(x))#endif +#if __riscv_xlen ==64 +#define cpu_to_lle cpu_to_le64 +#define lle_to_cpu le64_to_cpu +#elif __riscv_xlen ==32 +#define cpu_to_lle cpu_to_le32 +#define lle_to_cpu le32_to_cpu +#else +#error "Unknown __riscv_xlen" +#endif +#endif /* __SBI_BYTEORDER_H__ */
Signature · 1 line
2.34.1
PATCH v3 2/8 include: sbi: Add TINFO debug trigger CSR
In reply to Himanshu ChauhanAdd the missing TINFO debug trigger CSR.
--- include/sbi/riscv_encoding.h | 1 + 1 file changed, 1 insertion(+)
include/sbi/riscv_encoding.h +1 -0
@@ -686,6 +686,7 @@#define CSR_TDATA1 0x7a1#define CSR_TDATA2 0x7a2#define CSR_TDATA3 0x7a3 +#define CSR_TINFO 0x7a4/* Debug Mode Registers */ #define CSR_DCSR 0x7b0
Signature · 1 line
2.34.1
PATCH v3 3/8 include: sbi: Introduce debug trigger register encodings
In reply to Himanshu ChauhanThis patch introduces Mcontrol and M6 control register encodings along with macros to manipulate them.
--- include/sbi/riscv_dbtr.h | 249 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 include/sbi/riscv_dbtr.h
include/sbi/riscv_dbtr.h new file +249 -0
@@ -0,0 +1,249 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2023 Ventana Micro System, Inc. +* +* Authors: +* Himanshu Chauhan <[email protected]> +*/ + +#ifndef __RISCV_DBTR_H__ +#define __RISCV_DBTR_H__ + +#define RV_MAX_TRIGGERS 32 + +enum { +RISCV_DBTR_TRIG_NONE =0 , +RISCV_DBTR_TRIG_LEGACY , +RISCV_DBTR_TRIG_MCONTROL , +RISCV_DBTR_TRIG_ICOUNT , +RISCV_DBTR_TRIG_ITRIGGER , +RISCV_DBTR_TRIG_ETRIGGER , +RISCV_DBTR_TRIG_MCONTROL6 , +}; + +#define RV_DBTR_BIT (_prefix, _name) \ + RV_DBTR_##_prefix##_##_name##_BIT + +#define RV_DBTR_BIT_MASK (_prefix, _name) \ + RV_DBTR_##_prefix##_name##_BIT_MASK + +#define RV_DBTR_DECLARE_BIT (_prefix, _name, _val) \ + RV_DBTR_BIT(_prefix, _name) = _val + +#define RV_DBTR_DECLARE_BIT_MASK (_prefix, _name, _width) \ + RV_DBTR_BIT_MASK(_prefix, _name) = \ + (((1UL << _width) - 1) << RV_DBTR_BIT(_prefix, _name)) + +#define CLEAR_DBTR_BIT (_target, _prefix, _bit_name) \ + __clear_bit(RV_DBTR_BIT(_prefix, _bit_name), &_target) + +#define SET_DBTR_BIT (_target, _prefix, _bit_name) \ + __set_bit(RV_DBTR_BIT(_prefix, _bit_name), &_target) + +/* Trigger Data 1 */ +enum { + RV_DBTR_DECLARE_BIT(TDATA1, DATA, 0), +#if __riscv_xlen ==64 + RV_DBTR_DECLARE_BIT(TDATA1, DMODE, 59), + RV_DBTR_DECLARE_BIT(TDATA1, TYPE, 60), +#elif __riscv_xlen ==32 + RV_DBTR_DECLARE_BIT(TDATA1, DMODE, 27), + RV_DBTR_DECLARE_BIT(TDATA1, TYPE, 28), +#else + #error "Unknown __riscv_xlen" +#endif +}; + +enum { +#if __riscv_xlen == 64 + RV_DBTR_DECLARE_BIT_MASK(TDATA1, DATA, 59), +#elif __riscv_xlen == 32 + RV_DBTR_DECLARE_BIT_MASK(TDATA1, DATA, 27), +#else + #error "Unknown __riscv_xlen" +#endif + RV_DBTR_DECLARE_BIT_MASK(TDATA1, DMODE, 1), + RV_DBTR_DECLARE_BIT_MASK(TDATA1, TYPE, 4), +}; + +/* MC - Match Control Type Register */ +enum { + RV_DBTR_DECLARE_BIT(MC, LOAD, 0), + RV_DBTR_DECLARE_BIT(MC, STORE, 1), + RV_DBTR_DECLARE_BIT(MC, EXEC, 2), + RV_DBTR_DECLARE_BIT(MC, U, 3), + RV_DBTR_DECLARE_BIT(MC, S, 4), + RV_DBTR_DECLARE_BIT(MC, RES2, 5), + RV_DBTR_DECLARE_BIT(MC, M, 6), + RV_DBTR_DECLARE_BIT(MC, MATCH, 7), + RV_DBTR_DECLARE_BIT(MC, CHAIN, 11), + RV_DBTR_DECLARE_BIT(MC, ACTION, 12), + RV_DBTR_DECLARE_BIT(MC, SIZELO, 16), + RV_DBTR_DECLARE_BIT(MC, TIMING, 18), + RV_DBTR_DECLARE_BIT(MC, SELECT, 19), + RV_DBTR_DECLARE_BIT(MC, HIT, 20), +#if __riscv_xlen >= 64 + RV_DBTR_DECLARE_BIT(MC, SIZEHI, 21), +#endif +#if __riscv_xlen == 64 + RV_DBTR_DECLARE_BIT(MC, MASKMAX, 53), + RV_DBTR_DECLARE_BIT(MC, DMODE, 59), + RV_DBTR_DECLARE_BIT(MC, TYPE, 60), +#elif __riscv_xlen == 32 + RV_DBTR_DECLARE_BIT(MC, MASKMAX, 21), + RV_DBTR_DECLARE_BIT(MC, DMODE, 27), + RV_DBTR_DECLARE_BIT(MC, TYPE, 28), +#else +#error "Unknown __riscv_xlen" +#endif +}; + +enum { + RV_DBTR_DECLARE_BIT_MASK(MC, LOAD, 1), + RV_DBTR_DECLARE_BIT_MASK(MC, STORE, 1), + RV_DBTR_DECLARE_BIT_MASK(MC, EXEC, 1), + RV_DBTR_DECLARE_BIT_MASK(MC, U, 1), + RV_DBTR_DECLARE_BIT_MASK(MC, S, 1), + RV_DBTR_DECLARE_BIT_MASK(MC, RES2, 1), + RV_DBTR_DECLARE_BIT_MASK(MC, M, 1), + RV_DBTR_DECLARE_BIT_MASK(MC, MATCH, 4), + RV_DBTR_DECLARE_BIT_MASK(MC, CHAIN, 1), + RV_DBTR_DECLARE_BIT_MASK(MC, ACTION, 4), + RV_DBTR_DECLARE_BIT_MASK(MC, SIZELO, 2), + RV_DBTR_DECLARE_BIT_MASK(MC, TIMING, 1), + RV_DBTR_DECLARE_BIT_MASK(MC, SELECT, 1), + RV_DBTR_DECLARE_BIT_MASK(MC, HIT, 1), +#if __riscv_xlen >=64 + RV_DBTR_DECLARE_BIT_MASK(MC, SIZEHI, 2), +#endif + RV_DBTR_DECLARE_BIT_MASK(MC, MASKMAX, 6), + RV_DBTR_DECLARE_BIT_MASK(MC, DMODE, 1), + RV_DBTR_DECLARE_BIT_MASK(MC, TYPE, 4), +}; + +/* MC6 - Match Control 6 Type Register */ +enum { + RV_DBTR_DECLARE_BIT(MC6, LOAD, 0), + RV_DBTR_DECLARE_BIT(MC6, STORE, 1), + RV_DBTR_DECLARE_BIT(MC6, EXEC, 2), + RV_DBTR_DECLARE_BIT(MC6, U, 3), + RV_DBTR_DECLARE_BIT(MC6, S, 4), + RV_DBTR_DECLARE_BIT(MC6, RES2, 5), + RV_DBTR_DECLARE_BIT(MC6, M, 6), + RV_DBTR_DECLARE_BIT(MC6, MATCH, 7), + RV_DBTR_DECLARE_BIT(MC6, CHAIN, 11), + RV_DBTR_DECLARE_BIT(MC6, ACTION, 12), + RV_DBTR_DECLARE_BIT(MC6, SIZE, 16), + RV_DBTR_DECLARE_BIT(MC6, TIMING, 20), + RV_DBTR_DECLARE_BIT(MC6, SELECT, 21), + RV_DBTR_DECLARE_BIT(MC6, HIT, 22), + RV_DBTR_DECLARE_BIT(MC6, VU, 23), + RV_DBTR_DECLARE_BIT(MC6, VS, 24), +#if __riscv_xlen == 64 + RV_DBTR_DECLARE_BIT(MC6, DMODE, 59), + RV_DBTR_DECLARE_BIT(MC6, TYPE, 60), +#elif __riscv_xlen == 32 + RV_DBTR_DECLARE_BIT(MC6, DMODE, 27), + RV_DBTR_DECLARE_BIT(MC6, TYPE, 28), +#else + #error "Unknown __riscv_xlen" +#endif +}; + +enum { + RV_DBTR_DECLARE_BIT_MASK(MC6, LOAD, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, STORE, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, EXEC, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, U, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, S, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, RES2, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, M, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, MATCH, 4), + RV_DBTR_DECLARE_BIT_MASK(MC6, CHAIN, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, ACTION, 4), + RV_DBTR_DECLARE_BIT_MASK(MC6, SIZE, 4), + RV_DBTR_DECLARE_BIT_MASK(MC6, TIMING, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, SELECT, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, HIT, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, VU, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, VS, 1), +#if __riscv_xlen == 64 + RV_DBTR_DECLARE_BIT_MASK(MC6, DMODE, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, TYPE, 4), +#elif __riscv_xlen == 32 + RV_DBTR_DECLARE_BIT_MASK(MC6, DMODE, 1), + RV_DBTR_DECLARE_BIT_MASK(MC6, TYPE, 4), +#else + #error "Unknown __riscv_xlen" +#endif +}; + +#define RV_DBTR_SET_TDATA1_TYPE(_t1, _type) \ + do { \ + _t1 &= ~RV_DBTR_BIT_MASK(TDATA1, TYPE); \ + _t1 |= (((unsigned long)_type \ + << RV_DBTR_BIT(TDATA1, TYPE)) \ + & RV_DBTR_BIT_MASK(TDATA1, TYPE)); \ + }while (0); + +#define RV_DBTR_SET_MC_TYPE(_t1, _type) \ + do { \ + _t1 &= ~RV_DBTR_BIT_MASK (MC ,TYPE ); \ + _t1 |= (((unsigned long )_type \ + <<RV_DBTR_BIT (MC ,TYPE )) \ + &RV_DBTR_BIT_MASK (MC ,TYPE )); \ + }while (0 ); + +#define RV_DBTR_SET_MC6_TYPE (_t1, _type) \ + do { \ + _t1 &= ~RV_DBTR_BIT_MASK(MC6, TYPE); \ + _t1 |= (((unsigned long)_type \ + << RV_DBTR_BIT(MC6, TYPE)) \ + & RV_DBTR_BIT_MASK(MC6, TYPE)); \ + }while (0); + +#define RV_DBTR_SET_MC_EXEC (_t1) \ + SET_DBTR_BIT(_t1, MC, EXEC) + +#define RV_DBTR_SET_MC_LOAD (_t1) \ + SET_DBTR_BIT(_t1, MC, LOAD) + +#define RV_DBTR_SET_MC_STORE (_t1) \ + SET_DBTR_BIT(_t1, MC, STORE) + +#define RV_DBTR_SET_MC_SIZELO (_t1, _val) \ + do { \ + _t1 &= ~RV_DBTR_BIT_MASK(MC, SIZELO); \ + _t1 |= ((_val << RV_DBTR_BIT(MC, SIZELO)) \ + & RV_DBTR_BIT_MASK(MC, SIZELO)); \ + } while(0); + +#define RV_DBTR_SET_MC_SIZEHI (_t1, _val) \ + do { \ + _t1 &= ~RV_DBTR_BIT_MASK(MC, SIZEHI); \ + _t1 |= ((_val << RV_DBTR_BIT(MC, SIZEHI)) \ + & RV_DBTR_BIT_MASK(MC, SIZEHI)); \ + } while(0); + +#define RV_DBTR_SET_MC6_EXEC (_t1) \ + SET_DBTR_BIT(_t1, MC6, EXEC) + +#define RV_DBTR_SET_MC6_LOAD (_t1) \ + SET_DBTR_BIT(_t1, MC6, LOAD) + +#define RV_DBTR_SET_MC6_STORE (_t1) \ + SET_DBTR_BIT(_t1, MC6, STORE) + +#define RV_DBTR_SET_MC6_SIZE (_t1, _val) \ + do { \ + _t1 &= ~RV_DBTR_BIT_MASK(MC6, SIZE); \ + _t1 |= ((_val << RV_DBTR_BIT(MC6, SIZE)) \ + & RV_DBTR_BIT_MASK(MC6, SIZE)); \ + } while(0); + +typedef unsigned long riscv_dbtr_tdata1_mcontrol_t ; +typedef unsigned long riscv_dbtr_tdata1_mcontrol6_t ; +typedef unsigned long riscv_dbtr_tdata1_t ; + +#endif /* __RISCV_DBTR_H__ */
Signature · 1 line
2.34.1
PATCH v3 4/8 lib: sbi: Detect support of debug triggers
In reply to Himanshu ChauhanDetect if debug triggers, sdtrig extension, is supported by the CPU. The support is detected by access traps and ISA string parsing.
--- include/sbi/sbi_hart.h | 2 ++ lib/sbi/sbi_hart.c | 4 ++++ 2 files changed, 6 insertions(+)
include/sbi/sbi_hart.h +2 -0
@@ -53,6 +53,8 @@ enum sbi_hart_extensions {SBI_HART_EXT_ZICBOM ,/** Hart has Svpbmt extension */ SBI_HART_EXT_SVPBMT , +/** Hart has debug trigger extension */ +SBI_HART_EXT_SDTRIG ,/** Maximum index of Hart extension */ SBI_HART_EXT_MAX,
lib/sbi/sbi_hart.c +4 -0
@@ -657,6 +657,7 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = {__SBI_HART_EXT_DATA (zicboz,SBI_HART_EXT_ZICBOZ ),__SBI_HART_EXT_DATA (zicbom,SBI_HART_EXT_ZICBOM ),__SBI_HART_EXT_DATA (svpbmt,SBI_HART_EXT_SVPBMT ), + __SBI_HART_EXT_DATA(sdtrig, SBI_HART_EXT_SDTRIG), };/**
@@ -898,6 +899,9 @@ __pmp_skip:/* Detect if hart supports smcntrpmf */ __check_ext_csr (SBI_HART_PRIV_VER_1_12 ,CSR_MCYCLECFG ,SBI_HART_EXT_SMCNTRPMF ); +/* Detect if hart support sdtrig (debug triggers) */ +__check_ext_csr (SBI_HART_PRIV_VER_UNKNOWN , +CSR_TSELECT ,SBI_HART_EXT_SDTRIG );#undef __check_ext_csr
Signature · 1 line
2.34.1
PATCH v3 4/8 lib: sbi: Detect support of debug triggers
Quoted 6 lines · On Tue, Jan 9, 2024 at 11:45?PM Himanshu Chauhan <[email protected]>…
Detect if debug triggers, sdtrig extension, is supported by the CPU. The support is detected by access traps and ISA string parsing.
Signed-off-by Himanshu Chauhan <[email protected]>
LGTM.
Regards,
Anup
Quoted 48 lines
--- include/sbi/sbi_hart.h | 2 ++ lib/sbi/sbi_hart.c | 4 ++++ 2 files changed, 6 insertions(+)include/sbi/sbi_hart.h +2
-0@@ -53,6 +53,8 @@ enum sbi_hart_extensions {SBI_HART_EXT_ZICBOM ,/** Hart has Svpbmt extension */ SBI_HART_EXT_SVPBMT , +/** Hart has debug trigger extension */ +SBI_HART_EXT_SDTRIG ,/** Maximum index of Hart extension */ SBI_HART_EXT_MAX,lib/sbi/sbi_hart.c +4
-1@@ -657,6 +657,7 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = {__SBI_HART_EXT_DATA (zicboz,SBI_HART_EXT_ZICBOZ ),__SBI_HART_EXT_DATA (zicbom,SBI_HART_EXT_ZICBOM ),__SBI_HART_EXT_DATA (svpbmt,SBI_HART_EXT_SVPBMT ), + __SBI_HART_EXT_DATA(sdtrig, SBI_HART_EXT_SDTRIG), };/** @@ -898,6 +899,9 @@ __pmp_skip:/* Detect if hart supports smcntrpmf */ __check_ext_csr (SBI_HART_PRIV_VER_1_12 ,CSR_MCYCLECFG ,SBI_HART_EXT_SMCNTRPMF ); +/* Detect if hart support sdtrig (debug triggers) */ +__check_ext_csr (SBI_HART_PRIV_VER_UNKNOWN , +CSR_TSELECT ,SBI_HART_EXT_SDTRIG );#undef __check_ext_csr --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v3 5/8 lib: sbi: Introduce the SBI debug triggers extension support
In reply to Himanshu ChauhanRISC-V Debug specification includes Sdtrig ISA extension which describes Trigger Module. Triggers can cause a breakpoint exception or trace action without execution of a special instruction. They can be used to implement hardware breakpoints and watchpoints for native debugging.
The SBI Debut Trigger extension (Draft v6) can be found at:
https://lists.riscv.org/g/tech-debug/topic/99825362#1302
This patch is an initial implementation of SBI Debug Trigger Extension (Draft v6) in OpenSBI.
The following features are supported:
* mcontrol, mcontrol6 triggers
* Breakpoint and trace actions
NOTE: Chained triggers are not supported
--- include/sbi/sbi_dbtr.h | 128 +++++++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_dbtr.c | 739 +++++++++++++++++++++++++++++++++++++++++ lib/sbi/sbi_init.c | 9 + 4 files changed, 877 insertions(+) create mode 100644 include/sbi/sbi_dbtr.h create mode 100644 lib/sbi/sbi_dbtr.c
include/sbi/sbi_dbtr.h new file +128 -0
@@ -0,0 +1,128 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2023 Ventana Micro Systems, Inc. +* +* Authors: +* Himanshu Chauhan <[email protected]> +*/ + +#ifndef __SBI_DBTR_H__ +#define __SBI_DBTR_H__ + +#include <sbi/riscv_dbtr.h> + +#include <sbi/sbi_hartmask.h> +#include <sbi/sbi_scratch.h> +#include <sbi/sbi_domain.h> +#include <sbi/sbi_types.h> +#include <sbi/sbi_byteorder.h> + +enum { + RV_DBTR_DECLARE_BIT(TS, MAPPED, 0), /* trigger mapped to hw trigger */ + RV_DBTR_DECLARE_BIT(TS, U, 1), + RV_DBTR_DECLARE_BIT(TS, S, 2), + RV_DBTR_DECLARE_BIT(TS, VU, 3), + RV_DBTR_DECLARE_BIT(TS, VS, 4), + RV_DBTR_DECLARE_BIT(TS, HAVE_TRIG, 5), /* H/w dbtr details available */ + RV_DBTR_DECLARE_BIT(TS, HW_IDX, 8), /* Hardware index of trigger */ +}; + +enum { + RV_DBTR_DECLARE_BIT_MASK(TS, MAPPED, 1), + RV_DBTR_DECLARE_BIT_MASK(TS, U, 1), + RV_DBTR_DECLARE_BIT_MASK(TS, S, 1), + RV_DBTR_DECLARE_BIT_MASK(TS, VU, 1), + RV_DBTR_DECLARE_BIT_MASK(TS, VS, 1), + RV_DBTR_DECLARE_BIT_MASK(TS, HAVE_TRIG, 1), + RV_DBTR_DECLARE_BIT_MASK(TS, HW_IDX, (__riscv_xlen-9)), +}; + +#if __riscv_xlen ==64 +#define SBI_DBTR_SHMEM_INVALID_ADDR 0xFFFFFFFFFFFFFFFFUL +#elif __riscv_xlen ==32 +#define SBI_DBTR_SHMEM_INVALID_ADDR 0xFFFFFFFFUL +#error "Unexpected __riscv_xlen" +#endif + +struct sbi_dbtr_shmem { +unsigned long phys_lo; +unsigned long phys_hi; +}; + +struct sbi_dbtr_trigger { +unsigned long index; +unsigned long type_mask; +unsigned long state; +unsigned long tdata1; +unsigned long tdata2; +unsigned long tdata3; +}; + +struct sbi_dbtr_data_msg { +unsigned long tstate; +unsigned long tdata1; +unsigned long tdata2; +unsigned long tdata3; +}; + +struct sbi_dbtr_id_msg { +unsigned long idx; +}; + +struct sbi_dbtr_hart_triggers_state { +struct sbi_dbtr_trigger triggers[RV_MAX_TRIGGERS ]; +struct sbi_dbtr_shmem shmem; +u32 total_trigs; +u32 available_trigs; +u32 hartid; +u32 probed; +}; + +#define TDATA1_GET_TYPE (_t1) \ + EXTRACT_FIELD(_t1, RV_DBTR_BIT_MASK(TDATA1, TYPE)) + +/* Set the hardware index of trigger in logical trigger state */ +#define SET_TRIG_HW_INDEX (_state, _idx) \ + do { \ + _state &= ~RV_DBTR_BIT_MASK(TS, HW_IDX); \ + _state |= (((unsigned long)_idx \ + << RV_DBTR_BIT(TS, HW_IDX)) \ + & RV_DBTR_BIT_MASK(TS, HW_IDX)); \ + }while (0); + +/** SBI shared mem messages layout */ +struct sbi_dbtr_shmem_entry { +struct sbi_dbtr_data_msg data; +struct sbi_dbtr_id_msg id; +}; + +#define SBI_DBTR_SHMEM_ALIGN_MASK ((__riscv_xlen / 8) - 1) + +/** Initialize debug triggers */ +int sbi_dbtr_init (struct sbi_scratch *scratch,bool coldboot); + +/** SBI DBTR extension functions */ +int sbi_dbtr_supported (void ); +int sbi_dbtr_setup_shmem (const struct sbi_domain *dom,unsigned long smode, +unsigned long shmem_phys_lo, +unsigned long shmem_phys_hi); +int sbi_dbtr_num_trig (unsigned long trig_tdata1,unsigned long *out); +int sbi_dbtr_read_trig (const struct sbi_domain *dom,unsigned long smode, +unsigned long trig_idx_base,unsigned long trig_count); +int sbi_dbtr_install_trig (const struct sbi_domain *dom,unsigned long smode, +unsigned long trig_count,unsigned long *out); +int sbi_dbtr_uninstall_trig (unsigned long trig_idx_base, +unsigned long trig_idx_mask); +int sbi_dbtr_enable_trig (unsigned long trig_idx_base, +unsigned long trig_idx_mask); +int sbi_dbtr_update_trig (const struct sbi_domain *dom, +unsigned long smode, +unsigned long trig_idx_base, +unsigned long trig_idx_mask); +int sbi_dbtr_disable_trig (unsigned long trig_idx_base, +unsigned long trig_idx_mask); + +int sbi_dbtr_get_total_triggers (void ); + +#endif
lib/sbi/objects.mk +1 -0
@@ -70,6 +70,7 @@ libsbi-objs-y += sbi_irqchip.o libsbi-objs-y += sbi_misaligned_ldst.o libsbi-objs-y += sbi_platform.o libsbi-objs-y += sbi_pmu.o +libsbi-objs-y += sbi_dbtr.o libsbi-objs-y += sbi_scratch.o libsbi-objs-y += sbi_string.o libsbi-objs-y += sbi_system.o
lib/sbi/sbi_dbtr.c new file +739 -0
739 lines not on this page · raw message
lib/sbi/sbi_init.c +9 -0
@@ -23,6 +23,7 @@#include <sbi/sbi_irqchip.h> #include <sbi/sbi_platform.h> #include <sbi/sbi_pmu.h> +#include <sbi/sbi_dbtr.h> #include <sbi/sbi_system.h> #include <sbi/sbi_string.h> #include <sbi/sbi_timer.h>
@@ -322,6 +323,10 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)sbi_hart_hang (); } + rc =sbi_dbtr_init (scratch, true); +if (rc) +sbi_hart_hang (); +sbi_boot_print_banner (scratch); rc =sbi_irqchip_init (scratch, true);
@@ -439,6 +444,10 @@ static void __noreturn init_warm_startup(struct sbi_scratch *scratch,if (rc)sbi_hart_hang (); + rc =sbi_dbtr_init (scratch, false); +if (rc) +sbi_hart_hang (); + rc =sbi_irqchip_init (scratch, false);if (rc)sbi_hart_hang ();
Signature · 1 line
2.34.1
PATCH v3 6/8 include: sbi: Add SBI debug trigger extension related defines
In reply to Himanshu ChauhanThis patch adds defines for SBI debug trigger extension and function IDs to access the extension.
--- include/sbi/sbi_ecall_interface.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/sbi/sbi_ecall_interface.h +11 -0
@@ -32,6 +32,7 @@#define SBI_EXT_DBCN 0x4442434E#define SBI_EXT_SUSP 0x53555350#define SBI_EXT_CPPC 0x43505043 +#define SBI_EXT_DBTR 0x44425452/* SBI function IDs for BASE extension*/ #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0
@@ -105,6 +106,16 @@#define SBI_EXT_PMU_COUNTER_FW_READ_HI 0x6#define SBI_EXT_PMU_SNAPSHOT_SET_SHMEM 0x7 +/* SBI function IDs for DBTR extension */ +#define SBI_EXT_DBTR_NUM_TRIGGERS 0x0 +#define SBI_EXT_DBTR_SETUP_SHMEM 0x1 +#define SBI_EXT_DBTR_TRIGGER_READ 0x2 +#define SBI_EXT_DBTR_TRIGGER_INSTALL 0x3 +#define SBI_EXT_DBTR_TRIGGER_UPDATE 0x4 +#define SBI_EXT_DBTR_TRIGGER_UNINSTALL 0x5 +#define SBI_EXT_DBTR_TRIGGER_ENABLE 0x6 +#define SBI_EXT_DBTR_TRIGGER_DISABLE 0x7 +/** General pmu event codes specified in SBI PMU extension */ enum sbi_pmu_hw_generic_events_t {SBI_PMU_HW_NO_EVENT =0 ,
Signature · 1 line
2.34.1
PATCH v3 7/8 lib: sbi: Implement SBI debug trigger extension
In reply to Himanshu ChauhanThis patch adds functions to register ecalls for debug triggers and handler to handle the debug trigger function IDs.
--- lib/sbi/Kconfig | 4 +++ lib/sbi/objects.mk | 3 ++ lib/sbi/sbi_ecall_dbtr.c | 73 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 lib/sbi/sbi_ecall_dbtr.c
lib/sbi/Kconfig +4 -0
@@ -46,4 +46,8 @@ config SBI_ECALL_VENDOR bool "Platform-defined vendor extensions" default y +config SBI_ECALL_DBTR + bool "Debug Trigger Extension" + default y + endmenu
lib/sbi/objects.mk +3 -0
@@ -52,6 +52,9 @@ libsbi-objs-$(CONFIG_SBI_ECALL_LEGACY) += sbi_ecall_legacy.o carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_VENDOR) += ecall_vendor libsbi-objs-$(CONFIG_SBI_ECALL_VENDOR) += sbi_ecall_vendor.o +carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_DBTR) += ecall_dbtr +libsbi-objs-$(CONFIG_SBI_ECALL_DBTR) += sbi_ecall_dbtr.o + libsbi-objs-y += sbi_bitmap.o libsbi-objs-y += sbi_bitops.o libsbi-objs-y += sbi_console.o
lib/sbi/sbi_ecall_dbtr.c new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 8/8 lib: sbi: Print number of debug triggers found
In reply to Himanshu ChauhanPrint the total number of triggers found on the boot hart.
--- lib/sbi/sbi_init.c | 2 ++ 1 file changed, 2 insertions(+)
lib/sbi/sbi_init.c +2 -0
@@ -184,6 +184,8 @@ static void sbi_boot_print_hart(struct sbi_scratch *scratch, u32 hartid)sbi_printf ("Boot HART MHPM Info : %lu (0x%08x)\n" ,sbi_popcount (sbi_hart_mhpm_mask (scratch)),sbi_hart_mhpm_mask (scratch)); +sbi_printf ("Boot HART Debug Triggers : %d trigger(s) found.\n" , +sbi_dbtr_get_total_triggers ());sbi_hart_delegation_dump (scratch,"Boot HART " ," " ); }
Signature · 1 line
2.34.1
Anup Patel
Appliedv3 cover Introduce support for SBI Debug Trigger Extension
In reply to Himanshu ChauhanQuoted 34 lines · On Tue, Jan 9, 2024 at 11:45?PM Himanshu Chauhan <[email protected]>…
RISC-V Debug specification includes Sdtrig ISA extension which describes Trigger Module. Triggers can cause a breakpoint exception or trace action without execution of a special instruction. They can be used to implement hardware breakpoints and watchpoints for native debugging.
The SBI Debug Trigger extension v6 can be found at:
https://lists.riscv.org/g/tech-debug/topic/99825362#1302This patch is an initial implementation of SBI Debug Trigger Extension(v6) in OpenSBI. It is based on similar patchset from Sergey Matyukevich.
(http://lists.infradead.org/pipermail/opensbi/2022-October/003531.html)The following features are supported:
* mcontrol, mcontrol6 triggers
* Breakpoint and trace actionsLinux Kernel Branch (Breakpoint driver support):
https://github.com/hschauhan/riscv-linux/tree/sdtrig-v6NOTE: Chained triggers are not supported
Changes from v2:
- Detection of sdtrig support (via trap and ISA string)
- Removed redundant functions (sdtrig supports and get total triggers)
- Removed check for S-mode
- Skip the debug trigger probing if already probed for CPU (warm boot)Changes from v1:
- Rebased to latest OpenSBI master
- Other cosmetic changes as per the comments
Quoted 9 lines
Himanshu Chauhan (8):
include: sbi: Introduce common endianess conversion macro
include: sbi: Add TINFO debug trigger CSR
include: sbi: Introduce debug trigger register encodings
lib: sbi: Detect support of debug triggers
lib: sbi: Introduce the SBI debug triggers extension support
include: sbi: Add SBI debug trigger extension related defines
lib: sbi: Implement SBI debug trigger extension
lib: sbi: Print number of debug triggers found
Applied this series to the riscv/opensbi repo.
Thanks,
Anup
Quoted 27 lines
include/sbi/riscv_dbtr.h | 249 ++++++++++ include/sbi/riscv_encoding.h | 1 + include/sbi/sbi_byteorder.h | 10 + include/sbi/sbi_dbtr.h | 128 ++++++ include/sbi/sbi_ecall_interface.h | 11 + include/sbi/sbi_hart.h | 2 + lib/sbi/Kconfig | 4 + lib/sbi/objects.mk | 4 + lib/sbi/sbi_dbtr.c | 739 ++++++++++++++++++++++++++++++ lib/sbi/sbi_ecall_dbtr.c | 73 +++ lib/sbi/sbi_hart.c | 4 + lib/sbi/sbi_init.c | 11 + 12 files changed, 1236 insertions(+) create mode 100644 include/sbi/riscv_dbtr.h create mode 100644 include/sbi/sbi_dbtr.h create mode 100644 lib/sbi/sbi_dbtr.c create mode 100644 lib/sbi/sbi_ecall_dbtr.c--
2.34.1--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi