From: Anup Patel <apatel@ventanamicro.com>
To: Atish Patra <atishp@rivosinc.com>
Cc: Andrew Jones <ajones@ventanamicro.com>,
Anup Patel <anup@brainfault.org>,
opensbi@lists.infradead.org, Anup Patel <apatel@ventanamicro.com>
Subject: [PATCH 1/3] lib: sbi: Introduce IPI device rating
Date: Tue, 2 Sep 2025 17:47:19 +0530 [thread overview]
Message-ID: <20250902121721.401933-2-apatel@ventanamicro.com> (raw)
In-Reply-To: <20250902121721.401933-1-apatel@ventanamicro.com>
A platform can have multiple IPI devices (such as ACLINT MSWI,
AIA IMSIC, etc). Currently, OpenSBI rely on platform calling
the sbi_ipi_set_device() function in correct order and prefer
the first avaiable IPI device which is fragile.
Instead of the above, introdcue IPI device rating and prefer
the highest rated IPI device. This further allows extending
the sbi_ipi_raw_clear() to clear all available IPI devices.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
include/sbi/sbi_ipi.h | 6 +++++-
lib/sbi/sbi_init.c | 2 +-
lib/sbi/sbi_ipi.c | 28 ++++++++++++++++++++--------
lib/utils/ipi/aclint_mswi.c | 1 +
lib/utils/ipi/andes_plicsw.c | 1 +
lib/utils/irqchip/imsic.c | 1 +
6 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/include/sbi/sbi_ipi.h b/include/sbi/sbi_ipi.h
index 62d61304..0a9ae03d 100644
--- a/include/sbi/sbi_ipi.h
+++ b/include/sbi/sbi_ipi.h
@@ -14,6 +14,7 @@
/* clang-format off */
+#define SBI_IPI_DEVICE_MAX (4)
#define SBI_IPI_EVENT_MAX (8 * __SIZEOF_LONG__)
/* clang-format on */
@@ -23,6 +24,9 @@ struct sbi_ipi_device {
/** Name of the IPI device */
char name[32];
+ /** Ratings of the IPI device (higher is better) */
+ unsigned long rating;
+
/** Send IPI to a target HART index */
void (*ipi_send)(u32 hart_index);
@@ -87,7 +91,7 @@ void sbi_ipi_process(void);
int sbi_ipi_raw_send(u32 hartindex);
-void sbi_ipi_raw_clear(void);
+void sbi_ipi_raw_clear(bool all_devices);
const struct sbi_ipi_device *sbi_ipi_get_device(void);
diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
index 84a63748..663b486b 100644
--- a/lib/sbi/sbi_init.c
+++ b/lib/sbi/sbi_init.c
@@ -507,7 +507,7 @@ static void __noreturn init_warmboot(struct sbi_scratch *scratch, u32 hartid)
if (hstate == SBI_HSM_STATE_SUSPENDED) {
init_warm_resume(scratch, hartid);
} else {
- sbi_ipi_raw_clear();
+ sbi_ipi_raw_clear(true);
init_warm_startup(scratch, hartid);
}
}
diff --git a/lib/sbi/sbi_ipi.c b/lib/sbi/sbi_ipi.c
index 2de459b0..b57ec652 100644
--- a/lib/sbi/sbi_ipi.c
+++ b/lib/sbi/sbi_ipi.c
@@ -32,8 +32,9 @@ _Static_assert(
"type of sbi_ipi_data.ipi_type has changed, please redefine SBI_IPI_EVENT_MAX"
);
-static unsigned long ipi_data_off;
+static unsigned long ipi_data_off, ipi_dev_count;
static const struct sbi_ipi_device *ipi_dev = NULL;
+static const struct sbi_ipi_device *ipi_dev_array[SBI_IPI_DEVICE_MAX];
static const struct sbi_ipi_event_ops *ipi_ops_array[SBI_IPI_EVENT_MAX];
static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartindex,
@@ -248,7 +249,7 @@ void sbi_ipi_process(void)
sbi_scratch_offset_ptr(scratch, ipi_data_off);
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_RECVD);
- sbi_ipi_raw_clear();
+ sbi_ipi_raw_clear(false);
ipi_type = atomic_raw_xchg_ulong(&ipi_data->ipi_type, 0);
ipi_event = 0;
@@ -283,10 +284,19 @@ int sbi_ipi_raw_send(u32 hartindex)
return 0;
}
-void sbi_ipi_raw_clear(void)
+void sbi_ipi_raw_clear(bool all_devices)
{
- if (ipi_dev && ipi_dev->ipi_clear)
- ipi_dev->ipi_clear();
+ int i;
+
+ if (all_devices) {
+ for (i = 0; i < ipi_dev_count; i++) {
+ if (ipi_dev_array[i]->ipi_clear)
+ ipi_dev_array[i]->ipi_clear();
+ }
+ } else {
+ if (ipi_dev && ipi_dev->ipi_clear)
+ ipi_dev->ipi_clear();
+ }
/*
* Ensure that memory or MMIO writes after this
@@ -307,10 +317,12 @@ const struct sbi_ipi_device *sbi_ipi_get_device(void)
void sbi_ipi_set_device(const struct sbi_ipi_device *dev)
{
- if (!dev || ipi_dev)
+ if (!dev || ipi_dev_count >= SBI_IPI_DEVICE_MAX)
return;
+ ipi_dev_array[ipi_dev_count++] = dev;
- ipi_dev = dev;
+ if (!ipi_dev || ipi_dev->rating < dev->rating)
+ ipi_dev = dev;
}
int sbi_ipi_init(struct sbi_scratch *scratch, bool cold_boot)
@@ -347,7 +359,7 @@ int sbi_ipi_init(struct sbi_scratch *scratch, bool cold_boot)
ipi_data->ipi_type = 0x00;
/* Clear any pending IPIs for the current hart */
- sbi_ipi_raw_clear();
+ sbi_ipi_raw_clear(true);
/* Enable software interrupts */
csr_set(CSR_MIE, MIP_MSIP);
diff --git a/lib/utils/ipi/aclint_mswi.c b/lib/utils/ipi/aclint_mswi.c
index 9e55078a..23510551 100644
--- a/lib/utils/ipi/aclint_mswi.c
+++ b/lib/utils/ipi/aclint_mswi.c
@@ -62,6 +62,7 @@ static void mswi_ipi_clear(void)
static struct sbi_ipi_device aclint_mswi = {
.name = "aclint-mswi",
+ .rating = 100,
.ipi_send = mswi_ipi_send,
.ipi_clear = mswi_ipi_clear
};
diff --git a/lib/utils/ipi/andes_plicsw.c b/lib/utils/ipi/andes_plicsw.c
index 5d085d85..000fe9fd 100644
--- a/lib/utils/ipi/andes_plicsw.c
+++ b/lib/utils/ipi/andes_plicsw.c
@@ -61,6 +61,7 @@ static void plicsw_ipi_clear(void)
static struct sbi_ipi_device plicsw_ipi = {
.name = "andes_plicsw",
+ .rating = 200,
.ipi_send = plicsw_ipi_send,
.ipi_clear = plicsw_ipi_clear
};
diff --git a/lib/utils/irqchip/imsic.c b/lib/utils/irqchip/imsic.c
index 057b9fa7..3c150c37 100644
--- a/lib/utils/irqchip/imsic.c
+++ b/lib/utils/irqchip/imsic.c
@@ -199,6 +199,7 @@ static void imsic_ipi_send(u32 hart_index)
static struct sbi_ipi_device imsic_ipi_device = {
.name = "aia-imsic",
+ .rating = 300,
.ipi_send = imsic_ipi_send
};
--
2.43.0
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next prev parent reply other threads:[~2025-09-02 16:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-02 12:17 [PATCH 0/3] OpenSBI IPI device rating Anup Patel
2025-09-02 12:17 ` Anup Patel [this message]
2025-09-02 23:41 ` [PATCH 1/3] lib: sbi: Introduce " Samuel Holland
2025-09-03 6:49 ` Anup Patel
2025-09-03 7:00 ` Nick Hu
2025-09-03 7:05 ` Anup Patel
2025-09-03 7:13 ` Anup Patel
2025-09-03 7:23 ` Anup Patel
2025-09-03 10:36 ` Nick Hu
2025-09-02 12:17 ` [PATCH 2/3] include: sbi: Remove platform specific IPI init Anup Patel
2025-09-02 23:44 ` Samuel Holland
2025-09-03 6:50 ` Anup Patel
2025-09-02 12:17 ` [PATCH 3/3] lib: utils/ipi: Convert IPI drivers as early drivers Anup Patel
2025-09-02 23:53 ` Samuel Holland
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=20250902121721.401933-2-apatel@ventanamicro.com \
--to=apatel@ventanamicro.com \
--cc=ajones@ventanamicro.com \
--cc=anup@brainfault.org \
--cc=atishp@rivosinc.com \
--cc=opensbi@lists.infradead.org \
/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