[PATCH v2 1/2] lib: sbi: introduce abstraction for wired interrupt handling
Raymond Mao
raymondmaoca at gmail.com
Mon Feb 2 07:02:06 PST 2026
From: Raymond Mao <raymond.mao at riscstar.com>
Add wired interrupt handling abstraction into irqchip.
This introduces a small provider interface based on
claim/complete/mask/unmak semantics, allowing to register a wired
interrupt controller as a provider.
Signed-off-by: Raymond Mao <raymond.mao at riscstar.com>
---
include/sbi/sbi_irqchip.h | 52 +++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/include/sbi/sbi_irqchip.h b/include/sbi/sbi_irqchip.h
index e0ae12f5..27b88765 100644
--- a/include/sbi/sbi_irqchip.h
+++ b/include/sbi/sbi_irqchip.h
@@ -27,6 +27,38 @@ struct sbi_irqchip_device {
int (*irq_handle)(void);
};
+/* Handler for a specified hwirq */
+typedef int (*sbi_irqchip_irq_handler_t)(void *priv);
+
+/* Provider operations */
+struct sbi_irqchip_provider_ops {
+ /*
+ * Claim a pending wired interrupt on current hart.
+ * Returns:
+ * SBI_OK : *hwirq is valid
+ * SBI_ENOENT : no pending wired interrupt
+ * <0 : error
+ */
+ int (*claim)(void *ctx, u32 *hwirq);
+
+ /*
+ * Complete/acknowledge a previously claimed wired interrupt
+ * (if required by HW).
+ * Some HW may not require an explicit completion.
+ */
+ void (*complete)(void *ctx, u32 hwirq);
+
+ /*
+ * mask/unmask a wired interrupt line.
+ *
+ * These are required for reliable couriering of level-triggered device
+ * interrupts to S-mode: mask in M-mode before enqueueing, and unmask
+ * after S-mode has cleared the device interrupt source.
+ */
+ void (*mask)(void *ctx, u32 hwirq);
+ void (*unmask)(void *ctx, u32 hwirq);
+};
+
/**
* Process external interrupts
*
@@ -46,4 +78,24 @@ int sbi_irqchip_init(struct sbi_scratch *scratch, bool cold_boot);
/** Exit interrupt controllers */
void sbi_irqchip_exit(struct sbi_scratch *scratch);
+/*
+ * Register the active wired interrupt provider.
+ * - max_hwirq specifies the highest valid hwirq ID.
+ */
+int sbi_irqchip_register_provider(const struct sbi_irqchip_provider_ops *ops,
+ void *ctx, u32 max_hwirq);
+
+u32 sbi_irqchip_get_max_src(void);
+
+/* Set/clear handler for a specified hwirq */
+int sbi_irqchip_set_handler(u32 hwirq, sbi_irqchip_irq_handler_t handler,
+ void *priv);
+int sbi_irqchip_clear_handler(u32 hwirq);
+
+void sbi_irqchip_mask_irq(u32 hwirq);
+void sbi_irqchip_unmask_irq(u32 hwirq);
+
+/* external interrupt handler (irqchip device hook) */
+int sbi_irqchip_handle_external_irq(void);
+
#endif
--
2.25.1
More information about the opensbi
mailing list