v4l2-fh.h 4.2 KB

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