Skip to content

Commit ec52ac7

Browse files
committed
lib: sbi: Enable Ssqosid Ext using mstateen0
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 Changes in v5: - Remove SBI_HART_EXT_SSQOSID dependency SBI_HART_PRIV_VER_1_12 Changes in v4: - Remove extraneous parentheses around SMSTATEEN0_SRMCFG Changes in v3: - Check SBI_HART_EXT_SSQOSID when swapping SRMCFG Changes in v2: - Remove trap-n-detect - Context switch CSR_SRMCFG Signed-off-by: Chen Pei <cp0613@linux.alibaba.com> Reviewed-by: Radim Krčmář <rkrcmar@ventanamicro.com> Link: https://lore.kernel.org/r/20251114115722.1831-1-cp0613@linux.alibaba.com Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent ce6ec8f commit ec52ac7

4 files changed

Lines changed: 17 additions & 0 deletions

File tree

include/sbi/riscv_encoding.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@
383383
#define CSR_SSTATEEN2 0x10E
384384
#define CSR_SSTATEEN3 0x10F
385385

386+
/* Supervisor Resource Management Configuration CSRs */
387+
#define CSR_SRMCFG 0x181
388+
386389
/* Machine-Level Control transfer records CSRs */
387390
#define CSR_MCTRCTL 0x34e
388391

@@ -822,6 +825,8 @@
822825
#define SMSTATEEN0_FCSR (_ULL(1) << SMSTATEEN0_FCSR_SHIFT)
823826
#define SMSTATEEN0_CTR_SHIFT 54
824827
#define SMSTATEEN0_CTR (_ULL(1) << SMSTATEEN0_CTR_SHIFT)
828+
#define SMSTATEEN0_SRMCFG_SHIFT 55
829+
#define SMSTATEEN0_SRMCFG (_ULL(1) << SMSTATEEN0_SRMCFG_SHIFT)
825830
#define SMSTATEEN0_CONTEXT_SHIFT 57
826831
#define SMSTATEEN0_CONTEXT (_ULL(1) << SMSTATEEN0_CONTEXT_SHIFT)
827832
#define SMSTATEEN0_IMSIC_SHIFT 58

include/sbi/sbi_hart.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ enum sbi_hart_extensions {
7979
SBI_HART_EXT_SMCTR,
8080
/** HART has CTR S-mode CSRs */
8181
SBI_HART_EXT_SSCTR,
82+
/** Hart has Ssqosid extension */
83+
SBI_HART_EXT_SSQOSID,
8284
/** HART has Ssstateen extension **/
8385
SBI_HART_EXT_SSSTATEEN,
8486

lib/sbi/sbi_domain_context.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ struct hart_context {
4545
unsigned long scounteren;
4646
/** Supervisor environment configuration register */
4747
unsigned long senvcfg;
48+
/** Supervisor resource management configuration register */
49+
unsigned long srmcfg;
4850

4951
/** Reference to the owning domain */
5052
struct sbi_domain *dom;
@@ -135,6 +137,8 @@ static void switch_to_next_domain_context(struct hart_context *ctx,
135137
ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
136138
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12)
137139
ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
140+
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
141+
ctx->srmcfg = csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
138142

139143
/* Save current trap state and restore target domain's trap state */
140144
trap_ctx = sbi_trap_get_context(scratch);

lib/sbi/sbi_hart.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ static void mstatus_init(struct sbi_scratch *scratch)
110110
else
111111
mstateen_val &= ~SMSTATEEN0_CTR;
112112

113+
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
114+
mstateen_val |= SMSTATEEN0_SRMCFG;
115+
else
116+
mstateen_val &= ~SMSTATEEN0_SRMCFG;
117+
113118
csr_write64(CSR_MSTATEEN0, mstateen_val);
114119
csr_write64(CSR_MSTATEEN1, SMSTATEEN_STATEN);
115120
csr_write64(CSR_MSTATEEN2, SMSTATEEN_STATEN);
@@ -724,6 +729,7 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = {
724729
__SBI_HART_EXT_DATA(ssdbltrp, SBI_HART_EXT_SSDBLTRP),
725730
__SBI_HART_EXT_DATA(smctr, SBI_HART_EXT_SMCTR),
726731
__SBI_HART_EXT_DATA(ssctr, SBI_HART_EXT_SSCTR),
732+
__SBI_HART_EXT_DATA(ssqosid, SBI_HART_EXT_SSQOSID),
727733
__SBI_HART_EXT_DATA(ssstateen, SBI_HART_EXT_SSSTATEEN),
728734
};
729735

0 commit comments

Comments
 (0)