[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-media
Subject: [PATCH v3] media: videobuf2-dma-sg: fix vmap and vunmap callbacks
From: Michael Grzeschik <m.grzeschik () pengutronix ! de>
Date: 2023-10-31 23:04:35
Message-ID: 20231031230435.3356103-1-m.grzeschik () pengutronix ! de
[Download RAW message or body]
For dmabuf import users to be able to use the vaddr from another
videobuf2-dma-sg source, the exporter needs to set a proper vaddr on
vb2_dma_sg_dmabuf_ops_vmap callback.
This patch adds vmap on map if buf->vaddr was not set, and also
adds the vb2_dma_sg_dmabuf_ops_vunmap function to remove the mapping
afterwards.
Cc: stable@kernel.org
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
---
v2 -> v3: resend as a single patch
v1 -> v2: using vmap and vunmap instead of vm_map_ram and vm_unmap_ram
.../media/common/videobuf2/videobuf2-dma-sg.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c \
b/drivers/media/common/videobuf2/videobuf2-dma-sg.c index \
28f3fdfe23a298..05b43edda94a7e 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c
@@ -489,11 +489,26 @@ static int vb2_dma_sg_dmabuf_ops_vmap(struct dma_buf *dbuf,
{
struct vb2_dma_sg_buf *buf = dbuf->priv;
+ if (!buf->vaddr)
+ buf->vaddr = vmap(buf->pages, buf->num_pages, VM_MAP,
+ PAGE_KERNEL);
+
iosys_map_set_vaddr(map, buf->vaddr);
return 0;
}
+static void vb2_dma_sg_dmabuf_ops_vunmap(struct dma_buf *dbuf,
+ struct iosys_map *map)
+{
+ struct vb2_dma_sg_buf *buf = dbuf->priv;
+
+ if (buf->vaddr)
+ vunmap(buf->vaddr);
+
+ buf->vaddr = NULL;
+}
+
static int vb2_dma_sg_dmabuf_ops_mmap(struct dma_buf *dbuf,
struct vm_area_struct *vma)
{
@@ -508,6 +523,7 @@ static const struct dma_buf_ops vb2_dma_sg_dmabuf_ops = {
.begin_cpu_access = vb2_dma_sg_dmabuf_ops_begin_cpu_access,
.end_cpu_access = vb2_dma_sg_dmabuf_ops_end_cpu_access,
.vmap = vb2_dma_sg_dmabuf_ops_vmap,
+ .vunmap = vb2_dma_sg_dmabuf_ops_vunmap,
.mmap = vb2_dma_sg_dmabuf_ops_mmap,
.release = vb2_dma_sg_dmabuf_ops_release,
};
--
2.39.2
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic