Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipc: icbmsg: Add support for POSIX arch targets #78109

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions boards/native/nrf_bsim/ipc_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,31 @@
#include "nsi_cpu_if.h"
#include <zephyr/device.h>

#if defined(CONFIG_IPC_SERVICE_STATIC_VRINGS)

#define DT_DRV_COMPAT zephyr_ipc_openamp_static_vrings

#define DEFINE_BACKEND_BUFFER(i) \
NATIVE_SIMULATOR_IF \
char IPC##i##_shm_buffer[DT_REG_SIZE(DT_INST_PHANDLE(i, memory_region))];

DT_INST_FOREACH_STATUS_OKAY(DEFINE_BACKEND_BUFFER)

#endif

#if defined(CONFIG_IPC_SERVICE_BACKEND_ICBMSG)

#undef DT_DRV_COMPAT
#define DT_DRV_COMPAT zephyr_ipc_icbmsg

#define DEFINE_BACKEND_BUFFER_DIR(i, dir) \
NATIVE_SIMULATOR_IF \
char IPC##i##_##dir##_shm_buffer[DT_REG_SIZE(DT_INST_PHANDLE(i, dir##_region))] = {0};

#define DEFINE_BACKEND_BUFFER(i) \
DEFINE_BACKEND_BUFFER_DIR(i, tx) \
DEFINE_BACKEND_BUFFER_DIR(i, rx)

Check notice on line 44 in boards/native/nrf_bsim/ipc_backend.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

boards/native/nrf_bsim/ipc_backend.c:44 -#define DEFINE_BACKEND_BUFFER_DIR(i, dir) \ - NATIVE_SIMULATOR_IF \ +#define DEFINE_BACKEND_BUFFER_DIR(i, dir) \ + NATIVE_SIMULATOR_IF \ char IPC##i##_##dir##_shm_buffer[DT_REG_SIZE(DT_INST_PHANDLE(i, dir##_region))] = {0}; -#define DEFINE_BACKEND_BUFFER(i) \ - DEFINE_BACKEND_BUFFER_DIR(i, tx) \ +#define DEFINE_BACKEND_BUFFER(i) \ + DEFINE_BACKEND_BUFFER_DIR(i, tx) \

Check notice on line 44 in boards/native/nrf_bsim/ipc_backend.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

boards/native/nrf_bsim/ipc_backend.c:44 -#define DEFINE_BACKEND_BUFFER_DIR(i, dir) \ - NATIVE_SIMULATOR_IF \ +#define DEFINE_BACKEND_BUFFER_DIR(i, dir) \ + NATIVE_SIMULATOR_IF \ char IPC##i##_##dir##_shm_buffer[DT_REG_SIZE(DT_INST_PHANDLE(i, dir##_region))] = {0}; -#define DEFINE_BACKEND_BUFFER(i) \ - DEFINE_BACKEND_BUFFER_DIR(i, tx) \ +#define DEFINE_BACKEND_BUFFER(i) \ + DEFINE_BACKEND_BUFFER_DIR(i, tx) \

DT_INST_FOREACH_STATUS_OKAY(DEFINE_BACKEND_BUFFER)

#endif
24 changes: 15 additions & 9 deletions include/zephyr/ipc/pbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@
#define PBUF_HEADER_OVERHEAD(dcache_align) \
(MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE)

#if !defined(CONFIG_ARCH_POSIX)
#define PBUF_CHECKS(name, mem_addr, size, dcache_align) \
BUILD_ASSERT(dcache_align >= 0, \
"Cache line size must be non negative."); \
BUILD_ASSERT((size) > 0 && IS_PTR_ALIGNED_BYTES(size, _PBUF_IDX_SIZE), \
"Incorrect size."); \
BUILD_ASSERT(IS_PTR_ALIGNED_BYTES(mem_addr, MAX(dcache_align, _PBUF_IDX_SIZE)), \
"Misaligned memory."); \
BUILD_ASSERT(size >= (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE + \
_PBUF_MIN_DATA_LEN), "Insufficient size.");
#else

