forked from nuttx/nuttx-update
rptun: move rptun cmd definition before the resource table
Because locate the command at the end the resource table is unfriendly when we want to support multi virtio devices instead only one virtio rpmsg device. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
parent
10e8b6c9f6
commit
dbe43b0ae9
4 changed files with 33 additions and 20 deletions
|
@ -102,6 +102,7 @@ sim_rptun_get_resource(struct rptun_dev_s *dev)
|
|||
{
|
||||
struct sim_rptun_dev_s *priv = container_of(dev,
|
||||
struct sim_rptun_dev_s, rptun);
|
||||
struct rptun_cmd_s *cmd;
|
||||
|
||||
priv->shmem = host_allocshmem(priv->shmemname,
|
||||
sizeof(*priv->shmem));
|
||||
|
@ -110,12 +111,15 @@ sim_rptun_get_resource(struct rptun_dev_s *dev)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
cmd = RPTUN_RSC2CMD(&priv->shmem->rsc);
|
||||
|
||||
priv->raddrenv[0].da = 0;
|
||||
priv->raddrenv[0].size = sizeof(*priv->shmem);
|
||||
|
||||
if (priv->master)
|
||||
{
|
||||
struct rptun_rsc_s *rsc = &priv->shmem->rsc;
|
||||
|
||||
memset(priv->shmem->buf, 0, sizeof(priv->shmem->buf));
|
||||
memset(rsc, 0, sizeof(struct rptun_rsc_s));
|
||||
|
||||
|
@ -142,9 +146,8 @@ sim_rptun_get_resource(struct rptun_dev_s *dev)
|
|||
rsc->rpmsg_vring1.notifyid = RSC_NOTIFY_ID_ANY;
|
||||
rsc->config.r2h_buf_size = 0x800;
|
||||
rsc->config.h2r_buf_size = 0x800;
|
||||
rsc->cmd_master = 0;
|
||||
rsc->cmd_slave = 0;
|
||||
|
||||
cmd->cmd_slave = 0;
|
||||
priv->shmem->base = (uintptr_t)priv->shmem;
|
||||
|
||||
/* The master notifies its slave when it starts again */
|
||||
|
@ -174,6 +177,8 @@ sim_rptun_get_resource(struct rptun_dev_s *dev)
|
|||
usleep(1000);
|
||||
}
|
||||
|
||||
cmd->cmd_master = 0;
|
||||
|
||||
priv->raddrenv[0].pa = (uintptr_t)priv->shmem->base;
|
||||
|
||||
priv->shmem->boots = SIM_RPTUN_STATUS_OK;
|
||||
|
@ -232,12 +237,13 @@ 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);
|
||||
struct rptun_cmd_s *cmd = RPTUN_RSC2CMD(&priv->shmem->rsc);
|
||||
|
||||
/* Don't send RPTUN_CMD_STOP when slave recovery */
|
||||
|
||||
if (priv->shmem->boots & SIM_RPTUN_STATUS_OK)
|
||||
{
|
||||
priv->shmem->rsc.cmd_master = RPTUN_CMD(RPTUN_CMD_STOP, 0);
|
||||
cmd->cmd_master = RPTUN_CMD(RPTUN_CMD_STOP, 0);
|
||||
}
|
||||
|
||||
if ((priv->master & SIM_RPTUN_BOOT) && priv->pid > 0)
|
||||
|
@ -288,8 +294,8 @@ 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->rsc.cmd_slave :
|
||||
priv->shmem->rsc.cmd_master;
|
||||
struct rptun_cmd_s *rcmd = RPTUN_RSC2CMD(&priv->shmem->rsc);
|
||||
uint32_t cmd = priv->master ? rcmd->cmd_slave : rcmd->cmd_master;
|
||||
|
||||
switch (RPTUN_GET_CMD(cmd))
|
||||
{
|
||||
|
|
|
@ -372,18 +372,18 @@ static bool rptun_is_recursive(FAR struct rptun_priv_s *priv)
|
|||
|
||||
static void rptun_command(FAR struct rptun_priv_s *priv)
|
||||
{
|
||||
FAR struct rptun_rsc_s *rsc = priv->rproc.rsc_table;
|
||||
FAR struct rptun_cmd_s *rptun_cmd = RPTUN_RSC2CMD(priv->rproc.rsc_table);
|
||||
uint32_t cmd;
|
||||
|
||||
if (RPTUN_IS_MASTER(priv->dev))
|
||||
{
|
||||
cmd = rsc->cmd_slave;
|
||||
rsc->cmd_slave = 0;
|
||||
cmd = rptun_cmd->cmd_slave;
|
||||
rptun_cmd->cmd_slave = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = rsc->cmd_master;
|
||||
rsc->cmd_master = 0;
|
||||
cmd = rptun_cmd->cmd_master;
|
||||
rptun_cmd->cmd_master = 0;
|
||||
}
|
||||
|
||||
switch (RPTUN_GET_CMD(cmd))
|
||||
|
@ -678,7 +678,7 @@ static int rptun_ioctl(FAR struct rpmsg_s *rpmsg, int cmd, unsigned long arg)
|
|||
static void rptun_panic(FAR struct rpmsg_s *rpmsg)
|
||||
{
|
||||
FAR struct rptun_priv_s *priv = (FAR struct rptun_priv_s *)rpmsg;
|
||||
FAR struct rptun_rsc_s *rsc = priv->rproc.rsc_table;
|
||||
FAR struct rptun_cmd_s *cmd = RPTUN_RSC2CMD(priv->rproc.rsc_table);
|
||||
|
||||
if (priv->dev->ops->panic != NULL)
|
||||
{
|
||||
|
@ -688,11 +688,11 @@ static void rptun_panic(FAR struct rpmsg_s *rpmsg)
|
|||
|
||||
if (RPTUN_IS_MASTER(priv->dev))
|
||||
{
|
||||
rsc->cmd_master = RPTUN_CMD(RPTUN_CMD_PANIC, 0);
|
||||
cmd->cmd_master = RPTUN_CMD(RPTUN_CMD_PANIC, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
rsc->cmd_slave = RPTUN_CMD(RPTUN_CMD_PANIC, 0);
|
||||
cmd->cmd_slave = RPTUN_CMD(RPTUN_CMD_PANIC, 0);
|
||||
}
|
||||
|
||||
rptun_notify(&priv->rproc, RPTUN_NOTIFY_ALL);
|
||||
|
|
|
@ -142,6 +142,7 @@ rptun_ivshmem_get_resource(FAR struct rptun_dev_s *dev)
|
|||
{
|
||||
FAR struct rptun_ivshmem_dev_s *priv =
|
||||
(FAR struct rptun_ivshmem_dev_s *)dev;
|
||||
FAR struct rptun_cmd_s *cmd = RPTUN_RSC2CMD(&priv->shmem->rsc);
|
||||
|
||||
priv->raddrenv[0].da = 0;
|
||||
priv->raddrenv[0].size = priv->shmem_size;
|
||||
|
@ -152,18 +153,17 @@ rptun_ivshmem_get_resource(FAR struct rptun_dev_s *dev)
|
|||
|
||||
/* Wait untils salve is ready */
|
||||
|
||||
while (RPTUN_GET_CMD(priv->shmem->rsc.cmd_slave) != RPTUN_CMD_READY)
|
||||
while (RPTUN_GET_CMD(cmd->cmd_slave) != RPTUN_CMD_READY)
|
||||
{
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
priv->shmem->rsc.cmd_slave = 0;
|
||||
cmd->cmd_slave = 0;
|
||||
priv->shmem->basem = (uint64_t)(uintptr_t)priv->shmem;
|
||||
}
|
||||
else
|
||||
{
|
||||
FAR struct rptun_rsc_s *rsc = &priv->shmem->rsc;
|
||||
|
||||
memset(priv->shmem, 0, priv->shmem_size);
|
||||
|
||||
rsc->rsc_tbl_hdr.ver = 1;
|
||||
|
@ -188,10 +188,10 @@ rptun_ivshmem_get_resource(FAR struct rptun_dev_s *dev)
|
|||
rsc->rpmsg_vring1.notifyid = RSC_NOTIFY_ID_ANY;
|
||||
rsc->config.r2h_buf_size = CONFIG_RPTUN_IVSHMEM_BUFFSIZE;
|
||||
rsc->config.h2r_buf_size = CONFIG_RPTUN_IVSHMEM_BUFFSIZE;
|
||||
rsc->cmd_master = 0;
|
||||
|
||||
priv->shmem->rsc_size = sizeof(struct rptun_rsc_s);
|
||||
priv->shmem->rsc.cmd_slave = RPTUN_CMD_READY;
|
||||
cmd->cmd_master = 0;
|
||||
cmd->cmd_slave = RPTUN_CMD(RPTUN_CMD_READY, 0);
|
||||
|
||||
/* Wait untils master is ready, salve need use master base to
|
||||
* initialize addrenv.
|
||||
|
|
|
@ -57,6 +57,9 @@
|
|||
#define RPTUN_GET_CMD(c) ((c) >> RPTUN_CMD_SHIFT)
|
||||
#define RPTUN_GET_CMD_VAL(c) ((c) & RPTUN_CMD_MASK)
|
||||
|
||||
#define RPTUN_RSC2CMD(r) \
|
||||
((FAR struct rptun_cmd_s *)&((FAR struct resource_table *)(r))->reserved[0])
|
||||
|
||||
#ifdef CONFIG_OPENAMP_CACHE
|
||||
# define RPTUN_INVALIDATE(x) metal_cache_invalidate(&x, sizeof(x))
|
||||
#else
|
||||
|
@ -337,6 +340,12 @@ struct rptun_addrenv_s
|
|||
size_t size;
|
||||
};
|
||||
|
||||
begin_packed_struct struct rptun_cmd_s
|
||||
{
|
||||
uint32_t cmd_master;
|
||||
uint32_t cmd_slave;
|
||||
} end_packed_struct;
|
||||
|
||||
struct aligned_data(8) rptun_rsc_s
|
||||
{
|
||||
struct resource_table rsc_tbl_hdr;
|
||||
|
@ -346,8 +355,6 @@ struct aligned_data(8) rptun_rsc_s
|
|||
struct fw_rsc_vdev_vring rpmsg_vring0;
|
||||
struct fw_rsc_vdev_vring rpmsg_vring1;
|
||||
struct fw_rsc_config config;
|
||||
uint32_t cmd_master;
|
||||
uint32_t cmd_slave;
|
||||
};
|
||||
|
||||
struct rptun_dev_s;
|
||||
|
|
Loading…
Reference in a new issue