mm: Don't pin ZERO_PAGE in pin_user_pages()
[linux-block.git] / include / media / videobuf-dma-sg.h
CommitLineData
77512baa 1/* SPDX-License-Identifier: GPL-2.0-only */
7a7d9a89 2/*
0705135e 3 * helper functions for SG DMA video4linux capture buffers
7a7d9a89 4 *
5d6aaf50 5 * The functions expect the hardware being able to scatter gather
7a7d9a89
MCC
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.
9 *
32590819 10 * (c) 2007 Mauro Carvalho Chehab, <mchehab@kernel.org>
7a7d9a89
MCC
11 *
12 * Highly based on video-buf written originally by:
13 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
32590819 14 * (c) 2006 Mauro Carvalho Chehab, <mchehab@kernel.org>
7a7d9a89 15 * (c) 2006 Ted Walther and John Sokol
7a7d9a89 16 */
7a02264c
PO
17#ifndef _VIDEOBUF_DMA_SG_H
18#define _VIDEOBUF_DMA_SG_H
7a7d9a89
MCC
19
20#include <media/videobuf-core.h>
21
22/* --------------------------------------------------------------------- */
23
7a7d9a89
MCC
24/*
25 * A small set of helper functions to manage buffers (both userland
26 * and kernel) for DMA.
27 *
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().
32 *
33 * videobuf_dma_*()
985098a0 34 * see Documentation/core-api/dma-api-howto.rst, these functions to
7a7d9a89
MCC
35 * basically the same. The map function does also build a
36 * scatterlist for the buffer (and unmap frees it ...)
37 *
38 * videobuf_dma_free()
39 * no comment ...
40 *
41 */
42
43struct videobuf_dmabuf {
44 u32 magic;
45
46 /* for userland buffer */
47 int offset;
2fc11536 48 size_t size;
7a7d9a89
MCC
49 struct page **pages;
50
51 /* for kernel buffers */
bb6dbe74 52 void *vaddr;
7b4eeed1
JH
53 struct page **vaddr_pages;
54 dma_addr_t *dma_addr;
55 struct device *dev;
7a7d9a89 56
7a7d9a89
MCC
57 /* for overlay buffers (pci-pci dma) */
58 dma_addr_t bus_addr;
59
60 /* common */
61 struct scatterlist *sglist;
62 int sglen;
1faa39e0 63 unsigned long nr_pages;
7a7d9a89
MCC
64 int direction;
65};
66
7a02264c 67struct videobuf_dma_sg_memory {
7a7d9a89
MCC
68 u32 magic;
69
70 /* for mmap'ed buffers */
7a7d9a89
MCC
71 struct videobuf_dmabuf dma;
72};
73
95268403
LP
74/*
75 * Scatter-gather DMA buffer API.
76 *
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.
80 *
81 * Despite the name, this is totally unrelated to videobuf, except that
82 * videobuf-dma-sg uses the same API internally.
83 */
7a7d9a89
MCC
84int videobuf_dma_free(struct videobuf_dmabuf *dma);
85
95268403 86int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
7a02264c 87struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf);
7a7d9a89 88
0705135e 89void *videobuf_sg_alloc(size_t size);
7a7d9a89 90
7a02264c 91void videobuf_queue_sg_init(struct videobuf_queue *q,
38a54f35 92 const struct videobuf_queue_ops *ops,
0705135e 93 struct device *dev,
7a7d9a89
MCC
94 spinlock_t *irqlock,
95 enum v4l2_buf_type type,
96 enum v4l2_field field,
97 unsigned int msize,
08bff03e
HV
98 void *priv,
99 struct mutex *ext_lock);
7a7d9a89 100
7a02264c
PO
101#endif /* _VIDEOBUF_DMA_SG_H */
102