Skip to content

Mailbox framework - #8285

Draft
jamike wants to merge 7 commits into
OP-TEE:masterfrom
jamike:mailbox_framework
Draft

jamike wants to merge 7 commits into
OP-TEE:masterfrom
jamike:mailbox_framework

Conversation

@jamike

@jamike jamike commented Nov 19, 2026 •

Copy link
Copy Markdown

This series introduces a mailbox framework in OP-TEE core, allowing the secure world to exchange notifications with a remote processor over mailbox channels, together with its device-tree bindings and self-tests.

The framework mirrors the Linux mailbox model: mailbox controllers register as providers and consumers resolve their channels either from the device tree ( mboxes / #mbox-cells ) or programmatically. It supports synchronous send/receive, per-channel.

For the mailbox test execution takes OP-TEE/optee_test#859

The framework enables OPTEE exchange with a remote processor based on
mailbox channel notification. The framework provide mailbox device
registering services and user service for channel exchange with remote
processor.

A channel is granted to a single consumer at a time: requesting a
channel already granted returns TEE_ERROR_BUSY until it is released.

Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
Add DT_DRIVER_MAILBOX to the device tree driver types so that mailbox
controllers can register as device providers and mailbox consumers can
resolve their channels from the "mboxes" device tree property.

The number of cells of a mailbox specifier is described by the
"#mbox-cells" property of the provider node.

Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
Add the mailbox device tree services, built when CFG_DT is enabled
(stubs returning TEE_ERROR_NOT_SUPPORTED otherwise):
- mbox_dt_register_controller() registers a controller as a
  DT_DRIVER_MAILBOX provider; the cells of the consumer "mboxes"
  specifier are given to the controller request_channel operation.
- mbox_dt_request_channel_by_index() gets a channel from the "mboxes"
  property.
- mbox_dt_request_channel_by_name() gets a channel from its name in the
  "mbox-names" property.

Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
Register the TI SCI transport as a mailbox controller and drop the
dedicated transport initialization from main.c.

Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
Implement the Versal IPI as a mailbox controller and route
versal_mbox calls through the mailbox framework.

Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
A virtual driver mailbox is used to test mailbox framework.
The test are launched by PTA commands.

A virtual mailbox flavor whose recv_sync() waits for a message using
an asynchronous notification is also provided, with two PTA commands to
be invoked concurrently: one blocks in mbox_recv_sync() while the other
sends the message. The commands return TEE_ERROR_NOT_SUPPORTED when
CFG_CORE_ASYNC_NOTIF is disabled.

Change-Id: I38015bf7686c46137db3e2d4f9b8d1a849d34fe5
Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
The device tree interface of the mailbox framework was not covered by
any test. mbox_dt_register_controller() on the provider side, and both
mbox_dt_request_channel_by_index() and mbox_dt_request_channel_by_name()
on the consumer side, could only be exercised on a platform embedding a
real mailbox controller.

Add an emulated mailbox provider to the device tree test device. It is
declared on the "linaro,dt-test-provider" compatible, hence it is also
covered by the existing probe deferral test. Its channels can send but
cannot receive.

Add probe_test_mbox() to the test consumer probe. It resolves the two
channels by index, checks that a channel already granted cannot be
requested again by name, then that once released it is granted again
with the same reference. It sends a message on a channel and checks that
reception is reported as not supported. It also checks that an out of range index and
an unknown name are both rejected.

The outcome is reported by the existing DT driver test command, so no
new test identifier is needed.

Enable CFG_DRIVERS_MAILBOX together with CFG_DT_DRIVER_EMBEDDED_TEST so
that these tests are embedded along with the other DT driver tests.

Assisted-by: GitHub-Copilot:Claude Opus 5.5
Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
@github-actions

Copy link
Copy Markdown

FYI @glneo

@thariaruchamy-bit

Copy link
Copy Markdown
Contributor

@jamike We've reviewed #8285 against our Qualcomm TME-Lite mailbox stack (QMP-Lite transport and its client) (#7956) and we are looking to pick your generic mailbox changes instead of having QCOM specific mbox changes

What is the planned timeline for merging #8285?

Once your changes are accomodated, our PRs (#7956, #8282, #8274) will depend on #8285

@jamike

jamike commented Nov 20, 2026

Copy link
Copy Markdown
Author

On my side , the planning is as soon as possible till all the "possible" mailbox framework users provide their feedback. Especially for the review / test for plat-k3 and versal and also the usage in #8120 . @qc-azarrabi and @ldts can you help on this review / test ?


ops = chan->controller->desc->ops;
if (ops->free_channel)
ops->free_channel(chan);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mbox_free_channel() clears requested and drops the lock before it calls free_channel(). A concurrent mbox_request_channel() on a static channel can be granted inside that window. The previous owner's teardown then runs on the channel the new owner just received. Is concurrent request/free meant to be supported? If it is, the channel should stay granted until the op returns. The Versal driver frees the channel inside the op, so that case needs some thought. If it isn't, the spinlock and this ordering could be documented as single-consumer.

* @retval: TEE_ERROR_BAD_PARAMETERS If there was a bad parameter.
* @retval: TEE_ERROR_ITEM_NOT_FOUND If @index does not exist.
* @retval: TEE_ERROR_DEFER_DRIVER_INIT If the controller is not yet probed.
* @retval: TEE_ERROR_BUSY If the channel is already granted.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The channel stays granted until mbox_free_channel(), but a DT consumer probe is re-run when it returns TEE_ERROR_DEFER_DRIVER_INIT. A probe that gets a channel and then defers (on a clock, a regulator, a second channel...) without freeing it gets TEE_ERROR_BUSY on the retry. That puts the driver on the failed list, and probe_dt_drivers() panics. This is easy to get wrong in a real driver. Could the DT getters be idempotent for the same consumer node? At minimum, could the doc say that a probe must mbox_free_channel() every channel it holds before returning an error or DEFER?

@GseoC GseoC Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the driver's responsibility to handle the resources it got if it takes a TEE_ERROR_DEFER_DRIVER_INIT path.

The thing is the channel isn't really "requested", it's rather "acquired". So I'd rather rename the field in the channel structure and the function names at minimum

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop the Assisted-by tag as its no more a valid tag supported by latest checkpatch/CI?

Comment thread core/pta/tests/invoke.c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change-Id from this commit can be dropped

@maroueneboubakri

Copy link
Copy Markdown
Contributor

@jamike Are you still collecting feedback on this RFC, or are you planning to open the PR soon?

@jamike

jamike commented Nov 26, 2026

Copy link
Copy Markdown
Author

@jamike Are you still collecting feedback on this RFC, or are you planning to open the PR soon?

Actually , it 's a draft PR, I planned to set as release PR. I collect all the feedback /review comment on this PR.

@ldts

ldts commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

from my end and now with a user, happy to move it along - will validate your versal changes

@GseoC

GseoC commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

@jamike, please open the PR with above comments addressed. #7956 also uses the framework. We can use the P-R to collect feedback from the different platform maintainers

Comment thread core/drivers/versal_ipi.c
remote < VERSAL_IPI_ID_PMC || remote > VERSAL_IPI_ID_5)
return TEE_ERROR_BAD_PARAMETERS;

ipi = calloc(1, sizeof(*ipi));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on every call we are allocating a new structure. Since we are now part of a runtime framework, shouldn't we make sure that two requests for the same local/remote ipi can not succeed

Comment thread core/drivers/versal_ipi.c
{
TEE_Result res = TEE_SUCCESS;

if (!versal_controller) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a lock for future use cases?

#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <tee/cache.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can now drop <tee/cache.h from here>

Comment thread core/drivers/versal_ipi.c
#define IPI_TRIG_OFFSET 0x00
#define IPI_OBR_OFFSET 0x04
#define IPI_ISR_OFFSET 0x10
#define IPI_IMR_OFFSET 0x14

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can drop the unused macros while we are at it

Comment thread core/drivers/versal_ipi.c
}

static const struct mbox_controller_ops versal_mbox_ops = {
.request_channel = versal_mbox_request_channel,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these functions should be renamed as versal_ipi_request_channel, versal_ipi_free_channel and versal_ipi_send_sync I think

@thariaruchamy-bit

Copy link
Copy Markdown
Contributor

@GseoC @ldts @b49020 @zelvam95 @jamike
Ran the #8285 mailbox self tests on ipq52xx (Hermosa, LM profile): upstream TOT + #8285 + the #7956 commits, CFG_TEE_CORE_EMBED_INTERNAL_TESTS=y, test PTA called once at boot. Result: 16 test(s) run, 0 failed (register 3, channel 6, sync 7)

Feel free to add my tested by tag <Tested-by: Harikrishna hart@qti.qualcomm.com (IPQ52xx)>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants