Skip to content

Commit 93a6f69

Browse files
glneommahadevan108
authored andcommitted
drivers: ipm: Add IPM over MBOX driver
The Multi-Channel Inter-Processor Mailbox (MBOX) framework can be seen as a more general version of the Inter-Processor Mailbox (IPM) framework. An MBOX driver provides for multiple channels, where IPM provides for only a single channel of communication. Currently many applications are written to use IPM, while some are now being written to use MBOX. This means if a platform wants to support both types of apps a given it must have a driver for both frameworks. As MBOX is the newer and more generic framework, new drivers are being added for this framework only and older IPM drivers are being migrated to MBOX. This leads to the situation where applications need to be written twice, once for each framework, to run across all platforms. The solution is to add a gasket driver that exposes the IPM interface while using a MBOX driver in the back-end. This shim driver allows platforms to only need an MBOX driver to support both types of application. This IPM driver can be used when an application only supports IPM but the platform only supports MBOX. This will allow platforms and applications to be ported over to MBOX independently of each other. Add this driver here. Signed-off-by: Andrew Davis <[email protected]>
1 parent 417a9e8 commit 93a6f69

File tree

4 files changed

+142
-0
lines changed

4 files changed

+142
-0
lines changed

drivers/ipm/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ zephyr_library_sources_ifdef(CONFIG_IPM_SEDI ipm_sedi.c)
1515
zephyr_library_sources_ifdef(CONFIG_IPM_IVSHMEM ipm_ivshmem.c)
1616
zephyr_library_sources_ifdef(CONFIG_ESP32_SOFT_IPM ipm_esp32.c)
1717
zephyr_library_sources_ifdef(CONFIG_XLNX_IPI ipm_xlnx_ipi.c)
18+
zephyr_library_sources_ifdef(CONFIG_IPM_MBOX ipm_mbox.c)
1819

1920
zephyr_library_sources_ifdef(CONFIG_USERSPACE ipm_handlers.c)

drivers/ipm/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ config XLNX_IPI
5555
Inter Processor Interrupt driver for AMD-Xilinx
5656
platforms such as ZynqMP Ultrascale+.
5757

58+
config IPM_MBOX
59+
bool "IPM over MBOX driver"
60+
default y
61+
depends on DT_HAS_ZEPHYR_MBOX_IPM_ENABLED
62+
depends on MBOX
63+
help
64+
IPM driver using a MBOX driver as the backend mechanism.
65+
5866
source "drivers/ipm/Kconfig.nrfx"
5967
source "drivers/ipm/Kconfig.imx"
6068
source "drivers/ipm/Kconfig.stm32"

drivers/ipm/ipm_mbox.c

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright (c) 2024 Texas Instruments Incorporated
3+
* Andrew Davis <[email protected]>
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#define DT_DRV_COMPAT zephyr_mbox_ipm
9+
10+
#include <zephyr/kernel.h>
11+
#include <zephyr/device.h>
12+
#include <zephyr/drivers/ipm.h>
13+
#include <zephyr/drivers/mbox.h>
14+
15+
#include <zephyr/logging/log.h>
16+
LOG_MODULE_REGISTER(ipm_mbox, CONFIG_IPM_LOG_LEVEL);
17+
18+
struct ipm_mbox_data {
19+
ipm_callback_t callback;
20+
void *user_data;
21+
};
22+
23+
struct ipm_mbox_config {
24+
struct mbox_dt_spec mbox_tx;
25+
struct mbox_dt_spec mbox_rx;
26+
};
27+
28+
static void ipm_mbox_callback(const struct device *mboxdev, mbox_channel_id_t channel_id,
29+
void *user_data, struct mbox_msg *data)
30+
{
31+
const struct device *ipmdev = user_data;
32+
struct ipm_mbox_data *ipm_mbox_data = ipmdev->data;
33+
34+
ipm_mbox_data->callback(ipmdev, ipm_mbox_data->user_data, channel_id, (void *)data->data);
35+
}
36+
37+
static int ipm_mbox_send(const struct device *ipmdev, int wait, uint32_t id,
38+
const void *data, int size)
39+
{
40+
const struct ipm_mbox_config *config = ipmdev->config;
41+
42+
struct mbox_msg message = {
43+
.data = data,
44+
.size = size,
45+
};
46+
47+
return mbox_send_dt(&config->mbox_tx, &message);
48+
}
49+
50+
static void ipm_mbox_register_callback(const struct device *ipmdev,
51+
ipm_callback_t cb,
52+
void *user_data)
53+
{
54+
struct ipm_mbox_data *data = ipmdev->data;
55+
56+
data->callback = cb;
57+
data->user_data = user_data;
58+
}
59+
60+
static int ipm_mbox_get_max_data_size(const struct device *ipmdev)
61+
{
62+
const struct ipm_mbox_config *config = ipmdev->config;
63+
64+
return mbox_mtu_get_dt(&config->mbox_tx);
65+
}
66+
67+
static uint32_t ipm_mbox_get_max_id(const struct device *ipmdev)
68+
{
69+
const struct ipm_mbox_config *config = ipmdev->config;
70+
71+
return mbox_max_channels_get_dt(&config->mbox_tx);
72+
}
73+
74+
static int ipm_mbox_set_enable(const struct device *ipmdev, int enable)
75+
{
76+
const struct ipm_mbox_config *config = ipmdev->config;
77+
78+
mbox_set_enabled_dt(&config->mbox_rx, enable);
79+
80+
return 0;
81+
}
82+
83+
static int ipm_mbox_init(const struct device *ipmdev)
84+
{
85+
const struct ipm_mbox_config *config = ipmdev->config;
86+
87+
mbox_register_callback_dt(&config->mbox_rx, ipm_mbox_callback, (void *)ipmdev);
88+
89+
return 0;
90+
}
91+
92+
static const struct ipm_driver_api ipm_mbox_funcs = {
93+
.send = ipm_mbox_send,
94+
.register_callback = ipm_mbox_register_callback,
95+
.max_data_size_get = ipm_mbox_get_max_data_size,
96+
.max_id_val_get = ipm_mbox_get_max_id,
97+
.set_enabled = ipm_mbox_set_enable,
98+
};
99+
100+
#define IPM_MBOX_DEV_DEFINE(n) \
101+
static struct ipm_mbox_data ipm_mbox_data_##n; \
102+
static const struct ipm_mbox_config ipm_mbox_config_##n = { \
103+
.mbox_tx = MBOX_DT_SPEC_INST_GET(n, tx), \
104+
.mbox_rx = MBOX_DT_SPEC_INST_GET(n, rx), \
105+
}; \
106+
DEVICE_DT_INST_DEFINE(n, \
107+
&ipm_mbox_init, \
108+
NULL, \
109+
&ipm_mbox_data_##n, \
110+
&ipm_mbox_config_##n, \
111+
POST_KERNEL, \
112+
0, \
113+
&ipm_mbox_funcs);
114+
115+
DT_INST_FOREACH_STATUS_OKAY(IPM_MBOX_DEV_DEFINE)

dts/bindings/ipm/zephyr,mbox-ipm.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2024 Texas Instruments Incorporated
2+
# Andrew Davis <[email protected]>
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
description: Inter-Processor-Message to Mailbox adaptor driver
6+
7+
compatible: "zephyr,mbox-ipm"
8+
9+
include: base.yaml
10+
11+
properties:
12+
mboxes:
13+
description: phandle to the MBOX controller (TX and RX are required)
14+
required: true
15+
16+
mbox-names:
17+
description: MBOX channel names (must be called "tx" and "rx")
18+
required: true

0 commit comments

Comments
 (0)