blob: 930ff8d454fc9b8078badd1c9ae10de42f034a54 [file] [log] [blame]
Thomas Gleixner77512ba2019-06-03 07:44:53 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -03002/*
Guennadi Liakhovetski07051352008-04-22 14:42:13 -03003 * helper functions for SG DMA video4linux capture buffers
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -03004 *
Magnus Damm5d6aaf52008-07-16 21:27:49 -03005 * The functions expect the hardware being able to scatter gather
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -03006 * (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 *
Mauro Carvalho Chehab32590812018-04-25 05:34:48 -040010 * (c) 2007 Mauro Carvalho Chehab, <mchehab@kernel.org>
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030011 *
12 * Highly based on video-buf written originally by:
13 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
Mauro Carvalho Chehab32590812018-04-25 05:34:48 -040014 * (c) 2006 Mauro Carvalho Chehab, <mchehab@kernel.org>
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030015 * (c) 2006 Ted Walther and John Sokol
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030016 */
Pawel Osciak7a022642010-03-17 04:01:04 -030017#ifndef _VIDEOBUF_DMA_SG_H
18#define _VIDEOBUF_DMA_SG_H
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030019
20#include <media/videobuf-core.h>
21
22/* --------------------------------------------------------------------- */
23
24/*
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030025 * 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_*()
Mauro Carvalho Chehab985098a2020-06-23 09:09:10 +020034 * see Documentation/core-api/dma-api-howto.rst, these functions to
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030035 * 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;
Hans Verkuil2fc11532010-09-07 06:10:45 -030048 size_t size;
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030049 struct page **pages;
50
51 /* for kernel buffers */
Laurent Pinchartbb6dbe72010-05-11 10:36:34 -030052 void *vaddr;
James Harper7b4eeed2014-06-12 06:53:38 -030053 struct page **vaddr_pages;
54 dma_addr_t *dma_addr;
55 struct device *dev;
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030056
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030057 /* for overlay buffers (pci-pci dma) */
58 dma_addr_t bus_addr;
59
60 /* common */
61 struct scatterlist *sglist;
62 int sglen;
Mauro Carvalho Chehab1faa39e2020-09-01 11:09:26 +020063 unsigned long nr_pages;
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030064 int direction;
65};
66
Pawel Osciak7a022642010-03-17 04:01:04 -030067struct videobuf_dma_sg_memory {
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030068 u32 magic;
69
70 /* for mmap'ed buffers */
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030071 struct videobuf_dmabuf dma;
72};
73
Laurent Pinchart95268402010-05-11 10:36:30 -030074/*
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 */
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030084int videobuf_dma_free(struct videobuf_dmabuf *dma);
85
Laurent Pinchart95268402010-05-11 10:36:30 -030086int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
Pawel Osciak7a022642010-03-17 04:01:04 -030087struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf);
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030088
Guennadi Liakhovetski07051352008-04-22 14:42:13 -030089void *videobuf_sg_alloc(size_t size);
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030090
Pawel Osciak7a022642010-03-17 04:01:04 -030091void videobuf_queue_sg_init(struct videobuf_queue *q,
Jonathan Corbet38a54f32009-11-17 19:43:41 -030092 const struct videobuf_queue_ops *ops,
Guennadi Liakhovetski07051352008-04-22 14:42:13 -030093 struct device *dev,
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030094 spinlock_t *irqlock,
95 enum v4l2_buf_type type,
96 enum v4l2_field field,
97 unsigned int msize,
Hans Verkuil08bff032010-09-20 17:39:46 -030098 void *priv,
99 struct mutex *ext_lock);
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -0300100
Pawel Osciak7a022642010-03-17 04:01:04 -0300101#endif /* _VIDEOBUF_DMA_SG_H */
102