Check notice on line 140 in include/zephyr/ipc/pbuf.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/ipc/pbuf.h:140 -#define PBUF_CHECKS(name, mem_addr, size, dcache_align) \ -BUILD_ASSERT(dcache_align >= 0, \ - "Cache line size must be non negative."); \ -BUILD_ASSERT((size) > 0 && IS_PTR_ALIGNED_BYTES(size, _PBUF_IDX_SIZE), \ - "Incorrect size."); \ -BUILD_ASSERT(IS_PTR_ALIGNED_BYTES(mem_addr, MAX(dcache_align, _PBUF_IDX_SIZE)), \ - "Misaligned memory."); \ -BUILD_ASSERT(size >= (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE + \ - _PBUF_MIN_DATA_LEN), "Insufficient size."); +#define PBUF_CHECKS(name, mem_addr, size, dcache_align) \ + BUILD_ASSERT(dcache_align >= 0, "Cache line size must be non negative."); \ + BUILD_ASSERT((size) > 0 && IS_PTR_ALIGNED_BYTES(size, _PBUF_IDX_SIZE), "Incorrect size."); \ + BUILD_ASSERT(IS_PTR_ALIGNED_BYTES(mem_addr, MAX(dcache_align, _PBUF_IDX_SIZE)), \ + "Misaligned memory."); \ + BUILD_ASSERT( \ + size >= (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE + _PBUF_MIN_DATA_LEN), \ + "Insufficient size.");

Check notice on line 140 in include/zephyr/ipc/pbuf.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/ipc/pbuf.h:140 -#define PBUF_CHECKS(name, mem_addr, size, dcache_align) \ -BUILD_ASSERT(dcache_align >= 0, \ - "Cache line size must be non negative."); \ -BUILD_ASSERT((size) > 0 && IS_PTR_ALIGNED_BYTES(size, _PBUF_IDX_SIZE), \ - "Incorrect size."); \ -BUILD_ASSERT(IS_PTR_ALIGNED_BYTES(mem_addr, MAX(dcache_align, _PBUF_IDX_SIZE)), \ - "Misaligned memory."); \ -BUILD_ASSERT(size >= (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE + \ - _PBUF_MIN_DATA_LEN), "Insufficient size."); +#define PBUF_CHECKS(name, mem_addr, size, dcache_align) \ + BUILD_ASSERT(dcache_align >= 0, "Cache line size must be non negative."); \ + BUILD_ASSERT((size) > 0 && IS_PTR_ALIGNED_BYTES(size, _PBUF_IDX_SIZE), "Incorrect size."); \ + BUILD_ASSERT(IS_PTR_ALIGNED_BYTES(mem_addr, MAX(dcache_align, _PBUF_IDX_SIZE)), \ + "Misaligned memory."); \ + BUILD_ASSERT( \ + size >= (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE + _PBUF_MIN_DATA_LEN), \ + "Insufficient size.");
#define PBUF_CHECKS(name, mem_addr, size, dcache_align)
#endif

/**
* @brief Statically define and initialize pbuf.
*
Expand All @@ -136,20 +150,12 @@
* @param dcache_align Data cache line size.
*/
#define PBUF_DEFINE(name, mem_addr, size, dcache_align) \
BUILD_ASSERT(dcache_align >= 0, \
"Cache line size must be non negative."); \
BUILD_ASSERT((size) > 0 && IS_PTR_ALIGNED_BYTES(size, _PBUF_IDX_SIZE), \
"Incorrect size."); \
BUILD_ASSERT(IS_PTR_ALIGNED_BYTES(mem_addr, MAX(dcache_align, _PBUF_IDX_SIZE)), \
"Misaligned memory."); \
BUILD_ASSERT(size >= (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE + \
_PBUF_MIN_DATA_LEN), "Insufficient size."); \
\
PBUF_CHECKS(name, mem_addr, size, dcache_align) \
static const struct pbuf_cfg cfg_##name = \
PBUF_CFG_INIT(mem_addr, size, dcache_align); \
static struct pbuf name = { \
.cfg = &cfg_##name, \
}

Check notice on line 158 in include/zephyr/ipc/pbuf.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/ipc/pbuf.h:158 -#define PBUF_DEFINE(name, mem_addr, size, dcache_align) \ - PBUF_CHECKS(name, mem_addr, size, dcache_align) \ - static const struct pbuf_cfg cfg_##name = \ - PBUF_CFG_INIT(mem_addr, size, dcache_align); \ - static struct pbuf name = { \ - .cfg = &cfg_##name, \ +#define PBUF_DEFINE(name, mem_addr, size, dcache_align) \ + PBUF_CHECKS(name, mem_addr, size, dcache_align) \ + static const struct pbuf_cfg cfg_##name = PBUF_CFG_INIT(mem_addr, size, dcache_align); \ + static struct pbuf name = { \ + .cfg = &cfg_##name, \

