add remote poweroff support

Signed-off-by: yintao <yintao@xiaomi.com>
This commit is contained in:
ligd 2023-07-24 23:27:23 +08:00 committed by Xiang Xiao
parent e8550a02b9
commit 378470f611
4 changed files with 69 additions and 13 deletions

View File

@ -26,6 +26,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
#include <sys/param.h> #include <sys/param.h>
#include <fcntl.h> #include <fcntl.h>
@ -130,7 +131,7 @@ static void rptun_ns_bind(FAR struct rpmsg_device *rdev,
FAR const char *name, uint32_t dest); FAR const char *name, uint32_t dest);
static int rptun_dev_start(FAR struct remoteproc *rproc); static int rptun_dev_start(FAR struct remoteproc *rproc);
static int rptun_dev_stop(FAR struct remoteproc *rproc); static int rptun_dev_stop(FAR struct remoteproc *rproc, bool stop_ns);
static int rptun_dev_ioctl(FAR struct file *filep, int cmd, static int rptun_dev_ioctl(FAR struct file *filep, int cmd,
unsigned long arg); unsigned long arg);
@ -225,25 +226,31 @@ static inline void rptun_pm_action(FAR struct rptun_priv_s *priv,
static void rptun_worker(FAR void *arg) static void rptun_worker(FAR void *arg)
{ {
FAR struct rptun_priv_s *priv = arg; FAR struct rptun_priv_s *priv = arg;
unsigned long cmd = priv->cmd;
switch (priv->cmd) priv->cmd = RPTUNIOC_NONE;
switch (cmd)
{ {
case RPTUNIOC_START: case RPTUNIOC_START:
if (priv->rproc.state == RPROC_OFFLINE) if (priv->rproc.state == RPROC_OFFLINE)
{ {
rptun_dev_start(&priv->rproc); rptun_dev_start(&priv->rproc);
} }
else
{
rptun_dev_stop(&priv->rproc, false);
rptun_dev_start(&priv->rproc);
}
break; break;
case RPTUNIOC_STOP: case RPTUNIOC_STOP:
if (priv->rproc.state != RPROC_OFFLINE) if (priv->rproc.state != RPROC_OFFLINE)
{ {
rptun_dev_stop(&priv->rproc); rptun_dev_stop(&priv->rproc, true);
} }
break; break;
} }
priv->cmd = RPTUNIOC_NONE;
remoteproc_get_notification(&priv->rproc, RPTUN_NOTIFY_ALL); remoteproc_get_notification(&priv->rproc, RPTUN_NOTIFY_ALL);
} }
@ -462,10 +469,10 @@ static int rptun_notify_wait(FAR struct remoteproc *rproc, uint32_t id)
static void *rptun_get_priv_by_rdev(FAR struct rpmsg_device *rdev) static void *rptun_get_priv_by_rdev(FAR struct rpmsg_device *rdev)
{ {
struct rpmsg_virtio_device *rvdev; FAR struct rpmsg_virtio_device *rvdev;
struct virtio_device *vdev; FAR struct virtio_device *vdev;
struct remoteproc_virtio *rpvdev; FAR struct remoteproc_virtio *rpvdev;
struct remoteproc *rproc; FAR struct remoteproc *rproc;
if (!rdev) if (!rdev)
{ {
@ -748,16 +755,33 @@ static int rptun_dev_start(FAR struct remoteproc *rproc)
return 0; return 0;
} }
static int rptun_dev_stop(FAR struct remoteproc *rproc) static int rptun_dev_stop(FAR struct remoteproc *rproc, bool stop_ns)
{ {
FAR struct rptun_priv_s *priv = rproc->priv; FAR struct rptun_priv_s *priv = rproc->priv;
FAR struct rpmsg_device *rdev = &priv->rvdev.rdev;
FAR struct metal_list *node; FAR struct metal_list *node;
FAR struct metal_list *tmp;
FAR struct rptun_cb_s *cb; FAR struct rptun_cb_s *cb;
rdev->support_ns = stop_ns;
#ifdef CONFIG_RPTUN_PING #ifdef CONFIG_RPTUN_PING
rptun_ping_deinit(&priv->ping); rptun_ping_deinit(&priv->ping);
#endif #endif
nxrmutex_lock(&priv->lock);
metal_list_for_each_safe(&priv->bind, node, tmp)
{
FAR struct rptun_bind_s *bind;
bind = metal_container_of(node, struct rptun_bind_s, node);
metal_list_del(node);
kmm_free(bind);
}
nxrmutex_unlock(&priv->lock);
/* Unregister callback from mbox */ /* Unregister callback from mbox */
RPTUN_UNREGISTER_CALLBACK(priv->dev); RPTUN_UNREGISTER_CALLBACK(priv->dev);
@ -779,15 +803,15 @@ static int rptun_dev_stop(FAR struct remoteproc *rproc)
nxrmutex_unlock(&g_rptun_lockcb); nxrmutex_unlock(&g_rptun_lockcb);
/* Remote proc stop and shutdown */
remoteproc_shutdown(rproc);
/* Remote proc remove */ /* Remote proc remove */
rpmsg_deinit_vdev(&priv->rvdev); rpmsg_deinit_vdev(&priv->rvdev);
remoteproc_remove_virtio(rproc, priv->rvdev.vdev); remoteproc_remove_virtio(rproc, priv->rvdev.vdev);
/* Remote proc stop and shutdown */
remoteproc_shutdown(rproc);
return 0; return 0;
} }

View File

@ -0,0 +1,28 @@
From f06b90cdc478124eba45b3be4f3630e8a729c51b Mon Sep 17 00:00:00 2001
From: ligd <liguiding1@xiaomi.com>
Date: Tue, 25 Jul 2023 14:25:58 +0800
Subject: [PATCH] libmetal: add metal_list_for_each_safe() support
Signed-off-by: ligd <liguiding1@xiaomi.com>
---
lib/list.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/list.h libmetal/lib/list.h
index eb0e7b3..3e8d17f 100644
--- a/lib/list.h
+++ libmetal/lib/list.h
@@ -98,6 +98,10 @@ static inline struct metal_list *metal_list_first(struct metal_list *list)
(node) != (list); \
(node) = (node)->next)
+#define metal_list_for_each_safe(list, node, temp) \
+ for(node = (list)->next, temp = node->next; \
+ node != (list); node = temp, temp = node->next)
+
static inline bool metal_list_find_node(struct metal_list *list,
struct metal_list *node)
{
--
2.25.1

View File

@ -33,6 +33,9 @@ if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/libmetal)
"" ""
INSTALL_COMMAND INSTALL_COMMAND
"" ""
PATCH_COMMAND
patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
${CMAKE_CURRENT_LIST_DIR}/0001-libmetal-add-metal_list_for_each_safe-support.patch
DOWNLOAD_NO_PROGRESS true DOWNLOAD_NO_PROGRESS true
TIMEOUT 30) TIMEOUT 30)

View File

@ -77,6 +77,7 @@ libmetal.zip:
$(call DOWNLOAD,https://github.com/OpenAMP/libmetal/archive,v$(VERSION).zip,libmetal.zip) $(call DOWNLOAD,https://github.com/OpenAMP/libmetal/archive,v$(VERSION).zip,libmetal.zip)
$(Q) unzip -o libmetal.zip $(Q) unzip -o libmetal.zip
$(Q) mv libmetal-$(VERSION) libmetal $(Q) mv libmetal-$(VERSION) libmetal
$(Q) patch -p0 < 0001-libmetal-add-metal_list_for_each_safe-support.patch
.libmetal_headers: libmetal.zip .libmetal_headers: libmetal.zip
else else