/* 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 mandatory 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* file_to_v4l2_fh - Return the v4l2_fh associated with a struct file60*61* @filp: pointer to &struct file62*63* This function should be used by drivers to retrieve the &struct v4l2_fh64* instance pointer stored in the file private_data instead of accessing the65* private_data field directly.66*/67static inline struct v4l2_fh *file_to_v4l2_fh(struct file *filp)68{69return filp->private_data;70}7172/**73* v4l2_fh_init - Initialise the file handle.74*75* @fh: pointer to &struct v4l2_fh76* @vdev: pointer to &struct video_device77*78* Parts of the V4L2 framework using the79* file handles should be initialised in this function. Must be called80* from driver's v4l2_file_operations->open\(\) handler if the driver81* uses &struct v4l2_fh.82*/83void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev);8485/**86* v4l2_fh_add - Add the fh to the list of file handles on a video_device.87*88* @fh: pointer to &struct v4l2_fh89* @filp: pointer to &struct file associated with @fh90*91* The function sets filp->private_data to point to @fh.92*93* .. note::94* The @fh file handle must be initialised first.95*/96void v4l2_fh_add(struct v4l2_fh *fh, struct file *filp);9798/**99* v4l2_fh_open - Ancillary routine that can be used as the open\(\) op100* of v4l2_file_operations.101*102* @filp: pointer to struct file103*104* It allocates a v4l2_fh and inits and adds it to the &struct video_device105* associated with the file pointer.106*107* On error filp->private_data will be %NULL, otherwise it will point to108* the &struct v4l2_fh.109*/110int v4l2_fh_open(struct file *filp);111112/**113* v4l2_fh_del - Remove file handle from the list of file handles.114*115* @fh: pointer to &struct v4l2_fh116* @filp: pointer to &struct file associated with @fh117*118* The function resets filp->private_data to NULL.119*120* .. note::121* Must be called in v4l2_file_operations->release\(\) handler if the driver122* uses &struct v4l2_fh.123*/124void v4l2_fh_del(struct v4l2_fh *fh, struct file *filp);125126/**127* v4l2_fh_exit - Release resources related to a file handle.128*129* @fh: pointer to &struct v4l2_fh130*131* Parts of the V4L2 framework using the v4l2_fh must release their132* resources here, too.133*134* .. note::135* Must be called in v4l2_file_operations->release\(\) handler if the136* driver uses &struct v4l2_fh.137*/138void v4l2_fh_exit(struct v4l2_fh *fh);139140/**141* v4l2_fh_release - Ancillary routine that can be used as the release\(\) op142* of v4l2_file_operations.143*144* @filp: pointer to struct file145*146* It deletes and exits the v4l2_fh associated with the file pointer and147* frees it. It will do nothing if filp->private_data (the pointer to the148* v4l2_fh struct) is %NULL.149*150* This function always returns 0.151*/152int v4l2_fh_release(struct file *filp);153154/**155* v4l2_fh_is_singular - Returns 1 if this filehandle is the only filehandle156* opened for the associated video_device.157*158* @fh: pointer to &struct v4l2_fh159*160* If @fh is NULL, then it returns 0.161*/162int v4l2_fh_is_singular(struct v4l2_fh *fh);163164/**165* v4l2_fh_is_singular_file - Returns 1 if this filehandle is the only166* filehandle opened for the associated video_device.167*168* @filp: pointer to struct file169*170* This is a helper function variant of v4l2_fh_is_singular() with uses171* struct file as argument.172*173* If filp->private_data is %NULL, then it will return 0.174*/175static inline int v4l2_fh_is_singular_file(struct file *filp)176{177return v4l2_fh_is_singular(filp->private_data);178}179180#endif /* V4L2_EVENT_H */181182183