11babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus/* 21babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * v4l2-fh.h 31babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * 41babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * V4L2 file handle. Store per file handle data for the V4L2 51babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * framework. Using file handles is optional for the drivers. 61babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * 71babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * Copyright (C) 2009--2010 Nokia Corporation. 81babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * 98c5dff905714446f8836b40a93bfeabd0aea8c82Sakari Ailus * Contact: Sakari Ailus <sakari.ailus@iki.fi> 101babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * 111babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * This program is free software; you can redistribute it and/or 121babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * modify it under the terms of the GNU General Public License 131babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * version 2 as published by the Free Software Foundation. 141babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * 151babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * This program is distributed in the hope that it will be useful, but 161babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * WITHOUT ANY WARRANTY; without even the implied warranty of 171babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 181babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * General Public License for more details. 191babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * 201babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * You should have received a copy of the GNU General Public License 211babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * along with this program; if not, write to the Free Software 221babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 231babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * 02110-1301 USA 241babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus */ 251babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus 261babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus#ifndef V4L2_FH_H 271babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus#define V4L2_FH_H 281babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus 294f1af2a33c9c5fbd2bf31a1679378860aca79f9eLaurent Pinchart#include <linux/fs.h> 301babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus#include <linux/list.h> 31c8d185ce33ecd560275f76c590fda4cdba824bd9Laurent Pinchart#include <linux/videodev2.h> 321babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus 331babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailusstruct video_device; 342d28b686adc18567b388362e1f7b86658cfd81fcHans Verkuilstruct v4l2_ctrl_handler; 351babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus 361babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailusstruct v4l2_fh { 371babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus struct list_head list; 381babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus struct video_device *vdev; 392d28b686adc18567b388362e1f7b86658cfd81fcHans Verkuil struct v4l2_ctrl_handler *ctrl_handler; 40fc5602be7ca5b55174c5d6595089718779b28dfaHans Verkuil enum v4l2_priority prio; 41523f46d6aba9dcb0a2d0fc474ca884e93a7cf198Hans Verkuil 42523f46d6aba9dcb0a2d0fc474ca884e93a7cf198Hans Verkuil /* Events */ 43523f46d6aba9dcb0a2d0fc474ca884e93a7cf198Hans Verkuil wait_queue_head_t wait; 44523f46d6aba9dcb0a2d0fc474ca884e93a7cf198Hans Verkuil struct list_head subscribed; /* Subscribed events */ 45523f46d6aba9dcb0a2d0fc474ca884e93a7cf198Hans Verkuil struct list_head available; /* Dequeueable event */ 46523f46d6aba9dcb0a2d0fc474ca884e93a7cf198Hans Verkuil unsigned int navailable; 47523f46d6aba9dcb0a2d0fc474ca884e93a7cf198Hans Verkuil u32 sequence; 488e6e8f93f7cb3452b1c00da8a30d01558628d913Sylwester Nawrocki 498e6e8f93f7cb3452b1c00da8a30d01558628d913Sylwester Nawrocki#if IS_ENABLED(CONFIG_V4L2_MEM2MEM_DEV) 508e6e8f93f7cb3452b1c00da8a30d01558628d913Sylwester Nawrocki struct v4l2_m2m_ctx *m2m_ctx; 518e6e8f93f7cb3452b1c00da8a30d01558628d913Sylwester Nawrocki#endif 521babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus}; 531babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus 541babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus/* 551babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * Initialise the file handle. Parts of the V4L2 framework using the 561babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * file handles should be initialised in this function. Must be called 571babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * from driver's v4l2_file_operations->open() handler if the driver 581babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * uses v4l2_fh. 591babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus */ 60523f46d6aba9dcb0a2d0fc474ca884e93a7cf198Hans Verkuilvoid v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev); 611babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus/* 621babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * Add the fh to the list of file handles on a video_device. The file 631babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * handle must be initialised first. 641babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus */ 651babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailusvoid v4l2_fh_add(struct v4l2_fh *fh); 661babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus/* 6773cb42068cff419e72456940c713ceb5efa68c2aHans Verkuil * Can be used as the open() op of v4l2_file_operations. 6873cb42068cff419e72456940c713ceb5efa68c2aHans Verkuil * It allocates a v4l2_fh and inits and adds it to the video_device associated 6973cb42068cff419e72456940c713ceb5efa68c2aHans Verkuil * with the file pointer. 7073cb42068cff419e72456940c713ceb5efa68c2aHans Verkuil */ 7173cb42068cff419e72456940c713ceb5efa68c2aHans Verkuilint v4l2_fh_open(struct file *filp); 7273cb42068cff419e72456940c713ceb5efa68c2aHans Verkuil/* 731babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * Remove file handle from the list of file handles. Must be called in 741babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * v4l2_file_operations->release() handler if the driver uses v4l2_fh. 7573cb42068cff419e72456940c713ceb5efa68c2aHans Verkuil * On error filp->private_data will be NULL, otherwise it will point to 7673cb42068cff419e72456940c713ceb5efa68c2aHans Verkuil * the v4l2_fh struct. 771babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus */ 781babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailusvoid v4l2_fh_del(struct v4l2_fh *fh); 791babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus/* 801babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * Release resources related to a file handle. Parts of the V4L2 811babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * framework using the v4l2_fh must release their resources here, too. 821babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * Must be called in v4l2_file_operations->release() handler if the 831babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus * driver uses v4l2_fh. 841babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus */ 851babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailusvoid v4l2_fh_exit(struct v4l2_fh *fh); 8673cb42068cff419e72456940c713ceb5efa68c2aHans Verkuil/* 8773cb42068cff419e72456940c713ceb5efa68c2aHans Verkuil * Can be used as the release() op of v4l2_file_operations. 8873cb42068cff419e72456940c713ceb5efa68c2aHans Verkuil * It deletes and exits the v4l2_fh associated with the file pointer and 8973cb42068cff419e72456940c713ceb5efa68c2aHans Verkuil * frees it. It will do nothing if filp->private_data (the pointer to the 9073cb42068cff419e72456940c713ceb5efa68c2aHans Verkuil * v4l2_fh struct) is NULL. This function always returns 0. 9173cb42068cff419e72456940c713ceb5efa68c2aHans Verkuil */ 9273cb42068cff419e72456940c713ceb5efa68c2aHans Verkuilint v4l2_fh_release(struct file *filp); 93dfddb2441f39e8c0254504516be35b854addf6faHans Verkuil/* 94dfddb2441f39e8c0254504516be35b854addf6faHans Verkuil * Returns 1 if this filehandle is the only filehandle opened for the 95dfddb2441f39e8c0254504516be35b854addf6faHans Verkuil * associated video_device. If fh is NULL, then it returns 0. 96dfddb2441f39e8c0254504516be35b854addf6faHans Verkuil */ 97dfddb2441f39e8c0254504516be35b854addf6faHans Verkuilint v4l2_fh_is_singular(struct v4l2_fh *fh); 98dfddb2441f39e8c0254504516be35b854addf6faHans Verkuil/* 99dfddb2441f39e8c0254504516be35b854addf6faHans Verkuil * Helper function with struct file as argument. If filp->private_data is 100dfddb2441f39e8c0254504516be35b854addf6faHans Verkuil * NULL, then it will return 0. 101dfddb2441f39e8c0254504516be35b854addf6faHans Verkuil */ 102dfddb2441f39e8c0254504516be35b854addf6faHans Verkuilstatic inline int v4l2_fh_is_singular_file(struct file *filp) 103dfddb2441f39e8c0254504516be35b854addf6faHans Verkuil{ 104dfddb2441f39e8c0254504516be35b854addf6faHans Verkuil return v4l2_fh_is_singular(filp->private_data); 105dfddb2441f39e8c0254504516be35b854addf6faHans Verkuil} 1061babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus 1071babcb460f2b87c20eb6860b9685a0dab636cc4bSakari Ailus#endif /* V4L2_EVENT_H */ 108