Skip to content

Commit 6e46581

Browse files
committed
[nrf fromlist] soc: nordic: Add support for IRONside calls
Upstream PR #: 88937 IRONside calls are remote procedure calls which comprise the runtime interface of Nordic IRONside SE. They are realized using a simple IPC mechanism. A local domain (client) issues requests to the server by exchanging data in shared memory, which is divided into evenly sized buffers. The client selects a buffer, writes a request into it, and sends it to the server. The server processes that request and writes a response into the same buffer before returning it to the client. This patch adds the initial client-side implementation on top of MBOX. It features cache management and a blocking alloc/dispatch/release API for synchronous, zero-copy transfers. A new devicetree binding is added to support this implementation. It is patterned after the `zephyr,ipc-*` bindings, where each node associates a pair of mailboxes and a shared memory region. Signed-off-by: Grzegorz Swiderski <[email protected]> (cherry picked from commit 53c8dc9775b148f07f427b8e24f71da3a7c97bdb)
1 parent 87432d9 commit 6e46581

File tree

7 files changed

+253
-0
lines changed

7 files changed

+253
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: IPC configuration for Nordic IRONside calls
5+
6+
compatible: "nordic,ipc-ironside"
7+
8+
include: base.yaml
9+
10+
properties:
11+
memory-region:
12+
type: phandle
13+
required: true
14+
description: phandle to shared memory region
15+
16+
mboxes:
17+
required: true
18+
description: MBOX channel specifiers (TX and RX are required)
19+
20+
mbox-names:
21+
required: true
22+
description: MBOX channel names (must be called "tx" and "rx")

soc/nordic/common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
add_subdirectory_ifdef(CONFIG_RISCV_CORE_NORDIC_VPR vpr)
5+
add_subdirectory_ifdef(CONFIG_SOC_NRF54H20_IRON ironside)
56

