Skip to content

Commit

Permalink
rptun/rptun_ivshmem:add restart cmd to reboot slave
Browse files Browse the repository at this point in the history
Master can send restart command to slave to reboot the slave core

Signed-off-by: mazhuang <[email protected]>
Signed-off-by: Yongrong Wang <[email protected]>
  • Loading branch information
mazhuang authored and xiaoxiang781216 committed Sep 25, 2024
1 parent 75b87a8 commit 4fa1c46
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
37 changes: 37 additions & 0 deletions drivers/rptun/rptun_ivshmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
****************************************************************************/
Expand All @@ -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);
Expand 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;
Expand Down
2 changes: 2 additions & 0 deletions include/nuttx/rptun/rptun.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4fa1c46

Please sign in to comment.