xref: /linux/include/media/v4l2-fh.h (revision 8e6e8f93f7cb3452b1c00da8a30d01558628d913)
11babcb46SSakari Ailus /*
21babcb46SSakari Ailus  * v4l2-fh.h
31babcb46SSakari Ailus  *
41babcb46SSakari Ailus  * V4L2 file handle. Store per file handle data for the V4L2
51babcb46SSakari Ailus  * framework. Using file handles is optional for the drivers.
61babcb46SSakari Ailus  *
71babcb46SSakari Ailus  * Copyright (C) 2009--2010 Nokia Corporation.
81babcb46SSakari Ailus  *
98c5dff90SSakari Ailus  * Contact: Sakari Ailus <sakari.ailus@iki.fi>
101babcb46SSakari Ailus  *
111babcb46SSakari Ailus  * This program is free software; you can redistribute it and/or
121babcb46SSakari Ailus  * modify it under the terms of the GNU General Public License
131babcb46SSakari Ailus  * version 2 as published by the Free Software Foundation.
141babcb46SSakari Ailus  *
151babcb46SSakari Ailus  * This program is distributed in the hope that it will be useful, but
161babcb46SSakari Ailus  * WITHOUT ANY WARRANTY; without even the implied warranty of
171babcb46SSakari Ailus  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
181babcb46SSakari Ailus  * General Public License for more details.
191babcb46SSakari Ailus  *
201babcb46SSakari Ailus  * You should have received a copy of the GNU General Public License
211babcb46SSakari Ailus  * along with this program; if not, write to the Free Software
221babcb46SSakari Ailus  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
231babcb46SSakari Ailus  * 02110-1301 USA
241babcb46SSakari Ailus  */
251babcb46SSakari Ailus 
261babcb46SSakari Ailus #ifndef V4L2_FH_H
271babcb46SSakari Ailus #define V4L2_FH_H
281babcb46SSakari Ailus 
294f1af2a3SLaurent Pinchart #include <linux/fs.h>
301babcb46SSakari Ailus #include <linux/list.h>
31c8d185ceSLaurent Pinchart #include <linux/videodev2.h>
321babcb46SSakari Ailus 
331babcb46SSakari Ailus struct video_device;
342d28b686SHans Verkuil struct v4l2_ctrl_handler;
351babcb46SSakari Ailus 
361babcb46SSakari Ailus struct v4l2_fh {
371babcb46SSakari Ailus 	struct list_head	list;
381babcb46SSakari Ailus 	struct video_device	*vdev;
392d28b686SHans Verkuil 	struct v4l2_ctrl_handler *ctrl_handler;
40fc5602beSHans Verkuil 	enum v4l2_priority	prio;
41523f46d6SHans Verkuil 
42523f46d6SHans Verkuil 	/* Events */
43523f46d6SHans Verkuil 	wait_queue_head_t	wait;
44523f46d6SHans Verkuil 	struct list_head	subscribed; /* Subscribed events */
45523f46d6SHans Verkuil 	struct list_head	available; /* Dequeueable event */
46523f46d6SHans Verkuil 	unsigned int		navailable;
47523f46d6SHans Verkuil 	u32			sequence;
48*8e6e8f93SSylwester Nawrocki 
49*8e6e8f93SSylwester Nawrocki #if IS_ENABLED(CONFIG_V4L2_MEM2MEM_DEV)
50*8e6e8f93SSylwester Nawrocki 	struct v4l2_m2m_ctx	*m2m_ctx;
51*8e6e8f93SSylwester Nawrocki #endif
521babcb46SSakari Ailus };
531babcb46SSakari Ailus 
541babcb46SSakari Ailus /*
551babcb46SSakari Ailus  * Initialise the file handle. Parts of the V4L2 framework using the
561babcb46SSakari Ailus  * file handles should be initialised in this function. Must be called
571babcb46SSakari Ailus  * from driver's v4l2_file_operations->open() handler if the driver
581babcb46SSakari Ailus  * uses v4l2_fh.
591babcb46SSakari Ailus  */
60523f46d6SHans Verkuil void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev);
611babcb46SSakari Ailus /*
621babcb46SSakari Ailus  * Add the fh to the list of file handles on a video_device. The file
631babcb46SSakari Ailus  * handle must be initialised first.
641babcb46SSakari Ailus  */
651babcb46SSakari Ailus void v4l2_fh_add(struct v4l2_fh *fh);
661babcb46SSakari Ailus /*
6773cb4206SHans Verkuil  * Can be used as the open() op of v4l2_file_operations.
6873cb4206SHans Verkuil  * It allocates a v4l2_fh and inits and adds it to the video_device associated
6973cb4206SHans Verkuil  * with the file pointer.
7073cb4206SHans Verkuil  */
7173cb4206SHans Verkuil int v4l2_fh_open(struct file *filp);
7273cb4206SHans Verkuil /*
731babcb46SSakari Ailus  * Remove file handle from the list of file handles. Must be called in
741babcb46SSakari Ailus  * v4l2_file_operations->release() handler if the driver uses v4l2_fh.
7573cb4206SHans Verkuil  * On error filp->private_data will be NULL, otherwise it will point to
7673cb4206SHans Verkuil  * the v4l2_fh struct.
771babcb46SSakari Ailus  */
781babcb46SSakari Ailus void v4l2_fh_del(struct v4l2_fh *fh);
791babcb46SSakari Ailus /*
801babcb46SSakari Ailus  * Release resources related to a file handle. Parts of the V4L2
811babcb46SSakari Ailus  * framework using the v4l2_fh must release their resources here, too.
821babcb46SSakari Ailus  * Must be called in v4l2_file_operations->release() handler if the
831babcb46SSakari Ailus  * driver uses v4l2_fh.
841babcb46SSakari Ailus  */
851babcb46SSakari Ailus void v4l2_fh_exit(struct v4l2_fh *fh);
8673cb4206SHans Verkuil /*
8773cb4206SHans Verkuil  * Can be used as the release() op of v4l2_file_operations.
8873cb4206SHans Verkuil  * It deletes and exits the v4l2_fh associated with the file pointer and
8973cb4206SHans Verkuil  * frees it. It will do nothing if filp->private_data (the pointer to the
9073cb4206SHans Verkuil  * v4l2_fh struct) is NULL. This function always returns 0.
9173cb4206SHans Verkuil  */
9273cb4206SHans Verkuil int v4l2_fh_release(struct file *filp);
93dfddb244SHans Verkuil /*
94dfddb244SHans Verkuil  * Returns 1 if this filehandle is the only filehandle opened for the
95dfddb244SHans Verkuil  * associated video_device. If fh is NULL, then it returns 0.
96dfddb244SHans Verkuil  */
97dfddb244SHans Verkuil int v4l2_fh_is_singular(struct v4l2_fh *fh);
98dfddb244SHans Verkuil /*
99dfddb244SHans Verkuil  * Helper function with struct file as argument. If filp->private_data is
100dfddb244SHans Verkuil  * NULL, then it will return 0.
101dfddb244SHans Verkuil  */
102dfddb244SHans Verkuil static inline int v4l2_fh_is_singular_file(struct file *filp)
103dfddb244SHans Verkuil {
104dfddb244SHans Verkuil 	return v4l2_fh_is_singular(filp->private_data);
105dfddb244SHans Verkuil }
1061babcb46SSakari Ailus 
1071babcb46SSakari Ailus #endif /* V4L2_EVENT_H */
108