drm_irq.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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_IRQ_H_
  24. #define _DRM_IRQ_H_
  25. #include <linux/seqlock.h>
  26. /**
  27. * struct drm_pending_vblank_event - pending vblank event tracking
  28. */
  29. struct drm_pending_vblank_event {
  30. /**
  31. * @base: Base structure for tracking pending DRM events.
  32. */
  33. struct drm_pending_event base;
  34. /**
  35. * @pipe: drm_crtc_index() of the &drm_crtc this event is for.
  36. */
  37. unsigned int pipe;
  38. /**
  39. * @event: Actual event which will be sent to userspace.
  40. */
  41. struct drm_event_vblank event;
  42. };
  43. /**
  44. * struct drm_vblank_crtc - vblank tracking for a CRTC
  45. *
  46. * This structure tracks the vblank state for one CRTC.
  47. *
  48. * Note that for historical reasons - the vblank handling code is still shared
  49. * with legacy/non-kms drivers - this is a free-standing structure not directly
  50. * connected to struct &drm_crtc. But all public interface functions are taking
  51. * a struct &drm_crtc to hide this implementation detail.
  52. */
  53. struct drm_vblank_crtc {
  54. /**
  55. * @dev: Pointer to the &drm_device.
  56. */
  57. struct drm_device *dev;
  58. /**
  59. * @queue: Wait queue for vblank waiters.
  60. */
  61. wait_queue_head_t queue; /**< VBLANK wait queue */
  62. /**
  63. * @disable_timer: Disable timer for the delayed vblank disabling
  64. * hysteresis logic. Vblank disabling is controlled through the
  65. * drm_vblank_offdelay module option and the setting of the
  66. * max_vblank_count value in the &drm_device structure.
  67. */
  68. struct timer_list disable_timer;
  69. /**
  70. * @seqlock: Protect vblank count and time.
  71. */
  72. seqlock_t seqlock; /* protects vblank count and time */
  73. /**
  74. * @count: Current software vblank counter.
  75. */
  76. u32 count;
  77. /**
  78. * @time: Vblank timestamp corresponding to @count.
  79. */
  80. struct timeval time;
  81. /**
  82. * @refcount: Number of users/waiters of the vblank interrupt. Only when
  83. * this refcount reaches 0 can the hardware interrupt be disabled using
  84. * @disable_timer.
  85. */
  86. atomic_t refcount; /* number of users of vblank interruptsper crtc */
  87. /**
  88. * @last: Protected by dev->vbl_lock, used for wraparound handling.
  89. */
  90. u32 last;
  91. /**
  92. * @inmodeset: Tracks whether the vblank is disabled due to a modeset.
  93. * For legacy driver bit 2 additionally tracks whether an additional
  94. * temporary vblank reference has been acquired to paper over the
  95. * hardware counter resetting/jumping. KMS drivers should instead just
  96. * call drm_crtc_vblank_off() and drm_crtc_vblank_on(), which explicitly
  97. * save and restore the vblank count.
  98. */
  99. unsigned int inmodeset; /* Display driver is setting mode */
  100. /**
  101. * @pipe: drm_crtc_index() of the &drm_crtc corresponding to this
  102. * structure.
  103. */
  104. unsigned int pipe;
  105. /**
  106. * @framedur_ns: Frame/Field duration in ns, used by
  107. * drm_calc_vbltimestamp_from_scanoutpos() and computed by
  108. * drm_calc_timestamping_constants().
  109. */
  110. int framedur_ns;
  111. /**
  112. * @linedur_ns: Line duration in ns, used by
  113. * drm_calc_vbltimestamp_from_scanoutpos() and computed by
  114. * drm_calc_timestamping_constants().
  115. */
  116. int linedur_ns;
  117. /**
  118. * @enabled: Tracks the enabling state of the corresponding &drm_crtc to
  119. * avoid double-disabling and hence corrupting saved state. Needed by
  120. * drivers not using atomic KMS, since those might go through their CRTC
  121. * disabling functions multiple times.
  122. */
  123. bool enabled;
  124. };
  125. extern int drm_irq_install(struct drm_device *dev, int irq);
  126. extern int drm_irq_uninstall(struct drm_device *dev);
  127. extern int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs);
  128. extern int drm_wait_vblank(struct drm_device *dev, void *data,
  129. struct drm_file *filp);
  130. extern u32 drm_vblank_count(struct drm_device *dev, unsigned int pipe);
  131. extern u32 drm_crtc_vblank_count(struct drm_crtc *crtc);
  132. extern u32 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc,
  133. struct timeval *vblanktime);
  134. extern void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
  135. struct drm_pending_vblank_event *e);
  136. extern void drm_crtc_arm_vblank_event(struct drm_crtc *crtc,
  137. struct drm_pending_vblank_event *e);
  138. extern bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe);
  139. extern bool drm_crtc_handle_vblank(struct drm_crtc *crtc);
  140. extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
  141. extern void drm_crtc_vblank_put(struct drm_crtc *crtc);
  142. extern void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe);
  143. extern void drm_crtc_wait_one_vblank(struct drm_crtc *crtc);
  144. extern void drm_vblank_off(struct drm_device *dev, unsigned int pipe);
  145. extern void drm_vblank_on(struct drm_device *dev, unsigned int pipe);
  146. extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
  147. extern void drm_crtc_vblank_reset(struct drm_crtc *crtc);
  148. extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
  149. extern void drm_vblank_cleanup(struct drm_device *dev);
  150. extern u32 drm_accurate_vblank_count(struct drm_crtc *crtc);
  151. extern u32 drm_vblank_no_hw_counter(struct drm_device *dev, unsigned int pipe);
  152. extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
  153. unsigned int pipe, int *max_error,
  154. struct timeval *vblank_time,
  155. unsigned flags,
  156. const struct drm_display_mode *mode);
  157. extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
  158. const struct drm_display_mode *mode);
  159. /**
  160. * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC
  161. * @crtc: which CRTC's vblank waitqueue to retrieve
  162. *
  163. * This function returns a pointer to the vblank waitqueue for the CRTC.
  164. * Drivers can use this to implement vblank waits using wait_event() and related
  165. * functions.
  166. */
  167. static inline wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc)
  168. {
  169. return &crtc->dev->vblank[drm_crtc_index(crtc)].queue;
  170. }
  171. #endif