11babcb46SSakari Ailus /* 21babcb46SSakari Ailus * v4l2-fh.h 31babcb46SSakari Ailus * 41babcb46SSakari Ailus * V4L2 file handle. Store per file handle data for the V4L2 51babcb46SSakari Ailus * framework. Using file handles is optional for the drivers. 61babcb46SSakari Ailus * 71babcb46SSakari Ailus * Copyright (C) 2009--2010 Nokia Corporation. 81babcb46SSakari Ailus * 98c5dff90SSakari Ailus * Contact: Sakari Ailus <sakari.ailus@iki.fi> 101babcb46SSakari Ailus * 111babcb46SSakari Ailus * This program is free software; you can redistribute it and/or 121babcb46SSakari Ailus * modify it under the terms of the GNU General Public License 131babcb46SSakari Ailus * version 2 as published by the Free Software Foundation. 141babcb46SSakari Ailus * 151babcb46SSakari Ailus * This program is distributed in the hope that it will be useful, but 161babcb46SSakari Ailus * WITHOUT ANY WARRANTY; without even the implied warranty of 171babcb46SSakari Ailus * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 181babcb46SSakari Ailus * General Public License for more details. 191babcb46SSakari Ailus */ 201babcb46SSakari Ailus 211babcb46SSakari Ailus #ifndef V4L2_FH_H 221babcb46SSakari Ailus #define V4L2_FH_H 231babcb46SSakari Ailus 244f1af2a3SLaurent Pinchart #include <linux/fs.h> 2514351d44SAlexandre Courbot #include <linux/kconfig.h> 261babcb46SSakari Ailus #include <linux/list.h> 27c8d185ceSLaurent Pinchart #include <linux/videodev2.h> 281babcb46SSakari Ailus 291babcb46SSakari Ailus struct video_device; 302d28b686SHans Verkuil struct v4l2_ctrl_handler; 311babcb46SSakari Ailus 324ada120eSMauro Carvalho Chehab /** 334ada120eSMauro Carvalho Chehab * struct v4l2_fh - Describes a V4L2 file handler 344ada120eSMauro Carvalho Chehab * 354ada120eSMauro Carvalho Chehab * @list: list of file handlers 364ada120eSMauro Carvalho Chehab * @vdev: pointer to &struct video_device 374ada120eSMauro Carvalho Chehab * @ctrl_handler: pointer to &struct v4l2_ctrl_handler 384ada120eSMauro Carvalho Chehab * @prio: priority of the file handler, as defined by &enum v4l2_priority 394ada120eSMauro Carvalho Chehab * 404ada120eSMauro Carvalho Chehab * @wait: event' s wait queue 41*ad608fbcSSakari Ailus * @subscribe_lock: serialise changes to the subscribed list; guarantee that 42*ad608fbcSSakari Ailus * the add and del event callbacks are orderly called 434ada120eSMauro Carvalho Chehab * @subscribed: list of subscribed events 444ada120eSMauro Carvalho Chehab * @available: list of events waiting to be dequeued 454ada120eSMauro Carvalho Chehab * @navailable: number of available events at @available list 464ada120eSMauro Carvalho Chehab * @sequence: event sequence number 47*ad608fbcSSakari Ailus * 484ada120eSMauro Carvalho Chehab * @m2m_ctx: pointer to &struct v4l2_m2m_ctx 494ada120eSMauro Carvalho Chehab */ 501babcb46SSakari Ailus struct v4l2_fh { 511babcb46SSakari Ailus struct list_head list; 521babcb46SSakari Ailus struct video_device *vdev; 532d28b686SHans Verkuil struct v4l2_ctrl_handler *ctrl_handler; 54fc5602beSHans Verkuil enum v4l2_priority prio; 55523f46d6SHans Verkuil 56523f46d6SHans Verkuil /* Events */ 57523f46d6SHans Verkuil wait_queue_head_t wait; 58*ad608fbcSSakari Ailus struct mutex subscribe_lock; 594ada120eSMauro Carvalho Chehab struct list_head subscribed; 604ada120eSMauro Carvalho Chehab struct list_head available; 61523f46d6SHans Verkuil unsigned int navailable; 62523f46d6SHans Verkuil u32 sequence; 638e6e8f93SSylwester Nawrocki 648e6e8f93SSylwester Nawrocki #if IS_ENABLED(CONFIG_V4L2_MEM2MEM_DEV) 658e6e8f93SSylwester Nawrocki struct v4l2_m2m_ctx *m2m_ctx; 668e6e8f93SSylwester Nawrocki #endif 671babcb46SSakari Ailus }; 681babcb46SSakari Ailus 694ada120eSMauro Carvalho Chehab /** 704ada120eSMauro Carvalho Chehab * v4l2_fh_init - Initialise the file handle. 714ada120eSMauro Carvalho Chehab * 724ada120eSMauro Carvalho Chehab * @fh: pointer to &struct v4l2_fh 734ada120eSMauro Carvalho Chehab * @vdev: pointer to &struct video_device 744ada120eSMauro Carvalho Chehab * 754ada120eSMauro Carvalho Chehab * Parts of the V4L2 framework using the 761babcb46SSakari Ailus * file handles should be initialised in this function. Must be called 774ada120eSMauro Carvalho Chehab * from driver's v4l2_file_operations->open\(\) handler if the driver 784ada120eSMauro Carvalho Chehab * uses &struct v4l2_fh. 791babcb46SSakari Ailus */ 80523f46d6SHans Verkuil void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev); 814ada120eSMauro Carvalho Chehab 824ada120eSMauro Carvalho Chehab /** 834ada120eSMauro Carvalho Chehab * v4l2_fh_add - Add the fh to the list of file handles on a video_device. 844ada120eSMauro Carvalho Chehab * 854ada120eSMauro Carvalho Chehab * @fh: pointer to &struct v4l2_fh 864ada120eSMauro Carvalho Chehab * 874ada120eSMauro Carvalho Chehab * .. note:: 884ada120eSMauro Carvalho Chehab * The @fh file handle must be initialised first. 891babcb46SSakari Ailus */ 901babcb46SSakari Ailus void v4l2_fh_add(struct v4l2_fh *fh); 914ada120eSMauro Carvalho Chehab 924ada120eSMauro Carvalho Chehab /** 934ada120eSMauro Carvalho Chehab * v4l2_fh_open - Ancillary routine that can be used as the open\(\) op 944ada120eSMauro Carvalho Chehab * of v4l2_file_operations. 954ada120eSMauro Carvalho Chehab * 964ada120eSMauro Carvalho Chehab * @filp: pointer to struct file 974ada120eSMauro Carvalho Chehab * 984ada120eSMauro Carvalho Chehab * It allocates a v4l2_fh and inits and adds it to the &struct video_device 994ada120eSMauro Carvalho Chehab * associated with the file pointer. 10073cb4206SHans Verkuil */ 10173cb4206SHans Verkuil int v4l2_fh_open(struct file *filp); 1024ada120eSMauro Carvalho Chehab 1034ada120eSMauro Carvalho Chehab /** 1044ada120eSMauro Carvalho Chehab * v4l2_fh_del - Remove file handle from the list of file handles. 1054ada120eSMauro Carvalho Chehab * 1064ada120eSMauro Carvalho Chehab * @fh: pointer to &struct v4l2_fh 1074ada120eSMauro Carvalho Chehab * 1084ada120eSMauro Carvalho Chehab * On error filp->private_data will be %NULL, otherwise it will point to 1094ada120eSMauro Carvalho Chehab * the &struct v4l2_fh. 1104ada120eSMauro Carvalho Chehab * 1114ada120eSMauro Carvalho Chehab * .. note:: 1124ada120eSMauro Carvalho Chehab * Must be called in v4l2_file_operations->release\(\) handler if the driver 1134ada120eSMauro Carvalho Chehab * uses &struct v4l2_fh. 1141babcb46SSakari Ailus */ 1151babcb46SSakari Ailus void v4l2_fh_del(struct v4l2_fh *fh); 1164ada120eSMauro Carvalho Chehab 1174ada120eSMauro Carvalho Chehab /** 1184ada120eSMauro Carvalho Chehab * v4l2_fh_exit - Release resources related to a file handle. 1194ada120eSMauro Carvalho Chehab * 1204ada120eSMauro Carvalho Chehab * @fh: pointer to &struct v4l2_fh 1214ada120eSMauro Carvalho Chehab * 1224ada120eSMauro Carvalho Chehab * Parts of the V4L2 framework using the v4l2_fh must release their 1234ada120eSMauro Carvalho Chehab * resources here, too. 1244ada120eSMauro Carvalho Chehab * 1254ada120eSMauro Carvalho Chehab * .. note:: 1264ada120eSMauro Carvalho Chehab * Must be called in v4l2_file_operations->release\(\) handler if the 1274ada120eSMauro Carvalho Chehab * driver uses &struct v4l2_fh. 1281babcb46SSakari Ailus */ 1291babcb46SSakari Ailus void v4l2_fh_exit(struct v4l2_fh *fh); 1304ada120eSMauro Carvalho Chehab 1314ada120eSMauro Carvalho Chehab /** 1324ada120eSMauro Carvalho Chehab * v4l2_fh_release - Ancillary routine that can be used as the release\(\) op 1334ada120eSMauro Carvalho Chehab * of v4l2_file_operations. 1344ada120eSMauro Carvalho Chehab * 1354ada120eSMauro Carvalho Chehab * @filp: pointer to struct file 1364ada120eSMauro Carvalho Chehab * 13773cb4206SHans Verkuil * It deletes and exits the v4l2_fh associated with the file pointer and 13873cb4206SHans Verkuil * frees it. It will do nothing if filp->private_data (the pointer to the 1394ada120eSMauro Carvalho Chehab * v4l2_fh struct) is %NULL. 1404ada120eSMauro Carvalho Chehab * 1414ada120eSMauro Carvalho Chehab * This function always returns 0. 14273cb4206SHans Verkuil */ 14373cb4206SHans Verkuil int v4l2_fh_release(struct file *filp); 1444ada120eSMauro Carvalho Chehab 1454ada120eSMauro Carvalho Chehab /** 1464ada120eSMauro Carvalho Chehab * v4l2_fh_is_singular - Returns 1 if this filehandle is the only filehandle 1474ada120eSMauro Carvalho Chehab * opened for the associated video_device. 1484ada120eSMauro Carvalho Chehab * 1494ada120eSMauro Carvalho Chehab * @fh: pointer to &struct v4l2_fh 1504ada120eSMauro Carvalho Chehab * 1514ada120eSMauro Carvalho Chehab * If @fh is NULL, then it returns 0. 152dfddb244SHans Verkuil */ 153dfddb244SHans Verkuil int v4l2_fh_is_singular(struct v4l2_fh *fh); 1544ada120eSMauro Carvalho Chehab 1554ada120eSMauro Carvalho Chehab /** 1564ada120eSMauro Carvalho Chehab * v4l2_fh_is_singular_file - Returns 1 if this filehandle is the only 1574ada120eSMauro Carvalho Chehab * filehandle opened for the associated video_device. 1584ada120eSMauro Carvalho Chehab * 1594ada120eSMauro Carvalho Chehab * @filp: pointer to struct file 1604ada120eSMauro Carvalho Chehab * 1614ada120eSMauro Carvalho Chehab * This is a helper function variant of v4l2_fh_is_singular() with uses 1624ada120eSMauro Carvalho Chehab * struct file as argument. 1634ada120eSMauro Carvalho Chehab * 1644ada120eSMauro Carvalho Chehab * If filp->private_data is %NULL, then it will return 0. 165dfddb244SHans Verkuil */ 166dfddb244SHans Verkuil static inline int v4l2_fh_is_singular_file(struct file *filp) 167dfddb244SHans Verkuil { 168dfddb244SHans Verkuil return v4l2_fh_is_singular(filp->private_data); 169dfddb244SHans Verkuil } 1701babcb46SSakari Ailus 1711babcb46SSakari Ailus #endif /* V4L2_EVENT_H */ 172