msm_kms.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
  4. * Copyright (C) 2013 Red Hat
  5. * Author: Rob Clark <[email protected]>
  6. */
  7. #ifndef __MSM_KMS_H__
  8. #define __MSM_KMS_H__
  9. #include <linux/clk.h>
  10. #include <linux/regulator/consumer.h>
  11. #include "msm_drv.h"
  12. #define MAX_PLANE 4
  13. /* As there are different display controller blocks depending on the
  14. * snapdragon version, the kms support is split out and the appropriate
  15. * implementation is loaded at runtime. The kms module is responsible
  16. * for constructing the appropriate planes/crtcs/encoders/connectors.
  17. */
  18. struct msm_kms_funcs {
  19. /* hw initialization: */
  20. int (*hw_init)(struct msm_kms *kms);
  21. /* irq handling: */
  22. void (*irq_preinstall)(struct msm_kms *kms);
  23. int (*irq_postinstall)(struct msm_kms *kms);
  24. void (*irq_uninstall)(struct msm_kms *kms);
  25. irqreturn_t (*irq)(struct msm_kms *kms);
  26. int (*enable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
  27. void (*disable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
  28. /*
  29. * Atomic commit handling:
  30. *
  31. * Note that in the case of async commits, the funcs which take
  32. * a crtc_mask (ie. ->flush_commit(), and ->complete_commit())
  33. * might not be evenly balanced with ->prepare_commit(), however
  34. * each crtc that effected by a ->prepare_commit() (potentially
  35. * multiple times) will eventually (at end of vsync period) be
  36. * flushed and completed.
  37. *
  38. * This has some implications about tracking of cleanup state,
  39. * for example SMP blocks to release after commit completes. Ie.
  40. * cleanup state should be also duplicated in the various
  41. * duplicate_state() methods, as the current cleanup state at
  42. * ->complete_commit() time may have accumulated cleanup work
  43. * from multiple commits.
  44. */
  45. /**
  46. * Enable/disable power/clks needed for hw access done in other
  47. * commit related methods.
  48. *
  49. * If mdp4 is migrated to runpm, we could probably drop these
  50. * and use runpm directly.
  51. */
  52. void (*enable_commit)(struct msm_kms *kms);
  53. void (*disable_commit)(struct msm_kms *kms);
  54. /**
  55. * If the kms backend supports async commit, it should implement
  56. * this method to return the time of the next vsync. This is
  57. * used to determine a time slightly before vsync, for the async
  58. * commit timer to run and complete an async commit.
  59. */
  60. ktime_t (*vsync_time)(struct msm_kms *kms, struct drm_crtc *crtc);
  61. /**
  62. * Prepare for atomic commit. This is called after any previous
  63. * (async or otherwise) commit has completed.
  64. */
  65. void (*prepare_commit)(struct msm_kms *kms, struct drm_atomic_state *state);
  66. /**
  67. * Flush an atomic commit. This is called after the hardware
  68. * updates have already been pushed down to effected planes/
  69. * crtcs/encoders/connectors.
  70. */
  71. void (*flush_commit)(struct msm_kms *kms, unsigned crtc_mask);
  72. /**
  73. * Wait for any in-progress flush to complete on the specified
  74. * crtcs. This should not block if there is no in-progress
  75. * commit (ie. don't just wait for a vblank), as it will also
  76. * be called before ->prepare_commit() to ensure any potential
  77. * "async" commit has completed.
  78. */
  79. void (*wait_flush)(struct msm_kms *kms, unsigned crtc_mask);
  80. /**
  81. * Clean up after commit is completed. This is called after
  82. * ->wait_flush(), to give the backend a chance to do any
  83. * post-commit cleanup.
  84. */
  85. void (*complete_commit)(struct msm_kms *kms, unsigned crtc_mask);
  86. /*
  87. * Format handling:
  88. */
  89. /* get msm_format w/ optional format modifiers from drm_mode_fb_cmd2 */
  90. const struct msm_format *(*get_format)(struct msm_kms *kms,
  91. const uint32_t format,
  92. const uint64_t modifiers);
  93. /* do format checking on format modified through fb_cmd2 modifiers */
  94. int (*check_modified_format)(const struct msm_kms *kms,
  95. const struct msm_format *msm_fmt,
  96. const struct drm_mode_fb_cmd2 *cmd,
  97. struct drm_gem_object **bos);
  98. /* misc: */
  99. long (*round_pixclk)(struct msm_kms *kms, unsigned long rate,
  100. struct drm_encoder *encoder);
  101. int (*set_split_display)(struct msm_kms *kms,
  102. struct drm_encoder *encoder,
  103. struct drm_encoder *slave_encoder,
  104. bool is_cmd_mode);
  105. /* cleanup: */
  106. void (*destroy)(struct msm_kms *kms);
  107. /* snapshot: */
  108. void (*snapshot)(struct msm_disp_state *disp_state, struct msm_kms *kms);
  109. #ifdef CONFIG_DEBUG_FS
  110. /* debugfs: */
  111. int (*debugfs_init)(struct msm_kms *kms, struct drm_minor *minor);
  112. #endif
  113. };
  114. struct msm_kms;
  115. /*
  116. * A per-crtc timer for pending async atomic flushes. Scheduled to expire
  117. * shortly before vblank to flush pending async updates.
  118. */
  119. struct msm_pending_timer {
  120. struct msm_hrtimer_work work;
  121. struct kthread_worker *worker;
  122. struct msm_kms *kms;
  123. unsigned crtc_idx;
  124. };
  125. struct msm_kms {
  126. const struct msm_kms_funcs *funcs;
  127. struct drm_device *dev;
  128. /* irq number to be passed on to msm_irq_install */
  129. int irq;
  130. bool irq_requested;
  131. /* mapper-id used to request GEM buffer mapped for scanout: */
  132. struct msm_gem_address_space *aspace;
  133. /* disp snapshot support */
  134. struct kthread_worker *dump_worker;
  135. struct kthread_work dump_work;
  136. struct mutex dump_mutex;
  137. /*
  138. * For async commit, where ->flush_commit() and later happens
  139. * from the crtc's pending_timer close to end of the frame:
  140. */
  141. struct mutex commit_lock[MAX_CRTCS];
  142. unsigned pending_crtc_mask;
  143. struct msm_pending_timer pending_timers[MAX_CRTCS];
  144. };
  145. static inline int msm_kms_init(struct msm_kms *kms,
  146. const struct msm_kms_funcs *funcs)
  147. {
  148. unsigned i, ret;
  149. for (i = 0; i < ARRAY_SIZE(kms->commit_lock); i++)
  150. mutex_init(&kms->commit_lock[i]);
  151. kms->funcs = funcs;
  152. for (i = 0; i < ARRAY_SIZE(kms->pending_timers); i++) {
  153. ret = msm_atomic_init_pending_timer(&kms->pending_timers[i], kms, i);
  154. if (ret) {
  155. return ret;
  156. }
  157. }
  158. return 0;
  159. }
  160. static inline void msm_kms_destroy(struct msm_kms *kms)
  161. {
  162. unsigned i;
  163. for (i = 0; i < ARRAY_SIZE(kms->pending_timers); i++)
  164. msm_atomic_destroy_pending_timer(&kms->pending_timers[i]);
  165. }
  166. #define for_each_crtc_mask(dev, crtc, crtc_mask) \
  167. drm_for_each_crtc(crtc, dev) \
  168. for_each_if (drm_crtc_mask(crtc) & (crtc_mask))
  169. #define for_each_crtc_mask_reverse(dev, crtc, crtc_mask) \
  170. drm_for_each_crtc_reverse(crtc, dev) \
  171. for_each_if (drm_crtc_mask(crtc) & (crtc_mask))
  172. #endif /* __MSM_KMS_H__ */