67
if(CONFIG_ARM)
78
# Let SystemInit() be called in place of soc_reset_hook() by default.
@@ -26,6 +27,7 @@ if((CONFIG_SOC_SERIES_NRF54HX OR CONFIG_SOC_SERIES_NRF92X) AND CONFIG_CPU_HAS_CU
2627
endif()
2728

2829
zephyr_include_directories(.)
30+
zephyr_include_directories(include)
2931

3032
if(CONFIG_HAS_NORDIC_DMM)
3133
zephyr_library_sources(dmm.c)

soc/nordic/common/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ source "subsys/logging/Kconfig.template.log_config"
4949
endif # MRAM_LATENCY
5050

5151
rsource "vpr/Kconfig"
52+
rsource "ironside/Kconfig"
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef ZEPHYR_SOC_NORDIC_COMMON_INCLUDE_NRF_IRONSIDE_SE_CALL_H_
7+
#define ZEPHYR_SOC_NORDIC_COMMON_INCLUDE_NRF_IRONSIDE_SE_CALL_H_
8+
9+
#include <stdint.h>
10+
11+
/** @brief Maximum number of arguments to an IRONside call.
12+
*
13+
* This is chosen so that the containing message buffer size is minimal but
14+
* cache line aligned.
15+
*/
16+
#define NRF_IRONSIDE_CALL_NUM_ARGS 7
17+
18+
/** @brief Message buffer. */
19+
struct ironside_call_buf {
20+
/** See enum ironside_call_status. */
21+
uint16_t status;
22+
/** Operation identifier. */
23+
uint16_t id;
24+
/** Arguments to the given operation. */
25+
uint32_t args[NRF_IRONSIDE_CALL_NUM_ARGS];
26+
};
27+
28+
/** @brief Status code of a message buffer. */
29+
enum ironside_call_status {
30+
/** Buffer is idle and available for allocation. */
31+
IRONSIDE_CALL_STATUS_IDLE,
32+
/** Request was processed successfully by the server. */
33+
IRONSIDE_CALL_STATUS_RSP_SUCCESS,
34+
/** Request status code is unknown. */
35+
IRONSIDE_CALL_STATUS_RSP_ERR_UNKNOWN_STATUS,
36+
/** Request status code is no longer supported. */
37+
IRONSIDE_CALL_STATUS_RSP_ERR_EXPIRED_STATUS,
38+
/** Operation identifier is unknown. */
39+
IRONSIDE_CALL_STATUS_RSP_ERR_UNKNOWN_ID,
40+
/** Operation identifier is no longer supported. */
41+
IRONSIDE_CALL_STATUS_RSP_ERR_EXPIRED_ID,
42+
/** Buffer contains a request from the client. */
43+
IRONSIDE_CALL_STATUS_REQ,
44+
};
45+
46+
/**
47+
* @brief Allocate memory for an IRONside call.
48+
*
49+
* This function may block when no buffers are available, until one is released.
50+
*
51+
* @return Pointer to the allocated buffer.
52+
*/
53+
struct ironside_call_buf *ironside_call_alloc(void);
54+
55+
/**
56+
* @brief Dispatch an IRONside call.
57+
*
58+
* This function will block until a response is received.
59+
*
60+
* @param buf Buffer returned by ironside_call_alloc(). It should be populated
61+
* with request data before calling this function. Upon returning,
62+
* this data will have been replaced by response data.
63+
*/
64+
void ironside_call_dispatch(struct ironside_call_buf *buf);
65+
66+
/**
67+
* @brief Release an IRONside call buffer.
68+
*
69+
* This function must be called after processing the response.
70+
*
71+
* @param buf Buffer used to perform the call.
72+
*/
73+
void ironside_call_release(struct ironside_call_buf *buf);
74+
75+
#endif /* ZEPHYR_SOC_NORDIC_COMMON_INCLUDE_NRF_IRONSIDE_SE_CALL_H_ */
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
zephyr_include_directories(include)
5+
6+
zephyr_library_sources_ifdef(CONFIG_NRF_IRONSIDE_CALL call.c)

soc/nordic/common/ironside/Kconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config NRF_IRONSIDE_CALL
5+
bool
6+
depends on DT_HAS_NORDIC_IPC_IRONSIDE_ENABLED
7+
depends on SOC_NRF54H20_IRON
8+
select EVENTS
9+
select MBOX
10+
help
11+
This is selected by features that require support for IRONside calls.
12+
13+
if NRF_IRONSIDE_CALL
14+
15+
config NRF_IRONSIDE_CALL_INIT_PRIORITY
16+
int "IRONside calls' initialization priority"
17+
default 47
18+
19+
endif # NRF_IRONSIDE_CALL

soc/nordic/common/ironside/call.c

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <nrf/ironside/call.h>
7+
#include <zephyr/cache.h>
8+
#include <zephyr/device.h>
9+
#include <zephyr/drivers/mbox.h>
10+
#include <zephyr/kernel.h>
11+
#include <zephyr/sys/barrier.h>
12+
#include <zephyr/sys/math_extras.h>
13+
#include <zephyr/sys/util.h>
14+
15+
#define DT_DRV_COMPAT nordic_ipc_ironside
16+
17+
#define SHM_NODE DT_INST_PHANDLE(0, memory_region)
18+
#define NUM_BUFS (DT_REG_SIZE(SHM_NODE) / sizeof(struct ironside_call_buf))
19+
#define ALL_BUF_BITS BIT_MASK(NUM_BUFS)
20+
21+
/* Note: this area is already zero-initialized at reset time. */
22+
static struct ironside_call_buf *const bufs = (void *)DT_REG_ADDR(SHM_NODE);
23+
24+
#if defined(CONFIG_DCACHE_LINE_SIZE)
25+
BUILD_ASSERT((DT_REG_ADDR(SHM_NODE) % CONFIG_DCACHE_LINE_SIZE) == 0);
26+
BUILD_ASSERT((sizeof(struct ironside_call_buf) % CONFIG_DCACHE_LINE_SIZE) == 0);
27+
#endif
28+
29+
static const struct mbox_dt_spec mbox_rx = MBOX_DT_SPEC_INST_GET(0, rx);
30+
static const struct mbox_dt_spec mbox_tx = MBOX_DT_SPEC_INST_GET(0, tx);
31+
32+
K_EVENT_DEFINE(alloc_evts);
33+
K_EVENT_DEFINE(rsp_evts);
34+
35+
static void ironside_call_rsp(const struct device *dev, mbox_channel_id_t channel_id,
36+
void *user_data, struct mbox_msg *data)
37+
{
38+
ARG_UNUSED(dev);
39+
ARG_UNUSED(channel_id);
40+
ARG_UNUSED(user_data);
41+
ARG_UNUSED(data);
42+
43+
struct ironside_call_buf *buf;
44+
uint32_t rsp_buf_bits = 0;
45+
const uint32_t skip_buf_bits = k_event_test(&rsp_evts, ALL_BUF_BITS);
46+
47+
for (int i = 0; i < NUM_BUFS; i++) {
48+
if (skip_buf_bits & BIT(i)) {
49+
/* Must not cache-invalidate this buffer. */
50+
continue;
51+
}
52+
53+
buf = &bufs[i];
54+
55+
sys_cache_data_invd_range(buf, sizeof(*buf));
56+
barrier_dmem_fence_full();
57+
58+
if (buf->status != IRONSIDE_CALL_STATUS_IDLE &&
59+
buf->status != IRONSIDE_CALL_STATUS_REQ) {
60+
rsp_buf_bits |= BIT(i);
61+
}
62+
}
63+
k_event_post(&rsp_evts, rsp_buf_bits);
64+
}
65+
66+
static int ironside_call_init(const struct device *dev)
67+
{
68+
ARG_UNUSED(dev);
69+
70+
int err;
71+
72+
k_event_set(&alloc_evts, ALL_BUF_BITS);
73+
k_event_set(&rsp_evts, ALL_BUF_BITS);
74+
75+
err = mbox_register_callback_dt(&mbox_rx, ironside_call_rsp, NULL);
76+
__ASSERT_NO_MSG(err == 0);
77+
78+
err = mbox_set_enabled_dt(&mbox_rx, 1);
79+
__ASSERT_NO_MSG(err == 0);
80+
81+
return 0;
82+
}
83+
84+
DEVICE_DT_INST_DEFINE(0, ironside_call_init, NULL, NULL, NULL, POST_KERNEL,
85+
CONFIG_NRF_IRONSIDE_CALL_INIT_PRIORITY, NULL);
86+
87+
struct ironside_call_buf *ironside_call_alloc(void)
88+
{
89+
uint32_t avail_buf_bits;
90+
uint32_t alloc_buf_bit;
91+
92+
do {
93+
avail_buf_bits = k_event_wait(&alloc_evts, ALL_BUF_BITS, false, K_FOREVER);
94+
alloc_buf_bit = LSB_GET(avail_buf_bits);
95+
} while (!k_event_clear(&alloc_evts, alloc_buf_bit));
96+
97+
return &bufs[u32_count_trailing_zeros(alloc_buf_bit)];
98+
}
99+
100+
void ironside_call_dispatch(struct ironside_call_buf *buf)
101+
{
102+
const uint32_t buf_bit = BIT(buf - bufs);
103+
int err;
104+
105+
buf->status = IRONSIDE_CALL_STATUS_REQ;
106+
barrier_dmem_fence_full();
107+
108+
sys_cache_data_flush_range(buf, sizeof(*buf));
109+
110+
k_event_clear(&rsp_evts, buf_bit);
111+
112+
err = mbox_send_dt(&mbox_tx, NULL);
113+
__ASSERT_NO_MSG(err == 0);
114+
115+
k_event_wait(&rsp_evts, buf_bit, false, K_FOREVER);
116+
}
117+
118+
void ironside_call_release(struct ironside_call_buf *buf)
119+
{
120+
const uint32_t buf_bit = BIT(buf - bufs);
121+
122+
buf->status = IRONSIDE_CALL_STATUS_IDLE;
123+
barrier_dmem_fence_full();
124+
125+
sys_cache_data_flush_range(buf, sizeof(*buf));
126+
127+
k_event_post(&alloc_evts, buf_bit);
128+
}

0 commit comments

Comments
 (0)