summaryrefslogtreecommitdiff
path: root/drivers/staging/dt3155v4l/dt3155-bufs.h
blob: db6d387231b2325c027e0bb8c85ce759ce322534 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/***************************************************************************
 *   Copyright (C) 2006-2010 by Marin Mitov                                *
 *   mitov@issp.bas.bg                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef _DT3155_BUFS_H_
#define _DT3155_BUFS_H_

#include <linux/pci.h>

/* 4 chunks of 4MB, 9 buffers each = 36 buffers (> VIDEO_MAX_FRAME) */
#define DT3155_CHUNK_NUM 4

/* DT3155_CHUNK_SIZE should be 4M (2^22) or less, but more than image size */
#define DT3155_CHUNK_SIZE (1U << 22)
#define DT3155_CHUNK_FLAGS (GFP_KERNEL | GFP_DMA32 | __GFP_COLD | __GFP_NOWARN)

/* DT3155_BUF_SIZE = 108 * PAGE_SIZE, so each buf is PAGE_SIZE alligned  */
#define DT3155_BUF_SIZE (768 * 576)

/**
 * struct dt3155_buf - image buffer structure
 *
 * @cpu:	virtual kernel address of the buffer
 * @dma:	dma (bus) address of the buffer
 * @next:	pointer to the next buffer in the fifo
 * @tv:		time value when the image has been acquired
 */
struct dt3155_buf {
	void *cpu;
	dma_addr_t dma;
	struct dt3155_buf *next;
	struct timeval tv;
};

/**
 * struct dt3155_fifo - fifo structure
 *
 * @head:	pointer to the head of the fifo
 * @tail:	pionter to the tail of the fifo
 * @lock:	spin_lock to protect the fifo
 */
struct dt3155_fifo {
	struct dt3155_buf *head;
	struct dt3155_buf *tail;
	spinlock_t lock;
};

struct dt3155_buf * __must_check
dt3155_init_chunks_buf(void);
void
dt3155_free_chunks_buf(struct dt3155_buf *buf);

struct dt3155_fifo * __must_check
dt3155_init_fifo(void);
#define dt3155_free_fifo(x) kfree(x)

struct dt3155_buf * __must_check
dt3155_get_buf(struct dt3155_fifo *fifo);
void
dt3155_put_buf(struct dt3155_buf *buf, struct dt3155_fifo *fifo);

struct dt3155_fifo * __must_check
dt3155_init_chunks_fifo(void);
void
dt3155_free_chunks_fifo(struct dt3155_fifo *chunks);

struct dt3155_fifo * __must_check
dt3155_init_ibufs_fifo(struct dt3155_fifo *chunks, int buf_size);
void
dt3155_free_ibufs_fifo(struct dt3155_fifo *fifo);

#endif /*  _DT3155_BUFS_H_  */