1*1802d0beSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 21babcb46SSakari Ailus /* 31babcb46SSakari Ailus * v4l2-fh.h 41babcb46SSakari Ailus * 51babcb46SSakari Ailus * V4L2 file handle. Store per file handle data for the V4L2 61babcb46SSakari Ailus * framework. Using file handles is optional for the drivers. 71babcb46SSakari Ailus * 81babcb46SSakari Ailus * Copyright (C) 2009--2010 Nokia Corporation. 91babcb46SSakari Ailus * 108c5dff90SSakari Ailus * Contact: Sakari Ailus <sakari.ailus@iki.fi> 111babcb46SSakari Ailus */ 121babcb46SSakari Ailus 131babcb46SSakari Ailus #ifndef V4L2_FH_H 141babcb46SSakari Ailus #define V4L2_FH_H 151babcb46SSakari Ailus 164f1af2a3SLaurent Pinchart #include <linux/fs.h> 1714351d44SAlexandre Courbot #include <linux/kconfig.h> 181babcb46SSakari Ailus #include <linux/list.h> 19c8d185ceSLaurent Pinchart #include <linux/videodev2.h> 201babcb46SSakari Ailus 211babcb46SSakari Ailus struct video_device; 222d28b686SHans Verkuil struct v4l2_ctrl_handler; 231babcb46SSakari Ailus 244ada120eSMauro Carvalho Chehab /** 254ada120eSMauro Carvalho Chehab * struct v4l2_fh - Describes a V4L2 file handler 264ada120eSMauro Carvalho Chehab * 274ada120eSMauro Carvalho Chehab * @list: list of file handlers 284ada120eSMauro Carvalho Chehab * @vdev: pointer to &struct video_device 294ada120eSMauro Carvalho Chehab * @ctrl_handler: pointer to &struct v4l2_ctrl_handler 304ada120eSMauro Carvalho Chehab * @prio: priority of the file handler, as defined by &enum v4l2_priority 314ada120eSMauro Carvalho Chehab * 324ada120eSMauro Carvalho Chehab * @wait: event' s wait queue 33ad608fbcSSakari Ailus * @subscribe_lock: serialise changes to the subscribed list; guarantee that 34ad608fbcSSakari Ailus * the add and del event callbacks are orderly called 354ada120eSMauro Carvalho Chehab * @subscribed: list of subscribed events 364ada120eSMauro Carvalho Chehab * @available: list of events waiting to be dequeued 374ada120eSMauro Carvalho Chehab * @navailable: number of available events at @available list 384ada120eSMauro Carvalho Chehab * @sequence: event sequence number 39ad608fbcSSakari Ailus * 404ada120eSMauro Carvalho Chehab * @m2m_ctx: pointer to &struct v4l2_m2m_ctx 414ada120eSMauro Carvalho Chehab */ 421babcb46SSakari Ailus struct v4l2_fh { 431babcb46SSakari Ailus struct list_head list; 441babcb46SSakari Ailus struct video_device *vdev; 452d28b686SHans Verkuil struct v4l2_ctrl_handler *ctrl_handler; 46fc5602beSHans Verkuil enum v4l2_priority prio; 47523f46d6SHans Verkuil 48523f46d6SHans Verkuil /* Events */ 49523f46d6SHans Verkuil wait_queue_head_t wait; 50ad608fbcSSakari Ailus struct mutex subscribe_lock; 514ada120eSMauro Carvalho Chehab struct list_head subscribed; 524ada120eSMauro Carvalho Chehab struct list_head available; 53523f46d6SHans Verkuil unsigned int navailable; 54523f46d6SHans Verkuil u32 sequence; 558e6e8f93SSylwester Nawrocki 568e6e8f93SSylwester Nawrocki struct v4l2_m2m_ctx *m2m_ctx; 571babcb46SSakari Ailus }; 581babcb46SSakari Ailus 594ada120eSMauro Carvalho Chehab /** 604ada120eSMauro Carvalho Chehab * v4l2_fh_init - Initialise the file handle. 614ada120eSMauro Carvalho Chehab * 624ada120eSMauro Carvalho Chehab * @fh: pointer to &struct v4l2_fh 634ada120eSMauro Carvalho Chehab * @vdev: pointer to &struct video_device 644ada120eSMauro Carvalho Chehab * 654ada120eSMauro Carvalho Chehab * Parts of the V4L2 framework using the 661babcb46SSakari Ailus * file handles should be initialised in this function. Must be called 674ada120eSMauro Carvalho Chehab * from driver's v4l2_file_operations->open\(\) handler if the driver 684ada120eSMauro Carvalho Chehab * uses &struct v4l2_fh. 691babcb46SSakari Ailus */ 70523f46d6SHans Verkuil void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev); 714ada120eSMauro Carvalho Chehab 724ada120eSMauro Carvalho Chehab /** 734ada120eSMauro Carvalho Chehab * v4l2_fh_add - Add the fh to the list of file handles on a video_device. 744ada120eSMauro Carvalho Chehab * 754ada120eSMauro Carvalho Chehab * @fh: pointer to &struct v4l2_fh 764ada120eSMauro Carvalho Chehab * 774ada120eSMauro Carvalho Chehab * .. note:: 784ada120eSMauro Carvalho Chehab * The @fh file handle must be initialised first. 791babcb46SSakari Ailus */ 801babcb46SSakari Ailus void v4l2_fh_add(struct v4l2_fh *fh); 814ada120eSMauro Carvalho Chehab 824ada120eSMauro Carvalho Chehab /** 834ada120eSMauro Carvalho Chehab * v4l2_fh_open - Ancillary routine that can be used as the open\(\) op 844ada120eSMauro Carvalho Chehab * of v4l2_file_operations. 854ada120eSMauro Carvalho Chehab * 864ada120eSMauro Carvalho Chehab * @filp: pointer to struct file 874ada120eSMauro Carvalho Chehab * 884ada120eSMauro Carvalho Chehab * It allocates a v4l2_fh and inits and adds it to the &struct video_device 894ada120eSMauro Carvalho Chehab * associated with the file pointer. 9073cb4206SHans Verkuil */ 9173cb4206SHans Verkuil int v4l2_fh_open(struct file *filp); 924ada120eSMauro Carvalho Chehab 934ada120eSMauro Carvalho Chehab /** 944ada120eSMauro Carvalho Chehab * v4l2_fh_del - Remove file handle from the list of file handles. 954ada120eSMauro Carvalho Chehab * 964ada120eSMauro Carvalho Chehab * @fh: pointer to &struct v4l2_fh 974ada120eSMauro Carvalho Chehab * 984ada120eSMauro Carvalho Chehab * On error filp->private_data will be %NULL, otherwise it will point to 994ada120eSMauro Carvalho Chehab * the &struct v4l2_fh. 1004ada120eSMauro Carvalho Chehab * 1014ada120eSMauro Carvalho Chehab * .. note:: 1024ada120eSMauro Carvalho Chehab * Must be called in v4l2_file_operations->release\(\) handler if the driver 1034ada120eSMauro Carvalho Chehab * uses &struct v4l2_fh. 1041babcb46SSakari Ailus */ 1051babcb46SSakari Ailus void v4l2_fh_del(struct v4l2_fh *fh); 1064ada120eSMauro Carvalho Chehab 1074ada120eSMauro Carvalho Chehab /** 1084ada120eSMauro Carvalho Chehab * v4l2_fh_exit - Release resources related to a file handle. 1094ada120eSMauro Carvalho Chehab * 1104ada120eSMauro Carvalho Chehab * @fh: pointer to &struct v4l2_fh 1114ada120eSMauro Carvalho Chehab * 1124ada120eSMauro Carvalho Chehab * Parts of the V4L2 framework using the v4l2_fh must release their 1134ada120eSMauro Carvalho Chehab * resources here, too. 1144ada120eSMauro Carvalho Chehab * 1154ada120eSMauro Carvalho Chehab * .. note:: 1164ada120eSMauro Carvalho Chehab * Must be called in v4l2_file_operations->release\(\) handler if the 1174ada120eSMauro Carvalho Chehab * driver uses &struct v4l2_fh. 1181babcb46SSakari Ailus */ 1191babcb46SSakari Ailus void v4l2_fh_exit(struct v4l2_fh *fh); 1204ada120eSMauro Carvalho Chehab 1214ada120eSMauro Carvalho Chehab /** 1224ada120eSMauro Carvalho Chehab * v4l2_fh_release - Ancillary routine that can be used as the release\(\) op 1234ada120eSMauro Carvalho Chehab * of v4l2_file_operations. 1244ada120eSMauro Carvalho Chehab * 1254ada120eSMauro Carvalho Chehab * @filp: pointer to struct file 1264ada120eSMauro Carvalho Chehab * 12773cb4206SHans Verkuil * It deletes and exits the v4l2_fh associated with the file pointer and 12873cb4206SHans Verkuil * frees it. It will do nothing if filp->private_data (the pointer to the 1294ada120eSMauro Carvalho Chehab * v4l2_fh struct) is %NULL. 1304ada120eSMauro Carvalho Chehab * 1314ada120eSMauro Carvalho Chehab * This function always returns 0. 13273cb4206SHans Verkuil */ 13373cb4206SHans Verkuil int v4l2_fh_release(struct file *filp); 1344ada120eSMauro Carvalho Chehab 1354ada120eSMauro Carvalho Chehab /** 1364ada120eSMauro Carvalho Chehab * v4l2_fh_is_singular - Returns 1 if this filehandle is the only filehandle 1374ada120eSMauro Carvalho Chehab * opened for the associated video_device. 1384ada120eSMauro Carvalho Chehab * 1394ada120eSMauro Carvalho Chehab * @fh: pointer to &struct v4l2_fh 1404ada120eSMauro Carvalho Chehab * 1414ada120eSMauro Carvalho Chehab * If @fh is NULL, then it returns 0. 142dfddb244SHans Verkuil */ 143dfddb244SHans Verkuil int v4l2_fh_is_singular(struct v4l2_fh *fh); 1444ada120eSMauro Carvalho Chehab 1454ada120eSMauro Carvalho Chehab /** 1464ada120eSMauro Carvalho Chehab * v4l2_fh_is_singular_file - Returns 1 if this filehandle is the only 1474ada120eSMauro Carvalho Chehab * filehandle opened for the associated video_device. 1484ada120eSMauro Carvalho Chehab * 1494ada120eSMauro Carvalho Chehab * @filp: pointer to struct file 1504ada120eSMauro Carvalho Chehab * 1514ada120eSMauro Carvalho Chehab * This is a helper function variant of v4l2_fh_is_singular() with uses 1524ada120eSMauro Carvalho Chehab * struct file as argument. 1534ada120eSMauro Carvalho Chehab * 1544ada120eSMauro Carvalho Chehab * If filp->private_data is %NULL, then it will return 0. 155dfddb244SHans Verkuil */ v4l2_fh_is_singular_file(struct file * filp)156dfddb244SHans Verkuilstatic inline int v4l2_fh_is_singular_file(struct file *filp) 157dfddb244SHans Verkuil { 158dfddb244SHans Verkuil return v4l2_fh_is_singular(filp->private_data); 159dfddb244SHans Verkuil } 1601babcb46SSakari Ailus 1611babcb46SSakari Ailus #endif /* V4L2_EVENT_H */ 162