* [PATCH] dmaengine: mediatek: uart: synchronize completion callbacks
@ 2026-10-21 21:13 James Hilliard
2026-10-22 16:03 ` Frank Li
0 siblings, 1 reply; 2+ messages in thread
From: James Hilliard @ 2026-10-21 21:13 UTC (permalink / raw)
To: Sean Wang, Vinod Koul, Frank Li, Matthias Brugger,
AngeloGioacchino Del Regno, Long Cheng
Cc: dmaengine, linux-arm-kernel, linux-mediatek, linux-kernel,
James Hilliard
Terminating a UART APDMA channel waits for its interrupt handler, but
completion callbacks run in the virt-dma tasklet. A callback already
removed from desc_completed can still be running after termination
returns. With no device_synchronize hook, dmaengine_synchronize() does
not wait for that callback either.
Implement the hook using vchan_synchronize(). This lets clients finish
asynchronous cancellation before reusing callback state or freeing DMA
buffers. Keep the callback wait out of device_terminate_all so it can be
performed without locks acquired by the callback.
Fixes: 9135408c3ace ("dmaengine: mediatek: Add MediaTek UART APDMA support")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/dma/mediatek/mtk-uart-apdma.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c
index f74e9a328588..7583c287da5d 100644
--- a/drivers/dma/mediatek/mtk-uart-apdma.c
+++ b/drivers/dma/mediatek/mtk-uart-apdma.c
@@ -440,6 +440,13 @@ static int mtk_uart_apdma_terminate_all(struct dma_chan *chan)
return 0;
}
+static void mtk_uart_apdma_synchronize(struct dma_chan *chan)
+{
+ struct mtk_chan *c = to_mtk_uart_apdma_chan(chan);
+
+ vchan_synchronize(&c->vc);
+}
+
static int mtk_uart_apdma_device_pause(struct dma_chan *chan)
{
struct mtk_chan *c = to_mtk_uart_apdma_chan(chan);
@@ -514,6 +521,7 @@ static int mtk_uart_apdma_probe(struct platform_device *pdev)
mtkd->ddev.device_config = mtk_uart_apdma_slave_config;
mtkd->ddev.device_pause = mtk_uart_apdma_device_pause;
mtkd->ddev.device_terminate_all = mtk_uart_apdma_terminate_all;
+ mtkd->ddev.device_synchronize = mtk_uart_apdma_synchronize;
mtkd->ddev.src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE);
mtkd->ddev.dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE);
mtkd->ddev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
---
base-commit: 93f51579e7df248780214094418f205253383cc5
change-id: 20261021-submit-mtk-uart-dma-synchronize-v1-158c8303b574
Best regards,
--
James Hilliard <james.hilliard1@gmail.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] dmaengine: mediatek: uart: synchronize completion callbacks
2026-10-21 21:13 [PATCH] dmaengine: mediatek: uart: synchronize completion callbacks James Hilliard
@ 2026-10-22 16:03 ` Frank Li
0 siblings, 0 replies; 2+ messages in thread
From: Frank Li @ 2026-10-22 16:03 UTC (permalink / raw)
To: James Hilliard
Cc: Sean Wang, Vinod Koul, Frank Li, Matthias Brugger,
AngeloGioacchino Del Regno, Long Cheng, dmaengine,
linux-arm-kernel, linux-mediatek, linux-kernel
On Wed, Oct 21, 2026 at 03:13:24PM -0600, James Hilliard wrote:
> Terminating a UART APDMA channel waits for its interrupt handler, but
> completion callbacks run in the virt-dma tasklet. A callback already
> removed from desc_completed can still be running after termination
> returns. With no device_synchronize hook, dmaengine_synchronize() does
> not wait for that callback either.
>
> Implement the hook using vchan_synchronize(). This lets clients finish
> asynchronous cancellation before reusing callback state or freeing DMA
> buffers. Keep the callback wait out of device_terminate_all so it can be
> performed without locks acquired by the callback.
>
> Fixes: 9135408c3ace ("dmaengine: mediatek: Add MediaTek UART APDMA support")
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
> drivers/dma/mediatek/mtk-uart-apdma.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c
> index f74e9a328588..7583c287da5d 100644
> --- a/drivers/dma/mediatek/mtk-uart-apdma.c
> +++ b/drivers/dma/mediatek/mtk-uart-apdma.c
> @@ -440,6 +440,13 @@ static int mtk_uart_apdma_terminate_all(struct dma_chan *chan)
> return 0;
> }
>
> +static void mtk_uart_apdma_synchronize(struct dma_chan *chan)
> +{
> + struct mtk_chan *c = to_mtk_uart_apdma_chan(chan);
> +
> + vchan_synchronize(&c->vc);
Can you create vchan API, which use dma_chan as agurement like, basic
move this function into vchan-dma.h
vchan_dma_synchronize(struct dma_chan *chan)
So below callback direct use this API and avoid other drivers duplicate
this segment code.
Frank
> +}
> +
> static int mtk_uart_apdma_device_pause(struct dma_chan *chan)
> {
> struct mtk_chan *c = to_mtk_uart_apdma_chan(chan);
> @@ -514,6 +521,7 @@ static int mtk_uart_apdma_probe(struct platform_device *pdev)
> mtkd->ddev.device_config = mtk_uart_apdma_slave_config;
> mtkd->ddev.device_pause = mtk_uart_apdma_device_pause;
> mtkd->ddev.device_terminate_all = mtk_uart_apdma_terminate_all;
> + mtkd->ddev.device_synchronize = mtk_uart_apdma_synchronize;
> mtkd->ddev.src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE);
> mtkd->ddev.dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE);
> mtkd->ddev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
>
> ---
> base-commit: 93f51579e7df248780214094418f205253383cc5
> change-id: 20261021-submit-mtk-uart-dma-synchronize-v1-158c8303b574
>
> Best regards,
> --
> James Hilliard <james.hilliard1@gmail.com>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-22 16:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 21:13 [PATCH] dmaengine: mediatek: uart: synchronize completion callbacks James Hilliard
2026-10-22 16:03 ` Frank Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®