drm_vblank.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright 2016 Intel Corp.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #ifndef _DRM_VBLANK_H_
  24. #define _DRM_VBLANK_H_
  25. #include <linux/seqlock.h>
  26. #include <linux/idr.h>
  27. #include <linux/poll.h>
  28. #include <drm/drm_file.h>
  29. #include <drm/drm_modes.h>
  30. #include <uapi/drm/drm.h>
  31. struct drm_device;
  32. struct drm_crtc;
  33. /**
  34. * struct drm_pending_vblank_event - pending vblank event tracking
  35. */
  36. struct drm_pending_vblank_event {
  37. /**
  38. * @base: Base structure for tracking pending DRM events.
  39. */
  40. struct drm_pending_event base;
  41. /**
  42. * @pipe: drm_crtc_index() of the &drm_crtc this event is for.
  43. */
  44. unsigned int pipe;
  45. /**
  46. * @event: Actual event which will be sent to userspace.
  47. */
  48. struct drm_event_vblank event;
  49. };
  50. /**
  51. * struct drm_vblank_crtc - vblank tracking for a CRTC
  52. *
  53. * This structure tracks the vblank state for one CRTC.
  54. *
  55. * Note that for historical reasons - the vblank handling code is still shared
  56. * with legacy/non-kms drivers - this is a free-standing structure not directly
  57. * connected to &struct drm_crtc. But all public interface functions are taking
  58. * a &struct drm_crtc to hide this implementation detail.
  59. */
  60. struct drm_vblank_crtc {
  61. /**
  62. * @dev: Pointer to the &drm_device.
  63. */
  64. struct drm_device *dev;
  65. /**
  66. * @queue: Wait queue for vblank waiters.
  67. */
  68. wait_queue_head_t queue; /**< VBLANK wait queue */
  69. /**
  70. * @disable_timer: Disable timer for the delayed vblank disabling
  71. * hysteresis logic. Vblank disabling is controlled through the
  72. * drm_vblank_offdelay module option and the setting of the
  73. * &drm_device.max_vblank_count value.
  74. */
  75. struct timer_list disable_timer;
  76. /**
  77. * @seqlock: Protect vblank count and time.
  78. */
  79. seqlock_t seqlock; /* protects vblank count and time */
  80. /**
  81. * @count: Current software vblank counter.
  82. */
  83. u32 count;
  84. /**
  85. * @time: Vblank timestamp corresponding to @count.
  86. */
  87. ktime_t time;
  88. /**
  89. * @refcount: Number of users/waiters of the vblank interrupt. Only when
  90. * this refcount reaches 0 can the hardware interrupt be disabled using
  91. * @disable_timer.
  92. */
  93. atomic_t refcount; /* number of users of vblank interruptsper crtc */
  94. /**
  95. * @last: Protected by &drm_device.vbl_lock, used for wraparound handling.
  96. */
  97. u32 last;
  98. /**
  99. * @inmodeset: Tracks whether the vblank is disabled due to a modeset.
  100. * For legacy driver bit 2 additionally tracks whether an additional
  101. * temporary vblank reference has been acquired to paper over the
  102. * hardware counter resetting/jumping. KMS drivers should instead just
  103. * call drm_crtc_vblank_off() and drm_crtc_vblank_on(), which explicitly
  104. * save and restore the vblank count.
  105. */
  106. unsigned int inmodeset; /* Display driver is setting mode */
  107. /**
  108. * @pipe: drm_crtc_index() of the &drm_crtc corresponding to this
  109. * structure.
  110. */
  111. unsigned int pipe;
  112. /**
  113. * @framedur_ns: Frame/Field duration in ns, used by
  114. * drm_calc_vbltimestamp_from_scanoutpos() and computed by
  115. * drm_calc_timestamping_constants().
  116. */
  117. int framedur_ns;
  118. /**
  119. * @linedur_ns: Line duration in ns, used by
  120. * drm_calc_vbltimestamp_from_scanoutpos() and computed by
  121. * drm_calc_timestamping_constants().
  122. */
  123. int linedur_ns;
  124. /**
  125. * @hwmode:
  126. *
  127. * Cache of the current hardware display mode. Only valid when @enabled
  128. * is set. This is used by helpers like
  129. * drm_calc_vbltimestamp_from_scanoutpos(). We can't just access the
  130. * hardware mode by e.g. looking at &drm_crtc_state.adjusted_mode,
  131. * because that one is really hard to get from interrupt context.
  132. */
  133. struct drm_display_mode hwmode;
  134. /**
  135. * @enabled: Tracks the enabling state of the corresponding &drm_crtc to
  136. * avoid double-disabling and hence corrupting saved state. Needed by
  137. * drivers not using atomic KMS, since those might go through their CRTC
  138. * disabling functions multiple times.
  139. */
  140. bool enabled;
  141. };
  142. int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs);
  143. u32 drm_crtc_vblank_count(struct drm_crtc *crtc);
  144. u32 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc,
  145. ktime_t *vblanktime);
  146. void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
  147. struct drm_pending_vblank_event *e);
  148. void drm_crtc_arm_vblank_event(struct drm_crtc *crtc,
  149. struct drm_pending_vblank_event *e);
  150. bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe);
  151. bool drm_crtc_handle_vblank(struct drm_crtc *crtc);
  152. int drm_crtc_vblank_get(struct drm_crtc *crtc);
  153. void drm_crtc_vblank_put(struct drm_crtc *crtc);
  154. void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe);
  155. void drm_crtc_wait_one_vblank(struct drm_crtc *crtc);
  156. void drm_crtc_vblank_off(struct drm_crtc *crtc);
  157. void drm_crtc_vblank_reset(struct drm_crtc *crtc);
  158. void drm_crtc_vblank_on(struct drm_crtc *crtc);
  159. u32 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc);
  160. bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
  161. unsigned int pipe, int *max_error,
  162. ktime_t *vblank_time,
  163. bool in_vblank_irq);
  164. void drm_calc_timestamping_constants(struct drm_crtc *crtc,
  165. const struct drm_display_mode *mode);
  166. wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc);
  167. #endif