This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit f3c9a8643ba3996beef8fdeb5aa847e256a27762 Author: yintao <yin...@xiaomi.com> AuthorDate: Thu Aug 31 19:43:45 2023 +0800 nuttx: change RPTUNIOC_START and RPTUNIOC_STOP to synchronous Support quit remote when server poweroff Signed-off-by: yintao <yin...@xiaomi.com> --- arch/sim/src/sim/sim_head.c | 5 +++ arch/sim/src/sim/sim_rptun.c | 2 +- drivers/rptun/rptun.c | 78 +++++++++++++++++++++----------------------- include/nuttx/rptun/rptun.h | 1 + 4 files changed, 45 insertions(+), 41 deletions(-) diff --git a/arch/sim/src/sim/sim_head.c b/arch/sim/src/sim/sim_head.c index 9fa76c77eb..e97c2bb901 100644 --- a/arch/sim/src/sim/sim_head.c +++ b/arch/sim/src/sim/sim_head.c @@ -34,6 +34,7 @@ #include <nuttx/arch.h> #include <nuttx/board.h> #include <nuttx/symtab.h> +#include <nuttx/rptun/rptun.h> #include <nuttx/syslog/syslog_rpmsg.h> #include "sim_internal.h" @@ -201,6 +202,10 @@ int main(int argc, char **argv, char **envp) #ifdef CONFIG_BOARDCTL_POWEROFF int board_power_off(int status) { +#ifdef CONFIG_RPTUN + rptun_poweroff(NULL); +#endif + /* Abort simulator */ host_abort(status); diff --git a/arch/sim/src/sim/sim_rptun.c b/arch/sim/src/sim/sim_rptun.c index b88f05de7d..3613f19f90 100644 --- a/arch/sim/src/sim/sim_rptun.c +++ b/arch/sim/src/sim/sim_rptun.c @@ -198,7 +198,7 @@ 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); - if (priv->master & SIM_RPTUN_BOOT) + if ((priv->master & SIM_RPTUN_BOOT) && (priv->pid > 0)) { priv->shmem->cmdm = SIM_RPTUN_STOP << SIM_RPTUN_SHIFT; diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c index a70337c6be..da3f6eca83 100644 --- a/drivers/rptun/rptun.c +++ b/drivers/rptun/rptun.c @@ -68,7 +68,6 @@ struct rptun_priv_s rmutex_t lock; struct metal_list node; sem_t semtx; - unsigned long cmd; #ifdef CONFIG_RPTUN_WORKQUEUE struct work_s work; #else @@ -223,33 +222,19 @@ static inline void rptun_pm_action(FAR struct rptun_priv_s *priv, # define rptun_pm_action(priv, stay) #endif -static void rptun_worker(FAR void *arg) +static void rptun_start_worker(FAR void *arg) { FAR struct rptun_priv_s *priv = arg; - unsigned long cmd = priv->cmd; - priv->cmd = RPTUNIOC_NONE; - switch (cmd) + if (priv->rproc.state == RPROC_OFFLINE) { - case RPTUNIOC_START: - if (priv->rproc.state == RPROC_OFFLINE) - { - rptun_dev_start(&priv->rproc); - } - else - { - rptun_dev_stop(&priv->rproc, false); - rptun_dev_start(&priv->rproc); - } - break; - - case RPTUNIOC_STOP: - if (priv->rproc.state != RPROC_OFFLINE) - { - rptun_dev_stop(&priv->rproc, true); - } - break; + rptun_dev_start(&priv->rproc); } +} + +static void rptun_worker(FAR void *arg) +{ + FAR struct rptun_priv_s *priv = arg; remoteproc_get_notification(&priv->rproc, RPTUN_NOTIFY_ALL); } @@ -280,6 +265,11 @@ static int rptun_thread(int argc, FAR char *argv[]) priv = (FAR struct rptun_priv_s *)((uintptr_t)strtoul(argv[2], NULL, 16)); priv->tid = nxsched_gettid(); + if (RPTUN_IS_AUTOSTART(priv->dev)) + { + rptun_start_worker(priv); + } + while (1) { nxsem_wait_uninterruptible(&priv->semrx); @@ -724,13 +714,16 @@ static int rptun_dev_start(FAR struct remoteproc *rproc) ret = remoteproc_start(rproc); if (ret) { + rpmsg_deinit_vdev(&priv->rvdev); remoteproc_remove_virtio(rproc, vdev); + remoteproc_shutdown(rproc); return ret; } /* Register callback to mbox for receiving remote message */ RPTUN_REGISTER_CALLBACK(priv->dev, rptun_callback, priv); + rptun_wakeup_rx(priv); /* Broadcast device_created to all registers */ @@ -743,8 +736,6 @@ static int rptun_dev_start(FAR struct remoteproc *rproc) { cb->device_created(&priv->rvdev.rdev, cb->priv); } - - rptun_update_rx(priv); } nxrmutex_unlock(&g_rptun_lockcb); @@ -825,9 +816,21 @@ static int rptun_do_ioctl(FAR struct rptun_priv_s *priv, int cmd, switch (cmd) { case RPTUNIOC_START: + if (priv->rproc.state == RPROC_OFFLINE) + { + rptun_dev_start(&priv->rproc); + } + else + { + rptun_dev_stop(&priv->rproc, false); + rptun_dev_start(&priv->rproc); + } + break; case RPTUNIOC_STOP: - priv->cmd = cmd; - rptun_wakeup_rx(priv); + if (priv->rproc.state != RPROC_OFFLINE) + { + rptun_dev_stop(&priv->rproc, true); + } break; case RPTUNIOC_RESET: RPTUN_RESET(priv->dev, arg); @@ -1230,21 +1233,11 @@ int rptun_initialize(FAR struct rptun_dev_s *dev) #ifdef CONFIG_RPTUN_WORKQUEUE if (RPTUN_IS_AUTOSTART(dev)) { - priv->cmd = RPTUNIOC_START; - work_queue(HPWORK, &priv->work, rptun_worker, priv, 0); + work_queue(HPWORK, &priv->work, rptun_start_worker, priv, 0); } #else - if (RPTUN_IS_AUTOSTART(dev)) - { - priv->cmd = RPTUNIOC_START; - nxsem_init(&priv->semrx, 0, 1); - } - else - { - nxsem_init(&priv->semrx, 0, 0); - } - - snprintf(arg1, sizeof(arg1), "%p", priv); + nxsem_init(&priv->semrx, 0, 0); + snprintf(arg1, sizeof(arg1), "0x%" PRIxPTR, (uintptr_t)priv); argv[0] = (void *)RPTUN_GET_CPUNAME(dev); argv[1] = arg1; argv[2] = NULL; @@ -1282,6 +1275,11 @@ int rptun_boot(FAR const char *cpuname) return rptun_ioctl_foreach(cpuname, RPTUNIOC_START, 0); } +int rptun_poweroff(FAR const char *cpuname) +{ + return rptun_ioctl_foreach(cpuname, RPTUNIOC_STOP, 0); +} + int rptun_reset(FAR const char *cpuname, int value) { return rptun_ioctl_foreach(cpuname, RPTUNIOC_RESET, value); diff --git a/include/nuttx/rptun/rptun.h b/include/nuttx/rptun/rptun.h index 6d17377909..a27cc86582 100644 --- a/include/nuttx/rptun/rptun.h +++ b/include/nuttx/rptun/rptun.h @@ -366,6 +366,7 @@ extern "C" int rptun_initialize(FAR struct rptun_dev_s *dev); int rptun_boot(FAR const char *cpuname); +int rptun_poweroff(FAR const char *cpuname); int rptun_reset(FAR const char *cpuname, int value); int rptun_panic(FAR const char *cpuname); void rptun_dump_all(void);