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: [RFC PATCH 1/2] lib: sbi: introduce INTC abstraction for wired interrupts
Date: Tue, 27 Jan 2026 10:23:41 -0500 [thread overview]
Message-ID: <20260127152342.1231995-2-raymondmaoca@gmail.com> (raw)
In-Reply-To: <20260127152342.1231995-1-raymondmaoca@gmail.com>
From: Raymond Mao <raymond.mao@riscstar.com>
Add a wired interrupt-controller (INTC) abstraction to OpenSBI.
This introduces a small provider interface based on
claim/complete/mask/unmak semantics, allowing to register a wired
interrupt controller as a provider.
Plus, add virtual IRQ number mapping to avoid exposure of hwirq.
Signed-off-by: Raymond Mao <raymond.mao@riscstar.com>
---
sbi_intc.h | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+)
create mode 100644 sbi_intc.h
diff --git a/sbi_intc.h b/sbi_intc.h
new file mode 100644
index 00000000..f51974c9
--- /dev/null
+++ b/sbi_intc.h
@@ -0,0 +1,99 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 RISCstar Solutions Corporation.
+ *
+ * Author: Raymond Mao <raymond.mao@riscstar.com>
+ */
+
+#ifndef __SBI_INTC_H__
+#define __SBI_INTC_H__
+
+#include <sbi/sbi_types.h>
+
+/* Handler for a specified IRQ number */
+typedef int (*sbi_intc_irq_handler_t)(u32 irq, void *priv);
+
+/*
+ * Provider capabilities, at the moment it contains the maximum valid source ID
+ * but extensible in the future
+ */
+struct sbi_intc_provider_caps {
+ /*
+ * Maximum supported wired source ID for this provider.
+ *
+ * For APLIC this corresponds to the highest valid source ID (1..N).
+ * The INTC core treats this as an abstract provider source ID space.
+ */
+ u32 max_src;
+};
+
+/* Provider operations */
+struct sbi_intc_provider_ops {
+ /*
+ * Query provider capabilities.
+ *
+ * This avoids exposing provider-specific limits (such as APLIC
+ * num_source) through the registration API.
+ */
+ int (*get_caps)(void *ctx, struct sbi_intc_provider_caps *caps);
+
+ /*
+ * 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 *irq);
+
+ /*
+ * Complete/acknowledge a previously claimed wired interrupt
+ * (if required by HW).
+ * Some HW may not require an explicit completion.
+ */
+ void (*complete)(void *ctx, u32 irq);
+
+ /*
+ * 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 irq);
+ void (*unmask)(void *ctx, u32 irq);
+};
+
+/* Register the active wired interrupt provider, e.g. APLIC, via ops and ctx */
+int sbi_intc_register_provider(const struct sbi_intc_provider_ops *ops,
+ void *ctx);
+
+/*
+ * Optional: map a IRQ number (irq) to a hardware wired IRQ (hwirq).
+ *
+ * If no explicit mapping exists, 'irq==hwirq' is assumed.
+ *
+ * This allows upper layers (e.g. VIRQ courier/emulation) to use stable irq
+ * identifiers without exposing the wired controller's hwirq numbering.
+ */
+int sbi_intc_map_irq(u32 irq, u32 hwirq);
+int sbi_intc_unmap_irq(u32 irq);
+u32 sbi_intc_irq_to_hwirq(u32 irq);
+u32 sbi_intc_hwirq_to_irq(u32 hwirq);
+
+/* Set/clear handler for a specified IRQ number */
+int sbi_intc_set_handler(u32 irq, sbi_intc_irq_handler_t handler, void *priv);
+int sbi_intc_clear_handler(u32 irq);
+
+/*
+ * Platform independent mask/unmak wrappers on top of platform registered
+ * mask/unmask ops functions.
+ */
+void sbi_intc_mask_irq(u32 irq);
+void sbi_intc_unmask_irq(u32 irq);
+
+/* External interrupt handler (for irqchip device hook 'irqchip.irq_handle') */
+int sbi_intc_handle_external_irq(void);
+
+#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-01-27 15:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-27 15:23 [RFC PATCH 0/2] Introduce INTC and VIRQ layer prototypes Raymond Mao
2026-01-27 15:23 ` Raymond Mao [this message]
2026-01-30 7:48 ` [RFC PATCH 1/2] lib: sbi: introduce INTC abstraction for wired interrupts Anup Patel
2026-01-30 15:00 ` Raymond Mao
2026-01-27 15:23 ` [RFC PATCH 2/2] lib: sbi: Add VIRQ layer Raymond Mao
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=20260127152342.1231995-2-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