mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH 1/2] media: tegra-vde: match DMA direction on cache reuse
@ 2026-11-29 17:46 Florian Krischer
  2026-11-29 17:46 ` [RFC PATCH 2/2] media: tegra-vde: map capture planes bidirectionally Florian Krischer
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Krischer @ 2026-11-29 17:46 UTC (permalink / raw)
  To: Dmitry Osipenko, Mauro Carvalho Chehab
  Cc: Thierry Reding, Jonathan Hunter, linux-media, linux-tegra, linux-kernel

The DMA-BUF cache can reuse an attachment mapped in a different
direction. Updating the cached direction does not change the mapping,
and later unmap then uses a direction different from the original map.

Match both the DMA-BUF and its mapping direction before reusing a
cached attachment. This preserves the original direction for unmap
and keeps same-direction cache hits.

Signed-off-by: Florian Krischer <florian.krischer@fkr.dev>
---
Build-tested for ARM with W=1 on media-committers/next with the
separately submitted mutex fix applied.
Hardware testing of cross-direction DMA-BUF reuse is pending.

diff --git a/drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c b/drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c
--- a/drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c
+++ b/drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c
@@ -76,14 +76,11 @@
 	mutex_lock(&vde->map_lock);
 
 	list_for_each_entry(entry, &vde->map_list, list) {
-		if (entry->a->dmabuf != dmabuf)
+		if (entry->a->dmabuf != dmabuf || entry->dma_dir != dma_dir)
 			continue;
 
 		if (!cancel_delayed_work(&entry->dwork))
 			continue;
-
-		if (entry->dma_dir != dma_dir)
-			entry->dma_dir = DMA_BIDIRECTIONAL;
 
 		dma_buf_put(dmabuf);
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [RFC PATCH 2/2] media: tegra-vde: map capture planes bidirectionally
  2026-11-29 17:46 [RFC PATCH 1/2] media: tegra-vde: match DMA direction on cache reuse Florian Krischer
@ 2026-11-29 17:46 ` Florian Krischer
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Krischer @ 2026-11-29 17:46 UTC (permalink / raw)
  To: Dmitry Osipenko, Mauro Carvalho Chehab
  Cc: Thierry Reding, Jonathan Hunter, linux-media, linux-tegra, linux-kernel

The decoder writes pictures into CAPTURE buffers and reads those
pictures again when they are used as H.264 references. The CAPTURE
queue and the driver's DMA-BUF import path currently describe the
planes as device-write-only.

Mark the CAPTURE queue bidirectional and use the direction set by
videobuf2 for the driver's DMA-BUF imports. This keeps both mapping
paths in sync and preserves the OUTPUT direction. Leave allocation
attributes and auxiliary buffers unchanged.

Signed-off-by: Florian Krischer <florian.krischer@fkr.dev>
---
Build-tested for ARM with W=1 on media-committers/next with the
separately submitted mutex fix applied.
On an ASUS SL101 running v7.4-rc4 with the mutex fix, both the
baseline and the two-patch RFC completed three 60-frame H.264
decodes (4 I-frames, 56 P-frames) with identical I420 hashes.
Ioctl tracing confirmed MMAP CAPTURE on both kernels. Neither
run logged a new VDE warning. DMA-BUF import and cross-direction
reuse remain untested.

Does this scope make sense for CAPTURE planes? I would also welcome
feedback on cache-maintenance costs on noncoherent systems.

Thanks for taking a look.

 drivers/media/platform/nvidia/tegra-vde/v4l2.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/nvidia/tegra-vde/v4l2.c b/drivers/media/platform/nvidia/tegra-vde/v4l2.c
--- a/drivers/media/platform/nvidia/tegra-vde/v4l2.c
+++ b/drivers/media/platform/nvidia/tegra-vde/v4l2.c
@@ -151,7 +151,6 @@
 	struct tegra_ctx *ctx = vb2_get_drv_priv(vq);
 	struct tegra_m2m_buffer *tb = vb_to_tegra_buf(vb);
 	struct tegra_vde *vde = ctx->vde;
-	enum dma_data_direction dma_dir;
 	struct sg_table *sgt;
 	unsigned int i;
 	int err;
@@ -167,17 +166,12 @@
 			return err;
 	}
 
-	if (V4L2_TYPE_IS_OUTPUT(vq->type))
-		dma_dir = DMA_TO_DEVICE;
-	else
-		dma_dir = DMA_FROM_DEVICE;
-
 	for (i = 0; i < vb->num_planes; i++) {
 		if (vq->memory == VB2_MEMORY_DMABUF) {
 			get_dma_buf(vb->planes[i].dbuf);
 
 			err = tegra_vde_dmabuf_cache_map(vde, vb->planes[i].dbuf,
-							 dma_dir, &tb->a[i],
+							 vq->dma_dir, &tb->a[i],
 							 &tb->dma_base[i]);
 			if (err) {
 				dma_buf_put(vb->planes[i].dbuf);
@@ -386,6 +380,8 @@
 	dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
 	dst_vq->io_modes = VB2_DMABUF | VB2_MMAP;
 	dst_vq->lock = &vde->v4l2_lock;
+	/* VDE reads decoded pictures back as references. */
+	dst_vq->bidirectional = true;
 	dst_vq->dma_attrs = dma_attrs;
 	dst_vq->mem_ops = mem_ops;
 	dst_vq->ops = &tegra_qops;

base-commit: fb8b2c10a588f1384b98280b1c32307da9db4747

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-29 17:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 17:46 [RFC PATCH 1/2] media: tegra-vde: match DMA direction on cache reuse Florian Krischer
2026-11-29 17:46 ` [RFC PATCH 2/2] media: tegra-vde: map capture planes bidirectionally Florian Krischer

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®