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 <wangyongrong@xiaomi.com>
This commit is contained in:
Yongrong Wang
2024-08-06 11:32:14 +08:00
committed by Xiang Xiao
parent 420af99797
commit 10e8b6c9f6
6 changed files with 24 additions and 27 deletions
-2
View File
@@ -47,8 +47,6 @@ struct sim_rpmsg_virtio_shmem_s
volatile uintptr_t base; volatile uintptr_t base;
volatile unsigned int seqs; volatile unsigned int seqs;
volatile unsigned int seqm; volatile unsigned int seqm;
volatile unsigned int cmds;
volatile unsigned int cmdm;
volatile unsigned int boots; volatile unsigned int boots;
volatile unsigned int bootm; volatile unsigned int bootm;
struct rpmsg_virtio_rsc_s rsc; struct rpmsg_virtio_rsc_s rsc;
+7 -11
View File
@@ -34,9 +34,6 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define SIM_RPTUN_STOP 0x1
#define SIM_RPTUN_MASK 0xffff
#define SIM_RPTUN_SHIFT 16
#define SIM_RPTUN_WORK_DELAY 1 #define SIM_RPTUN_WORK_DELAY 1
/* Status byte for master/slave to report progress */ /* Status byte for master/slave to report progress */
@@ -54,8 +51,6 @@ struct sim_rptun_shmem_s
volatile uint64_t base; volatile uint64_t base;
volatile uint32_t seqs; volatile uint32_t seqs;
volatile uint32_t seqm; volatile uint32_t seqm;
volatile uint32_t cmds;
volatile uint32_t cmdm;
volatile uint32_t boots; volatile uint32_t boots;
volatile uint32_t bootm; volatile uint32_t bootm;
struct rptun_rsc_s rsc; 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 *priv = container_of(dev,
struct sim_rptun_dev_s, rptun); 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) 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) 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) 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: case RPTUN_CMD_STOP:
host_abort(cmd & SIM_RPTUN_MASK); host_abort(RPTUN_GET_CMD_VAL(cmd));
break; break;
default: default:
-2
View File
@@ -54,8 +54,6 @@ struct rpmsg_virtio_ivshmem_mem_s
volatile uint64_t basem; volatile uint64_t basem;
volatile uint32_t seqs; volatile uint32_t seqs;
volatile uint32_t seqm; volatile uint32_t seqm;
volatile uint32_t cmds;
volatile uint32_t cmdm;
struct rpmsg_virtio_rsc_s rsc; struct rpmsg_virtio_rsc_s rsc;
}; };
+3 -5
View File
@@ -54,8 +54,6 @@
#define RPTUN_TIMEOUT_MS 20 #define RPTUN_TIMEOUT_MS 20
#define RPTUN_CMD_PANIC 0x1
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
@@ -388,7 +386,7 @@ static void rptun_command(FAR struct rptun_priv_s *priv)
rsc->cmd_master = 0; rsc->cmd_master = 0;
} }
switch (cmd) switch (RPTUN_GET_CMD(cmd))
{ {
case RPTUN_CMD_PANIC: case RPTUN_CMD_PANIC:
PANIC(); PANIC();
@@ -690,11 +688,11 @@ static void rptun_panic(FAR struct rpmsg_s *rpmsg)
if (RPTUN_IS_MASTER(priv->dev)) if (RPTUN_IS_MASTER(priv->dev))
{ {
rsc->cmd_master = RPTUN_CMD_PANIC; rsc->cmd_master = RPTUN_CMD(RPTUN_CMD_PANIC, 0);
} }
else else
{ {
rsc->cmd_slave = RPTUN_CMD_PANIC; rsc->cmd_slave = RPTUN_CMD(RPTUN_CMD_PANIC, 0);
} }
rptun_notify(&priv->rproc, RPTUN_NOTIFY_ALL); rptun_notify(&priv->rproc, RPTUN_NOTIFY_ALL);
+3 -7
View File
@@ -42,7 +42,6 @@
container_of(ivshmem_get_driver(dev), struct rptun_ivshmem_dev_s, drv) container_of(ivshmem_get_driver(dev), struct rptun_ivshmem_dev_s, drv)
#define RPTUN_IVSHMEM_SHMEM_BAR 2 #define RPTUN_IVSHMEM_SHMEM_BAR 2
#define RPTUN_IVSHMEM_READY 1
#define RPTUN_IVSHMEM_WDOG_DELAY MSEC2TICK(1) #define RPTUN_IVSHMEM_WDOG_DELAY MSEC2TICK(1)
/**************************************************************************** /****************************************************************************
@@ -54,8 +53,6 @@ struct rptun_ivshmem_mem_s
volatile uint64_t basem; volatile uint64_t basem;
volatile uint32_t seqs; volatile uint32_t seqs;
volatile uint32_t seqm; volatile uint32_t seqm;
volatile uint32_t cmds;
volatile uint32_t cmdm;
volatile uint32_t reserved; volatile uint32_t reserved;
volatile uint32_t rsc_size; volatile uint32_t rsc_size;
struct rptun_rsc_s rsc; struct rptun_rsc_s rsc;
@@ -155,12 +152,12 @@ rptun_ivshmem_get_resource(FAR struct rptun_dev_s *dev)
/* Wait untils salve is ready */ /* 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); usleep(1000);
} }
priv->shmem->cmds = 0; priv->shmem->rsc.cmd_slave = 0;
priv->shmem->basem = (uint64_t)(uintptr_t)priv->shmem; priv->shmem->basem = (uint64_t)(uintptr_t)priv->shmem;
} }
else 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.r2h_buf_size = CONFIG_RPTUN_IVSHMEM_BUFFSIZE;
rsc->config.h2r_buf_size = CONFIG_RPTUN_IVSHMEM_BUFFSIZE; rsc->config.h2r_buf_size = CONFIG_RPTUN_IVSHMEM_BUFFSIZE;
rsc->cmd_master = 0; rsc->cmd_master = 0;
rsc->cmd_slave = 0;
priv->shmem->rsc_size = sizeof(struct rptun_rsc_s); 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 /* Wait untils master is ready, salve need use master base to
* initialize addrenv. * initialize addrenv.
+11
View File
@@ -46,6 +46,17 @@
#define RPTUNIOC_RESET _RPTUNIOC(102) #define RPTUNIOC_RESET _RPTUNIOC(102)
#define RPTUN_NOTIFY_ALL (UINT32_MAX - 0) #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 #ifdef CONFIG_OPENAMP_CACHE
# define RPTUN_INVALIDATE(x) metal_cache_invalidate(&x, sizeof(x)) # define RPTUN_INVALIDATE(x) metal_cache_invalidate(&x, sizeof(x))
#else #else