Multi-Channel Inter-Processor Mailbox (MBOX)

Overview

An MBOX device is a peripheral capable of passing signals (and data depending on the peripheral) between CPUs and clusters in the system. Each MBOX instance is providing one or more channels, each one targeting one other CPU cluster (multiple channels can target the same cluster).

API Reference

group mbox_interface

MBOX Interface.

                     CPU #1        |
+----------+                       |        +----------+
|          +---TX9----+   +--------+--RX8---+          |
|  dev A   |          |   |        |        |  CPU #2  |
|          <---RX8--+ |   | +------+--TX9--->          |
+----------+        | |   | |      |        +----------+
                 +--+-v---v-+--+   |
                 |             |   |
                 |   MBOX dev  |   |
                 |             |   |
                 +--+-^---^--+-+   |
+----------+        | |   |  |     |        +----------+
|          <---RX2--+ |   |  +-----+--TX3--->          |
|  dev B   |          |   |        |        |  CPU #3  |
|          +---TX3----+   +--------+--RX2---+          |
+----------+                       |        +----------+
                                   |
Since

1.0

Version

0.1.0

An MBOX device is a peripheral capable of passing signals (and data depending on the peripheral) between CPUs and clusters in the system. Each MBOX instance is providing one or more channels, each one targeting one other CPU cluster (multiple channels can target the same cluster).

For example in the plot the device ‘dev A’ is using the TX channel 9 to signal (or send data to) the CPU #2 and it’s expecting data or signals on the RX channel 8. Thus it can send the message through the channel 9, and it can register a callback on the channel 8 of the MBOX device.

This API supports two modes: signalling mode and data transfer mode.

In signalling mode:

In data transfer mode:

  • mbox_mtu_get() must return a (value != 0)

  • mbox_send() must have (msg != NULL)

  • the callback must be called with (data != NULL)

  • The msg content must be the same between sender and receiver

Defines

MBOX_DT_SPEC_GET(node_id, name)

Structure initializer for struct mbox_dt_spec from devicetree.

This helper macro expands to a static initializer for a struct mbox_dt_spec by reading the relevant device controller and channel number from the devicetree.

Example devicetree fragment:

n: node {
        mboxes = <&mbox1 8>,
                 <&mbox1 9>;
        mbox-names = "tx", "rx";
};

Example usage:

const struct mbox_dt_spec spec = MBOX_DT_SPEC_GET(DT_NODELABEL(n), tx);
Parameters:
  • node_id – Devicetree node identifier for the MBOX device

  • name – lowercase-and-underscores name of the mboxes element

Returns:

static initializer for a struct mbox_dt_spec

MBOX_DT_SPEC_INST_GET(inst, name)

Instance version of MBOX_DT_CHANNEL_GET()

Parameters:
  • inst – DT_DRV_COMPAT instance number

  • name – lowercase-and-underscores name of the mboxes element

Returns:

static initializer for a struct mbox_dt_spec

Typedefs

typedef uint32_t mbox_channel_id_t

Type for MBOX channel identifiers.

Functions

static inline bool mbox_is_ready_dt(const struct mbox_dt_spec *spec)

Validate if MBOX device instance from a struct mbox_dt_spec is ready.

Parameters:
  • spec – MBOX specification from devicetree

Returns:

See return values for mbox_send()

int mbox_send(const struct device *dev, mbox_channel_id_t channel_id, const struct mbox_msg *msg)

Try to send a message over the MBOX device.

Send a message over an struct mbox_channel. The msg parameter must be NULL when the driver is used for signalling.

If the msg parameter is not NULL, this data is expected to be delivered on the receiving side using the data parameter of the receiving callback.

Parameters:
  • dev – MBOX device instance

  • channel_id – MBOX channel identifier

  • msg – Message

Return values:
  • 0 – On success.

  • -EBUSY – If the remote hasn’t yet read the last data sent.

  • -EMSGSIZE – If the supplied data size is unsupported by the driver.

  • -EINVAL – If there was a bad parameter, such as: too-large channel descriptor or the device isn’t an outbound MBOX channel.

static inline int mbox_send_dt(const struct mbox_dt_spec *spec, const struct mbox_msg *msg)

Try to send a message over the MBOX device from a struct mbox_dt_spec.

