Skip to content

Commit

Permalink
ipc: icbmsg: Add support for POSIX arch targets
Browse files Browse the repository at this point in the history
Add support in this IPC backend for POSIX arch targets in general,
and ensure the nrf5340bsim defines the buffer which will be used.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
  • Loading branch information
aescolar committed Sep 7, 2024
1 parent 34982bb commit 81c1df8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 10 deletions.
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 @@ struct pbuf {
#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,15 +150,7 @@ struct pbuf {
* @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 = { \
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 @@ const static struct ipc_service_backend backend_ops = {
((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 @@ const static struct ipc_service_backend backend_ops = {
/**
* 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 @@ const static struct ipc_service_backend backend_ops = {
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

0 comments on commit 81c1df8

Please sign in to comment.