diff --git a/subsys/CMakeLists.txt b/subsys/CMakeLists.txt index 98c669a083bf..3f67f61c1b36 100644 --- a/subsys/CMakeLists.txt +++ b/subsys/CMakeLists.txt @@ -48,5 +48,6 @@ add_subdirectory_ifdef(CONFIG_SHELL_BT_NUS shell) add_subdirectory(debug) add_subdirectory(partition_manager) -add_subdirectory_ifdef(CONFIG_NRF_RPC nrf_rpc) add_subdirectory_ifdef(CONFIG_NRF_802154_RADIO_DRIVER ieee802154) +add_subdirectory_ifdef(CONFIG_NRF_RPC nrf_rpc) +add_subdirectory_ifdef(CONFIG_SM_IPT sm_ipt) diff --git a/subsys/Kconfig b/subsys/Kconfig index 319f3a5318f2..03b2ccf2e411 100644 --- a/subsys/Kconfig +++ b/subsys/Kconfig @@ -1,5 +1,5 @@ # -# Copyright (c) 2018 - 2020 Nordic Semiconductor +# Copyright (c) 2018 - 2021 Nordic Semiconductor # # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause # @@ -37,6 +37,8 @@ rsource "partition_manager/Kconfig" rsource "nrf_rpc/Kconfig" +rsource "sm_ipt/Kconfig" + rsource "zigbee/Kconfig" rsource "mgmt/fmfu/Kconfig" diff --git a/subsys/nrf_rpc/include/nrf_rpc_log.h b/subsys/nrf_rpc/include/nrf_rpc_log.h index b3086ba7e4ce..e029ecd11fe3 100644 --- a/subsys/nrf_rpc/include/nrf_rpc_log.h +++ b/subsys/nrf_rpc/include/nrf_rpc_log.h @@ -15,7 +15,17 @@ #define _NRF_RPC_LOG_REGISTER1(module) \ _NRF_RPC_LOG_REGISTER2(module) +#define _NRF_RPC_LOG_DECLARE2(module) \ + LOG_MODULE_DECLARE(module, CONFIG_ ## module ## _LOG_LEVEL) + +#define _NRF_RPC_LOG_DECLARE1(module) \ + _NRF_RPC_LOG_DECLARE2(module) + +#ifdef NRF_RPC_LOG_MODULE _NRF_RPC_LOG_REGISTER1(NRF_RPC_LOG_MODULE); +#elif defined(NRF_RPC_LOG_MODULE_DECLARE) +_NRF_RPC_LOG_DECLARE1(NRF_RPC_LOG_MODULE_DECLARE); +#endif #define NRF_RPC_ERR(...) LOG_ERR(__VA_ARGS__) #define NRF_RPC_WRN(...) LOG_WRN(__VA_ARGS__) diff --git a/subsys/nrf_rpc/nrf_rpc_os.c b/subsys/nrf_rpc/nrf_rpc_os.c index 8afbb21fc0dd..3e06d074274d 100644 --- a/subsys/nrf_rpc/nrf_rpc_os.c +++ b/subsys/nrf_rpc/nrf_rpc_os.c @@ -1,14 +1,15 @@ /* - * Copyright (c) 2020 Nordic Semiconductor ASA + * Copyright (c) 2020-2021 Nordic Semiconductor ASA * * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ -#define NRF_RPC_LOG_MODULE NRF_RPC_OS -#include - +#include "nrf_rpc_errno.h" #include "nrf_rpc_os.h" +#define NRF_RPC_LOG_MODULE NRF_RPC_OS +#include "nrf_rpc_log.h" + /* Maximum number of remote thread that this implementation allows. */ #define MAX_REMOTE_THREADS 255 diff --git a/subsys/sm_ipt/CMakeLists.txt b/subsys/sm_ipt/CMakeLists.txt new file mode 100644 index 000000000000..cb8b86af756a --- /dev/null +++ b/subsys/sm_ipt/CMakeLists.txt @@ -0,0 +1,11 @@ +# +# Copyright (c) 2021 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +zephyr_include_directories(include) + +zephyr_library() + +zephyr_library_sources(sm_ipt_os.c) diff --git a/subsys/sm_ipt/Kconfig b/subsys/sm_ipt/Kconfig new file mode 100644 index 000000000000..d77b6f583b37 --- /dev/null +++ b/subsys/sm_ipt/Kconfig @@ -0,0 +1,18 @@ +# +# Copyright (c) 2021 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +menu "SM IPT (Shared Memory Inter-Processor Transport) library" + +if SM_IPT + +module = SM_IPT_OS +module-str = SM IPT OS +source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config" + +endif # SM_IPT + +endmenu + diff --git a/subsys/sm_ipt/include/sm_ipt_log.h b/subsys/sm_ipt/include/sm_ipt_log.h new file mode 100644 index 000000000000..58b228959d84 --- /dev/null +++ b/subsys/sm_ipt/include/sm_ipt_log.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#ifndef SM_IPT_LOG_H_ +#define SM_IPT_LOG_H_ + +#include + +#ifndef SM_IPT_LOG_MODULE + +#define SM_IPT_LOG_MODULE SM_IPT + +#endif + +#define _SM_IPT_LOG_REGISTER2(module) \ + LOG_MODULE_REGISTER(module, CONFIG_ ## module ## _LOG_LEVEL) + +#define _SM_IPT_LOG_REGISTER1(module) \ + _SM_IPT_LOG_REGISTER2(module) + +_SM_IPT_LOG_REGISTER1(SM_IPT_LOG_MODULE); + +#define SM_IPT_ERR(...) LOG_ERR(__VA_ARGS__) +#define SM_IPT_WRN(...) LOG_WRN(__VA_ARGS__) +#define SM_IPT_INF(...) LOG_INF(__VA_ARGS__) +#define SM_IPT_DBG(...) LOG_DBG(__VA_ARGS__) + +#endif /* SM_IPT_LOG_H_ */ diff --git a/subsys/sm_ipt/include/sm_ipt_os.h b/subsys/sm_ipt/include/sm_ipt_os.h new file mode 100644 index 000000000000..8889bc9671db --- /dev/null +++ b/subsys/sm_ipt/include/sm_ipt_os.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2021 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#ifndef SM_IPT_OS_H_ +#define SM_IPT_OS_H_ + +#include + +/** + * @defgroup sm_ipt_os_zephyr SM IPT OS abstraction for Zephyr. + * @{ + * @brief SM IPT OS abstraction for Zephyr. + * + * API is compatible with sm_ipt_os API. For API documentation + * @see sm_ipt_os_tmpl.h + */ + +#ifdef __cplusplus +extern "C" { +#endif + + +struct sm_ipt_os_ctx{ + void *out_shmem_ptr; + void *in_shmem_ptr; + uint32_t out_total_size; + uint32_t in_total_size; + void (*signal_handler)(struct sm_ipt_os_ctx *); + const struct device *ipm_tx_handle; +}; + +#define SM_IPT_ASSERT(_expr) __ASSERT(_expr, "SM IPT assertion failed") + +#define SM_IPT_OS_MEMORY_BARRIER() __DSB() + +#define SM_IPT_OS_GET_CONTAINTER(ptr, type, field) CONTAINER_OF(ptr, type, field) + +void sm_ipt_os_signal(struct sm_ipt_os_ctx *os_ctx); +void sm_ipt_os_signal_handler(struct sm_ipt_os_ctx *os_ctx, void (*handler)(struct sm_ipt_os_ctx *)); +int sm_ipt_os_init(struct sm_ipt_os_ctx *os_ctx); + +typedef atomic_t sm_ipt_os_atomic_t; +#define sm_ipt_os_atomic_or atomic_or +#define sm_ipt_os_atomic_and atomic_and +#define sm_ipt_os_atomic_get atomic_get + +typedef struct k_mutex sm_ipt_os_mutex_t; +#define sm_ipt_os_mutex_init k_mutex_init +#define sm_ipt_os_unlock k_mutex_unlock + +static inline void sm_ipt_os_lock(sm_ipt_os_mutex_t *mutex) { + k_mutex_lock(mutex, K_FOREVER); +} + +typedef struct k_sem sm_ipt_os_sem_t; +#define sm_ipt_os_give k_sem_give + +static inline void sm_ipt_os_sem_init(sm_ipt_os_sem_t *sem) { + k_sem_init(sem, 0, 1); +} +static inline void sm_ipt_os_take(sm_ipt_os_sem_t *sem) { + k_sem_take(sem, K_FOREVER); +} + +#define sm_ipt_os_yield k_yield +#define sm_ipt_os_fatal k_oops +#define sm_ipt_os_clz64 __builtin_clzll +#define sm_ipt_os_clz32 __builtin_clz + + +#ifdef __cplusplus +} +#endif + +/** + *@} + */ + +#endif /* SM_IPT_OS_H */ diff --git a/subsys/sm_ipt/sm_ipt_os.c b/subsys/sm_ipt/sm_ipt_os.c new file mode 100644 index 000000000000..3276c35dc4b4 --- /dev/null +++ b/subsys/sm_ipt/sm_ipt_os.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2021 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include +#include + +#define SM_IPT_LOG_MODULE SM_IPT_OS +#include + +#include + +#define SHM_NODE DT_CHOSEN(zephyr_ipc_shm) +#define SHM_START_ADDR DT_REG_ADDR(SHM_NODE) +#define SHM_SIZE DT_REG_SIZE(SHM_NODE) + +void sm_ipt_os_signal(struct sm_ipt_os_ctx *os_ctx) +{ + int err = ipm_send(os_ctx->ipm_tx_handle, 0, 0, NULL, 0); + if (err != 0) { + LOG_ERR("Failed to notify: %d", err); + } +} + +void sm_ipt_os_signal_handler(struct sm_ipt_os_ctx *os_ctx, void (*handler)(struct sm_ipt_os_ctx *)) +{ + os_ctx->signal_handler = handler; +} + +static void ipm_callback(const struct device *ipmdev, void *user_data, uint32_t id, + volatile void *data) +{ + struct sm_ipt_os_ctx *os_ctx = (struct sm_ipt_os_ctx *)user_data; + + if (os_ctx->signal_handler) + os_ctx->signal_handler(os_ctx); +} + +int sm_ipt_os_init(struct sm_ipt_os_ctx *os_ctx) +{ + const struct device *ipm_rx_handle; + uint32_t size = WB_DN(SHM_SIZE / 2); + + os_ctx->out_total_size = size; + os_ctx->in_total_size = size; + + uint32_t addr1 = SHM_START_ADDR; + uint32_t addr2 = SHM_START_ADDR + size; + + if (IS_ENABLED(CONFIG_SM_IPT_PRIMARY)) { + os_ctx->out_shmem_ptr = (void*)addr1; + os_ctx->in_shmem_ptr = (void*)addr2; + } else { + os_ctx->out_shmem_ptr = (void*)addr2; + os_ctx->in_shmem_ptr = (void*)addr1; + } + + /* IPM setup. */ + os_ctx->ipm_tx_handle = device_get_binding(IS_ENABLED(CONFIG_SM_IPT_PRIMARY) ? + "IPM_1" : "IPM_0"); + if (!os_ctx->ipm_tx_handle) { + LOG_ERR("Could not get TX IPM device handle"); + return -NRF_ENODEV; + } + + ipm_rx_handle = device_get_binding(IS_ENABLED(CONFIG_SM_IPT_PRIMARY) ? + "IPM_0" : "IPM_1"); + if (!ipm_rx_handle) { + LOG_ERR("Could not get RX IPM device handle"); + return -NRF_ENODEV; + } + + ipm_register_callback(ipm_rx_handle, ipm_callback, os_ctx); + + return 0; +} diff --git a/west.yml b/west.yml index 4f4c71127d25..59c1901898ca 100644 --- a/west.yml +++ b/west.yml @@ -104,7 +104,7 @@ manifest: - name: nrfxlib repo-path: sdk-nrfxlib path: nrfxlib - revision: d048f584bb79997e1f60e3539b4520026ebb7745 + revision: pull/525/head - name: trusted-firmware-m repo-path: sdk-trusted-firmware-m path: modules/tee/tfm