Parameters:
  • spec – MBOX specification from devicetree

  • msg – Message

Returns:

See return values for mbox_send()

static inline int mbox_register_callback(const struct device *dev, mbox_channel_id_t channel_id, mbox_callback_t cb, void *user_data)

Register a callback function on a channel for incoming messages.

This function doesn’t assume anything concerning the status of the interrupts. Use mbox_set_enabled() to enable or to disable the interrupts if needed.

Parameters:
  • dev – MBOX device instance

  • channel_id – MBOX channel identifier

  • cb – Callback function to execute on incoming message interrupts.

  • user_data – Application-specific data pointer which will be passed to the callback function when executed.

Return values:
  • 0 – On success.

  • -errno – Negative errno on error.

static inline int mbox_register_callback_dt(const struct mbox_dt_spec *spec, mbox_callback_t cb, void *user_data)

Register a callback function on a channel for incoming messages from a struct mbox_dt_spec.

Parameters:
  • spec – MBOX specification from devicetree

  • cb – Callback function to execute on incoming message interrupts.

  • user_data – Application-specific data pointer which will be passed to the callback function when executed.

Returns:

See return values for mbox_register_callback()

int mbox_mtu_get(const struct device *dev)

Return the maximum number of bytes possible in an outbound message.

Returns the actual number of bytes that it is possible to send through an outgoing channel.

This number can be 0 when the driver only supports signalling or when on the receiving side the content and size of the message must be retrieved in an indirect way (i.e. probing some other peripheral, reading memory regions, etc…).

If this function returns 0, the msg parameter in mbox_send() is expected to be NULL.

Parameters:
  • dev – MBOX device instance.

Return values:
  • >0 – Maximum possible size of a message in bytes

  • 0 – Indicates signalling

  • -errno – Negative errno on error.

static inline int mbox_mtu_get_dt(const struct mbox_dt_spec *spec)

Return the maximum number of bytes possible in an outbound message from struct mbox_dt_spec.

Parameters:
  • spec – MBOX specification from devicetree

Returns:

See return values for mbox_register_callback()

int mbox_set_enabled(const struct device *dev, mbox_channel_id_t channel_id, bool enabled)

Enable (disable) interrupts and callbacks for inbound channels.

Enable interrupt for the channel when the parameter ‘enable’ is set to true. Disable it otherwise.

Immediately after calling this function with ‘enable’ set to true, the channel is considered enabled and ready to receive signal and messages (even already pending), so the user must take care of installing a proper callback (if needed) using mbox_register_callback() on the channel before enabling it. For this reason it is recommended that all the channels are disabled at probe time.

Enabling a channel for which there is no installed callback is considered undefined behavior (in general the driver must take care of gracefully handling spurious interrupts with no installed callback).

Parameters:
  • dev – MBOX device instance

  • channel_id – MBOX channel identifier

  • enabled – Enable (true) or disable (false) the channel.

Return values:
  • 0 – On success.

  • -EINVAL – If it isn’t an inbound channel.

  • -EALREADY – If channel is already enabled.

static inline int mbox_set_enabled_dt(const struct mbox_dt_spec *spec, bool enabled)

Enable (disable) interrupts and callbacks for inbound channels from a struct mbox_dt_spec.

Parameters:
  • spec – MBOX specification from devicetree

  • enabled – Enable (true) or disable (false) the channel.

Returns:

See return values for mbox_set_enabled()

uint32_t mbox_max_channels_get(const struct device *dev)

Return the maximum number of channels.

Return the maximum number of channels supported by the hardware.

Parameters:
  • dev – MBOX device instance.

Returns:

>0 Maximum possible number of supported channels on success

Returns:

-errno Negative errno on error.

static inline int mbox_max_channels_get_dt(const struct mbox_dt_spec *spec)

Return the maximum number of channels from a struct mbox_dt_spec.

Parameters:
  • spec – MBOX specification from devicetree

Returns:

See return values for mbox_max_channels_get()

struct mbox_msg
#include <mbox.h>

Message struct (to hold data and its size).

Public Members

const void *data

Pointer to the data sent in the message.

size_t size

Size of the data.

struct mbox_dt_spec
#include <mbox.h>

MBOX specification from DT.

Public Members

const struct device *dev

MBOX device pointer.

mbox_channel_id_t channel_id

Channel ID.