Blame view

include/media/videobuf-core.h 7.09 KB
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  /*
   * generic helper functions for handling video4linux capture buffers
   *
   * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org>
   *
   * Highly based on video-buf written originally by:
   * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
   * (c) 2006 Mauro Carvalho Chehab, <mchehab@infradead.org>
   * (c) 2006 Ted Walther and John Sokol
   *
   * 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
   */
59d344899   Mauro Carvalho Chehab   V4L/DVB (7566): v...
15
16
  #ifndef _VIDEOBUF_CORE_H
  #define _VIDEOBUF_CORE_H
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
17
  #include <linux/poll.h>
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
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
  #include <linux/videodev2.h>
  
  #define UNSET (-1U)
  
  
  struct videobuf_buffer;
  struct videobuf_queue;
  
  /* --------------------------------------------------------------------- */
  
  /*
   * A small set of helper functions to manage video4linux buffers.
   *
   * struct videobuf_buffer holds the data structures used by the helper
   * functions, additionally some commonly used fields for v4l buffers
   * (width, height, lists, waitqueue) are in there.  That struct should
   * be used as first element in the drivers buffer struct.
   *
   * about the mmap helpers (videobuf_mmap_*):
   *
   * The mmaper function allows to map any subset of contingous buffers.
   * This includes one mmap() call for all buffers (which the original
   * video4linux API uses) as well as one mmap() for every single buffer
   * (which v4l2 uses).
   *
   * If there is a valid mapping for a buffer, buffer->baddr/bsize holds
   * userspace address + size which can be feeded into the
   * videobuf_dma_init_user function listed above.
   *
   */
  
  struct videobuf_mapping {
  	unsigned int count;
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
51
52
53
54
  	struct videobuf_queue *q;
  };
  
  enum videobuf_state {
0fc0686e6   Brandon Philips   V4L/DVB (6600): V...
55
56
57
58
59
60
61
  	VIDEOBUF_NEEDS_INIT = 0,
  	VIDEOBUF_PREPARED   = 1,
  	VIDEOBUF_QUEUED     = 2,
  	VIDEOBUF_ACTIVE     = 3,
  	VIDEOBUF_DONE       = 4,
  	VIDEOBUF_ERROR      = 5,
  	VIDEOBUF_IDLE       = 6,
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
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
89
90
91
92
93
94
  };
  
  struct videobuf_buffer {
  	unsigned int            i;
  	u32                     magic;
  
  	/* info about the buffer */
  	unsigned int            width;
  	unsigned int            height;
  	unsigned int            bytesperline; /* use only if != 0 */
  	unsigned long           size;
  	unsigned int            input;
  	enum v4l2_field         field;
  	enum videobuf_state     state;
  	struct list_head        stream;  /* QBUF/DQBUF list */
  
  	/* touched by irq handler */
  	struct list_head        queue;
  	wait_queue_head_t       done;
  	unsigned int            field_count;
  	struct timeval          ts;
  
  	/* Memory type */
  	enum v4l2_memory        memory;
  
  	/* buffer size */
  	size_t                  bsize;
  
  	/* buffer offset (mmap + overlay) */
  	size_t                  boff;
  
  	/* buffer addr (userland ptr!) */
  	unsigned long           baddr;
851c0c96b   Mauro Carvalho Chehab   V4L/DVB (6266): v...
95
96
  	/* for mmap'ed buffers */
  	struct videobuf_mapping *map;
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  	/* Private pointer to allow specific methods to store their data */
  	int			privsize;
  	void                    *priv;
  };
  
  struct videobuf_queue_ops {
  	int (*buf_setup)(struct videobuf_queue *q,
  			 unsigned int *count, unsigned int *size);
  	int (*buf_prepare)(struct videobuf_queue *q,
  			   struct videobuf_buffer *vb,
  			   enum v4l2_field field);
  	void (*buf_queue)(struct videobuf_queue *q,
  			  struct videobuf_buffer *vb);
  	void (*buf_release)(struct videobuf_queue *q,
  			    struct videobuf_buffer *vb);
  };
  
  #define MAGIC_QTYPE_OPS	0x12261003
  
  /* Helper operations - device type dependent */
  struct videobuf_qtype_ops {
  	u32                     magic;
33c38283f   Pawel Osciak   V4L/DVB: videobuf...
119
  	struct videobuf_buffer *(*alloc_vb)(size_t size);
037c75eb1   Hans Verkuil   V4L/DVB: v4l vide...
120
  	void *(*vaddr)		(struct videobuf_buffer *buf);
7a02264ca   Pawel Osciak   V4L/DVB: v4l: vid...
121
  	int (*iolock)		(struct videobuf_queue *q,
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
122
123
  				 struct videobuf_buffer *vb,
  				 struct v4l2_framebuffer *fbuf);
7a02264ca   Pawel Osciak   V4L/DVB: v4l: vid...
124
  	int (*sync)		(struct videobuf_queue *q,
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
125
  				 struct videobuf_buffer *buf);
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
126
  	int (*mmap_mapper)	(struct videobuf_queue *q,
0b62b7377   Hans Verkuil   V4L/DVB: v4l vide...
127
128
  				 struct videobuf_buffer *buf,
  				 struct vm_area_struct *vma);
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
129
130
131
  };
  
  struct videobuf_queue {
64f9477f9   Mauro Carvalho Chehab   V4L/DVB (7121): R...
132
  	struct mutex               vb_lock;
973976878   Hans Verkuil   V4L/DVB: videobuf...
133
  	struct mutex               *ext_lock;
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
134
  	spinlock_t                 *irqlock;
e9bcf6675   Guennadi Liakhovetski   V4L/DVB (7376): I...
135
  	struct device		   *dev;
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
136

137d1cb19   Brandon Philips   V4L/DVB (7493): v...
137
  	wait_queue_head_t	   wait; /* wait if queue is empty */
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
138
139
140
141
142
143
  	enum v4l2_buf_type         type;
  	unsigned int               inputs; /* for V4L2_BUF_FLAG_INPUT */
  	unsigned int               msize;
  	enum v4l2_field            field;
  	enum v4l2_field            last;   /* for field=V4L2_FIELD_ALTERNATE */
  	struct videobuf_buffer     *bufs[VIDEO_MAX_FRAME];
38a54f35a   Jonathan Corbet   V4L/DVB (13377): ...
144
  	const struct videobuf_queue_ops  *ops;
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
145
  	struct videobuf_qtype_ops  *int_ops;
d6964aa8d   Brandon Philips   V4L/DVB (6603): V...
146
147
  	unsigned int               streaming:1;
  	unsigned int               reading:1;
d05051c82   Mauro Carvalho Chehab   V4L/DVB (6997): R...
148

7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
149
  	/* capture via mmap() + ioctl(QBUF/DQBUF) */
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
150
151
152
  	struct list_head           stream;
  
  	/* capture via read() */
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
153
154
155
156
157
  	unsigned int               read_off;
  	struct videobuf_buffer     *read_buf;
  
  	/* driver private data */
  	void                       *priv_data;
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
158
  };
973976878   Hans Verkuil   V4L/DVB: videobuf...
159
160
161
162
163
164
165
166
167
168
169
  static inline void videobuf_queue_lock(struct videobuf_queue *q)
  {
  	if (!q->ext_lock)
  		mutex_lock(&q->vb_lock);
  }
  
  static inline void videobuf_queue_unlock(struct videobuf_queue *q)
  {
  	if (!q->ext_lock)
  		mutex_unlock(&q->vb_lock);
  }
0e0809a58   Hans Verkuil   V4L/DVB: videobuf...
170
171
  int videobuf_waiton(struct videobuf_queue *q, struct videobuf_buffer *vb,
  		int non_blocking, int intr);
7a02264ca   Pawel Osciak   V4L/DVB: v4l: vid...
172
  int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
173
  		struct v4l2_framebuffer *fbuf);
33c38283f   Pawel Osciak   V4L/DVB: videobuf...
174
  struct videobuf_buffer *videobuf_alloc_vb(struct videobuf_queue *q);
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
175

59d344899   Mauro Carvalho Chehab   V4L/DVB (7566): v...
176
  /* Used on videobuf-dvb */
f4fce60e8   Hans Verkuil   V4L/DVB: v4l vide...
177
178
  void *videobuf_queue_to_vaddr(struct videobuf_queue *q,
  			      struct videobuf_buffer *buf);
59d344899   Mauro Carvalho Chehab   V4L/DVB (7566): v...
179

d4cae5a50   Mauro Carvalho Chehab   V4L/DVB (6292): v...
180
  void videobuf_queue_core_init(struct videobuf_queue *q,
38a54f35a   Jonathan Corbet   V4L/DVB (13377): ...
181
  			 const struct videobuf_queue_ops *ops,
e9bcf6675   Guennadi Liakhovetski   V4L/DVB (7376): I...
182
  			 struct device *dev,
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
183
184
185
186
  			 spinlock_t *irqlock,
  			 enum v4l2_buf_type type,
  			 enum v4l2_field field,
  			 unsigned int msize,
d4cae5a50   Mauro Carvalho Chehab   V4L/DVB (6292): v...
187
  			 void *priv,
08bff03ed   Hans Verkuil   V4L/DVB: videobuf...
188
189
  			 struct videobuf_qtype_ops *int_ops,
  			 struct mutex *ext_lock);
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
190
191
192
193
194
195
196
197
198
199
200
  int  videobuf_queue_is_busy(struct videobuf_queue *q);
  void videobuf_queue_cancel(struct videobuf_queue *q);
  
  enum v4l2_field videobuf_next_field(struct videobuf_queue *q);
  int videobuf_reqbufs(struct videobuf_queue *q,
  		     struct v4l2_requestbuffers *req);
  int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b);
  int videobuf_qbuf(struct videobuf_queue *q,
  		  struct v4l2_buffer *b);
  int videobuf_dqbuf(struct videobuf_queue *q,
  		   struct v4l2_buffer *b, int nonblocking);
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
201
202
  int videobuf_streamon(struct videobuf_queue *q);
  int videobuf_streamoff(struct videobuf_queue *q);
19bc5133d   Brandon Philips   V4L/DVB (6601): V...
203
  void videobuf_stop(struct videobuf_queue *q);
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
  int videobuf_read_start(struct videobuf_queue *q);
  void videobuf_read_stop(struct videobuf_queue *q);
  ssize_t videobuf_read_stream(struct videobuf_queue *q,
  			     char __user *data, size_t count, loff_t *ppos,
  			     int vbihack, int nonblocking);
  ssize_t videobuf_read_one(struct videobuf_queue *q,
  			  char __user *data, size_t count, loff_t *ppos,
  			  int nonblocking);
  unsigned int videobuf_poll_stream(struct file *file,
  				  struct videobuf_queue *q,
  				  poll_table *wait);
  
  int videobuf_mmap_setup(struct videobuf_queue *q,
  			unsigned int bcount, unsigned int bsize,
  			enum v4l2_memory memory);
81b2dbcad   Arjan van de Ven   Fix a deadlock in...
219
220
221
  int __videobuf_mmap_setup(struct videobuf_queue *q,
  			unsigned int bcount, unsigned int bsize,
  			enum v4l2_memory memory);
7a7d9a89d   Mauro Carvalho Chehab   V4L/DVB (6251): R...
222
223
224
  int videobuf_mmap_free(struct videobuf_queue *q);
  int videobuf_mmap_mapper(struct videobuf_queue *q,
  			 struct vm_area_struct *vma);
59d344899   Mauro Carvalho Chehab   V4L/DVB (7566): v...
225
  #endif