lib: sbi: Enable Ssqosid Ext using mstateen0
PATCH 1/1 lib: sbi: Enable Ssqosid Ext using mstateen0
From: Chen Pei <[email protected]>
The QoS Identifiers extension (Ssqosid) introduces the srmcfg register, which configures a hart with two identifiers: a Resource Control ID (RCID) and a Monitoring Counter ID (MCID). These identifiers accompany each request issued by the hart to shared resource controllers.
If extension Smstateen is implemented together with Ssqosid, then Ssqosid also requires the SRMCFG bit in mstateen0 to be implemented. If mstateen0.SRMCFG is 0, attempts to access srmcfg in privilege modes less privileged than M-mode raise an illegal-instruction exception. If mstateen0.SRMCFG is 1 or if extension Smstateen is not implemented, attempts to access srmcfg when V=1 raise a virtual-instruction exception.
This extension can be found in the RISC-V Instruction Set Manual:
https://github.com/riscv/riscv-isa-manual
--- include/sbi/riscv_encoding.h | 5 +++++ include/sbi/sbi_hart.h | 2 ++ lib/sbi/sbi_hart.c | 9 +++++++++ 3 files changed, 16 insertions(+)
include/sbi/riscv_encoding.h +5 -0
@@ -389,6 +389,9 @@/* VS-Level Control transfer records CSRs */ #define CSR_VSCTRCTL 0x24e +/* Supervisor Resource Management Configuration CSRs */ +#define CSR_SRMCFG 0x181 +/* ===== Hypervisor-level CSRs ===== */ /* Hypervisor Trap Setup (H-extension) */
@@ -815,6 +818,8 @@#define SMSTATEEN0_FCSR (_ULL(1) << SMSTATEEN0_FCSR_SHIFT)#define SMSTATEEN0_CTR_SHIFT 54#define SMSTATEEN0_CTR (_ULL(1) << SMSTATEEN0_CTR_SHIFT) +#define SMSTATEEN0_SRMCFG_SHIFT 55 +#define SMSTATEEN0_SRMCFG (_ULL(1) << SMSTATEEN0_SRMCFG_SHIFT)#define SMSTATEEN0_CONTEXT_SHIFT 57#define SMSTATEEN0_CONTEXT (_ULL(1) << SMSTATEEN0_CONTEXT_SHIFT)#define SMSTATEEN0_IMSIC_SHIFT 58
include/sbi/sbi_hart.h +2 -0
@@ -81,6 +81,8 @@ enum sbi_hart_extensions {SBI_HART_EXT_SSCTR ,/** HART has Ssstateen extension **/ SBI_HART_EXT_SSSTATEEN , +/** Hart has Ssqosid extension */ +SBI_HART_EXT_SSQOSID ,/** Maximum index of Hart extension */ SBI_HART_EXT_MAX,
lib/sbi/sbi_hart.c +9 -0
@@ -110,6 +110,11 @@ static void mstatus_init(struct sbi_scratch *scratch)else mstateen_val &= ~SMSTATEEN0_CTR ; +if (sbi_hart_has_extension (scratch,SBI_HART_EXT_SSQOSID )) + mstateen_val |= (SMSTATEEN0_SRMCFG ); +else + mstateen_val &= ~(SMSTATEEN0_SRMCFG ); +csr_write64 (CSR_MSTATEEN0 , mstateen_val);csr_write64 (CSR_MSTATEEN1 ,SMSTATEEN_STATEN );csr_write64 (CSR_MSTATEEN2 ,SMSTATEEN_STATEN );
@@ -727,6 +732,7 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = {__SBI_HART_EXT_DATA (smctr,SBI_HART_EXT_SMCTR ),__SBI_HART_EXT_DATA (ssctr,SBI_HART_EXT_SSCTR ),__SBI_HART_EXT_DATA (ssstateen,SBI_HART_EXT_SSSTATEEN ), +__SBI_HART_EXT_DATA (ssqosid,SBI_HART_EXT_SSQOSID ), }; _Static_assert(SBI_HART_EXT_MAX == array_size(sbi_hart_ext),
@@ -989,6 +995,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 supports ssqosid */ +__check_ext_csr (SBI_HART_PRIV_VER_1_12 , +CSR_SRMCFG ,SBI_HART_EXT_SSQOSID );/* Detect if hart support sdtrig (debug triggers) */ __check_ext_csr (SBI_HART_PRIV_VER_UNKNOWN ,CSR_TSELECT ,SBI_HART_EXT_SDTRIG );
Signature · 7 lines
2.49.0 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
Quoted 66 lines · On Tue, Sep 23, 2025 at 3:28 PM <[email protected]> wrote:
From: Chen Pei <[email protected]>
The QoS Identifiers extension (Ssqosid) introduces the srmcfg register, which configures a hart with two identifiers: a Resource Control ID (RCID) and a Monitoring Counter ID (MCID). These identifiers accompany each request issued by the hart to shared resource controllers.
If extension Smstateen is implemented together with Ssqosid, then Ssqosid also requires the SRMCFG bit in mstateen0 to be implemented. If mstateen0.SRMCFG is 0, attempts to access srmcfg in privilege modes less privileged than M-mode raise an illegal-instruction exception. If mstateen0.SRMCFG is 1 or if extension Smstateen is not implemented, attempts to access srmcfg when V=1 raise a virtual-instruction exception.
This extension can be found in the RISC-V Instruction Set Manual:
https://github.com/riscv/riscv-isa-manualSigned-off-by Chen Pei <[email protected]>--- include/sbi/riscv_encoding.h | 5 +++++ include/sbi/sbi_hart.h | 2 ++ lib/sbi/sbi_hart.c | 9 +++++++++ 3 files changed, 16 insertions(+)include/sbi/riscv_encoding.h +5
-0@@ -389,6 +389,9 @@/* VS-Level Control transfer records CSRs */ #define CSR_VSCTRCTL 0x24e +/* Supervisor Resource Management Configuration CSRs */ +#define CSR_SRMCFG 0x181 +/* ===== Hypervisor-level CSRs ===== */ /* Hypervisor Trap Setup (H-extension) */ @@ -815,6 +818,8 @@#define SMSTATEEN0_FCSR (_ULL(1) << SMSTATEEN0_FCSR_SHIFT)#define SMSTATEEN0_CTR_SHIFT 54#define SMSTATEEN0_CTR (_ULL(1) << SMSTATEEN0_CTR_SHIFT) +#define SMSTATEEN0_SRMCFG_SHIFT 55 +#define SMSTATEEN0_SRMCFG (_ULL(1) << SMSTATEEN0_SRMCFG_SHIFT)#define SMSTATEEN0_CONTEXT_SHIFT 57#define SMSTATEEN0_CONTEXT (_ULL(1) << SMSTATEEN0_CONTEXT_SHIFT)#define SMSTATEEN0_IMSIC_SHIFT 58include/sbi/sbi_hart.h +2
-0@@ -81,6 +81,8 @@ enum sbi_hart_extensions {SBI_HART_EXT_SSCTR ,/** HART has Ssstateen extension **/ SBI_HART_EXT_SSSTATEEN , +/** Hart has Ssqosid extension */ +SBI_HART_EXT_SSQOSID ,/** Maximum index of Hart extension */ SBI_HART_EXT_MAX,lib/sbi/sbi_hart.c +0
-0
lib/sbi/sbi_hart.c static void mstatus_init(struct sbi_scratch *scratch) · line 117
Quoted 8 lines
lib/sbi/sbi_hart.c +5
-0@@ -110,6 +110,11 @@ static void mstatus_init(struct sbi_scratch *scratch)else mstateen_val &= ~SMSTATEEN0_CTR ; +if (sbi_hart_has_extension (scratch,SBI_HART_EXT_SSQOSID )) + mstateen_val |= (SMSTATEEN0_SRMCFG ); +else + mstateen_val &= ~(SMSTATEEN0_SRMCFG ); +
Since we are enabling Srmcfg CSR for S-mode, we should also context switch it in the switch_to_next_domain_context() function.
Quoted 12 lines
lib/sbi/sbi_hart.c +1
-0csr_write64 (CSR_MSTATEEN0 , mstateen_val);csr_write64 (CSR_MSTATEEN1 ,SMSTATEEN_STATEN );csr_write64 (CSR_MSTATEEN2 ,SMSTATEEN_STATEN );@@ -727,6 +732,7 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = {__SBI_HART_EXT_DATA (smctr,SBI_HART_EXT_SMCTR ),__SBI_HART_EXT_DATA (ssctr,SBI_HART_EXT_SSCTR ),__SBI_HART_EXT_DATA (ssstateen,SBI_HART_EXT_SSSTATEEN ), +__SBI_HART_EXT_DATA (ssqosid,SBI_HART_EXT_SSQOSID ), }; _Static_assert(SBI_HART_EXT_MAX == array_size(sbi_hart_ext),
lib/sbi/sbi_hart.c __pmp_skip: · line 1000
Quoted 6 lines
lib/sbi/sbi_hart.c +3
-0@@ -989,6 +995,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 supports ssqosid */ +__check_ext_csr (SBI_HART_PRIV_VER_1_12 , +CSR_SRMCFG ,SBI_HART_EXT_SSQOSID );
For newer extensions, detecting from ISA string is sufficient so no need to trap-n-detect here.
Quoted 6 lines
lib/sbi/sbi_hart.c +0
-1/* Detect if hart support sdtrig (debug triggers) */ __check_ext_csr (SBI_HART_PRIV_VER_UNKNOWN ,CSR_TSELECT ,SBI_HART_EXT_SDTRIG ); --2.49.0
Regards,
Anup
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi