Thomas Gleixner | 77512ba | 2019-06-03 07:44:53 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 2 | /* |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 3 | * helper functions for SG DMA video4linux capture buffers |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 4 | * |
Magnus Damm | 5d6aaf5 | 2008-07-16 21:27:49 -0300 | [diff] [blame] | 5 | * The functions expect the hardware being able to scatter gather |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 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 | * |
Mauro Carvalho Chehab | 3259081 | 2018-04-25 05:34:48 -0400 | [diff] [blame] | 10 | * (c) 2007 Mauro Carvalho Chehab, <mchehab@kernel.org> |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 11 | * |
| 12 | * Highly based on video-buf written originally by: |
| 13 | * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org> |
Mauro Carvalho Chehab | 3259081 | 2018-04-25 05:34:48 -0400 | [diff] [blame] | 14 | * (c) 2006 Mauro Carvalho Chehab, <mchehab@kernel.org> |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 15 | * (c) 2006 Ted Walther and John Sokol |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 16 | */ |
Pawel Osciak | 7a02264 | 2010-03-17 04:01:04 -0300 | [diff] [blame] | 17 | #ifndef _VIDEOBUF_DMA_SG_H |
| 18 | #define _VIDEOBUF_DMA_SG_H |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 19 | |
| 20 | #include <media/videobuf-core.h> |
| 21 | |
| 22 | /* --------------------------------------------------------------------- */ |
| 23 | |
| 24 | /* |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 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_*() |
Mauro Carvalho Chehab | 985098a | 2020-06-23 09:09:10 +0200 | [diff] [blame] | 34 | * see Documentation/core-api/dma-api-howto.rst, these functions to |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 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 | |
| 43 | struct videobuf_dmabuf { |
| 44 | u32 magic; |
| 45 | |
| 46 | /* for userland buffer */ |
| 47 | int offset; |
Hans Verkuil | 2fc1153 | 2010-09-07 06:10:45 -0300 | [diff] [blame] | 48 | size_t size; |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 49 | struct page **pages; |
| 50 | |
| 51 | /* for kernel buffers */ |
Laurent Pinchart | bb6dbe7 | 2010-05-11 10:36:34 -0300 | [diff] [blame] | 52 | void *vaddr; |
James Harper | 7b4eeed | 2014-06-12 06:53:38 -0300 | [diff] [blame] | 53 | struct page **vaddr_pages; |
| 54 | dma_addr_t *dma_addr; |
| 55 | struct device *dev; |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 56 | |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 57 | /* for overlay buffers (pci-pci dma) */ |
| 58 | dma_addr_t bus_addr; |
| 59 | |
| 60 | /* common */ |
| 61 | struct scatterlist *sglist; |
| 62 | int sglen; |
Mauro Carvalho Chehab | 1faa39e | 2020-09-01 11:09:26 +0200 | [diff] [blame] | 63 | unsigned long nr_pages; |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 64 | int direction; |
| 65 | }; |
| 66 | |
Pawel Osciak | 7a02264 | 2010-03-17 04:01:04 -0300 | [diff] [blame] | 67 | struct videobuf_dma_sg_memory { |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 68 | u32 magic; |
| 69 | |
| 70 | /* for mmap'ed buffers */ |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 71 | struct videobuf_dmabuf dma; |
| 72 | }; |
| 73 | |
Laurent Pinchart | 9526840 | 2010-05-11 10:36:30 -0300 | [diff] [blame] | 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 | */ |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 84 | int videobuf_dma_free(struct videobuf_dmabuf *dma); |
| 85 | |
Laurent Pinchart | 9526840 | 2010-05-11 10:36:30 -0300 | [diff] [blame] | 86 | int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma); |
Pawel Osciak | 7a02264 | 2010-03-17 04:01:04 -0300 | [diff] [blame] | 87 | struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf); |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 88 | |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 89 | void *videobuf_sg_alloc(size_t size); |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 90 | |
Pawel Osciak | 7a02264 | 2010-03-17 04:01:04 -0300 | [diff] [blame] | 91 | void videobuf_queue_sg_init(struct videobuf_queue *q, |
Jonathan Corbet | 38a54f3 | 2009-11-17 19:43:41 -0300 | [diff] [blame] | 92 | const struct videobuf_queue_ops *ops, |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 93 | struct device *dev, |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 94 | spinlock_t *irqlock, |
| 95 | enum v4l2_buf_type type, |
| 96 | enum v4l2_field field, |
| 97 | unsigned int msize, |
Hans Verkuil | 08bff03 | 2010-09-20 17:39:46 -0300 | [diff] [blame] | 98 | void *priv, |
| 99 | struct mutex *ext_lock); |
Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 100 | |
Pawel Osciak | 7a02264 | 2010-03-17 04:01:04 -0300 | [diff] [blame] | 101 | #endif /* _VIDEOBUF_DMA_SG_H */ |
| 102 | |