1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * v4l2-fh.h 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * V4L2 file handle. Store per file handle data for the V4L2 6*4882a593Smuzhiyun * framework. Using file handles is optional for the drivers. 7*4882a593Smuzhiyun * 8*4882a593Smuzhiyun * Copyright (C) 2009--2010 Nokia Corporation. 9*4882a593Smuzhiyun * 10*4882a593Smuzhiyun * Contact: Sakari Ailus <sakari.ailus@iki.fi> 11*4882a593Smuzhiyun */ 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun #ifndef V4L2_FH_H 14*4882a593Smuzhiyun #define V4L2_FH_H 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun #include <linux/fs.h> 17*4882a593Smuzhiyun #include <linux/kconfig.h> 18*4882a593Smuzhiyun #include <linux/list.h> 19*4882a593Smuzhiyun #include <linux/videodev2.h> 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun struct video_device; 22*4882a593Smuzhiyun struct v4l2_ctrl_handler; 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun /** 25*4882a593Smuzhiyun * struct v4l2_fh - Describes a V4L2 file handler 26*4882a593Smuzhiyun * 27*4882a593Smuzhiyun * @list: list of file handlers 28*4882a593Smuzhiyun * @vdev: pointer to &struct video_device 29*4882a593Smuzhiyun * @ctrl_handler: pointer to &struct v4l2_ctrl_handler 30*4882a593Smuzhiyun * @prio: priority of the file handler, as defined by &enum v4l2_priority 31*4882a593Smuzhiyun * 32*4882a593Smuzhiyun * @wait: event' s wait queue 33*4882a593Smuzhiyun * @subscribe_lock: serialise changes to the subscribed list; guarantee that 34*4882a593Smuzhiyun * the add and del event callbacks are orderly called 35*4882a593Smuzhiyun * @subscribed: list of subscribed events 36*4882a593Smuzhiyun * @available: list of events waiting to be dequeued 37*4882a593Smuzhiyun * @navailable: number of available events at @available list 38*4882a593Smuzhiyun * @sequence: event sequence number 39*4882a593Smuzhiyun * 40*4882a593Smuzhiyun * @m2m_ctx: pointer to &struct v4l2_m2m_ctx 41*4882a593Smuzhiyun */ 42*4882a593Smuzhiyun struct v4l2_fh { 43*4882a593Smuzhiyun struct list_head list; 44*4882a593Smuzhiyun struct video_device *vdev; 45*4882a593Smuzhiyun struct v4l2_ctrl_handler *ctrl_handler; 46*4882a593Smuzhiyun enum v4l2_priority prio; 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun /* Events */ 49*4882a593Smuzhiyun wait_queue_head_t wait; 50*4882a593Smuzhiyun struct mutex subscribe_lock; 51*4882a593Smuzhiyun struct list_head subscribed; 52*4882a593Smuzhiyun struct list_head available; 53*4882a593Smuzhiyun unsigned int navailable; 54*4882a593Smuzhiyun u32 sequence; 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun struct v4l2_m2m_ctx *m2m_ctx; 57*4882a593Smuzhiyun }; 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun /** 60*4882a593Smuzhiyun * v4l2_fh_init - Initialise the file handle. 61*4882a593Smuzhiyun * 62*4882a593Smuzhiyun * @fh: pointer to &struct v4l2_fh 63*4882a593Smuzhiyun * @vdev: pointer to &struct video_device 64*4882a593Smuzhiyun * 65*4882a593Smuzhiyun * Parts of the V4L2 framework using the 66*4882a593Smuzhiyun * file handles should be initialised in this function. Must be called 67*4882a593Smuzhiyun * from driver's v4l2_file_operations->open\(\) handler if the driver 68*4882a593Smuzhiyun * uses &struct v4l2_fh. 69*4882a593Smuzhiyun */ 70*4882a593Smuzhiyun void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev); 71*4882a593Smuzhiyun 72*4882a593Smuzhiyun /** 73*4882a593Smuzhiyun * v4l2_fh_add - Add the fh to the list of file handles on a video_device. 74*4882a593Smuzhiyun * 75*4882a593Smuzhiyun * @fh: pointer to &struct v4l2_fh 76*4882a593Smuzhiyun * 77*4882a593Smuzhiyun * .. note:: 78*4882a593Smuzhiyun * The @fh file handle must be initialised first. 79*4882a593Smuzhiyun */ 80*4882a593Smuzhiyun void v4l2_fh_add(struct v4l2_fh *fh); 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun /** 83*4882a593Smuzhiyun * v4l2_fh_open - Ancillary routine that can be used as the open\(\) op 84*4882a593Smuzhiyun * of v4l2_file_operations. 85*4882a593Smuzhiyun * 86*4882a593Smuzhiyun * @filp: pointer to struct file 87*4882a593Smuzhiyun * 88*4882a593Smuzhiyun * It allocates a v4l2_fh and inits and adds it to the &struct video_device 89*4882a593Smuzhiyun * associated with the file pointer. 90*4882a593Smuzhiyun */ 91*4882a593Smuzhiyun int v4l2_fh_open(struct file *filp); 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun /** 94*4882a593Smuzhiyun * v4l2_fh_del - Remove file handle from the list of file handles. 95*4882a593Smuzhiyun * 96*4882a593Smuzhiyun * @fh: pointer to &struct v4l2_fh 97*4882a593Smuzhiyun * 98*4882a593Smuzhiyun * On error filp->private_data will be %NULL, otherwise it will point to 99*4882a593Smuzhiyun * the &struct v4l2_fh. 100*4882a593Smuzhiyun * 101*4882a593Smuzhiyun * .. note:: 102*4882a593Smuzhiyun * Must be called in v4l2_file_operations->release\(\) handler if the driver 103*4882a593Smuzhiyun * uses &struct v4l2_fh. 104*4882a593Smuzhiyun */ 105*4882a593Smuzhiyun void v4l2_fh_del(struct v4l2_fh *fh); 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun /** 108*4882a593Smuzhiyun * v4l2_fh_exit - Release resources related to a file handle. 109*4882a593Smuzhiyun * 110*4882a593Smuzhiyun * @fh: pointer to &struct v4l2_fh 111*4882a593Smuzhiyun * 112*4882a593Smuzhiyun * Parts of the V4L2 framework using the v4l2_fh must release their 113*4882a593Smuzhiyun * resources here, too. 114*4882a593Smuzhiyun * 115*4882a593Smuzhiyun * .. note:: 116*4882a593Smuzhiyun * Must be called in v4l2_file_operations->release\(\) handler if the 117*4882a593Smuzhiyun * driver uses &struct v4l2_fh. 118*4882a593Smuzhiyun */ 119*4882a593Smuzhiyun void v4l2_fh_exit(struct v4l2_fh *fh); 120*4882a593Smuzhiyun 121*4882a593Smuzhiyun /** 122*4882a593Smuzhiyun * v4l2_fh_release - Ancillary routine that can be used as the release\(\) op 123*4882a593Smuzhiyun * of v4l2_file_operations. 124*4882a593Smuzhiyun * 125*4882a593Smuzhiyun * @filp: pointer to struct file 126*4882a593Smuzhiyun * 127*4882a593Smuzhiyun * It deletes and exits the v4l2_fh associated with the file pointer and 128*4882a593Smuzhiyun * frees it. It will do nothing if filp->private_data (the pointer to the 129*4882a593Smuzhiyun * v4l2_fh struct) is %NULL. 130*4882a593Smuzhiyun * 131*4882a593Smuzhiyun * This function always returns 0. 132*4882a593Smuzhiyun */ 133*4882a593Smuzhiyun int v4l2_fh_release(struct file *filp); 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun /** 136*4882a593Smuzhiyun * v4l2_fh_is_singular - Returns 1 if this filehandle is the only filehandle 137*4882a593Smuzhiyun * opened for the associated video_device. 138*4882a593Smuzhiyun * 139*4882a593Smuzhiyun * @fh: pointer to &struct v4l2_fh 140*4882a593Smuzhiyun * 141*4882a593Smuzhiyun * If @fh is NULL, then it returns 0. 142*4882a593Smuzhiyun */ 143*4882a593Smuzhiyun int v4l2_fh_is_singular(struct v4l2_fh *fh); 144*4882a593Smuzhiyun 145*4882a593Smuzhiyun /** 146*4882a593Smuzhiyun * v4l2_fh_is_singular_file - Returns 1 if this filehandle is the only 147*4882a593Smuzhiyun * filehandle opened for the associated video_device. 148*4882a593Smuzhiyun * 149*4882a593Smuzhiyun * @filp: pointer to struct file 150*4882a593Smuzhiyun * 151*4882a593Smuzhiyun * This is a helper function variant of v4l2_fh_is_singular() with uses 152*4882a593Smuzhiyun * struct file as argument. 153*4882a593Smuzhiyun * 154*4882a593Smuzhiyun * If filp->private_data is %NULL, then it will return 0. 155*4882a593Smuzhiyun */ v4l2_fh_is_singular_file(struct file * filp)156*4882a593Smuzhiyunstatic inline int v4l2_fh_is_singular_file(struct file *filp) 157*4882a593Smuzhiyun { 158*4882a593Smuzhiyun return v4l2_fh_is_singular(filp->private_data); 159*4882a593Smuzhiyun } 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun #endif /* V4L2_EVENT_H */ 162