rptun/rptun_ivshmem:add restart cmd to reboot slave

Master can send restart command to slave to reboot the slave core

Signed-off-by: mazhuang <mazhuang@xiaomi.com>
Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
This commit is contained in:
mazhuang 2024-08-20 16:32:38 +08:00 committed by Xiang Xiao
parent 75b87a85dd
commit 4fa1c460d3
2 changed files with 39 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include <errno.h>
#include <stdio.h>
#include <nuttx/board.h>
#include <nuttx/drivers/addrenv.h>
#include <nuttx/pci/pci_ivshmem.h>
#include <nuttx/rptun/rptun.h>
@ -285,6 +286,38 @@ static int rptun_ivshmem_register_callback(FAR struct rptun_dev_s *dev,
return 0;
}
/****************************************************************************
* Name: rptun_ivshmem_check_cmd
****************************************************************************/
static void rptun_ivshmem_check_cmd(FAR struct rptun_ivshmem_dev_s *priv)
{
FAR struct rptun_cmd_s *rptun_cmd = RPTUN_RSC2CMD(&priv->shmem->rsc);
uint32_t cmd;
if (priv->master)
{
cmd = RPTUN_GET_CMD(rptun_cmd->cmd_slave);
rptun_cmd->cmd_slave = RPTUN_CMD(RPTUN_CMD_DEFAULT, 0);
}
else
{
cmd = RPTUN_GET_CMD(rptun_cmd->cmd_master);
rptun_cmd->cmd_master = RPTUN_CMD(RPTUN_CMD_DEFAULT, 0);
}
switch (cmd)
{
case RPTUN_CMD_RESTART:
#ifdef CONFIG_BOARDCTL_RESET
board_reset(0);
#endif
break;
default:
break;
}
}
/****************************************************************************
* Name: rptun_ivshmem_interrupt
****************************************************************************/
@ -293,6 +326,8 @@ static int rptun_ivshmem_interrupt(int irq, FAR void *context, FAR void *arg)
{
FAR struct rptun_ivshmem_dev_s *priv = arg;
rptun_ivshmem_check_cmd(priv);
if (priv->callback != NULL)
{
priv->callback(priv->arg, RPTUN_NOTIFY_ALL);
@ -311,6 +346,8 @@ static void rptun_ivshmem_wdog(wdparm_t arg)
(FAR struct rptun_ivshmem_dev_s *)arg;
bool should_notify = false;
rptun_ivshmem_check_cmd(priv);
if (priv->master && priv->seq != priv->shmem->seqs)
{
priv->seq = priv->shmem->seqs;

View File

@ -47,9 +47,11 @@
#define RPTUN_NOTIFY_ALL (UINT32_MAX - 0)
#define RPTUN_CMD_DEFAULT 0x0
#define RPTUN_CMD_PANIC 0x1
#define RPTUN_CMD_STOP 0x2
#define RPTUN_CMD_READY 0x3
#define RPTUN_CMD_RESTART 0x4
#define RPTUN_CMD_MASK 0xffff
#define RPTUN_CMD_SHIFT 16