Check notice on line 158 in include/zephyr/ipc/pbuf.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/ipc/pbuf.h:158 -#define PBUF_DEFINE(name, mem_addr, size, dcache_align) \ - PBUF_CHECKS(name, mem_addr, size, dcache_align) \ - static const struct pbuf_cfg cfg_##name = \ - PBUF_CFG_INIT(mem_addr, size, dcache_align); \ - static struct pbuf name = { \ - .cfg = &cfg_##name, \ +#define PBUF_DEFINE(name, mem_addr, size, dcache_align) \ + PBUF_CHECKS(name, mem_addr, size, dcache_align) \ + static const struct pbuf_cfg cfg_##name = PBUF_CFG_INIT(mem_addr, size, dcache_align); \ + static struct pbuf name = { \ + .cfg = &cfg_##name, \

/**
* @brief Initialize the packet buffer.
Expand Down
28 changes: 27 additions & 1 deletion subsys/ipc/ipc_service/backends/ipc_icbmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1213,13 +1213,32 @@
((total_size) - GET_BLOCK_SIZE(i, (total_size), (local_blocks), \
(remote_blocks)) * (local_blocks))



/**

Check notice on line 1218 in subsys/ipc/ipc_service/backends/ipc_icbmsg.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/ipc/ipc_service/backends/ipc_icbmsg.c:1218 - -

Check notice on line 1218 in subsys/ipc/ipc_service/backends/ipc_icbmsg.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/ipc/ipc_service/backends/ipc_icbmsg.c:1218 - -
* Return shared memory start address aligned to block alignment and cache line.
*/
#if !defined(CONFIG_ARCH_POSIX)
#define ICBMSG_BACKEND_PRE(...)
#define GET_MEM_ADDR_INST(i, direction) \
ROUND_UP(DT_REG_ADDR(DT_INST_PHANDLE(i, direction##_region)), \
GET_CACHE_ALIGNMENT(i))

#else
#if (CONFIG_NATIVE_SIMULATOR_MCU_N == 1)
#define _IPC0_tx_shm_buffer IPC0_rx_shm_buffer
#define _IPC0_rx_shm_buffer IPC0_tx_shm_buffer
#else
#define _IPC0_tx_shm_buffer IPC0_tx_shm_buffer
#define _IPC0_rx_shm_buffer IPC0_rx_shm_buffer
#endif

#define ICBMSG_BACKEND_PRE(i, direction) \
extern char _IPC##i##_##direction##_shm_buffer[];
#define GET_MEM_ADDR_INST(i, direction) \
(const uintptr_t)_IPC##i##_##direction##_shm_buffer
#endif

Check notice on line 1240 in subsys/ipc/ipc_service/backends/ipc_icbmsg.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/ipc/ipc_service/backends/ipc_icbmsg.c:1240 -#define ICBMSG_BACKEND_PRE(i, direction) \ - extern char _IPC##i##_##direction##_shm_buffer[]; -#define GET_MEM_ADDR_INST(i, direction) \ - (const uintptr_t)_IPC##i##_##direction##_shm_buffer +#define ICBMSG_BACKEND_PRE(i, direction) extern char _IPC##i##_##direction##_shm_buffer[]; +#define GET_MEM_ADDR_INST(i, direction) (const uintptr_t) _IPC##i##_##direction##_shm_buffer

Check notice on line 1240 in subsys/ipc/ipc_service/backends/ipc_icbmsg.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/ipc/ipc_service/backends/ipc_icbmsg.c:1240 -#define ICBMSG_BACKEND_PRE(i, direction) \ - extern char _IPC##i##_##direction##_shm_buffer[]; -#define GET_MEM_ADDR_INST(i, direction) \ - (const uintptr_t)_IPC##i##_##direction##_shm_buffer +#define ICBMSG_BACKEND_PRE(i, direction) extern char _IPC##i##_##direction##_shm_buffer[]; +#define GET_MEM_ADDR_INST(i, direction) (const uintptr_t) _IPC##i##_##direction##_shm_buffer

/**
* Return shared memory end address aligned to block alignment and cache line.
*/
Expand All @@ -1231,8 +1250,13 @@
/**
* Return shared memory size aligned to block alignment and cache line.
*/
#define GET_MEM_SIZE_INST(i, direction) \
#if !defined(CONFIG_ARCH_POSIX)
#define GET_MEM_SIZE_INST(i, direction) \
(GET_MEM_END_INST(i, direction) - GET_MEM_ADDR_INST(i, direction))
#else
#define GET_MEM_SIZE_INST(i, direction) \
DT_REG_SIZE(DT_INST_PHANDLE(i, direction##_region))
#endif

Check notice on line 1259 in subsys/ipc/ipc_service/backends/ipc_icbmsg.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/ipc/ipc_service/backends/ipc_icbmsg.c:1259 -#define GET_MEM_SIZE_INST(i, direction) \ +#define GET_MEM_SIZE_INST(i, direction) \ (GET_MEM_END_INST(i, direction) - GET_MEM_ADDR_INST(i, direction)) #else -#define GET_MEM_SIZE_INST(i, direction) \ - DT_REG_SIZE(DT_INST_PHANDLE(i, direction##_region)) +#define GET_MEM_SIZE_INST(i, direction) DT_REG_SIZE(DT_INST_PHANDLE(i, direction##_region))

Check notice on line 1259 in subsys/ipc/ipc_service/backends/ipc_icbmsg.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/ipc/ipc_service/backends/ipc_icbmsg.c:1259 -#define GET_MEM_SIZE_INST(i, direction) \ +#define GET_MEM_SIZE_INST(i, direction) \ (GET_MEM_END_INST(i, direction) - GET_MEM_ADDR_INST(i, direction)) #else -#define GET_MEM_SIZE_INST(i, direction) \ - DT_REG_SIZE(DT_INST_PHANDLE(i, direction##_region)) +#define GET_MEM_SIZE_INST(i, direction) DT_REG_SIZE(DT_INST_PHANDLE(i, direction##_region))

/**
* Returns GET_ICMSG_SIZE, but for specific instance and direction.
Expand Down Expand Up @@ -1272,6 +1296,8 @@
DT_INST_PROP(i, rem##_blocks))

#define DEFINE_BACKEND_DEVICE(i) \
ICBMSG_BACKEND_PRE(i, tx); \
ICBMSG_BACKEND_PRE(i, rx); \
SYS_BITARRAY_DEFINE_STATIC(tx_usage_bitmap_##i, DT_INST_PROP(i, tx_blocks)); \
SYS_BITARRAY_DEFINE_STATIC(rx_hold_bitmap_##i, DT_INST_PROP(i, rx_blocks)); \
PBUF_DEFINE(tx_icbmsg_pb_##i, \
Expand Down Expand Up @@ -1327,5 +1353,5 @@
POST_KERNEL, \
CONFIG_IPC_SERVICE_REG_BACKEND_PRIORITY, \
&backend_ops);

Check notice on line 1356 in subsys/ipc/ipc_service/backends/ipc_icbmsg.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/ipc/ipc_service/backends/ipc_icbmsg.c:1356 -#define DEFINE_BACKEND_DEVICE(i) \ - ICBMSG_BACKEND_PRE(i, tx); \ - ICBMSG_BACKEND_PRE(i, rx); \ - SYS_BITARRAY_DEFINE_STATIC(tx_usage_bitmap_##i, DT_INST_PROP(i, tx_blocks)); \ - SYS_BITARRAY_DEFINE_STATIC(rx_hold_bitmap_##i, DT_INST_PROP(i, rx_blocks)); \ - PBUF_DEFINE(tx_icbmsg_pb_##i, \ - GET_MEM_ADDR_INST(i, tx), \ - GET_ICMSG_SIZE_INST(i, tx, rx), \ - GET_CACHE_ALIGNMENT(i)); \ - PBUF_DEFINE(rx_icbmsg_pb_##i, \ - GET_MEM_ADDR_INST(i, rx), \ - GET_ICMSG_SIZE_INST(i, rx, tx), \ - GET_CACHE_ALIGNMENT(i)); \ - static struct backend_data backend_data_##i = { \ - .control_data = { \ - .tx_pb = &tx_icbmsg_pb_##i, \ - .rx_pb = &rx_icbmsg_pb_##i, \ - } \ - }; \ - static const struct icbmsg_config backend_config_##i = \ - { \ - .control_config = { \ - .mbox_tx = MBOX_DT_SPEC_INST_GET(i, tx), \ - .mbox_rx = MBOX_DT_SPEC_INST_GET(i, rx), \ - }, \ - .tx = { \ - .blocks_ptr = (uint8_t *)GET_BLOCKS_ADDR_INST(i, tx, rx), \ - .block_count = DT_INST_PROP(i, tx_blocks), \ - .block_size = GET_BLOCK_SIZE_INST(i, tx, rx), \ - }, \ - .rx = { \ - .blocks_ptr = (uint8_t *)GET_BLOCKS_ADDR_INST(i, rx, tx), \ - .block_count = DT_INST_PROP(i, rx_blocks), \ - .block_size = GET_BLOCK_SIZE_INST(i, rx, tx), \ - }, \ - .tx_usage_bitmap = &tx_usage_bitmap_##i, \ - .rx_hold_bitmap = &rx_hold_bitmap_##i, \ - }; \ - BUILD_ASSERT(IS_POWER_OF_TWO(GET_CACHE_ALIGNMENT(i)), \ - "This module supports only power of two cache alignment"); \ - BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, tx, rx) > GET_CACHE_ALIGNMENT(i)) && \ - (GET_BLOCK_SIZE_INST(i, tx, rx) < \ - GET_MEM_SIZE_INST(i, tx)), \ - "TX region is too small for provided number of blocks"); \ - BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, rx, tx) > GET_CACHE_ALIGNMENT(i)) && \ - (GET_BLOCK_SIZE_INST(i, rx, tx) < \ - GET_MEM_SIZE_INST(i, rx)), \ - "RX region is too small for provided number of blocks"); \ - BUILD_ASSERT(DT_INST_PROP(i, rx_blocks) <= 256, "Too many RX blocks"); \ - BUILD_ASSERT(DT_INST_PROP(i, tx_blocks) <= 256, "Too many TX blocks"); \ - DEVICE_DT_INST_DEFINE(i, \ - &backend_init, \ - NULL, \ - &backend_data_##i, \ - &backend_config_##i, \ - POST_KERNEL, \ - CONFIG_IPC_SERVICE_REG_BACKEND_PRIORITY, \ - &backend_ops); +#define DEFINE_BACKEND_DEVICE(i) \ + ICBMSG_BACKEND_PRE(i, tx); \ + ICBMSG_BACKEND_PRE(i, rx); \ + SYS_BITARRAY_DEFINE_STATIC(tx_usage_bitmap_##i, DT_INST_PROP(i, tx_blocks)); \ + SYS_BITARRAY_DEFINE_STATIC(rx_hold_bitmap_##i, DT_INST_PROP(i, rx_blocks)); \ + PBUF_DEFINE(tx_icbmsg_pb_##i, GET_MEM_ADDR_INST(i, tx), GET_ICMSG_SIZE_INST(i, tx, rx), \ + GET_CACHE_ALIGNMENT(i)); \ + PBUF_DEFINE(rx_icbmsg_pb_##i, GET_MEM_ADDR_INST(i, rx), GET_ICMSG_SIZE_INST(i, rx, tx), \ + GET_CACHE_ALIGNMENT(i)); \ + static struct backend_data backend_data_##i = {.control_data = { \ + .tx_pb = &tx_icbmsg_pb_##i, \ + .rx_pb = &rx_icbmsg_pb_##i, \ + }}; \ + static const struct icbmsg_config backend_config_##i = { \ + .control_config = \ + { \ + .mbox_tx = MBOX_DT_SPEC_INST_GET(i, tx), \ + .mbox_rx = MBOX_DT_SPEC_INST_GET(i, rx),

Check notice on line 1356 in subsys/ipc/ipc_service/backends/ipc_icbmsg.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/ipc/ipc_service/backends/ipc_icbmsg.c:1356 -#define DEFINE_BACKEND_DEVICE(i) \ - ICBMSG_BACKEND_PRE(i, tx); \ - ICBMSG_BACKEND_PRE(i, rx); \ - SYS_BITARRAY_DEFINE_STATIC(tx_usage_bitmap_##i, DT_INST_PROP(i, tx_blocks)); \ - SYS_BITARRAY_DEFINE_STATIC(rx_hold_bitmap_##i, DT_INST_PROP(i, rx_blocks)); \ - PBUF_DEFINE(tx_icbmsg_pb_##i, \ - GET_MEM_ADDR_INST(i, tx), \ - GET_ICMSG_SIZE_INST(i, tx, rx), \ - GET_CACHE_ALIGNMENT(i)); \ - PBUF_DEFINE(rx_icbmsg_pb_##i, \ - GET_MEM_ADDR_INST(i, rx), \ - GET_ICMSG_SIZE_INST(i, rx, tx), \ - GET_CACHE_ALIGNMENT(i)); \ - static struct backend_data backend_data_##i = { \ - .control_data = { \ - .tx_pb = &tx_icbmsg_pb_##i, \ - .rx_pb = &rx_icbmsg_pb_##i, \ - } \ - }; \ - static const struct icbmsg_config backend_config_##i = \ - { \ - .control_config = { \ - .mbox_tx = MBOX_DT_SPEC_INST_GET(i, tx), \ - .mbox_rx = MBOX_DT_SPEC_INST_GET(i, rx), \ - }, \ - .tx = { \ - .blocks_ptr = (uint8_t *)GET_BLOCKS_ADDR_INST(i, tx, rx), \ - .block_count = DT_INST_PROP(i, tx_blocks), \ - .block_size = GET_BLOCK_SIZE_INST(i, tx, rx), \ - }, \ - .rx = { \ - .blocks_ptr = (uint8_t *)GET_BLOCKS_ADDR_INST(i, rx, tx), \ - .block_count = DT_INST_PROP(i, rx_blocks), \ - .block_size = GET_BLOCK_SIZE_INST(i, rx, tx), \ - }, \ - .tx_usage_bitmap = &tx_usage_bitmap_##i, \ - .rx_hold_bitmap = &rx_hold_bitmap_##i, \ - }; \ - BUILD_ASSERT(IS_POWER_OF_TWO(GET_CACHE_ALIGNMENT(i)), \ - "This module supports only power of two cache alignment"); \ - BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, tx, rx) > GET_CACHE_ALIGNMENT(i)) && \ - (GET_BLOCK_SIZE_INST(i, tx, rx) < \ - GET_MEM_SIZE_INST(i, tx)), \ - "TX region is too small for provided number of blocks"); \ - BUILD_ASSERT((GET_BLOCK_SIZE_INST(i, rx, tx) > GET_CACHE_ALIGNMENT(i)) && \ - (GET_BLOCK_SIZE_INST(i, rx, tx) < \ - GET_MEM_SIZE_INST(i, rx)), \ - "RX region is too small for provided number of blocks"); \ - BUILD_ASSERT(DT_INST_PROP(i, rx_blocks) <= 256, "Too many RX blocks"); \ - BUILD_ASSERT(DT_INST_PROP(i, tx_blocks) <= 256, "Too many TX blocks"); \ - DEVICE_DT_INST_DEFINE(i, \ - &backend_init, \ - NULL, \ - &backend_data_##i, \ - &backend_config_##i, \ - POST_KERNEL, \ - CONFIG_IPC_SERVICE_REG_BACKEND_PRIORITY, \ - &backend_ops); +#define DEFINE_BACKEND_DEVICE(i) \ + ICBMSG_BACKEND_PRE(i, tx); \ + ICBMSG_BACKEND_PRE(i, rx); \ + SYS_BITARRAY_DEFINE_STATIC(tx_usage_bitmap_##i, DT_INST_PROP(i, tx_blocks)); \ + SYS_BITARRAY_DEFINE_STATIC(rx_hold_bitmap_##i, DT_INST_PROP(i, rx_blocks)); \ + PBUF_DEFINE(tx_icbmsg_pb_##i, GET_MEM_ADDR_INST(i, tx), GET_ICMSG_SIZE_INST(i, tx, rx), \ + GET_CACHE_ALIGNMENT(i)); \ + PBUF_DEFINE(rx_icbmsg_pb_##i, GET_MEM_ADDR_INST(i, rx), GET_ICMSG_SIZE_INST(i, rx, tx), \ + GET_CACHE_ALIGNMENT(i)); \ + static struct backend_data backend_data_##i = {.control_data = { \ + .tx_pb = &tx_icbmsg_pb_##i, \ + .rx_pb = &rx_icbmsg_pb_##i, \ + }}; \ + static const struct icbmsg_config backend_config_##i = { \ + .control_config = \ + { \ + .mbox_tx = MBOX_DT_SPEC_INST_GET(i, tx), \ + .mbox_rx = MBOX_DT_SPEC_INST_GET(i, rx),
DT_INST_FOREACH_STATUS_OKAY(DEFINE_BACKEND_DEVICE)
Loading