forked from nuttx/nuttx-update
rpmsg_virtio: move rpmsg virtio cmd definition before the resource table
use reserved[2] in struct resource_table as the command, avoid the resource table format do not follow the standard. Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
This commit is contained in:
parent
30aa947b95
commit
d0e4c4436e
4 changed files with 36 additions and 16 deletions
|
@ -88,6 +88,7 @@ sim_rpmsg_virtio_get_resource(struct rpmsg_virtio_s *dev)
|
|||
struct sim_rpmsg_virtio_dev_s *priv =
|
||||
container_of(dev, struct sim_rpmsg_virtio_dev_s, dev);
|
||||
struct rpmsg_virtio_rsc_s *rsc;
|
||||
struct rpmsg_virtio_cmd_s *cmd;
|
||||
|
||||
priv->shmem = host_allocshmem(priv->shmemname, sizeof(*priv->shmem));
|
||||
if (!priv->shmem)
|
||||
|
@ -96,6 +97,7 @@ sim_rpmsg_virtio_get_resource(struct rpmsg_virtio_s *dev)
|
|||
}
|
||||
|
||||
rsc = &priv->shmem->rsc;
|
||||
cmd = RPMSG_VIRTIO_RSC2CMD(rsc);
|
||||
|
||||
if (priv->master)
|
||||
{
|
||||
|
@ -113,8 +115,7 @@ sim_rpmsg_virtio_get_resource(struct rpmsg_virtio_s *dev)
|
|||
rsc->rpmsg_vring1.num = 8;
|
||||
rsc->config.r2h_buf_size = 2048;
|
||||
rsc->config.h2r_buf_size = 2048;
|
||||
rsc->cmd_master = 0;
|
||||
rsc->cmd_slave = 0;
|
||||
cmd->cmd_slave = 0;
|
||||
|
||||
priv->shmem->base = (uintptr_t)priv->shmem;
|
||||
}
|
||||
|
@ -127,6 +128,7 @@ sim_rpmsg_virtio_get_resource(struct rpmsg_virtio_s *dev)
|
|||
usleep(1000);
|
||||
}
|
||||
|
||||
cmd->cmd_master = 0;
|
||||
priv->addrenv[0].va = (uintptr_t)priv->shmem;
|
||||
priv->addrenv[0].pa = priv->shmem->base;
|
||||
priv->addrenv[0].size = sizeof(*priv->shmem);
|
||||
|
|
|
@ -45,8 +45,6 @@
|
|||
#define RPMSG_VIRTIO_TIMEOUT_MS 20
|
||||
#define RPMSG_VIRTIO_NOTIFYID 0
|
||||
|
||||
#define RPMSG_VIRTIO_CMD_PANIC 0x1
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
@ -275,14 +273,15 @@ static void rpmsg_virtio_panic(FAR struct rpmsg_s *rpmsg)
|
|||
{
|
||||
FAR struct rpmsg_virtio_priv_s *priv =
|
||||
(FAR struct rpmsg_virtio_priv_s *)rpmsg;
|
||||
FAR struct rpmsg_virtio_cmd_s *cmd = RPMSG_VIRTIO_RSC2CMD(priv->rsc);
|
||||
|
||||
if (RPMSG_VIRTIO_IS_MASTER(priv->dev))
|
||||
{
|
||||
priv->rsc->cmd_master = RPMSG_VIRTIO_CMD_PANIC;
|
||||
cmd->cmd_master = RPMSG_VIRTIO_CMD(RPMSG_VIRTIO_CMD_PANIC, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
priv->rsc->cmd_slave = RPMSG_VIRTIO_CMD_PANIC;
|
||||
cmd->cmd_slave = RPMSG_VIRTIO_CMD(RPMSG_VIRTIO_CMD_PANIC, 0);
|
||||
}
|
||||
|
||||
rpmsg_virtio_notify(priv->vdev.vrings_info->vq);
|
||||
|
@ -453,21 +452,22 @@ static void rpmsg_virtio_wakeup_rx(FAR struct rpmsg_virtio_priv_s *priv)
|
|||
|
||||
static void rpmsg_virtio_command(FAR struct rpmsg_virtio_priv_s *priv)
|
||||
{
|
||||
FAR struct rpmsg_virtio_rsc_s *rsc = priv->rsc;
|
||||
FAR struct rpmsg_virtio_cmd_s *rpmsg_virtio_cmd =
|
||||
RPMSG_VIRTIO_RSC2CMD(priv->rsc);
|
||||
uint32_t cmd;
|
||||
|
||||
if (RPMSG_VIRTIO_IS_MASTER(priv->dev))
|
||||
{
|
||||
cmd = rsc->cmd_slave;
|
||||
rsc->cmd_slave = 0;
|
||||
cmd = rpmsg_virtio_cmd->cmd_slave;
|
||||
rpmsg_virtio_cmd->cmd_slave = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = rsc->cmd_master;
|
||||
rsc->cmd_master = 0;
|
||||
cmd = rpmsg_virtio_cmd->cmd_master;
|
||||
rpmsg_virtio_cmd->cmd_master = 0;
|
||||
}
|
||||
|
||||
switch (cmd)
|
||||
switch (RPMSG_VIRTIO_GET_CMD(cmd))
|
||||
{
|
||||
case RPMSG_VIRTIO_CMD_PANIC:
|
||||
PANIC();
|
||||
|
|
|
@ -127,8 +127,10 @@ rpmsg_virtio_ivshmem_get_resource(FAR struct rpmsg_virtio_s *dev)
|
|||
FAR struct rpmsg_virtio_ivshmem_dev_s *priv =
|
||||
(FAR struct rpmsg_virtio_ivshmem_dev_s *)dev;
|
||||
FAR struct rpmsg_virtio_rsc_s *rsc;
|
||||
FAR struct rpmsg_virtio_cmd_s *cmd;
|
||||
|
||||
rsc = &priv->shmem->rsc;
|
||||
cmd = RPMSG_VIRTIO_RSC2CMD(rsc);
|
||||
|
||||
if (priv->master)
|
||||
{
|
||||
|
@ -146,8 +148,7 @@ rpmsg_virtio_ivshmem_get_resource(FAR struct rpmsg_virtio_s *dev)
|
|||
rsc->rpmsg_vring1.num = CONFIG_RPMSG_VIRTIO_IVSHMEM_BUFFNUM;
|
||||
rsc->config.r2h_buf_size = CONFIG_RPMSG_VIRTIO_IVSHMEM_BUFFSIZE;
|
||||
rsc->config.h2r_buf_size = CONFIG_RPMSG_VIRTIO_IVSHMEM_BUFFSIZE;
|
||||
rsc->cmd_master = 0;
|
||||
rsc->cmd_slave = 0;
|
||||
cmd->cmd_slave = 0;
|
||||
|
||||
priv->shmem->basem = (uint64_t)(uintptr_t)priv->shmem;
|
||||
}
|
||||
|
@ -162,6 +163,7 @@ rpmsg_virtio_ivshmem_get_resource(FAR struct rpmsg_virtio_s *dev)
|
|||
usleep(1000);
|
||||
}
|
||||
|
||||
cmd->cmd_master = 0;
|
||||
priv->addrenv[0].va = (uint64_t)(uintptr_t)priv->shmem;
|
||||
priv->addrenv[0].pa = priv->shmem->basem;
|
||||
priv->addrenv[0].size = priv->shmem_size;
|
||||
|
|
|
@ -38,6 +38,18 @@
|
|||
|
||||
#define RPMSG_VIRTIO_NOTIFY_ALL UINT32_MAX
|
||||
|
||||
#define RPMSG_VIRTIO_CMD_PANIC 0x1
|
||||
#define RPMSG_VIRTIO_CMD_MASK 0xffff
|
||||
#define RPMSG_VIRTIO_CMD_SHIFT 16
|
||||
|
||||
#define RPMSG_VIRTIO_CMD(c,v) (((c) << RPMSG_VIRTIO_CMD_SHIFT) | \
|
||||
((v) & RPMSG_VIRTIO_CMD_MASK))
|
||||
#define RPMSG_VIRTIO_GET_CMD(c) ((c) >> RPMSG_VIRTIO_CMD_SHIFT)
|
||||
|
||||
#define RPMSG_VIRTIO_RSC2CMD(r) \
|
||||
((FAR struct rpmsg_virtio_cmd_s *) \
|
||||
&((FAR struct resource_table *)(r))->reserved[0])
|
||||
|
||||
/* Access macros ************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -151,6 +163,12 @@
|
|||
|
||||
typedef CODE int (*rpmsg_virtio_callback_t)(FAR void *arg, uint32_t vqid);
|
||||
|
||||
begin_packed_struct struct rpmsg_virtio_cmd_s
|
||||
{
|
||||
uint32_t cmd_master;
|
||||
uint32_t cmd_slave;
|
||||
} end_packed_struct;
|
||||
|
||||
struct aligned_data(8) rpmsg_virtio_rsc_s
|
||||
{
|
||||
struct resource_table rsc_tbl_hdr;
|
||||
|
@ -160,8 +178,6 @@ struct aligned_data(8) rpmsg_virtio_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 rpmsg_virtio_s;
|
||||
|
|
Loading…
Reference in a new issue