armbian-build/patch/kernel/archive/spacemit-6.18/016-Revert-k1x_rproc-avoid-creating-busy-looping-mailbox.patch
Sven-Ola Tuecke 71736aaa11 Spacemit: HDMI audio fix: revert busy-loop removal, apply 1 sec timeout
Signed-off-by: Sven-Ola Tuecke <sven-ola@gmx.de>
2026-02-19 22:10:34 -05:00

132 lines
3.7 KiB
Diff

From dc256ce61874b4b90b9417500abb3bbe28c0698d Mon Sep 17 00:00:00 2001
From: Sven-Ola Tuecke <sven-ola@gmx.de>
Date: Fri, 23 Jan 2026 17:30:17 +0100
Subject: [PATCH] Revert "k1x_rproc: avoid creating busy looping mailbox
threads"
This reverts commit 57803086cdfa1df3b4fd5f66889a1f3649b2e796.
---
drivers/remoteproc/k1x-rproc.c | 51 +++++++++++++++++++++++++++++-----
1 file changed, 44 insertions(+), 7 deletions(-)
diff --git a/drivers/remoteproc/k1x-rproc.c b/drivers/remoteproc/k1x-rproc.c
index 36d3d17d4..8d0c318b5 100644
--- a/drivers/remoteproc/k1x-rproc.c
+++ b/drivers/remoteproc/k1x-rproc.c
@@ -12,6 +12,7 @@
#include <linux/reset.h>
#include <linux/clk.h>
#include <linux/clkdev.h>
+#include <linux/kthread.h>
#include <linux/clk-provider.h>
#include <linux/mailbox_client.h>
#include <linux/completion.h>
@@ -57,6 +58,8 @@ struct spacemit_mbox {
const char name[10];
struct mbox_chan *chan;
struct mbox_client client;
+ struct task_struct *mb_thread;
+ bool kthread_running;
struct completion mb_comp;
int vq_id;
};
@@ -267,6 +270,27 @@ static struct rproc_ops spacemit_rproc_ops = {
.get_boot_addr = spacemit_get_boot_addr,
};
+static int __process_theread(void *arg)
+{
+ int ret;
+ struct mbox_client *cl = arg;
+ struct rproc *rproc = dev_get_drvdata(cl->dev);
+ struct spacemit_mbox *mb = container_of(cl, struct spacemit_mbox, client);
+ struct sched_param param = {.sched_priority = 0 };
+
+ mb->kthread_running = true;
+ ret = sched_setscheduler(current, SCHED_FIFO, &param);
+
+ do {
+ wait_for_completion_timeout(&mb->mb_comp, 10);
+ if (rproc_vq_interrupt(rproc, mb->vq_id) == IRQ_NONE)
+ dev_dbg(&rproc->dev, "no message found in vq%d\n", mb->vq_id);
+ } while (!kthread_should_stop());
+
+ mb->kthread_running = false;
+
+ return 0;
+}
static void k1x_rproc_mb_callback(struct mbox_client *cl, void *data)
{
struct spacemit_mbox *mb = container_of(cl, struct spacemit_mbox, client);
@@ -281,9 +305,6 @@ static struct spacemit_mbox k1x_rpoc_mbox[] = {
.client = {
.rx_callback = k1x_rproc_mb_callback,
.tx_block = true,
- .tx_done = NULL,
- .tx_tout = 500,
- .knows_txdone = false,
},
},
{
@@ -292,10 +313,7 @@ static struct spacemit_mbox k1x_rpoc_mbox[] = {
.client = {
.rx_callback = k1x_rproc_mb_callback,
.tx_block = true,
- .tx_done = NULL,
- .tx_tout = 500,
- .knows_txdone = false,
- },
+ },
},
};
@@ -569,6 +587,12 @@ static int spacemit_rproc_probe(struct platform_device *pdev)
dev_err(dev, "failed to request mbox channel\n");
return -EINVAL;
}
+
+ if (priv->mb[i].vq_id >= 0) {
+ priv->mb[i].mb_thread = kthread_run(__process_theread, (void *)cl, name);
+ if (IS_ERR(priv->mb[i].mb_thread))
+ return PTR_ERR(priv->mb[i].mb_thread);
+ }
}
#ifdef CONFIG_PM_SLEEP
@@ -604,7 +628,13 @@ static void k1x_rproc_free_mbox(struct rproc *rproc)
static void spacemit_rproc_remove(struct platform_device *pdev)
{
+ int i = 0;
struct rproc *rproc = platform_get_drvdata(pdev);
+ struct spacemit_rproc *ddata = rproc->priv;
+
+ for (i = 0; i < MAX_MBOX; ++i)
+ if (ddata->mb[i].kthread_running)
+ kthread_stop(ddata->mb[i].mb_thread);
rproc_del(rproc);
k1x_rproc_free_mbox(rproc);
@@ -625,11 +655,18 @@ MODULE_DEVICE_TABLE(of, spacemit_rproc_of_match);
static void spacemit_rproc_shutdown(struct platform_device *pdev)
{
+ int i;
struct rproc *rproc;
struct spacemit_rproc *priv;
rproc = dev_get_drvdata(&pdev->dev);
priv = rproc->priv;
+
+ for (i = 0; i < MAX_MBOX; ++i) {
+ /* release the resource of rt thread */
+ kthread_stop(priv->mb[i].mb_thread);
+ /* mbox_free_channel(priv->mb[i].chan); */
+ }
}
static struct platform_driver spacemit_rproc_driver = {
--
2.34.1