* [PATCH v2 0/5] Parallel message send using SBI MPXY
@ 2026-11-16 4:00 Anup Patel
2026-11-16 4:00 ` [PATCH v2 1/5] RISC-V: Move common MPXY helper routines to arch/riscv Anup Patel
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Anup Patel @ 2026-11-16 4:00 UTC (permalink / raw)
To: Palmer Dabbelt, Paul Walmsley, Rahul Pathak, Stephen Boyd,
Brian Masney, Jerome Brunet, Thomas Gleixner, Radu Rendec,
Jassi Brar
Cc: Sunil V L, Himanshu Chauhan, Atish Patra, Anup Patel,
Amirreza Zarrabi, linux-riscv, linux-kernel, linux-clk,
Anup Patel
This series primarily extends mailbox framework and SBI MPXY mailbox
driver to allow sending messages in-parallel from multiple CPUs. It
also serves as perparatory series for the upcoming RISC-V ACPI EINJ
support and RISC-V TEE support.
These patches can also be found in the riscv_mpxy_imp_v2 branch at:
https://github.com/avpatel/linux.git
Changes since v1:
- Rebase on Linux-7.4-rc2
- Replace PATCH2 to factor-out per-hart MPXY shared-memory acquisition
with a new patch to Use irqsave to prevent interrupt when accessing
MPXY shared memory
- Adopt Jassi's implementation of mbox_send_message_sync() from:
https://git.kernel.org/pub/scm/linux/kernel/git/jassibrar/mailbox.git/log/?h=jsb/rfc-synch-xfer
Anup Patel (2):
RISC-V: Move common MPXY helper routines to arch/riscv
RISC-V: Use irqsave to prevent interrupt when accessing MPXY shared
memory
Jassi Brar (3):
mailbox: add direct synchronous transmit API
mailbox: document direct synchronous transmit
mailbox: convert RISC-V SBI MPXY to direct transmit
Documentation/driver-api/mailbox.rst | 350 ++++++++++++++-
arch/riscv/include/asm/sbi.h | 86 +++-
arch/riscv/kernel/Makefile | 2 +-
arch/riscv/kernel/sbi_mpxy.c | 340 ++++++++++++++
drivers/clk/clk-rpmi.c | 3 -
drivers/irqchip/irq-riscv-rpmi-sysmsi.c | 3 -
drivers/mailbox/mailbox.c | 144 +++++-
drivers/mailbox/riscv-sbi-mpxy-mbox.c | 415 +++---------------
.../pmdomain/riscv/riscv-rpmi-device-power.c | 3 -
include/linux/mailbox/riscv-rpmi-message.h | 17 +-
include/linux/mailbox_client.h | 9 +-
include/linux/mailbox_controller.h | 38 ++
12 files changed, 1006 insertions(+), 404 deletions(-)
create mode 100644 arch/riscv/kernel/sbi_mpxy.c
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/5] RISC-V: Move common MPXY helper routines to arch/riscv
2026-11-16 4:00 [PATCH v2 0/5] Parallel message send using SBI MPXY Anup Patel
@ 2026-11-16 4:00 ` Anup Patel
2026-11-16 4:00 ` [PATCH v2 2/5] RISC-V: Use irqsave to prevent interrupt when accessing MPXY shared memory Anup Patel
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Anup Patel @ 2026-11-16 4:00 UTC (permalink / raw)
To: Palmer Dabbelt, Paul Walmsley, Rahul Pathak, Stephen Boyd,
Brian Masney, Jerome Brunet, Thomas Gleixner, Radu Rendec,
Jassi Brar
Cc: Sunil V L, Himanshu Chauhan, Atish Patra, Anup Patel,
Amirreza Zarrabi, linux-riscv, linux-kernel, linux-clk,
Anup Patel
There are upcoming kernel changes (such as RISC-V EINJ FFH support)
where the MPXY channel_id is known but the Linux mailbox channel
instance is not available. For such cases, the kernel will directly
do SBI MPXY calls bypassing the Linux mailbox framework and share
the MPXY shared memory with the Linux SBI MPXY mailbox driver.
To support the above, move the common MPXY helper routines and
MPXY shared memory management from Linux SBI MPXY mailbox driver
to arch/riscv.
Co-developed-by: Himanshu Chauhan <himanshu.chauhan@oss.qualcomm.com>
Signed-off-by: Himanshu Chauhan <himanshu.chauhan@oss.qualcomm.com>
Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
---
arch/riscv/include/asm/sbi.h | 86 +++++-
arch/riscv/kernel/Makefile | 2 +-
arch/riscv/kernel/sbi_mpxy.c | 340 +++++++++++++++++++++++
drivers/mailbox/riscv-sbi-mpxy-mbox.c | 386 +++-----------------------
4 files changed, 460 insertions(+), 354 deletions(-)
create mode 100644 arch/riscv/kernel/sbi_mpxy.c
diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
index fd6266a7b339..1ba1f66af02c 100644
--- a/arch/riscv/include/asm/sbi.h
+++ b/arch/riscv/include/asm/sbi.h
@@ -693,6 +693,37 @@ static inline int sbi_fwft_set_online_cpus(u32 feature, unsigned long value,
return sbi_fwft_set_cpumask(cpu_online_mask, feature, value, flags);
}
+/* SBI MPXY notification data in shared memory */
+struct sbi_mpxy_notification_data {
+ /* Remaining number of notification events */
+ __le32 remaining;
+ /* Number of notification events returned */
+ __le32 returned;
+ /* Number of notification events lost */
+ __le32 lost;
+ /* Reserved for future use */
+ __le32 reserved;
+ /* Returned channel id array */
+ u8 events_data[];
+};
+
+unsigned long sbi_mpxy_shmem_size(void);
+int sbi_mpxy_get_channel_count(u32 *channel_count);
+int sbi_mpxy_get_channel_ids(u32 channel_count, u32 *channel_ids);
+int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attrid, u32 attr_count,
+ u32 *attrs_buf);
+int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attrid, u32 attr_count,
+ u32 *attrs_buf);
+int sbi_mpxy_send_message_with_resp(u32 channel_id, u32 msg_id,
+ void *tx, unsigned long tx_len,
+ void *rx, unsigned long max_rx_len,
+ unsigned long *rx_len);
+int sbi_mpxy_send_message_without_resp(u32 channel_id, u32 msg_id,
+ void *tx, unsigned long tx_len);
+int sbi_mpxy_get_notifications(u32 channel_id,
+ struct sbi_mpxy_notification_data *notif_data,
+ unsigned long *events_data_len);
+
/* Check if current SBI specification version is 0.1 or not */
static inline int sbi_spec_is_0_1(void)
{
@@ -754,7 +785,60 @@ int sbi_debug_console_read(char *bytes, unsigned int num_bytes);
#else /* CONFIG_RISCV_SBI */
static inline int sbi_remote_fence_i(const struct cpumask *cpu_mask) { return -1; }
-static inline void sbi_init(void) {}
+static inline void sbi_init(void)
+{
+}
+
+struct sbi_mpxy_notification_data;
+
+static inline unsigned long sbi_mpxy_shmem_size(void)
+{
+ return 0;
+}
+
+static inline int sbi_mpxy_get_channel_count(u32 *channel_count)
+{
+ return -ENODEV;
+}
+
+static inline int sbi_mpxy_get_channel_ids(u32 channel_count, u32 *channel_ids)
+{
+ return -ENODEV;
+}
+
+static inline int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attrid, u32 attr_count,
+ u32 *attrs_buf)
+{
+ return -ENODEV;
+}
+
+static inline int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attrid, u32 attr_count,
+ u32 *attrs_buf)
+{
+ return -ENODEV;
+}
+
+static inline int sbi_mpxy_send_message_with_resp(u32 channel_id, u32 msg_id,
+ void *tx, unsigned long tx_len,
+ void *rx, unsigned long max_rx_len,
+ unsigned long *rx_len)
+{
+ return -ENODEV;
+}
+
+static inline int sbi_mpxy_send_message_without_resp(u32 channel_id, u32 msg_id,
+ void *tx, unsigned long tx_len)
+{
+ return -ENODEV;
+}
+
+static inline int sbi_mpxy_get_notifications(u32 channel_id,
+ struct sbi_mpxy_notification_data *notif_data,
+ unsigned long *events_data_len)
+{
+ return -ENODEV;
+}
+
#endif /* CONFIG_RISCV_SBI */
unsigned long riscv_get_mvendorid(void);
diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index 7f52ae724225..cb2578182ee5 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -101,7 +101,7 @@ obj-$(CONFIG_DYNAMIC_FTRACE) += mcount-dyn.o
obj-$(CONFIG_PERF_EVENTS) += perf_callchain.o
obj-$(CONFIG_HAVE_PERF_REGS) += perf_regs.o
-obj-$(CONFIG_RISCV_SBI) += sbi.o sbi_ecall.o
+obj-$(CONFIG_RISCV_SBI) += sbi.o sbi_ecall.o sbi_mpxy.o
ifeq ($(CONFIG_RISCV_SBI), y)
obj-$(CONFIG_SMP) += sbi-ipi.o
obj-$(CONFIG_SMP) += cpu_ops_sbi.o
diff --git a/arch/riscv/kernel/sbi_mpxy.c b/arch/riscv/kernel/sbi_mpxy.c
new file mode 100644
index 000000000000..17a2cee21311
--- /dev/null
+++ b/arch/riscv/kernel/sbi_mpxy.c
@@ -0,0 +1,340 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Common SBI MPXY access library.
+ *
+ * Copyright (c) 2026 Qualcomm Technologies, Inc.
+ */
+
+#define pr_fmt(fmt) "riscv: " fmt
+#include <linux/cpu.h>
+#include <linux/init.h>
+#include <linux/mm.h>
+#include <linux/percpu.h>
+#include <linux/printk.h>
+#include <linux/string.h>
+#include <linux/types.h>
+#include <asm/byteorder.h>
+#include <asm/sbi.h>
+
+/* SBI MPXY channel IDs data in shared memory */
+struct sbi_mpxy_channel_ids_data {
+ /* Remaining number of channel ids */
+ __le32 remaining;
+ /* Returned channel ids in current function call */
+ __le32 returned;
+ /* Returned channel id array */
+ __le32 channel_array[];
+};
+
+/* MPXY Per-CPU or local context */
+struct mpxy_local {
+ /* Shared memory base address */
+ void *shmem;
+ /* Shared memory physical address */
+ phys_addr_t shmem_phys_addr;
+ /* Flag representing whether shared memory is active or not */
+ bool shmem_active;
+};
+
+static DEFINE_PER_CPU(struct mpxy_local, mpxy_local);
+static unsigned long mpxy_shmem_size;
+static bool mpxy_shmem_init_done;
+
+unsigned long sbi_mpxy_shmem_size(void)
+{
+ if (!mpxy_shmem_init_done)
+ return 0;
+ return mpxy_shmem_size;
+}
+EXPORT_SYMBOL_GPL(sbi_mpxy_shmem_size);
+
+int sbi_mpxy_get_channel_count(u32 *channel_count)
+{
+ struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
+ struct sbi_mpxy_channel_ids_data *sdata = mpxy->shmem;
+ u32 remaining, returned;
+ struct sbiret sret;
+
+ if (!mpxy->shmem_active)
+ return -ENODEV;
+ if (!channel_count)
+ return -EINVAL;
+
+ get_cpu();
+
+ /* Get the remaining and returned fields to calculate total */
+ sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_CHANNEL_IDS,
+ 0, 0, 0, 0, 0, 0);
+ if (sret.error)
+ goto err_put_cpu;
+
+ remaining = le32_to_cpu(sdata->remaining);
+ returned = le32_to_cpu(sdata->returned);
+ *channel_count = remaining + returned;
+
+err_put_cpu:
+ put_cpu();
+ return sbi_err_map_linux_errno(sret.error);
+}
+EXPORT_SYMBOL_GPL(sbi_mpxy_get_channel_count);
+
+int sbi_mpxy_get_channel_ids(u32 channel_count, u32 *channel_ids)
+{
+ struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
+ struct sbi_mpxy_channel_ids_data *sdata = mpxy->shmem;
+ u32 remaining, returned, count, start_index = 0;
+ struct sbiret sret;
+
+ if (!mpxy->shmem_active)
+ return -ENODEV;
+ if (!channel_count || !channel_ids)
+ return -EINVAL;
+
+ get_cpu();
+
+ do {
+ sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_CHANNEL_IDS,
+ start_index, 0, 0, 0, 0, 0);
+ if (sret.error)
+ goto err_put_cpu;
+
+ remaining = le32_to_cpu(sdata->remaining);
+ returned = le32_to_cpu(sdata->returned);
+
+ count = returned < (channel_count - start_index) ?
+ returned : (channel_count - start_index);
+ memcpy_from_le32(&channel_ids[start_index], sdata->channel_array, count);
+ start_index += count;
+ } while (remaining && start_index < channel_count);
+
+err_put_cpu:
+ put_cpu();
+ return sbi_err_map_linux_errno(sret.error);
+}
+EXPORT_SYMBOL_GPL(sbi_mpxy_get_channel_ids);
+
+int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attrid, u32 attr_count,
+ u32 *attrs_buf)
+{
+ struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
+ struct sbiret sret;
+
+ if (!mpxy->shmem_active)
+ return -ENODEV;
+ if (!attr_count || !attrs_buf)
+ return -EINVAL;
+
+ get_cpu();
+
+ sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_READ_ATTRS,
+ channel_id, base_attrid, attr_count, 0, 0, 0);
+ if (sret.error)
+ goto err_put_cpu;
+
+ memcpy_from_le32(attrs_buf, (__le32 *)mpxy->shmem, attr_count);
+
+err_put_cpu:
+ put_cpu();
+ return sbi_err_map_linux_errno(sret.error);
+}
+EXPORT_SYMBOL_GPL(sbi_mpxy_read_attrs);
+
+int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attrid, u32 attr_count,
+ u32 *attrs_buf)
+{
+ struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
+ struct sbiret sret;
+
+ if (!mpxy->shmem_active)
+ return -ENODEV;
+ if (!attr_count || !attrs_buf)
+ return -EINVAL;
+
+ get_cpu();
+
+ memcpy_to_le32((__le32 *)mpxy->shmem, attrs_buf, attr_count);
+ sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_WRITE_ATTRS,
+ channel_id, base_attrid, attr_count, 0, 0, 0);
+
+ put_cpu();
+ return sbi_err_map_linux_errno(sret.error);
+}
+EXPORT_SYMBOL_GPL(sbi_mpxy_write_attrs);
+
+int sbi_mpxy_send_message_with_resp(u32 channel_id, u32 msg_id,
+ void *tx, unsigned long tx_len,
+ void *rx, unsigned long max_rx_len,
+ unsigned long *rx_len)
+{
+ struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
+ unsigned long rx_bytes;
+ struct sbiret sret;
+
+ if (!mpxy->shmem_active)
+ return -ENODEV;
+ if (!tx && tx_len)
+ return -EINVAL;
+
+ get_cpu();
+
+ /* Message protocols allowed to have no data in messages */
+ if (tx_len)
+ memcpy(mpxy->shmem, tx, tx_len);
+
+ sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SEND_MSG_WITH_RESP,
+ channel_id, msg_id, tx_len, 0, 0, 0);
+ if (rx && !sret.error) {
+ rx_bytes = sret.value;
+ if (rx_bytes > max_rx_len) {
+ put_cpu();
+ return -ENOSPC;
+ }
+
+ memcpy(rx, mpxy->shmem, rx_bytes);
+ if (rx_len)
+ *rx_len = rx_bytes;
+ }
+
+ put_cpu();
+ return sbi_err_map_linux_errno(sret.error);
+}
+EXPORT_SYMBOL_GPL(sbi_mpxy_send_message_with_resp);
+
+int sbi_mpxy_send_message_without_resp(u32 channel_id, u32 msg_id,
+ void *tx, unsigned long tx_len)
+{
+ struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
+ struct sbiret sret;
+
+ if (!mpxy->shmem_active)
+ return -ENODEV;
+ if (!tx && tx_len)
+ return -EINVAL;
+
+ get_cpu();
+
+ /* Message protocols allowed to have no data in messages */
+ if (tx_len)
+ memcpy(mpxy->shmem, tx, tx_len);
+
+ sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SEND_MSG_WITHOUT_RESP,
+ channel_id, msg_id, tx_len, 0, 0, 0);
+
+ put_cpu();
+ return sbi_err_map_linux_errno(sret.error);
+}
+EXPORT_SYMBOL_GPL(sbi_mpxy_send_message_without_resp);
+
+int sbi_mpxy_get_notifications(u32 channel_id,
+ struct sbi_mpxy_notification_data *notif_data,
+ unsigned long *events_data_len)
+{
+ struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
+ struct sbiret sret;
+
+ if (!mpxy->shmem_active)
+ return -ENODEV;
+ if (!notif_data || !events_data_len)
+ return -EINVAL;
+
+ get_cpu();
+
+ sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_NOTIFICATION_EVENTS,
+ channel_id, 0, 0, 0, 0, 0);
+ if (sret.error)
+ goto err_put_cpu;
+ if (sret.value < 0 || mpxy_shmem_size < sizeof(*notif_data) ||
+ sret.value > mpxy_shmem_size - sizeof(*notif_data)) {
+ put_cpu();
+ return -EOVERFLOW;
+ }
+
+ memcpy(notif_data, mpxy->shmem, sret.value + sizeof(*notif_data));
+ *events_data_len = sret.value;
+
+err_put_cpu:
+ put_cpu();
+ return sbi_err_map_linux_errno(sret.error);
+}
+EXPORT_SYMBOL_GPL(sbi_mpxy_get_notifications);
+
+static int mpxy_get_shmem_size(unsigned long *shmem_size)
+{
+ struct sbiret sret;
+
+ sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_SHMEM_SIZE,
+ 0, 0, 0, 0, 0, 0);
+ if (sret.error)
+ return sbi_err_map_linux_errno(sret.error);
+ if (shmem_size)
+ *shmem_size = sret.value;
+ return 0;
+}
+
+static int mpxy_setup_shmem(unsigned int cpu)
+{
+ struct page *shmem_page;
+ struct mpxy_local *mpxy;
+ struct sbiret sret;
+
+ mpxy = per_cpu_ptr(&mpxy_local, cpu);
+ if (mpxy->shmem_active)
+ return 0;
+
+ shmem_page = alloc_pages(GFP_KERNEL | __GFP_ZERO, get_order(mpxy_shmem_size));
+ if (!shmem_page)
+ return -ENOMEM;
+
+ /*
+ * Linux setup of shmem is done in mpxy OVERWRITE mode.
+ * flags[1:0] = 00b
+ */
+ sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SET_SHMEM,
+ page_to_phys(shmem_page), 0, 0, 0, 0, 0);
+ if (sret.error) {
+ free_pages((unsigned long)page_to_virt(shmem_page),
+ get_order(mpxy_shmem_size));
+ return sbi_err_map_linux_errno(sret.error);
+ }
+
+ mpxy->shmem = page_to_virt(shmem_page);
+ mpxy->shmem_phys_addr = page_to_phys(shmem_page);
+ mpxy->shmem_active = true;
+
+ return 0;
+}
+
+static int __init sbi_mpxy_init(void)
+{
+ int rc;
+
+ /* Skip quietly when MPXY extension is not supported. */
+ if (sbi_spec_version < sbi_mk_version(3, 0) ||
+ !sbi_probe_extension(SBI_EXT_MPXY))
+ return 0;
+ pr_info("SBI MPXY extension detected\n");
+
+ /* Find-out shared memory size */
+ rc = mpxy_get_shmem_size(&mpxy_shmem_size);
+ if (rc) {
+ pr_err("failed to get MPXY shared memory size\n");
+ return rc;
+ }
+
+ /*
+ * Setup MPXY shared memory on each CPU
+ *
+ * Note: Don't cleanup MPXY shared memory upon CPU power-down
+ * because the RPMI System MSI irqchip driver needs it to be
+ * available when migrating IRQs in CPU power-down path.
+ */
+ rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "riscv/sbi-mpxy-shmem",
+ mpxy_setup_shmem, NULL);
+ if (rc < 0)
+ return rc;
+
+ /* Mark as MPXY shared memory initialization done */
+ mpxy_shmem_init_done = true;
+ return 0;
+}
+arch_initcall(sbi_mpxy_init);
diff --git a/drivers/mailbox/riscv-sbi-mpxy-mbox.c b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
index 2134ceea1044..432972195e46 100644
--- a/drivers/mailbox/riscv-sbi-mpxy-mbox.c
+++ b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
@@ -17,7 +17,6 @@
#include <linux/module.h>
#include <linux/msi.h>
#include <linux/of_irq.h>
-#include <linux/percpu.h>
#include <linux/platform_device.h>
#include <linux/smp.h>
#include <linux/string.h>
@@ -85,295 +84,6 @@ struct sbi_mpxy_rpmi_channel_attrs {
u32 impl_version;
};
-/* SBI MPXY channel IDs data in shared memory */
-struct sbi_mpxy_channel_ids_data {
- /* Remaining number of channel ids */
- __le32 remaining;
- /* Returned channel ids in current function call */
- __le32 returned;
- /* Returned channel id array */
- __le32 channel_array[];
-};
-
-/* SBI MPXY notification data in shared memory */
-struct sbi_mpxy_notification_data {
- /* Remaining number of notification events */
- __le32 remaining;
- /* Number of notification events returned */
- __le32 returned;
- /* Number of notification events lost */
- __le32 lost;
- /* Reserved for future use */
- __le32 reserved;
- /* Returned channel id array */
- u8 events_data[];
-};
-
-/* ====== MPXY data structures & helper routines ====== */
-
-/* MPXY Per-CPU or local context */
-struct mpxy_local {
- /* Shared memory base address */
- void *shmem;
- /* Shared memory physical address */
- phys_addr_t shmem_phys_addr;
- /* Flag representing whether shared memory is active or not */
- bool shmem_active;
-};
-
-static DEFINE_PER_CPU(struct mpxy_local, mpxy_local);
-static unsigned long mpxy_shmem_size;
-static bool mpxy_shmem_init_done;
-
-static int mpxy_get_channel_count(u32 *channel_count)
-{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
- struct sbi_mpxy_channel_ids_data *sdata = mpxy->shmem;
- u32 remaining, returned;
- struct sbiret sret;
-
- if (!mpxy->shmem_active)
- return -ENODEV;
- if (!channel_count)
- return -EINVAL;
-
- get_cpu();
-
- /* Get the remaining and returned fields to calculate total */
- sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_CHANNEL_IDS,
- 0, 0, 0, 0, 0, 0);
- if (sret.error)
- goto err_put_cpu;
-
- remaining = le32_to_cpu(sdata->remaining);
- returned = le32_to_cpu(sdata->returned);
- *channel_count = remaining + returned;
-
-err_put_cpu:
- put_cpu();
- return sbi_err_map_linux_errno(sret.error);
-}
-
-static int mpxy_get_channel_ids(u32 channel_count, u32 *channel_ids)
-{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
- struct sbi_mpxy_channel_ids_data *sdata = mpxy->shmem;
- u32 remaining, returned, count, start_index = 0;
- struct sbiret sret;
-
- if (!mpxy->shmem_active)
- return -ENODEV;
- if (!channel_count || !channel_ids)
- return -EINVAL;
-
- get_cpu();
-
- do {
- sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_CHANNEL_IDS,
- start_index, 0, 0, 0, 0, 0);
- if (sret.error)
- goto err_put_cpu;
-
- remaining = le32_to_cpu(sdata->remaining);
- returned = le32_to_cpu(sdata->returned);
-
- count = returned < (channel_count - start_index) ?
- returned : (channel_count - start_index);
- memcpy_from_le32(&channel_ids[start_index], sdata->channel_array, count);
- start_index += count;
- } while (remaining && start_index < channel_count);
-
-err_put_cpu:
- put_cpu();
- return sbi_err_map_linux_errno(sret.error);
-}
-
-static int mpxy_read_attrs(u32 channel_id, u32 base_attrid, u32 attr_count,
- u32 *attrs_buf)
-{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
- struct sbiret sret;
-
- if (!mpxy->shmem_active)
- return -ENODEV;
- if (!attr_count || !attrs_buf)
- return -EINVAL;
-
- get_cpu();
-
- sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_READ_ATTRS,
- channel_id, base_attrid, attr_count, 0, 0, 0);
- if (sret.error)
- goto err_put_cpu;
-
- memcpy_from_le32(attrs_buf, (__le32 *)mpxy->shmem, attr_count);
-
-err_put_cpu:
- put_cpu();
- return sbi_err_map_linux_errno(sret.error);
-}
-
-static int mpxy_write_attrs(u32 channel_id, u32 base_attrid, u32 attr_count,
- u32 *attrs_buf)
-{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
- struct sbiret sret;
-
- if (!mpxy->shmem_active)
- return -ENODEV;
- if (!attr_count || !attrs_buf)
- return -EINVAL;
-
- get_cpu();
-
- memcpy_to_le32((__le32 *)mpxy->shmem, attrs_buf, attr_count);
- sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_WRITE_ATTRS,
- channel_id, base_attrid, attr_count, 0, 0, 0);
-
- put_cpu();
- return sbi_err_map_linux_errno(sret.error);
-}
-
-static int mpxy_send_message_with_resp(u32 channel_id, u32 msg_id,
- void *tx, unsigned long tx_len,
- void *rx, unsigned long max_rx_len,
- unsigned long *rx_len)
-{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
- unsigned long rx_bytes;
- struct sbiret sret;
-
- if (!mpxy->shmem_active)
- return -ENODEV;
- if (!tx && tx_len)
- return -EINVAL;
-
- get_cpu();
-
- /* Message protocols allowed to have no data in messages */
- if (tx_len)
- memcpy(mpxy->shmem, tx, tx_len);
-
- sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SEND_MSG_WITH_RESP,
- channel_id, msg_id, tx_len, 0, 0, 0);
- if (rx && !sret.error) {
- rx_bytes = sret.value;
- if (rx_bytes > max_rx_len) {
- put_cpu();
- return -ENOSPC;
- }
-
- memcpy(rx, mpxy->shmem, rx_bytes);
- if (rx_len)
- *rx_len = rx_bytes;
- }
-
- put_cpu();
- return sbi_err_map_linux_errno(sret.error);
-}
-
-static int mpxy_send_message_without_resp(u32 channel_id, u32 msg_id,
- void *tx, unsigned long tx_len)
-{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
- struct sbiret sret;
-
- if (!mpxy->shmem_active)
- return -ENODEV;
- if (!tx && tx_len)
- return -EINVAL;
-
- get_cpu();
-
- /* Message protocols allowed to have no data in messages */
- if (tx_len)
- memcpy(mpxy->shmem, tx, tx_len);
-
- sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SEND_MSG_WITHOUT_RESP,
- channel_id, msg_id, tx_len, 0, 0, 0);
-
- put_cpu();
- return sbi_err_map_linux_errno(sret.error);
-}
-
-static int mpxy_get_notifications(u32 channel_id,
- struct sbi_mpxy_notification_data *notif_data,
- unsigned long *events_data_len)
-{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
- struct sbiret sret;
-
- if (!mpxy->shmem_active)
- return -ENODEV;
- if (!notif_data || !events_data_len)
- return -EINVAL;
-
- get_cpu();
-
- sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_NOTIFICATION_EVENTS,
- channel_id, 0, 0, 0, 0, 0);
- if (sret.error)
- goto err_put_cpu;
- if (sret.value < 0 || mpxy_shmem_size < sizeof(*notif_data) ||
- sret.value > mpxy_shmem_size - sizeof(*notif_data)) {
- put_cpu();
- return -EOVERFLOW;
- }
-
- memcpy(notif_data, mpxy->shmem, sret.value + sizeof(*notif_data));
- *events_data_len = sret.value;
-
-err_put_cpu:
- put_cpu();
- return sbi_err_map_linux_errno(sret.error);
-}
-
-static int mpxy_get_shmem_size(unsigned long *shmem_size)
-{
- struct sbiret sret;
-
- sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_SHMEM_SIZE,
- 0, 0, 0, 0, 0, 0);
- if (sret.error)
- return sbi_err_map_linux_errno(sret.error);
- if (shmem_size)
- *shmem_size = sret.value;
- return 0;
-}
-
-static int mpxy_setup_shmem(unsigned int cpu)
-{
- struct page *shmem_page;
- struct mpxy_local *mpxy;
- struct sbiret sret;
-
- mpxy = per_cpu_ptr(&mpxy_local, cpu);
- if (mpxy->shmem_active)
- return 0;
-
- shmem_page = alloc_pages(GFP_KERNEL | __GFP_ZERO, get_order(mpxy_shmem_size));
- if (!shmem_page)
- return -ENOMEM;
-
- /*
- * Linux setup of shmem is done in mpxy OVERWRITE mode.
- * flags[1:0] = 00b
- */
- sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SET_SHMEM,
- page_to_phys(shmem_page), 0, 0, 0, 0, 0);
- if (sret.error) {
- free_pages((unsigned long)page_to_virt(shmem_page),
- get_order(mpxy_shmem_size));
- return sbi_err_map_linux_errno(sret.error);
- }
-
- mpxy->shmem = page_to_virt(shmem_page);
- mpxy->shmem_phys_addr = page_to_phys(shmem_page);
- mpxy->shmem_active = true;
-
- return 0;
-}
-
/* ====== MPXY mailbox data structures ====== */
/* MPXY mailbox channel */
@@ -447,13 +157,13 @@ static void mpxy_mbox_send_rpmi_data(struct mpxy_mbox_channel *mchan,
msg->error = -EIO;
break;
}
- msg->error = mpxy_send_message_with_resp(mchan->channel_id,
- msg->data.service_id,
- msg->data.request,
- msg->data.request_len,
- msg->data.response,
- msg->data.max_response_len,
- &msg->data.out_response_len);
+ msg->error = sbi_mpxy_send_message_with_resp(mchan->channel_id,
+ msg->data.service_id,
+ msg->data.request,
+ msg->data.request_len,
+ msg->data.response,
+ msg->data.max_response_len,
+ &msg->data.out_response_len);
break;
case RPMI_MBOX_MSG_TYPE_SEND_WITHOUT_RESPONSE:
if ((!msg->data.request && msg->data.request_len) ||
@@ -465,10 +175,10 @@ static void mpxy_mbox_send_rpmi_data(struct mpxy_mbox_channel *mchan,
msg->error = -EIO;
break;
}
- msg->error = mpxy_send_message_without_resp(mchan->channel_id,
- msg->data.service_id,
- msg->data.request,
- msg->data.request_len);
+ msg->error = sbi_mpxy_send_message_without_resp(mchan->channel_id,
+ msg->data.service_id,
+ msg->data.request,
+ msg->data.request_len);
break;
default:
msg->error = -EOPNOTSUPP;
@@ -504,10 +214,10 @@ static void mpxy_mbox_peek_rpmi_data(struct mbox_chan *chan,
static int mpxy_mbox_read_rpmi_attrs(struct mpxy_mbox_channel *mchan)
{
- return mpxy_read_attrs(mchan->channel_id,
- SBI_MPXY_ATTR_MSGPROTO_ATTR_START,
- sizeof(mchan->rpmi_attrs) / sizeof(u32),
- (u32 *)&mchan->rpmi_attrs);
+ return sbi_mpxy_read_attrs(mchan->channel_id,
+ SBI_MPXY_ATTR_MSGPROTO_ATTR_START,
+ sizeof(mchan->rpmi_attrs) / sizeof(u32),
+ (u32 *)&mchan->rpmi_attrs);
}
/* ====== MPXY mailbox callbacks ====== */
@@ -536,7 +246,7 @@ static bool mpxy_mbox_peek_data(struct mbox_chan *chan)
return false;
do {
- rc = mpxy_get_notifications(mchan->channel_id, notif, &data_len);
+ rc = sbi_mpxy_get_notifications(mchan->channel_id, notif, &data_len);
if (rc || !data_len)
break;
@@ -580,8 +290,8 @@ static int mpxy_mbox_setup_msi(struct mbox_chan *chan,
/* Enable channel MSI control */
mchan->attrs.msi_control = 1;
- rc = mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_MSI_CONTROL,
- 1, &mchan->attrs.msi_control);
+ rc = sbi_mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_MSI_CONTROL,
+ 1, &mchan->attrs.msi_control);
if (rc) {
dev_err(dev, "enable MSI control failed for MPXY channel 0x%x\n",
mchan->channel_id);
@@ -609,8 +319,8 @@ static void mpxy_mbox_cleanup_msi(struct mbox_chan *chan,
/* Disable channel MSI control */
mchan->attrs.msi_control = 0;
- rc = mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_MSI_CONTROL,
- 1, &mchan->attrs.msi_control);
+ rc = sbi_mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_MSI_CONTROL,
+ 1, &mchan->attrs.msi_control);
if (rc) {
dev_err(dev, "disable MSI control failed for MPXY channel 0x%x\n",
mchan->channel_id);
@@ -635,8 +345,8 @@ static int mpxy_mbox_setup_events(struct mpxy_mbox_channel *mchan)
/* Enable channel events state */
mchan->attrs.events_state_ctrl = 1;
- rc = mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_EVENTS_STATE_CONTROL,
- 1, &mchan->attrs.events_state_ctrl);
+ rc = sbi_mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_EVENTS_STATE_CONTROL,
+ 1, &mchan->attrs.events_state_ctrl);
if (rc) {
dev_err(dev, "enable events state failed for MPXY channel 0x%x\n",
mchan->channel_id);
@@ -662,8 +372,8 @@ static void mpxy_mbox_cleanup_events(struct mpxy_mbox_channel *mchan)
/* Disable channel events state */
mchan->attrs.events_state_ctrl = 0;
- rc = mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_EVENTS_STATE_CONTROL,
- 1, &mchan->attrs.events_state_ctrl);
+ rc = sbi_mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_EVENTS_STATE_CONTROL,
+ 1, &mchan->attrs.events_state_ctrl);
if (rc)
dev_err(dev, "disable events state failed for MPXY channel 0x%x\n",
mchan->channel_id);
@@ -741,8 +451,8 @@ static void mpxy_mbox_msi_write(struct msi_desc *desc, struct msi_msg *msg)
minfo->msi_addr_hi = msg->address_hi;
minfo->msi_data = msg->data;
- rc = mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_MSI_ADDR_LO,
- sizeof(*minfo) / sizeof(u32), (u32 *)minfo);
+ rc = sbi_mpxy_write_attrs(mchan->channel_id, SBI_MPXY_ATTR_MSI_ADDR_LO,
+ sizeof(*minfo) / sizeof(u32), (u32 *)minfo);
if (rc) {
dev_warn(dev, "failed to write MSI info for MPXY channel 0x%x\n",
mchan->channel_id);
@@ -776,7 +486,7 @@ static int mpxy_mbox_populate_channels(struct mpxy_mbox *mbox)
int rc;
/* Find-out of number of channels */
- rc = mpxy_get_channel_count(&mbox->channel_count);
+ rc = sbi_mpxy_get_channel_count(&mbox->channel_count);
if (rc)
return dev_err_probe(mbox->dev, rc, "failed to get number of MPXY channels\n");
if (!mbox->channel_count)
@@ -786,7 +496,7 @@ static int mpxy_mbox_populate_channels(struct mpxy_mbox *mbox)
channel_ids = kzalloc_objs(*channel_ids, mbox->channel_count);
if (!channel_ids)
return -ENOMEM;
- rc = mpxy_get_channel_ids(mbox->channel_count, channel_ids);
+ rc = sbi_mpxy_get_channel_ids(mbox->channel_count, channel_ids);
if (rc)
return dev_err_probe(mbox->dev, rc, "failed to get MPXY channel IDs\n");
@@ -800,9 +510,9 @@ static int mpxy_mbox_populate_channels(struct mpxy_mbox *mbox)
mchan->mbox = mbox;
mchan->channel_id = channel_ids[i];
- rc = mpxy_read_attrs(mchan->channel_id, SBI_MPXY_ATTR_MSG_PROT_ID,
- sizeof(mchan->attrs) / sizeof(u32),
- (u32 *)&mchan->attrs);
+ rc = sbi_mpxy_read_attrs(mchan->channel_id, SBI_MPXY_ATTR_MSG_PROT_ID,
+ sizeof(mchan->attrs) / sizeof(u32),
+ (u32 *)&mchan->attrs);
if (rc) {
return dev_err_probe(mbox->dev, rc,
"MPXY channel 0x%x read attrs failed\n",
@@ -818,11 +528,11 @@ static int mpxy_mbox_populate_channels(struct mpxy_mbox *mbox)
}
}
- mchan->notif = devm_kzalloc(mbox->dev, mpxy_shmem_size, GFP_KERNEL);
+ mchan->notif = devm_kzalloc(mbox->dev, sbi_mpxy_shmem_size(), GFP_KERNEL);
if (!mchan->notif)
return -ENOMEM;
- mchan->max_xfer_len = min(mpxy_shmem_size, mchan->attrs.msg_max_len);
+ mchan->max_xfer_len = min(sbi_mpxy_shmem_size(), mchan->attrs.msg_max_len);
if ((mchan->attrs.capability & SBI_MPXY_CHAN_CAP_GET_NOTIFICATIONS) &&
(mchan->attrs.capability & SBI_MPXY_CHAN_CAP_EVENTS_STATE))
@@ -847,40 +557,12 @@ static int mpxy_mbox_probe(struct platform_device *pdev)
int msi_idx, rc;
u32 i;
- /*
- * Initialize MPXY shared memory only once. This also ensures
- * that SBI MPXY mailbox is probed only once.
- */
- if (mpxy_shmem_init_done) {
- dev_err(dev, "SBI MPXY mailbox already initialized\n");
- return -EALREADY;
- }
-
/* Probe for SBI MPXY extension */
- if (sbi_spec_version < sbi_mk_version(1, 0) ||
- sbi_probe_extension(SBI_EXT_MPXY) <= 0) {
+ if (!sbi_mpxy_shmem_size()) {
dev_info(dev, "SBI MPXY extension not available\n");
return -ENODEV;
}
- /* Find-out shared memory size */
- rc = mpxy_get_shmem_size(&mpxy_shmem_size);
- if (rc)
- return dev_err_probe(dev, rc, "failed to get MPXY shared memory size\n");
-
- /*
- * Setup MPXY shared memory on each CPU
- *
- * Note: Don't cleanup MPXY shared memory upon CPU power-down
- * because the RPMI System MSI irqchip driver needs it to be
- * available when migrating IRQs in CPU power-down path.
- */
- cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "riscv/sbi-mpxy-shmem",
- mpxy_setup_shmem, NULL);
-
- /* Mark as MPXY shared memory initialization done */
- mpxy_shmem_init_done = true;
-
/* Allocate mailbox instance */
mbox = devm_kzalloc_obj(dev, *mbox);
if (!mbox)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/5] RISC-V: Use irqsave to prevent interrupt when accessing MPXY shared memory
2026-11-16 4:00 [PATCH v2 0/5] Parallel message send using SBI MPXY Anup Patel
2026-11-16 4:00 ` [PATCH v2 1/5] RISC-V: Move common MPXY helper routines to arch/riscv Anup Patel
@ 2026-11-16 4:00 ` Anup Patel
2026-11-16 4:00 ` [PATCH v2 3/5] mailbox: add direct synchronous transmit API Anup Patel
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Anup Patel @ 2026-11-16 4:00 UTC (permalink / raw)
To: Palmer Dabbelt, Paul Walmsley, Rahul Pathak, Stephen Boyd,
Brian Masney, Jerome Brunet, Thomas Gleixner, Radu Rendec,
Jassi Brar
Cc: Sunil V L, Himanshu Chauhan, Atish Patra, Anup Patel,
Amirreza Zarrabi, linux-riscv, linux-kernel, linux-clk,
Anup Patel
Currently, get_cpu()/put_cpu() is used to prevent getting preempted when
accessing shared memory but an external interrupt can still be taken which
may invoke RPMI system IRQ driver potentially corrupting MPXY shared memory.
To prevent the above, replace get_cpu()/put_cpu() with irq save/restore
which ensures external interrupt can't corrupt MPXY shared memory.
Co-developed-by: Jassi Brar <jassisinghbrar@gmail.com>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>
Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
---
arch/riscv/kernel/sbi_mpxy.c | 114 +++++++++++++++++------------------
1 file changed, 57 insertions(+), 57 deletions(-)
diff --git a/arch/riscv/kernel/sbi_mpxy.c b/arch/riscv/kernel/sbi_mpxy.c
index 17a2cee21311..99ab3e552da3 100644
--- a/arch/riscv/kernel/sbi_mpxy.c
+++ b/arch/riscv/kernel/sbi_mpxy.c
@@ -6,8 +6,10 @@
*/
#define pr_fmt(fmt) "riscv: " fmt
+#include <linux/cleanup.h>
#include <linux/cpu.h>
#include <linux/init.h>
+#include <linux/irqflags.h>
#include <linux/mm.h>
#include <linux/percpu.h>
#include <linux/printk.h>
@@ -50,113 +52,116 @@ EXPORT_SYMBOL_GPL(sbi_mpxy_shmem_size);
int sbi_mpxy_get_channel_count(u32 *channel_count)
{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
- struct sbi_mpxy_channel_ids_data *sdata = mpxy->shmem;
+ struct sbi_mpxy_channel_ids_data *sdata;
+ struct mpxy_local *mpxy;
u32 remaining, returned;
struct sbiret sret;
- if (!mpxy->shmem_active)
- return -ENODEV;
if (!channel_count)
return -EINVAL;
- get_cpu();
+ /*
+ * The shared memory is per-CPU. Disable IRQs so that a local IRQ
+ * cannot re-enter and clobber the buffer while the SBI call uses it.
+ * This also pins the current CPU for this_cpu_ptr().
+ */
+ guard(irqsave)();
+ mpxy = this_cpu_ptr(&mpxy_local);
+ if (!mpxy->shmem_active)
+ return -ENODEV;
+ sdata = mpxy->shmem;
/* Get the remaining and returned fields to calculate total */
sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_CHANNEL_IDS,
0, 0, 0, 0, 0, 0);
if (sret.error)
- goto err_put_cpu;
+ return sbi_err_map_linux_errno(sret.error);
remaining = le32_to_cpu(sdata->remaining);
returned = le32_to_cpu(sdata->returned);
*channel_count = remaining + returned;
-err_put_cpu:
- put_cpu();
- return sbi_err_map_linux_errno(sret.error);
+ return 0;
}
EXPORT_SYMBOL_GPL(sbi_mpxy_get_channel_count);
int sbi_mpxy_get_channel_ids(u32 channel_count, u32 *channel_ids)
{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
- struct sbi_mpxy_channel_ids_data *sdata = mpxy->shmem;
u32 remaining, returned, count, start_index = 0;
+ struct sbi_mpxy_channel_ids_data *sdata;
+ struct mpxy_local *mpxy;
struct sbiret sret;
- if (!mpxy->shmem_active)
- return -ENODEV;
if (!channel_count || !channel_ids)
return -EINVAL;
- get_cpu();
+ guard(irqsave)();
+ mpxy = this_cpu_ptr(&mpxy_local);
+ if (!mpxy->shmem_active)
+ return -ENODEV;
+ sdata = mpxy->shmem;
do {
sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_CHANNEL_IDS,
start_index, 0, 0, 0, 0, 0);
if (sret.error)
- goto err_put_cpu;
+ return sbi_err_map_linux_errno(sret.error);
remaining = le32_to_cpu(sdata->remaining);
returned = le32_to_cpu(sdata->returned);
- count = returned < (channel_count - start_index) ?
- returned : (channel_count - start_index);
+ count = min(returned, channel_count - start_index);
memcpy_from_le32(&channel_ids[start_index], sdata->channel_array, count);
start_index += count;
} while (remaining && start_index < channel_count);
-err_put_cpu:
- put_cpu();
- return sbi_err_map_linux_errno(sret.error);
+ return 0;
}
EXPORT_SYMBOL_GPL(sbi_mpxy_get_channel_ids);
int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attrid, u32 attr_count,
u32 *attrs_buf)
{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
+ struct mpxy_local *mpxy;
struct sbiret sret;
- if (!mpxy->shmem_active)
- return -ENODEV;
if (!attr_count || !attrs_buf)
return -EINVAL;
- get_cpu();
+ guard(irqsave)();
+ mpxy = this_cpu_ptr(&mpxy_local);
+ if (!mpxy->shmem_active)
+ return -ENODEV;
sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_READ_ATTRS,
channel_id, base_attrid, attr_count, 0, 0, 0);
if (sret.error)
- goto err_put_cpu;
+ return sbi_err_map_linux_errno(sret.error);
memcpy_from_le32(attrs_buf, (__le32 *)mpxy->shmem, attr_count);
-err_put_cpu:
- put_cpu();
- return sbi_err_map_linux_errno(sret.error);
+ return 0;
}
EXPORT_SYMBOL_GPL(sbi_mpxy_read_attrs);
int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attrid, u32 attr_count,
u32 *attrs_buf)
{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
+ struct mpxy_local *mpxy;
struct sbiret sret;
- if (!mpxy->shmem_active)
- return -ENODEV;
if (!attr_count || !attrs_buf)
return -EINVAL;
- get_cpu();
+ guard(irqsave)();
+ mpxy = this_cpu_ptr(&mpxy_local);
+ if (!mpxy->shmem_active)
+ return -ENODEV;
memcpy_to_le32((__le32 *)mpxy->shmem, attrs_buf, attr_count);
sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_WRITE_ATTRS,
channel_id, base_attrid, attr_count, 0, 0, 0);
- put_cpu();
return sbi_err_map_linux_errno(sret.error);
}
EXPORT_SYMBOL_GPL(sbi_mpxy_write_attrs);
@@ -166,16 +171,17 @@ int sbi_mpxy_send_message_with_resp(u32 channel_id, u32 msg_id,
void *rx, unsigned long max_rx_len,
unsigned long *rx_len)
{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
+ struct mpxy_local *mpxy;
unsigned long rx_bytes;
struct sbiret sret;
- if (!mpxy->shmem_active)
- return -ENODEV;
if (!tx && tx_len)
return -EINVAL;
- get_cpu();
+ guard(irqsave)();
+ mpxy = this_cpu_ptr(&mpxy_local);
+ if (!mpxy->shmem_active)
+ return -ENODEV;
/* Message protocols allowed to have no data in messages */
if (tx_len)
@@ -185,17 +191,14 @@ int sbi_mpxy_send_message_with_resp(u32 channel_id, u32 msg_id,
channel_id, msg_id, tx_len, 0, 0, 0);
if (rx && !sret.error) {
rx_bytes = sret.value;
- if (rx_bytes > max_rx_len) {
- put_cpu();
+ if (rx_bytes > max_rx_len)
return -ENOSPC;
- }
memcpy(rx, mpxy->shmem, rx_bytes);
if (rx_len)
*rx_len = rx_bytes;
}
- put_cpu();
return sbi_err_map_linux_errno(sret.error);
}
EXPORT_SYMBOL_GPL(sbi_mpxy_send_message_with_resp);
@@ -203,15 +206,16 @@ EXPORT_SYMBOL_GPL(sbi_mpxy_send_message_with_resp);
int sbi_mpxy_send_message_without_resp(u32 channel_id, u32 msg_id,
void *tx, unsigned long tx_len)
{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
+ struct mpxy_local *mpxy;
struct sbiret sret;
- if (!mpxy->shmem_active)
- return -ENODEV;
if (!tx && tx_len)
return -EINVAL;
- get_cpu();
+ guard(irqsave)();
+ mpxy = this_cpu_ptr(&mpxy_local);
+ if (!mpxy->shmem_active)
+ return -ENODEV;
/* Message protocols allowed to have no data in messages */
if (tx_len)
@@ -220,7 +224,6 @@ int sbi_mpxy_send_message_without_resp(u32 channel_id, u32 msg_id,
sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_SEND_MSG_WITHOUT_RESP,
channel_id, msg_id, tx_len, 0, 0, 0);
- put_cpu();
return sbi_err_map_linux_errno(sret.error);
}
EXPORT_SYMBOL_GPL(sbi_mpxy_send_message_without_resp);
@@ -229,32 +232,29 @@ int sbi_mpxy_get_notifications(u32 channel_id,
struct sbi_mpxy_notification_data *notif_data,
unsigned long *events_data_len)
{
- struct mpxy_local *mpxy = this_cpu_ptr(&mpxy_local);
+ struct mpxy_local *mpxy;
struct sbiret sret;
- if (!mpxy->shmem_active)
- return -ENODEV;
if (!notif_data || !events_data_len)
return -EINVAL;
- get_cpu();
+ guard(irqsave)();
+ mpxy = this_cpu_ptr(&mpxy_local);
+ if (!mpxy->shmem_active)
+ return -ENODEV;
sret = sbi_ecall(SBI_EXT_MPXY, SBI_EXT_MPXY_GET_NOTIFICATION_EVENTS,
channel_id, 0, 0, 0, 0, 0);
if (sret.error)
- goto err_put_cpu;
+ return sbi_err_map_linux_errno(sret.error);
if (sret.value < 0 || mpxy_shmem_size < sizeof(*notif_data) ||
- sret.value > mpxy_shmem_size - sizeof(*notif_data)) {
- put_cpu();
+ sret.value > mpxy_shmem_size - sizeof(*notif_data))
return -EOVERFLOW;
- }
memcpy(notif_data, mpxy->shmem, sret.value + sizeof(*notif_data));
*events_data_len = sret.value;
-err_put_cpu:
- put_cpu();
- return sbi_err_map_linux_errno(sret.error);
+ return 0;
}
EXPORT_SYMBOL_GPL(sbi_mpxy_get_notifications);
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 3/5] mailbox: add direct synchronous transmit API
2026-11-16 4:00 [PATCH v2 0/5] Parallel message send using SBI MPXY Anup Patel
2026-11-16 4:00 ` [PATCH v2 1/5] RISC-V: Move common MPXY helper routines to arch/riscv Anup Patel
2026-11-16 4:00 ` [PATCH v2 2/5] RISC-V: Use irqsave to prevent interrupt when accessing MPXY shared memory Anup Patel
@ 2026-11-16 4:00 ` Anup Patel
2026-11-16 4:00 ` [PATCH v2 4/5] mailbox: document direct synchronous transmit Anup Patel
2026-11-16 4:00 ` [PATCH v2 5/5] mailbox: convert RISC-V SBI MPXY to direct transmit Anup Patel
4 siblings, 0 replies; 6+ messages in thread
From: Anup Patel @ 2026-11-16 4:00 UTC (permalink / raw)
To: Palmer Dabbelt, Paul Walmsley, Rahul Pathak, Stephen Boyd,
Brian Masney, Jerome Brunet, Thomas Gleixner, Radu Rendec,
Jassi Brar
Cc: Sunil V L, Himanshu Chauhan, Atish Patra, Anup Patel,
Amirreza Zarrabi, linux-riscv, linux-kernel, linux-clk,
Anup Patel
From: Jassi Brar <jassisinghbrar@gmail.com>
The mailbox framework only models queued transfers.
tx_block=true sleeps, while tx_block=false goes through the
single-request queue and txdone state machine. Controllers
that complete synchronously in the caller's context therefore
cannot return a reliable per-call result when multiple CPUs
use the same channel.
Add an opt-in per-channel direct transmit mode. A controller
advertises MBOX_CHAN_CAP_SYNC_ATOMIC and/or
MBOX_CHAN_CAP_SYNC_SLEEPABLE and implements the corresponding
send_data_sync* operation. The new mbox_send_message_sync*
client APIs bypass the queue, active_req, and txdone state
machine entirely and return the controller's result to the
caller. The framework imposes no per-channel lock on this
path; the controller owns serialization of its own resources
and the client owns serialization against free and unbind.
Direct channels reject mbox_send_message() and mbox_flush(),
warn on txdone misuse, and report zero TX slots.
Registration validates the capability and operation combination.
Existing controllers and clients keep zero sync_caps and
are unchanged.
Co-developed-by: Anup Patel <anup.patel@oss.qualcomm.com>
Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>
---
drivers/mailbox/mailbox.c | 144 ++++++++++++++++++++++++++++-
include/linux/mailbox_client.h | 9 +-
include/linux/mailbox_controller.h | 38 ++++++++
3 files changed, 184 insertions(+), 7 deletions(-)
diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
index efacd24a085d..0cc7d2eed7cf 100644
--- a/drivers/mailbox/mailbox.c
+++ b/drivers/mailbox/mailbox.c
@@ -11,6 +11,7 @@
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
+#include <linux/kernel.h>
#include <linux/mailbox_client.h>
#include <linux/mailbox_controller.h>
#include <linux/module.h>
@@ -162,10 +163,14 @@ EXPORT_SYMBOL_GPL(mbox_chan_received_data);
*
* The controller that has IRQ for TX ACK calls this atomic API
* to tick the TX state machine. It works only if txdone_irq
- * is set by the controller.
+ * is set by the controller. Direct channels do not use the queued
+ * state machine, so calling this on one is a bug and is ignored.
*/
void mbox_chan_txdone(struct mbox_chan *chan, int r)
{
+ if (WARN_ON_ONCE(mbox_chan_is_sync(chan)))
+ return;
+
if (unlikely(!(chan->txdone_method & MBOX_TXDONE_BY_IRQ))) {
dev_err(chan->mbox->dev,
"Controller can't run the TX ticker\n");
@@ -183,10 +188,15 @@ EXPORT_SYMBOL_GPL(mbox_chan_txdone);
*
* The client/protocol had received some 'ACK' packet and it notifies
* the API that the last packet was sent successfully. This only works
- * if the controller can't sense TX-Done.
+ * if the controller can't sense TX-Done. Direct channels return the
+ * per-call result from mbox_send_message_sync(), so calling this on one
+ * is a bug and is ignored.
*/
void mbox_client_txdone(struct mbox_chan *chan, int r)
{
+ if (WARN_ON_ONCE(mbox_chan_is_sync(chan)))
+ return;
+
if (unlikely(!(chan->txdone_method & MBOX_TXDONE_BY_ACK))) {
dev_err(chan->mbox->dev, "Client can't run the TX ticker\n");
return;
@@ -228,7 +238,8 @@ EXPORT_SYMBOL_GPL(mbox_client_peek_data);
* mbox_send_message() before the channel's TX queue is full. This helps
* clients avoid the -ENOBUFS error without needing to increase
* MBOX_TX_QUEUE_LEN.
- * This can be called from atomic context.
+ * This can be called from atomic context. Direct channels have no TX
+ * queue and always report zero slots.
*
* Return: Number of available slots in the channel's TX queue.
*/
@@ -236,6 +247,9 @@ unsigned int mbox_chan_tx_slots_available(struct mbox_chan *chan)
{
unsigned int ret;
+ if (mbox_chan_is_sync(chan))
+ return 0;
+
guard(spinlock_irqsave)(&chan->lock);
ret = MBOX_TX_QUEUE_LEN - chan->msg_count;
@@ -266,6 +280,9 @@ EXPORT_SYMBOL_GPL(mbox_chan_tx_slots_available);
* access to a channel if multi-threads are to send messages through the
* same channel, i.e. caller should not call this function until any
* previous call returns.
+ * A direct channel (see MBOX_CHAN_CAP_SYNC_*) does not use this queued
+ * path; use mbox_send_message_sync() or
+ * mbox_send_message_sync_sleepable() instead.
*
* Return: Non-negative integer for successful submission (non-blocking mode)
* or transmission over chan (blocking mode).
@@ -278,6 +295,9 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg)
if (!chan || !chan->cl || mssg == MBOX_NO_MSG)
return -EINVAL;
+ if (mbox_chan_is_sync(chan))
+ return -EOPNOTSUPP;
+
t = add_to_rbuf(chan, mssg);
if (t < 0) {
dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n");
@@ -308,6 +328,78 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg)
}
EXPORT_SYMBOL_GPL(mbox_send_message);
+/**
+ * mbox_send_message_sync - directly transmit a message from atomic context
+ * @chan: Mailbox channel assigned to this client.
+ * @mssg: Client specific message typecasted.
+ *
+ * Directly invoke the controller's atomic-safe synchronous transmit
+ * operation. The operation runs in the caller's context, without
+ * chan->lock and without touching the queued state machine, and returns
+ * the controller's per-call result. This function does not sleep and may
+ * be called from any context in which the controller's send_data_sync()
+ * operation is safe, including hardirq context.
+ *
+ * The message buffer must remain valid until this function returns; the
+ * controller must not retain it afterwards. The caller is responsible for
+ * serializing this call against mbox_free_channel() and driver removal.
+ *
+ * Return: 0 on success, -EINVAL for invalid arguments, -EOPNOTSUPP if the
+ * channel does not support atomic-safe direct transmit, or another
+ * negative errno from the controller.
+ */
+int mbox_send_message_sync(struct mbox_chan *chan, void *mssg)
+{
+ if (!chan || !READ_ONCE(chan->cl) || mssg == MBOX_NO_MSG)
+ return -EINVAL;
+
+ lockdep_assert_not_held(&chan->lock);
+
+ if (!(chan->sync_caps & MBOX_CHAN_CAP_SYNC_ATOMIC) ||
+ !chan->mbox->ops->send_data_sync)
+ return -EOPNOTSUPP;
+
+ return chan->mbox->ops->send_data_sync(chan, mssg);
+}
+EXPORT_SYMBOL_GPL(mbox_send_message_sync);
+
+/**
+ * mbox_send_message_sync_sleepable - directly transmit from sleepable context
+ * @chan: Mailbox channel assigned to this client.
+ * @mssg: Client specific message typecasted.
+ *
+ * Directly invoke a synchronous transmit operation that may sleep. If the
+ * channel implements send_data_sync_sleepable(), that operation is used;
+ * otherwise the atomic-safe send_data_sync() is used as a fallback. This
+ * function may sleep and must only be called from sleepable context.
+ *
+ * The message buffer and free/unbind rules are the same as for
+ * mbox_send_message_sync().
+ *
+ * Return: 0 on success, -EINVAL for invalid arguments, -EOPNOTSUPP if the
+ * channel does not support direct transmit, or another negative errno from
+ * the controller.
+ */
+int mbox_send_message_sync_sleepable(struct mbox_chan *chan, void *mssg)
+{
+ if (!chan || !READ_ONCE(chan->cl) || mssg == MBOX_NO_MSG)
+ return -EINVAL;
+
+ lockdep_assert_not_held(&chan->lock);
+ might_sleep();
+
+ if ((chan->sync_caps & MBOX_CHAN_CAP_SYNC_SLEEPABLE) &&
+ chan->mbox->ops->send_data_sync_sleepable)
+ return chan->mbox->ops->send_data_sync_sleepable(chan, mssg);
+
+ if ((chan->sync_caps & MBOX_CHAN_CAP_SYNC_ATOMIC) &&
+ chan->mbox->ops->send_data_sync)
+ return chan->mbox->ops->send_data_sync(chan, mssg);
+
+ return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL_GPL(mbox_send_message_sync_sleepable);
+
/**
* mbox_flush - flush a mailbox channel
* @chan: mailbox channel to flush
@@ -319,6 +411,8 @@ EXPORT_SYMBOL_GPL(mbox_send_message);
* call the mbox_flush() function at any time after mbox_send_message() to
* flush the transmission. After the function returns success, the mailbox
* transmission is guaranteed to have completed.
+ * Direct channels have no framework transmission to flush, so this function
+ * returns -EOPNOTSUPP for them.
*
* Returns: 0 on success or a negative error code on failure.
*/
@@ -326,6 +420,9 @@ int mbox_flush(struct mbox_chan *chan, unsigned long timeout)
{
int ret;
+ if (mbox_chan_is_sync(chan))
+ return -EOPNOTSUPP;
+
if (!chan->mbox->ops->flush)
return -ENOTSUPP;
@@ -343,7 +440,8 @@ static void mbox_clean_and_put_channel(struct mbox_chan *chan)
scoped_guard(spinlock_irqsave, &chan->lock) {
chan->cl = NULL;
chan->active_req = MBOX_NO_MSG;
- if (chan->txdone_method == MBOX_TXDONE_BY_ACK)
+ if (!mbox_chan_is_sync(chan) &&
+ chan->txdone_method == MBOX_TXDONE_BY_ACK)
chan->txdone_method = MBOX_TXDONE_BY_POLL;
}
@@ -367,7 +465,8 @@ static int __mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl)
chan->cl = cl;
init_completion(&chan->tx_complete);
- if (chan->txdone_method == MBOX_TXDONE_BY_POLL && cl->knows_txdone)
+ if (chan->txdone_method == MBOX_TXDONE_BY_POLL &&
+ !mbox_chan_is_sync(chan) && cl->knows_txdone)
chan->txdone_method = MBOX_TXDONE_BY_ACK;
}
@@ -543,6 +642,41 @@ int mbox_controller_register(struct mbox_controller *mbox)
if (!mbox || !mbox->dev || !mbox->ops || !mbox->chans || !mbox->num_chans)
return -EINVAL;
+ for (i = 0; i < mbox->num_chans; i++) {
+ struct mbox_chan *chan = &mbox->chans[i];
+
+ if (chan->sync_caps & ~(MBOX_CHAN_CAP_SYNC_ATOMIC |
+ MBOX_CHAN_CAP_SYNC_SLEEPABLE)) {
+ dev_err(mbox->dev,
+ "channel %d has unknown sync capabilities 0x%x\n",
+ i, chan->sync_caps);
+ return -EINVAL;
+ }
+
+ if ((chan->sync_caps & MBOX_CHAN_CAP_SYNC_ATOMIC) &&
+ !mbox->ops->send_data_sync) {
+ dev_err(mbox->dev,
+ "channel %d advertises atomic sync without send_data_sync\n",
+ i);
+ return -EINVAL;
+ }
+
+ if ((chan->sync_caps & MBOX_CHAN_CAP_SYNC_SLEEPABLE) &&
+ !mbox->ops->send_data_sync_sleepable) {
+ dev_err(mbox->dev,
+ "channel %d advertises sleepable sync without send_data_sync_sleepable\n",
+ i);
+ return -EINVAL;
+ }
+
+ if (!mbox_chan_is_sync(chan) && !mbox->ops->send_data) {
+ dev_err(mbox->dev,
+ "queued channel %d has no send_data operation\n",
+ i);
+ return -EINVAL;
+ }
+ }
+
if (mbox->txdone_irq)
txdone = MBOX_TXDONE_BY_IRQ;
else if (mbox->txdone_poll)
diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h
index e5997120f45c..49b778aa4b9a 100644
--- a/include/linux/mailbox_client.h
+++ b/include/linux/mailbox_client.h
@@ -16,11 +16,13 @@ struct mbox_chan;
* struct mbox_client - User of a mailbox
* @dev: The client device
* @tx_block: If the mbox_send_message should block until data is
- * transmitted.
- * @tx_tout: Max block period in ms before TX is assumed failure
+ * transmitted. Ignored on direct channels.
+ * @tx_tout: Max block period in ms before TX is assumed failure.
+ * Ignored on direct channels.
* @knows_txdone: If the client could run the TX state machine. Usually
* if the client receives some ACK packet for transmission.
* Unused if the controller already has TX_Done/RTR IRQ.
+ * Ignored on direct channels.
* @rx_callback: Atomic callback to provide client the data received
* @tx_prepare: Atomic callback to ask client to prepare the payload
* before initiating the transmission if required.
@@ -42,6 +44,9 @@ struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl,
const char *name);
struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index);
int mbox_send_message(struct mbox_chan *chan, void *mssg);
+int __must_check mbox_send_message_sync(struct mbox_chan *chan, void *mssg);
+int __must_check mbox_send_message_sync_sleepable(struct mbox_chan *chan,
+ void *mssg);
int mbox_flush(struct mbox_chan *chan, unsigned long timeout);
void mbox_client_txdone(struct mbox_chan *chan, int r); /* atomic */
bool mbox_client_peek_data(struct mbox_chan *chan); /* atomic */
diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_controller.h
index 26a238a6f941..34724bfc683d 100644
--- a/include/linux/mailbox_controller.h
+++ b/include/linux/mailbox_controller.h
@@ -19,6 +19,16 @@ struct mbox_chan;
#define MBOX_TXDONE_BY_POLL BIT(1) /* controller can read status of last TX */
#define MBOX_TXDONE_BY_ACK BIT(2) /* S/W ACK received by Client ticks the TX */
+/*
+ * Per-channel direct synchronous transmit capabilities. A channel with any
+ * of these bits set is a direct channel: mbox_send_message() and mbox_flush()
+ * are rejected on it and the matching direct operation is the only transmit
+ * path. The bits are set by the controller before registration and are
+ * immutable afterwards.
+ */
+#define MBOX_CHAN_CAP_SYNC_ATOMIC BIT(0) /* may not sleep */
+#define MBOX_CHAN_CAP_SYNC_SLEEPABLE BIT(1) /* may sleep */
+
/**
* struct mbox_chan_ops - methods to control mailbox channels
* @send_data: The API asks the MBOX controller driver, in atomic
@@ -50,6 +60,18 @@ struct mbox_chan;
* Used only if txdone_poll:=true && txdone_irq:=false
* @peek_data: Atomic check for any received data. Return true if controller
* has some data to push to the client. False otherwise.
+ * @send_data_sync: Optional direct synchronous transmit. It is called from
+ * the client's context without chan->lock and must complete the
+ * transfer before returning. It must not sleep, must not call the
+ * txdone or mailbox transmit APIs recursively, and must not retain
+ * @data. It may be called concurrently on the same channel from
+ * multiple CPUs; the controller must protect its own resources and
+ * may return -EBUSY when a call cannot be served concurrently.
+ * Requires MBOX_CHAN_CAP_SYNC_ATOMIC on the channel.
+ * @send_data_sync_sleepable: Optional sleepable variant of @send_data_sync.
+ * It has the same direct semantics but may sleep and may therefore
+ * only be called from sleepable context. Requires
+ * MBOX_CHAN_CAP_SYNC_SLEEPABLE on the channel.
*/
struct mbox_chan_ops {
int (*send_data)(struct mbox_chan *chan, void *data);
@@ -58,6 +80,14 @@ struct mbox_chan_ops {
void (*shutdown)(struct mbox_chan *chan);
bool (*last_tx_done)(struct mbox_chan *chan);
bool (*peek_data)(struct mbox_chan *chan);
+
+ /*
+ * Optional direct synchronous transmit operations. Keep these at the
+ * end so positional initializers for the queued operations remain
+ * valid.
+ */
+ int (*send_data_sync)(struct mbox_chan *chan, void *data);
+ int (*send_data_sync_sleepable)(struct mbox_chan *chan, void *data);
};
/**
@@ -127,6 +157,8 @@ struct mbox_controller {
* @msg_data: Hook for data packet
* @lock: Serialise access to the channel
* @con_priv: Hook for controller driver to attach private data
+ * @sync_caps: Per-channel direct transmit capabilities, immutable
+ * after registration. Zero means a queued channel.
*/
struct mbox_chan {
struct mbox_controller *mbox;
@@ -139,8 +171,14 @@ struct mbox_chan {
void *msg_data[MBOX_TX_QUEUE_LEN];
spinlock_t lock; /* Serialise access to the channel */
void *con_priv;
+ unsigned int sync_caps; /* MBOX_CHAN_CAP_SYNC_* */
};
+static inline bool mbox_chan_is_sync(const struct mbox_chan *chan)
+{
+ return chan->sync_caps != 0;
+}
+
int mbox_controller_register(struct mbox_controller *mbox); /* can sleep */
void mbox_controller_unregister(struct mbox_controller *mbox); /* can sleep */
void mbox_chan_received_data(struct mbox_chan *chan, void *data); /* atomic */
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 4/5] mailbox: document direct synchronous transmit
2026-11-16 4:00 [PATCH v2 0/5] Parallel message send using SBI MPXY Anup Patel
` (2 preceding siblings ...)
2026-11-16 4:00 ` [PATCH v2 3/5] mailbox: add direct synchronous transmit API Anup Patel
@ 2026-11-16 4:00 ` Anup Patel
2026-11-16 4:00 ` [PATCH v2 5/5] mailbox: convert RISC-V SBI MPXY to direct transmit Anup Patel
4 siblings, 0 replies; 6+ messages in thread
From: Anup Patel @ 2026-11-16 4:00 UTC (permalink / raw)
To: Palmer Dabbelt, Paul Walmsley, Rahul Pathak, Stephen Boyd,
Brian Masney, Jerome Brunet, Thomas Gleixner, Radu Rendec,
Jassi Brar
Cc: Sunil V L, Himanshu Chauhan, Atish Patra, Anup Patel,
Amirreza Zarrabi, linux-riscv, linux-kernel, linux-clk,
Anup Patel
From: Jassi Brar <jassisinghbrar@gmail.com>
Document the three transmit models supported by the mailbox
framework: non-blocking queued, blocking queued, and direct
synchronous.
Describe the controller-side capability advertisement and
operation contracts, including atomic versus sleepable
operations, per-CPU and controller-wide resource protection,
registration validation, and the client-side context,
lifetime, and free/unbind rules. Add the normative interaction
table for the queued APIs on a direct channel and examples for
atomic-safe and per-CPU controllers.
Co-developed-by: Anup Patel <anup.patel@oss.qualcomm.com>
Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>
---
Documentation/driver-api/mailbox.rst | 350 +++++++++++++++++++++++++--
1 file changed, 329 insertions(+), 21 deletions(-)
diff --git a/Documentation/driver-api/mailbox.rst b/Documentation/driver-api/mailbox.rst
index d46c60bd5df6..81d471027539 100644
--- a/Documentation/driver-api/mailbox.rst
+++ b/Documentation/driver-api/mailbox.rst
@@ -20,14 +20,28 @@ ever deal at client's protocol level.
Some of the choices made during implementation are the result of this
peculiarity of this "common" framework.
+The framework supports three transmit models:
+
+* non-blocking queued: ``mbox_send_message()`` returns a queue token and
+ completion is reported later through ``tx_done``;
+* blocking queued: ``tx_block`` is set and the caller waits on the
+ channel completion;
+* direct synchronous: the controller completes the transfer in the
+ caller's context and the client receives the per-call result directly.
+
+The first two models share the per-channel queue and TX-done state
+machine. The direct model is opt-in per channel and bypasses that state
+machine entirely.
Controller Driver (See include/linux/mailbox_controller.h)
==========================================================
-
Allocate mbox_controller and the array of mbox_chan.
-Populate mbox_chan_ops, except flush() and peek_data() all are mandatory.
+Populate mbox_chan_ops. ``send_data`` is mandatory for queued channels;
+``flush``, ``startup``, ``shutdown``, ``last_tx_done``, and ``peek_data``
+are optional depending on the controller's capabilities and the selected
+TX-done method.
The controller driver might know a message has been consumed
by the remote by getting an IRQ or polling some hardware flag
or it can never know (the client knows by way of the protocol).
@@ -35,14 +49,197 @@ The method in order of preference is IRQ -> Poll -> None, which
the controller driver should set via 'txdone_irq' or 'txdone_poll'
or neither.
+Queued transmit
+---------------
+
+``send_data()`` is called by ``msg_submit()`` with ``chan->lock`` held and
+local IRQs disabled. It must not sleep. It should return 0 if the message
+was accepted, or a negative errno (for example ``-EBUSY``) if it could not
+be accepted. Completion is reported later with ``mbox_chan_txdone()``
+(IRQ mode) or by the polling timer calling ``last_tx_done()``. A client
+using the ``knows_txdone`` retrofit calls ``mbox_client_txdone()`` itself.
+
+The queue and TX-done state machine assume a single outstanding request
+per channel. All senders on a queued channel are therefore serialized by
+the framework, and ``tx_block`` callers must serialize themselves.
+
+Direct synchronous transmit
+---------------------------
+
+Some controllers complete a transfer synchronously in the calling context
+and can return the result immediately. Such a controller may advertise a
+direct channel by setting ``struct mbox_chan.sync_caps`` before calling
+``mbox_controller_register()``:
+
+.. code-block:: c
+
+ #define MBOX_CHAN_CAP_SYNC_ATOMIC BIT(0)
+ #define MBOX_CHAN_CAP_SYNC_SLEEPABLE BIT(1)
+
+A channel with either bit set is a *direct channel*. ``sync_caps`` is
+immutable after registration; zero means the channel keeps the existing
+queued behavior. Controllers must therefore initialize it to zero for
+queued channels; ``kzalloc()`` and static storage already do so.
+
+The controller implements one or both of these operations:
+
+.. code-block:: c
+
+ int (*send_data_sync)(struct mbox_chan *chan, void *data);
+ int (*send_data_sync_sleepable)(struct mbox_chan *chan, void *data);
+
+``send_data_sync()``
+ Atomic-safe direct transmit. It must not sleep, must complete the
+ transfer (or return a per-call error) before returning, and must not
+ use a later TX-done interrupt, polling timer, or ``mbox_chan_txdone()``.
+ It must not call the txdone APIs or any client callback recursively.
+ It must not retain ``data`` after returning.
+
+``send_data_sync_sleepable()``
+ Sleepable direct transmit. It has the same per-call, no-retained-buffer
+ contract but may use mutexes, completions, sleeping bus access, and other
+ sleepable primitives. It must only be called from sleepable context.
+
+Both operations are called in the client's context with no framework lock
+held and with the caller's IRQ and preemption state. The framework calls
+the operation exactly once per client call and returns its result to that
+same caller.
+
+A controller that implements a direct operation but does not set the
+matching capability bit is valid; the operation is then simply unused.
+Registration rejects unknown capability bits, a capability bit without the
+matching operation, and a queued channel without ``send_data``.
+
+Concurrency and resource ownership
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The framework does not serialize direct callers. Multiple CPUs may call
+the direct API on the same channel concurrently. This is deliberate: a
+per-channel framework lock would violate the concurrency contract and would
+still not protect controller-wide or per-CPU resources.
+
+The controller owns protection of everything its direct operation touches:
+
+* controller-wide registers and shared FIFOs;
+* per-channel state, which may live in ``chan->con_priv``;
+* per-CPU scratch memory and other per-CPU state;
+* resources shared with non-mailbox users of the same controller helpers.
+
+The controller may take its own lock to serialize, or may return ``-EBUSY``
+to a caller it cannot serve concurrently. It must not assume that the
+framework disabled IRQs for it.
+
+If the operation uses per-CPU state, it must also prevent same-CPU IRQ
+re-entry. ``local_irq_save()`` is the portable hardirq-safe choice.
+``local_lock_irqsave()`` gives lockdep coverage on non-RT kernels, but on
+PREEMPT_RT it maps to a per-CPU sleeping spinlock and must not be used from
+hardirq context. A per-CPU ``raw_spinlock_t`` taken with IRQs disabled is
+another option. A plain ``get_cpu()``/``put_cpu()`` pair only disables
+preemption and does not stop an IRQ on the same CPU from re-entering.
+
+Example: atomic-safe controller
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. code-block:: c
+
+ struct my_chan {
+ void __iomem *tx_reg;
+ spinlock_t lock; /* protects this controller's registers */
+ bool busy;
+ };
+
+ static int my_send_data_sync(struct mbox_chan *chan, void *data)
+ {
+ struct my_chan *c = chan->con_priv;
+ unsigned long flags;
+ u32 status;
+ int ret = 0;
+
+ /*
+ * The framework does not serialize direct callers and does not
+ * disable IRQs. This controller shares one register block across
+ * all CPUs, so it uses its own IRQ-safe lock.
+ */
+ spin_lock_irqsave(&c->lock, flags);
+ if (c->busy) {
+ ret = -EBUSY;
+ goto out;
+ }
+
+ c->busy = true;
+ writel(*(u32 *)data, c->tx_reg);
+ if (readl_poll_timeout_atomic(c->tx_reg + MY_STATUS, status,
+ status & MY_DONE, 1, 1000))
+ ret = -ETIMEDOUT;
+ c->busy = false;
+ out:
+ spin_unlock_irqrestore(&c->lock, flags);
+ return ret;
+ }
+
+ static const struct mbox_chan_ops my_ops = {
+ .send_data_sync = my_send_data_sync,
+ /* .send_data may be NULL if every channel is direct-only. */
+ };
+
+ static int my_probe(struct platform_device *pdev)
+ {
+ ...
+ for (i = 0; i < MY_NUM_CHANS; i++)
+ mbox->chans[i].sync_caps = MBOX_CHAN_CAP_SYNC_ATOMIC;
+ ...
+ return devm_mbox_controller_register(dev, &mbox->controller);
+ }
+
+Example: per-CPU shared-memory controller
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+A controller that hands a per-CPU buffer to firmware must guard the whole
+copy/firmware-call/copy sequence, not just the copy:
+
+.. code-block:: c
+
+ static int my_send_data_sync(struct mbox_chan *chan, void *data)
+ {
+ struct my_msg *msg = data;
+ int ret;
+
+ /*
+ * The firmware uses per-CPU scratch memory. A hardirq on this CPU
+ * could otherwise re-enter and clobber it between the copy and the
+ * firmware call.
+ */
+ guard(irqsave)();
+ memcpy(this_cpu_ptr(&my_buf)->data, msg->tx, msg->len);
+ ret = my_firmware_call(this_cpu_ptr(&my_buf)->phys, msg->len);
+ if (!ret)
+ memcpy(msg->rx, this_cpu_ptr(&my_buf)->data, msg->rx_len);
+ return ret;
+ }
+
+Every user of the per-CPU buffer must take the same guard. Attribute
+queries, notification fetches, MSI programming, and non-mailbox users that
+share the buffer are all part of the same critical section. Delivering RX
+through ``mbox_chan_received_data()`` while holding that guard can deadlock
+if the client sends from ``rx_callback``; release the guard first or use a
+separate RX lock.
+
Client Driver (See include/linux/mailbox_client.h)
==================================================
+The client might want to operate in one of three modes:
-The client might want to operate in blocking mode (synchronously
-send a message through before returning) or non-blocking/async mode (submit
-a message and a callback function to the API and return immediately).
+* non-blocking queued: submit a message and a callback, return immediately;
+* blocking queued: wait until the queued transfer completes or times out;
+* direct synchronous: call the controller operation and receive its result.
+
+The first two use ``mbox_send_message()`` and the queued state machine.
+The third uses ``mbox_send_message_sync()`` or
+``mbox_send_message_sync_sleepable()`` and must be used on a direct channel.
+
+Blocking and non-blocking queued modes
+--------------------------------------
::
@@ -82,12 +279,12 @@ a message and a callback function to the API and return immediately).
static void client_demo(struct platform_device *pdev)
{
- struct demo_client *dc_sync, *dc_async;
- /* The controller already knows async_pkt and sync_pkt */
+ struct demo_client *dc_blocking, *dc_async;
+ /* The controller already knows async_pkt and blocking_pkt */
struct async_pkt ap;
- struct sync_pkt sp;
+ struct blocking_pkt bp;
- dc_sync = kzalloc_obj(*dc_sync);
+ dc_blocking = kzalloc_obj(*dc_blocking);
dc_async = kzalloc_obj(*dc_async);
/* Populate non-blocking mode client */
@@ -101,13 +298,13 @@ a message and a callback function to the API and return immediately).
init_completion(&dc_async->c);
/* Populate blocking mode client */
- dc_sync->cl.dev = &pdev->dev;
- dc_sync->cl.rx_callback = message_from_remote;
- dc_sync->cl.tx_done = NULL; /* operate in blocking mode */
- dc_sync->cl.tx_block = true;
- dc_sync->cl.tx_tout = 500; /* by half a second */
- dc_sync->cl.knows_txdone = false; /* depending upon protocol */
- dc_sync->async = false;
+ dc_blocking->cl.dev = &pdev->dev;
+ dc_blocking->cl.rx_callback = message_from_remote;
+ dc_blocking->cl.tx_done = NULL; /* operate in blocking mode */
+ dc_blocking->cl.tx_block = true;
+ dc_blocking->cl.tx_tout = 500; /* by half a second */
+ dc_blocking->cl.knows_txdone = false; /* depending upon protocol */
+ dc_blocking->async = false;
/* ASync mailbox is listed second in 'mboxes' property */
dc_async->mbox = mbox_request_channel(&dc_async->cl, 1);
@@ -116,14 +313,125 @@ a message and a callback function to the API and return immediately).
/* Send async message to remote */
mbox_send_message(dc_async->mbox, &ap);
- /* Sync mailbox is listed first in 'mboxes' property */
- dc_sync->mbox = mbox_request_channel(&dc_sync->cl, 0);
+ /* Blocking mailbox is listed first in 'mboxes' property */
+ dc_blocking->mbox = mbox_request_channel(&dc_blocking->cl, 0);
/* Populate data packet */
- /* sp.abc = 123; etc */
+ /* bp.abc = 123; etc */
/* Send message to remote in blocking mode */
- mbox_send_message(dc_sync->mbox, &sp);
- /* At this point 'sp' has been sent */
+ mbox_send_message(dc_blocking->mbox, &bp);
+ /* At this point 'bp' has been sent */
/* Now wait for async chan to be done */
wait_for_completion(&dc_async->c);
}
+
+The documentation uses "blocking queued" rather than "sync" for
+``tx_block=true`` so that it is not confused with direct synchronous
+transmit. ``tx_block`` callers must serialize themselves on a channel.
+
+Direct synchronous mode
+-----------------------
+
+.. code-block:: c
+
+ int __must_check mbox_send_message_sync(struct mbox_chan *chan,
+ void *mssg);
+ int __must_check mbox_send_message_sync_sleepable(struct mbox_chan *chan,
+ void *mssg);
+
+``mbox_send_message_sync()``
+ Calls ``send_data_sync()``. It never sleeps and may be called from any
+ context in which the controller operation is safe, including hardirq.
+ It does not fall back to a sleepable operation.
+
+``mbox_send_message_sync_sleepable()``
+ Calls ``send_data_sync_sleepable()`` when the channel advertises it.
+ If only ``MBOX_CHAN_CAP_SYNC_ATOMIC`` is advertised, it calls the
+ stronger ``send_data_sync()`` instead. It calls ``might_sleep()`` and
+ may therefore be used only from sleepable context.
+
+Both functions return 0 on success, ``-EINVAL`` for invalid arguments,
+``-EOPNOTSUPP`` when the channel does not support the requested direct
+mode, or another negative errno from the controller. Positive values are
+not used by the direct API; controllers must return 0 or a negative errno.
+The declarations are ``__must_check`` because the per-call result is the
+whole point of the API.
+
+The caller must keep the message buffer valid until the call returns. The
+controller must not retain the pointer afterwards. The caller is also
+responsible for serializing the call against ``mbox_free_channel()`` and
+driver removal; the framework does not wait for or refcount in-flight direct
+calls. The ``chan->cl`` check in the wrapper is only a best-effort sanity
+check.
+
+The capability probe is the call itself: a client may attempt the direct
+API and handle ``-EOPNOTSUPP``. There is no capability query helper in the
+minimal API.
+
+Example:
+
+.. code-block:: c
+
+ ret = mbox_send_message_sync(client->chan, msg);
+ if (ret)
+ /* Handle the per-call error. */
+
+The direct path calls neither ``tx_prepare`` nor ``tx_done``. The client
+prepares its buffer before the call, and the return value is the completion
+notification. ``tx_block``, ``tx_tout``, and ``knows_txdone`` are ignored
+on a direct channel because ``mbox_send_message()`` and
+``mbox_client_txdone()`` are rejected there.
+
+Interaction with the existing API
+=================================
+
+The following table is normative for a direct channel
+(``sync_caps != 0``):
+
+.. list-table:: Interaction with the existing API on a direct channel
+ :header-rows: 1
+ :widths: 30 70
+
+ * - API / callback
+ - Behavior on a direct channel
+ * - ``mbox_send_message()``
+ - Returns ``-EOPNOTSUPP``. Mixing queued and direct paths would
+ reintroduce the single-request state machine.
+ * - ``mbox_flush()``
+ - Returns ``-EOPNOTSUPP``. There is no framework transmission to
+ flush.
+ * - ``tx_prepare``
+ - Never called. The client prepares its own buffer.
+ * - ``tx_done``
+ - Never called. The direct return value is the notification.
+ * - ``mbox_chan_txdone()``
+ - ``WARN_ON_ONCE()`` and no-op. The controller must return the result
+ from the direct operation.
+ * - ``mbox_client_txdone()``
+ - ``WARN_ON_ONCE()`` and no-op. Same reason.
+ * - ``mbox_chan_tx_slots_available()``
+ - Returns 0. A direct channel has no queue.
+ * - ``tx_block`` / ``tx_tout``
+ - Ignored. ``mbox_send_message()`` is rejected.
+ * - ``knows_txdone``
+ - Ignored. ``mbox_client_txdone()`` is rejected.
+ * - ``startup`` / ``shutdown``
+ - Unchanged. Called on bind/unbind and may sleep.
+ * - ``rx_callback`` / ``peek_data`` / ``mbox_chan_received_data()``
+ - Unchanged. Receive delivery is independent of the transmit mode.
+ * - ``mbox_free_channel()``
+ - Unchanged. The client must serialize it against in-flight direct
+ calls.
+ * - debugfs mailbox summary
+ - Unchanged; it only reports channel ownership.
+
+Debugging aids provided by the framework are
+``lockdep_assert_not_held(&chan->lock)`` in both direct wrappers,
+``might_sleep()`` in the sleepable wrapper, txdone misuse warnings, and
+registration-time capability validation. ``CONFIG_DEBUG_ATOMIC_SLEEP`` and
+``CONFIG_PROVE_LOCKING`` catch controller bugs that the framework cannot
+detect statically.
+
+The KUnit suite in ``drivers/mailbox/mailbox-sync-test.c`` exercises the
+capability matrix, registration validation, per-call results, multi-CPU
+concurrency, hardirq context, queued compatibility, and free/rebind.
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 5/5] mailbox: convert RISC-V SBI MPXY to direct transmit
2026-11-16 4:00 [PATCH v2 0/5] Parallel message send using SBI MPXY Anup Patel
` (3 preceding siblings ...)
2026-11-16 4:00 ` [PATCH v2 4/5] mailbox: document direct synchronous transmit Anup Patel
@ 2026-11-16 4:00 ` Anup Patel
4 siblings, 0 replies; 6+ messages in thread
From: Anup Patel @ 2026-11-16 4:00 UTC (permalink / raw)
To: Palmer Dabbelt, Paul Walmsley, Rahul Pathak, Stephen Boyd,
Brian Masney, Jerome Brunet, Thomas Gleixner, Radu Rendec,
Jassi Brar
Cc: Sunil V L, Himanshu Chauhan, Atish Patra, Anup Patel,
Amirreza Zarrabi, linux-riscv, linux-kernel, linux-clk,
Anup Patel
From: Jassi Brar <jassisinghbrar@gmail.com>
The MPXY controller completes RPMI requests synchronously in
the caller's context, and the RPMI clients currently use the
tx_block=false plus knows_txdone retrofit. That retrofit is
tied to the single active_req slot and reports the wrong result
when two CPUs send on the same channel.
Advertise MBOX_CHAN_CAP_SYNC_ATOMIC for RPMI MPXY channels,
implement send_data_sync() returning msg->error. Switch
rpmi_mbox_send_message() to mbox_send_message_sync() and
drop the mbox_client_txdone() side channel and the obsolete
client flags.
Co-developed-by: Anup Patel <anup.patel@oss.qualcomm.com>
Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>
---
drivers/clk/clk-rpmi.c | 3 --
drivers/irqchip/irq-riscv-rpmi-sysmsi.c | 3 --
drivers/mailbox/riscv-sbi-mpxy-mbox.c | 29 +++++++++++++++++--
.../pmdomain/riscv/riscv-rpmi-device-power.c | 3 --
include/linux/mailbox/riscv-rpmi-message.h | 17 ++++-------
5 files changed, 33 insertions(+), 22 deletions(-)
diff --git a/drivers/clk/clk-rpmi.c b/drivers/clk/clk-rpmi.c
index 40c11c373556..32af5b4e4dea 100644
--- a/drivers/clk/clk-rpmi.c
+++ b/drivers/clk/clk-rpmi.c
@@ -526,9 +526,6 @@ static int rpmi_clk_probe(struct platform_device *pdev)
context->client.dev = context->dev;
context->client.rx_callback = NULL;
- context->client.tx_block = false;
- context->client.knows_txdone = true;
- context->client.tx_tout = 0;
context->chan = mbox_request_channel(&context->client, 0);
if (IS_ERR(context->chan))
diff --git a/drivers/irqchip/irq-riscv-rpmi-sysmsi.c b/drivers/irqchip/irq-riscv-rpmi-sysmsi.c
index 7461d5339ddf..4e76303bd786 100644
--- a/drivers/irqchip/irq-riscv-rpmi-sysmsi.c
+++ b/drivers/irqchip/irq-riscv-rpmi-sysmsi.c
@@ -223,9 +223,6 @@ static int rpmi_sysmsi_probe(struct platform_device *pdev)
/* Setup mailbox client */
priv->client.dev = priv->dev;
priv->client.rx_callback = NULL;
- priv->client.tx_block = false;
- priv->client.knows_txdone = true;
- priv->client.tx_tout = 0;
/* Request mailbox channel */
priv->chan = mbox_request_channel(&priv->client, 0);
diff --git a/drivers/mailbox/riscv-sbi-mpxy-mbox.c b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
index 432972195e46..5134a88fa984 100644
--- a/drivers/mailbox/riscv-sbi-mpxy-mbox.c
+++ b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
@@ -234,6 +234,24 @@ static int mpxy_mbox_send_data(struct mbox_chan *chan, void *data)
return -EOPNOTSUPP;
}
+static int mpxy_mbox_send_data_sync(struct mbox_chan *chan, void *data)
+{
+ struct mpxy_mbox_channel *mchan = chan->con_priv;
+ struct rpmi_mbox_message *msg = data;
+
+ if (mchan->attrs.msg_proto_id != SBI_MPXY_MSGPROTO_RPMI_ID)
+ return -EOPNOTSUPP;
+ if (!msg)
+ return -EINVAL;
+
+ /*
+ * The MPXY helpers take the per-CPU shared-memory guard and complete
+ * the SBI call synchronously, so msg->error is this call's result.
+ */
+ mpxy_mbox_send_rpmi_data(mchan, msg);
+ return msg->error;
+}
+
static bool mpxy_mbox_peek_data(struct mbox_chan *chan)
{
struct mpxy_mbox_channel *mchan = chan->con_priv;
@@ -424,6 +442,7 @@ static void mpxy_mbox_shutdown(struct mbox_chan *chan)
static const struct mbox_chan_ops mpxy_mbox_ops = {
.send_data = mpxy_mbox_send_data,
+ .send_data_sync = mpxy_mbox_send_data_sync,
.peek_data = mpxy_mbox_peek_data,
.startup = mpxy_mbox_startup,
.shutdown = mpxy_mbox_shutdown,
@@ -586,8 +605,14 @@ static int mpxy_mbox_probe(struct platform_device *pdev)
mbox->channel_count);
if (!mbox->controller.chans)
return -ENOMEM;
- for (i = 0; i < mbox->channel_count; i++)
- mbox->controller.chans[i].con_priv = &mbox->channels[i];
+ for (i = 0; i < mbox->channel_count; i++) {
+ struct mbox_chan *chan = &mbox->controller.chans[i];
+ struct mpxy_mbox_channel *mchan = &mbox->channels[i];
+
+ chan->con_priv = mchan;
+ if (mchan->attrs.msg_proto_id == SBI_MPXY_MSGPROTO_RPMI_ID)
+ chan->sync_caps = MBOX_CHAN_CAP_SYNC_ATOMIC;
+ }
/* Setup MSIs for mailbox (if required) */
if (mbox->msi_count) {
diff --git a/drivers/pmdomain/riscv/riscv-rpmi-device-power.c b/drivers/pmdomain/riscv/riscv-rpmi-device-power.c
index 86b58ab29ca5..558e3dc0ef5e 100644
--- a/drivers/pmdomain/riscv/riscv-rpmi-device-power.c
+++ b/drivers/pmdomain/riscv/riscv-rpmi-device-power.c
@@ -347,9 +347,6 @@ static int rpmi_pm_domain_probe(struct platform_device *pdev)
/* Setup mailbox client */
mpxy_ctx->client.dev = dev;
mpxy_ctx->client.rx_callback = NULL;
- mpxy_ctx->client.tx_block = false;
- mpxy_ctx->client.knows_txdone = true;
- mpxy_ctx->client.tx_tout = 0;
/* Request mailbox channel */
mpxy_ctx->chan = mbox_request_channel(&mpxy_ctx->client, 0);
diff --git a/include/linux/mailbox/riscv-rpmi-message.h b/include/linux/mailbox/riscv-rpmi-message.h
index d5362b5821f9..be7c803292f2 100644
--- a/include/linux/mailbox/riscv-rpmi-message.h
+++ b/include/linux/mailbox/riscv-rpmi-message.h
@@ -238,17 +238,12 @@ static inline void *rpmi_mbox_get_msg_response(struct rpmi_mbox_message *msg)
static inline int rpmi_mbox_send_message(struct mbox_chan *chan,
struct rpmi_mbox_message *msg)
{
- int ret;
-
- /* Send message for the underlying mailbox channel */
- ret = mbox_send_message(chan, msg);
- if (ret < 0)
- return ret;
-
- /* Explicitly signal txdone for mailbox channel */
- ret = msg->error;
- mbox_client_txdone(chan, ret);
- return ret;
+ /*
+ * RPMI mailbox channels complete the request synchronously and return
+ * the per-call protocol result. Do not use the queued mailbox state
+ * machine or its txdone side channel.
+ */
+ return mbox_send_message_sync(chan, msg);
}
#endif /* _LINUX_RISCV_RPMI_MESSAGE_H_ */
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-16 4:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 4:00 [PATCH v2 0/5] Parallel message send using SBI MPXY Anup Patel
2026-11-16 4:00 ` [PATCH v2 1/5] RISC-V: Move common MPXY helper routines to arch/riscv Anup Patel
2026-11-16 4:00 ` [PATCH v2 2/5] RISC-V: Use irqsave to prevent interrupt when accessing MPXY shared memory Anup Patel
2026-11-16 4:00 ` [PATCH v2 3/5] mailbox: add direct synchronous transmit API Anup Patel
2026-11-16 4:00 ` [PATCH v2 4/5] mailbox: document direct synchronous transmit Anup Patel
2026-11-16 4:00 ` [PATCH v2 5/5] mailbox: convert RISC-V SBI MPXY to direct transmit Anup Patel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®