xref: /linux/include/media/v4l2-fh.h (revision 4ada120eaa2d57378b9c270273e8c0b7e542f019)
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 
36*4ada120eSMauro Carvalho Chehab /**
37*4ada120eSMauro Carvalho Chehab  * struct v4l2_fh - Describes a V4L2 file handler
38*4ada120eSMauro Carvalho Chehab  *
39*4ada120eSMauro Carvalho Chehab  * @list: list of file handlers
40*4ada120eSMauro Carvalho Chehab  * @vdev: pointer to &struct video_device
41*4ada120eSMauro Carvalho Chehab  * @ctrl_handler: pointer to &struct v4l2_ctrl_handler
42*4ada120eSMauro Carvalho Chehab  * @prio: priority of the file handler, as defined by &enum v4l2_priority
43*4ada120eSMauro Carvalho Chehab  *
44*4ada120eSMauro Carvalho Chehab  * @wait: event' s wait queue
45*4ada120eSMauro Carvalho Chehab  * @subscribed: list of subscribed events
46*4ada120eSMauro Carvalho Chehab  * @available: list of events waiting to be dequeued
47*4ada120eSMauro Carvalho Chehab  * @navailable: number of available events at @available list
48*4ada120eSMauro Carvalho Chehab  * @sequence: event sequence number
49*4ada120eSMauro Carvalho Chehab  * @m2m_ctx: pointer to &struct v4l2_m2m_ctx
50*4ada120eSMauro Carvalho Chehab  */
511babcb46SSakari Ailus struct v4l2_fh {
521babcb46SSakari Ailus 	struct list_head	list;
531babcb46SSakari Ailus 	struct video_device	*vdev;
542d28b686SHans Verkuil 	struct v4l2_ctrl_handler *ctrl_handler;
55fc5602beSHans Verkuil 	enum v4l2_priority	prio;
56523f46d6SHans Verkuil 
57523f46d6SHans Verkuil 	/* Events */
58523f46d6SHans Verkuil 	wait_queue_head_t	wait;
59*4ada120eSMauro Carvalho Chehab 	struct list_head	subscribed;
60*4ada120eSMauro Carvalho Chehab 	struct list_head	available;
61523f46d6SHans Verkuil 	unsigned int		navailable;
62523f46d6SHans Verkuil 	u32			sequence;
638e6e8f93SSylwester Nawrocki 
648e6e8f93SSylwester Nawrocki #if IS_ENABLED(CONFIG_V4L2_MEM2MEM_DEV)
658e6e8f93SSylwester Nawrocki 	struct v4l2_m2m_ctx	*m2m_ctx;
668e6e8f93SSylwester Nawrocki #endif
671babcb46SSakari Ailus };
681babcb46SSakari Ailus 
69*4ada120eSMauro Carvalho Chehab /**
70*4ada120eSMauro Carvalho Chehab  * v4l2_fh_init - Initialise the file handle.
71*4ada120eSMauro Carvalho Chehab  *
72*4ada120eSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
73*4ada120eSMauro Carvalho Chehab  * @vdev: pointer to &struct video_device
74*4ada120eSMauro Carvalho Chehab  *
75*4ada120eSMauro Carvalho Chehab  * Parts of the V4L2 framework using the
761babcb46SSakari Ailus  * file handles should be initialised in this function. Must be called
77*4ada120eSMauro Carvalho Chehab  * from driver's v4l2_file_operations->open\(\) handler if the driver
78*4ada120eSMauro Carvalho Chehab  * uses &struct v4l2_fh.
791babcb46SSakari Ailus  */
80523f46d6SHans Verkuil void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev);
81*4ada120eSMauro Carvalho Chehab 
82*4ada120eSMauro Carvalho Chehab /**
83*4ada120eSMauro Carvalho Chehab  * v4l2_fh_add - Add the fh to the list of file handles on a video_device.
84*4ada120eSMauro Carvalho Chehab  *
85*4ada120eSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
86*4ada120eSMauro Carvalho Chehab  *
87*4ada120eSMauro Carvalho Chehab  * .. note::
88*4ada120eSMauro Carvalho Chehab  *    The @fh file handle must be initialised first.
891babcb46SSakari Ailus  */
901babcb46SSakari Ailus void v4l2_fh_add(struct v4l2_fh *fh);
91*4ada120eSMauro Carvalho Chehab 
92*4ada120eSMauro Carvalho Chehab /**
93*4ada120eSMauro Carvalho Chehab  * v4l2_fh_open - Ancillary routine that can be used as the open\(\) op
94*4ada120eSMauro Carvalho Chehab  *	of v4l2_file_operations.
95*4ada120eSMauro Carvalho Chehab  *
96*4ada120eSMauro Carvalho Chehab  * @filp: pointer to struct file
97*4ada120eSMauro Carvalho Chehab  *
98*4ada120eSMauro Carvalho Chehab  * It allocates a v4l2_fh and inits and adds it to the &struct video_device
99*4ada120eSMauro Carvalho Chehab  * associated with the file pointer.
10073cb4206SHans Verkuil  */
10173cb4206SHans Verkuil int v4l2_fh_open(struct file *filp);
102*4ada120eSMauro Carvalho Chehab 
103*4ada120eSMauro Carvalho Chehab /**
104*4ada120eSMauro Carvalho Chehab  * v4l2_fh_del - Remove file handle from the list of file handles.
105*4ada120eSMauro Carvalho Chehab  *
106*4ada120eSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
107*4ada120eSMauro Carvalho Chehab  *
108*4ada120eSMauro Carvalho Chehab  * On error filp->private_data will be %NULL, otherwise it will point to
109*4ada120eSMauro Carvalho Chehab  * the &struct v4l2_fh.
110*4ada120eSMauro Carvalho Chehab  *
111*4ada120eSMauro Carvalho Chehab  * .. note::
112*4ada120eSMauro Carvalho Chehab  *    Must be called in v4l2_file_operations->release\(\) handler if the driver
113*4ada120eSMauro Carvalho Chehab  *    uses &struct v4l2_fh.
1141babcb46SSakari Ailus  */
1151babcb46SSakari Ailus void v4l2_fh_del(struct v4l2_fh *fh);
116*4ada120eSMauro Carvalho Chehab 
117*4ada120eSMauro Carvalho Chehab /**
118*4ada120eSMauro Carvalho Chehab  * v4l2_fh_exit - Release resources related to a file handle.
119*4ada120eSMauro Carvalho Chehab  *
120*4ada120eSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
121*4ada120eSMauro Carvalho Chehab  *
122*4ada120eSMauro Carvalho Chehab  * Parts of the V4L2 framework using the v4l2_fh must release their
123*4ada120eSMauro Carvalho Chehab  * resources here, too.
124*4ada120eSMauro Carvalho Chehab  *
125*4ada120eSMauro Carvalho Chehab  * .. note::
126*4ada120eSMauro Carvalho Chehab  *    Must be called in v4l2_file_operations->release\(\) handler if the
127*4ada120eSMauro Carvalho Chehab  *    driver uses &struct v4l2_fh.
1281babcb46SSakari Ailus  */
1291babcb46SSakari Ailus void v4l2_fh_exit(struct v4l2_fh *fh);
130*4ada120eSMauro Carvalho Chehab 
131*4ada120eSMauro Carvalho Chehab /**
132*4ada120eSMauro Carvalho Chehab  * v4l2_fh_release - Ancillary routine that can be used as the release\(\) op
133*4ada120eSMauro Carvalho Chehab  *	of v4l2_file_operations.
134*4ada120eSMauro Carvalho Chehab  *
135*4ada120eSMauro Carvalho Chehab  * @filp: pointer to struct file
136*4ada120eSMauro Carvalho Chehab  *
13773cb4206SHans Verkuil  * It deletes and exits the v4l2_fh associated with the file pointer and
13873cb4206SHans Verkuil  * frees it. It will do nothing if filp->private_data (the pointer to the
139*4ada120eSMauro Carvalho Chehab  * v4l2_fh struct) is %NULL.
140*4ada120eSMauro Carvalho Chehab  *
141*4ada120eSMauro Carvalho Chehab  * This function always returns 0.
14273cb4206SHans Verkuil  */
14373cb4206SHans Verkuil int v4l2_fh_release(struct file *filp);
144*4ada120eSMauro Carvalho Chehab 
145*4ada120eSMauro Carvalho Chehab /**
146*4ada120eSMauro Carvalho Chehab  * v4l2_fh_is_singular - Returns 1 if this filehandle is the only filehandle
147*4ada120eSMauro Carvalho Chehab  *	 opened for the associated video_device.
148*4ada120eSMauro Carvalho Chehab  *
149*4ada120eSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
150*4ada120eSMauro Carvalho Chehab  *
151*4ada120eSMauro Carvalho Chehab  * If @fh is NULL, then it returns 0.
152dfddb244SHans Verkuil  */
153dfddb244SHans Verkuil int v4l2_fh_is_singular(struct v4l2_fh *fh);
154*4ada120eSMauro Carvalho Chehab 
155*4ada120eSMauro Carvalho Chehab /**
156*4ada120eSMauro Carvalho Chehab  * v4l2_fh_is_singular_file - Returns 1 if this filehandle is the only
157*4ada120eSMauro Carvalho Chehab  *	filehandle opened for the associated video_device.
158*4ada120eSMauro Carvalho Chehab  *
159*4ada120eSMauro Carvalho Chehab  * @filp: pointer to struct file
160*4ada120eSMauro Carvalho Chehab  *
161*4ada120eSMauro Carvalho Chehab  * This is a helper function variant of v4l2_fh_is_singular() with uses
162*4ada120eSMauro Carvalho Chehab  * struct file as argument.
163*4ada120eSMauro Carvalho Chehab  *
164*4ada120eSMauro Carvalho Chehab  * If filp->private_data is %NULL, then it will return 0.
165dfddb244SHans Verkuil  */
166dfddb244SHans Verkuil static inline int v4l2_fh_is_singular_file(struct file *filp)
167dfddb244SHans Verkuil {
168dfddb244SHans Verkuil 	return v4l2_fh_is_singular(filp->private_data);
169dfddb244SHans Verkuil }
1701babcb46SSakari Ailus 
1711babcb46SSakari Ailus #endif /* V4L2_EVENT_H */
172