aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/v4l2-dev.c
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2010-12-29 08:05:02 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-03-22 15:37:54 -0400
commit022654930891c7ddfdb1ea34d6c4af9d1096bf91 (patch)
tree396edb9d7c4dcde4e862e89b2ed4b770ad830462 /drivers/media/video/v4l2-dev.c
parent8c1476ffc0b820f6ca8cc0b3f50c8a0f57e8d82d (diff)
[media] v4l2_prio: move from v4l2-common to v4l2-dev
We are going to move priority handling into the v4l2 core. As a consequence the v4l2_prio helper functions need to be moved into the core videodev module as well to prevent circular dependencies. Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/v4l2-dev.c')
-rw-r--r--drivers/media/video/v4l2-dev.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index e405b8094b94..65d546f35ef4 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -182,6 +182,70 @@ struct video_device *video_devdata(struct file *file)
182} 182}
183EXPORT_SYMBOL(video_devdata); 183EXPORT_SYMBOL(video_devdata);
184 184
185
186/* Priority handling */
187
188static inline bool prio_is_valid(enum v4l2_priority prio)
189{
190 return prio == V4L2_PRIORITY_BACKGROUND ||
191 prio == V4L2_PRIORITY_INTERACTIVE ||
192 prio == V4L2_PRIORITY_RECORD;
193}
194
195void v4l2_prio_init(struct v4l2_prio_state *global)
196{
197 memset(global, 0, sizeof(*global));
198}
199EXPORT_SYMBOL(v4l2_prio_init);
200
201int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
202 enum v4l2_priority new)
203{
204 if (!prio_is_valid(new))
205 return -EINVAL;
206 if (*local == new)
207 return 0;
208
209 atomic_inc(&global->prios[new]);
210 if (prio_is_valid(*local))
211 atomic_dec(&global->prios[*local]);
212 *local = new;
213 return 0;
214}
215EXPORT_SYMBOL(v4l2_prio_change);
216
217void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
218{
219 v4l2_prio_change(global, local, V4L2_PRIORITY_DEFAULT);
220}
221EXPORT_SYMBOL(v4l2_prio_open);
222
223void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local)
224{
225 if (prio_is_valid(local))
226 atomic_dec(&global->prios[local]);
227}
228EXPORT_SYMBOL(v4l2_prio_close);
229
230enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
231{
232 if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
233 return V4L2_PRIORITY_RECORD;
234 if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
235 return V4L2_PRIORITY_INTERACTIVE;
236 if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
237 return V4L2_PRIORITY_BACKGROUND;
238 return V4L2_PRIORITY_UNSET;
239}
240EXPORT_SYMBOL(v4l2_prio_max);
241
242int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local)
243{
244 return (local < v4l2_prio_max(global)) ? -EBUSY : 0;
245}
246EXPORT_SYMBOL(v4l2_prio_check);
247
248
185static ssize_t v4l2_read(struct file *filp, char __user *buf, 249static ssize_t v4l2_read(struct file *filp, char __user *buf,
186 size_t sz, loff_t *off) 250 size_t sz, loff_t *off)
187{ 251{