| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 1 | /* | 
| Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 2 |  * helper functions for SG DMA video4linux capture buffers | 
| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 3 |  * | 
| Magnus Damm | 5d6aaf5 | 2008-07-16 21:27:49 -0300 | [diff] [blame] | 4 |  * The functions expect the hardware being able to scatter gather | 
| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 5 |  * (i.e. the buffers are not linear in physical memory, but fragmented | 
 | 6 |  * into PAGE_SIZE chunks).  They also assume the driver does not need | 
 | 7 |  * to touch the video data. | 
 | 8 |  * | 
 | 9 |  * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org> | 
 | 10 |  * | 
 | 11 |  * Highly based on video-buf written originally by: | 
 | 12 |  * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org> | 
 | 13 |  * (c) 2006 Mauro Carvalho Chehab, <mchehab@infradead.org> | 
 | 14 |  * (c) 2006 Ted Walther and John Sokol | 
 | 15 |  * | 
 | 16 |  * This program is free software; you can redistribute it and/or modify | 
 | 17 |  * it under the terms of the GNU General Public License as published by | 
 | 18 |  * the Free Software Foundation; either version 2 | 
 | 19 |  */ | 
| Pawel Osciak | 7a02264 | 2010-03-17 04:01:04 -0300 | [diff] [blame] | 20 | #ifndef _VIDEOBUF_DMA_SG_H | 
 | 21 | #define _VIDEOBUF_DMA_SG_H | 
| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 22 |  | 
 | 23 | #include <media/videobuf-core.h> | 
 | 24 |  | 
 | 25 | /* --------------------------------------------------------------------- */ | 
 | 26 |  | 
 | 27 | /* | 
| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 28 |  * A small set of helper functions to manage buffers (both userland | 
 | 29 |  * and kernel) for DMA. | 
 | 30 |  * | 
 | 31 |  * videobuf_dma_init_*() | 
 | 32 |  *	creates a buffer.  The userland version takes a userspace | 
 | 33 |  *	pointer + length.  The kernel version just wants the size and | 
 | 34 |  *	does memory allocation too using vmalloc_32(). | 
 | 35 |  * | 
 | 36 |  * videobuf_dma_*() | 
| Randy Dunlap | 5872fb9 | 2009-01-29 16:28:02 -0800 | [diff] [blame] | 37 |  *	see Documentation/PCI/PCI-DMA-mapping.txt, these functions to | 
| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 38 |  *	basically the same.  The map function does also build a | 
 | 39 |  *	scatterlist for the buffer (and unmap frees it ...) | 
 | 40 |  * | 
 | 41 |  * videobuf_dma_free() | 
 | 42 |  *	no comment ... | 
 | 43 |  * | 
 | 44 |  */ | 
 | 45 |  | 
 | 46 | struct videobuf_dmabuf { | 
 | 47 | 	u32                 magic; | 
 | 48 |  | 
 | 49 | 	/* for userland buffer */ | 
 | 50 | 	int                 offset; | 
 | 51 | 	struct page         **pages; | 
 | 52 |  | 
 | 53 | 	/* for kernel buffers */ | 
| Laurent Pinchart | bb6dbe7 | 2010-05-11 10:36:34 -0300 | [diff] [blame] | 54 | 	void                *vaddr; | 
| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 55 |  | 
| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 56 | 	/* for overlay buffers (pci-pci dma) */ | 
 | 57 | 	dma_addr_t          bus_addr; | 
 | 58 |  | 
 | 59 | 	/* common */ | 
 | 60 | 	struct scatterlist  *sglist; | 
 | 61 | 	int                 sglen; | 
 | 62 | 	int                 nr_pages; | 
 | 63 | 	int                 direction; | 
 | 64 | }; | 
 | 65 |  | 
| Pawel Osciak | 7a02264 | 2010-03-17 04:01:04 -0300 | [diff] [blame] | 66 | struct videobuf_dma_sg_memory { | 
| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 67 | 	u32                 magic; | 
 | 68 |  | 
 | 69 | 	/* for mmap'ed buffers */ | 
| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 70 | 	struct videobuf_dmabuf  dma; | 
 | 71 | }; | 
 | 72 |  | 
| Laurent Pinchart | 9526840 | 2010-05-11 10:36:30 -0300 | [diff] [blame] | 73 | /* | 
 | 74 |  * Scatter-gather DMA buffer API. | 
 | 75 |  * | 
 | 76 |  * These functions provide a simple way to create a page list and a | 
 | 77 |  * scatter-gather list from a kernel, userspace of physical address and map the | 
 | 78 |  * memory for DMA operation. | 
 | 79 |  * | 
 | 80 |  * Despite the name, this is totally unrelated to videobuf, except that | 
 | 81 |  * videobuf-dma-sg uses the same API internally. | 
 | 82 |  */ | 
| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 83 | void videobuf_dma_init(struct videobuf_dmabuf *dma); | 
 | 84 | int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction, | 
 | 85 | 			   unsigned long data, unsigned long size); | 
 | 86 | int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction, | 
 | 87 | 			     int nr_pages); | 
 | 88 | int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction, | 
 | 89 | 			      dma_addr_t addr, int nr_pages); | 
 | 90 | int videobuf_dma_free(struct videobuf_dmabuf *dma); | 
 | 91 |  | 
| Laurent Pinchart | 9526840 | 2010-05-11 10:36:30 -0300 | [diff] [blame] | 92 | int videobuf_dma_map(struct device *dev, struct videobuf_dmabuf *dma); | 
 | 93 | int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma); | 
| Pawel Osciak | 7a02264 | 2010-03-17 04:01:04 -0300 | [diff] [blame] | 94 | struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf); | 
| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 95 |  | 
| Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 96 | void *videobuf_sg_alloc(size_t size); | 
| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 97 |  | 
| Pawel Osciak | 7a02264 | 2010-03-17 04:01:04 -0300 | [diff] [blame] | 98 | void videobuf_queue_sg_init(struct videobuf_queue *q, | 
| Jonathan Corbet | 38a54f3 | 2009-11-17 19:43:41 -0300 | [diff] [blame] | 99 | 			 const struct videobuf_queue_ops *ops, | 
| Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 100 | 			 struct device *dev, | 
| Mauro Carvalho Chehab | 7a7d9a8 | 2007-08-23 16:26:14 -0300 | [diff] [blame] | 101 | 			 spinlock_t *irqlock, | 
 | 102 | 			 enum v4l2_buf_type type, | 
 | 103 | 			 enum v4l2_field field, | 
 | 104 | 			 unsigned int msize, | 
 | 105 | 			 void *priv); | 
 | 106 |  | 
| Pawel Osciak | 7a02264 | 2010-03-17 04:01:04 -0300 | [diff] [blame] | 107 | #endif /* _VIDEOBUF_DMA_SG_H */ | 
 | 108 |  |