From 10e8b6c9f687816fe724599b7ab4f3d9af346307 Mon Sep 17 00:00:00 2001 From: Yongrong Wang Date: Tue, 6 Aug 2024 11:32:14 +0800 Subject: [PATCH] rptun/rpmsg_virtio: remove chip cmd and reuse the common ones Add more common command for rptun and rpmsg_virtio frameworks, also modify the rptun and rpmsg_virtio driver to use the common commands. Signed-off-by: Yongrong Wang --- arch/sim/src/sim/sim_rpmsg_virtio.c | 2 -- arch/sim/src/sim/sim_rptun.c | 18 +++++++----------- drivers/rpmsg/rpmsg_virtio_ivshmem.c | 2 -- drivers/rptun/rptun.c | 8 +++----- drivers/rptun/rptun_ivshmem.c | 10 +++------- include/nuttx/rptun/rptun.h | 11 +++++++++++ 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/arch/sim/src/sim/sim_rpmsg_virtio.c b/arch/sim/src/sim/sim_rpmsg_virtio.c index 737c92bbcb..e8362d225e 100644 --- a/arch/sim/src/sim/sim_rpmsg_virtio.c +++ b/arch/sim/src/sim/sim_rpmsg_virtio.c @@ -47,8 +47,6 @@ struct sim_rpmsg_virtio_shmem_s volatile uintptr_t base; volatile unsigned int seqs; volatile unsigned int seqm; - volatile unsigned int cmds; - volatile unsigned int cmdm; volatile unsigned int boots; volatile unsigned int bootm; struct rpmsg_virtio_rsc_s rsc; diff --git a/arch/sim/src/sim/sim_rptun.c b/arch/sim/src/sim/sim_rptun.c index 5ffebc5150..d301217cc7 100644 --- a/arch/sim/src/sim/sim_rptun.c +++ b/arch/sim/src/sim/sim_rptun.c @@ -34,9 +34,6 @@ * Pre-processor Definitions ****************************************************************************/ -#define SIM_RPTUN_STOP 0x1 -#define SIM_RPTUN_MASK 0xffff -#define SIM_RPTUN_SHIFT 16 #define SIM_RPTUN_WORK_DELAY 1 /* Status byte for master/slave to report progress */ @@ -54,8 +51,6 @@ struct sim_rptun_shmem_s volatile uint64_t base; volatile uint32_t seqs; volatile uint32_t seqm; - volatile uint32_t cmds; - volatile uint32_t cmdm; volatile uint32_t boots; volatile uint32_t bootm; struct rptun_rsc_s rsc; @@ -238,11 +233,11 @@ static int sim_rptun_stop(struct rptun_dev_s *dev) struct sim_rptun_dev_s *priv = container_of(dev, struct sim_rptun_dev_s, rptun); - /* Don't send SIM_RPTUN_STOP when slave recovery */ + /* Don't send RPTUN_CMD_STOP when slave recovery */ if (priv->shmem->boots & SIM_RPTUN_STATUS_OK) { - priv->shmem->cmdm = SIM_RPTUN_STOP << SIM_RPTUN_SHIFT; + priv->shmem->rsc.cmd_master = RPTUN_CMD(RPTUN_CMD_STOP, 0); } if ((priv->master & SIM_RPTUN_BOOT) && priv->pid > 0) @@ -293,12 +288,13 @@ static int sim_rptun_register_callback(struct rptun_dev_s *dev, static void sim_rptun_check_cmd(struct sim_rptun_dev_s *priv) { - unsigned int cmd = priv->master ? priv->shmem->cmds : priv->shmem->cmdm; + unsigned int cmd = priv->master ? priv->shmem->rsc.cmd_slave : + priv->shmem->rsc.cmd_master; - switch ((cmd >> SIM_RPTUN_SHIFT) & SIM_RPTUN_MASK) + switch (RPTUN_GET_CMD(cmd)) { - case SIM_RPTUN_STOP: - host_abort(cmd & SIM_RPTUN_MASK); + case RPTUN_CMD_STOP: + host_abort(RPTUN_GET_CMD_VAL(cmd)); break; default: diff --git a/drivers/rpmsg/rpmsg_virtio_ivshmem.c b/drivers/rpmsg/rpmsg_virtio_ivshmem.c index dec7ab147b..7004d1d292 100644 --- a/drivers/rpmsg/rpmsg_virtio_ivshmem.c +++ b/drivers/rpmsg/rpmsg_virtio_ivshmem.c @@ -54,8 +54,6 @@ struct rpmsg_virtio_ivshmem_mem_s volatile uint64_t basem; volatile uint32_t seqs; volatile uint32_t seqm; - volatile uint32_t cmds; - volatile uint32_t cmdm; struct rpmsg_virtio_rsc_s rsc; }; diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c index 5243315d48..a274501786 100644 --- a/drivers/rptun/rptun.c +++ b/drivers/rptun/rptun.c @@ -54,8 +54,6 @@ #define RPTUN_TIMEOUT_MS 20 -#define RPTUN_CMD_PANIC 0x1 - /**************************************************************************** * Private Types ****************************************************************************/ @@ -388,7 +386,7 @@ static void rptun_command(FAR struct rptun_priv_s *priv) rsc->cmd_master = 0; } - switch (cmd) + switch (RPTUN_GET_CMD(cmd)) { case RPTUN_CMD_PANIC: PANIC(); @@ -690,11 +688,11 @@ static void rptun_panic(FAR struct rpmsg_s *rpmsg) if (RPTUN_IS_MASTER(priv->dev)) { - rsc->cmd_master = RPTUN_CMD_PANIC; + rsc->cmd_master = RPTUN_CMD(RPTUN_CMD_PANIC, 0); } else { - rsc->cmd_slave = RPTUN_CMD_PANIC; + rsc->cmd_slave = RPTUN_CMD(RPTUN_CMD_PANIC, 0); } rptun_notify(&priv->rproc, RPTUN_NOTIFY_ALL); diff --git a/drivers/rptun/rptun_ivshmem.c b/drivers/rptun/rptun_ivshmem.c index b468f54457..670198d32e 100644 --- a/drivers/rptun/rptun_ivshmem.c +++ b/drivers/rptun/rptun_ivshmem.c @@ -42,7 +42,6 @@ container_of(ivshmem_get_driver(dev), struct rptun_ivshmem_dev_s, drv) #define RPTUN_IVSHMEM_SHMEM_BAR 2 -#define RPTUN_IVSHMEM_READY 1 #define RPTUN_IVSHMEM_WDOG_DELAY MSEC2TICK(1) /**************************************************************************** @@ -54,8 +53,6 @@ struct rptun_ivshmem_mem_s volatile uint64_t basem; volatile uint32_t seqs; volatile uint32_t seqm; - volatile uint32_t cmds; - volatile uint32_t cmdm; volatile uint32_t reserved; volatile uint32_t rsc_size; struct rptun_rsc_s rsc; @@ -155,12 +152,12 @@ rptun_ivshmem_get_resource(FAR struct rptun_dev_s *dev) /* Wait untils salve is ready */ - while (priv->shmem->cmds != RPTUN_IVSHMEM_READY) + while (RPTUN_GET_CMD(priv->shmem->rsc.cmd_slave) != RPTUN_CMD_READY) { usleep(1000); } - priv->shmem->cmds = 0; + priv->shmem->rsc.cmd_slave = 0; priv->shmem->basem = (uint64_t)(uintptr_t)priv->shmem; } else @@ -192,10 +189,9 @@ rptun_ivshmem_get_resource(FAR struct rptun_dev_s *dev) rsc->config.r2h_buf_size = CONFIG_RPTUN_IVSHMEM_BUFFSIZE; rsc->config.h2r_buf_size = CONFIG_RPTUN_IVSHMEM_BUFFSIZE; rsc->cmd_master = 0; - rsc->cmd_slave = 0; priv->shmem->rsc_size = sizeof(struct rptun_rsc_s); - priv->shmem->cmds = RPTUN_IVSHMEM_READY; + priv->shmem->rsc.cmd_slave = RPTUN_CMD_READY; /* Wait untils master is ready, salve need use master base to * initialize addrenv. diff --git a/include/nuttx/rptun/rptun.h b/include/nuttx/rptun/rptun.h index 13524bcd1a..0fd0693bb3 100644 --- a/include/nuttx/rptun/rptun.h +++ b/include/nuttx/rptun/rptun.h @@ -46,6 +46,17 @@ #define RPTUNIOC_RESET _RPTUNIOC(102) #define RPTUN_NOTIFY_ALL (UINT32_MAX - 0) + +#define RPTUN_CMD_PANIC 0x1 +#define RPTUN_CMD_STOP 0x2 +#define RPTUN_CMD_READY 0x3 +#define RPTUN_CMD_MASK 0xffff +#define RPTUN_CMD_SHIFT 16 + +#define RPTUN_CMD(c,v) (((c) << RPTUN_CMD_SHIFT) | ((v) & RPTUN_CMD_MASK)) +#define RPTUN_GET_CMD(c) ((c) >> RPTUN_CMD_SHIFT) +#define RPTUN_GET_CMD_VAL(c) ((c) & RPTUN_CMD_MASK) + #ifdef CONFIG_OPENAMP_CACHE # define RPTUN_INVALIDATE(x) metal_cache_invalidate(&x, sizeof(x)) #else