1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * helper functions for SG DMA video4linux capture buffers
5 * The functions expect the hardware being able to scatter gather
6 * (i.e. the buffers are not linear in physical memory, but fragmented
7 * into PAGE_SIZE chunks). They also assume the driver does not need
8 * to touch the video data.
10 * (c) 2007 Mauro Carvalho Chehab, <mchehab@kernel.org>
12 * Highly based on video-buf written originally by:
13 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
14 * (c) 2006 Mauro Carvalho Chehab, <mchehab@kernel.org>
15 * (c) 2006 Ted Walther and John Sokol
17 #ifndef _VIDEOBUF_DMA_SG_H
18 #define _VIDEOBUF_DMA_SG_H
20 #include <media/videobuf-core.h>
22 /* --------------------------------------------------------------------- */
25 * A small set of helper functions to manage buffers (both userland
26 * and kernel) for DMA.
28 * videobuf_dma_init_*()
29 * creates a buffer. The userland version takes a userspace
30 * pointer + length. The kernel version just wants the size and
31 * does memory allocation too using vmalloc_32().
34 * see Documentation/core-api/dma-api-howto.rst, these functions to
35 * basically the same. The map function does also build a
36 * scatterlist for the buffer (and unmap frees it ...)
43 struct videobuf_dmabuf {
46 /* for userland buffer */
51 /* for kernel buffers */
53 struct page **vaddr_pages;
57 /* for overlay buffers (pci-pci dma) */
61 struct scatterlist *sglist;
63 unsigned long nr_pages;
67 struct videobuf_dma_sg_memory {
70 /* for mmap'ed buffers */
71 struct videobuf_dmabuf dma;
75 * Scatter-gather DMA buffer API.
77 * These functions provide a simple way to create a page list and a
78 * scatter-gather list from a kernel, userspace of physical address and map the
79 * memory for DMA operation.
81 * Despite the name, this is totally unrelated to videobuf, except that
82 * videobuf-dma-sg uses the same API internally.
84 int videobuf_dma_free(struct videobuf_dmabuf *dma);
86 int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
87 struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf);
89 void *videobuf_sg_alloc(size_t size);
91 void videobuf_queue_sg_init(struct videobuf_queue *q,
92 const struct videobuf_queue_ops *ops,
95 enum v4l2_buf_type type,
96 enum v4l2_field field,
99 struct mutex *ext_lock);
101 #endif /* _VIDEOBUF_DMA_SG_H */