162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * v4l2-fh.h 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * V4L2 file handle. Store per file handle data for the V4L2 662306a36Sopenharmony_ci * framework. Using file handles is optional for the drivers. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Copyright (C) 2009--2010 Nokia Corporation. 962306a36Sopenharmony_ci * 1062306a36Sopenharmony_ci * Contact: Sakari Ailus <sakari.ailus@iki.fi> 1162306a36Sopenharmony_ci */ 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#ifndef V4L2_FH_H 1462306a36Sopenharmony_ci#define V4L2_FH_H 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#include <linux/fs.h> 1762306a36Sopenharmony_ci#include <linux/kconfig.h> 1862306a36Sopenharmony_ci#include <linux/list.h> 1962306a36Sopenharmony_ci#include <linux/videodev2.h> 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_cistruct video_device; 2262306a36Sopenharmony_cistruct v4l2_ctrl_handler; 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci/** 2562306a36Sopenharmony_ci * struct v4l2_fh - Describes a V4L2 file handler 2662306a36Sopenharmony_ci * 2762306a36Sopenharmony_ci * @list: list of file handlers 2862306a36Sopenharmony_ci * @vdev: pointer to &struct video_device 2962306a36Sopenharmony_ci * @ctrl_handler: pointer to &struct v4l2_ctrl_handler 3062306a36Sopenharmony_ci * @prio: priority of the file handler, as defined by &enum v4l2_priority 3162306a36Sopenharmony_ci * 3262306a36Sopenharmony_ci * @wait: event' s wait queue 3362306a36Sopenharmony_ci * @subscribe_lock: serialise changes to the subscribed list; guarantee that 3462306a36Sopenharmony_ci * the add and del event callbacks are orderly called 3562306a36Sopenharmony_ci * @subscribed: list of subscribed events 3662306a36Sopenharmony_ci * @available: list of events waiting to be dequeued 3762306a36Sopenharmony_ci * @navailable: number of available events at @available list 3862306a36Sopenharmony_ci * @sequence: event sequence number 3962306a36Sopenharmony_ci * 4062306a36Sopenharmony_ci * @m2m_ctx: pointer to &struct v4l2_m2m_ctx 4162306a36Sopenharmony_ci */ 4262306a36Sopenharmony_cistruct v4l2_fh { 4362306a36Sopenharmony_ci struct list_head list; 4462306a36Sopenharmony_ci struct video_device *vdev; 4562306a36Sopenharmony_ci struct v4l2_ctrl_handler *ctrl_handler; 4662306a36Sopenharmony_ci enum v4l2_priority prio; 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci /* Events */ 4962306a36Sopenharmony_ci wait_queue_head_t wait; 5062306a36Sopenharmony_ci struct mutex subscribe_lock; 5162306a36Sopenharmony_ci struct list_head subscribed; 5262306a36Sopenharmony_ci struct list_head available; 5362306a36Sopenharmony_ci unsigned int navailable; 5462306a36Sopenharmony_ci u32 sequence; 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci struct v4l2_m2m_ctx *m2m_ctx; 5762306a36Sopenharmony_ci}; 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/** 6062306a36Sopenharmony_ci * v4l2_fh_init - Initialise the file handle. 6162306a36Sopenharmony_ci * 6262306a36Sopenharmony_ci * @fh: pointer to &struct v4l2_fh 6362306a36Sopenharmony_ci * @vdev: pointer to &struct video_device 6462306a36Sopenharmony_ci * 6562306a36Sopenharmony_ci * Parts of the V4L2 framework using the 6662306a36Sopenharmony_ci * file handles should be initialised in this function. Must be called 6762306a36Sopenharmony_ci * from driver's v4l2_file_operations->open\(\) handler if the driver 6862306a36Sopenharmony_ci * uses &struct v4l2_fh. 6962306a36Sopenharmony_ci */ 7062306a36Sopenharmony_civoid v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev); 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci/** 7362306a36Sopenharmony_ci * v4l2_fh_add - Add the fh to the list of file handles on a video_device. 7462306a36Sopenharmony_ci * 7562306a36Sopenharmony_ci * @fh: pointer to &struct v4l2_fh 7662306a36Sopenharmony_ci * 7762306a36Sopenharmony_ci * .. note:: 7862306a36Sopenharmony_ci * The @fh file handle must be initialised first. 7962306a36Sopenharmony_ci */ 8062306a36Sopenharmony_civoid v4l2_fh_add(struct v4l2_fh *fh); 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci/** 8362306a36Sopenharmony_ci * v4l2_fh_open - Ancillary routine that can be used as the open\(\) op 8462306a36Sopenharmony_ci * of v4l2_file_operations. 8562306a36Sopenharmony_ci * 8662306a36Sopenharmony_ci * @filp: pointer to struct file 8762306a36Sopenharmony_ci * 8862306a36Sopenharmony_ci * It allocates a v4l2_fh and inits and adds it to the &struct video_device 8962306a36Sopenharmony_ci * associated with the file pointer. 9062306a36Sopenharmony_ci */ 9162306a36Sopenharmony_ciint v4l2_fh_open(struct file *filp); 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci/** 9462306a36Sopenharmony_ci * v4l2_fh_del - Remove file handle from the list of file handles. 9562306a36Sopenharmony_ci * 9662306a36Sopenharmony_ci * @fh: pointer to &struct v4l2_fh 9762306a36Sopenharmony_ci * 9862306a36Sopenharmony_ci * On error filp->private_data will be %NULL, otherwise it will point to 9962306a36Sopenharmony_ci * the &struct v4l2_fh. 10062306a36Sopenharmony_ci * 10162306a36Sopenharmony_ci * .. note:: 10262306a36Sopenharmony_ci * Must be called in v4l2_file_operations->release\(\) handler if the driver 10362306a36Sopenharmony_ci * uses &struct v4l2_fh. 10462306a36Sopenharmony_ci */ 10562306a36Sopenharmony_civoid v4l2_fh_del(struct v4l2_fh *fh); 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci/** 10862306a36Sopenharmony_ci * v4l2_fh_exit - Release resources related to a file handle. 10962306a36Sopenharmony_ci * 11062306a36Sopenharmony_ci * @fh: pointer to &struct v4l2_fh 11162306a36Sopenharmony_ci * 11262306a36Sopenharmony_ci * Parts of the V4L2 framework using the v4l2_fh must release their 11362306a36Sopenharmony_ci * resources here, too. 11462306a36Sopenharmony_ci * 11562306a36Sopenharmony_ci * .. note:: 11662306a36Sopenharmony_ci * Must be called in v4l2_file_operations->release\(\) handler if the 11762306a36Sopenharmony_ci * driver uses &struct v4l2_fh. 11862306a36Sopenharmony_ci */ 11962306a36Sopenharmony_civoid v4l2_fh_exit(struct v4l2_fh *fh); 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci/** 12262306a36Sopenharmony_ci * v4l2_fh_release - Ancillary routine that can be used as the release\(\) op 12362306a36Sopenharmony_ci * of v4l2_file_operations. 12462306a36Sopenharmony_ci * 12562306a36Sopenharmony_ci * @filp: pointer to struct file 12662306a36Sopenharmony_ci * 12762306a36Sopenharmony_ci * It deletes and exits the v4l2_fh associated with the file pointer and 12862306a36Sopenharmony_ci * frees it. It will do nothing if filp->private_data (the pointer to the 12962306a36Sopenharmony_ci * v4l2_fh struct) is %NULL. 13062306a36Sopenharmony_ci * 13162306a36Sopenharmony_ci * This function always returns 0. 13262306a36Sopenharmony_ci */ 13362306a36Sopenharmony_ciint v4l2_fh_release(struct file *filp); 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci/** 13662306a36Sopenharmony_ci * v4l2_fh_is_singular - Returns 1 if this filehandle is the only filehandle 13762306a36Sopenharmony_ci * opened for the associated video_device. 13862306a36Sopenharmony_ci * 13962306a36Sopenharmony_ci * @fh: pointer to &struct v4l2_fh 14062306a36Sopenharmony_ci * 14162306a36Sopenharmony_ci * If @fh is NULL, then it returns 0. 14262306a36Sopenharmony_ci */ 14362306a36Sopenharmony_ciint v4l2_fh_is_singular(struct v4l2_fh *fh); 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci/** 14662306a36Sopenharmony_ci * v4l2_fh_is_singular_file - Returns 1 if this filehandle is the only 14762306a36Sopenharmony_ci * filehandle opened for the associated video_device. 14862306a36Sopenharmony_ci * 14962306a36Sopenharmony_ci * @filp: pointer to struct file 15062306a36Sopenharmony_ci * 15162306a36Sopenharmony_ci * This is a helper function variant of v4l2_fh_is_singular() with uses 15262306a36Sopenharmony_ci * struct file as argument. 15362306a36Sopenharmony_ci * 15462306a36Sopenharmony_ci * If filp->private_data is %NULL, then it will return 0. 15562306a36Sopenharmony_ci */ 15662306a36Sopenharmony_cistatic inline int v4l2_fh_is_singular_file(struct file *filp) 15762306a36Sopenharmony_ci{ 15862306a36Sopenharmony_ci return v4l2_fh_is_singular(filp->private_data); 15962306a36Sopenharmony_ci} 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci#endif /* V4L2_EVENT_H */ 162