From: Raymond Mao <raymondmaoca@gmail.com>
To: opensbi@lists.infradead.org
Cc: scott@riscstar.com, dave.patel@riscstar.com,
raymond.mao@riscstar.com, robin.randhawa@sifive.com,
samuel.holland@sifive.com, anup.patel@qti.qualcomm.com,
anuppate@qti.qualcomm.com, dhaval@rivosinc.com,
peter.lin@sifive.com
Subject: [PATCH v2 2/2] lib: sbi: Add VIRQ interrupt abstraction
Date: Mon, 2 Feb 2026 10:02:07 -0500 [thread overview]
Message-ID: <20260202150207.1331811-3-raymondmaoca@gmail.com> (raw)
In-Reply-To: <20260202150207.1331811-1-raymondmaoca@gmail.com>
From: Raymond Mao <raymond.mao@riscstar.com>
VIRQ (Virtual IRQ) layer is on top of irqchip, providing IRQ state
management via per-(domain,hart) IRQ pending queue, with courier
dispatching and interface to enqueue/pop/complete an IRQ.
It dispatches claimed wired interrupts to S-Mode domains via SSE
injection on current hart.
Signed-off-by: Raymond Mao <raymond.mao@riscstar.com>
---
include/sbi/sbi_virq.h | 90 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
create mode 100644 include/sbi/sbi_virq.h
diff --git a/include/sbi/sbi_virq.h b/include/sbi/sbi_virq.h
new file mode 100644
index 00000000..1760d9b5
--- /dev/null
+++ b/include/sbi/sbi_virq.h
@@ -0,0 +1,90 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 RISCstar Solutions Corporation.
+ *
+ * Author: Raymond Mao <raymond.mao@riscstar.com>
+ */
+
+#ifndef __SBI_VIRQ_H__
+#define __SBI_VIRQ_H__
+
+#include <sbi/sbi_domain.h>
+#include <sbi/sbi_types.h>
+
+/*
+ * Keep the queue small for bring-up. If it overflows, we drop and warn.
+ */
+#define SBI_VIRQ_QSIZE 32
+
+/* per-(domain,hart) IRQ state */
+struct sbi_domain_virq_state {
+ spinlock_t lock;
+ u32 head;
+ u32 tail;
+ /* pending IRQ queue */
+ u32 q[SBI_VIRQ_QSIZE];
+};
+
+/* Per-domain VIRQ context */
+struct sbi_domain_virq_priv {
+ /* harts number of the domain */
+ u32 nharts;
+ /* IRQ states of all harts of the domain */
+ struct sbi_domain_virq_state st[];
+};
+
+struct sbi_virq_courier_priv {
+ struct sbi_domain *dom;
+ u32 virq;
+};
+
+/* Enqueue an interrupt (as seen by the generic irqchip layer) for a domain. */
+int sbi_virq_enqueue(struct sbi_domain *dom, u32 irq);
+
+/*
+ * Complete a previously couriered irq for the current domain.
+ *
+ * This will unmask the interrupt line at the active irqchip provider, allowing
+ * further interrupts once S-mode has cleared the device interrupt source.
+ */
+void sbi_virq_complete_thishart(u32 irq);
+
+/* Pop next pending irq for current domain on this hart. Returns 0 if none. */
+u32 sbi_virq_pop_thishart(void);
+
+/*
+ * Courier handler for wired irqchip dispatch.
+ *
+ * Intended usage:
+ * sbi_irqchip_set_handler(hwirq, sbi_virq_courier_handler, dom);
+ *
+ * It will enqueue (irq) for the provided domain and inject SSE on the
+ * current hart to notify S-mode.
+ */
+int sbi_virq_courier_handler(void *priv);
+
+/*
+ * Bind helper function: bind a given irq and register the courier handler
+ * for a domain.
+ */
+int sbi_virq_bind_irq_to_domain(u32 irq, struct sbi_domain *dom);
+
+/* Initialize per-domain virq state (alloc + lock init). */
+int sbi_virq_domain_init(struct sbi_domain *dom);
+
+
+/*
+ * Optional: map a virtual IRQ number (virq) to a hardware wired IRQ (hwirq).
+ *
+ * If no explicit mapping exists, 'virq==hwirq' is assumed.
+ *
+ * This allows upper layers (e.g. VIRQ courier/emulation) to use stable virq
+ * identifiers without exposing the wired controller's hwirq numbering.
+ */
+int sbi_virq_map_irq(u32 virq, u32 hwirq);
+int sbi_virq_unmap_irq(u32 virq);
+u32 sbi_virq_irq_to_hwirq(u32 virq);
+u32 sbi_virq_hwirq_to_irq(u32 hwirq);
+
+#endif
--
2.25.1
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next prev parent reply other threads:[~2026-02-02 15:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-02 15:02 [RFC v2 PATCH 0/2] Introduce irqchip and VIRQ layer prototypes Raymond Mao
2026-02-02 15:02 ` [PATCH v2 1/2] lib: sbi: introduce abstraction for wired interrupt handling Raymond Mao
2026-02-07 10:10 ` Anup Patel
2026-02-07 16:23 ` Raymond Mao
2026-02-02 15:02 ` Raymond Mao [this message]
2026-02-07 10:07 ` [RFC v2 PATCH 0/2] Introduce irqchip and VIRQ layer prototypes Anup Patel
2026-02-07 16:11 ` Raymond Mao
2026-02-08 13:23 ` Anup Patel
2026-02-08 18:50 ` Raymond Mao
2026-02-10 16:06 ` Anup Patel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260202150207.1331811-3-raymondmaoca@gmail.com \
--to=raymondmaoca@gmail.com \
--cc=anup.patel@qti.qualcomm.com \
--cc=anuppate@qti.qualcomm.com \
--cc=dave.patel@riscstar.com \
--cc=dhaval@rivosinc.com \
--cc=opensbi@lists.infradead.org \
--cc=peter.lin@sifive.com \
--cc=raymond.mao@riscstar.com \
--cc=robin.randhawa@sifive.com \
--cc=samuel.holland@sifive.com \
--cc=scott@riscstar.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox