Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: marouene.boubakri@oss.nxp.com
To: Jens Wiklander <jens.wiklander@linaro.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Jassi Brar <jassisinghbrar@gmail.com>,
	Jonathan Corbet <corbet@lwn.net>
Cc: Sumit Garg <sumit.garg@linaro.org>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	op-tee@lists.trustedfirmware.org, linux-doc@vger.kernel.org,
	linux-riscv@lists.infradead.org,
	Marouene Boubakri <marouene.boubakri@oss.nxp.com>
Subject: [RFC PATCH v1 1/6] mailbox: riscv-sbi-mpxy: add riscv_sbi_mpxy_mbox_call() for hart-local requests
Date: Thu, 10 Sep 2026 03:20:52 +0200	[thread overview]
Message-ID: <20260910012057.106966-2-marouene.boubakri@oss.nxp.com> (raw)
In-Reply-To: <20260910012057.106966-1-marouene.boubakri@oss.nxp.com>

From: Marouene Boubakri <marouene.boubakri@oss.nxp.com>

An SBI MPXY message send is not queued in a hardware mailbox: it is an
ecall executed on the calling hart with the calling hart's shared memory
which returns once the SBI implementation has processed the message.
For most RPMI service groups that means forwarding the message to a
platform microcontroller, which takes a bounded time. Some message
protocols are instead processed on the calling hart itself, for example
when the SBI implementation forwards the message to another supervisor
domain and switches the hart to it until it responds (this is the model
of the TEE service group of RPMI v2.0, where TEE_CALL runs the target
TEE on the hart of the caller). Such processing is unbounded and
depends on interrupts reaching the other domain so that it can yield.

Sending such messages through mbox_send_message() is not an option: the
mailbox core calls the controller send_data() callback from msg_submit()
with the channel spinlock held and interrupts disabled. Every hart would
then serialize on a single spinlock, spinning with interrupts disabled
for the whole duration of a message processed on another hart, while
the calling hart would run the other domain with the channel lock held.

Add riscv_sbi_mpxy_mbox_call() which performs the RPMI transfer directly
in the calling context, bypassing the mailbox core queue and channel
lock. The channel must still be requested through the mailbox core so
that its ownership is tracked. Local interrupts are disabled around the
ecall since the per-hart shared memory is also used from hard interrupt
context by mbox_send_message() users such as the RPMI system MSI
irqchip; calls from different harts proceed in parallel because each
hart has its own shared memory.

Signed-off-by: Marouene Boubakri <marouene.boubakri@oss.nxp.com>
---
 MAINTAINERS                                 |  1 +
 drivers/mailbox/riscv-sbi-mpxy-mbox.c       | 60 +++++++++++++++++++++
 include/linux/mailbox/riscv-sbi-mpxy-mbox.h | 23 ++++++++
 3 files changed, 84 insertions(+)
 create mode 100644 include/linux/mailbox/riscv-sbi-mpxy-mbox.h

diff --git a/MAINTAINERS b/MAINTAINERS
index c392ded53..44860f991 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -23581,6 +23581,7 @@ F:	drivers/clk/clk-rpmi.c
 F:	drivers/irqchip/irq-riscv-rpmi-sysmsi.c
 F:	drivers/mailbox/riscv-sbi-mpxy-mbox.c
 F:	include/linux/mailbox/riscv-rpmi-message.h
+F:	include/linux/mailbox/riscv-sbi-mpxy-mbox.h
 
 RISC-V SPACEMIT SoC Support
 M:	Yixun Lan <dlan@kernel.org>
diff --git a/drivers/mailbox/riscv-sbi-mpxy-mbox.c b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
index ea69c6b6b..2c80e6fd1 100644
--- a/drivers/mailbox/riscv-sbi-mpxy-mbox.c
+++ b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
@@ -12,6 +12,7 @@
 #include <linux/irqchip/riscv-imsic.h>
 #include <linux/mailbox_controller.h>
 #include <linux/mailbox/riscv-rpmi-message.h>
+#include <linux/mailbox/riscv-sbi-mpxy-mbox.h>
 #include <linux/minmax.h>
 #include <linux/mm.h>
 #include <linux/module.h>
@@ -719,6 +720,65 @@ static const struct mbox_chan_ops mpxy_mbox_ops = {
 	.shutdown = mpxy_mbox_shutdown,
 };
 
+/**
+ * riscv_sbi_mpxy_mbox_call() - Send an RPMI message directly on an MPXY channel
+ * @chan: SBI MPXY mailbox channel owned by the caller
+ * @msg: RPMI message of type RPMI_MBOX_MSG_TYPE_SEND_WITH_RESPONSE or
+ *       RPMI_MBOX_MSG_TYPE_SEND_WITHOUT_RESPONSE
+ *
+ * An SBI MPXY message send is not queued anywhere: it is an ecall executed
+ * on the calling hart, using the calling hart's shared memory, which only
+ * returns once the SBI implementation has processed the message. For some
+ * message protocols that processing is unbounded because it runs on the
+ * calling hart itself, for example when the SBI implementation forwards
+ * the message to another supervisor domain and switches the hart to it
+ * until it responds (the RPMI TEE service group's TEE_CALL does this).
+ *
+ * Such messages must not go through mbox_send_message(): the mailbox core
+ * invokes the controller send_data() callback with the channel spinlock
+ * held and interrupts disabled, which would serialize all harts on a single
+ * lock and keep interrupts disabled on the calling hart for the whole
+ * duration of the call.
+ *
+ * This helper bypasses the mailbox core queue and channel lock and performs
+ * the transfer directly in the calling context. Only local interrupts are
+ * disabled around the ecall, because the per-hart shared memory can be used
+ * from hard interrupt context through mbox_send_message() by other clients.
+ * Calls from different harts run concurrently since each hart has its own
+ * shared memory.
+ *
+ * The caller must own @chan through mbox_request_channel() (or a variant of
+ * it) so that no other client can use the channel, and must not use
+ * mbox_send_message() on it concurrently.
+ *
+ * Return: 0 on success or a negative error code.
+ */
+int riscv_sbi_mpxy_mbox_call(struct mbox_chan *chan,
+			     struct rpmi_mbox_message *msg)
+{
+	struct mpxy_mbox_channel *mchan;
+	unsigned long flags;
+
+	if (!chan || !chan->cl || !chan->mbox || !msg)
+		return -EINVAL;
+	if (chan->mbox->ops != &mpxy_mbox_ops)
+		return -EINVAL;
+	if (msg->type != RPMI_MBOX_MSG_TYPE_SEND_WITH_RESPONSE &&
+	    msg->type != RPMI_MBOX_MSG_TYPE_SEND_WITHOUT_RESPONSE)
+		return -EINVAL;
+
+	mchan = chan->con_priv;
+	if (mchan->attrs.msg_proto_id != SBI_MPXY_MSGPROTO_RPMI_ID)
+		return -EOPNOTSUPP;
+
+	local_irq_save(flags);
+	mpxy_mbox_send_rpmi_data(mchan, msg);
+	local_irq_restore(flags);
+
+	return msg->error;
+}
+EXPORT_SYMBOL_GPL(riscv_sbi_mpxy_mbox_call);
+
 /* ====== MPXY platform driver ===== */
 
 static void mpxy_mbox_msi_write(struct msi_desc *desc, struct msi_msg *msg)
diff --git a/include/linux/mailbox/riscv-sbi-mpxy-mbox.h b/include/linux/mailbox/riscv-sbi-mpxy-mbox.h
new file mode 100644
index 000000000..4fb7b04cd
--- /dev/null
+++ b/include/linux/mailbox/riscv-sbi-mpxy-mbox.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright 2026 NXP */
+
+#ifndef _LINUX_RISCV_SBI_MPXY_MBOX_H_
+#define _LINUX_RISCV_SBI_MPXY_MBOX_H_
+
+#include <linux/errno.h>
+
+struct mbox_chan;
+struct rpmi_mbox_message;
+
+#if IS_ENABLED(CONFIG_RISCV_SBI_MPXY_MBOX)
+int riscv_sbi_mpxy_mbox_call(struct mbox_chan *chan,
+			     struct rpmi_mbox_message *msg);
+#else
+static inline int riscv_sbi_mpxy_mbox_call(struct mbox_chan *chan,
+					   struct rpmi_mbox_message *msg)
+{
+	return -ENODEV;
+}
+#endif
+
+#endif /* _LINUX_RISCV_SBI_MPXY_MBOX_H_ */
-- 
2.43.0


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2026-09-10  1:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10  1:20 [RFC PATCH v1 0/6] tee: optee: RISC-V support over the RPMI TEE service group marouene.boubakri
2026-09-10  1:20 ` marouene.boubakri [this message]
2026-09-10  1:20 ` [RFC PATCH v1 2/6] tee: optee: select the SMC ABI conduit from the firmware node match data marouene.boubakri
2026-09-10  1:20 ` [RFC PATCH v1 3/6] tee: optee: teach the memory type check about RISC-V page attributes marouene.boubakri
2026-09-10  1:20 ` [RFC PATCH v1 4/6] mailbox: riscv-rpmi-message: add TEE service group definitions marouene.boubakri
2026-09-10  1:20 ` [RFC PATCH v1 5/6] dt-bindings: firmware: add OP-TEE over the RISC-V RPMI TEE service group marouene.boubakri
2026-09-10  1:20 ` [RFC PATCH v1 6/6] tee: optee: add a RISC-V conduit over the " marouene.boubakri

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=20260910012057.106966-2-marouene.boubakri@oss.nxp.com \
    --to=marouene.boubakri@oss.nxp.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=jassisinghbrar@gmail.com \
    --cc=jens.wiklander@linaro.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=robh@kernel.org \
    --cc=sumit.garg@linaro.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