ipc: rpmsg_multi_instance: Use only rpsmg_mi_ctx_cfg for configuration
For the instance configuration the rpmsg_multi_instance code is currently using a set of configuration info coming from two different sources: the rpsmg_mi_ctx_cfg struct and Kconfig. This is not only confusing but it's preventing to configure the instances using information not coming from Kconfig (for example if we want to configure the instance using DT). Signed-off-by: Carlo Caione <ccaione@baylibre.com>
This commit is contained in:
parent
27f36bda51
commit
66fb1bc2bc
6 changed files with 52 additions and 35 deletions
|
@ -96,6 +96,8 @@ struct rpmsg_mi_ctx {
|
||||||
const struct device *ipm_tx_handle;
|
const struct device *ipm_tx_handle;
|
||||||
const struct device *ipm_rx_handle;
|
const struct device *ipm_rx_handle;
|
||||||
|
|
||||||
|
unsigned int ipm_tx_id;
|
||||||
|
|
||||||
uint32_t shm_status_reg_addr;
|
uint32_t shm_status_reg_addr;
|
||||||
struct metal_io_region *shm_io;
|
struct metal_io_region *shm_io;
|
||||||
struct metal_device shm_device;
|
struct metal_device shm_device;
|
||||||
|
@ -121,6 +123,12 @@ struct rpmsg_mi_ctx_cfg {
|
||||||
/** Name of instance. */
|
/** Name of instance. */
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
|
/** Physical address shared memory region. */
|
||||||
|
uintptr_t shm_addr;
|
||||||
|
|
||||||
|
/** Size shared memory region. */
|
||||||
|
size_t shm_size;
|
||||||
|
|
||||||
/** Stack area for k_work_q. */
|
/** Stack area for k_work_q. */
|
||||||
k_thread_stack_t *ipm_stack_area;
|
k_thread_stack_t *ipm_stack_area;
|
||||||
|
|
||||||
|
@ -138,6 +146,9 @@ struct rpmsg_mi_ctx_cfg {
|
||||||
|
|
||||||
/** Name of the RX IPM channel. */
|
/** Name of the RX IPM channel. */
|
||||||
const char *ipm_rx_name;
|
const char *ipm_rx_name;
|
||||||
|
|
||||||
|
/** IPM message identifier. */
|
||||||
|
unsigned int ipm_tx_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief Initialization of RPMsg instance.
|
/** @brief Initialization of RPMsg instance.
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#define IPM_WORK_QUEUE_STACK_SIZE 1024
|
#define IPM_WORK_QUEUE_STACK_SIZE 1024
|
||||||
#define APP_TASK_STACK_SIZE 1024
|
#define APP_TASK_STACK_SIZE 1024
|
||||||
|
|
||||||
|
#define IPM_MSG_ID 0
|
||||||
|
|
||||||
K_THREAD_STACK_DEFINE(ipm_stack_area_1, IPM_WORK_QUEUE_STACK_SIZE);
|
K_THREAD_STACK_DEFINE(ipm_stack_area_1, IPM_WORK_QUEUE_STACK_SIZE);
|
||||||
K_THREAD_STACK_DEFINE(ipm_stack_area_2, IPM_WORK_QUEUE_STACK_SIZE);
|
K_THREAD_STACK_DEFINE(ipm_stack_area_2, IPM_WORK_QUEUE_STACK_SIZE);
|
||||||
|
|
||||||
|
@ -72,6 +74,9 @@ static const struct rpmsg_mi_ctx_cfg cfg_1 = {
|
||||||
.ipm_work_q_prio = 0,
|
.ipm_work_q_prio = 0,
|
||||||
.ipm_tx_name = CONFIG_RPMSG_MULTI_INSTANCE_0_IPM_TX_NAME,
|
.ipm_tx_name = CONFIG_RPMSG_MULTI_INSTANCE_0_IPM_TX_NAME,
|
||||||
.ipm_rx_name = CONFIG_RPMSG_MULTI_INSTANCE_0_IPM_RX_NAME,
|
.ipm_rx_name = CONFIG_RPMSG_MULTI_INSTANCE_0_IPM_RX_NAME,
|
||||||
|
.ipm_tx_id = IPM_MSG_ID,
|
||||||
|
.shm_addr = SHM_START_ADDR,
|
||||||
|
.shm_size = SHM_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct rpmsg_mi_ctx_cfg cfg_2 = {
|
static const struct rpmsg_mi_ctx_cfg cfg_2 = {
|
||||||
|
@ -82,6 +87,9 @@ static const struct rpmsg_mi_ctx_cfg cfg_2 = {
|
||||||
.ipm_work_q_prio = 0,
|
.ipm_work_q_prio = 0,
|
||||||
.ipm_tx_name = CONFIG_RPMSG_MULTI_INSTANCE_1_IPM_TX_NAME,
|
.ipm_tx_name = CONFIG_RPMSG_MULTI_INSTANCE_1_IPM_TX_NAME,
|
||||||
.ipm_rx_name = CONFIG_RPMSG_MULTI_INSTANCE_1_IPM_RX_NAME,
|
.ipm_rx_name = CONFIG_RPMSG_MULTI_INSTANCE_1_IPM_RX_NAME,
|
||||||
|
.ipm_tx_id = IPM_MSG_ID,
|
||||||
|
.shm_addr = SHM_START_ADDR,
|
||||||
|
.shm_size = SHM_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct rpmsg_mi_cb cb_1 = {
|
static struct rpmsg_mi_cb cb_1 = {
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#define IPM_WORK_QUEUE_STACK_SIZE 1024
|
#define IPM_WORK_QUEUE_STACK_SIZE 1024
|
||||||
#define APP_TASK_STACK_SIZE 1024
|
#define APP_TASK_STACK_SIZE 1024
|
||||||
|
|
||||||
|
#define IPM_MSG_ID 0
|
||||||
|
|
||||||
K_THREAD_STACK_DEFINE(ipm_stack_area_1, IPM_WORK_QUEUE_STACK_SIZE);
|
K_THREAD_STACK_DEFINE(ipm_stack_area_1, IPM_WORK_QUEUE_STACK_SIZE);
|
||||||
K_THREAD_STACK_DEFINE(ipm_stack_area_2, IPM_WORK_QUEUE_STACK_SIZE);
|
K_THREAD_STACK_DEFINE(ipm_stack_area_2, IPM_WORK_QUEUE_STACK_SIZE);
|
||||||
|
|
||||||
|
@ -72,6 +74,9 @@ static const struct rpmsg_mi_ctx_cfg cfg_1 = {
|
||||||
.ipm_work_q_prio = 0,
|
.ipm_work_q_prio = 0,
|
||||||
.ipm_tx_name = CONFIG_RPMSG_MULTI_INSTANCE_0_IPM_TX_NAME,
|
.ipm_tx_name = CONFIG_RPMSG_MULTI_INSTANCE_0_IPM_TX_NAME,
|
||||||
.ipm_rx_name = CONFIG_RPMSG_MULTI_INSTANCE_0_IPM_RX_NAME,
|
.ipm_rx_name = CONFIG_RPMSG_MULTI_INSTANCE_0_IPM_RX_NAME,
|
||||||
|
.ipm_tx_id = IPM_MSG_ID,
|
||||||
|
.shm_addr = SHM_START_ADDR,
|
||||||
|
.shm_size = SHM_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct rpmsg_mi_ctx_cfg cfg_2 = {
|
static const struct rpmsg_mi_ctx_cfg cfg_2 = {
|
||||||
|
@ -82,6 +87,9 @@ static const struct rpmsg_mi_ctx_cfg cfg_2 = {
|
||||||
.ipm_work_q_prio = 0,
|
.ipm_work_q_prio = 0,
|
||||||
.ipm_tx_name = CONFIG_RPMSG_MULTI_INSTANCE_1_IPM_TX_NAME,
|
.ipm_tx_name = CONFIG_RPMSG_MULTI_INSTANCE_1_IPM_TX_NAME,
|
||||||
.ipm_rx_name = CONFIG_RPMSG_MULTI_INSTANCE_1_IPM_RX_NAME,
|
.ipm_rx_name = CONFIG_RPMSG_MULTI_INSTANCE_1_IPM_RX_NAME,
|
||||||
|
.ipm_tx_id = IPM_MSG_ID,
|
||||||
|
.shm_addr = SHM_START_ADDR,
|
||||||
|
.shm_size = SHM_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct rpmsg_mi_cb cb_1 = {
|
static struct rpmsg_mi_cb cb_1 = {
|
||||||
|
|
|
@ -22,6 +22,7 @@ LOG_MODULE_REGISTER(ipc_rpmsg_multi_instance, CONFIG_IPC_SERVICE_LOG_LEVEL);
|
||||||
|
|
||||||
#define PRIO_INIT_VAL INT_MAX
|
#define PRIO_INIT_VAL INT_MAX
|
||||||
#define INSTANCE_NAME_SIZE 16
|
#define INSTANCE_NAME_SIZE 16
|
||||||
|
#define IPM_MSG_ID 0
|
||||||
|
|
||||||
#define CH_NAME(idx, sub) (CONFIG_RPMSG_MULTI_INSTANCE_ ## idx ## _IPM_ ## sub ## _NAME)
|
#define CH_NAME(idx, sub) (CONFIG_RPMSG_MULTI_INSTANCE_ ## idx ## _IPM_ ## sub ## _NAME)
|
||||||
|
|
||||||
|
@ -136,6 +137,10 @@ static int register_ept(struct ipc_ept **ept, const struct ipc_ept_cfg *cfg)
|
||||||
ctx_cfg.ipm_thread_name = instances[i_idx].name;
|
ctx_cfg.ipm_thread_name = instances[i_idx].name;
|
||||||
ctx_cfg.ipm_rx_name = ipm_rx_name[i_idx];
|
ctx_cfg.ipm_rx_name = ipm_rx_name[i_idx];
|
||||||
ctx_cfg.ipm_tx_name = ipm_tx_name[i_idx];
|
ctx_cfg.ipm_tx_name = ipm_tx_name[i_idx];
|
||||||
|
ctx_cfg.ipm_tx_id = IPM_MSG_ID;
|
||||||
|
|
||||||
|
ctx_cfg.shm_addr = SHM_START_ADDR;
|
||||||
|
ctx_cfg.shm_size = SHM_SIZE;
|
||||||
|
|
||||||
if (rpmsg_mi_ctx_init(&instances[i_idx].ctx, &ctx_cfg) < 0) {
|
if (rpmsg_mi_ctx_init(&instances[i_idx].ctx, &ctx_cfg) < 0) {
|
||||||
LOG_ERR("Instance initialization failed");
|
LOG_ERR("Instance initialization failed");
|
||||||
|
|
|
@ -68,13 +68,6 @@ config RPMSG_MULTI_INSTANCE_INIT_PRIORITY
|
||||||
help
|
help
|
||||||
If in doubt, do not modify this value.
|
If in doubt, do not modify this value.
|
||||||
|
|
||||||
config IPM_MSG_ID
|
|
||||||
int "IPM message identifier."
|
|
||||||
default 0
|
|
||||||
help
|
|
||||||
Values are constrained by ipm_max_data_size_get since many boards
|
|
||||||
only allow for a subset of bits in a 32-bit register to store the ID.
|
|
||||||
|
|
||||||
module = RPMSG_MULTI_INSTANCE
|
module = RPMSG_MULTI_INSTANCE
|
||||||
module-str = RPMsg multi instance
|
module-str = RPMsg multi instance
|
||||||
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
|
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(rpmsg_multi_instance, CONFIG_RPMSG_MULTI_INSTANCE_LOG_LEVEL);
|
LOG_MODULE_REGISTER(rpmsg_multi_instance, CONFIG_RPMSG_MULTI_INSTANCE_LOG_LEVEL);
|
||||||
|
|
||||||
static bool config_correct;
|
|
||||||
static int instance;
|
static int instance;
|
||||||
|
|
||||||
static void rpmsg_service_unbind(struct rpmsg_endpoint *p_ep)
|
static void rpmsg_service_unbind(struct rpmsg_endpoint *p_ep)
|
||||||
|
@ -67,7 +66,7 @@ static void virtio_notify(struct virtqueue *vq)
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
status = ipm_send(ctx->ipm_tx_handle, 0, CONFIG_IPM_MSG_ID, NULL, 0);
|
status = ipm_send(ctx->ipm_tx_handle, 0, ctx->ipm_tx_id, NULL, 0);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
LOG_WRN("Failed to notify: %d", status);
|
LOG_WRN("Failed to notify: %d", status);
|
||||||
}
|
}
|
||||||
|
@ -102,9 +101,11 @@ static void ipm_callback(const struct device *dev, void *context, uint32_t id, v
|
||||||
|
|
||||||
int rpmsg_mi_configure_shm(struct rpmsg_mi_ctx *ctx, const struct rpmsg_mi_ctx_cfg *cfg)
|
int rpmsg_mi_configure_shm(struct rpmsg_mi_ctx *ctx, const struct rpmsg_mi_ctx_cfg *cfg)
|
||||||
{
|
{
|
||||||
uint8_t vring_size = VRING_SIZE_GET(SHM_SIZE);
|
uint8_t vring_size = VRING_SIZE_GET(cfg->shm_size);
|
||||||
uint32_t shm_addr = SHMEM_INST_ADDR_AUTOALLOC_GET(SHM_START_ADDR, SHM_SIZE, instance);
|
uint32_t shm_addr = SHMEM_INST_ADDR_AUTOALLOC_GET(cfg->shm_addr,
|
||||||
uint32_t shm_size = SHMEM_INST_SIZE_AUTOALLOC_GET(SHM_SIZE);
|
cfg->shm_size,
|
||||||
|
instance);
|
||||||
|
uint32_t shm_size = SHMEM_INST_SIZE_AUTOALLOC_GET(cfg->shm_size);
|
||||||
|
|
||||||
uint32_t shm_local_start_addr = shm_addr + VDEV_STATUS_SIZE;
|
uint32_t shm_local_start_addr = shm_addr + VDEV_STATUS_SIZE;
|
||||||
uint32_t shm_local_size = shm_size - VDEV_STATUS_SIZE;
|
uint32_t shm_local_size = shm_size - VDEV_STATUS_SIZE;
|
||||||
|
@ -193,10 +194,20 @@ static void ns_bind_cb(struct rpmsg_device *rdev, const char *name, uint32_t des
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool rpmsg_mi_config_verify(const struct rpmsg_mi_ctx_cfg *cfg)
|
||||||
|
{
|
||||||
|
if (SHMEM_INST_SIZE_AUTOALLOC_GET(cfg->shm_size) * IPC_INSTANCE_COUNT > cfg->shm_size) {
|
||||||
|
LOG_ERR("Not enough memory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int rpmsg_mi_ctx_init(struct rpmsg_mi_ctx *ctx, const struct rpmsg_mi_ctx_cfg *cfg)
|
int rpmsg_mi_ctx_init(struct rpmsg_mi_ctx *ctx, const struct rpmsg_mi_ctx_cfg *cfg)
|
||||||
{
|
{
|
||||||
struct metal_init_params metal_params = METAL_INIT_DEFAULTS;
|
struct metal_init_params metal_params = METAL_INIT_DEFAULTS;
|
||||||
uint8_t vring_size = VRING_SIZE_GET(SHM_SIZE);
|
uint8_t vring_size = VRING_SIZE_GET(cfg->shm_size);
|
||||||
struct metal_device *device;
|
struct metal_device *device;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -204,7 +215,7 @@ int rpmsg_mi_ctx_init(struct rpmsg_mi_ctx *ctx, const struct rpmsg_mi_ctx_cfg *c
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config_correct) {
|
if (!rpmsg_mi_config_verify(cfg)) {
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,6 +269,8 @@ int rpmsg_mi_ctx_init(struct rpmsg_mi_ctx *ctx, const struct rpmsg_mi_ctx_cfg *c
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx->ipm_tx_id = cfg->ipm_tx_id;
|
||||||
|
|
||||||
ctx->ipm_rx_handle = device_get_binding(cfg->ipm_rx_name);
|
ctx->ipm_rx_handle = device_get_binding(cfg->ipm_rx_name);
|
||||||
if (!ctx->ipm_rx_handle) {
|
if (!ctx->ipm_rx_handle) {
|
||||||
LOG_ERR("Could not get RX IPM device handle");
|
LOG_ERR("Could not get RX IPM device handle");
|
||||||
|
@ -367,24 +380,3 @@ int rpmsg_mi_send(struct rpmsg_mi_ept *ept, const void *data, size_t len)
|
||||||
{
|
{
|
||||||
return rpmsg_send(&ept->ep, data, len);
|
return rpmsg_send(&ept->ep, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool rpmsg_mi_config_verify(void)
|
|
||||||
{
|
|
||||||
if (SHMEM_INST_SIZE_AUTOALLOC_GET(SHM_SIZE) * IPC_INSTANCE_COUNT > SHM_SIZE) {
|
|
||||||
LOG_ERR("Not enough memory");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int rpmsg_mi_init(const struct device *dev)
|
|
||||||
{
|
|
||||||
ARG_UNUSED(dev);
|
|
||||||
|
|
||||||
LOG_DBG("Initialization of RPMsg multiple instance");
|
|
||||||
config_correct = rpmsg_mi_config_verify();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SYS_INIT(rpmsg_mi_init, POST_KERNEL, CONFIG_RPMSG_MULTI_INSTANCE_INIT_PRIORITY);
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue