/* SPDX-License-Identifier: GPL-2.0-only */1/*2* v4l2-fh.h3*4* V4L2 file handle. Store per file handle data for the V4L25* framework. Using file handles is optional for the drivers.6*7* Copyright (C) 2009--2010 Nokia Corporation.8*9* Contact: Sakari Ailus <[email protected]>10*/1112#ifndef V4L2_FH_H13#define V4L2_FH_H1415#include <linux/fs.h>16#include <linux/kconfig.h>17#include <linux/list.h>18#include <linux/videodev2.h>1920struct video_device;21struct v4l2_ctrl_handler;2223/**24* struct v4l2_fh - Describes a V4L2 file handler25*26* @list: list of file handlers27* @vdev: pointer to &struct video_device28* @ctrl_handler: pointer to &struct v4l2_ctrl_handler29* @prio: priority of the file handler, as defined by &enum v4l2_priority30*31* @wait: event' s wait queue32* @subscribe_lock: serialise changes to the subscribed list; guarantee that33* the add and del event callbacks are orderly called34* @subscribed: list of subscribed events35* @available: list of events waiting to be dequeued36* @navailable: number of available events at @available list37* @sequence: event sequence number38*39* @m2m_ctx: pointer to &struct v4l2_m2m_ctx40*/41struct v4l2_fh {42struct list_head list;43struct video_device *vdev;44struct v4l2_ctrl_handler *ctrl_handler;45enum v4l2_priority prio;4647/* Events */48wait_queue_head_t wait;49struct mutex subscribe_lock;50struct list_head subscribed;51struct list_head available;52unsigned int navailable;53u32 sequence;5455struct v4l2_m2m_ctx *m2m_ctx;56};5758/**59* v4l2_fh_init - Initialise the file handle.60*61* @fh: pointer to &struct v4l2_fh62* @vdev: pointer to &struct video_device63*64* Parts of the V4L2 framework using the65* file handles should be initialised in this function. Must be called66* from driver's v4l2_file_operations->open\(\) handler if the driver67* uses &struct v4l2_fh.68*/69void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev);7071/**72* v4l2_fh_add - Add the fh to the list of file handles on a video_device.73*74* @fh: pointer to &struct v4l2_fh75*76* .. note::77* The @fh file handle must be initialised first.78*/79void v4l2_fh_add(struct v4l2_fh *fh);8081/**82* v4l2_fh_open - Ancillary routine that can be used as the open\(\) op83* of v4l2_file_operations.84*85* @filp: pointer to struct file86*87* It allocates a v4l2_fh and inits and adds it to the &struct video_device88* associated with the file pointer.89*/90int v4l2_fh_open(struct file *filp);9192/**93* v4l2_fh_del - Remove file handle from the list of file handles.94*95* @fh: pointer to &struct v4l2_fh96*97* On error filp->private_data will be %NULL, otherwise it will point to98* the &struct v4l2_fh.99*100* .. note::101* Must be called in v4l2_file_operations->release\(\) handler if the driver102* uses &struct v4l2_fh.103*/104void v4l2_fh_del(struct v4l2_fh *fh);105106/**107* v4l2_fh_exit - Release resources related to a file handle.108*109* @fh: pointer to &struct v4l2_fh110*111* Parts of the V4L2 framework using the v4l2_fh must release their112* resources here, too.113*114* .. note::115* Must be called in v4l2_file_operations->release\(\) handler if the116* driver uses &struct v4l2_fh.117*/118void v4l2_fh_exit(struct v4l2_fh *fh);119120/**121* v4l2_fh_release - Ancillary routine that can be used as the release\(\) op122* of v4l2_file_operations.123*124* @filp: pointer to struct file125*126* It deletes and exits the v4l2_fh associated with the file pointer and127* frees it. It will do nothing if filp->private_data (the pointer to the128* v4l2_fh struct) is %NULL.129*130* This function always returns 0.131*/132int v4l2_fh_release(struct file *filp);133134/**135* v4l2_fh_is_singular - Returns 1 if this filehandle is the only filehandle136* opened for the associated video_device.137*138* @fh: pointer to &struct v4l2_fh139*140* If @fh is NULL, then it returns 0.141*/142int v4l2_fh_is_singular(struct v4l2_fh *fh);143144/**145* v4l2_fh_is_singular_file - Returns 1 if this filehandle is the only146* filehandle opened for the associated video_device.147*148* @filp: pointer to struct file149*150* This is a helper function variant of v4l2_fh_is_singular() with uses151* struct file as argument.152*153* If filp->private_data is %NULL, then it will return 0.154*/155static inline int v4l2_fh_is_singular_file(struct file *filp)156{157return v4l2_fh_is_singular(filp->private_data);158}159160#endif /* V4L2_EVENT_H */161162163