blob: d8fb6012c10dfefe39ece727105a7c8168cd5110 [file] [log] [blame]
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -03001/*
Guennadi Liakhovetski07051352008-04-22 14:42:13 -03002 * helper functions for SG DMA video4linux capture buffers
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -03003 *
Magnus Damm5d6aaf52008-07-16 21:27:49 -03004 * The functions expect the hardware being able to scatter gather
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -03005 * (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 Osciak7a022642010-03-17 04:01:04 -030020#ifndef _VIDEOBUF_DMA_SG_H
21#define _VIDEOBUF_DMA_SG_H
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030022
23#include <media/videobuf-core.h>
24
25/* --------------------------------------------------------------------- */
26
27/*
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030028 * 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_*()
Paul Bolle395cf962011-08-15 02:02:26 +020037 * see Documentation/DMA-API-HOWTO.txt, these functions to
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030038 * 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
46struct videobuf_dmabuf {
47 u32 magic;
48
49 /* for userland buffer */
50 int offset;
Hans Verkuil2fc11532010-09-07 06:10:45 -030051 size_t size;
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030052 struct page **pages;
53
54 /* for kernel buffers */
Laurent Pinchartbb6dbe72010-05-11 10:36:34 -030055 void *vaddr;
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;
63 int nr_pages;
64 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 -030084void videobuf_dma_init(struct videobuf_dmabuf *dma);
85int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
86 unsigned long data, unsigned long size);
87int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
88 int nr_pages);
89int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
90 dma_addr_t addr, int nr_pages);
91int videobuf_dma_free(struct videobuf_dmabuf *dma);
92
Laurent Pinchart95268402010-05-11 10:36:30 -030093int videobuf_dma_map(struct device *dev, struct videobuf_dmabuf *dma);
94int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
Pawel Osciak7a022642010-03-17 04:01:04 -030095struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf);
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030096
Guennadi Liakhovetski07051352008-04-22 14:42:13 -030097void *videobuf_sg_alloc(size_t size);
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -030098
Pawel Osciak7a022642010-03-17 04:01:04 -030099void videobuf_queue_sg_init(struct videobuf_queue *q,
Jonathan Corbet38a54f32009-11-17 19:43:41 -0300100 const struct videobuf_queue_ops *ops,
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300101 struct device *dev,
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -0300102 spinlock_t *irqlock,
103 enum v4l2_buf_type type,
104 enum v4l2_field field,
105 unsigned int msize,
Hans Verkuil08bff032010-09-20 17:39:46 -0300106 void *priv,
107 struct mutex *ext_lock);
Mauro Carvalho Chehab7a7d9a82007-08-23 16:26:14 -0300108
Pawel Osciak7a022642010-03-17 04:01:04 -0300109#endif /* _VIDEOBUF_DMA_SG_H */
110