lib: sbi: Enable Ssqosid Ext using mstateen0
PATCH v4 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_domain_context.c | 7 ++++++- lib/sbi/sbi_hart.c | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-)
include/sbi/riscv_encoding.h +5 -0
@@ -378,6 +378,9 @@#define CSR_SSTATEEN2 0x10E#define CSR_SSTATEEN3 0x10F +/* Supervisor Resource Management Configuration CSRs */ +#define CSR_SRMCFG 0x181 +/* Machine-Level Control transfer records CSRs */ #define CSR_MCTRCTL 0x34e
@@ -849,6 +852,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
@@ -79,6 +79,8 @@ enum sbi_hart_extensions {SBI_HART_EXT_SMCTR ,/** HART has CTR S-mode CSRs */ SBI_HART_EXT_SSCTR , +/** Hart has Ssqosid extension */ +SBI_HART_EXT_SSQOSID ,/** HART has Ssstateen extension **/ SBI_HART_EXT_SSSTATEEN,/** Hart has Xsfcflushdlone extension */
lib/sbi/sbi_domain_context.c +6 -1
@@ -45,6 +45,8 @@ struct hart_context {unsigned long scounteren;/** Supervisor environment configuration register */ unsigned long senvcfg; +/** Supervisor resource management configuration register */ +unsigned long srmcfg;/** Reference to the owning domain */ struct sbi_domain *dom;
@@ -143,8 +145,11 @@ static int switch_to_next_domain_context(struct hart_context *ctx, ctx->satp =csr_swap (CSR_SATP , dom_ctx->satp);if (sbi_hart_priv_version (scratch) >=SBI_HART_PRIV_VER_1_10 ) ctx->scounteren =csr_swap (CSR_SCOUNTEREN , dom_ctx->scounteren); -if (sbi_hart_priv_version (scratch) >=SBI_HART_PRIV_VER_1_12 ) +if (sbi_hart_priv_version (scratch) >=SBI_HART_PRIV_VER_1_12 ) { ctx->senvcfg =csr_swap (CSR_SENVCFG , dom_ctx->senvcfg); +if (sbi_hart_has_extension (scratch,SBI_HART_EXT_SSQOSID )) + ctx->srmcfg =csr_swap (CSR_SRMCFG , dom_ctx->srmcfg); + }/* Save current trap state and restore target domain's trap state */ trap_ctx =sbi_trap_get_context (scratch);
lib/sbi/sbi_hart.c +6 -0
@@ -112,6 +112,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 );
@@ -685,6 +690,7 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = {__SBI_HART_EXT_DATA (ssdbltrp,SBI_HART_EXT_SSDBLTRP ),__SBI_HART_EXT_DATA (smctr,SBI_HART_EXT_SMCTR ),__SBI_HART_EXT_DATA (ssctr,SBI_HART_EXT_SSCTR ), +__SBI_HART_EXT_DATA (ssqosid,SBI_HART_EXT_SSQOSID ),__SBI_HART_EXT_DATA (ssstateen,SBI_HART_EXT_SSSTATEEN ),__SBI_HART_EXT_DATA (xsfcflushdlone,SBI_HART_EXT_XSIFIVE_CFLUSH_D_L1 ), __SBI_HART_EXT_DATA(xsfcease, SBI_HART_EXT_XSIFIVE_CEASE),
Signature · 7 lines
2.50.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
2025-11-14T15:13:58+08:00, <[email protected]>:
Quoted 14 lines
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.
Quoted 5 lines
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]>---
v4: remove extraneous parentheses around SMSTATEEN0_SRMCFG
include/sbi/sbi_hart.h static int switch_to_next_domain_context(struct hart_context *ctx, · line 152
Quoted 11 lines
include/sbi/sbi_hart.h +4
-1@@ -143,8 +145,11 @@ static int switch_to_next_domain_context(struct hart_context *ctx, ctx->satp =csr_swap (CSR_SATP , dom_ctx->satp);if (sbi_hart_priv_version (scratch) >=SBI_HART_PRIV_VER_1_10 ) ctx->scounteren =csr_swap (CSR_SCOUNTEREN , dom_ctx->scounteren); -if (sbi_hart_priv_version (scratch) >=SBI_HART_PRIV_VER_1_12 ) +if (sbi_hart_priv_version (scratch) >=SBI_HART_PRIV_VER_1_12 ) { ctx->senvcfg =csr_swap (CSR_SENVCFG , dom_ctx->senvcfg); +if (sbi_hart_has_extension (scratch,SBI_HART_EXT_SSQOSID )) + ctx->srmcfg =csr_swap (CSR_SRMCFG , dom_ctx->srmcfg); + }
This should be:
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12)
ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
+ if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
+ ctx->srmcfg = csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
Because SBI_HART_EXT_SSQOSID doesn't depend on SBI_HART_PRIV_VER_1_12.
Thanks.
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi