• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * ispqueue.h
3  *
4  * TI OMAP3 ISP - Video buffers queue handling
5  *
6  * Copyright (C) 2010 Nokia Corporation
7  *
8  * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9  *	     Sakari Ailus <sakari.ailus@iki.fi>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2 as
13  * published by the Free Software Foundation.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23  * 02110-1301 USA
24  */
25 
26 #ifndef OMAP3_ISP_QUEUE_H
27 #define OMAP3_ISP_QUEUE_H
28 
29 #include <linux/kernel.h>
30 #include <linux/list.h>
31 #include <linux/mutex.h>
32 #include <linux/videodev2.h>
33 #include <linux/wait.h>
34 
35 struct isp_video_queue;
36 struct page;
37 struct scatterlist;
38 
39 #define ISP_VIDEO_MAX_BUFFERS		16
40 
41 /**
42  * enum isp_video_buffer_state - ISP video buffer state
43  * @ISP_BUF_STATE_IDLE:	The buffer is under userspace control (dequeued
44  *	or not queued yet).
45  * @ISP_BUF_STATE_QUEUED: The buffer has been queued but isn't used by the
46  *	device yet.
47  * @ISP_BUF_STATE_ACTIVE: The buffer is in use for an active video transfer.
48  * @ISP_BUF_STATE_ERROR: The device is done with the buffer and an error
49  *	occurred. For capture device the buffer likely contains corrupted data or
50  *	no data at all.
51  * @ISP_BUF_STATE_DONE: The device is done with the buffer and no error occurred.
52  *	For capture devices the buffer contains valid data.
53  */
54 enum isp_video_buffer_state {
55 	ISP_BUF_STATE_IDLE,
56 	ISP_BUF_STATE_QUEUED,
57 	ISP_BUF_STATE_ACTIVE,
58 	ISP_BUF_STATE_ERROR,
59 	ISP_BUF_STATE_DONE,
60 };
61 
62 /**
63  * struct isp_video_buffer - ISP video buffer
64  * @vma_use_count: Number of times the buffer is mmap'ed to userspace
65  * @stream: List head for insertion into main queue
66  * @queue: ISP buffers queue this buffer belongs to
67  * @prepared: Whether the buffer has been prepared
68  * @skip_cache: Whether to skip cache management operations for this buffer
69  * @vaddr: Memory virtual address (for kernel buffers)
70  * @vm_flags: Buffer VMA flags (for userspace buffers)
71  * @offset: Offset inside the first page (for userspace buffers)
72  * @npages: Number of pages (for userspace buffers)
73  * @pages: Pages table (for userspace non-VM_PFNMAP buffers)
74  * @paddr: Memory physical address (for userspace VM_PFNMAP buffers)
75  * @sglen: Number of elements in the scatter list (for non-VM_PFNMAP buffers)
76  * @sglist: Scatter list (for non-VM_PFNMAP buffers)
77  * @vbuf: V4L2 buffer
78  * @irqlist: List head for insertion into IRQ queue
79  * @state: Current buffer state
80  * @wait: Wait queue to signal buffer completion
81  */
82 struct isp_video_buffer {
83 	unsigned long vma_use_count;
84 	struct list_head stream;
85 	struct isp_video_queue *queue;
86 	unsigned int prepared:1;
87 	bool skip_cache;
88 
89 	/* For kernel buffers. */
90 	void *vaddr;
91 
92 	/* For userspace buffers. */
93 	vm_flags_t vm_flags;
94 	unsigned long offset;
95 	unsigned int npages;
96 	struct page **pages;
97 	dma_addr_t paddr;
98 
99 	/* For all buffers except VM_PFNMAP. */
100 	unsigned int sglen;
101 	struct scatterlist *sglist;
102 
103 	/* Touched by the interrupt handler. */
104 	struct v4l2_buffer vbuf;
105 	struct list_head irqlist;
106 	enum isp_video_buffer_state state;
107 	wait_queue_head_t wait;
108 };
109 
110 #define to_isp_video_buffer(vb)	container_of(vb, struct isp_video_buffer, vb)
111 
112 /**
113  * struct isp_video_queue_operations - Driver-specific operations
114  * @queue_prepare: Called before allocating buffers. Drivers should clamp the
115  *	number of buffers according to their requirements, and must return the
116  *	buffer size in bytes.
117  * @buffer_prepare: Called the first time a buffer is queued, or after changing
118  *	the userspace memory address for a USERPTR buffer, with the queue lock
119  *	held. Drivers should perform device-specific buffer preparation (such as
120  *	mapping the buffer memory in an IOMMU). This operation is optional.
121  * @buffer_queue: Called when a buffer is being added to the queue with the
122  *	queue irqlock spinlock held.
123  * @buffer_cleanup: Called before freeing buffers, or before changing the
124  *	userspace memory address for a USERPTR buffer, with the queue lock held.
125  *	Drivers must perform cleanup operations required to undo the
126  *	buffer_prepare call. This operation is optional.
127  */
128 struct isp_video_queue_operations {
129 	void (*queue_prepare)(struct isp_video_queue *queue,
130 			      unsigned int *nbuffers, unsigned int *size);
131 	int  (*buffer_prepare)(struct isp_video_buffer *buf);
132 	void (*buffer_queue)(struct isp_video_buffer *buf);
133 	void (*buffer_cleanup)(struct isp_video_buffer *buf);
134 };
135 
136 /**
137  * struct isp_video_queue - ISP video buffers queue
138  * @type: Type of video buffers handled by this queue
139  * @ops: Queue operations
140  * @dev: Device used for DMA operations
141  * @bufsize: Size of a driver-specific buffer object
142  * @count: Number of currently allocated buffers
143  * @buffers: ISP video buffers
144  * @lock: Mutex to protect access to the buffers, main queue and state
145  * @irqlock: Spinlock to protect access to the IRQ queue
146  * @streaming: Queue state, indicates whether the queue is streaming
147  * @queue: List of all queued buffers
148  */
149 struct isp_video_queue {
150 	enum v4l2_buf_type type;
151 	const struct isp_video_queue_operations *ops;
152 	struct device *dev;
153 	unsigned int bufsize;
154 
155 	unsigned int count;
156 	struct isp_video_buffer *buffers[ISP_VIDEO_MAX_BUFFERS];
157 	struct mutex lock;
158 	spinlock_t irqlock;
159 
160 	unsigned int streaming:1;
161 
162 	struct list_head queue;
163 };
164 
165 int omap3isp_video_queue_cleanup(struct isp_video_queue *queue);
166 int omap3isp_video_queue_init(struct isp_video_queue *queue,
167 			      enum v4l2_buf_type type,
168 			      const struct isp_video_queue_operations *ops,
169 			      struct device *dev, unsigned int bufsize);
170 
171 int omap3isp_video_queue_reqbufs(struct isp_video_queue *queue,
172 				 struct v4l2_requestbuffers *rb);
173 int omap3isp_video_queue_querybuf(struct isp_video_queue *queue,
174 				  struct v4l2_buffer *vbuf);
175 int omap3isp_video_queue_qbuf(struct isp_video_queue *queue,
176 			      struct v4l2_buffer *vbuf);
177 int omap3isp_video_queue_dqbuf(struct isp_video_queue *queue,
178 			       struct v4l2_buffer *vbuf, int nonblocking);
179 int omap3isp_video_queue_streamon(struct isp_video_queue *queue);
180 void omap3isp_video_queue_streamoff(struct isp_video_queue *queue);
181 void omap3isp_video_queue_discard_done(struct isp_video_queue *queue);
182 int omap3isp_video_queue_mmap(struct isp_video_queue *queue,
183 			      struct vm_area_struct *vma);
184 unsigned int omap3isp_video_queue_poll(struct isp_video_queue *queue,
185 				       struct file *file, poll_table *wait);
186 
187 #endif /* OMAP3_ISP_QUEUE_H */
188