xref: /linux/include/media/v4l2-fh.h (revision 14351d44830ec00b8c66b44c8c866944da678c33)
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 
211babcb46SSakari Ailus #ifndef V4L2_FH_H
221babcb46SSakari Ailus #define V4L2_FH_H
231babcb46SSakari Ailus 
244f1af2a3SLaurent Pinchart #include <linux/fs.h>
25*14351d44SAlexandre Courbot #include <linux/kconfig.h>
261babcb46SSakari Ailus #include <linux/list.h>
27c8d185ceSLaurent Pinchart #include <linux/videodev2.h>
281babcb46SSakari Ailus 
291babcb46SSakari Ailus struct video_device;
302d28b686SHans Verkuil struct v4l2_ctrl_handler;
311babcb46SSakari Ailus 
324ada120eSMauro Carvalho Chehab /**
334ada120eSMauro Carvalho Chehab  * struct v4l2_fh - Describes a V4L2 file handler
344ada120eSMauro Carvalho Chehab  *
354ada120eSMauro Carvalho Chehab  * @list: list of file handlers
364ada120eSMauro Carvalho Chehab  * @vdev: pointer to &struct video_device
374ada120eSMauro Carvalho Chehab  * @ctrl_handler: pointer to &struct v4l2_ctrl_handler
384ada120eSMauro Carvalho Chehab  * @prio: priority of the file handler, as defined by &enum v4l2_priority
394ada120eSMauro Carvalho Chehab  *
404ada120eSMauro Carvalho Chehab  * @wait: event' s wait queue
414ada120eSMauro Carvalho Chehab  * @subscribed: list of subscribed events
424ada120eSMauro Carvalho Chehab  * @available: list of events waiting to be dequeued
434ada120eSMauro Carvalho Chehab  * @navailable: number of available events at @available list
444ada120eSMauro Carvalho Chehab  * @sequence: event sequence number
454ada120eSMauro Carvalho Chehab  * @m2m_ctx: pointer to &struct v4l2_m2m_ctx
464ada120eSMauro Carvalho Chehab  */
471babcb46SSakari Ailus struct v4l2_fh {
481babcb46SSakari Ailus 	struct list_head	list;
491babcb46SSakari Ailus 	struct video_device	*vdev;
502d28b686SHans Verkuil 	struct v4l2_ctrl_handler *ctrl_handler;
51fc5602beSHans Verkuil 	enum v4l2_priority	prio;
52523f46d6SHans Verkuil 
53523f46d6SHans Verkuil 	/* Events */
54523f46d6SHans Verkuil 	wait_queue_head_t	wait;
554ada120eSMauro Carvalho Chehab 	struct list_head	subscribed;
564ada120eSMauro Carvalho Chehab 	struct list_head	available;
57523f46d6SHans Verkuil 	unsigned int		navailable;
58523f46d6SHans Verkuil 	u32			sequence;
598e6e8f93SSylwester Nawrocki 
608e6e8f93SSylwester Nawrocki #if IS_ENABLED(CONFIG_V4L2_MEM2MEM_DEV)
618e6e8f93SSylwester Nawrocki 	struct v4l2_m2m_ctx	*m2m_ctx;
628e6e8f93SSylwester Nawrocki #endif
631babcb46SSakari Ailus };
641babcb46SSakari Ailus 
654ada120eSMauro Carvalho Chehab /**
664ada120eSMauro Carvalho Chehab  * v4l2_fh_init - Initialise the file handle.
674ada120eSMauro Carvalho Chehab  *
684ada120eSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
694ada120eSMauro Carvalho Chehab  * @vdev: pointer to &struct video_device
704ada120eSMauro Carvalho Chehab  *
714ada120eSMauro Carvalho Chehab  * Parts of the V4L2 framework using the
721babcb46SSakari Ailus  * file handles should be initialised in this function. Must be called
734ada120eSMauro Carvalho Chehab  * from driver's v4l2_file_operations->open\(\) handler if the driver
744ada120eSMauro Carvalho Chehab  * uses &struct v4l2_fh.
751babcb46SSakari Ailus  */
76523f46d6SHans Verkuil void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev);
774ada120eSMauro Carvalho Chehab 
784ada120eSMauro Carvalho Chehab /**
794ada120eSMauro Carvalho Chehab  * v4l2_fh_add - Add the fh to the list of file handles on a video_device.
804ada120eSMauro Carvalho Chehab  *
814ada120eSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
824ada120eSMauro Carvalho Chehab  *
834ada120eSMauro Carvalho Chehab  * .. note::
844ada120eSMauro Carvalho Chehab  *    The @fh file handle must be initialised first.
851babcb46SSakari Ailus  */
861babcb46SSakari Ailus void v4l2_fh_add(struct v4l2_fh *fh);
874ada120eSMauro Carvalho Chehab 
884ada120eSMauro Carvalho Chehab /**
894ada120eSMauro Carvalho Chehab  * v4l2_fh_open - Ancillary routine that can be used as the open\(\) op
904ada120eSMauro Carvalho Chehab  *	of v4l2_file_operations.
914ada120eSMauro Carvalho Chehab  *
924ada120eSMauro Carvalho Chehab  * @filp: pointer to struct file
934ada120eSMauro Carvalho Chehab  *
944ada120eSMauro Carvalho Chehab  * It allocates a v4l2_fh and inits and adds it to the &struct video_device
954ada120eSMauro Carvalho Chehab  * associated with the file pointer.
9673cb4206SHans Verkuil  */
9773cb4206SHans Verkuil int v4l2_fh_open(struct file *filp);
984ada120eSMauro Carvalho Chehab 
994ada120eSMauro Carvalho Chehab /**
1004ada120eSMauro Carvalho Chehab  * v4l2_fh_del - Remove file handle from the list of file handles.
1014ada120eSMauro Carvalho Chehab  *
1024ada120eSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
1034ada120eSMauro Carvalho Chehab  *
1044ada120eSMauro Carvalho Chehab  * On error filp->private_data will be %NULL, otherwise it will point to
1054ada120eSMauro Carvalho Chehab  * the &struct v4l2_fh.
1064ada120eSMauro Carvalho Chehab  *
1074ada120eSMauro Carvalho Chehab  * .. note::
1084ada120eSMauro Carvalho Chehab  *    Must be called in v4l2_file_operations->release\(\) handler if the driver
1094ada120eSMauro Carvalho Chehab  *    uses &struct v4l2_fh.
1101babcb46SSakari Ailus  */
1111babcb46SSakari Ailus void v4l2_fh_del(struct v4l2_fh *fh);
1124ada120eSMauro Carvalho Chehab 
1134ada120eSMauro Carvalho Chehab /**
1144ada120eSMauro Carvalho Chehab  * v4l2_fh_exit - Release resources related to a file handle.
1154ada120eSMauro Carvalho Chehab  *
1164ada120eSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
1174ada120eSMauro Carvalho Chehab  *
1184ada120eSMauro Carvalho Chehab  * Parts of the V4L2 framework using the v4l2_fh must release their
1194ada120eSMauro Carvalho Chehab  * resources here, too.
1204ada120eSMauro Carvalho Chehab  *
1214ada120eSMauro Carvalho Chehab  * .. note::
1224ada120eSMauro Carvalho Chehab  *    Must be called in v4l2_file_operations->release\(\) handler if the
1234ada120eSMauro Carvalho Chehab  *    driver uses &struct v4l2_fh.
1241babcb46SSakari Ailus  */
1251babcb46SSakari Ailus void v4l2_fh_exit(struct v4l2_fh *fh);
1264ada120eSMauro Carvalho Chehab 
1274ada120eSMauro Carvalho Chehab /**
1284ada120eSMauro Carvalho Chehab  * v4l2_fh_release - Ancillary routine that can be used as the release\(\) op
1294ada120eSMauro Carvalho Chehab  *	of v4l2_file_operations.
1304ada120eSMauro Carvalho Chehab  *
1314ada120eSMauro Carvalho Chehab  * @filp: pointer to struct file
1324ada120eSMauro Carvalho Chehab  *
13373cb4206SHans Verkuil  * It deletes and exits the v4l2_fh associated with the file pointer and
13473cb4206SHans Verkuil  * frees it. It will do nothing if filp->private_data (the pointer to the
1354ada120eSMauro Carvalho Chehab  * v4l2_fh struct) is %NULL.
1364ada120eSMauro Carvalho Chehab  *
1374ada120eSMauro Carvalho Chehab  * This function always returns 0.
13873cb4206SHans Verkuil  */
13973cb4206SHans Verkuil int v4l2_fh_release(struct file *filp);
1404ada120eSMauro Carvalho Chehab 
1414ada120eSMauro Carvalho Chehab /**
1424ada120eSMauro Carvalho Chehab  * v4l2_fh_is_singular - Returns 1 if this filehandle is the only filehandle
1434ada120eSMauro Carvalho Chehab  *	 opened for the associated video_device.
1444ada120eSMauro Carvalho Chehab  *
1454ada120eSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
1464ada120eSMauro Carvalho Chehab  *
1474ada120eSMauro Carvalho Chehab  * If @fh is NULL, then it returns 0.
148dfddb244SHans Verkuil  */
149dfddb244SHans Verkuil int v4l2_fh_is_singular(struct v4l2_fh *fh);
1504ada120eSMauro Carvalho Chehab 
1514ada120eSMauro Carvalho Chehab /**
1524ada120eSMauro Carvalho Chehab  * v4l2_fh_is_singular_file - Returns 1 if this filehandle is the only
1534ada120eSMauro Carvalho Chehab  *	filehandle opened for the associated video_device.
1544ada120eSMauro Carvalho Chehab  *
1554ada120eSMauro Carvalho Chehab  * @filp: pointer to struct file
1564ada120eSMauro Carvalho Chehab  *
1574ada120eSMauro Carvalho Chehab  * This is a helper function variant of v4l2_fh_is_singular() with uses
1584ada120eSMauro Carvalho Chehab  * struct file as argument.
1594ada120eSMauro Carvalho Chehab  *
1604ada120eSMauro Carvalho Chehab  * If filp->private_data is %NULL, then it will return 0.
161dfddb244SHans Verkuil  */
162dfddb244SHans Verkuil static inline int v4l2_fh_is_singular_file(struct file *filp)
163dfddb244SHans Verkuil {
164dfddb244SHans Verkuil 	return v4l2_fh_is_singular(filp->private_data);
165dfddb244SHans Verkuil }
1661babcb46SSakari Ailus 
1671babcb46SSakari Ailus #endif /* V4L2_EVENT_H */
168