Skip to contentSkip to conversation

media: tegra-vde: match DMA direction on cache reuse

RFC PATCH New Florian Krischer 1 participant 2 messages Nov 29

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 media: tegra-vde: match DMA direction on cache reuse

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.

---
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.

drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c +1 -4
@@ -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);
 
#1 lore raw

RFC PATCH 2/2 media: tegra-vde: map capture planes bidirectionally

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.

---
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(-)
drivers/media/platform/nvidia/tegra-vde/v4l2.c +3 -7
@@ -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