* [PATCH 0/6] lib: sbi: sse: spec update and fixes
@ 2025-03-17 10:54 Clément Léger
2025-03-17 10:54 ` [PATCH 1/6] lib: sbi: sse: Update SSE event ids Clément Léger
` (5 more replies)
0 siblings, 6 replies; 15+ messages in thread
From: Clément Léger @ 2025-03-17 10:54 UTC (permalink / raw)
To: opensbi
The SBI specification added a few new events as well as specifying
sse_write_attrs() invalid attributes errors. Also handle new fields
to be saved (SPELP, SDT) upon injection.
Cl?ment L?ger (6):
lib: sbi: sse: Update SSE event ids
lib: sbi: sse: Fix format string for event invalid state
lib: sbi: sse: Return SBI_EDENIED for read only parameters.
lib: sbi: sse: Rename STATUS* interrupted flags to SSTATUS*
lib: sbi: sse: Add support for SSTATUS.SPELP
lib: sbi: sse: Add support for SSTATUS.SDT
include/sbi/riscv_encoding.h | 3 +-
include/sbi/sbi_ecall_interface.h | 50 ++++++++++++++++++++++++-------
lib/sbi/sbi_pmu.c | 4 +--
lib/sbi/sbi_sse.c | 50 +++++++++++++++++++++----------
4 files changed, 78 insertions(+), 29 deletions(-)
--
2.47.2
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 1/6] lib: sbi: sse: Update SSE event ids
2025-03-17 10:54 [PATCH 0/6] lib: sbi: sse: spec update and fixes Clément Léger
@ 2025-03-17 10:54 ` Clément Léger
2025-03-24 16:15 ` Andrew Jones
2025-03-17 10:54 ` [PATCH 2/6] lib: sbi: sse: Fix format string for event invalid state Clément Léger
` (4 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Clément Léger @ 2025-03-17 10:54 UTC (permalink / raw)
To: opensbi
The latest specification added new high priority RAS events and renamed
the PMU to PMU_OVERFLOW.
Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
---
include/sbi/sbi_ecall_interface.h | 44 ++++++++++++++++++++++++-------
lib/sbi/sbi_pmu.c | 4 +--
lib/sbi/sbi_sse.c | 8 +++---
3 files changed, 42 insertions(+), 14 deletions(-)
diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h
index a7dab8c3..bd694aa8 100644
--- a/include/sbi/sbi_ecall_interface.h
+++ b/include/sbi/sbi_ecall_interface.h
@@ -393,34 +393,60 @@ enum sbi_sse_state {
};
/* SBI SSE Event IDs. */
-#define SBI_SSE_EVENT_LOCAL_RAS 0x00000000
+/* Range 0x00000000 - 0x0000ffff */
+#define SBI_SSE_EVENT_LOCAL_HIGH_PRIO_RAS 0x00000000
#define SBI_SSE_EVENT_LOCAL_DOUBLE_TRAP 0x00000001
+#define SBI_SSE_EVENT_LOCAL_RESERVED_0_START 0x00000002
+#define SBI_SSE_EVENT_LOCAL_RESERVED_0_END 0x00003fff
#define SBI_SSE_EVENT_LOCAL_PLAT_0_START 0x00004000
#define SBI_SSE_EVENT_LOCAL_PLAT_0_END 0x00007fff
-#define SBI_SSE_EVENT_GLOBAL_RAS 0x00008000
+
+#define SBI_SSE_EVENT_GLOBAL_HIGH_PRIO_RAS 0x00008000
+#define SBI_SSE_EVENT_GLOBAL_RESERVED_0_START 0x00008001
+#define SBI_SSE_EVENT_GLOBAL_RESERVED_0_END 0x0000bfff
#define SBI_SSE_EVENT_GLOBAL_PLAT_0_START 0x0000c000
#define SBI_SSE_EVENT_GLOBAL_PLAT_0_END 0x0000ffff
-#define SBI_SSE_EVENT_LOCAL_PMU 0x00010000
+/* Range 0x00010000 - 0x0001ffff */
+#define SBI_SSE_EVENT_LOCAL_PMU_OVERFLOW 0x00010000
+#define SBI_SSE_EVENT_LOCAL_RESERVED_1_START 0x00010001
+#define SBI_SSE_EVENT_LOCAL_RESERVED_1_END 0x00013fff
#define SBI_SSE_EVENT_LOCAL_PLAT_1_START 0x00014000
#define SBI_SSE_EVENT_LOCAL_PLAT_1_END 0x00017fff
+
+#define SBI_SSE_EVENT_GLOBAL_RESERVED_1_START 0x00018000
+#define SBI_SSE_EVENT_GLOBAL_RESERVED_1_END 0x0001bfff
#define SBI_SSE_EVENT_GLOBAL_PLAT_1_START 0x0001c000
#define SBI_SSE_EVENT_GLOBAL_PLAT_1_END 0x0001ffff
-#define SBI_SSE_EVENT_LOCAL_PLAT_2_START 0x00024000
-#define SBI_SSE_EVENT_LOCAL_PLAT_2_END 0x00027fff
-#define SBI_SSE_EVENT_GLOBAL_PLAT_2_START 0x0002c000
-#define SBI_SSE_EVENT_GLOBAL_PLAT_2_END 0x0002ffff
+/* Range 0x00100000 - 0x0010ffff */
+#define SBI_SSE_EVENT_LOCAL_LOW_PRIO_RAS 0x00100000
+#define SBI_SSE_EVENT_LOCAL_RESERVED_2_START 0x00100001
+#define SBI_SSE_EVENT_LOCAL_RESERVED_2_END 0x00103fff
+#define SBI_SSE_EVENT_LOCAL_PLAT_2_START 0x00104000
+#define SBI_SSE_EVENT_LOCAL_PLAT_2_END 0x00107fff
+#define SBI_SSE_EVENT_GLOBAL_LOW_PRIO_RAS 0x00108000
+#define SBI_SSE_EVENT_GLOBAL_RESERVED_2_START 0x00108001
+#define SBI_SSE_EVENT_GLOBAL_RESERVED_2_END 0x0010bfff
+#define SBI_SSE_EVENT_GLOBAL_PLAT_2_START 0x0010c000
+#define SBI_SSE_EVENT_GLOBAL_PLAT_2_END 0x0010ffff
+
+/* Range 0xffff0000 - 0xffffffff */
#define SBI_SSE_EVENT_LOCAL_SOFTWARE 0xffff0000
+#define SBI_SSE_EVENT_LOCAL_RESERVED_3_START 0xffff0001
+#define SBI_SSE_EVENT_LOCAL_RESERVED_3_END 0xffff3fff
#define SBI_SSE_EVENT_LOCAL_PLAT_3_START 0xffff4000
#define SBI_SSE_EVENT_LOCAL_PLAT_3_END 0xffff7fff
+
#define SBI_SSE_EVENT_GLOBAL_SOFTWARE 0xffff8000
+#define SBI_SSE_EVENT_GLOBAL_RESERVED_3_START 0xffff8001
+#define SBI_SSE_EVENT_GLOBAL_RESERVED_3_END 0xffffbfff
#define SBI_SSE_EVENT_GLOBAL_PLAT_3_START 0xffffc000
#define SBI_SSE_EVENT_GLOBAL_PLAT_3_END 0xffffffff
-#define SBI_SSE_EVENT_GLOBAL_BIT (1 << 15)
-#define SBI_SSE_EVENT_PLATFORM_BIT (1 << 14)
+#define SBI_SSE_EVENT_GLOBAL_BIT BIT(15)
+#define SBI_SSE_EVENT_PLATFORM_BIT BIT(14)
/* SBI function IDs for MPXY extension */
#define SBI_EXT_MPXY_GET_SHMEM_SIZE 0x0
diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c
index 40b898fe..4f113c23 100644
--- a/lib/sbi/sbi_pmu.c
+++ b/lib/sbi/sbi_pmu.c
@@ -313,7 +313,7 @@ void sbi_pmu_ovf_irq()
* on an irq being triggered
*/
csr_clear(CSR_MIE, sbi_pmu_irq_mask());
- sbi_sse_inject_event(SBI_SSE_EVENT_LOCAL_PMU);
+ sbi_sse_inject_event(SBI_SSE_EVENT_LOCAL_PMU_OVERFLOW);
}
static int pmu_ctr_enable_irq_hw(int ctr_idx)
@@ -1166,7 +1166,7 @@ int sbi_pmu_init(struct sbi_scratch *scratch, bool cold_boot)
total_ctrs = num_hw_ctrs + SBI_PMU_FW_CTR_MAX;
if (sbi_pmu_irq_bit() >= 0)
- sbi_sse_add_event(SBI_SSE_EVENT_LOCAL_PMU, &pmu_sse_cb_ops);
+ sbi_sse_add_event(SBI_SSE_EVENT_LOCAL_PMU_OVERFLOW, &pmu_sse_cb_ops);
}
phs = pmu_get_hart_state_ptr(scratch);
diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
index 2f9bdef8..4722ddc4 100644
--- a/lib/sbi/sbi_sse.c
+++ b/lib/sbi/sbi_sse.c
@@ -195,10 +195,12 @@ static SBI_SLIST_HEAD(supported_events, sse_event_info) =
* events in order to return SBI_ERR_NOT_SUPPORTED for them.
*/
static const uint32_t standard_events[] = {
- SBI_SSE_EVENT_LOCAL_RAS,
+ SBI_SSE_EVENT_LOCAL_HIGH_PRIO_RAS,
SBI_SSE_EVENT_LOCAL_DOUBLE_TRAP,
- SBI_SSE_EVENT_GLOBAL_RAS,
- SBI_SSE_EVENT_LOCAL_PMU,
+ SBI_SSE_EVENT_GLOBAL_HIGH_PRIO_RAS,
+ SBI_SSE_EVENT_LOCAL_PMU_OVERFLOW,
+ SBI_SSE_EVENT_LOCAL_LOW_PRIO_RAS,
+ SBI_SSE_EVENT_GLOBAL_LOW_PRIO_RAS,
SBI_SSE_EVENT_LOCAL_SOFTWARE,
SBI_SSE_EVENT_GLOBAL_SOFTWARE,
};
--
2.47.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 2/6] lib: sbi: sse: Fix format string for event invalid state
2025-03-17 10:54 [PATCH 0/6] lib: sbi: sse: spec update and fixes Clément Léger
2025-03-17 10:54 ` [PATCH 1/6] lib: sbi: sse: Update SSE event ids Clément Léger
@ 2025-03-17 10:54 ` Clément Léger
2025-03-24 16:39 ` Andrew Jones
2025-03-17 10:54 ` [PATCH 3/6] lib: sbi: sse: Return SBI_EDENIED for read only parameters Clément Léger
` (3 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Clément Léger @ 2025-03-17 10:54 UTC (permalink / raw)
To: opensbi
Add a missing newline and modify the display value of the event id to
use hex representation.
Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
---
lib/sbi/sbi_sse.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
index 4722ddc4..a30fad54 100644
--- a/lib/sbi/sbi_sse.c
+++ b/lib/sbi/sbi_sse.c
@@ -1268,7 +1268,7 @@ void sbi_sse_exit(struct sbi_scratch *scratch)
goto skip;
if (sse_event_state(e) > SBI_SSE_STATE_REGISTERED) {
- sbi_printf("Event %d in invalid state at exit",
+ sbi_printf("Event 0x%x in invalid state at exit\n",
info->event_id);
sse_event_set_state(e, SBI_SSE_STATE_UNUSED);
}
--
2.47.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 3/6] lib: sbi: sse: Return SBI_EDENIED for read only parameters.
2025-03-17 10:54 [PATCH 0/6] lib: sbi: sse: spec update and fixes Clément Léger
2025-03-17 10:54 ` [PATCH 1/6] lib: sbi: sse: Update SSE event ids Clément Léger
2025-03-17 10:54 ` [PATCH 2/6] lib: sbi: sse: Fix format string for event invalid state Clément Léger
@ 2025-03-17 10:54 ` Clément Léger
2025-03-24 17:01 ` Andrew Jones
2025-03-17 10:54 ` [PATCH 4/6] lib: sbi: sse: Rename STATUS* interrupted flags to SSTATUS* Clément Léger
` (2 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Clément Léger @ 2025-03-17 10:54 UTC (permalink / raw)
To: opensbi
The SSE specification did specified that read only parameters should
return SBI_EBADRANGE but was modified recently to return SBI_EDENIED.
Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
---
lib/sbi/sbi_sse.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
index a30fad54..ac714b8a 100644
--- a/lib/sbi/sbi_sse.c
+++ b/lib/sbi/sbi_sse.c
@@ -388,7 +388,7 @@ static int sse_event_set_hart_id_check(struct sbi_sse_event *e,
struct sbi_domain *hd = sbi_domain_thishart_ptr();
if (!sse_event_is_global(e))
- return SBI_EBAD_RANGE;
+ return SBI_EDENIED;
if (!sbi_domain_is_assigned_hart(hd, sbi_hartid_to_hartindex(hartid)))
return SBI_EINVAL;
@@ -444,7 +444,7 @@ static int sse_event_set_attr_check(struct sbi_sse_event *e, uint32_t attr_id,
return SBI_OK;
default:
- return SBI_EBAD_RANGE;
+ return SBI_EDENIED;
}
}
--
2.47.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 4/6] lib: sbi: sse: Rename STATUS* interrupted flags to SSTATUS*
2025-03-17 10:54 [PATCH 0/6] lib: sbi: sse: spec update and fixes Clément Léger
` (2 preceding siblings ...)
2025-03-17 10:54 ` [PATCH 3/6] lib: sbi: sse: Return SBI_EDENIED for read only parameters Clément Léger
@ 2025-03-17 10:54 ` Clément Léger
2025-03-24 17:03 ` Andrew Jones
2025-03-17 10:54 ` [PATCH 5/6] lib: sbi: sse: Add support for SSTATUS.SPELP Clément Léger
2025-03-17 10:54 ` [PATCH 6/6] lib: sbi: sse: Add support for SSTATUS.SDT Clément Léger
5 siblings, 1 reply; 15+ messages in thread
From: Clément Léger @ 2025-03-17 10:54 UTC (permalink / raw)
To: opensbi
As raised by Andrew on the kvm-unit-test review, this flags are meant to
hold SSTATUS bits in the specification. Rename them to match that.
Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
---
include/sbi/sbi_ecall_interface.h | 4 ++--
lib/sbi/sbi_sse.c | 12 ++++++------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h
index bd694aa8..51e42eed 100644
--- a/include/sbi/sbi_ecall_interface.h
+++ b/include/sbi/sbi_ecall_interface.h
@@ -380,8 +380,8 @@ enum sbi_sse_attr_id {
#define SBI_SSE_ATTR_CONFIG_ONESHOT (1 << 0)
-#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPP BIT(0)
-#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPIE BIT(1)
+#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP BIT(0)
+#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE BIT(1)
#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV BIT(2)
#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP BIT(3)
diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
index ac714b8a..fb7ccf05 100644
--- a/lib/sbi/sbi_sse.c
+++ b/lib/sbi/sbi_sse.c
@@ -427,8 +427,8 @@ static int sse_event_set_attr_check(struct sbi_sse_event *e, uint32_t attr_id,
return sse_event_set_hart_id_check(e, val);
case SBI_SSE_ATTR_INTERRUPTED_FLAGS:
- if (val & ~(SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPP |
- SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPIE |
+ if (val & ~(SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP |
+ SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE |
SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV |
SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP))
return SBI_EINVAL;
@@ -513,9 +513,9 @@ static unsigned long sse_interrupted_flags(unsigned long mstatus)
unsigned long hstatus, flags = 0;
if (mstatus & (MSTATUS_SPIE))
- flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPIE;
+ flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE;
if (mstatus & (MSTATUS_SPP))
- flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPP;
+ flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP;
if (misa_extension('H')) {
hstatus = csr_read(CSR_HSTATUS);
@@ -626,11 +626,11 @@ static void sse_event_resume(struct sbi_sse_event *e,
regs->mstatus |= MSTATUS_SIE;
regs->mstatus &= ~MSTATUS_SPIE;
- if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPIE)
+ if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE)
regs->mstatus |= MSTATUS_SPIE;
regs->mstatus &= ~MSTATUS_SPP;
- if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPP)
+ if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP)
regs->mstatus |= MSTATUS_SPP;
regs->a7 = i_ctx->a7;
--
2.47.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 5/6] lib: sbi: sse: Add support for SSTATUS.SPELP
2025-03-17 10:54 [PATCH 0/6] lib: sbi: sse: spec update and fixes Clément Léger
` (3 preceding siblings ...)
2025-03-17 10:54 ` [PATCH 4/6] lib: sbi: sse: Rename STATUS* interrupted flags to SSTATUS* Clément Léger
@ 2025-03-17 10:54 ` Clément Léger
2025-03-24 17:08 ` Andrew Jones
2025-03-17 10:54 ` [PATCH 6/6] lib: sbi: sse: Add support for SSTATUS.SDT Clément Léger
5 siblings, 1 reply; 15+ messages in thread
From: Clément Léger @ 2025-03-17 10:54 UTC (permalink / raw)
To: opensbi
As raised during the ARC review, SPELP was not handled during the event
injection process. Save it as part of the interrupted flags, clear it
before injecting the event and restore it after completion.
Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
---
include/sbi/sbi_ecall_interface.h | 1 +
lib/sbi/sbi_sse.c | 16 +++++++++++++---
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h
index 51e42eed..a93e61fa 100644
--- a/include/sbi/sbi_ecall_interface.h
+++ b/include/sbi/sbi_ecall_interface.h
@@ -384,6 +384,7 @@ enum sbi_sse_attr_id {
#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE BIT(1)
#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV BIT(2)
#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP BIT(3)
+#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP BIT(4)
enum sbi_sse_state {
SBI_SSE_STATE_UNUSED = 0,
diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
index fb7ccf05..a45d3eeb 100644
--- a/lib/sbi/sbi_sse.c
+++ b/lib/sbi/sbi_sse.c
@@ -430,7 +430,8 @@ static int sse_event_set_attr_check(struct sbi_sse_event *e, uint32_t attr_id,
if (val & ~(SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP |
SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE |
SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV |
- SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP))
+ SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP |
+ SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP))
return SBI_EINVAL;
__attribute__((__fallthrough__));
case SBI_SSE_ATTR_INTERRUPTED_SEPC:
@@ -516,6 +517,8 @@ static unsigned long sse_interrupted_flags(unsigned long mstatus)
flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE;
if (mstatus & (MSTATUS_SPP))
flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP;
+ if (mstatus & (MSTATUS_SPELP))
+ flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP;
if (misa_extension('H')) {
hstatus = csr_read(CSR_HSTATUS);
@@ -573,8 +576,11 @@ static void sse_event_inject(struct sbi_sse_event *e,
regs->a7 = e->attrs.entry.arg;
regs->mepc = e->attrs.entry.pc;
- /* Return to S-mode with virtualization disabled */
- regs->mstatus &= ~(MSTATUS_MPP | MSTATUS_SIE);
+ /*
+ * Return to S-mode with virtualization disabled, no expected landing
+ * pad.
+ */
+ regs->mstatus &= ~(MSTATUS_MPP | MSTATUS_SIE | MSTATUS_SPELP);
regs->mstatus |= (PRV_S << MSTATUS_MPP_SHIFT);
#if __riscv_xlen == 64
@@ -633,6 +639,10 @@ static void sse_event_resume(struct sbi_sse_event *e,
if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP)
regs->mstatus |= MSTATUS_SPP;
+ regs->mstatus &= ~MSTATUS_SPELP;
+ if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP)
+ regs->mstatus |= MSTATUS_SPELP;
+
regs->a7 = i_ctx->a7;
regs->a6 = i_ctx->a6;
csr_write(CSR_SEPC, i_ctx->sepc);
--
2.47.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 6/6] lib: sbi: sse: Add support for SSTATUS.SDT
2025-03-17 10:54 [PATCH 0/6] lib: sbi: sse: spec update and fixes Clément Léger
` (4 preceding siblings ...)
2025-03-17 10:54 ` [PATCH 5/6] lib: sbi: sse: Add support for SSTATUS.SPELP Clément Léger
@ 2025-03-17 10:54 ` Clément Léger
2025-03-24 17:46 ` Andrew Jones
5 siblings, 1 reply; 15+ messages in thread
From: Clément Léger @ 2025-03-17 10:54 UTC (permalink / raw)
To: opensbi
Similarly to what is done for SPELP, handle SSTATUS.SDT upon event
injection. In order to mimick an interrupt, set SDT to 1 for injection and
save its previous value in interrupted_flags[5:5]. Restore it upon
completion.
Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
---
include/sbi/riscv_encoding.h | 3 ++-
include/sbi/sbi_ecall_interface.h | 1 +
lib/sbi/sbi_sse.c | 12 ++++++++++--
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h
index 03c68a57..84d3c17b 100644
--- a/include/sbi/riscv_encoding.h
+++ b/include/sbi/riscv_encoding.h
@@ -32,7 +32,8 @@
#define MSTATUS_TVM _UL(0x00100000)
#define MSTATUS_TW _UL(0x00200000)
#define MSTATUS_TSR _UL(0x00400000)
-#define MSTATUS_SPELP _UL(0x00800000)
+#define MSTATUS_SPELP _UL(0x00800000)
+#define MSTATUS_SDT _UL(0x01000000)
#define MSTATUS32_SD _UL(0x80000000)
#if __riscv_xlen == 64
#define MSTATUS_UXL _ULL(0x0000000300000000)
diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h
index a93e61fa..3d8bbcf3 100644
--- a/include/sbi/sbi_ecall_interface.h
+++ b/include/sbi/sbi_ecall_interface.h
@@ -385,6 +385,7 @@ enum sbi_sse_attr_id {
#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV BIT(2)
#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP BIT(3)
#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP BIT(4)
+#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT BIT(5)
enum sbi_sse_state {
SBI_SSE_STATE_UNUSED = 0,
diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
index a45d3eeb..79c5bdb4 100644
--- a/lib/sbi/sbi_sse.c
+++ b/lib/sbi/sbi_sse.c
@@ -431,7 +431,8 @@ static int sse_event_set_attr_check(struct sbi_sse_event *e, uint32_t attr_id,
SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE |
SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV |
SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP |
- SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP))
+ SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP |
+ SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT))
return SBI_EINVAL;
__attribute__((__fallthrough__));
case SBI_SSE_ATTR_INTERRUPTED_SEPC:
@@ -519,6 +520,8 @@ static unsigned long sse_interrupted_flags(unsigned long mstatus)
flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP;
if (mstatus & (MSTATUS_SPELP))
flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP;
+ if (mstatus & (MSTATUS_SDT))
+ flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT;
if (misa_extension('H')) {
hstatus = csr_read(CSR_HSTATUS);
@@ -578,10 +581,11 @@ static void sse_event_inject(struct sbi_sse_event *e,
/*
* Return to S-mode with virtualization disabled, no expected landing
- * pad.
+ * pad, supervisor trap disabled.
*/
regs->mstatus &= ~(MSTATUS_MPP | MSTATUS_SIE | MSTATUS_SPELP);
regs->mstatus |= (PRV_S << MSTATUS_MPP_SHIFT);
+ regs->mstatus |= MSTATUS_SDT;
#if __riscv_xlen == 64
regs->mstatus &= ~MSTATUS_MPV;
@@ -643,6 +647,10 @@ static void sse_event_resume(struct sbi_sse_event *e,
if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP)
regs->mstatus |= MSTATUS_SPELP;
+ regs->mstatus &= ~MSTATUS_SDT;
+ if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT)
+ regs->mstatus |= MSTATUS_SDT;
+
regs->a7 = i_ctx->a7;
regs->a6 = i_ctx->a6;
csr_write(CSR_SEPC, i_ctx->sepc);
--
2.47.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 1/6] lib: sbi: sse: Update SSE event ids
2025-03-17 10:54 ` [PATCH 1/6] lib: sbi: sse: Update SSE event ids Clément Léger
@ 2025-03-24 16:15 ` Andrew Jones
0 siblings, 0 replies; 15+ messages in thread
From: Andrew Jones @ 2025-03-24 16:15 UTC (permalink / raw)
To: opensbi
On Mon, Mar 17, 2025 at 11:54:19AM +0100, Cl?ment L?ger wrote:
> The latest specification added new high priority RAS events and renamed
> the PMU to PMU_OVERFLOW.
>
> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
> ---
> include/sbi/sbi_ecall_interface.h | 44 ++++++++++++++++++++++++-------
> lib/sbi/sbi_pmu.c | 4 +--
> lib/sbi/sbi_sse.c | 8 +++---
> 3 files changed, 42 insertions(+), 14 deletions(-)
>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 2/6] lib: sbi: sse: Fix format string for event invalid state
2025-03-17 10:54 ` [PATCH 2/6] lib: sbi: sse: Fix format string for event invalid state Clément Léger
@ 2025-03-24 16:39 ` Andrew Jones
2025-03-24 16:41 ` Clément Léger
0 siblings, 1 reply; 15+ messages in thread
From: Andrew Jones @ 2025-03-24 16:39 UTC (permalink / raw)
To: opensbi
On Mon, Mar 17, 2025 at 11:54:20AM +0100, Cl?ment L?ger wrote:
> Add a missing newline and modify the display value of the event id to
> use hex representation.
>
> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
> ---
> lib/sbi/sbi_sse.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
> index 4722ddc4..a30fad54 100644
> --- a/lib/sbi/sbi_sse.c
> +++ b/lib/sbi/sbi_sse.c
> @@ -1268,7 +1268,7 @@ void sbi_sse_exit(struct sbi_scratch *scratch)
> goto skip;
>
> if (sse_event_state(e) > SBI_SSE_STATE_REGISTERED) {
> - sbi_printf("Event %d in invalid state at exit",
> + sbi_printf("Event 0x%x in invalid state at exit\n",
> info->event_id);
> sse_event_set_state(e, SBI_SSE_STATE_UNUSED);
> }
> --
> 2.47.2
>
I'm not sure we want the print statement, but if we do, then
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 2/6] lib: sbi: sse: Fix format string for event invalid state
2025-03-24 16:39 ` Andrew Jones
@ 2025-03-24 16:41 ` Clément Léger
0 siblings, 0 replies; 15+ messages in thread
From: Clément Léger @ 2025-03-24 16:41 UTC (permalink / raw)
To: opensbi
On 24/03/2025 17:39, Andrew Jones wrote:
> On Mon, Mar 17, 2025 at 11:54:20AM +0100, Cl?ment L?ger wrote:
>> Add a missing newline and modify the display value of the event id to
>> use hex representation.
>>
>> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
>> ---
>> lib/sbi/sbi_sse.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
>> index 4722ddc4..a30fad54 100644
>> --- a/lib/sbi/sbi_sse.c
>> +++ b/lib/sbi/sbi_sse.c
>> @@ -1268,7 +1268,7 @@ void sbi_sse_exit(struct sbi_scratch *scratch)
>> goto skip;
>>
>> if (sse_event_state(e) > SBI_SSE_STATE_REGISTERED) {
>> - sbi_printf("Event %d in invalid state at exit",
>> + sbi_printf("Event 0x%x in invalid state at exit\n",
>> info->event_id);
>> sse_event_set_state(e, SBI_SSE_STATE_UNUSED);
>> }
>> --
>> 2.47.2
>>
>
> I'm not sure we want the print statement, but if we do, then
Agreed, that's actually debug so that should probably be removed and
handled gracefully.
Thanks,
Cl?ment
>
> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 3/6] lib: sbi: sse: Return SBI_EDENIED for read only parameters.
2025-03-17 10:54 ` [PATCH 3/6] lib: sbi: sse: Return SBI_EDENIED for read only parameters Clément Léger
@ 2025-03-24 17:01 ` Andrew Jones
2025-03-24 17:02 ` Clément Léger
0 siblings, 1 reply; 15+ messages in thread
From: Andrew Jones @ 2025-03-24 17:01 UTC (permalink / raw)
To: opensbi
On Mon, Mar 17, 2025 at 11:54:21AM +0100, Cl?ment L?ger wrote:
> The SSE specification did specified that read only parameters should
> return SBI_EBADRANGE but was modified recently to return SBI_EDENIED.
>
> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
> ---
> lib/sbi/sbi_sse.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
> index a30fad54..ac714b8a 100644
> --- a/lib/sbi/sbi_sse.c
> +++ b/lib/sbi/sbi_sse.c
> @@ -388,7 +388,7 @@ static int sse_event_set_hart_id_check(struct sbi_sse_event *e,
> struct sbi_domain *hd = sbi_domain_thishart_ptr();
>
> if (!sse_event_is_global(e))
> - return SBI_EBAD_RANGE;
> + return SBI_EDENIED;
>
> if (!sbi_domain_is_assigned_hart(hd, sbi_hartid_to_hartindex(hartid)))
> return SBI_EINVAL;
> @@ -444,7 +444,7 @@ static int sse_event_set_attr_check(struct sbi_sse_event *e, uint32_t attr_id,
>
> return SBI_OK;
> default:
> - return SBI_EBAD_RANGE;
> + return SBI_EDENIED;
This confused me at first. Maybe a comment pointing out that
sbi_sse_attr_check() already confirmed we're in range and
this switch default just catches read-only attributes would
be helpful.
Otherwise,
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Thanks,
drew
> }
> }
>
> --
> 2.47.2
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 3/6] lib: sbi: sse: Return SBI_EDENIED for read only parameters.
2025-03-24 17:01 ` Andrew Jones
@ 2025-03-24 17:02 ` Clément Léger
0 siblings, 0 replies; 15+ messages in thread
From: Clément Léger @ 2025-03-24 17:02 UTC (permalink / raw)
To: opensbi
On 24/03/2025 18:01, Andrew Jones wrote:
> On Mon, Mar 17, 2025 at 11:54:21AM +0100, Cl?ment L?ger wrote:
>> The SSE specification did specified that read only parameters should
>> return SBI_EBADRANGE but was modified recently to return SBI_EDENIED.
>>
>> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
>> ---
>> lib/sbi/sbi_sse.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
>> index a30fad54..ac714b8a 100644
>> --- a/lib/sbi/sbi_sse.c
>> +++ b/lib/sbi/sbi_sse.c
>> @@ -388,7 +388,7 @@ static int sse_event_set_hart_id_check(struct sbi_sse_event *e,
>> struct sbi_domain *hd = sbi_domain_thishart_ptr();
>>
>> if (!sse_event_is_global(e))
>> - return SBI_EBAD_RANGE;
>> + return SBI_EDENIED;
>>
>> if (!sbi_domain_is_assigned_hart(hd, sbi_hartid_to_hartindex(hartid)))
>> return SBI_EINVAL;
>> @@ -444,7 +444,7 @@ static int sse_event_set_attr_check(struct sbi_sse_event *e, uint32_t attr_id,
>>
>> return SBI_OK;
>> default:
>> - return SBI_EBAD_RANGE;
>> + return SBI_EDENIED;
>
> This confused me at first. Maybe a comment pointing out that
> sbi_sse_attr_check() already confirmed we're in range and
> this switch default just catches read-only attributes would
> be helpful.
Yes sure, I'll do that in the next version.
Thanks,
Cl?ment
>
> Otherwise,
>
> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
>
> Thanks,
> drew
>
>> }
>> }
>>
>> --
>> 2.47.2
>>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 4/6] lib: sbi: sse: Rename STATUS* interrupted flags to SSTATUS*
2025-03-17 10:54 ` [PATCH 4/6] lib: sbi: sse: Rename STATUS* interrupted flags to SSTATUS* Clément Léger
@ 2025-03-24 17:03 ` Andrew Jones
0 siblings, 0 replies; 15+ messages in thread
From: Andrew Jones @ 2025-03-24 17:03 UTC (permalink / raw)
To: opensbi
On Mon, Mar 17, 2025 at 11:54:22AM +0100, Cl?ment L?ger wrote:
> As raised by Andrew on the kvm-unit-test review, this flags are meant to
> hold SSTATUS bits in the specification. Rename them to match that.
>
> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
> ---
> include/sbi/sbi_ecall_interface.h | 4 ++--
> lib/sbi/sbi_sse.c | 12 ++++++------
> 2 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h
> index bd694aa8..51e42eed 100644
> --- a/include/sbi/sbi_ecall_interface.h
> +++ b/include/sbi/sbi_ecall_interface.h
> @@ -380,8 +380,8 @@ enum sbi_sse_attr_id {
>
> #define SBI_SSE_ATTR_CONFIG_ONESHOT (1 << 0)
>
> -#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPP BIT(0)
> -#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPIE BIT(1)
> +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP BIT(0)
> +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE BIT(1)
> #define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV BIT(2)
> #define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP BIT(3)
>
> diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
> index ac714b8a..fb7ccf05 100644
> --- a/lib/sbi/sbi_sse.c
> +++ b/lib/sbi/sbi_sse.c
> @@ -427,8 +427,8 @@ static int sse_event_set_attr_check(struct sbi_sse_event *e, uint32_t attr_id,
>
> return sse_event_set_hart_id_check(e, val);
> case SBI_SSE_ATTR_INTERRUPTED_FLAGS:
> - if (val & ~(SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPP |
> - SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPIE |
> + if (val & ~(SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP |
> + SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE |
> SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV |
> SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP))
> return SBI_EINVAL;
> @@ -513,9 +513,9 @@ static unsigned long sse_interrupted_flags(unsigned long mstatus)
> unsigned long hstatus, flags = 0;
>
> if (mstatus & (MSTATUS_SPIE))
> - flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPIE;
> + flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE;
> if (mstatus & (MSTATUS_SPP))
> - flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPP;
> + flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP;
>
> if (misa_extension('H')) {
> hstatus = csr_read(CSR_HSTATUS);
> @@ -626,11 +626,11 @@ static void sse_event_resume(struct sbi_sse_event *e,
> regs->mstatus |= MSTATUS_SIE;
>
> regs->mstatus &= ~MSTATUS_SPIE;
> - if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPIE)
> + if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE)
> regs->mstatus |= MSTATUS_SPIE;
>
> regs->mstatus &= ~MSTATUS_SPP;
> - if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPP)
> + if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP)
> regs->mstatus |= MSTATUS_SPP;
>
> regs->a7 = i_ctx->a7;
> --
> 2.47.2
>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 5/6] lib: sbi: sse: Add support for SSTATUS.SPELP
2025-03-17 10:54 ` [PATCH 5/6] lib: sbi: sse: Add support for SSTATUS.SPELP Clément Léger
@ 2025-03-24 17:08 ` Andrew Jones
0 siblings, 0 replies; 15+ messages in thread
From: Andrew Jones @ 2025-03-24 17:08 UTC (permalink / raw)
To: opensbi
On Mon, Mar 17, 2025 at 11:54:23AM +0100, Cl?ment L?ger wrote:
> As raised during the ARC review, SPELP was not handled during the event
> injection process. Save it as part of the interrupted flags, clear it
> before injecting the event and restore it after completion.
>
> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
> ---
> include/sbi/sbi_ecall_interface.h | 1 +
> lib/sbi/sbi_sse.c | 16 +++++++++++++---
> 2 files changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h
> index 51e42eed..a93e61fa 100644
> --- a/include/sbi/sbi_ecall_interface.h
> +++ b/include/sbi/sbi_ecall_interface.h
> @@ -384,6 +384,7 @@ enum sbi_sse_attr_id {
> #define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE BIT(1)
> #define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV BIT(2)
> #define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP BIT(3)
> +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP BIT(4)
>
> enum sbi_sse_state {
> SBI_SSE_STATE_UNUSED = 0,
> diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
> index fb7ccf05..a45d3eeb 100644
> --- a/lib/sbi/sbi_sse.c
> +++ b/lib/sbi/sbi_sse.c
> @@ -430,7 +430,8 @@ static int sse_event_set_attr_check(struct sbi_sse_event *e, uint32_t attr_id,
> if (val & ~(SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP |
> SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE |
> SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV |
> - SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP))
> + SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP |
> + SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP))
> return SBI_EINVAL;
> __attribute__((__fallthrough__));
> case SBI_SSE_ATTR_INTERRUPTED_SEPC:
> @@ -516,6 +517,8 @@ static unsigned long sse_interrupted_flags(unsigned long mstatus)
> flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE;
> if (mstatus & (MSTATUS_SPP))
> flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP;
> + if (mstatus & (MSTATUS_SPELP))
> + flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP;
Not sure why we have the superfluous (), but I guess this is consistent.
>
> if (misa_extension('H')) {
> hstatus = csr_read(CSR_HSTATUS);
> @@ -573,8 +576,11 @@ static void sse_event_inject(struct sbi_sse_event *e,
> regs->a7 = e->attrs.entry.arg;
> regs->mepc = e->attrs.entry.pc;
>
> - /* Return to S-mode with virtualization disabled */
> - regs->mstatus &= ~(MSTATUS_MPP | MSTATUS_SIE);
> + /*
> + * Return to S-mode with virtualization disabled, no expected landing
s/no/not/
> + * pad.
> + */
> + regs->mstatus &= ~(MSTATUS_MPP | MSTATUS_SIE | MSTATUS_SPELP);
> regs->mstatus |= (PRV_S << MSTATUS_MPP_SHIFT);
>
> #if __riscv_xlen == 64
> @@ -633,6 +639,10 @@ static void sse_event_resume(struct sbi_sse_event *e,
> if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP)
> regs->mstatus |= MSTATUS_SPP;
>
> + regs->mstatus &= ~MSTATUS_SPELP;
> + if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP)
> + regs->mstatus |= MSTATUS_SPELP;
> +
> regs->a7 = i_ctx->a7;
> regs->a6 = i_ctx->a6;
> csr_write(CSR_SEPC, i_ctx->sepc);
> --
> 2.47.2
>
Otherwise,
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 6/6] lib: sbi: sse: Add support for SSTATUS.SDT
2025-03-17 10:54 ` [PATCH 6/6] lib: sbi: sse: Add support for SSTATUS.SDT Clément Léger
@ 2025-03-24 17:46 ` Andrew Jones
0 siblings, 0 replies; 15+ messages in thread
From: Andrew Jones @ 2025-03-24 17:46 UTC (permalink / raw)
To: opensbi
On Mon, Mar 17, 2025 at 11:54:24AM +0100, Cl?ment L?ger wrote:
> Similarly to what is done for SPELP, handle SSTATUS.SDT upon event
> injection. In order to mimick an interrupt, set SDT to 1 for injection and
> save its previous value in interrupted_flags[5:5]. Restore it upon
> completion.
>
> Signed-off-by: Cl?ment L?ger <cleger@rivosinc.com>
> ---
> include/sbi/riscv_encoding.h | 3 ++-
> include/sbi/sbi_ecall_interface.h | 1 +
> lib/sbi/sbi_sse.c | 12 ++++++++++--
> 3 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h
> index 03c68a57..84d3c17b 100644
> --- a/include/sbi/riscv_encoding.h
> +++ b/include/sbi/riscv_encoding.h
> @@ -32,7 +32,8 @@
> #define MSTATUS_TVM _UL(0x00100000)
> #define MSTATUS_TW _UL(0x00200000)
> #define MSTATUS_TSR _UL(0x00400000)
> -#define MSTATUS_SPELP _UL(0x00800000)
> +#define MSTATUS_SPELP _UL(0x00800000)
> +#define MSTATUS_SDT _UL(0x01000000)
> #define MSTATUS32_SD _UL(0x80000000)
> #if __riscv_xlen == 64
> #define MSTATUS_UXL _ULL(0x0000000300000000)
> diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h
> index a93e61fa..3d8bbcf3 100644
> --- a/include/sbi/sbi_ecall_interface.h
> +++ b/include/sbi/sbi_ecall_interface.h
> @@ -385,6 +385,7 @@ enum sbi_sse_attr_id {
> #define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV BIT(2)
> #define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP BIT(3)
> #define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP BIT(4)
> +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT BIT(5)
>
> enum sbi_sse_state {
> SBI_SSE_STATE_UNUSED = 0,
> diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
> index a45d3eeb..79c5bdb4 100644
> --- a/lib/sbi/sbi_sse.c
> +++ b/lib/sbi/sbi_sse.c
> @@ -431,7 +431,8 @@ static int sse_event_set_attr_check(struct sbi_sse_event *e, uint32_t attr_id,
> SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE |
> SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV |
> SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP |
> - SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP))
> + SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP |
> + SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT))
> return SBI_EINVAL;
> __attribute__((__fallthrough__));
> case SBI_SSE_ATTR_INTERRUPTED_SEPC:
> @@ -519,6 +520,8 @@ static unsigned long sse_interrupted_flags(unsigned long mstatus)
> flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP;
> if (mstatus & (MSTATUS_SPELP))
> flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP;
> + if (mstatus & (MSTATUS_SDT))
> + flags |= SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT;
>
> if (misa_extension('H')) {
> hstatus = csr_read(CSR_HSTATUS);
> @@ -578,10 +581,11 @@ static void sse_event_inject(struct sbi_sse_event *e,
>
> /*
> * Return to S-mode with virtualization disabled, no expected landing
> - * pad.
> + * pad, supervisor trap disabled.
> */
> regs->mstatus &= ~(MSTATUS_MPP | MSTATUS_SIE | MSTATUS_SPELP);
> regs->mstatus |= (PRV_S << MSTATUS_MPP_SHIFT);
> + regs->mstatus |= MSTATUS_SDT;
>
> #if __riscv_xlen == 64
> regs->mstatus &= ~MSTATUS_MPV;
> @@ -643,6 +647,10 @@ static void sse_event_resume(struct sbi_sse_event *e,
> if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPELP)
> regs->mstatus |= MSTATUS_SPELP;
>
> + regs->mstatus &= ~MSTATUS_SDT;
> + if (i_ctx->flags & SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SDT)
> + regs->mstatus |= MSTATUS_SDT;
> +
> regs->a7 = i_ctx->a7;
> regs->a6 = i_ctx->a6;
> csr_write(CSR_SEPC, i_ctx->sepc);
> --
> 2.47.2
>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2025-03-24 17:46 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-17 10:54 [PATCH 0/6] lib: sbi: sse: spec update and fixes Clément Léger
2025-03-17 10:54 ` [PATCH 1/6] lib: sbi: sse: Update SSE event ids Clément Léger
2025-03-24 16:15 ` Andrew Jones
2025-03-17 10:54 ` [PATCH 2/6] lib: sbi: sse: Fix format string for event invalid state Clément Léger
2025-03-24 16:39 ` Andrew Jones
2025-03-24 16:41 ` Clément Léger
2025-03-17 10:54 ` [PATCH 3/6] lib: sbi: sse: Return SBI_EDENIED for read only parameters Clément Léger
2025-03-24 17:01 ` Andrew Jones
2025-03-24 17:02 ` Clément Léger
2025-03-17 10:54 ` [PATCH 4/6] lib: sbi: sse: Rename STATUS* interrupted flags to SSTATUS* Clément Léger
2025-03-24 17:03 ` Andrew Jones
2025-03-17 10:54 ` [PATCH 5/6] lib: sbi: sse: Add support for SSTATUS.SPELP Clément Léger
2025-03-24 17:08 ` Andrew Jones
2025-03-17 10:54 ` [PATCH 6/6] lib: sbi: sse: Add support for SSTATUS.SDT Clément Léger
2025-03-24 17:46 ` Andrew Jones
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.