rptun.c/rpmsg_virtio.c: move panic logic from chip to rptun/rpmsg_virtio
Move the panic logic in common places, later we can move more logic to the framework instead of having the drivers implement it repeatedly. Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com> Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
parent
9cceccb14a
commit
7c7d08d13a
8 changed files with 112 additions and 5 deletions
|
@ -115,6 +115,8 @@ 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;
|
||||
|
||||
priv->shmem->base = (uintptr_t)priv->shmem;
|
||||
}
|
||||
|
|
|
@ -148,6 +148,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;
|
||||
|
||||
priv->shmem->base = (uintptr_t)priv->shmem;
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
#define RPMSG_VIRTIO_TIMEOUT_MS 20
|
||||
#define RPMSG_VIRTIO_NOTIFYID 0
|
||||
|
||||
#define RPMSG_VIRTIO_CMD_PANIC 0x1
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
@ -69,6 +71,7 @@ struct rpmsg_virtio_priv_s
|
|||
|
||||
static int rpmsg_virtio_wait(FAR struct rpmsg_s *rpmsg, FAR sem_t *sem);
|
||||
static int rpmsg_virtio_post(FAR struct rpmsg_s *rpmsg, FAR sem_t *sem);
|
||||
static void rpmsg_virtio_panic(FAR struct rpmsg_s *rpmsg);
|
||||
static void rpmsg_virtio_dump(FAR struct rpmsg_s *rpmsg);
|
||||
static FAR const char *
|
||||
rpmsg_virtio_get_local_cpuname(FAR struct rpmsg_s *rpmsg);
|
||||
|
@ -97,6 +100,7 @@ static const struct rpmsg_ops_s g_rpmsg_virtio_ops =
|
|||
{
|
||||
.wait = rpmsg_virtio_wait,
|
||||
.post = rpmsg_virtio_post,
|
||||
.panic = rpmsg_virtio_panic,
|
||||
.dump = rpmsg_virtio_dump,
|
||||
.get_local_cpuname = rpmsg_virtio_get_local_cpuname,
|
||||
.get_cpuname = rpmsg_virtio_get_cpuname,
|
||||
|
@ -267,6 +271,23 @@ static int rpmsg_virtio_post(FAR struct rpmsg_s *rpmsg, FAR sem_t *sem)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void rpmsg_virtio_panic(FAR struct rpmsg_s *rpmsg)
|
||||
{
|
||||
FAR struct rpmsg_virtio_priv_s *priv =
|
||||
(FAR struct rpmsg_virtio_priv_s *)rpmsg;
|
||||
|
||||
if (RPMSG_VIRTIO_IS_MASTER(priv->dev))
|
||||
{
|
||||
priv->rsc->cmd_master = RPMSG_VIRTIO_CMD_PANIC;
|
||||
}
|
||||
else
|
||||
{
|
||||
priv->rsc->cmd_slave = RPMSG_VIRTIO_CMD_PANIC;
|
||||
}
|
||||
|
||||
rpmsg_virtio_notify(priv->vdev.vrings_info->vq);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_OPENAMP_DEBUG
|
||||
static int rpmsg_virtio_buffer_nused(FAR struct rpmsg_virtio_device *rvdev,
|
||||
bool rx)
|
||||
|
@ -430,6 +451,33 @@ 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;
|
||||
uint32_t cmd;
|
||||
|
||||
if (RPMSG_VIRTIO_IS_MASTER(priv->dev))
|
||||
{
|
||||
cmd = rsc->cmd_slave;
|
||||
rsc->cmd_slave = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = rsc->cmd_master;
|
||||
rsc->cmd_master = 0;
|
||||
}
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case RPMSG_VIRTIO_CMD_PANIC:
|
||||
PANIC();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int rpmsg_virtio_callback(FAR void *arg, uint32_t vqid)
|
||||
{
|
||||
FAR struct rpmsg_virtio_priv_s *priv = arg;
|
||||
|
@ -437,6 +485,8 @@ static int rpmsg_virtio_callback(FAR void *arg, uint32_t vqid)
|
|||
FAR struct virtio_device *vdev = rvdev->vdev;
|
||||
FAR struct virtqueue *rvq = rvdev->rvq;
|
||||
|
||||
rpmsg_virtio_command(priv);
|
||||
|
||||
if (vqid == RPMSG_VIRTIO_NOTIFY_ALL ||
|
||||
vqid == vdev->vrings_info[rvq->vq_queue_index].notifyid)
|
||||
{
|
||||
|
|
|
@ -148,6 +148,8 @@ 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;
|
||||
|
||||
priv->shmem->basem = (uint64_t)(uintptr_t)priv->shmem;
|
||||
}
|
||||
|
|
|
@ -52,10 +52,10 @@
|
|||
# define ALIGN_UP(s, a) (((s) + (a) - 1) & ~((a) - 1))
|
||||
#endif
|
||||
|
||||
#define RPTUNIOC_NONE 0
|
||||
|
||||
#define RPTUN_TIMEOUT_MS 20
|
||||
|
||||
#define RPTUN_CMD_PANIC 0x1
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
@ -372,6 +372,33 @@ static bool rptun_is_recursive(FAR struct rptun_priv_s *priv)
|
|||
return nxsched_gettid() == priv->tid;
|
||||
}
|
||||
|
||||
static void rptun_command(FAR struct rptun_priv_s *priv)
|
||||
{
|
||||
FAR struct rptun_rsc_s *rsc = priv->rproc.rsc_table;
|
||||
uint32_t cmd;
|
||||
|
||||
if (RPTUN_IS_MASTER(priv->dev))
|
||||
{
|
||||
cmd = rsc->cmd_slave;
|
||||
rsc->cmd_slave = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = rsc->cmd_master;
|
||||
rsc->cmd_master = 0;
|
||||
}
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case RPTUN_CMD_PANIC:
|
||||
PANIC();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int rptun_callback(FAR void *arg, uint32_t vqid)
|
||||
{
|
||||
FAR struct rptun_priv_s *priv = arg;
|
||||
|
@ -380,6 +407,8 @@ static int rptun_callback(FAR void *arg, uint32_t vqid)
|
|||
FAR struct virtqueue *svq = rvdev->svq;
|
||||
FAR struct virtqueue *rvq = rvdev->rvq;
|
||||
|
||||
rptun_command(priv);
|
||||
|
||||
if (vqid == RPTUN_NOTIFY_ALL ||
|
||||
vqid == vdev->vrings_info[rvq->vq_queue_index].notifyid)
|
||||
{
|
||||
|
@ -651,8 +680,24 @@ 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;
|
||||
|
||||
RPTUN_PANIC(priv->dev);
|
||||
if (priv->dev->ops->panic != NULL)
|
||||
{
|
||||
RPTUN_PANIC(priv->dev);
|
||||
return;
|
||||
}
|
||||
|
||||
if (RPTUN_IS_MASTER(priv->dev))
|
||||
{
|
||||
rsc->cmd_master = RPTUN_CMD_PANIC;
|
||||
}
|
||||
else
|
||||
{
|
||||
rsc->cmd_slave = RPTUN_CMD_PANIC;
|
||||
}
|
||||
|
||||
rptun_notify(&priv->rproc, RPTUN_NOTIFY_ALL);
|
||||
}
|
||||
|
||||
static void rptun_dump(FAR struct rpmsg_s *rpmsg)
|
||||
|
|
|
@ -191,6 +191,8 @@ 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;
|
||||
rsc->cmd_slave = 0;
|
||||
|
||||
priv->shmem->rsc_size = sizeof(struct rptun_rsc_s);
|
||||
priv->shmem->cmds = RPTUN_IVSHMEM_READY;
|
||||
|
|
|
@ -160,6 +160,8 @@ 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;
|
||||
|
|
|
@ -294,7 +294,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#define RPTUN_RESET(d,v) ((d)->ops->reset ? \
|
||||
(d)->ops->reset(d,v) : -ENOSYS)
|
||||
(d)->ops->reset(d,v) : UNUSED(d))
|
||||
|
||||
/****************************************************************************
|
||||
* Name: RPTUN_PANIC
|
||||
|
@ -311,7 +311,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#define RPTUN_PANIC(d) ((d)->ops->panic ? \
|
||||
(d)->ops->panic(d) : -ENOSYS)
|
||||
(d)->ops->panic(d) : UNUSED(d))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
|
@ -335,6 +335,8 @@ 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